Ignore:
File:
1 edited

Legend:

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

    r36df4109 rf66c203d  
    2929 */
    3030
    31 #include <abi/asmtool.h>
    3231#include <arch/boot/boot.h>
    33 #include <arch/boot/memmap.h>
    3432#include <arch/mm/page.h>
    3533#include <arch/pm.h>
    3634#include <genarch/multiboot/multiboot.h>
    3735#include <arch/cpuid.h>
    38 #include <arch/cpu.h>
    3936
    4037#define START_STACK  (BOOT_OFFSET - BOOT_STACK_SIZE)
     
    6461
    6562.align 4
     63.global multiboot_image_start
    6664multiboot_header:
    6765        .long MULTIBOOT_HEADER_MAGIC
     
    7472        .long multiboot_image_start
    7573
    76 SYMBOL(multiboot_image_start)
     74multiboot_image_start:
    7775        cli
    7876        cld
     
    142140        pm2_status $status_prot3
    143141       
    144         /* Call ia32_pre_main(multiboot_eax, multiboot_ebx) */
     142        /* Call arch_pre_main(multiboot_eax, multiboot_ebx) */
    145143        pushl multiboot_ebx
    146144        pushl multiboot_eax
    147         call ia32_pre_main
     145        call arch_pre_main
    148146       
    149147        pm2_status $status_main
     
    164162 *
    165163 */
    166 FUNCTION_BEGIN(map_kernel_pse)
     164.global map_kernel_pse
    167165map_kernel_pse:
    168166        /* Paging features */
    169167        movl %cr4, %ecx
    170         orl $CR4_PSE, %ecx      /* PSE on */
    171         andl $~CR4_PAE, %ecx    /* PAE off */
     168        orl $(1 << 4), %ecx      /* PSE on */
     169        andl $(~(1 << 5)), %ecx  /* PAE off */
    172170        movl %ecx, %cr4
    173171       
     
    178176       
    179177        floop_pse:
    180                 movl $(PDE_4M | PDE_RW | PDE_P), %eax
     178                movl $((1 << 7) | (1 << 1) | (1 << 0)), %eax
    181179                orl %ebx, %eax
    182180                /* Mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */
     
    193191       
    194192        movl %cr0, %ebx
    195         orl $CR0_PG, %ebx       /* paging on */
     193        orl $(1 << 31), %ebx  /* paging on */
    196194        movl %ebx, %cr0
    197195        ret
    198 FUNCTION_END(map_kernel_pse)
    199196
    200197/** Setup mapping for the kernel (non-PSE variant).
     
    204201 *
    205202 */
    206 FUNCTION_BEGIN(map_kernel_non_pse)
     203.global map_kernel_non_pse
     204map_kernel_non_pse:
    207205        /* Paging features */
    208206        movl %cr4, %ecx
    209         andl $~CR4_PAE, %ecx  /* PAE off */
     207        andl $(~(1 << 5)), %ecx  /* PAE off */
    210208        movl %ecx, %cr4
    211209       
     
    222220               
    223221                /* Align address down to 4k */
    224                 andl $(~(PAGE_SIZE - 1)), %esi
     222                andl $(~4095), %esi
    225223               
    226224        use_kernel_end:
    227225               
    228226                /* Align address to 4k */
    229                 addl $(PAGE_SIZE - 1), %esi
    230                 andl $(~(PAGE_SIZE - 1)), %esi
     227                addl $4095, %esi
     228                andl $(~4095), %esi
    231229               
    232230                /* Allocate space for page tables */
    233231                movl %esi, pt_loc
    234                 movl $KA2PA(ballocs), %edi
     232                movl $ballocs, %edi
     233                andl $0x7fffffff, %edi
    235234               
    236235                movl %esi, (%edi)
     
    243242               
    244243                floop_pt:
    245                         movl $(PTE_RW | PTE_P), %eax
     244                        movl $((1 << 1) | (1 << 0)), %eax
    246245                        orl %ebx, %eax
    247246                        movl %eax, (%esi, %ecx, 4)
    248                         addl $PAGE_SIZE, %ebx
     247                        addl $(4 * 1024), %ebx
    249248                       
    250249                        incl %ecx
     
    260259               
    261260                floop:
    262                         movl $(PDE_RW | PDE_P), %eax
     261                        movl $((1 << 1) | (1 << 0)), %eax
    263262                        orl %ebx, %eax
    264263                       
     
    268267                        /* Mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */
    269268                        movl %eax, (%edi, %ecx, 4)
    270                         addl $PAGE_SIZE, %ebx
     269                        addl $(4 * 1024), %ebx
    271270                       
    272271                        incl %ecx
     
    278277               
    279278                movl %cr0, %ebx
    280                 orl $CR0_PG, %ebx  /* paging on */
     279                orl $(1 << 31), %ebx  /* paging on */
    281280                movl %ebx, %cr0
    282281               
    283282                ret
    284 FUNCTION_END(map_kernel_non_pse)
    285283
    286284/** Calculate unmapped address of the end of the kernel. */
    287285calc_kernel_end:
    288         movl $KA2PA(hardcoded_load_address), %edi
     286        movl $hardcoded_load_address, %edi
     287        andl $0x7fffffff, %edi
    289288        movl (%edi), %esi
    290         leal KA2PA(0)(%esi), %esi
    291        
    292         movl $KA2PA(hardcoded_ktext_size), %edi
     289        andl $0x7fffffff, %esi
     290       
     291        movl $hardcoded_ktext_size, %edi
     292        andl $0x7fffffff, %edi
    293293        addl (%edi), %esi
    294         leal KA2PA(0)(%esi), %esi
    295        
    296         movl $KA2PA(hardcoded_kdata_size), %edi
     294        andl $0x7fffffff, %esi
     295       
     296        movl $hardcoded_kdata_size, %edi
     297        andl $0x7fffffff, %edi
    297298        addl (%edi), %esi
    298         leal KA2PA(0)(%esi), %esi
     299        andl $0x7fffffff, %esi
    299300        movl %esi, kernel_end
    300301       
     
    316317                /* Check if memory map flag is present */
    317318                movl (%ebx), %edx
    318                 andl $MULTIBOOT_INFO_FLAGS_MMAP, %edx
     319                andl $(1 << 6), %edx
    319320                jnz use_multiboot_map
    320321                       
     
    324325               
    325326                /* Copy address of the memory map to edx */
    326                 movl MULTIBOOT_INFO_OFFSET_MMAP_ADDR(%ebx), %edx
     327                movl 48(%ebx), %edx
    327328                movl %edx, %ecx
    328329               
    329                 addl MULTIBOOT_INFO_OFFSET_MMAP_LENGTH(%ebx), %ecx
     330                addl 44(%ebx), %ecx
    330331               
    331332                /* Find a free region at least 2M in size */
     
    333334                       
    334335                        /* Is this a free region? */
    335                         cmpl $MEMMAP_MEMORY_AVAILABLE, MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_TYPE(%edx)
     336                        cmp $1, 20(%edx)
    336337                        jnz next_region
    337338                       
    338339                        /* Check size */
    339                         cmpl $0, MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_SIZE + 4(%edx)
     340                        cmp $0, 16(%edx)
    340341                        jnz next_region
    341                         cmpl $(2 * 1024 * 1024 + PAGE_SIZE), MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_SIZE(%edx)
     342                       
     343                        cmpl $(2 * 1024 * 1024 + 4 * 1024), 12(%edx)
    342344                        jbe next_region
    343345                       
    344                         cmpl $0, MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_BASE_ADDRESS + 4(%edx)
     346                        cmp $0, 8(%edx)
    345347                        jz found_region
    346348               
     
    354356                next_region_do:
    355357                       
    356                         addl MULTIBOOT_MEMMAP_OFFSET_SIZE(%edx), %edx
    357                         addl $MULTIBOOT_MEMMAP_SIZE_SIZE, %edx
     358                        addl (%edx), %edx
     359                        addl $4, %edx
    358360                        jmp check_memmap_loop
    359361                       
     
    361363                       
    362364                        /* Use end of the found region */
    363                         mov MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_BASE_ADDRESS(%edx), %ecx
    364                         add MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_SIZE(%edx), %ecx
     365                        mov 4(%edx), %ecx
     366                        add 12(%edx), %ecx
    365367                        sub $(2 * 1024 * 1024), %ecx
    366368                        mov %ecx, free_area
     
    705707        .space 4096, 0
    706708
    707 SYMBOL(bootstrap_idtr)
     709.global bootstrap_idtr
     710bootstrap_idtr:
    708711        .word 0
    709712        .long 0
    710713
    711 SYMBOL(bootstrap_gdtr)
     714.global bootstrap_gdtr
     715bootstrap_gdtr:
    712716        .word GDT_SELECTOR(GDT_ITEMS)
    713717        .long KA2PA(gdt)
    714718
    715 SYMBOL(multiboot_eax)
     719.global multiboot_eax
     720multiboot_eax:
    716721        .long 0
    717722
    718 SYMBOL(multiboot_ebx)
     723.global multiboot_ebx
     724multiboot_ebx:
    719725        .long 0
    720726
Note: See TracChangeset for help on using the changeset viewer.