Ignore:
File:
1 edited

Legend:

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

    re02bfb4 ra35b458  
    7777        cli
    7878        cld
    79        
     79
    8080        /* Initialize stack pointer */
    8181        movl $START_STACK, %esp
    82        
     82
    8383        /*
    8484         * Initialize Global Descriptor Table and
     
    8787        lgdtl bootstrap_gdtr
    8888        lidtl bootstrap_idtr
    89        
     89
    9090        /* Kernel data + stack */
    9191        movw $GDT_SELECTOR(KDATA_DES), %cx
     
    9595        movw %cx, %ds
    9696        movw %cx, %ss
    97        
     97
    9898        jmpl $GDT_SELECTOR(KTEXT_DES), $multiboot_meeting_point
    9999        multiboot_meeting_point:
    100        
     100
    101101        /* Save multiboot arguments */
    102102        movl %eax, multiboot_eax
    103103        movl %ebx, multiboot_ebx
    104        
     104
    105105        pm_status $status_prot
    106        
     106
    107107#include "vesa_prot.inc"
    108        
     108
    109109#ifndef PROCESSOR_i486
    110        
     110
    111111        pm_status $status_prot2
    112        
     112
    113113        movl $(INTEL_CPUID_LEVEL), %eax
    114114        cpuid
    115115        cmp $0x0, %eax  /* any function > 0? */
    116116        jbe pse_unsupported
    117        
     117
    118118        movl $(INTEL_CPUID_STANDARD), %eax
    119119        cpuid
    120120        bt $(INTEL_PSE), %edx
    121121        jnc pse_unsupported
    122                
     122
    123123                /* Map kernel and turn paging on */
    124124                pm_status $status_pse
    125125                call map_kernel_pse
    126126                jmp stack_init
    127        
     127
    128128#endif /* PROCESSOR_i486 */
    129        
     129
    130130        pse_unsupported:
    131                
     131
    132132                /* Map kernel and turn paging on */
    133133                pm_status $status_non_pse
    134134                call map_kernel_non_pse
    135        
     135
    136136        stack_init:
    137        
     137
    138138        /* Create the first stack frame */
    139139        pushl $0
    140140        movl %esp, %ebp
    141        
     141
    142142        pm2_status $status_prot3
    143        
     143
    144144        /* Call ia32_pre_main(multiboot_eax, multiboot_ebx) */
    145145        pushl multiboot_ebx
    146146        pushl multiboot_eax
    147147        call ia32_pre_main
    148        
     148
    149149        pm2_status $status_main
    150        
     150
    151151        /* Call main_bsp() */
    152152        call main_bsp
    153        
     153
    154154        /* Not reached */
    155155        cli
     
    170170        andl $~CR4_PAE, %ecx    /* PAE off */
    171171        movl %ecx, %cr4
    172        
     172
    173173        movl $(page_directory + 0), %esi
    174174        movl $(page_directory + 2048), %edi
    175175        xorl %ecx, %ecx
    176176        xorl %ebx, %ebx
    177        
     177
    178178        floop_pse:
    179179                movl $(PDE_4M | PDE_RW | PDE_P), %eax
     
    184184                movl %eax, (%edi, %ecx, 4)
    185185                addl $(4 * 1024 * 1024), %ebx
    186                
     186
    187187                incl %ecx
    188188                cmpl $512, %ecx
    189189                jl floop_pse
    190        
     190
    191191        movl %esi, %cr3
    192        
     192
    193193        movl %cr0, %ebx
    194194        orl $CR0_PG, %ebx       /* paging on */
     
    208208        andl $~CR4_PAE, %ecx  /* PAE off */
    209209        movl %ecx, %cr4
    210        
     210
    211211        call calc_kernel_end
    212212        call find_mem_for_pt
    213        
     213
    214214        mov kernel_end, %esi
    215215        mov free_area, %ecx
    216        
     216
    217217        cmpl %esi, %ecx
    218218        jbe use_kernel_end
    219                
     219
    220220                mov %ecx, %esi
    221                
     221
    222222                /* Align address down to 4k */
    223223                andl $(~(PAGE_SIZE - 1)), %esi
    224                
     224
    225225        use_kernel_end:
    226                
     226
    227227                /* Align address to 4k */
    228228                addl $(PAGE_SIZE - 1), %esi
    229229                andl $(~(PAGE_SIZE - 1)), %esi
    230                
     230
    231231                /* Allocate space for page tables */
    232232                movl %esi, pt_loc
    233233                movl $KA2PA(ballocs), %edi
    234                
     234
    235235                movl %esi, (%edi)
    236236                addl $4, %edi
    237237                movl $(2 * 1024 * 1024), (%edi)
    238                
     238
    239239                /* Fill page tables */
    240240                xorl %ecx, %ecx
    241241                xorl %ebx, %ebx
    242                
     242
    243243                floop_pt:
    244244                        movl $(PTE_RW | PTE_P), %eax
     
    246246                        movl %eax, (%esi, %ecx, 4)
    247247                        addl $PAGE_SIZE, %ebx
    248                        
     248
    249249                        incl %ecx
    250250                        cmpl $(512 * 1024), %ecx
    251                        
     251
    252252                        jl floop_pt
    253                
     253
    254254                /* Fill page directory */
    255255                movl $(page_directory + 0), %esi
     
    257257                xorl %ecx, %ecx
    258258                movl pt_loc, %ebx
    259                
     259
    260260                floop:
    261261                        movl $(PDE_RW | PDE_P), %eax
    262262                        orl %ebx, %eax
    263                        
     263
    264264                        /* Mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */
    265265                        movl %eax, (%esi, %ecx, 4)
    266                        
     266
    267267                        /* Mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M */
    268268                        movl %eax, (%edi, %ecx, 4)
    269269                        addl $PAGE_SIZE, %ebx
    270                        
     270
    271271                        incl %ecx
    272272                        cmpl $512, %ecx
    273                        
     273
    274274                        jl floop
    275                
     275
    276276                movl %esi, %cr3
    277                
     277
    278278                movl %cr0, %ebx
    279279                orl $CR0_PG, %ebx  /* paging on */
    280280                movl %ebx, %cr0
    281                
     281
    282282                ret
    283283FUNCTION_END(map_kernel_non_pse)
     
    288288        movl (%edi), %esi
    289289        leal KA2PA(0)(%esi), %esi
    290        
     290
    291291        movl $KA2PA(hardcoded_ktext_size), %edi
    292292        addl (%edi), %esi
    293293        leal KA2PA(0)(%esi), %esi
    294        
     294
    295295        movl $KA2PA(hardcoded_kdata_size), %edi
    296296        addl (%edi), %esi
    297297        leal KA2PA(0)(%esi), %esi
    298298        movl %esi, kernel_end
    299        
     299
    300300        ret
    301301
     
    305305        cmpl $MULTIBOOT_LOADER_MAGIC, multiboot_eax
    306306        je check_multiboot_map
    307                
     307
    308308                ret
    309        
     309
    310310        check_multiboot_map:
    311                
     311
    312312                /* Copy address of the multiboot info to ebx */
    313313                movl multiboot_ebx, %ebx
    314                
     314
    315315                /* Check if memory map flag is present */
    316316                movl (%ebx), %edx
    317317                andl $MULTIBOOT_INFO_FLAGS_MMAP, %edx
    318318                jnz use_multiboot_map
    319                        
     319
    320320                        ret
    321                
     321
    322322        use_multiboot_map:
    323                
     323
    324324                /* Copy address of the memory map to edx */
    325325                movl MULTIBOOT_INFO_OFFSET_MMAP_ADDR(%ebx), %edx
    326326                movl %edx, %ecx
    327                
     327
    328328                addl MULTIBOOT_INFO_OFFSET_MMAP_LENGTH(%ebx), %ecx
    329                
     329
    330330                /* Find a free region at least 2M in size */
    331331                check_memmap_loop:
    332                        
     332
    333333                        /* Is this a free region? */
    334334                        cmpl $MEMMAP_MEMORY_AVAILABLE, MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_TYPE(%edx)
    335335                        jnz next_region
    336                        
     336
    337337                        /* Check size */
    338338                        cmpl $0, MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_SIZE + 4(%edx)
     
    340340                        cmpl $(2 * 1024 * 1024 + PAGE_SIZE), MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_SIZE(%edx)
    341341                        jbe next_region
    342                        
     342
    343343                        cmpl $0, MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_BASE_ADDRESS + 4(%edx)
    344344                        jz found_region
    345                
     345
    346346                next_region:
    347                        
     347
    348348                        cmp %ecx, %edx
    349349                        jbe next_region_do
    350                        
     350
    351351                                ret
    352                
     352
    353353                next_region_do:
    354                        
     354
    355355                        addl MULTIBOOT_MEMMAP_OFFSET_SIZE(%edx), %edx
    356356                        addl $MULTIBOOT_MEMMAP_SIZE_SIZE, %edx
    357357                        jmp check_memmap_loop
    358                        
     358
    359359                found_region:
    360                        
     360
    361361                        /* Use end of the found region */
    362362                        mov MULTIBOOT_MEMMAP_OFFSET_MM_INFO + E820MEMMAP_OFFSET_BASE_ADDRESS(%edx), %ecx
     
    364364                        sub $(2 * 1024 * 1024), %ecx
    365365                        mov %ecx, free_area
    366                        
     366
    367367                        ret
    368368
     
    381381        movl $0xb8000, %edi  /* base of EGA text mode memory */
    382382        xorl %eax, %eax
    383        
     383
    384384        /* Read bits 8 - 15 of the cursor address */
    385385        movw $0x3d4, %dx
    386386        movb $0xe, %al
    387387        outb %al, %dx
    388        
     388
    389389        movw $0x3d5, %dx
    390390        inb %dx, %al
    391391        shl $8, %ax
    392        
     392
    393393        /* Read bits 0 - 7 of the cursor address */
    394394        movw $0x3d4, %dx
    395395        movb $0xf, %al
    396396        outb %al, %dx
    397        
     397
    398398        movw $0x3d5, %dx
    399399        inb %dx, %al
    400        
     400
    401401        /* Sanity check for the cursor on screen */
    402402        cmp $2000, %ax
    403403        jb err_cursor_ok
    404        
     404
    405405                movw $1998, %ax
    406        
     406
    407407        err_cursor_ok:
    408        
     408
    409409        movw %ax, %bx
    410410        shl $1, %eax
    411411        addl %eax, %edi
    412        
     412
    413413        err_ploop:
    414414                lodsb
    415                
     415
    416416                cmp $0, %al
    417417                je err_ploop_end
    418                
     418
    419419                movb $0x0c, %ah  /* black background, light red foreground */
    420420                stosw
    421                
     421
    422422                /* Sanity check for the cursor on the last line */
    423423                inc %bx
    424424                cmp $2000, %bx
    425425                jb err_ploop
    426                
     426
    427427                /* Scroll the screen (24 rows) */
    428428                movl %esi, %edx
     
    431431                movl $960, %ecx
    432432                rep movsl
    433                
     433
    434434                /* Clear the 24th row */
    435435                xorl %eax, %eax
    436436                movl $40, %ecx
    437437                rep stosl
    438                
     438
    439439                /* Go to row 24 */
    440440                movl %edx, %esi
    441441                movl $0xb8f00, %edi
    442442                movw $1920, %bx
    443                
     443
    444444                jmp err_ploop
    445445        err_ploop_end:
    446        
     446
    447447        /* Write bits 8 - 15 of the cursor address */
    448448        movw $0x3d4, %dx
    449449        movb $0xe, %al
    450450        outb %al, %dx
    451        
     451
    452452        movw $0x3d5, %dx
    453453        movb %bh, %al
    454454        outb %al, %dx
    455        
     455
    456456        /* Write bits 0 - 7 of the cursor address */
    457457        movw $0x3d4, %dx
    458458        movb $0xf, %al
    459459        outb %al, %dx
    460        
     460
    461461        movw $0x3d5, %dx
    462462        movb %bl, %al
    463463        outb %al, %dx
    464        
     464
    465465        cli
    466466        hlt1:
     
    486486        pushl %edx
    487487        pushl %edi
    488        
     488
    489489        movl $0xb8000, %edi  /* base of EGA text mode memory */
    490490        xorl %eax, %eax
    491        
     491
    492492        /* Read bits 8 - 15 of the cursor address */
    493493        movw $0x3d4, %dx
    494494        movb $0xe, %al
    495495        outb %al, %dx
    496        
     496
    497497        movw $0x3d5, %dx
    498498        inb %dx, %al
    499499        shl $8, %ax
    500        
     500
    501501        /* Read bits 0 - 7 of the cursor address */
    502502        movw $0x3d4, %dx
    503503        movb $0xf, %al
    504504        outb %al, %dx
    505        
     505
    506506        movw $0x3d5, %dx
    507507        inb %dx, %al
    508        
     508
    509509        /* Sanity check for the cursor on screen */
    510510        cmp $2000, %ax
    511511        jb pm_puts_cursor_ok
    512        
     512
    513513                movw $1998, %ax
    514        
     514
    515515        pm_puts_cursor_ok:
    516        
     516
    517517        movw %ax, %bx
    518518        shl $1, %eax
    519519        addl %eax, %edi
    520        
     520
    521521        pm_puts_ploop:
    522522                lodsb
    523                
     523
    524524                cmp $0, %al
    525525                je pm_puts_ploop_end
    526                
     526
    527527                movb $0x0a, %ah  /* black background, light green foreground */
    528528                stosw
    529                
     529
    530530                /* Sanity check for the cursor on the last line */
    531531                inc %bx
    532532                cmp $2000, %bx
    533533                jb pm_puts_ploop
    534                
     534
    535535                /* Scroll the screen (24 rows) */
    536536                movl %esi, %edx
     
    539539                movl $960, %ecx
    540540                rep movsl
    541                
     541
    542542                /* Clear the 24th row */
    543543                xorl %eax, %eax
    544544                movl $40, %ecx
    545545                rep stosl
    546                
     546
    547547                /* Go to row 24 */
    548548                movl %edx, %esi
    549549                movl $0xb8f00, %edi
    550550                movw $1920, %bx
    551                
     551
    552552                jmp pm_puts_ploop
    553553        pm_puts_ploop_end:
    554        
     554
    555555        /* Write bits 8 - 15 of the cursor address */
    556556        movw $0x3d4, %dx
    557557        movb $0xe, %al
    558558        outb %al, %dx
    559        
     559
    560560        movw $0x3d5, %dx
    561561        movb %bh, %al
    562562        outb %al, %dx
    563        
     563
    564564        /* Write bits 0 - 7 of the cursor address */
    565565        movw $0x3d4, %dx
    566566        movb $0xf, %al
    567567        outb %al, %dx
    568        
     568
    569569        movw $0x3d5, %dx
    570570        movb %bl, %al
    571571        outb %al, %dx
    572        
     572
    573573        popl %edi
    574574        popl %edx
     
    576576        popl %ebx
    577577        popl %eax
    578        
     578
    579579        ret
    580580
     
    591591 */
    592592early_puts:
    593        
     593
    594594#if ((defined(CONFIG_EGA)) && (!defined(CONFIG_FB)))
    595        
     595
    596596        /* Prologue, save preserved registers */
    597597        pushl %ebp
     
    600600        pushl %esi
    601601        pushl %edi
    602        
     602
    603603        movl 0x08(%ebp), %esi
    604604        movl $(PA2KA(0xb8000)), %edi  /* base of EGA text mode memory */
    605605        xorl %eax, %eax
    606        
     606
    607607        /* Read bits 8 - 15 of the cursor address */
    608608        movw $0x3d4, %dx
    609609        movb $0xe, %al
    610610        outb %al, %dx
    611        
     611
    612612        movw $0x3d5, %dx
    613613        inb %dx, %al
    614614        shl $8, %ax
    615        
     615
    616616        /* Read bits 0 - 7 of the cursor address */
    617617        movw $0x3d4, %dx
    618618        movb $0xf, %al
    619619        outb %al, %dx
    620        
     620
    621621        movw $0x3d5, %dx
    622622        inb %dx, %al
    623        
     623
    624624        /* Sanity check for the cursor on screen */
    625625        cmp $2000, %ax
    626626        jb early_puts_cursor_ok
    627        
     627
    628628                movw $1998, %ax
    629        
     629
    630630        early_puts_cursor_ok:
    631        
     631
    632632        movw %ax, %bx
    633633        shl $1, %eax
    634634        addl %eax, %edi
    635        
     635
    636636        early_puts_ploop:
    637637                lodsb
    638                
     638
    639639                cmp $0, %al
    640640                je early_puts_ploop_end
    641                
     641
    642642                movb $0x0e, %ah  /* black background, yellow foreground */
    643643                stosw
    644                
     644
    645645                /* Sanity check for the cursor on the last line */
    646646                inc %bx
    647647                cmp $2000, %bx
    648648                jb early_puts_ploop
    649                
     649
    650650                /* Scroll the screen (24 rows) */
    651651                movl %esi, %edx
     
    654654                movl $960, %ecx
    655655                rep movsl
    656                
     656
    657657                /* Clear the 24th row */
    658658                xorl %eax, %eax
    659659                movl $40, %ecx
    660660                rep stosl
    661                
     661
    662662                /* Go to row 24 */
    663663                movl %edx, %esi
    664664                movl $(PA2KA(0xb8f00)), %edi
    665665                movw $1920, %bx
    666                
     666
    667667                jmp early_puts_ploop
    668668        early_puts_ploop_end:
    669        
     669
    670670        /* Write bits 8 - 15 of the cursor address */
    671671        movw $0x3d4, %dx
    672672        movb $0xe, %al
    673673        outb %al, %dx
    674        
     674
    675675        movw $0x3d5, %dx
    676676        movb %bh, %al
    677677        outb %al, %dx
    678        
     678
    679679        /* Write bits 0 - 7 of the cursor address */
    680680        movw $0x3d4, %dx
    681681        movb $0xf, %al
    682682        outb %al, %dx
    683        
     683
    684684        movw $0x3d5, %dx
    685685        movb %bl, %al
    686686        outb %al, %dx
    687        
     687
    688688        /* Epilogue, restore preserved registers */
    689689        popl %edi
     
    691691        popl %ebx
    692692        leave
    693        
     693
    694694#endif
    695        
     695
    696696        ret
    697697
Note: See TracChangeset for help on using the changeset viewer.