Index: /trunk/src/VBox/ValidationKit/bootsectors/Config.kmk
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/Config.kmk	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/Config.kmk	(revision 60554)
@@ -78,19 +78,44 @@
 # @param    1   The target name.
 # @param    2   List of functions.
-BS3KIT_FN_GEN_NEARSTUBS = $(foreach fn,$2,$(evalcall2 def_Bs3KitGenNearStubSource,$1,$(fn)))
+BS3KIT_FN_GEN_NEARSTUBS = $(foreach fn,$2,$(evalcall2 def_Bs3KitGenNearStubSource,$1,_$(fn)_c16,_$(fn)_f16))
+
+##
+# Macro for generating near-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_NEARSTUBS = $(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_Bs3KitGenNearStubSource,$1,_$(fn)$(suff),_$(fn)$(suff)_far)))
+
+# @param    1   The target name.
+# @param    2   The near function name.
+# @param    3   The far function name.
 define def_Bs3KitGenNearStubSource
-$1_SOURCES += $$($1_0_OUTDIR)/near-call-to-$2_f16.asm
-$1_CLEAN   += $$($1_0_OUTDIR)/near-call-to-$2_f16.asm
-$$$$($1_0_OUTDIR)/near-call-to-$2_f16.asm: $$(VBOX_PATH_BOOTSECTORS_SRC)/Config.kmk | $$$$(dir $$$$@)
+$1_SOURCES += $$($1_0_OUTDIR)/stub$2.asm
+$1_CLEAN   += $$($1_0_OUTDIR)/stub$2.asm
+$$$$($1_0_OUTDIR)/stub$2.asm: $$(VBOX_PATH_BOOTSECTORS_SRC)/Config.kmk | $$$$(dir $$$$@)
 	$(QUIET)$(APPEND) -tn $$@ \
 		'%include "bs3kit.mac"' \
        	'BS3_BEGIN_TEXT16' \
-               '      extern  _$2_f16' \
+               '      extern  $3' \
        	'BS3_BEGIN_TEXT16_NEARSTUBS' \
-		'BS3_GLOBAL_NAME_EX _$2_c16, function, 6' \
+		'BS3_GLOBAL_NAME_EX $2, function, 6' \
                '      pop     ax' \
                '      push    cs' \
                '      push    ax' \
-               '      jmp     _$2_f16 wrt CGROUP16'
+               '      jmp     $3 wrt CGROUP16'
 endef
 
@@ -631,5 +656,7 @@
 	,,$(QUIET)$(MV_EXT) -f -- "$(out)" "$(out).tmp" \
 	$$(NLTAB)$(QUIET)$(VBoxBs3Linker_1_TARGET) -o $(out) $(bs3-bootsector_1_TARGET) $(out).tmp \
-	$$(NLTAB)$(QUIET)$(RM_EXT) -f -- "$(out).tmp")
+	$$(NLTAB)$(QUIET)$(RM_EXT) -f -- "$(out).tmp") \
+	$(eval .PRECIOUS: $(outbase).map) # ugly hack!
+
 
 TEMPLATE_VBoxBS3KitImg_LIBS = \
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.mac
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.mac	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3-cpu-basic-2-template.mac	(revision 60554)
@@ -40,5 +40,5 @@
 
 %if 0 ; Will be doing the testing in C, I think.
-BS3_PROC_BEGIN_MODE bs3CpuBasic2_iret
+BS3_PROC_BEGIN_MODE bs3CpuBasic2_iret, BS3_PBC_FAR
         BS3_CALL_CONV_PROLOG 1
         push    xBP
@@ -79,5 +79,5 @@
 
 
-BS3_PROC_BEGIN_MODE bs3CpuBasic2_Int80
+BS3_PROC_BEGIN_MODE bs3CpuBasic2_Int80, BS3_PBC_NEAR
         int     80h
 .again: ud2
@@ -86,5 +86,5 @@
 
 
-BS3_PROC_BEGIN_MODE bs3CpuBasic2_Int81
+BS3_PROC_BEGIN_MODE bs3CpuBasic2_Int81, BS3_PBC_NEAR
         int     81h
 .again: ud2
@@ -93,5 +93,5 @@
 
 
-BS3_PROC_BEGIN_MODE bs3CpuBasic2_Int82
+BS3_PROC_BEGIN_MODE bs3CpuBasic2_Int82, BS3_PBC_NEAR
         int     82h
 .again: ud2
@@ -100,5 +100,5 @@
 
 
-BS3_PROC_BEGIN_MODE bs3CpuBasic2_Int83
+BS3_PROC_BEGIN_MODE bs3CpuBasic2_Int83, BS3_PBC_NEAR
         int     83h
 .again: ud2
@@ -107,5 +107,5 @@
 
 
-BS3_PROC_BEGIN_MODE bs3CpuBasic2_sidt_bx_ud2
+BS3_PROC_BEGIN_MODE bs3CpuBasic2_sidt_bx_ud2, BS3_PBC_NEAR
         sidt    [xBX]
 .again: ud2
@@ -114,5 +114,5 @@
 
 
-BS3_PROC_BEGIN_MODE bs3CpuBasic2_lidt_bx_ud2
+BS3_PROC_BEGIN_MODE bs3CpuBasic2_lidt_bx_ud2, BS3_PBC_NEAR
         lidt    [xBX]
 .again: ud2
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk	(revision 60554)
@@ -90,4 +90,5 @@
        bs3-cmn-SelFar32ToFlat32.c \
        bs3-cmn-SelProtFar32ToFlat32.c \
+       bs3-cmn-SelProtModeCodeToRealMode.asm \
        bs3-cmn-SelRealModeCodeToProtMode.asm \
        bs3-cmn-SelFlatCodeToRealMode.asm \
@@ -102,4 +103,6 @@
        bs3-cmn-SlabListAllocEx.c \
        bs3-cmn-SlabListFree.c \
+       bs3-cmn-SwitchHlpConvRealModeRetfPopBpDecBpAndReturn.asm \
+       bs3-cmn-SwitchHlpConvProtModeRetfPopBpDecBpAndReturn.asm \
        bs3-cmn-SwitchToRing0.asm \
        bs3-cmn-SwitchToRing1.asm \
@@ -213,6 +216,12 @@
        Bs3TestSubF \
        Bs3TestSubV \
-       Bs3Trap16InitEx
+       Bs3Trap16InitEx \
+
+bs3kit-common-16_VBOX_NEAR_TO_FAR_MODE_FUNCTIONS := \
+	Bs3TestDoModes \
+	Bs3TrapInit \
+
 $(call BS3KIT_FN_GEN_NEARSTUBS,bs3kit-common-16,$(bs3kit-common-16_VBOX_NEAR_TO_FAR_FUNCTIONS))
+$(call BS3KIT_FN_GEN_MODE_NEARSTUBS,bs3kit-common-16,$(bs3kit-common-16_VBOX_NEAR_TO_FAR_MODE_FUNCTIONS))
 
 # The 32-bit BS3Kit library.
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-A20Enable.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-A20Enable.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-A20Enable.asm	(revision 60554)
@@ -45,5 +45,5 @@
         call    BS3_CMN_NM(Bs3A20EnableViaPortA)
 ;; @todo real 286 support
-;        call    TMPL_NM_CMN(Bs3A20EnableViaKbd)
+;        call    BS3_CMN_NM(Bs3A20EnableViaKbd)
 
         pop     xBP
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SelProtModeCodeToRealMode.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SelProtModeCodeToRealMode.asm	(revision 60554)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SelProtModeCodeToRealMode.asm	(revision 60554)
@@ -0,0 +1,106 @@
+; $Id$
+;; @file
+; BS3Kit - Bs3SelProtModeCodeToRealMode.
+;
+
+;
+; 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"
+
+;
+; Make sure we can get at all the segments.
+;
+BS3_BEGIN_TEXT16
+BS3_BEGIN_X0TEXT16
+BS3_BEGIN_X1TEXT16
+TMPL_BEGIN_TEXT
+
+
+;;
+; @cproto   BS3_CMN_PROTO(uint16_t, Bs3SelProtModeCodeToRealMode,(uint16_t uRealSel), false);
+; @uses     ax (return register)
+;
+BS3_PROC_BEGIN_CMN Bs3SelProtModeCodeToRealMode, BS3_PBC_NEAR
+        BS3_CALL_CONV_PROLOG 1
+        push    xBP
+        mov     xBP, xSP
+
+        ; Load it and mask off the RPL.
+        mov     ax, [xBP + xCB + cbCurRetAddr]
+        and     ax, X86_SEL_MASK_OFF_RPL
+
+        ; We're allowed to use the real-mode segment value.
+        cmp     ax, BS3TEXT16
+        je      .bs3text16
+
+        ; Check for typical code segments.
+        cmp     ax, BS3_SEL_R0_CS16
+        je      .bs3text16
+        cmp     ax, BS3_SEL_X0TEXT16_CS
+        je      .bs3x0text16
+        cmp     ax, BS3_SEL_X1TEXT16_CS
+        je      .bs3x1text16
+
+        ; Check for less common BS3_SEL_R*_CS16_* values.
+        cmp     ax, BS3_SEL_R0_FIRST
+        jb      .panic
+        cmp     ax, BS3_SEL_R3_FIRST + (1 << BS3_SEL_RING_SHIFT)
+        jae     .panic
+
+        ; Since the relevant bits now are the lower 8 ones, we skip the
+        ;       AND AX, BS3_SEL_RING_SHIFT
+        ;       ADD AX, BS3_SEL_R0_FIRST
+        ; bits and compare AL with lower 8-bit of the BS3_SEL_R0_CS16* values.
+AssertCompile(BS3_SEL_RING_SHIFT == 8)
+        cmp     al, BS3_SEL_R0_CS16 & 0xff
+        je      .bs3text16
+        cmp     al, BS3_SEL_R0_CS16_EO & 0xff
+        je      .bs3text16
+        cmp     ax, BS3_SEL_R0_CS16_CNF & 0xff
+        je      .bs3text16
+        cmp     ax, BS3_SEL_R0_CS16_CNF_EO & 0xff
+        je      .bs3text16
+.panic:
+        extern  BS3_CMN_NM(Bs3Panic)
+        call    BS3_CMN_NM(Bs3Panic)
+        jmp     .return
+
+.bs3x1text16:
+        mov     ax, BS3_SEL_X1TEXT16_CS
+        jmp     .return
+.bs3x0text16:
+        mov     ax, BS3_SEL_X0TEXT16_CS
+        jmp     .return
+.bs3text16:
+        mov     ax, BS3TEXT16
+.return:
+        pop     xBP
+        BS3_CALL_CONV_EPILOG 1
+        BS3_HYBRID_RET
+BS3_PROC_END_CMN   Bs3SelProtModeCodeToRealMode
+
+;
+; We may be using the near code in some critical code paths, so don't
+; penalize it.
+;
+BS3_CMN_FAR_STUB   Bs3SelProtModeCodeToRealMode, 2
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SelRealModeCodeToProtMode.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SelRealModeCodeToProtMode.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SelRealModeCodeToProtMode.asm	(revision 60554)
@@ -38,4 +38,5 @@
 ;;
 ; @cproto   BS3_CMN_PROTO(uint16_t, Bs3SelRealModeCodeToProtMode,(uint16_t uRealSel), false);
