Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3-fpustate-1-template.c
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3-fpustate-1-template.c	(revision 61388)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3-fpustate-1-template.c	(revision 61389)
@@ -126,7 +126,9 @@
     X86FXSTATE BS3_FAR *pChecking = pExpected + 1;
     uint32_t            iLoop;
+    uint32_t            uStartTick;
     bool                fMmioReadback;
     bool                fReadBackError = false;
     BS3PTRUNION         MmioReg;
+
 
 # undef  CHECK_STATE
@@ -138,4 +140,5 @@
                 Bs3TestFailedF("State differs after " #a_Instr " (write) in loop #%RU32\n", iLoop); \
                 bs3FpuState1_Diff(pExpected, pChecking); \
+                Bs3PitDisable(); \
                 return 1; \
             } \
@@ -146,5 +149,13 @@
      */
 
-    /* First, figure out which MMIO region we'll be using so we can correctly initialize FPUDS. */
+    /* Make this code executable in raw-mode.  A bit tricky. */
+    ASMSetCR0(ASMGetCR0() | X86_CR0_WP);
+    Bs3PitSetupAndEnablePeriodTimer(20);
+    ASMIntEnable();
+# if ARCH_BITS != 64
+    ASMHalt();
+# endif
+
+    /* Figure out which MMIO region we'll be using so we can correctly initialize FPUDS. */
 # if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
     MmioReg.pv = BS3_FP_MAKE(0xffff, VMMDEV_TESTING_MMIO_BASE - _1M + 16);
@@ -166,13 +177,14 @@
     }
 
-    /* Second, make 100% sure we don't trap accessing the FPU state and that we can use fxsave/fxrstor. */
+    /* Make 100% sure we don't trap accessing the FPU state and that we can use fxsave/fxrstor. */
     g_usBs3TestStep = 1;
     ASMSetCR0((ASMGetCR0() & ~(X86_CR0_TS | X86_CR0_EM)) | X86_CR0_MP);
     ASMSetCR4(ASMGetCR4() | X86_CR4_OSFXSR /*| X86_CR4_OSXMMEEXCPT*/);
 
-    /* Third, come up with a distinct state. We do that from assembly (will do FPU in R0/RC). */
+    /* Come up with a distinct state. We do that from assembly (will do FPU in R0/RC). */
     g_usBs3TestStep = 2;
     Bs3MemSet(abBuf, 0x42, sizeof(abBuf));
     TMPL_NM(bs3FpuState1_InitState)(pExpected, MmioReg.pb);
+
 
     /*
@@ -180,6 +192,12 @@
      */
     g_usBs3TestStep = 3;
-    for (iLoop = 0; iLoop < _1M; iLoop++) /** @todo adjust counter. will hardcode for now and do timers later so day... */
+    uStartTick = g_cBs3PitTicks;
+    for (iLoop = 0; iLoop < _16M; iLoop++)
+    {
         CHECK_STATE(nop);
+        if (   (iLoop & 0xffff) == 0xffff
+            && g_cBs3PitTicks - uStartTick >= 20 * 20) /* 20 seconds*/
+            break;
+    }
 
     /*
@@ -190,5 +208,6 @@
      */
     g_usBs3TestStep = 4;
-    for (iLoop = 0; iLoop < _128K; iLoop++) /** @todo adjust counter. will hardcode for now and do timers later so day... */
+    uStartTick = g_cBs3PitTicks;
+    for (iLoop = 0; iLoop < _1M; iLoop++)
     {
         unsigned off;
@@ -269,6 +288,12 @@
 # endif
         CHECK_STATE(FMUL);
+
+        /* check for timeout every now an then. */
+        if (   (iLoop & 0xfff) == 0xfff
+            && g_cBs3PitTicks - uStartTick >= 20 * 20) /* 20 seconds*/
+            break;
     }
 
+    Bs3PitDisable();
     return 0;
 }
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk	(revision 61388)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk	(revision 61389)
@@ -90,5 +90,10 @@
        bs3-cmn-PagingProtect.c \
        bs3-cmn-PagingSetupCanonicalTraps.c \
+       bs3-cmn-pic-data.c \
        bs3-cmn-PicMaskAll.c \
+       bs3-cmn-PicUpdateMask.c \
+       bs3-cmn-PicSetup.c \
+       bs3-cmn-pit.c \
+       bs3-cmn-PitIrqHandler.c \
        bs3-cmn-RegCtxRestore.asm \
        bs3-cmn-RegCtxConvertToRingX.c \
@@ -158,6 +163,8 @@
 	bs3-cmn-Trap64SetGate.c \
 	bs3-cmn-TrapDefaultHandler.c \
+	bs3-cmn-TrapHandlersData.asm \
 	bs3-cmn-TrapPrintFrame.c \
 	bs3-cmn-TrapSetHandler.c \
+	bs3-cmn-TrapSetHandlerEx.c \
 	bs3-cmn-TrapSetJmp.asm \
 	bs3-cmn-TrapSetJmpAndRestore.c \
@@ -210,5 +217,4 @@
        bs3-c16-Trap16Generic.asm \
        bs3-c16-TrapRmV86Generic.asm \
