From 4130562b1555cabe441efe9420cebe12e7ed8d39 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sat, 13 Jan 2024 16:43:49 -0500 Subject: application loading --- kernel/syscall.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 kernel/syscall.cpp (limited to 'kernel/syscall.cpp') diff --git a/kernel/syscall.cpp b/kernel/syscall.cpp new file mode 100644 index 0000000..e91d12d --- /dev/null +++ b/kernel/syscall.cpp @@ -0,0 +1,46 @@ +#include +#include +#include + +using namespace mercury::kernel; + +extern "C" uint32_t syscall_encode_color(uint32_t c) { + return (uint32_t)framebuffer::encode_color( + c & 0xff, (c >> 8) & 0xff, (c >> 16) & 0xff + ); +} + +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); + } + 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); +} + +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]; + } +} -- cgit v1.2.3