From 51016670a24092b6b9ecd0f50d1aaa976e780cc1 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Tue, 4 May 2021 23:06:50 +0200 Subject: General fixes (see description) - closes #17 Somehow the Grub conversion (or anything before/between that) seems to have caused a *very* weird memory bug involving the heap/stack/sth overflowing into the video memory which will obviously result in strange undefined behaviour when data is written to the video memory. VERY STRANGE. Well, I need to prepare for my finals (Abitur) so I don't know whether I can fix this issue in the next few days. We'll see... --- kernel/drivers/fb.c | 14 ++++++-------- kernel/features/mm.c | 1 + kernel/inc/proc.h | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) (limited to 'kernel') diff --git a/kernel/drivers/fb.c b/kernel/drivers/fb.c index 8831a52..8122654 100644 --- a/kernel/drivers/fb.c +++ b/kernel/drivers/fb.c @@ -12,6 +12,8 @@ #include #include +#define FB_SIZE (vbe->height * vbe->pitch) + struct vbe_basic { u8 stuff1[16]; u16 pitch; @@ -27,8 +29,7 @@ PROTECTED static struct vbe_basic *vbe = NULL; static u32 fb_map_buffer(struct page_dir *dir) { assert(vbe); - u32 size = vbe->height * vbe->pitch; - return virtual_alloc(dir, memory_range_around((u32)vbe->fb, size), MEMORY_USER).base; + return virtual_alloc(dir, memory_range_around((u32)vbe->fb, FB_SIZE), MEMORY_USER).base; } static u32 fb_owner = 0; @@ -48,8 +49,7 @@ static res fb_ioctl(u32 request, void *arg1, void *arg2, void *arg3) if (fb_owner != 0 && proc_from_pid(fb_owner)) return -EBUSY; - else - fb_owner = proc_current()->pid; + fb_owner = proc_current()->pid; u32 fb = fb_map_buffer(proc_current()->page_dir); vbe->fb = (u8 *)fb; @@ -69,8 +69,6 @@ CLEAR void fb_install(void) dev->control = fb_ioctl; io_add(IO_FRAMEBUFFER, dev); - // Identity map framebuffer to kernel to prevent unwanted writing - u32 size = vbe->height * vbe->pitch; - memory_map_identity(virtual_kernel_dir(), memory_range_around((u32)vbe->fb, size), - MEMORY_CLEAR); + // Set framebuffer range used to prevent unwanted writing + physical_set_used(memory_range_around((u32)vbe->fb, FB_SIZE)); } diff --git a/kernel/features/mm.c b/kernel/features/mm.c index e60e2b5..7a39b33 100644 --- a/kernel/features/mm.c +++ b/kernel/features/mm.c @@ -136,6 +136,7 @@ static void physical_page_set_free(u32 address) CLEAR void physical_set_total(u32 total) { + assert(total > 0); memory_total = total; } diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h index 000d77d..242a8d4 100644 --- a/kernel/inc/proc.h +++ b/kernel/inc/proc.h @@ -10,7 +10,7 @@ #include #define PROC_QUANTUM 42 // Milliseconds or something // TODO -#define PROC_STACK_SIZE (1 << 20) // 1MiB +#define PROC_STACK_SIZE 0x4000 // 16KiB #define EFLAGS_ALWAYS 0x2 // Always one #define EFLAGS_INTERRUPTS 0x200 // Enable interrupts -- cgit v1.2.3