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