Index: trunk/src/os2ahci/Makefile
===================================================================
--- trunk/src/os2ahci/Makefile	(revision 143)
+++ trunk/src/os2ahci/Makefile	(revision 144)
@@ -55,5 +55,5 @@
 	       -I$(DDK)\base\src\dev\dasd\diskh \
                -I$(DDK)\base\src\dev\thinkpad\dockii\apmcalls \
-               -I$(CC16)\include
+#               -I$(CC16)\include
 
 AS_INCLUDE   = -I:$(DDK)\base\inc \
@@ -63,5 +63,5 @@
 	       $(DDK)\base\src\dev\dasd\devhlp\ \
                $(DDK)\base\src\dev\thinkpad\dockii\apmcalls\ \
-               $(CC16)\lib\ \
+#               $(CC16)\lib\ \
 
 
@@ -85,5 +85,6 @@
 
 clean:
-	rm -f $(OBJS) $(TARGET) *.cod *.lst *.def *.map *.sym bldday.h
+	rm -f $(OBJS) $(TARGET) *.cod *.lst *.def *.map *.sym *.err *.lnk \
+		bldday.h
 
 
@@ -132,7 +133,9 @@
 .asm.obj:
 	$(AS) $(AFLAGS) $(AS_INCLUDE) $*.asm
+	wdis -l $*.obj
 
 .c.obj:
 	$(CC) $(CFLAGS) $(CC_INCLUDE) $*.c
+	wdis -l $*.obj
 
 os2ahci.def:
@@ -143,4 +146,2 @@
 	$(LD) $(LFLAGS) $(OBJS),$(TARGET),$*.map,$(LIB_DIRS) $(LIBS),$*.def
 	$(MAPSYM) os2ahci
-
-
Index: trunk/src/os2ahci/_build.cmd
===================================================================
--- trunk/src/os2ahci/_build.cmd	(revision 143)
+++ 	(revision )
@@ -1,2 +1,0 @@
-@echo off
-nmake
Index: trunk/src/os2ahci/_clean.cmd
===================================================================
--- trunk/src/os2ahci/_clean.cmd	(revision 143)
+++ 	(revision )
@@ -1,2 +1,0 @@
-@echo off
-nmake clean
Index: trunk/src/os2ahci/_ibuild.cmd
===================================================================
--- trunk/src/os2ahci/_ibuild.cmd	(revision 144)
+++ trunk/src/os2ahci/_ibuild.cmd	(revision 144)
@@ -0,0 +1,3 @@
+@echo off
+nmake
+
Index: trunk/src/os2ahci/_iclean.cmd
===================================================================
--- trunk/src/os2ahci/_iclean.cmd	(revision 144)
+++ trunk/src/os2ahci/_iclean.cmd	(revision 144)
@@ -0,0 +1,2 @@
+@echo off
+nmake clean
Index: trunk/src/os2ahci/_wbuild.cmd
===================================================================
--- trunk/src/os2ahci/_wbuild.cmd	(revision 144)
+++ trunk/src/os2ahci/_wbuild.cmd	(revision 144)
@@ -0,0 +1,2 @@
+@echo off
+wmake -ms -f wmakefile
Index: trunk/src/os2ahci/_wclean.cmd
===================================================================
--- trunk/src/os2ahci/_wclean.cmd	(revision 144)
+++ trunk/src/os2ahci/_wclean.cmd	(revision 144)
@@ -0,0 +1,2 @@
+@echo off
+wmake -ms -f wmakefile clean
Index: trunk/src/os2ahci/ahci.c
===================================================================
--- trunk/src/os2ahci/ahci.c	(revision 143)
+++ trunk/src/os2ahci/ahci.c	(revision 144)
@@ -1467,5 +1467,5 @@
   }
 
