VirtualBox

Changeset 61389 in vbox


Ignore:
Timestamp:
Jun 2, 2016 12:04:34 AM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
107703
Message:

bs3kit: Use PIT for timing out the FPU testcase.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/bootsectors/bs3-fpustate-1-template.c

    r61385 r61389  
    126126    X86FXSTATE BS3_FAR *pChecking = pExpected + 1;
    127127    uint32_t            iLoop;
     128    uint32_t            uStartTick;
    128129    bool                fMmioReadback;
    129130    bool                fReadBackError = false;
    130131    BS3PTRUNION         MmioReg;
     132
    131133
    132134# undef  CHECK_STATE
     
    138140                Bs3TestFailedF("State differs after " #a_Instr " (write) in loop #%RU32\n", iLoop); \
    139141                bs3FpuState1_Diff(pExpected, pChecking); \
     142                Bs3PitDisable(); \
    140143                return 1; \
    141144            } \
     
    146149     */
    147150
    148     /* First, figure out which MMIO region we'll be using so we can correctly initialize FPUDS. */
     151    /* Make this code executable in raw-mode.  A bit tricky. */
     152    ASMSetCR0(ASMGetCR0() | X86_CR0_WP);
     153    Bs3PitSetupAndEnablePeriodTimer(20);
     154    ASMIntEnable();
     155# if ARCH_BITS != 64
     156    ASMHalt();
     157# endif
     158
     159    /* Figure out which MMIO region we'll be using so we can correctly initialize FPUDS. */
    149160# if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
    150161    MmioReg.pv = BS3_FP_MAKE(0xffff, VMMDEV_TESTING_MMIO_BASE - _1M + 16);
     
    166177    }
    167178
    168     /* Second, make 100% sure we don't trap accessing the FPU state and that we can use fxsave/fxrstor. */
     179    /* Make 100% sure we don't trap accessing the FPU state and that we can use fxsave/fxrstor. */
    169180    g_usBs3TestStep = 1;
    170181    ASMSetCR0((ASMGetCR0() & ~(X86_CR0_TS | X86_CR0_EM)) | X86_CR0_MP);
    171182    ASMSetCR4(ASMGetCR4() | X86_CR4_OSFXSR /*| X86_CR4_OSXMMEEXCPT*/);
    172183
    173     /* Third, come up with a distinct state. We do that from assembly (will do FPU in R0/RC). */
     184    /* Come up with a distinct state. We do that from assembly (will do FPU in R0/RC). */
    174185    g_usBs3TestStep = 2;
    175186    Bs3MemSet(abBuf, 0x42, sizeof(abBuf));
    176187    TMPL_NM(bs3FpuState1_InitState)(pExpected, MmioReg.pb);
     188
    177189
    178190    /*
     
    180192     */
    181193    g_usBs3TestStep = 3;
    182     for (iLoop = 0; iLoop < _1M; iLoop++) /** @todo adjust counter. will hardcode for now and do timers later so day... */
     194    uStartTick = g_cBs3PitTicks;
     195    for (iLoop = 0; iLoop < _16M; iLoop++)
     196    {
    183197        CHECK_STATE(nop);
     198        if (   (iLoop & 0xffff) == 0xffff
     199            && g_cBs3PitTicks - uStartTick >= 20 * 20) /* 20 seconds*/
     200            break;
     201    }
    184202
    185203    /*
     
    190208     */
    191209    g_usBs3TestStep = 4;
    192     for (iLoop = 0; iLoop < _128K; iLoop++) /** @todo adjust counter. will hardcode for now and do timers later so day... */
     210    uStartTick = g_cBs3PitTicks;
     211    for (iLoop = 0; iLoop < _1M; iLoop++)
    193212    {
    194213        unsigned off;
     
    269288# endif
    270289        CHECK_STATE(FMUL);
     290
     291        /* check for timeout every now an then. */
     292        if (   (iLoop & 0xfff) == 0xfff
     293            && g_cBs3PitTicks - uStartTick >= 20 * 20) /* 20 seconds*/
     294            break;
    271295    }
    272296
     297    Bs3PitDisable();
    273298    return 0;
    274299}
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk

    r60774 r61389  
    9090       bs3-cmn-PagingProtect.c \
    9191       bs3-cmn-PagingSetupCanonicalTraps.c \
     92       bs3-cmn-pic-data.c \
    9293       bs3-cmn-PicMaskAll.c \
     94       bs3-cmn-PicUpdateMask.c \
     95       bs3-cmn-PicSetup.c \
     96       bs3-cmn-pit.c \
     97       bs3-cmn-PitIrqHandler.c \
    9398       bs3-cmn-RegCtxRestore.asm \
    9499       bs3-cmn-RegCtxConvertToRingX.c \
     
    158163        bs3-cmn-Trap64SetGate.c \
    159164        bs3-cmn-TrapDefaultHandler.c \
     165        bs3-cmn-TrapHandlersData.asm \
    160166        bs3-cmn-TrapPrintFrame.c \
    161167        bs3-cmn-TrapSetHandler.c \
     168        bs3-cmn-TrapSetHandlerEx.c \
    162169        bs3-cmn-TrapSetJmp.asm \
    163170        bs3-cmn-TrapSetJmpAndRestore.c \
     
    210217       bs3-c16-Trap16Generic.asm \
    211218       bs3-c16-TrapRmV86Generic.asm \
    212        bs3-c16-Trap16RmV86Data.asm \
    213219       bs3-c16-TrapRmV86Data.c \
    214220        bs3-c16-CreateHybridFarRet.asm
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-c32-Trap32Generic.asm

    r60657 r61389  
    4040BS3_EXTERN_DATA16 g_bBs3CurrentMode
    4141BS3_EXTERN_DATA16 g_uBs3CpuDetected
     42BS3_EXTERN_DATA16 g_apfnBs3TrapHandlers_c32
    4243BS3_EXTERN_SYSTEM16 Bs3Gdt
    4344TMPL_BEGIN_TEXT
     
    5859        dd Bs3Trap32DoubleFaultHandler wrt FLAT
    5960
    60 BS3_BEGIN_DATA32
    61 ;; Pointer C trap handlers.
    62 BS3_GLOBAL_DATA g_apfnBs3TrapHandlers_c32, 1024
    63         resd 256
    64 
    65 
     61
     62TMPL_BEGIN_TEXT
    6663
    6764;;
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-c64-Trap64Generic.asm

    r60657 r61389  
    3939;*********************************************************************************************************************************
    4040BS3_EXTERN_DATA16 g_bBs3CurrentMode
     41BS3_EXTERN_DATA16 g_apfnBs3TrapHandlers_c64
    4142TMPL_BEGIN_TEXT
    4243BS3_EXTERN_CMN Bs3TrapDefaultHandler
     
    5354        dd Bs3Trap64GenericEntries wrt FLAT
    5455
    55 BS3_BEGIN_DATA64
    56 ;; Pointer C trap handlers.
    57 BS3_GLOBAL_DATA g_apfnBs3TrapHandlers_c64, 2048
    58         resq 256
    59 
    60 
     56
     57TMPL_BEGIN_TEXT
    6158
    6259;;
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-rm-InitAll.c

    r60749 r61389  
    6969    }
    7070    ASMIntDisable();
    71     Bs3PicMaskAll();
     71    Bs3PicSetup();
    7272
    7373    /*
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-system-data.asm

    r60724 r61389  
    5858
    5959BS3_GLOBAL_DATA Bs3Gdte_Ldt, 16                 ; Entry 010h
    60         dw  BS3_DATA_NM(Bs3LdtEnd) - BS3_DATA_NM(Bs3Ldt)
     60        dw  BS3_DATA_NM(Bs3LdtEnd) - BS3_DATA_NM(Bs3Ldt) - 1
    6161        dw  BS3_SYSTEM16_BASE_LOW(Bs3Ldt)
    6262        db  BS3_SYSTEM16_BASE_16_23
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-autostubs.kmk

    r60774 r61389  
    5353$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3StrPrintf)
    5454$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3StrPrintfV)
     55$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3PicUpdateMask)
    5556$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3SlabFree)
    5657$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3TestSubErrorCount)
     
    7273$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3MemGuardedTestPageFree)
    7374$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3PicMaskAll)
     75$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3PicSetup)
     76$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3PitDisable)
     77$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3PitSetupAndEnablePeriodTimer)
    7478$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3PrintStr)
    7579$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3RegCtxConvertToRingX)
     
    112116$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3TrapRmV86InitEx)
    113117$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3TrapRmV86SetGate)
     118$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3TrapSetHandlerEx)
    114119$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3TrapSetJmpAndRestore)
    115120$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3TrapUnsetJmp)
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-define.h

    r60774 r61389  
    6060#define Bs3Panic BS3_CMN_MANGLER(Bs3Panic)
    6161#define Bs3PicMaskAll BS3_CMN_MANGLER(Bs3PicMaskAll)
     62#define Bs3PicSetup BS3_CMN_MANGLER(Bs3PicSetup)
     63#define Bs3PicUpdateMask BS3_CMN_MANGLER(Bs3PicUpdateMask)
     64#define Bs3PitDisable BS3_CMN_MANGLER(Bs3PitDisable)
     65#define Bs3PitSetupAndEnablePeriodTimer BS3_CMN_MANGLER(Bs3PitSetupAndEnablePeriodTimer)
    6266#define Bs3PrintChr BS3_CMN_MANGLER(Bs3PrintChr)
    6367#define Bs3Printf BS3_CMN_MANGLER(Bs3Printf)
     
    139143#define Bs3TrapRmV86SetGate BS3_CMN_MANGLER(Bs3TrapRmV86SetGate)
    140144#define Bs3TrapSetHandler BS3_CMN_MANGLER(Bs3TrapSetHandler)
     145#define Bs3TrapSetHandlerEx BS3_CMN_MANGLER(Bs3TrapSetHandlerEx)
    141146#define Bs3TrapSetJmp BS3_CMN_MANGLER(Bs3TrapSetJmp)
    142147#define Bs3TrapSetJmpAndRestore BS3_CMN_MANGLER(Bs3TrapSetJmpAndRestore)
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-undef.h

    r60774 r61389  
    6060#undef Bs3Panic
    6161#undef Bs3PicMaskAll
     62#undef Bs3PicSetup
     63#undef Bs3PicUpdateMask
     64#undef Bs3PitDisable
     65#undef Bs3PitSetupAndEnablePeriodTimer
    6266#undef Bs3PrintChr
    6367#undef Bs3Printf
     
    139143#undef Bs3TrapRmV86SetGate
    140144#undef Bs3TrapSetHandler
     145#undef Bs3TrapSetHandlerEx
    141146#undef Bs3TrapSetJmp
    142147#undef Bs3TrapSetJmpAndRestore
  • trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h

    r61385 r61389  
    628628 * Declares a BS3Kit callback function (typically static).
    629629 *
    630  * Until we outgrow BS3TEXT16, we use all near functions in 16-bit.
    631  *
    632630 * @param a_Type        The return type. */
    633631#ifdef IN_BS3KIT
     
    637635#endif
    638636
     637/** @def BS3_DECL_NEAR_CALLBACK
     638 * Declares a near BS3Kit callback function (typically static).
     639 *
     640 * 16-bit users must be in CGROUP16!
     641 *
     642 * @param a_Type        The return type. */
     643#ifdef IN_BS3KIT
     644# define BS3_DECL_NEAR_CALLBACK(a_Type) a_Type BS3_NEAR_CODE BS3_CALL
     645#else
     646# define BS3_DECL_NEAR_CALLBACK(a_Type) a_Type BS3_NEAR_CODE BS3_CALL
     647#endif
     648
    639649/**
    640650 * Constructs a common name.
     
    685695 *  \#define Bs3Gdt BS3_DATA_NM(Bs3Gdt)
    686696 *  extern X86DESC BS3_FAR_DATA Bs3Gdt
    687  * @endcode
     697f * @endcode
    688698 *
    689699 * @param   a_Name      The name of the global variable.
     
    22232233 * for a command (call #Bs3KbdWait if unsure).
    22242234 *
    2225  * @returns      The value read is returned (in al).
    2226  * @param        bCmd            The read command.
     2235 * @returns The value read is returned (in al).
     2236 * @param   bCmd            The read command.
    22272237 */
    22282238BS3_CMN_PROTO_NOSB(uint8_t, Bs3KbdRead,(uint8_t bCmd));
     
    22342244 * for a command (call #Bs3KbdWait if unsure).
    22352245 *
    2236  * @param        bCmd           The write command.
    2237  * @param        bData          The data to write.
     2246 * @param   bCmd           The write command.
     2247 * @param   bData          The data to write.
    22382248 */
    22392249BS3_CMN_PROTO_NOSB(void, Bs3KbdWrite,(uint8_t bCmd, uint8_t bData));
     
    22412251
    22422252/**
     2253 * Configures the PIC, once only.
     2254 *
     2255 * Subsequent calls to this function will not do anything.
     2256 *
     2257 * The PIC will be programmed to use IDT/IVT vectors 0x70 thru 0x7f, auto
     2258 * end-of-interrupt, and all IRQs masked.  The individual PIC users will have to
     2259 * use #Bs3PicUpdateMask unmask their IRQ once they've got all the handlers
     2260 * installed.
     2261 */
     2262BS3_CMN_PROTO_STUB(void, Bs3PicSetup,(void));
     2263
     2264/**
     2265 * Updates the PIC masks.
     2266 *
     2267 * @returns The new mask - master in low, slave in high byte.
     2268 * @param   fAndMask    Things to keep as-is. Master in low, slave in high byte.
     2269 * @param   fOrMask     Things to start masking. Ditto wrt bytes.
     2270 */
     2271BS3_CMN_PROTO_STUB(uint16_t, Bs3PicUpdateMask,(uint16_t fAndMask, uint16_t fOrMask));
     2272
     2273/**
    22432274 * Disables all IRQs on the PIC.
    22442275 */
    22452276BS3_CMN_PROTO_STUB(void, Bs3PicMaskAll,(void));
     2277
     2278
     2279/**
     2280 * Sets up the PIT for periodic callback.
     2281 *
     2282 * @param   cHzDesired      The desired Hz.  Zero means max interval length
     2283 *                          (18.2Hz).  Plase check the various PIT globals for
     2284 *                          the actual interval length.
     2285 */
     2286BS3_CMN_PROTO_STUB(void, Bs3PitSetupAndEnablePeriodTimer,(uint16_t cHzDesired));
     2287
     2288/**
     2289 * Disables the PIT if active.
     2290 */
     2291BS3_CMN_PROTO_STUB(void, Bs3PitDisable,(void));
     2292
     2293/** Nano seconds (approx) since last the PIT timer was started. */
     2294extern uint64_t volatile    g_cBs3PitNs;
     2295/** Milliseconds seconds (very approx) since last the PIT timer was started. */
     2296extern uint64_t volatile    g_cBs3PitMs;
     2297/** Number of ticks since last the PIT timer was started.  */
     2298extern uint32_t volatile    g_cBs3PitTicks;
     2299/** The current interval in nanon seconds.  */
     2300extern uint32_t             g_cBs3PitIntervalNs;
     2301/** The current interval in milliseconds (approximately).
     2302 * This is 0 if not yet started (used for checking the state internally). */
     2303extern uint16_t volatile    g_cBs3PitIntervalMs;
     2304/** The current PIT frequency (approximately).  0 if not yet started.  */
     2305extern uint16_t             g_cBs3PitIntervalHz;
    22462306
    22472307
     
    26452705 * C-style trap handler.
    26462706 *
    2647  * Upon return Bs3Trap16ResumeFrame_c16, #Bs3Trap32ResumeFrame_c32, or
    2648  * Bs3Trap64ResumeFrame_c64 will be called depending on the current template
    2649  * context.
     2707 * The caller will resume the context in @a pTrapFrame upon return.
    26502708 *
    26512709 * @param   pTrapFrame  The trap frame.  Registers can be modified.
    2652  */
    2653 typedef BS3_DECL_CALLBACK(void) FNBS3TRAPHANDLER(PBS3TRAPFRAME pTrapFrame);
     2710 * @note    The 16-bit versions must be in CGROUP16!
     2711 */
     2712typedef BS3_DECL_NEAR_CALLBACK(void) FNBS3TRAPHANDLER(PBS3TRAPFRAME pTrapFrame);
    26542713/** Pointer to a trap handler (current template context). */
    26552714typedef FNBS3TRAPHANDLER *PFNBS3TRAPHANDLER;
    26562715
     2716/** @copydoc FNBS3TRAPHANDLER */
     2717typedef FNBS3TRAPHANDLER    FNBS3TRAPHANDLER16;
     2718/** @copydoc PFNBS3TRAPHANDLER */
     2719typedef FNBS3TRAPHANDLER16 *PFNBS3TRAPHANDLER16;
     2720#if ARCH_BITS == 16
     2721/** @copydoc FNBS3TRAPHANDLER */
     2722typedef FNBS3FAR            FNBS3TRAPHANDLER32;
     2723/** @copydoc FNBS3TRAPHANDLER */
     2724typedef FNBS3FAR            FNBS3TRAPHANDLER64;
     2725#else
     2726/** @copydoc FNBS3TRAPHANDLER */
     2727typedef FNBS3TRAPHANDLER    FNBS3TRAPHANDLER32;
     2728/** @copydoc FNBS3TRAPHANDLER */
     2729typedef FNBS3TRAPHANDLER    FNBS3TRAPHANDLER64;
     2730#endif
     2731/** @copydoc PFNBS3TRAPHANDLER */
     2732typedef FNBS3TRAPHANDLER32 *PFNBS3TRAPHANDLER32;
     2733/** @copydoc PFNBS3TRAPHANDLER */
     2734typedef FNBS3TRAPHANDLER64 *PFNBS3TRAPHANDLER64;
     2735
     2736
     2737/**
     2738 * C-style trap handler, near 16-bit (CGROUP16).
     2739 *
     2740 * The caller will resume the context in @a pTrapFrame upon return.
     2741 *
     2742 * @param   pTrapFrame  The trap frame.  Registers can be modified.
     2743 */
     2744typedef BS3_DECL_NEAR_CALLBACK(void) FNBS3TRAPHANDLER16(PBS3TRAPFRAME pTrapFrame);
     2745/** Pointer to a trap handler (current template context). */
     2746typedef FNBS3TRAPHANDLER16 *PFNBS3TRAPHANDLER16;
     2747
     2748/**
     2749 * C-style trap handler, near 16-bit (CGROUP16).
     2750 *
     2751 * The caller will resume the context in @a pTrapFrame upon return.
     2752 *
     2753 * @param   pTrapFrame  The trap frame.  Registers can be modified.
     2754 */
     2755typedef BS3_DECL_CALLBACK(void) FNBS3TRAPHANDLER3264(PBS3TRAPFRAME pTrapFrame);
     2756/** Pointer to a trap handler (current template context). */
     2757typedef FNBS3TRAPHANDLER3264 *FPFNBS3TRAPHANDLER3264;
     2758
     2759
    26572760/**
    26582761 * Sets a trap handler (C/C++/assembly) for the current bitcount.
    2659  *
    2660  * When using a 32-bit IDT, only #Bs3TrapSetHandler_c32 will have any effect.
    2661  * Likewise, when using a 16-bit IDT, only Bs3TrapSetHandler_c16 will make any
    2662  * difference.  Ditto 64-bit.
    2663  *
    2664  * Rational: It's mainly a C API, can't easily mix function pointers from other
    2665  * bit counts in C.  Use assembly helpers or something if that is necessary.
    2666  * Besides, most of the real trap handling goes thru the default handler with
    2667  * help of trap records.
    26682762 *
    26692763 * @returns Previous handler.
    26702764 * @param   iIdt        The index of the IDT entry to set.
    26712765 * @param   pfnHandler  Pointer to the handler.
     2766 * @sa      Bs3TrapSetHandlerEx
    26722767 */
    26732768BS3_CMN_PROTO_STUB(PFNBS3TRAPHANDLER, Bs3TrapSetHandler,(uint8_t iIdt, PFNBS3TRAPHANDLER pfnHandler));
     2769
     2770/**
     2771 * Sets a trap handler (C/C++/assembly) for all the bitcounts.
     2772 *
     2773 * @param   iIdt            The index of the IDT and IVT entry to set.
     2774 * @param   pfnHandler16    Pointer to the 16-bit handler. (Assumes linker addresses.)
     2775 * @param   pfnHandler32    Pointer to the 32-bit handler. (Assumes linker addresses.)
     2776 * @param   pfnHandler64    Pointer to the 64-bit handler. (Assumes linker addresses.)
     2777 * @sa      Bs3TrapSetHandler
     2778 */
     2779BS3_CMN_PROTO_STUB(void, Bs3TrapSetHandlerEx,(uint8_t iIdt, PFNBS3TRAPHANDLER16 pfnHandler16,
     2780                                              PFNBS3TRAPHANDLER32 pfnHandler32, PFNBS3TRAPHANDLER64 pfnHandler64));
    26742781
    26752782/**
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