Index: /trunk/src/VBox/ValidationKit/bootsectors/Config.kmk
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/Config.kmk	(revision 60577)
+++ /trunk/src/VBox/ValidationKit/bootsectors/Config.kmk	(revision 60578)
@@ -78,5 +78,5 @@
 # @param    1   The target name.
 # @param    2   List of functions.
-BS3KIT_FN_GEN_NEARSTUBS = $(foreach fn,$2,$(evalcall2 def_Bs3KitGenNearStubSource,$1,_$(fn)_c16,_$(fn)_f16))
+BS3KIT_FN_GEN_CMN_NEARSTUBS = $(foreach fn,$2,$(evalcall2 def_Bs3KitGenNearStubSource,$1,_$(fn)_c16,_$(fn)_f16))
 
 ##
@@ -118,4 +118,67 @@
                '      push    ax' \
                '      jmp     $3 wrt CGROUP16'
+endef
+
+
+##
+# Macro for generating far-call aliases for zero or more 16-bit C or assembly functions.
+# @param    1   The target name.
+# @param    2   List of functions.
+BS3KIT_FN_GEN_CMN_FARSTUBS = $(foreach fn,$2,$(evalcall2 def_Bs3KitGenFarStubSource,$1,$(fn),_f16,_c16))
+
+##
+# Macro for generating far-call aliases for zero or more 16-bit C mode functions.
+# @param    1   The target name.
+# @param    2   List of mode functions.
+BS3KIT_FN_GEN_MODE_FARSTUBS = $(foreach fn,$2,$(foreach suff, \
+	_rm \
+	_pe16 \
+	_pe16_v86 \
+	_pe32_16 \
+	_pev86 \
+	_pp16 \
+	_pp16_v86 \
+	_pp32_16 \
+	_ppv86 \
+	_pae16 \
+	_pae16_v86 \
+	_pae32_16 \
+	_paev86 \
+	_lm16 \
+	,$(evalcall2 def_Bs3KitGenFarStubSource,$1,$(fn),$(suff)_far,$(suff))
+
+# @param    1   The target name.
+# @param    2   The function and amount of parameters.
+# @param    3   The far function suffix.
+# @param    4   The near function suffix.
+define def_Bs3KitGenFarStubSource
+$(eval local fn2 = $(firstword $(subst :, $(SP), $2)))
+$(eval local cbParam = $(lastword $(subst :, $(SP), $2)))
+
+$1_SOURCES += $$($1_0_OUTDIR)/stub_$(fn2)$3.asm
+$1_CLEAN   += $$($1_0_OUTDIR)/stub_$(fn2)$3.asm
+$$$$($1_0_OUTDIR)/stub_$(fn2)$3.asm: $$(VBOX_PATH_BOOTSECTORS_SRC)/Config.kmk | $$$$(dir $$$$@)
+	$(QUIET)$(APPEND) -tn $$@ \
+		'%include "bs3kit.mac"' \
+       	'BS3_BEGIN_TEXT16' \
+               '      extern  _$(fn2)$4' \
+       	'BS3_BEGIN_TEXT16_FARSTUBS' \
+		'BS3_PROC_BEGIN _$(fn2)$3' \
+               '      CPU 8086' \
+               '      inc     bp' \
+               '      push    bp' \
+               '      mov     bp, sp' \
+               '%assign offParam $(cbParam)' \
+               '%rep $(cbParam) / 2' \
+               '      push    word [bp + 2 + 4 + offParam - 2]' \
+               '%assign offParam offParam - 2' \
+               '%endrep' \
+               '      call    _$(fn2)$4' \
+               '      add     sp, $(cbParam)' \
+               '      pop     bp' \
+               '      dec     bp' \
+               '      retf' \
+		'BS3_PROC_END _$(fn2)$3' \
+               ''
 endef
 
Index: /trunk/src/VBox/ValidationKit/bootsectors/Makefile.kmk
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/Makefile.kmk	(revision 60577)
+++ /trunk/src/VBox/ValidationKit/bootsectors/Makefile.kmk	(revision 60578)
@@ -241,8 +241,11 @@
 	bs3-cpu-basic-2-c.c \
 	bs3-cpu-basic-2.asm \
-       bs3kit/bs3-cmn-instantiate.c16 \
+       bs3kit/bs3-cmn-instantiate-x0.c16 \
        bs3kit/bs3-cmn-instantiate.c32 \
        bs3kit/bs3-cmn-instantiate.c64
-bs3-cpu-basic-2-template.o:: $$(addprefix $$(bs3-cpu-basic-2_0_OUTDIR)/bs3kit/bs3-cmn-instantiate,.o16 .o32 .o64)
+bs3-cpu-basic-2-template.o:: \
+	$$(bs3-cpu-basic-2_0_OUTDIR)/bs3kit/bs3-cmn-instantiate-x0.o16 \
+	$$(bs3-cpu-basic-2_0_OUTDIR)/bs3kit/bs3-cmn-instantiate.o32 \
+	$$(bs3-cpu-basic-2_0_OUTDIR)/bs3kit/bs3-cmn-instantiate.o64
 endif
 
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.c
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.c	(revision 60577)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.c	(revision 60578)
@@ -258,4 +258,7 @@
     else
         fExtraEfl = X86_EFL_RF;
+#if 0 /** @todo Running on an AMD Phenom II X6 1100T under AMD-V I'm not getting good X86_EFL_RF results.  Enable this to get on with other work.  */
+    fExtraEfl = pTrapCtx->Ctx.rflags.u32 & X86_EFL_RF;
+#endif
     Bs3TestCheckRegCtxEx(&pTrapCtx->Ctx, pStartCtx, 0 /*cbIpAdjust*/, 0 /*cbSpAdjust*/, fExtraEfl, g_pszTestMode, g_usBs3TestStep);
     if (Bs3TestSubErrorCount() != cErrorsBefore)
@@ -404,5 +407,7 @@
     Ctx80.rsp.u -= 0x300;
     Ctx80.rip.u  = (uintptr_t)BS3_FP_OFF(&TMPL_NM(bs3CpuBasic2_Int80));
-# if TMPL_BITS == 32
+# if TMPL_BITS == 16
+    Ctx80.cs = BS3_MODE_IS_RM_OR_V86(g_bTestMode) ? BS3_SEL_TEXT16 : BS3_SEL_R0_CS16;
+# elif TMPL_BITS == 32
     g_uBs3TrapEipHint = Ctx80.rip.u32;
 # endif
@@ -1523,5 +1528,5 @@
      * Re-initialize the IDT.
      */
-    TMPL_NM(Bs3TrapInit)();
+    TMPL_FAR_NM(Bs3TrapInit)();
     return bRet;
 }
@@ -1549,5 +1554,5 @@
      * Re-initialize the IDT.
      */
-    TMPL_NM(Bs3TrapInit)();
+    TMPL_FAR_NM(Bs3TrapInit)();
     return 0;
 #elif TMPL_MODE == BS3_MODE_RM
@@ -1595,5 +1600,5 @@
      * Re-initialize the IDT.
      */
-    TMPL_NM(Bs3TrapInit)();
+    TMPL_FAR_NM(Bs3TrapInit)();
     return 0;
 }
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk	(revision 60577)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk	(revision 60578)
@@ -201,5 +201,5 @@
 	bs3-c16-CreateHybridFarRet.asm
 bs3kit-common-16_bs3-cmn-UInt64Div.c_CFLAGS = -oh -d0 # -d1+ vs -d0 saves 0x6a3-0x577 = 0x12C (300)!
