From 3a3d50d7eb0f4fdbb9beaf16bacfa98689cc448c Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 29 Apr 2021 23:59:48 +0200 Subject: Alright! --- kernel/drivers/fb.c | 33 ++++++++++++++++++--------------- kernel/drivers/gdt.c | 4 ++-- kernel/drivers/ps2/mouse.c | 1 - 3 files changed, 20 insertions(+), 18 deletions(-) (limited to 'kernel/drivers') diff --git a/kernel/drivers/fb.c b/kernel/drivers/fb.c index 7c02919..2a29eb7 100644 --- a/kernel/drivers/fb.c +++ b/kernel/drivers/fb.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -21,7 +22,15 @@ struct vbe_basic { u8 stuff3[212]; }; -PROTECTED static struct vid_info *info = NULL; +PROTECTED static struct vbe_basic *vbe = NULL; + +static void fb_map_buffer(struct page_dir *dir) +{ + // TODO: Return virtual mapped address + assert(vbe); + u32 size = vbe->height * vbe->pitch; + memory_map_identity(dir, memory_range_around((u32)vbe->fb, size), MEMORY_USER); +} static u32 fb_owner = 0; static res fb_ioctl(u32 request, void *arg1, void *arg2, void *arg3) @@ -31,10 +40,11 @@ static res fb_ioctl(u32 request, void *arg1, void *arg2, void *arg3) switch (request) { case IOCTL_FB_GET: { - if (!info) + if (!vbe) return -ENOENT; - if (!memory_writable_range(memory_range(arg1, sizeof(struct vbe_basic)))) + u32 size = MIN(sizeof(*vbe), (u32)arg2); + if (!memory_writable_range(memory_range(arg1, size))) return -EFAULT; if (fb_owner != 0 && proc_from_pid(fb_owner)) @@ -42,10 +52,8 @@ static res fb_ioctl(u32 request, void *arg1, void *arg2, void *arg3) else fb_owner = proc_current()->pid; - stac(); - memcpy(arg1, info->vbe, sizeof(struct vbe_basic)); - clac(); - fb_map_buffer(proc_current()->page_dir, info); + memcpy_user(arg1, vbe, size); + fb_map_buffer(proc_current()->page_dir); return EOK; } default: @@ -53,18 +61,13 @@ static res fb_ioctl(u32 request, void *arg1, void *arg2, void *arg3) } } -void fb_map_buffer(struct page_dir *dir, struct vid_info *boot) -{ - struct vbe_basic *vbe = (struct vbe_basic *)boot->vbe; - u32 size = vbe->height * vbe->pitch; - memory_map_identity(dir, memory_range_around((u32)vbe->fb, size), MEMORY_USER); -} - CLEAR void fb_install(void) { - //info = boot; + vbe = (void *)multiboot_vbe(); struct io_dev *dev = zalloc(sizeof(*dev)); dev->control = fb_ioctl; io_add(IO_FRAMEBUFFER, dev); + + fb_map_buffer(virtual_kernel_dir()); } diff --git a/kernel/drivers/gdt.c b/kernel/drivers/gdt.c index 73db111..66a9086 100644 --- a/kernel/drivers/gdt.c +++ b/kernel/drivers/gdt.c @@ -56,7 +56,7 @@ void tss_set_stack(u32 ss, u32 esp) tss.ss0 = ss; } -CLEAR void gdt_install(void) +CLEAR void gdt_install(u32 esp) { // Set GDT pointer and limit gp.limit = (sizeof(struct gdt_entry) * 6) - 1; @@ -78,7 +78,7 @@ CLEAR void gdt_install(void) gdt_set_gate(4, 0, 0xffffffff, 0xf2, 0xcf); // Write TSS - tss_write(5, GDT_SUPER_DATA_OFFSET, STACK_START); + tss_write(5, GDT_SUPER_DATA_OFFSET, esp); // Remove old GDT and install the new changes! gdt_flush(); diff --git a/kernel/drivers/ps2/mouse.c b/kernel/drivers/ps2/mouse.c index 7748c99..abca0a8 100644 --- a/kernel/drivers/ps2/mouse.c +++ b/kernel/drivers/ps2/mouse.c @@ -1,7 +1,6 @@ // MIT License, Copyright (c) 2020 Marvin Borner #include -#include #include #include #include -- cgit v1.2.3