1 /* See COPYRIGHT for copyright information. */
4 #include <inc/memlayout.h>
8 #define SRL(val, shamt) (((val) >> (shamt)) & ~(-1 << (32 - (shamt))))
11 ###################################################################
12 # The kernel (this code) is linked at address ~(KERNBASE + 1 Meg),
13 # but the bootloader loads it at address ~1 Meg.
15 # RELOC(x) maps a symbol x from its link address to its actual
16 # location in physical memory (its load address).
17 ###################################################################
19 #define RELOC(x) ((x) - KERNBASE)
22 .set CODE_SEL,0x8 # index of code seg within mygdt
23 .set DATA_SEL,0x10 # index of data seg within mygdt
25 #define MULTIBOOT_PAGE_ALIGN (1<<0)
26 #define MULTIBOOT_MEMORY_INFO (1<<1)
27 #define MULTIBOOT_HEADER_MAGIC (0x1BADB002)
28 #define MULTIBOOT_HEADER_FLAGS (MULTIBOOT_MEMORY_INFO | MULTIBOOT_PAGE_ALIGN)
29 #define CHECKSUM (-(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS))
31 ###################################################################
33 ###################################################################
37 # The Multiboot header
39 .long MULTIBOOT_HEADER_MAGIC
40 .long MULTIBOOT_HEADER_FLAGS
45 movw $0x1234,0x472 # warm boot
47 # Establish our own GDT in place of the boot loader's temporary GDT.
48 lgdt RELOC(mygdtdesc) # load descriptor table
50 # Immediately reload all segment registers (including CS!)
51 # with segment selectors from the new GDT.
52 movl $DATA_SEL, %eax # Data segment selector
53 movw %ax,%ds # -> DS: Data Segment
54 movw %ax,%es # -> ES: Extra Segment
55 movw %ax,%ss # -> SS: Stack Segment
56 ljmp $CODE_SEL,$relocated # reload CS by jumping
59 # Clear the frame pointer register (EBP)
60 # so that once we get into debugging C code,
61 # stack backtraces will be terminated properly.
62 movl $0x0,%ebp # nuke frame pointer
64 # Leave a few words on the stack for the user trap frame
65 movl $(bootstacktop-SIZEOF_STRUCT_TRAPFRAME),%esp
70 # Should never get here, but in case we do, just spin.
74 ###################################################################
76 ###################################################################
78 .p2align PGSHIFT # force page alignment
85 ###################################################################
87 ###################################################################
88 .p2align 2 # force 4 byte alignment
91 SEG(STA_X|STA_R, -KERNBASE, 0xffffffff) # code seg
92 SEG(STA_W, -KERNBASE, 0xffffffff) # data seg
94 .word 0x17 # sizeof(mygdt) - 1
95 .long RELOC(mygdt) # address mygdt