diff options
author | Benji Dial <benji6283@gmail.com> | 2020-09-06 15:47:06 -0400 |
---|---|---|
committer | Benji Dial <benji6283@gmail.com> | 2020-09-06 15:47:06 -0400 |
commit | b8284137d4e0eec11c78bc14047243fce6a51373 (patch) | |
tree | 5969602dc3d090b536edccbf34d33d46a300c192 /src | |
parent | 73bb0e48640b842824a0b45fe4854df8ff7faf7b (diff) | |
download | portland-os-b8284137d4e0eec11c78bc14047243fce6a51373.tar.gz |
minor changes, redoing makefile, meminfo program
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/elf-link.ld | 2 | ||||
-rw-r--r-- | src/kernel/idt.c | 40 | ||||
-rw-r--r-- | src/kernel/isrs.asm | 2 | ||||
-rw-r--r-- | src/kernel/log.c | 2 | ||||
-rw-r--r-- | src/kernel/main.c | 23 | ||||
-rw-r--r-- | src/kernel/task.c | 3 | ||||
-rw-r--r-- | src/user/hello/hello.c | 2 | ||||
-rw-r--r-- | src/user/include/knob/format.h | 1 | ||||
-rw-r--r-- | src/user/include/pland/syscall.h | 27 | ||||
-rw-r--r-- | src/user/init/init.c (renamed from src/user/init/main.c) | 2 | ||||
-rw-r--r-- | src/user/knob/format.c | 18 | ||||
-rw-r--r-- | src/user/meminfo/meminfo.c | 19 |
12 files changed, 114 insertions, 27 deletions
diff --git a/src/kernel/elf-link.ld b/src/kernel/elf-link.ld index 10abac0..84d3f92 100644 --- a/src/kernel/elf-link.ld +++ b/src/kernel/elf-link.ld @@ -4,7 +4,7 @@ OUTPUT_ARCH(i386) SECTIONS { . = 0x00030000; .text : { - */main.o(.text) + */main.ko(.text) *(.text) } .rodata : { diff --git a/src/kernel/idt.c b/src/kernel/idt.c index 31d597f..3d23797 100644 --- a/src/kernel/idt.c +++ b/src/kernel/idt.c @@ -6,6 +6,7 @@ #include "panic.h" #include "task.h" #include "paging.h" +#include "pmap.h" enum { IDT_PRESENT = 0x80, @@ -73,6 +74,32 @@ static void *sc_allocate_ram(uint32_t pages) { return pd_user_allocate_anywhere_writable(active_task->page_directory, pages); } +enum mi_arg { + MI_KERNEL_MAX, + MI_KERNEL_LEFT, + MI_USER_MAX, + MI_USER_LEFT, + MI_TASK_LEFT +}; + +__attribute__ ((pure)) +static uint32_t sc_memory_info(enum mi_arg arg) { + switch (arg) { + case MI_KERNEL_MAX: + return max_kernel_pages; + case MI_KERNEL_LEFT: + return kernel_pages_left; + case MI_USER_MAX: + return max_user_pages; + case MI_USER_LEFT: + return user_pages_left; + case MI_TASK_LEFT: + panic("TODO: this process memory left"); + default: + return -1; + } +} + void const *syscall_table[] = { &sc_open_file, &sc_close_file, @@ -81,14 +108,17 @@ void const *syscall_table[] = { &sc_start_task, &sc_log_string, &sc_get_key, - &sc_allocate_ram + &sc_allocate_ram, + &sc_memory_info }; -extern void syscall_isr; -extern void quit_isr; -extern void yield_isr; +typedef void isr_t; + +extern isr_t syscall_isr; +extern isr_t quit_isr; +extern isr_t yield_isr; -static void register_int(uint8_t n, void *isr, uint8_t dpl) { +static void register_int(uint8_t n, isr_t *isr, uint8_t dpl) { idt[n].addr_low = (uint32_t)isr & 0xffff; idt[n].addr_high = (uint32_t)isr >> 16; idt[n].cs = 0x10; diff --git a/src/kernel/isrs.asm b/src/kernel/isrs.asm index 1fd6fcb..82c17fe 100644 --- a/src/kernel/isrs.asm +++ b/src/kernel/isrs.asm @@ -11,7 +11,7 @@ extern active_task extern delete_task extern advance_active_task -n_syscalls equ 8 +n_syscalls equ 0x9 section .text syscall_isr: diff --git a/src/kernel/log.c b/src/kernel/log.c index 39fc1ba..b5a96cb 100644 --- a/src/kernel/log.c +++ b/src/kernel/log.c @@ -12,6 +12,8 @@ static const uint8_t log_mode_colors[] = { void set_log_mode(enum log_mode mode) { vga_set_color(log_mode_colors[mode]); + vga_printch('\n'); + vga_printch('\n'); } void logch(char ch) { diff --git a/src/kernel/main.c b/src/kernel/main.c index 2f63d71..d99b595 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -124,30 +124,25 @@ void main() { logch('\n'); } - if (!try_elf_run(drives, "BIN/INIT.ELF")) - panic("Failed to load init program."); - if (BOOT_INFO->support_flags & BIS_PAE) - logsz("Processor supports PAE (but Portland OS does not yet).\n\n"); + logsz("Processor supports PAE (but Portland OS does not yet).\n"); else - logsz("Processor does not support PAE.\n\n"); + logsz("Processor does not support PAE.\n"); - u32_dec(kernel_pages_left * 4, nbuf); - logsz(nbuf); - logsz("k / "); + logsz("Kernel dynamic area size: "); u32_dec(max_kernel_pages * 4, nbuf); logsz(nbuf); - logsz("k kernel heap free.\n"); - u32_dec(user_pages_left * 4, nbuf); - logsz(nbuf); - logsz("k / "); + logsz("k\nUserspace area size: "); u32_dec(max_user_pages * 4, nbuf); logsz(nbuf); - logsz("k user memory free.\n"); + logsz("k\n\n"); + + if (!try_elf_run(drives, "BIN/INIT.ELF")) + panic("Failed to load init program."); init_idt(); + logsz("Switching to init task.\n"); set_log_mode(LOG_USER); - logch('\n'); _start_user_mode(); }
\ No newline at end of file diff --git a/src/kernel/task.c b/src/kernel/task.c index 80818a7..2a1f4c4 100644 --- a/src/kernel/task.c +++ b/src/kernel/task.c @@ -79,9 +79,8 @@ void advance_active_task() { if (++active_task == tasks + MAX_TASKS) active_task = tasks; if (active_task == prev_task) { - logch('\n'); set_log_mode(LOG_SYSTEM); - logsz("\nNo active tasks, halting."); + logsz("No active tasks, halting."); while (1) asm ("hlt"); } diff --git a/src/user/hello/hello.c b/src/user/hello/hello.c index 65e23f0..00d33b5 100644 --- a/src/user/hello/hello.c +++ b/src/user/hello/hello.c @@ -1,5 +1,5 @@ #include <knob/user.h> void main() { - tell_user_sz("\nHello, world!\nThis is a userspace program that has been started by init."); + tell_user_sz("Hello, world!\n"); }
\ No newline at end of file diff --git a/src/user/include/knob/format.h b/src/user/include/knob/format.h index 16d3d83..6c4aa5d 100644 --- a/src/user/include/knob/format.h +++ b/src/user/include/knob/format.h @@ -5,5 +5,6 @@ #include <stdint.h> bool try_sntoi(const char *s, uint32_t n, uint32_t *out); +void itosz(uint32_t i, char *out); #endif
\ No newline at end of file diff --git a/src/user/include/pland/syscall.h b/src/user/include/pland/syscall.h index 5858d16..298fc51 100644 --- a/src/user/include/pland/syscall.h +++ b/src/user/include/pland/syscall.h @@ -7,6 +7,8 @@ typedef uint32_t _file_handle_t; typedef uint32_t _task_handle_t; typedef uint32_t _drive_number_t; +typedef uint32_t _pages_t; + typedef enum { _KEY_BACKSPACE = '\b', _KEY_RETURN = '\n', @@ -40,7 +42,8 @@ enum _scn { _SCN_START_TASK, _SCN_LOG_STRING, _SCN_GET_KEY, - _SCN_ALLOCATE_RAM + _SCN_ALLOCATE_RAM, + _SCN_MEMORY_INFO }; static inline uint32_t _sc0(enum _scn eax) { @@ -133,8 +136,28 @@ static inline _key_code_t _get_key() { return _sc0(_SCN_GET_KEY); } -static inline void *_allocate_ram(uint32_t pages) { +static inline void *_allocate_ram(_pages_t pages) { return (void *)_sc1(_SCN_ALLOCATE_RAM, pages); } +static inline _pages_t _kernel_dynamic_area_size() { + return _sc1(_SCN_MEMORY_INFO, 0x0); +} + +static inline _pages_t _kernel_dynamic_area_left() { + return _sc1(_SCN_MEMORY_INFO, 0x1); +} + +static inline _pages_t _total_userspace_size() { + return _sc1(_SCN_MEMORY_INFO, 0x2); +} + +static inline _pages_t _total_userspace_left() { + return _sc1(_SCN_MEMORY_INFO, 0x3); +} + +static inline _pages_t _this_process_memory_left() { + return _sc1(_SCN_MEMORY_INFO, 0x4); +} + #endif
\ No newline at end of file diff --git a/src/user/init/main.c b/src/user/init/init.c index c301a78..b8536be 100644 --- a/src/user/init/main.c +++ b/src/user/init/init.c @@ -5,7 +5,7 @@ void main() { struct file *f = open_file("SYS/STARTUP.RC"); if (!f) { - tell_user_sz("\nCould not open SYS/STARTUP.RC"); + tell_user_sz("Could not open SYS/STARTUP.RC\n"); return; } diff --git a/src/user/knob/format.c b/src/user/knob/format.c index f55e857..087f6fd 100644 --- a/src/user/knob/format.c +++ b/src/user/knob/format.c @@ -10,4 +10,22 @@ bool try_sntoi(const char *s, uint32_t n, uint32_t *out) { } *out = calc; return true; +} + +void itosz(uint32_t i, char *out) { + if (!i) { + *(uint16_t *)out = (uint16_t)'0'; + return; + } + bool zero = false; + for (uint32_t m = 1000000000; m; m /= 10) { + uint8_t d = (i / m) % 10; + if (zero) + *(out++) = d + '0'; + else if (d) { + zero = true; + *(out++) = d + '0'; + } + } + *out = '\0'; }
\ No newline at end of file diff --git a/src/user/meminfo/meminfo.c b/src/user/meminfo/meminfo.c new file mode 100644 index 0000000..dd1d371 --- /dev/null +++ b/src/user/meminfo/meminfo.c @@ -0,0 +1,19 @@ +#include <pland/syscall.h> +#include <knob/user.h> +#include <knob/format.h> + +void main() { + char nbuf[11]; + + tell_user_sz("Kernel dynamic memory remaining: "); + + itosz(_kernel_dynamic_area_left() * 4, nbuf); + tell_user_sz(nbuf); + tell_user_sz("k\n"); + + tell_user_sz("Userspace memory remaining: "); + + itosz(_total_userspace_left() * 4, nbuf); + tell_user_sz(nbuf); + tell_user_sz("k\n"); +}
\ No newline at end of file |