From b96c27bba0b242fc860fc9a2fcb63f121312fa7e Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sat, 20 Mar 2021 19:52:56 +0100 Subject: LGTM! --- kernel/Makefile | 2 +- kernel/drivers/fb.c | 12 ++++++++---- kernel/features/load.c | 5 ++--- kernel/features/mm.c | 26 ++++++++++++++------------ kernel/features/syscall.c | 10 ++++++---- kernel/inc/fb.h | 2 ++ kernel/inc/mm.h | 9 +++++++-- kernel/link.ld | 2 +- kernel/main.c | 2 ++ 9 files changed, 43 insertions(+), 27 deletions(-) (limited to 'kernel') diff --git a/kernel/Makefile b/kernel/Makefile index 1d9e87a..64035e5 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -36,5 +36,5 @@ all: compile compile: $(COBJS) @mkdir -p ../build/ - @$(LD) -N -z undefs -ekernel_main -Ttext 0x00050000 -o ../build/kernel.elf -L../build/ $+ -lk + @$(LD) -N -z undefs -ekernel_main -Ttext 0x00009000 -o ../build/kernel.elf -L../build/ $+ -lk @$(LD) -N -z max-page-size=0x1000 -Tlink.ld -o ../build/kernel.bin -L../build/ $+ -lk diff --git a/kernel/drivers/fb.c b/kernel/drivers/fb.c index af8a830..2db05f2 100644 --- a/kernel/drivers/fb.c +++ b/kernel/drivers/fb.c @@ -33,11 +33,8 @@ static s32 fb_ioctl(u32 request, void *arg1, void *arg2, void *arg3, struct devi 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); + fb_map_buffer(proc_current()->page_dir, info); return 0; } default: @@ -50,6 +47,13 @@ static s32 fb_ready(void) return 1; } +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); +} + void fb_install(struct vid_info *boot) { info = boot; diff --git a/kernel/features/load.c b/kernel/features/load.c index d3f3495..3430a75 100644 --- a/kernel/features/load.c +++ b/kernel/features/load.c @@ -104,9 +104,8 @@ s32 elf_load(const char *path, struct proc *proc) struct memory_range prange = physical_alloc(vrange.size); virtual_map(proc->page_dir, prange, vrange.base, MEMORY_CLEAR | MEMORY_USER); - if ((u32)vfs_read(path, (void *)program.vaddr, program.offset, program.filesz) != - program.filesz) { - print("OH NOSE!\n"); + if ((u32)vfs_read(proc->name, (void *)program.vaddr, program.offset, + program.filesz) != program.filesz) { memory_switch_dir(prev); return -ENOEXEC; } diff --git a/kernel/features/mm.c b/kernel/features/mm.c index b06657f..b804076 100644 --- a/kernel/features/mm.c +++ b/kernel/features/mm.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -15,23 +16,23 @@ static struct page_table kernel_tables[PAGE_KERNEL_COUNT] ALIGNED(PAGE_SIZE) = { * Lowlevel paging */ -/*static void paging_disable(void) +static void paging_switch_dir(u32 dir) +{ + cr3_set(dir); +} + +extern void paging_invalidate_tlb(void); + +/*void paging_disable(void) { cr0_set(cr0_get() | 0x7fffffff); }*/ -static void paging_enable(void) +void paging_enable(void) { cr0_set(cr0_get() | 0x80000000); } -static void paging_switch_dir(u32 dir) -{ - cr3_set(dir); -} - -extern void paging_invalidate_tlb(void); - void page_fault_handler(struct regs *r) { print("--- PAGE FAULT! ---\n"); @@ -415,12 +416,12 @@ void memory_backup_dir(struct page_dir **backup) static u8 memory_bypass_validity = 0; void memory_bypass_enable(void) { - memory_bypass_validity = 1; + /* memory_bypass_validity = 1; */ } void memory_bypass_disable(void) { - memory_bypass_validity = 0; + /* memory_bypass_validity = 0; */ } // TODO: Limit by proc stack and data range @@ -506,9 +507,10 @@ void memory_install(struct mem_info *mem_info, struct vid_info *vid_info) memory_map_identity(&kernel_dir, memory_range_around(STACK_START - STACK_SIZE, STACK_SIZE), MEMORY_NONE); - // Map VBE data + // Map framebuffer memory_map_identity(&kernel_dir, memory_range_around((u32)vid_info->vbe, 0x1000), MEMORY_NONE); + fb_map_buffer(virtual_kernel_dir(), vid_info); // Unmap NULL byte/page struct memory_range zero = memory_range(0, PAGE_SIZE); diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c index 2334947..7d68d93 100644 --- a/kernel/features/syscall.c +++ b/kernel/features/syscall.c @@ -73,11 +73,13 @@ static void syscall_handler(struct regs *r) char *path = (char *)r->ebx; struct proc *proc = proc_make(PROC_PRIV_NONE); r->eax = (u32)elf_load(path, proc); - if (r->eax != 0) + if (r->eax != 0) { proc_exit(proc, -r->eax); - // TODO: Reimplement argc,argv - proc_stack_push(proc, 0); - proc_yield(r); + } else { + // TODO: Reimplement argc,argv + proc_stack_push(proc, 0); + proc_yield(r); + } break; } case SYS_EXIT: { diff --git a/kernel/inc/fb.h b/kernel/inc/fb.h index 212230b..3b545fd 100644 --- a/kernel/inc/fb.h +++ b/kernel/inc/fb.h @@ -4,7 +4,9 @@ #define FB_H #include +#include +void fb_map_buffer(struct page_dir *dir, struct vid_info *boot); void fb_install(struct vid_info *boot); #endif diff --git a/kernel/inc/mm.h b/kernel/inc/mm.h index 98dcf46..5a307b2 100644 --- a/kernel/inc/mm.h +++ b/kernel/inc/mm.h @@ -12,6 +12,13 @@ struct memory_range { u32 size; }; +/** + * Lowlevel paging + */ + +void paging_enable(void); +void page_fault_handler(struct regs *r); + /** * Physical */ @@ -109,6 +116,4 @@ u8 memory_valid(const void *addr); void memory_install(struct mem_info *mem_info, struct vid_info *vid_info); -void page_fault_handler(struct regs *r); - #endif diff --git a/kernel/link.ld b/kernel/link.ld index 5a63e33..fbe8a8c 100644 --- a/kernel/link.ld +++ b/kernel/link.ld @@ -1,7 +1,7 @@ OUTPUT_FORMAT("binary") OUTPUT_ARCH(i386) ENTRY(kernel_main) -phys = 0x00050000; +phys = 0x00009000; SECTIONS { diff --git a/kernel/main.c b/kernel/main.c index 5c5299e..3ff0463 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -27,6 +27,8 @@ void kernel_main(struct mem_info *mem_info, struct vid_info *vid_info) serial_print("Serial connected.\n"); memory_install(mem_info, vid_info); + memory_switch_dir(virtual_kernel_dir()); + paging_enable(); cpu_enable_features(); cpu_print(); -- cgit v1.2.3