From c9a1266d219a83882735a3a8304f3824e0219cdb Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Mon, 15 Jan 2024 15:44:20 -0500 Subject: redo application paging and system calls, rename mercury to hilbert --- kernel/allocator.cpp | 6 +- kernel/application.cpp | 216 +++++++++++++++++++++---------------------- kernel/entry.cpp | 22 ++--- kernel/framebuffer.cpp | 52 +++++++++-- kernel/interrupts.cpp | 4 +- kernel/paging.cpp | 37 ++------ kernel/storage.cpp | 4 +- kernel/storage/bd/memory.cpp | 4 +- kernel/storage/fs/tarfs.cpp | 4 +- kernel/syscall.asm | 70 ++++---------- kernel/syscall.cpp | 62 ++++++------- kernel/terminal.cpp | 6 +- kernel/utility.cpp | 4 +- kernel/vfile.cpp | 4 +- 14 files changed, 236 insertions(+), 259 deletions(-) (limited to 'kernel') diff --git a/kernel/allocator.cpp b/kernel/allocator.cpp index b04078c..807bc94 100644 --- a/kernel/allocator.cpp +++ b/kernel/allocator.cpp @@ -1,7 +1,7 @@ -#include +#include #include -namespace mercury::kernel::allocator { +namespace hilbert::kernel::allocator { struct free_entry { uint64_t start; @@ -118,7 +118,7 @@ namespace mercury::kernel::allocator { } -using namespace mercury::kernel::allocator; +using namespace hilbert::kernel::allocator; void *_new(size_t len) { if (len == 0) diff --git a/kernel/application.cpp b/kernel/application.cpp index 19b1dbc..ed8795b 100644 --- a/kernel/application.cpp +++ b/kernel/application.cpp @@ -1,83 +1,87 @@ -#include -#include +#include +#include //TODO - scheduling. -namespace mercury::kernel::application { +namespace hilbert::kernel::application { - app_instance::app_instance() : state(app_state::paused) { + app_instance::app_instance() + : state(app_state::paused), framebuffer_vaddr(0) { - framebuffer_vaddr = 0; + uint64_t p4_vaddr; + paging::map_new_kernel_page(p4_vaddr, p4_paddr); + p4 = (uint64_t *)p4_vaddr; uint64_t p3_paddr; - uint64_t p2_paddr; - - uint64_t p4_vaddr; uint64_t p3_vaddr; - uint64_t p2_vaddr; - - paging::map_new_kernel_page(p4_vaddr, p4_paddr); paging::map_new_kernel_page(p3_vaddr, p3_paddr); - paging::map_new_kernel_page(p2_vaddr, p2_paddr); - - p4 = (uint64_t *)p4_vaddr; p3 = (uint64_t *)p3_vaddr; - p2 = (uint64_t *)p2_vaddr; for (int i = 1; i < 511; ++i) p4[i] = 0; + p4[0] = paging::encode_pte(p3_paddr, true, true, true); p4[511] = paging::kernel_p4e; - p4[0] = paging::encode_pte(p3_paddr, true, true, true, false); - for (int i = 1; i < 512; ++i) + for (int i = 0; i < 512; ++i) { p3[i] = 0; - p3[0] = paging::encode_pte(p2_paddr, true, true, true, false); - - for (int i = 0; i < 512; ++i) - p2[i] = 0; - - p2es_to_free_on_exit = new bool[512]; + p2s[i] = 0; + p1s[i] = 0; + p1es_to_free_on_exit[i] = 0; + } } - app_instance::~app_instance() { + void app_instance::map_page(uint64_t vaddr, uint64_t paddr, + bool write, bool execute, bool free_pram_on_exit + ) { - for (int i = 1; i < 512; ++i) - if (p2[i] != 0 && p2es_to_free_on_exit[i]) { - uint64_t paddr = p2[i] & ~0x1fffffULL; - paging::mark_pram_region_free(paddr, paddr + 0x200000); + uint64_t i = ((vaddr / 4096) / 512) / 512; + uint64_t j = ((vaddr / 4096) / 512) % 512; + uint64_t k = (vaddr / 4096) % 512; + + if (p2s[i] == 0) { + uint64_t p2_paddr; + uint64_t p2_vaddr; + paging::map_new_kernel_page(p2_vaddr, p2_paddr); + p3[i] = paging::encode_pte(p2_paddr, true, true, true); + p2s[i] = (uint64_t *)p2_vaddr; + p1s[i] = new uint64_t *[512]; + p1es_to_free_on_exit[i] = new bool *[512]; + for (int u = 0; u < 512; ++u) { + p2s[i][u] = 0; + p1s[i][u] = 0; + p1es_to_free_on_exit[i][u] = 0; } + } - delete[] p2es_to_free_on_exit; - - uint64_t p2_paddr = p3[0] & ~0x1fffffULL; - paging::unmap_kernel_page((uint64_t)p2); - paging::mark_pram_region_free(p2_paddr, p2_paddr + 4096); - - uint64_t p3_paddr = p4[0] & ~0x1fffffULL; - paging::unmap_kernel_page((uint64_t)p3); - paging::mark_pram_region_free(p3_paddr, p3_paddr + 4096); - - paging::unmap_kernel_page((uint64_t)p4); - paging::mark_pram_region_free(p4_paddr, p4_paddr + 4096); + if (p2s[i][j] == 0) { + uint64_t p1_paddr; + uint64_t p1_vaddr; + paging::map_new_kernel_page(p1_vaddr, p1_paddr); + p2s[i][j] = paging::encode_pte(p1_paddr, true, true, true); + p1s[i][j] = (uint64_t *)p1_vaddr; + p1es_to_free_on_exit[i][j] = new bool[512]; + for (int u = 0; u < 512; ++u) { + p1s[i][j][u] = 0; + p1es_to_free_on_exit[i][j][u] = false; + } + } - } + p1s[i][j][k] = paging::encode_pte(paddr, true, write, execute); + p1es_to_free_on_exit[i][j][k] = free_pram_on_exit; - void app_instance::map_page(uint64_t vaddr, uint64_t paddr, - bool write, bool execute, bool free_pram_on_exit - ) { - uint64_t i = vaddr / 0x200000; - p2[i] = paging::encode_pte(paddr, true, write, execute, true); - p2es_to_free_on_exit[i] = free_pram_on_exit; } uint64_t app_instance::get_free_vaddr_pages(uint64_t count) { - uint64_t start = 1; + uint64_t start = 0x200000 / 4096; uint64_t length = 0; - while (start + length < 510) { + while (start + length <= 0x8000000000 / 4096) { if (length == count) - return start * 0x200000; - if (p2[start + length] == 0) + return start * 4096; + int i = ((start + length) / 512) / 512; + int j = ((start + length) / 512) % 512; + int k = (start + length) % 512; + if (p1s[i] == 0 || p1s[i][j] == 0 || p1s[i][j][k] == 0) ++length; else { start += length + 1; @@ -88,28 +92,15 @@ namespace mercury::kernel::application { return 0; } - void app_instance::create_stack() { - uint64_t stack_paddr = paging::take_2mib_pram_page(); - map_page(0x3fe00000, stack_paddr, true, false, true); - for (int i = 0; i < 512; ++i) { - uint64_t vaddr = paging::find_unmapped_vram_region(1); - paging::map_kernel_page(stack_paddr + 512 * i, vaddr, true, false); - for (int j = 0; j < 4096 / 8; ++j) - *(uint64_t *)(vaddr + j * 8) = 0; - paging::unmap_kernel_page(vaddr); - } - saved_regs.rsp = 0x40000000; - } - - void app_instance::set_instruction_pointer(uint64_t vaddr) { - saved_regs.rip = vaddr; - } - uint64_t app_instance::count_mapped_vram_pages() { uint64_t count = 0; - for (int i = 1; i < 512; ++i) - if (p2[i] != 0) - ++count; + for (int i = 0; i < 512; ++i) + if (p1s[i] != 0) + for (int j = 0; j < 512; ++j) + if (p1s[i][j] != 0) + for (int k = 0; k < 512; ++k) + if (p1s[i][j][k] != 0) + ++count; return count; } @@ -186,18 +177,19 @@ namespace mercury::kernel::application { READ(entry_start + 40, 8, &vsize) READ(entry_start + 4, 4, &flags) - if (vaddr & 0x1fffff) + if (vaddr & 4095) return create_app_result::app_corrupt; if (file.dir_entry.length < foffset + fsize) return create_app_result::app_corrupt; if (fsize > vsize) return create_app_result::app_corrupt; - if (vaddr == 0) + + if (vaddr < 0x200000) return create_app_result::app_corrupt; - uint64_t vpages = (vsize - 1) / 0x200000 + 1; + uint64_t vpages = (vsize - 1) / 4096 + 1; - if (vaddr + vpages * 0x200000 > ((1 << 30) - (4 << 20))) + if (vaddr + vpages * 4096 > 0x8000000000) return create_app_result::app_corrupt; load_info info = { @@ -217,47 +209,55 @@ namespace mercury::kernel::application { for (unsigned i = 0; i < load_infos.count; ++i) { const auto &info = load_infos.buffer[i]; for (uint64_t j = 0; j < info.vpages; ++j) { - uint64_t paddr = paging::take_2mib_pram_page(); - out->map_page(info.vaddr + j * 0x200000, paddr, + uint64_t paddr = paging::take_pram_page(); + out->map_page(info.vaddr + j * 4096, paddr, info.writable, info.executable, true); - for (int k = 0; k < 512; ++k) { - uint64_t offset_in_segment = j * 0x200000 + k * 4096; - uint64_t kvaddr = paging::find_unmapped_vram_region(1); - paging::map_kernel_page(paddr + k * 4096, kvaddr, true, false); - storage::fs_result result = storage::fs_result::success; - if (info.fsize > offset_in_segment) { - if (info.fsize >= offset_in_segment + 4096) - result = file.read_file( - info.foffset + offset_in_segment, 4096, (void *)kvaddr); - else { - int to_read = info.fsize - offset_in_segment; - result = file.read_file( - info.foffset + offset_in_segment, to_read, (void *)kvaddr); - uint8_t *blank = (uint8_t *)(kvaddr + to_read); - for (int i = 0; i < 4096 - to_read; ++i) - blank[i] = 0; - } - } + uint64_t kvaddr = paging::find_unmapped_vram_region(1); + paging::map_kernel_page(paddr, kvaddr, true, false); + storage::fs_result result = storage::fs_result::success; + if (info.fsize > j * 4096) { + if (info.fsize >= j * 4096 + 4096) + result = file.read_file( + info.foffset + j * 4096, 4096, (void *)kvaddr); else { - uint8_t *blank = (uint8_t *)kvaddr; - for (int i = 0; i < 4096; ++i) + int to_read = info.fsize - j * 4096; + result = file.read_file( + info.foffset + j * 4096, to_read, (void *)kvaddr); + uint8_t *blank = (uint8_t *)(kvaddr + to_read); + for (int i = 0; i < 4096 - to_read; ++i) blank[i] = 0; } - paging::unmap_kernel_page(kvaddr); - if (result == storage::fs_result::device_error) { - delete out; - return create_app_result::device_error; - } - if (result == storage::fs_result::fs_corrupt) { - delete out; - return create_app_result::fs_corrupt; - } + } + else { + uint8_t *blank = (uint8_t *)kvaddr; + for (int i = 0; i < 4096; ++i) + blank[i] = 0; + } + paging::unmap_kernel_page(kvaddr); + if (result == storage::fs_result::device_error) { + delete out; + return create_app_result::device_error; + } + if (result == storage::fs_result::fs_corrupt) { + delete out; + return create_app_result::fs_corrupt; } } } - out->create_stack(); - out->set_instruction_pointer(entry_point); + for (uint64_t vaddr = 0x1000; vaddr < 0x1ff000; vaddr += 4096) { + uint64_t paddr = paging::take_pram_page(); + uint64_t kvaddr = paging::find_unmapped_vram_region(1); + paging::map_kernel_page(paddr, kvaddr, true, false); + uint8_t *p = (uint8_t *)kvaddr; + for (int i = 0; i < 4096; ++i) + p[i] = 0; + paging::unmap_kernel_page(kvaddr); + out->map_page(vaddr, paddr, true, false, true); + } + + out->saved_regs.rsp = 0x1ff000; + out->saved_regs.rip = entry_point; return create_app_result::success; diff --git a/kernel/entry.cpp b/kernel/entry.cpp index cce8066..8ba585f 100644 --- a/kernel/entry.cpp +++ b/kernel/entry.cpp @@ -1,13 +1,13 @@ -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include -using namespace mercury::kernel; +using namespace hilbert::kernel; LIMINE_BASE_REVISION(1) @@ -173,8 +173,8 @@ extern "C" [[noreturn]] void entry() { //set up framebuffer and terminal: //TODO: assumes framebuffer is 32-bpp rgb - framebuffer::init_framebuffer( - fb_vaddr, framebuffer->width, framebuffer->height, framebuffer->pitch); + framebuffer::init_framebuffer(fb_start, fb_vaddr, + framebuffer->width, framebuffer->height, framebuffer->pitch); //switch to kernel p4 diff --git a/kernel/framebuffer.cpp b/kernel/framebuffer.cpp index a115e0b..dbd735f 100644 --- a/kernel/framebuffer.cpp +++ b/kernel/framebuffer.cpp @@ -1,20 +1,60 @@ -#include +#include +#include +#include -namespace mercury::kernel::framebuffer { +namespace hilbert::kernel::framebuffer { - uint32_t *vaddr; + static uint64_t paddr; + static uint32_t *vaddr; int width; int height; - int dword_pitch; + static int dword_pitch; - void init_framebuffer( - uint64_t vaddr, uint64_t width, uint64_t height, uint64_t pitch + void encode_color_syscall( + uint64_t &rax, uint64_t &rdi, uint64_t &rsi, uint64_t &rdx ) { + rax = (uint64_t)encode_color( + rdi & 0xff, (rdi >> 8) & 0xff, (rdi >> 16) & 0xff); + rdi = 0; + rsi = 0; + rdx = 0; + } + + void get_framebuffer_syscall( + uint64_t &rax, uint64_t &rdi, uint64_t &rsi, uint64_t &rdx + ) { + + auto *app = application::running_app; + if (app->framebuffer_vaddr == 0) { + uint64_t pages_needed = (dword_pitch * height * 4 - 1) / 4096 + 1; + uint64_t vaddr = app->get_free_vaddr_pages(pages_needed); + for (uint64_t i = 0; i < pages_needed; ++i) + app->map_page(vaddr + i * 4096, paddr + i * 4096, true, false, false); + app->framebuffer_vaddr = vaddr; + } + + rax = app->framebuffer_vaddr; + rdi = (uint64_t)(uint32_t)width | ((uint64_t)(uint32_t)height << 32); + rsi = (uint32_t)dword_pitch; + rdx = 0; + + } + + void init_framebuffer(uint64_t paddr, uint64_t vaddr, + uint64_t width, uint64_t height, uint64_t pitch + ) { + //TODO: assumes 32-bpp rgb + + framebuffer::paddr = paddr; framebuffer::vaddr = (uint32_t *)vaddr; framebuffer::width = width; framebuffer::height = height; dword_pitch = pitch / 4; + + syscall::add_syscall(0, &encode_color_syscall); + syscall::add_syscall(1, &get_framebuffer_syscall); + } color encode_color(uint8_t r, uint8_t g, uint8_t b) { diff --git a/kernel/interrupts.cpp b/kernel/interrupts.cpp index 8ac986d..1a95f22 100644 --- a/kernel/interrupts.cpp +++ b/kernel/interrupts.cpp @@ -1,6 +1,6 @@ -#include +#include -using namespace mercury::kernel; +using namespace hilbert::kernel; struct [[gnu::packed]] exception_info_t { diff --git a/kernel/paging.cpp b/kernel/paging.cpp index 17b61f4..d8869fc 100644 --- a/kernel/paging.cpp +++ b/kernel/paging.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include //see also ../documentation/memory.txt @@ -7,7 +7,7 @@ extern "C" { uint64_t __kernel_p4_paddr; } -namespace mercury::kernel::paging { +namespace hilbert::kernel::paging { static constexpr uint64_t kernel_vram_start = 0xffffffffc0000000; static constexpr uint64_t kernel_vram_end = 0xffffffffffe00000; @@ -38,11 +38,9 @@ namespace mercury::kernel::paging { uint64_t kernel_p4e; - uint64_t encode_pte( - uint64_t addr, bool user, bool write, bool execute, bool ps - ) { + uint64_t encode_pte(uint64_t addr, bool user, bool write, bool execute) { return (addr & 0x0000ffffffffffff) | (execute ? 0 : (1ULL << 63)) - | (ps << 7) | (user << 2) | (write << 1) | 1; + | (user << 2) | (write << 1) | 1; } void init_kernel_page_tables(uint64_t kernel_offset) { @@ -50,15 +48,15 @@ namespace mercury::kernel::paging { for (int i = 0; i < 511; ++i) kernel_p4[i] = 0; kernel_p4e = encode_pte( - (uint64_t)kernel_p3 - kernel_offset, false, true, true, false); + (uint64_t)kernel_p3 - kernel_offset, false, true, true); kernel_p4[511] = kernel_p4e; for (int i = 0; i < 511; ++i) kernel_p3[i] = 0; kernel_p3[511] = encode_pte( - (uint64_t)kernel_p2 - kernel_offset, false, true, true, false); + (uint64_t)kernel_p2 - kernel_offset, false, true, true); for (int i = 0; i < 512; ++i) kernel_p2[i] = encode_pte( - (uint64_t)kernel_p1s + 4096 * i - kernel_offset, false, true, true, false); + (uint64_t)kernel_p1s + 4096 * i - kernel_offset, false, true, true); for (int i = 0; i < 512 * 512; ++i) kernel_p1s[i] = 0; } @@ -66,7 +64,7 @@ namespace mercury::kernel::paging { void map_kernel_page( uint64_t paddr, uint64_t vaddr, bool write, bool execute) { uint64_t i = (vaddr - kernel_vram_start) / 4096; - kernel_p1s[i] = encode_pte(paddr, false, write, execute, false); + kernel_p1s[i] = encode_pte(paddr, false, write, execute); } void unmap_kernel_page(uint64_t vaddr) { @@ -77,7 +75,7 @@ namespace mercury::kernel::paging { ); } - static uint64_t take_pram_page() { + uint64_t take_pram_page() { for (uint64_t i = 0; i < pram_pages / 64; ++i) if (~pram_usage_bitmap[i] != 0) for (int j = 0; j < 64; ++j) @@ -89,21 +87,6 @@ namespace mercury::kernel::paging { return 0; } - uint64_t take_2mib_pram_page() { - for (uint64_t i = 0; i < pram_pages / 512; ++i) { - for (int j = 0; j < 8; ++j) - if (pram_usage_bitmap[i * 8 + j] != 0) - goto next_i; - for (int j = 0; j < 8; ++j) - pram_usage_bitmap[i * 8 + j] = ~0ULL; - return 0x200000 * i; - next_i: - ; - } - //TODO: handle error - return 0; - } - void map_kernel_stacks() { for (uint64_t vaddr = syscall_stack_bottom; vaddr < syscall_stack_top; vaddr += 4096) diff --git a/kernel/storage.cpp b/kernel/storage.cpp index f500f8e..b6b1a04 100644 --- a/kernel/storage.cpp +++ b/kernel/storage.cpp @@ -1,6 +1,6 @@ -#include +#include -namespace mercury::kernel::storage { +namespace hilbert::kernel::storage { bd_result block_device::load_cache_block(uint64_t i) { diff --git a/kernel/storage/bd/memory.cpp b/kernel/storage/bd/memory.cpp index 2f82099..d6a6719 100644 --- a/kernel/storage/bd/memory.cpp +++ b/kernel/storage/bd/memory.cpp @@ -1,6 +1,6 @@ -#include +#include -namespace mercury::kernel::storage::bd { +namespace hilbert::kernel::storage::bd { memory::memory(void *buffer, uint64_t buffer_len) : buffer((uint8_t *)buffer) diff --git a/kernel/storage/fs/tarfs.cpp b/kernel/storage/fs/tarfs.cpp index 4b752a2..fb1eff8 100644 --- a/kernel/storage/fs/tarfs.cpp +++ b/kernel/storage/fs/tarfs.cpp @@ -1,9 +1,9 @@ -#include +#include //in tarfs_instance, node_id_t and directory_iter_t refer to the number //of bytes into the block device that the info sector is located. -namespace mercury::kernel::storage::fs { +namespace hilbert::kernel::storage::fs { #define BD_TO_FS(expr) \ { \ diff --git a/kernel/syscall.asm b/kernel/syscall.asm index e4e0d77..c293402 100644 --- a/kernel/syscall.asm +++ b/kernel/syscall.asm @@ -4,51 +4,7 @@ global start_user_mode section .text -extern syscall_encode_color - -encode_color_syscall: - call syscall_encode_color - mov edi, eax - xor rax, rax - mov eax, edi - xor rdi, rdi - xor rsi, rsi - xor rdx, rdx - jmp syscall_return - -extern syscall_get_fb_vaddr -extern syscall_get_fb_dims -extern syscall_get_fb_pitch - -get_framebuffer_syscall: - call syscall_get_fb_vaddr - push rax - call syscall_get_fb_dims - push rax - call syscall_get_fb_pitch - xor rsi, rsi - mov esi, eax - pop rdi - pop rax - xor rdx, rdx - jmp syscall_return - -extern syscall_copy_framebuffer - -draw_framebuffer_syscall: - call syscall_copy_framebuffer - xor rax, rax - xor rdi, rdi - xor rsi, rsi - xor rdx, rdx - jmp syscall_return - -bad_syscall: - xor rax, rax - xor rdi, rdi - xor rsi, rsi - xor rdx, rdx - jmp syscall_return +extern do_syscall syscall_entry: mov r11, rsp @@ -56,15 +12,23 @@ syscall_entry: push r11 push rcx - cmp rax, 0 - je encode_color_syscall - cmp rax, 1 - je get_framebuffer_syscall - cmp rax, 2 - je draw_framebuffer_syscall - jmp bad_syscall + push rdx + push rsi + push rdi + push rax + + mov rdi, rsp + lea rsi, [rsp + 8] + lea rdx, [rsp + 16] + lea rcx, [rsp + 24] + + call do_syscall + + pop rax + pop rdi + pop rsi + pop rdx -syscall_return: xor r8, r8 xor r9, r9 xor r10, r10 diff --git a/kernel/syscall.cpp b/kernel/syscall.cpp index e91d12d..3aa4105 100644 --- a/kernel/syscall.cpp +++ b/kernel/syscall.cpp @@ -1,46 +1,36 @@ -#include -#include -#include +#include +#include +#include +#include -using namespace mercury::kernel; +namespace hilbert::kernel::syscall { -extern "C" uint32_t syscall_encode_color(uint32_t c) { - return (uint32_t)framebuffer::encode_color( - c & 0xff, (c >> 8) & 0xff, (c >> 16) & 0xff - ); -} + syscall_handler handlers[256]; -extern "C" uint64_t syscall_get_fb_vaddr() { - auto *app = application::running_app; - if (app->framebuffer_vaddr != 0) - return app->framebuffer_vaddr; - uint64_t fb_len = framebuffer::dword_pitch * framebuffer::height * 4; - uint64_t fb_pages = (fb_len - 1) / 0x200000 + 1; - uint64_t vaddr = app->get_free_vaddr_pages(fb_pages); - for (uint64_t i = 0; i < fb_pages; ++i) { - uint64_t paddr = paging::take_2mib_pram_page(); - app->map_page(vaddr + i * 0x200000, paddr, true, false, true); + void init_syscalls() { + for (int i = 0; i < 256; ++i) + handlers[i] = 0; } - app->framebuffer_vaddr = vaddr; - return vaddr; -} -extern "C" uint64_t syscall_get_fb_dims() { - return (uint64_t)(uint32_t)framebuffer::width + - ((uint64_t)(uint32_t)framebuffer::height << 32); -} + void add_syscall(uint64_t rax, syscall_handler handler) { + handlers[rax] = handler; + } -extern "C" uint32_t syscall_get_fb_pitch() { - return (uint32_t)framebuffer::dword_pitch; } -extern "C" void syscall_copy_framebuffer() { - auto *app = application::running_app; - if (app->framebuffer_vaddr != 0) { - const uint32_t *source = (const uint32_t *)app->framebuffer_vaddr; - for (int y = 0; y < framebuffer::height; ++y) - for (int x = 0; x < framebuffer::width; ++x) - framebuffer::vaddr[y * framebuffer::dword_pitch + x] - = source[y * framebuffer::dword_pitch + x]; +using namespace hilbert::kernel::syscall; + +extern "C" void do_syscall( + uint64_t &rax, uint64_t &rdi, uint64_t &rsi, uint64_t &rdx +) { + + if (rax < 256 && handlers[rax] != 0) + handlers[rax](rax, rdi, rsi, rdx); + else { + rax = 0; + rdi = 0; + rsi = 0; + rdx = 0; } + } diff --git a/kernel/terminal.cpp b/kernel/terminal.cpp index 1074fe7..167e6cf 100644 --- a/kernel/terminal.cpp +++ b/kernel/terminal.cpp @@ -1,7 +1,7 @@ -#include -#include +#include +#include -namespace mercury::kernel::terminal { +namespace hilbert::kernel::terminal { uint8_t *termfont; uint64_t termfont_len; diff --git a/kernel/utility.cpp b/kernel/utility.cpp index 865b817..249fb2c 100644 --- a/kernel/utility.cpp +++ b/kernel/utility.cpp @@ -1,6 +1,6 @@ -#include +#include -namespace mercury::kernel::utility { +namespace hilbert::kernel::utility { void mark_bitmap_region_zero( uint64_t *bitmap, uint64_t start_i, uint64_t end_i) { diff --git a/kernel/vfile.cpp b/kernel/vfile.cpp index 3b9dcb2..74cfbf9 100644 --- a/kernel/vfile.cpp +++ b/kernel/vfile.cpp @@ -1,9 +1,9 @@ -#include +#include //TODO: handle symlink loops nicely in vfile::get_child, // vfile::get_children, and lookup_path. -namespace mercury::kernel::vfile { +namespace hilbert::kernel::vfile { void canon_path::parent() { if (segments.count != 0) -- cgit v1.2.3