diff options
-rw-r--r-- | apps/wm/wm.c | 4 | ||||
-rw-r--r-- | kernel/drivers/fb.c | 33 | ||||
-rw-r--r-- | kernel/drivers/gdt.c | 4 | ||||
-rw-r--r-- | kernel/drivers/ps2/mouse.c | 1 | ||||
-rw-r--r-- | kernel/entry.asm | 15 | ||||
-rw-r--r-- | kernel/features/mm.c | 15 | ||||
-rw-r--r-- | kernel/features/proc.c | 1 | ||||
-rw-r--r-- | kernel/inc/boot.h | 45 | ||||
-rw-r--r-- | kernel/inc/fb.h | 2 | ||||
-rw-r--r-- | kernel/inc/gdt.h | 2 | ||||
-rw-r--r-- | kernel/inc/io.h | 1 | ||||
-rw-r--r-- | kernel/inc/mm.h | 1 | ||||
-rw-r--r-- | kernel/inc/multiboot.h | 1 | ||||
-rw-r--r-- | kernel/main.c | 7 | ||||
-rw-r--r-- | kernel/multiboot.c | 9 | ||||
-rw-r--r-- | libs/libc/inc/mem.h | 1 |
16 files changed, 47 insertions, 95 deletions
diff --git a/apps/wm/wm.c b/apps/wm/wm.c index 3d8fb33..237026d 100644 --- a/apps/wm/wm.c +++ b/apps/wm/wm.c @@ -565,7 +565,7 @@ int main(int argc, char **argv) atexit(handle_exit); - assert(io_control(IO_FRAMEBUFFER, IOCTL_FB_GET, &screen) == EOK); + assert(io_control(IO_FRAMEBUFFER, IOCTL_FB_GET, &screen, sizeof(screen)) == EOK); log("WM loaded: %dx%d\n", screen.width, screen.height); wm_client = (struct client){ .conn = 0 }; bypp = (screen.bpp >> 3); @@ -583,6 +583,8 @@ int main(int argc, char **argv) WF_NO_DRAG | WF_NO_FOCUS | WF_NO_RESIZE | WF_ALPHA); /* gfx_write(&direct->ctx, vec2(0, 0), FONT_32, COLOR_FG, "Loading Melvix..."); */ + while (1) + ; gfx_load_wallpaper(&wallpaper->ctx, "/res/wall.png"); memset(cursor->ctx.fb, 0, cursor->ctx.bytes); gfx_load_wallpaper(&cursor->ctx, "/res/cursor.png"); 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 <io.h> #include <mem.h> #include <mm.h> +#include <multiboot.h> #include <str.h> #include <sys.h> @@ -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 <assert.h> -#include <boot.h> #include <cpu.h> #include <errno.h> #include <interrupts.h> diff --git a/kernel/entry.asm b/kernel/entry.asm index 10b6b25..a06b6ab 100644 --- a/kernel/entry.asm +++ b/kernel/entry.asm @@ -1,6 +1,5 @@ bits 32 -%define STACK_POINTER 0x00500000 ; The initial stack pointer in kernel mode %define MULTIBOOT_MAGIC 0x1badb002 %define MULTIBOOT_PAGE_ALIGN 0x1 %define MULTIBOOT_MEMORY_INFO 0x2 @@ -24,18 +23,24 @@ dd 0x00000000 ; MULTIBOOT_VIDEO_MODE dd 0x00000000 -dd 1280 -dd 1024 +dd 1920 +dd 1200 dd 32 global boot_entry extern kernel_main boot_entry: - mov esp, STACK_POINTER + mov esp, stack_top + push esp push ebx push eax - cli call kernel_main hlt jmp $ + +section .bss +align 32 +stack_bottom: + resb 0x4000 +stack_top: diff --git a/kernel/features/mm.c b/kernel/features/mm.c index 9dd425e..e60e2b5 100644 --- a/kernel/features/mm.c +++ b/kernel/features/mm.c @@ -740,25 +740,12 @@ CLEAR void memory_install(void) memory_used = 0; printf("Detected memory: %dKiB (%dMiB)\n", memory_total >> 10, memory_total >> 20); - // Set first MiB 'used' (bootloader(s), VESA tables, memory maps, ...) - //physical_set_used(memory_range(0, 0x00100000)); - // Map kernel memory_map_identity(&kernel_dir, kernel_ro_memory_range(), MEMORY_READONLY); memory_map_identity(&kernel_dir, kernel_rw_memory_range(), MEMORY_NONE); - // Map kernel stack with readonly boundaries (stack grows downwards!) - memory_map_identity(&kernel_dir, memory_range(STACK_START - STACK_SIZE, STACK_SIZE), - MEMORY_NONE); - memory_map_identity(&kernel_dir, - memory_range(STACK_START - STACK_SIZE - PAGE_SIZE, PAGE_SIZE), - MEMORY_READONLY); - memory_map_identity(&kernel_dir, memory_range(STACK_START, PAGE_SIZE), MEMORY_READONLY); - // 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); */ + memory_map_identity(&kernel_dir, memory_range_around(multiboot_vbe(), 0x1000), MEMORY_NONE); // Unmap NULL byte/page struct memory_range zero = memory_range(0, PAGE_SIZE); diff --git a/kernel/features/proc.c b/kernel/features/proc.c index 6812c72..ffa711b 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -1,7 +1,6 @@ // MIT License, Copyright (c) 2020 Marvin Borner #include <assert.h> -#include <boot.h> #include <cpu.h> #include <errno.h> #include <fs.h> diff --git a/kernel/inc/boot.h b/kernel/inc/boot.h deleted file mode 100644 index 48ab440..0000000 --- a/kernel/inc/boot.h +++ /dev/null @@ -1,45 +0,0 @@ -// MIT License, Copyright (c) 2020 Marvin Borner -// This file specifies the structs passed by the bootloader - -#ifndef BOOT_H -#define BOOT_H - -#include <def.h> - -struct vid_info { - u32 mode; - u32 *vbe; -}; - -enum mmap_type { - MEMORY_AVAILABLE = 1, - MEMORY_RESERVED, - MEMORY_ACPI, - MEMORY_NVS, - MEMORY_DEFECT, - MEMORY_DISABLED -}; - -struct mmap_boot { - u32 lbase; - u32 hbase; - u32 lsize; - u32 hsize; - u32 type; - u32 acpi; -}; - -struct mem_info { - struct mmap_boot *start; - u32 *end; - u32 size; -}; - -struct boot_info { - struct vid_info *vid; - struct mem_info *mem; - u32 tss; - u32 drive; -}; - -#endif diff --git a/kernel/inc/fb.h b/kernel/inc/fb.h index 46f9020..b3486e0 100644 --- a/kernel/inc/fb.h +++ b/kernel/inc/fb.h @@ -3,10 +3,8 @@ #ifndef FB_H #define FB_H -#include <boot.h> #include <mm.h> -void fb_map_buffer(struct page_dir *dir, struct vid_info *boot) NONNULL; void fb_install(void) NONNULL; #endif diff --git a/kernel/inc/gdt.h b/kernel/inc/gdt.h index 06388a9..9a9fd01 100644 --- a/kernel/inc/gdt.h +++ b/kernel/inc/gdt.h @@ -54,7 +54,7 @@ struct tss_entry { u16 iomap_base; } PACKED; -void gdt_install(void); +void gdt_install(u32 esp); void tss_set_stack(u32 ss, u32 esp); #endif diff --git a/kernel/inc/io.h b/kernel/inc/io.h index 5d51f89..b3e8b9b 100644 --- a/kernel/inc/io.h +++ b/kernel/inc/io.h @@ -3,7 +3,6 @@ #ifndef IO_H #define IO_H -#include <boot.h> #include <def.h> #include <interrupts.h> #include <proc.h> diff --git a/kernel/inc/mm.h b/kernel/inc/mm.h index a33d9d1..a8116e6 100644 --- a/kernel/inc/mm.h +++ b/kernel/inc/mm.h @@ -3,7 +3,6 @@ #ifndef PAGING_H #define PAGING_H -#include <boot.h> #include <def.h> #include <errno.h> #include <interrupts.h> diff --git a/kernel/inc/multiboot.h b/kernel/inc/multiboot.h index 839ade7..5227fb0 100644 --- a/kernel/inc/multiboot.h +++ b/kernel/inc/multiboot.h @@ -122,6 +122,7 @@ struct multiboot_mod_list { }; void multiboot_mmap(void); +u32 multiboot_vbe(void); void multiboot_init(u32 magic, u32 addr); #endif diff --git a/kernel/main.c b/kernel/main.c index 37dd2da..023190a 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -1,6 +1,5 @@ // MIT License, Copyright (c) 2020 Marvin Borner -#include <boot.h> #include <cpu.h> #include <fs.h> #include <gdt.h> @@ -21,15 +20,15 @@ PROTECTED extern u32 __stack_chk_guard; PROTECTED u32 __stack_chk_guard; -int kernel_main(u32 magic, u32 addr); // Decl -int kernel_main(u32 magic, u32 addr) +int kernel_main(u32 magic, u32 addr, u32 esp); // Decl +int kernel_main(u32 magic, u32 addr, u32 esp) { // Serial connection serial_install(); serial_print("\nKernel was compiled at " __TIME__ " on " __DATE__ "\n"); serial_print("Serial connected!\n"); - gdt_install(); + gdt_install(esp); multiboot_init(magic, addr); diff --git a/kernel/multiboot.c b/kernel/multiboot.c index a9a0c75..8fa7aa6 100644 --- a/kernel/multiboot.c +++ b/kernel/multiboot.c @@ -18,9 +18,16 @@ CLEAR void multiboot_init(u32 magic, u32 addr) } } +CLEAR u32 multiboot_vbe(void) +{ + assert(info->flags & MULTIBOOT_INFO_VBE_INFO); + + return info->vbe_mode_info; +} + CLEAR void multiboot_mmap(void) { - assert(info->flags & MULTIBOOT_INFO_MEMORY); + assert(info->flags & MULTIBOOT_INFO_MEM_MAP); struct multiboot_mmap_entry *mmap = (void *)info->mmap_addr; u32 length = info->mmap_length; diff --git a/libs/libc/inc/mem.h b/libs/libc/inc/mem.h index 63a1b14..75174c9 100644 --- a/libs/libc/inc/mem.h +++ b/libs/libc/inc/mem.h @@ -17,7 +17,6 @@ void free_debug(void *ptr, const char *file, int line, const char *func, const c #define free(ptr) free_debug((void *)(ptr), __FILE__, __LINE__, __func__, #ptr) #ifdef KERNEL -#define STACK_START 0x00500000 // Defined in bootloader #define STACK_SIZE (1 << 20) // 1MiB #elif defined(USER) #endif |