VirtualBox

Changeset 60657 in vbox


Ignore:
Timestamp:
Apr 22, 2016 3:57:22 PM (8 years ago)
Author:
vboxsync
Message:

bs3kit: updates

Location:
trunk/src/VBox/ValidationKit/bootsectors
Files:
8 added
40 edited
2 copied

Legend:

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

    r60609 r60657  
    247247        $$(bs3-cpu-basic-2_0_OUTDIR)/bs3kit/bs3-cmn-instantiate-x0.o16 \
    248248        $$(bs3-cpu-basic-2_0_OUTDIR)/bs3kit/bs3-cmn-instantiate.o32 \
    249         $$(bs3-cpu-basic-2_0_OUTDIR)/bs3kit/bs3-cmn-instantiate.o64
     249        $$(bs3-cpu-basic-2_0_OUTDIR)/bs3kit/bs3-cmn-instantiate.o64 \
     250        $$(bs3-cpu-basic-2_0_OUTDIR)/bs3-cpu-basic-2-asm.o16
    250251endif
    251252
  • trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.c

    r60609 r60657  
    13101310    BS3TRAPFRAME        TrapCtx;
    13111311    BS3REGCTX           Ctx;
     1312    BS3REGCTX           CtxUdExpected;
    13121313    BS3REGCTX           TmpCtx;
    1313     uint8_t             abBuf[16];
     1314    uint8_t const       cbBuf = 8*2;         /* test buffer area  */
     1315    uint8_t             abBuf[8*2 + 8 + 8];  /* test buffer w/ misalignment test space and some extra guard. */
    13141316    uint8_t BS3_FAR    *pbBuf = abBuf;
     1317    uint8_t const       cbIdtr = BS3_MODE_IS_64BIT_CODE(g_bTestMode) ? 2+8 : BS3_MODE_IS_32BIT_CODE(g_bTestMode) ? 2+4
     1318                        : (g_uBs3CpuDetected & BS3CPU_TYPE_MASK) == BS3CPU_80286 ? 2+3 : 2+4;
     1319    uint8_t             bFiller;
     1320    unsigned            off;
     1321    //unsigned            i, j;
     1322
     1323    g_usBs3TestStep = 0;
    13151324
    13161325    /* make sure they're allocated  */
    13171326    Bs3MemZero(&Ctx, sizeof(Ctx));
     1327    Bs3MemZero(&CtxUdExpected, sizeof(CtxUdExpected));
    13181328    Bs3MemZero(&TmpCtx, sizeof(TmpCtx));
    13191329    Bs3MemZero(&TrapCtx, sizeof(TrapCtx));
     
    13221332    /* Create a context, give this routine some more stack space, point the context
    13231333       at our SIDT [xBX] + UD2 combo, and point DS:xBX at abBuf. */
    1324     Bs3RegCtxSave(&Ctx);
    1325     Ctx.rsp.u -= 0x80;
     1334    Bs3RegCtxSaveEx(&Ctx, g_bTestMode, 256 /*cbExtraStack*/);
    13261335    Ctx.rip.u  = (uintptr_t)BS3_FP_OFF(&bs3CpuBasic2_sidt_bx_ud2);
    13271336# if TMPL_BITS == 32
     
    13331342# endif
    13341343
    1335     /*
    1336      * Check that it works at all.
    1337      */
    1338     Bs3MemZero(&abBuf, sizeof(abBuf));
     1344    /* For successful SIDT attempts, we'll stop at the UD2. */
     1345    Bs3MemCpy(&CtxUdExpected, &Ctx, sizeof(Ctx));
     1346    CtxUdExpected.rip.u += 3;
     1347
     1348    /*
     1349     * Check that it works at all and that only bytes we expect gets written to.
     1350     */
     1351    /* First with zero buffer. */
     1352    Bs3MemZero(abBuf, sizeof(abBuf));
     1353    if (!ASMMemIsAllU8(abBuf, sizeof(abBuf), 0))
     1354        Bs3TestFailedF("ASMMemIsAllU8 or Bs3MemZero is busted: abBuf=%.*Rhxs\n", sizeof(abBuf), pbBuf);
     1355    if (!ASMMemIsZero(abBuf, sizeof(abBuf)))
     1356        Bs3TestFailedF("ASMMemIsZero or Bs3MemZero is busted: abBuf=%.*Rhxs\n", sizeof(abBuf), pbBuf);
    13391357    Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
    1340     g_usBs3TestStep = 0;
    1341     //bs3CpuBasic2_CompareIntCtx1(&TrapCtx, &Ctx, 0x80 /*bXcpt*/);
     1358    bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
     1359    if (!ASMMemIsZero(&abBuf[cbIdtr], cbBuf - cbIdtr))
     1360        Bs3TestFailedF("Unexpected buffer bytes set (#1): cbIdtr=%u abBuf=%.*Rhxs\n", cbIdtr, cbBuf, pbBuf);
     1361    g_usBs3TestStep++;
     1362
     1363    /* Again with buffer filled a byte not occuring in the previous result. */
     1364    bFiller = 0x55;
     1365    while (Bs3MemChr(abBuf, bFiller, cbBuf) != NULL)
     1366        bFiller++;
     1367    Bs3MemSet(abBuf, bFiller, sizeof(abBuf));
     1368    if (!ASMMemIsAllU8(abBuf, sizeof(abBuf), bFiller))
     1369        Bs3TestFailedF("ASMMemIsAllU8 or Bs3MemSet is busted: bFiller=%#x abBuf=%.*Rhxs\n", bFiller, sizeof(abBuf), pbBuf);
     1370
     1371    Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
     1372    bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
     1373    if (!ASMMemIsAllU8(&abBuf[cbIdtr], cbBuf - cbIdtr, bFiller))
     1374        Bs3TestFailedF("Unexpected buffer bytes set (#2): cbIdtr=%u bFiller=%#x abBuf=%.*Rhxs\n", cbIdtr, bFiller, cbBuf, pbBuf);
     1375    if (Bs3MemChr(abBuf, bFiller, cbIdtr) != NULL)
     1376        Bs3TestFailedF("Not all bytes touched: cbIdtr=%u bFiller=%#x abBuf=%.*Rhxs\n", cbIdtr, bFiller, cbBuf, pbBuf);
     1377    g_usBs3TestStep++;
     1378
     1379    /*
     1380     * Slide the buffer along 8 bytes to cover misalignment.
     1381     */
     1382    for (off = 0; off < 8; off++)
     1383    {
     1384        pbBuf = &abBuf[off];
     1385        CtxUdExpected.rbx.u = Ctx.rbx.u = BS3_FP_OFF(pbBuf);
     1386
     1387        /* First with zero buffer. */
     1388        Bs3MemZero(abBuf, sizeof(abBuf));
     1389        Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
     1390        bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
     1391        if (off > 0 && !ASMMemIsZero(abBuf, off))
     1392            Bs3TestFailedF("Unexpected buffer bytes set before (#3): cbIdtr=%u off=%u abBuf=%.*Rhxs\n",
     1393                           cbIdtr, off, off + cbBuf, abBuf);
     1394        if (!ASMMemIsZero(&abBuf[off + cbIdtr], sizeof(abBuf) - cbIdtr - off))
     1395            Bs3TestFailedF("Unexpected buffer bytes set after (#3): cbIdtr=%u off=%u abBuf=%.*Rhxs\n",
     1396                           cbIdtr, off, off + cbBuf, abBuf);
     1397        g_usBs3TestStep++;
     1398
     1399        /* Again with buffer filled a byte not occuring in the previous result. */
     1400        Bs3MemSet(abBuf, bFiller, sizeof(abBuf));
     1401        Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
     1402        bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
     1403        if (off > 0 && !ASMMemIsAllU8(abBuf, off, bFiller))
     1404            Bs3TestFailedF("Unexpected buffer bytes set before (#4): cbIdtr=%u off=%u bFiller=%#x abBuf=%.*Rhxs\n",
     1405                           cbIdtr, off, bFiller, off + cbBuf, abBuf);
     1406        if (!ASMMemIsAllU8(&abBuf[off + cbIdtr], sizeof(abBuf) - cbIdtr - off, bFiller))
     1407            Bs3TestFailedF("Unexpected buffer bytes set after (#4): cbIdtr=%u off=%u bFiller=%#x abBuf=%.*Rhxs\n",
     1408                           cbIdtr, off, bFiller, off + cbBuf, abBuf);
     1409        if (Bs3MemChr(&abBuf[off], bFiller, cbIdtr) != NULL)
     1410            Bs3TestFailedF("Not all bytes touched (#4): cbIdtr=%u off=%u bFiller=%#x abBuf=%.*Rhxs\n",
     1411                           cbIdtr, off, bFiller, off + cbBuf, abBuf);
     1412        g_usBs3TestStep++;
     1413
     1414    }
     1415    pbBuf = abBuf;
     1416    CtxUdExpected.rbx.u = Ctx.rbx.u = BS3_FP_OFF(pbBuf);
     1417
     1418    /*
     1419     * Play with the selector limit if the target mode supports limit checking
     1420     * We use BS3_SEL_TEST_PAGE_00 for this
     1421     */
     1422    if (   !BS3_MODE_IS_RM_OR_V86(g_bTestMode)
     1423        && !BS3_MODE_IS_64BIT_CODE(g_bTestMode))
     1424    {
     1425        uint16_t cbLimit;
     1426        uint16_t const uSavedDs = Ctx.ds;
     1427        uint32_t uFlatBuf = Bs3SelPtrToFlat(pbBuf);
     1428        Bs3GdteTestPage00 = Bs3Gdte_DATA16;
     1429        Bs3GdteTestPage00.Gen.u16BaseLow  = (uint16_t)uFlatBuf;
     1430        Bs3GdteTestPage00.Gen.u8BaseHigh1 = (uint8_t)(uFlatBuf >> 16);
     1431        Bs3GdteTestPage00.Gen.u8BaseHigh2 = (uint8_t)(uFlatBuf >> 24);
     1432
     1433        CtxUdExpected.ds = Ctx.ds = BS3_SEL_TEST_PAGE_00;
     1434        for (off = 0; off < 8; off++)
     1435        {
     1436            CtxUdExpected.rbx.u = Ctx.rbx.u = off;
     1437            for (cbLimit = 0; cbLimit < cbIdtr*2; cbLimit++)
     1438            {
     1439                Bs3GdteTestPage00.Gen.u16LimitLow = cbLimit;
     1440                Bs3MemSet(abBuf, bFiller, sizeof(abBuf));
     1441                Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
     1442                if (off + cbIdtr <= cbLimit + 1)
     1443                {
     1444                    bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
     1445                    if (Bs3MemChr(&abBuf[off], bFiller, cbIdtr) != NULL)
     1446                        Bs3TestFailedF("Not all bytes touched (#5): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
     1447                                       cbIdtr, off, cbLimit, bFiller, off + cbBuf, abBuf);
     1448                }
     1449                else
     1450                {
     1451                    bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
     1452                    if (off + 2 <= cbLimit + 1)
     1453                    {
     1454                        if (Bs3MemChr(&abBuf[off], bFiller, 2) != NULL)
     1455                            Bs3TestFailedF("Limit bytes not touched (#6): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
     1456                                           cbIdtr, off, cbLimit, bFiller, off + cbBuf, abBuf);
     1457                        if (!ASMMemIsAllU8(&abBuf[off + 2], cbIdtr - 2, bFiller))
     1458                            Bs3TestFailedF("Base bytes touched on #GP (#6): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
     1459                                           cbIdtr, off, cbLimit, bFiller, off + cbBuf, abBuf);
     1460                    }
     1461                    else if (!ASMMemIsAllU8(abBuf, sizeof(abBuf), bFiller))
     1462                        Bs3TestFailedF("Bytes touched on #GP: cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
     1463                                       cbIdtr, off, cbLimit, bFiller, off + cbBuf, abBuf);
     1464                }
     1465
     1466                if (off > 0 && !ASMMemIsAllU8(abBuf, off, bFiller))
     1467                    Bs3TestFailedF("Leading bytes touched (#7): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
     1468                                   cbIdtr, off, cbLimit, bFiller, off + cbBuf, abBuf);
     1469                if (!ASMMemIsAllU8(&abBuf[off + cbIdtr], sizeof(abBuf) - off - cbIdtr, bFiller))
     1470                    Bs3TestFailedF("Trailing bytes touched (#7): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
     1471                                   cbIdtr, off, cbLimit, bFiller, off + cbBuf, abBuf);
     1472
     1473                g_usBs3TestStep++;
     1474            }
     1475        }
     1476
     1477        CtxUdExpected.ds = Ctx.ds = uSavedDs;
     1478        CtxUdExpected.rbx.u = Ctx.rbx.u = BS3_FP_OFF(pbBuf);
     1479    }
     1480
     1481    /*
     1482     * Play with the paging.
     1483     */
     1484    if (BS3_MODE_IS_PAGED(g_bTestMode))
     1485    {
     1486
     1487
     1488    }
    13421489
    13431490}
     
    15911738BS3_DECL_FAR(uint8_t) TMPL_NM(bs3CpuBasic2_sidt)(uint8_t bMode)
    15921739{
     1740//if (bMode == BS3_MODE_PE16_V86)
     1741{
    15931742    g_pszTestMode = TMPL_NM(g_szBs3ModeName);
    15941743    g_bTestMode   = bMode;
     
    16061755     */
    16071756    Bs3TrapInit();
     1757}
     1758
    16081759    return 0;
    16091760}
  • trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.mac

    r60609 r60657  
    9696.again: ud2
    9797        jmp     .again
     98AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_sidt_bx_ud2) == 3)
    9899BS3_PROC_END_CMN   bs3CpuBasic2_sidt_bx_ud2
    99100
     
    103104.again: ud2
    104105        jmp     .again
     106AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_lidt_bx_ud2) == 3)
    105107BS3_PROC_END_CMN   bs3CpuBasic2_lidt_bx_ud2
    106108
  • trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2.c

    r60609 r60657  
    4949{
    5050    //BS3TESTMODEENTRY_MODE("tss / gate / esp", bs3CpuBasic2_TssGateEsp),
    51     BS3TESTMODEENTRY_MODE("raise xcpt #1", bs3CpuBasic2_RaiseXcpt1),
     51//    BS3TESTMODEENTRY_MODE("raise xcpt #1", bs3CpuBasic2_RaiseXcpt1),
    5252    //BS3TESTMODEENTRY_CMN("iret", bs3CpuBasic2_iret),
    53     BS3TESTMODEENTRY_MODE("iret", bs3CpuBasic2_iret),
    54 //    BS3TESTMODEENTRY_MODE("sidt", bs3CpuBasic2_sidt),
     53//    BS3TESTMODEENTRY_MODE("iret", bs3CpuBasic2_iret),
     54    BS3TESTMODEENTRY_MODE("sidt", bs3CpuBasic2_sidt),
    5555};
    5656
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk

    r60585 r60657  
    7171       bs3-cmn-StrNLen.c \
    7272       bs3-cmn-StrCpy.c \
     73       bs3-cmn-MemChr.asm \
    7374       bs3-cmn-MemCpy.c \
    7475       bs3-cmn-MemPCpy.c \
    7576       bs3-cmn-MemMove.c \
     77       bs3-cmn-MemSet.asm \
    7678       bs3-cmn-MemZero.asm \
    7779       bs3-cmn-MemAlloc.c \
     
    8890       bs3-cmn-RegCtxPrint.c \
    8991       bs3-cmn-RegCtxSave.asm \
     92       bs3-cmn-RegCtxSaveEx.asm \
    9093       bs3-cmn-SelFar32ToFlat32.c \
     94       bs3-cmn-SelFar32ToFlat32NoClobber.asm \
    9195       bs3-cmn-SelProtFar32ToFlat32.c \
    9296       bs3-cmn-SelProtModeCodeToRealMode.asm \
     
    9498       bs3-cmn-SelFlatCodeToRealMode.asm \
    9599       bs3-cmn-SelFlatCodeToProtFar16.asm \
     100       bs3-cmn-SelRealModeDataToProtFar16.asm \
     101       bs3-cmn-SelProtFar16DataToRealMode.asm \
     102       bs3-cmn-SelRealModeDataToFlat.asm \
     103       bs3-cmn-SelProtFar16DataToFlat.asm \
     104       bs3-cmn-SelFlatDataToProtFar16.asm \
     105       bs3-cmn-SelFlatDataToRealMode.asm \
    96106       bs3-cmn-SlabInit.c \
    97107       bs3-cmn-SlabAlloc.c \
     
    451461# Rule for regenerating bs3kit-mangling-functions-undef.h.
    452462#
    453 bs3kit-mangling-code-undef.h: $(PATH_SUB_CURRENT)/bs3kit-mangling-code-define.h
     463bs3kit-mangling-code-undef.h: $(PATH_SUB_CURRENT)/bs3kit-mangling-code-define.h $(MAKEFILE)
    454464        $(SED) \
    455465                -e 's/#\( *\)define \([a-zA-Z_][a-zA-Z0-9_]*\) .*$(DOLLAR)/#\1undef \2/' \
     
    464474                $(PATH_SUB_CURRENT)/bs3kit.h \
    465475                $(PATH_SUB_CURRENT)/bs3-cmn-paging.h \
    466                 $(PATH_SUB_CURRENT)/bs3-cmn-test.h
     476                $(PATH_SUB_CURRENT)/bs3-cmn-test.h \
     477                $(MAKEFILE)
    467478        $(APPEND) -tn "$(dir $<)$@" \
    468479                 '/* $(DOLLAR)Id: $(DOLLAR) */' \
     
    496507                -e 's/^ *BS3_CMN_PROTO_NOSB([^,]*, *\([a-zA-Z_][a-zA-Z0-9_]*\) *,.*$(DOLLAR)/#define \1 BS3_CMN_MANGLER(\1)/p' \
    497508                -e 's/^ *BS3_CMN_PROTO_FARSTUB([^,]*,[^,]*, *\([a-zA-Z_][a-zA-Z0-9_]*\) *,.*$(DOLLAR)/#define \1 BS3_CMN_MANGLER(\1)/p' \
    498                 $< | sort >> "$(dir $<)bs3kit-mangling-code-define.h"
     509                $(filter %.h,$^) | sort >> "$(dir $<)bs3kit-mangling-code-define.h"
    499510        $(APPEND) -n "$(dir $<)$@" '#ifndef BS3_CMN_ONLY'
    500511        $(SED) -n \
     
    502513                -e 's/^ *BS3_MODE_PROTO_NOSB([^,]*, *\([a-zA-Z_][a-zA-Z0-9_]*\) *,.*$(DOLLAR)/# define \1 BS3_MODE_MANGLER(\1)/p' \
    503514                -e 's/^ *BS3_MODE_PROTO_FARSTUB([^,]*,[^,]*, *\([a-zA-Z_][a-zA-Z0-9_]*\) *,.*$(DOLLAR)/# define \1 BS3_MODE_MANGLER(\1)/p' \
    504                 $< | sort >> "$(dir $<)bs3kit-mangling-code-define.h"
     515                $(filter %.h,$^) | sort >> "$(dir $<)bs3kit-mangling-code-define.h"
    505516        $(APPEND) -n "$(dir $<)$@" '#endif /* !BS3_CMN_ONLY */'
    506517
     
    512523                $(PATH_SUB_CURRENT)/bs3-cmn-memory.h \
    513524                $(PATH_SUB_CURRENT)/bs3-cmn-paging.h \
    514                 $(PATH_SUB_CURRENT)/bs3-cmn-test.h
     525                $(PATH_SUB_CURRENT)/bs3-cmn-test.h \
     526                $(MAKEFILE)
    515527        $(APPEND) -tn "$(dir $<)$@" \
    516528                 '# $(DOLLAR)Id: $(DOLLAR)' \
     
    542554        $(SED) -n \
    543555                -e '/^ *BS3_CMN_PROTO_STUB/p' \
    544                 -e '/^ *BS3_CMD_PROTO_FARSTUB/p' \
     556                -e '/^ *BS3_CMN_PROTO_FARSTUB/p' \
    545557                -e '/^ *BS3_MODE_PROTO_STUB/p' \
    546558                -e '/^ *BS3_MODE_PROTO_FARSTUB/p' \
    547                 $< \
     559                $(filter %.h,$^) \
    548560        | sort \
    549561        | $(SED) -n \
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-c16-Trap16Generic.asm

    r60585 r60657  
    432432
    433433.skip_crX_because_cpl_not_0:
    434         or      byte [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.fbFlags], BS3REG_CTX_F_NO_CR
    435         jmp     .set_flags
     434        or      byte [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.fbFlags], \
     435                BS3REG_CTX_F_NO_CR2_CR3 | BS3REG_CTX_F_NO_CR4 | BS3REG_CTX_F_NO_CR0_IS_MSW
    436436
    437437CPU 286
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-c16-TrapRmV86Generic.asm

    r60585 r60657  
    5454BS3_PROC_BEGIN Bs3TrapRmV86GenericEntries
    5555%macro Bs3TrapRmV86GenericEntryNoErr 1
    56         push    byte 0                  ; 2 byte: fake error code
    57         db      06ah, i                 ; 2 byte: push imm8 - note that this is a signextended value.
    58         jmp     %1                      ; 3 byte
     56        push    ax                      ; 1 byte:  Reserve space for fake error cd.     (BP(+2) + 4)
     57        push    ax                      ; 1 byte:  Save AX                              (BP(+2) + 2)
     58        mov     ax, i | 00000h          ; 2 bytes: AL = trap/interrupt number; AH=indicate no error code
     59        jmp     %1                      ; 3 bytes: Jump to handler code
    5960        ALIGNCODE(8)
    6061%assign i i+1
     
    6263
    6364%macro Bs3TrapRmV86GenericEntryErrCd 1
    64         db      06ah, i                 ; 2 byte: push imm8 - note that this is a signextended value.
    65         jmp     %1                      ; 3 byte
     65        push    ax                      ; 1 byte:  Save AX                              (BP(+2) + 2)
     66        mov     ax, i | 0ff00h          ; 2 bytes: AL = trap/interrupt number; AH=indicate have error code.
     67        jmp     %1                      ; 3 bytes: Jump to handler code
    6668        ALIGNCODE(8)
    6769%assign i i+1
     
    111113; Trap or interrupt with error code, faked if necessary.
    112114;
    113 ; Note! This code is going to "misbehave" if the high word of ESP is not cleared.
    114 ;
    115115BS3_PROC_BEGIN _bs3TrapRmV86GenericTrapOrInt
    116116BS3_PROC_BEGIN bs3TrapRmV86GenericTrapOrInt
     
    137137        movzx   ebx, sp
    138138
    139         mov     [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rax], eax
    140         mov     edx, [bp - 12h]         ; This isn't quite right for wrap arounds, but close enough for now
     139
     140        mov     edx, [bp - 12h]
    141141        mov     [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rsp], edx     ; high bits
    142142        mov     [ss:bx + BS3TRAPFRAME.uHandlerRsp], edx             ; high bits
    143143        mov     dx, [bp - 0eh]
    144         ;mov     [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.ss], dx - share this here
    145144        mov     [ss:bx + BS3TRAPFRAME.uHandlerSs], dx
    146145        mov     edx, [bp - 0ch]
     
    153152        mov     edx, [bp]
    154153        mov     [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rbp], edx
    155 
    156         mov     dl, [bp + 4]
    157         mov     [ss:bx + BS3TRAPFRAME.bXcpt], dl
    158 
     154        mov     edx, eax                                            ; high bits
     155        mov     dx, [bp + 4]
     156        mov     [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rax], edx
     157
     158        mov     [ss:bx + BS3TRAPFRAME.bXcpt], al
     159
     160        test    ah, 0ffh
     161        jz      .no_error_code
     162;; @todo Do voodoo checks for 'int xx' or misguided hardware interrupts.
    159163        mov     dx, [bp + 6]
    160 ;; @todo Do voodoo checks for 'int xx' or misguided hardware interrupts.
    161164        mov     [ss:bx + BS3TRAPFRAME.uErrCd], dx
     165.no_error_code:
    162166
    163167        add     bp, 6                   ; adjust so it points to the word before the iret frame.
     
    173177        push    bp
    174178        mov     bp, sp
    175         push    bx
    176         pushf
    177         push    ax
     179        push    bx                      ; BP - 2
     180        pushf                           ; BP - 4
    178181        cld
    179182
    180183        ; Reserve space for the the register and trap frame.
    181184        mov     bx, (BS3TRAPFRAME_size + 7) / 8
     185        push    ax
    182186        xor     ax, ax
    183187.more_zeroed_space:
     
    189193        jnz     .more_zeroed_space
    190194        mov     bx, sp
    191 
    192         mov     [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rax], ax
    193         ;mov     [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.ss], ss - share this here
     195        pop     ax
     196
    194197        mov     [ss:bx + BS3TRAPFRAME.uHandlerSs], ss
    195198        mov     [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rdx], dx
     
    201204        mov     [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rbp], dx
    202205
    203         mov     dl, [bp + 2]
    204         mov     [ss:bx + BS3TRAPFRAME.bXcpt], dl
    205 
     206        mov     dx, [bp + 2]
     207        mov     [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rax], dx
     208
     209        mov     [ss:bx + BS3TRAPFRAME.bXcpt], al
     210
     211        test    ah, 0ffh
     212        jz      .no_error_code
     213;; @todo Do voodoo checks for 'int xx' or misguided hardware interrupts.
    206214        mov     dx, [bp + 4]
    207 ;; @todo Do voodoo checks for 'int xx' or misguided hardware interrupts.
    208215        mov     [ss:bx + BS3TRAPFRAME.uErrCd], dx
     216.no_error_code:
    209217
    210218        add     bp, 4                   ; adjust so it points to the word before the iret frame.
     
    217225; Common context saving code and dispatching.
    218226;
    219 ; @param    bx      Pointer to the trap frame, zero filled.  The following members
     227; @param    ss:bx   Pointer to the trap frame, zero filled.  The following members
    220228;                   have been filled in by the previous code:
    221229;                       - bXcpt
     
    295303        mov     byte [ss:bx + BS3TRAPFRAME.cbIretFrame], 3*2
    296304
     305        ; The VM flag and CPL.
     306        test    al, BS3_MODE_CODE_V86
     307        jz      .dont_set_vm
     308        or      byte [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.rflags + 2], X86_EFL_VM >> 16
     309        mov     byte [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.bCpl], 3
     310.dont_set_vm:
     311
     312
    297313        ;
    298314        ; Control registers.
    299315        ;
     316        ; Since we're in real or v8086 here, we cannot save TR and LDTR.
     317        ; But get MSW (CR0) first since that's always accessible and we
     318        ; need it even on a 386 to check whether we're in v8086 mode or not.
     319        ;
    300320        cmp     byte [BS3_DATA16_WRT(g_uBs3CpuDetected)], BS3CPU_80286
    301         jb      .skip_control_regsiters_because_80186_or_older
    302 
    303         ; The 286 ones.
     321        jb      .skip_control_registers_because_80186_or_older
    304322CPU 286
    305         str     [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.tr]
    306         sldt    [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.ldtr]
    307323        smsw    ax
    308324        mov     [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.cr0], ax
     
    333349
    334350CPU 8086
    335 .skip_control_regsiters_because_80186_or_older:
     351.skip_control_registers_because_80186_or_older:
    336352.skip_crX_because_v8086:
    337         or      byte [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.fbFlags], BS3REG_CTX_F_NO_CR
     353        or      byte [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.fbFlags], \
     354                BS3REG_CTX_F_NO_CR0_IS_MSW | BS3REG_CTX_F_NO_CR2_CR3 | BS3REG_CTX_F_NO_CR4
    338355.set_flags:                             ; The double fault code joins us here.
    339         or      byte [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.fbFlags], BS3REG_CTX_F_NO_AMD64
     356        or      byte [ss:bx + BS3TRAPFRAME.Ctx + BS3REGCTX.fbFlags], BS3REG_CTX_F_NO_AMD64 | BS3REG_CTX_F_NO_TR_LDTR
    340357
    341358        ;
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-c32-Trap32Generic.asm

    r60319 r60657  
    370370
    371371.skip_crX_because_cpl_not_0:
    372         or      byte [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.fbFlags], BS3REG_CTX_F_NO_CR
    373 
     372        or      byte [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.fbFlags], \
     373                BS3REG_CTX_F_NO_CR0_IS_MSW | BS3REG_CTX_F_NO_CR2_CR3 | BS3REG_CTX_F_NO_CR4
     374        smsw    [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.cr0]
    374375.set_flags:
    375376        or      byte [edi + BS3TRAPFRAME.Ctx + BS3REGCTX.fbFlags], BS3REG_CTX_F_NO_AMD64
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-c64-Trap64Generic.asm

    r60203 r60657  
    296296
    297297.skip_crX_because_cpl_not_0:
    298         or      byte [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.fbFlags], BS3REG_CTX_F_NO_CR
     298        or      byte [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.fbFlags], \
     299                BS3REG_CTX_F_NO_CR0_IS_MSW | BS3REG_CTX_F_NO_CR2_CR3 | BS3REG_CTX_F_NO_CR4
     300        smsw    [rdi + BS3TRAPFRAME.Ctx + BS3REGCTX.cr0]
    299301
    300302        ;
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-A20Disable.asm

    r60527 r60657  
    4040BS3_PROC_BEGIN_CMN Bs3A20Disable, BS3_PBC_HYBRID_0_ARGS
    4141        ; Must call both because they may be ORed together on real HW.
    42         BS3_ONLY_64BIT_STMT sub     rsp, 20h
     42BONLY64 sub     rsp, 20h
    4343        call    BS3_CMN_NM(Bs3A20DisableViaKbd)
    4444        call    BS3_CMN_NM(Bs3A20DisableViaPortA)
    45         BS3_ONLY_64BIT_STMT add     rsp, 20h
     45BONLY64 add     rsp, 20h
    4646        BS3_HYBRID_RET
    4747BS3_PROC_END_CMN   Bs3A20Disable
     
    8080        pushf
    8181        cli
    82         BS3_ONLY_64BIT_STMT sub     rsp, 20h
     82BONLY64 sub     rsp, 20h
    8383
    8484        call    Bs3KbdWait
     
    9797        call    Bs3KbdWait
    9898
    99         BS3_ONLY_64BIT_STMT add     rsp, 20h
     99BONLY64 add     rsp, 20h
    100100        popf
    101101        pop     xAX
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-A20Enable.asm

    r60554 r60657  
    4141        push    xBP
    4242        mov     xBP, xSP
    43         BS3_ONLY_64BIT_STMT sub     rsp, 20h
     43BONLY64 sub     rsp, 20h
    4444
    4545        call    BS3_CMN_NM(Bs3A20EnableViaPortA)
     
    6363        pushf
    6464        cli
    65         BS3_ONLY_64BIT_STMT sub     rsp, 20h
     65BONLY64 sub     rsp, 20h
    6666
    6767        call    Bs3KbdWait
     
    8080        call    Bs3KbdWait
    8181
    82         BS3_ONLY_64BIT_STMT add     rsp, 20h
     82BONLY64 add     rsp, 20h
    8383        popf
    8484        pop     xAX
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-KbdWrite.asm

    r60527 r60657  
    4949        mov     xBP, xSP
    5050        push    xAX
    51         BS3_ONLY_64BIT_STMT sub     rsp, 20h
     51BONLY64 sub     rsp, 20h
    5252
    5353        mov     al, [xBP + xCB*2]
     
    5959        call    Bs3KbdWait
    6060
    61         BS3_ONLY_64BIT_STMT add     rsp, 20h
     61BONLY64 add     rsp, 20h
    6262        pop     xAX
    6363        pop     xBP
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-MemChr.asm

    r60585 r60657  
    11; $Id$
    22;; @file
    3 ; BS3Kit - Bs3MemZero.
     3; BS3Kit - Bs3MemChr.
    44;
    55
    66;
    7 ; Copyright (C) 2007-2015 Oracle Corporation
     7; Copyright (C) 2007-2016 Oracle Corporation
    88;
    99; This file is part of VirtualBox Open Source Edition (OSE), as
     
    2828
    2929;;
    30 ; @cproto   BS3_DECL(void) Bs3MemZero_c16(void BS3_FAR *pvDst, size_t cbDst);
     30; @cproto   BS3_CMN_PROTO_NOSB(void BS3_FAR *, Bs3MemChr,(void BS3_FAR const *pvHaystack, uint8_t bNeedle, size_t cbHaystack));
    3131;
    32 BS3_PROC_BEGIN_CMN Bs3MemZero, BS3_PBC_HYBRID
    33 %ifdef RT_ARCH_AMD64
    34         push    rdi
     32BS3_PROC_BEGIN_CMN Bs3MemChr, BS3_PBC_HYBRID
     33        push    xBP
     34        mov     xBP, xSP
     35        push    xDI
     36TONLY16 push    es
    3537
    36         mov     rdi, rcx                ; rdi = pvDst
    37         mov     rcx, rdx                ; rcx = cbDst
    38         shr     rcx, 3                  ; calc qword count.
    39         xor     eax, eax                ; rax = 0 (filler qword)
     38%if TMPL_BITS == 64
     39
     40        mov     rdi, rcx                ; rdi = pvHaystack
     41        mov     rcx, r8                 ; rcx = cbHaystack
     42        mov     al, dl                  ; bNeedle
     43        mov     rcx, r8
     44
     45%elif TMPL_BITS == 16
     46        mov     di, [bp + 2 + cbCurRetAddr]     ; pvHaystack.off
     47        mov     es, [bp + 2 + cbCurRetAddr + 2] ; pvHaystack.sel
     48        mov     al, [bp + 2 + cbCurRetAddr + 4] ; bNeedle
     49        mov     cx, [bp + 2 + cbCurRetAddr + 6] ; cbHaystack
     50
     51%elif TMPL_BITS == 32
     52        mov     edi, [ebp + 8]                          ; pvHaystack
     53        mov     al, byte [ebp + 4 + cbCurRetAddr + 4]   ; bNeedle
     54        mov     ecx, [ebp + 4 + cbCurRetAddr + 8]       ; cbHaystack
     55%else
     56 %error "TMPL_BITS!"
     57%endif
     58
    4059        cld
    41         rep stosq
     60        repne scasb
     61        je      .found
    4262
    43         mov     rcx, rdx                ; cbDst
    44         and     rcx, 7                  ; calc trailing byte count.
    45         rep stosb
     63        xor     xAX, xAX
     64TONLY16 xor     dx, dx
    4665
    47         pop     rdi
     66.return:
     67TONLY16 pop     es
     68        pop     xDI
     69        pop     xBP
    4870        BS3_HYBRID_RET
    4971
    50 %elif ARCH_BITS == 16
    51         push    bp
    52         mov     bp, sp
    53         push    di
    54         push    es
     72.found:
     73        lea     xAX, [xDI - 1]
     74TONLY16 mov     dx, es
     75        jmp     .return
    5576
    56         mov     di, [bp + 2 + cbCurRetAddr]     ; pvDst.off
    57         mov     dx, [bp + 2 + cbCurRetAddr + 2] ; pvDst.sel
    58         mov     es, dx
    59         mov     cx, [bp + 2 + cbCurRetAddr + 4] ; cbDst
    60         shr     cx, 1                           ; calc dword count.
    61         xor     ax, ax
    62         rep stosw
     77BS3_PROC_END_CMN   Bs3MemChr
    6378
    64         mov     cx, [bp + 2 + cbCurRetAddr + 4] ; cbDst
    65         and     cx, 1                           ; calc tailing byte count.
    66         rep stosb
    67 
    68         pop     es
    69         pop     di
    70         pop     bp
    71         BS3_HYBRID_RET
    72 
    73 %elif ARCH_BITS == 32
    74         push    edi
    75 
    76         mov     edi, [esp + 8]          ; pvDst
    77         mov     ecx, [esp + 8 + 4]      ; cbDst
    78         shr     cx, 2                   ; calc dword count.
    79         xor     eax, eax
    80         rep stosd
    81 
    82         mov     ecx, [esp + 8 + 4]      ; cbDst
    83         and     ecx, 3                  ; calc tailing byte count.
    84         rep stosb
    85 
    86         pop     edi
    87         BS3_HYBRID_RET
    88 
    89 %else
    90  %error "Unknown bitness."
    91 %endif
    92 BS3_PROC_END_CMN   Bs3MemZero
    93 
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-MemSet.asm

    r60585 r60657  
    11; $Id$
    22;; @file
    3 ; BS3Kit - Bs3MemZero.
     3; BS3Kit - Bs3MemSet.
    44;
    55
     
    2828
    2929;;
    30 ; @cproto   BS3_DECL(void) Bs3MemZero_c16(void BS3_FAR *pvDst, size_t cbDst);
     30; @cproto   BS3_CMN_PROTO_NOSB(void, Bs3MemSet,(void BS3_FAR *pvDst, uint8_t bFiller, size_t cbDst));
    3131;
    32 BS3_PROC_BEGIN_CMN Bs3MemZero, BS3_PBC_HYBRID
     32BS3_PROC_BEGIN_CMN Bs3MemSet, BS3_PBC_HYBRID
     33        push    xBP
     34        mov     xBP, xSP
     35        push    xDI
    3336%ifdef RT_ARCH_AMD64
    34         push    rdi
    3537
    3638        mov     rdi, rcx                ; rdi = pvDst
    37         mov     rcx, rdx                ; rcx = cbDst
     39        mov     rcx, r8                 ; rcx = cbDst
     40        movzx   edx, dl                 ; bFiller
     41        mov     rax, 0101010101010101h
     42        mul     rdx
     43        mov     rcx, r8
    3844        shr     rcx, 3                  ; calc qword count.
    39         xor     eax, eax                ; rax = 0 (filler qword)
    4045        cld
    4146        rep stosq
    4247
    43         mov     rcx, rdx                ; cbDst
     48        mov     rcx, r8                 ; cbDst
    4449        and     rcx, 7                  ; calc trailing byte count.
    4550        rep stosb
    4651
    47         pop     rdi
    48         BS3_HYBRID_RET
    49 
    5052%elif ARCH_BITS == 16
    51         push    bp
    52         mov     bp, sp
    53         push    di
    5453        push    es
    5554
    5655        mov     di, [bp + 2 + cbCurRetAddr]     ; pvDst.off
    57         mov     dx, [bp + 2 + cbCurRetAddr + 2] ; pvDst.sel
    58         mov     es, dx
    59         mov     cx, [bp + 2 + cbCurRetAddr + 4] ; cbDst
     56        mov     es, [bp + 2 + cbCurRetAddr + 2] ; pvDst.sel
     57        mov     al, [bp + 2 + cbCurRetAddr + 4] ; bFiller
     58        mov     ah, al
     59        mov     cx, [bp + 2 + cbCurRetAddr + 6] ; cbDst
    6060        shr     cx, 1                           ; calc dword count.
    61         xor     ax, ax
    6261        rep stosw
    6362
    64         mov     cx, [bp + 2 + cbCurRetAddr + 4] ; cbDst
     63        mov     cx, [bp + 2 + cbCurRetAddr + 6] ; cbDst
    6564        and     cx, 1                           ; calc tailing byte count.
    6665        rep stosb
    6766
    6867        pop     es
    69         pop     di
    70         pop     bp
    71         BS3_HYBRID_RET
    7268
    7369%elif ARCH_BITS == 32
    74         push    edi
    75 
    76         mov     edi, [esp + 8]          ; pvDst
    77         mov     ecx, [esp + 8 + 4]      ; cbDst
    78         shr     cx, 2                   ; calc dword count.
    79         xor     eax, eax
     70        mov     edi, [ebp + 8]                          ; pvDst
     71        mov     al, byte [ebp + 4 + cbCurRetAddr + 4]   ; bFiller
     72        mov     ah, al
     73        mov     dx, ax
     74        shl     eax, 16
     75        mov     ax, dx                                  ; eax = RT_MAKE_U32_FROM_U8(bFiller, bFiller, bFiller, bFiller)
     76        mov     ecx, [ebp + 4 + cbCurRetAddr + 8]       ; cbDst
     77        shr     cx, 2                                   ; calc dword count.
    8078        rep stosd
    8179
    82         mov     ecx, [esp + 8 + 4]      ; cbDst
    83         and     ecx, 3                  ; calc tailing byte count.
     80        mov     ecx, [ebp + 4 + cbCurRetAddr + 8]       ; cbDst
     81        and     ecx, 3                                  ; calc tailing byte count.
    8482        rep stosb
    85 
    86         pop     edi
    87         BS3_HYBRID_RET
    8883
    8984%else
    9085 %error "Unknown bitness."
    9186%endif
    92 BS3_PROC_END_CMN   Bs3MemZero
    9387
     88        pop     xDI
     89        pop     xBP
     90        BS3_HYBRID_RET
     91BS3_PROC_END_CMN   Bs3MemSet
     92
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-PrintU32.asm

    r60527 r60657  
    4343        push    sCX
    4444        push    sBX
    45         BS3_ONLY_16BIT_STMT push ds
     45BONLY16 push    ds
    4646
    4747        mov     eax, [xBP + xCB + cbCurRetAddr]
     
    4949        ; Allocate a stack buffer and terminate it. ds:bx points ot the end.
    5050        sub     xSP, 30h
    51         BS3_ONLY_16BIT_STMT mov bx, ss
    52         BS3_ONLY_16BIT_STMT mov ds, bx
     51BONLY16 mov    bx, ss
     52BONLY16 mov    ds, bx
    5353        mov     xBX, xSP
    5454        add     xBX, 2fh
     
    6666
    6767        ; Print the string.
    68         BS3_ONLY_64BIT_STMT add     rsp, 18h
    69         BS3_ONLY_16BIT_STMT push    ss
     68BONLY64 add     rsp, 18h
     69BONLY16 push    ss
    7070        push    xBX
    7171        BS3_CALL Bs3PrintStr, 1
    7272
    7373        add     xSP, 30h + BS3_IF_16_32_64BIT(2, 0, 18h) + xCB
    74         BS3_ONLY_16BIT_STMT pop ds
     74BONLY16 pop    ds
    7575        pop     sBX
    7676        pop     sCX
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-PrintX32.asm

    r60527 r60657  
    4343        push    sCX
    4444        push    sBX
    45         BS3_ONLY_16BIT_STMT push ds
     45BONLY16 push    ds
    4646
    4747        mov     eax, [xBP + xCB + cbCurRetAddr]
     
    4949        ; Allocate a stack buffer and terminate it. ds:bx points ot the end.
    5050        sub     xSP, 30h
    51         BS3_ONLY_16BIT_STMT mov bx, ss
    52         BS3_ONLY_16BIT_STMT mov ds, bx
     51BONLY16 mov    bx, ss
     52BONLY16 mov    ds, bx
    5353        mov     xBX, xSP
    5454        add     xBX, 2fh
     
    7070
    7171        ; Print the string.
    72         BS3_ONLY_64BIT_STMT add     rsp, 18h
    73         BS3_ONLY_16BIT_STMT push    ss
     72BONLY64 add     rsp, 18h
     73BONLY16 push    ss
    7474        push    xBX
    7575        BS3_CALL Bs3PrintStr, 1
    7676
    7777        add     xSP, 30h + BS3_IF_16_32_64BIT(2, 0, 18h) + xCB
    78         BS3_ONLY_16BIT_STMT pop ds
     78BONLY16 pop    ds
    7979        pop     sBX
    8080        pop     sCX
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-RegCtxRestore.asm

    r60527 r60657  
    6969        ; CS or SS values).
    7070        ;
     71%if TMPL_BITS == 16
     72        cmp     byte [BS3_DATA16_WRT(g_bBs3CurrentMode)], BS3_MODE_RM
     73        je      .in_ring0
     74        test    byte [BS3_DATA16_WRT(g_bBs3CurrentMode)], BS3_MODE_CODE_V86
     75        jnz     .do_syscall_restore_ctx
     76%endif
    7177        mov     ax, ss
    7278        test    al, 3
    7379        jz      .in_ring0
     80
     81.do_syscall_restore_ctx:
    7482%if TMPL_BITS == 16
    7583        mov     si, [bp + xCB + cbCurRetAddr]
     
    8492%endif
    8593        call    Bs3Syscall
    86 .in_ring0:
    8794
    8895        ;
     
    9097        ; and g_uBs3CpuDetected), DS:xBX with pRegCtx and fFlags into xCX.
    9198        ;
     99.in_ring0:
    92100%if TMPL_BITS == 16
    93101        mov     ax, BS3_SEL_DATA16
     
    236244        test    cl, BS3TRAPRESUME_F_SKIP_CRX
    237245        jnz     .skip_control_regs
    238         test    byte [xBX + BS3REGCTX.fbFlags], BS3REG_CTX_F_NO_CR
     246        test    byte [xBX + BS3REGCTX.fbFlags], BS3REG_CTX_F_NO_CR0_IS_MSW | BS3REG_CTX_F_NO_CR2_CR3
    239247        jnz     .skip_control_regs
    240248
     
    355363        ; 32-bit/16-bit is more complicated as we have three different iret frames.
    356364        ;
    357         cmp     byte [BS3_ONLY_16BIT(es:) BS3_DATA16_WRT(g_bBs3CurrentMode)], BS3_MODE_RM
     365        mov     al, [BS3_ONLY_16BIT(es:) BS3_DATA16_WRT(g_bBs3CurrentMode)]
     366        cmp     al, BS3_MODE_RM
    358367        je      .iretd_same_cpl_rm
    359368
     
    387396        mov     ecx, [xBX + BS3REGCTX.rcx]
    388397        mov     esi, [xBX + BS3REGCTX.rsi]
    389 %if TMPL_BITS == 16 ; if SS is 16-bit, we will not be able to restore the high word.
     398 %if TMPL_BITS == 16 ; if SS is 16-bit, we will not be able to restore the high word.
    390399        mov     edi, [xBX + BS3REGCTX.rsp]
    391400        mov     di, sp
    392401        mov     esp, edi
    393 %endif
     402 %endif
    394403        mov     edi, [xBX + BS3REGCTX.rdi]
    395404        mov     ebx, [xBX + BS3REGCTX.rbx]
     
    405414        ; Use STOSD/ES:EDI to create the frame.
    406415        mov     es,  [xBX + BS3REGCTX.ss]
    407         movzx   esp, word [xBX + BS3REGCTX.rsp]
    408         jmp     .using_16_bit_stack_pointer
     416        mov     esi, [xBX + BS3REGCTX.rsp]
     417        sub     esi, 5*4
     418        movzx   edi, si
     419        jmp     .es_edi_is_pointing_to_return_frame_location
    409420
    410421.iretd_same_cpl:
     
    420431        jnz     .using_32_bit_stack_pointer
    421432.using_16_bit_stack_pointer:
     433        mov     esi, edi                ; save rsp for later.
    422434        movzx   edi, di
    423         mov     esi, [xBX + BS3REGCTX.rsp]
    424         mov     si, di                  ; save rsp for later.
    425435        jmp     .es_edi_is_pointing_to_return_frame_location
    426436.using_32_bit_stack_pointer:
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-RegCtxSave.asm

    r60527 r60657  
    4444;
    4545BS3_PROC_BEGIN_CMN Bs3RegCtxSave, BS3_PBC_HYBRID_SAFE
    46         TMPL_ONLY_16BIT_STMT CPU 8086
     46TONLY16 CPU 8086
    4747        BS3_CALL_CONV_PROLOG 1
    4848        push    xBP
     
    5252        push    xCX                     ; xBP - xCB*3: save incoming xCX
    5353        push    xDI                     ; xBP - xCB*4: save incoming xDI
    54         BS3_ONLY_16BIT_STMT push    es  ; xBP - xCB*5
    55         BS3_ONLY_16BIT_STMT push    ds  ; xBP - xCB*6
     54BONLY16 push    es                      ; xBP - xCB*5
     55BONLY16 push    ds                      ; xBP - xCB*6
    5656
    5757        ;
     
    153153        pop     dword [xDI + BS3REGCTX.rflags]
    154154%endif
     155%if TMPL_BITS != 64
     156        ; The VM flag is never on the stack, so derive it from the bMode we saved above.
     157        test    byte [xDI + BS3REGCTX.bMode], BS3_MODE_CODE_V86
     158        jz      .not_v8086
     159        or      byte [xDI + BS3REGCTX.rflags + 2], X86_EFL_VM >> 16
     160        mov     byte [xDI + BS3REGCTX.bCpl], 3
     161.not_v8086:
     162%endif
    155163
    156164        ; 386 segment registers.
     
    186194
    187195.common_full_no_control_regs:
    188         or      byte [xDI + BS3REGCTX.fbFlags], BS3REG_CTX_F_NO_CR
     196        or      byte [xDI + BS3REGCTX.fbFlags], BS3REG_CTX_F_NO_CR0_IS_MSW | BS3REG_CTX_F_NO_CR2_CR3 | BS3REG_CTX_F_NO_CR4
     197        smsw    [xDI + BS3REGCTX.cr0]
    189198
    190199        ; 80286 control registers.
    191200.common_80286:
    192         TMPL_ONLY_16BIT_STMT CPU 286
     201TONLY16 CPU 286
     202%if TMPL_BITS != 64
    193203        cmp     cl, BS3_MODE_RM
    194         je      .common_ancient
     204        je      .no_str_sldt
     205        test    cl, BS3_MODE_CODE_V86
     206        jnz     .no_str_sldt
     207%endif
    195208        str     [xDI + BS3REGCTX.tr]
    196209        sldt    [xDI + BS3REGCTX.ldtr]
    197210
     211.no_str_sldt:
     212        or      byte [xDI + BS3REGCTX.fbFlags], BS3REG_CTX_F_NO_TR_LDTR
     213
    198214        ; Common stuff - stuff on the stack, 286 segment registers.
    199215.common_ancient:
    200         TMPL_ONLY_16BIT_STMT CPU 8086
     216TONLY16 CPU 8086
    201217        mov     xAX, [xBP - xCB*1]
    202218        mov     [xDI + BS3REGCTX.rflags], xAX
     
    232248        ;
    233249.return:
    234         BS3_ONLY_16BIT_STMT pop     ds
    235         BS3_ONLY_16BIT_STMT pop     es
     250BONLY16 pop     ds
     251BONLY16 pop     es
    236252        pop     xDI
    237253        pop     xCX
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-StrFormatV.c

    r60527 r60657  
    436436            }
    437437            State.fFlags |= STR_F_WIDTH;
     438            ch = *pszFormat++;
    438439        }
    439440
     
    442443         */
    443444        State.cchPrecision = 0;
    444         if (RT_C_IS_DIGIT(ch))
    445         {
    446             do
    447             {
    448                 State.cchPrecision *= 10;
    449                 State.cchPrecision  = ch - '0';
     445        if (ch == '.')
     446        {
     447            ch = *pszFormat++;
     448            if (RT_C_IS_DIGIT(ch))
     449            {
     450                do
     451                {
     452                    State.cchPrecision *= 10;
     453                    State.cchPrecision  = ch - '0';
     454                    ch = *pszFormat++;
     455                } while (RT_C_IS_DIGIT(ch));
     456                State.fFlags |= STR_F_PRECISION;
     457            }
     458            else if (ch == '*')
     459            {
     460                State.cchPrecision = va_arg(va, int);
     461                if (State.cchPrecision < 0)
     462                    State.cchPrecision = 0;
     463                State.fFlags |= STR_F_PRECISION;
    450464                ch = *pszFormat++;
    451             } while (RT_C_IS_DIGIT(ch));
    452             State.fFlags |= STR_F_PRECISION;
    453         }
    454         else if (ch == '*')
    455         {
    456             State.cchPrecision = va_arg(va, int);
    457             if (State.cchPrecision < 0)
    458                 State.cchPrecision = 0;
    459             State.fFlags |= STR_F_PRECISION;
     465            }
    460466        }
    461467
     
    651657                        State.fFlags &= ~(STR_F_PLUS | STR_F_BLANK);
    652658                        State.uBase   = 16;
     659                        break;
     660                    case 'h':
     661                        ch = *pszFormat++;
     662                        if (ch == 'x')
     663                        {
     664                            /* Hex dumping. */
     665                            uint8_t const BS3_FAR *pbHex = va_arg(va, uint8_t const BS3_FAR *);
     666                            if (State.cchPrecision < 0)
     667                                State.cchPrecision = 16;
     668                            ch = *pszFormat++;
     669                            if (ch == 's' || ch == 'd')
     670                            {
     671                                /* %Rhxd is currently implemented as %Rhxs. */
     672                                while (State.cchPrecision-- > 0)
     673                                {
     674                                    uint8_t b = *pbHex++;
     675                                    State.pfnOutput(g_achBs3HexDigits[b >> 4], State.pvUser);
     676                                    State.pfnOutput(g_achBs3HexDigits[b & 0x0f], State.pvUser);
     677                                    if (State.cchPrecision)
     678                                        State.pfnOutput(' ', State.pvUser);
     679                                }
     680                            }
     681                        }
     682                        State.uBase   = 0;
    653683                        break;
    654684                    default:
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchTo16Bit.asm

    r60527 r60657  
    103103
    104104        popfd
    105         TMPL_ONLY_64BIT_STMT pop     ebx
     105TONLY64 pop     ebx
    106106        pop     ebx
    107         TMPL_ONLY_64BIT_STMT pop     eax
     107TONLY64 pop     eax
    108108        pop     eax
    109         TMPL_ONLY_64BIT_STMT add     sp, 4
     109TONLY64 add     sp, 4
    110110        ret     (TMPL_BITS - 16) / 8    ; Return and pop 2 or 6 bytes of "parameters" (unused return value)
    111111
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchTo16BitV86.asm

    r60527 r60657  
    4242BS3_PROC_BEGIN_CMN Bs3SwitchTo16BitV86, BS3_PBC_NEAR
    4343        ; Construct basic v8086 return frame.
    44         BS3_ONLY_16BIT_STMT movzx   esp, sp
     44BONLY16 movzx   esp, sp
    4545        push    dword 0                                 ; +0x20: GS
    4646        push    dword 0                                 ; +0x1c: FS
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchToRing0.asm

    r60527 r60657  
    5555%else
    5656        push    0
    57         TMPL_ONLY_16BIT_STMT push cs
     57TONLY16 push    cs
    5858        call    Bs3SwitchToRingX
    5959        add     xSP, xCB
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchToRing1.asm

    r60527 r60657  
    5555%else
    5656        push    1
    57         TMPL_ONLY_16BIT_STMT push cs
     57TONLY16 push    cs
    5858        call    Bs3SwitchToRingX
    5959        add     xSP, xCB
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchToRing2.asm

    r60527 r60657  
    5555%else
    5656        push    2
    57         TMPL_ONLY_16BIT_STMT push cs
     57TONLY16 push    cs
    5858        call    Bs3SwitchToRingX
    5959        add     xSP, xCB
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchToRing3.asm

    r60527 r60657  
    5555%else
    5656        push    3
    57         TMPL_ONLY_16BIT_STMT push cs
     57TONLY16 push    cs
    5858        call    Bs3SwitchToRingX
    5959        add     xSP, xCB
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-TestCheckRegCtxEx.c

    r60527 r60657  
    3636                                        uint32_t fExtraEfl, const char *pszMode, uint16_t idTestStep))
    3737{
    38     uint16_t cErrorsBefore = Bs3TestSubErrorCount();
     38    uint16_t const cErrorsBefore = Bs3TestSubErrorCount();
     39    uint8_t  const fbFlags       = pActualCtx->fbFlags | pExpectedCtx->fbFlags;
    3940
    4041#define CHECK_MEMBER(a_szName, a_szFmt, a_Actual, a_Expected) \
     
    5253    CHECK_MEMBER("rsi",     "%08RX64",  pActualCtx->rsi.u,    pExpectedCtx->rsi.u);
    5354    CHECK_MEMBER("rdi",     "%08RX64",  pActualCtx->rdi.u,    pExpectedCtx->rdi.u);
    54     if (   !(pActualCtx->fbFlags & BS3REG_CTX_F_NO_AMD64)
    55         && !(pExpectedCtx->fbFlags & BS3REG_CTX_F_NO_AMD64) )
     55    if (!(fbFlags & BS3REG_CTX_F_NO_AMD64))
    5656    {
    5757        CHECK_MEMBER("r8",      "%08RX64",  pActualCtx->r8.u,     pExpectedCtx->r8.u);
     
    7171    CHECK_MEMBER("fs",      "%04RX16",  pActualCtx->fs,       pExpectedCtx->fs);
    7272    CHECK_MEMBER("gs",      "%04RX16",  pActualCtx->gs,       pExpectedCtx->gs);
    73     CHECK_MEMBER("tr",      "%04RX16",  pActualCtx->tr,       pExpectedCtx->tr);
    74     CHECK_MEMBER("ldtr",    "%04RX16",  pActualCtx->ldtr,     pExpectedCtx->ldtr);
     73
     74    if (!(fbFlags & BS3REG_CTX_F_NO_TR_LDTR))
     75    {
     76        CHECK_MEMBER("tr",      "%04RX16",  pActualCtx->tr,       pExpectedCtx->tr);
     77        CHECK_MEMBER("ldtr",    "%04RX16",  pActualCtx->ldtr,     pExpectedCtx->ldtr);
     78    }
    7579    CHECK_MEMBER("bMode",   "%#04x",    pActualCtx->bMode,    pExpectedCtx->bMode);
    7680    CHECK_MEMBER("bCpl",    "%u",       pActualCtx->bCpl,     pExpectedCtx->bCpl);
    77     if (!(pActualCtx->fbFlags & BS3REG_CTX_F_NO_CR))
     81
     82    if (!(fbFlags & BS3REG_CTX_F_NO_CR0_IS_MSW))
     83        CHECK_MEMBER("cr0", "%08RX64",  pActualCtx->cr0.u,    pExpectedCtx->cr0.u);
     84    else
     85        CHECK_MEMBER("msw", "%08RX16",  pActualCtx->cr0.u16,  pExpectedCtx->cr0.u16);
     86    if (!(fbFlags & BS3REG_CTX_F_NO_CR2_CR3))
    7887    {
    79         CHECK_MEMBER("cr0", "%08RX64",  pActualCtx->cr0.u,    pExpectedCtx->cr0.u);
    8088        CHECK_MEMBER("cr2", "%08RX64",  pActualCtx->cr2.u,    pExpectedCtx->cr2.u);
    8189        CHECK_MEMBER("cr3", "%08RX64",  pActualCtx->cr3.u,    pExpectedCtx->cr3.u);
     90    }
     91    if (!(fbFlags & BS3REG_CTX_F_NO_CR4))
    8292        CHECK_MEMBER("cr4", "%08RX64",  pActualCtx->cr4.u,    pExpectedCtx->cr4.u);
    83     }
    8493#undef CHECK_MEMBER
    8594
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-TestSendCmdWithStr.asm

    r60527 r60657  
    4141        push    xDX
    4242        push    xSI
    43         BS3_ONLY_16BIT_STMT push ds
     43BONLY16 push    ds
    4444
    4545        cmp     byte [BS3_DATA16_WRT(g_fbBs3VMMDevTesting)], 0
     
    7070
    7171.no_vmmdev:
    72         BS3_ONLY_16BIT_STMT pop ds
     72BONLY16 pop    ds
    7373        pop     xSI
    7474        pop     xDX
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-TrapDefaultHandler.c

    r60527 r60657  
    2929*********************************************************************************************************************************/
    3030#include "bs3kit-template-header.h"
     31#if TMPL_BITS != 64
     32# include <VBox/VMMDevTesting.h>
     33# include <iprt/asm-amd64-x86.h>
     34#endif
    3135
    3236
     
    148152            else if (bOpCode == 0xfb)
    149153                pTrapFrame->Ctx.rflags.u16 |= X86_EFL_IF;
     154            /* OUT: byte I/O to VMMDev. */
     155            else if (   bOpCode == 0xee
     156                     && ((unsigned)(pTrapFrame->Ctx.rdx.u16 - VMMDEV_TESTING_IOPORT_BASE) < (unsigned)VMMDEV_TESTING_IOPORT_COUNT))
     157                ASMOutU8(pTrapFrame->Ctx.rdx.u16, pTrapFrame->Ctx.rax.u8);
     158            /* OUT: [d]word I/O to VMMDev. */
     159            else if (   bOpCode == 0xef
     160                     && ((unsigned)(pTrapFrame->Ctx.rdx.u16 - VMMDEV_TESTING_IOPORT_BASE) < (unsigned)VMMDEV_TESTING_IOPORT_COUNT))
     161            {
     162                if (cBitsOpcode != 32)
     163                    ASMOutU16(pTrapFrame->Ctx.rdx.u16, pTrapFrame->Ctx.rax.u16);
     164                else
     165                    ASMOutU32(pTrapFrame->Ctx.rdx.u16, pTrapFrame->Ctx.rax.u32);
     166            }
     167            /* IN: byte I/O to VMMDev. */
     168            else if (   bOpCode == 0xec
     169                     && ((unsigned)(pTrapFrame->Ctx.rdx.u16 - VMMDEV_TESTING_IOPORT_BASE) < (unsigned)VMMDEV_TESTING_IOPORT_COUNT))
     170                pTrapFrame->Ctx.rax.u8 = ASMInU8(pTrapFrame->Ctx.rdx.u16);
     171            /* IN: [d]word I/O to VMMDev. */
     172            else if (   bOpCode == 0xed
     173                     && ((unsigned)(pTrapFrame->Ctx.rdx.u16 - VMMDEV_TESTING_IOPORT_BASE) < (unsigned)VMMDEV_TESTING_IOPORT_COUNT))
     174            {
     175                if (cBitsOpcode != 32)
     176                    pTrapFrame->Ctx.rax.u16 = ASMInU16(pTrapFrame->Ctx.rdx.u16);
     177                else
     178                    pTrapFrame->Ctx.rax.u32 = ASMInU32(pTrapFrame->Ctx.rdx.u32);
     179            }
    150180            /* Unexpected. */
    151181            else
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-TrapPrintFrame.c

    r60527 r60657  
    3535{
    3636#if 1
    37     Bs3TestPrintf("Trap %#04x errcd=%#06RX64 at %04x:%016RX64 - test step %d (%#x)\n",
     37    Bs3TestPrintf("Trap %#04x errcd=%#06RX64 at %04x:%016RX64 (by %04x/%04x) - test step %d (%#x)\n",
    3838                  pTrapFrame->bXcpt,
    3939                  pTrapFrame->uErrCd,
    4040                  pTrapFrame->Ctx.cs,
    4141                  pTrapFrame->Ctx.rip.u64,
     42                  pTrapFrame->uHandlerCs,
     43                  pTrapFrame->uHandlerSs,
    4244                  g_usBs3TestStep, g_usBs3TestStep);
    4345    Bs3RegCtxPrint(&pTrapFrame->Ctx);
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-TrapSetJmp.asm

    r60527 r60657  
    5454        mov     xBP, xSP
    5555        push    xBX
    56         BS3_ONLY_64BIT_STMT sub     xSP, 20h
     56BONLY64 sub     xSP, 20h
    5757
    5858        ;
    5959        ; Save the current register context.
    6060        ;
    61         BS3_ONLY_16BIT_STMT push    ds
     61BONLY16 push    ds
    6262        BS3_LEA_MOV_WRT_RIP(xAX, BS3_DATA16_WRT(g_Bs3TrapSetJmpCtx))
    6363        push    xAX
     
    125125        ;
    126126        mov     xAX, 1
    127         BS3_ONLY_64BIT_STMT add     xSP, 20h
     127BONLY64 add     xSP, 20h
    128128        pop     xBX
    129129        pop     xBP
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-PagingGetRootForLM64.asm

    r60554 r60657  
    7171        push    xBP
    7272        mov     xBP, xSP
    73         BS3_ONLY_16BIT_STMT push    es
     73BONLY16 push    es
    7474        push    sDX
    7575        push    sCX
     
    102102        ; Not a problematic addressing mode.
    103103        ;
    104         BS3_ONLY_64BIT_STMT sub     rsp, 20h
     104BONLY64 sub     rsp, 20h
    105105        BS3_CALL Bs3PagingInitRootForLM, 0
    106         BS3_ONLY_64BIT_STMT add     rsp, 20h
     106BONLY64 add     rsp, 20h
    107107%endif
    108108
     
    121121        pop     sCX
    122122        pop     sDX
    123         BS3_ONLY_16BIT_STMT pop     es
     123BONLY16 pop     es
    124124        leave
    125125%ifdef BS3_STRICT
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-PagingGetRootForPAE32.asm

    r60554 r60657  
    6060        push    xBP
    6161        mov     xBP, xSP
    62         BS3_ONLY_16BIT_STMT push    es
     62BONLY16 push    es
    6363        push    sDX
    6464        push    sCX
     
    9292        ; Not a problematic addressing mode.
    9393        ;
    94         BS3_ONLY_64BIT_STMT sub     rsp, 20h
     94BONLY64 sub     rsp, 20h
    9595        BS3_CALL Bs3PagingInitRootForPAE, 0
    96         BS3_ONLY_64BIT_STMT add     rsp, 20h
     96BONLY64 add     rsp, 20h
    9797%endif
    9898
     
    111111        pop     sCX
    112112        pop     sDX
    113         BS3_ONLY_16BIT_STMT pop     es
     113BONLY16 pop     es
    114114        leave
    115115        ret
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-PagingGetRootForPP32.asm

    r60554 r60657  
    7171        push    xBP
    7272        mov     xBP, xSP
    73         BS3_ONLY_16BIT_STMT push    es
     73BONLY16 push    es
    7474        push    sDX
    7575        push    sCX
     
    103103        ; Not a problematic addressing mode.
    104104        ;
    105         BS3_ONLY_64BIT_STMT sub     rsp, 20h
     105BONLY64 sub     rsp, 20h
    106106        BS3_CALL Bs3PagingInitRootForPP, 0
    107         BS3_ONLY_64BIT_STMT add     rsp, 20h
     107BONLY64 add     rsp, 20h
    108108%endif
    109109
     
    122122        pop     sCX
    123123        pop     sDX
    124         BS3_ONLY_16BIT_STMT pop     es
     124BONLY16 pop     es
    125125        leave
    126126%ifdef BS3_STRICT
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToRM.asm

    r60557 r60657  
    181181        and     ax, ~X86_CR0_PE
    182182        mov     cr0, eax
    183 hlt
    184183        jmp     BS3_SEL_TEXT16:.resume
    185184 %endif
     
    323322 %if BS3_MODE_IS_64BIT_SYS(TMPL_MODE)
    324323        pop     ecx
    325         TMPL_ONLY_64BIT_STMT pop eax
     324TONLY64 pop    eax
    326325        pop     edx
    327         TMPL_ONLY_64BIT_STMT pop eax
     326TONLY64 pop    eax
    328327 %endif
    329328        popfd
    330         TMPL_ONLY_64BIT_STMT pop eax
     329TONLY64 pop    eax
    331330        pop     ebx
    332         TMPL_ONLY_64BIT_STMT pop eax
     331TONLY64 pop    eax
    333332        pop     eax
    334         TMPL_ONLY_64BIT_STMT add sp, 4
     333TONLY64 add    sp, 4
    335334        retn    (TMPL_BITS - 16) / 8
    336335
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TrapSystemCallHandler.asm

    r60557 r60657  
    319319
    320320        ; Convert the register context from whatever it is to ring-0.
    321         BS3_ONLY_64BIT_STMT sub     rsp, 10h
     321BONLY64 sub     rsp, 10h
    322322        mov     ax, VAR_CALLER_AX
    323323        sub     ax, BS3_SYSCALL_TO_RING0
    324324        push    xAX
    325         BS3_ONLY_16BIT_STMT push    ss
     325BONLY16 push    ss
    326326        push    xBX
    327327        BS3_CALL Bs3RegCtxConvertToRingX, 2
     
    330330        ; Restore the register context (does not return).
    331331        pop     xBX                     ; restore saved pointer.
    332         BS3_ONLY_64BIT_STMT sub     rsp, 18h
    333         BS3_ONLY_16BIT_STMT push    ss
     332BONLY64 sub     rsp, 18h
     333BONLY16 push    ss
    334334        push    xBX
    335335        BS3_CALL Bs3RegCtxRestore, 1
     
    342342.restore_ctx:
    343343        call    .convert_ptr_arg_to_cx_xSI
    344         BS3_ONLY_64BIT_STMT sub     rsp, 10h
     344BONLY64 sub     rsp, 10h
    345345        mov     xDX, VAR_CALLER_DX
    346346        push    xDX
    347         BS3_ONLY_16BIT_STMT push    cx
     347BONLY16 push    cx
    348348        push    xSI
    349349        BS3_CALL Bs3RegCtxRestore, 2
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-autostubs.kmk

    r60585 r60657  
    2525#
    2626
     27$(call BS3KIT_FN_GEN_CMN_FARSTUB,bs3kit-common-16,Bs3SelFlatDataToProtFar16,4)
     28$(call BS3KIT_FN_GEN_CMN_FARSTUB,bs3kit-common-16,Bs3SelFlatDataToRealMode,4)
     29$(call BS3KIT_FN_GEN_CMN_FARSTUB,bs3kit-common-16,Bs3SelProtFar16DataToFlat,4)
     30$(call BS3KIT_FN_GEN_CMN_FARSTUB,bs3kit-common-16,Bs3SelProtFar16DataToRealMode,4)
     31$(call BS3KIT_FN_GEN_CMN_FARSTUB,bs3kit-common-16,Bs3SelRealModeDataToFlat,4)
     32$(call BS3KIT_FN_GEN_CMN_FARSTUB,bs3kit-common-16,Bs3SelRealModeDataToProtFar16,4)
     33$(call BS3KIT_FN_GEN_CMN_FARSTUB,bs3kit-common-16,Bs3SelFar32ToFlat32NoClobber,6)
     34$(call BS3KIT_FN_GEN_CMN_FARSTUB,bs3kit-common-16,Bs3RegCtxSaveEx,8)
    2735$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3TestCheckRegCtxEx)
    2836$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3StrCpy)
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-define.h

    r60585 r60657  
    3636#define Bs3MemAlloc BS3_CMN_MANGLER(Bs3MemAlloc)
    3737#define Bs3MemAllocZ BS3_CMN_MANGLER(Bs3MemAllocZ)
     38#define Bs3MemChr BS3_CMN_MANGLER(Bs3MemChr)
    3839#define Bs3MemCpy BS3_CMN_MANGLER(Bs3MemCpy)
    3940#define Bs3MemFree BS3_CMN_MANGLER(Bs3MemFree)
    4041#define Bs3MemMove BS3_CMN_MANGLER(Bs3MemMove)
    4142#define Bs3MemPCpy BS3_CMN_MANGLER(Bs3MemPCpy)
     43#define Bs3MemSet BS3_CMN_MANGLER(Bs3MemSet)
    4244#define Bs3MemZero BS3_CMN_MANGLER(Bs3MemZero)
    4345#define Bs3PagingInitRootForLM BS3_CMN_MANGLER(Bs3PagingInitRootForLM)
     
    5961#define Bs3RegCtxRestore BS3_CMN_MANGLER(Bs3RegCtxRestore)
    6062#define Bs3RegCtxSave BS3_CMN_MANGLER(Bs3RegCtxSave)
     63#define Bs3RegCtxSaveEx BS3_CMN_MANGLER(Bs3RegCtxSaveEx)
    6164#define Bs3SelFar32ToFlat32 BS3_CMN_MANGLER(Bs3SelFar32ToFlat32)
     65#define Bs3SelFar32ToFlat32NoClobber BS3_CMN_MANGLER(Bs3SelFar32ToFlat32NoClobber)
    6266#define Bs3SelFlatCodeToProtFar16 BS3_CMN_MANGLER(Bs3SelFlatCodeToProtFar16)
    6367#define Bs3SelFlatCodeToRealMode BS3_CMN_MANGLER(Bs3SelFlatCodeToRealMode)
     68#define Bs3SelFlatDataToProtFar16 BS3_CMN_MANGLER(Bs3SelFlatDataToProtFar16)
     69#define Bs3SelFlatDataToRealMode BS3_CMN_MANGLER(Bs3SelFlatDataToRealMode)
     70#define Bs3SelProtFar16DataToFlat BS3_CMN_MANGLER(Bs3SelProtFar16DataToFlat)
     71#define Bs3SelProtFar16DataToRealMode BS3_CMN_MANGLER(Bs3SelProtFar16DataToRealMode)
    6472#define Bs3SelProtFar32ToFlat32 BS3_CMN_MANGLER(Bs3SelProtFar32ToFlat32)
    6573#define Bs3SelProtModeCodeToRealMode BS3_CMN_MANGLER(Bs3SelProtModeCodeToRealMode)
    6674#define Bs3SelRealModeCodeToProtMode BS3_CMN_MANGLER(Bs3SelRealModeCodeToProtMode)
     75#define Bs3SelRealModeDataToFlat BS3_CMN_MANGLER(Bs3SelRealModeDataToFlat)
     76#define Bs3SelRealModeDataToProtFar16 BS3_CMN_MANGLER(Bs3SelRealModeDataToProtFar16)
    6777#define Bs3Shutdown BS3_CMN_MANGLER(Bs3Shutdown)
    6878#define Bs3SlabAlloc BS3_CMN_MANGLER(Bs3SlabAlloc)
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-undef.h

    r60585 r60657  
    3636#undef Bs3MemAlloc
    3737#undef Bs3MemAllocZ
     38#undef Bs3MemChr
    3839#undef Bs3MemCpy
    3940#undef Bs3MemFree
    4041#undef Bs3MemMove
    4142#undef Bs3MemPCpy
     43#undef Bs3MemSet
    4244#undef Bs3MemZero
    4345#undef Bs3PagingInitRootForLM
     
    5961#undef Bs3RegCtxRestore
    6062#undef Bs3RegCtxSave
     63#undef Bs3RegCtxSaveEx
    6164#undef Bs3SelFar32ToFlat32
     65#undef Bs3SelFar32ToFlat32NoClobber
    6266#undef Bs3SelFlatCodeToProtFar16
    6367#undef Bs3SelFlatCodeToRealMode
     68#undef Bs3SelFlatDataToProtFar16
     69#undef Bs3SelFlatDataToRealMode
     70#undef Bs3SelProtFar16DataToFlat
     71#undef Bs3SelProtFar16DataToRealMode
    6472#undef Bs3SelProtFar32ToFlat32
    6573#undef Bs3SelProtModeCodeToRealMode
    6674#undef Bs3SelRealModeCodeToProtMode
     75#undef Bs3SelRealModeDataToFlat
     76#undef Bs3SelRealModeDataToProtFar16
    6777#undef Bs3Shutdown
    6878#undef Bs3SlabAlloc
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-template-footer.mac

    r60554 r60657  
    124124%undef sSI
    125125
    126 %unmacro TMPL_ONLY_16BIT_STMT 1+
    127 %unmacro TMPL_ONLY_32BIT_STMT 1+
    128 %unmacro TMPL_ONLY_64BIT_STMT 1+
     126%unmacro TONLY16 1+
     127%unmacro TONLY32 1+
     128%unmacro TONLY64 1+
    129129
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-template-header.mac

    r60554 r60657  
    438438%endif
    439439
    440 ;; @def TMPL_ONLY_16BIT_STMT
    441 ; Version of BS3_ONLY_16BIT_STMT that follows the code template.
     440;; @def TONLY16
     441; Version of BONLY16 that follows the code template.
     442; Like BONLY16 this normally goes in column 1.
    442443%if TMPL_BITS == 16
    443  %macro TMPL_ONLY_16BIT_STMT 1+
     444 %macro TONLY16 1+
    444445        %1
    445446 %endmacro
    446447%else
    447  %macro TMPL_ONLY_16BIT_STMT 1+
    448  %endmacro
    449 %endif
    450 
    451 ;; @def TMPL_ONLY_32BIT_STMT
    452 ; Version of BS3_ONLY_32BIT_STMT that follows the code template.
     448 %macro TONLY16 1+
     449 %endmacro
     450%endif
     451
     452;; @def TONLY32
     453; Version of BONLY32 that follows the code template.
     454; Like BONLY32 this normally goes in column 1.
    453455%if TMPL_BITS == 32
    454  %macro TMPL_ONLY_32BIT_STMT 1+
     456 %macro TONLY32 1+
    455457        %1
    456458 %endmacro
    457459%else
    458  %macro TMPL_ONLY_32BIT_STMT 1+
    459  %endmacro
    460 %endif
    461 
    462 ;; @def TMPL_ONLY_64BIT_STMT
    463 ; Version of BS3_ONLY_64BIT_STMT that follows the code template.
     460 %macro TONLY32 1+
     461 %endmacro
     462%endif
     463
     464;; @def TONLY64
     465; Version of BONLY64 that follows the code template.
     466; Like BONLY64 this normally goes in column 1.
    464467%if TMPL_BITS == 64
    465  %macro TMPL_ONLY_64BIT_STMT 1+
     468 %macro TONLY64 1+
    466469        %1
    467470 %endmacro
    468471%else
    469  %macro TMPL_ONLY_64BIT_STMT 1+
     472 %macro TONLY64 1+
    470473 %endmacro
    471474%endif
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h

    r60609 r60657  
    911911/** The BS3DATA16/BS3KIT_GRPNM_DATA16 GDT entry. */
    912912extern X86DESC BS3_FAR_DATA Bs3Gdte_DATA16;
     913
    913914/** Free GDTes, part \#4. */
    914 
    915915extern X86DESC BS3_FAR_DATA Bs3GdteFreePart4[211];
     916
    916917extern X86DESC BS3_FAR_DATA Bs3GdtePreTestPage08; /**< GDT entry 8 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_08 */
    917918extern X86DESC BS3_FAR_DATA Bs3GdtePreTestPage07; /**< GDT entry 7 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_07 */
     
    16231624BS3_CMN_PROTO_NOSB(void, Bs3MemZero,(void BS3_FAR *pvDst, size_t cbDst));
    16241625
     1626/**
     1627 * CRT style memset.
     1628 *
     1629 * @param   pvDst           The buffer to be fill.
     1630 * @param   bFiller         The filler byte.
     1631 * @param   cbDst           The number of bytes to fill.
     1632 */
     1633BS3_CMN_PROTO_NOSB(void, Bs3MemSet,(void BS3_FAR *pvDst, uint8_t bFiller, size_t cbDst));
     1634
     1635/**
     1636 * CRT style memchr.
     1637 *
     1638 * @param   pvHaystack      The memory to scan for @a bNeedle.
     1639 * @param   bNeedle         The byte to search for.
     1640 * @param   cbHaystack      The amount of memory to search.
     1641 */
     1642BS3_CMN_PROTO_NOSB(void BS3_FAR *, Bs3MemChr,(void const BS3_FAR *pvHaystack, uint8_t bNeedle, size_t cbHaystack));
     1643
    16251644
    16261645BS3_CMN_PROTO_STUB(void, Bs3UInt64Div,(RTUINT64U uDividend, RTUINT64U uDivisor, RTUINT64U BS3_FAR *paQuotientReminder));
     
    16471666
    16481667/**
     1668 * Wrapper around Bs3SelFar32ToFlat32 that makes it easier to use in tight
     1669 * assembly spots.
     1670 *
     1671 * @returns 32-bit flat address.
     1672 * @param   off             The segment offset.
     1673 * @param   uSel            The current mode segment selector.
     1674 * @remarks All register are preserved, except return.
     1675 * @remarks No 20h scratch space required in 64-bit mode.
     1676 */
     1677BS3_CMN_PROTO_FARSTUB(6, uint32_t, Bs3SelFar32ToFlat32NoClobber,(uint32_t off, uint16_t uSel));
     1678
     1679/**
    16491680 * Converts a real mode code segment to a protected mode code segment selector.
    16501681 *
    16511682 * @returns protected mode segment selector.
    16521683 * @param   uRealSeg        Real mode code segment.
     1684 * @remarks All register are preserved, except return and parameter.
    16531685 */
    16541686BS3_CMN_PROTO_NOSB(uint16_t, Bs3SelRealModeCodeToProtMode,(uint16_t uRealSeg));
     
    16591691 * @returns protected mode segment selector.
    16601692 * @param   uProtSel        Real mode code segment.
     1693 * @remarks All register are preserved, except return and parameter.
    16611694 */
    16621695BS3_CMN_PROTO_NOSB(uint16_t, Bs3SelProtModeCodeToRealMode,(uint16_t uProtSel));
     
    16651698 * Converts a flat code address to a real mode segment and offset.
    16661699 *
    1667  * @returns Far real mode address (high 16-bit is segment, low is offset)
     1700 * @returns Far real mode address (high 16-bit is segment, low is offset).
    16681701 * @param   uFlatAddr       Flat code address.
     1702 * @remarks All register are preserved, except return and parameter.
    16691703 */
    16701704BS3_CMN_PROTO_NOSB(uint32_t, Bs3SelFlatCodeToRealMode,(uint32_t uFlatAddr));
     
    16761710 *          low is segment offset).
    16771711 * @param   uFlatAddr       Flat code address.
     1712 * @remarks All register are preserved, except return and parameter.
    16781713 */
    16791714BS3_CMN_PROTO_NOSB(uint32_t, Bs3SelFlatCodeToProtFar16,(uint32_t uFlatAddr));
     1715
     1716/**
     1717 * Converts a flat data address to a real mode segment and offset.
     1718 *
     1719 * @returns Far real mode address (high 16-bit is segment, low is offset)
     1720 * @param   uFlatAddr       Flat code address.
     1721 * @remarks All register are preserved, except return.
     1722 * @remarks No 20h scratch space required in 64-bit mode.
     1723 */
     1724BS3_CMN_PROTO_FARSTUB(4, uint32_t, Bs3SelFlatDataToRealMode,(uint32_t uFlatAddr));
     1725
     1726/**
     1727 * Converts a flat data address to a real mode segment and offset.
     1728 *
     1729 * @returns Far 16-bit protected mode address (high 16-bit is segment selector,
     1730 *          low is segment offset).
     1731 * @param   uFlatAddr       Flat code address.
     1732 * @remarks All register are preserved, except return.
     1733 * @remarks No 20h scratch space required in 64-bit mode.
     1734 */
     1735BS3_CMN_PROTO_FARSTUB(4, uint32_t, Bs3SelFlatDataToProtFar16,(uint32_t uFlatAddr));
     1736
     1737/**
     1738 * Converts a far 16:16 data address to a real mode segment and offset.
     1739 *
     1740 * @returns Far real mode address (high 16-bit is segment, low is offset)
     1741 * @param   uFar1616        Far 16-bit protected mode address (high 16-bit is
     1742 *                          segment selector, low is segment offset).
     1743 * @remarks All register are preserved, except return.
     1744 * @remarks No 20h scratch space required in 64-bit mode.
     1745 */
     1746BS3_CMN_PROTO_FARSTUB(4, uint32_t, Bs3SelProtFar16DataToRealMode,(uint32_t uFar1616));
     1747
     1748/**
     1749 * Converts a far 16:16 real mode address to a 16-bit protected mode address.
     1750 *
     1751 * @returns Far real mode address (high 16-bit is segment, low is offset)
     1752 * @param   uFar1616        Far real mode address (high 16-bit is segment, low
     1753 *                          is offset).
     1754 * @remarks All register are preserved, except return.
     1755 * @remarks No 20h scratch space required in 64-bit mode.
     1756 */
     1757BS3_CMN_PROTO_FARSTUB(4, uint32_t, Bs3SelRealModeDataToProtFar16,(uint32_t uFar1616));
     1758
     1759/**
     1760 * Converts a far 16:16 data address to a flat 32-bit address.
     1761 *
     1762 * @returns 32-bit flat address.
     1763 * @param   uFar1616        Far 16-bit protected mode address (high 16-bit is
     1764 *                          segment selector, low is segment offset).
     1765 * @remarks All register are preserved, except return.
     1766 * @remarks No 20h scratch space required in 64-bit mode.
     1767 */
     1768BS3_CMN_PROTO_FARSTUB(4, uint32_t, Bs3SelProtFar16DataToFlat,(uint32_t uFar1616));
     1769
     1770/**
     1771 * Converts a far 16:16 real mode address to a flat address.
     1772 *
     1773 * @returns 32-bit flat address.
     1774 * @param   uFar1616        Far real mode address (high 16-bit is segment, low
     1775 *                          is offset).
     1776 * @remarks All register are preserved, except return.
     1777 * @remarks No 20h scratch space required in 64-bit mode.
     1778 */
     1779BS3_CMN_PROTO_FARSTUB(4, uint32_t, Bs3SelRealModeDataToFlat,(uint32_t uFar1616));
    16801780
    16811781/**
     
    20942194/** @name BS3REG_CTX_F_XXX - BS3REGCTX::fbFlags masks.
    20952195 * @{ */
    2096 /** The context doesn't have valid values for the CRx fields.
    2097  * This is usually because it wasn't created with CPL=0. */
    2098 #define BS3REG_CTX_F_NO_CR              UINT8_C(0x01)
    2099 /** The CPU is too old for CR4, so no CR4 in this context. */
    2100 #define BS3REG_CTX_F_NO_CR4             UINT8_C(0x02)
     2196/** The CR0 is MSW (only low 16-bit). */
     2197#define BS3REG_CTX_F_NO_CR0_IS_MSW      UINT8_C(0x01)
     2198/** No CR2 and CR3 values.  Not in CPL 0 or CPU too old for CR2 & CR3. */
     2199#define BS3REG_CTX_F_NO_CR2_CR3         UINT8_C(0x02)
     2200/** No CR4 value. The CPU is too old for CR4. */
     2201#define BS3REG_CTX_F_NO_CR4             UINT8_C(0x04)
     2202/** No TR and LDTR values.  Context gathered in real mode or v8086 mode. */
     2203#define BS3REG_CTX_F_NO_TR_LDTR         UINT8_C(0x08)
    21012204/** The context doesn't have valid values for AMD64 GPR extensions. */
    2102 #define BS3REG_CTX_F_NO_AMD64           UINT8_C(0x04)
     2205#define BS3REG_CTX_F_NO_AMD64           UINT8_C(0x10)
    21032206/** @} */
    21042207
     
    21092212 */
    21102213BS3_CMN_PROTO_NOSB(void, Bs3RegCtxSave,(PCBS3REGCTX pRegCtx));
     2214
     2215/**
     2216 * Switch to the specified CPU bitcount, reserve additional stack and save the
     2217 * CPU context.
     2218 *
     2219 * This is for writing more flexible test drivers that can test more than the
     2220 * CPU bitcount (16-bit, 32-bit, 64-bit, and virtual 8086) of the driver itself.
     2221 * For instance a 32-bit driver can do V86 and 16-bit testing, thus saving more
     2222 * precious and problematic 16-bit code.
     2223 *
     2224 * @param   pRegCtx         Where to store the register context.
     2225 * @param   bBitMode        Bit mode to switch to, BS3_MODE_CODE_XXX.  Only
     2226 *                          BS3_MODE_CODE_MASK is used, other bits are ignored
     2227 *                          to make it possible to pass a full mode value.
     2228 * @param   cbExtraStack    Number of bytes of additional stack to allocate.
     2229 */
     2230BS3_CMN_PROTO_FARSTUB(8, void, Bs3RegCtxSaveEx,(PCBS3REGCTX pRegCtx, uint8_t bBitMode, uint16_t cbExtraStack));
    21112231
    21122232/**
     
    23132433
    23142434/**
    2315  * Sets a trap handler (C/C++/assembly) for the current bitness.
     2435 * Sets a trap handler (C/C++/assembly) for the current bitcount.
    23162436 *
    23172437 * When using a 32-bit IDT, only #Bs3TrapSetHandler_c32 will have any effect.
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.mac

    r60609 r60657  
    272272;;
    273273; For instruction that should only be emitted in 16-bit mode. Follows BS3_SET_BITS.
    274 %macro BS3_ONLY_16BIT_STMT 1+
     274; BONLY16 normally goes in column 1.
     275%macro BONLY16 1+
    275276 %if __BITS__ == 16
    276277        %1
     
    280281;;
    281282; For instruction that should only be emitted in 32-bit mode. Follows BS3_SET_BITS.
    282 %macro BS3_ONLY_32BIT_STMT 1+
     283; BONLY32 normally goes in column 1.
     284%macro BONLY32 1+
    283285 %if __BITS__ == 32
    284286        %1
     
    288290;;
    289291; For instruction that should only be emitted in 64-bit mode. Follows BS3_SET_BITS.
    290 %macro BS3_ONLY_64BIT_STMT 1+
     292; BONLY64 normally goes in column 1.
     293%macro BONLY64 1+
    291294 %if __BITS__ == 64
    292295        %1
     
    14051408;; @name BS3REG_CTX_F_XXX - BS3REGCTX::fbFlags masks.
    14061409; @{
    1407 ;; The context doesn't have valid values for the CRx fields.
    1408 ;  This is usually because it wasn't created with CPL=0.
    1409 %define BS3REG_CTX_F_NO_CR              0x01
    1410 ;; The CPU is too old for CR4, so no CR4 in this context.
    1411 %define BS3REG_CTX_F_NO_CR4             0x02
     1410;; The CR0 is MSW (only low 16-bit). */
     1411%define BS3REG_CTX_F_NO_CR0_IS_MSW      0x01
     1412;; No CR2 and CR3 values.  Not in CPL 0 or CPU too old for CR2 & CR3.
     1413%define BS3REG_CTX_F_NO_CR2_CR3         0x02
     1414;; No CR4 value. The CPU is too old for CR4.
     1415%define BS3REG_CTX_F_NO_CR4             0x04
     1416;; No TR and LDTR values.  Context gathered in real mode or v8086 mode.
     1417%define BS3REG_CTX_F_NO_TR_LDTR         0x08
    14121418;; The context doesn't have valid values for AMD64 GPR extensions.
    1413 %define BS3REG_CTX_F_NO_AMD64           0x04
     1419%define BS3REG_CTX_F_NO_AMD64           0x10
    14141420;; @}
    14151421
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