Ignore:
File:
1 edited

Legend:

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

    rf66c203d r36df4109  
    2929 */
    3030
     31#include <abi/asmtool.h>
    3132#include <arch/boot/boot.h>
     33#include <arch/boot/memmap.h>
    3234#include <arch/mm/page.h>
    3335#include <arch/pm.h>
    3436#include <genarch/multiboot/multiboot.h>
    3537#include <arch/cpuid.h>
     38#include <arch/cpu.h>
    3639
    3740#define START_STACK  (BOOT_OFFSET - BOOT_STACK_SIZE)
     
    6164
    6265.align 4
    63 .global multiboot_image_start
    6466multiboot_header:
    6567        .long MULTIBOOT_HEADER_MAGIC
     
    7274        .long multiboot_image_start
    7375
    74 multiboot_image_start:
     76SYMBOL(multiboot_image_start)
    7577        cli
    7678        cld
     
    140142        pm2_status $status_prot3
    141143       
    142         /* Call arch_pre_main(multiboot_eax, multiboot_ebx) */
     144        /* Call ia32_pre_main(multiboot_eax, multiboot_ebx) */
    143145        pushl multiboot_ebx
    144146        pushl multiboot_eax
    145         call arch_pre_main
     147        call ia32_pre_main
    146148       
    147149        pm2_status $status_main
     
    162164 *
    163165 */
    164 .global map_kernel_pse
     166FUNCTION_BEGIN(map_kernel_pse)
    165167map_kernel_pse:
    166168        /* Paging features */
    167169        movl %cr4, %ecx
    168         orl $(1 << 4), %ecx      /* PSE on */
    169         andl $(~(1 << 5)), %ecx  /* PAE off */
     170        orl $CR4_PSE, %ecx      /* PSE on */
     171        andl $~CR4_PAE, %ecx    /* PAE off */
    170172        movl %ecx, %cr4
    171173       
     
    176178       
    177179        floop_pse:
    178                 movl $((1 << 7) | (1 << 1) | (1 << 0)), %eax
     180                movl $(PDE_4M | PDE_RW | PDE_P), %eax
    179181                orl %ebx, %eax
    180182                /* Mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */
     
    191193       
    192194        movl %cr0, %ebx
    193         orl $(1 << 31), %ebx  /* paging on */
     195        orl $CR0_PG, %ebx       /* paging on */
    194196        movl %ebx, %cr0
    195197        ret
     198FUNCTION_END(map_kernel_pse)
    196199
    197200/** Setup mapping for the kernel (non-PSE variant).
     
    201204 *
    202205 */
    203 .global map_kernel_non_pse
    204 map_kernel_non_pse:
     206FUNCTION_BEGIN(map_kernel_non_pse)
    205207        /* Paging features */
    206208        movl %cr4, %ecx
    207         andl $(~(1 << 5)), %ecx  /* PAE off */
     209        andl $~CR4_PAE, %ecx  /* PAE off */
    208210        movl %ecx, %cr4
    209211       
     
    220222               
    221223                /* Align address down to 4k */
    222                 andl $(~4095), %esi
     224                andl $(~(PAGE_SIZE - 1)), %esi
    223225               
    224226        use_kernel_end:
    225227               
    226228                /* Align address to 4k */
    227                 addl $4095, %esi
    228                 andl $(~4095), %esi
     229                addl $(PAGE_SIZE - 1), %esi
     230                andl $(~(PAGE_SIZE - 1)), %esi
    229231               
    230232                /* Allocate space for page tables */
    231233                movl %esi, pt_loc
    232                 movl $ballocs, %edi
    233                 andl $0x7fffffff, %edi
     234                movl $KA2PA(ballocs), %edi
    234235               
    235236                movl %esi, (%edi)
     
    242243               
    243244                floop_pt:
    244                         movl $((1 << 1) | (1 << 0)), %eax
     245                        movl $(PTE_RW | PTE_P), %eax
    245246                        orl %ebx, %eax
    246247                        movl %eax, (%esi, %ecx, 4)
    247                         addl $(4 * 1024), %ebx
     248                        addl $PAGE_SIZE, %ebx
    248249                       
    249250                        incl %ecx
     
    259260               
    260261                floop:
    261                         movl $((1 << 1) | (1 << 0)), %eax
     262                        movl $(PDE_RW | PDE_P), %eax
    262263                        orl %ebx, %eax
    263264                       
     
    267268                        /* Mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */
    268269                        movl %eax, (%edi, %ecx, 4)
    269                         addl $(4 * 1024), %ebx
     270                        addl $PAGE_SIZE, %ebx
    270271                       
    271272                        incl %ecx
     
    277278               
    278279                movl %cr0, %ebx
    279                 orl $(1 << 31), %ebx  /* paging on */
     280                orl $CR0_PG, %ebx  /* paging on */
    280281                movl %ebx, %cr0
    281282               
    282283                ret
     284FUNCTION_END(map_kernel_non_pse)
    283285
    284286/** Calculate unmapped address of the end of the kernel. */
    285287calc_kernel_end:
    286         movl $hardcoded_load_address, %edi
    287         andl $0x7fffffff, %edi
     288        movl $KA2PA(hardcoded_load_address), %edi
    288289        movl (%edi), %esi
    289         andl $0x7fffffff, %esi
    290        
    291         movl $hardcoded_ktext_size, %edi
    292         andl $0x7fffffff, %edi
     290        leal KA2PA(0)(%esi), %esi
     291       
     292        movl $KA2PA(hardcoded_ktext_size), %edi
    293293        addl (%edi), %esi
    294         andl $0x7fffffff, %esi
    295        
    296         movl $hardcoded_kdata_size, %edi
    297         andl $0x7fffffff, %edi
     294        leal KA2PA(0)(%esi), %esi
     295       
     296        movl $KA2PA(hardcoded_kdata_size), %edi
    298297        addl (%edi), %esi
    299         andl $0x7fffffff, %esi
     298        leal KA2PA(0)(%esi), %esi
    300299        movl %esi, kernel_end
    301300       
     
    317316                /* Check if memory map flag is present */
    318317                movl (%ebx), %edx
    319                 andl $(1 << 6), %edx
     318                andl $MULTIBOOT_INFO_FLAGS_MMAP, %edx
    320319                jnz use_multiboot_map
    321320                       
     
    325324               
    326325                /* Copy address of the memory map to edx */
    327                 movl 48(%ebx), %edx
     326                movl MULTIBOOT_INFO_OFFSET_MMAP_ADDR(%ebx), %edx
    328327                movl %edx, %ecx
    329328               
    330                 addl 44(%ebx), %ecx
     329                addl MULTIBOOT_INFO_OFFSET_MMAP_LENGTH(%ebx), %ecx
    331330               
    332331                /* Find a free region at least 2M in size */
     
    334333                       
    335334                        /* Is this a free region? */
    336                         cmp $1, 20(%edx)
     335                        cmpl $MEMMAP_MEMORY_AVAILABLE, MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_TYPE(%edx)
    337336                        jnz next_region
    338337                       
    339338                        /* Check size */
    340                         cmp $0, 16(%edx)
     339                        cmpl $0, MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_SIZE + 4(%edx)
    341340                        jnz next_region
    342                        
    343                         cmpl $(2 * 1024 * 1024 + 4 * 1024), 12(%edx)
     341                        cmpl $(2 * 1024 * 1024 + PAGE_SIZE), MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_SIZE(%edx)
    344342                        jbe next_region
    345343                       
    346                         cmp $0, 8(%edx)
     344                        cmpl $0, MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_BASE_ADDRESS + 4(%edx)
    347345                        jz found_region
    348346               
     
    356354                next_region_do:
    357355                       
    358                         addl (%edx), %edx
    359                         addl $4, %edx
     356                        addl MULTIBOOT_MEMMAP_OFFSET_SIZE(%edx), %edx
     357                        addl $MULTIBOOT_MEMMAP_SIZE_SIZE, %edx
    360358                        jmp check_memmap_loop
    361359                       
     
    363361                       
    364362                        /* Use end of the found region */
    365                         mov 4(%edx), %ecx
    366                         add 12(%edx), %ecx
     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
    367365                        sub $(2 * 1024 * 1024), %ecx
    368366                        mov %ecx, free_area
     
    707705        .space 4096, 0
    708706
    709 .global bootstrap_idtr
    710 bootstrap_idtr:
     707SYMBOL(bootstrap_idtr)
    711708        .word 0
    712709        .long 0
    713710
    714 .global bootstrap_gdtr
    715 bootstrap_gdtr:
     711SYMBOL(bootstrap_gdtr)
    716712        .word GDT_SELECTOR(GDT_ITEMS)
    717713        .long KA2PA(gdt)
    718714
    719 .global multiboot_eax
    720 multiboot_eax:
     715SYMBOL(multiboot_eax)
    721716        .long 0
    722717
    723 .global multiboot_ebx
    724 multiboot_ebx:
     718SYMBOL(multiboot_ebx)
    725719        .long 0
    726720
Note: See TracChangeset for help on using the changeset viewer.