1 # Multiboot header, for multiboot boot loaders like GNU Grub.
2 # http://www.gnu.org/software/grub/manual/multiboot/multiboot.html
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:
10 # set root='(hd0,msdos1)'
11 # set kernel='/boot/kernel'
12 # echo "Loading ${kernel}..."
13 # multiboot ${kernel} ${kernel}
21 #define SEG_KCODE 1 // kernel code
22 #define SEG_KDATA 2 // kernel data+stack
24 # Multiboot header. Data to direct multiboot loader.
27 .globl multiboot_header
29 #define magic 0x1badb002
30 #define flags (1<<16 | 1<<0)
34 .long multiboot_header # beginning of image
35 .long multiboot_header
40 # Multiboot entry point. Machine is mostly set up.
41 # Configure the GDT to match the environment that our usual
42 # boot loader - bootasm.S - sets up.
43 .globl multiboot_entry
46 ljmp $(SEG_KCODE<<3), $mbstart32
49 # Set up the protected-mode data segment registers
50 movw $(SEG_KDATA<<3), %ax # Our data segment selector
51 movw %ax, %ds # -> DS: Data Segment
52 movw %ax, %es # -> ES: Extra Segment
53 movw %ax, %ss # -> SS: Stack Segment
54 movw $0, %ax # Zero segments not ready for use
58 # Set up the stack pointer and call into C.
59 movl $(stack + STACK), %esp
65 .p2align 2 # force 4 byte alignment
67 SEG_NULLASM # null seg
68 SEG_ASM(STA_X|STA_R, 0x0, 0xffffffff) # code seg
69 SEG_ASM(STA_W, 0x0, 0xffffffff) # data seg
72 .word (gdtdesc - gdt - 1) # sizeof(gdt) - 1
73 .long gdt # address gdt