+; @uses     ax (return register)
 ;
 BS3_PROC_BEGIN_CMN Bs3SelRealModeCodeToProtMode, BS3_PBC_NEAR
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchHlpConvProtModeRetfPopBpDecBpAndReturn.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchHlpConvProtModeRetfPopBpDecBpAndReturn.asm	(revision 60554)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchHlpConvProtModeRetfPopBpDecBpAndReturn.asm	(revision 60554)
@@ -0,0 +1,117 @@
+; $Id$
+;; @file
+; BS3Kit - Bs3SwitchToPP32
+;
+
+;
+; 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.
+;
+
+%include "bs3kit-template-header.mac"
+
+
+%if TMPL_BITS == 16
+BS3_EXTERN_CMN Bs3SelProtModeCodeToRealMode
+%else
+BS3_EXTERN_CMN Bs3SelFar32ToFlat32
+%endif
+
+
+;;
+; SwitchToXxx helper that converts a 16-bit protected mode far return
+; into something suitable for the current mode and performs the return.
+;
+; The caller jmps to this routine.  The stack holds an incremented BP (odd is
+; far indicator) and a 16-bit far return address.
+;
+; @uses     Nothing.
+; @remarks  16-bit ASSUMES we're returning to protected mode!!
+;
+%if TMPL_BITS == 16
+BS3_BEGIN_TEXT16_FARSTUBS
+%endif
+BS3_PROC_BEGIN_CMN Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn, BS3_PBC_NEAR
+%if TMPL_BITS == 16
+        ; Convert the selector of the 16:16 protected mode return address to the
+        ; corresponding 16-bit real mode segment.
+        push        ax
+
+        mov         ax, [bp + 2 + 2]
+        push        ax
+        call        Bs3SelProtModeCodeToRealMode ; This doesn't trash any registers (except AX).
+        add         sp, 2
+        mov         [bp + 2 + 2], ax
+
+        pop         ax
+
+        pop         bp
+        dec         bp
+        retf
+
+%elif TMPL_BITS == 32
+        push    eax
+        push    ecx
+        push    edx
+
+        movzx   eax, word [esp + 4*3 + 2]       ; return offset
+        movzx   edx, word [esp + 4*3 + 2 + 2]   ; return selector
+        push    eax
+        push    edx
+        call    Bs3SelFar32ToFlat32
+        add     esp, 8
+        mov     [esp + 4*3 + 2], eax
+
+        pop     edx
+        pop     ecx
+        pop     eax
+        pop     bp
+        dec     bp
+        ret
+%else
+        push    rax
+        push    rcx
+        push    rdx
+        push    r8
+        push    r9
+        push    r10
+        push    r11
+
+        movzx   ecx, word [rsp + 8*7 + 2]       ; return offset
+        movzx   edx, word [rsp + 8*7 + 2 + 2]   ; return selector
+        sub     rsp, 20h
+        call    Bs3SelFar32ToFlat32
+        add     rsp, 20h
+        mov     [rsp + 8*7 + 2], eax
+
+        pop     r11
+        pop     r10
+        pop     r9
+        pop     r8
+        pop     rdx
+        pop     rcx
+        pop     rax
+        mov     bp, [rsp]
+        add     rsp, 2h
+        dec     bp
+        o32 ret
+%endif
+BS3_PROC_END_CMN   Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchHlpConvRealModeRetfPopBpDecBpAndReturn.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchHlpConvRealModeRetfPopBpDecBpAndReturn.asm	(revision 60554)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchHlpConvRealModeRetfPopBpDecBpAndReturn.asm	(revision 60554)
@@ -0,0 +1,87 @@
+; $Id$
+;; @file
+; BS3Kit - SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+;
+
+;
+; 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.
+;
+
+%include "bs3kit-template-header.mac"
+
+BS3_EXTERN_CMN Bs3SelFar32ToFlat32
+
+;;
+; SwitchToXxx helper that converts a 16-bit real mode far return
+; into something suitable for the current mode and performs the return.
+;
+; The caller jmps to this routine.  The stack holds an incremented BP (odd is
+; far indicator) and a 16-bit far return address.
+;
+; @uses     Nothing.
+; @remarks  16-bit ASSUMES we're returning to protected mode!!
+;
+%if TMPL_BITS == 16
+BS3_BEGIN_TEXT16_FARSTUBS
+%endif
+BS3_PROC_BEGIN_CMN Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn, BS3_PBC_NEAR
+%if TMPL_BITS == 16
+        ; Convert the selector of the 16:16 real mode return address to the
+        ; corresponding 16-bit protected mode selector.
+        push        ax
+
+        mov         ax, [bp + 2 + 2]
+        push        ax
+        BS3_EXTERN_CMN Bs3SelRealModeCodeToProtMode
+        call        Bs3SelRealModeCodeToProtMode ; This doesn't trash any registers (except AX).
+        add         sp, 2
+        mov         [bp + 2 + 2], ax
+
+        pop         ax
+
+        pop         bp
+        dec         bp
+        retf
+
+%else
+        push    xAX
+        push    xDX
+
+        movzx   eax, word [xSP + 4*2 + 2 + 2]   ; return segment
+        movzx   edx, word [xSP + 4*2 + 2]       ; return offset
+        shl     eax, 4
+        add     eax, edx
+        mov     [xSP + 4*3 + 2], eax
+
+        pop     xDX
+        pop     xAX
+ %if TMPL_BITS == 32
+        pop     bp
+        dec     bp
+        ret
+ %else
+        mov     bp, [rsp]
+        add     rsp, 2h
+        dec     bp
+        o32 ret
+ %endif
+%endif
+BS3_PROC_END_CMN   Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-first-common.mac
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-first-common.mac	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-first-common.mac	(revision 60554)
@@ -157,4 +157,5 @@
 section BS3RMTEXT16_END   align=1 CLASS=BS3CLASS16RMCODE PUBLIC USE16
 BS3_GLOBAL_DATA Bs3RmText16_EndOfSegment, 0
+GROUP BS3GROUPRMTEXT16 BS3RMTEXT16_START BS3RMTEXT16 BS3RMTEXT16_END
 
 
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-CpuDetect.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-CpuDetect.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-CpuDetect.asm	(revision 60554)
@@ -42,5 +42,5 @@
 ; @remarks  ASSUMES we're in ring-0 when not in some kind of real mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3CpuDetect
+BS3_PROC_BEGIN_MODE Bs3CpuDetect, BS3_PBC_HYBRID_0_ARGS
 CPU 8086
         push    xBP
@@ -293,5 +293,5 @@
         popf
         pop     xBP
-        ret
+        BS3_HYBRID_RET
 
 BS3_PROC_END_MODE   Bs3CpuDetect
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-EnteredMode.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-EnteredMode.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-EnteredMode.asm	(revision 60554)
@@ -40,5 +40,5 @@
 ; @remarks  ASSUMES we're in ring-0 when not in some kind of real mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3EnteredMode
+BS3_PROC_BEGIN_MODE Bs3EnteredMode, BS3_PBC_NEAR ; won't need this outside the switchers, so always near.
         push    xBP
         mov     xBP, xSP
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-PagingGetRootForLM64.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-PagingGetRootForLM64.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-PagingGetRootForLM64.asm	(revision 60554)
@@ -51,5 +51,5 @@
 ; @remarks  returns value in EAX, not dx:ax!
 ;
-BS3_PROC_BEGIN_MODE Bs3PagingGetRootForLM64
+BS3_PROC_BEGIN_MODE Bs3PagingGetRootForLM64, BS3_PBC_NEAR ; Internal function, no far variant necessary.
         mov     eax, [BS3_DATA16_WRT(g_PhysPagingRootLM)]
         cmp     eax, 0ffffffffh
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-PagingGetRootForPAE16.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-PagingGetRootForPAE16.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-PagingGetRootForPAE16.asm	(revision 60554)
@@ -40,5 +40,5 @@
 ; @remarks  returns value in EAX, not dx:ax!
 ;
-BS3_PROC_BEGIN_MODE Bs3PagingGetRootForPAE16
+BS3_PROC_BEGIN_MODE Bs3PagingGetRootForPAE16, BS3_PBC_NEAR ; Internal function, no far variant necessary.
         jmp     TMPL_NM(Bs3PagingGetRootForPAE32)
 BS3_PROC_END_MODE   Bs3PagingGetRootForPAE16
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-PagingGetRootForPAE32.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-PagingGetRootForPAE32.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-PagingGetRootForPAE32.asm	(revision 60554)
@@ -51,5 +51,5 @@
 ; @remarks  returns value in EAX, not dx:ax!
 ;
-BS3_PROC_BEGIN_MODE Bs3PagingGetRootForPAE32
+BS3_PROC_BEGIN_MODE Bs3PagingGetRootForPAE32, BS3_PBC_NEAR ; Internal function, no far variant necessary.
         mov     eax, [BS3_DATA16_WRT(g_PhysPagingRootPAE)]
         cmp     eax, 0ffffffffh
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-PagingGetRootForPP16.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-PagingGetRootForPP16.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-PagingGetRootForPP16.asm	(revision 60554)
@@ -40,5 +40,5 @@
 ; @remarks  returns value in EAX, not dx:ax!
 ;
-BS3_PROC_BEGIN_MODE Bs3PagingGetRootForPP16
+BS3_PROC_BEGIN_MODE Bs3PagingGetRootForPP16, BS3_PBC_NEAR ; Internal function, no far variant necessary.
         jmp     TMPL_NM(Bs3PagingGetRootForPP32)
 BS3_PROC_END_MODE   Bs3PagingGetRootForPP16
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-PagingGetRootForPP32.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-PagingGetRootForPP32.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-PagingGetRootForPP32.asm	(revision 60554)
@@ -51,5 +51,5 @@
 ; @remarks  returns value in EAX, not dx:ax!
 ;
-BS3_PROC_BEGIN_MODE Bs3PagingGetRootForPP32
+BS3_PROC_BEGIN_MODE Bs3PagingGetRootForPP32, BS3_PBC_NEAR ; Internal function, no far variant necessary.
         mov     eax, [BS3_DATA16_WRT(g_PhysPagingRootPP)]
         cmp     eax, 0ffffffffh
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToLM16.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToLM16.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToLM16.asm	(revision 60554)
@@ -41,5 +41,5 @@
 ; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3SwitchToLM16
+BS3_PROC_BEGIN_MODE Bs3SwitchToLM16, BS3_PBC_NEAR
 %ifdef TMPL_LM16
         extern  BS3_CMN_NM(Bs3SwitchToRing0)
@@ -83,2 +83,27 @@
 BS3_PROC_END_MODE   Bs3SwitchToLM16
 
+
+%if TMPL_BITS == 16
+;;
+; Custom far stub.
+BS3_BEGIN_TEXT16_FARSTUBS
+BS3_PROC_BEGIN_MODE Bs3SwitchToLM16, BS3_PBC_FAR
+        inc         bp
+        push        bp
+        mov         bp, sp
+
+        ; Call the real thing.
+        call        TMPL_NM(Bs3SwitchToLM16)
+
+ %if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+        ; Jmp to  common code for the tedious conversion.
+        BS3_EXTERN_CMN Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+ %else
+        pop         bp
+        dec         bp
+        retf
+ %endif
+BS3_PROC_END_MODE   Bs3SwitchToLM16
+%endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToLM32.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToLM32.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToLM32.asm	(revision 60554)
@@ -44,5 +44,5 @@
 ; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3SwitchToLM32
+BS3_PROC_BEGIN_MODE Bs3SwitchToLM32, BS3_PBC_NEAR
 %ifdef TMPL_LM32
         ret
@@ -152,2 +152,28 @@
 BS3_PROC_END_MODE   Bs3SwitchToLM32
 
+
+%if TMPL_BITS == 16
+;;
+; Custom far stub.
+BS3_BEGIN_TEXT16_FARSTUBS
+BS3_PROC_BEGIN_MODE Bs3SwitchToLM32, BS3_PBC_FAR
+        inc         bp
+        push        bp
+        mov         bp, sp
+
+        ; Call the real thing.
+        call        TMPL_NM(Bs3SwitchToLM32)
+        BS3_SET_BITS 32
+
+        ; Jmp to common code for the tedious conversion.
+ %if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+        BS3_EXTERN_CMN Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+ %else
+        BS3_EXTERN_CMN Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+ %endif
+        BS3_SET_BITS 16
+BS3_PROC_END_MODE   Bs3SwitchToLM32
+%endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToLM64.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToLM64.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToLM64.asm	(revision 60554)
@@ -41,5 +41,5 @@
 ; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3SwitchToLM64
+BS3_PROC_BEGIN_MODE Bs3SwitchToLM64, BS3_PBC_NEAR
 %ifdef TMPL_LM64
         ret
@@ -76,2 +76,28 @@
 BS3_PROC_END_MODE   Bs3SwitchToLM64
 
+
+%if TMPL_BITS == 16
+;;
+; Custom far stub.
+BS3_BEGIN_TEXT16_FARSTUBS
+BS3_PROC_BEGIN_MODE Bs3SwitchToLM64, BS3_PBC_FAR
+        inc         bp
+        push        bp
+        mov         bp, sp
+
+        ; Call the real thing.
+        call        TMPL_NM(Bs3SwitchToLM64)
+        BS3_SET_BITS 64
+
+        ; Jmp to common code for the tedious conversion.
+ %if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+        BS3_EXTERN_CMN Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+ %else
+        BS3_EXTERN_CMN Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+ %endif
+        BS3_SET_BITS 16
+BS3_PROC_END_MODE   Bs3SwitchToLM64
+%endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPAE16.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPAE16.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPAE16.asm	(revision 60554)
@@ -47,5 +47,5 @@
 ; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3SwitchToPAE16
+BS3_PROC_BEGIN_MODE Bs3SwitchToPAE16, BS3_PBC_NEAR
 %ifdef TMPL_PAE16
         extern  BS3_CMN_NM(Bs3SwitchToRing0)
@@ -166,2 +166,27 @@
 BS3_PROC_END_MODE   Bs3SwitchToPAE16
 
+
+%if TMPL_BITS == 16
+;;
+; Custom far stub.
+BS3_BEGIN_TEXT16_FARSTUBS
+BS3_PROC_BEGIN_MODE Bs3SwitchToPAE16, BS3_PBC_FAR
+        inc         bp
+        push        bp
+        mov         bp, sp
+
+        ; Call the real thing.
+        call        TMPL_NM(Bs3SwitchToPAE16)
+
+ %if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+        ; Jmp to  common code for the tedious conversion.
+        BS3_EXTERN_CMN Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+ %else
+        pop         bp
+        dec         bp
+        retf
+ %endif
+BS3_PROC_END_MODE   Bs3SwitchToPAE16
+%endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPAE16_32.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPAE16_32.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPAE16_32.asm	(revision 60554)
@@ -40,5 +40,5 @@
 ; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3SwitchToPAE16_32
+BS3_PROC_BEGIN_MODE Bs3SwitchToPAE16_32, BS3_PBC_NEAR
 %ifdef TMPL_PAE16_32
         ret
@@ -76,2 +76,28 @@
 BS3_PROC_END_MODE   Bs3SwitchToPAE16_32
 
+
+%if TMPL_BITS == 16
+;;
+; Custom far stub.
+BS3_BEGIN_TEXT16_FARSTUBS
+BS3_PROC_BEGIN_MODE Bs3SwitchToPAE16_32, BS3_PBC_FAR
+        inc         bp
+        push        bp
+        mov         bp, sp
+
+        ; Call the real thing.
+        call        TMPL_NM(Bs3SwitchToPAE16_32)
+        BS3_SET_BITS 32
+
+        ; Jmp to common code for the tedious conversion.
+ %if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+        BS3_EXTERN_CMN Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+ %else
+        BS3_EXTERN_CMN Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+ %endif
+        BS3_SET_BITS 16
+BS3_PROC_END_MODE   Bs3SwitchToPAE16_32
+%endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPAE16_V86.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPAE16_V86.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPAE16_V86.asm	(revision 60554)
@@ -40,5 +40,5 @@
 ; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3SwitchToPAE16_V86
