VirtualBox

Changeset 60682 in vbox


Ignore:
Timestamp:
Apr 24, 2016 6:56:17 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
106850
Message:

bs3kit: Can finally check for non-canonical address #GP(0).

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.c

    r60681 r60682  
    13921392    uint8_t             bFiller;
    13931393    int                 off;
     1394    int                 off2;
    13941395    unsigned            cb;
    13951396    uint8_t BS3_FAR    *pbTest;
     
    18811882     * Check non-canonical 64-bit space.
    18821883     */
    1883     if (BS3_MODE_IS_64BIT_CODE(bTestMode))
    1884     {
    1885 
    1886     }
     1884    if (   BS3_MODE_IS_64BIT_CODE(bTestMode)
     1885        && (pbTest = (uint8_t BS3_FAR *)Bs3PagingSetupCanonicalTraps()) != NULL)
     1886    {
     1887        /* Make our references relative to the gap. */
     1888        pbTest += g_cbBs3PagingOneCanonicalTrap;
     1889
     1890        /* Hit it from below. */
     1891        for (off = -cbIdtr - 8; off < cbIdtr + 8; off++)
     1892        {
     1893            Ctx.rbx.u = CtxUdExpected.rbx.u = UINT64_C(0x0000800000000000) + off;
     1894            Bs3MemSet(&pbTest[-64], bFiller, 64*2);
     1895            Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
     1896            if (off + cbIdtr <= 0)
     1897            {
     1898                bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
     1899                if (Bs3MemCmp(&pbTest[off], pabExpected, cbIdtr) != 0)
     1900                    Bs3TestFailedF("Mismatch (#21): expected %.*Rhxs, got %.*Rhxs\n", cbIdtr, pabExpected, cbIdtr, &pbTest[off]);
     1901            }
     1902            else
     1903            {
     1904                bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
     1905                if (off <= -2 && Bs3MemCmp(&pbTest[off], pabExpected, 2) != 0)
     1906                    Bs3TestFailedF("Mismatch (#21): expected limit %.2Rhxs, got %.2Rhxs\n", pabExpected, &pbTest[off]);
     1907                off2 = off <= -2 ? 2 : 0;
     1908                cb   = cbIdtr - off2;
     1909                if (!ASMMemIsAllU8(&pbTest[off + off2], cb, bFiller))
     1910                    Bs3TestFailedF("Mismatch (#21): touched base %.*Rhxs, got %.*Rhxs\n",
     1911                                   cb, &pabExpected[off], cb, &pbTest[off + off2]);
     1912            }
     1913            if (!ASMMemIsAllU8(&pbTest[off - 16], 16, bFiller))
     1914                Bs3TestFailedF("Leading bytes touched (#21): bFiller=%#x, got %.16Rhxs\n", bFiller, &pbTest[off]);
     1915            if (!ASMMemIsAllU8(&pbTest[off + cbIdtr], 16, bFiller))
     1916                Bs3TestFailedF("Trailing bytes touched (#21): bFiller=%#x, got %.16Rhxs\n", bFiller, &pbTest[off + cbIdtr]);
     1917        }
     1918
     1919        /* Hit it from above. */
     1920        for (off = -cbIdtr - 8; off < cbIdtr + 8; off++)
     1921        {
     1922            Ctx.rbx.u = CtxUdExpected.rbx.u = UINT64_C(0xffff800000000000) + off;
     1923            Bs3MemSet(&pbTest[-64], bFiller, 64*2);
     1924            Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
     1925            if (off >= 0)
     1926            {
     1927                bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
     1928                if (Bs3MemCmp(&pbTest[off], pabExpected, cbIdtr) != 0)
     1929                    Bs3TestFailedF("Mismatch (#22): expected %.*Rhxs, got %.*Rhxs\n", cbIdtr, pabExpected, cbIdtr, &pbTest[off]);
     1930            }
     1931            else
     1932            {
     1933                bs3CpuBasic2_CompareGpCtx(&TrapCtx, &Ctx, 0);
     1934                if (!ASMMemIsAllU8(&pbTest[off], cbIdtr, bFiller))
     1935                    Bs3TestFailedF("Mismatch (#22): touched base %.*Rhxs, got %.*Rhxs\n",
     1936                                   cbIdtr, &pabExpected[off], cbIdtr, &pbTest[off]);
     1937            }
     1938            if (!ASMMemIsAllU8(&pbTest[off - 16], 16, bFiller))
     1939                Bs3TestFailedF("Leading bytes touched (#22): bFiller=%#x, got %.16Rhxs\n", bFiller, &pbTest[off]);
     1940            if (!ASMMemIsAllU8(&pbTest[off + cbIdtr], 16, bFiller))
     1941                Bs3TestFailedF("Trailing bytes touched (#22): bFiller=%#x, got %.16Rhxs\n", bFiller, &pbTest[off + cbIdtr]);
     1942        }
     1943
     1944    }
     1945
    18871946}
    18881947
     
    21612220BS3_DECL_FAR(uint8_t) TMPL_NM(bs3CpuBasic2_sidt)(uint8_t bMode)
    21622221{
    2163 if (bMode == BS3_MODE_LM64)
     2222//if (bMode == BS3_MODE_LM64)
    21642223{
    21652224    union
     
    21942253BS3_DECL_FAR(uint8_t) TMPL_NM(bs3CpuBasic2_sgdt)(uint8_t bMode)
    21952254{
    2196 if (bMode == BS3_MODE_LM64)
     2255//if (bMode == BS3_MODE_LM64)
    21972256{
    21982257    union
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk

    r60676 r60682  
    8787       bs3-cmn-PagingInitRootForLM.c \
    8888       bs3-cmn-PagingProtect.c \
     89       bs3-cmn-PagingSetupCanonicalTraps.c \
    8990       bs3-cmn-PicMaskAll.c \
    9091       bs3-cmn-RegCtxRestore.asm \
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-PagingData.c

    r60311 r60682  
    4242uint32_t g_PhysPagingRootLM  = UINT32_MAX;
    4343
     44uint32_t g_uBs3PagingCanonicalTrapsAddr = UINT32_MAX;
     45uint16_t g_cbBs3PagingCanonicalTraps    = 0;
     46uint16_t g_cbBs3PagingOneCanonicalTrap  = 0;
     47
    4448#endif
    4549
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-PagingProtect.c

    r60678 r60682  
    9393                {
    9494                    if (pPD->a[iPde].u <= uMaxAddr)
    95                     {
    9695                        pPTE = &((X86PT BS3_FAR *)Bs3XptrFlatToCurrent(pPD->a[iPde].u & ~(uint32_t)PAGE_OFFSET_MASK))->a[iPte];
    97                         *prc = VINF_SUCCESS;
    98                     }
    9996                    else
    10097                        BS3PAGING_DPRINTF1(("bs3PagingGetLegacyPte: out of range! iPde=%#x: %#x\n", iPde, pPD->a[iPde].u));
     
    122119                            ASMInvalidatePage(uFlat);
    123120                        pPTE = &pPT->a[iPte];
    124                         *prc = VINF_SUCCESS;
    125121                    }
    126122                }
     
    134130
    135131
     132/**
     133 * Get the PTE for an address, given a PAE or long mode CR3.
     134 *
     135 * @returns Pointer to the PTE on success, NULL on failure.
     136 * @param   cr3                 The CR3.
     137 * @param   bMode               Indicates whether it's PAE or long mode.
     138 * @param   uFlat               The address for which we want the PTE.
     139 * @param   fUseInvlPg          Whether we can use invalidate page when
     140 *                              replacing large pages.
     141 * @param   prc                 Updated only on failure.
     142 */
    136143#undef bs3PagingGetPte
    137 BS3_CMN_DEF(X86PTEPAE BS3_FAR *, bs3PagingGetPte,(RTCCUINTXREG cr3, uint64_t uFlat, bool fUseInvlPg, int *prc))
     144BS3_CMN_DEF(X86PTEPAE BS3_FAR *, bs3PagingGetPte,(RTCCUINTXREG cr3, uint8_t bMode, uint64_t uFlat, bool fUseInvlPg, int *prc))
    138145{
    139146    X86PTEPAE BS3_FAR  *pPTE = NULL;
     
    148155    {
    149156        X86PDPAE BS3_FAR *pPD;
    150         if (BS3_MODE_IS_64BIT_SYS(g_bBs3CurrentMode))
     157        if (BS3_MODE_IS_64BIT_SYS(bMode))
    151158        {
    152159            unsigned const   iPml4e = (uFlat >> X86_PML4_SHIFT) & X86_PML4_MASK;
     
    206213            {
    207214                if ((pPD->a[iPde].u & X86_PDE_PAE_PG_MASK) <= uMaxAddr)
    208                 {
    209215                    pPTE = &((X86PTPAE BS3_FAR *)Bs3XptrFlatToCurrent(pPD->a[iPde].u & ~(uint64_t)PAGE_OFFSET_MASK))->a[iPte];
    210                     *prc = VINF_SUCCESS;
    211                 }
    212216                else
    213217                    BS3PAGING_DPRINTF1(("bs3PagingGetPte: out of range! iPde=%#x: %RX64 max=%RX32\n",
     
    233237                        ASMInvalidatePage(uFlat);
    234238                    pPTE = &pPT->a[iPte];
    235                     *prc = VINF_SUCCESS;
    236239                }
    237240            }
     
    304307            while (cb > 0)
    305308            {
    306                 PX86PTEPAE pPte = BS3_CMN_FAR_NM(bs3PagingGetPte)(cr3, uFlat, fUseInvlPg, &rc);
     309                PX86PTEPAE pPte = BS3_CMN_FAR_NM(bs3PagingGetPte)(cr3, g_bBs3CurrentMode, uFlat, fUseInvlPg, &rc);
    307310                if (!pPte)
    308311                    return rc;
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-TestSub.c

    r60527 r60682  
    5353    g_cusBs3SubTestAtErrors = g_cusBs3TestErrors;
    5454    BS3_ASSERT(!g_fbBs3SubTestSkipped);
     55    g_cusBs3SubTests++;
    5556
    5657    /*
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-paging.h

    r60311 r60682  
    3131#include <iprt/asm.h>
    3232
    33 RT_C_DECLS_BEGIN;
     33RT_C_DECLS_BEGIN
    3434
    3535/** Root directory for page protected mode.
    3636 * UINT32_MAX if not initialized. */
    37 #ifndef DOXYGEN_RUNNING
    38 # define g_PhysPagingRootPP BS3_DATA_NM(g_PhysPagingRootPP)
    39 #endif
    4037extern uint32_t g_PhysPagingRootPP;
    4138/** Root directory pointer table for PAE mode.
    4239 * UINT32_MAX if not initialized. */
    43 #ifndef DOXYGEN_RUNNING
    44 # define g_PhysPagingRootPAE BS3_DATA_NM(g_PhysPagingRootPAE)
    45 #endif
    4640extern uint32_t g_PhysPagingRootPAE;
    4741/** Root table (level 4) for long mode.
    4842 * UINT32_MAX if not initialized. */
    49 #ifndef DOXYGEN_RUNNING
    50 # define g_PhysPagingRootLM BS3_DATA_NM(g_PhysPagingRootLM)
    51 #endif
    5243extern uint32_t g_PhysPagingRootLM;
    5344
    54 RT_C_DECLS_END;
     45#undef bs3PagingGetLegacyPte
     46BS3_CMN_PROTO_STUB(X86PTE BS3_FAR *, bs3PagingGetLegacyPte,(RTCCUINTXREG cr3, uint32_t uFlat, bool fUseInvlPg, int *prc));
     47#undef bs3PagingGetPte
     48BS3_CMN_PROTO_STUB(X86PTEPAE BS3_FAR *, bs3PagingGetPte,(RTCCUINTXREG cr3, uint8_t bMode, uint64_t uFlat,
     49                                                         bool fUseInvlPg, int *prc));
    5550
     51RT_C_DECLS_END
    5652
    57 #define bs3PagingGetLegacyPte BS3_CMN_NM(bs3PagingGetLegacyPte)
    58 BS3_DECL(X86PTE BS3_FAR *) bs3PagingGetLegacyPte(RTCCUINTXREG cr3, uint32_t uFlat, bool fUseInvlPg, int *prc);
    59 
    60 #define bs3PagingGetPte BS3_CMN_NM(bs3PagingGetPte)
    61 BS3_DECL(X86PTEPAE BS3_FAR *) bs3PagingGetPte(RTCCUINTXREG cr3, uint64_t uFlat, bool fUseInvlPg, int *prc);
    62 
     53#include "bs3kit-mangling-code.h"
    6354
    6455#endif
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-autostubs.kmk

    r60676 r60682  
    6161$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3MemMove)
    6262$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3MemPCpy)
     63$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3PagingSetupCanonicalTraps)
    6364$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3SlabAlloc)
    6465$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3SlabAllocEx)
     
    109110$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3UInt32Div)
    110111$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3UInt64Div)
     112$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,bs3PagingGetLegacyPte)
     113$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,bs3PagingGetPte)
    111114$(call BS3KIT_FN_GEN_MODE_NEARSTUB,bs3kit-common-16,Bs3TrapInit)
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-define.h

    r60676 r60682  
    4747#define Bs3MemSet BS3_CMN_MANGLER(Bs3MemSet)
    4848#define Bs3MemZero BS3_CMN_MANGLER(Bs3MemZero)
     49#define bs3PagingGetLegacyPte BS3_CMN_MANGLER(bs3PagingGetLegacyPte)
     50#define bs3PagingGetPte BS3_CMN_MANGLER(bs3PagingGetPte)
    4951#define Bs3PagingInitRootForLM BS3_CMN_MANGLER(Bs3PagingInitRootForLM)
    5052#define Bs3PagingInitRootForPAE BS3_CMN_MANGLER(Bs3PagingInitRootForPAE)
     
    5254#define Bs3PagingProtect BS3_CMN_MANGLER(Bs3PagingProtect)
    5355#define Bs3PagingProtectPtr BS3_CMN_MANGLER(Bs3PagingProtectPtr)
     56#define Bs3PagingSetupCanonicalTraps BS3_CMN_MANGLER(Bs3PagingSetupCanonicalTraps)
    5457#define Bs3Panic BS3_CMN_MANGLER(Bs3Panic)
    5558#define Bs3PicMaskAll BS3_CMN_MANGLER(Bs3PicMaskAll)
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-undef.h

    r60676 r60682  
    4747#undef Bs3MemSet
    4848#undef Bs3MemZero
     49#undef bs3PagingGetLegacyPte
     50#undef bs3PagingGetPte
    4951#undef Bs3PagingInitRootForLM
    5052#undef Bs3PagingInitRootForPAE
     
    5254#undef Bs3PagingProtect
    5355#undef Bs3PagingProtectPtr
     56#undef Bs3PagingSetupCanonicalTraps
    5457#undef Bs3Panic
    5558#undef Bs3PicMaskAll
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h

    r60681 r60682  
    21372137BS3_CMN_PROTO_STUB(int, Bs3PagingProtectPtr,(void BS3_FAR *pv, size_t cb, uint64_t fSet, uint64_t fClear));
    21382138
     2139/** The physical / flat address of the buffer backing the canonical traps.
     2140 * This buffer is spread equally on each side of the 64-bit non-canonical
     2141 * address divide.  Non-64-bit code can use this to setup trick shots and
     2142 * inspect their results. */
     2143extern uint32_t g_uBs3PagingCanonicalTrapsAddr;
     2144/** The size of the buffer at g_uPagingCanonicalTraps (both sides). */
     2145extern uint16_t g_cbBs3PagingCanonicalTraps;
     2146/** The size of one trap buffer (low or high).
     2147 * This is g_cbBs3PagingCanonicalTraps divided by two. */
     2148extern uint16_t g_cbBs3PagingOneCanonicalTrap;
     2149
     2150/**
     2151 * Sets up the 64-bit canonical address space trap buffers, if neceessary.
     2152 *
     2153 * @returns Pointer to the buffers (i.e. the first page of the low one) on
     2154 *          success.  NULL on failure.
     2155 */
     2156BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3PagingSetupCanonicalTraps,(void));
     2157
    21392158/**
    21402159 * Waits for the keyboard controller to become ready.
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