X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fthreads%2Floader.S;h=d67af3858f2cbefd592742c1dbab02827f4e00f2;hb=828d300fd2039b686b69244c2bd6f8b87645086d;hp=970d2e213dd03a6e12d60bca4ce77f4173811c3c;hpb=8063d8f3b3a778e9a15eff66dfd1b08652bae523;p=pintos-anon diff --git a/src/threads/loader.S b/src/threads/loader.S index 970d2e2..d67af38 100644 --- a/src/threads/loader.S +++ b/src/threads/loader.S @@ -1,5 +1,5 @@ -#include "mmu.h" #include "loader.h" +#include "mmu.h" ############################################################################## # Kernel loader. @@ -12,6 +12,12 @@ # first byte of the kernel, where start.S is linked. ############################################################################## +/* Flags in control register 0 */ +#define CR0_PE 0x00000001 /* Protection Enable. */ +#define CR0_EM 0x00000004 /* (Floating-point) Emulation. */ +#define CR0_PG 0x80000000 /* Paging. */ +#define CR0_WP 0x00010000 /* Write-Protect enable in kernel mode. */ + .globl start # Entry point start: .code16 # This runs in real mode cli # Disable interrupts @@ -133,35 +139,35 @@ read_sector: cmpl $KERNEL_LOAD_PAGES*8 + 1, %ebx jnz read_sector -##### Create temporary PDE and PTE, set page directory pointer, and turn -##### on paging. +##### Create temporary page directory and page table, set page +##### directory pointer, and turn on paging. ##### FIXME? We could use a single 4 MB page instead of 1024 4 kB pages. - # Create PDE at 64 kB. + # Create page directory at 64 kB. movl $0x10000, %edi movl %edi, %cr3 - # Fill PDE with zeroes. + # Fill page directory with zeroes. subl %eax, %eax movl $0x400, %ecx rep stosl - # Set PDE entries for 0 and LOADER_PHYS_BASE to point to the - # PTE. + # Set PDEs for 0 and LOADER_PHYS_BASE to point to the + # page table. movl $0x11000 | PG_U | PG_W | PG_P, %eax movl %eax, 0x10000 movl %eax, 0x10000 | (LOADER_PHYS_BASE >> 20) - # Initialize PTE. + # Initialize page table. movl $PG_U | PG_W | PG_P, %eax movl $0x400, %ecx 1: stosl addl $0x1000, %eax loop 1b - # Enable paging. + # Turn on paging and kernel write-protect. movl %cr0, %eax - orl $CR0_PG, %eax + orl $CR0_PG | CR0_WP, %eax movl %eax, %cr0 jmp 1f 1: @@ -175,9 +181,10 @@ read_sector: ##### Jump to kernel entry point. - movl $LOADER_PHYS_BASE + LOADER_BASE, %esp + movl $LOADER_PHYS_BASE + 0x20000, %esp movl $LOADER_PHYS_BASE + LOADER_KERN_BASE, %eax - jmp *%eax + call *%eax + jmp panic ##### GDT