VirtualBox

Changeset 60194 in vbox for trunk


Ignore:
Timestamp:
Mar 26, 2016 1:17:53 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
106228
Message:

bs3kit: updates.

Location:
trunk/src/VBox/ValidationKit/bootsectors
Files:
1 added
10 edited
2 copied

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/src/VBox/ValidationKit/bootsectors/Makefile.kmk

    r60140 r60194  
    228228#
    229229
    230 # shutdown example.
     230# CPU basics #2 (first being bootsector2-cpu-basic-1).
    231231MISCBINS += bs3-cpu-basic-2
    232232bs3-cpu-basic-2_TEMPLATE = VBoxBS3KitImg
     
    243243       bs3kit/bs3-cmn-instantiate.c16 \
    244244       bs3kit/bs3-cmn-instantiate.c32 \
    245        bs3kit/bs3-cmn-instantiate.c64 \
    246 
     245       bs3kit/bs3-cmn-instantiate.c64
     246bs3-cpu-basic-2-template.o:: $$(addprefix $$(bs3-cpu-basic-2_0_OUTDIR)/bs3kit/bs3-cmn-instantiate,.o16 .o32 .o64)
    247247endif
    248248
  • TabularUnified trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-c.c

    r60024 r60194  
    3636*********************************************************************************************************************************/
    3737BS3TESTMODE_PROTOTYPES_MODE(bs3CpuBasic2_TssGateEsp);
     38BS3TESTMODE_PROTOTYPES_MODE(bs3CpuBasic2_RaiseXcpt1);
    3839//BS3TESTMODE_PROTOTYPES_CMN(bs3CpuBasic2_iret);
    3940//BS3TESTMODE_PROTOTYPES_MODE(bs3CpuBasic2_iret);
     
    4546static const BS3TESTMODEENTRY g_aModeTest[] =
    4647{
    47     BS3TESTMODEENTRY_MODE("tss / gate / esp", bs3CpuBasic2_TssGateEsp),
     48    //BS3TESTMODEENTRY_MODE("tss / gate / esp", bs3CpuBasic2_TssGateEsp),
     49    BS3TESTMODEENTRY_MODE("raise xcpt #1", bs3CpuBasic2_RaiseXcpt1),
    4850    //BS3TESTMODEENTRY_CMN("iret", bs3CpuBasic2_iret),
    4951    //BS3TESTMODEENTRY_MODE("iret", bs3CpuBasic2_iret),
  • TabularUnified trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.c

    r60184 r60194  
    3535
    3636/*********************************************************************************************************************************
     37*   Defined Constants And Macros                                                                                                 *
     38*********************************************************************************************************************************/
     39# undef MyBs3Idt
     40# if BS3_MODE_IS_16BIT_SYS(TMPL_MODE)
     41#  define MyBs3Idt  BS3_DATA_NM(Bs3Idt16)
     42# elif BS3_MODE_IS_32BIT_SYS(TMPL_MODE)
     43#  define MyBs3Idt  BS3_DATA_NM(Bs3Idt32)
     44# elif BS3_MODE_IS_64BIT_SYS(TMPL_MODE)
     45#  define MyBs3Idt  BS3_DATA_NM(Bs3Idt64)
     46# else
     47#  error "TMPL_MODE"
     48# endif
     49
     50
     51/*********************************************************************************************************************************
    3752*   Internal Functions                                                                                                           *
    3853*********************************************************************************************************************************/
    39 extern BS3_DECL(void) TMPL_NM(bs3CpuBasic2_TssGateEsp_IntXx)(void);
    40 
    41 
    42 # if TMPL_MODE == BS3_MODE_PE16 \
    43   || TMPL_MODE == BS3_MODE_PE16_32
    44 
     54extern BS3_DECL(void) TMPL_NM(bs3CpuBasic2_Int80)(void);
     55extern BS3_DECL(void) TMPL_NM(bs3CpuBasic2_Int81)(void);
     56extern BS3_DECL(void) TMPL_NM(bs3CpuBasic2_Int82)(void);
     57extern BS3_DECL(void) TMPL_NM(bs3CpuBasic2_Int83)(void);
     58
     59
     60#if TMPL_MODE == BS3_MODE_PE16 || TMPL_MODE == BS3_MODE_PE16_32 || TMPL_MODE == BS3_MODE_LM64
    4561/**
    4662 * Compares trap stuff.
     
    6379        Bs3TrapPrintFrame(pTrapCtx);
    6480}
    65 
    66 
     81#endif
     82
     83
     84#if TMPL_MODE == BS3_MODE_PE16 || TMPL_MODE == BS3_MODE_PE16_32
    6785/**
    6886 * Worker for bs3CpuBasic2_TssGateEsp that tests the INT 80 from outer rings.
     
    117135    }
    118136}
    119 
    120137#endif
    121138
     
    148165    Bs3RegCtxSave(&Ctx);
    149166    Ctx.rsp.u -= 0x80;
    150     Ctx.rip.u  = (uintptr_t)BS3_FP_OFF(&TMPL_NM(bs3CpuBasic2_TssGateEsp_IntXx));
     167    Ctx.rip.u  = (uintptr_t)BS3_FP_OFF(&TMPL_NM(bs3CpuBasic2_Int80));
    151168# if TMPL_BITS == 32
    152169    BS3_DATA_NM(g_uBs3TrapEipHint) = Ctx.rip.u32;
     
    158175     * the DPLs.
    159176     */
    160 # if BS3_MODE_IS_16BIT_SYS(TMPL_MODE)
    161     BS3_DATA_NM(Bs3Idt16)[0x80].Gate.u2Dpl = 3;
    162     BS3_DATA_NM(Bs3Idt16)[0x81].Gate.u2Dpl = 0;
    163 # else
    164     BS3_DATA_NM(Bs3Idt32)[0x80].Gate.u2Dpl = 3;
    165     BS3_DATA_NM(Bs3Idt32)[0x81].Gate.u2Dpl = 0;
    166 # endif
     177    MyBs3Idt[0x80].Gate.u2Dpl = 3;
     178    MyBs3Idt[0x81].Gate.u2Dpl = 0;
    167179
    168180    /*
     
    238250     * Re-initialize the IDT.
    239251     */
    240 #if BS3_MODE_IS_16BIT_SYS(TMPL_MODE)
    241     Bs3Trap16Init();
    242 #elif BS3_MODE_IS_32BIT_SYS(TMPL_MODE)
    243     Bs3Trap32Init();
    244 #elif BS3_MODE_IS_32BIT_SYS(TMPL_MODE)
    245     Bs3Trap64Init();
    246 #endif
    247 
     252    TMPL_NM(Bs3TrapInit)();
    248253    return bRet;
    249254}
     255
     256
     257
     258BS3_DECL(uint8_t) TMPL_NM(bs3CpuBasic2_RaiseXcpt1)(uint8_t bMode)
     259{
     260    uint8_t         bRet = 0;
     261    BS3TRAPFRAME    TrapCtx;
     262    BS3REGCTX       Ctx80;
     263    BS3REGCTX       Ctx81;
     264    BS3REGCTX       Ctx82;
     265    BS3REGCTX       Ctx83;
     266    uint8_t        *pbTmp;
     267    unsigned        uLine;
     268    const char     *pszMode = BS3_DATA_NM(TMPL_NM(g_szBs3ModeName));
     269    bool const      f16BitSys = BS3_MODE_IS_16BIT_SYS(TMPL_MODE);
     270
     271    pbTmp = NULL; NOREF(pbTmp); uLine = 0; NOREF(uLine); NOREF(pszMode); NOREF(f16BitSys);
     272
     273    /* make sure they're allocated  */
     274    Bs3MemZero(&Ctx80, sizeof(Ctx80));
     275    Bs3MemZero(&Ctx81, sizeof(Ctx81));
     276    Bs3MemZero(&Ctx82, sizeof(Ctx82));
     277    Bs3MemZero(&Ctx83, sizeof(Ctx83));
     278    Bs3MemZero(&TrapCtx, sizeof(TrapCtx));
     279
     280#if !BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
     281
     282    /*
     283     * IDT entry 80 thru 83 are assigned DPLs according to the number.
     284     * (We'll be useing more, but this'll do for now.)
     285     */
     286    MyBs3Idt[0x80].Gate.u2Dpl = 0;
     287    MyBs3Idt[0x81].Gate.u2Dpl = 1;
     288    MyBs3Idt[0x82].Gate.u2Dpl = 2;
     289    MyBs3Idt[0x83].Gate.u2Dpl = 3;
     290
     291    Bs3RegCtxSave(&Ctx80);
     292    Ctx80.rsp.u -= 0x80;
     293    Ctx80.rip.u  = (uintptr_t)BS3_FP_OFF(&TMPL_NM(bs3CpuBasic2_Int80));
     294# if TMPL_BITS == 32
     295    BS3_DATA_NM(g_uBs3TrapEipHint) = Ctx80.rip.u32;
     296# endif
     297    Bs3MemCpy(&Ctx81, &Ctx80, sizeof(Ctx80));
     298    Ctx81.rip.u  = (uintptr_t)BS3_FP_OFF(&TMPL_NM(bs3CpuBasic2_Int81));
     299    Bs3MemCpy(&Ctx82, &Ctx80, sizeof(Ctx80));
     300    Ctx82.rip.u  = (uintptr_t)BS3_FP_OFF(&TMPL_NM(bs3CpuBasic2_Int82));
     301    Bs3MemCpy(&Ctx83, &Ctx80, sizeof(Ctx80));
     302    Ctx83.rip.u  = (uintptr_t)BS3_FP_OFF(&TMPL_NM(bs3CpuBasic2_Int83));
     303
     304    /*
     305     * Check that all the above gates work from ring-0.
     306     */
     307    Bs3TrapSetJmpAndRestore(&Ctx80, &TrapCtx);
     308    bs3CpuBasic2_CompareTrapCtx1(&TrapCtx, &Ctx80, 2 /*int 80h*/, 0x80 /*bXcpt*/, pszMode, __LINE__);
     309    Bs3TrapSetJmpAndRestore(&Ctx81, &TrapCtx);
     310    bs3CpuBasic2_CompareTrapCtx1(&TrapCtx, &Ctx81, 2 /*int 81h*/, 0x81 /*bXcpt*/, pszMode, __LINE__);
     311    Bs3TrapSetJmpAndRestore(&Ctx82, &TrapCtx);
     312    bs3CpuBasic2_CompareTrapCtx1(&TrapCtx, &Ctx82, 2 /*int 82h*/, 0x82 /*bXcpt*/, pszMode, __LINE__);
     313    Bs3TrapSetJmpAndRestore(&Ctx83, &TrapCtx);
     314    bs3CpuBasic2_CompareTrapCtx1(&TrapCtx, &Ctx83, 2 /*int 83h*/, 0x83 /*bXcpt*/, pszMode, __LINE__);
     315
     316#if 0
     317    /*
     318     * Check that the basic stuff works first.
     319     */
     320    Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
     321    bs3CpuBasic2_CompareTrapCtx1(&TrapCtx, &Ctx, 2 /*int 80h*/, 0x80 /*bXcpt*/, pszMode, __LINE__);
     322
     323    bs3CpuBasic2_TssGateEsp_AltStackOuterRing(&Ctx, 1, NULL, 0, f16BitSys, f16BitSys, f16BitSys, pszMode, __LINE__);
     324    bs3CpuBasic2_TssGateEsp_AltStackOuterRing(&Ctx, 2, NULL, 0, f16BitSys, f16BitSys, f16BitSys, pszMode, __LINE__);
     325    bs3CpuBasic2_TssGateEsp_AltStackOuterRing(&Ctx, 3, NULL, 0, f16BitSys, f16BitSys, f16BitSys, pszMode, __LINE__);
     326
     327    /*
     328     * Check that the upper part of ESP is preserved when doing .
     329     */
     330    if ((BS3_DATA_NM(g_uBs3CpuDetected) & BS3CPU_TYPE_MASK) >= BS3CPU_80386)
     331    {
     332        size_t const cbAltStack = _8K;
     333        uint8_t *pbAltStack = Bs3MemAllocZ(BS3MEMKIND_TILED, cbAltStack);
     334        if (pbAltStack)
     335        {
     336            /* same ring */
     337            uLine = __LINE__;
     338            Bs3MemCpy(&Ctx2, &Ctx, sizeof(Ctx2));
     339            Ctx2.rsp.u = Bs3SelPtrToFlat(pbAltStack + 0x1980);
     340            if (Bs3TrapSetJmp(&TrapCtx))
     341                Bs3RegCtxRestore(&Ctx2, 0); /* (does not return) */
     342            bs3CpuBasic2_CompareTrapCtx1(&TrapCtx, &Ctx2, 2 /*int 80h*/, 0x80 /*bXcpt*/, pszMode, uLine);
     343# if TMPL_BITS == 16
     344            if ((pbTmp = (uint8_t *)ASMMemFirstNonZero(pbAltStack, cbAltStack)) != NULL)
     345                Bs3TestFailedF("%u - %s: someone touched the alt stack (%p) with SS:ESP=%04x:%#RX32: %p=%02x\n",
     346                               uLine, pszMode, pbAltStack, Ctx2.ss, Ctx2.rsp.u32, pbTmp, *pbTmp);
     347# else
     348            if (ASMMemIsZero(pbAltStack, cbAltStack))
     349                Bs3TestFailedF("%u - %s: alt stack wasn't used despite SS:ESP=%04x:%#RX32\n",
     350                               uLine, pszMode, Ctx2.ss, Ctx2.rsp.u32);
     351# endif
     352
     353            /* Different rings (load SS0:SP0 from TSS). */
     354            bs3CpuBasic2_TssGateEsp_AltStackOuterRing(&Ctx, 1, pbAltStack, cbAltStack,
     355                                                      f16BitSys, f16BitSys, f16BitSys, pszMode, __LINE__);
     356            bs3CpuBasic2_TssGateEsp_AltStackOuterRing(&Ctx, 2, pbAltStack, cbAltStack,
     357                                                      f16BitSys, f16BitSys, f16BitSys, pszMode, __LINE__);
     358            bs3CpuBasic2_TssGateEsp_AltStackOuterRing(&Ctx, 3, pbAltStack, cbAltStack,
     359                                                      f16BitSys, f16BitSys, f16BitSys, pszMode, __LINE__);
     360
     361            /* Different rings but switch the SS bitness in the TSS. */
     362# if BS3_MODE_IS_16BIT_SYS(TMPL_MODE)
     363            Bs3Tss16.ss0 = BS3_SEL_R0_SS32;
     364            bs3CpuBasic2_TssGateEsp_AltStackOuterRing(&Ctx, 1, pbAltStack, cbAltStack,
     365                                                      false, f16BitSys, f16BitSys, pszMode, __LINE__);
     366            Bs3Tss16.ss0 = BS3_SEL_R0_SS16;
     367# else
     368            Bs3Tss32.ss0 = BS3_SEL_R0_SS16;
     369            bs3CpuBasic2_TssGateEsp_AltStackOuterRing(&Ctx, 1, pbAltStack, cbAltStack,
     370                                                      true,  f16BitSys, f16BitSys, pszMode, __LINE__);
     371            Bs3Tss32.ss0 = BS3_SEL_R0_SS32;
     372# endif
     373
     374            Bs3MemFree(pbAltStack, cbAltStack);
     375        }
     376        else
     377            Bs3TestPrintf("%s: Skipping ESP check, alloc failed\n", pszMode);
     378    }
     379    else
     380        Bs3TestPrintf("%s: Skipping ESP check, CPU too old\n", pszMode);
     381#endif
     382
     383#else
     384    bRet = BS3TESTDOMODE_SKIPPED;
     385#endif
     386
     387    /*
     388     * Re-initialize the IDT.
     389     */
     390    TMPL_NM(Bs3TrapInit)();
     391    return bRet;
     392}
     393
     394
    250395
    251396
  • TabularUnified trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.mac

    r60132 r60194  
    7373
    7474
    75 BS3_PROC_BEGIN_MODE bs3CpuBasic2_TssGateEsp_IntXx
     75BS3_PROC_BEGIN_MODE bs3CpuBasic2_Int80
    7676        int     80h
    77         nop
    78 BS3_PROC_END_MODE   bs3CpuBasic2_TssGateEsp_IntXx
     77        ud2
     78BS3_PROC_END_MODE   bs3CpuBasic2_Int80
    7979
     80
     81BS3_PROC_BEGIN_MODE bs3CpuBasic2_Int81
     82        int     81h
     83        ud2
     84BS3_PROC_END_MODE   bs3CpuBasic2_Int81
     85
     86
     87BS3_PROC_BEGIN_MODE bs3CpuBasic2_Int82
     88        int     82h
     89        ud2
     90BS3_PROC_END_MODE   bs3CpuBasic2_Int82
     91
     92
     93BS3_PROC_BEGIN_MODE bs3CpuBasic2_Int83
     94        int     83h
     95        ud2
     96BS3_PROC_END_MODE   bs3CpuBasic2_Int83
    8097
    8198
  • TabularUnified trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk

    r60137 r60194  
    124124        bs3-cmn-Trap32Init.c \
    125125        bs3-cmn-Trap32SetGate.c \
     126        bs3-cmn-Trap64Init.c \
    126127        bs3-cmn-Trap64SetGate.c \
    127128        bs3-cmn-TrapDefaultHandler.c \
     
    191192bs3kit-common-64-asm_DEFS     = TMPL_LM64 BS3_CMN_ONLY
    192193bs3kit-common-64-asm_ASDEFS   = RT_ASMDEFS_INC_FIRST_FILE
    193 bs3kit-common-64-asm_SOURCES  = $(filter %.asm,$(VBOX_BS3KIT_COMMON_SOURCES))
     194bs3kit-common-64-asm_SOURCES  = $(filter %.asm,$(VBOX_BS3KIT_COMMON_SOURCES)) \
     195       bs3-c64-Trap64Generic.asm
    194196
    195197# The 64-bit BS3Kit library.
     
    234236        bs3-mode-PagingGetRootForPAE32.asm \
    235237        bs3-mode-PagingGetRootForLM64.asm \
     238        bs3-mode-TrapInit.c \
    236239        bs3-mode-TrapSystemCallHandler.asm \
    237240        bs3-mode-TestDoModes.c \
  • TabularUnified trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-c64-Trap64Generic.asm

    r60188 r60194  
    11; $Id$
    22;; @file
    3 ; BS3Kit - Trap, 32-bit assembly handlers.
     3; BS3Kit - Trap, 64-bit assembly handlers.
    44;
    55
     
    3030%include "bs3kit-template-header.mac"
    3131
    32 %ifndef TMPL_32BIT
    33  %error "32-bit only template"
     32%ifndef TMPL_64BIT
     33 %error "64-bit only template"
    3434%endif
    3535
     
    3939;*********************************************************************************************************************************
    4040BS3_EXTERN_DATA16 g_bBs3CurrentMode
    41 BS3_EXTERN_SYSTEM16 Bs3Gdt
    4241TMPL_BEGIN_TEXT
    4342BS3_EXTERN_CMN Bs3TrapDefaultHandler
     
    5049;*********************************************************************************************************************************
    5150BS3_BEGIN_DATA16
    52 ;; Easy to access flat address of Bs3Trap32GenericEntries.
    53 BS3_GLOBAL_DATA g_Bs3Trap32GenericEntriesFlatAddr, 4
    54         dd Bs3Trap32GenericEntries wrt FLAT
    55 ;; Easy to access flat address of Bs3Trap32DoubleFaultHandler.
    56 BS3_GLOBAL_DATA g_Bs3Trap32DoubleFaultHandlerFlatAddr, 4
    57         dd Bs3Trap32DoubleFaultHandler wrt FLAT
    58 
    59 BS3_BEGIN_DATA32
     51;; Easy to access flat address of Bs3Trap64GenericEntries.
     52BS3_GLOBAL_DATA g_Bs3Trap64GenericEntriesFlatAddr, 4
     53        dd Bs3Trap64GenericEntries wrt FLAT
     54
     55BS3_BEGIN_DATA64
    6056;; Pointer C trap handlers.
    61 BS3_GLOBAL_DATA g_apfnBs3TrapHandlers_c32, 1024
    62         resd 256
     57BS3_GLOBAL_DATA g_apfnBs3TrapHandlers_c64, 2048
     58        resq 256
    6359
    6460
     
    6763; Generic entry points for IDT handlers, 8 byte spacing.
    6864;
    69 BS3_PROC_BEGIN Bs3Trap32GenericEntries
    70 %macro Bs3Trap32GenericEntry 1
     65BS3_PROC_BEGIN Bs3Trap64GenericEntries
     66%macro Bs3Trap64GenericEntry 1
    7167        db      06ah, i                 ; push imm8 - note that this is a signextended value.
    7268        jmp     %1
     
    7672
    7773%assign i 0                             ; start counter.
    78         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; 0
    79         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; 1
    80         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; 2
    81         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; 3
    82         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; 4
    83         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; 5
    84         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; 6
    85         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; 7
    86         Bs3Trap32GenericEntry bs3Trap32GenericTrapErrCode ; 8
    87         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; 9
    88         Bs3Trap32GenericEntry bs3Trap32GenericTrapErrCode ; a
    89         Bs3Trap32GenericEntry bs3Trap32GenericTrapErrCode ; b
    90         Bs3Trap32GenericEntry bs3Trap32GenericTrapErrCode ; c
    91         Bs3Trap32GenericEntry bs3Trap32GenericTrapErrCode ; d
    92         Bs3Trap32GenericEntry bs3Trap32GenericTrapErrCode ; e
    93         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; f  (reserved)
    94         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; 10
    95         Bs3Trap32GenericEntry bs3Trap32GenericTrapErrCode ; 11
    96         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; 12
    97         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; 13
    98         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; 14
    99         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; 15 (reserved)
    100         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; 16 (reserved)
    101         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; 17 (reserved)
    102         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; 18 (reserved)
    103         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; 19 (reserved)
    104         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; 1a (reserved)
    105         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; 1b (reserved)
    106         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; 1c (reserved)
    107         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; 1d (reserved)
    108         Bs3Trap32GenericEntry bs3Trap32GenericTrapErrCode ; 1e
    109         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt   ; 1f (reserved)
     74        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; 0
     75        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; 1
     76        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; 2
     77        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; 3
     78        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; 4
     79        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; 5
     80        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; 6
     81        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; 7
     82        Bs3Trap64GenericEntry Bs3Trap64GenericTrapErrCode ; 8
     83        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; 9
     84        Bs3Trap64GenericEntry Bs3Trap64GenericTrapErrCode ; a
     85        Bs3Trap64GenericEntry Bs3Trap64GenericTrapErrCode ; b
     86        Bs3Trap64GenericEntry Bs3Trap64GenericTrapErrCode ; c
     87        Bs3Trap64GenericEntry Bs3Trap64GenericTrapErrCode ; d
     88        Bs3Trap64GenericEntry Bs3Trap64GenericTrapErrCode ; e
     89        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; f  (reserved)
     90        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; 10
     91        Bs3Trap64GenericEntry Bs3Trap64GenericTrapErrCode ; 11
     92        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; 12
     93        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; 13
     94        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; 14
     95        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; 15 (reserved)
     96        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; 16 (reserved)
     97        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; 17 (reserved)
     98        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; 18 (reserved)
     99        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; 19 (reserved)
     100        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; 1a (reserved)
     101        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; 1b (reserved)
     102        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; 1c (reserved)
     103        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; 1d (reserved)
     104        Bs3Trap64GenericEntry Bs3Trap64GenericTrapErrCode ; 1e
     105        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt   ; 1f (reserved)
    110106%rep 224
    111         Bs3Trap32GenericEntry bs3Trap32GenericTrapOrInt
     107        Bs3Trap64GenericEntry Bs3Trap64GenericTrapOrInt
    112108%endrep
    113 BS3_PROC_END  Bs3Trap32GenericEntries
     109BS3_PROC_END  Bs3Trap64GenericEntries
    114110
    115111
     
    119115; Trap or interrupt (no error code).
    120116;
    121 BS3_PROC_BEGIN bs3Trap32GenericTrapOrInt
    122         push    ebp                     ; 0
    123         mov     ebp, esp
    124         pushfd                          ; -04h
     117BS3_PROC_BEGIN Bs3Trap64GenericTrapOrInt
     118        push    rbp                     ; 0
     119        mov     rbp, rsp
     120        pushfq                          ; -08h
    125121        cli
    126122        cld
    127         push    eax                     ; -08h
    128         push    edi                     ; -0ch
    129         lea     eax, [esp + (4 + 1)*4]  ; 4 pushes above, 1 exception number push.
    130         push    eax                     ; -10h = handler ESP
    131         add     eax, 3*4                ; 3 dword iret frame
    132         push    eax                     ; -14h = caller ESP if same CPL
    133         push    ss                      ; -18h
    134         push    ds                      ; -1ch
    135 
    136         ; Make sure we've got a flat DS (ASSUMES ring-0). It makes everything so much simpler.
    137         mov     ax, BS3_SEL_R0_DS32
    138         mov     ds, ax
    139 
    140         ;
    141         ; We may be comming from 16-bit code with a 16-bit SS.  Thunk it as
    142         ; the C code may assume flat SS and we'll mess up by using EBP/ESP/EDI
    143         ; instead of BP/SP/SS:DI. ASSUMES standard GDT selector.
    144         ;
    145         mov     ax, ss
    146         lar     eax, ax
    147         test    eax, X86LAR_F_D
    148         jz      .stack_thunk
    149         mov     ax, BS3_SEL_R0_SS32
    150         mov     ss, ax
    151         jmp     .stack_flat
    152 .stack_thunk:
    153         mov     di, ss
    154         and     edi, X86_SEL_MASK_OFF_RPL
    155         mov     al, [X86DESCGENERIC_BIT_OFF_BASE_HIGH1 / 8 + edi + Bs3Gdt wrt FLAT]
    156         mov     ah, [X86DESCGENERIC_BIT_OFF_BASE_HIGH2 / 8 + edi + Bs3Gdt wrt FLAT]
    157         shl     eax, 16
    158         mov     ax, [X86DESCGENERIC_BIT_OFF_BASE_LOW / 8   + edi + Bs3Gdt wrt FLAT] ; eax = SS.base
    159         movzx   ebp, bp                 ; SS:BP -> flat EBP.
    160         add     ebp, eax
    161         movzx   edi, sp                 ; SS:SP -> flat ESP in EAX.
    162         add     eax, edi
    163         mov     di, BS3_SEL_R0_SS32
    164         mov     ss, di
    165         mov     esp, eax
    166         sub     dword [ebp - 10h], (4+1)*4   ; Recalc handler ESP in case of wraparound.
    167         add     word [ebp - 10h],  (4+1)*4
    168         sub     dword [ebp - 10h], (4+1+3)*4 ; Recalc caller ESP in case of wraparound.
    169         add     word [ebp - 10h],  (4+1+3)*4
    170 .stack_flat:
     123        push    rdi
    171124
    172125        ; Reserve space for the the register and trap frame.
    173         mov     eax, (BS3TRAPFRAME_size + 7) / 8
    174 AssertCompileSizeAlignment(BS3TRAPFRAME, 8)
     126        mov     edi, (BS3TRAPFRAME_size + 15) / 16
    175127.more_zeroed_space:
    176         push    dword 0
    177         push    dword 0
    178         dec     eax
     128        push    qword 0
     129        push    qword 0
     130        dec     edi
    179131        jnz     .more_zeroed_space
    180         mov     edi, esp                ; edi points to trapframe structure.
     132        mov     rdi, rsp                ; rdi points to trapframe structure.
     133
     134        ; Free up rax.
     135        mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rax], rax
    181136
    182137        ; Copy stuff from the stack over.
    183         mov     al, [ebp + 4]
    184         mov     [edi + BS3TRAPFRAME.bXcpt], al
    185         mov     eax, [ebp]
    186         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rbp], eax
    187         mov     eax, [ebp - 04h]
    188         mov     [edi + BS3TRAPFRAME.fHandlerRfl], eax
    189         mov     eax, [ebp - 08h]
    190         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rax], eax
    191         mov     eax, [ebp - 0ch]
    192         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rdi], eax
    193         mov     eax, [ebp - 10h]
    194         mov     [edi + BS3TRAPFRAME.uHandlerRsp], eax
    195         mov     eax, [ebp - 14h]
    196         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rsp], eax
    197         mov     ax, [ebp - 18h]
    198         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.ss], ax
    199         mov     [edi + BS3TRAPFRAME.uHandlerSs], ax
    200         mov     ax, [ebp - 1ch]
    201         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.ds], ax
    202 
    203         lea     ebp, [ebp + 4]          ; iret - 4 (i.e. ebp frame chain location)
    204         jmp     bs3Trap32GenericCommon
    205 BS3_PROC_END   bs3Trap32GenericTrapOrInt
     138        mov     al, [rbp + 08h]
     139        mov     [rdi + BS3TRAPFRAME.bXcpt], al
     140        mov     rax, [rbp]
     141        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.rbp], rax
     142        mov     rax, [rbp - 08h]
     143        mov     [rdi + BS3TRAPFRAME.fHandlerRfl], rax
     144        mov     rax, [rbp - 10h]
     145        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.rdi], rax
     146
     147        lea     rbp, [rbp + 08h]        ; iret - 8 (i.e. rbp frame chain location)
     148        jmp     Bs3Trap64GenericCommon
     149BS3_PROC_END   Bs3Trap64GenericTrapOrInt
    206150
    207151
     
    209153; Trap with error code.
    210154;
    211 BS3_PROC_BEGIN bs3Trap32GenericTrapErrCode
    212         push    ebp                     ; 0
    213         mov     ebp, esp
    214         pushfd                          ; -04h
     155BS3_PROC_BEGIN Bs3Trap64GenericTrapErrCode
     156        push    rbp                     ; 0
     157        mov     rbp, rsp
     158        pushfq                          ; -08h
    215159        cli
    216160        cld
    217         push    eax                     ; -08h
    218         push    edi                     ; -0ch
    219         lea     eax, [esp + (4+1+1)*4]  ; 4 pushes above, 1 exception number push, 1 error code.
    220         push    eax                     ; -10h = handler ESP
    221         add     eax, 3*4                ; 3 dword iret frame
    222         push    eax                     ; -14h = caller ESP if same CPL
    223         push    ss                      ; -18h
    224         push    ds                      ; -1ch
    225 
    226         ; Make sure we've got a flat DS (ASSUMES ring-0). It makes everything so much simpler.
    227         mov     ax, BS3_SEL_R0_DS32
    228         mov     ds, ax
    229 
    230         ;
    231         ; We may be comming from 16-bit code with a 16-bit SS.  Thunk it as
    232         ; the C code may assume flat SS and we'll mess up by using EBP/ESP/EDI
    233         ; instead of BP/SP/SS:DI. ASSUMES standard GDT selector.
    234         ;
    235         mov     ax, ss
    236         lar     eax, ax
    237         test    eax, X86LAR_F_D
    238         jz      .stack_thunk
    239         mov     ax, BS3_SEL_R0_SS32
    240         mov     ss, ax
    241         jmp     .stack_flat
    242 .stack_thunk:
    243         mov     di, ss
    244         and     edi, X86_SEL_MASK_OFF_RPL
    245         mov     al, [X86DESCGENERIC_BIT_OFF_BASE_HIGH1 / 8 + edi + Bs3Gdt wrt FLAT]
    246         mov     ah, [X86DESCGENERIC_BIT_OFF_BASE_HIGH2 / 8 + edi + Bs3Gdt wrt FLAT]
    247         shl     eax, 16
    248         mov     ax, [X86DESCGENERIC_BIT_OFF_BASE_LOW / 8   + edi + Bs3Gdt wrt FLAT] ; eax = SS.base
    249         movzx   ebp, bp                 ; SS:BP -> flat EBP.
    250         add     ebp, eax
    251         movzx   edi, sp                 ; SS:SP -> flat ESP in EAX.
    252         add     eax, edi
    253         mov     di, BS3_SEL_R0_SS32
    254         mov     ss, di
    255         mov     esp, eax
    256         sub     dword [ebp - 10h], (4+1+1)*4   ; Recalc handler ESP in case of wraparound.
    257         add     word [ebp - 10h],  (4+1+1)*4
    258         sub     dword [ebp - 14h], (4+1+1+3)*4 ; Recalc caller ESP in case of wraparound.
    259         add     word [ebp - 14h],  (4+1+1+3)*4
    260 .stack_flat:
     161        push    rdi
    261162
    262163        ; Reserve space for the the register and trap frame.
    263         mov     eax, (BS3TRAPFRAME_size + 7) / 8
    264 AssertCompileSizeAlignment(BS3TRAPFRAME, 8)
     164        mov     edi, (BS3TRAPFRAME_size + 15) / 16
    265165.more_zeroed_space:
    266         push    dword 0
    267         push    dword 0
    268         dec     eax
     166        push    qword 0
     167        push    qword 0
     168        dec     edi
    269169        jnz     .more_zeroed_space
    270         mov     edi, esp                ; edi points to trapframe structure.
     170        mov     rdi, rsp                ; rdi points to trapframe structure.
     171
     172        ; Free up rax.
     173        mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rax], rax
    271174
    272175        ; Copy stuff from the stack over.
    273         mov     eax, [ebp + 8]
    274 ;; @todo Do voodoo checks for 'int xx' or misguided hardware interrupts.
    275         mov     [edi + BS3TRAPFRAME.uErrCd], eax
    276         mov     al, [ebp + 4]
    277         mov     [edi + BS3TRAPFRAME.bXcpt], al
    278         mov     eax, [ebp]
    279         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rbp], eax
    280         mov     eax, [ebp - 04h]
    281         mov     [edi + BS3TRAPFRAME.fHandlerRfl], eax
    282         mov     eax, [ebp - 08h]
    283         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rax], eax
    284         mov     eax, [ebp - 0ch]
    285         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rdi], eax
    286         mov     eax, [ebp - 10h]
    287         mov     [edi + BS3TRAPFRAME.uHandlerRsp], eax
    288         mov     eax, [ebp - 14h]
    289         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rsp], eax
    290         mov     ax, [ebp - 18h]
    291         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.ss], ax
    292         mov     [edi + BS3TRAPFRAME.uHandlerSs], ax
    293         mov     ax, [ebp - 1ch]
    294         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.ds], ax
    295 
    296         lea     ebp, [ebp + 8]          ; iret - 4 (i.e. ebp frame chain location)
    297         jmp     bs3Trap32GenericCommon
    298 BS3_PROC_END   bs3Trap32GenericTrapErrCode
     176        mov     rax, [rbp + 10h]
     177        mov     [rdi + BS3TRAPFRAME.uErrCd], rax
     178        mov     al, [rbp + 08h]
     179        mov     [rdi + BS3TRAPFRAME.bXcpt], al
     180        mov     rax, [rbp]
     181        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.rbp], rax
     182        mov     rax, [rbp - 08h]
     183        mov     [rdi + BS3TRAPFRAME.fHandlerRfl], rax
     184        mov     rax, [rbp - 10h]
     185        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.rdi], rax
     186
     187        lea     rbp, [rbp + 10h]        ; iret - 8 (i.e. rbp frame chain location)
     188        jmp     Bs3Trap64GenericCommon
     189BS3_PROC_END   Bs3Trap64GenericTrapErrCode
    299190
    300191
     
    302193; Common context saving code and dispatching.
    303194;
    304 ; @param    edi     Pointer to the trap frame.  The following members have been
     195; @param    rdi     Pointer to the trap frame.  The following members have been
    305196;                   filled in by the previous code:
    306197;                       - bXcpt
    307198;                       - uErrCd
    308199;                       - fHandlerRfl
    309 ;                       - uHandlerRsp
    310 ;                       - uHandlerSs
    311200;                       - Ctx.rax
    312201;                       - Ctx.rbp
    313202;                       - Ctx.rdi
    314 ;                       - Ctx.rsp - assuming same CPL
    315 ;                       - Ctx.ds
    316 ;                       - Ctx.ss
    317 ;
    318 ; @param    ebp     Pointer to the dword before the iret frame, i.e. where ebp
     203;
     204; @param    rbp     Pointer to the dword before the iret frame, i.e. where rbp
    319205;                   would be saved if this was a normal call.
    320206;
    321 BS3_PROC_BEGIN bs3Trap32GenericCommon
    322         ;
    323         ; Fake EBP frame.
    324         ;
    325         mov     eax, [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rbp]
    326         mov     [ebp], eax
     207BS3_PROC_BEGIN Bs3Trap64GenericCommon
     208        ;
     209        ; Fake RBP frame.
     210        ;
     211        mov     rax, [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.rbp]
     212        mov     [rbp], rax
    327213
    328214        ;
    329215        ; Save the remaining GPRs and segment registers.
    330216        ;
    331         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rcx], ecx
    332         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rdx], edx
    333         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rbx], ebx
    334         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rsi], esi
    335         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.es], es
    336         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.fs], fs
    337         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.gs], gs
    338 
    339         ;
    340         ; Load 32-bit data selector for the DPL we're executing at into DS and ES.
     217        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.rcx], rcx
     218        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.rdx], rdx
     219        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.rbx], rbx
     220        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.rsi], rsi
     221        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.r8 ], r8
     222        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.r9 ], r9
     223        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.r10], r10
     224        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.r11], r11
     225        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.r12], r12
     226        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.r13], r13
     227        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.r14], r14
     228        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.r15], r15
     229        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.ds], ds
     230        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.es], es
     231        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.fs], fs
     232        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.gs], gs
     233        lea     rax, [rbp + 8h]
     234        mov     [rdi + BS3TRAPFRAME.uHandlerRsp], rax
     235        mov     [rdi + BS3TRAPFRAME.uHandlerSs], ss
     236
     237        ;
     238        ; Load 32-bit data selector for the DPL we're executing at into DS, ES and SS.
    341239        ; Save the handler CS value first.
    342240        ;
    343241        mov     ax, cs
    344         mov     [edi + BS3TRAPFRAME.uHandlerCs], ax
     242        mov     [rdi + BS3TRAPFRAME.uHandlerCs], ax
    345243        and     ax, 3
    346         mov     cx, ax
     244        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.bCpl], al
     245
     246        mov     cx, ax                  ; AX is CPL, see above.
    347247        shl     ax, BS3_SEL_RING_SHIFT
    348248        or      ax, cx
    349         add     ax, BS3_SEL_R0_DS32
     249        add     ax, BS3_SEL_R0_DS64
    350250        mov     ds, ax
    351251        mov     es, ax
    352 
    353         ;
    354         ; Copy and update the mode now that we've got a flat DS.
     252        mov     ss, ax
     253
     254        ;
     255        ; Copy and update the mode.
    355256        ;
    356257        mov     al, [BS3_DATA16_WRT(g_bBs3CurrentMode)]
    357         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.bMode], al
     258        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.bMode], al
    358259        and     al, ~BS3_MODE_CODE_MASK
    359         or      al, BS3_MODE_CODE_32
     260        or      al, BS3_MODE_CODE_64
    360261        mov     [BS3_DATA16_WRT(g_bBs3CurrentMode)], al
    361262
    362263        ;
    363         ; Copy iret info.
    364         ;
    365         mov     ecx, [ebp + 4]
    366         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rip], ecx
    367         mov     ecx, [ebp + 12]
    368         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rflags], ecx
    369         mov     cx, [ebp + 8]
    370         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.cs], cx
    371         test    dword [ebp + 12], X86_EFL_VM
    372         jnz     .iret_frame_v8086
    373         mov     ax, ss
    374         and     al, 3
    375         and     cl, 3
    376         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.bCpl], cl
    377         cmp     cl, al
    378         je      .iret_frame_same_cpl
    379 
    380 .iret_frame_different_cpl:
    381         mov     ecx, [ebp + 16]
    382         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rsp], ecx
    383         mov     cx, [ebp + 20]
    384         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.ss], cx
    385         mov     byte [edi + BS3TRAPFRAME.cbIretFrame], 5*4
    386         jmp     .iret_frame_done
    387 
    388 .iret_frame_v8086:
    389         mov     byte [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.bCpl], 3
    390         or      byte [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.bMode], BS3_MODE_CODE_V86 ; paranoia ^ 2
    391         movzx   ecx, word [ebp + 16]
    392         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rsp], ecx
    393         mov     cx, [ebp + 20]
    394         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.ss], cx
    395         mov     cx, [ebp + 24]
    396         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.es], cx
    397         mov     cx, [ebp + 28]
    398         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.ds], cx
    399         mov     cx, [ebp + 32]
    400         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.fs], cx
    401         mov     cx, [ebp + 36]
    402         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.gs], cx
    403         mov     byte [edi + BS3TRAPFRAME.cbIretFrame], 9*4
    404         jmp     .iret_frame_done
    405 
    406 .iret_frame_same_cpl:                   ; (caller already set SS:RSP and uHandlerRsp for same CPL iret frames)
    407         mov     byte [edi + BS3TRAPFRAME.cbIretFrame], 3*4
    408 
    409 .iret_frame_done:
     264        ; Copy iret info.  Bless AMD for only doing one 64-bit iret frame layout.
     265        ;
     266        mov     rcx, [rbp + 08]
     267        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.rip], rcx
     268        mov     cx,  [rbp + 10h]
     269        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.cs], cx
     270        mov     rcx, [rbp + 18h]
     271        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.rflags], rcx
     272        mov     rcx, [rbp + 20h]
     273        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.rsp], rcx
     274        mov     cx,  [rbp + 28h]
     275        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.ss], cx
     276        mov     byte [rdi + BS3TRAPFRAME.cbIretFrame], 5*8
     277
    410278        ;
    411279        ; Control registers.
    412280        ;
    413         mov     eax, cr0
    414         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.cr0], eax
    415         mov     eax, cr2
    416         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.cr2], eax
    417         mov     eax, cr3
    418         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.cr3], eax
    419         mov     eax, cr4
    420         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.cr4], eax
     281        mov     rax, cr0
     282        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.cr0], rax
     283        mov     rax, cr2
     284        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.cr2], rax
     285        mov     rax, cr3
     286        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.cr3], rax
     287        mov     rax, cr4
     288        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.cr4], rax
    421289        str     ax
    422         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.tr], ax
     290        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.tr], ax
    423291        sldt    ax
    424         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.ldtr], ax
     292        mov     [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.ldtr], ax
    425293
    426294        ;
    427295        ; Dispatch it to C code.
    428296        ;
    429 .dispatch_to_handler:                   ; The double fault code joins us here.
    430         movzx   ebx, byte [edi + BS3TRAPFRAME.bXcpt]
    431         mov     eax, [ebx * 4 + BS3_DATA16_WRT(_g_apfnBs3TrapHandlers_c32)]
    432         or      eax, eax
     297        movzx   ebx, byte [rdi + BS3TRAPFRAME.bXcpt]
     298        lea     rax, [BS3_DATA16_WRT(_g_apfnBs3TrapHandlers_c64)]
     299        mov     rax, [rax + rbx * 8]
     300        or      rax, rax
    433301        jnz     .call_handler
    434         mov     eax, Bs3TrapDefaultHandler
     302        lea     rax, [BS3_WRT_RIP(Bs3TrapDefaultHandler)]
    435303.call_handler:
    436         push    edi
    437         call    eax
     304        sub     rsp, 20h
     305        mov     [rsp], rdi
     306        mov     rcx, rdi
     307        call    rax
    438308
    439309        ;
    440310        ; Resume execution using trap frame.
    441311        ;
    442         push    0
    443         add     edi, BS3TRAPFRAME.Ctx
    444         push    edi
     312        xor     edx, edx                        ; fFlags
     313        mov     [rsp + 8], rdx
     314        lea     rcx, [rdi + BS3TRAPFRAME.Ctx]   ; pCtx
     315        mov     [rsp], rcx
    445316        call    Bs3RegCtxRestore
    446317.panic:
    447318        hlt
    448319        jmp     .panic
    449 BS3_PROC_END   bs3Trap32GenericCommon
    450 
    451 
    452 ;;
    453 ; Helper.
    454 ;
    455 ; @retruns  Flat address in eax.
    456 ; @param    ax
    457 ; @uses     eax
    458 ;
    459 bs3Trap32TssInAxToFlatInEax:
    460         ; Get the GDT base address and find the descriptor address (EAX)
    461         sub     esp, 8+2
    462         sgdt    [esp]
    463         and     eax, 0fff8h
    464         add     eax, [esp + 2]          ; GDT base address.
    465         add     esp, 8+2
    466 
    467         ; Get the flat TSS address from the descriptor.
    468         mov     al, [eax + (X86DESCGENERIC_BIT_OFF_BASE_HIGH1 / 8)]
    469         mov     ah, [eax + (X86DESCGENERIC_BIT_OFF_BASE_HIGH2 / 8)]
    470         shl     eax, 16
    471         mov     ax, [eax + (X86DESCGENERIC_BIT_OFF_BASE_LOW / 8)]
    472         ret
    473 
    474 ;;
    475 ; Double fault handler.
    476 ;
    477 ; We don't have to load any selectors or clear anything in EFLAGS because the
    478 ; TSS specified sane values which got loaded during the task switch.
    479 ;
    480 BS3_PROC_BEGIN Bs3Trap32DoubleFaultHandler
    481         push    0                       ; We'll copy the rip from the other TSS here later to create a more sensible call chain.
    482         push    ebp
    483         mov     ebp, esp
    484 
    485         pushfd                          ; Get handler flags.
    486         pop     ecx
    487 
    488         xor     edx, edx                ; NULL register.
    489 
    490         ;
    491         ; Allocate a zero filled trap frame.
    492         ;
    493         mov     eax, (BS3TRAPFRAME_size + 7) / 8
    494 AssertCompileSizeAlignment(BS3TRAPFRAME, 8)
    495 .more_zeroed_space:
    496         push    edx
    497         push    edx
    498         dec     eax
    499         jz      .more_zeroed_space
    500         mov     edi, esp
    501 
    502         ;
    503         ; Fill in the non-context trap frame bits.
    504         ;
    505         mov     [edi + BS3TRAPFRAME.fHandlerRfl], ecx
    506         mov     word [edi + BS3TRAPFRAME.bXcpt], X86_XCPT_DF
    507         mov     [edi + BS3TRAPFRAME.uHandlerCs], cs
    508         mov     [edi + BS3TRAPFRAME.uHandlerSs], ss
    509         lea     ecx, [ebp + 3*4]        ; two pushes, one error code.
    510         mov     [edi + BS3TRAPFRAME.uHandlerRsp], ecx
    511         mov     ecx, [ebp + 8]
    512         mov     [edi + BS3TRAPFRAME.uErrCd], ecx
    513 
    514         ;
    515         ; Copy the register state from the previous task segment.
    516         ;
    517 
    518         ; Find our TSS.
    519         str     ax
    520         call    bs3Trap32TssInAxToFlatInEax
    521 
    522         ; Find the previous TSS.
    523         mov     ax, [eax + X86TSS32.selPrev]
    524         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.tr], ax
    525         call    bs3Trap32TssInAxToFlatInEax
    526 
    527         ; Do the copying.
    528         mov     ecx, [eax + X86TSS32.eax]
    529         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rax], ecx
    530         mov     ecx, [eax + X86TSS32.ecx]
    531         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rcx], ecx
    532         mov     ecx, [eax + X86TSS32.edx]
    533         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rdx], ecx
    534         mov     ecx, [eax + X86TSS32.ebx]
    535         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rbx], ecx
    536         mov     ecx, [eax + X86TSS32.esp]
    537         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rsp], ecx
    538         mov     ecx, [eax + X86TSS32.ebp]
    539         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rbp], ecx
    540         mov     [ebp], ecx              ; For better call stacks.
    541         mov     ecx, [eax + X86TSS32.esi]
    542         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rsi], ecx
    543         mov     ecx, [eax + X86TSS32.edi]
    544         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rdi], ecx
    545         mov     ecx, [eax + X86TSS32.esi]
    546         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rsi], ecx
    547         mov     ecx, [eax + X86TSS32.eflags]
    548         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rflags], ecx
    549         mov     ecx, [eax + X86TSS32.eip]
    550         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.rip], ecx
    551         mov     [ebp + 4], ecx          ; For better call stacks.
    552         mov     cx, [eax + X86TSS32.cs]
    553         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.cs], cx
    554         mov     cx, [eax + X86TSS32.ds]
    555         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.ds], cx
    556         mov     cx, [eax + X86TSS32.es]
    557         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.es], cx
    558         mov     cx, [eax + X86TSS32.fs]
    559         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.fs], cx
    560         mov     cx, [eax + X86TSS32.gs]
    561         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.gs], cx
    562         mov     cx, [eax + X86TSS32.ss]
    563         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.ss], cx
    564         mov     cx, [eax + X86TSS32.selLdt]             ; Note! This isn't necessarily the ldtr at the time of the fault.
    565         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.ldtr], cx
    566         mov     cx, [eax + X86TSS32.cr3]                ; Note! This isn't necessarily the cr3 at the time of the fault.
    567         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.cr3], ecx
    568 
    569         ;
    570         ; Set CPL; copy and update mode.
    571         ;
    572         mov     cl, [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.ss]
    573         and     cl, 3
    574         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.bCpl], cl
    575 
    576         mov     cl, [BS3_DATA16_WRT(g_bBs3CurrentMode)]
    577         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.bMode], cl
    578         and     cl, ~BS3_MODE_CODE_MASK
    579         or      cl, BS3_MODE_CODE_32
    580         mov     [BS3_DATA16_WRT(g_bBs3CurrentMode)], cl
    581 
    582         ;
    583         ; Control registers.
    584         ;
    585         mov     ecx, cr0
    586         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.cr0], ecx
    587         mov     ecx, cr2
    588         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.cr2], ecx
    589         mov     ecx, cr4
    590         mov     [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.cr4], ecx
    591 
    592         ;
    593         ; Join code paths with the generic handler code.
    594         ;
    595         jmp     bs3Trap32GenericCommon.dispatch_to_handler
    596 BS3_PROC_END   Bs3Trap32DoubleFaultHandler
    597 
     320BS3_PROC_END   Bs3Trap64GenericCommon
     321
  • TabularUnified trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-RegCtxRestore.asm

    r60119 r60194  
    192192        cmp     sAX, sDX
    193193        je      .skip_cr4
     194hlt
    194195        mov     cr4, sAX
    195196.skip_cr4:
  • TabularUnified trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-Trap64Init.c

    r60188 r60194  
    11/* $Id$ */
    22/** @file
    3  * BS3Kit - Bs3Trap32Init
     3 * BS3Kit - Bs3Trap64Init
    44 */
    55
     
    3131
    3232
    33 /*********************************************************************************************************************************
    34 *   Global Variables                                                                                                             *
    35 *********************************************************************************************************************************/
    36 extern uint32_t BS3_DATA_NM(g_Bs3Trap32DoubleFaultHandlerFlatAddr);
    37 
    38 
    39 BS3_DECL(void) Bs3Trap32Init(void)
     33BS3_DECL(void) Bs3Trap64Init(void)
    4034{
    41      X86TSS32 BS3_FAR *pTss;
     35     X86TSS64 BS3_FAR *pTss;
    4236     unsigned iIdt;
    4337
    4438    /*
    4539     * IDT entries, except the system call gate.
     40     * The #DF entry get IST=1, all others IST=0.
    4641     */
    4742    for (iIdt = 0; iIdt < BS3_TRAP_SYSCALL; iIdt++)
    48         Bs3Trap32SetGate(iIdt, X86_SEL_TYPE_SYS_386_INT_GATE, 0 /*bDpl*/,
    49                          BS3_SEL_R0_CS32, BS3_DATA_NM(g_Bs3Trap32GenericEntriesFlatAddr) + iIdt * 8, 0 /*cParams*/);
     43        Bs3Trap64SetGate(iIdt, AMD64_SEL_TYPE_SYS_INT_GATE, 0 /*bDpl*/,
     44                         BS3_SEL_R0_CS64, BS3_DATA_NM(g_Bs3Trap64GenericEntriesFlatAddr) + iIdt * 8, iIdt == X86_XCPT_DF /*bIst*/);
    5045    for (iIdt = BS3_TRAP_SYSCALL + 1; iIdt < 256; iIdt++)
    51         Bs3Trap32SetGate(iIdt, X86_SEL_TYPE_SYS_386_INT_GATE, 0 /*bDpl*/,
    52                          BS3_SEL_R0_CS32, BS3_DATA_NM(g_Bs3Trap32GenericEntriesFlatAddr) + iIdt * 8, 0 /*cParams*/);
     46        Bs3Trap64SetGate(iIdt, AMD64_SEL_TYPE_SYS_INT_GATE, 0 /*bDpl*/,
     47                         BS3_SEL_R0_CS64, BS3_DATA_NM(g_Bs3Trap64GenericEntriesFlatAddr) + iIdt * 8, 0 /*bIst*/);
    5348
    5449    /*
    5550     * Initialize the normal TSS so we can do ring transitions via the IDT.
    5651     */
    57     pTss = &BS3_DATA_NM(Bs3Tss32);
     52    pTss = &BS3_DATA_NM(Bs3Tss64);
    5853    Bs3MemZero(pTss, sizeof(*pTss));
    59     pTss->esp0      = BS3_ADDR_STACK_R0;
    60     pTss->ss0       = BS3_SEL_R0_SS32;
    61     pTss->esp1      = BS3_ADDR_STACK_R1;
    62     pTss->ss1       = BS3_SEL_R1_SS32 | 1;
    63     pTss->esp2      = BS3_ADDR_STACK_R2;
    64     pTss->ss2       = BS3_SEL_R2_SS32 | 2;
    65 
    66     /*
    67      * Initialize the double fault TSS.
    68      * cr3 is filled in by switcher code, when needed.
    69      */
    70     pTss = &BS3_DATA_NM(Bs3Tss32DoubleFault);
    71     Bs3MemZero(pTss, sizeof(*pTss));
    72     pTss->esp0      = BS3_ADDR_STACK_R0;
    73     pTss->ss0       = BS3_SEL_R0_SS32;
    74     pTss->esp1      = BS3_ADDR_STACK_R1;
    75     pTss->ss1       = BS3_SEL_R1_SS32 | 1;
    76     pTss->esp2      = BS3_ADDR_STACK_R2;
    77     pTss->ss2       = BS3_SEL_R2_SS32 | 2;
    78     pTss->eip       = BS3_DATA_NM(g_Bs3Trap32DoubleFaultHandlerFlatAddr);
    79     pTss->eflags    = X86_EFL_1;
    80     pTss->esp       = BS3_ADDR_STACK_R0_IST1;
    81     pTss->es        = BS3_SEL_R0_DS32;
    82     pTss->ds        = BS3_SEL_R0_DS32;
    83     pTss->cs        = BS3_SEL_R0_CS32;
    84     pTss->ss        = BS3_SEL_R0_SS32;
    85 
    86     Bs3Trap32SetGate(X86_XCPT_DF, X86_SEL_TYPE_SYS_TASK_GATE, 0 /*bDpl*/, BS3_SEL_TSS32_DF, 0, 0 /*cParams*/);
     54    pTss->rsp0      = BS3_ADDR_STACK_R0;
     55    pTss->rsp1      = BS3_ADDR_STACK_R1;
     56    pTss->rsp2      = BS3_ADDR_STACK_R2;
     57    pTss->ist1      = BS3_ADDR_STACK_R0_IST1;
     58    pTss->ist2      = BS3_ADDR_STACK_R0_IST2;
     59    pTss->ist3      = BS3_ADDR_STACK_R0_IST3;
     60    pTss->ist4      = BS3_ADDR_STACK_R0_IST4;
     61    pTss->ist5      = BS3_ADDR_STACK_R0_IST5;
     62    pTss->ist6      = BS3_ADDR_STACK_R0_IST6;
     63    pTss->ist7      = BS3_ADDR_STACK_R0_IST7;
    8764}
    8865
  • TabularUnified trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-TrapSetJmp.asm

    r60097 r60194  
    9393%else
    9494        mov     xDI, [xBP + xCB*2]
    95         mov     cx, BS3TRAPFRAME_size / 4
     95        mov     ecx, BS3TRAPFRAME_size / 4
    9696        mov     xAX, 0feedfaceh
    9797        rep stosd
  • TabularUnified trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TrapSystemCallHandler.asm

    r60019 r60194  
    9090        mov     xBP, xSP
    9191%if TMPL_BITS == 64
    92         push    0                       ; dummy DS entry
     92        push    0
     93        mov     [rsp+2], es
     94        mov     [rsp], ds
    9395%else
    9496        push    ds
     
    330332        iret
    331333%else
    332         leave                           ; skips fake ds
     334        mov     es, [rsp+2]
     335        mov     ds, [rsp]
     336        leave                           ; skips ds
    333337        iretq
    334338%endif
  • TabularUnified trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-rm-InitAll.c

    r60024 r60194  
    3737    Bs3CpuDetect_rm();
    3838    Bs3InitMemory_rm();
    39 //    if (BS3_DATA_NM(g_uBs3CpuDetected) & BS3CPU_F_LONG_MODE)
    40 //        Bs3Trap64Init();
     39    if (BS3_DATA_NM(g_uBs3CpuDetected) & BS3CPU_F_LONG_MODE)
     40        Bs3Trap64Init();
    4141    if ((BS3_DATA_NM(g_uBs3CpuDetected) & BS3CPU_TYPE_MASK) >= BS3CPU_80386)
    4242        Bs3Trap32Init();
  • TabularUnified trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h

    r60184 r60194  
    4343 *       implemented in C and functions that does not have parameters.
    4444 */
     45#define BS3_KIT_WITH_NO_RETURN
    4546#ifndef BS3_KIT_WITH_NO_RETURN
    4647# undef  DECL_NO_RETURN
     
    18701871BS3_DECL(DECL_NO_RETURN(void)) Bs3RegCtxRestore_c64(PCBS3REGCTX pRegCtx, uint16_t fFlags); /**< @copydoc Bs3RegCtxRestore_c16 */
    18711872#define Bs3RegCtxRestore BS3_CMN_NM(Bs3RegCtxRestore) /**< Selects #Bs3RegCtxRestore_c16, #Bs3RegCtxRestore_c32 or #Bs3RegCtxRestore_c64. */
    1872 #if /*!defined(BS3_KIT_WITH_NO_RETURN) &&*/ defined(__WATCOMC__)
     1873#if !defined(BS3_KIT_WITH_NO_RETURN) && defined(__WATCOMC__)
    18731874# pragma aux Bs3RegCtxRestore_c16 "_Bs3RegCtxRestore_aborts_c16" __aborts
    18741875# pragma aux Bs3RegCtxRestore_c32 "_Bs3RegCtxRestore_aborts_c32" __aborts
     
    18991900    uint8_t     cbIretFrame;
    19001901    /** 0x02: The handler CS. */
    1901     uint16_t    uHandlerCc;
     1902    uint16_t    uHandlerCs;
    19021903    /** 0x04: The handler SS. */
    19031904    uint16_t    uHandlerSs;
     
    24812482    BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_ppv86)    a_Parameters; \
    24822483    BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_pae16)    a_Parameters; \
    2483     BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_pae16_16) a_Parameters; \
     2484    BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_pae16_32) a_Parameters; \
    24842485    BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_pae16_v86)a_Parameters; \
    24852486    BS3_DECL(a_RetType) RT_CONCAT(a_BaseFnNm,_pae32)    a_Parameters; \
     
    25612562extern uint16_t BS3_DATA_NM(g_uBs3CpuDetected);
    25622563
     2564/**
     2565 * Initializes trap handling for the current system.
     2566 *
     2567 * Calls the appropriate Bs3Trap16Init, Bs3Trap32Init or Bs3Trap64Init function.
     2568 */
     2569BS3_MODE_EXPAND_PROTOTYPES(void, Bs3TrapInit,(void));
    25632570
    25642571/**
     
    25702577BS3_MODE_EXPAND_PROTOTYPES(void, Bs3TestDoModes, (PCBS3TESTMODEENTRY paEntries, size_t cEntries));
    25712578
     2579
    25722580/** @} */
    25732581
Note: See TracChangeset for help on using the changeset viewer.

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