-       bs3-c16-Trap16RmV86Data.asm \
        bs3-c16-TrapRmV86Data.c \
 	bs3-c16-CreateHybridFarRet.asm
Index: unk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-c16-Trap16RmV86Data.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-c16-Trap16RmV86Data.asm	(revision 61388)
+++ 	(revision )
@@ -1,42 +1,0 @@
-; $Id$
-;; @file
-; BS3Kit - Trap, data shared between real, virtual 8086, and 16-bit protected mode.
-;
-
-;
-; Copyright (C) 2007-2016 Oracle Corporation
-;
-; This file is part of VirtualBox Open Source Edition (OSE), as
-; available from http://www.virtualbox.org. This file is free software;
-; you can redistribute it and/or modify it under the terms of the GNU
-; General Public License (GPL) as published by the Free Software
-; Foundation, in version 2 as it comes in the "COPYING" file of the
-; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
-; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
-;
-; The contents of this file may alternatively be used under the terms
-; of the Common Development and Distribution License Version 1.0
-; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
-; VirtualBox OSE distribution, in which case the provisions of the
-; CDDL are applicable instead of those of the GPL.
-;
-; You may elect to license modified versions of this file under the
-; terms and conditions of either the GPL or the CDDL or both.
-;
-
-;*********************************************************************************************************************************
-;*  Header Files                                                                                                                 *
-;*********************************************************************************************************************************
-%include "bs3kit-template-header.mac"
-
-%ifndef TMPL_16BIT
- %error "16-bit only template"
-%endif
-
-
-BS3_BEGIN_DATA16
-;; Pointer C trap handlers (CGROUP16).
-BS3_GLOBAL_DATA g_apfnBs3TrapHandlers_c16, 512
-        resw 256
-
-
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-c32-Trap32Generic.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-c32-Trap32Generic.asm	(revision 61388)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-c32-Trap32Generic.asm	(revision 61389)
@@ -40,4 +40,5 @@
 BS3_EXTERN_DATA16 g_bBs3CurrentMode
 BS3_EXTERN_DATA16 g_uBs3CpuDetected
+BS3_EXTERN_DATA16 g_apfnBs3TrapHandlers_c32
 BS3_EXTERN_SYSTEM16 Bs3Gdt
 TMPL_BEGIN_TEXT
@@ -58,10 +59,6 @@
         dd Bs3Trap32DoubleFaultHandler wrt FLAT
 
-BS3_BEGIN_DATA32
-;; Pointer C trap handlers.
-BS3_GLOBAL_DATA g_apfnBs3TrapHandlers_c32, 1024
-        resd 256
-
-
+
+TMPL_BEGIN_TEXT
 
 ;;
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-c64-Trap64Generic.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-c64-Trap64Generic.asm	(revision 61388)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-c64-Trap64Generic.asm	(revision 61389)
@@ -39,4 +39,5 @@
 ;*********************************************************************************************************************************
 BS3_EXTERN_DATA16 g_bBs3CurrentMode
+BS3_EXTERN_DATA16 g_apfnBs3TrapHandlers_c64
 TMPL_BEGIN_TEXT
 BS3_EXTERN_CMN Bs3TrapDefaultHandler
@@ -53,10 +54,6 @@
         dd Bs3Trap64GenericEntries wrt FLAT
 
