Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-asm.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-asm.asm	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-asm.asm	(revision 60676)
@@ -37,5 +37,5 @@
 BS3_BEGIN_DATA16
 BS3_GLOBAL_DATA g_bs3CpuBasic2_ud2_FlatAddr, 4
-        dd  bs3CpuBasic2_ud2 wrt FLAT
+        dd  _bs3CpuBasic2_ud2 wrt FLAT
 
 
@@ -46,37 +46,37 @@
 BS3_BEGIN_TEXT16
 
-BS3_PROC_BEGIN  bs3CpuBasic2_ud2, BS3_PB_WITH_US_ALIAS
+BS3_PROC_BEGIN _bs3CpuBasic2_ud2
 .again:
         ud2
         jmp     .again
-BS3_PROC_END    bs3CpuBasic2_ud2
+BS3_PROC_END   _bs3CpuBasic2_ud2
 
 
-BS3_PROC_BEGIN bs3CpuBasic2_Int80, BS3_PB_WITH_US_ALIAS
+BS3_PROC_BEGIN _bs3CpuBasic2_Int80
         int     80h
 .again: ud2
         jmp     .again
-BS3_PROC_END   bs3CpuBasic2_Int80
+BS3_PROC_END   _bs3CpuBasic2_Int80
 
 
-BS3_PROC_BEGIN bs3CpuBasic2_Int81, BS3_PB_WITH_US_ALIAS
+BS3_PROC_BEGIN _bs3CpuBasic2_Int81
         int     81h
 .again: ud2
         jmp     .again
-BS3_PROC_END   bs3CpuBasic2_Int81
+BS3_PROC_END   _bs3CpuBasic2_Int81
 
 
-BS3_PROC_BEGIN bs3CpuBasic2_Int82, BS3_PB_WITH_US_ALIAS
+BS3_PROC_BEGIN _bs3CpuBasic2_Int82
         int     82h
 .again: ud2
         jmp     .again
-BS3_PROC_END   bs3CpuBasic2_Int82
+BS3_PROC_END   _bs3CpuBasic2_Int82
 
 
-BS3_PROC_BEGIN bs3CpuBasic2_Int83, BS3_PB_WITH_US_ALIAS
+BS3_PROC_BEGIN _bs3CpuBasic2_Int83
         int     83h
 .again: ud2
         jmp     .again
-BS3_PROC_END   bs3CpuBasic2_Int83
+BS3_PROC_END   _bs3CpuBasic2_Int83
 
 
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.c
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.c	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.c	(revision 60676)
@@ -82,4 +82,12 @@
     uint8_t u1DescType;
 } BS3CB2INVLDESCTYPE;
+
+typedef struct BS3CB2SIDTSGDT
+{
+    FPFNBS3FAR  fpfnWorker;
+    uint8_t     cbInstr;
+    bool        fSs;
+    uint8_t     bMode;
+} BS3CB2SIDTSGDT;
 #endif
 
@@ -89,15 +97,34 @@
 *********************************************************************************************************************************/
 #ifdef BS3_INSTANTIATING_CMN
-extern BS3_DECL(void)   bs3CpuBasic2_Int80(void);
-extern BS3_DECL(void)   bs3CpuBasic2_Int81(void);
-extern BS3_DECL(void)   bs3CpuBasic2_Int82(void);
-extern BS3_DECL(void)   bs3CpuBasic2_Int83(void);
-extern BS3_DECL(void)   bs3CpuBasic2_ud2(void);
-#define                 bs3CpuBasic2_sidt_bx_ud2 BS3_CMN_NM(bs3CpuBasic2_sidt_bx_ud2)
-extern BS3_DECL(void)   bs3CpuBasic2_sidt_bx_ud2(void);
-#define                 bs3CpuBasic2_lidt_bx_ud2 BS3_CMN_NM(bs3CpuBasic2_lidt_bx_ud2)
-extern BS3_DECL(void)   bs3CpuBasic2_lidt_bx_ud2(void);
-#define                 g_bs3CpuBasic2_ud2_FlatAddr BS3_DATA_NM(g_bs3CpuBasic2_ud2_FlatAddr)
-extern uint32_t         g_bs3CpuBasic2_ud2_FlatAddr;
+extern FNBS3FAR     bs3CpuBasic2_Int80;
+extern FNBS3FAR     bs3CpuBasic2_Int81;
+extern FNBS3FAR     bs3CpuBasic2_Int82;
+extern FNBS3FAR     bs3CpuBasic2_Int83;
+extern FNBS3FAR     bs3CpuBasic2_ud2;
+# define            g_bs3CpuBasic2_ud2_FlatAddr BS3_DATA_NM(g_bs3CpuBasic2_ud2_FlatAddr)
+extern uint32_t     g_bs3CpuBasic2_ud2_FlatAddr;
+
+extern FNBS3FAR     bs3CpuBasic2_sidt_bx_ud2_c16;
+extern FNBS3FAR     bs3CpuBasic2_sidt_bx_ud2_c32;
+extern FNBS3FAR     bs3CpuBasic2_sidt_bx_ud2_c64;
+extern FNBS3FAR     bs3CpuBasic2_sidt_ss_bx_ud2_c16;
+extern FNBS3FAR     bs3CpuBasic2_sidt_ss_bx_ud2_c32;
+extern FNBS3FAR     bs3CpuBasic2_sidt_rexw_bx_ud2_c64;
+extern FNBS3FAR     bs3CpuBasic2_sidt_opsize_bx_ud2_c16;
+extern FNBS3FAR     bs3CpuBasic2_sidt_opsize_bx_ud2_c32;
+extern FNBS3FAR     bs3CpuBasic2_sidt_opsize_bx_ud2_c64;
+extern FNBS3FAR     bs3CpuBasic2_sidt_opsize_ss_bx_ud2_c16;
+extern FNBS3FAR     bs3CpuBasic2_sidt_opsize_ss_bx_ud2_c32;
+extern FNBS3FAR     bs3CpuBasic2_sidt_opsize_rexw_bx_ud2_c64;
+
+extern FNBS3FAR     bs3CpuBasic2_sgdt_bx_ud2_c16;
+extern FNBS3FAR     bs3CpuBasic2_sgdt_bx_ud2_c32;
+extern FNBS3FAR     bs3CpuBasic2_sgdt_bx_ud2_c64;
+extern FNBS3FAR     bs3CpuBasic2_sgdt_opsize_bx_ud2_c16;
+extern FNBS3FAR     bs3CpuBasic2_sgdt_opsize_bx_ud2_c32;
+extern FNBS3FAR     bs3CpuBasic2_sgdt_opsize_bx_ud2_c64;
+extern FNBS3FAR     bs3CpuBasic2_lidt_bx_ud2_c16;
+extern FNBS3FAR     bs3CpuBasic2_lidt_bx_ud2_c32;
+extern FNBS3FAR     bs3CpuBasic2_lidt_bx_ud2_c64;
 #endif
 
@@ -113,4 +140,38 @@
 # define                    g_f16BitSys     BS3_CMN_NM(g_f16BitSys)
 static bool                 g_f16BitSys = 1;
+
+
+static BS3CB2SIDTSGDT const g_aSidtWorkers[] =
+{
+    { bs3CpuBasic2_sidt_bx_ud2_c16,             3, false,   BS3_MODE_CODE_16 | BS3_MODE_CODE_V86 },
+//    { bs3CpuBasic2_sidt_ss_bx_ud2_c16,          4, true,    BS3_MODE_CODE_16 | BS3_MODE_CODE_V86 },
+    { bs3CpuBasic2_sidt_opsize_bx_ud2_c16,      4, false,   BS3_MODE_CODE_16 | BS3_MODE_CODE_V86 },
+//    { bs3CpuBasic2_sidt_opsize_ss_bx_ud2_c16,   5, true,    BS3_MODE_CODE_16 | BS3_MODE_CODE_V86 },
+    { bs3CpuBasic2_sidt_bx_ud2_c32,             3, false,   BS3_MODE_CODE_32 },
+//    { bs3CpuBasic2_sidt_ss_bx_ud2_c32,          4, true,    BS3_MODE_CODE_32 },
+    { bs3CpuBasic2_sidt_opsize_bx_ud2_c32,      4, false,   BS3_MODE_CODE_32 },
+//    { bs3CpuBasic2_sidt_opsize_ss_bx_ud2_c32,   5, true,    BS3_MODE_CODE_32 },
+    { bs3CpuBasic2_sidt_bx_ud2_c64,             3, false,   BS3_MODE_CODE_64 },
+    { bs3CpuBasic2_sidt_rexw_bx_ud2_c64,        4, false,   BS3_MODE_CODE_64 },
+    { bs3CpuBasic2_sidt_opsize_bx_ud2_c64,      4, false,   BS3_MODE_CODE_64 },
+    { bs3CpuBasic2_sidt_opsize_rexw_bx_ud2_c64, 5, false,   BS3_MODE_CODE_64 },
+};
+
+#if 0
+static BS3CB2SIDTSGDT const g_aSgdtNormal[3] =
+{
+    { bs3CpuBasic2_sgdt_bx_ud2_c16, bs3CpuBasic2_sgdt_ss_bx_ud2_c16, BS3_MODE_CODE_16 | BS3_MODE_CODE_V86 },
+    { bs3CpuBasic2_sgdt_bx_ud2_c32, bs3CpuBasic2_sgdt_ss_bx_ud2_c32, BS3_MODE_CODE_32 },
+    { bs3CpuBasic2_sgdt_bx_ud2_c64, bs3CpuBasic2_sgdt_rexw_bx_ud2_c64, BS3_MODE_CODE_64 },
+};
+
+static BS3CB2SIDTSGDT const g_aSgdtOpSize[3] =
+{
+    { bs3CpuBasic2_sgdt_opsize_bx_ud2_c16, bs3CpuBasic2_sgdt_ss_bx_ud2_c16, BS3_MODE_CODE_16 | BS3_MODE_CODE_V86 },
+    { bs3CpuBasic2_sgdt_opsize_bx_ud2_c32, bs3CpuBasic2_sgdt_ss_bx_ud2_c32, BS3_MODE_CODE_32 },
+    { bs3CpuBasic2_sgdt_opsize_bx_ud2_c64, bs3CpuBasic2_sgdt_rexw_bx_ud2_c64, BS3_MODE_CODE_64 },
+};
+#endif
+
 
 /** Table containing invalid CS selector types. */
@@ -1305,6 +1366,13 @@
 
 
-# define bs3CpuBasic2_sidt_Common BS3_CMN_NM(bs3CpuBasic2_sidt_Common)
-BS3_DECL_NEAR(void) bs3CpuBasic2_sidt_Common(void)
+/**
+ * Executes one round of SIDT and SGDT tests using one assembly worker.
+ *
+ * This is written with driving everything from the 16-bit or 32-bit worker in
+ * mind, i.e. not assuming the test bitcount is the same as the current.
+ */
+# define bs3CpuBasic2_sidt_sgdt_One BS3_CMN_NM(bs3CpuBasic2_sidt_sgdt_One)
+BS3_DECL_NEAR(void) bs3CpuBasic2_sidt_sgdt_One(BS3CB2SIDTSGDT const BS3_FAR *pWorker, uint8_t bTestMode,
+                                               uint8_t const *pabExpected)
 {
     BS3TRAPFRAME        TrapCtx;
@@ -1315,10 +1383,10 @@
     uint8_t             abBuf[8*2 + 8 + 8];  /* test buffer w/ misalignment test space and some extra guard. */
     uint8_t BS3_FAR    *pbBuf  = abBuf;
-    uint8_t const       cbIdtr = BS3_MODE_IS_64BIT_CODE(g_bTestMode) ? 2+8 : 2+4;
+    uint8_t const       cbIdtr = BS3_MODE_IS_64BIT_CODE(bTestMode) ? 2+8 : 2+4;
     bool const          f286   = (g_uBs3CpuDetected & BS3CPU_TYPE_MASK) == BS3CPU_80286;
     uint8_t             bFiller;
-    unsigned            off;
-
-    g_usBs3TestStep = 0;
+    int                 off;
+    uint8_t BS3_FAR    *pbTest;
+Bs3TestPrintf("bs3CpuBasic2_sidt_sgdt_One: %p bTestMode=%#x\n",  pWorker,  bTestMode);
 
     /* make sure they're allocated  */
@@ -1331,17 +1399,13 @@
     /* Create a context, give this routine some more stack space, point the context
        at our SIDT [xBX] + UD2 combo, and point DS:xBX at abBuf. */
-    Bs3RegCtxSaveEx(&Ctx, g_bTestMode, 256 /*cbExtraStack*/);
-    Ctx.rip.u  = (uintptr_t)BS3_FP_OFF(&bs3CpuBasic2_sidt_bx_ud2);
-# if TMPL_BITS == 32
-    g_uBs3TrapEipHint = Ctx.rip.u32;
-# endif
-    Ctx.rbx.u = BS3_FP_OFF(pbBuf);
-# if TMPL_BITS == 16
-    Ctx.ds    = BS3_FP_SEG(pbBuf);
-# endif
+    Bs3RegCtxSaveEx(&Ctx, bTestMode, 256 /*cbExtraStack*/);
+    Bs3RegCtxSetGrpDsFromCurPtr(&Ctx, &Ctx.rbx, abBuf);
+    Bs3RegCtxSetRipCsFromLnkPtr(&Ctx, pWorker->fpfnWorker);
+    if (BS3_MODE_IS_16BIT_SYS(bTestMode))
+        g_uBs3TrapEipHint = Ctx.rip.u32;
 
     /* For successful SIDT attempts, we'll stop at the UD2. */
     Bs3MemCpy(&CtxUdExpected, &Ctx, sizeof(Ctx));
-    CtxUdExpected.rip.u += 3;
+    CtxUdExpected.rip.u += pWorker->cbInstr;
 
     /*
@@ -1360,4 +1424,6 @@
     if (!ASMMemIsZero(&abBuf[cbIdtr], cbBuf - cbIdtr))
         Bs3TestFailedF("Unexpected buffer bytes set (#1): cbIdtr=%u abBuf=%.*Rhxs\n", cbIdtr, cbBuf, pbBuf);
+    if (Bs3MemCmp(abBuf, pabExpected, cbIdtr) != 0)
+        Bs3TestFailedF("Mismatch (#1): expected %.*Rhxs, got %.*Rhxs\n", cbIdtr, pabExpected, cbIdtr, abBuf);
     g_usBs3TestStep++;
 
@@ -1378,4 +1444,6 @@
     if (Bs3MemChr(abBuf, bFiller, cbIdtr) != NULL)
         Bs3TestFailedF("Not all bytes touched: cbIdtr=%u bFiller=%#x abBuf=%.*Rhxs\n", cbIdtr, bFiller, cbBuf, pbBuf);
+    if (Bs3MemCmp(abBuf, pabExpected, cbIdtr) != 0)
+        Bs3TestFailedF("Mismatch (#2): expected %.*Rhxs, got %.*Rhxs\n", cbIdtr, pabExpected, cbIdtr, abBuf);
     g_usBs3TestStep++;
 
@@ -1386,5 +1454,6 @@
     {
         pbBuf = &abBuf[off];
-        CtxUdExpected.rbx.u = Ctx.rbx.u = BS3_FP_OFF(pbBuf);
+        Bs3RegCtxSetGrpDsFromCurPtr(&Ctx, &Ctx.rbx, &abBuf[off]);
+        CtxUdExpected.rbx.u = Ctx.rbx.u;
 
         /* First with zero buffer. */
@@ -1400,4 +1469,6 @@
         if (f286 && abBuf[off + cbIdtr - 1] != 0xff)
             Bs3TestFailedF("286: Top base byte isn't 0xff (#3): %#x\n", abBuf[off + cbIdtr - 1]);
+        if (Bs3MemCmp(&abBuf[off], pabExpected, cbIdtr) != 0)
+            Bs3TestFailedF("Mismatch (#3): expected %.*Rhxs, got %.*Rhxs\n", cbIdtr, pabExpected, cbIdtr, &abBuf[off]);
         g_usBs3TestStep++;
 
@@ -1417,9 +1488,11 @@
         if (f286 && abBuf[off + cbIdtr - 1] != 0xff)
             Bs3TestFailedF("286: Top base byte isn't 0xff (#4): %#x\n", abBuf[off + cbIdtr - 1]);
+        if (Bs3MemCmp(&abBuf[off], pabExpected, cbIdtr) != 0)
+            Bs3TestFailedF("Mismatch (#4): expected %.*Rhxs, got %.*Rhxs\n", cbIdtr, pabExpected, cbIdtr, &abBuf[off]);
         g_usBs3TestStep++;
-
     }
     pbBuf = abBuf;
