Index: trunk/src/os2ahci/Makefile
===================================================================
--- trunk/src/os2ahci/Makefile	(revision 147)
+++ trunk/src/os2ahci/Makefile	(revision 148)
@@ -1,9 +1,8 @@
 ###############################################################################
-# Makefile - makefile for os2ahci driver, c600 tool chain
+# Makefile - makefile for os2ahci driver using WATCOM compiler
 #
-# Copyright (c) 2011 thi.guten Software Development
-# Copyright (c) 2011 Mensys B.V.
-#
-# Authors: Christian Mueller, Markus Thielen
+# Copyright (c) 2010 Christian Mueller, Markus Thielen.
+# Parts copied from/inspired by the Linux AHCI driver;
+# those parts are (c) Linux AHCI/ATA maintainers
 #
 #  This program is free software; you can redistribute it and/or modify
@@ -20,99 +19,119 @@
 #  along with this program; if not, write to the Free Software
 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
+
+
+###############################################################################
+# Environment
+
+.ERASE
+.SUFFIXES
+.SUFFIXES: .lst .obj .c .asm .lib .def
+
+# Define default build version if not specified in environment
+BLD_MAJOR=1
+BLD_MINOR=26 # must be 2 digits
+BLD_REV=0 # not used at this time
+
+!ifndef %WATCOM # if not defined in the environment
+!error WATCOM must be set in the environment.
+!endif
+WATCOM=$(%WATCOM)
+
+!ifndef %DDK # if not defined in the environment
+!error DDK must be set in the environment.
+!endif
+DDK=$(%DDK)
+
+!ifdef %VENDOR
+VENDOR=$(%VENDOR)
+!else
+VENDOR=Mensys BV
+!endif
+
+!ifdef %BLD_MAJOR
+BLD_MAJOR=$(%BLD_MAJOR)
+!endif
+
+!ifdef %BLD_MINOR
+BLD_MINOR=$(%BLD_MINOR)
+!endif
+
+CC_INCLUDE = -I..\include &
+             -I$(DDK)\base\h &
+             -I$(DDK)\base\ibmh &
+             -I$(DDK)\base\src\dev\dasd\diskh &
+             -I$(DDK)\base\src\dev\thinkpad\dockii\apmcalls &
+
+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\thinkpad\dockii\apmcalls\
 
 ###############################################################################
 # Tool Chain
 #
+# This makefile uses the Watcom 16-bit compiler, Watcom Assembler and Linker.
+# The updated DDK devhelp.h is required and a copy is in the include directory
+# of this project.
+#
 
-AS         = $(DDK)\tools\alp.exe
-CC         = cl
-LD         = $(DDK)\base\tools\link.exe
+%PATH=..\..\tools;$(WATCOM)\BINP;$(WATCOM)\BINW;
+AS         = wasm
+CC         = wcc
 MAPSYM     = $(DDK)\base\tools\mapsym.exe
-BLDLEVEL   = cmd.exe /c ..\..\tools\bldlvl.cmd
-BLDDATE    = cmd.exe /c ..\..\tools\blddate.cmd
 
-AFLAGS     = -Mb
-CFLAGS     = -c -nologo -Asnw -W2 -G2ms -Zlpd -Fc -Zi -DECS_BUILD
-LFLAGS     = /noe /nod /packd /a:16 /batch /map /line
-
-###############################################################################
-# Environment
-
-# main path to OS/2 DDK; this needs to be set before this makefile will work
-!ifndef DDK
-DDK          = i:\ddk
+!ifdef __LOADDLL__
+!loaddll wcc   $(WATCOM)\BINP\DLL\wccd.dll
+!loaddll wlink $(WATCOM)\BINP\DLL\wlinkd.dll
 !endif
 
-# main path to 16 bit C compiler
-!ifndef CC16
-CC16         = i:\c600
-!endif
-
-CC_INCLUDE   = -I..\include \
-               -I$(DDK)\base\h \
-               -I$(DDK)\base\ibmh \
-	       -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
-
-LIB_DIRS     = $(DDK)\base\lib\ \
-	       $(DDK)\base\src\dev\dasd\devhlp\ \
-               $(DDK)\base\src\dev\thinkpad\dockii\apmcalls\ \
-#               $(CC16)\lib\ \
-
+AFLAGS = -q
+#CFLAGS = -ei -5 -d3 -hc -bt=os2 -ms -zu -w3 -wcd=138 -wcd=300 -ecc -zp1 -q -s -zgp -zfp -oi
+# In order to build the SMP safe version you must have the updated devhelp.h and define OS2AHCI_SMP.
+CFLAGS = -ei -5 -d0 -bt=os2 -ms -zu -w=0 -ecc -zp=1 -q -s -zgp -zfp -oi -DOS2AHCI_SMP
+CFLAGS_DEBUG = -ei -5 -d3 -hc -bt=os2 -ms -zu -ecc -zp=1 -q -s -zgp -zfp -od
 
 ###############################################################################
 # Main dependencies
 
-TARGET   = os2ahci.add
+LIBS = addcalls doscalls rmcalls apmcalls
 
-LIBS     = addcalls dhcalls doscalls slibcep rmcalls apmcalls
+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
 
-SRCS     = init.asm libc.c os2ahci.c pci.c ahci.c ata.c atapi.c ctxhook.c \
-           apm.c ioctl.c trace.c
+OBJS = init.obj libc.obj os2ahci.obj pci.obj ahci.obj ata.obj atapi.obj &
+       ctxhook.obj trace.obj ioctl.obj apm.obj
 
-OBJS     = init.obj libc.obj os2ahci.obj pci.obj ahci.obj ata.obj atapi.obj \
-           ctxhook.obj apm.obj ioctl.obj trace.obj
+INCS = os2ahci.h ahci.h
 
-INCS     = os2ahci.h ahci.h version.h ioctl.h ..\include\ahci-idc.h
+all: os2ahci.add os2ahci.sym
 
-
-all: $(TARGET)
-
-clean:
-	rm -f $(OBJS) $(TARGET) *.cod *.lst *.def *.map *.sym *.err *.lnk \
-		bldday.h
-
+clean: .symbolic
+    rm -f $(OBJS) os2ahci.add *.cod *.lst *.def *.map *.sym *.err *.lnk version.h
 
 ###############################################################################
 # Object/source dependencies
 
-init.obj:     init.asm   Makefile
+libc.obj: libc.c Makefile $(INCS)
 
-libc.obj:     libc.c     Makefile $(INCS)
+os2ahci.obj: os2ahci.c Makefile $(INCS) version.h ioctl.h
 
-os2ahci.obj:  os2ahci.c  Makefile $(INCS) bldday.h ioctl.h
+pci.obj: pci.c Makefile $(INCS)
 
-pci.obj:      pci.c      Makefile $(INCS)
+ahci.obj: ahci.c Makefile $(INCS) ata.h atapi.h
 
-ahci.obj:     ahci.c     Makefile $(INCS) ata.h atapi.h
+ata.obj: ata.c Makefile $(INCS) ata.h
 