-BS3_BEGIN_DATA64
-;; Pointer C trap handlers.
-BS3_GLOBAL_DATA g_apfnBs3TrapHandlers_c64, 2048
-        resq 256
-
-
+
+TMPL_BEGIN_TEXT
 
 ;;
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-PicSetup.c
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-PicSetup.c	(revision 61389)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-PicSetup.c	(revision 61389)
@@ -0,0 +1,79 @@
+/* $Id$ */
+/** @file
+ * BS3Kit - PIC Setup.
+ */
+
+/*
+ * Copyright (C) 2007-2016 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+/*********************************************************************************************************************************
+*   Header Files                                                                                                                 *
+*********************************************************************************************************************************/
+#include "bs3kit-template-header.h"
+#include <iprt/asm-amd64-x86.h>
+#include "bs3-cmn-pic.h"
+
+
+
+/**
+ * Configures the PIC, once only.
+ *
+ * Subsequent calls to this function will not do anything.
+ *
+ * The PIC will be programmed to use IDT/IVT vectors 0x70 thru 0x7f, auto
+ * end-of-interrupt, and all IRQs masked.  The individual PIC users will have to
+ * use #Bs3PicUpdateMask unmask their IRQ once they've got all the handlers
+ * installed.
+ */
+#undef Bs3PicSetup
+BS3_CMN_DEF(void, Bs3PicSetup,(void))
+{
+    /*
+     * The first call configures the PIC to send interrupts to vectors 0x70 thru 0x7f,
+     * masking all of them.  Things producing IRQs is responsible for configure their
+     * handlers and then(!) use Bs3PicUpdateMask to unmask the IRQ.
+     */
+    if (!g_fBs3PicConfigured)
+    {
+        g_fBs3PicConfigured = true;
+
+        /* Start init. */
+        ASMOutU8(BS3_PIC_PORT_MASTER, BS3_PIC_CMD_INIT | BS3_PIC_CMD_INIT_F_4STEP);
+        ASMOutU8(BS3_PIC_PORT_SLAVE,  BS3_PIC_CMD_INIT | BS3_PIC_CMD_INIT_F_4STEP);
+
+        /* Set IRQ base. */
+        ASMOutU8(BS3_PIC_PORT_MASTER + 1, 0x70);
+        ASMOutU8(BS3_PIC_PORT_SLAVE  + 1, 0x78);
+
+        /* Dunno. */
+        ASMOutU8(BS3_PIC_PORT_MASTER + 1, 4);
+        ASMOutU8(BS3_PIC_PORT_SLAVE  + 1, 2);
+
+        /* Set IRQ base. */
+        ASMOutU8(BS3_PIC_PORT_MASTER + 1, BS3_PIC_I4_F_AUTO_EOI);
+        ASMOutU8(BS3_PIC_PORT_SLAVE  + 1, BS3_PIC_I4_F_AUTO_EOI);
+
+        /* Mask everything. */
+        ASMOutU8(BS3_PIC_PORT_MASTER + 1, UINT8_MAX);
+        ASMOutU8(BS3_PIC_PORT_SLAVE  + 1, UINT8_MAX);
+    }
+}
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-PicUpdateMask.c
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-PicUpdateMask.c	(revision 61389)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-PicUpdateMask.c	(revision 61389)
@@ -0,0 +1,44 @@
+/* $Id$ */
+/** @file
+ * BS3Kit - PIC Setup.
+ */
+
+/*
+ * Copyright (C) 2007-2016 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+/*********************************************************************************************************************************
+*   Header Files                                                                                                                 *
+*********************************************************************************************************************************/
+#include "bs3kit-template-header.h"
+#include <iprt/asm-amd64-x86.h>
+#include "bs3-cmn-pic.h"
+
+
+#undef Bs3PicUpdateMask
+BS3_CMN_DEF(uint16_t, Bs3PicUpdateMask,(uint16_t fAndMask, uint16_t fOrMask))
+{
+    uint8_t bPic0Mask = (ASMInU8(BS3_PIC_PORT_MASTER + 1) & (uint8_t)fAndMask) | (uint8_t)fOrMask;
+    uint8_t bPic1Mask = (ASMInU8(BS3_PIC_PORT_SLAVE  + 1) & (fAndMask >> 8))   | (fOrMask >> 8);
+    ASMOutU8(BS3_PIC_PORT_SLAVE  + 1, bPic1Mask);
+    ASMOutU8(BS3_PIC_PORT_MASTER + 1, bPic0Mask);
+    return RT_MAKE_U16(bPic0Mask, bPic1Mask);
+}
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-PitIrqHandler.c
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-PitIrqHandler.c	(revision 61389)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-PitIrqHandler.c	(revision 61389)
@@ -0,0 +1,66 @@
+/* $Id$ */
+/** @file
+ * BS3Kit - The PIT IRQ Handler and associated data..
+ */
+
+/*
+ * Copyright (C) 2007-2016 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+/*********************************************************************************************************************************
+*   Header Files                                                                                                                 *
+*********************************************************************************************************************************/
+#include "bs3kit-template-header.h"
+#include <iprt/asm-amd64-x86.h>
+
+
+/*********************************************************************************************************************************
+*   Global Variables                                                                                                             *
+*********************************************************************************************************************************/
+#if ARCH_BITS == 16
+/** Nano seconds (approx) since last the PIT timer was started. */
+uint64_t volatile   g_cBs3PitNs    = 0;
+/** Milliseconds seconds (very approx) since last the PIT timer was started. */
+uint64_t volatile   g_cBs3PitMs    = 0;
+/** Number of ticks since last the PIT timer was started.  */
+uint32_t volatile   g_cBs3PitTicks = 0;
+/** The current interval in nanon seconds.  */
+uint32_t            g_cBs3PitIntervalNs = 0;
+/** The current interval in milliseconds (approximately).
+ * This is 0 if not yet started (used for checking the state internally). */
+uint16_t volatile   g_cBs3PitIntervalMs = 0;
+/** The current PIT frequency (approximately).  0 if not yet started.  */
+uint16_t            g_cBs3PitIntervalHz = 0;
+#endif
+
+
+BS3_DECL_NEAR_CALLBACK(void) BS3_CMN_NM(bs3PitIrqHandler)(PBS3TRAPFRAME pTrapFrame)
+{
+    uint16_t cMsIntercal = g_cBs3PitIntervalMs;
+    if (cMsIntercal)
+    {
+        g_cBs3PitMs += cMsIntercal;
+        g_cBs3PitNs += g_cBs3PitIntervalNs;
+        g_cBs3PitTicks++;
+    }
+    NOREF(pTrapFrame);
+    ASMOutU8(0x20, 0x20); /** @todo function! */
+}
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-TrapHandlersData.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-TrapHandlersData.asm	(revision 61389)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-TrapHandlersData.asm	(revision 61389)
@@ -0,0 +1,40 @@
+; $Id$
+;; @file
+; BS3Kit - Per bit-count trap data.
+;
+
+;
+; Copyright (C) 2007-2016 Oracle Corporation
+;
+; This file is part of VirtualBox Open Source Edition (OSE), as
+; available from http://www.virtualbox.org. This file is free software;
+; you can redistribute it and/or modify it under the terms of the GNU
+; General Public License (GPL) as published by the Free Software
+; Foundation, in version 2 as it comes in the "COPYING" file of the
+; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+;
+; The contents of this file may alternatively be used under the terms
+; of the Common Development and Distribution License Version 1.0
+; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+; VirtualBox OSE distribution, in which case the provisions of the
+; CDDL are applicable instead of those of the GPL.
+;
+; You may elect to license modified versions of this file under the
+; terms and conditions of either the GPL or the CDDL or both.
+;
+
+;*********************************************************************************************************************************
+;*  Header Files                                                                                                                 *
+;*********************************************************************************************************************************
+%include "bs3kit-template-header.mac"
+
+
+
+BS3_BEGIN_DATA16
+;; Pointer C trap handlers.
+;; Note! The 16-bit ones are all near so we can share them between real, v86 and prot mode.
+;; Note! Must be in 16-bit data because of BS3TrapSetHandlerEx.
+BS3_GLOBAL_NAME_EX BS3_CMN_NM(g_apfnBs3TrapHandlers), , 256 * xCB
+        resb 256 * xCB
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-TrapSetHandlerEx.c
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-TrapSetHandlerEx.c	(revision 61389)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-TrapSetHandlerEx.c	(revision 61389)
@@ -0,0 +1,60 @@
+/* $Id$ */
+/** @file
+ * BS3Kit - Bs3Trap32SetHandlerEx
+ */
+
+/*
+ * Copyright (C) 2007-2016 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+/*********************************************************************************************************************************
+*   Header Files                                                                                                                 *
+*********************************************************************************************************************************/
+#include "bs3kit-template-header.h"
+#include <iprt/asm-amd64-x86.h>
+
+
+/*********************************************************************************************************************************
+*   External Symbols                                                                                                             *
+*********************************************************************************************************************************/
+extern uint16_t     BS3_DATA_NM(g_apfnBs3TrapHandlers_c16)[256];
+extern uint32_t     BS3_DATA_NM(g_apfnBs3TrapHandlers_c32)[256];
+extern uint64_t     BS3_DATA_NM(g_apfnBs3TrapHandlers_c64)[256];
+
+
+#undef Bs3TrapSetHandlerEx
+BS3_CMN_DEF(void, Bs3TrapSetHandlerEx,(uint8_t iIdt, PFNBS3TRAPHANDLER16 pfnHandler16,
+                                       PFNBS3TRAPHANDLER32 pfnHandler32, PFNBS3TRAPHANDLER64 pfnHandler64))
+{
+    RTCCUINTREG fFlags = ASMIntDisableFlags();
+#if ARCH_BITS == 16
+    /* Far real mode pointers as input. */
+    g_apfnBs3TrapHandlers_c16[iIdt]  = (uint16_t)pfnHandler16;
+    g_apfnBs3TrapHandlers_c32[iIdt]  = Bs3SelRealModeCodeToFlat((PFNBS3FARADDRCONV)pfnHandler32);
+    g_apfnBs3TrapHandlers_c64[iIdt]  = Bs3SelRealModeCodeToFlat((PFNBS3FARADDRCONV)pfnHandler64);
+#else
+    /* Flat pointers as input. */
+    g_apfnBs3TrapHandlers_c16[iIdt]  = (uint16_t)Bs3SelFlatCodeToProtFar16((uintptr_t)pfnHandler16);
+    g_apfnBs3TrapHandlers_c32[iIdt]  = (uint32_t)(uintptr_t)pfnHandler32;
+    g_apfnBs3TrapHandlers_c64[iIdt]  = (uintptr_t)pfnHandler64;
+#endif
+    ASMSetFlags(fFlags);
+}
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-pic-data.c
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-pic-data.c	(revision 61389)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-pic-data.c	(revision 61389)
@@ -0,0 +1,41 @@
+/* $Id$ */
+/** @file
+ * BS3Kit - PIC Data.
+ */
+
+/*
+ * Copyright (C) 2007-2016 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+/*********************************************************************************************************************************
+*   Header Files                                                                                                                 *
+*********************************************************************************************************************************/
+#include "bs3kit-template-header.h"
+#include "bs3-cmn-pic.h"
+
+
+/*********************************************************************************************************************************
+*   Global Variables                                                                                                             *
+*********************************************************************************************************************************/
+#if ARCH_BITS == 16
+/** Set by the first call to Bs3PicSetup. */
+bool g_fBs3PicConfigured = false;
+#endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-pic.h
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-pic.h	(revision 61389)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-pic.h	(revision 61389)
@@ -0,0 +1,57 @@
+/* $Id$ */
+/** @file
+ * BS3Kit - Internal PIC Defines, Variables and Functions.
+ */
+
+/*
+ * Copyright (C) 2007-2016 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+#ifndef ___bs3_cmn_pic_h
+#define ___bs3_cmn_pic_h
+
+#include "bs3kit.h"
+
+
+/** The master PIC port (base).   */
+#define BS3_PIC_PORT_MASTER         UINT8_C(0x20)
+/** The slave PIC port (base).   */
+#define BS3_PIC_PORT_SLAVE          UINT8_C(0xa0)
+
+/** The init command. */
+#define BS3_PIC_CMD_INIT            UINT8_C(0x10)
+/** 4th init step option for the init command.   */
+#define BS3_PIC_CMD_INIT_F_4STEP    UINT8_C(0x01)
+
+/** Auto end of interrupt flag for the 4th init step. */
+#define BS3_PIC_I4_F_AUTO_EOI       UINT8_C(0x01)
+
+
+RT_C_DECLS_BEGIN
+
+extern bool g_fBs3PicConfigured;
+
+RT_C_DECLS_END
+
+
+#include "bs3kit-mangling-code.h"
+
+#endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-pit.c
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-pit.c	(revision 61389)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-pit.c	(revision 61389)
@@ -0,0 +1,155 @@
+/* $Id$ */
+/** @file
+ * BS3Kit - PIT Setup and Disable code.
+ */
+
+/*
+ * Copyright (C) 2007-2016 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+/*********************************************************************************************************************************
+*   Header Files                                                                                                                 *
+*********************************************************************************************************************************/
+#include "bs3kit-template-header.h"
+#include <iprt/asm-amd64-x86.h>
+
+
+/*********************************************************************************************************************************
+*   Defined Constants And Macros                                                                                                 *
+*********************************************************************************************************************************/
+#define BS3_PIT_PORT_CMD        0x43
+#define BS3_PIT_PORT_CH0_DATA   0x40
+#define BS3_PIT_HZ              UINT32_C(1193182)
+
+
+/*********************************************************************************************************************************
+*   External Symbols                                                                                                             *
+*********************************************************************************************************************************/
+extern FNBS3TRAPHANDLER16 bs3PitIrqHandler_c16;
+extern FNBS3TRAPHANDLER32 bs3PitIrqHandler_c32;
+extern FNBS3TRAPHANDLER64 bs3PitIrqHandler_c64;
+
+
+#undef Bs3PitSetupAndEnablePeriodTimer
+BS3_CMN_DEF(void, Bs3PitSetupAndEnablePeriodTimer,(uint16_t cHzDesired))
+{
+    RTCCUINTREG fSaved;
+    uint16_t    cCount;
+    uint16_t    cMsInterval;
+    uint32_t    cNsInterval;
+
+    /*
+     * Disable the PIT and make sure we've configured the IRQ handlers.
+     */
+    Bs3PitDisable();
+    Bs3PicSetup();
+    Bs3TrapSetHandlerEx(0x70, bs3PitIrqHandler_c16, bs3PitIrqHandler_c32, bs3PitIrqHandler_c64);
+
+    /*
+     * Calculate an interval.
+     */
+    if (cHzDesired <= 18)
+    {
+        cCount      = 0;                    /* 1193182 / 65536 = 18.206512451171875  Hz */
+        cHzDesired  = 18;
+        cNsInterval = UINT32_C(54925401);   /* 65536 / 1193182 = 0.054925401154224586022920225078823 seconds */
+        cMsInterval = 55;
+    }
+    else
+    {
+        cCount      = BS3_PIT_HZ / cHzDesired;
+        cHzDesired  = BS3_PIT_HZ / cCount;
+        /* 1s/1193182 = 0.000 000 838 095 110 38550698887512550474278 */
+#if ARCH_BITS == 64
+        cNsInterval = cCount * UINT64_C(838095110) / 1000000;
+#elif ARCH_BITS == 32
+        cNsInterval = cCount * UINT32_C(8381) / 10;
+#else
+        cNsInterval = cCount * 838;
+#endif
+        if (cCount <= 1194)
+            cMsInterval = 1; /* Must not be zero! */
+        else
+            cMsInterval = cCount / 1194;
+    }
+
+
+    /*
+     * Do the reprogramming.
+     */
+    fSaved = ASMIntDisableFlags();
+    ASMOutU8(BS3_PIT_PORT_CMD,
+               (0 << 6) /* select:      channel 0 */
+             | (3 << 4) /* access mode: lobyte/hibyte */
+             | (2 << 1) /* operation:   Mode 2 */
+             | 0        /* binary mode */
+             );
+    ASMOutU8(BS3_PIT_PORT_CH0_DATA, (uint8_t)cCount);
+    ASMOutU8(BS3_PIT_PORT_CH0_DATA, (uint8_t)(cCount >> 8));
+
+    g_cBs3PitIntervalNs = cNsInterval;
+    g_cBs3PitIntervalHz = cHzDesired;
+    g_cBs3PitIntervalMs = cMsInterval;
+
+    Bs3PicUpdateMask(UINT16_C(0xfffe), 0);
+
+    ASMSetFlags(fSaved);
+}
+
+
+#undef Bs3PitDisable
+BS3_CMN_DEF(void, Bs3PitDisable,(void))
+{
+    if (g_cBs3PitIntervalMs != 0)
+    {
+        RTCCUINTREG fSaved = ASMIntDisableFlags();
+
+        /*
+         * Not entirely sure what's the best way to do this, but let's try reprogram
+         * it to a no-reload mode like 0 and set the count to 1.
+         */
+        g_cBs3PitIntervalMs = 0;
+        ASMOutU8(BS3_PIT_PORT_CMD,
+                   (0 << 6) /* select:      channel 0 */
+                 | (1 << 4) /* access mode: lobyte */
+                 | (0 << 1) /* operation:   Mode 0 */
+                 | 0        /* binary mode */
+                 );
+        ASMOutU8(BS3_PIT_PORT_CH0_DATA, (uint8_t)1);
+
+        /*
+         * Then mask the PIT IRQ on the PIC.
+         */
+        Bs3PicUpdateMask(UINT16_C(0xffff), 1);
+
+        ASMSetFlags(fSaved);
+    }
+
+    /*
+     * Reset all the values.
+     */
+    g_cBs3PitNs         = 0;
+    g_cBs3PitMs         = 0;
+    g_cBs3PitTicks      = 0;
+    g_cBs3PitIntervalNs = 0;
+    g_cBs3PitIntervalMs = 0;
+    g_cBs3PitIntervalHz = 0;
+}
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-rm-InitAll.c
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-rm-InitAll.c	(revision 61388)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-rm-InitAll.c	(revision 61389)
@@ -69,5 +69,5 @@
     }
     ASMIntDisable();
