VirtualBox

Ignore:
Timestamp:
Apr 1, 2016 8:51:29 PM (9 years ago)
Author:
vboxsync
Message:

bs3kit: A bunch of changes to be able to test the effects of a GDT page being read-only or not-present.

  • Extended the GDT so we get a whole page to play paging tricks with.
  • Added syscall for restoring a context from ring-0 so we can safely get out of bogus test context that aren't in ring-0 (non-standard CS value causing trouble here). Implemented the string print syscall since the restore syscall forced me to sort out pointers.
  • Changed most string printers to do more than one char at a time (usually a line) to save context switches (screen priting is done via INT 10h in real mode).
  • Test the CS access bit handling during INT XXh.
Location:
trunk/src/VBox/ValidationKit/bootsectors
Files:
1 added
23 edited

Legend:

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

    r60270 r60291  
    515515         segment BS3SYSTEM16 \
    516516         clname FAR_DATA \
    517           segment BS3DATA16 segaddr=0x2700 \
     517          segment BS3DATA16 segaddr=0x2900 \
    518518          segment BS3DATA16CONST \
    519519          segment BS3DATA16CONST2 \
  • trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-c.c

    r60232 r60291  
    3838BS3TESTMODE_PROTOTYPES_MODE(bs3CpuBasic2_RaiseXcpt1);
    3939//BS3TESTMODE_PROTOTYPES_CMN(bs3CpuBasic2_iret);
    40 //BS3TESTMODE_PROTOTYPES_MODE(bs3CpuBasic2_iret);
     40BS3TESTMODE_PROTOTYPES_MODE(bs3CpuBasic2_iret);
    4141
    4242
  • trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.c

    r60233 r60291  
    207207    unsigned        uLine;
    208208# if TMPL_BITS != 16
     209    int             rc;
    209210    uint8_t        *pbIdtCopyAlloc;
    210211    PX86DESC        pIdtCopy;
    211212    const unsigned  cbIdte = 1 << (3 + cIdteShift);
     213    RTCCUINTXREG    uCr0Saved = ASMGetCR0();
     214    RTGDTR          GdtrSaved;
    212215# endif
    213216    RTIDTR          IdtrSaved;
     
    215218
    216219    ASMGetIDTR(&IdtrSaved);
     220# if TMPL_BITS != 16
     221    ASMGetGDTR(&GdtrSaved);
     222# endif
    217223
    218224    /* make sure they're allocated  */
     
    481487            bs3CpuBasic2_CompareIntCtx1(&TrapCtx, &Ctx80, 0x80 /*bXcpt*/, pszMode, uLine++);
    482488
    483             i = Bs3PagingProtect(uCr2Expected, _4K, 0 /*fSet*/, X86_PTE_P /*fClear*/);
    484             if (RT_SUCCESS(i))
     489            rc = Bs3PagingProtect(uCr2Expected, _4K, 0 /*fSet*/, X86_PTE_P /*fClear*/);
     490            if (RT_SUCCESS(rc))
    485491            {
    486492                ASMSetIDTR(&Idtr);
     
    496502                /* Check if that the entry type is checked after the whole IDTE has been cleared for #PF. */
    497503                pIdtCopy[0x80 << cIdteShift].Gate.u4Type = 0;
    498                 i = Bs3PagingProtect(uCr2Expected, _4K, 0 /*fSet*/, X86_PTE_P /*fClear*/);
    499                 if (RT_SUCCESS(i))
     504                rc = Bs3PagingProtect(uCr2Expected, _4K, 0 /*fSet*/, X86_PTE_P /*fClear*/);
     505                if (RT_SUCCESS(rc))
    500506                {
    501507                    ASMSetIDTR(&Idtr);
     
    527533        bs3CpuBasic2_CompareIntCtx1(&TrapCtx, &Ctx81, 0x81 /*bXcpt*/, pszMode, uLine++);
    528534
    529         i = Bs3PagingProtect(Idtr.pIdt, _4K, 0 /*fSet*/, X86_PTE_RW | X86_PTE_US /*fClear*/);
    530         if (RT_SUCCESS(i))
     535        rc = Bs3PagingProtect(Idtr.pIdt, _4K, 0 /*fSet*/, X86_PTE_RW | X86_PTE_US /*fClear*/);
     536        if (RT_SUCCESS(rc))
    531537        {
    532538            ASMSetIDTR(&Idtr);
     
    537543        }
    538544        ASMSetIDTR(&IdtrSaved);
     545    }
     546
     547    /*
     548     * Check that CS.u1Accessed is set to 1. Use the test page selector #0 and #3 together
     549     * with interrupt gates 80h and 83h, respectively.
     550     */
     551    uLine = 5400;
     552    if (BS3_MODE_IS_PAGED(bMode) && pbIdtCopyAlloc)
     553    {
     554        BS3_DATA_NM(Bs3GdteTestPage00) = BS3_DATA_NM(Bs3Gdt)[uSysR0Cs >> X86_SEL_SHIFT];
     555        BS3_DATA_NM(Bs3GdteTestPage00).Gen.u4Type &= ~X86_SEL_TYPE_ACCESSED;
     556        paIdt[0x80 << cIdteShift].Gate.u16Sel   = BS3_SEL_TEST_PAGE_00;
     557
     558        BS3_DATA_NM(Bs3GdteTestPage03) = BS3_DATA_NM(Bs3Gdt)[(uSysR0Cs + (3 << BS3_SEL_RING_SHIFT)) >> X86_SEL_SHIFT];
     559        BS3_DATA_NM(Bs3GdteTestPage03).Gen.u4Type &= ~X86_SEL_TYPE_ACCESSED;
     560        paIdt[0x83 << cIdteShift].Gate.u16Sel   = BS3_SEL_TEST_PAGE_03; /* rpl is ignored, so leave it as zero. */
     561
     562        /* Check that the CS.A bit is being set on a general basis and that
     563           the special CS values work with out generic handler code. */
     564        Bs3TrapSetJmpAndRestore(&Ctx80, &TrapCtx);
     565        bs3CpuBasic2_CompareIntCtx1(&TrapCtx, &Ctx80, 0x80 /*bXcpt*/, pszMode, uLine);
     566        if (!(BS3_DATA_NM(Bs3GdteTestPage00).Gen.u4Type & X86_SEL_TYPE_ACCESSED))
     567            Bs3TestFailedF("%u - %s: u4Type=%#x, not accessed\n", uLine, pszMode, BS3_DATA_NM(Bs3GdteTestPage00).Gen.u4Type);
     568        uLine++;
     569
     570        Bs3MemCpy(&CtxTmp, &Ctx83, sizeof(CtxTmp));
     571        Bs3RegCtxConvertToRingX(&CtxTmp, 3);
     572        Bs3TrapSetJmpAndRestore(&CtxTmp, &TrapCtx);
     573        bs3CpuBasic2_CompareIntCtx1(&TrapCtx, &CtxTmp, 0x83 /*bXcpt*/, pszMode, uLine);
     574        if (!(BS3_DATA_NM(Bs3GdteTestPage03).Gen.u4Type & X86_SEL_TYPE_ACCESSED))
     575            Bs3TestFailedF("%u - %s: u4Type=%#x, not accessed!\n", uLine, pszMode, BS3_DATA_NM(Bs3GdteTestPage00).Gen.u4Type);
     576        uLine++;
     577
     578        /*
     579         * Now check that setting CS.u1Access to 1 does __NOT__ trigger a page
     580         * fault due to the RW bit being zero.
     581         * (We check both with with and without the WP bit if 80486.)
     582         */
     583        if ((BS3_DATA_NM(g_uBs3CpuDetected) & BS3CPU_TYPE_MASK) >= BS3CPU_80486)
     584            ASMSetCR0(uCr0Saved | X86_CR0_WP);
     585
     586        BS3_DATA_NM(Bs3GdteTestPage00).Gen.u4Type &= ~X86_SEL_TYPE_ACCESSED;
     587        BS3_DATA_NM(Bs3GdteTestPage03).Gen.u4Type &= ~X86_SEL_TYPE_ACCESSED;
     588        rc = Bs3PagingProtect(GdtrSaved.pGdt + BS3_SEL_TEST_PAGE_00, 8, 0 /*fSet*/, X86_PTE_RW /*fClear*/);
     589        if (RT_SUCCESS(rc))
     590        {
     591            /* ring-0 handler */
     592            Bs3TrapSetJmpAndRestore(&Ctx80, &TrapCtx);
     593            bs3CpuBasic2_CompareIntCtx1(&TrapCtx, &Ctx80, 0x80 /*bXcpt*/, pszMode, uLine);
     594            if (!(BS3_DATA_NM(Bs3GdteTestPage00).Gen.u4Type & X86_SEL_TYPE_ACCESSED))
     595                Bs3TestFailedF("%u - %s: u4Type=%#x, not accessed!\n", uLine, pszMode, BS3_DATA_NM(Bs3GdteTestPage00).Gen.u4Type);
     596            uLine++;
     597
     598            /* ring-3 handler */
     599            Bs3MemCpy(&CtxTmp, &Ctx83, sizeof(CtxTmp));
     600            Bs3RegCtxConvertToRingX(&CtxTmp, 3);
     601            Bs3TrapSetJmpAndRestore(&CtxTmp, &TrapCtx);
     602            bs3CpuBasic2_CompareIntCtx1(&TrapCtx, &CtxTmp, 0x83 /*bXcpt*/, pszMode, uLine);
     603            if (!(BS3_DATA_NM(Bs3GdteTestPage03).Gen.u4Type & X86_SEL_TYPE_ACCESSED))
     604                Bs3TestFailedF("%u - %s: u4Type=%#x, not accessed!\n", uLine, pszMode, BS3_DATA_NM(Bs3GdteTestPage00).Gen.u4Type);
     605            uLine++;
     606
     607            /* clear WP and repeat the above. */
     608            if ((BS3_DATA_NM(g_uBs3CpuDetected) & BS3CPU_TYPE_MASK) >= BS3CPU_80486)
     609                ASMSetCR0(uCr0Saved & ~X86_CR0_WP);
     610            BS3_DATA_NM(Bs3GdteTestPage00).Gen.u4Type &= ~X86_SEL_TYPE_ACCESSED; /* (No need to RW the page - ring-0, WP=0.) */
     611            BS3_DATA_NM(Bs3GdteTestPage03).Gen.u4Type &= ~X86_SEL_TYPE_ACCESSED; /* (No need to RW the page - ring-0, WP=0.) */
     612
     613            Bs3TrapSetJmpAndRestore(&Ctx80, &TrapCtx);
     614            bs3CpuBasic2_CompareIntCtx1(&TrapCtx, &Ctx80, 0x80 /*bXcpt*/, pszMode, uLine);
     615            if (!(BS3_DATA_NM(Bs3GdteTestPage00).Gen.u4Type & X86_SEL_TYPE_ACCESSED))
     616                Bs3TestFailedF("%u - %s: u4Type=%#x, not accessed!\n", uLine, pszMode, BS3_DATA_NM(Bs3GdteTestPage00).Gen.u4Type);
     617            uLine++;
     618
     619            Bs3TrapSetJmpAndRestore(&CtxTmp, &TrapCtx);
     620            bs3CpuBasic2_CompareIntCtx1(&TrapCtx, &CtxTmp, 0x83 /*bXcpt*/, pszMode, uLine);
     621            if (!(BS3_DATA_NM(Bs3GdteTestPage03).Gen.u4Type & X86_SEL_TYPE_ACCESSED))
     622                Bs3TestFailedF("%u - %s: u4Type=%#x, not accessed!\n", uLine, pszMode, BS3_DATA_NM(Bs3GdteTestPage03).Gen.u4Type);
     623            uLine++;
     624
     625            Bs3PagingProtect(GdtrSaved.pGdt + BS3_SEL_TEST_PAGE_00, 8, X86_PTE_RW /*fSet*/, 0 /*fClear*/);
     626        }
     627
     628        ASMSetCR0(uCr0Saved);
     629
     630        /*
     631         * While we're here, check that if the CS GDT entry is a non-present
     632         * page we do get a #PF with the rigth error code and CR2.
     633         */
     634        BS3_DATA_NM(Bs3GdteTestPage00).Gen.u4Type &= ~X86_SEL_TYPE_ACCESSED; /* Just for fun, really a pointless gesture. */
     635        BS3_DATA_NM(Bs3GdteTestPage03).Gen.u4Type &= ~X86_SEL_TYPE_ACCESSED;
     636        rc = Bs3PagingProtect(GdtrSaved.pGdt + BS3_SEL_TEST_PAGE_00, 8, 0 /*fSet*/, X86_PTE_P /*fClear*/);
     637        if (RT_SUCCESS(rc))
     638        {
     639            Bs3TrapSetJmpAndRestore(&Ctx80, &TrapCtx);
     640            bs3CpuBasic2_ComparePfCtx(&TrapCtx, &Ctx80, 0 /*uErrCd*/, GdtrSaved.pGdt + BS3_SEL_TEST_PAGE_00,
     641                                      f16BitSys, pszMode, uLine);
     642            uLine++;
     643
     644            /* Do it from ring-3 to check ErrCd, which doesn't set X86_TRAP_PF_US it turns out. */
     645            Bs3MemCpy(&CtxTmp, &Ctx83, sizeof(CtxTmp));
     646            Bs3RegCtxConvertToRingX(&CtxTmp, 3);
     647            Bs3TrapSetJmpAndRestore(&CtxTmp, &TrapCtx);
     648
     649            bs3CpuBasic2_ComparePfCtx(&TrapCtx, &CtxTmp, 0 /*uErrCd*/, GdtrSaved.pGdt + BS3_SEL_TEST_PAGE_03,
     650                                      f16BitSys, pszMode, uLine);
     651            uLine++;
     652
     653            Bs3PagingProtect(GdtrSaved.pGdt + BS3_SEL_TEST_PAGE_00, 8, X86_PTE_P /*fSet*/, 0 /*fClear*/);
     654            if (BS3_DATA_NM(Bs3GdteTestPage00).Gen.u4Type & X86_SEL_TYPE_ACCESSED)
     655                Bs3TestFailedF("%u - %s: u4Type=%#x, accessed!\n", uLine - 2, pszMode, BS3_DATA_NM(Bs3GdteTestPage00).Gen.u4Type);
     656            if (BS3_DATA_NM(Bs3GdteTestPage03).Gen.u4Type & X86_SEL_TYPE_ACCESSED)
     657                Bs3TestFailedF("%u - %s: u4Type=%#x, accessed!\n", uLine - 1, pszMode, BS3_DATA_NM(Bs3GdteTestPage03).Gen.u4Type);
     658        }
     659
     660        /* restore */
     661        paIdt[0x80 << cIdteShift].Gate.u16Sel = uSysR0Cs;
     662        paIdt[0x83 << cIdteShift].Gate.u16Sel = uSysR0Cs + (3 << BS3_SEL_RING_SHIFT) + 3;
    539663    }
    540664
     
    614738     *  - Run \#PF and \#GP (and others?) at CPLs other than zero.
    615739     *  - Quickly generate all faults.
    616      *  - Check that CS.u1Accessed is set to 1.
    617      *  - Check that setting CS.u1Access to 1 triggers page fault.
    618740     *  - Check CS.u1Access = 1 \#PF against \#NP(CS), CS.u2DPL, \#NP(SS),
    619741     *    SS.u2DPL, and SS.u1Access=1 \#PF.
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk

    r60234 r60291  
    6464        bs3-cmn-PrintX32.asm \
    6565        bs3-cmn-PrintStr.c \
     66        bs3-cmn-PrintStrN.asm \
    6667       bs3-cmn-PrintStrColonSpaces.asm \
    6768       bs3-cmn-PrintStrSpacesColonSpace.c \
     
    197198       ../../../Runtime/common/asm/ASMGetIDTR.asm \
    198199       ../../../Runtime/common/asm/ASMSetIDTR.asm \
     200       ../../../Runtime/common/asm/ASMGetGDTR.asm \
     201       ../../../Runtime/common/asm/ASMSetGDTR.asm \
    199202
    200203
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-PrintStr.c

    r58675 r60291  
    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
     
    2727#include "bs3kit-template-header.h"
    2828
    29 #undef Bs3PrintStr
    30 BS3_DECL(void) BS3_CMN_NM(Bs3PrintStr)(const char BS3_FAR *pszString)
     29BS3_DECL(void) Bs3PrintStr(const char BS3_FAR *pszString)
    3130{
    32     char ch;
    33     while ((ch = *pszString++) != '\0')
    34         Bs3PrintChr(ch);
     31    Bs3PrintStrN(pszString, Bs3StrLen(pszString));
    3532}
    3633
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-Printf.c

    r58812 r60291  
    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
     
    2525 */
    2626
     27
     28/*********************************************************************************************************************************
     29*   Header Files                                                                                                                 *
     30*********************************************************************************************************************************/
    2731#include "bs3kit-template-header.h"
    2832#include <iprt/ctype.h>
    2933
    3034
     35/*********************************************************************************************************************************
     36*   Structures and Typedefs                                                                                                      *
     37*********************************************************************************************************************************/
     38/** Output buffering for Bs3TestPrintfV. */
     39typedef struct BS3PRINTBUF
     40{
     41    uint8_t cchBuf;
     42    char    achBuf[79];
     43} BS3PRINTBUF;
     44
     45
    3146static BS3_DECL_CALLBACK(size_t) bs3PrintFmtOutput(char ch, void BS3_FAR *pvUser)
    3247{
     48    BS3PRINTBUF BS3_FAR *pBuf = (BS3PRINTBUF BS3_FAR *)pvUser;
    3349    if (ch != '\0')
    3450    {
    35         if (ch == '\n')
    36             Bs3PrintChr('\r');
    37         Bs3PrintChr(ch);
    38         return 1;
     51        BS3_ASSERT(pBuf->cchBuf < RT_ELEMENTS(pBuf->achBuf));
     52        pBuf->achBuf[pBuf->cchBuf++] = ch;
     53
     54        /* Whether to flush the buffer.  We do line flushing here to avoid
     55           dropping too much info when the formatter crashes on bad input. */
     56        if (   pBuf->cchBuf < RT_ELEMENTS(pBuf->achBuf)
     57            && ch != '\n')
     58            return 1;
    3959    }
    40     NOREF(pvUser);
    41     return 0;
     60    Bs3PrintStrN(&pBuf->achBuf[0], pBuf->cchBuf);
     61    pBuf->cchBuf = 0;
     62    return ch != '\0';
    4263}
    4364
     
    4566BS3_DECL(size_t) Bs3PrintfV(const char BS3_FAR *pszFormat, va_list va)
    4667{
    47     return Bs3StrFormatV(pszFormat, va, bs3PrintFmtOutput, NULL);
     68    BS3PRINTBUF Buf;
     69    Buf.cchBuf = 0;
     70    return Bs3StrFormatV(pszFormat, va, bs3PrintFmtOutput, &Buf);
    4871}
    4972
     
    5477    va_list va;
    5578    va_start(va, pszFormat);
    56     cchRet = Bs3StrFormatV(pszFormat, va, bs3PrintFmtOutput, NULL);
     79    cchRet = Bs3PrintfV(pszFormat, va);
    5780    va_end(va);
    5881    return cchRet;
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-RegCtxConvertToRingX.c

    r60119 r60291  
    7373 * @param   uSeg            The current selector value.
    7474 * @param   bRing           The target ring.
     75 * @param   iReg            Register index.
    7576 */
    76 static uint16_t bs3RegCtxConvertProtSelToRingX(uint16_t uSel, uint8_t bRing)
     77static uint16_t bs3RegCtxConvertProtSelToRingX(uint16_t uSel, uint8_t bRing, uint8_t iReg)
    7778{
    7879    if (   uSel > X86_SEL_RPL
    7980        && !(uSel & X86_SEL_LDT) )
    8081    {
    81         if (uSel >= BS3_SEL_R0_FIRST)
     82        if (uSel >= BS3_SEL_R0_FIRST && uSel < BS3_SEL_R0_FIRST + (5 << BS3_SEL_RING_SHIFT))
    8283        {
    8384            /* Convert BS3_SEL_R*_XXX to the target ring. */
     
    9596            else if (uSelRaw == BS3_SEL_DATA16)
    9697                uSel = (BS3_SEL_R0_DS16 | bRing) + ((uint16_t)bRing << BS3_SEL_RING_SHIFT);
     98            /* CS and SS must have CPL == DPL.  So, convert to standard selectors as we're
     99               usually here because Bs3SwitchToRing0 was called to get out of a test situation. */
     100            else if (iReg == X86_SREG_CS || iReg == X86_SREG_SS)
     101            {
     102                if (   BS3_DATA_NM(Bs3Gdt)[uSel >> X86_SEL_SHIFT].Gen.u1Long
     103                    && BS3_MODE_IS_64BIT_SYS(BS3_DATA_NM(g_bBs3CurrentMode)) )
     104                    uSel = iReg == X86_SREG_CS ? BS3_SEL_R0_CS64 : BS3_SEL_R0_DS64;
     105                else
     106                {
     107                    uint32_t uFlat   = Bs3SelFar32ToFlat32(0, uSel);
     108                    bool     fDefBig = BS3_DATA_NM(Bs3Gdt)[uSel >> X86_SEL_SHIFT].Gen.u1DefBig;
     109                    if (!fDefBig && uFlat == BS3_ADDR_BS3TEXT16 && iReg == X86_SREG_CS)
     110                        uSel = BS3_SEL_R0_CS16;
     111                    else if (!fDefBig && uFlat == 0 && iReg == X86_SREG_SS)
     112                        uSel = BS3_SEL_R0_SS16;
     113                    else if (fDefBig && uFlat == 0)
     114                        uSel = iReg == X86_SREG_CS ? BS3_SEL_R0_CS32 : BS3_SEL_R0_SS32;
     115                    else
     116                    {
     117                        Bs3Printf("uSel=%#x iReg=%d\n", uSel, iReg);
     118                        BS3_ASSERT(0);
     119                        return uSel;
     120                    }
     121                    uSel |= bRing;
     122                    uSel += (uint16_t)bRing << BS3_SEL_RING_SHIFT;
     123                }
     124            }
    97125            /* Adjust the RPL on tiled and MMIO selectors. */
    98126            else if (   uSelRaw == BS3_SEL_VMMDEV_MMIO16
     
    128156    else
    129157    {
    130         pRegCtx->cs = bs3RegCtxConvertProtSelToRingX(pRegCtx->cs, bRing);
    131         pRegCtx->ss = bs3RegCtxConvertProtSelToRingX(pRegCtx->ss, bRing);
    132         pRegCtx->ds = bs3RegCtxConvertProtSelToRingX(pRegCtx->ds, bRing);
    133         pRegCtx->es = bs3RegCtxConvertProtSelToRingX(pRegCtx->es, bRing);
    134         pRegCtx->fs = bs3RegCtxConvertProtSelToRingX(pRegCtx->fs, bRing);
    135         pRegCtx->gs = bs3RegCtxConvertProtSelToRingX(pRegCtx->gs, bRing);
     158        pRegCtx->cs = bs3RegCtxConvertProtSelToRingX(pRegCtx->cs, bRing, X86_SREG_CS);
     159        pRegCtx->ss = bs3RegCtxConvertProtSelToRingX(pRegCtx->ss, bRing, X86_SREG_SS);
     160        pRegCtx->ds = bs3RegCtxConvertProtSelToRingX(pRegCtx->ds, bRing, X86_SREG_DS);
     161        pRegCtx->es = bs3RegCtxConvertProtSelToRingX(pRegCtx->es, bRing, X86_SREG_ES);
     162        pRegCtx->fs = bs3RegCtxConvertProtSelToRingX(pRegCtx->fs, bRing, X86_SREG_FS);
     163        pRegCtx->gs = bs3RegCtxConvertProtSelToRingX(pRegCtx->gs, bRing, X86_SREG_GS);
    136164    }
    137165    pRegCtx->bCpl = bRing;
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-RegCtxRestore.asm

    r60199 r60291  
    3434%endif
    3535TMPL_BEGIN_TEXT
    36 BS3_EXTERN_CMN Bs3SwitchToRing0
     36BS3_EXTERN_CMN Bs3Syscall
    3737TMPL_BEGIN_TEXT
    3838
     
    5858BS3_PROC_BEGIN_CMN Bs3RegCtxRestore
    5959        BS3_CALL_CONV_PROLOG 2
    60 
    61         ;
    62         ; Make sure we're in ring-0 when we do this job.
     60        push    xBP
     61        mov     xBP, xSP
     62
     63        ;
     64        ; If we're not in ring-0, ask the kernel to restore it for us (quicker
     65        ; and less problematic if we're in a funny context right now with weird
     66        ; CS or SS values).
    6367        ;
    6468        mov     ax, ss
    6569        test    al, 3
    6670        jz      .in_ring0
    67         call    Bs3SwitchToRing0
     71%if TMPL_BITS == 16
     72        mov     si, [bp + 4]
     73        mov     cx, [bp + 4+2]
     74        mov     dx, [bp + 8]
     75        mov     ax, BS3_SYSCALL_RESTORE_CTX
     76%else
     77        mov     cx, ds
     78        mov     xSI, [xBP + xCB*2]
     79        movzx   edx, word [xBP + xCB*3]
     80        mov     eax, BS3_SYSCALL_RESTORE_CTX
     81%endif
     82        call    Bs3Syscall
    6883.in_ring0:
    6984
     
    7287        ; g_uBs3CpuDetected), DS:xBX with pRegCtx and fFlags into xCX.
    7388        ;
    74         push    xBP
    75         mov     xBP, xSP
    7689%if TMPL_BITS == 16
    7790        mov     ax, BS3DATA16
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-TestPrintf.c

    r60097 r60291  
    3535
    3636
     37/*********************************************************************************************************************************
     38*   Structures and Typedefs                                                                                                      *
     39*********************************************************************************************************************************/
     40/** Output buffering for Bs3TestPrintfV. */
     41typedef struct BS3TESTPRINTBUF
     42{
     43    bool    fNewCmd;
     44    uint8_t cchBuf;
     45    char    achBuf[78];
     46} BS3TESTPRINTBUF;
     47
     48
    3749/**
    3850 * @impl_callback_method{FNBS3STRFORMATOUTPUT, Prints to screen and VMMDev}
     
    4052static BS3_DECL_CALLBACK(size_t) bs3TestPrintfStrOutput(char ch, void BS3_FAR *pvUser)
    4153{
     54    BS3TESTPRINTBUF BS3_FAR *pBuf = (BS3TESTPRINTBUF BS3_FAR *)pvUser;
     55
    4256    /*
    4357     * VMMDev first.  We do line by line processing to avoid running out of
     
    4660    if (BS3_DATA_NM(g_fbBs3VMMDevTesting))
    4761    {
    48         bool *pfNewCmd = (bool *)pvUser;
    49         if (ch != '\n' && !*pfNewCmd)
     62        if (ch != '\n' && !pBuf->fNewCmd)
    5063            ASMOutU8(VMMDEV_TESTING_IOPORT_DATA, ch);
    5164        else if (ch != '\0')
    5265        {
    53             if (*pfNewCmd)
     66            if (pBuf->fNewCmd)
    5467            {
    5568                ASMOutU32(VMMDEV_TESTING_IOPORT_CMD, VMMDEV_TESTING_CMD_PRINT);
    56                 *pfNewCmd = false;
     69                pBuf->fNewCmd = false;
    5770            }
    5871            ASMOutU8(VMMDEV_TESTING_IOPORT_DATA, ch);
     
    6073            {
    6174                ASMOutU8(VMMDEV_TESTING_IOPORT_DATA, '\0');
    62                 *pfNewCmd = true;
     75                pBuf->fNewCmd = true;
    6376            }
    6477        }
     
    6982     */
    7083    if (ch != '\0')
    71         Bs3PrintChr(ch);
    72     return 1;
     84    {
     85        BS3_ASSERT(pBuf->cchBuf < RT_ELEMENTS(pBuf->achBuf));
     86        pBuf->achBuf[pBuf->cchBuf++] = ch;
     87
     88        /* Whether to flush the buffer.  We do line flushing here to avoid
     89           dropping too much info when the formatter crashes on bad input. */
     90        if (   pBuf->cchBuf < RT_ELEMENTS(pBuf->achBuf)
     91            && ch != '\n')
     92            return 1;
     93    }
     94    BS3_ASSERT(pBuf->cchBuf <= RT_ELEMENTS(pBuf->achBuf));
     95    Bs3PrintStrN(&pBuf->achBuf[0], pBuf->cchBuf);
     96    pBuf->cchBuf = 0;
     97    return ch != '\0';
    7398}
    7499
     
    77102BS3_DECL(void) Bs3TestPrintfV(const char BS3_FAR *pszFormat, va_list va)
    78103{
    79     bool fNewCmd = true;
    80     Bs3StrFormatV(pszFormat, va, bs3TestPrintfStrOutput, &fNewCmd);
     104    BS3TESTPRINTBUF Buf;
     105    Buf.fNewCmd = true;
     106    Buf.cchBuf  = 0;
     107    Bs3StrFormatV(pszFormat, va, bs3TestPrintfStrOutput, &Buf);
    81108}
    82109
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-TrapDefaultHandler.c

    r60088 r60291  
    4747    if (pTrapFrame->Ctx.rax.u16 == BS3_SYSCALL_PRINT_CHR)
    4848        Bs3PrintChr(pTrapFrame->Ctx.rcx.u8);
     49    else if (pTrapFrame->Ctx.rax.u16 == BS3_SYSCALL_PRINT_STR)
     50        Bs3PrintStrN(Bs3XptrFlatToCurrent((pTrapFrame->Ctx.rcx.u16 << 4) + pTrapFrame->Ctx.rsi.u16), pTrapFrame->Ctx.rdx.u16);
     51    else if (pTrapFrame->Ctx.rax.u16 == BS3_SYSCALL_RESTORE_CTX)
     52        Bs3RegCtxRestore(Bs3XptrFlatToCurrent((pTrapFrame->Ctx.rcx.u16 << 4) + pTrapFrame->Ctx.rsi.u16), pTrapFrame->Ctx.rdx.u16);
    4953    else if (   pTrapFrame->Ctx.rax.u16 == BS3_SYSCALL_TO_RING0
    5054             || pTrapFrame->Ctx.rax.u16 == BS3_SYSCALL_TO_RING1
     
    180184        //Bs3Printf("Calling longjmp: pSetJmpFrame=%p (%#lx)\n", pSetJmpFrame, g_pBs3TrapSetJmpFrame);
    181185        g_pBs3TrapSetJmpFrame = 0;
    182 
    183186        Bs3MemCpy(pSetJmpFrame, pTrapFrame, sizeof(*pSetJmpFrame));
    184187        //Bs3RegCtxPrint(&g_Bs3TrapSetJmpCtx);
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-TrapSetJmpAndRestore.c

    r60119 r60291  
    3434{
    3535    if (Bs3TrapSetJmp(pTrapFrame))
     36    {
     37#if TMPL_BITS == 32
     38        BS3_DATA_NM(g_uBs3TrapEipHint) = pCtxRestore->rip.u32;
     39#endif
    3640        Bs3RegCtxRestore(pCtxRestore, 0);
     41    }
    3742}
    3843
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-PagingGetRootForLM64.asm

    r60019 r60291  
    5555        cmp     eax, 0ffffffffh
    5656        je      .init_root
     57%ifdef BS3_STRICT
     58.return:
     59        cmp     eax, 1000h
     60        jnb     .cr3_ok_low
     61        hlt
     62.cr3_ok_low:
     63        cmp     eax, 16*_1M
     64        jb     .cr3_ok_high
     65        hlt
     66.cr3_ok_high:
     67%endif
    5768        ret
    5869
     
    112123        BS3_ONLY_16BIT_STMT pop     es
    113124        leave
     125%ifdef BS3_STRICT
     126        jmp     .return
     127%else
    114128        ret
     129%endif
    115130BS3_PROC_END_MODE   Bs3PagingGetRootForLM64
    116131
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-PagingGetRootForPP32.asm

    r60019 r60291  
    5555        cmp     eax, 0ffffffffh
    5656        je      .init_root
     57%ifdef BS3_STRICT
     58.return:
     59        cmp     eax, 1000h
     60        jnb     .cr3_ok_low
     61        hlt
     62.cr3_ok_low:
     63        cmp     eax, 16*_1M
     64        jb     .cr3_ok_high
     65        hlt
     66.cr3_ok_high:
     67%endif
    5768        ret
    5869
     
    113124        BS3_ONLY_16BIT_STMT pop     es
    114125        leave
     126%ifdef BS3_STRICT
     127        jmp     .return
     128%else
    115129        ret
     130%endif
    116131BS3_PROC_END_MODE   Bs3PagingGetRootForPP32
    117132
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToLM16.asm

    r59946 r60291  
    4343BS3_PROC_BEGIN_MODE Bs3SwitchToLM16
    4444%ifdef TMPL_LM16
     45        extern  BS3_CMN_NM(Bs3SwitchToRing0)
     46        call    BS3_CMN_NM(Bs3SwitchToRing0)
     47        push    ax
     48        mov     ax, BS3_SEL_R0_DS16
     49        mov     ds, ax
     50        mov     es, ax
     51        pop     ax
    4552        ret
    4653
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPAE16.asm

    r59950 r60291  
    4949BS3_PROC_BEGIN_MODE Bs3SwitchToPAE16
    5050%ifdef TMPL_PAE16
     51        extern  BS3_CMN_NM(Bs3SwitchToRing0)
     52        call    BS3_CMN_NM(Bs3SwitchToRing0)
     53        push    ax
     54        mov     ax, BS3_SEL_R0_DS16
     55        mov     ds, ax
     56        mov     es, ax
     57        pop     ax
    5158        ret
    5259
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE16.asm

    r59950 r60291  
    4242BS3_PROC_BEGIN_MODE Bs3SwitchToPE16
    4343%ifdef TMPL_PE16
     44        extern  BS3_CMN_NM(Bs3SwitchToRing0)
     45        call    BS3_CMN_NM(Bs3SwitchToRing0)
     46        push    ax
     47        mov     ax, BS3_SEL_R0_DS16
     48        mov     ds, ax
     49        mov     es, ax
     50        pop     ax
    4451        ret
    4552
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPP16.asm

    r59950 r60291  
    4949BS3_PROC_BEGIN_MODE Bs3SwitchToPP16
    5050%ifdef TMPL_PP16
     51        extern  BS3_CMN_NM(Bs3SwitchToRing0)
     52        call    BS3_CMN_NM(Bs3SwitchToRing0)
     53        push    ax
     54        mov     ax, BS3_SEL_R0_DS16
     55        mov     ds, ax
     56        mov     es, ax
     57        pop     ax
    5158        ret
    5259
     
    97104        push    ecx
    98105        pushfd
     106%ifdef BS3_STRICT
     107        mov     ax, ds
     108        cmp     ax, BS3_ADDR_BS3DATA16 >> 4
     109        je      .real_mode_ds_ok
     110        hlt
     111.real_mode_ds_ok:
     112%endif
    99113
    100114        ;
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToRM.asm

    r60019 r60291  
    5353BS3_PROC_BEGIN_MODE Bs3SwitchToRM
    5454%ifdef TMPL_RM
     55        push    ax
     56        mov     ax, BS3_SEL_DATA16
     57        mov     ds, ax
     58        mov     es, ax
     59        pop     ax
    5560        ret
    5661
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TrapSystemCallHandler.asm

    r60218 r60291  
    4141TMPL_BEGIN_TEXT
    4242
    43 %if TMPL_BITS == 32
    4443BS3_EXTERN_CMN Bs3SelProtFar32ToFlat32
    45 %endif
    4644BS3_EXTERN_CMN Bs3RegCtxConvertToRingX
    4745BS3_EXTERN_CMN Bs3RegCtxRestore
    4846BS3_EXTERN_CMN Bs3Panic
     47
     48BS3_BEGIN_TEXT16
     49extern Bs3PrintStrN_c16_CX_Bytes_At_DS_SI
    4950TMPL_BEGIN_TEXT
    5051
     
    7374 %define VAR_CALLER_DS     [xBP         - xCB]
    7475%endif
    75 %define VAR_CALLER_BX      [xBP - sCB*1 - xCB]
     76%define VAR_CALLER_BX      [xBP - sCB*1 - xCB] ; Note! the upper word is not clean on pre-386 (16-bit mode).
    7677%define VAR_CALLER_AX      [xBP - sCB*2 - xCB]
    7778%define VAR_CALLER_CX      [xBP - sCB*3 - xCB]
    7879%define VAR_CALLER_DX      [xBP - sCB*4 - xCB]
    7980%define VAR_CALLER_SI      [xBP - sCB*5 - xCB]
     81%define VAR_CALLER_SI_HI   [xBP - sCB*5 - xCB + 2]
    8082%define VAR_CALLER_DI      [xBP - sCB*6 - xCB]
     83%define VAR_CALLER_DI_HI   [xBP - sCB*6 - xCB + 2]
    8184%if TMPL_BITS == 16
    8285 %define VAR_CALLER_EBP    [xBP - sCB*7 - xCB]
     
    8487 %define VAR_CALLER_EFLAGS [xBP - sCB*9 - xCB]
    8588 %define VAR_CALLER_MODE   [xBP - sCB*9 - xCB*2]
     89 %define BP_TOP_STACK_EXPR xBP - sCB*9 - xCB*2
    8690%else
    8791 %define VAR_CALLER_MODE   [xBP - sCB*6 - xCB*2]
     92 %define BP_TOP_STACK_EXPR xBP - sCB*6 - xCB*2
    8893%endif
    8994        push    xBP
     
    122127        push    bx                      ; dummy
    123128        push    bx
    124         push    ax                      ; dummy
     129        xor     bx, bx
     130        push    bx                      ; dummy
    125131        push    ax
    126         push    cx                      ; dummy
     132        push    bx                      ; dummy
    127133        push    cx
    128         push    dx                      ; dummy
     134        push    bx                      ; dummy
    129135        push    dx
    130         push    si                      ; dummy
     136        push    bx                      ; dummy
    131137        push    si
    132         push    di                      ; dummy
     138        push    bx                      ; dummy
    133139        push    di
    134140        sub     sp, 0ch                 ; dummy
     
    167173        dw      .to_ringX        wrt BS3TEXT16
    168174        dw      .to_ringX        wrt BS3TEXT16
     175        dw      .restore_ctx     wrt BS3TEXT16
    169176%else
    170177        dd      .invalid_syscall wrt FLAT
     
    175182        dd      .to_ringX        wrt FLAT
    176183        dd      .to_ringX        wrt FLAT
     184        dd      .restore_ctx     wrt FLAT
    177185%endif
    178186
     
    238246
    239247        ;
    240         ; Print CX chars from string pointed to by DX:SI in 16-bit and v8086 mode,
    241         ; and ESI/RSI in 64-bit and 32-bit mode (flat).
     248        ; Prints DX chars from the string pointed to by CX:xSI to the screen.
    242249        ;
    243250        ; We use the vga bios teletype interrupt to do the writing, so we must
    244         ; be in some kind of real mode for this to work.  16-bit code segment
    245         ; requried for the mode switching code.
     251        ; be in some kind of real mode for this to work.  The string must be
     252        ; accessible from real mode too.
    246253        ;
    247254.print_str:
    248 ;;%if TMPL_BITS != 64
    249 ;;        mov     bl, byte VAR_CALLER_MODE
    250 ;;        and     bl, BS3_MODE_CODE_MASK
    251 ;;        cmp     bl, BS3_MODE_CODE_V86
    252 ;;        jne     .print_str_not_v8086
    253 ;;        ;; @todo this gets complicated _fast_. Later.
    254 ;;.print_str_not_v8086:
    255 ;;%endif
    256         int3
     255%if TMPL_BITS != 64
     256        push    es
     257%endif
     258        ; Convert the incoming pointer to real mode (assuming caller checked
     259        ; that real mode can access it).
     260        call    .convert_ptr_arg_to_real_mode_ax_si
     261        mov     cx, VAR_CALLER_DX
     262
     263        ; Switch to real mode (no 20h scratch required)
     264%ifndef TMPL_CMN_R86
     265 %if TMPL_BITS != 16
     266        jmp     .print_str_to_16bit
     267BS3_BEGIN_TEXT16
     268.print_str_to_16bit:
     269        BS3_SET_BITS TMPL_BITS
     270 %endif
     271        extern  TMPL_NM(Bs3SwitchToRM)
     272        call    TMPL_NM(Bs3SwitchToRM)
     273        BS3_SET_BITS 16
     274%endif
     275        ; Call code in Bs3PrintStrN to do the work.
     276        mov     ds, ax
     277        call    Bs3PrintStrN_c16_CX_Bytes_At_DS_SI
     278
     279        ; Switch back (20h param scratch area not required).
     280%ifndef TMPL_CMN_R86
     281        extern  RT_CONCAT3(_Bs3SwitchTo,TMPL_MODE_UNAME,_rm)
     282        call    RT_CONCAT3(_Bs3SwitchTo,TMPL_MODE_UNAME,_rm)
     283 %if TMPL_BITS != 16
     284        BS3_SET_BITS TMPL_BITS
     285        jmp     .print_str_end
     286TMPL_BEGIN_TEXT
     287 %endif
     288.print_str_end:
     289%endif
     290%if TMPL_BITS != 64
     291        pop     es
     292%endif
    257293        jmp     .return
    258294
     
    298334        jmp     Bs3Panic
    299335
     336
     337        ;
     338        ; Restore context pointed to by cx:xSI.
     339        ;
     340.restore_ctx:
     341        call    .convert_ptr_arg_to_cx_xSI
     342        BS3_ONLY_64BIT_STMT sub     rsp, 10h
     343        mov     xDX, VAR_CALLER_DX
     344        push    xDX
     345        BS3_ONLY_16BIT_STMT push    cx
     346        push    xSI
     347        BS3_CALL Bs3RegCtxRestore, 2
     348        jmp     Bs3Panic
    300349
    301350        ;
     
    696745
    697746
     747        ;
     748        ; Internal function for converting a syscall pointer parameter (cx:xSI)
     749        ; to a pointer we can use here in this context.
     750        ;
     751        ; Returns the result in cx:xSI.
     752        ; @uses xAX, xCX, xDX
     753        ;
     754.convert_ptr_arg_to_cx_xSI:
     755        call    .convert_ptr_arg_to_flat
     756%if TMPL_BITS == 16
     757        ; Convert to tiled address.
     758        mov     si, ax                  ; offset.
     759        shl     dx, X86_SEL_SHIFT
     760        add     dx, BS3_SEL_TILED
     761        mov     cx, dx
     762%else
     763        ; Just supply a flat selector.
     764        mov     xSI, xAX
     765        mov     cx, ds
     766%endif
     767        ret
     768
     769        ;
     770        ; Internal function for converting a syscall pointer parameter (caller CX:xSI)
     771        ; to a real mode pointer.
     772        ;
     773        ; Returns the result in AX:SI.
     774        ; @uses xAX, xCX, xDX
     775        ;
     776.convert_ptr_arg_to_real_mode_ax_si:
     777        call    .convert_ptr_arg_to_flat
     778        mov     si, ax
     779%if TMPL_BITS == 16
     780        mov     ax, dx
     781%else
     782        shr     eax, 16
     783%endif
     784        shl     ax, 12
     785        ret
     786
     787        ;
     788        ; Internal function for the above that wraps the Bs3SelProtFar32ToFlat32 call.
     789        ;
     790        ; @returns  eax (32-bit, 64-bit), dx+ax (16-bit).
     791        ; @uses     eax, ecx, edx
     792        ;
     793.convert_ptr_arg_to_flat:
     794%if TMPL_BITS == 16
     795        ; Convert to (32-bit) flat address first.
     796        test    byte VAR_CALLER_MODE, BS3_MODE_CODE_V86
     797        jz      .convert_ptr_arg_to_flat_prot_16
     798
     799        mov     ax, VAR_CALLER_CX
     800        mov     dx, ax
     801        shl     ax, 4
     802        shr     dx, 12
     803        add     ax, VAR_CALLER_SI
     804        adc     dx, 0
     805        ret
     806
     807.convert_ptr_arg_to_flat_prot_16:
     808        push    es
     809        push    bx
     810        push    word VAR_CALLER_CX      ; selector
     811        xor     ax, ax
     812        test    byte VAR_CALLER_MODE, BS3_MODE_CODE_16
     813        jnz     .caller_is_16_bit
     814        mov     ax, VAR_CALLER_SI_HI
     815.caller_is_16_bit:
     816        push    ax                      ; offset high
     817        push    word VAR_CALLER_SI      ; offset low
     818        call    Bs3SelProtFar32ToFlat32
     819        add     sp, 2*3
     820        pop     bx
     821        pop     es
     822        ret
     823
     824%else ; 32 or 64 bit
     825        test    byte VAR_CALLER_MODE, BS3_MODE_CODE_V86
     826        jz      .convert_ptr_arg_to_cx_xSI_prot
     827
     828        ; Convert real mode address to flat address and return it.
     829        movzx   eax, word VAR_CALLER_CX
     830        shl     eax, 4
     831        movzx   edx, word VAR_CALLER_SI
     832        add     eax, edx
     833        ret
     834
     835        ; Convert to (32-bit) flat address.
     836.convert_ptr_arg_to_cx_xSI_prot:
     837 %if TMPL_BITS == 64
     838        push    r11
     839        push    r10
     840        push    r9
     841        push    r8
     842        sub     rsp, 10h
     843 %endif
     844        movzx   ecx, word VAR_CALLER_CX
     845        push    xCX
     846        mov     eax, VAR_CALLER_SI
     847        test    byte VAR_CALLER_MODE, BS3_MODE_CODE_16
     848        jz      .no_masking_offset
     849        and     eax, 0ffffh
     850.no_masking_offset:
     851        push    xAX
     852        BS3_CALL Bs3SelProtFar32ToFlat32,2
     853        add     xSP, xCB*2 BS3_ONLY_64BIT(+ 10h)
     854 %if TMPL_BITS == 64
     855        pop     r8
     856        pop     r9
     857        pop     r10
     858        pop     r11
     859 %endif
     860%endif
     861        ret
     862
    698863BS3_PROC_END_MODE   Bs3TrapSystemCallHandler
    699864
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-rm-InitMemory.c

    r59941 r60291  
    170170     *      - 0x10000 to 0x1yyyy - BS3TEXT16
    171171     *      - 0x20000 to 0x26fff - BS3SYSTEM16
    172      *      - 0x27000 to 0xzzzzz - BS3DATA16, BS3TEXT32, BS3TEXT64, BS3DATA32, BS3DATA64 (in that order).
     172     *      - 0x29000 to 0xzzzzz - BS3DATA16, BS3TEXT32, BS3TEXT64, BS3DATA32, BS3DATA64 (in that order).
    173173     *      - 0xzzzzZ to 0x9fdff - Free conventional memory.
    174174     *      - 0x9fc00 to 0x9ffff - Extended BIOS data area (exact start may vary).
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-system-data.asm

    r60210 r60291  
    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
     
    2525;
    2626
    27 
    2827%include "bs3kit.mac"
    2928
     
    3736StartSystem16:
    3837        db  10, 13, 'eye-catcher: SYSTEM16.......', 10, 13 ; 32 bytes long
    39 BS3_GLOBAL_DATA Bs3Gdt, 3000
     38BS3_GLOBAL_DATA Bs3Gdt, 4000h - 20h
    4039
    4140;; Macro for checking GDT offsets as we go along.
     
    198197
    199198BS3_GLOBAL_DATA Bs3Gdte_R %+ %1 %+ _DS16, 8     ; Entry 108h
    200         dw  0ffffh, (0xffff & BS3_ADDR_BS3DATA16) ; 16-bit data segment with base 027000h.
     199        dw  0ffffh, (0xffff & BS3_ADDR_BS3DATA16) ; 16-bit data segment with base 029000h.
    201200        dw  09300h | (%1 << 0dh) | (0xff & (BS3_ADDR_BS3DATA16 >> 16)), 00000h | (0xff00 & (BS3_ADDR_BS3DATA16 >> 16))
    202201
     
    417416
    418417        ;
    419         ; 2008..26f8h - Free GDTEs.
    420         ;
    421 BS3_GLOBAL_DATA Bs3GdteFreePart3, 06f8h
    422         times 06f8h db 0
    423 
    424         ;
    425         ; 2700h - the real mode segment number for BS3DATA16. DPL=3. BASE=0x23000h
    426         ;
    427 BS3GdtAssertOffset 02700h
     418        ; 2008..28f8h - Free GDTEs.
     419        ;
     420BS3_GLOBAL_DATA Bs3GdteFreePart3, 08f8h
     421        times 08f8h db 0
     422
     423        ;
     424        ; 2900h - the real mode segment number for BS3DATA16. DPL=3. BASE=0x29000h
     425        ;
     426BS3GdtAssertOffset 02900h
    428427BS3_GLOBAL_DATA Bs3Gdte_DATA16, 8h
    429         dw  0ffffh, 07000h, 0f302h, 00000h
     428        dw  0ffffh, 09000h, 0f302h, 00000h
     429
     430        ;
     431        ; 2908..2f98h - Free GDTEs.
     432        ;
     433BS3GdtAssertOffset 02908h
     434BS3_GLOBAL_DATA Bs3GdteFreePart4, 698h
     435        times 698h db 0
     436
     437        ;
     438        ; 2be0..2fe0h - 8 spare entries preceeding the test page which we're free
     439        ;               to mess with page table protection.
     440        ;
     441BS3GdtAssertOffset 02fa0h
     442BS3_GLOBAL_DATA Bs3GdtePreTestPage08, 8
     443        dq 0
     444BS3_GLOBAL_DATA Bs3GdtePreTestPage07, 8
     445        dq 0
     446BS3_GLOBAL_DATA Bs3GdtePreTestPage06, 8
     447        dq 0
     448BS3_GLOBAL_DATA Bs3GdtePreTestPage05, 8
     449        dq 0
     450BS3_GLOBAL_DATA Bs3GdtePreTestPage04, 8
     451        dq 0
     452BS3_GLOBAL_DATA Bs3GdtePreTestPage03, 8
     453        dq 0
     454BS3_GLOBAL_DATA Bs3GdtePreTestPage02, 8
     455        dq 0
     456BS3_GLOBAL_DATA Bs3GdtePreTestPage01, 8
     457        dq 0
     458
     459        ;
     460        ; 2fe0..3fd8h - 16 Test entries at the start of the page where we're free
     461        ;               to mess with page table protection.
     462        ;
     463BS3GdtAssertOffset 02fe0h
     464AssertCompile(($ - $$) == 0x3000)
     465BS3_GLOBAL_DATA Bs3GdteTestPage, 0
     466BS3_GLOBAL_DATA Bs3GdteTestPage00, 8
     467        dq 0
     468BS3_GLOBAL_DATA Bs3GdteTestPage01, 8
     469        dq 0
     470BS3_GLOBAL_DATA Bs3GdteTestPage02, 8
     471        dq 0
     472BS3_GLOBAL_DATA Bs3GdteTestPage03, 8
     473        dq 0
     474BS3_GLOBAL_DATA Bs3GdteTestPage04, 8
     475        dq 0
     476BS3_GLOBAL_DATA Bs3GdteTestPage05, 8
     477        dq 0
     478BS3_GLOBAL_DATA Bs3GdteTestPage06, 8
     479        dq 0
     480BS3_GLOBAL_DATA Bs3GdteTestPage07, 8
     481        dq 0
     482BS3GdtAssertOffset 3020h
     483        times 0fb8h db 0
     484BS3GdtAssertOffset 3fd8h
    430485BS3_GLOBAL_DATA Bs3GdtEnd, 0
    431486        db  10, 13, 'GDTE', 10, 13      ; alignment padding (next address on 16 byte boundrary).
     487BS3GdtAssertOffset 4000h - 20h ; We're at a page boundrary here! Only GDT and eyecatchers on page starting at 3000h!
     488AssertCompile(($ - $$) == 0x4000)
     489
    432490
    433491
     
    9541012; LDT filling up the rest of the segment.
    9551013;
    956 ; Currently this starts at 0x6c50, which leaves us with 0x3b0 bytes.  We'll use
     1014; Currently this starts at 0x84d0, which leaves us with 0xb30 bytes.  We'll use
    9571015; the last 32 of those for an eye catcher.
    9581016;
    959 BS3_GLOBAL_DATA Bs3Ldt, 03b0h
    960         times (03b0h - 32) db 0
     1017BS3_GLOBAL_DATA Bs3Ldt, 0b30h - 32
     1018        times (0b30h - 32) db 0
    9611019BS3_GLOBAL_DATA Bs3LdtEnd, 0
    9621020        db  10, 13, 'eye-catcher: SYSTEM16 END', 10, 13, 0, 0, 0 ; 32 bytes long
     
    9661024;
    9671025%ifndef KBUILD_GENERATING_MAKEFILE_DEPENDENCIES
    968  %if ($ - $$) != 07000h
     1026 %if ($ - $$) != 09000h
    9691027  %assign offActual ($ - $$)
    970   %error "Bad BS3SYSTEM16 segment size: " %+ offActual %+ ", expected 0x7000 (28672)"
     1028  %error "Bad BS3SYSTEM16 segment size: " %+ offActual %+ ", expected 0x9000 (36864)"
    9711029 %endif
    9721030%endif
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h

    r60231 r60291  
    184184/** The base address of the BS3DATA16 segment.
    185185 * @sa BS3_SEL_DATA16 */
    186 #define BS3_ADDR_BS3DATA16      0x27000
     186#define BS3_ADDR_BS3DATA16      0x29000
    187187/** @} */
    188188
     
    198198 * | BS3TEXT16   |   0x00010000 |             1000h |
    199199 * | BS3SYSTEM16 |   0x00020000 |             2000h |
    200  * | BS3DATA16   |   0x00027000 |             2700h |
     200 * | BS3DATA16   |   0x00029000 |             2900h |
    201201 *
    202202 * This means that we've got a lot of GDT space to play around with.
     
    352352
    353353#define BS3_SEL_FREE_PART3          0x2008 /**< Free selector space - part \#3. */
    354 #define BS3_SEL_FREE_PART3_LAST     0x26f8 /**< Free selector space - part \#3, last entry. */
    355 
    356 #define BS3_SEL_DATA16              0x2700 /**< The BS3DATA16 selector. */
    357 
    358 #define BS3_SEL_GDT_LIMIT           0x2707 /**< The GDT limit. */
     354#define BS3_SEL_FREE_PART3_LAST     0x28f8 /**< Free selector space - part \#3, last entry. */
     355
     356#define BS3_SEL_DATA16              0x2900 /**< The BS3DATA16 selector. */
     357
     358#define BS3_SEL_FREE_PART4          0x2908 /**< Free selector space - part \#4. */
     359#define BS3_SEL_FREE_PART4_LAST     0x2f98 /**< Free selector space - part \#4, last entry. */
     360
     361#define BS3_SEL_PRE_TEST_PAGE_08    0x2fa0 /**< Selector located 8 selectors before the test page. */
     362#define BS3_SEL_PRE_TEST_PAGE_07    0x2fa8 /**< Selector located 7 selectors before the test page. */
     363#define BS3_SEL_PRE_TEST_PAGE_06    0x2fb0 /**< Selector located 6 selectors before the test page. */
     364#define BS3_SEL_PRE_TEST_PAGE_05    0x2fb8 /**< Selector located 5 selectors before the test page. */
     365#define BS3_SEL_PRE_TEST_PAGE_04    0x2fc0 /**< Selector located 4 selectors before the test page. */
     366#define BS3_SEL_PRE_TEST_PAGE_03    0x2fc8 /**< Selector located 3 selectors before the test page. */
     367#define BS3_SEL_PRE_TEST_PAGE_02    0x2fd0 /**< Selector located 2 selectors before the test page. */
     368#define BS3_SEL_PRE_TEST_PAGE_01    0x2fd8 /**< Selector located 1 selector  before the test page. */
     369#define BS3_SEL_TEST_PAGE           0x2fe0 /**< Start of the test page intended for playing around with paging and GDT. */
     370#define BS3_SEL_TEST_PAGE_00        0x2fe0 /**< Test page selector number 00h (convenience). */
     371#define BS3_SEL_TEST_PAGE_01        0x2fe8 /**< Test page selector number 01h (convenience). */
     372#define BS3_SEL_TEST_PAGE_02        0x2ff0 /**< Test page selector number 02h (convenience). */
     373#define BS3_SEL_TEST_PAGE_03        0x2ff8 /**< Test page selector number 03h (convenience). */
     374#define BS3_SEL_TEST_PAGE_04        0x3000 /**< Test page selector number 04h (convenience). */
     375#define BS3_SEL_TEST_PAGE_05        0x3008 /**< Test page selector number 05h (convenience). */
     376#define BS3_SEL_TEST_PAGE_06        0x3010 /**< Test page selector number 06h (convenience). */
     377#define BS3_SEL_TEST_PAGE_07        0x3018 /**< Test page selector number 07h (convenience). */
     378#define BS3_SEL_TEST_PAGE_LAST      0x3fd0 /**< The last selector in the spare page. */
     379
     380#define BS3_SEL_GDT_LIMIT           0x3fd8 /**< The GDT limit. */
    359381/** @} */
    360382
     
    570592
    571593/** @name System call numbers (ax).
    572  * Paramenters are generally passed in registers specific to each system call.
     594 * Paramenters are generally passed in registers specific to each system call,
     595 * however cx:xSI is used for passing a pointer parameter.
    573596 * @{ */
    574597/** Print char (cl). */
    575598#define BS3_SYSCALL_PRINT_CHR   UINT16_C(0x0001)
    576 /** Print string (pointer in ds:[e]si, length in cx). */
     599/** Print string (pointer in cx:xSI, length in dx). */
    577600#define BS3_SYSCALL_PRINT_STR   UINT16_C(0x0002)
    578601/** Switch to ring-0. */
     
    584607/** Switch to ring-3. */
    585608#define BS3_SYSCALL_TO_RING3    UINT16_C(0x0006)
     609/** Restore context (pointer in cx:xSI, flags in dx). */
     610#define BS3_SYSCALL_RESTORE_CTX UINT16_C(0x0007)
    586611/** @} */
    587612
     
    734759/** The BS3DATA16/BS3_FAR_DATA GDT entry. */
    735760extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3Gdte_DATA16);
    736 /** The end of the GDT (exclusive). */
     761/** Free GDTes, part \#4. */
     762
     763extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteFreePart4)[211];
     764extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdtePreTestPage08); /**< GDT entry 8 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_08 */
     765extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdtePreTestPage07); /**< GDT entry 7 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_07 */
     766extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdtePreTestPage06); /**< GDT entry 6 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_06 */
     767extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdtePreTestPage05); /**< GDT entry 5 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_05 */
     768extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdtePreTestPage04); /**< GDT entry 4 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_04 */
     769extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdtePreTestPage03); /**< GDT entry 3 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_03 */
     770extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdtePreTestPage02); /**< GDT entry 2 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_02 */
     771extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdtePreTestPage01); /**< GDT entry 1 selectors prior to the test page, testcase resource. @see BS3_SEL_PRE_TEST_PAGE_01 */
     772/** Array of GDT entries starting on a page boundrary and filling (almost) the
     773 * whole page.   This is for playing with paging and GDT usage.
     774 * @see BS3_SEL_TEST_PAGE */
     775extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteTestPage)[2043];
     776extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteTestPage00); /**< GDT entry 0 on the test page (convenience). @see BS3_SEL_TEST_PAGE_00 */
     777extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteTestPage01); /**< GDT entry 1 on the test page (convenience). @see BS3_SEL_TEST_PAGE_01 */
     778extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteTestPage02); /**< GDT entry 2 on the test page (convenience). @see BS3_SEL_TEST_PAGE_02 */
     779extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteTestPage03); /**< GDT entry 3 on the test page (convenience). @see BS3_SEL_TEST_PAGE_03 */
     780extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteTestPage04); /**< GDT entry 4 on the test page (convenience). @see BS3_SEL_TEST_PAGE_04 */
     781extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteTestPage05); /**< GDT entry 5 on the test page (convenience). @see BS3_SEL_TEST_PAGE_05 */
     782extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteTestPage06); /**< GDT entry 6 on the test page (convenience). @see BS3_SEL_TEST_PAGE_06 */
     783extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdteTestPage07); /**< GDT entry 7 on the test page (convenience). @see BS3_SEL_TEST_PAGE_07 */
     784
     785/** The end of the GDT (exclusive - contains eye-catcher string). */
    737786extern X86DESC BS3_FAR_DATA BS3_DATA_NM(Bs3GdtEnd);
    738787
     
    11911240
    11921241/**
     1242 * Prints a string to the screen.
     1243 *
     1244 * @param   pchString       The string to print.  Any terminator charss will be printed.
     1245 * @param   cchString       The exact number of characters to print.
     1246 */
     1247BS3_DECL(void) Bs3PrintStrN_c16(const char BS3_FAR *pszString, size_t cchString);
     1248BS3_DECL(void) Bs3PrintStrN_c32(const char BS3_FAR *pszString, size_t cchString); /**< @copydoc Bs3PrintStrN_c16 */
     1249BS3_DECL(void) Bs3PrintStrN_c64(const char BS3_FAR *pszString, size_t cchString); /**< @copydoc Bs3PrintStrN_c16 */
     1250#define Bs3PrintStrN BS3_CMN_NM(Bs3PrintStrN) /**< Selects #Bs3PrintStrN_c16, #Bs3PrintStrN_c32 or #Bs3PrintStrN_c64. */
     1251
     1252/**
    11931253 * Prints a char to the screen.
    11941254 *
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.mac

    r60217 r60291  
    11211121;; The base address of the BS3DATA16 segment.
    11221122;; @sa BS3_SEL_DATA16
    1123 %define BS3_ADDR_BS3DATA16      027000h
     1123%define BS3_ADDR_BS3DATA16      029000h
    11241124;; @}
    11251125
     
    12191219
    12201220;; @name System call numbers (ax)
     1221;; @note Pointers are always passed in cx:xDI.
    12211222;; @{
    12221223;; Print char (cl).
    12231224%define BS3_SYSCALL_PRINT_CHR       0001h
    1224 ;; Print string (pointer in ds:[e]si, length in cx).
     1225;; Print string (pointer in cx:xDI, length in xDX).
    12251226%define BS3_SYSCALL_PRINT_STR       0002h
    12261227;; Switch to ring-0.
     
    12321233;; Switch to ring-3.
    12331234%define BS3_SYSCALL_TO_RING3        0006h
     1235;; Restore context (pointer in cx:xDI, flags in dx).
     1236%define BS3_SYSCALL_RESTORE_CTX     0007h
    12341237;; The last system call value.
    1235 %define BS3_SYSCALL_LAST            BS3_SYSCALL_TO_RING3
     1238%define BS3_SYSCALL_LAST            BS3_SYSCALL_RESTORE_CTX
    12361239;; @}
    12371240
     
    13891392
    13901393%define BS3_SEL_FREE_PART3          2008h ;;< Free selector space - part \%3.
    1391 %define BS3_SEL_FREE_PART3_LAST     26f8h ;;< Free selector space - part \%3, last entry.
    1392 
    1393 %define BS3_SEL_DATA16              2700h ;;< The BS3DATA16 selector.
    1394 
    1395 %define BS3_SEL_GDT_LIMIT           2707h ;;< The GDT limit.
     1394%define BS3_SEL_FREE_PART3_LAST     28f8h ;;< Free selector space - part \%3, last entry.
     1395
     1396%define BS3_SEL_DATA16              2900h ;;< The BS3DATA16 selector.
     1397
     1398%define BS3_SEL_FREE_PART4          2908h ;;< Free selector space - part \#4.
     1399%define BS3_SEL_FREE_PART4_LAST     2f98h ;;< Free selector space - part \#4, last entry.
     1400
     1401%define BS3_SEL_PRE_TEST_PAGE_08    2fa0h ;;< Selector located 8 selectors before the test page.
     1402%define BS3_SEL_PRE_TEST_PAGE_07    2fa8h ;;< Selector located 7 selectors before the test page.
     1403%define BS3_SEL_PRE_TEST_PAGE_06    2fb0h ;;< Selector located 6 selectors before the test page.
     1404%define BS3_SEL_PRE_TEST_PAGE_05    2fb8h ;;< Selector located 5 selectors before the test page.
     1405%define BS3_SEL_PRE_TEST_PAGE_04    2fc0h ;;< Selector located 4 selectors before the test page.
     1406%define BS3_SEL_PRE_TEST_PAGE_03    2fc8h ;;< Selector located 3 selectors before the test page.
     1407%define BS3_SEL_PRE_TEST_PAGE_02    2fd0h ;;< Selector located 2 selectors before the test page.
     1408%define BS3_SEL_PRE_TEST_PAGE_01    2fd8h ;;< Selector located 1 selector  before the test page.
     1409%define BS3_SEL_TEST_PAGE           2fe0h ;;< Start of the test page intended for playing around with paging and GDT.
     1410%define BS3_SEL_TEST_PAGE_00        2fe0h ;;< Test page selector number 00h (convenience).
     1411%define BS3_SEL_TEST_PAGE_01        2fe8h ;;< Test page selector number 01h (convenience).
     1412%define BS3_SEL_TEST_PAGE_02        2ff0h ;;< Test page selector number 02h (convenience).
     1413%define BS3_SEL_TEST_PAGE_03        2ff8h ;;< Test page selector number 03h (convenience).
     1414%define BS3_SEL_TEST_PAGE_04        3000h ;;< Test page selector number 04h (convenience).
     1415%define BS3_SEL_TEST_PAGE_05        3008h ;;< Test page selector number 05h (convenience).
     1416%define BS3_SEL_TEST_PAGE_06        3010h ;;< Test page selector number 06h (convenience).
     1417%define BS3_SEL_TEST_PAGE_07        3018h ;;< Test page selector number 07h (convenience).
     1418%define BS3_SEL_TEST_PAGE_LAST      3fd0h ;;< The last selector in the spare page.
     1419
     1420%define BS3_SEL_GDT_LIMIT           3fd8h ;;< The GDT limit.
    13961421
    13971422;; @}
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