+BS3_PROC_BEGIN_MODE Bs3SwitchToPAE16_V86, BS3_PBC_NEAR
 %ifdef TMPL_PAE16_V86
         ret
@@ -72,2 +72,27 @@
 BS3_PROC_END_MODE   Bs3SwitchToPAE16_V86
 
+
+%if TMPL_BITS == 16
+;;
+; Custom far stub.
+BS3_BEGIN_TEXT16_FARSTUBS
+BS3_PROC_BEGIN_MODE Bs3SwitchToPAE16_V86, BS3_PBC_FAR
+        inc         bp
+        push        bp
+        mov         bp, sp
+
+        ; Call the real thing.
+        call        TMPL_NM(Bs3SwitchToPAE16_V86)
+
+ %if !BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+        ; Jmp to common code for the tedious conversion.
+        BS3_EXTERN_CMN Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+ %else
+        pop         bp
+        dec         bp
+        retf
+ %endif
+BS3_PROC_END_MODE   Bs3SwitchToPAE16_V86
+%endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPAE32.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPAE32.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPAE32.asm	(revision 60554)
@@ -42,5 +42,5 @@
 ; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3SwitchToPAE32
+BS3_PROC_BEGIN_MODE Bs3SwitchToPAE32, BS3_PBC_NEAR
 %ifdef TMPL_PAE32
         ret
@@ -158,2 +158,28 @@
 BS3_PROC_END_MODE   Bs3SwitchToPAE32
 
+
+%if TMPL_BITS == 16
+;;
+; Custom far stub.
+BS3_BEGIN_TEXT16_FARSTUBS
+BS3_PROC_BEGIN_MODE Bs3SwitchToPAE32, BS3_PBC_FAR
+        inc         bp
+        push        bp
+        mov         bp, sp
+
+        ; Call the real thing.
+        call        TMPL_NM(Bs3SwitchToPAE32)
+        BS3_SET_BITS 32
+
+        ; Jmp to common code for the tedious conversion.
+ %if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+        BS3_EXTERN_CMN Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+ %else
+        BS3_EXTERN_CMN Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+ %endif
+        BS3_SET_BITS 16
+BS3_PROC_END_MODE   Bs3SwitchToPAE32
+%endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPAE32_16.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPAE32_16.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPAE32_16.asm	(revision 60554)
@@ -40,5 +40,5 @@
 ; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3SwitchToPAE32_16
+BS3_PROC_BEGIN_MODE Bs3SwitchToPAE32_16, BS3_PBC_NEAR
 %if TMPL_MODE == BS3_MODE_PAE32_16
         ret
@@ -80,2 +80,26 @@
 BS3_PROC_END_MODE   Bs3SwitchToPAE32_16
 
+%if TMPL_BITS == 16
+;;
+; Custom far stub.
+BS3_BEGIN_TEXT16_FARSTUBS
+BS3_PROC_BEGIN_MODE Bs3SwitchToPAE32_16, BS3_PBC_FAR
+        inc         bp
+        push        bp
+        mov         bp, sp
+
+        ; Call the real thing.
+        call        TMPL_NM(Bs3SwitchToPAE32_16)
+
+ %if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+        ; Jmp to  common code for the tedious conversion.
+        BS3_EXTERN_CMN Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+ %else
+        pop         bp
+        dec         bp
+        retf
+ %endif
+BS3_PROC_END_MODE   Bs3SwitchToPAE32_16
+%endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPAEV86.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPAEV86.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPAEV86.asm	(revision 60554)
@@ -40,5 +40,5 @@
 ; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3SwitchToPAEV86
+BS3_PROC_BEGIN_MODE Bs3SwitchToPAEV86, BS3_PBC_NEAR
 %if TMPL_MODE == BS3_MODE_PAEV86
         ret
@@ -66,2 +66,27 @@
 BS3_PROC_END_MODE   Bs3SwitchToPAEV86
 
+
+%if TMPL_BITS == 16
+;;
+; Custom far stub.
+BS3_BEGIN_TEXT16_FARSTUBS
+BS3_PROC_BEGIN_MODE Bs3SwitchToPAEV86, BS3_PBC_FAR
+        inc         bp
+        push        bp
+        mov         bp, sp
+
+        ; Call the real thing.
+        call        TMPL_NM(Bs3SwitchToPAEV86)
+
+ %if !BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+        ; Jmp to common code for the tedious conversion.
+        BS3_EXTERN_CMN Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+ %else
+        pop         bp
+        dec         bp
+        retf
+ %endif
+BS3_PROC_END_MODE   Bs3SwitchToPAEV86
+%endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE16.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE16.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE16.asm	(revision 60554)
@@ -40,5 +40,5 @@
 ; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3SwitchToPE16
+BS3_PROC_BEGIN_MODE Bs3SwitchToPE16, BS3_PBC_NEAR
 %ifdef TMPL_PE16
         extern  BS3_CMN_NM(Bs3SwitchToRing0)
@@ -125,2 +125,27 @@
 BS3_PROC_END_MODE   Bs3SwitchToPE16
 
+
+%if TMPL_BITS == 16
+;;
+; Custom far stub.
+BS3_BEGIN_TEXT16_FARSTUBS
+BS3_PROC_BEGIN_MODE Bs3SwitchToPE16, BS3_PBC_FAR
+        inc         bp
+        push        bp
+        mov         bp, sp
+
+        ; Call the real thing.
+        call        TMPL_NM(Bs3SwitchToPE16)
+
+ %if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+        ; Jmp to  common code for the tedious conversion.
+        BS3_EXTERN_CMN Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+ %else
+        pop         bp
+        dec         bp
+        retf
+ %endif
+BS3_PROC_END_MODE   Bs3SwitchToPE16
+%endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE16_32.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE16_32.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE16_32.asm	(revision 60554)
@@ -40,5 +40,5 @@
 ; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3SwitchToPE16_32
+BS3_PROC_BEGIN_MODE Bs3SwitchToPE16_32, BS3_PBC_NEAR
 %ifdef TMPL_PE16_32
         ret
@@ -76,2 +76,28 @@
 BS3_PROC_END_MODE   Bs3SwitchToPE16_32
 
+
+%if TMPL_BITS == 16
+;;
+; Custom far stub.
+BS3_BEGIN_TEXT16_FARSTUBS
+BS3_PROC_BEGIN_MODE Bs3SwitchToPE16_32, BS3_PBC_FAR
+        inc         bp
+        push        bp
+        mov         bp, sp
+
+        ; Call the real thing.
+        call        TMPL_NM(Bs3SwitchToPE16_32)
+        BS3_SET_BITS 32
+
+        ; Jmp to common code for the tedious conversion.
+ %if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+        BS3_EXTERN_CMN Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+ %else
+        BS3_EXTERN_CMN Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+ %endif
+        BS3_SET_BITS 16
+BS3_PROC_END_MODE   Bs3SwitchToPE16_32
+%endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE16_V86.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE16_V86.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE16_V86.asm	(revision 60554)
@@ -40,5 +40,5 @@
 ; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3SwitchToPE16_V86
+BS3_PROC_BEGIN_MODE Bs3SwitchToPE16_V86, BS3_PBC_NEAR
 %ifdef TMPL_PE16_V86
         ret
@@ -72,2 +72,27 @@
 BS3_PROC_END_MODE   Bs3SwitchToPE16_V86
 
+
+%if TMPL_BITS == 16
+;;
+; Custom far stub.
+BS3_BEGIN_TEXT16_FARSTUBS
+BS3_PROC_BEGIN_MODE Bs3SwitchToPE16_V86, BS3_PBC_FAR
+        inc         bp
+        push        bp
+        mov         bp, sp
+
+        ; Call the real thing.
+        call        TMPL_NM(Bs3SwitchToPE16_V86)
+
+ %if !BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+        ; Jmp to common code for the tedious conversion.
+        BS3_EXTERN_CMN Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+ %else
+        pop         bp
+        dec         bp
+        retf
+ %endif
+BS3_PROC_END_MODE   Bs3SwitchToPE16_V86
+%endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE32.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE32.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE32.asm	(revision 60554)
@@ -41,5 +41,5 @@
 ; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3SwitchToPE32
+BS3_PROC_BEGIN_MODE Bs3SwitchToPE32, BS3_PBC_NEAR
 %ifdef TMPL_PE32
         ret
@@ -136,2 +136,28 @@
 BS3_PROC_END_MODE   Bs3SwitchToPE32
 
+
+%if TMPL_BITS == 16
+;;
+; Custom far stub.
+BS3_BEGIN_TEXT16_FARSTUBS
+BS3_PROC_BEGIN_MODE Bs3SwitchToPE32, BS3_PBC_FAR
+        inc         bp
+        push        bp
+        mov         bp, sp
+
+        ; Call the real thing.
+        call        TMPL_NM(Bs3SwitchToPE32)
+        BS3_SET_BITS 32
+
+        ; Jmp to common code for the tedious conversion.
+ %if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+        BS3_EXTERN_CMN Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+ %else
+        BS3_EXTERN_CMN Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+ %endif
+        BS3_SET_BITS 16
+BS3_PROC_END_MODE   Bs3SwitchToPE32
+%endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE32_16.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE32_16.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE32_16.asm	(revision 60554)
@@ -40,5 +40,5 @@
 ; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3SwitchToPE32_16
+BS3_PROC_BEGIN_MODE Bs3SwitchToPE32_16, BS3_PBC_NEAR
 %if TMPL_MODE == BS3_MODE_PE32_16
         ret
@@ -80,2 +80,27 @@
 BS3_PROC_END_MODE   Bs3SwitchToPE32_16
 
+
+%if TMPL_BITS == 16
+;;
+; Custom far stub.
+BS3_BEGIN_TEXT16_FARSTUBS
+BS3_PROC_BEGIN_MODE Bs3SwitchToPE32_16, BS3_PBC_FAR
+        inc         bp
+        push        bp
+        mov         bp, sp
+
+        ; Call the real thing.
+        call        TMPL_NM(Bs3SwitchToPE32_16)
+
+ %if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+        ; Jmp to  common code for the tedious conversion.
+        BS3_EXTERN_CMN Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+ %else
+        pop         bp
+        dec         bp
+        retf
+ %endif
+BS3_PROC_END_MODE   Bs3SwitchToPE32_16
+%endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPEV86.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPEV86.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPEV86.asm	(revision 60554)
@@ -40,5 +40,5 @@
 ; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3SwitchToPEV86
+BS3_PROC_BEGIN_MODE Bs3SwitchToPEV86, BS3_PBC_NEAR
 %if TMPL_MODE == BS3_MODE_PEV86
         ret
@@ -66,2 +66,27 @@
 BS3_PROC_END_MODE   Bs3SwitchToPEV86
 
+
+%if TMPL_BITS == 16
+;;
+; Custom far stub.
+BS3_BEGIN_TEXT16_FARSTUBS
+BS3_PROC_BEGIN_MODE Bs3SwitchToPEV86, BS3_PBC_FAR
+        inc         bp
+        push        bp
+        mov         bp, sp
+
+        ; Call the real thing.
+        call        TMPL_NM(Bs3SwitchToPEV86)
+
+ %if !BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+        ; Jmp to common code for the tedious conversion.
+        BS3_EXTERN_CMN Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+ %else
+        pop         bp
+        dec         bp
+        retf
+ %endif
+BS3_PROC_END_MODE   Bs3SwitchToPEV86
+%endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPP16.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPP16.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPP16.asm	(revision 60554)
@@ -47,5 +47,5 @@
 ; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3SwitchToPP16
+BS3_PROC_BEGIN_MODE Bs3SwitchToPP16, BS3_PBC_NEAR
 %ifdef TMPL_PP16
         extern  BS3_CMN_NM(Bs3SwitchToRing0)
@@ -182,2 +182,27 @@
 BS3_PROC_END_MODE   Bs3SwitchToPP16
 
+
+%if TMPL_BITS == 16
+;;
+; Custom far stub.
+BS3_BEGIN_TEXT16_FARSTUBS
+BS3_PROC_BEGIN_MODE Bs3SwitchToPP16, BS3_PBC_FAR
+        inc         bp
+        push        bp
+        mov         bp, sp
+
+        ; Call the real thing.
+        call        TMPL_NM(Bs3SwitchToPP16)
+
+ %if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+        ; Jmp to  common code for the tedious conversion.
+        BS3_EXTERN_CMN Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+ %else
+        pop         bp
+        dec         bp
+        retf
+ %endif
+BS3_PROC_END_MODE   Bs3SwitchToPP16
+%endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPP16_32.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPP16_32.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPP16_32.asm	(revision 60554)
@@ -40,5 +40,5 @@
 ; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3SwitchToPP16_32
+BS3_PROC_BEGIN_MODE Bs3SwitchToPP16_32, BS3_PBC_NEAR
 %ifdef TMPL_PP16_32
         ret
@@ -76,2 +76,28 @@
 BS3_PROC_END_MODE   Bs3SwitchToPP16_32
 
+
+%if TMPL_BITS == 16
+;;
+; Custom far stub.
+BS3_BEGIN_TEXT16_FARSTUBS
+BS3_PROC_BEGIN_MODE Bs3SwitchToPP16_32, BS3_PBC_FAR
+        inc         bp
+        push        bp
+        mov         bp, sp
+
+        ; Call the real thing.
+        call        TMPL_NM(Bs3SwitchToPP16_32)
+        BS3_SET_BITS 32
+
+        ; Jmp to common code for the tedious conversion.
+ %if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+        BS3_EXTERN_CMN Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+ %else
+        BS3_EXTERN_CMN Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+ %endif
+        BS3_SET_BITS 16
+BS3_PROC_END_MODE   Bs3SwitchToPP16_32
+%endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPP16_V86.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPP16_V86.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPP16_V86.asm	(revision 60554)
@@ -40,5 +40,5 @@
 ; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3SwitchToPP16_V86