-    CtxUdExpected.rbx.u = Ctx.rbx.u = BS3_FP_OFF(pbBuf);
+    Bs3RegCtxSetGrpDsFromCurPtr(&Ctx, &Ctx.rbx, abBuf);
+    CtxUdExpected.rbx.u = Ctx.rbx.u;
 
     /*
@@ -1427,10 +1500,9 @@
      * We use BS3_SEL_TEST_PAGE_00 for this
      */
-    if (   !BS3_MODE_IS_RM_OR_V86(g_bTestMode)
-        && !BS3_MODE_IS_64BIT_CODE(g_bTestMode))
+    if (   !BS3_MODE_IS_RM_OR_V86(bTestMode)
+        && !BS3_MODE_IS_64BIT_CODE(bTestMode))
     {
         uint16_t cbLimit;
-        uint16_t const uSavedDs = Ctx.ds;
-        uint32_t uFlatBuf = Bs3SelPtrToFlat(pbBuf);
+        uint32_t uFlatBuf = Bs3SelPtrToFlat(abBuf);
         Bs3GdteTestPage00 = Bs3Gdte_DATA16;
         Bs3GdteTestPage00.Gen.u16BaseLow  = (uint16_t)uFlatBuf;
@@ -1455,4 +1527,6 @@
                         Bs3TestFailedF("Not all bytes touched (#5): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
                                        cbIdtr, off, cbLimit, bFiller, off + cbBuf, abBuf);
+                    if (Bs3MemCmp(&abBuf[off], pabExpected, cbIdtr) != 0)
+                        Bs3TestFailedF("Mismatch (#5): expected %.*Rhxs, got %.*Rhxs\n", cbIdtr, pabExpected, cbIdtr, &abBuf[off]);
                     if (f286 && abBuf[off + cbIdtr - 1] != 0xff)
                         Bs3TestFailedF("286: Top base byte isn't 0xff (#5): %#x\n", abBuf[off + cbIdtr - 1]);
@@ -1466,4 +1540,6 @@
                             Bs3TestFailedF("Limit bytes not touched (#6): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
                                            cbIdtr, off, cbLimit, bFiller, off + cbBuf, abBuf);
+                        if (Bs3MemCmp(&abBuf[off], pabExpected, 2) != 0)
+                            Bs3TestFailedF("Mismatch (#6): expected %.2Rhxs, got %.2Rhxs\n", pabExpected, &abBuf[off]);
                         if (!ASMMemIsAllU8(&abBuf[off + 2], cbIdtr - 2, bFiller))
                             Bs3TestFailedF("Base bytes touched on #GP (#6): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
@@ -1506,8 +1582,10 @@
                     bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
                     if (Bs3MemChr(&abBuf[off], bFiller, cbIdtr) != NULL)
-                        Bs3TestFailedF("Not all bytes touched (#5): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
+                        Bs3TestFailedF("Not all bytes touched (#8): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
                                        cbIdtr, off, cbLimit, bFiller, off + cbBuf, abBuf);
+                    if (Bs3MemCmp(&abBuf[off], pabExpected, cbIdtr) != 0)
+                        Bs3TestFailedF("Mismatch (#8): expected %.*Rhxs, got %.*Rhxs\n", cbIdtr, pabExpected, cbIdtr, &abBuf[off]);
                     if (f286 && abBuf[off + cbIdtr - 1] != 0xff)
-                        Bs3TestFailedF("286: Top base byte isn't 0xff (#5): %#x\n", abBuf[off + cbIdtr - 1]);
+                        Bs3TestFailedF("286: Top base byte isn't 0xff (#8): %#x\n", abBuf[off + cbIdtr - 1]);
                 }
                 else
@@ -1520,8 +1598,8 @@
 
                 if (off > 0 && !ASMMemIsAllU8(abBuf, off, bFiller))
-                    Bs3TestFailedF("Leading bytes touched (#7): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
+                    Bs3TestFailedF("Leading bytes touched (#9): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
                                    cbIdtr, off, cbLimit, bFiller, off + cbBuf, abBuf);
                 if (!ASMMemIsAllU8(&abBuf[off + cbIdtr], sizeof(abBuf) - off - cbIdtr, bFiller))
-                    Bs3TestFailedF("Trailing bytes touched (#7): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
+                    Bs3TestFailedF("Trailing bytes touched (#9): cbIdtr=%u off=%u cbLimit=%u bFiller=%#x abBuf=%.*Rhxs\n",
                                    cbIdtr, off, cbLimit, bFiller, off + cbBuf, abBuf);
 
@@ -1530,6 +1608,5 @@
         }
 
-        CtxUdExpected.ds = Ctx.ds = uSavedDs;
-        CtxUdExpected.rbx.u = Ctx.rbx.u = BS3_FP_OFF(pbBuf);
+        Bs3RegCtxSetGrpDsFromCurPtr(&Ctx, &Ctx.rbx, pbBuf);
     }
 
@@ -1537,11 +1614,96 @@
      * Play with the paging.
      */
-    if (BS3_MODE_IS_PAGED(g_bTestMode))
-    {
-
-
+    if (   BS3_MODE_IS_PAGED(bTestMode)
+
+        && (pbTest = (uint8_t BS3_FAR *)Bs3MemGuardedTestPageAlloc(BS3MEMKIND_TILED)) != NULL)
+    {
+        RTCCUINTXREG uFlatTest = Bs3SelPtrToFlat(pbTest);
+
+        /*
+         * Slide the buffer towards the trailing guard page.  We'll observe the
+         * first word being written entirely separately from the 2nd dword/qword.
+         */
+        for (off = X86_PAGE_4K_SIZE - cbIdtr - 4; off < X86_PAGE_4K_SIZE + 4; off++)
+        {
+            Bs3MemSet(&pbTest[X86_PAGE_4K_SIZE - cbIdtr * 2], bFiller, cbIdtr * 2);
+            Bs3RegCtxSetGrpDsFromCurPtr(&Ctx, &Ctx.rbx, &pbTest[off]);
+            Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
+            if (off + cbIdtr <= X86_PAGE_4K_SIZE)
+            {
+                CtxUdExpected.rbx = Ctx.rbx;
+                CtxUdExpected.ds  = Ctx.ds;
+                bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
+                if (Bs3MemCmp(&pbTest[off], pabExpected, cbIdtr) != 0)
+                    Bs3TestFailedF("Mismatch (#9): expected %.*Rhxs, got %.*Rhxs\n", cbIdtr, pabExpected, cbIdtr, &pbTest[off]);
+            }
+            else
+            {
+                bs3CpuBasic2_ComparePfCtx(&TrapCtx, &Ctx, X86_TRAP_PF_RW | (Ctx.bCpl ? X86_TRAP_PF_US : 0),
+                                          uFlatTest + RT_MAX(off, X86_PAGE_4K_SIZE));
+                if (   off <= X86_PAGE_4K_SIZE - 2
+                    && Bs3MemCmp(&pbTest[off], pabExpected, 2) != 0)
+                    Bs3TestPrintf("Mismatch (#10): Expected limit %.2Rhxs, got %.2Rhxs; off=%#x\n",
+                                  pabExpected, &pbTest[off], off);
+                if (   off < X86_PAGE_4K_SIZE - 2
+                    && !ASMMemIsAllU8(&pbTest[off + 2], X86_PAGE_4K_SIZE - off - 2, bFiller))
+                    Bs3TestPrintf("Wrote partial base on #PF (#10): Expected %.*Rhxs, got %.*Rhxs; off=%#x\n",
+                                  X86_PAGE_4K_SIZE - off - 2, pabExpected, X86_PAGE_4K_SIZE - off - 2, &pbTest[off + 2], off);
+                if (off == X86_PAGE_4K_SIZE - 1 && pbTest[off] != bFiller)
+                    Bs3TestPrintf("Wrote partial limit on #PF (#10): Expected %02x, got %02x\n", bFiller, pbTest[off]);
+            }
+        }
+
+        /*
+         * Now, do it the other way around. It should look normal now since writing
+         * the limit will #PF first and nothing should be written.
+         */
+        for (off = cbIdtr + 4; off >= -cbIdtr - 4; off--)
+        {
+            Bs3MemSet(pbTest, bFiller, 32);
+            Bs3RegCtxSetGrpDsFromCurPtr(&Ctx, &Ctx.rbx, &pbTest[off]);
+            Bs3TrapSetJmpAndRestore(&Ctx, &TrapCtx);
+            if (off >= 0)
+            {
+                CtxUdExpected.rbx = Ctx.rbx;
+                CtxUdExpected.ds  = Ctx.ds;
+                bs3CpuBasic2_CompareUdCtx(&TrapCtx, &CtxUdExpected);
+                if (Bs3MemCmp(&pbTest[off], pabExpected, cbIdtr) != 0)
+                    Bs3TestFailedF("Mismatch (#10): expected %.*Rhxs, got %.*Rhxs\n", cbIdtr, pabExpected, cbIdtr, &pbTest[off]);
+            }
+            else
+            {
+                bs3CpuBasic2_ComparePfCtx(&TrapCtx, &Ctx, X86_TRAP_PF_RW | (Ctx.bCpl ? X86_TRAP_PF_US : 0),
+                                          uFlatTest + RT_MAX(off, X86_PAGE_4K_SIZE));
+                if (   -off < cbIdtr
+                    && !ASMMemIsAllU8(pbTest, cbIdtr + off, bFiller))
+                    Bs3TestPrintf("Wrote partial content on #PF (#11): bFiller=%#x, found %.*Rhxs; off=%d\n",
+                                  bFiller, cbIdtr + off, pbTest, off);
+            }
+            if (!ASMMemIsAllU8(&pbTest[RT_MAX(cbIdtr + off, 0)], 16, bFiller))
+                Bs3TestPrintf("Wrote beyond expected area (#12): bFiller=%#x, found %.16Rhxs; off=%d\n",
+                              bFiller, &pbTest[RT_MAX(cbIdtr + off, 0)], off);
+        }
+
+        Bs3MemGuardedTestPageFree(pbTest);
     }
 
 }
+
+# define bs3CpuBasic2_sidt_sgdt_Common BS3_CMN_NM(bs3CpuBasic2_sidt_sgdt_Common)
+BS3_DECL_NEAR(void) bs3CpuBasic2_sidt_sgdt_Common(uint8_t bTestMode, BS3CB2SIDTSGDT const BS3_FAR *paWorkers, unsigned cWorkers,
+                                                  uint8_t const *pabExpected)
+{
+    unsigned idx;
+    unsigned iStep = 0;
+
+    for (idx = 0; idx < cWorkers; idx++)
+        if (paWorkers[idx].bMode & (bTestMode & BS3_MODE_CODE_MASK))
+        {
+            g_usBs3TestStep = iStep;
+            bs3CpuBasic2_sidt_sgdt_One(&paWorkers[idx], bTestMode, pabExpected);
+            iStep += 1000;
+        }
+}
+
 
 # if ARCH_BITS != 64
@@ -1794,5 +1956,12 @@
 {
 //if (bMode == BS3_MODE_PE16_V86)
-{
+if (bMode & BS3_MODE_CODE_V86)
+{
+    union
+    {
+        RTIDTR  Idtr;
+        uint8_t ab[16];
+    } Expected;
+
     g_pszTestMode = TMPL_NM(g_szBs3ModeName);
     g_bTestMode   = bMode;
@@ -1804,5 +1973,7 @@
      * Pass to common worker which is only compiled once per mode.
      */
-    bs3CpuBasic2_sidt_Common();
+    Bs3MemZero(&Expected, sizeof(Expected));
+    ASMGetIDTR(&Expected.Idtr);
+    bs3CpuBasic2_sidt_sgdt_Common(bMode, g_aSidtWorkers, RT_ELEMENTS(g_aSidtWorkers), Expected.ab);
 
     /*
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.mac
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.mac	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.mac	(revision 60676)
@@ -92,4 +92,7 @@
 %ifdef BS3_INSTANTIATING_CMN
 
+;
+; SIDT
+;
 BS3_PROC_BEGIN_CMN bs3CpuBasic2_sidt_bx_ud2, BS3_PBC_NEAR
         sidt    [xBX]
@@ -99,5 +102,89 @@
 BS3_PROC_END_CMN   bs3CpuBasic2_sidt_bx_ud2
 
+BS3_PROC_BEGIN_CMN bs3CpuBasic2_sidt_opsize_bx_ud2, BS3_PBC_NEAR
+        db      X86_OP_PRF_SIZE_OP
+        sidt    [xBX]
+.again: ud2
+        jmp     .again
+AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_sidt_opsize_bx_ud2) == 4)
+BS3_PROC_END_CMN   bs3CpuBasic2_sidt_opsize_bx_ud2
 
+%if TMPL_BITS == 64
+BS3_PROC_BEGIN_CMN bs3CpuBasic2_sidt_rexw_bx_ud2, BS3_PBC_NEAR
+        db      X86_OP_REX_W
+        sidt    [xBX]
+.again: ud2
+        jmp     .again
+AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_sidt_rexw_bx_ud2) == 4)
+BS3_PROC_END_CMN   bs3CpuBasic2_sidt_rexw_bx_ud2
+
+BS3_PROC_BEGIN_CMN bs3CpuBasic2_sidt_opsize_rexw_bx_ud2, BS3_PBC_NEAR
+        db      X86_OP_PRF_SIZE_OP
+        db      X86_OP_REX_W
+        sidt    [xBX]
+.again: ud2
+        jmp     .again
+AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_sidt_opsize_rexw_bx_ud2) == 5)
+BS3_PROC_END_CMN   bs3CpuBasic2_sidt_opsize_rexw_bx_ud2
+%endif
+
+%if TMPL_BITS != 64
+BS3_PROC_BEGIN_CMN bs3CpuBasic2_sidt_ss_bx_ud2, BS3_PBC_NEAR
+        sidt    [ss:xBX]
+.again: ud2
+        jmp     .again
+AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_sidt_ss_bx_ud2) == 4)
+BS3_PROC_END_CMN   bs3CpuBasic2_sidt_ss_bx_ud2
+
+BS3_PROC_BEGIN_CMN bs3CpuBasic2_sidt_opsize_ss_bx_ud2, BS3_PBC_NEAR
+        db      X86_OP_PRF_SIZE_OP
+        sidt    [ss:xBX]
+.again: ud2
+        jmp     .again
+AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_sidt_opsize_ss_bx_ud2) == 5)
+BS3_PROC_END_CMN   bs3CpuBasic2_sidt_opsize_ss_bx_ud2
+%endif
+
+;
+; SGDT
+;
+BS3_PROC_BEGIN_CMN bs3CpuBasic2_sgdt_bx_ud2, BS3_PBC_NEAR
+        sgdt    [xBX]
+.again: ud2
+        jmp     .again
+AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_sgdt_bx_ud2) == 3)
+BS3_PROC_END_CMN   bs3CpuBasic2_sgdt_bx_ud2
+
+BS3_PROC_BEGIN_CMN bs3CpuBasic2_sgdt_opsize_bx_ud2, BS3_PBC_NEAR
+        db      X86_OP_PRF_SIZE_OP
+        sgdt    [xBX]
+.again: ud2
+        jmp     .again
+AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_sgdt_opsize_bx_ud2) == 4)
+BS3_PROC_END_CMN   bs3CpuBasic2_sgdt_opsize_bx_ud2
+
+%if TMPL_BITS == 64
+BS3_PROC_BEGIN_CMN bs3CpuBasic2_sgdt_rexw_bx_ud2, BS3_PBC_NEAR
+        db      X86_OP_REX_W
+        sgdt    [xBX]
+.again: ud2
+        jmp     .again
+AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_sgdt_rexw_bx_ud2) == 4)
+BS3_PROC_END_CMN   bs3CpuBasic2_sgdt_rexw_bx_ud2
+%endif
+
+%if TMPL_BITS != 64
+BS3_PROC_BEGIN_CMN bs3CpuBasic2_sgdt_ss_bx_ud2, BS3_PBC_NEAR
+        sgdt    [ss:xBX]
+.again: ud2
+        jmp     .again
+AssertCompile(.again - BS3_CMN_NM(bs3CpuBasic2_sgdt_ss_bx_ud2) == 4)
+BS3_PROC_END_CMN   bs3CpuBasic2_sgdt_ss_bx_ud2
+%endif
+
+
+;
+;
+;
 BS3_PROC_BEGIN_CMN bs3CpuBasic2_lidt_bx_ud2, BS3_PBC_NEAR
         lidt    [xBX]
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk	(revision 60676)
@@ -72,4 +72,5 @@
        bs3-cmn-StrCpy.c \
        bs3-cmn-MemChr.asm \
+       bs3-cmn-MemCmp.asm \
        bs3-cmn-MemCpy.c \
        bs3-cmn-MemPCpy.c \
@@ -80,4 +81,5 @@
        bs3-cmn-MemAllocZ.c \
        bs3-cmn-MemFree.c \
+       bs3-cmn-MemGuardedTestPage.c \
        bs3-cmn-PagingData.c \
        bs3-cmn-PagingInitRootForPP.c \
@@ -91,4 +93,7 @@
        bs3-cmn-RegCtxSave.asm \
        bs3-cmn-RegCtxSaveEx.asm \
+       bs3-cmn-RegCtxSetGrpSegFromCurPtr.c \
+       bs3-cmn-RegCtxSetGrpSegFromFlat.c \
+       bs3-cmn-RegCtxSetRipCsFromLnkPtr.c \
        bs3-cmn-SelFar32ToFlat32.c \
        bs3-cmn-SelFar32ToFlat32NoClobber.asm \
@@ -193,4 +198,5 @@
 	bs3-wc16-U4D.asm \
 	bs3-wc16-I4D.asm \
+       bs3-c16-SwitchFromV86To16BitAndCallC.asm \
        bs3-c16-Trap16Generic.asm \
        bs3-c16-TrapRmV86Generic.asm \
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/VBoxBs3ObjConverter.cpp
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/VBoxBs3ObjConverter.cpp	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/VBoxBs3ObjConverter.cpp	(revision 60676)
@@ -257,4 +257,19 @@
 typedef OMFSYMBOL *POMFSYMBOL;
 
+/** OMF Writer LNAME lookup record. */
+typedef struct OMFWRLNAME
+{
+    /** Pointer to the next entry with the name hash. */
+    struct OMFWRLNAME      *pNext;
+    /** The LNAMES index number.   */
+    uint16_t                idxName;
+    /** The name length.   */
+    uint8_t                 cchName;
+    /** The name (variable size).   */
+    char                    szName[1];
+} OMFWRLNAME;
+/** Pointer to the a OMF writer LNAME lookup record. */
+typedef OMFWRLNAME *POMFWRLNAME;
+
 /**
  * OMF converter & writer instance.
@@ -312,4 +327,7 @@
     /** The EXTDEF index of the __ImageBase symbol. */
     uint16_t        idxExtImageBase;
+
+    /** LNAME lookup hash table. To avoid too many duplicates. */
+    POMFWRLNAME     apNameLookup[63];
 } OMFWRITE;
 /** Pointer to an OMF writer. */
@@ -353,8 +371,24 @@
 {
     free(pThis->paSymbols);
+
     for (uint32_t i = 0; i < pThis->cSegments; i++)
         if (pThis->paSegments[i].pszName)
             free(pThis->paSegments[i].pszName);
+
     free(pThis->paSegments);
+
+    uint32_t i = RT_ELEMENTS(pThis->apNameLookup);
+    while (i-- > 0)
+    {
+        POMFWRLNAME pNext = pThis->apNameLookup[i];
+        pThis->apNameLookup[i] = NULL;
+        while (pNext)
+        {
+            POMFWRLNAME pFree = pNext;
+            pNext = pNext->pNext;
+            free(pFree);
+        }
+    }
+
     free(pThis);
 }
@@ -424,9 +458,10 @@
 }
 
-static bool omfWriter_RecAddStringN(POMFWRITER pThis, const char *pchString, size_t cchString)
+static bool omfWriter_RecAddStringNEx(POMFWRITER pThis, const char *pchString, size_t cchString, bool fPrependUnderscore)
 {
     if (cchString < 256)
     {
-        return omfWriter_RecAddU8(pThis, (uint8_t)cchString)
+        return omfWriter_RecAddU8(pThis, (uint8_t)cchString + fPrependUnderscore)
+            && (!fPrependUnderscore || omfWriter_RecAddU8(pThis, '_'))
             && omfWriter_RecAddBytes(pThis, pchString, cchString);
     }
@@ -435,7 +470,12 @@
 }
 
+static bool omfWriter_RecAddStringN(POMFWRITER pThis, const char *pchString, size_t cchString)
+{
+    return omfWriter_RecAddStringNEx(pThis, pchString, cchString, false /*fPrependUnderscore*/);
+}
+
 static bool omfWriter_RecAddString(POMFWRITER pThis, const char *pszString)
 {
-    return omfWriter_RecAddStringN(pThis, pszString, strlen(pszString));
+    return omfWriter_RecAddStringNEx(pThis, pszString, strlen(pszString), false /*fPrependUnderscore*/);
 }
 
@@ -471,6 +511,86 @@
 }
 
+
+/**
+ * Simple stupid string hashing function (for LNAMES)
+ * @returns 8-bit hash.
+ * @param   pchName             The string.
+ * @param   cchName             The string length.
+ */
+DECLINLINE(uint8_t) omfWriter_HashStrU8(const char *pchName, size_t cchName)
+{
+    if (cchName)
+        return (uint8_t)(cchName + pchName[cchName >> 1]);
+    return 0;
+}
+
+/**
+ * Looks up a LNAME.
+ *
+ * @returns Index (0..32K) if found, UINT16_MAX if not found.
+ * @param   pThis               The OMF writer.
+ * @param   pchName             The name to look up.
+ * @param   cchName             The length of the name.
+ */
+static uint16_t omfWriter_LNamesLookupN(POMFWRITER pThis, const char *pchName, size_t cchName)
+{
+    uint8_t uHash = omfWriter_HashStrU8(pchName, cchName);
+    uHash %= RT_ELEMENTS(pThis->apNameLookup);
+
+    POMFWRLNAME pCur = pThis->apNameLookup[uHash];
+    while (pCur)
+    {
+        if (   pCur->cchName == cchName
+            && memcmp(pCur->szName, pchName, cchName) == 0)
+            return pCur->idxName;
+        pCur = pCur->pNext;
+    }
+
+    return UINT16_MAX;
+}
+
+/**
+ * Add a LNAME lookup record.
+ *
+ * @returns success indicator.
+ * @param   pThis               The OMF writer.
+ * @param   pchName             The name to look up.
+ * @param   cchName             The length of the name.
+ * @param   idxName             The name index.
+ */
+static bool omfWriter_LNamesAddLookup(POMFWRITER pThis, const char *pchName, size_t cchName, uint16_t idxName)
+{
+    POMFWRLNAME pCur = (POMFWRLNAME)malloc(sizeof(*pCur) + cchName);
+    if (!pCur)
+        return error("???", "Out of memory!\n");
+
+    pCur->idxName = idxName;
+    pCur->cchName = (uint8_t)cchName;
+    memcpy(pCur->szName, pchName, cchName);
+    pCur->szName[cchName] = '\0';
+
+    uint8_t uHash = omfWriter_HashStrU8(pchName, cchName);
+    uHash %= RT_ELEMENTS(pThis->apNameLookup);
+    pCur->pNext = pThis->apNameLookup[uHash];
+    pThis->apNameLookup[uHash] = pCur;
+
+    return true;
+}
+
+
 static bool omfWriter_LNamesAddN(POMFWRITER pThis, const char *pchName, size_t cchName, uint16_t *pidxName)
 {
+    /* See if we've already got that name in the list. */
+    uint16_t idxName;
+    if (pidxName) /* If pidxName is NULL, we assume the caller migth just be passing stuff thru. */
+    {
+        idxName = omfWriter_LNamesLookupN(pThis, pchName, cchName);
+        if (idxName != UINT16_MAX)
+        {
+            *pidxName = idxName;
+            return true;
+        }
+    }
+
     /* split? */
     if (pThis->cbRec + 1 /*len*/ + cchName + 1 /*crc*/ > OMF_MAX_RECORD_PAYLOAD)
@@ -483,8 +603,9 @@
     }
 
+    idxName = pThis->idxNextName++;
     if (pidxName)
-        *pidxName = pThis->idxNextName;
-    pThis->idxNextName++;
-    return omfWriter_RecAddStringN(pThis, pchName, cchName);
+        *pidxName = idxName;
+    return omfWriter_RecAddStringN(pThis, pchName, cchName)
+        && omfWriter_LNamesAddLookup(pThis, pchName, cchName, idxName);
 }
 
@@ -548,8 +669,9 @@
 }
 
