Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk	(revision 59884)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk	(revision 59885)
@@ -193,4 +193,6 @@
 	bs3-mode-SwitchToRM.asm \
 	bs3-mode-SwitchToPE16.asm \
+	bs3-mode-SwitchToPE16_32.asm \
+	bs3-mode-SwitchToPE16_V86.asm \
 	bs3-mode-SwitchToPE32.asm \
 	bs3-mode-SwitchToPP16.asm \
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchTo16Bit.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchTo16Bit.asm	(revision 59884)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchTo16Bit.asm	(revision 59885)
@@ -27,8 +27,6 @@
 %include "bs3kit-template-header.mac"
 
-%if TMPL_BITS != 16
 BS3_EXTERN_DATA16 g_bBs3CurrentMode
 TMPL_BEGIN_TEXT
-%endif
 
 
@@ -39,5 +37,24 @@
 BS3_PROC_BEGIN_CMN Bs3SwitchTo16Bit
 %if TMPL_BITS == 16
+        push    ax
+        push    ds
+
+        ; Check g_bBs3CurrentMode whether we're in v8086 mode or not.
+        mov     ax, seg g_bBs3CurrentMode
+        mov     ds, ax
+        mov     al, [g_bBs3CurrentMode]
+        and     al, BS3_MODE_CODE_MASK
+        cmp     al, BS3_MODE_CODE_V86
+        jne     .ret_16bit
+
+        ; Switch to ring-0 if v8086 mode.
+        mov     ax, BS3_SYSCALL_TO_RING0
+        int     BS3_TRAP_SYSCALL
+
+.ret_16bit:
+        pop     ds
+        pop     ax
         ret
+
 %else
         push    xAX
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchTo32Bit.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchTo32Bit.asm	(revision 59884)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchTo32Bit.asm	(revision 59885)
@@ -53,4 +53,21 @@
         cli
 
+%if TMPL_BITS == 16
+        ; Check for v8086 mode, we need to exit it to enter 32-bit mode.
+        mov     ax, seg g_bBs3CurrentMode
+        mov     ds, ax
+        mov     al, [g_bBs3CurrentMode]
+        and     al, BS3_MODE_CODE_MASK
+        cmp     al, BS3_MODE_CODE_V86
+        jne     .not_v8086
+
+        mov     ax, BS3_SYSCALL_TO_RING0
+        int     BS3_TRAP_SYSCALL
+
+        mov     xAX, BS3_SEL_R0_CS32
+        jmp     .do_far_jump
+%endif
+
+.not_v8086:
         ; Calc ring addend.
         mov     ax, cs
@@ -60,4 +77,5 @@
 
         ; Create far return for switching to 32-bit mode.
+.do_far_jump:
         push    sAX
  %if TMPL_BITS == 16
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchTo64Bit.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchTo64Bit.asm	(revision 59884)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchTo64Bit.asm	(revision 59885)
@@ -41,4 +41,9 @@
 %if TMPL_BITS == 64
         ret
