Changes in kernel/arch/ia32/src/boot/boot.S [fb45c7b:1d3d2cf] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/ia32/src/boot/boot.S
rfb45c7b r1d3d2cf 2 2 * Copyright (c) 2001 Jakub Jermar 3 3 * Copyright (c) 2005 Martin Decky 4 * Copyright (c) 2011 Martin Sucha5 4 * All rights reserved. 6 5 * … … 98 97 pm_status $status_prot 99 98 100 #include "vesa_prot.inc"101 102 #ifndef PROCESSOR_i486103 104 pm_status $status_prot2105 106 99 movl $(INTEL_CPUID_LEVEL), %eax 107 100 cpuid … … 112 105 cpuid 113 106 bt $(INTEL_PSE), %edx 114 jnc pse_unsupported 115 116 /* Map kernel and turn paging on */ 117 pm_status $status_pse 118 call map_kernel_pse 119 jmp stack_init 120 121 #endif /* PROCESSOR_i486 */ 107 jc pse_supported 122 108 123 109 pse_unsupported: 124 110 125 /* Map kernel and turn paging on */ 126 pm_status $status_non_pse 127 call map_kernel_non_pse 128 129 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 130 119 131 120 /* Create the first stack frame */ … … 133 122 movl %esp, %ebp 134 123 135 pm2_status $status_prot 3124 pm2_status $status_prot2 136 125 137 126 /* Call arch_pre_main(grub_eax, grub_ebx) */ … … 151 140 jmp hlt0 152 141 153 /** Setup mapping for the kernel (PSE variant)142 /** Setup mapping for the kernel. 154 143 * 155 144 * Setup mapping for both the unmapped and mapped sections … … 157 146 * 158 147 */ 159 .global map_kernel_pse 160 map_kernel_pse: 161 /* Paging features */ 148 .global map_kernel 149 map_kernel: 162 150 movl %cr4, %ecx 163 151 orl $(1 << 4), %ecx /* PSE on */ … … 170 158 xorl %ebx, %ebx 171 159 172 floop _pse:160 floop: 173 161 movl $((1 << 7) | (1 << 1) | (1 << 0)), %eax 174 162 orl %ebx, %eax … … 181 169 incl %ecx 182 170 cmpl $512, %ecx 183 jl floop _pse171 jl floop 184 172 185 173 movl %esi, %cr3 … … 189 177 movl %ebx, %cr0 190 178 ret 191 192 /** Setup mapping for the kernel (non-PSE variant).193 *194 * Setup mapping for both the unmapped and mapped sections195 * of the kernel. For simplicity, we map the entire 4G space.196 *197 */198 map_kernel_non_pse: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.