entry.S (1743B)
1 # Multiboot header, for multiboot boot loaders like GNU Grub. 2 # http://www.gnu.org/software/grub/manual/multiboot/multiboot.html 3 # 4 # Using GRUB 2, you can boot xv6 from a file stored in a 5 # Linux file system by copying kernel or kernelmemfs to /boot 6 # and then adding this menu entry: 7 # 8 # menuentry "xv6" { 9 # insmod ext2 10 # set root='(hd0,msdos1)' 11 # set kernel='/boot/kernel' 12 # echo "Loading ${kernel}..." 13 # multiboot ${kernel} ${kernel} 14 # boot 15 # } 16 17 #include "asm.h" 18 #include "memlayout.h" 19 #include "mmu.h" 20 #include "param.h" 21 22 # Multiboot header. Data to direct multiboot loader. 23 .p2align 2 24 .text 25 .globl multiboot_header 26 multiboot_header: 27 #define magic 0x1badb002 28 #define flags 0x10000 29 .long magic 30 .long flags 31 .long (-magic-flags) 32 .long V2P_WO(multiboot_header) 33 .long V2P_WO(multiboot_header) 34 .long V2P_WO(edata) 35 .long V2P_WO(end) 36 .long _start 37 38 # By convention, the _start symbol specifies the ELF entry point. 39 # Since we haven't set up virtual memory yet, our entry point is 40 # the physical address of 'entry'. 41 .globl _start 42 _start = V2P_WO(entry) 43 44 # Entering xv6 on boot processor, with paging off. 45 .globl entry 46 entry: 47 # Turn on page size extension for 4Mbyte pages 48 movl %cr4, %eax 49 orl $(CR4_PSE), %eax 50 movl %eax, %cr4 51 # Set page directory 52 movl $(V2P_WO(entrypgdir)), %eax 53 movl %eax, %cr3 54 # Turn on paging. 55 movl %cr0, %eax 56 orl $(CR0_PG|CR0_WP), %eax 57 movl %eax, %cr0 58 59 # Set up the stack pointer. 60 movl $(stack + KSTACKSIZE), %esp 61 62 # Jump to main(), and switch to executing at 63 # high addresses. The indirect call is needed because 64 # the assembler produces a PC-relative instruction 65 # for a direct jump. 66 mov $main, %eax 67 jmp *%eax 68 69 .comm stack, KSTACKSIZE