-static bool omfWriter_PubDefAddN(POMFWRITER pThis, uint32_t uValue, const char *pchString, size_t cchString)
+static bool omfWriter_PubDefAddN(POMFWRITER pThis, uint32_t uValue, const char *pchString, size_t cchString,
+                                 bool fPrependUnderscore)
 {
     /* Split? */
-    if (pThis->cbRec + 1 + cchString + 4 + 1 + 1 > OMF_MAX_RECORD_PAYLOAD)
+    if (pThis->cbRec + 1 + cchString + 4 + 1 + 1 + fPrependUnderscore > OMF_MAX_RECORD_PAYLOAD)
     {
         if (cchString >= 256)
@@ -568,12 +690,12 @@
     }
 
-    return omfWriter_RecAddStringN(pThis, pchString, cchString)
+    return omfWriter_RecAddStringNEx(pThis, pchString, cchString, fPrependUnderscore)
         && omfWriter_RecAddU32(pThis, uValue)
         && omfWriter_RecAddIdx(pThis, 0); /* type */
 }
 
-static bool omfWriter_PubDefAdd(POMFWRITER pThis, uint32_t uValue, const char *pszString)
-{
-    return omfWriter_PubDefAddN(pThis, uValue, pszString, strlen(pszString));
+static bool omfWriter_PubDefAdd(POMFWRITER pThis, uint32_t uValue, const char *pszString, bool fPrependUnderscore)
+{
+    return omfWriter_PubDefAddN(pThis, uValue, pszString, strlen(pszString), fPrependUnderscore);
 }
 
@@ -595,8 +717,9 @@
  * EXTDEF - Add an entry, split record if necessary.
  */
-static bool omfWriter_ExtDefAddN(POMFWRITER pThis, const char *pchString, size_t cchString, uint16_t idxType)
+static bool omfWriter_ExtDefAddN(POMFWRITER pThis, const char *pchString, size_t cchString, uint16_t idxType,
+                                 bool fPrependUnderscore)
 {
     /* Split? */
-    if (pThis->cbRec + 1 + cchString + 1 + 1 > OMF_MAX_RECORD_PAYLOAD)
+    if (pThis->cbRec + 1 + cchString + 1 + 1 + fPrependUnderscore > OMF_MAX_RECORD_PAYLOAD)
     {
         if (cchString >= 256)
@@ -608,5 +731,5 @@
     }
 
-    return omfWriter_RecAddStringN(pThis, pchString, cchString)
+    return omfWriter_RecAddStringNEx(pThis, pchString, cchString, fPrependUnderscore)
         && omfWriter_RecAddIdx(pThis, idxType); /* type */
 }
@@ -615,7 +738,7 @@
  * EXTDEF - Add an entry, split record if necessary.
  */
-static bool omfWriter_ExtDefAdd(POMFWRITER pThis, const char *pszString)
-{
-    return omfWriter_ExtDefAddN(pThis, pszString, strlen(pszString), 0);
+static bool omfWriter_ExtDefAdd(POMFWRITER pThis, const char *pszString, bool fPrependUnderscore)
+{
+    return omfWriter_ExtDefAddN(pThis, pszString, strlen(pszString), 0, fPrependUnderscore);
 }
 
@@ -1506,25 +1629,8 @@
                         && pThis->paSymbols[iSym].enmType   == OMFSYMTYPE_PUBDEF)
                     {
+                        /* Underscore prefix all names not already underscored/mangled. */
                         const char *pszName = &pElfStuff->pchStrTab[paSymbols[iSym].st_name];
-                        if (!omfWriter_PubDefAdd(pThis, paSymbols[iSym].st_value, pszName))
+                        if (!omfWriter_PubDefAdd(pThis, paSymbols[iSym].st_value, pszName, pszName[0] != '_'))
                             return false;
-
-                        /* If the symbol doesn't start with an underscore and is a _c64 or _lm64 symbol,
-                           add an underscore prefixed alias to ease access from 16-bit and 32-bit code. */
-                        size_t cchName = strlen(pszName);
-                        if (   *pszName != '_'
-                            && (   (cchName > 4 && strcmp(&pszName[cchName - 4], "_c64")  == 0)
-                                || (cchName > 5 && strcmp(&pszName[cchName - 5], "_lm64") == 0) ) )
-                        {
-                            char   szCdeclName[512];
-                            if (cchName > sizeof(szCdeclName) - 2)
-                                cchName = sizeof(szCdeclName) - 2;
-                            szCdeclName[0] = '_';
-                            memcpy(&szCdeclName[1], pszName, cchName);
-                            szCdeclName[cchName + 1] = '\0';
-                            if (!omfWriter_PubDefAdd(pThis, paSymbols[iSym].st_value, szCdeclName))
-                                return false;
-                        }
-
                         pThis->paSymbols[iSym].idx = idxPubDef++;
                     }
@@ -1542,6 +1648,7 @@
                 && pThis->paSymbols[iSym].enmType   == OMFSYMTYPE_PUBDEF)
             {
+                /* Underscore prefix all names not already underscored/mangled. */
                 const char *pszName = &pElfStuff->pchStrTab[paSymbols[iSym].st_name];
-                if (!omfWriter_PubDefAdd(pThis, paSymbols[iSym].st_value, pszName))
+                if (!omfWriter_PubDefAdd(pThis, paSymbols[iSym].st_value, pszName, pszName[0] != '_'))
                     return false;
                 pThis->paSymbols[iSym].idx = idxPubDef++;
@@ -1560,6 +1667,7 @@
         if (pThis->paSymbols[iSym].enmType == OMFSYMTYPE_EXTDEF)
         {
+            /* Underscore prefix all names not already underscored/mangled. */
             const char *pszName = &pElfStuff->pchStrTab[paSymbols[iSym].st_name];
-            if (!omfWriter_ExtDefAdd(pThis, pszName))
+            if (!omfWriter_ExtDefAdd(pThis, pszName, *pszName != '_'))
                 return false;
             pThis->paSymbols[iSym].idx = idxExtDef++;
@@ -2337,25 +2445,8 @@
                         && pThis->paSymbols[iSym].enmType   == OMFSYMTYPE_PUBDEF)
                     {
+                        /* Underscore prefix all symbols not already underscored or mangled. */
                         const char *pszName = coffGetSymbolName(&paSymbols[iSym], pchStrTab, cbStrTab, szShort);
-                        if (!omfWriter_PubDefAdd(pThis, paSymbols[iSym].Value, pszName))
+                        if (!omfWriter_PubDefAdd(pThis, paSymbols[iSym].Value, pszName, pszName[0] != '_' && pszName[0] != '?'))
                             return false;
-
-                        /* If the symbol doesn't start with an underscore and is a _c64 or _lm64 symbol,
-                           add an underscore prefixed alias to ease access from 16-bit and 32-bit code. */
-                        size_t cchName = strlen(pszName);
-                        if (   *pszName != '_'
-                            && (   (cchName > 4 && strcmp(&pszName[cchName - 4], "_c64")  == 0)
-                                || (cchName > 5 && strcmp(&pszName[cchName - 5], "_lm64") == 0) ) )
-                        {
-                            char   szCdeclName[512];
-                            if (cchName > sizeof(szCdeclName) - 2)
-                                cchName = sizeof(szCdeclName) - 2;
-                            szCdeclName[0] = '_';
-                            memcpy(&szCdeclName[1], pszName, cchName);
-                            szCdeclName[cchName + 1] = '\0';
-                            if (!omfWriter_PubDefAdd(pThis, paSymbols[iSym].Value, szCdeclName))
-                                return false;
-                        }
-
                         pThis->paSymbols[iSym].idx = idxPubDef++;
                     }
@@ -2373,6 +2464,7 @@
                 && pThis->paSymbols[iSym].enmType   == OMFSYMTYPE_PUBDEF)
             {
-                if (!omfWriter_PubDefAdd(pThis, paSymbols[iSym].Value,
-                                         coffGetSymbolName(&paSymbols[iSym], pchStrTab, cbStrTab, szShort)) )
+                /* Underscore prefix all symbols not already underscored or mangled. */
+                const char *pszName = coffGetSymbolName(&paSymbols[iSym], pchStrTab, cbStrTab, szShort);
+                if (!omfWriter_PubDefAdd(pThis, paSymbols[iSym].Value, pszName, pszName[0] != '_' && pszName[0] != '?') )
                     return false;
                 pThis->paSymbols[iSym].idx = idxPubDef++;
@@ -2391,5 +2483,7 @@
         if (pThis->paSymbols[iSym].enmType == OMFSYMTYPE_EXTDEF)
         {
-            if (!omfWriter_ExtDefAdd(pThis, coffGetSymbolName(&paSymbols[iSym], pchStrTab, cbStrTab, szShort)))
+            /* Underscore prefix all symbols not already underscored or mangled. */
+            const char *pszName = coffGetSymbolName(&paSymbols[iSym], pchStrTab, cbStrTab, szShort);
+            if (!omfWriter_ExtDefAdd(pThis, pszName, pszName[0] != '_' && pszName[0] != '?'))
                 return false;
             pThis->paSymbols[iSym].idx = idxExtDef++;
@@ -2400,5 +2494,5 @@
     if (iSymImageBase != UINT32_MAX)
         pThis->idxExtImageBase = pThis->paSymbols[iSymImageBase].idx;
-    else if (omfWriter_ExtDefAdd(pThis, "__ImageBase"))
+    else if (omfWriter_ExtDefAdd(pThis, "__ImageBase", false /*fPrependUnderscore*/))
         pThis->idxExtImageBase = idxExtDef;
     else
@@ -2724,9 +2818,9 @@
 };
 
-/** Macro for getting the size of a AMD64 ELF relocation. */
-#define ELF_AMD64_RELOC_SIZE(a_Type) ( (a_Type) < RT_ELEMENTS(g_acbElfAmd64RelTypes) ? g_acbElfAmd64RelTypes[(a_Type)] : 1)
-
-
-typedef struct ELFDETAILS
+/** Macro for getting the size of a AMD64 Mach-O relocation. */
+#define MACHO_AMD64_RELOC_SIZE(a_Type) ( (a_Type) < RT_ELEMENTS(g_acbMachOAmd64RelTypes) ? g_acbMachOAmd64RelTypes[(a_Type)] : 1)
+
+
+typedef struct MACHODETAILS
 {
     /** The ELF header. */
@@ -2752,17 +2846,17 @@
     size_t              cbStrTab;
 
-} ELFDETAILS;
-typedef ELFDETAILS *PELFDETAILS;
-typedef ELFDETAILS const *PCELFDETAILS;
-
-
-static bool validateElf(const char *pszFile, uint8_t const *pbFile, size_t cbFile, PELFDETAILS pElfStuff)
-{
-    /*
-     * Initialize the ELF details structure.
-     */
-    memset(pElfStuff, 0,  sizeof(*pElfStuff));
-    pElfStuff->iSymSh = UINT16_MAX;
-    pElfStuff->iStrSh = UINT16_MAX;
+} MACHODETAILS;
+typedef MACHODETAILS *PMACHODETAILS;
+typedef MACHODETAILS const *PCMACHODETAILS;
+
+
+static bool validateMacho(const char *pszFile, uint8_t const *pbFile, size_t cbFile, PMACHODETAILS pMachOStuff)
+{
+    /*
+     * Initialize the Mach-O details structure.
+     */
+    memset(pMachOStuff, 0,  sizeof(*pMachOStuff));
+    pMachOStuff->iSymSh = UINT16_MAX;
+    pMachOStuff->iStrSh = UINT16_MAX;
 
     /*
@@ -2770,5 +2864,5 @@
      */
     Elf64_Ehdr const *pEhdr = (Elf64_Ehdr const *)pbFile;
-    pElfStuff->pEhdr = pEhdr;
+    pMachOStuff->pEhdr = pEhdr;
     if (   pEhdr->e_ident[EI_CLASS] != ELFCLASS64
         || pEhdr->e_ident[EI_DATA]  != ELFDATA2LSB
@@ -2797,5 +2891,5 @@
      */
     Elf64_Shdr const *paShdrs = (Elf64_Shdr const *)&pbFile[pEhdr->e_shoff];
-    pElfStuff->paShdrs = paShdrs;
+    pMachOStuff->paShdrs = paShdrs;
 
     Elf64_Xword const cbShStrTab = paShdrs[pEhdr->e_shstrndx].sh_size;
@@ -2807,5 +2901,5 @@
                      paShdrs[pEhdr->e_shstrndx].sh_offset, paShdrs[pEhdr->e_shstrndx].sh_size, (Elf64_Xword)cbFile);
     const char *pchShStrTab = (const char *)&pbFile[paShdrs[pEhdr->e_shstrndx].sh_offset];
-    pElfStuff->pchShStrTab = pchShStrTab;
+    pMachOStuff->pchShStrTab = pchShStrTab;
 
     /*
@@ -2911,9 +3005,9 @@
                              i, pszShNm, paShdrs[i].sh_size, cSymbols);
 
-            if (pElfStuff->iSymSh == UINT16_MAX)
-            {
-                pElfStuff->iSymSh    = (uint16_t)i;
-                pElfStuff->paSymbols = (Elf64_Sym const *)&pbFile[paShdrs[i].sh_offset];
-                pElfStuff->cSymbols  = cSymbols;
+            if (pMachOStuff->iSymSh == UINT16_MAX)
+            {
+                pMachOStuff->iSymSh    = (uint16_t)i;
+                pMachOStuff->paSymbols = (Elf64_Sym const *)&pbFile[paShdrs[i].sh_offset];
+                pMachOStuff->cSymbols  = cSymbols;
 
                 if (paShdrs[i].sh_link != 0)
@@ -2921,7 +3015,7 @@
                     /* Note! The symbol string table section header may not have been validated yet! */
                     Elf64_Shdr const *pStrTabShdr = &paShdrs[paShdrs[i].sh_link];
-                    pElfStuff->iStrSh    = paShdrs[i].sh_link;
-                    pElfStuff->pchStrTab = (const char *)&pbFile[pStrTabShdr->sh_offset];
-                    pElfStuff->cbStrTab  = (size_t)pStrTabShdr->sh_size;
+                    pMachOStuff->iStrSh    = paShdrs[i].sh_link;
+                    pMachOStuff->pchStrTab = (const char *)&pbFile[pStrTabShdr->sh_offset];
+                    pMachOStuff->cbStrTab  = (size_t)pStrTabShdr->sh_size;
                 }
                 else
@@ -2931,5 +3025,5 @@
             else
                 fRet = error(pszFile, "Section #%u '%s': Found additonal symbol table, previous in #%u\n",
-                             i, pszShNm, pElfStuff->iSymSh);
+                             i, pszShNm, pMachOStuff->iSymSh);
         }
     }