-    Bs3PicMaskAll();
+    Bs3PicSetup();
 
     /*
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-system-data.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-system-data.asm	(revision 61388)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-system-data.asm	(revision 61389)
@@ -58,5 +58,5 @@
 
 BS3_GLOBAL_DATA Bs3Gdte_Ldt, 16                 ; Entry 010h
-        dw  BS3_DATA_NM(Bs3LdtEnd) - BS3_DATA_NM(Bs3Ldt)
+        dw  BS3_DATA_NM(Bs3LdtEnd) - BS3_DATA_NM(Bs3Ldt) - 1
         dw  BS3_SYSTEM16_BASE_LOW(Bs3Ldt)
         db  BS3_SYSTEM16_BASE_16_23
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-autostubs.kmk
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-autostubs.kmk	(revision 61388)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-autostubs.kmk	(revision 61389)
@@ -53,4 +53,5 @@
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3StrPrintf)
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3StrPrintfV)
+$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3PicUpdateMask)
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3SlabFree)
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3TestSubErrorCount)
@@ -72,4 +73,7 @@
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3MemGuardedTestPageFree)
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3PicMaskAll)
+$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3PicSetup)
+$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3PitDisable)
+$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3PitSetupAndEnablePeriodTimer)
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3PrintStr)
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3RegCtxConvertToRingX)
@@ -112,4 +116,5 @@
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3TrapRmV86InitEx)
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3TrapRmV86SetGate)
+$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3TrapSetHandlerEx)
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3TrapSetJmpAndRestore)
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3TrapUnsetJmp)
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-define.h
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-define.h	(revision 61388)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-define.h	(revision 61389)
@@ -60,4 +60,8 @@
 #define Bs3Panic BS3_CMN_MANGLER(Bs3Panic)
 #define Bs3PicMaskAll BS3_CMN_MANGLER(Bs3PicMaskAll)
+#define Bs3PicSetup BS3_CMN_MANGLER(Bs3PicSetup)
+#define Bs3PicUpdateMask BS3_CMN_MANGLER(Bs3PicUpdateMask)
+#define Bs3PitDisable BS3_CMN_MANGLER(Bs3PitDisable)
+#define Bs3PitSetupAndEnablePeriodTimer BS3_CMN_MANGLER(Bs3PitSetupAndEnablePeriodTimer)
 #define Bs3PrintChr BS3_CMN_MANGLER(Bs3PrintChr)
 #define Bs3Printf BS3_CMN_MANGLER(Bs3Printf)
@@ -139,4 +143,5 @@
 #define Bs3TrapRmV86SetGate BS3_CMN_MANGLER(Bs3TrapRmV86SetGate)
 #define Bs3TrapSetHandler BS3_CMN_MANGLER(Bs3TrapSetHandler)
+#define Bs3TrapSetHandlerEx BS3_CMN_MANGLER(Bs3TrapSetHandlerEx)
 #define Bs3TrapSetJmp BS3_CMN_MANGLER(Bs3TrapSetJmp)
 #define Bs3TrapSetJmpAndRestore BS3_CMN_MANGLER(Bs3TrapSetJmpAndRestore)
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-undef.h
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-undef.h	(revision 61388)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-undef.h	(revision 61389)
@@ -60,4 +60,8 @@
 #undef Bs3Panic
 #undef Bs3PicMaskAll
+#undef Bs3PicSetup
+#undef Bs3PicUpdateMask
+#undef Bs3PitDisable
+#undef Bs3PitSetupAndEnablePeriodTimer
 #undef Bs3PrintChr
 #undef Bs3Printf
@@ -139,4 +143,5 @@
 #undef Bs3TrapRmV86SetGate
 #undef Bs3TrapSetHandler
+#undef Bs3TrapSetHandlerEx
 #undef Bs3TrapSetJmp
 #undef Bs3TrapSetJmpAndRestore
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h	(revision 61388)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h	(revision 61389)
@@ -628,6 +628,4 @@
  * Declares a BS3Kit callback function (typically static).
  *
- * Until we outgrow BS3TEXT16, we use all near functions in 16-bit.
- *
  * @param a_Type        The return type. */
 #ifdef IN_BS3KIT
