Ignore:
Timestamp:
2018-11-13T20:22:20Z (5 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
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)
Message:

Allocate non-PSE page tables statically

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/ia32/src/boot/multiboot.S

    r87db879 r948e85b  
    220220        movl %ecx, %cr4
    221221
    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
    294274FUNCTION_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), %edi
    299         movl %edi, kernel_end
    300         ret
    301 
    302 // TODO: remove this cruft
    303 
    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_eax
    308         je check_multiboot_map
    309 
    310                 ret
    311 
    312         check_multiboot_map:
    313 
    314                 /* Copy address of the multiboot info to ebx */
    315                 movl multiboot_ebx, %ebx
    316 
    317                 /* Check if memory map flag is present */
    318                 movl (%ebx), %edx
    319                 andl $MULTIBOOT_INFO_FLAGS_MMAP, %edx
    320                 jnz use_multiboot_map
    321 
    322                         ret
    323 
    324         use_multiboot_map:
    325 
    326                 /* Copy address of the memory map to edx */
    327                 movl MULTIBOOT_INFO_OFFSET_MMAP_ADDR(%ebx), %edx
    328                 movl %edx, %ecx
    329 
    330                 addl MULTIBOOT_INFO_OFFSET_MMAP_LENGTH(%ebx), %ecx
    331 
    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_region
    338 
    339                         /* Check size */
    340                         cmpl $0, MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_SIZE + 4(%edx)
    341                         jnz next_region
    342                         cmpl $(2 * 1024 * 1024 + PAGE_SIZE), MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_SIZE(%edx)
    343                         jbe next_region
    344 
    345                         cmpl $0, MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_BASE_ADDRESS + 4(%edx)
    346                         jz found_region
    347 
    348                 next_region:
    349 
    350                         cmp %ecx, %edx
    351                         jbe next_region_do
    352 
    353                                 ret
    354 
    355                 next_region_do:
    356 
    357                         addl MULTIBOOT_MEMMAP_OFFSET_SIZE(%edx), %edx
    358                         addl $MULTIBOOT_MEMMAP_SIZE_SIZE, %edx
    359                         jmp check_memmap_loop
    360 
    361                 found_region:
    362 
    363                         /* Use end of the found region */
    364                         mov MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_BASE_ADDRESS(%edx), %ecx
    365                         add MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_SIZE(%edx), %ecx
    366                         sub $(2 * 1024 * 1024), %ecx
    367                         mov %ecx, free_area
    368 
    369                         ret
    370275
    371276/** Print string to EGA display (in light green).
     
    600505
    601506.align 4096
     507page_tables:
     508        .space 2*1024*1024;
     509
     510.align 4096
    602511page_directory:
    603512        .space 4096, 0
     
    611520
    612521SYMBOL(multiboot_ebx)
    613         .long 0
    614 
    615 pt_loc:
    616         .long 0
    617 kernel_end:
    618         .long 0
    619 free_area:
    620522        .long 0
    621523
Note: See TracChangeset for help on using the changeset viewer.