-bs3kit-common-16_VBOX_NEAR_TO_FAR_FUNCTIONS := \
+bs3kit-common-16_VBOX_NEAR_TO_FAR_CMN_FUNCTIONS := \
 	$(sort $(subst bs3-cmn-,Bs3,$(basename $(filter-out \
 		%Data.c \
@@ -221,6 +221,11 @@
 	Bs3TrapInit \
 
-$(call BS3KIT_FN_GEN_NEARSTUBS,bs3kit-common-16,$(bs3kit-common-16_VBOX_NEAR_TO_FAR_FUNCTIONS))
+bs3kit-common-16_VBOX_FAR_TO_NEAR_CMN_FUNCTIONS := \
+	ASMMemFirstMismatchingU8:8 \
+	ASMMemFirstNonZero:6 \
+
+$(call BS3KIT_FN_GEN_CMN_NEARSTUBS,bs3kit-common-16,$(bs3kit-common-16_VBOX_NEAR_TO_FAR_CMN_FUNCTIONS))
 $(call BS3KIT_FN_GEN_MODE_NEARSTUBS,bs3kit-common-16,$(bs3kit-common-16_VBOX_NEAR_TO_FAR_MODE_FUNCTIONS))
+$(call BS3KIT_FN_GEN_CMN_FARSTUBS,bs3kit-common-16,$(bs3kit-common-16_VBOX_FAR_TO_NEAR_CMN_FUNCTIONS))
 
 # The 32-bit BS3Kit library.
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-instantiate-x0.c16
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-instantiate-x0.c16	(revision 60578)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-instantiate-x0.c16	(revision 60578)
@@ -0,0 +1,29 @@
+/* $Id$ */
+/** @file
+ * BS3Kit - 16-bit common C template instantiator, using the BS3X0TEXT16 segment.
+ */
+
+/*
+ * 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.
+ */
+
+#define BS3_USE_X0_TEXT_SEG 1
+#include "bs3-cmn-instantiate-common.h"
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-instantiate-x1.c16
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-instantiate-x1.c16	(revision 60578)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-instantiate-x1.c16	(revision 60578)
@@ -0,0 +1,29 @@
+/* $Id$ */
+/** @file
+ * BS3Kit - 16-bit common C template instantiator, using the BS3X1TEXT16 segment.
+ */
+
+/*
+ * 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.
+ */
+
+#define BS3_USE_X1_TEXT_SEG 1
+#include "bs3-cmn-instantiate-common.h"
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToLM64.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToLM64.asm	(revision 60577)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToLM64.asm	(revision 60578)
@@ -41,5 +41,5 @@
 ; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
 ;
-BS3_GLOBAL_NAME_EX TMPL_NM(Bs3SwitchToLM16_Safe), function, 0
+BS3_GLOBAL_NAME_EX TMPL_NM(Bs3SwitchToLM64_Safe), function, 0
 BS3_PROC_BEGIN_MODE Bs3SwitchToLM64, BS3_PBC_NEAR
 %ifdef TMPL_LM64
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TestDoModes.c
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TestDoModes.c	(revision 60577)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TestDoModes.c	(revision 60578)
@@ -25,16 +25,12 @@
  */
 
-/** @todo get this mess into the RM segment! */
-
 
 /*********************************************************************************************************************************
 *   Header Files                                                                                                                 *
 *********************************************************************************************************************************/
-#if defined(__WATCOMC__) && TMPL_MODE == BS3_MODE_RM
-/* In real mode we move this blob of code to the RMTEXT16 segment to save space. */
-# define BS3_USE_RM_TEXT_SEG 1
+#if TMPL_MODE == BS3_MODE_RM
+# define BS3_USE_RM_TEXT_SEG 1 /* Real mode version in RMTEXT16 segment to save space. */
 # include "bs3kit-template-header.h"
 # include "bs3-cmn-test.h"
-# pragma code_seg("BS3RMTEXT16", "BS3CLASS16RMCODE")
 #else
 # include "bs3kit-template-header.h"
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-rm-InitAll.c
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-rm-InitAll.c	(revision 60577)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-rm-InitAll.c	(revision 60578)
@@ -34,8 +34,4 @@
 #include <iprt/asm-amd64-x86.h>
 
-//#ifdef __WATCOMC__
-//# pragma code_seg("BS3RMTEXT16", "BS3CLASS16RMCODE")
-//#endif
-
 
 BS3_DECL(void) Bs3InitAll_rm(void)
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-rm-InitGdt.c
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-rm-InitGdt.c	(revision 60577)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-rm-InitGdt.c	(revision 60578)
@@ -32,8 +32,4 @@
 #include <iprt/asm.h>
 
-#ifdef __WATCOMC__
-# pragma code_seg("BS3RMTEXT16", "BS3CLASS16RMCODE")
-#endif
-
 
 /*********************************************************************************************************************************
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-rm-InitMemory.c
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-rm-InitMemory.c	(revision 60577)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-rm-InitMemory.c	(revision 60578)
@@ -32,8 +32,4 @@
 #include "bs3-cmn-memory.h"
 #include <iprt/asm.h>
-
-#ifdef __WATCOMC__
-# pragma code_seg("BS3RMTEXT16", "BS3CLASS16RMCODE")
-#endif
 
 
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code.h
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code.h	(revision 60577)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code.h	(revision 60578)
@@ -30,5 +30,5 @@
  */
 #undef BS3_CMN_MANGLER
-#if ARCH_BITS != 16 || !defined(BS3_USE_RM_TEXT_SEG)
+#if ARCH_BITS != 16 || !defined(BS3_USE_ALT_16BIT_TEXT_SEG)
 # define BS3_CMN_MANGLER(a_Function)            BS3_CMN_NM(a_Function)
 #else
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h	(revision 60577)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h	(revision 60578)
@@ -49,4 +49,13 @@
 #endif
 
+/** @def BS3_USE_ALT_16BIT_TEXT_SEG
+ * Combines the BS3_USE_RM_TEXT_SEG,  BS3_USE_X0_TEXT_SEG, and
+ * BS3_USE_X1_TEXT_SEG indicators into a single one. */
+#if defined(BS3_USE_RM_TEXT_SEG) || defined(BS3_USE_X0_TEXT_SEG) || defined(BS3_USE_X1_TEXT_SEG)
+# define BS3_USE_ALT_16BIT_TEXT_SEG
+#else
+# undef  BS3_USE_ALT_16BIT_TEXT_SEG
+#endif
+
 /*
  * We may want to reuse some IPRT code in the common name space, so we
@@ -55,8 +64,10 @@
  * declarations before we can define it. Thus the duplciate effort.)
  */
-#if ARCH_BITS != 16 || !defined(BS3_USE_RM_TEXT_SEG)
+#if ARCH_BITS != 16 || !defined(BS3_USE_ALT_16BIT_TEXT_SEG)
 # define RT_MANGLER(a_Name) RT_CONCAT3(a_Name,_c,ARCH_BITS)
 #else
 # define RT_MANGLER(a_Name) RT_CONCAT(a_Name,_f16)
+# undef RTCALL
+# define RTCALL __cdecl __far
 #endif
 #include <iprt/mangling.h>
@@ -509,5 +520,5 @@
  *
  * @param a_Type        The return type. */
-#if ARCH_BITS != 16 || !defined(BS3_USE_RM_TEXT_SEG)
+#if ARCH_BITS != 16 || !defined(BS3_USE_ALT_16BIT_TEXT_SEG)
 # define BS3_DECL(a_Type)  BS3_DECL_NEAR(a_Type)
 #else
@@ -576,6 +587,6 @@
  * Constructs a common function name, far or near as defined by the source.
  *
- * Which to use in 16-bit mode is defined by BS3_USE_RM_TEXT_SEG.  In 32-bit and
- * 64-bit mode there are no far symbols, only near ones.
+ * Which to use in 16-bit mode is defined by BS3_USE_ALT_16BIT_TEXT_SEG.  In
+ * 32-bit and 64-bit mode there are no far symbols, only near ones.
  *
  * Example: BS3_CMN_FN_NM(Bs3Shutdown)
@@ -583,5 +594,5 @@
  * @param   a_Name      The name of the function.
  */
-#if ARCH_BITS != 16 || !defined(BS3_USE_RM_TEXT_SEG)
+#if ARCH_BITS != 16 || !defined(BS3_USE_ALT_16BIT_TEXT_SEG)
 # define BS3_CMN_FN_NM(a_Name)  BS3_CMN_NM(a_Name)
 #else
@@ -2687,5 +2698,21 @@
 #include "bs3kit-mangling-code.h"
 
-
-#endif
-
+/*
+ * Change 16-bit text segment if requested.
+ */
+#if defined(BS3_USE_ALT_16BIT_TEXT_SEG) && ARCH_BITS == 16 && !defined(BS3_DONT_CHANGE_TEXT_SEG)
+# if (defined(BS3_USE_RM_TEXT_SEG) + defined(BS3_USE_X0_TEXT_SEG) + defined(BS3_USE_X1_TEXT_SEG)) != 1
+#  error "Cannot set more than one alternative 16-bit text segment!"
+# elif defined(BS3_USE_RM_TEXT_SEG)
+#  pragma code_seg("BS3RMTEXT16", "BS3CLASS16RMCODE")
+# elif defined(BS3_USE_X0_TEXT_SEG)
+#  pragma code_seg("BS3X0TEXT16", "BS3CLASS16X0CODE")
+# elif defined(BS3_USE_X1_TEXT_SEG)
+#  pragma code_seg("BS3X1TEXT16", "BS3CLASS16X1CODE")
+# else
+#  error "Huh? Which alternative text segment did you want again?"
+# endif
+#endif
+
+#endif
+
