Index: /trunk/src/VBox/ValidationKit/bootsectors/Makefile.kmk
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/Makefile.kmk	(revision 58592)
+++ /trunk/src/VBox/ValidationKit/bootsectors/Makefile.kmk	(revision 58593)
@@ -187,122 +187,4 @@
 
 
-ifeq ($(USER),bird) # work in progress.
-
-#
-# BS3Kit
-#
-
-# Dummy CP "linker" tool.
-TOOL_VBoxBsCpLd = Dummy copy linker.
-TOOL_VBoxBsCpLd_LINK_MISCBIN_OUTPUT =
-TOOL_VBoxBsCpLd_LINK_MISCBIN_DEPEND =
-TOOL_VBoxBsCpLd_LINK_MISCBIN_DEPORD =
-define TOOL_VBoxBsCpLd_LINK_MISCBIN_CMDS
-	$(CP) -- $(objs) $(othersrc) "$(out)"
-endef
-
-# Dummy exit 1 "linker" tool.
-TOOL_VBoxBsUnusedLd = Dummy unused linker.
-TOOL_VBoxBsUnusedLd_LINK_MISCBIN_OUTPUT =
-TOOL_VBoxBsUnusedLd_LINK_MISCBIN_DEPEND =
-TOOL_VBoxBsUnusedLd_LINK_MISCBIN_DEPORD =
-define TOOL_VBoxBsUnusedLd_LINK_MISCBIN_CMDS
-	echo "cannot use this template for linking"
-	exit 1
-endef
-
-# BS3Kit template for assembly and 16-bit code.
-TEMPLATE_VBoxBS3KitImg = Template for building BS3Kit test images.
-TEMPLATE_VBoxBS3KitImg_INST     = $(INST_VALIDATIONKIT)bootsectors/
-TEMPLATE_VBoxBS3KitImg_BINSUFF  = .img
-TEMPLATE_VBoxBS3KitImg_MODE     = 0644
-TEMPLATE_VBoxBS3KitImg_ASTOOL   = NASM
-TEMPLATE_VBoxBS3KitImg_ASFLAGS := -f obj -g -w+orphan-labels #-P $(PATH_SUB_CURRENT)/bootsector2-first.mac
-TEMPLATE_VBoxBS3KitImg_ASDEFS   = ASM_FORMAT_OMF __NASM__
-TEMPLATE_VBoxBS3KitImg_ARTOOL   = OPENWATCOM-16
-TEMPLATE_VBoxBS3KitImg_CTOOL    = OPENWATCOM-16
-TEMPLATE_VBoxBS3KitImg_CXXTOOL  = OPENWATCOM-16
-TEMPLATE_VBoxBS3KitImg_CFLAGS   = -nt=TEXT16 -nd=DATA16 -nc=CODE16
-TEMPLATE_VBoxBS3KitImg_CXXFLAGS = -nt=TEXT16 -nd=DATA16 -nc=CODE16
-TEMPLATE_VBoxBS3KitImg_INCS     = bs3kit .
-TEMPLATE_VBoxBS3KitImg_LDTOOL   = OPENWATCOM-WL
-TEMPLATE_VBoxBS3KitImg_LDFLAGS  = \
- 	output raw offset=0x10000 \
- 	order \
- 	 clname CODE16 \
- 	  segment TEXT16  segaddr=0x1000 \
- 	 clname DATA16 \
- 	  segment DATA16  segaddr=0x1000 \
-        clname CODE32 \
- 	  segment TEXT32 \
-        clname DATA32 \
- 	  segment DATA32
-
-# BS3Kit template for 32-bit code.
-TEMPLATE_VBoxBS3KitImg32 = Template for building BS3Kit test images.
-TEMPLATE_VBoxBS3KitImg32_INSTTYPE = none
-TEMPLATE_VBoxBS3KitImg32_ASTOOL   = NASM
-TEMPLATE_VBoxBS3KitImg32_ASFLAGS := -f obj -g -w+orphan-labels #-P $(PATH_SUB_CURRENT)/bootsector2-first.mac
-TEMPLATE_VBoxBS3KitImg32_ASDEFS   = ASM_FORMAT_OMF __NASM__
-TEMPLATE_VBoxBS3KitImg32_ARTOOL   = OPENWATCOM
-TEMPLATE_VBoxBS3KitImg32_CTOOL    = OPENWATCOM
-TEMPLATE_VBoxBS3KitImg32_CXXTOOL  = OPENWATCOM
-TEMPLATE_VBoxBS3KitImg32_CFLAGS   = -nt=TEXT32 -nd=DATA32 -nc=CODE32
-TEMPLATE_VBoxBS3KitImg32_CXXFLAGS = -nt=TEXT32 -nd=DATA32 -nc=CODE32
-TEMPLATE_VBoxBS3KitImg32_INCS     = bs3kit .
-TEMPLATE_VBoxBS3KitImg32_LDTOOL   = VBoxBsUnusedLd
-
-# BS3Kit template for 64-bit code.
-TEMPLATE_VBoxBS3KitImg64 = Template for building BS3Kit test images.
-TEMPLATE_VBoxBS3KitImg64_INSTTYPE = none
-TEMPLATE_VBoxBS3KitImg64_ASTOOL   = NASM
-TEMPLATE_VBoxBS3KitImg64_ASFLAGS := -f elf64 -g -w+orphan-labels #-P $(PATH_SUB_CURRENT)/bootsector2-first.mac
-TEMPLATE_VBoxBS3KitImg64_ASDEFS   = ASM_FORMAT_ELF __NASM__ TMPL
-TEMPLATE_VBoxBS3KitImg64_ARTOOL   = OPENWATCOM
-TEMPLATE_VBoxBS3KitImg64_CTOOL    = DUMMY
-TEMPLATE_VBoxBS3KitImg64_CXXTOOL  = DUMMY
-TEMPLATE_VBoxBS3KitImg64_INCS     = bs3kit .
-TEMPLATE_VBoxBS3KitImg64_LDTOOL   = VBoxBsUnusedLd
-
-# BS3Kit template for the bootsector.
-TEMPLATE_VBoxBS3KitBS = Template for building BS3Kit test images.
-TEMPLATE_VBoxBS3KitBS_INST     = $(INST_VALIDATIONKIT)bootsectors/
-TEMPLATE_VBoxBS3KitBS_INSTTYPE = none
-TEMPLATE_VBoxBS3KitBS_BINSUFF  = .img
-TEMPLATE_VBoxBS3KitBS_MODE     = 0644
-TEMPLATE_VBoxBS3KitBS_ASTOOL   = YASM
-TEMPLATE_VBoxBS3KitBS_ASFLAGS := -f bin --mapfile
-TEMPLATE_VBoxBS3KitBS_ASDEFS   = ASM_FORMAT_BIN __YASM__
-TEMPLATE_VBoxBS3KitBS_INCS     = bs3kit
-TEMPLATE_VBoxBS3KitBS_LDTOOL   = VBoxBsCpLd
-
-# The boot sector.
-MISCBINS += bs3-bootsector
-bs3-bootsector_TEMPLATE = VBoxBS3KitBS
-bs3-bootsector_SOURCES  = bs3kit/bs3-bootsector.asm
-
-# The BS3Kit library.
-LIBRARIES += bs3kit-common-16
-bs3kit-common-16_TEMPLATE = VBoxBS3KitImg
-bs3kit-common-16_DEFS     = TMPL_PE16 BS3_CMN_ONLY
-bs3kit-common-16_SOURCES  = \
-	bs3kit/bs3-shutdown.asm
-
-# The 32-bit BS3Kit library.
-LIBRARIES += bs3kit-common-32
-bs3kit-common-32_TEMPLATE = VBoxBS3KitImg32
-bs3kit-common-32_DEFS     = TMPL_PE32 BS3_CMN_ONLY
-bs3kit-common-32_SOURCES  = \
-	bs3kit/bs3-shutdown.asm
-
-# The 64-bit BS3Kit library.
-LIBRARIES += bs3kit-common-64
-bs3kit-common-64_TEMPLATE = VBoxBS3KitImg64
-bs3kit-common-64_DEFS     = TMPL_LM64 BS3_CMN_ONLY
-bs3kit-common-64_SOURCES  = \
-	bs3kit/bs3-shutdown.asm
-
-endif # experimental
-
 include $(FILE_KBUILD_SUB_FOOTER)
 
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk	(revision 58593)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/Makefile.kmk	(revision 58593)
@@ -0,0 +1,178 @@
+# $Id$
+## @file
+# VirtualBox Validation Kit - Bootsector Kit v3
+#
+
+#
+# Copyright (C) 2006-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.
+#
+
+SUB_DEPTH = ../../../../..
+include $(KBUILD_PATH)/subheader.kmk
+
+
+#
+# ----- Config.kmk: start -----
+#
+
+# The bs3kit source directory.
+VBOX_PATH_BS3KIT_SRC = $(VBOX_PATH_VALIDATIONKIT_SRC)/bootsectors/bs3kit
+
+# Dummy CP "linker" tool.
+TOOL_VBoxBsCpLd = Dummy copy linker.
+TOOL_VBoxBsCpLd_LINK_MISCBIN_OUTPUT =
+TOOL_VBoxBsCpLd_LINK_MISCBIN_DEPEND =
+TOOL_VBoxBsCpLd_LINK_MISCBIN_DEPORD =
+define TOOL_VBoxBsCpLd_LINK_MISCBIN_CMDS
+	$(CP) -- $(objs) $(othersrc) "$(out)"
+endef
+
+# Dummy exit 1 "linker" tool.
+TOOL_VBoxBsUnusedLd = Dummy unused linker.
+TOOL_VBoxBsUnusedLd_LINK_MISCBIN_OUTPUT =
+TOOL_VBoxBsUnusedLd_LINK_MISCBIN_DEPEND =
+TOOL_VBoxBsUnusedLd_LINK_MISCBIN_DEPORD =
+define TOOL_VBoxBsUnusedLd_LINK_MISCBIN_CMDS
+	echo "cannot use this template for linking"
+	exit 1
+endef
+
+# BS3Kit template for assembly and 16-bit code.
+TEMPLATE_VBoxBS3KitImg = Template for building BS3Kit test images.
+TEMPLATE_VBoxBS3KitImg_INST     = $(INST_VALIDATIONKIT)bootsectors/
+TEMPLATE_VBoxBS3KitImg_BINSUFF  = .img
+TEMPLATE_VBoxBS3KitImg_MODE     = 0644
+TEMPLATE_VBoxBS3KitImg_ASTOOL   = NASM
+TEMPLATE_VBoxBS3KitImg_ASFLAGS := -f obj -g -w+orphan-labels
+TEMPLATE_VBoxBS3KitImg_ASDEFS   = ASM_FORMAT_OMF RT_NOINC_SEGMENTS __NASM__
+TEMPLATE_VBoxBS3KitImg_ARTOOL   = OPENWATCOM-16
+TEMPLATE_VBoxBS3KitImg_CTOOL    = OPENWATCOM-16
+TEMPLATE_VBoxBS3KitImg_CXXTOOL  = OPENWATCOM-16
+TEMPLATE_VBoxBS3KitImg_CFLAGS   = -nt=BS3TEXT16 -nd=BS3DATA16 -nc=BS3CODE16 -ecc -q -3 -wx -zl -zu -s -oafs -mc -hc -d1+
+TEMPLATE_VBoxBS3KitImg_CXXFLAGS = -nt=BS3TEXT16 -nd=BS3DATA16 -nc=BS3CODE16 -ecc -q -3 -wx -zl -zu -s -oafs -mc -hc -d1+
+TEMPLATE_VBoxBS3KitImg_INCS     = $(VBOX_PATH_BS3KIT_SRC) .
+TEMPLATE_VBoxBS3KitImg_LDTOOL   = OPENWATCOM-WL
+# 	option quiet, nofarcalls\
+#	disable 1014, 1023, 2120, 1080
+
+TEMPLATE_VBoxBS3KitImg_LDFLAGS  = system dos \
+	debug codeview all \
+	option quiet, map, statics, verbose, symfile, start=_start \
+       disable 1014, 1080 \
+	\
+ 	output raw offset=0x10000 \
+ 	order \
+ 	 clname CODE16  segaddr=0x1000 \
+ 	  segment BS3TEXT16 \
+ 	  segment text \
+ 	 clname FAR_DATA \
+ 	  segment BS3DATA16 \
+        clname CODE32 \
+ 	  segment BS3TEXT32 \
+ 	  segment TEXT32 \
+        clname DATA32 \
+ 	  segment BS3DATA32 \
+ 	  segment DATA32
+TEMPLATE_VBoxBS3KitImg_LIBS = \
+    $(PATH_OBJ)/bs3kit-common-16/bs3kit-common-16.lib \
+    $(PATH_OBJ)/bs3kit-common-32/bs3kit-common-32.lib \
+    $(PATH_OBJ)/bs3kit-common-64/bs3kit-common-64.lib
+
+# BS3Kit template for 32-bit code.
+TEMPLATE_VBoxBS3KitImg32 = Template for building BS3Kit test images.
+TEMPLATE_VBoxBS3KitImg32_INSTTYPE = none
+TEMPLATE_VBoxBS3KitImg32_ASTOOL   = NASM
+TEMPLATE_VBoxBS3KitImg32_ASFLAGS := -f obj -g --allow-64bit-code-anywhere -w+orphan-labels
+TEMPLATE_VBoxBS3KitImg32_ASDEFS   = ASM_FORMAT_OMF RT_NOINC_SEGMENTS __NASM__
+TEMPLATE_VBoxBS3KitImg32_ARTOOL   = OPENWATCOM
+TEMPLATE_VBoxBS3KitImg32_CTOOL    = OPENWATCOM
+TEMPLATE_VBoxBS3KitImg32_CXXTOOL  = OPENWATCOM
+TEMPLATE_VBoxBS3KitImg32_CFLAGS   = -nt=BS3TEXT32 -nd=BS3DATA32 -nc=BS3CODE32 -ecc -q -wx -zu -s -oas -ms -hc -d1
+TEMPLATE_VBoxBS3KitImg32_CXXFLAGS = -nt=BS3TEXT32 -nd=BS3DATA32 -nc=BS3CODE32 -ecc -q -wx -zu -s -oas -ms -hc -d1
+TEMPLATE_VBoxBS3KitImg32_INCS     = $(VBOX_PATH_BS3KIT_SRC) .
+TEMPLATE_VBoxBS3KitImg32_LDTOOL   = VBoxBsUnusedLd
+
+# BS3Kit template for 64-bit code.
+TEMPLATE_VBoxBS3KitImg64 = Template for building BS3Kit test images.
+TEMPLATE_VBoxBS3KitImg64_INSTTYPE = none
+TEMPLATE_VBoxBS3KitImg64_ASTOOL   = NASM
+TEMPLATE_VBoxBS3KitImg64_ASFLAGS := -f obj -g --allow-64bit-code-anywhere -w+orphan-labels
+TEMPLATE_VBoxBS3KitImg64_ASDEFS   = ASM_FORMAT_OMF RT_NOINC_SEGMENTS __NASM__
+TEMPLATE_VBoxBS3KitImg64_ARTOOL   = OPENWATCOM
+TEMPLATE_VBoxBS3KitImg64_INCS     = $(VBOX_PATH_BS3KIT_SRC) .
+TEMPLATE_VBoxBS3KitImg64_CTOOL    = VBoxBsUnusedLd
+TEMPLATE_VBoxBS3KitImg64_CXXTOOL  = VBoxBsUnusedLd
+TEMPLATE_VBoxBS3KitImg64_LDTOOL   = VBoxBsUnusedLd
+
+# BS3Kit template for the bootsector.
+TEMPLATE_VBoxBS3KitBS = Template for building BS3Kit test images.
+TEMPLATE_VBoxBS3KitBS_INST     = $(INST_VALIDATIONKIT)bootsectors/
+TEMPLATE_VBoxBS3KitBS_INSTTYPE = none
+TEMPLATE_VBoxBS3KitBS_BINSUFF  = .img
+TEMPLATE_VBoxBS3KitBS_MODE     = 0644
+TEMPLATE_VBoxBS3KitBS_ASTOOL   = YASM
+TEMPLATE_VBoxBS3KitBS_ASFLAGS := -f bin --mapfile
+TEMPLATE_VBoxBS3KitBS_ASDEFS   = ASM_FORMAT_BIN RT_NOINC_SEGMENTS __YASM__
+TEMPLATE_VBoxBS3KitBS_INCS     = $(VBOX_PATH_BS3KIT_SRC) .
+TEMPLATE_VBoxBS3KitBS_LDTOOL   = VBoxBsCpLd
+
+#
+# ----- Config.kmk: end -----
+#
+
+
+# The boot sector.
+MISCBINS += bs3-bootsector
+bs3-bootsector_TEMPLATE = VBoxBS3KitBS
+bs3-bootsector_SOURCES  = bs3-bootsector.asm
+
+# Common sources to be compiled into _p16, _p32 and _p64 versions.
+VBOX_BS3KIT_COMMON_SOURCES = \
+	bs3-cmn-shutdown.asm \
+	bs3-cmn-panic.asm
+
+# The BS3Kit library.
+LIBRARIES += bs3kit-common-16
+bs3kit-common-16_TEMPLATE = VBoxBS3KitImg
+bs3kit-common-16_DEFS     = TMPL_PE16 BS3_CMN_ONLY
+bs3kit-common-16_SOURCES  = $(VBOX_BS3KIT_COMMON_SOURCES)
+
+# The 32-bit BS3Kit library.
+LIBRARIES += bs3kit-common-32
+bs3kit-common-32_TEMPLATE = VBoxBS3KitImg32
+bs3kit-common-32_DEFS     = TMPL_PE32 BS3_CMN_ONLY
+bs3kit-common-32_SOURCES  = $(VBOX_BS3KIT_COMMON_SOURCES)
+
+# The 64-bit BS3Kit library.
+LIBRARIES += bs3kit-common-64
+bs3kit-common-64_TEMPLATE = VBoxBS3KitImg64
+bs3kit-common-64_DEFS     = TMPL_LM64 BS3_CMN_ONLY
+bs3kit-common-64_SOURCES  = $(VBOX_BS3KIT_COMMON_SOURCES)
+
+#
+# shutdown example.
+#
+MISCBINS += bs3-shutdown
+bs3-shutdown_TEMPLATE = VBoxBS3KitImg
+bs3-shutdown_SOURCES = bs3-first-rm.asm bs3-shutdown.c
+
+
+include $(FILE_KBUILD_SUB_FOOTER)
+
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-shutdown.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-shutdown.asm	(revision 58593)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-shutdown.asm	(revision 58593)
@@ -0,0 +1,50 @@
+; $Id$
+;; @file
+; BS3Kit - Bs3Shutdown
+;
+
+;
+; 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"
+
+EXTERN_CMN_NM Bs3Panic
+
+BEGINPROC TMPL_CMN_NM(Bs3Shutdown)
+        cli
+        mov     bl, 64
+        mov     dx, 08900h
+%ifdef TMPL_16BIT
+        mov     ax, cs
+        mov     ds, ax
+%endif
+.retry:
+        mov     ecx, 8
+        mov     esi, .s_szShutdown
+        rep outsb
+        dec     bl
+        jnz     .retry
+        ; Shutdown failed!
+        jmp     Bs3Panic
+.s_szShutdown:
+        db      'Shutdown', 0
+ENDPROC TMPL_CMN_NM(Bs3Shutdown)
+
Index: unk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-shutdown.asm
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-shutdown.asm	(revision 58592)
+++ 	(revision )
@@ -1,50 +1,0 @@
-; $Id$
-;; @file
-; BS3Kit - Bs3Shutdown
-;
-
-;
-; 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"
-
-extern TMPL_CMN_NM(Bs3Panic)
-
-BEGINPROC TMPL_CMN_NM(Bs3Shutdown)
-        cli
-        mov     bl, 64
-        mov     dx, 08900h
-%ifdef TMPL_16BIT
-        mov     ax, cs
-        mov     ds, ax
-%endif
-.retry:
-        mov     ecx, 8
-        mov     esi, .s_szShutdown
-        rep outsb
-        dec     bl
-        jnz     .retry
-        ; Shutdown failed!
-        jmp     TMPL_CMN_NM(Bs3Panic)
-.s_szShutdown:
-        db      'Shutdown', 0
-ENDPROC TMPL_CMN_NM(Bs3Shutdown)
-
Index: /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.mac
===================================================================
--- /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.mac	(revision 58592)
+++ /trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3kit.mac	(revision 58593)
@@ -28,6 +28,43 @@
 %define ___bs3kit_mac___
 
