Changes in kernel/arch/ia32/src/boot/boot.S [e3e4a2c:1d3d2cf] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/ia32/src/boot/boot.S
re3e4a2c r1d3d2cf 97 97 pm_status $status_prot 98 98 99 #include "vesa_prot.inc"100 101 #ifndef PROCESSOR_i486102 103 pm_status $status_prot2104 105 99 movl $(INTEL_CPUID_LEVEL), %eax 106 100 cpuid … … 111 105 cpuid 112 106 bt $(INTEL_PSE), %edx 113 jnc pse_unsupported 114 115 /* Map kernel and turn paging on */ 116 pm_status $status_pse 117 call map_kernel_pse 118 jmp stack_init 119 120 #endif /* PROCESSOR_i486 */ 107 jc pse_supported 121 108 122 109 pse_unsupported: 123 110 124 /* Map kernel and turn paging on */ 125 pm_status $status_non_pse 126 call map_kernel 127 128 stack_init: 111 pm_error $err_pse 112 113 pse_supported: 114 115 #include "vesa_prot.inc" 116 117 /* Map kernel and turn paging on */ 118 call map_kernel 129 119 130 120 /* Create the first stack frame */ … … 132 122 movl %esp, %ebp 133 123 134 pm2_status $status_prot 3124 pm2_status $status_prot2 135 125 136 126 /* Call arch_pre_main(grub_eax, grub_ebx) */ … … 150 140 jmp hlt0 151 141 152 /** Setup mapping for the kernel (PSE variant)142 /** Setup mapping for the kernel. 153 143 * 154 144 * Setup mapping for both the unmapped and mapped sections … … 156 146 * 157 147 */ 158 .global map_kernel_pse 159 map_kernel_pse: 160 /* Paging features */ 148 .global map_kernel 149 map_kernel: 161 150 movl %cr4, %ecx 162 151 orl $(1 << 4), %ecx /* PSE on */ … … 169 158 xorl %ebx, %ebx 170 159 171 floop _pse:160 floop: 172 161 movl $((1 << 7) | (1 << 1) | (1 << 0)), %eax 173 162 orl %ebx, %eax … … 180 169 incl %ecx 181 170 cmpl $512, %ecx 182 jl floop _pse171 jl floop 183 172 184 173 movl %esi, %cr3 … … 188 177 movl %ebx, %cr0 189 178 ret 190 191 /** Setup mapping for the kernel (non-PSE variant).192 *193 * Setup mapping for both the unmapped and mapped sections194 * of the kernel. For simplicity, we map the entire 4G space.195 *196 */197 .global map_kernel198 map_kernel:199 /* Paging features */200 movl %cr4, %ecx201 andl $(~(1 << 5)), %ecx /* PAE off */202 movl %ecx, %cr4203 204 call calc_kernel_end205 call find_mem_for_pt206 207 mov kernel_end, %esi208 mov free_area, %ecx209 210 cmpl %esi, %ecx211 jbe use_kernel_end212 213 mov %ecx, %esi214 215 /* Align address down to 4k */216 andl $(~4095), %esi217 218 use_kernel_end:219 220 /* Align address to 4k */221 addl $4095, %esi222 andl $(~4095), %esi223 224 /* Allocate space for page tables */225 movl %esi, pt_loc226 movl $ballocs, %edi227 andl $0x7fffffff, %edi228 229 movl %esi, (%edi)230 addl $4, %edi231 movl $(2 * 1024 * 1024), (%edi)232 233 /* Fill page tables */234 xorl %ecx, %ecx235 xorl %ebx, %ebx236 237 floop_pt:238 movl $((1 << 1) | (1 << 0)), %eax239 orl %ebx, %eax240 movl %eax, (%esi, %ecx, 4)241 addl $(4 * 1024), %ebx242 243 incl %ecx244 cmpl $(512 * 1024), %ecx245 246 jl floop_pt247 248 /* Fill page directory */249 movl $(page_directory + 0), %esi250 movl $(page_directory + 2048), %edi251 xorl %ecx, %ecx252 movl pt_loc, %ebx253 254 floop:255 movl $((1 << 1) | (1 << 0)), %eax256 orl %ebx, %eax257 258 /* Mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */259 movl %eax, (%esi, %ecx, 4)260 261 /* Mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */262 movl %eax, (%edi, %ecx, 4)263 addl $(4 * 1024), %ebx264 265 incl %ecx266 cmpl $512, %ecx267 268 jl floop269 270 movl %esi, %cr3271 272 movl %cr0, %ebx273 orl $(1 << 31), %ebx /* paging on */274 movl %ebx, %cr0275 276 ret277 278 /** Calculate unmapped address of the end of the kernel. */279 calc_kernel_end:280 movl $hardcoded_load_address, %edi281 andl $0x7fffffff, %edi282 movl (%edi), %esi283 andl $0x7fffffff, %esi284 285 movl $hardcoded_ktext_size, %edi286 andl $0x7fffffff, %edi287 addl (%edi), %esi288 andl $0x7fffffff, %esi289 290 movl $hardcoded_kdata_size, %edi291 andl $0x7fffffff, %edi292 addl (%edi), %esi293 andl $0x7fffffff, %esi294 movl %esi, kernel_end295 296 ret297 298 /** Find free 2M (+4k for alignment) region where to store page tables */299 find_mem_for_pt:300 /* Check if multiboot info is present */301 cmpl $MULTIBOOT_LOADER_MAGIC, grub_eax302 je check_multiboot_map303 304 ret305 306 check_multiboot_map:307 308 /* Copy address of the multiboot info to ebx */309 movl grub_ebx, %ebx310 311 /* Check if memory map flag is present */312 movl (%ebx), %edx313 andl $(1 << 6), %edx314 jnz use_multiboot_map315 316 ret317 318 use_multiboot_map:319 320 /* Copy address of the memory map to edx */321 movl 48(%ebx), %edx322 movl %edx, %ecx323 324 addl 44(%ebx), %ecx325 326 /* Find a free region at least 2M in size */327 check_memmap_loop:328 329 /* Is this a free region? */330 cmp $1, 20(%edx)331 jnz next_region332 333 /* Check size */334 cmp $0, 16(%edx)335 jnz next_region336 337 cmpl $(2 * 1024 * 1024 + 4 * 1024), 12(%edx)338 jbe next_region339 340 cmp $0, 8(%edx)341 jz found_region342 343 next_region:344 345 cmp %ecx, %edx346 jbe next_region_do347 348 ret349 350 next_region_do:351 352 addl (%edx), %edx353 addl $4, %edx354 jmp check_memmap_loop355 356 found_region:357 358 /* Use end of the found region */359 mov 4(%edx), %ecx360 add 12(%edx), %ecx361 sub $(2 * 1024 * 1024), %ecx362 mov %ecx, free_area363 364 ret365 179 366 180 /** Print string to EGA display (in light red) and halt. … … 707 521 grub_eax: 708 522 .long 0 523 709 524 grub_ebx: 710 525 .long 0 711 526 712 pt_loc: 713 .long 0 714 kernel_end: 715 .long 0 716 free_area: 717 .long 0 527 err_pse: 528 .asciz "Page Size Extension not supported. System halted." 718 529 719 530 status_prot: 720 531 .asciz "[prot] " 721 status_pse:722 .asciz "[pse] "723 status_non_pse:724 .asciz "[non_pse] "725 532 status_vesa_copy: 726 533 .asciz "[vesa_copy] " … … 731 538 status_prot2: 732 539 .asciz "[prot2] " 733 status_prot3:734 .asciz "[prot3] "735 540 status_main: 736 541 .asciz "[main] "
Note:
See TracChangeset
for help on using the changeset viewer.