aboutsummaryrefslogtreecommitdiff
path: root/kernel/drivers/fb.c
diff options
context:
space:
mode:
authorMarvin Borner2021-03-14 16:12:44 +0100
committerGitHub2021-03-14 16:12:44 +0100
commit268f3ccdb90ab4b9bd70ca176478797aae97ca05 (patch)
tree2dbc3e52d90dab4aae8021773f09b6b72a74b8cb /kernel/drivers/fb.c
parent4309322f9d2b3e31421a3cc5399ab1f4368e0652 (diff)
parent6dec7db5158447b66f31a3f786ce2916cab83cec (diff)
Added memory management using paging
This was quite a roller-coaster and most things are slower now, but it works and is way more secure. I still need to implement things like shared memory for the WM/GUI system but other than that everything is supported.
Diffstat (limited to 'kernel/drivers/fb.c')
-rw-r--r--kernel/drivers/fb.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/kernel/drivers/fb.c b/kernel/drivers/fb.c
new file mode 100644
index 0000000..8e73f5b
--- /dev/null
+++ b/kernel/drivers/fb.c
@@ -0,0 +1,64 @@
+// MIT License, Copyright (c) 2021 Marvin Borner
+
+#include <assert.h>
+#include <def.h>
+#include <fb.h>
+#include <fs.h>
+#include <ioctl.h>
+#include <mem.h>
+#include <mm.h>
+#include <str.h>
+#include <sys.h>
+
+struct vbe_basic {
+ u8 stuff1[16];
+ u16 pitch;
+ u16 width;
+ u16 height;
+ u8 stuff2[18];
+ u8 *fb;
+ u8 stuff3[212];
+};
+
+static u32 dev_id = 0;
+static struct vid_info *info = NULL;
+
+static s32 fb_ioctl(u32 request, void *arg1, void *arg2, void *arg3, struct device *dev)
+{
+ UNUSED(arg2);
+ UNUSED(arg3);
+ UNUSED(dev);
+
+ switch (request) {
+ case IO_FB_GET: {
+ if (!info)
+ return -1;
+ struct vbe_basic *vbe = (struct vbe_basic *)info->vbe;
+ memcpy(arg1, info->vbe, sizeof(struct vbe_basic));
+ u32 size = vbe->height * vbe->pitch;
+ memory_map_identity(proc_current()->page_dir,
+ memory_range_around((u32)vbe->fb, size), MEMORY_USER);
+ return 0;
+ }
+ default:
+ return -1;
+ }
+}
+
+static u8 fb_ready(void)
+{
+ return 1;
+}
+
+void fb_install(struct vid_info *boot)
+{
+ info = boot;
+
+ struct device *dev = zalloc(sizeof(*dev));
+ dev->name = strdup("fb");
+ dev->type = DEV_CHAR;
+ dev->ioctl = fb_ioctl;
+ dev->ready = fb_ready;
+ device_add(dev);
+ dev_id = dev->id;
+}