@@ -637,4 +635,16 @@
 #endif
 
+/** @def BS3_DECL_NEAR_CALLBACK
+ * Declares a near BS3Kit callback function (typically static).
+ *
+ * 16-bit users must be in CGROUP16!
+ *
+ * @param a_Type        The return type. */
+#ifdef IN_BS3KIT
+# define BS3_DECL_NEAR_CALLBACK(a_Type) a_Type BS3_NEAR_CODE BS3_CALL
+#else
+# define BS3_DECL_NEAR_CALLBACK(a_Type) a_Type BS3_NEAR_CODE BS3_CALL
+#endif
+
 /**
  * Constructs a common name.
@@ -685,5 +695,5 @@
  *  \#define Bs3Gdt BS3_DATA_NM(Bs3Gdt)
  *  extern X86DESC BS3_FAR_DATA Bs3Gdt
- * @endcode
+f * @endcode
  *
  * @param   a_Name      The name of the global variable.
@@ -2223,6 +2233,6 @@
  * for a command (call #Bs3KbdWait if unsure).
  *
- * @returns      The value read is returned (in al).
- * @param        bCmd            The read command.
+ * @returns The value read is returned (in al).
+ * @param   bCmd            The read command.
  */
 BS3_CMN_PROTO_NOSB(uint8_t, Bs3KbdRead,(uint8_t bCmd));
