# HG changeset patch # User windel # Date 1325199095 -3600 # Node ID 0148f55bfe24e817698e2d0fbecd111de0186afb # Parent 7e3bdcb391dcf82577f26f37025af2aeb64dafe0 Added static asserts and fixed pages diff -r 7e3bdcb391dc -r 0148f55bfe24 cos/Makefile --- a/cos/Makefile Thu Dec 29 19:34:01 2011 +0100 +++ b/cos/Makefile Thu Dec 29 23:51:35 2011 +0100 @@ -1,8 +1,7 @@ # vim: set noexpandtab: -all: bootdisk.img Makefile - -bootdisk.img: kernel/lcfos.bin grub/menu.lst Makefile +all: + make -C kernel cp grub/emptybootdisk.img bootdisk.img mcopy -D o -i bootdisk.img kernel/lcfos.bin :: mcopy -D o -i bootdisk.img grub/menu.lst ::/grub diff -r 7e3bdcb391dc -r 0148f55bfe24 cos/grub/menu.lst --- a/cos/grub/menu.lst Thu Dec 29 19:34:01 2011 +0100 +++ b/cos/grub/menu.lst Thu Dec 29 23:51:35 2011 +0100 @@ -1,5 +1,5 @@ default 0 -timeout 3 +timeout 0 title lcfos root (fd0) kernel /lcfos.bin diff -r 7e3bdcb391dc -r 0148f55bfe24 cos/kernel/Makefile --- a/cos/kernel/Makefile Thu Dec 29 19:34:01 2011 +0100 +++ b/cos/kernel/Makefile Thu Dec 29 23:51:35 2011 +0100 @@ -16,7 +16,7 @@ %.o : %.asm nasm -f elf64 -o $@ $< -%.o : %.c +%.o : %.c kernel.h gcc $(CFLAGS) -o $@ -c $< clean: diff -r 7e3bdcb391dc -r 0148f55bfe24 cos/kernel/handlers.c --- a/cos/kernel/handlers.c Thu Dec 29 19:34:01 2011 +0100 +++ b/cos/kernel/handlers.c Thu Dec 29 23:51:35 2011 +0100 @@ -303,4 +303,3 @@ panic("Default int handler called\n"); } - diff -r 7e3bdcb391dc -r 0148f55bfe24 cos/kernel/kernel.h --- a/cos/kernel/kernel.h Thu Dec 29 19:34:01 2011 +0100 +++ b/cos/kernel/kernel.h Thu Dec 29 23:51:35 2011 +0100 @@ -70,7 +70,7 @@ uint64_t ps : 1; // must be 0. uint64_t ignored2 : 4; // 12 bits so far - uint64_t address : 48; // address of page directory pointer table. + uint64_t address : 40; // address of page directory pointer table. uint64_t ignored3 : 11; uint64_t xd : 1; // execute disable } PML4E_t; // 64 bits wide, PML4 table must be 4096 byte aligned. @@ -94,7 +94,7 @@ uint64_t ps : 1; // page size, must be 0, otherwise maps a 1 GB page. uint64_t ignored2 : 4; // 12 bits so far - uint64_t address : 48; // address of page directory table. + uint64_t address : 40; // address of page directory table. uint64_t ignored3 : 11; uint64_t xd : 1; // execute disable } PDPTE_t; // Page directory pointer table entry, 64 bits wide. 4-kB aligned. @@ -118,7 +118,7 @@ uint64_t ps : 1; // page size, must be 0, otherwise maps a 2-MB page. uint64_t ignored2 : 4; // 12 bits so far - uint64_t address : 48; // address of page table. + uint64_t address : 40; // address of page table. uint64_t ignored3 : 11; uint64_t xd : 1; // execute disable } PDE_t; @@ -130,9 +130,10 @@ uint64_t physicalAddress; } PD_t; + typedef struct { - uint64_t present : 1; + unsigned present : 1; uint64_t rw : 1; uint64_t us : 1; // user or supervisor uint64_t pwt : 1; @@ -143,11 +144,16 @@ uint64_t g : 1; // Global? uint64_t ignored : 3; - uint64_t address : 48; + uint64_t address : 40; uint64_t ignored2 : 11; uint64_t xd : 1; } page_t; +_Static_assert(sizeof(page_t) == 8, "sizeof(page_t) != 8"); +_Static_assert(sizeof(PDE_t) == 8, "sizeof(PDE_t) != 8"); +_Static_assert(sizeof(PDPTE_t) == 8, "sizeof(PDPTE_t) != 8"); +_Static_assert(sizeof(PML4E_t) == 8, "sizeof(PML4E_t) != 8"); + // Page table: typedef struct { diff -r 7e3bdcb391dc -r 0148f55bfe24 cos/kernel/mm.c --- a/cos/kernel/mm.c Thu Dec 29 19:34:01 2011 +0100 +++ b/cos/kernel/mm.c Thu Dec 29 23:51:35 2011 +0100 @@ -58,6 +58,8 @@ // Memory manager functions: void init_memory(uint64_t total_mem_size) { + printf("Size of PT_t = %d\n", sizeof(PD_t)); + printf("Size of page_t = %d\n", sizeof(page_t)); // Allocate and clear bits to remember which 4kb-frames are in use: nframes = (total_mem_size / 0x1000); frames = (uint64_t*)kmalloc_int( (nframes / 64) * sizeof(uint64_t) ); @@ -80,6 +82,7 @@ page->present = 1; page->rw = 1; page->us = 1; // Make all things accessable for users for now. + //page->pwt = 1; // Is this bit required? set_frame(i / 0x1000); @@ -87,8 +90,8 @@ } // Set the created mapping as active: - // switch_mapping(kernel_map); - // TODO: debug crash after enable of new memory map + switch_mapping(kernel_map); + // TODO: set the use of placement malloc to invalid after here. } @@ -146,7 +149,6 @@ { // Create new table: pdpt = (PDPT_t*)kmalloc_aligned_int(sizeof(PDPT_t)); - printf("Creating PDPT %x\n", pdpt); memset(pdpt, 0, sizeof(PDPT_t)); // TODO: get function like virt2phys or something here @@ -166,7 +168,6 @@ } else { - printf("Creating PD\n"); // Create a new table: pd = (PD_t*)kmalloc_aligned_int(sizeof(PD_t)); memset(pd, 0, sizeof(PD_t)); @@ -189,7 +190,6 @@ } else { - printf("Creating PT\n"); // Create table: pt = (PT_t*)kmalloc_aligned_int(sizeof(PD_t)); memset(pt, 0, sizeof(PT_t));