+BS3_PROC_BEGIN_MODE Bs3SwitchToPP16_V86, BS3_PBC_NEAR
 %ifdef TMPL_PP16_V86
         ret
@@ -72,2 +72,27 @@
 BS3_PROC_END_MODE   Bs3SwitchToPP16_V86
 
+
+%if TMPL_BITS == 16
+;;
+; Custom far stub.
+BS3_BEGIN_TEXT16_FARSTUBS
+BS3_PROC_BEGIN_MODE Bs3SwitchToPP16_V86, BS3_PBC_FAR
+        inc         bp
+        push        bp
+        mov         bp, sp
+
+        ; Call the real thing.
+        call        TMPL_NM(Bs3SwitchToPP16_V86)
+
+ %if !BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+        ; Jmp to common code for the tedious conversion.
+        BS3_EXTERN_CMN Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+ %else
+        pop         bp
+        dec         bp
+        retf
+ %endif
+BS3_PROC_END_MODE   Bs3SwitchToPP16_V86
+%endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPP32.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPP32.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPP32.asm	(revision 60554)
@@ -42,5 +42,5 @@
 ; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3SwitchToPP32
+BS3_PROC_BEGIN_MODE Bs3SwitchToPP32, BS3_PBC_NEAR
 %ifdef TMPL_PP32
         ret
@@ -166,2 +166,28 @@
 BS3_PROC_END_MODE   Bs3SwitchToPP32
 
+
+%if TMPL_BITS == 16
+;;
+; Custom far stub.
+BS3_BEGIN_TEXT16_FARSTUBS
+BS3_PROC_BEGIN_MODE Bs3SwitchToPP32, BS3_PBC_FAR
+        inc         bp
+        push        bp
+        mov         bp, sp
+
+        ; Call the real thing.
+        call        TMPL_NM(Bs3SwitchToPP32)
+        BS3_SET_BITS 32
+
+        ; Jmp to common code for the tedious conversion.
+ %if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+        BS3_EXTERN_CMN Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+ %else
+        BS3_EXTERN_CMN Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+ %endif
+        BS3_SET_BITS 16
+BS3_PROC_END_MODE   Bs3SwitchToPP32
+%endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPP32_16.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPP32_16.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPP32_16.asm	(revision 60554)
@@ -40,5 +40,5 @@
 ; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3SwitchToPP32_16
+BS3_PROC_BEGIN_MODE Bs3SwitchToPP32_16, BS3_PBC_NEAR
 %if TMPL_MODE == BS3_MODE_PP32_16
         ret
@@ -80,2 +80,27 @@
 BS3_PROC_END_MODE   Bs3SwitchToPP32_16
 
+
+%if TMPL_BITS == 16
+;;
+; Custom far stub.
+BS3_BEGIN_TEXT16_FARSTUBS
+BS3_PROC_BEGIN_MODE Bs3SwitchToPP32_16, BS3_PBC_FAR
+        inc         bp
+        push        bp
+        mov         bp, sp
+
+        ; Call the real thing.
+        call        TMPL_NM(Bs3SwitchToPP32_16)
+
+ %if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+        ; Jmp to  common code for the tedious conversion.
+        BS3_EXTERN_CMN Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvRealModeRetfPopBpDecBpAndReturn
+ %else
+        pop         bp
+        dec         bp
+        retf
+ %endif
+BS3_PROC_END_MODE   Bs3SwitchToPP32_16
+%endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPPV86.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPPV86.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPPV86.asm	(revision 60554)
@@ -40,5 +40,5 @@
 ; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3SwitchToPPV86
+BS3_PROC_BEGIN_MODE Bs3SwitchToPPV86, BS3_PBC_NEAR
 %if TMPL_MODE == BS3_MODE_PPV86
         ret
@@ -66,2 +66,27 @@
 BS3_PROC_END_MODE   Bs3SwitchToPPV86
 
+
+%if TMPL_BITS == 16
+;;
+; Custom far stub.
+BS3_BEGIN_TEXT16_FARSTUBS
+BS3_PROC_BEGIN_MODE Bs3SwitchToPPV86, BS3_PBC_FAR
+        inc         bp
+        push        bp
+        mov         bp, sp
+
+        ; Call the real thing.
+        call        TMPL_NM(Bs3SwitchToPPV86)
+
+ %if !BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+        ; Jmp to  common code for the tedious conversion.
+        BS3_EXTERN_CMN Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+ %else
+        pop         bp
+        dec         bp
+        retf
+ %endif
+BS3_PROC_END_MODE   Bs3SwitchToPPV86
+%endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToRM.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToRM.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToRM.asm	(revision 60554)
@@ -65,5 +65,5 @@
 ; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
 ;
-BS3_PROC_BEGIN_MODE Bs3SwitchToRM
+BS3_PROC_BEGIN_MODE Bs3SwitchToRM, BS3_PBC_NEAR
 %ifdef TMPL_RM
         push    ax
@@ -338,2 +338,27 @@
 BS3_PROC_END_MODE   Bs3SwitchToRM
 
+
+%if TMPL_BITS == 16
+;;
+; Custom far stub.
+BS3_BEGIN_TEXT16_FARSTUBS
+BS3_PROC_BEGIN_MODE Bs3SwitchToRM, BS3_PBC_FAR
+        inc         bp
+        push        bp
+        mov         bp, sp
+
+        ; Call the real thing.
+        call        TMPL_NM(Bs3SwitchToRM)
+
+ %if !BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+        ; Jmp to  common code for the tedious conversion.
+        BS3_EXTERN_CMN Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+        jmp         Bs3SwitchHlpConvProtModeRetfPopBpDecBpAndReturn
+ %else
+        pop         bp
+        dec         bp
+        retf
+ %endif
+BS3_PROC_END_MODE   Bs3SwitchToRM
+%endif
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TestDoModes.c
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TestDoModes.c	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TestDoModes.c	(revision 60554)
@@ -25,4 +25,6 @@
  */
 
+/** @todo get this mess into the RM segment! */
+
 
 /*********************************************************************************************************************************
@@ -61,26 +63,26 @@
 *   Assembly Symbols                                                                                                             *
 *********************************************************************************************************************************/
-BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInRM)(uint32_t uCallbackFarPtr);
-BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPE16)(uint32_t uCallbackFarPtr);
-BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPE16_32)(uint32_t uFlatAddrCallback);
-BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPE16_V86)(uint32_t uCallbackFarPtr);
-BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPE32)(uint32_t uFlatAddrCallback);
-BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPE32_16)(uint32_t uCallbackFarPtr);
-BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPEV86)(uint32_t uCallbackFarPtr);
-BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPP16)(uint32_t uCallbackFarPtr);
-BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPP16_32)(uint32_t uFlatAddrCallback);
-BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPP16_V86)(uint32_t uCallbackFarPtr);
-BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPP32)(uint32_t uFlatAddrCallback);
-BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPP32_16)(uint32_t uCallbackFarPtr);
-BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPPV86)(uint32_t uCallbackFarPtr);
-BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPAE16)(uint32_t uCallbackFarPtr);
-BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPAE16_32)(uint32_t uFlatAddrCallback);
-BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPAE16_V86)(uint32_t uCallbackFarPtr);
-BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPAE32)(uint32_t uFlatAddrCallback);
-BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPAE32_16)(uint32_t uCallbackFarPtr);
-BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInPAEV86)(uint32_t uCallbackFarPtr);
-BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInLM16)(uint32_t uCallbackFarPtr);
-BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInLM32)(uint32_t uFlatAddrCallback);
-BS3_DECL(uint8_t) TMPL_NM(Bs3TestCallDoerInLM64)(uint32_t uFlatAddrCallback);
+BS3_DECL_FAR(uint8_t) TMPL_FAR_NM(Bs3TestCallDoerInRM)(uint32_t uCallbackFarPtr);
+BS3_DECL_FAR(uint8_t) TMPL_FAR_NM(Bs3TestCallDoerInPE16)(uint32_t uCallbackFarPtr);
+BS3_DECL_FAR(uint8_t) TMPL_FAR_NM(Bs3TestCallDoerInPE16_32)(uint32_t uFlatAddrCallback);
+BS3_DECL_FAR(uint8_t) TMPL_FAR_NM(Bs3TestCallDoerInPE16_V86)(uint32_t uCallbackFarPtr);
+BS3_DECL_FAR(uint8_t) TMPL_FAR_NM(Bs3TestCallDoerInPE32)(uint32_t uFlatAddrCallback);
+BS3_DECL_FAR(uint8_t) TMPL_FAR_NM(Bs3TestCallDoerInPE32_16)(uint32_t uCallbackFarPtr);
+BS3_DECL_FAR(uint8_t) TMPL_FAR_NM(Bs3TestCallDoerInPEV86)(uint32_t uCallbackFarPtr);
+BS3_DECL_FAR(uint8_t) TMPL_FAR_NM(Bs3TestCallDoerInPP16)(uint32_t uCallbackFarPtr);
+BS3_DECL_FAR(uint8_t) TMPL_FAR_NM(Bs3TestCallDoerInPP16_32)(uint32_t uFlatAddrCallback);
+BS3_DECL_FAR(uint8_t) TMPL_FAR_NM(Bs3TestCallDoerInPP16_V86)(uint32_t uCallbackFarPtr);
+BS3_DECL_FAR(uint8_t) TMPL_FAR_NM(Bs3TestCallDoerInPP32)(uint32_t uFlatAddrCallback);
+BS3_DECL_FAR(uint8_t) TMPL_FAR_NM(Bs3TestCallDoerInPP32_16)(uint32_t uCallbackFarPtr);
+BS3_DECL_FAR(uint8_t) TMPL_FAR_NM(Bs3TestCallDoerInPPV86)(uint32_t uCallbackFarPtr);
+BS3_DECL_FAR(uint8_t) TMPL_FAR_NM(Bs3TestCallDoerInPAE16)(uint32_t uCallbackFarPtr);
+BS3_DECL_FAR(uint8_t) TMPL_FAR_NM(Bs3TestCallDoerInPAE16_32)(uint32_t uFlatAddrCallback);
+BS3_DECL_FAR(uint8_t) TMPL_FAR_NM(Bs3TestCallDoerInPAE16_V86)(uint32_t uCallbackFarPtr);
+BS3_DECL_FAR(uint8_t) TMPL_FAR_NM(Bs3TestCallDoerInPAE32)(uint32_t uFlatAddrCallback);
+BS3_DECL_FAR(uint8_t) TMPL_FAR_NM(Bs3TestCallDoerInPAE32_16)(uint32_t uCallbackFarPtr);
+BS3_DECL_FAR(uint8_t) TMPL_FAR_NM(Bs3TestCallDoerInPAEV86)(uint32_t uCallbackFarPtr);
+BS3_DECL_FAR(uint8_t) TMPL_FAR_NM(Bs3TestCallDoerInLM16)(uint32_t uCallbackFarPtr);
+BS3_DECL_FAR(uint8_t) TMPL_FAR_NM(Bs3TestCallDoerInLM32)(uint32_t uFlatAddrCallback);
+BS3_DECL_FAR(uint8_t) TMPL_FAR_NM(Bs3TestCallDoerInLM64)(uint32_t uFlatAddrCallback);
 
 
@@ -174,5 +176,6 @@
 }
 