@@ -2937,5 +3031,5 @@
 }
 
-static bool convertElfSectionsToSegDefsAndGrpDefs(POMFWRITER pThis, PCELFDETAILS pElfStuff)
+static bool convertMachoSectionsToSegDefsAndGrpDefs(POMFWRITER pThis, PCMACHODETAILS pMachOStuff)
 {
     /*
@@ -2954,9 +3048,9 @@
 
     bool              fHaveData = false;
-    Elf64_Shdr const *pShdr     = &pElfStuff->paShdrs[1];
-    Elf64_Half const  cSections = pElfStuff->pEhdr->e_shnum;
+    Elf64_Shdr const *pShdr     = &pMachOStuff->paShdrs[1];
+    Elf64_Half const  cSections = pMachOStuff->pEhdr->e_shnum;
     for (Elf64_Half i = 1; i < cSections; i++, pShdr++)
     {
-        const char *pszName = &pElfStuff->pchShStrTab[pShdr->sh_name];
+        const char *pszName = &pMachOStuff->pchShStrTab[pShdr->sh_name];
         if (*pszName == '\0')
             return error(pThis->pszSrc, "Section #%u has an empty name!\n", i);
@@ -3048,5 +3142,5 @@
      */
     uint16_t iSegDef = 1; /* Start counting at 1. */
-    pShdr = &pElfStuff->paShdrs[1];
+    pShdr = &pMachOStuff->paShdrs[1];
     for (Elf64_Half i = 1; i < cSections; i++, pShdr++)
     {
@@ -3140,7 +3234,7 @@
 }
 
-static bool convertElfSymbolsToPubDefsAndExtDefs(POMFWRITER pThis, PCELFDETAILS pElfStuff)
-{
-    if (!pElfStuff->cSymbols)
+static bool convertMachOSymbolsToPubDefsAndExtDefs(POMFWRITER pThis, PCMACHODETAILS pMachOStuff)
+{
+    if (!pMachOStuff->cSymbols)
         return true;
 
@@ -3154,16 +3248,16 @@
         pThis->paSegments[iSeg].cPubDefs = 0;
 
-    uint32_t const          cSections = pElfStuff->pEhdr->e_shnum;
-    uint32_t const          cSymbols  = pElfStuff->cSymbols;
-    Elf64_Sym const * const paSymbols = pElfStuff->paSymbols;
+    uint32_t const          cSections = pMachOStuff->pEhdr->e_shnum;
+    uint32_t const          cSymbols  = pMachOStuff->cSymbols;
+    Elf64_Sym const * const paSymbols = pMachOStuff->paSymbols;
     for (uint32_t iSym = 0; iSym < cSymbols; iSym++)
     {
         const uint8_t bBind      = ELF64_ST_BIND(paSymbols[iSym].st_info);
         const uint8_t bType      = ELF64_ST_TYPE(paSymbols[iSym].st_info);
-        const char   *pszSymName = &pElfStuff->pchStrTab[paSymbols[iSym].st_name];
+        const char   *pszSymName = &pMachOStuff->pchStrTab[paSymbols[iSym].st_name];
         if (   *pszSymName == '\0'
             && bType == STT_SECTION
             && paSymbols[iSym].st_shndx < cSections)
-            pszSymName = &pElfStuff->pchShStrTab[pElfStuff->paShdrs[paSymbols[iSym].st_shndx].sh_name];
+            pszSymName = &pMachOStuff->pchShStrTab[pMachOStuff->paShdrs[paSymbols[iSym].st_shndx].sh_name];
 
         pThis->paSymbols[iSym].enmType   = OMFSYMTYPE_IGNORED;
@@ -3230,4 +3324,6 @@
     /*
      * Emit the PUBDEFs the first time around (see order of records in TIS spec).
+     * Note! We expect the os x compiler to always underscore symbols, so unlike the
+     *       other 64-bit converters we don't need to check for underscores and add them.
      */
     uint16_t idxPubDef = 1;
@@ -3244,25 +3340,7 @@
                         && pThis->paSymbols[iSym].enmType   == OMFSYMTYPE_PUBDEF)
                     {
-                        const char *pszName = &pElfStuff->pchStrTab[paSymbols[iSym].st_name];
-                        if (!omfWriter_PubDefAdd(pThis, paSymbols[iSym].st_value, pszName))
+                        const char *pszName = &pMachOStuff->pchStrTab[paSymbols[iSym].st_name];
+                        if (!omfWriter_PubDefAdd(pThis, paSymbols[iSym].st_value, pszName, false /*fPrependUnderscore*/))
                             return false;
-
-                        /* If the symbol doesn't start with an underscore and is a _c64 or _lm64 symbol,
-                           add an underscore prefixed alias to ease access from 16-bit and 32-bit code. */
-                        size_t cchName = strlen(pszName);
-                        if (   *pszName != '_'
-                            && (   (cchName > 4 && strcmp(&pszName[cchName - 4], "_c64")  == 0)
-                                || (cchName > 5 && strcmp(&pszName[cchName - 5], "_lm64") == 0) ) )
-                        {
-                            char   szCdeclName[512];
-                            if (cchName > sizeof(szCdeclName) - 2)
-                                cchName = sizeof(szCdeclName) - 2;
-                            szCdeclName[0] = '_';
-                            memcpy(&szCdeclName[1], pszName, cchName);
-                            szCdeclName[cchName + 1] = '\0';
-                            if (!omfWriter_PubDefAdd(pThis, paSymbols[iSym].st_value, szCdeclName))
-                                return false;
-                        }
-
                         pThis->paSymbols[iSym].idx = idxPubDef++;
                     }
@@ -3280,6 +3358,6 @@
                 && pThis->paSymbols[iSym].enmType   == OMFSYMTYPE_PUBDEF)
             {
-                const char *pszName = &pElfStuff->pchStrTab[paSymbols[iSym].st_name];
-                if (!omfWriter_PubDefAdd(pThis, paSymbols[iSym].st_value, pszName))
+                const char *pszName = &pMachOStuff->pchStrTab[paSymbols[iSym].st_name];
+                if (!omfWriter_PubDefAdd(pThis, paSymbols[iSym].st_value, pszName, false /*fPrependUnderscore*/))
                     return false;
                 pThis->paSymbols[iSym].idx = idxPubDef++;
@@ -3298,6 +3376,6 @@
         if (pThis->paSymbols[iSym].enmType == OMFSYMTYPE_EXTDEF)
         {
-            const char *pszName = &pElfStuff->pchStrTab[paSymbols[iSym].st_name];
-            if (!omfWriter_ExtDefAdd(pThis, pszName))
+            const char *pszName = &pMachOStuff->pchStrTab[paSymbols[iSym].st_name];
+            if (!omfWriter_ExtDefAdd(pThis, pszName, false /*fPrependUnderscore*/))
                 return false;
             pThis->paSymbols[iSym].idx = idxExtDef++;
@@ -3310,8 +3388,9 @@
 }
 
-static bool convertElfSectionsToLeDataAndFixupps(POMFWRITER pThis, PCELFDETAILS pElfStuff, uint8_t const *pbFile, size_t cbFile)
-{
-    Elf64_Sym const    *paSymbols = pElfStuff->paSymbols;
-    Elf64_Shdr const   *paShdrs   = pElfStuff->paShdrs;
+static bool convertMachOSectionsToLeDataAndFixupps(POMFWRITER pThis, PCMACHODETAILS pMachOStuff,
+                                                   uint8_t const *pbFile, size_t cbFile)
+{
+    Elf64_Sym const    *paSymbols = pMachOStuff->paSymbols;
+    Elf64_Shdr const   *paShdrs   = pMachOStuff->paShdrs;
     bool                fRet      = true;
     for (uint32_t i = 1; i < pThis->cSegments; i++)
@@ -3320,5 +3399,5 @@
             continue;
 
-        const char         *pszSegNm   = &pElfStuff->pchShStrTab[paShdrs[i].sh_name];
+        const char         *pszSegNm   = &pMachOStuff->pchShStrTab[paShdrs[i].sh_name];
         bool const          fRelocs    = i + 1 < pThis->cSegments && paShdrs[i + 1].sh_type == SHT_RELA;
         uint32_t            cRelocs    = fRelocs ? paShdrs[i + 1].sh_size / sizeof(Elf64_Rela) : 0;
@@ -3384,5 +3463,5 @@
                 Elf64_Sym const * const pElfSym    =        &paSymbols[iSymbol];
                 POMFSYMBOL const        pOmfSym    = &pThis->paSymbols[iSymbol];
-                const char * const      pszSymName = &pElfStuff->pchStrTab[pElfSym->st_name];
+                const char * const      pszSymName = &pMachOStuff->pchStrTab[pElfSym->st_name];
 
                 /* Calc fixup location in the pending chunk and setup a flexible pointer to it. */
@@ -3524,6 +3603,6 @@
      * Validate the source file a little.
      */
-    ELFDETAILS ElfStuff;
-    if (!validateElf(pszFile, pbFile, cbFile, &ElfStuff))
+    MACHODETAILS MachOStuff;
+    if (!validateMachO(pszFile, pbFile, cbFile, &MachOStuff))
         return false;
 
@@ -3531,5 +3610,5 @@
      * Instantiate the OMF writer.
      */
-    POMFWRITER pThis = omfWriter_Create(pszFile, ElfStuff.pEhdr->e_shnum, ElfStuff.cSymbols, pDst);
+    POMFWRITER pThis = omfWriter_Create(pszFile, MachOStuff.pEhdr->e_shnum, MachOStuff.cSymbols, pDst);
     if (!pThis)
         return false;
@@ -3544,8 +3623,8 @@
         const char       *pszStrTab = (const char *)&pbFile[paShdrs[pEhdr->e_shstrndx].sh_offset];
 
-        if (   convertElfSectionsToSegDefsAndGrpDefs(pThis, &ElfStuff)
-            && convertElfSymbolsToPubDefsAndExtDefs(pThis, &ElfStuff)
+        if (   convertMachOSectionsToSegDefsAndGrpDefs(pThis, &MachOStuff)
+            && convertMachOSymbolsToPubDefsAndExtDefs(pThis, &MachOStuff)
             && omfWriter_LinkPassSeparator(pThis)
-            && convertElfSectionsToLeDataAndFixupps(pThis, &ElfStuff, pbFile, cbFile)
+            && convertMachOSectionsToLeDataAndFixupps(pThis, &MachOStuff, pbFile, cbFile)
             && omfWriter_EndModule(pThis) )
         {
@@ -4682,8 +4761,8 @@
                                 }
 
-                            if (!omfWriter_ExtDefAddN(pThis, szName, cchName, idxType))
+                            if (!omfWriter_ExtDefAddN(pThis, szName, cchName, idxType, false /*fPrependUnderscore*/))
                                 return false;
                         }
-                        else if (!omfWriter_ExtDefAddN(pThis, pchName, cchName, idxType))
+                        else if (!omfWriter_ExtDefAddN(pThis, pchName, cchName, idxType, false /*fPrependUnderscore*/))
                             return false;
                     }
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-bootsector.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-bootsector.asm	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-bootsector.asm	(revision 60676)
@@ -225,8 +225,8 @@
 .do_load
         mov     [g_bBootDrv], dl
-        call    bs3InitLoadImage
+        call    NAME(bs3InitLoadImage)
 %if 0
         mov     al, '='
-        call bs3PrintChrInAl
+        call    NAME(bs3PrintChrInAl)
 %endif
 
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-c16-SwitchFromV86To16BitAndCallC.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-c16-SwitchFromV86To16BitAndCallC.asm	(revision 60676)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-c16-SwitchFromV86To16BitAndCallC.asm	(revision 60676)
@@ -0,0 +1,100 @@
+; $Id$
+;; @file
+; BS3Kit - Bs3SwitchFromV86To16BitAndCallC
+;
+
+;
+; Copyright (C) 2007-2015 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"
+%if TMPL_BITS != 16
+ %error "16-bit only"
+%endif
+
+
+;*********************************************************************************************************************************
+;*  External Symbols                                                                                                             *
+;*********************************************************************************************************************************
+%ifdef BS3_STRICT
+BS3_EXTERN_DATA16 g_bBs3CurrentMode
+TMPL_BEGIN_TEXT
+BS3_EXTERN_CMN    Bs3Panic
+%endif
+BS3_EXTERN_CMN    Bs3SwitchTo16Bit
+BS3_EXTERN_CMN    Bs3SwitchTo16BitV86
+BS3_EXTERN_CMN    Bs3SelRealModeCodeToProtMode
+
+
+;;
+; @cproto   BS3_CMN_PROTO_STUB(int, Bs3SwitchFromV86To16BitAndCallC,(FPFNBS3FAR fpfnCall, unsigned cbParams, ...));
+;
+BS3_PROC_BEGIN_CMN Bs3SwitchFromV86To16BitAndCallC, BS3_PBC_HYBRID
+        inc     bp
+        push    bp
+        mov     bp, sp
+
+        ;
+        ; Push the arguments first.
+        ;
+        mov     ax, si                  ; save si
+        mov     si, [bp + 2 + cbCurRetAddr + 4]
+%ifdef BS3_STRICT
+        test    si, 1
+        jz      .cbParams_ok
+        call    Bs3Panic
+.cbParams_ok:
+        test    byte [g_bBs3CurrentMode], BS3_MODE_CODE_V86
+        jnz     .mode_ok
+        call    Bs3Panic
+.mode_ok:
+%endif
+
+.push_more:
+        push    word [bp + 2 + cbCurRetAddr + 4 + 2 + si - 2]
+        sub     si, 2
+        jnz     .push_more
+        mov     si, ax                  ; restore si
+
+        ;
+        ; Convert the code segment to a 16-bit prot mode selector
+        ;
+        push    word [bp + 2 + cbCurRetAddr + 2]
+        call    Bs3SelRealModeCodeToProtMode
+        mov     [bp + 2 + cbCurRetAddr + 2], ax
+        add     sp, 2
+
+        ;
+        ; Switch mode.
+        ;
+        call    Bs3SwitchTo16Bit
+        call far [bp + 2 + cbCurRetAddr]
+        call    Bs3SwitchTo16BitV86
+
+        mov     sp, bp
+        pop     bp
+        dec     bp
+        BS3_HYBRID_RET
+BS3_PROC_END_CMN   Bs3SwitchFromV86To16BitAndCallC
+
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-MemAlloc.c
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-MemAlloc.c	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-MemAlloc.c	(revision 60676)
@@ -37,5 +37,14 @@
 {
     void BS3_FAR   *pvRet;
-    uint8_t         idxSlabList = bs3MemSizeToSlabListIndex(cb);
+    uint8_t         idxSlabList;
+
+#if ARCH_BITS == 16
+    /* Don't try allocate memory which address we cannot return. */
+    if (   enmKind != BS3MEMKIND_REAL
+        && BS3_MODE_IS_RM_OR_V86(g_bBs3CurrentMode))
+        enmKind = BS3MEMKIND_REAL;
+#endif
+
+    idxSlabList = bs3MemSizeToSlabListIndex(cb);
     if (idxSlabList < BS3_MEM_SLAB_LIST_COUNT)
     {
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-MemCmp.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-MemCmp.asm	(revision 60676)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-MemCmp.asm	(revision 60676)
@@ -0,0 +1,89 @@
+; $Id$
+;; @file
+; BS3Kit - Bs3MemCmp.
+;
+
+;
+; 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.
+;
+
+%include "bs3kit-template-header.mac"
+
+;;
+; @cproto   BS3_CMN_PROTO_NOSB(int, Bs3MemCmp,(void const BS3_FAR *pv1, void const BS3_FAR *pv2, size_t cb));
+;
+BS3_PROC_BEGIN_CMN Bs3MemCmp, BS3_PBC_HYBRID
+TONLY16 CPU 8086
+        push    xBP
+        mov     xBP, xSP
+        push    xDI
+        push    xSI
+TNOT64  push    es
+TONLY16 push    ds
+        cld
+
+        ;
+        ; To save complexity and space, do straight forward byte compares.
+        ;
+%if TMPL_BITS == 16
+        mov     di, [bp + 2 + cbCurRetAddr]         ; pv1.off
+        mov     es, [bp + 2 + cbCurRetAddr + 2]     ; pv1.sel
+        mov     si, [bp + 2 + cbCurRetAddr + 4]     ; pv2.off
+        mov     ds, [bp + 2 + cbCurRetAddr + 6]     ; pv2.sel
+        mov     cx, [bp + 2 + cbCurRetAddr + 8]     ; cbDst
+        xor     ax, ax
+        repe cmpsb
+        je      .return
+
+        mov     al, [es:di - 1]
+        xor     dx, dx
+        mov     dl, [esi - 1]
+        sub     ax, dx
+
+%else
+ %if TMPL_BITS == 64
+        mov     rdi, rcx                            ; rdi = pv1
+        mov     rsi, rdx                            ; rdi = pv2
+        mov     rcx, r8                             ; rcx = cbDst
+ %else
+        mov     ax, ds
+        mov     es, ax                              ; paranoia
+        mov     edi, [ebp + 4 + cbCurRetAddr]       ; pv1
+        mov     esi, [ebp + 4 + cbCurRetAddr + 4]   ; pv2
+        mov     ecx, [ebp + 4 + cbCurRetAddr + 8]   ; cbDst
+ %endif
+        xor     eax, eax
+        repe cmpsb
+        je      .return
+
+        mov     al, [xDI - 1]
+        movzx   edx, byte [xSI - 1]
+        sub     eax, edx
+%endif
+
+.return:
+TONLY16 pop     ds
+TNOT64  pop     es
+        pop     xSI
+        pop     xDI
+        pop     xBP
+        BS3_HYBRID_RET
+BS3_PROC_END_CMN   Bs3MemCmp
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-MemGuardedTestPage.c
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-MemGuardedTestPage.c	(revision 60676)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-MemGuardedTestPage.c	(revision 60676)
@@ -0,0 +1,98 @@
+/* $Id$ */
+/** @file
+ * BS3Kit - Bs3MemGuardedTestPageAlloc, Bs3MemGuardedTestPageFree
+ */
+
+/*
+ * 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.h"
+
+
+#undef Bs3MemGuardedTestPageAllocEx
+BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3MemGuardedTestPageAllocEx,(BS3MEMKIND enmKind, uint64_t fPte))
+{
+    uint8_t BS3_FAR *pb = (uint8_t BS3_FAR *)Bs3MemAlloc(enmKind, X86_PAGE_4K_SIZE * 3);
+    if (pb)
+    {
+        int rc;
+
+        Bs3MemSet(pb, 0xcc, X86_PAGE_4K_SIZE);
+        Bs3MemSet(&pb[X86_PAGE_4K_SIZE], 0x00, X86_PAGE_4K_SIZE);
+        Bs3MemSet(&pb[X86_PAGE_4K_SIZE*2], 0xaa, X86_PAGE_4K_SIZE);
+
+        rc = Bs3PagingProtectPtr(pb, X86_PAGE_4K_SIZE, fPte, UINT64_MAX & ~fPte);
+        if (RT_SUCCESS(rc))
+        {
+            rc = Bs3PagingProtectPtr(&pb[X86_PAGE_4K_SIZE*2], X86_PAGE_4K_SIZE, fPte, UINT64_MAX & ~fPte);
+            if (RT_SUCCESS(rc))
+                return pb + X86_PAGE_4K_SIZE;
+
+            Bs3TestPrintf("warning: Bs3MemGuardedTestPageAlloc - Tail protect error %d (mode %#x)\n", rc, g_bBs3CurrentMode);
+            Bs3PagingProtectPtr(pb, X86_PAGE_4K_SIZE, X86_PTE_P, 0);
+        }
+        else
+            Bs3TestPrintf("warning: Bs3MemGuardedTestPageAlloc - Head protect error %d (mode %#x)\n", rc, g_bBs3CurrentMode);
+        Bs3MemFree(pb, X86_PAGE_4K_SIZE * 3);
+    }
+    else
+        Bs3TestPrintf("warning: Bs3MemGuardedTestPageAlloc - out of memory (mode %#x)\n", g_bBs3CurrentMode);
+    return NULL;
+}
+
+
+#undef Bs3MemGuardedTestPageAlloc
+BS3_CMN_DEF(void BS3_FAR *, Bs3MemGuardedTestPageAlloc,(BS3MEMKIND enmKind))
+{
+    return BS3_CMN_FAR_NM(Bs3MemGuardedTestPageAllocEx)(enmKind, 0);
+}
+
+
+#undef Bs3MemGuardedTestPageFree
+BS3_CMN_DEF(void, Bs3MemGuardedTestPageFree,(void BS3_FAR *pvGuardedPage))
+{
+    if (pvGuardedPage)
+    {
+        uint8_t BS3_FAR *pbGuardViolation;
+        uint8_t BS3_FAR *pb = (uint8_t BS3_FAR *)pvGuardedPage - X86_PAGE_4K_SIZE;
+        Bs3PagingProtectPtr(pb, X86_PAGE_4K_SIZE,
+                            X86_PTE_P | X86_PTE_RW | X86_PTE_US | X86_PTE_A | X86_PTE_D, UINT64_MAX);
+        Bs3PagingProtectPtr(&pb[X86_PAGE_4K_SIZE*2], X86_PAGE_4K_SIZE,
+                            X86_PTE_P | X86_PTE_RW | X86_PTE_US | X86_PTE_A | X86_PTE_D, UINT64_MAX);
+
+        pbGuardViolation = ASMMemFirstMismatchingU8(pb, X86_PAGE_4K_SIZE, 0xcc);
+        if (pbGuardViolation)
+            Bs3TestFailedF("Leading guard page touched: byte %#05x is %#04x instead of 0xcc\n",
+                           (unsigned)(uintptr_t)(pbGuardViolation - pb), *pbGuardViolation);
+
+        pbGuardViolation = ASMMemFirstMismatchingU8(&pb[X86_PAGE_4K_SIZE*2], X86_PAGE_4K_SIZE, 0xaa);
+        if (pbGuardViolation)
+            Bs3TestFailedF("Trailing guard page touched: byte %#05x is %#04x instead of 0xaa\n",
+                           (unsigned)(uintptr_t)(pbGuardViolation - &pb[X86_PAGE_4K_SIZE*2]), *pbGuardViolation);
+
+        Bs3MemFree(pb, X86_PAGE_4K_SIZE * 3);
+    }
+}
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-PagingProtect.c
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-PagingProtect.c	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-PagingProtect.c	(revision 60676)
@@ -37,8 +37,13 @@
 *   Defined Constants And Macros                                                                                                 *
 *********************************************************************************************************************************/
+#if 1
+# define BS3PAGING_DPRINTF1(a) Bs3TestPrintf a
+#else
+# define BS3PAGING_DPRINTF1(a) do { } while (0)
+#endif
 #if 0
-# define BS3PAGING_DPRINTF(a) Bs3TestPrintf a
-#else
-# define BS3PAGING_DPRINTF(a) do { } while (0)
+# define BS3PAGING_DPRINTF2(a) Bs3TestPrintf a
+#else
+# define BS3PAGING_DPRINTF2(a) do { } while (0)
 #endif
 
@@ -68,5 +73,5 @@
     uint32_t const  uMaxAddr = UINT32_MAX;
 #endif
-    BS3PAGING_DPRINTF(("bs3PagingGetLegacyPte: cr3=%RX32 uFlat=%RX32 uMaxAddr=%RX32\n", (uint32_t)cr3, uFlat, uMaxAddr));
+    BS3PAGING_DPRINTF2(("bs3PagingGetLegacyPte: cr3=%RX32 uFlat=%RX32 uMaxAddr=%RX32\n", (uint32_t)cr3, uFlat, uMaxAddr));
 
     *prc = VERR_OUT_OF_RANGE;
@@ -82,5 +87,5 @@
 
             BS3_ASSERT(pPD->a[iPde].b.u1Present);
-            BS3PAGING_DPRINTF(("bs3PagingGetLegacyPte: pPD=%p iPde=%#x: %#RX32\n", pPD, iPde, pPD->a[iPde]));
+            BS3PAGING_DPRINTF2(("bs3PagingGetLegacyPte: pPD=%p iPde=%#x: %#RX32\n", pPD, iPde, pPD->a[iPde]));
             if (pPD->a[iPde].b.u1Present)
             {
@@ -88,5 +93,10 @@
                 {
                     if (pPD->a[iPde].u <= uMaxAddr)
+                    {
                         pPTE = &((X86PT BS3_FAR *)Bs3XptrFlatToCurrent(pPD->a[iPde].u & ~(uint32_t)PAGE_OFFSET_MASK))->a[iPte];
+                        *prc = VINF_SUCCESS;
+                    }
+                    else
+                        BS3PAGING_DPRINTF1(("bs3PagingGetLegacyPte: out of range! iPde=%#x: %#x\n", iPde, pPD->a[iPde].u));
                 }
                 else
@@ -99,17 +109,18 @@
                         uPte |= X86_PTE_PAT;
 
-                    pPT = (X86PT BS3_FAR *)bs3PagingBuildPaeTable(RT_MAKE_U64(uPte, uPte + PAGE_SIZE),
+                    pPT = (X86PT BS3_FAR *)bs3PagingBuildPaeTable(RT_MAKE_U64(uPte, uPte | PAGE_SIZE),
                                                                   RT_MAKE_U64(PAGE_SIZE*2, PAGE_SIZE*2),
                                                                   uMaxAddr > _1M ? BS3MEMKIND_TILED : BS3MEMKIND_REAL, prc);
 
-                    BS3PAGING_DPRINTF(("bs3PagingGetLegacyPte: Built pPT=%p uPte=%RX32\n", pPT, uPte));
+                    BS3PAGING_DPRINTF2(("bs3PagingGetLegacyPte: Built pPT=%p uPte=%RX32\n", pPT, uPte));
                     if (pPT)
                     {
                         pPD->a[iPde].u = Bs3SelPtrToFlat(pPT)
                                        | (pPD->a[iPde].u & ~(uint32_t)(X86_PTE_PG_MASK | X86_PDE4M_PS | X86_PDE4M_G | X86_PDE4M_D));
-                        BS3PAGING_DPRINTF(("bs3PagingGetLegacyPte: iPde=%#x: %#RX32\n", iPde, pPD->a[iPde].u));
+                        BS3PAGING_DPRINTF2(("bs3PagingGetLegacyPte: iPde=%#x: %#RX32\n", iPde, pPD->a[iPde].u));
                         if (fUseInvlPg)
                             ASMInvalidatePage(uFlat);
                         pPTE = &pPT->a[iPte];
+                        *prc = VINF_SUCCESS;
                     }
                 }
@@ -117,4 +128,6 @@
         }
     }
+    else
+        BS3PAGING_DPRINTF1(("bs3PagingGetLegacyPte: out of range! cr3=%#x\n", cr3));
     return pPTE;
 }
@@ -149,4 +162,7 @@
                     if ((pPdpt->a[iPdpte].u & X86_PDPE_PG_MASK) <= uMaxAddr)
                         pPD = (X86PDPAE BS3_FAR *)Bs3XptrFlatToCurrent(pPdpt->a[iPdpte].u & ~(uint64_t)PAGE_OFFSET_MASK);
+                    else
+                        BS3PAGING_DPRINTF1(("bs3PagingGetPte: out of range! iPdpte=%#x: %RX64 max=%RX32\n",
+                                            iPdpte, pPdpt->a[iPdpte].u, (uint32_t)uMaxAddr));
                 }
                 else
@@ -174,7 +190,13 @@
             if ((pPdpt->a[iPdpte].u & X86_PDPE_PG_MASK) <= uMaxAddr)
                 pPD = (X86PDPAE BS3_FAR *)Bs3XptrFlatToCurrent(pPdpt->a[iPdpte].u & X86_PDPE_PG_MASK);
+            else
+                BS3PAGING_DPRINTF1(("bs3PagingGetPte: out of range! iPdpte=%#x: %RX64 max=%RX32\n",
+                                    iPdpte, pPdpt->a[iPdpte].u, (uint32_t)uMaxAddr));
         }
         else
+        {
             pPD = NULL;
+            BS3PAGING_DPRINTF1(("bs3PagingGetPte: out of range! uFlat=%#RX64 max=%RX32\n", uFlat, (uint32_t)uMaxAddr));
+        }
         if (pPD)
         {
@@ -184,5 +206,11 @@
             {
                 if ((pPD->a[iPde].u & X86_PDE_PAE_PG_MASK) <= uMaxAddr)
+                {
                     pPTE = &((X86PTPAE BS3_FAR *)Bs3XptrFlatToCurrent(pPD->a[iPde].u & ~(uint64_t)PAGE_OFFSET_MASK))->a[iPte];
+                    *prc = VINF_SUCCESS;
+                }
+                else
+                    BS3PAGING_DPRINTF1(("bs3PagingGetPte: out of range! iPde=%#x: %RX64 max=%RX32\n",
+                                        iPde, pPD->a[iPde].u, (uint32_t)uMaxAddr));
             }
             else
@@ -205,9 +233,11 @@
                         ASMInvalidatePage(uFlat);
                     pPTE = &pPT->a[iPte];
+                    *prc = VINF_SUCCESS;
                 }
             }
         }
     }