@@ -2234,6 +2244,6 @@
  * for a command (call #Bs3KbdWait if unsure).
  *
- * @param        bCmd           The write command.
- * @param        bData          The data to write.
+ * @param   bCmd           The write command.
+ * @param   bData          The data to write.
  */
 BS3_CMN_PROTO_NOSB(void, Bs3KbdWrite,(uint8_t bCmd, uint8_t bData));
@@ -2241,7 +2251,57 @@
 
 /**
+ * Configures the PIC, once only.
+ *
+ * Subsequent calls to this function will not do anything.
+ *
+ * The PIC will be programmed to use IDT/IVT vectors 0x70 thru 0x7f, auto
+ * end-of-interrupt, and all IRQs masked.  The individual PIC users will have to
+ * use #Bs3PicUpdateMask unmask their IRQ once they've got all the handlers
+ * installed.
+ */
+BS3_CMN_PROTO_STUB(void, Bs3PicSetup,(void));
+
+/**
+ * Updates the PIC masks.
+ *
+ * @returns The new mask - master in low, slave in high byte.
+ * @param   fAndMask    Things to keep as-is. Master in low, slave in high byte.
+ * @param   fOrMask     Things to start masking. Ditto wrt bytes.
+ */
+BS3_CMN_PROTO_STUB(uint16_t, Bs3PicUpdateMask,(uint16_t fAndMask, uint16_t fOrMask));
+
+/**
  * Disables all IRQs on the PIC.
  */
 BS3_CMN_PROTO_STUB(void, Bs3PicMaskAll,(void));
+
+
+/**
+ * Sets up the PIT for periodic callback.
+ *
+ * @param   cHzDesired      The desired Hz.  Zero means max interval length
+ *                          (18.2Hz).  Plase check the various PIT globals for
+ *                          the actual interval length.
+ */
+BS3_CMN_PROTO_STUB(void, Bs3PitSetupAndEnablePeriodTimer,(uint16_t cHzDesired));
+
+/**
+ * Disables the PIT if active.
+ */
+BS3_CMN_PROTO_STUB(void, Bs3PitDisable,(void));
+
+/** Nano seconds (approx) since last the PIT timer was started. */
+extern uint64_t volatile    g_cBs3PitNs;
+/** Milliseconds seconds (very approx) since last the PIT timer was started. */
+extern uint64_t volatile    g_cBs3PitMs;
+/** Number of ticks since last the PIT timer was started.  */
+extern uint32_t volatile    g_cBs3PitTicks;
+/** The current interval in nanon seconds.  */
+extern uint32_t             g_cBs3PitIntervalNs;
+/** The current interval in milliseconds (approximately).
+ * This is 0 if not yet started (used for checking the state internally). */
+extern uint16_t volatile    g_cBs3PitIntervalMs;
+/** The current PIT frequency (approximately).  0 if not yet started.  */
+extern uint16_t             g_cBs3PitIntervalHz;
 
 
@@ -2645,31 +2705,78 @@
  * C-style trap handler.
  *
- * Upon return Bs3Trap16ResumeFrame_c16, #Bs3Trap32ResumeFrame_c32, or
- * Bs3Trap64ResumeFrame_c64 will be called depending on the current template
- * context.
+ * The caller will resume the context in @a pTrapFrame upon return.
  *
  * @param   pTrapFrame  The trap frame.  Registers can be modified.
- */
-typedef BS3_DECL_CALLBACK(void) FNBS3TRAPHANDLER(PBS3TRAPFRAME pTrapFrame);
+ * @note    The 16-bit versions must be in CGROUP16!
+ */
+typedef BS3_DECL_NEAR_CALLBACK(void) FNBS3TRAPHANDLER(PBS3TRAPFRAME pTrapFrame);
 /** Pointer to a trap handler (current template context). */
 typedef FNBS3TRAPHANDLER *PFNBS3TRAPHANDLER;
 
+/** @copydoc FNBS3TRAPHANDLER */
+typedef FNBS3TRAPHANDLER    FNBS3TRAPHANDLER16;
+/** @copydoc PFNBS3TRAPHANDLER */
+typedef FNBS3TRAPHANDLER16 *PFNBS3TRAPHANDLER16;
+#if ARCH_BITS == 16
+/** @copydoc FNBS3TRAPHANDLER */
+typedef FNBS3FAR            FNBS3TRAPHANDLER32;
+/** @copydoc FNBS3TRAPHANDLER */
+typedef FNBS3FAR            FNBS3TRAPHANDLER64;
+#else
+/** @copydoc FNBS3TRAPHANDLER */
+typedef FNBS3TRAPHANDLER    FNBS3TRAPHANDLER32;
+/** @copydoc FNBS3TRAPHANDLER */
+typedef FNBS3TRAPHANDLER    FNBS3TRAPHANDLER64;
+#endif
+/** @copydoc PFNBS3TRAPHANDLER */
+typedef FNBS3TRAPHANDLER32 *PFNBS3TRAPHANDLER32;
+/** @copydoc PFNBS3TRAPHANDLER */
+typedef FNBS3TRAPHANDLER64 *PFNBS3TRAPHANDLER64;
+
+
+/**
+ * C-style trap handler, near 16-bit (CGROUP16).
+ *
+ * The caller will resume the context in @a pTrapFrame upon return.
+ *
+ * @param   pTrapFrame  The trap frame.  Registers can be modified.
+ */
+typedef BS3_DECL_NEAR_CALLBACK(void) FNBS3TRAPHANDLER16(PBS3TRAPFRAME pTrapFrame);
+/** Pointer to a trap handler (current template context). */
+typedef FNBS3TRAPHANDLER16 *PFNBS3TRAPHANDLER16;
+
+/**
+ * C-style trap handler, near 16-bit (CGROUP16).
+ *
+ * The caller will resume the context in @a pTrapFrame upon return.
+ *
+ * @param   pTrapFrame  The trap frame.  Registers can be modified.
+ */
+typedef BS3_DECL_CALLBACK(void) FNBS3TRAPHANDLER3264(PBS3TRAPFRAME pTrapFrame);
+/** Pointer to a trap handler (current template context). */
+typedef FNBS3TRAPHANDLER3264 *FPFNBS3TRAPHANDLER3264;
+
+
 /**
  * Sets a trap handler (C/C++/assembly) for the current bitcount.
- *
- * When using a 32-bit IDT, only #Bs3TrapSetHandler_c32 will have any effect.
- * Likewise, when using a 16-bit IDT, only Bs3TrapSetHandler_c16 will make any
- * difference.  Ditto 64-bit.
- *
- * Rational: It's mainly a C API, can't easily mix function pointers from other
- * bit counts in C.  Use assembly helpers or something if that is necessary.
- * Besides, most of the real trap handling goes thru the default handler with
- * help of trap records.
  *
  * @returns Previous handler.
  * @param   iIdt        The index of the IDT entry to set.
  * @param   pfnHandler  Pointer to the handler.
+ * @sa      Bs3TrapSetHandlerEx
  */
 BS3_CMN_PROTO_STUB(PFNBS3TRAPHANDLER, Bs3TrapSetHandler,(uint8_t iIdt, PFNBS3TRAPHANDLER pfnHandler));
+
+/**
+ * Sets a trap handler (C/C++/assembly) for all the bitcounts.
+ *
+ * @param   iIdt            The index of the IDT and IVT entry to set.
+ * @param   pfnHandler16    Pointer to the 16-bit handler. (Assumes linker addresses.)
+ * @param   pfnHandler32    Pointer to the 32-bit handler. (Assumes linker addresses.)
+ * @param   pfnHandler64    Pointer to the 64-bit handler. (Assumes linker addresses.)
+ * @sa      Bs3TrapSetHandler
+ */
+BS3_CMN_PROTO_STUB(void, Bs3TrapSetHandlerEx,(uint8_t iIdt, PFNBS3TRAPHANDLER16 pfnHandler16,
+                                              PFNBS3TRAPHANDLER32 pfnHandler32, PFNBS3TRAPHANDLER64 pfnHandler64));
 
 /**
