Changeset 948e85b in mainline
- Timestamp:
- 2018-11-13T20:22:20Z (6 years ago)
- Children:
- 33ef2f2
- Parents:
- 87db879
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-10-24 15:05:32)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-11-13 20:22:20)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/ia32/src/boot/multiboot.S
r87db879 r948e85b 220 220 movl %ecx, %cr4 221 221 222 call calc_kernel_end 223 call find_mem_for_pt 224 225 mov kernel_end, %esi 226 mov free_area, %ecx 227 228 cmpl %esi, %ecx 229 jbe use_kernel_end 230 231 mov %ecx, %esi 232 233 /* Align address down to 4k */ 234 andl $(~(PAGE_SIZE - 1)), %esi 235 236 use_kernel_end: 237 238 /* Align address to 4k */ 239 addl $(PAGE_SIZE - 1), %esi 240 andl $(~(PAGE_SIZE - 1)), %esi 241 242 /* Allocate space for page tables */ 243 movl %esi, pt_loc 244 movl $KA2PA(ballocs), %edi 245 246 movl %esi, (%edi) 247 addl $4, %edi 248 movl $(2 * 1024 * 1024), (%edi) 249 250 /* Fill page tables */ 251 xorl %ecx, %ecx 252 xorl %ebx, %ebx 253 254 floop_pt: 255 movl $(PTE_RW | PTE_P), %eax 256 orl %ebx, %eax 257 movl %eax, (%esi, %ecx, 4) 258 addl $PAGE_SIZE, %ebx 259 260 incl %ecx 261 cmpl $(512 * 1024), %ecx 262 263 jl floop_pt 264 265 /* Fill page directory */ 266 movl $(page_directory + 0), %esi 267 movl $(page_directory + 2048), %edi 268 xorl %ecx, %ecx 269 movl pt_loc, %ebx 270 271 floop: 272 movl $(PDE_RW | PDE_P), %eax 273 orl %ebx, %eax 274 275 /* Mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */ 276 movl %eax, (%esi, %ecx, 4) 277 278 /* Mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */ 279 movl %eax, (%edi, %ecx, 4) 280 addl $PAGE_SIZE, %ebx 281 282 incl %ecx 283 cmpl $512, %ecx 284 285 jl floop 286 287 movl %esi, %cr3 288 289 movl %cr0, %ebx 290 orl $CR0_PG, %ebx /* paging on */ 291 movl %ebx, %cr0 292 293 ret 222 /* Allocate space for page tables */ 223 // TODO: we shouldn't need to put this allocation in ballocs, 224 // since it's static. 225 movl $KA2PA(ballocs), %edi 226 movl $page_tables, 0(%edi) 227 movl $(2 * 1024 * 1024), 4(%edi) 228 229 /* Fill page tables */ 230 xorl %ecx, %ecx 231 xorl %ebx, %ebx 232 mov $page_tables, %esi 233 234 floop_pt: 235 movl $(PTE_RW | PTE_P), %eax 236 orl %ebx, %eax 237 movl %eax, (%esi, %ecx, 4) 238 addl $PAGE_SIZE, %ebx 239 240 incl %ecx 241 cmpl $(512 * 1024), %ecx 242 243 jl floop_pt 244 245 /* Fill page directory */ 246 movl $(page_directory + 0), %esi 247 movl $(page_directory + 2048), %edi 248 xorl %ecx, %ecx 249 movl $page_tables, %ebx 250 251 floop: 252 movl $(PDE_RW | PDE_P), %eax 253 orl %ebx, %eax 254 255 /* Mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */ 256 movl %eax, (%esi, %ecx, 4) 257 258 /* Mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */ 259 movl %eax, (%edi, %ecx, 4) 260 addl $PAGE_SIZE, %ebx 261 262 incl %ecx 263 cmpl $512, %ecx 264 265 jl floop 266 267 movl %esi, %cr3 268 269 movl %cr0, %ebx 270 orl $CR0_PG, %ebx /* paging on */ 271 movl %ebx, %cr0 272 273 ret 294 274 FUNCTION_END(map_kernel_non_pse) 295 296 /** Calculate unmapped address of the end of the kernel. */297 calc_kernel_end:298 movl $KA2PA(kdata_end), %edi299 movl %edi, kernel_end300 ret301 302 // TODO: remove this cruft303 304 /** Find free 2M (+4k for alignment) region where to store page tables */305 find_mem_for_pt:306 /* Check if multiboot info is present */307 cmpl $MULTIBOOT_LOADER_MAGIC, multiboot_eax308 je check_multiboot_map309 310 ret311 312 check_multiboot_map:313 314 /* Copy address of the multiboot info to ebx */315 movl multiboot_ebx, %ebx316 317 /* Check if memory map flag is present */318 movl (%ebx), %edx319 andl $MULTIBOOT_INFO_FLAGS_MMAP, %edx320 jnz use_multiboot_map321 322 ret323 324 use_multiboot_map:325 326 /* Copy address of the memory map to edx */327 movl MULTIBOOT_INFO_OFFSET_MMAP_ADDR(%ebx), %edx328 movl %edx, %ecx329 330 addl MULTIBOOT_INFO_OFFSET_MMAP_LENGTH(%ebx), %ecx331 332 /* Find a free region at least 2M in size */333 check_memmap_loop:334 335 /* Is this a free region? */336 cmpl $MEMMAP_MEMORY_AVAILABLE, MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_TYPE(%edx)337 jnz next_region338 339 /* Check size */340 cmpl $0, MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_SIZE + 4(%edx)341 jnz next_region342 cmpl $(2 * 1024 * 1024 + PAGE_SIZE), MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_SIZE(%edx)343 jbe next_region344 345 cmpl $0, MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_BASE_ADDRESS + 4(%edx)346 jz found_region347 348 next_region:349 350 cmp %ecx, %edx351 jbe next_region_do352 353 ret354 355 next_region_do:356 357 addl MULTIBOOT_MEMMAP_OFFSET_SIZE(%edx), %edx358 addl $MULTIBOOT_MEMMAP_SIZE_SIZE, %edx359 jmp check_memmap_loop360 361 found_region:362 363 /* Use end of the found region */364 mov MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_BASE_ADDRESS(%edx), %ecx365 add MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_SIZE(%edx), %ecx366 sub $(2 * 1024 * 1024), %ecx367 mov %ecx, free_area368 369 ret370 275 371 276 /** Print string to EGA display (in light green). … … 600 505 601 506 .align 4096 507 page_tables: 508 .space 2*1024*1024; 509 510 .align 4096 602 511 page_directory: 603 512 .space 4096, 0 … … 611 520 612 521 SYMBOL(multiboot_ebx) 613 .long 0614 615 pt_loc:616 .long 0617 kernel_end:618 .long 0619 free_area:620 522 .long 0 621 523
Note:
See TracChangeset
for help on using the changeset viewer.