-BS3_DECL(void) TMPL_NM(Bs3TestDoModes)(PCBS3TESTMODEENTRY paEntries, size_t cEntries)
+
+BS3_MODE_DEF(void, Bs3TestDoModes,(PCBS3TESTMODEENTRY paEntries, size_t cEntries))
 {
     bool const      fVerbose         = true;
@@ -215,5 +218,5 @@
         {
             PRE_DO_CALL(g_szBs3ModeName_rm);
-            bErrNo = TMPL_NM(Bs3TestCallDoerInRM)(CONV_TO_RM_FAR16(paEntries[i].pfnDoRM));
+            bErrNo = TMPL_FAR_NM(Bs3TestCallDoerInRM)(CONV_TO_RM_FAR16(paEntries[i].pfnDoRM));
             CHECK_RESULT(g_szBs3ModeName_rm);
         }
@@ -232,5 +235,5 @@
         {
             PRE_DO_CALL(g_szBs3ModeName_pe16);
-            bErrNo = TMPL_NM(Bs3TestCallDoerInPE16)(CONV_TO_PROT_FAR16(paEntries[i].pfnDoPE16));
+            bErrNo = TMPL_FAR_NM(Bs3TestCallDoerInPE16)(CONV_TO_PROT_FAR16(paEntries[i].pfnDoPE16));
             CHECK_RESULT(g_szBs3ModeName_pe16);
         }
@@ -245,5 +248,5 @@
         {
             PRE_DO_CALL(g_szBs3ModeName_pe16_32);
-            bErrNo = TMPL_NM(Bs3TestCallDoerInPE16_32)(CONV_TO_FLAT(paEntries[i].pfnDoPE16_32));
+            bErrNo = TMPL_FAR_NM(Bs3TestCallDoerInPE16_32)(CONV_TO_FLAT(paEntries[i].pfnDoPE16_32));
             CHECK_RESULT(g_szBs3ModeName_pe16_32);
         }
@@ -252,5 +255,5 @@
         {
             PRE_DO_CALL(g_szBs3ModeName_pe16_v86);
-            bErrNo = TMPL_NM(Bs3TestCallDoerInPE16_V86)(CONV_TO_RM_FAR16(paEntries[i].pfnDoPE16_V86));
+            bErrNo = TMPL_FAR_NM(Bs3TestCallDoerInPE16_V86)(CONV_TO_RM_FAR16(paEntries[i].pfnDoPE16_V86));
             CHECK_RESULT(g_szBs3ModeName_pe16_v86);
         }
@@ -259,5 +262,5 @@
         {
             PRE_DO_CALL(g_szBs3ModeName_pe32);
-            bErrNo = TMPL_NM(Bs3TestCallDoerInPE32)(CONV_TO_FLAT(paEntries[i].pfnDoPE32));
+            bErrNo = TMPL_FAR_NM(Bs3TestCallDoerInPE32)(CONV_TO_FLAT(paEntries[i].pfnDoPE32));
             CHECK_RESULT(g_szBs3ModeName_pe32);
         }
@@ -266,5 +269,5 @@
         {
             PRE_DO_CALL(g_szBs3ModeName_pe32_16);
-            bErrNo = TMPL_NM(Bs3TestCallDoerInPE32_16)(CONV_TO_PROT_FAR16(paEntries[i].pfnDoPE32_16));
+            bErrNo = TMPL_FAR_NM(Bs3TestCallDoerInPE32_16)(CONV_TO_PROT_FAR16(paEntries[i].pfnDoPE32_16));
             CHECK_RESULT(g_szBs3ModeName_pe32_16);
         }
@@ -273,5 +276,5 @@
         {
             PRE_DO_CALL(g_szBs3ModeName_pev86);
-            bErrNo = TMPL_NM(Bs3TestCallDoerInPEV86)(CONV_TO_RM_FAR16(paEntries[i].pfnDoPEV86));
+            bErrNo = TMPL_FAR_NM(Bs3TestCallDoerInPEV86)(CONV_TO_RM_FAR16(paEntries[i].pfnDoPEV86));
             CHECK_RESULT(g_szBs3ModeName_pev86);
         }
@@ -283,5 +286,5 @@
         {
             PRE_DO_CALL(g_szBs3ModeName_pp16);
-            bErrNo = TMPL_NM(Bs3TestCallDoerInPP16)(CONV_TO_PROT_FAR16(paEntries[i].pfnDoPP16));
+            bErrNo = TMPL_FAR_NM(Bs3TestCallDoerInPP16)(CONV_TO_PROT_FAR16(paEntries[i].pfnDoPP16));
             CHECK_RESULT(g_szBs3ModeName_pp16);
         }
@@ -290,5 +293,5 @@
         {
             PRE_DO_CALL(g_szBs3ModeName_pp16_32);
-            bErrNo = TMPL_NM(Bs3TestCallDoerInPP16_32)(CONV_TO_FLAT(paEntries[i].pfnDoPP16_32));
+            bErrNo = TMPL_FAR_NM(Bs3TestCallDoerInPP16_32)(CONV_TO_FLAT(paEntries[i].pfnDoPP16_32));
             CHECK_RESULT(g_szBs3ModeName_pp16_32);
         }
@@ -297,5 +300,5 @@
         {
             PRE_DO_CALL(g_szBs3ModeName_pp16_v86);
-            bErrNo = TMPL_NM(Bs3TestCallDoerInPP16_V86)(CONV_TO_RM_FAR16(paEntries[i].pfnDoPP16_V86));
+            bErrNo = TMPL_FAR_NM(Bs3TestCallDoerInPP16_V86)(CONV_TO_RM_FAR16(paEntries[i].pfnDoPP16_V86));
             CHECK_RESULT(g_szBs3ModeName_pp16_v86);
         }
@@ -304,5 +307,5 @@
         {
             PRE_DO_CALL(g_szBs3ModeName_pp32);
-            bErrNo = TMPL_NM(Bs3TestCallDoerInPP32)(CONV_TO_FLAT(paEntries[i].pfnDoPP32));
+            bErrNo = TMPL_FAR_NM(Bs3TestCallDoerInPP32)(CONV_TO_FLAT(paEntries[i].pfnDoPP32));
             CHECK_RESULT(g_szBs3ModeName_pp32);
         }
@@ -311,5 +314,5 @@
         {
             PRE_DO_CALL(g_szBs3ModeName_pp32_16);
-            bErrNo = TMPL_NM(Bs3TestCallDoerInPP32_16)(CONV_TO_PROT_FAR16(paEntries[i].pfnDoPP32_16));
+            bErrNo = TMPL_FAR_NM(Bs3TestCallDoerInPP32_16)(CONV_TO_PROT_FAR16(paEntries[i].pfnDoPP32_16));
             CHECK_RESULT(g_szBs3ModeName_pp32_16);
         }
@@ -318,5 +321,5 @@
         {
             PRE_DO_CALL(g_szBs3ModeName_ppv86);
-            bErrNo = TMPL_NM(Bs3TestCallDoerInPPV86)(CONV_TO_RM_FAR16(paEntries[i].pfnDoPPV86));
+            bErrNo = TMPL_FAR_NM(Bs3TestCallDoerInPPV86)(CONV_TO_RM_FAR16(paEntries[i].pfnDoPPV86));
             CHECK_RESULT(g_szBs3ModeName_ppv86);
         }
@@ -335,5 +338,5 @@
         {
             PRE_DO_CALL(g_szBs3ModeName_pae16);
-            bErrNo = TMPL_NM(Bs3TestCallDoerInPAE16)(CONV_TO_PROT_FAR16(paEntries[i].pfnDoPAE16));
+            bErrNo = TMPL_FAR_NM(Bs3TestCallDoerInPAE16)(CONV_TO_PROT_FAR16(paEntries[i].pfnDoPAE16));
             CHECK_RESULT(g_szBs3ModeName_pae16);
         }
@@ -342,5 +345,5 @@
         {
             PRE_DO_CALL(g_szBs3ModeName_pae16_32);
-            bErrNo = TMPL_NM(Bs3TestCallDoerInPAE16_32)(CONV_TO_FLAT(paEntries[i].pfnDoPAE16_32));
+            bErrNo = TMPL_FAR_NM(Bs3TestCallDoerInPAE16_32)(CONV_TO_FLAT(paEntries[i].pfnDoPAE16_32));
             CHECK_RESULT(g_szBs3ModeName_pae16_32);
         }
@@ -349,5 +352,5 @@
         {
             PRE_DO_CALL(g_szBs3ModeName_pae16_v86);
-            bErrNo = TMPL_NM(Bs3TestCallDoerInPAE16_V86)(CONV_TO_RM_FAR16(paEntries[i].pfnDoPAE16_V86));
+            bErrNo = TMPL_FAR_NM(Bs3TestCallDoerInPAE16_V86)(CONV_TO_RM_FAR16(paEntries[i].pfnDoPAE16_V86));
             CHECK_RESULT(g_szBs3ModeName_pae16_v86);
         }
@@ -356,5 +359,5 @@
         {
             PRE_DO_CALL(g_szBs3ModeName_pae32);
-            bErrNo = TMPL_NM(Bs3TestCallDoerInPAE32)(CONV_TO_FLAT(paEntries[i].pfnDoPAE32));
+            bErrNo = TMPL_FAR_NM(Bs3TestCallDoerInPAE32)(CONV_TO_FLAT(paEntries[i].pfnDoPAE32));
             CHECK_RESULT(g_szBs3ModeName_pae32);
         }
@@ -363,5 +366,5 @@
         {
             PRE_DO_CALL(g_szBs3ModeName_pae32_16);
-            bErrNo = TMPL_NM(Bs3TestCallDoerInPAE32_16)(CONV_TO_PROT_FAR16(paEntries[i].pfnDoPAE32_16));
+            bErrNo = TMPL_FAR_NM(Bs3TestCallDoerInPAE32_16)(CONV_TO_PROT_FAR16(paEntries[i].pfnDoPAE32_16));
             CHECK_RESULT(g_szBs3ModeName_pae32_16);
         }
@@ -370,5 +373,5 @@
         {
             PRE_DO_CALL(g_szBs3ModeName_paev86);
-            bErrNo = TMPL_NM(Bs3TestCallDoerInPAEV86)(CONV_TO_RM_FAR16(paEntries[i].pfnDoPAEV86));
+            bErrNo = TMPL_FAR_NM(Bs3TestCallDoerInPAEV86)(CONV_TO_RM_FAR16(paEntries[i].pfnDoPAEV86));
             CHECK_RESULT(g_szBs3ModeName_paev86);
         }
@@ -387,5 +390,5 @@
         {
             PRE_DO_CALL(g_szBs3ModeName_lm16);
-            bErrNo = TMPL_NM(Bs3TestCallDoerInLM16)(CONV_TO_PROT_FAR16(paEntries[i].pfnDoLM16));
+            bErrNo = TMPL_FAR_NM(Bs3TestCallDoerInLM16)(CONV_TO_PROT_FAR16(paEntries[i].pfnDoLM16));
             CHECK_RESULT(g_szBs3ModeName_lm16);
         }
@@ -394,5 +397,5 @@
         {
             PRE_DO_CALL(g_szBs3ModeName_lm32);
-            bErrNo = TMPL_NM(Bs3TestCallDoerInLM32)(CONV_TO_FLAT(paEntries[i].pfnDoLM32));
+            bErrNo = TMPL_FAR_NM(Bs3TestCallDoerInLM32)(CONV_TO_FLAT(paEntries[i].pfnDoLM32));
             CHECK_RESULT(g_szBs3ModeName_lm32);
         }
@@ -401,5 +404,5 @@
         {
             PRE_DO_CALL(g_szBs3ModeName_lm64);
-            bErrNo = TMPL_NM(Bs3TestCallDoerInLM64)(CONV_TO_FLAT(paEntries[i].pfnDoLM64));
+            bErrNo = TMPL_FAR_NM(Bs3TestCallDoerInLM64)(CONV_TO_FLAT(paEntries[i].pfnDoLM64));
             CHECK_RESULT(g_szBs3ModeName_lm64);
         }
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TestDoModesHlp.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TestDoModesHlp.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TestDoModesHlp.asm	(revision 60554)
@@ -154,5 +154,9 @@
         xPOPF
         pop     xBP
+%if TMPL_BITS == 16
+        retf
+%else
         ret
+%endif
 
 ;
@@ -213,12 +217,12 @@
 ; @cproto   BS3_DECL(uint8_t) Bs3TestCallDoerInRM(uint16_t offBs3Text16);
 ; @uses     rax
-BS3_PROC_BEGIN_MODE Bs3TestCallDoerInRM
-        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
-        jmp     TMPL_NM(bs3TestCallDoerPrologue)
-BS3_BEGIN_TEXT16
-BS3_SET_BITS TMPL_BITS
-.doit:
-        mov     ax, [xBP + xCB*2]       ; Load far function pointer.
-        mov     dx, [xBP + xCB*2 + 2]
+BS3_PROC_BEGIN_MODE Bs3TestCallDoerInRM, BS3_PBC_FAR
+        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
+        jmp     TMPL_NM(bs3TestCallDoerPrologue)
+BS3_BEGIN_TEXT16
+BS3_SET_BITS TMPL_BITS
+.doit:
+        mov     ax, [xBP + xCB + cbCurRetAddr]      ; Load far function pointer.
+        mov     dx, [xBP + xCB + cbCurRetAddr + 2]
 
         ; Mode switch, make the call, switch back.
@@ -254,12 +258,12 @@
 ; @cproto   BS3_DECL(uint8_t) Bs3TestCallDoerInPE16(uint16_t offBs3Text16);
 ; @uses     rax
-BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPE16
-        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
-        jmp     TMPL_NM(bs3TestCallDoerPrologue)
-BS3_BEGIN_TEXT16
-BS3_SET_BITS TMPL_BITS
-.doit:
-        mov     ax, [xBP + xCB*2]       ; Load far function pointer.
-        mov     dx, [xBP + xCB*2 + 2]
+BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPE16, BS3_PBC_FAR
+        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
+        jmp     TMPL_NM(bs3TestCallDoerPrologue)
+BS3_BEGIN_TEXT16
+BS3_SET_BITS TMPL_BITS
+.doit:
+        mov     ax, [xBP + xCB + cbCurRetAddr]      ; Load far function pointer.
+        mov     dx, [xBP + xCB + cbCurRetAddr + 2]
 
         ; Mode switch, make the call, switch back.
@@ -287,9 +291,9 @@
 ; @cproto   BS3_DECL(uint8_t) Bs3TestCallDoerInPE16_32(uint16_t offBs3Text16);
 ; @uses     rax
-BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPE16_32
-        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
-        jmp     TMPL_NM(bs3TestCallDoerPrologue)
-.doit:
-        mov     eax, [xBP + xCB*2]      ; Load function pointer.
+BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPE16_32, BS3_PBC_FAR
+        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
+        jmp     TMPL_NM(bs3TestCallDoerPrologue)
+.doit:
+        mov     eax, [xBP + xCB + cbCurRetAddr]      ; Load function pointer.
 
         ; Mode switch, make the call, switch back.
@@ -312,10 +316,10 @@
 ; @cproto   BS3_DECL(uint8_t) Bs3TestCallDoerInPE16_V86(uint16_t offBs3Text16);
 ; @uses     rax
-BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPE16_V86
-        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
-        jmp     TMPL_NM(bs3TestCallDoerPrologue)
-.doit:
-        mov     ax, [xBP + xCB*2]       ; Load far function pointer.
-        mov     dx, [xBP + xCB*2 + 2]
+BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPE16_V86, BS3_PBC_FAR
+        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
+        jmp     TMPL_NM(bs3TestCallDoerPrologue)
+.doit:
+        mov     ax, [xBP + xCB + cbCurRetAddr]      ; Load far function pointer.
+        mov     dx, [xBP + xCB + cbCurRetAddr + 2]
 
         ; Mode switch, make the call, switch back.
@@ -343,9 +347,9 @@
 ; @cproto   BS3_DECL(uint8_t) Bs3TestCallDoerInPE32(uint16_t offBs3Text16);
 ; @uses     rax
-BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPE32
-        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
-        jmp     TMPL_NM(bs3TestCallDoerPrologue)
-.doit:
-        mov     eax, [xBP + xCB*2]      ; Load function pointer.
+BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPE32, BS3_PBC_FAR
+        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
+        jmp     TMPL_NM(bs3TestCallDoerPrologue)
+.doit:
+        mov     eax, [xBP + xCB + cbCurRetAddr]      ; Load function pointer.
 
         ; Mode switch, make the call, switch back.
@@ -368,12 +372,12 @@
 ; @cproto   BS3_DECL(uint8_t) Bs3TestCallDoerInPE32_16(uint16_t offBs3Text16);
 ; @uses     rax
-BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPE32_16
-        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
-        jmp     TMPL_NM(bs3TestCallDoerPrologue)
-BS3_BEGIN_TEXT16
-BS3_SET_BITS TMPL_BITS
-.doit:
-        mov     ax, [xBP + xCB*2]       ; Load far function pointer.
-        mov     dx, [xBP + xCB*2 + 2]
+BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPE32_16, BS3_PBC_FAR
+        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
+        jmp     TMPL_NM(bs3TestCallDoerPrologue)
+BS3_BEGIN_TEXT16
+BS3_SET_BITS TMPL_BITS
+.doit:
+        mov     ax, [xBP + xCB + cbCurRetAddr]      ; Load far function pointer.
+        mov     dx, [xBP + xCB + cbCurRetAddr + 2]
 
         ; Mode switch, make the call, switch back.
@@ -402,12 +406,12 @@
 ; @cproto   BS3_DECL(uint8_t) Bs3TestCallDoerInPEV86(uint16_t offBs3Text16);
 ; @uses     rax
-BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPEV86
-        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
-        jmp     TMPL_NM(bs3TestCallDoerPrologue)
-BS3_BEGIN_TEXT16
-BS3_SET_BITS TMPL_BITS
-.doit:
-        mov     ax, [xBP + xCB*2]       ; Load far function pointer.
-        mov     dx, [xBP + xCB*2 + 2]
+BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPEV86, BS3_PBC_FAR
+        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
+        jmp     TMPL_NM(bs3TestCallDoerPrologue)
+BS3_BEGIN_TEXT16
+BS3_SET_BITS TMPL_BITS
+.doit:
+        mov     ax, [xBP + xCB + cbCurRetAddr]      ; Load far function pointer.
+        mov     dx, [xBP + xCB + cbCurRetAddr + 2]
 
         ; Mode switch, make the call, switch back.
@@ -442,12 +446,12 @@
 ; @cproto   BS3_DECL(uint8_t) Bs3TestCallDoerInPP16(uint16_t offBs3Text16);
 ; @uses     rax
-BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPP16
-        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
-        jmp     TMPL_NM(bs3TestCallDoerPrologue)
-BS3_BEGIN_TEXT16
-BS3_SET_BITS TMPL_BITS
-.doit:
-        mov     ax, [xBP + xCB*2]       ; Load far function pointer.
-        mov     dx, [xBP + xCB*2 + 2]
+BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPP16, BS3_PBC_FAR
+        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
+        jmp     TMPL_NM(bs3TestCallDoerPrologue)
+BS3_BEGIN_TEXT16
+BS3_SET_BITS TMPL_BITS
+.doit:
+        mov     ax, [xBP + xCB + cbCurRetAddr]      ; Load far function pointer.
+        mov     dx, [xBP + xCB + cbCurRetAddr + 2]
 
         ; Mode switch, make the call, switch back.
@@ -476,9 +480,9 @@
 ; @cproto   BS3_DECL(uint8_t) Bs3TestCallDoerInPP16_32(uint16_t offBs3Text16);
 ; @uses     rax
-BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPP16_32
-        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
-        jmp     TMPL_NM(bs3TestCallDoerPrologue)
-.doit:
-        mov     eax, [xBP + xCB*2]      ; Load function pointer.
+BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPP16_32, BS3_PBC_FAR
+        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
+        jmp     TMPL_NM(bs3TestCallDoerPrologue)
+.doit:
+        mov     eax, [xBP + xCB + cbCurRetAddr]      ; Load function pointer.
 
         ; Mode switch, make the call, switch back.
@@ -501,10 +505,10 @@
 ; @cproto   BS3_DECL(uint8_t) Bs3TestCallDoerInPP16_V86(uint16_t offBs3Text16);
 ; @uses     rax
-BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPP16_V86
-        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
-        jmp     TMPL_NM(bs3TestCallDoerPrologue)
-.doit:
-        mov     ax, [xBP + xCB*2]       ; Load far function pointer.
-        mov     dx, [xBP + xCB*2 + 2]
+BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPP16_V86, BS3_PBC_FAR
+        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
+        jmp     TMPL_NM(bs3TestCallDoerPrologue)
+.doit:
+        mov     ax, [xBP + xCB + cbCurRetAddr]      ; Load far function pointer.
+        mov     dx, [xBP + xCB + cbCurRetAddr + 2]
 
         ; Mode switch, make the call, switch back.
@@ -532,9 +536,9 @@
 ; @cproto   BS3_DECL(uint8_t) Bs3TestCallDoerInPP32(uint16_t offBs3Text16);
 ; @uses     rax
-BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPP32
-        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
-        jmp     TMPL_NM(bs3TestCallDoerPrologue)
-.doit:
-        mov     eax, [xBP + xCB*2]      ; Load function pointer.
+BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPP32, BS3_PBC_FAR
+        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
+        jmp     TMPL_NM(bs3TestCallDoerPrologue)
+.doit:
+        mov     eax, [xBP + xCB + cbCurRetAddr]      ; Load function pointer.
 
         ; Mode switch, make the call, switch back.
@@ -557,12 +561,12 @@
 ; @cproto   BS3_DECL(uint8_t) Bs3TestCallDoerInPP32_16(uint16_t offBs3Text16);
 ; @uses     rax
-BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPP32_16
-        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
-        jmp     TMPL_NM(bs3TestCallDoerPrologue)
-BS3_BEGIN_TEXT16
-BS3_SET_BITS TMPL_BITS
-.doit:
-        mov     ax, [xBP + xCB*2]       ; Load far function pointer.
-        mov     dx, [xBP + xCB*2 + 2]
+BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPP32_16, BS3_PBC_FAR
+        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
+        jmp     TMPL_NM(bs3TestCallDoerPrologue)
+BS3_BEGIN_TEXT16
+BS3_SET_BITS TMPL_BITS
+.doit:
+        mov     ax, [xBP + xCB + cbCurRetAddr]      ; Load far function pointer.
+        mov     dx, [xBP + xCB + cbCurRetAddr + 2]
 
         ; Mode switch, make the call, switch back.
@@ -591,12 +595,12 @@
 ; @cproto   BS3_DECL(uint8_t) Bs3TestCallDoerInPPV86(uint16_t offBs3Text16);
 ; @uses     rax
-BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPPV86
-        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
-        jmp     TMPL_NM(bs3TestCallDoerPrologue)
-BS3_BEGIN_TEXT16
-BS3_SET_BITS TMPL_BITS
-.doit:
-        mov     ax, [xBP + xCB*2]       ; Load far function pointer.
-        mov     dx, [xBP + xCB*2 + 2]
+BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPPV86, BS3_PBC_FAR
+        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
+        jmp     TMPL_NM(bs3TestCallDoerPrologue)
+BS3_BEGIN_TEXT16
+BS3_SET_BITS TMPL_BITS
+.doit:
+        mov     ax, [xBP + xCB + cbCurRetAddr]      ; Load far function pointer.
+        mov     dx, [xBP + xCB + cbCurRetAddr + 2]
 
         ; Mode switch, make the call, switch back.
@@ -631,12 +635,12 @@
 ; @cproto   BS3_DECL(uint8_t) Bs3TestCallDoerInPAE16(uint16_t offBs3Text16);
 ; @uses     rax
-BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPAE16
-        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
-        jmp     TMPL_NM(bs3TestCallDoerPrologue)
-BS3_BEGIN_TEXT16
-BS3_SET_BITS TMPL_BITS
-.doit:
-        mov     ax, [xBP + xCB*2]       ; Load far function pointer.
-        mov     dx, [xBP + xCB*2 + 2]
+BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPAE16, BS3_PBC_FAR
+        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
+        jmp     TMPL_NM(bs3TestCallDoerPrologue)
+BS3_BEGIN_TEXT16
+BS3_SET_BITS TMPL_BITS
+.doit:
+        mov     ax, [xBP + xCB + cbCurRetAddr]      ; Load far function pointer.
+        mov     dx, [xBP + xCB + cbCurRetAddr + 2]
 
         ; Mode switch, make the call, switch back.
@@ -665,9 +669,9 @@
 ; @cproto   BS3_DECL(uint8_t) Bs3TestCallDoerInPAE16_32(uint16_t offBs3Text16);
 ; @uses     rax
-BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPAE16_32
-        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
-        jmp     TMPL_NM(bs3TestCallDoerPrologue)
-.doit:
-        mov     eax, [xBP + xCB*2]      ; Load function pointer.
+BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPAE16_32, BS3_PBC_FAR
+        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
+        jmp     TMPL_NM(bs3TestCallDoerPrologue)
+.doit:
+        mov     eax, [xBP + xCB + cbCurRetAddr]      ; Load function pointer.
 
         ; Mode switch, make the call, switch back.
@@ -690,10 +694,10 @@
 ; @cproto   BS3_DECL(uint8_t) Bs3TestCallDoerInPAE16_V86(uint16_t offBs3Text16);
 ; @uses     rax
-BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPAE16_V86
-        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
-        jmp     TMPL_NM(bs3TestCallDoerPrologue)
-.doit:
-        mov     ax, [xBP + xCB*2]       ; Load far function pointer.
-        mov     dx, [xBP + xCB*2 + 2]
+BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPAE16_V86, BS3_PBC_FAR
+        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
+        jmp     TMPL_NM(bs3TestCallDoerPrologue)
+.doit:
+        mov     ax, [xBP + xCB + cbCurRetAddr]      ; Load far function pointer.
+        mov     dx, [xBP + xCB + cbCurRetAddr + 2]
 
         ; Mode switch, make the call, switch back.
@@ -721,9 +725,9 @@
 ; @cproto   BS3_DECL(uint8_t) Bs3TestCallDoerInPAE32(uint16_t offBs3Text16);
 ; @uses     rax
-BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPAE32
-        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
-        jmp     TMPL_NM(bs3TestCallDoerPrologue)
-.doit:
-        mov     eax, [xBP + xCB*2]      ; Load function pointer.
+BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPAE32, BS3_PBC_FAR
+        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
+        jmp     TMPL_NM(bs3TestCallDoerPrologue)
+.doit:
+        mov     eax, [xBP + xCB + cbCurRetAddr]      ; Load function pointer.
 
         ; Mode switch, make the call, switch back.
@@ -746,12 +750,12 @@
 ; @cproto   BS3_DECL(uint8_t) Bs3TestCallDoerInPAE32_16(uint16_t offBs3Text16);
 ; @uses     rax
-BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPAE32_16
-        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
-        jmp     TMPL_NM(bs3TestCallDoerPrologue)
-BS3_BEGIN_TEXT16
-BS3_SET_BITS TMPL_BITS
-.doit:
-        mov     ax, [xBP + xCB*2]       ; Load far function pointer.
-        mov     dx, [xBP + xCB*2 + 2]
+BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPAE32_16, BS3_PBC_FAR
+        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
+        jmp     TMPL_NM(bs3TestCallDoerPrologue)
+BS3_BEGIN_TEXT16
+BS3_SET_BITS TMPL_BITS
+.doit:
+        mov     ax, [xBP + xCB + cbCurRetAddr]      ; Load far function pointer.
+        mov     dx, [xBP + xCB + cbCurRetAddr + 2]
 
         ; Mode switch, make the call, switch back.
@@ -780,12 +784,12 @@
 ; @cproto   BS3_DECL(uint8_t) Bs3TestCallDoerInPAEV86(uint16_t offBs3Text16);
 ; @uses     rax
-BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPAEV86
-        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
-        jmp     TMPL_NM(bs3TestCallDoerPrologue)
-BS3_BEGIN_TEXT16
-BS3_SET_BITS TMPL_BITS
-.doit:
-        mov     ax, [xBP + xCB*2]       ; Load far function pointer.
-        mov     dx, [xBP + xCB*2 + 2]
+BS3_PROC_BEGIN_MODE Bs3TestCallDoerInPAEV86, BS3_PBC_FAR
+        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
+        jmp     TMPL_NM(bs3TestCallDoerPrologue)
+BS3_BEGIN_TEXT16
+BS3_SET_BITS TMPL_BITS
+.doit:
+        mov     ax, [xBP + xCB + cbCurRetAddr]      ; Load far function pointer.
+        mov     dx, [xBP + xCB + cbCurRetAddr + 2]
 
         ; Mode switch, make the call, switch back.
@@ -820,12 +824,12 @@
 ; @cproto   BS3_DECL(uint8_t) Bs3TestCallDoerInLM16(uint16_t offBs3Text16);
 ; @uses     rax
-BS3_PROC_BEGIN_MODE Bs3TestCallDoerInLM16
-        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
-        jmp     TMPL_NM(bs3TestCallDoerPrologue)
-BS3_BEGIN_TEXT16
-BS3_SET_BITS TMPL_BITS
-.doit:
-        mov     ax, [xBP + xCB*2]       ; Load far function pointer.
-        mov     dx, [xBP + xCB*2 + 2]
+BS3_PROC_BEGIN_MODE Bs3TestCallDoerInLM16, BS3_PBC_FAR
+        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
+        jmp     TMPL_NM(bs3TestCallDoerPrologue)
+BS3_BEGIN_TEXT16
+BS3_SET_BITS TMPL_BITS
+.doit:
+        mov     ax, [xBP + xCB + cbCurRetAddr]      ; Load far function pointer.
+        mov     dx, [xBP + xCB + cbCurRetAddr + 2]
 
         ; Mode switch, make the call, switch back.
@@ -854,9 +858,9 @@
 ; @cproto   BS3_DECL(uint8_t) Bs3TestCallDoerInLM32(uint16_t offBs3Text16);
 ; @uses     rax
-BS3_PROC_BEGIN_MODE Bs3TestCallDoerInLM32
-        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
-        jmp     TMPL_NM(bs3TestCallDoerPrologue)
-.doit:
-        mov     eax, [xBP + xCB*2]      ; Load function pointer.
+BS3_PROC_BEGIN_MODE Bs3TestCallDoerInLM32, BS3_PBC_FAR
+        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
+        jmp     TMPL_NM(bs3TestCallDoerPrologue)
+.doit:
+        mov     eax, [xBP + xCB + cbCurRetAddr]      ; Load function pointer.
 
         ; Mode switch, make the call, switch back.
@@ -880,9 +884,9 @@
 ; @cproto   BS3_DECL(uint8_t) Bs3TestCallDoerInLM64(uint16_t offBs3Text16);
 ; @uses     rax
-BS3_PROC_BEGIN_MODE Bs3TestCallDoerInLM64
-        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
-        jmp     TMPL_NM(bs3TestCallDoerPrologue)
-.doit:
-        mov     eax, [xBP + xCB*2]      ; Load function pointer.
+BS3_PROC_BEGIN_MODE Bs3TestCallDoerInLM64, BS3_PBC_FAR
+        BS3_LEA_MOV_WRT_RIP(xAX, .doit)
+        jmp     TMPL_NM(bs3TestCallDoerPrologue)
+.doit:
+        mov     eax, [xBP + xCB + cbCurRetAddr]      ; Load function pointer.
 
         ; Mode switch, make the call, switch back.
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TrapInit.c
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TrapInit.c	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TrapInit.c	(revision 60554)
@@ -32,5 +32,5 @@
 
 
-BS3_DECL(void) TMPL_NM(Bs3TrapInit)(void)
+BS3_MODE_DEF(void, Bs3TrapInit,(void))
 {
 #if BS3_MODE_IS_16BIT_SYS(TMPL_MODE)
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TrapSystemCallHandler.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TrapSystemCallHandler.asm	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-TrapSystemCallHandler.asm	(revision 60554)
@@ -67,5 +67,5 @@
 ;       CPUs too!
 ;
-BS3_PROC_BEGIN_MODE Bs3TrapSystemCallHandler
+BS3_PROC_BEGIN_MODE Bs3TrapSystemCallHandler, BS3_PBC_NEAR ; Near because we'll probably only ever need this from BS3TEXT16.
         ;
         ; This prologue is kind of complicated because of 80286 and older CPUs
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-define.h
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-define.h	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-define.h	(revision 60554)
@@ -64,4 +64,5 @@
 #define Bs3SelFar32ToFlat32                     BS3_CMN_MANGLER(Bs3SelFar32ToFlat32)
 #define Bs3SelProtFar32ToFlat32                 BS3_CMN_MANGLER(Bs3SelProtFar32ToFlat32)
+#define Bs3SelProtModeCodeToRealMode            BS3_CMN_MANGLER(Bs3SelProtModeCodeToRealMode)
 #define Bs3SelRealModeCodeToProtMode            BS3_CMN_MANGLER(Bs3SelRealModeCodeToProtMode)
 #define Bs3Shutdown                             BS3_CMN_MANGLER(Bs3Shutdown)
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-undef.h
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-undef.h	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-mangling-code-undef.h	(revision 60554)
@@ -64,4 +64,5 @@
 #undef Bs3SelFar32ToFlat32
 #undef Bs3SelProtFar32ToFlat32
+#undef Bs3SelProtModeCodeToRealMode
 #undef Bs3SelRealModeCodeToProtMode
 #undef Bs3Shutdown
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-template-footer.h
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-template-footer.h	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-template-footer.h	(revision 60554)
@@ -72,5 +72,5 @@
 
 #undef TMPL_NM
-#undef TMPL_NM_CMN
+#undef TMPL_FAR_NM
 #undef TMPL_MODE
 #undef TMPL_MODE_STR
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-template-footer.mac
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-template-footer.mac	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-template-footer.mac	(revision 60554)
@@ -83,4 +83,5 @@
 %undef TMPL_NM
 %undef TMPL_NM_U
+%undef TMPL_FAR_NM
 %undef BS3_CMN_NM
 %undef TMPL_UNDESCORE
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-template-header.h
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-template-header.h	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-template-header.h	(revision 60554)
@@ -107,6 +107,19 @@
  *
  * @param   Name        The function or variable name to mangle.
+ * @sa      #TMPL_FAR_NM, #BS3_CMN_NM, #BS3_CMN_FAR_NM
  */
 # define TMPL_NM(Name)  RT_CONCAT(Name,_mode)
+
+/** @def TMPL_FAR_NM
+ * Name mangling macro for the current mode into a far function name.
+ *
+ * In 32-bit and 64-bit code this does not differ from #TMPL_NM.
+ *
+ * Example: TMPL_FAR_NM(PrintChr)
+ *
+ * @param   Name        The function or variable name to mangle.
+ * @sa      #TMPL_NM, #BS3_CMN_FAR_NM, #BS3_CMN_NM
+ */
+# define TMPL_FAR_NM(Name)  RT_CONCAT3(Name,_mode,_far)
 
 /** @def TMPL_MODE_STR
@@ -473,4 +486,32 @@
 
 
+#if TMPL_MODE & (BS3_MODE_CODE_16 | BS3_MODE_CODE_V86)
+# define TMPL_FAR_NM(Name)      RT_CONCAT3(TMPL_NM(Name),_f,ar) /* _far and far may be #defined already. */
+#else
+# define TMPL_FAR_NM(Name)      TMPL_NM(Name)
+#endif
+
+
+/** @def BS3_MODE_DEF
+ * Macro for defining a mode specific function.
+ *
+ * This makes 16-bit mode functions far, while 32-bit and 64-bit are near.
+ * You need to update the make file to generate near->far wrappers in most
+ * cases.
+ *
+ * @param   a_RetType   The return type.
+ * @param   a_Name      The function basename.
+ * @param   a_Params    The parameter list (in parentheses).
+ *
+ * @sa      BS3_MODE_PROTO
+ */
+#if ARCH_BITS == 16
+# define BS3_MODE_DEF(a_RetType, a_Name, a_Params) BS3_DECL_FAR(a_RetType) TMPL_FAR_NM(a_Name) a_Params
+#else
+# define BS3_MODE_DEF(a_RetType, a_Name, a_Params) BS3_DECL_NEAR(a_RetType)    TMPL_NM(a_Name) a_Params
+#endif
+
+
+
 #ifndef TMPL_MODE_STR
 # error "internal error"
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-template-header.mac
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-template-header.mac	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit-template-header.mac	(revision 60554)
@@ -388,4 +388,11 @@
 %endif
 
+; TMPL_FAR_NM
+%if TMPL_MODE & (BS3_MODE_CODE_16 | BS3_MODE_CODE_V86)
+ %define TMPL_FAR_NM(Name)      TMPL_NM(Name) %+ _far
+%else
+ %define TMPL_FAR_NM(Name)      TMPL_NM(Name)
+%endif
+
 
 ;; @def TMPL_WRT_FLAT
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.h	(revision 60554)
@@ -1528,5 +1528,13 @@
  * @param   uRealSeg        Real mode code segment.
  */
-BS3_CMN_PROTO(uint16_t, Bs3SelRealModeCodeToProtMode,(uint16_t uRealSel), false);
+BS3_CMN_PROTO(uint16_t, Bs3SelRealModeCodeToProtMode,(uint16_t uRealSeg), false);
+
+/**
+ * Converts a real mode code segment to a protected mode code segment selector.
+ *
+ * @returns protected mode segment selector.
+ * @param   uProtSel        Real mode code segment.
+ */
+BS3_CMN_PROTO(uint16_t, Bs3SelProtModeCodeToRealMode,(uint16_t uProtSel), false);
 
 /**
@@ -2520,33 +2528,52 @@
 
 
-/**
+/** @def BS3_MODE_PROTO
  * Macro for reducing typing.
  *
  * Doxygen knows how to expand this, well, kind of.
- */
-#define BS3_MODE_EXPAND_PROTOTYPES(a_RetType, a_BaseFnNm, a_Parameters) \
-    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_BaseFnNm,_rm)       a_Parameters; \
-    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_BaseFnNm,_rm_far)   a_Parameters; \
-    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_BaseFnNm,_pe16)     a_Parameters; \
-    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_BaseFnNm,_pe16_32)  a_Parameters; \
-    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_BaseFnNm,_pe16_v86) a_Parameters; \
-    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_BaseFnNm,_pe32)     a_Parameters; \
-    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_BaseFnNm,_pe32_16)  a_Parameters; \
-    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_BaseFnNm,_pev86)    a_Parameters; \
-    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_BaseFnNm,_pp16)     a_Parameters; \
-    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_BaseFnNm,_pp16_32)  a_Parameters; \
-    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_BaseFnNm,_pp16_v86) a_Parameters; \
-    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_BaseFnNm,_pp32)     a_Parameters; \
-    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_BaseFnNm,_pp32_16)  a_Parameters; \
-    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_BaseFnNm,_ppv86)    a_Parameters; \
-    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_BaseFnNm,_pae16)    a_Parameters; \
-    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_BaseFnNm,_pae16_32) a_Parameters; \
-    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_BaseFnNm,_pae16_v86)a_Parameters; \
-    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_BaseFnNm,_pae32)    a_Parameters; \
-    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_BaseFnNm,_pae32_16) a_Parameters; \
-    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_BaseFnNm,_paev86)   a_Parameters; \
-    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_BaseFnNm,_lm16)     a_Parameters; \
-    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_BaseFnNm,_lm32)     a_Parameters; \
-    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_BaseFnNm,_lm64)     a_Parameters
+ *
+ * @param   a_RetType   The return type.
+ * @param   a_Name      The function basename.
+ * @param   a_Params    The parameter list (in parentheses).
+ * @param   a_fAutoStub Whether to autogenerate a 16-bit near -> 16-bit far stub
+ *                      function. Either 'true' for stub or 'false' for no stub.
+ */
+#define BS3_MODE_PROTO(a_RetType, a_Name, a_Params, a_fAutoStub) \
+    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_rm)           a_Params; \
+    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pe16)         a_Params; \
+    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pe16_32)      a_Params; \
+    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pe16_v86)     a_Params; \
+    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pe32)         a_Params; \
+    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pe32_16)      a_Params; \
+    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pev86)        a_Params; \
+    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pp16)         a_Params; \
+    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pp16_32)      a_Params; \
+    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pp16_v86)     a_Params; \
+    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pp32)         a_Params; \
+    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pp32_16)      a_Params; \
+    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_ppv86)        a_Params; \
+    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pae16)        a_Params; \
+    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pae16_32)     a_Params; \
+    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pae16_v86)    a_Params; \
+    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pae32)        a_Params; \
+    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_pae32_16)     a_Params; \
+    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_paev86)       a_Params; \
+    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_lm16)         a_Params; \
+    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_lm32)         a_Params; \
+    BS3_DECL_NEAR(a_RetType) RT_CONCAT(a_Name,_lm64)         a_Params; \
+    BS3_DECL_FAR(a_RetType)  RT_CONCAT(a_Name,_rm_far)       a_Params; \
+    BS3_DECL_FAR(a_RetType)  RT_CONCAT(a_Name,_pe16_far)     a_Params; \
+    BS3_DECL_FAR(a_RetType)  RT_CONCAT(a_Name,_pe16_v86_far) a_Params; \
+    BS3_DECL_FAR(a_RetType)  RT_CONCAT(a_Name,_pe32_16_far)  a_Params; \
+    BS3_DECL_FAR(a_RetType)  RT_CONCAT(a_Name,_pev86_far)    a_Params; \
+    BS3_DECL_FAR(a_RetType)  RT_CONCAT(a_Name,_pp16_far)     a_Params; \
+    BS3_DECL_FAR(a_RetType)  RT_CONCAT(a_Name,_pp16_v86_far) a_Params; \
+    BS3_DECL_FAR(a_RetType)  RT_CONCAT(a_Name,_pp32_16_far)  a_Params; \
+    BS3_DECL_FAR(a_RetType)  RT_CONCAT(a_Name,_ppv86_far)    a_Params; \
+    BS3_DECL_FAR(a_RetType)  RT_CONCAT(a_Name,_pae16_far)    a_Params; \
+    BS3_DECL_FAR(a_RetType)  RT_CONCAT(a_Name,_pae16_v86_far)a_Params; \
+    BS3_DECL_FAR(a_RetType)  RT_CONCAT(a_Name,_pae32_16_far) a_Params; \
+    BS3_DECL_FAR(a_RetType)  RT_CONCAT(a_Name,_paev86_far)   a_Params; \
+    BS3_DECL_FAR(a_RetType)  RT_CONCAT(a_Name,_lm16_far)     a_Params
 
 /**
@@ -2597,5 +2624,5 @@
  *          capabilities.
  */
