summaryrefslogtreecommitdiff
path: root/kernel/framebuffer.cpp
diff options
context:
space:
mode:
authorBenji Dial <benji@benjidial.net>2024-01-15 15:44:20 -0500
committerBenji Dial <benji@benjidial.net>2024-01-15 15:44:20 -0500
commitc9a1266d219a83882735a3a8304f3824e0219cdb (patch)
treefea71a0b5b0de8f3a8962dc6ed417273f231e2a9 /kernel/framebuffer.cpp
parent7c6a18d77a81f232ad2e1d3a311bb21ea8f1f5b4 (diff)
downloadhilbert-os-c9a1266d219a83882735a3a8304f3824e0219cdb.tar.gz
redo application paging and system calls, rename mercury to hilbert
Diffstat (limited to 'kernel/framebuffer.cpp')
-rw-r--r--kernel/framebuffer.cpp52
1 files changed, 46 insertions, 6 deletions
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 <mercury/kernel/framebuffer.hpp>
+#include <hilbert/kernel/application.hpp>
+#include <hilbert/kernel/framebuffer.hpp>
+#include <hilbert/kernel/syscall.hpp>
-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) {