+
+%elif BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+.again: int3                            ; Makes no sense to go to 64-bit mode from real or v8086 mode.
+        jmp     .again
+
 %else
  %if TMPL_BITS == 16
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchToV86.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchToV86.asm	(revision 59885)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-SwitchToV86.asm	(revision 59885)
@@ -0,0 +1,96 @@
+; $Id$
+;; @file
+; BS3Kit - Bs3SwitchTo16Bit
+;
+
+;
+; 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_DATA16 g_bBs3CurrentMode
+TMPL_BEGIN_TEXT
+%endif
+
+
+;;
+; @cproto   BS3_DECL(void) Bs3SwitchTo16Bit(void);
+; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
+;
+BS3_PROC_BEGIN_CMN Bs3SwitchTo16Bit
+%if BS3_MODE_IS_16BIT_CODE_NO_V86(TMPL_MODE)
+        ret
+%else
+        push    xAX
+        xPUSHF
+        cli
+
+%if BS3_MODE_IS_V86(TMPL_MODE)
+        ; Switch to ring-0 if v8086 mode.
+        mov     ax, BS3_SYSCALL_TO_RING0
+        int     BS3_TRAP_SYSCALL
+%endif
+
+        ; Calc new CS.
+%if BS3_MODE_IS_RM_OR_V86(TMPL_MODE)
+        mov     xAX, BS3_SEL_R0_CS16
+%else
+        mov     ax, cs
+        and     xAX, 3
+        shl     xAX, BS3_SEL_RING_SHIFT  ; ring addend.
+        add     xAX, BS3_SEL_R0_CS16
+%endif
+
+        ; Construct a far return for switching to 16-bit code.
+        push    xAX
+        push    .sixteen_bit
+        xRETF
+
+BS3_BEGIN_TEXT16
+.sixteen_bit:
+
+        ; Load 16-bit segment registers.
+        ;; @todo support non-standard stacks?
+        add     ax, BS3_SEL_R0_SS16 - BS3_SEL_R0_CS16
+        mov     ss, ax
+
+        add     ax, BS3_SEL_R0_DS16 - BS3_SEL_R0_SS16
+        mov     ds, ax
+        mov     es, ax
+
+        ; Update globals.
+        and     byte [g_bBs3CurrentMode], ~BS3_MODE_CODE_MASK
+        or      byte [g_bBs3CurrentMode], BS3_MODE_CODE_16
+
+        popfd
+ %if TMPL_BITS == 64
+        add     sp, 4
+ %endif
+        pop     eax
+ %if TMPL_BITS == 64
+        add     sp, 4
+ %endif
+        ret     sCB - 2                 ; Return and pop 2 or 6 bytes of "parameters" (unused return value)
+TMPL_BEGIN_TEXT
+%endif
+BS3_PROC_END_CMN   Bs3SwitchTo16Bit
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE16_32.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE16_32.asm	(revision 59885)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE16_32.asm	(revision 59885)
@@ -0,0 +1,78 @@
+; $Id$
+;; @file
+; BS3Kit - Bs3SwitchToPE16_32
+;
+
+;
+; 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"
+
+
+;;
+; Switch to 32-bit code under 16-bit unpaged protected mode sys/tss from any other mode.
+;
+; @cproto   BS3_DECL(void) Bs3SwitchToPE16_32(void);
+;
+; @uses     Nothing (except high 32-bit register parts).
+;
+; @remarks  Obviously returns to 32-bit mode, even if the caller was
+;           in 16-bit or 64-bit mode.
+;
+; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
+;
+BS3_PROC_BEGIN_MODE Bs3SwitchToPE16_32
+%ifdef TMPL_PE16_32
+        ret
+
+%else
+        ;
+        ; Make sure we're the 16-bit segment and then call Bs3SwitchToPE16.
+        ;
+ %if TMPL_BITS != 16
+        jmp     .sixteen_bit_segment
+BS3_BEGIN_TEXT16
+        BS3_SET_BITS TMPL_BITS
+.sixteen_bit_segment:
+ %endif
+        extern  TMPL_NM(Bs3SwitchToPE16)
+        call    TMPL_NM(Bs3SwitchToPE16)
+        BS3_SET_BITS 16
+
+        ;
+        ; Switch to 32-bit mode.
+        ;
+        extern  TMPL_NM(Bs3SwitchTo32Bit)
+        call    TMPL_NM(Bs3SwitchTo32Bit)
+        BS3_SET_BITS 32
+
+        ;
+        ; Fix the return address and return.
+        ;
+ %if TMPL_BITS == 16
+        push    word [esp]
+ %elif TMPL_BITS == 64
+        pop     dword [esp + 4]
+ %endif
+        ret
+%endif
+BS3_PROC_END_MODE   Bs3SwitchToPE16_32
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE16_V86.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE16_V86.asm	(revision 59885)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-mode-SwitchToPE16_V86.asm	(revision 59885)
@@ -0,0 +1,67 @@
+; $Id$
+;; @file
+; BS3Kit - Bs3SwitchToPE16_V86
+;
+
+;
+; 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"
+
+
+;;
+; Switch to 16-bit unpaged protected mode from any other mode.
+;
+; @cproto   BS3_DECL(void) Bs3SwitchToPE16(void);
+;
+; @uses     Nothing (except high 32-bit register parts).
+;
+; @remarks  Obviously returns to 16-bit mode, even if the caller was
+;           in 32-bit or 64-bit mode.
+;
+; @remarks  Does not require 20h of parameter scratch space in 64-bit mode.
+;
+BS3_PROC_BEGIN_MODE Bs3SwitchToPE16_V86
+%ifdef TMPL_PE16_V86
+        ret
+
+%else
+        ;
+        ; Make sure we're the 16-bit segment and then call Bs3SwitchToPE16.
+        ;
+ %if TMPL_BITS != 16
+        jmp     .sixteen_bit_segment
+BS3_BEGIN_TEXT16
+        BS3_SET_BITS TMPL_BITS
+.sixteen_bit_segment:
+ %endif
+        extern  TMPL_NM(Bs3SwitchToPE16)
+        call    TMPL_NM(Bs3SwitchToPE16)
+        BS3_SET_BITS 16
+
+        ;
+        ; Switch to v8086 mode.
+        ;
+        extern  TMPL_NM(Bs3SwitchToV86)
+        jmp     TMPL_NM(Bs3SwitchToV86)
+%endif
+BS3_PROC_END_MODE   Bs3SwitchToPE16_V86
+