-BS3_MODE_EXPAND_PROTOTYPES(uint8_t, Bs3CpuDetect,(void));
+BS3_MODE_PROTO(uint8_t, Bs3CpuDetect,(void), false);
 
 /** @name BS3CPU_XXX - CPU detected by BS3CpuDetect_c16() and friends.
@@ -2633,5 +2660,5 @@
  * Calls the appropriate Bs3Trap16Init, Bs3Trap32Init or Bs3Trap64Init function.
  */
-BS3_MODE_EXPAND_PROTOTYPES(void, Bs3TrapInit,(void));
+BS3_MODE_PROTO(void, Bs3TrapInit,(void), true);
 
 /**
@@ -2641,5 +2668,5 @@
  * @param   cEntries        The number of sub-test entries.
  */
-BS3_MODE_EXPAND_PROTOTYPES(void, Bs3TestDoModes, (PCBS3TESTMODEENTRY paEntries, size_t cEntries));
+BS3_MODE_PROTO(void, Bs3TestDoModes,(PCBS3TESTMODEENTRY paEntries, size_t cEntries), true);
 
 
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.mac
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.mac	(revision 60553)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.mac	(revision 60554)
@@ -680,115 +680,107 @@
 
 
-;; @name BS3_PBC_XXX - For use as the 2nd parameter to BS3_PROC_BEGIN_CMN.
+;; @name BS3_PBC_XXX - For use as the 2nd parameter to BS3_PROC_BEGIN_CMN and BS3_PROC_BEGIN_MODE.
 ;; @{
-%define BS3_PBC_NEAR          0 ;;< Only near.
-%define BS3_PBC_FAR           1 ;;< Only far.
-%define BS3_PBC_HYBRID        2 ;;< Hybrid near/far procedure, trashing AX
-%define BS3_PBC_HYBRID_SAFE   3 ;;< Hybrid near/far procedure, no trashing but slower.
-%define BS3_PBC_HYBRID_0_ARGS 4 ;;< Hybrid near/far procedure, no parameters so separate far stub, no trashing, fast near calls.
+%define BS3_PBC_NEAR          1 ;;< Only near.
+%define BS3_PBC_FAR           2 ;;< Only far.
+%define BS3_PBC_HYBRID        3 ;;< Hybrid near/far procedure, trashing AX
+%define BS3_PBC_HYBRID_SAFE   4 ;;< Hybrid near/far procedure, no trashing but slower.
+%define BS3_PBC_HYBRID_0_ARGS 5 ;;< Hybrid near/far procedure, no parameters so separate far stub, no trashing, fast near calls.
 ;; @}