-  dprintf("port #%d interrupt error status: 0x%08lx; restarting port\n", 
+  dprintf("port #%d interrupt error status: 0x%08lx; restarting port\n",
           p, irq_stat);
 
Index: trunk/src/os2ahci/init.asm
===================================================================
--- trunk/src/os2ahci/init.asm	(revision 143)
+++ trunk/src/os2ahci/init.asm	(revision 144)
@@ -8,10 +8,10 @@
 ; Constants
                 DEV_IDC  EQU    0400h        ;  IDC bit for ADD flags
-        
+
 ; -----------------------------------------------------------------------------
 ; Public symbols
 
                 PUBLIC  _asm_strat           ; low-level strategy routine
-                PUBLIC  _asm_idc_entry       ; low-level IDC entry point 
+                PUBLIC  _asm_idc_entry       ; low-level IDC entry point
                 PUBLIC  _asm_krnl_exit       ; low-level kernel exit routine
                 PUBLIC  _readl               ; MMIO read (32 bits)
@@ -29,5 +29,5 @@
                 PUBLIC  _end_of_data         ; end of all data (label)
                 PUBLIC  _end_of_code         ; end of all code (label)
-        
+
 ; ----------------------------------------------------------------------------
 ; Device Driver Header
@@ -65,4 +65,9 @@
 ; such as C.
 
+; When using the Watcom Linker, the segment ordering can be overridden in
+; the Watcom Makefile (wmakefile) where the Linker response-file is generated
+; containing statements for segment ordering. First you can order by class and
+; for each class you can specify the order of the segments within that class.
+; See the ORDER directive in the wlink documentation.
 _DATA           SEGMENT WORD PUBLIC 'DATA'
 readl_dbg_fmt   db      "readl(%04x:%04x) = 0x%08lx"
@@ -72,4 +77,7 @@
 _DATA           ENDS
 
+LIBDATA         SEGMENT WORD PUBLIC 'DATA'
+LIBDATA         ENDS
+
 CONST           SEGMENT WORD PUBLIC 'CONST'
 CONST           ENDS
@@ -83,5 +91,5 @@
 
 _z_data         SEGMENT WORD PUBLIC 'BSS'
-_end_of_data    db      0
+_end_of_data    db      ?
 _z_data         ENDS
 
@@ -98,9 +106,9 @@
 CODE            ENDS
 
+LIBCODE         SEGMENT WORD PUBLIC 'CODE'
+LIBCODE         ENDS
+
 RMCode          SEGMENT WORD PUBLIC 'CODE'
 RMCode          ENDS
-
-LIBCODE         SEGMENT WORD PUBLIC 'CODE'
-LIBCODE         ENDS
 
 _z_text         SEGMENT WORD PUBLIC 'CODE'
@@ -108,6 +116,13 @@
 _z_text         ENDS
 
-DGROUP          GROUP   DEVHDR, _DATA, CONST, _BSS, c_common, _z_data
-TGROUP          GROUP   _TEXT, CODE, _z_text
+
+; The Watcom Linker behaves differently than the IBM/MS Linkers when segments
+; are defined but not added to the corresponding group. So when you define a
+; a new (logical) segment and want it to be part of a physical segment (group)
+; then don't forget to add it below or unresolvable or miscalculated
+; relocations can be the result.
+DGROUP          GROUP   DEVHDR, _DATA, LIBDATA, _BSS, c_common, _z_data
+TGROUP          GROUP   _TEXT, CODE, LIBCODE, RMCode, _z_text
+
 
 ; ----------------------------------------------------------------------------
@@ -140,5 +155,5 @@
 ; IDC entry point (Assembler stub)
 _asm_idc_entry  PROC    FAR
-        
+
                 ; push request packet address
                 PUSH    ES
@@ -171,6 +186,6 @@
 
                 RET
-_asm_krnl_exit  ENDP        
-        
+_asm_krnl_exit  ENDP
+
 
                 .386
@@ -293,5 +308,5 @@
 
 
-; Halfway-decent 32-bit implementation of memcpy(). 
+; Halfway-decent 32-bit implementation of memcpy().
 ;
 ; C prototype: void *memcpy(void _far *d, void _far *s, size_t n);
@@ -377,5 +392,5 @@
 
 
-; Unsigned long divide routine; 
+; Unsigned long divide routine;
 ; taken from OS/2 Uniaud project, original author: Timur Tabi
 __U4D           proc    near
@@ -394,6 +409,6 @@
                 ret
 __U4D           endp
-        
-; Long multiply routine; 
+
+; Long multiply routine;
 ; taken from OS/2 Uniaud project, original author: Timur Tabi
 __U4M           proc    near
@@ -412,5 +427,5 @@
 
 
-; Signed long divide routine; 
+; Signed long divide routine;
 ; taken from OS/2 Uniaud project, original author: Timur Tabi
 __I4D           proc    near
@@ -429,5 +444,5 @@
                 ret
 __I4D           endp
-        
+
                 .286
 
Index: trunk/src/os2ahci/os2ahci.c
===================================================================
--- trunk/src/os2ahci/os2ahci.c	(revision 143)
+++ trunk/src/os2ahci/os2ahci.c	(revision 144)
@@ -164,5 +164,5 @@
     rc = char_dev_input((RP_RWV _far *) req);
     break;
-    
+
   default:
     rc = STDON | STATUS_ERR_UNKCMD;
@@ -358,5 +358,7 @@
 
 #ifdef ECS_BUILD
-  ciprintf("This driver is licensed for use only in conjunction with eComStation.");
+  ciprintf("This driver is licensed for use only in conjunction with eComStation.\n");
+#else
+  ciprintf("This is the Open Watcom build.\n");
 #endif
 
@@ -455,9 +457,9 @@
 
     case OS2AHCI_IDC_BIOSMODE:
-      /* reconfigure adapters in BIOS/int13 mode; needed for generating 
+      /* reconfigure adapters in BIOS/int13 mode; needed for generating
        * trap dumps on some machines. This is called by ACPI.PSD.
        *
        * To enter BIOS mode, we flush all write caches, turn off interrupts
-       * and restore the BIOS configuration. This is exactly what 
+       * and restore the BIOS configuration. This is exactly what
        * apm_suspend() does.
        */
@@ -474,5 +476,5 @@
   case DSKSP_CAT_GENERIC:
     return(ioctl_gen_dsk(ioctl));
-    
+
   case DSKSP_CAT_SMART:
     return(ioctl_smart(ioctl));
@@ -1521,5 +1523,4 @@
 {
   _asm {
-
     push ds
     push es
@@ -1533,5 +1534,6 @@
     mov si, OFFSET asm_krnl_exit
     mov dl, DevHlp_RegisterKrnlExit
-    call Device_Help
+
+    call dword ptr [Device_Help]
 
     pop  di
Index: trunk/src/os2ahci/os2ahci.def.template
===================================================================
--- trunk/src/os2ahci/os2ahci.def.template	(revision 143)
+++ trunk/src/os2ahci/os2ahci.def.template	(revision 144)
@@ -4,14 +4,14 @@
 
 segments
-  DEVHDR        CLASS 'DATA'
-  _DATA         CLASS 'DATA'
-  CONST         CLASS 'CONST'
-  _BSS          CLASS 'BSS'
-  c_common      CLASS 'BSS'
-  _z_data       CLASS 'BSS'
-  _TEXT         CLASS 'CODE' IOPL
+  'DEVHDR'      CLASS 'DATA'
+  '_DATA'       CLASS 'DATA'
+  'LIBDATA'     CLASS 'DATA'
+  'CONST'       CLASS 'CONST'
+  '_BSS'        CLASS 'BSS'
+  'c_common'    CLASS 'BSS'
+  '_z_data'     CLASS 'BSS'
+  '_TEXT'       CLASS 'CODE' IOPL
   'CODE'        CLASS 'CODE' IOPL
-  RMCode        CLASS 'CODE' IOPL
-  LIBCODE       CLASS 'CODE' IOPL
-  _z_text       CLASS 'CODE' IOPL
-
+  'LIBCODE'     CLASS 'CODE' IOPL
+  'RMCode'      CLASS 'CODE' IOPL
+  '_z_text'     CLASS 'CODE' IOPL
Index: trunk/src/os2ahci/os2ahci.h
===================================================================
--- trunk/src/os2ahci/os2ahci.h	(revision 143)
+++ trunk/src/os2ahci/os2ahci.h	(revision 144)
@@ -28,5 +28,5 @@
 
 /* IMPORTANT NOTE: The DDK headers require tight structure packing and this
- * is controlled via compiler parameters. Thus, all stuctures in os2ahci.sys
+ * is controlled via compiler parameters. Thus, all stuctures in os2ahci.add
  * are expected to be byte-aligned without the need of explicit pragma pack()
  * directives. Where possible, the structures are layed out such that words
@@ -49,4 +49,10 @@
 #include <reqpkt.h>
 
+/* NOTE: (Rousseau)
+ * The regular dhcalls.h from $(DDK)\base\h also works.
+ * The devhelp.h from $(DDK)\base\h produces inline assembler errors.
+ * The modified devhelp.h from ..\include works OK and is used because it
+ * generates a slightly smaller driver image.
+ */
 #ifdef __WATCOMC__
 /* include WATCOM specific DEVHELP stubs */
@@ -106,5 +112,5 @@
 #define dddphex   if (debug > 2) phex
 
-/* verbosity console print macros 
+/* verbosity console print macros
  * (we use 'i' in ciprintf here to avoid name clash
  * with vprintf-like funcs)
@@ -380,5 +386,5 @@
   SG_TO_BUF,                           /* copy from S/G list to buffer */
   BUF_TO_SG                            /* copy from buffer to S/G list */
-} SG_MEMCPY_DIRECTION;  
+} SG_MEMCPY_DIRECTION;
 
 /* -------------------------- function prototypes -------------------------- */
Index: trunk/src/os2ahci/wmakefile
===================================================================
--- trunk/src/os2ahci/wmakefile	(revision 143)
+++ trunk/src/os2ahci/wmakefile	(revision 144)
@@ -29,10 +29,4 @@
 #
 
-#
-# THE WATCOM BUILD IS BROKEN!
-#
-# It might run through but produces a non-working driver
-#
-
 ###############################################################################
 # wmake directives
@@ -43,4 +37,5 @@
 ###############################################################################
 # Environment
+
 
 # main path to OS/2 DDK; this needs to be set before this makefile will work
@@ -57,23 +52,33 @@
                -I$(DDK)\base\h \
                -I$(DDK)\base\ibmh \
-	       -I$(DDK)\base\src\dev\dasd\diskh \
+               -I$(DDK)\base\src\dev\dasd\diskh \
                -I$(DDK)\base\src\dev\thinkpad\dockii\apmcalls \
-               -I$(CC16)\include
-
-AS_INCLUDE   = -I:$(DDK)\base\inc \
-               -I:$(DDK)\base\src\dev\dasd\diskinc
+#               -I$(CC16)\include
+
+AS_INCLUDE   = -I=$(DDK)\base\inc \
+               -I=$(DDK)\base\src\dev\dasd\diskinc
 
 LIB_DIRS     = $(DDK)\base\lib\ \
-	       $(DDK)\base\src\dev\dasd\devhlp\ \
+               $(DDK)\base\src\dev\dasd\devhlp\ \
                $(DDK)\base\src\dev\thinkpad\dockii\apmcalls\ \
 
+
+
+
 ###############################################################################
 # Tool Chain
 #
-# This makefile uses the Watcom 16bit compiler.
-# Linker and assembler are link.exe and alp.exe that ship with the OS/2 DDK
-#
-
-AS         = $(DDK)\tools\alp.exe
+# This makefile uses the Watcom 16-bit compiler, Watcom Assembler and Linker.
+# You can change to the DDK Linker and Assembler by modifying the macros below.
+#
+
+
+#LINKER=ibm
+LINKER=watcom
+
+
+#AS         = $(DDK)\tools\alp.exe
+#AS         = jwasm -Cp
+AS         = wasm
 CC         = wcc
 LD         = $(DDK)\base\tools\link.exe
@@ -82,7 +87,9 @@
 MAPSYM     = $(DDK)\base\tools\mapsym.exe
 
-AFLAGS        = -Mb
-CFLAGS        = -d3 -hc -bt=os2 -ms -zu -5 -w3 -wcd=138 -wcd=300 -ecc -zp1 -q -s -zgp -zfp -oi
-CFLAGS_DEBUG  = -d3 -hc
+#AFLAGS        = -Mb
+#CFLAGS        = -ei -5 -d3 -hc -bt=os2 -ms -zu -w3 -wcd=138 -wcd=300 -ecc -zp1 -q -s -zgp -zfp -oi
+CFLAGS        = -ei -5 -d0 -bt=os2 -ms -zu -w=0 -ecc -zp=1 -q -s -zgp -zfp -oi
+CFLAGS_DEBUG  = -ei -5 -d3 -hc -bt=os2 -ms -zu -ecc -zp=1 -q -s -zgp -zfp -od
+
 LFLAGS        = /noe /nod /packd /a:16 /batch /map /line
 
@@ -92,8 +99,9 @@
 TARGET   = os2ahci.add
 
-LIBS     = addcalls doscalls rmcalls apmcalls # dhcalls not needed, see local devhelp.h
+#LIBS     = addcalls doscalls rmcalls apmcalls # dhcalls not needed, see local devhelp.h
+LIBS     = addcalls doscalls rmcalls apmcalls dhcalls
 
 SRCS     = init.asm math.asm libc.c os2ahci.c pci.c ahci.c ata.c atapi.c \
-	   ctxhook.c trace.c ioctl.c apm.c
+           ctxhook.c trace.c ioctl.c apm.c
 
 OBJS     = init.obj libc.obj os2ahci.obj pci.obj ahci.obj ata.obj atapi.obj \
@@ -106,32 +114,33 @@
 
 clean:
-	rm -f $(OBJS) $(TARGET) *.lst *.cod
+        rm -f $(OBJS) $(TARGET) *.cod *.lst *.def *.map *.sym *.err *.lnk \
+                bldday.h
 
 ###############################################################################
 # Object/source dependencies
 
-init.obj:     init.asm   Makefile
-
-libc.obj:     libc.c     Makefile $(INCS)
-
-os2ahci.obj:  os2ahci.c  Makefile $(INCS) bldday.h ioctl.h
-
-pci.obj:      pci.c      Makefile $(INCS)
-
-ahci.obj:     ahci.c     Makefile $(INCS) ata.h atapi.h
-
-ata.obj:      ata.c      Makefile $(INCS) ata.h
-
-atapi.obj:    atapi.c    Makefile $(INCS) ata.h atapi.h
-
-ctxhook.obj:  ctxhook.c  Makefile $(INCS) ata.h atapi.h
-
-apm.obj:      apm.c      Makefile $(INCS)
-
-ioctl.obj:    ioctl.c    Makefile $(INCS) atapi.h ioctl.h
-
-trace.obj:    trace.c    Makefile $(INCS)
-
-os2ahci.def:  version.h  os2ahci.def.template
+init.obj:       $*.asm  wmakefile
+
+libc.obj:       $*.c    wmakefile $(INCS)
+
+os2ahci.obj:    $*.c    wmakefile $(INCS) bldday.h ioctl.h
+
+pci.obj:        $*.c    wmakefile $(INCS)
+
+ahci.obj:       $*.c    wmakefile $(INCS) ata.h atapi.h
+
+ata.obj:        $*.c    wmakefile $(INCS) $*.h
+
+atapi.obj:      $*.c    wmakefile $(INCS) $*.h ata.h
+
+ctxhook.obj:    $*.c    wmakefile $(INCS) ata.h atapi.h
+
+apm.obj:        $*.c    wmakefile $(INCS)
+
+ioctl.obj:      $*.c    wmakefile $(INCS) $*.h atapi.h
+
+trace.obj:      $*.c    wmakefile $(INCS)
+
+os2ahci.def:  version.h $*.def.template
 
 ###############################################################################
@@ -140,23 +149,58 @@
 # emacs TAGS file creation
 # NOTE: OS/2 emacs etags.exe expects an empty file named c:\dev\null...
-tags:	$(SRCS) $(INCS)
-	etags.exe $(SRCS) $(INCS)
+tags:   $(SRCS) $(INCS)
+        etags.exe $(SRCS) $(INCS)
 
 bldday.h:
-	$(BLDDATE) > bldday.h
+        $(BLDDATE) > bldday.h
 
 .asm.obj:
-	$(AS) $(AFLAGS) $(AS_INCLUDE) $*.asm
+        $(AS) $(AFLAGS) $(AS_INCLUDE) $*.asm
+        wdis -l $*.obj
 
 .c.obj:
-	$(CC) $(CFLAGS) $(CC_INCLUDE) $*.c
-	wdis -l $*.obj
+        $(CC) $(CFLAGS) $(CC_INCLUDE) $*.c
+        wdis -l $*.obj
 
 os2ahci.def:
-	$(BLDLEVEL) os2ahci.def.template os2ahci.def version.h
-
-$(TARGET): $(OBJS) os2ahci.def wmakefile
-	$(LD) $(LFLAGS) $(OBJS),$(TARGET),$*.map,$(LIB_DIRS) $(LIBS),$*.def
-	mapsym os2ahci
-
-
+        $(BLDLEVEL) $*.def.template $*.def version.h
+
+$(TARGET): $(OBJS) $*.def wmakefile
+
+!if "$(LINKER)"=="watcom"
+        # Target name, system and type
+        @%create $*.lnk
+        @%append $*.lnk name $*.add
+        @%append $*.lnk sys os2 dll
+        # Merge BLDLEVEL information
+        @%append $*.lnk option
+        @qgrep -y -e "description" $*.def >> $*.lnk
+        # Set various options
+        @%append $*.lnk option protmode
+        @%append $*.lnk option map
+        @%append $*.lnk option quiet
+        @%append $*.lnk option nocase
+        @%append $*.lnk option stack=0
+        # Generate directives for objects, libraries and library search-paths
+        @for %f in ($(OBJS)) do @%append $*.lnk file %f
+        @for %f in ($(LIBS)) do @%append $*.lnk lib %f
+        @for %f in ($(LIB_DIRS)) do @%append $*.lnk libpath %f
+        # Attributes for the DATA and CODE segments
+        @%append $*.lnk segment type DATA SHARED
+        @%append $*.lnk segment type CODE IOPL
+        # Order segments by class
+        @%append $*.lnk order
+        @%append $*.lnk clname 'DATA'
+        @%append $*.lnk clname 'CONST'
+        @%append $*.lnk clname 'BSS'
+        @%append $*.lnk clname 'CODE'
+        # Link the stuff together and build the target
+        wlink  @$*.lnk
+
+!elseif "$(LINKER)"=="ibm"
+        $(LD) $(LFLAGS) $(OBJS),$(TARGET),$*.map,$(LIB_DIRS) $(LIBS),$*.def
+        mapsym $*
+!else
+        @echo "Error: No valid linker specified"
+!endif
+
