From b8284137d4e0eec11c78bc14047243fce6a51373 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sun, 6 Sep 2020 15:47:06 -0400 Subject: minor changes, redoing makefile, meminfo program --- src/kernel/idt.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'src/kernel/idt.c') 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; -- cgit v1.2.3