-ata.obj:      ata.c      Makefile $(INCS) ata.h
+atapi.obj: atapi.c Makefile $(INCS) atapi.h ata.h
 
-atapi.obj:    atapi.c    Makefile $(INCS) ata.h atapi.h
+ctxhook.obj: ctxhook.c Makefile $(INCS) ata.h atapi.h
 
-ctxhook.obj:  ctxhook.c  Makefile $(INCS) ata.h atapi.h
+apm.obj: apm.c Makefile $(INCS)
 
-apm.obj:      apm.c      Makefile $(INCS)
+ioctl.obj: ioctl.c Makefile $(INCS) ioctl.h atapi.h
 
-ioctl.obj:    ioctl.c    Makefile $(INCS) ata.h atapi.h ioctl.h
-
-trace.obj:    trace.c    Makefile $(INCS)
-
-os2ahci.def:  version.h  os2ahci.def.template
+trace.obj: trace.c Makefile $(INCS)
 
 ###############################################################################
@@ -121,27 +140,56 @@
 # emacs TAGS file creation
 # NOTE: OS/2 emacs etags.exe expects an empty file named c:\dev\null...
-tags:	$(SRCS) $(INCS) Makefile
-	etags.exe $(SRCS) $(INCS) $(DDK)\base\src\dev\dasd\diskh\dhcalls.h \
-	$(DDK)\base\src\dev\dasd\diskh\iorb.h \
-	$(DDK)\base\h\bsedos16.h \
-	$(DDK)\base\h\devcmd.h \
-	$(DDK)\base\h\reqpkt.h
+tags:   $(SRCS) $(INCS)
+    etags.exe $(SRCS) $(INCS)
 
-bldday.h:
-	$(BLDDATE) > bldday.h
+version.h: Makefile .always
+    @%create $^@
+    @%append $^@ /* Autogenerated by Makefile */
+    @%append $^@ $#define VERSION $(BLD_MAJOR)$(BLD_MINOR) /* driver version (2 implied decimals) */
+    @AddToFile $^@,$#define BLD_YEAR,DATEYEAR
+    @AddToFile $^@,$#define BLD_MONTH,DATEMONTH
+    @AddToFile $^@,$#define BLD_DAY,DATEDAY
 
