diff options
author | Benji Dial <benji@benjidial.net> | 2024-01-15 15:44:20 -0500 |
---|---|---|
committer | Benji Dial <benji@benjidial.net> | 2024-01-15 15:44:20 -0500 |
commit | c9a1266d219a83882735a3a8304f3824e0219cdb (patch) | |
tree | fea71a0b5b0de8f3a8962dc6ed417273f231e2a9 /kernel/syscall.cpp | |
parent | 7c6a18d77a81f232ad2e1d3a311bb21ea8f1f5b4 (diff) | |
download | hilbert-os-c9a1266d219a83882735a3a8304f3824e0219cdb.tar.gz |
redo application paging and system calls, rename mercury to hilbert
Diffstat (limited to 'kernel/syscall.cpp')
-rw-r--r-- | kernel/syscall.cpp | 62 |
1 files changed, 26 insertions, 36 deletions
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 <mercury/kernel/application.hpp> -#include <mercury/kernel/framebuffer.hpp> -#include <mercury/kernel/paging.hpp> +#include <hilbert/kernel/application.hpp> +#include <hilbert/kernel/framebuffer.hpp> +#include <hilbert/kernel/syscall.hpp> +#include <hilbert/kernel/paging.hpp> -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; } + } |