From 3c8de2434977fb4ea880ad8a90f80bc1bfb80d9b Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 10 Oct 2013 11:09:36 +0200 Subject: [PATCH 1/7] fixed some typos, added comments and some code cleanup --- arch/x86/kernel/entry32.asm | 4 ++-- arch/x86/kernel/entry64.asm | 18 +++++++++--------- arch/x86/mm/page32.c | 4 ++-- arch/x86/mm/page64.c | 8 ++++---- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/arch/x86/kernel/entry32.asm b/arch/x86/kernel/entry32.asm index eb4d8393..00ec044b 100644 --- a/arch/x86/kernel/entry32.asm +++ b/arch/x86/kernel/entry32.asm @@ -70,7 +70,7 @@ stublet: ; jump to the boot processors's C code extern main call main - jmp $ + jmp $ ; infinitive loop global cpu_init cpu_init: @@ -112,7 +112,7 @@ global read_ip read_ip: mov eax, [esp+4] pop DWORD [eax] ; Get the return address - add esp, 4 ; Dirty Hack! read_ip cleanup the stacl + add esp, 4 ; Dirty Hack! read_ip cleanup the stack jmp [eax] ; Return. Can't use RET because return ; address popped off the stack. diff --git a/arch/x86/kernel/entry64.asm b/arch/x86/kernel/entry64.asm index 3cebc86f..d749c08e 100644 --- a/arch/x86/kernel/entry64.asm +++ b/arch/x86/kernel/entry64.asm @@ -30,7 +30,7 @@ extern kernel_end extern apic_mp ; We use a special name to map this section at the begin of our kernel -; => Multiboot needs its magic number at the begin of the kernel +; => Multiboot needs its magic number at the beginning of the kernel SECTION .mboot global start start: @@ -42,19 +42,19 @@ mboot: ; Multiboot macros to make a few lines more readable later MULTIBOOT_PAGE_ALIGN equ 1<<0 MULTIBOOT_MEMORY_INFO equ 1<<1 - ; MULTIBOOT_AOUT_KLUDGE equ 1<<16 + ; MULTIBOOT_AOUT_KLUDGE equ 1<<16 MULTIBOOT_HEADER_MAGIC equ 0x1BADB002 MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO ; | MULTIBOOT_AOUT_KLUDGE - MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) + MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) EXTERN code, bss, end ; This is the GRUB Multiboot header. A boot signature dd MULTIBOOT_HEADER_MAGIC dd MULTIBOOT_HEADER_FLAGS dd MULTIBOOT_CHECKSUM - + ALIGN 4 -; we need already a valid GDT to switch in the 64bit modus +; we need already a valid GDT to switch in the 64bit mode GDT64: ; Global Descriptor Table (64-bit). .Null: equ $ - GDT64 ; The null descriptor. dw 0 ; Limit (low). @@ -81,7 +81,7 @@ GDT64: ; Global Descriptor Table (64-bit). dw $ - GDT64 - 1 ; Limit. dq GDT64 ; Base. - times 256 DD 0 + times 256 DD 0 ; stack for booting startup_stack: SECTION .data @@ -129,8 +129,8 @@ smp_entry: ; enable paging mov eax, cr0 - or eax, 1 << 31 | 1 << 0 ; Set the PG-bit, which is the 31nd bit, and the PM-bit, which is the 0th bit. - mov cr0, eax + or eax, 1 << 31 | 1 << 0 ; Set the PG-bit, which is the 31nd bit, and the PE-bit, which is the 0th bit. + mov cr0, eax ; According to the multiboot spec the PE-bit has to be set by bootloader already! mov edi, [esp+4] ; set argumet for smp_start lgdt [GDT64.Pointer] ; Load the 64-bit global descriptor table. @@ -342,7 +342,7 @@ Lc: ; enable paging mov eax, cr0 - or eax, 1 << 31 | 1 << 0 ; Set the PG-bit, which is the 31nd bit, and the PM-bit, which is the 0th bit. + or eax, 1 << 31 | 1 << 0 ; Set the PG-bit, which is the 31nd bit, and the PE-bit, which is the 0th bit. mov cr0, eax pop ebx ; restore pointer to multiboot structure diff --git a/arch/x86/mm/page32.c b/arch/x86/mm/page32.c index c961e0cc..c298befe 100644 --- a/arch/x86/mm/page32.c +++ b/arch/x86/mm/page32.c @@ -71,7 +71,7 @@ page_dir_t* get_boot_pgd(void) /* * TODO: We create a full copy of the current task. Copy-On-Access will be the better solution. * - * No PGD locking is needed because onls create_pgd use this function and holds already the + * No PGD locking is needed because only create_pgd use this function and holds already the * PGD lock. */ inline static size_t copy_page_table(task_t* task, uint32_t pgd_index, page_table_t* pgt, int* counter) @@ -650,7 +650,7 @@ static void pagefault_handler(struct state *s) memset((void*) viraddr, 0x00, PAGE_SIZE); return; } - + kprintf("Could not map 0x%x at 0x%x\n", phyaddr, viraddr); put_page(phyaddr); } diff --git a/arch/x86/mm/page64.c b/arch/x86/mm/page64.c index 1bb6cea5..9fb19fda 100644 --- a/arch/x86/mm/page64.c +++ b/arch/x86/mm/page64.c @@ -55,8 +55,8 @@ extern const void kernel_start; extern const void kernel_end; -// boot task's page directory and page directory lock -extern page_dir_t boot_pgd; +// boot task's page directory and p:age directory lock +extern page_dir_t boot_pgd; // TODO: initialization done in entry64.asm static spinlock_t kslock = SPINLOCK_INIT; static int paging_enabled = 0; @@ -67,7 +67,7 @@ page_dir_t* get_boot_pgd(void) int create_pgd(task_t* task, int copy) { - // Currently, we support only kernel tasks + // TODO: Currently, we support only kernel tasks // => all tasks are able to use the same pgd if (BUILTIN_EXPECT(!paging_enabled, 0)) @@ -130,7 +130,7 @@ size_t virt_to_phys(size_t viraddr) spinlock_irqsave_lock(&task->pgd_lock); - // Currently, we allocate pages only in kernel space. + // TODO: Currently, we allocate pages only in kernel space. // => physical address of the page table is identical of the virtual address pgt = (page_table_t*) (task->pgd->entries[idx_pd4] & PAGE_MASK); if (!pgt) From 7ffaec04f207af378a2a2f49647a03f9133b6273 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 10 Oct 2013 11:44:31 +0200 Subject: [PATCH 2/7] added missing newline at end of printf() --- newlib/examples/hello.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/newlib/examples/hello.c b/newlib/examples/hello.c index 8ef0d79d..ad8ff40d 100644 --- a/newlib/examples/hello.c +++ b/newlib/examples/hello.c @@ -68,7 +68,7 @@ int main(int argc, char** argv) exit(1); } testdirent = readdir(testdir); - printf("1. Dirent: %s", testdirent->d_name); + printf("1. Dirent: %s\n", testdirent->d_name); closedir(testdir); return errno; From 6b7b70903e4c8f37a1f0f458401d554542e8b5db Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 10 Oct 2013 11:45:03 +0200 Subject: [PATCH 3/7] removed non-existant header asm/mmu.h --- include/metalsvm/mmu.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/metalsvm/mmu.h b/include/metalsvm/mmu.h index efff6f58..4db5a367 100644 --- a/include/metalsvm/mmu.h +++ b/include/metalsvm/mmu.h @@ -31,7 +31,6 @@ #include #include -//#include #ifdef __cplusplus extern "C" { From 2f02db8dc09fd9abe9123e3dc911e5c0e870ca11 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 10 Oct 2013 11:46:04 +0200 Subject: [PATCH 4/7] fixed typo --- mm/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index 905adda4..2c60ff1c 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -75,7 +75,7 @@ inline static void page_set_mark(size_t i) size_t mod = i & 0x7; //if (page_marked(i)) - // kprintf("page %u is alread marked\n", i); + // kprintf("page %u is already marked\n", i); bitmap[index] = bitmap[index] | (1 << mod); } From b0749fc448745083f1ee109256218dbfd4a6d732 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 10 Oct 2013 11:48:00 +0200 Subject: [PATCH 5/7] added some comments --- kernel/syscall.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kernel/syscall.c b/kernel/syscall.c index 7dfee0c4..1d7eb0d2 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -403,6 +403,7 @@ static int sys_sbrk(int incr) spinlock_lock(&task->vma_lock); + // search vma containing the heap tmp = task->vma_list; while(tmp && !((task->end_heap >= tmp->start) && (task->end_heap <= tmp->end))) tmp = tmp->next; @@ -411,11 +412,16 @@ static int sys_sbrk(int incr) task->end_heap += incr; if (task->end_heap < task->start_heap) task->end_heap = task->start_heap; - + // resize virtual memory area if (tmp && (tmp->end <= task->end_heap)) tmp->end = task->end_heap; + // allocation and mapping of new pages for the heap + // is catched by the pagefault handler + + //kprintf("sys_sbrk: tid=%d, start_heap=%8x, end_heap=%8x, incr=%4x\n", task->id, task->start_heap, task->end_heap, incr); + spinlock_unlock(&task->vma_lock); return ret; From 2e230a609ec5267126d1119ff18df60e01c3976e Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 10 Oct 2013 11:50:38 +0200 Subject: [PATCH 6/7] added more output to vma_dump() --- mm/vma.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/vma.c b/mm/vma.c index b6139e02..f1e64580 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -72,9 +72,10 @@ int vma_dump(task_t* task) spinlock_lock(&task->vma_lock); + int cnt = 0; tmp = task->vma_list; while (tmp) { - kprintf("%8x - %8x: ", tmp->start, tmp->end); + kprintf("#%d\t%8x - %8x: size=%6x, flags=", cnt, tmp->start, tmp->end, tmp->end - tmp->start); if (tmp->type & VMA_READ) kputs("r"); @@ -93,6 +94,7 @@ int vma_dump(task_t* task) kputs("\n"); tmp = tmp->next; + cnt++; } spinlock_unlock(&task->vma_lock); From dac9b20c181bf1410fb7d6ca57f8a5458a275b83 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 16 Oct 2013 13:42:58 +0200 Subject: [PATCH 7/7] some comments cleaned up --- arch/x86/include/asm/SCC_API.h | 4 ++-- mm/memory.c | 16 ++++++---------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/arch/x86/include/asm/SCC_API.h b/arch/x86/include/asm/SCC_API.h index 8812fefc..f2217483 100644 --- a/arch/x86/include/asm/SCC_API.h +++ b/arch/x86/include/asm/SCC_API.h @@ -34,7 +34,7 @@ // ____ _ _ // / ___| _ _ _ __ ___ | |__ ___ | |___ // \___ \| | | | '_ ` _ \| '_ \ / _ \| / __| -// ___) | |_| | | | | | | |_) | (_) | \__ \ +// ___) | |_| | | | | | | |_) | (_) | \__ // |____/ \__, |_| |_| |_|_.__/ \___/|_|___/ // |___/ // @@ -253,7 +253,7 @@ // _____ _ _ // | ___| _ _ __ ___| |_(_) ___ _ __ ___ // | |_ | | | | '_ \ / __| __| |/ _ \| '_ \/ __| -// | _|| |_| | | | | (__| |_| | (_) | | | \__ \ +// | _|| |_| | | | | (__| |_| | (_) | | | \__ // |_| \__,_|_| |_|\___|\__|_|\___/|_| |_|___/ // // ######################################################################################### diff --git a/mm/memory.c b/mm/memory.c index 2c60ff1c..b01cdb58 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -109,7 +109,8 @@ int mmu_init(void) while (mmap < mmap_end) { if (mmap->type == MULTIBOOT_MEMORY_AVAILABLE) { - /* set the available memory as "unused" */ + / + // set the available memory as "unused" addr = mmap->addr; end_addr = addr + mmap->len; @@ -129,7 +130,7 @@ int mmu_init(void) } } #elif defined(CONFIG_ROCKCREEK) - /* of course, the first slots belong to the private memory */ + // of course, the first slots belong to the private memory for(addr=0x00; addr<1*0x1000000; addr+=PAGE_SIZE) { page_clear_mark(addr >> PAGE_SHIFT); if (addr > addr + PAGE_SIZE) @@ -147,9 +148,7 @@ int mmu_init(void) atomic_int32_inc(&total_available_pages); } - /* - * Mark the bootinfo as used. - */ + // mark the bootinfo as used. page_set_mark((size_t)bootinfo >> PAGE_SHIFT); atomic_int32_inc(&total_allocated_pages); atomic_int32_dec(&total_available_pages); @@ -164,7 +163,7 @@ int mmu_init(void) atomic_int32_add(&total_allocated_pages, kernel_size >> PAGE_SHIFT); atomic_int32_sub(&total_available_pages, kernel_size >> PAGE_SHIFT); - /* set kernel space as used */ + // set kernel space as used for(i=(size_t) &kernel_start >> PAGE_SHIFT; i < (size_t) &kernel_end >> PAGE_SHIFT; i++) page_set_mark(i); if ((size_t) &kernel_end & (PAGE_SIZE-1)) @@ -194,9 +193,7 @@ int mmu_init(void) if (mb_info && (mb_info->flags & MULTIBOOT_INFO_MODS)) { multiboot_module_t* mmodule = (multiboot_module_t*) ((size_t) mb_info->mods_addr); - /* - * Mark the mb_info as used. - */ + // mark the mb_info as used. page_set_mark((size_t)mb_info >> PAGE_SHIFT); atomic_int32_inc(&total_allocated_pages); atomic_int32_dec(&total_available_pages); @@ -371,7 +368,6 @@ void kfree(void* addr, size_t sz) index = phyaddr >> PAGE_SHIFT; page_clear_mark(index); - } spinlock_unlock(&bitmap_lock);