-.asm.obj:
-	$(AS) $(AFLAGS) $(AS_INCLUDE) $*.asm
-	wdis -l $*.obj
+.asm.obj: .autodepend
+    $(AS) $(AFLAGS) $(AS_INCLUDE) $[@
+    #wdis -l $^@
 
-.c.obj:
-	$(CC) $(CFLAGS) $(CC_INCLUDE) $*.c
-	wdis -l $*.obj
+.c.obj: .autodepend
+    $(CC) $(CFLAGS) $(CC_INCLUDE) $[@
+    #wdis -l $^@
 
-os2ahci.def:
-	$(BLDLEVEL) os2ahci.def.template os2ahci.def version.h
+os2ahci.add: $(OBJS) Makefile
+    # Target name, system and type
+    @%create $*.lnk
+    @%append $*.lnk name $*.add
+    @%append $*.lnk sys os2 dll
+    # Merge BLDLEVEL information
+	@AddToFile.cmd $*.lnk,option description,BLDLEVEL,$(VENDOR),$(BLD_MAJOR).$(BLD_MINOR),AHCI Driver (c) Mensys BV 2013
+    # 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
+    @%erase $*.lnk
 
+os2ahci.sym: os2ahci.map
+	wat2map.cmd $[@ $^*.ma1
+	$(MAPSYM) $^*.ma1
+	@%erase $^*.ma1
 
-$(TARGET): $(OBJS) os2ahci.def Makefile
-	$(LD) $(LFLAGS) $(OBJS),$(TARGET),$*.map,$(LIB_DIRS) $(LIBS),$*.def
-	$(MAPSYM) os2ahci
Index: trunk/src/os2ahci/Makefile.old
===================================================================
--- trunk/src/os2ahci/Makefile.old	(revision 148)
+++ trunk/src/os2ahci/Makefile.old	(revision 148)
@@ -0,0 +1,148 @@
+###############################################################################
+# Makefile.old - makefile for os2ahci driver, c600 tool chain
+# NOTICE: This makefile is depreciated and is not guaranteed to work anymore.
+#
+# Copyright (c) 2011 thi.guten Software Development
+# Copyright (c) 2011 Mensys B.V.
+#
+# Authors: Christian Mueller, Markus Thielen
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+
+###############################################################################
+# Tool Chain
+#
+
+AS         = $(DDK)\tools\alp.exe
+CC         = $(DDK)\base\tools\cl.exe
+LD         = $(DDK)\base\tools\link.exe
+MAPSYM     = $(DDK)\base\tools\mapsym.exe
+ADDTOFILE  = ..\..\tools\AddToFile.cmd
+
+AFLAGS     = -Mb
+# In order to build the SMP safe version you must have the updated DDK and define OS2AHCI_SMP
+CFLAGS     = -c -nologo -Asnw -W2 -G2ms -Zlpd -Fc -Zi #-DOS2AHCI_SMP
+LFLAGS     = /noe /nod /packd /a:16 /batch /map /line
+
+###############################################################################
+# Environment
+
+# main path to OS/2 DDK; this needs to be set before this makefile will work
+!ifndef DDK
+!error DDK must be set in the environment.
+!endif
+
+!ifndef VENDOR
+VENDOR=Mensys BV
+!endif
+
+BLD_MAJOR=1
+BLD_MINOR=26 # must be 2 digits
+BLD_REV=0 # not used at this time
+
+CC_INCLUDE   = -I..\include \
+               -I$(DDK)\base\h \
+               -I$(DDK)\base\ibmh \
+               -I$(DDK)\base\src\dev\dasd\diskh \
+               -I$(DDK)\base\src\dev\thinkpad\dockii\apmcalls
+
+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\thinkpad\dockii\apmcalls\ \
+
+###############################################################################
+# Main dependencies
+
+TARGET   = os2ahci.add
+
+LIBS     = addcalls dhcalls doscalls slibcep rmcalls apmcalls
+
+SRCS     = init.asm libc.c os2ahci.c pci.c ahci.c ata.c atapi.c ctxhook.c \
+           apm.c ioctl.c trace.c
+
+OBJS     = init.obj libc.obj os2ahci.obj pci.obj ahci.obj ata.obj atapi.obj \
+           ctxhook.obj apm.obj ioctl.obj trace.obj
+
+INCS     = os2ahci.h ahci.h version.h ioctl.h ..\include\ahci-idc.h
+
+
+all: $(TARGET)
+
+clean:
+    rm -f $(OBJS) $(TARGET) *.cod *.lst *.def *.map *.sym *.err *.lnk version.h
+
+###############################################################################
+# Object/source dependencies
+
+init.obj:     init.asm   Makefile.old
+
+libc.obj:     libc.c     Makefile.old $(INCS)
+
+os2ahci.obj:  os2ahci.c  Makefile.old $(INCS) version.h ioctl.h
+
+pci.obj:      pci.c      Makefile.old $(INCS)
+
+ahci.obj:     ahci.c     Makefile.old $(INCS) ata.h atapi.h
+
+ata.obj:      ata.c      Makefile.old $(INCS) ata.h
+
+atapi.obj:    atapi.c    Makefile.old $(INCS) ata.h atapi.h
+
+ctxhook.obj:  ctxhook.c  Makefile.old $(INCS) ata.h atapi.h
+
+apm.obj:      apm.c      Makefile.old $(INCS)
+
+ioctl.obj:    ioctl.c    Makefile.old $(INCS) ata.h atapi.h ioctl.h
+
+trace.obj:    trace.c    Makefile.old $(INCS)
+
+###############################################################################
+# Action definitions (compile/link commands)
+
+# emacs TAGS file creation
+# NOTE: OS/2 emacs etags.exe expects an empty file named c:\dev\null...
+tags:   $(SRCS) $(INCS) Makefile.old
+    etags.exe $(SRCS) $(INCS) $(DDK)\base\src\dev\dasd\diskh\dhcalls.h \
+    $(DDK)\base\src\dev\dasd\diskh\iorb.h \
+    $(DDK)\base\h\bsedos16.h \
+    $(DDK)\base\h\devcmd.h \
+    $(DDK)\base\h\reqpkt.h
+
+version.h: Makefile.old
+    @echo /* Autogenerated by Makefile.old */ >version.h
+    @echo #define VERSION $(BLD_MAJOR)$(BLD_MINOR) /* driver version (2 implied decimals) */ >>version.h
+    @$(ADDTOFILE) version.h,#define BLD_YEAR,DATEYEAR
+    @$(ADDTOFILE) version.h,#define BLD_MONTH,DATEMONTH
+    @$(ADDTOFILE) version.h,#define BLD_DAY,DATEDAY
+
+.asm.obj:
+    $(AS) $(AFLAGS) $(AS_INCLUDE) $*.asm
+#    wdis -l $*.obj
+
+.c.obj:
+    $(CC) $(CFLAGS) $(CC_INCLUDE) $*.c
+#    wdis -l $*.obj
+
+os2ahci.def: os2ahci.def.template Makefile.old
+    copy os2ahci.def.template os2ahci.def
+	@$(ADDTOFILE) os2ahci.def,Description,BLDLEVEL,$(VENDOR),$(BLD_MAJOR).$(BLD_MINOR),AHCI Driver (c) Mensys BV 2013
+
+$(TARGET): $(OBJS) os2ahci.def Makefile.old
+    $(LD) $(LFLAGS) $(OBJS),$(TARGET),$*.map,$(LIB_DIRS) $(LIBS),$*.def
+    $(MAPSYM) os2ahci
Index: trunk/src/os2ahci/README
===================================================================
--- trunk/src/os2ahci/README	(revision 147)
+++ trunk/src/os2ahci/README	(revision 148)
@@ -16,5 +16,5 @@
 
 Copyright (c) 2011 thi.guten Software Development
-Copyright (c) 2011 Mensys B.V.
+Copyright (c) 2011-2013 Mensys B.V.
 
 Authors: Christian Mueller, Markus Thielen
@@ -51,4 +51,28 @@
 as modifications will also be published as outlined in the GNU GPL2.
 
+Please note that builds other than the official binary delivered as
+part of eComStation releases or downloaded from ecomstation.nl are
+not officially supported by Mensys.
+
+
+Building The Driver
+-------------------
+
+The toolchain required for compilation consists of:
+
+ - IBM OS/2 DDK version 9.23 or later (see ddk\base\h\version.mak)
+   (Used for include files and qgrep)
+ - Open Watcom C/C++ package
+   (available from: http://www.openwatcom.org/index.php/Downloads)
+ - WCC 16-bit C Compiler (part of the Open Watcom package)
+ - WASM Assembler (part of the Open Watcom package)
+ - WLINK Linker (part of the Open Watcom package)
+ - MAPSYM (part of the DDK)
+
+Simply use "wmake" or "wmake -a" to build the driver.
+
+The driver can also be built using the DDK tools, but this build
+is depreciated and is not kept up-to-date.
+
 The toolchain required for compilation consists of:
 
@@ -57,33 +81,11 @@
  - ALP Assembler (part of DDK)
  - link.exe (part of DDK)
-
-Please note that builds other than the official binary delivered as
-part of eComStation releases or downloaded from ecomstation.nl are
-not officially supported by Mensys.
-
-
-Open Watcom Build
------------------
-
-The Open Watcom Build is fixed and now produces a working driver.
-
-The toolchain required for compilation with Open Watcom consists of:
-
- - IBM OS/2 DDK version 9.23 or later (see ddk\base\h\version.mak)
-   (Used for include files and qgrep)
- - Open Watcom C/C++ package
-   (available from: http://www.openwatcom.org/index.php/Downloads)
- - WCC 16-bits C Compiler (part of the Open Watcom package)
- - WASM Assembler (part of the Open Watcom package)
- - WLINK Linker (part of the Open Watcom package)
- - QGREP (part of DDK)
-
-Please note that the Open Watcom Build is not as extensively tested as the
-normal DDK Build so don't use it on production systems yet.
-
-Use the _wbuild.cmd script or run wmake -ms -f wmakefile to build it.
-When switching between building with the DDK and Open Watcom,
-be sure to do a clean first.
-
+ - MAPSYM (part of the DDK)
+
+Use "nmake -f Makefile.old" or "nmake -f Makefile.old -a" to build
+the driver.
+
+When switching between building with the DDK and Open Watcom, it is
+recommended to do a clean first (wmake clean or nmake -f Makefile.old clean).
 
 
Index: trunk/src/os2ahci/_ibuild.cmd
===================================================================
--- trunk/src/os2ahci/_ibuild.cmd	(revision 147)
+++ trunk/src/os2ahci/_ibuild.cmd	(revision 148)
@@ -1,3 +1,3 @@
 @echo off
-nmake
+nmake -f Makefile.old
 
Index: trunk/src/os2ahci/_iclean.cmd
===================================================================
--- trunk/src/os2ahci/_iclean.cmd	(revision 147)
+++ trunk/src/os2ahci/_iclean.cmd	(revision 148)
@@ -1,2 +1,2 @@
 @echo off
-nmake clean
+nmake -f Makefile.old clean
Index: trunk/src/os2ahci/_wbuild.cmd
===================================================================
--- trunk/src/os2ahci/_wbuild.cmd	(revision 147)
+++ trunk/src/os2ahci/_wbuild.cmd	(revision 148)
@@ -1,2 +1,7 @@
 @echo off
-wmake -ms -f wmakefile
+rem set VENDOR=Mensys BV
+rem set BLD_MAJOR=1
+rem set BLD_MINOR=26
+rem set WATCOM=i:\Watcom
+rem set DDK=i:\ddk
+wmake
Index: trunk/src/os2ahci/_wclean.cmd
===================================================================
--- trunk/src/os2ahci/_wclean.cmd	(revision 147)
+++ trunk/src/os2ahci/_wclean.cmd	(revision 148)
@@ -1,2 +1,2 @@
 @echo off
-wmake -ms -f wmakefile clean
+wmake clean
Index: trunk/src/os2ahci/ahci.c
===================================================================
--- trunk/src/os2ahci/ahci.c	(revision 147)
+++ trunk/src/os2ahci/ahci.c	(revision 148)
@@ -142,4 +142,6 @@
   }
 
+  ddprintf("ahci_save_bios_config: BIOS AHCI mode is %d\n", ai->bios_config[HOST_CTL / sizeof(u32)] & HOST_AHCI_EN);
+
   if ((ai->bios_config[HOST_CTL / sizeof(u32)] & HOST_AHCI_EN) == 0 &&
       ai->pci->vendor == PCI_VENDOR_ID_INTEL) {
@@ -165,38 +167,38 @@
 
       if (i == HOST_CAP) {
-        printf(" -");
-        if (val & HOST_CAP_64)         printf(" 64bit");
-        if (val & HOST_CAP_NCQ)        printf(" ncq");
-        if (val & HOST_CAP_SNTF)       printf(" sntf");
-        if (val & HOST_CAP_MPS)        printf(" mps");
-        if (val & HOST_CAP_SSS)        printf(" sss");
-        if (val & HOST_CAP_ALPM)       printf(" alpm");
-        if (val & HOST_CAP_LED)        printf(" led");
-        if (val & HOST_CAP_CLO)        printf(" clo");
-        if (val & HOST_CAP_ONLY)       printf(" ahci_only");
-        if (val & HOST_CAP_PMP)        printf(" pmp");
-        if (val & HOST_CAP_FBS)        printf(" fbs");
-        if (val & HOST_CAP_PIO_MULTI)  printf(" pio_multi");
-        if (val & HOST_CAP_SSC)        printf(" ssc");
-        if (val & HOST_CAP_PART)       printf(" part");
-        if (val & HOST_CAP_CCC)        printf(" ccc");
-        if (val & HOST_CAP_EMS)        printf(" ems");
-        if (val & HOST_CAP_SXS)        printf(" sxs");
-        printf(" cmd_slots:%d", (u16) ((val >> 8) & 0x1f) + 1);
-        printf(" ports:%d",     (u16) (val & 0x1f) + 1);
+        printf_nts(" -");
+        if (val & HOST_CAP_64)         printf_nts(" 64bit");
+        if (val & HOST_CAP_NCQ)        printf_nts(" ncq");
+        if (val & HOST_CAP_SNTF)       printf_nts(" sntf");
+        if (val & HOST_CAP_MPS)        printf_nts(" mps");
+        if (val & HOST_CAP_SSS)        printf_nts(" sss");
+        if (val & HOST_CAP_ALPM)       printf_nts(" alpm");
+        if (val & HOST_CAP_LED)        printf_nts(" led");
+        if (val & HOST_CAP_CLO)        printf_nts(" clo");
+        if (val & HOST_CAP_ONLY)       printf_nts(" ahci_only");
+        if (val & HOST_CAP_PMP)        printf_nts(" pmp");
+        if (val & HOST_CAP_FBS)        printf_nts(" fbs");
+        if (val & HOST_CAP_PIO_MULTI)  printf_nts(" pio_multi");
+        if (val & HOST_CAP_SSC)        printf_nts(" ssc");
+        if (val & HOST_CAP_PART)       printf_nts(" part");
+        if (val & HOST_CAP_CCC)        printf_nts(" ccc");
+        if (val & HOST_CAP_EMS)        printf_nts(" ems");
+        if (val & HOST_CAP_SXS)        printf_nts(" sxs");
+        printf_nts(" cmd_slots:%d", (u16) ((val >> 8) & 0x1f) + 1);
+        printf_nts(" ports:%d",     (u16) (val & 0x1f) + 1);
 
       } else if (i == HOST_CTL) {
-        printf(" -");
-        if (val & HOST_AHCI_EN)        printf(" ahci_enabled");
-        if (val & HOST_IRQ_EN)         printf(" irq_enabled");
-        if (val & HOST_RESET)          printf(" resetting");
+        printf_nts(" -");
+        if (val & HOST_AHCI_EN)        printf_nts(" ahci_enabled");
+        if (val & HOST_IRQ_EN)         printf_nts(" irq_enabled");
+        if (val & HOST_RESET)          printf_nts(" resetting");
 
       } else if (i == HOST_CAP2) {
-        printf(" -");
-        if (val & HOST_CAP2_BOH)       printf(" boh");
-        if (val & HOST_CAP2_NVMHCI)    printf(" nvmhci");
-        if (val & HOST_CAP2_APST)      printf(" apst");
+        printf_nts(" -");
+        if (val & HOST_CAP2_BOH)       printf_nts(" boh");
+        if (val & HOST_CAP2_NVMHCI)    printf_nts(" nvmhci");
+        if (val & HOST_CAP2_APST)      printf_nts(" apst");
       }
-      printf("\n");
+      printf_nts("\n");
     }
   }
@@ -287,5 +289,5 @@
 int ahci_restore_bios_config(AD_INFO *ai)
 {
-  ddprintf("restoring AHCI BIOS configuration\n");
+  ddprintf("ahci_restore_bios_config: restoring AHCI BIOS configuration on adapter %d\n", ad_no(ai));
 
   /* Restore saved BIOS configuration; please note that HOST_CTL is restored
@@ -349,5 +351,5 @@
 int ahci_restore_initial_config(AD_INFO *ai)
 {
-  ddprintf("restoring initial configuration\n");
+  ddprintf("ahci_restore_initial_config: restoring initial configuration on adapter %d\n", ad_no(ai));
 
   /* restore saved BIOS configuration */
@@ -448,6 +450,63 @@
 
   /* couldn't enable AHCI mode */
-  dprintf("failed to enable AHCI mode on adapter #%d\n", ad_no(ai));
+  dprintf("failed to enable AHCI mode on adapter %d\n", ad_no(ai));
   return(1);
+}
+
+int ahci_reset_controller(AD_INFO *ai)
+{
+    u32 tmp;
+    int timeout = 1000;
+
+    dprintf("controller reset starting on adapter %d\n", ad_no(ai));
+    /* we must be in AHCI mode, before using anything
+     * AHCI-specific, such as HOST_RESET.
+     */
+    ahci_enable_ahci(ai);
+
+    /* global controller reset */
+    tmp = readl(ai->mmio + HOST_CTL);
+    if ((tmp & HOST_RESET) == 0) {
+        writel(ai->mmio + HOST_CTL, tmp | HOST_RESET);
+        readl(ai->mmio + HOST_CTL); /* flush */
+    }
+
+    /*
+     * to perform host reset, OS should set HOST_RESET
+     * and poll until this bit is read to be "0".
+     * reset must complete within 1 second, or
+     * the hardware should be considered fried.
+     */
+    while (((tmp = readl(ai->mmio + HOST_CTL)) & HOST_RESET) == HOST_RESET) {
+        mdelay(10);
+        timeout -= 10;
+        if (timeout <= 0) {
+          dprintf("controller reset failed (0x%lx)\n", tmp);
+          return(-1);
+        }
+    }
+
+    /* turn on AHCI mode */
+    ahci_enable_ahci(ai);
+
+    /* Some registers might be cleared on reset.  Restore
+     * initial values.
+     */
+    ahci_restore_initial_config(ai);
+
+	if (ai->pci->vendor == PCI_VENDOR_ID_INTEL) {
+		u32 tmp16 = 0;
+
+        ddprintf("ahci_reset_controller: intel detected\n");
+		/* configure PCS */
+		pci_read_conf(ai->bus, ai->dev_func, 0x92, sizeof(u16), &tmp16);
+		if ((tmp16 & ai->port_map) != ai->port_map) {
+            ddprintf("ahci_reset_controller: updating PCS %x/%x\n", (u16)tmp16, ai->port_map);
+			tmp16 |= ai->port_map;
+			pci_write_conf(ai->bus, ai->dev_func, 0x92, sizeof(u16), tmp16);
+		}
+	}
+
+    return 0;
 }
 
@@ -487,4 +546,6 @@
   }
 
+  ahci_reset_controller(ai);
+
   if (ahci_enable_ahci(ai)) {
     goto exit_port_scan;
@@ -492,7 +553,13 @@
 
   /* perform port scan */
-  dprintf("scanning ports on adapter #%d\n", ad_no(ai));
+  dprintf("ahci_scan_ports: scanning ports on adapter %d\n", ad_no(ai));
   for (p = 0; p < AHCI_MAX_PORTS; p++) {
     if (ai->port_map & (1UL << p)) {
+
+      dprintf("ahci_scan_ports: Wait till not busy on port %d\n", p);
+      /* wait until all active commands have completed on this port */
+      while (ahci_port_busy(ai, p)) {
+        msleep(250);
+      }
 
       if (!init_complete) {
@@ -506,5 +573,5 @@
         rc = ahci_reset_port(ai, p, 0);
       } else {
-        ddprintf("(re)starting port #%d\n", p);
+        ddprintf("ahci_scan_ports: (re)starting port %d\n", p);
         ahci_stop_port(ai, p);
         rc = ahci_start_port(ai, p, 0);
@@ -517,5 +584,5 @@
 
       /* this port seems to have a device attached and ready for commands */
-      ddprintf("port #%d seems to be attached to a device; probing...\n", p);
+      ddprintf("ahci_scan_ports: port %d seems to be attached to a device; probing...\n", p);
 
       /* Get ATA(PI) identity. The so-called signature gives us a hint whether
@@ -575,5 +642,5 @@
   int i;
 
-  dprintf("completing initialization of adapter #%d\n", ad_no(ai));
+  dprintf("ahci_complete_init: completing initialization of adapter #%d\n", ad_no(ai));
 
   /* register IRQ handlers; each IRQ level is registered only once */
@@ -609,7 +676,8 @@
     if (ai->port_map & (1UL << p)) {
       if (init_reset) {
+        dprintf("ahci_complete_init: resetting port %d\n", p);
         ahci_reset_port(ai, p, 1);
       } else {
-        dprintf("restarting port #%d\n", p);
+        dprintf("ahci_complete_init: restarting port #%d\n", p);
         ahci_stop_port(ai, p);
         ahci_start_port(ai, p, 1);
@@ -648,9 +716,10 @@
   u8 _far *port_mmio = port_base(ai, p);
   u32 tmp;
-  int timeout = 5000;
-
-  dprintf("resetting port %d.%d\n", ad_no(ai), p);
+  int timeout;
+
+  dprintf("ahci_reset_port: resetting port %d.%d\n", ad_no(ai), p);
   if (debug > 1) {
-    printf("command engine status:\n");
+    printf(" PORT_CMD       = 0x%lx\n", readl(port_mmio + PORT_CMD));
+    printf("ahci_reset_port: command engine status:\n");
     printf(" PORT_SCR_ACT   = 0x%lx\n", readl(port_mmio + PORT_SCR_ACT));
     printf(" PORT_CMD_ISSUE = 0x%lx\n", readl(port_mmio + PORT_CMD_ISSUE));
@@ -673,14 +742,19 @@
   writel(port_mmio + PORT_SCR_ERR, tmp);
 
+  /* power up and spin up the drive if necessary */
+  if (((tmp = readl(port_mmio + PORT_CMD)) & (PORT_CMD_SPIN_UP|PORT_CMD_POWER_ON)) != (PORT_CMD_SPIN_UP|PORT_CMD_POWER_ON)) {
+    writel(port_mmio + PORT_CMD, tmp | PORT_CMD_SPIN_UP | PORT_CMD_POWER_ON);
+  }
+
   /* set link speed and power management options */
-  ddprintf("setting link speed and power management options\n");
-  tmp = readl(port_mmio + PORT_SCR_CTL) & ~0x00000ff0UL;
+  ddprintf("ahci_reset_port: setting link speed and power management options\n");
+  tmp = readl(port_mmio + PORT_SCR_CTL) & ~0x00000fffUL; //DAZ
   tmp |= ((u32) link_speed[ad_no(ai)][p] & 0x0f) << 4;
   tmp |= ((u32) link_power[ad_no(ai)][p] & 0x0f) << 8;
-  writel(port_mmio + PORT_SCR_CTL, tmp);
+  //DAZ writel(port_mmio + PORT_SCR_CTL, tmp);
 
   /* issue COMRESET on the port */
-  ddprintf("issuing COMRESET on port\n");
-  tmp = readl(port_mmio + PORT_SCR_CTL) & ~0x0000000fUL;
+  ddprintf("ahci_reset_port: issuing COMRESET on port %d\n", p);
+  //DAZ tmp = readl(port_mmio + PORT_SCR_CTL) & ~0x0000000fUL;
   writel(port_mmio + PORT_SCR_CTL, tmp | 1);
   readl(port_mmio + PORT_SCR_CTL);  /* flush */
@@ -693,4 +767,5 @@
 
   /* wait for communication to be re-established after port reset */
+  timeout = 5000;
   while (((tmp = readl(port_mmio + PORT_SCR_STAT)) & 3) != 3) {
     mdelay(10);
@@ -708,8 +783,9 @@
 
   /* start port so we can receive the COMRESET FIS */
-  ddprintf("starting port again\n");
+  ddprintf("ahci_reset_port: starting port %d again\n", p);
   ahci_start_port(ai, p, ei);
 
   /* wait for device to be ready ((PxTFD & (BSY | DRQ | ERR)) == 0) */
+  timeout = 5000;
   while (((tmp = readl(port_mmio + PORT_TFDATA)) & 0x89) != 0) {
     mdelay(10);
@@ -722,5 +798,5 @@
     }
   }
-  ddprintf(" PORT_TFDATA   = 0x%lx\n", readl(port_mmio + PORT_TFDATA));
+  ddprintf("ahci_reset_port: PORT_TFDATA   = 0x%lx\n", readl(port_mmio + PORT_TFDATA));
 
   return(0);
@@ -734,8 +810,24 @@
   u8 _far *port_mmio = port_base(ai, p);
   u32 status;
-
+  //int timeout;
+
+  dprintf("ahci_start_port %d.%d\n", ad_no(ai), p);
   /* check whether device presence is detected and link established */
+
+#if 0
+  /* wait for communication to be re-established after port reset */
+  timeout = 5000;
+  while (((status = readl(port_mmio + PORT_SCR_STAT)) & 3) != 3) {
+    mdelay(10);
+    timeout -= 10;
+    if (timeout <= 0) {
+      dprintf("ahci_start_port #%d (PORT_SCR_STAT = 0x%lx)\n", p, status);
+      return(-1);
+    }
+  }
+#endif
+
   status = readl(port_mmio + PORT_SCR_STAT);
-  ddprintf(" PORT_SCR_STAT = 0x%lx\n", status);
+  ddprintf("ahci_start_port: PORT_SCR_STAT = 0x%lx\n", status);
   if ((status & 0xf) != 3) {
     return(-1);
@@ -744,5 +836,5 @@
   /* clear SError, if any */
   status = readl(port_mmio + PORT_SCR_ERR);
-  ddprintf(" PORT_SCR_ERR  = 0x%lx\n", status);
+  ddprintf("ahci_start_port: PORT_SCR_ERR  = 0x%lx\n", status);
   writel(port_mmio + PORT_SCR_ERR, status);
 
@@ -827,4 +919,6 @@
   u32 tmp;
   int rc;
+
+  dprintf("ahci_stop_port %d.%d\n", ad_no(ai), p);
 
   /* disable port interrupts */
Index: trunk/src/os2ahci/libc.c
===================================================================
--- trunk/src/os2ahci/libc.c	(revision 147)
+++ trunk/src/os2ahci/libc.c	(revision 148)
@@ -58,5 +58,4 @@
                                                 ULONG parm2);
 static int              mdelay_cal_end         (void);
-static void             printf_nts             (const char *fmt, ...);
 
 /* ------------------------ global/static variables ------------------------ */
@@ -284,5 +283,5 @@
 
   spin_lock(com_lock);
-  
+
   if (ts) {
     /* include timestamp */
@@ -351,5 +350,5 @@
  * Print messages to COM port with no time stamp
  */
-static void printf_nts(const char *fmt, ...)
+void printf_nts(const char *fmt, ...)
 {
   va_list va;
@@ -509,5 +508,5 @@
       len -= l;
     }
-    
+
     pos += sg_list[i].XferBufLen;
   }
Index: trunk/src/os2ahci/os2ahci.c
===================================================================
--- trunk/src/os2ahci/os2ahci.c	(revision 147)
+++ trunk/src/os2ahci/os2ahci.c	(revision 148)
@@ -26,6 +26,4 @@
 
 #include "os2ahci.h"
-#include "bldday.h"
-
 #include "ioctl.h"
 
@@ -357,13 +355,13 @@
   ciprintf(init_msg, drv_name, VERSION / 100, VERSION % 100);
 
-#ifdef ECS_BUILD
-  ciprintf("This driver is licensed for use only in conjunction with eComStation.\n");
-#else
-  ciprintf("This is the Open Watcom build.\n");
-#endif
+//#ifdef ECS_BUILD
+//  ciprintf("This driver is licensed for use only in conjunction with eComStation.\n");
+//#else
+//  ciprintf("This is the Open Watcom build.\n");
+//#endif
 
   if (debug) {
     /* initialize com port for debug output */
-    init_com();
+    //DAZ init_com();
   }
 
@@ -781,4 +779,7 @@
       }
       init_complete = 1;
+
+      /* DAZ turn off COM port output */
+      com_base = 0;
 
       /* release all adapters */
Index: trunk/src/os2ahci/os2ahci.def.template
===================================================================
--- trunk/src/os2ahci/os2ahci.def.template	(revision 147)
+++ trunk/src/os2ahci/os2ahci.def.template	(revision 148)
@@ -1,4 +1,3 @@
 library os2ahci
-Description '$@#Mensys:0.0.0#@##1## 2011/05/02 11:41:00      ECSDEVEL::::00::@@AHCI Driver. (c) Mensys BV 2011'
 protmode
 
Index: trunk/src/os2ahci/os2ahci.h
===================================================================
--- trunk/src/os2ahci/os2ahci.h	(revision 147)
+++ trunk/src/os2ahci/os2ahci.h	(revision 148)
@@ -157,5 +157,5 @@
 #define DevHelp_FreeSpinLock(sph)      0
 
-#define DevHelp_AquireSpinLock(sph)    if ((sph) != 0)                \
+#define DevHelp_AcquireSpinLock(sph)    if ((sph) != 0)                \
                                          panic("recursive spinlock"); \
                                        (sph) = disable()
@@ -168,5 +168,5 @@
 
 /* shortcut macros */
-#define spin_lock(sl)     DevHelp_AquireSpinLock(sl)
+#define spin_lock(sl)     DevHelp_AcquireSpinLock(sl)
 #define spin_unlock(sl)   DevHelp_ReleaseSpinLock(sl)
 
@@ -476,4 +476,5 @@
 extern void        vfprintf      (const char *fmt, va_list va);
 extern void _cdecl printf        (const char *fmt, ...);
+extern void _cdecl printf_nts    (const char *fmt, ...);
 extern void        cprintf       (const char *fmt, ...);
 extern void        phex          (const void _far *p, int len, const char *fmt, ...);
@@ -500,6 +501,6 @@
 extern void        trace_exit    (void);
 extern void        trace_write   (u8 _far *s, int len);
-extern u16         trace_read    (void _far *buf, u16 cb_buf);
-extern u16         trace_bytes_avail(void);
+extern u16         trace_read    (u8 _far *buf, u16 cb_buf);
+//NOT_USED extern u16         trace_bytes_avail(void);
 extern u16         trace_char_dev(RP_RWV _far *rwrb);
 
@@ -511,4 +512,8 @@
 extern char     *vendor_from_id (u16 vendor);
 extern char     *device_from_id (u16 device);
+UCHAR pci_read_conf    (UCHAR bus, UCHAR dev_func, UCHAR indx,
+                        UCHAR size, ULONG _far *val);
+UCHAR pci_write_conf   (UCHAR bus, UCHAR dev_func, UCHAR indx, UCHAR size,
+                        ULONG val);
 
 /* ctxhook.c */
Index: trunk/src/os2ahci/pci.c
===================================================================
--- trunk/src/os2ahci/pci.c	(revision 147)
+++ trunk/src/os2ahci/pci.c	(revision 148)
@@ -147,8 +147,4 @@
 
 static void  add_pci_device   (PCI_ID *pci_id, OH_DATA _far *data);
-static UCHAR pci_read_conf    (UCHAR bus, UCHAR dev_func, UCHAR indx,
-                               UCHAR size, ULONG _far *val);
-static UCHAR pci_write_conf   (UCHAR bus, UCHAR dev_func, UCHAR indx, UCHAR size,
-                               ULONG val);
 static int   oemhlp_call      (UCHAR subfunction, OH_PARM _far *parm,
                                OH_DATA _far *data);
@@ -698,5 +694,5 @@
     ret = RMAllocResource(rm_drvh, ad_info->rm_bars + i, &resource);
     if (ret != RMRC_SUCCESS) {
-      cprintf("%s: couldn't register [MM]IO region (rc = %s)\n", 
+      cprintf("%s: couldn't register [MM]IO region (rc = %s)\n",
               drv_name, rmerr(ret));
       goto add_pci_fail;
@@ -813,5 +809,5 @@
  * Read PCI configuration space register
  */
-static UCHAR pci_read_conf(UCHAR bus, UCHAR dev_func, UCHAR indx, UCHAR size,
+UCHAR pci_read_conf(UCHAR bus, UCHAR dev_func, UCHAR indx, UCHAR size,
                            ULONG _far *val)
 {
@@ -838,5 +834,5 @@
  * Write PCI configuration space register
  */
-static UCHAR pci_write_conf(UCHAR bus, UCHAR dev_func, UCHAR indx, UCHAR size,
+UCHAR pci_write_conf(UCHAR bus, UCHAR dev_func, UCHAR indx, UCHAR size,
                             ULONG val)
 {
Index: trunk/src/os2ahci/trace.c
===================================================================
--- trunk/src/os2ahci/trace.c	(revision 147)
+++ trunk/src/os2ahci/trace.c	(revision 148)
@@ -42,5 +42,5 @@
   u16 writep;      /* current write offset in buffer */
   u16 readp;       /* current read offset in buffer */
-  int empty;       /* != 0 if buffer is empty */
+  u16 mask;        /* The mask for wrapping the buffer pointers */
 } ahci_trace_buf;
 
@@ -49,5 +49,5 @@
 /******************************************************************************
  * initialize AHCI circular trace buffer
- * 
+ *
  * NOTE: this func must be called during INIT time since it allocates
  *       a GDT selector for the trace ring buffer
@@ -60,5 +60,5 @@
   ahci_trace_buf.writep = 0;
   ahci_trace_buf.readp = 0;
-  ahci_trace_buf.empty = 1;
+  ahci_trace_buf.mask = AHCI_TRACE_BUF_SIZE - 1;
 
   if (ahci_trace_buf.phys_addr == 0) {
@@ -95,6 +95,6 @@
 
   }
-  
-  
+
+
 }
 
@@ -126,38 +126,35 @@
  * Note: This func wraps the buffer if necessary, so the caller does not
  *       need to call repeatedly until everything is written.
- *       
+ *
  */
 void trace_write(u8 _far *s, int len)
 {
-  u16 cbw; /* bytes we can store before buffer wrap occurrs */
-  u16 cb;
-  USHORT awake_cnt;
-  
+  //NOT USED USHORT awake_cnt;
+
   if (ahci_trace_buf.phys_addr == 0) {
     /* tracing not active */
     return;
   }
-  
-  cbw = AHCI_TRACE_BUF_SIZE - ahci_trace_buf.writep;
-
-  while (len > 0) {
-    cb = cbw < len ? cbw : len;
-    if (cb && ahci_trace_buf.empty) {
-      ahci_trace_buf.empty = 0;
-    }
-    memcpy(ahci_trace_buf.tbuf + ahci_trace_buf.writep, s, cb);
-    s += cb;
-    ahci_trace_buf.writep += cb;
-    len -= cb;
-
-    /* wrap? */
-    if (ahci_trace_buf.writep >= AHCI_TRACE_BUF_SIZE) {
-      ahci_trace_buf.writep = 0;
-      cbw = AHCI_TRACE_BUF_SIZE;
-    }
-  }
-       
+
+  while (len) {
+    /* The following line causes filling the trace buffer to stop when full.
+     * Comment the following line to keep filling and see the last buffer of data.
+     * Uncomment the following line to stop filling / see the first buffer of data.
+     */
+    if ( ((ahci_trace_buf.writep+1) & ahci_trace_buf.mask) == ahci_trace_buf.readp ) break; /* buffer is full */
+
+    ahci_trace_buf.tbuf[ahci_trace_buf.writep] = *s++;
+    ahci_trace_buf.writep++;
+    ahci_trace_buf.writep &= ahci_trace_buf.mask;
+
+    /* keep the latest full buffer of information */
+    if (ahci_trace_buf.writep == ahci_trace_buf.readp)
+      ahci_trace_buf.readp = (ahci_trace_buf.readp+1) & ahci_trace_buf.mask;
+
+    len--;
+  }
+
   /* wake up processes waiting for data from trace buffer */
-  DevHelp_ProcRun(ahci_trace_buf.phys_addr, &awake_cnt);
+  //NOT_USED DevHelp_ProcRun(ahci_trace_buf.phys_addr, &awake_cnt);
 
 }
@@ -167,46 +164,25 @@
  * returns the number of bytes written to the caller's buffer
  *
- * NOTE: the caller is expected to call this func repeatedly 
+ * NOTE: the caller is expected to call this func repeatedly
  *       (up to two times) until it returns 0
  */
-u16 trace_read(void _far *buf, u16 cb_buf)
+u16 trace_read(u8 _far *buf, u16 cb_buf)
 {
   u16 cb_avail;
   u16 cb_read;
 
-  if (ahci_trace_buf.phys_addr == NULL || ahci_trace_buf.empty) {
-    return 0;
-  }
-  
-  /* get number of bytes in buffer */
-  if (ahci_trace_buf.readp < ahci_trace_buf.writep) {
-    /* read pointer is smaller than write pointer; no wrap in between */
-    cb_avail = ahci_trace_buf.writep - ahci_trace_buf.readp;
-  } else {
-    /* read pointer is larger than (or same as) write pointer; 
-     * read up to buffer end and let caller come again (if necessary)
-     */
-    cb_avail = AHCI_TRACE_BUF_SIZE - ahci_trace_buf.readp;
-  }
-
-  /* determine number of bytes we actually can return */
-  cb_read = cb_buf > cb_avail ? cb_avail : cb_buf;
-
-  memcpy(buf, ahci_trace_buf.tbuf + ahci_trace_buf.readp, cb_read);
-  
-  /* update read pointer */
-  ahci_trace_buf.readp += cb_read;
-  if (ahci_trace_buf.readp >= AHCI_TRACE_BUF_SIZE) {
-    ahci_trace_buf.readp = 0;
-  }
-  
-  /* check if buffer is empty now */
-  if (ahci_trace_buf.readp == ahci_trace_buf.writep) {
-    ahci_trace_buf.empty = 1;
-  }
-     
+  if (ahci_trace_buf.phys_addr == NULL) return 0;
+
+  for (cb_read = 0; cb_read < cb_buf && ( ahci_trace_buf.readp != ahci_trace_buf.writep ); cb_read++)
+  {
+    *buf++ = ahci_trace_buf.tbuf[ahci_trace_buf.readp];
+    ahci_trace_buf.readp++;
+    ahci_trace_buf.readp &= ahci_trace_buf.mask;
+  }
+
   return cb_read;
 }
 
+#ifdef NOT_USED
 /******************************************************************************
  * return number of bytes we can read from the trace buffer
@@ -214,8 +190,6 @@
 u16 trace_bytes_avail(void)
 {
-  
-  if (ahci_trace_buf.empty) {
-    return 0;
-  }
+
+  if (ahci_trace_buf.writep == ahci_trace_buf.readp ) return 0; /* buffer is empty */
 
   if (ahci_trace_buf.readp <= ahci_trace_buf.writep) {
@@ -231,5 +205,5 @@
   return AHCI_TRACE_BUF_SIZE - ahci_trace_buf.readp + ahci_trace_buf.writep;
 }
-
+#endif
 
 /******************************************************************************
@@ -243,14 +217,13 @@
   USHORT mode = 0;
 
-  /* block process until data is available in the trace buffer;
-   * see also comment in ioctl.c next to DevHelp_ProcBlock
-   * concerning spin_lock and ProcBlock interaction
-   */
-  while (ahci_trace_buf.empty) {
+  spin_lock(com_lock);
+  #ifdef NOT_USED
+  /* block process until data is available in the trace buffer. */
+  while (ahci_trace_buf.writep == ahci_trace_buf.readp ) { /* buffer is empty */
     spin_lock(com_lock);
-#   ifndef OS2AHCI_SMP
+      #ifndef OS2AHCI_SMP
       com_lock = 0;
-#   endif
-      if (DevHelp_ProcBlock((ULONG) ahci_trace_buf.phys_addr, 
+      #endif
+      if (DevHelp_ProcBlock((ULONG) ahci_trace_buf.phys_addr,
                             (ULONG) -1, 0) == WAIT_INTERRUPTED) {
         /* user pressed Ctrl+C or whatever */
@@ -260,4 +233,5 @@
     spin_lock(com_lock);
   }
+  #endif
 
   /* get pointer to caller's buffer */
Index: trunk/src/os2ahci/version.h
===================================================================
--- trunk/src/os2ahci/version.h	(revision 147)
+++ 	(revision )
@@ -1,17 +1,0 @@
-/******************************************************************************
- * version.h - define version numbers and strings for OS2AHCI.ADD
- *
- * Copyright (c) 2011 thi.guten Software Development
- * Copyright (c) 2011 Mensys B.V.
- *
- * Authors: Christian Mueller, Markus Thielen
- *
- *
- * NOTE: this is kept in a separate file for easier parsing by
- *       bldlvl.cmd (which creates the bldlevel signature)
- *
- */
-
-
-#define VERSION            125       /* driver version (2 implied decimals) */
-
Index: trunk/src/os2ahci/wmakefile
===================================================================
--- trunk/src/os2ahci/wmakefile	(revision 147)
+++ 	(revision )
@@ -1,223 +1,0 @@
-###############################################################################
-# wmakefile - makefile for os2ahci driver using WATCOM compiler
-#
-# Copyright (c) 2010 Christian Mueller, Markus Thielen.
-# Parts copied from/inspired by the Linux AHCI driver;
-# those parts are (c) Linux AHCI/ATA maintainers
-#
-#  This program is free software; you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#  GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program; if not, write to the Free Software
-#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-###############################################################################
-# Calling Syntax
-#
-# wmake -ms -f wmakefile
-#
-# NOTE: we use MS compatibility mode (-ms) so we can use a syntax similar
-#       to the well known nmake syntax.
-#
-
-###############################################################################
-# wmake directives
-.HOLD # do not prompt for deletion of created files on error; leave them alone
-
-
-
-###############################################################################
-# Environment
-
-
-# main path to OS/2 DDK; this needs to be set before this makefile will work
-!ifndef DDK
-DDK          = i:\ddk
-!endif
-
-# main path to WATCOM installation
-!ifndef WATCOM
-WATCOM       = i:\watcom
-!endif
-
-CC_INCLUDE   = -I..\include \
-               -I$(DDK)\base\h \
-               -I$(DDK)\base\ibmh \
-               -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
-
-LIB_DIRS     = $(DDK)\base\lib\ \
-               $(DDK)\base\src\dev\dasd\devhlp\ \
-               $(DDK)\base\src\dev\thinkpad\dockii\apmcalls\ \
-
-
-
-
-###############################################################################
-# Tool Chain
-#
-# 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.
-#
-
-
-
-
-#
-# Specify Linker
-# Note: Using ALP with Wlink produces an oversized image, possibly due to
-#       the location of BSS segments. Putting the BSS segments after the CODE
-#       segments in init.asm and/or segment ordering in the Wlink response file
-#       seems not to work when using ALP.
-#
-
-#LINKER=ibm
-LINKER=watcom
-
-#
-# Specify Assembler
-# Note: This will only be of influence on assembling .asm files.
-#       C inline _asm statements will use Wasm.
-#
-
-#AS         = $(DDK)\tools\alp.exe
-#AS         = jwasm -Cp
-AS         = wasm
-
-
-CC         = wcc
-LD         = $(DDK)\base\tools\link.exe
-BLDLEVEL   = cmd.exe /c ..\..\tools\bldlvl.cmd
-BLDDATE    = cmd.exe /c ..\..\tools\blddate.cmd
-MAPSYM     = $(DDK)\base\tools\mapsym.exe
-
-#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
-
-###############################################################################
-# Main dependencies
-
-TARGET   = os2ahci.add
-
-#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
-
-OBJS     = init.obj libc.obj os2ahci.obj pci.obj ahci.obj ata.obj atapi.obj \
-           ctxhook.obj trace.obj ioctl.obj apm.obj
-
-INCS     = os2ahci.h ahci.h version.h
-
-
-all: $(TARGET)
-
-clean:
-        rm -f $(OBJS) $(TARGET) *.cod *.lst *.def *.map *.sym *.err *.lnk \
-                bldday.h
-
-###############################################################################
-# Object/source dependencies
-
-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
-
-###############################################################################
-# Action definitions (compile/link commands)
-
-# 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)
-
-bldday.h:
-        $(BLDDATE) > bldday.h
-
-.asm.obj:
-        $(AS) $(AFLAGS) $(AS_INCLUDE) $*.asm
-        wdis -l $*.obj
-
-.c.obj:
-        $(CC) $(CFLAGS) $(CC_INCLUDE) $*.c
-        wdis -l $*.obj
-
-os2ahci.def:
-        $(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
-