-
+    else
+        BS3PAGING_DPRINTF1(("bs3PagingGetPte: out of range! cr3=%#RX32 uMaxAddr=%#RX32\n", (uint32_t)cr3, (uint32_t)uMaxAddr));
     return pPTE;
 }
@@ -217,84 +247,95 @@
 BS3_CMN_DEF(int, Bs3PagingProtect,(uint64_t uFlat, uint64_t cb, uint64_t fSet, uint64_t fClear))
 {
-    RTCCUINTXREG const  cr3        = ASMGetCR3();
-    RTCCUINTXREG const  cr4        = g_uBs3CpuDetected & BS3CPU_F_CPUID ? ASMGetCR4() : 0;
-    bool const          fLegacyPTs = !(cr4 & X86_CR4_PAE);
-    bool const          fUseInvlPg = (g_uBs3CpuDetected & BS3CPU_TYPE_MASK) >= BS3CPU_80486
-                                  && (   cb < UINT64_C(16)*PAGE_SIZE
-                                      || (cr4 & X86_CR4_PGE));
-    unsigned            cEntries;
-    int                 rc;
-
+#if ARCH_BITS == 16
+    if (!BS3_MODE_IS_V86(g_bBs3CurrentMode))
+#endif
+    {
+        RTCCUINTXREG const  cr3        = ASMGetCR3();
+        RTCCUINTXREG const  cr4        = g_uBs3CpuDetected & BS3CPU_F_CPUID ? ASMGetCR4() : 0;
+        bool const          fLegacyPTs = !(cr4 & X86_CR4_PAE);
+        bool const          fUseInvlPg = (g_uBs3CpuDetected & BS3CPU_TYPE_MASK) >= BS3CPU_80486
+                                      && (   cb < UINT64_C(16)*PAGE_SIZE
+                                          || (cr4 & X86_CR4_PGE));
+        unsigned            cEntries;
+        int                 rc;
+
+        /*
+         * Adjust the range parameters.
+         */
+        cb += uFlat & PAGE_OFFSET_MASK;
+        cb = RT_ALIGN_64(cb, PAGE_SIZE);
+        uFlat &= ~(uint64_t)PAGE_OFFSET_MASK;
+
+        fSet   &= ~X86_PTE_PAE_PG_MASK;
+        fClear &= ~X86_PTE_PAE_PG_MASK;
+
+        BS3PAGING_DPRINTF1(("Bs3PagingProtect: uFlat=%RX64 cb=%RX64 fSet=%RX64 fClear=%RX64 %s %s\n", uFlat, cb, fSet, fClear,
+                            fLegacyPTs ? "legacy" : "pae/amd64", fUseInvlPg ? "invlpg" : "reload-cr3"));
+        if (fLegacyPTs)
+        {
+            /*
+             * Legacy page tables.
+             */
+            while ((uint32_t)cb > 0)
+            {
+                PX86PTE pPte = BS3_CMN_FAR_NM(bs3PagingGetLegacyPte)(cr3, (uint32_t)uFlat, fUseInvlPg, &rc);
+                if (!pPte)
+                    return rc;
+
+                cEntries = X86_PG_ENTRIES - ((uFlat >> X86_PT_SHIFT) & X86_PT_MASK);
+                while (cEntries-- > 0 && cb > 0)
+                {
+                    pPte->u &= ~(uint32_t)fClear;
+                    pPte->u |= (uint32_t)fSet;
+                    if (fUseInvlPg)
+                        ASMInvalidatePage(uFlat);
+
+                    pPte++;
+                    uFlat += PAGE_SIZE;
+                    cb    -= PAGE_SIZE;
+                }
+            }
+        }
+        else
+        {
+            /*
+             * Long mode or PAE page tables (at this level they are the same).
+             */
+            while (cb > 0)
+            {
+                PX86PTEPAE pPte = BS3_CMN_FAR_NM(bs3PagingGetPte)(cr3, uFlat, fUseInvlPg, &rc);
+                if (!pPte)
+                    return rc;
+
+                cEntries = X86_PG_ENTRIES - ((uFlat >> X86_PT_PAE_SHIFT) & X86_PT_PAE_MASK);
+                while (cEntries-- > 0 && cb > 0)
+                {
+                    pPte->u &= ~fClear;
+                    pPte->u |= fSet;
+                    if (fUseInvlPg)
+                        ASMInvalidatePage(uFlat);
+
+                    pPte++;
+                    uFlat += PAGE_SIZE;
+                    cb    -= PAGE_SIZE;
+                }
+            }
+        }
+
+        /*
+         * Flush the TLB if we didn't use INVLPG above.
+         */
+        BS3PAGING_DPRINTF2(("Bs3PagingProtect: reloading cr3=%RX32\n", (uint32_t)cr3));
+        //if (!fUseInvlPg)
+            ASMSetCR3(cr3);
+        BS3PAGING_DPRINTF2(("Bs3PagingProtect: reloaded cr3=%RX32\n", (uint32_t)cr3));
+    }
+#if ARCH_BITS == 16
     /*
-     * Adjust the range parameters.
+     * We can do this stuff in v8086 mode.
      */
-    cb += uFlat & PAGE_OFFSET_MASK;
-    cb = RT_ALIGN_64(cb, PAGE_SIZE);
-    uFlat &= ~(uint64_t)PAGE_OFFSET_MASK;
-
-    fSet   &= ~X86_PTE_PAE_PG_MASK;
-    fClear &= ~X86_PTE_PAE_PG_MASK;
-
-    BS3PAGING_DPRINTF(("Bs3PagingProtect: uFlat=%RX64 cb=%RX64 fSet=%RX64 fClear=%RX64 %s %s\n", uFlat, cb, fSet, fClear,
-                       fLegacyPTs ? "legacy" : "pae/amd64", fUseInvlPg ? "invlpg" : "reload-cr3"));
-    if (fLegacyPTs)
-    {
-        /*
-         * Legacy page tables.
-         */
-        while ((uint32_t)cb > 0)
-        {
-            PX86PTE pPte = BS3_CMN_NM(bs3PagingGetLegacyPte)(cr3, (uint32_t)uFlat, fUseInvlPg, &rc);
-            if (!pPte)
-                return rc;
-
-            cEntries = X86_PG_ENTRIES - ((uFlat >> X86_PT_SHIFT) & X86_PT_MASK);
-            while (cEntries-- > 0 && cb > 0)
-            {
-                pPte->u &= ~(uint32_t)fClear;
-                pPte->u |= (uint32_t)fSet;
-                if (fUseInvlPg)
-                    ASMInvalidatePage(uFlat);
-
-                pPte++;
-                uFlat += PAGE_SIZE;
-                cb    -= PAGE_SIZE;
-            }
-        }
-    }
     else
-    {
-        /*
-         * Long mode or PAE page tables (at this level they are the same).
-         */
-        while (cb > 0)
-        {
-            PX86PTEPAE pPte = BS3_CMN_NM(bs3PagingGetPte)(cr3, uFlat, fUseInvlPg, &rc);
-            if (!pPte)
-                return rc;
-
-            cEntries = X86_PG_ENTRIES - ((uFlat >> X86_PT_PAE_SHIFT) & X86_PT_PAE_MASK);
-            while (cEntries-- > 0 && cb > 0)
-            {
-                pPte->u &= ~fClear;
-                pPte->u |= fSet;
-                if (fUseInvlPg)
-                    ASMInvalidatePage(uFlat);
-
-                pPte++;
-                uFlat += PAGE_SIZE;
-                cb    -= PAGE_SIZE;
-            }
-        }
-    }
-
-    /*
-     * Flush the TLB if we didn't use INVLPG above.
-     */
-    BS3PAGING_DPRINTF(("Bs3PagingProtect: reloading cr3=%RX32\n", (uint32_t)cr3));
-    //if (!fUseInvlPg)
-        ASMSetCR3(cr3);
-    BS3PAGING_DPRINTF(("Bs3PagingProtect: reloaded cr3=%RX32\n", (uint32_t)cr3));
-
+        return Bs3SwitchFromV86To16BitAndCallC((FPFNBS3FAR)Bs3PagingProtect_f16, sizeof(uint64_t)*4, uFlat, cb, fSet, fClear);
+#endif
     return VINF_SUCCESS;
 }
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-RegCtxSetGrpSegFromCurPtr.c
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-RegCtxSetGrpSegFromCurPtr.c	(revision 60676)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-RegCtxSetGrpSegFromCurPtr.c	(revision 60676)
@@ -0,0 +1,49 @@
+/* $Id$ */
+/** @file
+ * BS3Kit - Bs3RegCtxSetGrpSegFromCurPtr, Bs3RegCtxSetGrpDsFromCurPtr
+ */
+
+/*
+ * 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"
+
+
+#undef Bs3RegCtxSetGrpSegFromCurPtr
+BS3_CMN_DEF(void, Bs3RegCtxSetGrpSegFromCurPtr,(PBS3REGCTX pRegCtx, PBS3REG pGpr, PRTSEL pSel, void  BS3_FAR *pvPtr))
+{
+#if ARCH_BITS == 16
+    Bs3RegCtxSetGrpSegFromFlat(pRegCtx, pGpr, pSel, Bs3SelPtrToFlat(pvPtr));
+#else
+    Bs3RegCtxSetGrpSegFromFlat(pRegCtx, pGpr, pSel, (uintptr_t)pvPtr);
+#endif
+}
+
+
+#undef Bs3RegCtxSetGrpDsFromCurPtr
+BS3_CMN_DEF(void, Bs3RegCtxSetGrpDsFromCurPtr,(PBS3REGCTX pRegCtx, PBS3REG pGpr, void  BS3_FAR *pvPtr))
+{
+    BS3_CMN_FAR_NM(Bs3RegCtxSetGrpSegFromCurPtr)(pRegCtx, pGpr, &pRegCtx->ds, pvPtr);
+}
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-RegCtxSetGrpSegFromFlat.c
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-RegCtxSetGrpSegFromFlat.c	(revision 60676)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-RegCtxSetGrpSegFromFlat.c	(revision 60676)
@@ -0,0 +1,64 @@
+/* $Id$ */
+/** @file
+ * BS3Kit - Bs3RegCtxSetGrpSegFromFlat
+ */
+
+/*
+ * 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"
+
+
+#undef Bs3RegCtxSetGrpSegFromFlat
+BS3_CMN_DEF(void, Bs3RegCtxSetGrpSegFromFlat,(PBS3REGCTX pRegCtx, PBS3REG pGpr, PRTSEL pSel, RTCCUINTXREG uFlat))
+{
+    if (BS3_MODE_IS_16BIT_CODE(pRegCtx->bMode))
+    {
+        uint32_t uFar1616;
+        if (BS3_MODE_IS_RM_OR_V86(pRegCtx->bMode))
+            uFar1616 = Bs3SelFlatDataToRealMode(uFlat);
+        else
+            uFar1616 = Bs3SelFlatDataToProtFar16(uFlat);
+        pGpr->u  = uFar1616 & UINT16_MAX;
+        *pSel    = uFar1616 >> 16;
+    }
+    else
+    {
+        pGpr->u  = uFlat;
+        if (BS3_MODE_IS_32BIT_CODE(pRegCtx->bMode))
+            *pSel = BS3_SEL_R0_DS32;
+        else
+            *pSel = BS3_SEL_R0_DS64;
+    }
+
+    /* Adjust CS to the right ring, if not ring-0 or V86 context. */
+    if (   pRegCtx->bCpl != 0
+        && !BS3_MODE_IS_RM_OR_V86(pRegCtx->bMode)
+        && BS3_SEL_IS_IN_R0_RANGE(*pSel))
+    {
+        *pSel += (uint16_t)pRegCtx->bCpl << BS3_SEL_RING_SHIFT;
+        *pSel |= pRegCtx->bCpl;
+    }
+}
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-RegCtxSetRipCsFromLnkPtr.c
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-RegCtxSetRipCsFromLnkPtr.c	(revision 60676)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-RegCtxSetRipCsFromLnkPtr.c	(revision 60676)
@@ -0,0 +1,76 @@
+/* $Id$ */
+/** @file
+ * BS3Kit - Bs3RegCtxSetRipCsFromLnkPtr
+ */
+
+/*
+ * 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"
+
+
+#undef Bs3RegCtxSetRipCsFromLnkPtr
+BS3_CMN_DEF(void, Bs3RegCtxSetRipCsFromLnkPtr,(PBS3REGCTX pRegCtx, FPFNBS3FAR pfnCode))
+{
+    if (BS3_MODE_IS_16BIT_CODE(pRegCtx->bMode))
+    {
+#if ARCH_BITS == 16
+        pRegCtx->rip.u = BS3_FP_OFF(pfnCode);
+        if (BS3_MODE_IS_RM_OR_V86(pRegCtx->bMode))
+            pRegCtx->cs = BS3_FP_SEG(pfnCode);
+        else
+            pRegCtx->cs = Bs3SelRealModeCodeToProtMode(BS3_FP_SEG(pfnCode));
+#else
+        uint32_t uFar1616;
+        if (BS3_MODE_IS_RM_OR_V86(pRegCtx->bMode))
+            uFar1616 = Bs3SelFlatCodeToRealMode((uint32_t)(uintptr_t)pfnCode);
+        else
+            uFar1616 = Bs3SelFlatCodeToProtFar16((uint32_t)(uintptr_t)pfnCode);
+        pRegCtx->rip.u = uFar1616 & UINT16_MAX;
+        pRegCtx->cs    = uFar1616 >> 16;
+#endif
+    }
+    else
+    {
+#if ARCH_BITS == 16
+        pRegCtx->rip.u = Bs3SelRealModeCodeToFlat(pfnCode);
+#else
+        pRegCtx->rip.u = (uintptr_t)pfnCode;
+#endif
+        if (BS3_MODE_IS_32BIT_CODE(pRegCtx->bMode))
+            pRegCtx->cs = BS3_SEL_R0_CS32;
+        else
+            pRegCtx->cs = BS3_SEL_R0_CS64;
+    }
+
+    /* Adjust CS to the right ring, if not ring-0 or V86 context. */
+    if (   pRegCtx->bCpl != 0
+        && !BS3_MODE_IS_RM_OR_V86(pRegCtx->bMode)
+        && BS3_SEL_IS_IN_R0_RANGE(pRegCtx->cs))
+    {
+        pRegCtx->cs += (uint16_t)pRegCtx->bCpl << BS3_SEL_RING_SHIFT;
+        pRegCtx->cs |= pRegCtx->bCpl;
+    }
+}
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SelRealModeDataToFlat.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SelRealModeDataToFlat.asm	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SelRealModeDataToFlat.asm	(revision 60676)
@@ -43,8 +43,10 @@
 ;;
 ; @cproto   BS3_CMN_PROTO_NOSB(uint32_t, Bs3SelRealModeDataToFlat,(uint32_t uFar1616));
