Ignore:
File:
1 edited

Legend:

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

    r873c681 r304342e  
    1 /*
    2  * Copyright (c) 2005 Ondrej Palkovsky
    3  * Copyright (c) 2006 Martin Decky
    4  * Copyright (c) 2008 Jakub Jermar
    5  * All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
    10  *
    11  * - Redistributions of source code must retain the above copyright
    12  *   notice, this list of conditions and the following disclaimer.
    13  * - Redistributions in binary form must reproduce the above copyright
    14  *   notice, this list of conditions and the following disclaimer in the
    15  *   documentation and/or other materials provided with the distribution.
    16  * - The name of the author may not be used to endorse or promote products
    17  *   derived from this software without specific prior written permission.
    18  *
    19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
    23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    29  */
     1#
     2# Copyright (c) 2005 Ondrej Palkovsky
     3# Copyright (c) 2006 Martin Decky
     4# Copyright (c) 2008 Jakub Jermar
     5# All rights reserved.
     6#
     7# Redistribution and use in source and binary forms, with or without
     8# modification, are permitted provided that the following conditions
     9# are met:
     10#
     11# - Redistributions of source code must retain the above copyright
     12#   notice, this list of conditions and the following disclaimer.
     13# - Redistributions in binary form must reproduce the above copyright
     14#   notice, this list of conditions and the following disclaimer in the
     15#   documentation and/or other materials provided with the distribution.
     16# - The name of the author may not be used to endorse or promote products
     17#   derived from this software without specific prior written permission.
     18#
     19# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     21# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     23# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     24# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     28# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29#
    3030
    3131#include <arch/boot/boot.h>
    3232#include <arch/boot/memmap.h>
    33 #include <arch/mm/page.h>
     33#include <arch/mm/page.h>       
    3434#include <arch/mm/ptl.h>
    3535#include <arch/pm.h>
     
    3737#include <arch/cpuid.h>
    3838
    39 #define START_STACK  (BOOT_OFFSET - BOOT_STACK_SIZE)
     39#define START_STACK     (BOOT_OFFSET - BOOT_STACK_SIZE)
    4040
    4141.section K_TEXT_START, "ax"
    4242
    4343.code32
    44 
    45 .macro pm_error msg
    46         movl \msg, %esi
    47         jmp pm_error_halt
    48 .endm
    49 
    50 .macro pm_status msg
    51 #ifdef CONFIG_EGA
    52         pushl %esi
    53         movl \msg, %esi
    54         call pm_early_puts
    55         popl %esi
    56 #endif
    57 .endm
    58 
    59 .macro pm2_status msg
    60 #ifndef CONFIG_FB
    61         pm_status \msg
    62 #endif
    63 .endm
    64 
    6544.align 4
    6645.global multiboot_image_start
     
    6847        .long MULTIBOOT_HEADER_MAGIC
    6948        .long MULTIBOOT_HEADER_FLAGS
    70         .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)  /* checksum */
     49        .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)  # checksum
    7150        .long multiboot_header
    7251        .long unmapped_ktext_start
     
    7756multiboot_image_start:
    7857        cld
    79        
    80         /* Initialize stack pointer */
    81         movl $START_STACK, %esp
    82        
    83         /* Initialize Global Descriptor Table register */
    84         lgdtl bootstrap_gdtr
    85        
    86         /* Kernel data + stack */
     58        movl $START_STACK, %esp             # initialize stack pointer
     59        lgdtl bootstrap_gdtr                # initialize Global Descriptor Table register
     60       
    8761        movw $gdtselector(KDATA_DES), %cx
    8862        movw %cx, %es
    89         movw %cx, %ds
     63        movw %cx, %ds                       # kernel data + stack
    9064        movw %cx, %ss
    9165       
    92         /*
    93          * Simics seems to remove hidden part of GS on entering user mode
    94          * when _visible_ part of GS does not point to user-mode segment.
    95          */
     66        #
     67        # Simics seems to remove hidden part of GS on entering user mode
     68        # when _visible_ part of GS does not point to user-mode segment.
     69        #
     70       
    9671        movw $gdtselector(UDATA_DES), %cx
    9772        movw %cx, %fs
     
    10176        multiboot_meeting_point:
    10277       
    103         /* Save GRUB arguments */
    104         movl %eax, grub_eax
     78        movl %eax, grub_eax                 # save parameters from GRUB
    10579        movl %ebx, grub_ebx
    10680       
    107         pm_status $status_prot
     81        #
     82        # Protected 32-bit. We want to reuse the code-seg descriptor,
     83        # the Default operand size must not be 1 when entering long mode.
     84        #
    10885       
    10986        movl $(INTEL_CPUID_EXTENDED), %eax
     
    11289        ja extended_cpuid_supported
    11390       
    114                 pm_error $err_extended_cpuid
     91                movl $extended_cpuid_msg, %esi
     92                jmp error_halt
    11593       
    11694        extended_cpuid_supported:
     
    12199        jc long_mode_supported
    122100       
    123                 pm_error $err_long_mode
     101                movl $long_mode_msg, %esi
     102                jmp error_halt
    124103       
    125104        long_mode_supported:
     
    128107        jc noexecute_supported
    129108       
    130                 pm_error $err_noexecute
     109                movl $noexecute_msg, %esi
     110                jmp error_halt
    131111       
    132112        noexecute_supported:
     
    137117        jc fx_supported
    138118       
    139                 pm_error $err_fx
     119                movl $fx_msg, %esi
     120                jmp error_halt
    140121       
    141122        fx_supported:
     
    144125        jc sse2_supported
    145126       
    146                 pm_error $err_sse2
     127                movl $sse2_msg, %esi
     128                jmp error_halt
    147129       
    148130        sse2_supported:
    149        
     131
    150132#include "vesa_prot.inc"
    151        
    152         /*
    153          * Protected 32-bit. We want to reuse the code-seg descriptor,
    154          * the Default operand size must not be 1 when entering long mode.
    155          */
    156        
    157         pm2_status $status_prot2
    158        
    159         /*
    160          * Enable 64-bit page translation entries - CR4.PAE = 1.
    161          * Paging is not enabled until after long mode is enabled.
    162          */
     133
     134        #
     135        # Enable 64-bit page translation entries - CR4.PAE = 1.
     136        # Paging is not enabled until after long mode is enabled.
     137        #
    163138       
    164139        movl %cr4, %eax
     
    166141        movl %eax, %cr4
    167142       
    168         /* Set up paging tables */
     143        # set up paging tables
     144       
    169145        leal ptl_0, %eax
    170146        movl %eax, %cr3
    171147       
    172         /* Enable long mode */
    173         movl $EFER_MSR_NUM, %ecx
    174         rdmsr                     /* read EFER */
    175         btsl $AMD_LME_FLAG, %eax  /* set LME = 1 */
    176         wrmsr
    177        
    178         /* Enable paging to activate long mode (set CR0.PG = 1) */
     148        # enable long mode
     149       
     150        movl $EFER_MSR_NUM, %ecx            # EFER MSR number
     151        rdmsr                               # read EFER
     152        btsl $AMD_LME_FLAG, %eax            # set LME = 1
     153        wrmsr                               # write EFER
     154       
     155        # enable paging to activate long mode (set CR0.PG = 1)
     156       
    179157        movl %cr0, %eax
    180158        btsl $31, %eax
    181159        movl %eax, %cr0
    182160       
    183         /* At this point we are in compatibility mode */
     161        # at this point we are in compatibility mode
     162       
    184163        jmpl $gdtselector(KTEXT_DES), $start64
    185164
    186 /** Print string to EGA display (in light red) and halt.
    187  *
    188  * Should be executed from 32 bit protected mode with paging
    189  * turned off. Stack is not required. This routine is used even
    190  * if CONFIG_EGA is not enabled. Since we are going to halt the
    191  * CPU anyway, it is always better to at least try to print
    192  * some hints.
    193  *
    194  * @param %esi NULL-terminated string to print.
    195  *
    196  */
    197 pm_error_halt:
    198         movl $0xb8000, %edi  /* base of EGA text mode memory */
     165.code64
     166start64:
     167        movq $(PA2KA(START_STACK)), %rsp
     168       
     169        # call arch_pre_main(grub_eax, grub_ebx)
     170        xorq %rdi, %rdi
     171        movl grub_eax, %edi
     172        xorq %rsi, %rsi
     173        movl grub_ebx, %esi
     174        call arch_pre_main
     175       
     176        # create the first stack frame
     177        pushq $0
     178        movq %rsp, %rbp
     179
     180        call main_bsp
     181       
     182        # not reached
     183       
     184        cli
     185        hlt0:
     186                hlt
     187                jmp hlt0
     188
     189# Print string from %esi to EGA display (in red) and halt
     190error_halt:
     191        movl $0xb8000, %edi       # base of EGA text mode memory
    199192        xorl %eax, %eax
    200193       
    201         /* Read bits 8 - 15 of the cursor address */
    202         movw $0x3d4, %dx
     194        movw $0x3d4, %dx          # read bits 8 - 15 of the cursor address
    203195        movb $0xe, %al
    204196        outb %al, %dx
     
    208200        shl $8, %ax
    209201       
    210         /* Read bits 0 - 7 of the cursor address */
    211         movw $0x3d4, %dx
     202        movw $0x3d4, %dx          # read bits 0 - 7 of the cursor address
    212203        movb $0xf, %al
    213204        outb %al, %dx
     
    216207        inb %dx, %al
    217208       
    218         /* Sanity check for the cursor on screen */
    219         cmp $2000, %ax
    220         jb err_cursor_ok
    221        
    222                 movw $1998, %ax
    223        
    224         err_cursor_ok:
     209        cmp $1920, %ax
     210        jbe cursor_ok
     211       
     212                movw $1920, %ax       # sanity check for the cursor on the last line
     213       
     214        cursor_ok:
    225215       
    226216        movw %ax, %bx
     
    228218        addl %eax, %edi
    229219       
    230         err_ploop:
     220        movw $0x0c00, %ax         # black background, light red foreground
     221       
     222        ploop:
    231223                lodsb
    232                
    233224                cmp $0, %al
    234                 je err_ploop_end
    235                
    236                 movb $0x0c, %ah  /* black background, light red foreground */
     225                je ploop_end
    237226                stosw
    238                
    239                 /* Sanity check for the cursor on the last line */
    240227                inc %bx
    241                 cmp $2000, %bx
    242                 jb err_ploop
    243                
    244                 /* Scroll the screen (24 rows) */
    245                 movl %esi, %edx
    246                 movl $0xb80a0, %esi
    247                 movl $0xb8000, %edi
    248                 movl $1920, %ecx
    249                 rep movsw
    250                
    251                 /* Clear the 24th row */
    252                 xorl %eax, %eax
    253                 movl $80, %ecx
    254                 rep stosw
    255                
    256                 /* Go to row 24 */
    257                 movl %edx, %esi
    258                 movl $0xb8f00, %edi
    259                 movw $1920, %bx
    260                
    261                 jmp err_ploop
    262         err_ploop_end:
    263        
    264         /* Write bits 8 - 15 of the cursor address */
    265         movw $0x3d4, %dx
     228                jmp ploop
     229        ploop_end:
     230       
     231        movw $0x3d4, %dx          # write bits 8 - 15 of the cursor address
    266232        movb $0xe, %al
    267233        outb %al, %dx
     
    271237        outb %al, %dx
    272238       
    273         /* Write bits 0 - 7 of the cursor address */
    274         movw $0x3d4, %dx
     239        movw $0x3d4, %dx          # write bits 0 - 7 of the cursor address
    275240        movb $0xf, %al
    276241        outb %al, %dx
     
    285250                jmp hlt1
    286251
    287 /** Print string to EGA display (in light green).
    288  *
    289  * Should be called from 32 bit protected mode with paging
    290  * turned off. A stack space of at least 24 bytes is required,
    291  * but the function does not establish a stack frame.
    292  *
    293  * Macros such as pm_status and pm2_status take care that
    294  * this function is used only when CONFIG_EGA is enabled
    295  * and CONFIG_FB is disabled.
    296  *
    297  * @param %esi NULL-terminated string to print.
    298  *
    299  */
    300 pm_early_puts:
    301         pushl %eax
    302         pushl %ebx
    303         pushl %ecx
    304         pushl %edx
    305         pushl %edi
    306        
    307         movl $0xb8000, %edi  /* base of EGA text mode memory */
    308         xorl %eax, %eax
    309        
    310         /* Read bits 8 - 15 of the cursor address */
    311         movw $0x3d4, %dx
    312         movb $0xe, %al
    313         outb %al, %dx
    314        
    315         movw $0x3d5, %dx
    316         inb %dx, %al
    317         shl $8, %ax
    318        
    319         /* Read bits 0 - 7 of the cursor address */
    320         movw $0x3d4, %dx
    321         movb $0xf, %al
    322         outb %al, %dx
    323        
    324         movw $0x3d5, %dx
    325         inb %dx, %al
    326        
    327         /* Sanity check for the cursor on screen */
    328         cmp $2000, %ax
    329         jb pm_puts_cursor_ok
    330        
    331                 movw $1998, %ax
    332        
    333         pm_puts_cursor_ok:
    334        
    335         movw %ax, %bx
    336         shl $1, %eax
    337         addl %eax, %edi
    338        
    339         pm_puts_ploop:
    340                 lodsb
    341                
    342                 cmp $0, %al
    343                 je pm_puts_ploop_end
    344                
    345                 movb $0x0a, %ah  /* black background, light green foreground */
    346                 stosw
    347                
    348                 /* Sanity check for the cursor on the last line */
    349                 inc %bx
    350                 cmp $2000, %bx
    351                 jb pm_puts_ploop
    352                
    353                 /* Scroll the screen (24 rows) */
    354                 movl %esi, %edx
    355                 movl $0xb80a0, %esi
    356                 movl $0xb8000, %edi
    357                 movl $1920, %ecx
    358                 rep movsw
    359                
    360                 /* Clear the 24th row */
    361                 xorl %eax, %eax
    362                 movl $80, %ecx
    363                 rep stosw
    364                
    365                 /* Go to row 24 */
    366                 movl %edx, %esi
    367                 movl $0xb8f00, %edi
    368                 movw $1920, %bx
    369                
    370                 jmp pm_puts_ploop
    371         pm_puts_ploop_end:
    372        
    373         /* Write bits 8 - 15 of the cursor address */
    374         movw $0x3d4, %dx
    375         movb $0xe, %al
    376         outb %al, %dx
    377        
    378         movw $0x3d5, %dx
    379         movb %bh, %al
    380         outb %al, %dx
    381        
    382         /* Write bits 0 - 7 of the cursor address */
    383         movw $0x3d4, %dx
    384         movb $0xf, %al
    385         outb %al, %dx
    386        
    387         movw $0x3d5, %dx
    388         movb %bl, %al
    389         outb %al, %dx
    390        
    391         popl %edi
    392         popl %edx
    393         popl %ecx
    394         popl %ebx
    395         popl %eax
    396        
    397         ret
    398 
    399 .code64
    400 
    401 .macro long_status msg
    402         pushq %rdi
    403         movq \msg, %rdi
    404         call early_puts
    405         popq %rdi
     252#include "vesa_real.inc"
     253
     254.section K_INI_PTLS, "aw", @progbits
     255
     256#
     257# Macro for generating initial page table contents.
     258# @param cnt Number of entries to generat. Must be multiple of 8.
     259# @param g   Number of GB that will be added to the mapping.
     260#
     261.macro ptl2gen cnt g
     262.if \cnt
     263        ptl2gen "\cnt - 8" \g
     264        .quad ((\cnt - 8) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
     265        .quad ((\cnt - 7) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
     266        .quad ((\cnt - 6) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
     267        .quad ((\cnt - 5) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
     268        .quad ((\cnt - 4) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
     269        .quad ((\cnt - 3) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
     270        .quad ((\cnt - 2) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
     271        .quad ((\cnt - 1) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
     272.endif
    406273.endm
    407274
    408 start64:
    409        
    410         /*
    411          * Long mode.
    412          */
    413        
    414         movq $(PA2KA(START_STACK)), %rsp
    415        
    416         /* Create the first stack frame */
    417         pushq $0
    418         movq %rsp, %rbp
    419        
    420         long_status $status_long
    421        
    422         /* Call arch_pre_main(grub_eax, grub_ebx) */
    423         xorq %rdi, %rdi
    424         movl grub_eax, %edi
    425         xorq %rsi, %rsi
    426         movl grub_ebx, %esi
    427        
    428         movabsq $arch_pre_main, %rax
    429         callq *%rax
    430        
    431         long_status $status_main
    432        
    433         /* Call main_bsp() */
    434         movabsq $main_bsp, %rax
    435         call *%rax
    436        
    437         /* Not reached */
    438         cli
    439         hlt0:
    440                 hlt
    441                 jmp hlt0
    442 
    443 /** Print string to EGA display.
    444  *
    445  * Should be called from long mode (with paging enabled
    446  * and stack established). This function is ABI compliant
    447  * (without red-zone).
    448  *
    449  * If CONFIG_EGA is undefined or CONFIG_FB is defined
    450  * then this function does nothing.
    451  *
    452  * @param %rdi NULL-terminated string to print.
    453  *
    454  */
    455 early_puts:
    456        
    457 #if ((defined(CONFIG_EGA)) && (!defined(CONFIG_FB)))
    458        
    459         /* Prologue, save preserved registers */
    460         pushq %rbp
    461         movq %rsp, %rbp
    462         pushq %rbx
    463        
    464         movq %rdi, %rsi
    465         movq $(PA2KA(0xb8000)), %rdi  /* base of EGA text mode memory */
    466         xorq %rax, %rax
    467        
    468         /* Read bits 8 - 15 of the cursor address */
    469         movw $0x3d4, %dx
    470         movb $0xe, %al
    471         outb %al, %dx
    472        
    473         movw $0x3d5, %dx
    474         inb %dx, %al
    475         shl $8, %ax
    476        
    477         /* Read bits 0 - 7 of the cursor address */
    478         movw $0x3d4, %dx
    479         movb $0xf, %al
    480         outb %al, %dx
    481        
    482         movw $0x3d5, %dx
    483         inb %dx, %al
    484        
    485         /* Sanity check for the cursor on screen */
    486         cmp $2000, %ax
    487         jb early_puts_cursor_ok
    488        
    489                 movw $1998, %ax
    490        
    491         early_puts_cursor_ok:
    492        
    493         movw %ax, %bx
    494         shl $1, %rax
    495         addq %rax, %rdi
    496        
    497         early_puts_ploop:
    498                 lodsb
    499                
    500                 cmp $0, %al
    501                 je early_puts_ploop_end
    502                
    503                 movb $0x0e, %ah  /* black background, yellow foreground */
    504                 stosw
    505                
    506                 /* Sanity check for the cursor on the last line */
    507                 inc %bx
    508                 cmp $2000, %bx
    509                 jb early_puts_ploop
    510                
    511                 /* Scroll the screen (24 rows) */
    512                 movq %rsi, %rdx
    513                 movq $(PA2KA(0xb80a0)), %rsi
    514                 movq $(PA2KA(0xb8000)), %rdi
    515                 movq $1920, %rcx
    516                 rep movsw
    517                
    518                 /* Clear the 24th row */
    519                 xorq %rax, %rax
    520                 movq $80, %rcx
    521                 rep stosw
    522                
    523                 /* Go to row 24 */
    524                 movq %rdx, %rsi
    525                 movq $(PA2KA(0xb8f00)), %rdi
    526                 movw $1920, %bx
    527                
    528                 jmp early_puts_ploop
    529         early_puts_ploop_end:
    530        
    531         /* Write bits 8 - 15 of the cursor address */
    532         movw $0x3d4, %dx
    533         movb $0xe, %al
    534         outb %al, %dx
    535        
    536         movw $0x3d5, %dx
    537         movb %bh, %al
    538         outb %al, %dx
    539        
    540         /* Write bits 0 - 7 of the cursor address */
    541         movw $0x3d4, %dx
    542         movb $0xf, %al
    543         outb %al, %dx
    544        
    545         movw $0x3d5, %dx
    546         movb %bl, %al
    547         outb %al, %dx
    548        
    549         /* Epilogue, restore preserved registers */
    550         popq %rbx
    551         leave
    552        
    553 #endif
    554        
    555         ret
    556 
    557 #include "vesa_real.inc"
    558 
    559 .section K_INI_PTLS, "aw", @progbits
    560 
    561 /** Generate initial page table contents.
    562  *
    563  * @param cnt Number of entries to generate. Must be multiple of 8.
    564  * @param g   Number of GB that will be added to the mapping.
    565  *
    566  */
    567 .macro ptl2gen cnt g
    568         .if \cnt
    569                 ptl2gen "\cnt - 8" \g
    570                 .quad ((\cnt - 8) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
    571                 .quad ((\cnt - 7) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
    572                 .quad ((\cnt - 6) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
    573                 .quad ((\cnt - 5) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
    574                 .quad ((\cnt - 4) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
    575                 .quad ((\cnt - 3) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
    576                 .quad ((\cnt - 2) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
    577                 .quad ((\cnt - 1) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
    578         .endif
    579 .endm
    580 
    581 /* Page table for pages in the 1st gigabyte. */
    582 .align 4096
    583 ptl_2_0g:
     275# Page table for pages in the first gigabyte.
     276.align 4096
     277.global ptl_2_0g
     278ptl_2_0g:       
    584279        ptl2gen 512 0
    585280
    586 /* Page table for pages in the 2nd gigabyte. */
    587 .align 4096
     281# Page table for pages in the second gigabyte.
     282.align 4096
     283.global ptl_2_1g
    588284ptl_2_1g:
    589285        ptl2gen 512 1
    590286
    591 /* Page table for pages in the 3rd gigabyte. */
    592 .align 4096
     287# Page table for pages in the third gigabyte.
     288.align 4096
     289.global ptl_2_2g
    593290ptl_2_2g:
    594291        ptl2gen 512 2
    595292
    596 /* Page table for pages in the 4th gigabyte. */
    597 .align 4096
     293# Page table for pages in the fourth gigabyte.
     294.align 4096
     295.global ptl_2_3g
    598296ptl_2_3g:
    599297        ptl2gen 512 3
    600298
    601 /* Page table for pages in the 5th gigabyte. */
    602 .align 4096
    603 ptl_2_4g:
    604         ptl2gen 512 3
    605 
    606 /* Page table for pages in the 6th gigabyte. */
    607 .align 4096
    608 ptl_2_5g:
    609         ptl2gen 512 3
    610 
    611 /* Page table for pages in the 7th gigabyte. */
    612 .align 4096
    613 ptl_2_6g:
    614         ptl2gen 512 3
    615 
    616 /* Page table for pages in the 8th gigabyte. */
    617 .align 4096
    618 ptl_2_7g:
    619         ptl2gen 512 3
    620 
    621 .align 4096
     299.align 4096
     300.global ptl_1
    622301ptl_1:
    623         /* Identity mapping for [0; 8G) */
     302        # Identity mapping for [0; 4G)
    624303        .quad ptl_2_0g + (PTL_WRITABLE | PTL_PRESENT)
    625         .quad ptl_2_1g + (PTL_WRITABLE | PTL_PRESENT)
     304        .quad ptl_2_1g + (PTL_WRITABLE | PTL_PRESENT) 
    626305        .quad ptl_2_2g + (PTL_WRITABLE | PTL_PRESENT)
    627306        .quad ptl_2_3g + (PTL_WRITABLE | PTL_PRESENT)
    628         .quad ptl_2_4g + (PTL_WRITABLE | PTL_PRESENT)
    629         .quad ptl_2_5g + (PTL_WRITABLE | PTL_PRESENT)
    630         .quad ptl_2_6g + (PTL_WRITABLE | PTL_PRESENT)
    631         .quad ptl_2_7g + (PTL_WRITABLE | PTL_PRESENT)
    632         .fill 504, 8, 0
     307        .fill 506, 8, 0
     308        # Mapping of [0; 1G) at -2G
     309        .quad ptl_2_0g + (PTL_WRITABLE | PTL_PRESENT)
     310        .fill 1, 8, 0
    633311
    634312.align 4096
     
    636314ptl_0:
    637315        .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
    638         .fill 255, 8, 0
     316        .fill 255,8,0
    639317        .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
    640         .fill 255, 8, 0
     318        .fill 254,8,0
     319        .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
    641320
    642321.section K_DATA_START, "aw", @progbits
     
    653332        .long 0
    654333
    655 err_extended_cpuid:
    656         .asciz "Error: Extended CPUID not supported -- CPU is not 64-bit. System halted."
    657 err_long_mode:
    658         .asciz "Error: 64-bit long mode not supported. System halted."
    659 err_noexecute:
    660         .asciz "Error: No-execute pages not supported. System halted."
    661 err_fx:
    662         .asciz "Error: FXSAVE/FXRESTORE instructions not supported. System halted."
    663 err_sse2:
    664         .asciz "Error: SSE2 instructions not supported. System halted."
    665 
    666 status_prot:
    667         .asciz "[prot] "
    668 status_vesa_copy:
    669         .asciz "[vesa_copy] "
    670 status_grub_cmdline:
    671         .asciz "[grub_cmdline] "
    672 status_vesa_real:
    673         .asciz "[vesa_real] "
    674 status_prot2:
    675         .asciz "[prot2] "
    676 status_long:
    677         .asciz "[long] "
    678 status_main:
    679         .asciz "[main] "
     334extended_cpuid_msg:
     335        .asciz "Extended CPUID not supported. System halted."
     336long_mode_msg:
     337        .asciz "64 bit long mode not supported. System halted."
     338noexecute_msg:
     339        .asciz "No-execute pages not supported. System halted."
     340fx_msg:
     341        .asciz "FXSAVE/FXRESTORE instructions not supported. System halted."
     342sse2_msg:
     343        .asciz "SSE2 instructions not supported. System halted."
Note: See TracChangeset for help on using the changeset viewer.