summaryrefslogtreecommitdiff
path: root/kernel/syscall.cpp
diff options
context:
space:
mode:
authorBenji Dial <benji@benjidial.net>2024-01-13 16:43:49 -0500
committerBenji Dial <benji@benjidial.net>2024-01-13 16:43:49 -0500
commit4130562b1555cabe441efe9420cebe12e7ed8d39 (patch)
treebeaf0012373aab2c3a13fe0147a5cda4af28ef78 /kernel/syscall.cpp
parent882e74b2191c059a9226cbd8bcb51c97da36247c (diff)
downloadhilbert-os-4130562b1555cabe441efe9420cebe12e7ed8d39.tar.gz
application loading
Diffstat (limited to 'kernel/syscall.cpp')
-rw-r--r--kernel/syscall.cpp46
1 files changed, 46 insertions, 0 deletions
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 <mercury/kernel/application.hpp>
+#include <mercury/kernel/framebuffer.hpp>
+#include <mercury/kernel/paging.hpp>
+
+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];
+ }
+}