+
+;; Internal begin procedure macro.
+;
+; @param    1       The near name.
+; @param    2       The far name
+; @param    3       BS3_PBC_XXX.
+%macro BS3_PROC_BEGIN_INT 3
+ ;%warning "BS3_PROC_BEGIN_INT:" 1=%1 2=%2 3=%3
+ %undef BS3_CUR_PROC_FLAGS
+ %if __BITS__ == 16
+  %if %3 == BS3_PBC_NEAR
+   %xdefine BS3_CUR_PROC_FLAGS  BS3_PBC_NEAR
+   %xdefine cbCurRetAddr        2
+   BS3_PROC_BEGIN       %1
+
+  %elif %3 == BS3_PBC_FAR
+   %xdefine BS3_CUR_PROC_FLAGS  BS3_PBC_FAR
+   %xdefine cbCurRetAddr        4
+   BS3_PROC_BEGIN       %2
+
+  %elif %3 == BS3_PBC_HYBRID
+   %xdefine BS3_CUR_PROC_FLAGS  BS3_PBC_HYBRID
+   %xdefine cbCurRetAddr        4
+   BS3_GLOBAL_NAME_EX   %1, function, 3
+        pop     ax
+        push    cs
+        push    ax
+   BS3_PROC_BEGIN       %2
+
+  %elif %3 == BS3_PBC_HYBRID_SAFE
+   %xdefine BS3_CUR_PROC_FLAGS  BS3_PBC_HYBRID_SAFE
+   %xdefine cbCurRetAddr        4
+   BS3_GLOBAL_NAME_EX   %1, function, 3
+        extern  Bs3CreateHybridFarRet_c16
+        call    Bs3CreateHybridFarRet_c16
+   BS3_PROC_BEGIN       %2
+
+  %elif %3 == BS3_PBC_HYBRID_0_ARGS
+   %xdefine BS3_CUR_PROC_FLAGS  BS3_PBC_NEAR
+   %xdefine cbCurRetAddr        2
+   %xdefine TMP_BEGIN_PREV_SEG  BS3_CUR_SEG_BEGIN_MACRO
+
+   BS3_BEGIN_TEXT16_FARSTUBS
+   BS3_PROC_BEGIN       %2
+        call    %1
+        retf
+   BS3_PROC_END         %2
+
+   TMP_BEGIN_PREV_SEG
+   BS3_PROC_BEGIN       %1
+   %undef  TMP_BEGIN_PREV_SEG
+
+  %else
+   %error BS3_PROC_BEGIN_CMN parameter 2 value %3 is not recognized.
+
+   %xdefine BS3_CUR_PROC_FLAGS   BS3_PBC_NEAR
+   %xdefine cbCurRetAddr         4
+   BS3_PROC_BEGIN       %1
+  %endif
+ %else
+  %xdefine BS3_CUR_PROC_FLAGS   BS3_PBC_NEAR
+  %xdefine cbCurRetAddr         xCB
+  BS3_PROC_BEGIN        %1
+ %endif
+%endmacro
+
+;; Internal end procedure macro
+;
+; @param    1       The near name.
+; @param    2       The far name
+;
+%macro BS3_PROC_END_INT 2
+ %if __BITS__ == 16
+  %if BS3_CUR_PROC_FLAGS == BS3_PBC_NEAR
+   BS3_PROC_END      %1
+  %else
+   BS3_PROC_END      %2
+  %endif
+ %else
+  BS3_PROC_END       %1
+ %endif
+ %undef BS3_CUR_PROC_FLAGS
+ %undef cbCurRetAddr
+%endmacro
+
 
 ;; Convenience macro for defining common procedures.
 ; This will emit both near and far 16-bit symbols according to parameter %2 (BS3_PBC_XXX).
 %macro BS3_PROC_BEGIN_CMN 2
