4 #define KERNEL_BASE (0xc0000000)
6 #define MULTIBOOT_HEADER_MAGIC (0x1BADB002)
8 #define MULTIBOOT_HEADER_FLAGS (0x00010003)
10 #define V2P(x) (x - 0xc0000000 + 0x200000)
14 #define AP_MAGIC (0x12481020)
18 .globl _NtProcessStartup
21 .globl _init_stack_top
23 .globl _trap_stack_top
30 * This is called by the realmode loader, with protected mode
31 * enabled, paging disabled and the segment registers pointing
32 * a 4Gb, 32-bit segment starting at zero.
34 * EAX = Multiboot magic or application processor magic
36 * EBX = Points to a structure in lowmem with data from the
44 /* Align 32 bits boundary */
47 /* Multiboot header */
50 .long MULTIBOOT_HEADER_MAGIC
52 .long MULTIBOOT_HEADER_FLAGS
54 .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
56 .long (0x200000 + multiboot_header - KERNEL_BASE)
60 .long (__bss_start__ + 0x200000 - KERNEL_BASE)
62 .long (__bss_end__ + 0x200000 - KERNEL_BASE)
64 .long (0x200000 + _start - KERNEL_BASE)
68 * This must be PIC because we haven't set up paging yet
72 * Gcc expects this at all times
79 * Save the multiboot or application processor magic
93 movl $__bss_end__, %ecx
94 subl $__bss_start__, %ecx
96 movl $__bss_start__, %edi
97 subl $0xc0000000, %edi
103 * Initialize the page directory
105 movl $V2P(startup_pagedirectory), %esi
106 movl $(V2P(lowmem_pagetable) + 0x7), 0x0(%esi)
107 movl $(V2P(kernel_pagetable) + 0x7), 0xC00(%esi)
108 movl $(V2P(kernel_pagetable+4096) + 0x7), 0xC04(%esi)
109 movl $(V2P(kernel_pagetable+2*4096) + 0x7), 0xC08(%esi)
110 movl $(V2P(kernel_pagetable+3*4096) + 0x7), 0xC0c(%esi)
111 movl $(V2P(kernel_pagetable+4*4096) + 0x7), 0xC10(%esi)
112 movl $(V2P(kernel_pagetable+5*4096) + 0x7), 0xC14(%esi)
113 movl $(V2P(kernel_pagetable+6*4096) + 0x7), 0xC18(%esi)
114 movl $(V2P(kernel_pagetable+7*4096) + 0x7), 0xC1c(%esi)
115 movl $(V2P(kernel_pagetable+8*4096) + 0x7), 0xC20(%esi)
116 movl $(V2P(kernel_pagetable+9*4096) + 0x7), 0xC24(%esi)
117 movl $(V2P(kernel_pagetable+10*4096) + 0x7), 0xC28(%esi)
118 movl $(V2P(kernel_pagetable+11*4096) + 0x7), 0xC2c(%esi)
119 movl $(V2P(kernel_pagetable+12*4096) + 0x7), 0xC30(%esi)
120 movl $(V2P(kernel_pagetable+13*4096) + 0x7), 0xC34(%esi)
121 movl $(V2P(kernel_pagetable+14*4096) + 0x7), 0xC38(%esi)
122 movl $(V2P(kernel_pagetable+15*4096) + 0x7), 0xC3c(%esi)
123 movl $(V2P(kernel_pagetable+16*4096) + 0x7), 0xC40(%esi)
124 movl $(V2P(kernel_pagetable+17*4096) + 0x7), 0xC44(%esi)
125 movl $(V2P(kernel_pagetable+18*4096) + 0x7), 0xC48(%esi)
126 movl $(V2P(kernel_pagetable+19*4096) + 0x7), 0xC4c(%esi)
127 movl $(V2P(kernel_pagetable+20*4096) + 0x7), 0xC50(%esi)
128 movl $(V2P(kernel_pagetable+21*4096) + 0x7), 0xC54(%esi)
129 movl $(V2P(kernel_pagetable+22*4096) + 0x7), 0xC58(%esi)
130 movl $(V2P(kernel_pagetable+23*4096) + 0x7), 0xC5c(%esi)
131 movl $(V2P(kernel_pagetable+24*4096) + 0x7), 0xC60(%esi)
132 movl $(V2P(kernel_pagetable+25*4096) + 0x7), 0xC64(%esi)
133 movl $(V2P(kernel_pagetable+26*4096) + 0x7), 0xC68(%esi)
134 movl $(V2P(kernel_pagetable+27*4096) + 0x7), 0xC6c(%esi)
135 movl $(V2P(kernel_pagetable+28*4096) + 0x7), 0xC70(%esi)
136 movl $(V2P(kernel_pagetable+29*4096) + 0x7), 0xC74(%esi)
137 movl $(V2P(kernel_pagetable+30*4096) + 0x7), 0xC78(%esi)
138 movl $(V2P(kernel_pagetable+31*4096) + 0x7), 0xC7c(%esi)
140 movl $(V2P(lowmem_pagetable) + 0x7), 0xD00(%esi)
141 movl $(V2P(startup_pagedirectory) + 0x7), 0xF00(%esi)
143 movl $(V2P(apic_pagetable) + 0x7), 0xFEC(%esi)
145 movl $(V2P(kpcr_pagetable) + 0x7), 0xFF0(%esi)
148 * Initialize the page table that maps low memory
150 movl $V2P(lowmem_pagetable), %esi
154 movl %eax, (%esi, %edi)
161 * Initialize the page table that maps kernel memory
163 movl $V2P(kernel_pagetable), %esi
167 movl %eax, (%esi, %edi)
176 * Initialize the page table that maps the APIC register address space
180 * FIXME: APIC register address space can be non-standard so do the
183 movl $V2P(apic_pagetable), %esi
185 movl $0xFEC0001B, %eax
186 movl %eax, (%esi, %edi)
188 movl $0xFEE0001B, %eax
189 movl %eax, (%esi, %edi)
194 * Initialize the page table that maps the initial KPCR (at FF000000)
196 movl $V2P(kpcr_pagetable), %esi
199 movl %eax, (%esi, %edi)
210 movl $(V2P(startup_pagedirectory)), %eax
214 * Enable paging and set write protect
217 orl $0x80010000, %eax
221 * Do an absolute jump because we now want to execute above 0xc0000000
228 * Load the GDTR and IDTR with new tables located above
232 /* FIXME: Application processors should have their own GDT/IDT */
233 lgdt _KiGdtDescriptor
234 lidt _KiIdtDescriptor
237 * Reload the data segment registers
239 movl $KERNEL_DS, %eax
253 * This is an application processor executing
263 * Call the application processor initialization code
268 pushl $_KiSystemStartup
272 * Catch illegal returns from KiSystemStartup
288 * Load the PCR selector
290 movl $PCR_SELECTOR, %eax
294 * Load the initial kernel stack
296 movl $_init_stack_top, %esp
305 * Call the main kernel initialization
316 * Catch illegal returns from main, try bug checking the system,
317 * if that fails then loop forever.
330 * This needs to be page aligned so put it at the beginning of the bss
334 startup_pagedirectory: