VirtualBox

Ignore:
Timestamp:
Jan 6, 2016 2:53:27 AM (9 years ago)
Author:
vboxsync
Message:

bs3kit: More IDT handling (mainly 32-bit).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToLM64.asm

    r59245 r59259  
    2929
    3030;;
    31 ; Switch to PAE paged protected mode from any other mode.
     31; Switch to 64-bit long mode from any other mode.
    3232;
    3333; @cproto   BS3_DECL(void) Bs3SwitchToLM64(void);
    3434;
    35 ; @uses     Nothing (except high 32-bit register parts), upper part of ESP is
    36 ;           cleared if caller is in 16-bit mode.
     35; @uses     Nothing (except possibly high 32-bit and/or upper 64-bit register parts).
    3736;
    38 ; @remarks  Obviously returns to 32-bit mode, even if the caller was
    39 ;           in 16-bit or 64-bit mode.  It doesn't not preserve the callers
    40 ;           ring, but instead changes to ring-0.
     37; @remarks  Obviously returns to 64-bit mode, even if the caller was in 16-bit
     38;           or 32-bit mode.  It doesn't not preserve the callers ring, but
     39;           instead changes to ring-0.
    4140;
    4241BS3_PROC_BEGIN_MODE Bs3SwitchToLM64
     
    5251
    5352%else
    54  %if TMPL_BITS == 16
    55         push    word 0                  ; save space for extending the return value.
    56  %endif
     53        ;
     54        ; Switch to LM32 and then switch to 64-bits (IDT & TSS are the same for
     55        ; LM16, LM32 and LM64, unlike the rest).
     56        ;
     57        ; (The long mode switching code is going via 32-bit protected mode, so
     58        ; Bs3SwitchToLM32 contains the actual code for switching to avoid
     59        ; unnecessary 32-bit -> 64-bit -> 32-bit trips.)
     60        ;
     61        extern  TMPL_NM(Bs3SwitchToLM32)
     62        call    TMPL_NM(Bs3SwitchToLM32)
     63        BS3_SET_BITS 32
    5764
    58         ;
    59         ; Switch to 32-bit protected mode (for identify mapped pages).
    60         ;
    61         extern  TMPL_NM(Bs3SwitchToPE32)
    62         call    TMPL_NM(Bs3SwitchToPE32)
    63         BS3_SET_BITS 32
    64  %if TMPL_BITS == 16
    65         jmp     .thirty_two_bit_segment
    66 BS3_BEGIN_TEXT32
    67 .thirty_two_bit_segment:
    68  %endif
    69 
    70         push    eax
    71         push    ecx
    72         push    edx
    73         pushfd
    74 
    75         ;
    76         ; Make sure both PAE and PSE are enabled (requires pentium pro).
    77         ;
    78         mov     eax, cr4
    79         mov     ecx, eax
    80         or      eax, X86_CR4_PAE | X86_CR4_PSE
    81         cmp     eax, ecx
    82         je      .cr4_is_fine
    83         mov     cr4, eax
    84 .cr4_is_fine:
    85 
    86         ;
    87         ; Get the page directory (returned in eax).
    88         ; Will lazy init page tables.
    89         ;
    90         extern NAME(Bs3PagingGetRootForLM64_pe32)
    91         call   NAME(Bs3PagingGetRootForLM64_pe32)
    92 
    93         cli
    94         mov     cr3, eax
    95 
    96         ;
    97         ; Enable long mode in EFER.
    98         ;
    99         mov     ecx, MSR_K6_EFER
    100         rdmsr
    101         or      eax, MSR_K6_EFER_LME
    102         wrmsr
    103 
    104         ;
    105         ; Enable paging and thereby activating LM64.
    106         ;
    107 BS3_EXTERN_SYSTEM16 Bs3Lgdt_Gdt
    108 BS3_BEGIN_TEXT32
    109         mov     eax, cr0
    110         or      eax, X86_CR0_PG
    111         mov     cr0, eax
    112         jmp     .in_lm32
    113 .in_lm32:
    114 
    115         ;
    116         ; Call rountine for doing mode specific setups.
    117         ;
    118         extern  NAME(Bs3EnteredMode_lm32)
    119         call    NAME(Bs3EnteredMode_lm32)
    120 
    121         ;
    122         ; Restore ecx, eax and flags (IF).
    123         ;
    124  %if TMPL_BITS == 16
    125         movzx   eax, word [esp + 16 + 2] ; Load return address.
    126         add     eax, BS3_ADDR_BS3TEXT16  ; Convert it to a flat address.
    127         mov     [esp + 16], eax          ; Store it in the place right for 32-bit returns.
    128  %endif
    129         popfd
    130         pop     edx
    131         pop     ecx
    132         pop     eax
    133 
    134         ;
    135         ; Now go to 32-bit mode.
    136         ;
    137         extern  NAME(Bs3SwitchTo64Bit_c32)
    138         jmp     NAME(Bs3SwitchTo64Bit_c32)
    139 
    140  %if TMPL_BITS != 32
    141 TMPL_BEGIN_TEXT
    142  %endif
     65        extern  _Bs3SwitchTo64Bit_c32
     66        jmp     _Bs3SwitchTo64Bit_c32
    14367%endif
    14468BS3_PROC_END_MODE   Bs3SwitchToLM64
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette