46 lines
1.5 KiB
C++
46 lines
1.5 KiB
C++
#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];
|
|
}
|
|
}
|