Changeset b112055 in mainline for kernel/arch/ia32/src/boot/boot.S


Ignore:
Timestamp:
2011-08-17T19:10:44Z (13 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f4fa6d9
Parents:
16dc887
Message:

Boot ia32 without Page Size Extensions

File:
1 edited

Legend:

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

    r16dc887 rb112055  
    140140                jmp hlt0
    141141
     142/** Calculate unmapped address of the end of the kernel. */
     143calc_end_of_kernel:
     144        movl $hardcoded_load_address, %edi
     145        andl $0x7fffffff, %edi
     146        movl (%edi), %esi
     147        andl $0x7fffffff, %esi
     148       
     149        movl $hardcoded_ktext_size, %edi
     150        andl $0x7fffffff, %edi
     151        addl (%edi), %esi
     152        andl $0x7fffffff, %esi
     153       
     154        movl $hardcoded_kdata_size, %edi
     155        andl $0x7fffffff, %edi
     156        addl (%edi), %esi
     157        andl $0x7fffffff, %esi
     158        movl %esi, end_of_kernel
     159        ret
     160
     161/** Find free 2M (+4k for alignment) region where to store page tables */
     162find_mem_for_pt:
     163        /* Check if multiboot info is present */
     164        cmpl $0x2BADB002, grub_eax
     165        je check_multiboot_map
     166        ret
     167check_multiboot_map:
     168        /* Copy address of the multiboot info to ebx */
     169        movl grub_ebx, %ebx
     170        /* Check if memory map flag is present */
     171        movl (%ebx), %edx
     172        andl $(1 << 6), %edx
     173        jnz use_multiboot_map
     174        ret
     175use_multiboot_map:
     176        /* Copy address of the memory map to edx */
     177        movl 48(%ebx), %edx
     178        movl %edx, %ecx
     179        addl 44(%ebx), %ecx
     180        /* Find a free region at least 2M in size */
     181        check_memmap_loop:
     182                /* Is this a free region? */
     183                cmp $1, 20(%edx)
     184                jnz next_region
     185                /* Check size */
     186                cmp $0, 16(%edx)
     187                jnz next_region
     188                cmpl $(2 * 1024 * 1024 + 4 * 1024), 12(%edx)
     189                jbe next_region
     190                cmp $0, 8(%edx)
     191                jz found_region
     192        next_region:
     193                cmp %ecx, %edx
     194                jbe next_region_do
     195                ret
     196        next_region_do:
     197                addl (%edx), %edx
     198                addl $4, %edx
     199                jmp check_memmap_loop
     200        found_region:
     201                /* Use end of the found region */
     202                mov 4(%edx), %ecx
     203                add 12(%edx), %ecx
     204                sub $(2 * 1024 * 1024), %ecx
     205                mov %ecx, free_area
     206        ret
     207               
     208
    142209/** Setup mapping for the kernel.
    143210 *
     
    148215.global map_kernel
    149216map_kernel:
     217        /* Paging features */
    150218        movl %cr4, %ecx
    151         orl $(1 << 4), %ecx      /* PSE on */
    152219        andl $(~(1 << 5)), %ecx  /* PAE off */
    153220        movl %ecx, %cr4
    154221       
     222        call calc_end_of_kernel
     223        call find_mem_for_pt
     224        mov end_of_kernel, %esi
     225        mov free_area, %ecx
     226        cmpl %esi, %ecx
     227        jbe use_end_of_kernel
     228        mov %ecx, %esi
     229        /* Align address down to 4k */
     230        andl $(~4095), %esi
     231use_end_of_kernel:
     232       
     233        /* Align address to 4k */
     234        addl $4095, %esi
     235        andl $(~4095), %esi
     236       
     237        /* Allocate space for page tables*/     
     238        movl %esi, pt_loc
     239        movl $ballocs, %edi
     240        andl $0x7fffffff, %edi
     241        movl %esi, (%edi)
     242        addl $4, %edi
     243        movl $(2*1024*1024), (%edi)
     244       
     245        /* Fill page tables */
     246        xorl %ecx, %ecx
     247        xorl %ebx, %ebx
     248       
     249        floop_pt:
     250                movl $((1 << 1) | (1 << 0)), %eax
     251                orl %ebx, %eax
     252                movl %eax, (%esi, %ecx, 4)
     253                addl $(4 * 1024), %ebx
     254               
     255                incl %ecx
     256                cmpl $(512 * 1024), %ecx
     257                jl floop_pt
     258       
     259        /* Fill page directory */
    155260        movl $(page_directory + 0), %esi
    156261        movl $(page_directory + 2048), %edi
    157262        xorl %ecx, %ecx
    158         xorl %ebx, %ebx
     263        movl pt_loc, %ebx
    159264       
    160265        floop:
    161                 movl $((1 << 7) | (1 << 1) | (1 << 0)), %eax
     266                movl $((1 << 1) | (1 << 0)), %eax
    162267                orl %ebx, %eax
    163268                /* Mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */
     
    165270                /* Mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */
    166271                movl %eax, (%edi, %ecx, 4)
    167                 addl $(4 * 1024 * 1024), %ebx
     272                addl $(4 * 1024), %ebx
    168273               
    169274                incl %ecx
     
    523628
    524629grub_ebx:
     630        .long 0
     631
     632pt_loc:
     633        .long 0
     634end_of_kernel:
     635        .long 0
     636free_area:
    525637        .long 0
    526638
Note: See TracChangeset for help on using the changeset viewer.