From 298aaf63f15350e6248d5a96e8c6a63b0ec93e0f Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 20 May 2021 20:41:24 +0200 Subject: Major restructuring --- kernel/drivers/acpi.c | 4 +-- kernel/drivers/cpu.c | 2 +- kernel/drivers/fb.c | 79 ------------------------------------------- kernel/drivers/gdt.c | 2 +- kernel/drivers/ide.c | 8 ++--- kernel/drivers/interrupts.c | 6 ++-- kernel/drivers/mbr.c | 4 +-- kernel/drivers/pci.c | 4 +-- kernel/drivers/ps2/keyboard.c | 6 ++-- kernel/drivers/ps2/mouse.c | 6 ++-- kernel/drivers/ps2/ps2.c | 4 +-- kernel/drivers/rtc.c | 6 ++-- kernel/drivers/rtl8139.c | 8 ++--- kernel/drivers/serial.c | 4 +-- kernel/drivers/timer.c | 8 ++--- kernel/drivers/vbe.c | 79 +++++++++++++++++++++++++++++++++++++++++++ kernel/drivers/vmware.c | 6 ++-- 17 files changed, 118 insertions(+), 118 deletions(-) delete mode 100644 kernel/drivers/fb.c create mode 100644 kernel/drivers/vbe.c (limited to 'kernel/drivers') diff --git a/kernel/drivers/acpi.c b/kernel/drivers/acpi.c index b8dad22..6860a43 100644 --- a/kernel/drivers/acpi.c +++ b/kernel/drivers/acpi.c @@ -1,8 +1,8 @@ // MIT License, Copyright (c) 2020 Marvin Borner -#include +#include #include -#include +#include #include #include #include diff --git a/kernel/drivers/cpu.c b/kernel/drivers/cpu.c index 296e73a..8927d1d 100644 --- a/kernel/drivers/cpu.c +++ b/kernel/drivers/cpu.c @@ -2,7 +2,7 @@ // This file is a wrapper around some CPU asm calls #include -#include +#include #include #include #include diff --git a/kernel/drivers/fb.c b/kernel/drivers/fb.c deleted file mode 100644 index 7ef1088..0000000 --- a/kernel/drivers/fb.c +++ /dev/null @@ -1,79 +0,0 @@ -// MIT License, Copyright (c) 2021 Marvin Borner - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define FB_SIZE (vbe->height * vbe->pitch) - -struct vbe_basic { - u8 stuff1[16]; - u16 pitch; - u16 width; - u16 height; - u8 stuff2[18]; - u8 *fb; - u8 stuff3[212]; -}; - -PROTECTED static struct vbe_basic *vbe = NULL; - -static u32 fb_map_buffer(struct page_dir *dir) -{ - assert(vbe); - struct memory_range r = - virtual_alloc(dir, memory_range_around((u32)vbe->fb, FB_SIZE), MEMORY_USER); - return r.base; -} - -static u32 fb_owner = 0; -static res fb_ioctl(u32 request, void *arg1, void *arg2, void *arg3) -{ - UNUSED(arg3); - - switch (request) { - case IOCTL_FB_GET: { - if (!vbe) - return -ENOENT; - - 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)) - return -EBUSY; - fb_owner = proc_current()->pid; - - u32 fb = fb_map_buffer(proc_current()->page_dir); - - stac(); - memcpy(arg1, vbe, size); - ((struct vbe_basic *)arg1)->fb = (u8 *)fb; - clac(); - - return EOK; - } - default: - return -EINVAL; - } -} - -CLEAR void fb_install(void) -{ - vbe = (void *)multiboot_vbe(); - - struct io_dev *dev = zalloc(sizeof(*dev)); - dev->control = fb_ioctl; - io_add(IO_FRAMEBUFFER, dev); - - // Set framebuffer range used to prevent unwanted writing - physical_set_used(memory_range_around((u32)vbe->fb, FB_SIZE)); -} diff --git a/kernel/drivers/gdt.c b/kernel/drivers/gdt.c index 0e8086f..aa76f2f 100644 --- a/kernel/drivers/gdt.c +++ b/kernel/drivers/gdt.c @@ -2,7 +2,7 @@ #include #include -#include +#include #include #define GDT_MAX_LIMIT 0xffff diff --git a/kernel/drivers/ide.c b/kernel/drivers/ide.c index ea02d9d..9e09860 100644 --- a/kernel/drivers/ide.c +++ b/kernel/drivers/ide.c @@ -1,13 +1,13 @@ // MIT License, Copyright (c) 2020 Marvin Borner #include -#include +#include #include #include -#include -#include +#include +#include #include -#include +#include #include #include diff --git a/kernel/drivers/interrupts.c b/kernel/drivers/interrupts.c index 5b57e56..e9ab0ce 100644 --- a/kernel/drivers/interrupts.c +++ b/kernel/drivers/interrupts.c @@ -2,14 +2,14 @@ // TODO: Remove some magic numbers #include -#include +#include #include -#include +#include #include #include #include #include -#include +#include /** * IDT diff --git a/kernel/drivers/mbr.c b/kernel/drivers/mbr.c index c85061d..c9eba15 100644 --- a/kernel/drivers/mbr.c +++ b/kernel/drivers/mbr.c @@ -2,8 +2,8 @@ #include #include -#include -#include +#include +#include #include #include #include diff --git a/kernel/drivers/pci.c b/kernel/drivers/pci.c index 829f5b9..55806c2 100644 --- a/kernel/drivers/pci.c +++ b/kernel/drivers/pci.c @@ -2,10 +2,10 @@ // Uses parts of the ToAruOS Project, released under the terms of the NCSA // Copyright (C) 2011-2018 K. Lange -#include +#include #include #include -#include +#include CLEAR void pci_write_field(u32 device, int field, u32 value) { diff --git a/kernel/drivers/ps2/keyboard.c b/kernel/drivers/ps2/keyboard.c index be057d7..bddb280 100644 --- a/kernel/drivers/ps2/keyboard.c +++ b/kernel/drivers/ps2/keyboard.c @@ -1,14 +1,14 @@ // MIT License, Copyright (c) 2020 Marvin Borner -#include +#include #include #include -#include +#include #include #include #include #include -#include +#include #include #include #include diff --git a/kernel/drivers/ps2/mouse.c b/kernel/drivers/ps2/mouse.c index abca0a8..2942e34 100644 --- a/kernel/drivers/ps2/mouse.c +++ b/kernel/drivers/ps2/mouse.c @@ -1,14 +1,14 @@ // MIT License, Copyright (c) 2020 Marvin Borner #include -#include +#include #include -#include +#include #include #include #include #include -#include +#include #include #include #include diff --git a/kernel/drivers/ps2/ps2.c b/kernel/drivers/ps2/ps2.c index 076a0bf..f8d849b 100644 --- a/kernel/drivers/ps2/ps2.c +++ b/kernel/drivers/ps2/ps2.c @@ -1,10 +1,10 @@ // MIT License, Copyright (c) 2021 Marvin Borner #include -#include +#include #include #include -#include +#include #define PS2_TIMEOUT 100 diff --git a/kernel/drivers/rtc.c b/kernel/drivers/rtc.c index 2da61da..63d9461 100644 --- a/kernel/drivers/rtc.c +++ b/kernel/drivers/rtc.c @@ -1,12 +1,12 @@ // MIT License, Copyright (c) 2021 Marvin Borner -#include +#include #include #include #include -#include +#include #include -#include +#include static u8 rtc_busy(void) { diff --git a/kernel/drivers/rtl8139.c b/kernel/drivers/rtl8139.c index 753bd6a..fdbc0c8 100644 --- a/kernel/drivers/rtl8139.c +++ b/kernel/drivers/rtl8139.c @@ -2,14 +2,14 @@ // Uses parts of the ToAruOS Project, released under the terms of the NCSA // Copyright (C) 2011-2018 K. Lange -#include +#include #include -#include +#include #include #include -#include +#include #include -#include +#include static int rtl_irq = 0; static u8 mac[6] = { 0 }; diff --git a/kernel/drivers/serial.c b/kernel/drivers/serial.c index 06403f6..95ac02d 100644 --- a/kernel/drivers/serial.c +++ b/kernel/drivers/serial.c @@ -1,9 +1,9 @@ // MIT License, Copyright (c) 2020 Marvin Borner #include -#include +#include #include -#include +#include #include #define PORT 0x3f8 diff --git a/kernel/drivers/timer.c b/kernel/drivers/timer.c index 176b499..c586088 100644 --- a/kernel/drivers/timer.c +++ b/kernel/drivers/timer.c @@ -1,13 +1,13 @@ // MIT License, Copyright (c) 2020 Marvin Borner -#include +#include #include -#include +#include #include #include #include -#include -#include +#include +#include static u32 timer_ticks = 0; PROTECTED static u8 call_scheduler = 0; diff --git a/kernel/drivers/vbe.c b/kernel/drivers/vbe.c new file mode 100644 index 0000000..b384936 --- /dev/null +++ b/kernel/drivers/vbe.c @@ -0,0 +1,79 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define FB_SIZE (vbe->height * vbe->pitch) + +struct vbe_basic { + u8 stuff1[16]; + u16 pitch; + u16 width; + u16 height; + u8 stuff2[18]; + u8 *fb; + u8 stuff3[212]; +}; + +PROTECTED static struct vbe_basic *vbe = NULL; + +static u32 vbe_map_buffer(struct page_dir *dir) +{ + assert(vbe); + struct memory_range r = + virtual_alloc(dir, memory_range_around((u32)vbe->fb, FB_SIZE), MEMORY_USER); + return r.base; +} + +static u32 fb_owner = 0; +static res vbe_control(u32 request, void *arg1, void *arg2, void *arg3) +{ + UNUSED(arg3); + + switch (request) { + case IOCTL_FB_GET: { + if (!vbe) + return -ENOENT; + + 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)) + return -EBUSY; + fb_owner = proc_current()->pid; + + u32 fb = vbe_map_buffer(proc_current()->page_dir); + + stac(); + memcpy(arg1, vbe, size); + ((struct vbe_basic *)arg1)->fb = (u8 *)fb; + clac(); + + return EOK; + } + default: + return -EINVAL; + } +} + +CLEAR void vbe_install(u32 data) +{ + vbe = (void *)data; + + struct io_dev *dev = zalloc(sizeof(*dev)); + dev->control = vbe_control; + io_add(IO_FRAMEBUFFER, dev); + + // Set framebuffer range used to prevent unwanted writing + physical_set_used(memory_range_around((u32)vbe->fb, FB_SIZE)); +} diff --git a/kernel/drivers/vmware.c b/kernel/drivers/vmware.c index c82042f..6f95d02 100644 --- a/kernel/drivers/vmware.c +++ b/kernel/drivers/vmware.c @@ -2,13 +2,13 @@ // VMWare extensions/backdoors for better VM integration #include -#include +#include #include #include #include -#include +#include #include -#include +#include #define VMWARE_CMD_VERSION 0x0a -- cgit v1.2.3