+; @cproto   BS3_CMN_PROTO_NOSB(uint32_t, Bs3SelRealModeCodeToFlat,(uint32_t uFar1616));
 ;
 ; @uses     Only return registers (ax:dx, eax, eax);
 ; @remarks  No 20h scratch area requirements.
 ;
+BS3_PROC_BEGIN_CMN Bs3SelRealModeCodeToFlat, BS3_PBC_NEAR      ; Far stub generated by the makefile/bs3kit.h.
 BS3_PROC_BEGIN_CMN Bs3SelRealModeDataToFlat, BS3_PBC_NEAR      ; Far stub generated by the makefile/bs3kit.h.
         push    xBP
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-EnteredMode.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-EnteredMode.asm	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-EnteredMode.asm	(revision 60676)
@@ -221,12 +221,12 @@
 %elif BS3_MODE_IS_64BIT_SYS(TMPL_MODE)
         BS3_EXTERN_CMN Bs3Trap64SetGate
-        extern         Bs3TrapSystemCallHandler_lm64
+        extern         _Bs3TrapSystemCallHandler_lm64
         TMPL_BEGIN_TEXT
         push    0                       ; bIst
  %if BS3_MODE_IS_64BIT_CODE(TMPL_MODE)
-        push    Bs3TrapSystemCallHandler_lm64 wrt FLAT
+        push    _Bs3TrapSystemCallHandler_lm64 wrt FLAT
  %else
         push    dword 0                 ; upper offset
