Changeset 8725fb4 in mainline for arch/amd64/src/boot/boot.S


Ignore:
Timestamp:
2006-01-08T18:11:20Z (19 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
46d26ee
Parents:
66def8d
Message:

break AMD64, will be fixed soon

File:
1 edited

Legend:

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

    r66def8d r8725fb4  
    3434#include <arch/boot/boot.h>
    3535
     36#define START_STACK     (BOOT_OFFSET - BOOT_STACK_SIZE)
    3637#define START_STACK_64  0xffffffff80007c00
    37                                        
    38 #
    39 # This is where we require any SPARTAN-kernel-compatible boot loader
    40 # to pass control in real mode.
    41 #
    42 # Protected mode tables are statically initialised during compile
    43 # time. So we can just load the respective table registers and
    44 # switch to protected mode.
    45 #
    46 
    47 #define START_STACK (BOOTSTRAP_OFFSET-0x400)
    4838       
    4939.section K_TEXT_START, "ax"
    50 .code16
    51 .global kernel_image_start
    52 .global multiboot_image_start
    53 kernel_image_start:
    54         cli
    55         xorw %ax,%ax
    56         movw %ax,%ds
    57         movw %ax,%es
    58         movw %ax,%ss            # initialize stack segment register
    59         movl $(START_STACK), %esp       # initialize stack pointer
    60        
    61         call memmap_arch_init
    62        
    63         movl $0x80000000, %eax 
    64         cpuid
    65         cmp $0x80000000, %eax   # any function > 80000000h?
    66         jbe no_long_mode
    67         movl $(AMD_CPUID_EXTENDED), %eax # Extended function code 80000001
    68         cpuid
    69         bt $29, %edx            # Test if long mode is supported.
    70         jnc no_long_mode
    71 
    72         # Load gdtr, idtr
    73         lgdt real_bootstrap_gdtr_boot
    74        
    75         movl %cr0,%eax
    76         orl $0x1,%eax
    77         movl %eax,%cr0                  # switch to protected mode
    78 
    79         jmpl $gdtselector(KTEXT32_DES), $now_in_prot
    80 
    81 no_long_mode:
    82 1:
    83         jmp 1b
    84        
     40# .code16
     41# .global kernel_image_start
     42# .global multiboot_image_start
     43# kernel_image_start:
     44#       cli
     45#       xorw %ax,%ax
     46#       movw %ax,%ds
     47#       movw %ax,%es
     48#       movw %ax,%ss            # initialize stack segment register
     49#       movl $(START_STACK), %esp       # initialize stack pointer
     50#      
     51#       call memmap_arch_init
     52#      
     53#       movl $0x80000000, %eax 
     54#       cpuid
     55#       cmp $0x80000000, %eax   # any function > 80000000h?
     56#       jbe no_long_mode
     57#       movl $(AMD_CPUID_EXTENDED), %eax # Extended function code 80000001
     58#       cpuid
     59#       bt $29, %edx            # Test if long mode is supported.
     60#       jnc no_long_mode
     61#
     62#       # Load gdtr, idtr
     63#       lgdt real_bootstrap_gdtr_boot
     64#      
     65#       movl %cr0,%eax
     66#       orl $0x1,%eax
     67#       movl %eax,%cr0                  # switch to protected mode
     68#
     69#       jmpl $gdtselector(KTEXT32_DES), $now_in_prot
     70#
     71# no_long_mode:
     72# 1:
     73#       jmp 1b
     74#      
    8575.code32
    8676.align 4
     
    8979        .long MULTIBOOT_HEADER_FLAGS
    9080        .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)        # checksum
    91         .long multiboot_header + BOOT_OFFSET
    92         .long unmapped_ktext_start + BOOT_OFFSET
     81        .long multiboot_header
     82        .long unmapped_ktext_start
    9383        .long 0
    9484        .long 0
    95         .long multiboot_image_start + BOOT_OFFSET
     85        .long multiboot_image_start
    9686
    9787multiboot_image_start:
     
    110100        multiboot_meeting_point:
    111101       
    112         hlt
    113 
    114 # Protected 32-bit. We want to reuse the code-seg descriptor,
    115 # the Default operand size must not be 1 when entering long mode
    116 now_in_prot: 
    117         # Set up stack & data descriptors
    118         movw $gdtselector(KDATA_DES), %ax
    119         movw %ax, %ds
    120         movw %ax, %ss
    121 
    122         movb $0xd1, %al         # enable A20 using the keyboard controller
    123         outb %al, $0x64
    124         movb $0xdf, %al
    125         outb %al, $0x60
    126 
     102        # Protected 32-bit. We want to reuse the code-seg descriptor,
     103        # the Default operand size must not be 1 when entering long mode
     104       
     105        pushl %ebx                                                      # save parameters from GRUB
     106        pushl %eax
    127107       
    128108        # Enable 64-bit page transaltion entries - CR4.PAE = 1.
    129109        # Paging is not enabled until after long mode is enabled
     110       
    130111        movl %cr4, %eax
    131112        btsl $5, %eax
     
    133114
    134115        # Set up paging tables
     116       
    135117        leal ptl_0, %eax
    136118        movl %eax, %cr3
    137119       
    138120        # Enable long mode
    139         movl $EFER_MSR_NUM, %ecx   # EFER MSR number
    140         rdmsr                   # Read EFER
    141         btsl $AMD_LME_FLAG, %eax            # Set LME=1
    142         wrmsr                   # Write EFER
     121       
     122        movl $EFER_MSR_NUM, %ecx        # EFER MSR number
     123        rdmsr                                           # Read EFER
     124        btsl $AMD_LME_FLAG, %eax        # Set LME=1
     125        wrmsr                                           # Write EFER
    143126       
    144127        # Enable paging to activate long mode (set CR0.PG=1)
     128       
    145129        movl %cr0, %eax
    146130        btsl $31, %eax
     
    148132       
    149133        # At this point we are in compatibility mode
     134       
    150135        jmpl $gdtselector(KTEXT_DES), $start64
    151136
     
    154139        movq $(PA2KA(START_STACK)), %rsp
    155140
    156         # Copy kernel to higher physical memory
    157         movq $BOOTSTRAP_OFFSET, %rsi
    158         movq $BOOTSTRAP_OFFSET + BOOT_OFFSET, %rdi
    159         movq $_hardcoded_kernel_size, %rcx
    160         cld
    161         rep movsb
    162        
    163141        call main_bsp   # never returns
    164 1:
    165         jmp 1b
     142       
     143        cli
     144        hlt
    166145                               
    167146.section K_DATA_START, "aw", @progbits
     
    219198        .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
    220199
    221 .global real_bootstrap_gdtr_boot
    222 real_bootstrap_gdtr_boot:
    223         .word gdtselector(GDT_ITEMS)
    224         .long KA2PA(gdt)-BOOT_OFFSET
    225 
    226200.global protected_bootstrap_gdtr
    227201protected_bootstrap_gdtr:
Note: See TracChangeset for help on using the changeset viewer.