+
+;; When using watcom + OMF, we're using __cdecl by default, which
+; get an underscore added in front.
+%ifdef ASM_FORMAT_OMF
+ %define NAME(name) _ %+ NAME_OVERLOAD(name)
+%endif
+
+
 %include "iprt/asmdefs.mac"
 %include "iprt/x86.mac"
+
+
+;;
+; Extern macro which mangles the name correctly.
+%macro EXTERN 1
+ extern NAME(%1)
+%endmacro
+
+;;
+; Extern macro which mangles the common name correctly, redefining the unmangled
+; name with to the mangled one for ease of use.
+%macro EXTERN_CMN_NM 1
+ %ifdef TMPL_64BIT
+  extern NAME(%1 %+ _p64)
+  %define %1 NAME(%1 %+ _p64)
+
+ %elifdef TMPL_32BIT
+  extern NAME(%1 %+ _p32)
+  %define %1 NAME(%1 %+ _p32)
+
+ %elifdef TMPL_16BIT
+  extern NAME(%1 %+ _p16)
+  %define %1 NAME(%1 %+ _p16)
+
+ %else
+  %error "Missing TMPL_xxBIT!"
+ %endif
+%endmacro
+
 
 
@@ -107,62 +144,79 @@
 ;; @{
 %macro BS3_BEGIN_TEXT16 0
- %ifndef BS3_BEGIN_TEXT16_NOT_FIRST
+ %ifndef  BS3_BEGIN_TEXT16_NOT_FIRST
   %define BS3_BEGIN_TEXT16_NOT_FIRST
-        section TEXT16 CLASS=CODE16 PUBLIC USE16 ALIGN=1
- %else
-        section TEXT16
+  %ifdef ASM_FORMAT_ELF
+        section BS3TEXT16 align=1 progbits alloc exec nowrite
+  %else
+        section BS3TEXT16 align=1 CLASS=CODE16 PUBLIC USE16
+  %endif
+
+ %else
+        section BS3TEXT16
  %endif
 %endmacro
 
 %macro BS3_BEGIN_DATA16 0
- %ifndef BS3_BEGIN_DATA16_NOT_FIRST
+ %ifndef  BS3_BEGIN_DATA16_NOT_FIRST
   %define BS3_BEGIN_DATA16_NOT_FIRST
-        section DATA16 CLASS=DATA16 PUBLIC USE16 ALIGN=2
- %else
-        section DATA16
+  %ifdef ASM_FORMAT_ELF
+        section BS3DATA16 align=2 progbits alloc noexec write
+  %else
+        section BS3DATA16 align=2 CLASS=FAR_DATA PUBLIC USE16
+  %endif
+ %else
+        section BS3DATA16
  %endif
 %endmacro
 
 %macro BS3_BEGIN_TEXT32 0
- %ifndef BS3_BEGIN_TEXT16_NOT_FIRST
-  %define BS3_BEGIN_TEXT16_NOT_FIRST
-        section TEXT32 CLASS=CODE32 PUBLIC USE32 ALIGN=1
- %else
-        section TEXT32
+ %ifndef  BS3_BEGIN_TEXT32_NOT_FIRST
+  %define BS3_BEGIN_TEXT32_NOT_FIRST
+  %ifdef ASM_FORMAT_ELF
+        section BS3TEXT32 align=1 progbits alloc exec nowrite
+  %else
+        section BS3TEXT32 align=1 CLASS=CODE32 PUBLIC USE32
+  %endif
+ %else
+        section BS3TEXT32
  %endif
 %endmacro
 
 %macro BS3_BEGIN_DATA32 0
- %ifndef BS3_BEGIN_DATA32_NOT_FIRST
+ %ifndef  BS3_BEGIN_DATA32_NOT_FIRST
   %define BS3_BEGIN_DATA32_NOT_FIRST
-        section DATA32 CLASS=DATA32 PUBLIC USE32 ALIGN=16
- %else
-        section DATA32
+  %ifdef ASM_FORMAT_ELF
+        section BS3DATA32 align=16 progbits alloc noexec write
+  %else
+        section BS3DATA32 align=16 CLASS=DATA32 PUBLIC USE32
+  %endif
+ %else
+        section BS3DATA32
  %endif
 %endmacro
 
 %macro BS3_BEGIN_TEXT64 0
- %ifndef BS3_BEGIN_TEXT64_NOT_FIRST
+ %ifndef  BS3_BEGIN_TEXT64_NOT_FIRST
   %define BS3_BEGIN_TEXT64_NOT_FIRST
   %ifdef ASM_FORMAT_ELF
-        section TEXT64 ALIGN=1
-  %else
-        section TEXT64 CLASS=CODE64 PUBLIC USE32 ALIGN=1
-  %endif
- %else
-        section TEXT64
+        section BS3TEXT64 align=1 progbits alloc exec nowrite
+  %else
+        section BS3TEXT64 align=1 CLASS=CODE64 PUBLIC USE32
+  %endif
+ %else
+        section BS3TEXT64
  %endif
 %endmacro
 
 %macro BS3_BEGIN_DATA64 0
- %ifndef BS3_BEGIN_DATA64_NOT_FIRST
+ %ifndef  BS3_BEGIN_DATA64_NOT_FIRST
   %define BS3_BEGIN_DATA64_NOT_FIRST
   %ifdef ASM_FORMAT_ELF
-        section DATA64 ALIGN=16
-  %else
-        section DATA64 CLASS=DATA64 PUBLIC USE32 ALIGN=16
-  %endif
- %else
-        section DATA64
+        section BS3DATA64 align=16 progbits alloc noexec write
+  %else
+        section BS3DATA64 align=16 CLASS=DATA64 PUBLIC USE32
+  %endif
+ %else
+        section BS3DATA64
  %endif
 %endmacro