-        push    dword Bs3TrapSystemCallHandler_lm64 wrt FLAT
+        push    dword _Bs3TrapSystemCallHandler_lm64 wrt FLAT
  %endif
         push    BS3_SEL_R0_CS64
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TestDoModesHlp.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TestDoModesHlp.asm	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TestDoModesHlp.asm	(revision 60676)
@@ -134,5 +134,5 @@
 extern RT_CONCAT3(_Bs3SwitchTo,TMPL_MODE_UNAME,_Safe_pae32):wrt BS3FLAT
 extern RT_CONCAT3(_Bs3SwitchTo,TMPL_MODE_UNAME,_Safe_lm32):wrt BS3FLAT
-extern RT_CONCAT3(Bs3SwitchTo,TMPL_MODE_UNAME,_Safe_lm64):wrt BS3FLAT
+extern RT_CONCAT3(_Bs3SwitchTo,TMPL_MODE_UNAME,_Safe_lm64):wrt BS3FLAT
 
 
@@ -1105,5 +1105,5 @@
 
         STRICT_SAVE_REGS
-        call    RT_CONCAT3(Bs3SwitchTo,TMPL_MODE_UNAME,_Safe_lm64)
+        call    RT_CONCAT3(_Bs3SwitchTo,TMPL_MODE_UNAME,_Safe_lm64)
         BS3_SET_BITS TMPL_BITS
         STRICT_CHECK_REGS
@@ -1133,2 +1133,3 @@
 
 %endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc16-I8DQ.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc16-I8DQ.asm	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc16-I8DQ.asm	(revision 60676)
@@ -33,5 +33,5 @@
 ; 64-bit unsigned integer division, SS variant.
 ;
-; @returns  ax:bx:cx:dx quotient.
+; @returns  ax:bx:cx:dx quotient. (AX is the most significant, DX the least)
 ; @param    ax:bx:cx:dx     Dividend.
 ; @param    [ss:si]         Divisor
@@ -58,5 +58,5 @@
 ; 64-bit unsigned integer division, ES variant.
 ;
-; @returns  ax:bx:cx:dx quotient.
+; @returns  ax:bx:cx:dx quotient. (AX is the most significant, DX the least)
 ; @param    ax:bx:cx:dx     Dividend.
 ; @param    [es:si]         Divisor
@@ -88,8 +88,8 @@
 
         ; The dividend.
+        push    ax
+        push    bx
+        push    cx
         push    dx
-        push    cx
-        push    bx
-        push    ax
 
         call    Bs3Int64Div
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc16-I8DR.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc16-I8DR.asm	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc16-I8DR.asm	(revision 60676)
@@ -33,5 +33,5 @@
 ; 64-bit unsigned integer modulo, SS variant.
 ;
-; @returns  ax:bx:cx:dx reminder.
+; @returns  ax:bx:cx:dx reminder. (AX is the most significant, DX the least)
 ; @param    ax:bx:cx:dx     Dividend.
 ; @param    [ss:si]         Divisor
@@ -88,8 +88,8 @@
 
         ; The dividend.
+        push    ax
+        push    bx
+        push    cx
         push    dx
-        push    cx
-        push    bx
-        push    ax
 
         call    Bs3Int64Div
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc16-I8RS.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc16-I8RS.asm	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc16-I8RS.asm	(revision 60676)
@@ -31,5 +31,5 @@
 ; 64-bit signed integer left shift.
 ;
-; @returns  AX:BX:CX:DX
+; @returns  AX:BX:CX:DX (AX is the most significant, DX the least)
 ; @param    AX:BX:CX:DX Value to shift.
 ; @param    SI          Shift count.
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc16-U8DQ.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc16-U8DQ.asm	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc16-U8DQ.asm	(revision 60676)
@@ -33,5 +33,5 @@
 ; 64-bit unsigned integer division, SS variant.
 ;
-; @returns  ax:bx:cx:dx quotient.
+; @returns  ax:bx:cx:dx quotient.  (AX is the most significant, DX the least)
 ; @param    ax:bx:cx:dx     Dividend.
 ; @param    [ss:si]         Divisor
@@ -58,5 +58,5 @@
 ; 64-bit unsigned integer division, ES variant.
 ;
-; @returns  ax:bx:cx:dx quotient.
+; @returns  ax:bx:cx:dx quotient. (AX is the most significant, DX the least)
 ; @param    ax:bx:cx:dx     Dividend.
 ; @param    [es:si]         Divisor
@@ -90,8 +90,8 @@
 
         ; The dividend.
+        push    ax
+        push    bx
+        push    cx
         push    dx
-        push    cx
-        push    bx
-        push    ax
 
         call    Bs3UInt64Div
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc16-U8DR.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc16-U8DR.asm	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc16-U8DR.asm	(revision 60676)
@@ -33,5 +33,5 @@
 ; 64-bit unsigned integer modulo, SS variant.
 ;
-; @returns  ax:bx:cx:dx reminder.
+; @returns  ax:bx:cx:dx reminder. (AX is the most significant, DX the least)
 ; @param    ax:bx:cx:dx     Dividend.
 ; @param    [ss:si]         Divisor
@@ -58,5 +58,5 @@
 ; 64-bit unsigned integer modulo, ES variant.
 ;
-; @returns  ax:bx:cx:dx reminder.
+; @returns  ax:bx:cx:dx reminder. (AX is the most significant, DX the least)
 ; @param    ax:bx:cx:dx     Dividend.
 ; @param    [es:si]         Divisor
@@ -90,8 +90,8 @@
 
         ; The dividend.
+        push    ax
+        push    bx
+        push    cx
         push    dx
-        push    cx
-        push    bx
-        push    ax
 
         call    Bs3UInt64Div
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc16-U8LS.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc16-U8LS.asm	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc16-U8LS.asm	(revision 60676)
@@ -31,5 +31,5 @@
 ; 64-bit integer left shift.
 ;
-; @returns  AX:BX:CX:DX
+; @returns  AX:BX:CX:DX (AX is the most significant, DX the least)
 ; @param    AX:BX:CX:DX Value to shift.
 ; @param    SI          Shift count.
@@ -47,15 +47,15 @@
         ; time in the below loop.
         ;
-        ; Using 8086 comatible approach here as it's less hazzle to write
+        ; Using 8086 compatible approach here as it's less hazzle to write
         ; and smaller.
         ;
         and     si, 3fh
+
         jz      .return
-
 .next_shift:
-        shl     ax, 1
+        shl     dx, 1
+        rcl     cx, 1
         rcl     bx, 1
-        rcl     cx, 1
-        rcl     dx, 1
+        rcl     ax, 1
         dec     si
         jnz     .next_shift
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc16-U8RS.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc16-U8RS.asm	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-wc16-U8RS.asm	(revision 60676)
@@ -31,5 +31,5 @@
 ; 64-bit unsigned integer left shift.
 ;
-; @returns  AX:BX:CX:DX
+; @returns  AX:BX:CX:DX (AX is the most significant, DX the least)
 ; @param    AX:BX:CX:DX Value to shift.
 ; @param    SI          Shift count.
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-autostubs.kmk
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-autostubs.kmk	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-autostubs.kmk	(revision 60676)
@@ -29,4 +29,5 @@
 $(call BS3KIT_FN_GEN_CMN_FARSTUB,bs3kit-common-16,Bs3SelProtFar16DataToFlat,4)
 $(call BS3KIT_FN_GEN_CMN_FARSTUB,bs3kit-common-16,Bs3SelProtFar16DataToRealMode,4)
+$(call BS3KIT_FN_GEN_CMN_FARSTUB,bs3kit-common-16,Bs3SelRealModeCodeToFlat,4)
 $(call BS3KIT_FN_GEN_CMN_FARSTUB,bs3kit-common-16,Bs3SelRealModeDataToFlat,4)
 $(call BS3KIT_FN_GEN_CMN_FARSTUB,bs3kit-common-16,Bs3SelRealModeDataToProtFar16,4)
@@ -40,4 +41,5 @@
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3PagingProtect)
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3PagingProtectPtr)
+$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3SwitchFromV86To16BitAndCallC)
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3TrapSetHandler)
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3Printf)
@@ -55,4 +57,6 @@
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3MemAllocZ)
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3MemCpy)
+$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3MemGuardedTestPageAlloc)
+$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3MemGuardedTestPageAllocEx)
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3MemMove)
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3MemPCpy)
@@ -62,8 +66,13 @@
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3SlabListAllocEx)
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3MemFree)
+$(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,Bs3PrintStr)
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3RegCtxConvertToRingX)
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3RegCtxPrint)
+$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3RegCtxSetGrpDsFromCurPtr)
+$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3RegCtxSetGrpSegFromCurPtr)
+$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3RegCtxSetGrpSegFromFlat)
+$(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3RegCtxSetRipCsFromLnkPtr)
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3SlabInit)
 $(call BS3KIT_FN_GEN_CMN_NEARSTUB,bs3kit-common-16,Bs3SlabListAdd)
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-define.h
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-define.h	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-define.h	(revision 60676)
@@ -37,6 +37,10 @@
 #define Bs3MemAllocZ BS3_CMN_MANGLER(Bs3MemAllocZ)
 #define Bs3MemChr BS3_CMN_MANGLER(Bs3MemChr)
+#define Bs3MemCmp BS3_CMN_MANGLER(Bs3MemCmp)
 #define Bs3MemCpy BS3_CMN_MANGLER(Bs3MemCpy)
 #define Bs3MemFree BS3_CMN_MANGLER(Bs3MemFree)
+#define Bs3MemGuardedTestPageAlloc BS3_CMN_MANGLER(Bs3MemGuardedTestPageAlloc)
+#define Bs3MemGuardedTestPageAllocEx BS3_CMN_MANGLER(Bs3MemGuardedTestPageAllocEx)
+#define Bs3MemGuardedTestPageFree BS3_CMN_MANGLER(Bs3MemGuardedTestPageFree)
 #define Bs3MemMove BS3_CMN_MANGLER(Bs3MemMove)
 #define Bs3MemPCpy BS3_CMN_MANGLER(Bs3MemPCpy)
@@ -62,4 +66,8 @@
 #define Bs3RegCtxSave BS3_CMN_MANGLER(Bs3RegCtxSave)
 #define Bs3RegCtxSaveEx BS3_CMN_MANGLER(Bs3RegCtxSaveEx)
+#define Bs3RegCtxSetGrpDsFromCurPtr BS3_CMN_MANGLER(Bs3RegCtxSetGrpDsFromCurPtr)
+#define Bs3RegCtxSetGrpSegFromCurPtr BS3_CMN_MANGLER(Bs3RegCtxSetGrpSegFromCurPtr)
+#define Bs3RegCtxSetGrpSegFromFlat BS3_CMN_MANGLER(Bs3RegCtxSetGrpSegFromFlat)
+#define Bs3RegCtxSetRipCsFromLnkPtr BS3_CMN_MANGLER(Bs3RegCtxSetRipCsFromLnkPtr)
 #define Bs3SelFar32ToFlat32 BS3_CMN_MANGLER(Bs3SelFar32ToFlat32)
 #define Bs3SelFar32ToFlat32NoClobber BS3_CMN_MANGLER(Bs3SelFar32ToFlat32NoClobber)
@@ -72,4 +80,5 @@
 #define Bs3SelProtFar32ToFlat32 BS3_CMN_MANGLER(Bs3SelProtFar32ToFlat32)
 #define Bs3SelProtModeCodeToRealMode BS3_CMN_MANGLER(Bs3SelProtModeCodeToRealMode)
+#define Bs3SelRealModeCodeToFlat BS3_CMN_MANGLER(Bs3SelRealModeCodeToFlat)
 #define Bs3SelRealModeCodeToProtMode BS3_CMN_MANGLER(Bs3SelRealModeCodeToProtMode)
 #define Bs3SelRealModeDataToFlat BS3_CMN_MANGLER(Bs3SelRealModeDataToFlat)
@@ -91,4 +100,5 @@
 #define Bs3StrPrintf BS3_CMN_MANGLER(Bs3StrPrintf)
 #define Bs3StrPrintfV BS3_CMN_MANGLER(Bs3StrPrintfV)
+#define Bs3SwitchFromV86To16BitAndCallC BS3_CMN_MANGLER(Bs3SwitchFromV86To16BitAndCallC)
 #define Bs3TestCheckRegCtxEx BS3_CMN_MANGLER(Bs3TestCheckRegCtxEx)
 #define Bs3TestFailed BS3_CMN_MANGLER(Bs3TestFailed)
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-undef.h
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-undef.h	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-undef.h	(revision 60676)
@@ -37,6 +37,10 @@
 #undef Bs3MemAllocZ
 #undef Bs3MemChr
+#undef Bs3MemCmp
 #undef Bs3MemCpy
 #undef Bs3MemFree
+#undef Bs3MemGuardedTestPageAlloc
+#undef Bs3MemGuardedTestPageAllocEx
+#undef Bs3MemGuardedTestPageFree
 #undef Bs3MemMove
 #undef Bs3MemPCpy
@@ -62,4 +66,8 @@
 #undef Bs3RegCtxSave
 #undef Bs3RegCtxSaveEx
+#undef Bs3RegCtxSetGrpDsFromCurPtr
+#undef Bs3RegCtxSetGrpSegFromCurPtr
+#undef Bs3RegCtxSetGrpSegFromFlat
+#undef Bs3RegCtxSetRipCsFromLnkPtr
 #undef Bs3SelFar32ToFlat32
 #undef Bs3SelFar32ToFlat32NoClobber
@@ -72,4 +80,5 @@
 #undef Bs3SelProtFar32ToFlat32
 #undef Bs3SelProtModeCodeToRealMode
+#undef Bs3SelRealModeCodeToFlat
 #undef Bs3SelRealModeCodeToProtMode
 #undef Bs3SelRealModeDataToFlat
@@ -91,4 +100,5 @@
 #undef Bs3StrPrintf
 #undef Bs3StrPrintfV
+#undef Bs3SwitchFromV86To16BitAndCallC
 #undef Bs3TestCheckRegCtxEx
 #undef Bs3TestFailed
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-data.h
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-data.h	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-data.h	(revision 60676)
@@ -32,4 +32,5 @@
 #define ___bs3kit_mangling_data_h
 
+#if 0 /* the object converter deals with this now  */
 #if ARCH_BITS == 64
 
@@ -275,4 +276,6 @@
 
 #endif /* ARCH_BITS == 64 */
+#endif /* not needed */
+
 #endif /* !___bs3kit_mangling_data_h */
 
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-template-footer.mac
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-template-footer.mac	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-template-footer.mac	(revision 60676)
@@ -127,3 +127,4 @@
 %unmacro TONLY32 1+
 %unmacro TONLY64 1+
+%unmacro TNOT64  1+
 
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-template-header.mac
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-template-header.mac	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-template-header.mac	(revision 60676)
@@ -137,6 +137,6 @@
  %define TMPL_BITS              64
  %define TMPL_PTR_DEF           dq
- %define TMPL_UNDERSCORE
- %define BS3_CMN_NM(Name)       Name %+ _c64
+ %define TMPL_UNDERSCORE        _
+ %define BS3_CMN_NM(Name)       _ %+ Name %+ _c64
 
 %else
@@ -361,5 +361,5 @@
  %define TMPL_LM64
  %define TMPL_MODE_STR          "long, 64-bit"
- %define TMPL_NM(Name)          Name %+ _lm64
+ %define TMPL_NM(Name)          _ %+ Name %+ _lm64
  %define TMPL_MODE_LNAME        lm64
  %define TMPL_MODE_UNAME        LM64
@@ -382,9 +382,5 @@
 
 ; TMPL_NM version with uppercased suffix and no underscore separating them.
-%ifnidn TMPL_UNDERSCORE,_
- %define TMPL_NM_U(Name)        Name %+ TMPL_MODE_UNAME
-%else
- %define TMPL_NM_U(Name)        TMPL_UNDERSCORE %+ Name %+ TMPL_MODE_UNAME
-%endif
+%define TMPL_NM_U(Name)         TMPL_UNDERSCORE %+ Name %+ TMPL_MODE_UNAME
 
 ; TMPL_FAR_NM
@@ -474,4 +470,16 @@
 %endif
 
