VirtualBox

Changeset 59215 in vbox


Ignore:
Timestamp:
Dec 22, 2015 7:47:07 PM (9 years ago)
Author:
vboxsync
Message:

bs3kit: mode switching fixes.

Location:
trunk/src/VBox/ValidationKit/bootsectors/bs3kit
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchTo16Bit.asm

    r58812 r59215  
    3434        ret
    3535%else
    36         push    xAX                     ; reserve space for far return
    3736        push    xAX
     37        xPUSHF
     38        cli
    3839
    39         ; Far return, offset part. bits 63/31:16 must be zero.
    40         movzx   eax, word [xSP + xCB * 3] ; returning to 16-bit, so bit 16 and out must be zero.
    41         mov     [xSP + xCB * 2], xAX
     40        ; Calc new CS.
     41        mov     ax, cs
     42        and     xAX, 3
     43        shl     xAX, BS3_SEL_RING_SHIFT  ; ring addend.
     44        add     xAX, BS3_SEL_R0_CS16
    4245
    43         mov     ax, cs
    44         and     ax, 3
    45         shl     ax, BS3_SEL_RING_SHIFT  ; ring addend.
    46         add     ax, BS3_SEL_R0_CS16
    47         mov     [esp + xCB * 3], xAX
     46        ; Construct a far return for switching to 16-bit code.
     47        push    xAX
     48        push    .sixteen_bit
     49        xRETF
    4850
     51BS3_BEGIN_TEXT16
     52.sixteen_bit:
    4953        ; Load 16-bit segment registers.
    5054        add     ax, BS3_SEL_R0_SS16 - BS3_SEL_R0_CS16
     
    5559        mov     es, ax
    5660
    57         ; Restore and return.
    58         pop     xAX
    59         retf
     61        popfd
     62 %if TMPL_BITS == 64
     63        add     sp, 4
     64 %endif
     65        pop     eax
     66 %if TMPL_BITS == 64
     67        add     sp, 4
     68 %endif
     69        ret     sCB - 2                 ; Return and pop 2 or 6 bytes of "parameters" (unused return value)
     70TMPL_BEGIN_TEXT
    6071%endif
    6172BS3_PROC_END_CMN   Bs3SwitchTo16Bit
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchTo32Bit.asm

    r58812 r59215  
    3535%else
    3636 %if TMPL_BITS == 16
    37         sub     sp, 6
    38         push    bp
    39         mov     bp, sp
     37        push    ax                      ; Reserve space for larger return value (adjusted in 32-bit code).
     38        push    eax
     39        pushfd
    4040 %else
    41         push    xPRE [xSP]                ; duplicate the return address
     41        pushfq
     42        mov     [rsp + 4], eax
    4243 %endif
    43         push    sAX
    44 
    45  %if TMPL_BITS == 16
    46         ; Convert the 16-bit near return into a 32-bit far return
    47         movzx   eax, word [bp + 8]
    48         add     eax, BS3_ADDR_BS3TEXT16
    49         mov     [bp + 2], eax
    50  %endif
     44        cli
    5145
    5246        ; Calc ring addend.
    5347        mov     ax, cs
    54         and     ax, 3
    55         shl     ax, BS3_SEL_RING_SHIFT
     48        and     xAX, 3
     49        shl     xAX, BS3_SEL_RING_SHIFT
     50        add     xAX, BS3_SEL_R0_CS32
    5651
    57         ; Set return segment.
    58         add     ax, BS3_SEL_R0_CS32
     52        ; Create far return for switching to 32-bit mode.
     53        push    sAX
    5954 %if TMPL_BITS == 16
    60         mov     [bp + 6], eax
     55        push    dword .thirty_two_bit wrt FLAT
     56        o32 retf
    6157 %else
    62         mov     [xSP + xCB*2], eax
     58        push    .thirty_two_bit
     59        o64 retf
    6360 %endif
    6461
     62BS3_SET_BITS 32
     63.thirty_two_bit:
    6564        ; Load 32-bit segment registers.
    66         add     ax, BS3_SEL_R0_SS32 - BS3_SEL_R0_CS32
     65        add     eax, BS3_SEL_R0_SS32 - BS3_SEL_R0_CS32
    6766        mov     ss, ax
    6867
    69         add     ax, BS3_SEL_R0_DS32 - BS3_SEL_R0_SS32
     68        add     eax, BS3_SEL_R0_DS32 - BS3_SEL_R0_SS32
    7069        mov     ds, ax
    7170        mov     es, ax
    7271
     72 %if TMPL_BITS == 16
     73        ; Adjust the return address.
     74        movsx   eax, word [esp + 4*2 + 2]
     75        add     eax, BS3_ADDR_BS3TEXT16
     76        mov     [esp + 4*2], eax
     77 %endif
     78
    7379        ; Restore and return.
    74         pop     sAX
    75  %if TMPL_BITS == 16
    76         leave
    77         o32 retf
    78  %else
    79         retf
    80  %endif
     80        popfd
     81        pop     eax
     82        ret
    8183%endif
    8284BS3_PROC_END_CMN   Bs3SwitchTo32Bit
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchTo64Bit.asm

    r58812 r59215  
    3737 %else
    3838  %if TMPL_BITS == 16
    39         sub     sp, 6
    40         push    bp
    41         mov     bp, sp
     39        sub     sp, 6                   ; Space for extended return value (corrected in 64-bit mode).
    4240  %else
    43         push    xPRE [xSP]                ; duplicate the return address
     41        push    xPRE [xSP]              ; Duplicate the return address.
     42        and     dword [xSP + xCB], 0    ; Clear the high dword or it.
    4443  %endif
     44        push    dword 0
    4545        push    sAX
    46 
    47   %if TMPL_BITS == 16
    48         ; Convert the 16-bit near return into a 32-bit far return
    49         movzx   eax, word [bp + 8]
    50         add     eax, BS3_ADDR_BS3TEXT16
    51         mov     [bp + 2], eax
    52   %endif
     46        push    dword 0
     47        pushfd
     48        cli
    5349
    5450        ; Calc ring addend.
    5551        mov     ax, cs
    56         and     ax, 3
    57         shl     ax, BS3_SEL_RING_SHIFT
     52        and     xAX, 3
     53        shl     xAX, BS3_SEL_RING_SHIFT
     54        add     xAX, BS3_SEL_R0_CS32
    5855
    59         ; Set return segment.
    60         add     ax, BS3_SEL_R0_CS64
    61   %if TMPL_BITS == 16
    62         mov     [bp + 6], eax
    63   %else
    64         mov     [xSP + xCB*2], eax
    65   %endif
     56        ; setup far return.
     57        push    sAX
     58 %if TMPL_BITS == 16
     59        push    dword .sixty_four_bit
     60        o32 retf
     61 %else
     62        push    .sixty_four_bit
     63        retf
     64 %endif
    6665
     66BS3_SET_BITS 64
     67.sixty_four_bit:
    6768        ; Load 64-bit segment registers (SS64==DS64).
    68         add     ax, BS3_SEL_R0_DS64 - BS3_SEL_R0_CS64
     69        add     eax, BS3_SEL_R0_DS64 - BS3_SEL_R0_CS64
    6970        mov     ss, ax
    7071        mov     ds, ax
    7172        mov     es, ax
    7273
    73         ; Restore and return.
    74         pop     sAX
    75  %if TMPL_BITS == 16
    76         leave
    77         o32 retf
    78  %else
    79         retf
     74  %if TMPL_BITS == 16
     75        movzx   eax, word [rsp + 8*2+6]
     76        add     eax, BS3_ADDR_BS3TEXT16
     77        mov     [rsp + 8*2], rax
     78  %endif
     79
     80        popf
     81        pop     rax
     82        ret
    8083 %endif
    81 %endif
    8284BS3_PROC_END_CMN   Bs3SwitchTo64Bit
    8385
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchToRing1.asm

    r58812 r59215  
    4141        int     BS3_TRAP_SYSCALL
    4242
    43 .return
     43.return:
    4444        pop     sAX
    4545        ret
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-first-pe16.asm

    r58814 r59215  
    4949EXTERN Bs3SwitchToRM_pe16
    5050EXTERN Bs3SwitchToPE32_rm
     51EXTERN Bs3SwitchTo32Bit_c16
     52EXTERN Bs3SwitchTo32Bit_c32
     53EXTERN Bs3SwitchTo16Bit_c16
     54EXTERN Bs3SwitchTo16Bit_c32
    5155EXTERN Bs3SwitchToRM_pe32
    5256EXTERN Bs3InitMemory_rm
     
    6266    call    NAME(Bs3InitMemory_rm)      ; Initialize the memory (must be done from real mode).
    6367    call    NAME(Bs3SwitchToPE16_rm)
     68
     69    call    NAME(Bs3SwitchTo32Bit_c16)
     70    BS3_SET_BITS 32
     71    call    NAME(Bs3SwitchTo16Bit_c32)
     72    BS3_SET_BITS 16
     73
    6474    call    NAME(Bs3SwitchToRM_pe16)
    6575
    6676    call    NAME(Bs3SwitchToPE32_rm)
    6777    BS3_SET_BITS 32
    68 .halt: hlt
    69 jmp .halt
    7078    call    NAME(Bs3SwitchToRM_pe32)
    7179    BS3_SET_BITS 16
     80    call    NAME(Bs3SwitchToPE16_rm)
    7281
    7382
     
    7584    ; Call main, if it returns shutdown the system.
    7685    ;
     86.halt: hlt
     87jmp .halt
    7788    call    NAME(Main_pe16)
    7889    call    Bs3Shutdown
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToRM.asm

    r58812 r59215  
    7373 extern TODO_FIX_LM_MODE_RETURN
    7474%endif
     75
    7576        push    eax
    7677        mov     eax, cr0
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-template-header.mac

    r58812 r59215  
    690690 %define xPUSHF pushq
    691691 %define xPOPF  popfq
     692 %define xRETF  o64 retf
    692693%else
    693694 %ifdef TMPL_32BIT
     
    707708  %define xPUSHF pushfd
    708709  %define xPOPF  popfd
     710  %define xRETF  retf
    709711 %else
    710712  %ifndef TMPL_16BIT
     
    726728  %define xPUSHF pushf
    727729  %define xPOPF  popf
     730  %define xRETF  retf
    728731 %endif
    729732%endif
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.mac

    r59210 r59215  
    405405  %endif
    406406 %endif
     407 int3                                   ; handy and avoids overlapping labels.
    407408%endmacro
    408409
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