- %undef BS3_CUR_PROC_FLAGS
- %if __BITS__ == 16
-  %if %2 == BS3_PBC_NEAR
-   %define BS3_CUR_PROC_FLAGS   BS3_PBC_NEAR
-   %xdefine cbCurRetAddr        2
-   BS3_PROC_BEGIN       BS3_CMN_NM(%1)
-
-  %elif %2 == BS3_PBC_FAR
-   %define BS3_CUR_PROC_FLAGS   BS3_PBC_FAR
-   %xdefine cbCurRetAddr        4
-   BS3_PROC_BEGIN       BS3_CMN_NM_FAR(%1)
-
-  %elif %2 == BS3_PBC_HYBRID
-   %define BS3_CUR_PROC_FLAGS   BS3_PBC_HYBRID
-   %xdefine cbCurRetAddr        4
-   BS3_GLOBAL_NAME_EX   BS3_CMN_NM(%1), function, 3
-        pop     ax
-        push    cs
-        push    ax
-   BS3_PROC_BEGIN       BS3_CMN_NM_FAR(%1)
-
-  %elif %2 == BS3_PBC_HYBRID_SAFE
-   %define BS3_CUR_PROC_FLAGS   BS3_PBC_HYBRID_SAFE
-   %xdefine cbCurRetAddr        4
-   BS3_GLOBAL_NAME_EX   BS3_CMN_NM(%1), function, 3
-        extern  Bs3CreateHybridFarRet_c16
-        call    Bs3CreateHybridFarRet_c16
-   BS3_PROC_BEGIN       BS3_CMN_NM_FAR(%1)
-
-  %elif %2 == BS3_PBC_HYBRID_0_ARGS
-   %define BS3_CUR_PROC_FLAGS   BS3_PBC_NEAR
-   %xdefine cbCurRetAddr        2
-   %undef  TMP_BEGIN_PREV_SEG
-   %xdefine TMP_BEGIN_PREV_SEG   BS3_CUR_SEG_BEGIN_MACRO
-
-   BS3_BEGIN_TEXT16_FARSTUBS
-   BS3_PROC_BEGIN       BS3_CMN_NM_FAR(%1)
-        call    BS3_CMN_NM(%1)
-        retf
-   BS3_PROC_END         BS3_CMN_NM_FAR(%1)
-
-   TMP_BEGIN_PREV_SEG
-   BS3_PROC_BEGIN       BS3_CMN_NM(%1)
-
-  %else
-   %error BS3_PROC_BEGIN_CMN parameter 2 value %2 is not recognized.
-
-   %define BS3_CUR_PROC_FLAGS    BS3_PBC_NEAR
-   %xdefine cbCurRetAddr         4
-   BS3_PROC_BEGIN       BS3_CMN_NM(%1)
-  %endif
- %else
-  %define BS3_CUR_PROC_FLAGS    BS3_PBC_NEAR
-  %xdefine cbCurRetAddr         xCB
-  BS3_PROC_BEGIN        BS3_CMN_NM(%1)
- %endif
+ BS3_PROC_BEGIN_INT BS3_CMN_NM(%1), BS3_CMN_NM_FAR(%1), %2
 %endmacro
 
 ;; Convenience macro for defining common procedures.
 %macro BS3_PROC_END_CMN 1
- %if __BITS__ == 16
-  %if BS3_CUR_PROC_FLAGS == BS3_PBC_NEAR
-   BS3_PROC_END      BS3_CMN_NM(%1)
-  %else
-   BS3_PROC_END      BS3_CMN_NM_FAR(%1)
-  %endif
- %else
-  BS3_PROC_END       BS3_CMN_NM(%1)
- %endif
- %undef cbCurRetAddr
-%endmacro
-
-;; Does a far return in 16-bit code, near return in 32-bit and 64-bit.
-; This is for use with BS3_PBC_XXX
-%macro BS3_HYBRID_RET 0-1
- %if __BITS__ == 16
-  %if %0 > 0
-   %if BS3_CUR_PROC_FLAGS == BS3_PBC_NEAR || BS3_CUR_PROC_FLAGS == BS3_PBC_HYBRID_0_ARGS
-        ret    %1
-   %else
-        retf    %1
-   %endif
-  %else
-   %if BS3_CUR_PROC_FLAGS == BS3_PBC_NEAR || BS3_CUR_PROC_FLAGS == BS3_PBC_HYBRID_0_ARGS
-        ret
-   %else
-        retf
-   %endif
-  %endif
- %else
-  %if BS3_CUR_PROC_FLAGS != BS3_PBC_NEAR
-   %error Expected BS3_CUR_PROC_FLAGS to be BS3_PBC_NEAR in non-16-bit code.
-  %endif
-  %if %0 > 0
-        ret     %1
-  %else
-        ret
-  %endif
- %endif
+ BS3_PROC_END_INT BS3_CMN_NM(%1), BS3_CMN_NM_FAR(%1)
 %endmacro
 
@@ -828,12 +820,43 @@
 %endmacro
 
+
 ;; Convenience macro for defining mode specific procedures.
-%macro BS3_PROC_BEGIN_MODE 1
- BS3_PROC_BEGIN     TMPL_NM(%1)
+%macro BS3_PROC_BEGIN_MODE 2
+ ;%warning "BS3_PROC_BEGIN_MODE: 1=" %1 "2=" %2
+ BS3_PROC_BEGIN_INT TMPL_NM(%1), TMPL_FAR_NM(%1), %2
 %endmacro
 
 ;; Convenience macro for defining mode specific procedures.
 %macro BS3_PROC_END_MODE 1
- BS3_PROC_END       TMPL_NM(%1)
+ BS3_PROC_END_INT TMPL_NM(%1), TMPL_FAR_NM(%1)
+%endmacro
+
+;; Does a far return in 16-bit code, near return in 32-bit and 64-bit.
+; This is for use with BS3_PBC_XXX
+%macro BS3_HYBRID_RET 0-1
+ %if __BITS__ == 16
+  %if %0 > 0
+   %if BS3_CUR_PROC_FLAGS == BS3_PBC_NEAR || BS3_CUR_PROC_FLAGS == BS3_PBC_HYBRID_0_ARGS
+        ret    %1
+   %else
+        retf    %1
+   %endif
+  %else
+   %if BS3_CUR_PROC_FLAGS == BS3_PBC_NEAR || BS3_CUR_PROC_FLAGS == BS3_PBC_HYBRID_0_ARGS
+        ret
+   %else
+        retf
+   %endif
+  %endif
+ %else
+  %if BS3_CUR_PROC_FLAGS != BS3_PBC_NEAR
+   %error Expected BS3_CUR_PROC_FLAGS to be BS3_PBC_NEAR in non-16-bit code.
+  %endif
+  %if %0 > 0
+        ret     %1
+  %else
+        ret
+  %endif
+ %endif
 %endmacro
 