+;; @def TNOT64
+; Version of BNOT64 that follows the code template.
+; Like BNOT64 this normally goes in column 1.
+%if TMPL_BITS == 64
+ %macro TNOT64 1+
+ %endmacro
+%else
+ %macro TNOT64 1+
+        %1
+ %endmacro
+%endif
+
 ;
 ; Default code segment (changes BITS too).
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h	(revision 60676)
@@ -309,7 +309,11 @@
 #define BS3_SEL_VMMDEV_MMIO16       0x00f8 /**< Selector for accessing the VMMDev MMIO segment at 0100000h from 16-bit code. */
 
+/** Checks if @a uSel is in the BS3_SEL_RX_XXX range. */
+#define BS3_SEL_IS_IN_RING_RANGE(uSel) ( (unsigned)(uSel -  BS3_SEL_R0_FIRST) < (unsigned)(4 << BS3_SEL_RING_SHIFT) )
 #define BS3_SEL_RING_SHIFT          8      /**< For the formula: BS3_SEL_R0_XXX + ((cs & 3) << BS3_SEL_RING_SHIFT) */
 #define BS3_SEL_RING_SUB_MASK       0x00f8 /**< Mask for getting the sub-selector. For use with BS3_SEL_R*_FIRST. */
 
+/** Checks if @a uSel is in the BS3_SEL_R0_XXX range. */
+#define BS3_SEL_IS_IN_R0_RANGE(uSel) ( (unsigned)(uSel -  BS3_SEL_R0_FIRST) < (unsigned)(1 << BS3_SEL_RING_SHIFT) )
 #define BS3_SEL_R0_FIRST            0x0100 /**< The first selector in the ring-0 block. */
 #define BS3_SEL_R0_CS16             0x0100 /**< ring-0: 16-bit code selector,  base 0x10000. */
@@ -387,4 +391,6 @@
 #define BS3_SEL_R3_CS64_CNF         0x0478 /**< ring-3: 64-bit conforming code selector, not accessed, flat. */
 #define BS3_SEL_R3_CS64_CNF_EO      0x0480 /**< ring-3: 64-bit execute-only conforming code selector, not accessed, flat. */
+
+#define BS3_SEL_R3_LAST             0x04f8 /**< ring-3: Last of the BS3_SEL_RX_XXX range. */
 
 #define BS3_SEL_SPARE_FIRST         0x0500 /**< The first selector in the spare block */
@@ -680,9 +686,9 @@
  * @remarks Mainly used in bs3kit-mangling.h, internal headers and templates.
  */
-#if ARCH_BITS == 64
-# define BS3_DATA_NM(a_Name)  RT_CONCAT(_,a_Name)
-#else
+//converter does this now//#if ARCH_BITS == 64
+//converter does this now//# define BS3_DATA_NM(a_Name)  RT_CONCAT(_,a_Name)
+//converter does this now//#else
 # define BS3_DATA_NM(a_Name)  a_Name
-#endif
+//converter does this now//#endif
 
 /**
@@ -736,4 +742,20 @@
 BS3_PTR_UNION_TEMPLATE(BS3CVPTRUNION, const volatile);
 
+/** Generic far function type. */
+typedef BS3_DECL_FAR(void)  FNBS3FAR(void);
+/** Generic far function pointer type. */
+typedef FNBS3FAR           *FPFNBS3FAR;
+
+/** Generic near function type. */
+typedef BS3_DECL_NEAR(void) FNBS3NEAR(void);
+/** Generic near function pointer type. */
+typedef FNBS3NEAR          *PFNBS3NEAR;
+
+/** Generic far 16:16 function pointer type for address conversion functions. */
+#if ARCH_BITS == 16
+typedef FPFNBS3FAR          PFNBS3FARADDRCONV;
+#else
+typedef uint32_t            PFNBS3FARADDRCONV;
+#endif
 
 /** The system call vector. */
@@ -1089,18 +1111,4 @@
 
 
-/** @def BS3_IS_PROTECTED_MODE
- * @returns true if protected mode, false if not. */
-#if ARCH_BITS != 16
-# define BS3_IS_PROTECTED_MODE() (true)
-#else
-# if 1
-#  define BS3_IS_PROTECTED_MODE() (!BS3_MODE_IS_RM_SYS(g_bBs3CurrentMode))
-# else
-#  define BS3_IS_PROTECTED_MODE() (Bs3AsmSmsw() & 1 /*PE*/)
-# endif
-#endif
-
-
-
 /** @defgroup bs3kit_cross_ptr  Cross Context Pointer Type
  *
@@ -1240,10 +1248,10 @@
 DECLINLINE(__segment) Bs3Sel16HighFlatPtrToSelector(uint16_t uHigh)
 {
-    if (BS3_IS_PROTECTED_MODE())
+    if (!BS3_MODE_IS_RM_OR_V86(g_bBs3CurrentMode))
         return (__segment)(((uHigh << 3) + BS3_SEL_TILED) | Bs3Sel16GetCurRing());
     return (__segment)(uHigh << 12);
 }
 
-#endif /* ARCH_BITS == 16*/
+#endif /* ARCH_BITS == 16 */
 
 /** @def BS3_XPTR_GET
@@ -1277,11 +1285,11 @@
     do { \
         a_Type BS3_FAR *pTypeCheck = (a_pValue); \
-        if (BS3_IS_PROTECTED_MODE()) \
+        if (BS3_MODE_IS_RM_OR_V86(g_bBs3CurrentMode)) \
+            (a_Name).XPtr.uFlat = BS3_FP_OFF(pTypeCheck) + ((uint32_t)BS3_FP_SEG(pTypeCheck) << 4); \
+        else \
         { \
             (a_Name).XPtr.u.uLow  = BS3_FP_OFF(pTypeCheck); \
             (a_Name).XPtr.u.uHigh = ((BS3_FP_SEG(pTypeCheck) & UINT16_C(0xfff8)) - BS3_SEL_TILED) >> 3; \
         } \
-        else \
-            (a_Name).XPtr.uFlat = BS3_FP_OFF(pTypeCheck) + ((uint32_t)BS3_FP_SEG(pTypeCheck) << 4); \
     } while (0)
 #elif ARCH_BITS == 32
@@ -1642,4 +1650,14 @@
 BS3_CMN_PROTO_NOSB(void BS3_FAR *, Bs3MemChr,(void const BS3_FAR *pvHaystack, uint8_t bNeedle, size_t cbHaystack));
 
+/**
+ * CRT style memcmp.
+ *
+ * @returns 0 if equal. Negative if the left side is 'smaller' than the right
+ *          side, and positive in the other case.
+ * @param   pv1             The left hand memory.
+ * @param   pv2             The right hand memory.
+ * @param   bNeedle         The number of bytes to compare.
+ */
+BS3_CMN_PROTO_NOSB(int, Bs3MemCmp,(void const BS3_FAR *pv1, void const BS3_FAR *pv2, size_t cb));
 
 BS3_CMN_PROTO_STUB(void, Bs3UInt64Div,(RTUINT64U uDividend, RTUINT64U uDivisor, RTUINT64U BS3_FAR *paQuotientReminder));
@@ -1713,4 +1731,16 @@
  */
 BS3_CMN_PROTO_NOSB(uint32_t, Bs3SelFlatCodeToProtFar16,(uint32_t uFlatAddr));
+
+/**
+ * Converts a far 16:16 real mode (code) address to a flat address.
+ *
+ * @returns 32-bit flat address.
+ * @param   uFar1616        Far real mode address (high 16-bit is segment, low
+ *                          is offset).
+ * @remarks All register are preserved, except return.
+ * @remarks No 20h scratch space required in 64-bit mode.
+ * @remarks Exactly the same as Bs3SelRealModeDataToFlat, except for param.
+ */
+BS3_CMN_PROTO_FARSTUB(4, uint32_t, Bs3SelRealModeCodeToFlat,(PFNBS3FARADDRCONV uFar1616));
 
 /**
@@ -1983,4 +2013,34 @@
 BS3_CMN_PROTO_STUB(void, Bs3MemFree,(void BS3_FAR *pv, size_t cb));
 
+/**
+ * Allocates a page with non-present pages on each side.
+ *
+ * @returns Pointer to the usable page.  NULL on failure.  Use
+ *          Bs3MemGuardedTestPageFree to free the allocation.
+ * @param   enmKind     The kind of addressing constraints imposed on the
+ *                      allocation.
+ */
+BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3MemGuardedTestPageAlloc,(BS3MEMKIND enmKind));
+
+/**
+ * Allocates a page with pages on each side to the @a fPte specification.
+ *
+ * @returns Pointer to the usable page.  NULL on failure.  Use
+ *          Bs3MemGuardedTestPageFree to free the allocation.
+ * @param   enmKind     The kind of addressing constraints imposed on the
+ *                      allocation.
+ * @param   fPte        The page table entry specification for the guard pages.
+ */
+BS3_CMN_PROTO_STUB(void BS3_FAR *, Bs3MemGuardedTestPageAllocEx,(BS3MEMKIND enmKind, uint64_t fPte));
+
+/**
+ * Frees guarded page allocated by Bs3MemGuardedTestPageAlloc or
+ * Bs3MemGuardedTestPageAllocEx.
+ *
+ * @param   pvGuardedPage   Pointer returned by Bs3MemGuardedTestPageAlloc or
+ *                          Bs3MemGuardedTestPageAllocEx.  NULL is ignored.
+ */
+BS3_CMN_PROTO_STUB(void, Bs3MemGuardedTestPageFree,(void BS3_FAR *pvGuardedPage));
+
 
 /**
@@ -2110,4 +2170,18 @@
 BS3_CMN_PROTO_STUB(void, Bs3PicMaskAll,(void));
 
+
+/**
+ * Call 16-bit prot mode function from v8086 mode.
+ *
+ * This switches from v8086 mode to 16-bit protected mode (code) and executed
+ * @a fpfnCall with @a cbParams bytes of parameters pushed on the stack.
+ * Afterwards it switches back to v8086 mode and returns a 16-bit status code.
+ *
+ * @returns     16-bit status code if the function returned anything.
+ * @param       fpfnCall        Far real mode pointer to the function to call.
+ * @param       cbParams        The size of the parameter list, in bytes.
+ * @param       ...             The parameters.
+ */
+BS3_CMN_PROTO_STUB(int, Bs3SwitchFromV86To16BitAndCallC,(FPFNBS3FAR fpfnCall, unsigned cbParams, ...));
 
 
@@ -2264,4 +2338,50 @@
 BS3_CMN_PROTO_STUB(void, Bs3RegCtxPrint,(PCBS3REGCTX pRegCtx));
 
+/**
+ * Sets a GPR and segment register to point at the same location as @a uFlat.
+ *
+ * @param   pRegCtx     The register context.
+ * @param   pGpr        The general purpose register to set (points within
+ *                      @a pRegCtx).
+ * @param   pSel        The selector register (points within @a pRegCtx).
+ * @param   uFlat       Flat location address.
+ */
+BS3_CMN_PROTO_STUB(void, Bs3RegCtxSetGrpSegFromFlat,(PBS3REGCTX pRegCtx, PBS3REG pGpr, PRTSEL pSel, RTCCUINTXREG uFlat));
+
+/**
+ * Sets a GPR and segment register to point at the same location as @a ovPtr.
+ *
+ * @param   pRegCtx     The register context.
+ * @param   pGpr        The general purpose register to set (points within
+ *                      @a pRegCtx).
+ * @param   pSel        The selector register (points within @a pRegCtx).
+ * @param   pvPtr       Current context pointer.
+ */
+BS3_CMN_PROTO_STUB(void, Bs3RegCtxSetGrpSegFromCurPtr,(PBS3REGCTX pRegCtx, PBS3REG pGpr, PRTSEL pSel, void  BS3_FAR *pvPtr));
+
+/**
+ * Sets a GPR and DS to point at the same location as @a ovPtr.
+ *
+ * @param   pRegCtx     The register context.
+ * @param   pGpr        The general purpose register to set (points within
+ *                      @a pRegCtx).
+ * @param   pvPtr       Current context pointer.
+ */
+BS3_CMN_PROTO_STUB(void, Bs3RegCtxSetGrpDsFromCurPtr,(PBS3REGCTX pRegCtx, PBS3REG pGpr, void  BS3_FAR *pvPtr));
+
+/**
+ * Sets CS:RIP to point at the same piece of code as @a pfnCode.
+ *
+ * The 16-bit edition of this function expects a far 16:16 address as written by
+ * the linker (i.e. real mode).
+ *
+ * @param   pRegCtx     The register context.
+ * @param   pfnCode     Pointer to the code. In 32-bit and 64-bit mode this is a
+ *                      flat address, while in 16-bit it's a far 16:16 address
+ *                      as fixed up by the linker (real mode selector).  This
+ *                      address is converted to match the mode of the context.
+ */
+BS3_CMN_PROTO_STUB(void, Bs3RegCtxSetRipCsFromLnkPtr,(PBS3REGCTX pRegCtx, FPFNBS3FAR pfnCode));
+
 
 /**
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.mac
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.mac	(revision 60675)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.mac	(revision 60676)
@@ -149,9 +149,5 @@
  ;; Mostly internal macro. Follows BS3_SET_BITS.
  %undef  BS3_NAME_UNDERSCORE
- %if %1 == 64
-  %define BS3_NAME_UNDERSCORE
- %else
-  %define BS3_NAME_UNDERSCORE _
- %endif
+ %define BS3_NAME_UNDERSCORE _
 
  ;; For segment overrides and stuff. Follows BS3_SET_BITS.
@@ -302,5 +298,5 @@
 ;; @{
 
-%ifdef ASM_FORMAT_OMF
+%ifndef ASM_FORMAT_BIN
 ; !!HACK ALERT!!
 ;
@@ -517,7 +513,5 @@
 ;; When using watcom + OMF, we're using __cdecl by default, which
 ; get an underscore added in front.
-%ifdef ASM_FORMAT_OMF
- %define NAME(name) _ %+ NAME_OVERLOAD(name)
-%endif
+%define NAME(name) _ %+ NAME_OVERLOAD(name)
 
 
@@ -627,13 +621,5 @@
 ;
 %macro BS3_GLOBAL_NAME_EX 3
-%ifdef ASM_FORMAT_ELF
- %ifdef __NASM__
-global %1:%2 %3
- %else
-global %1:%2
- %endif
-%else
 global %1
-%endif
 %1:
 %endmacro
@@ -656,16 +642,8 @@
 ;
 ; @param    %1      The mangled name.
-; @param    %2      Create an underscore prefixed alias if present and
-;                   BS3_PB_WITH_US_ALIAS (automatic in 64-bit code).
-;
-%macro BS3_PROC_BEGIN 1-2 0
-%if __BITS__ == 64 || ((%2) & BS3_PB_WITH_US_ALIAS)
-BS3_GLOBAL_NAME_EX _ %+ %1, function, (%1 %+ _EndProc - %1)
-%endif
+;
+%macro BS3_PROC_BEGIN 1
 BS3_GLOBAL_NAME_EX %1, function, (%1 %+ _EndProc - %1)
 %endmacro
-
-;; For use with BS3_PROC_BEGIN for making it produce an underscore prefixed alias.
-%define BS3_PB_WITH_US_ALIAS 1
 
 ;;
@@ -678,10 +656,4 @@
 %macro BS3_PROC_END  1
 BS3_GLOBAL_NAME_EX %1 %+ _EndProc, function hidden, (%1 %+ _EndProc - %1)
- %ifdef ASM_FORMAT_ELF
-  %ifdef __YASM__
-size %1                 %1 %+ _EndProc - %1
-size %1 %+ _EndProc     0
-  %endif
- %endif
  int3                                   ; handy and avoids overlapping labels.
 %endmacro
@@ -1073,5 +1045,5 @@
 %define BS3_MODE_NM_071h(a_Name)        _ %+ a_Name %+ _lm16
 %define BS3_MODE_NM_072h(a_Name)        _ %+ a_Name %+ _lm32
-%define BS3_MODE_NM_074h(a_Name)             a_Name %+ _lm64
+%define BS3_MODE_NM_074h(a_Name)        _ %+ a_Name %+ _lm64
 
 %define BS3_MODE_LNAME_001h             rm
@@ -1142,5 +1114,5 @@
 %define BS3_MODE_UNDERSCORE_071h        _
 %define BS3_MODE_UNDERSCORE_072h        _
-%define BS3_MODE_UNDERSCORE_074h
+%define BS3_MODE_UNDERSCORE_074h        _
 
 %define BS3_MODE_CNAME_001h             c16
@@ -1191,5 +1163,5 @@
 %define BS3_MODE_R0_NM_071h(a_Name)     _ %+ a_Name %+ _lm16
 %define BS3_MODE_R0_NM_072h(a_Name)     _ %+ a_Name %+ _lm32
-%define BS3_MODE_R0_NM_074h(a_Name)          a_Name %+ _lm64
+%define BS3_MODE_R0_NM_074h(a_Name)     _ %+ a_Name %+ _lm64
 ;; @}
 
