Index: trunk/src/os2ahci/Makefile
===================================================================
--- trunk/src/os2ahci/Makefile	(revision 110)
+++ trunk/src/os2ahci/Makefile	(revision 111)
@@ -117,6 +117,8 @@
 # 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) Makefile
+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
 
 bldday.h:
Index: trunk/src/os2ahci/ahci.c
===================================================================
--- trunk/src/os2ahci/ahci.c	(revision 110)
+++ trunk/src/os2ahci/ahci.c	(revision 111)
@@ -542,5 +542,6 @@
       if (rc == 0) {
         /* we have a valid IDENTIFY or IDENTIFY_PACKET response */
-        ddphex(id_buf, 512, "ATA_IDENTIFY%s results:\n", (is_ata) ? "" : "_PACKET");
+        ddphex(id_buf, 512, TRACE_MINOR_ATA_IDENTIFY,
+               "ATA_IDENTIFY%s results:\n", (is_ata) ? "" : "_PACKET");
         ahci_setup_device(ai, p, 0, id_buf);
       } else {
@@ -1550,5 +1551,5 @@
   dphex(((IORB_ADAPTER_PASSTHRU _far *) iorb)->pControllerCmd,
         ((IORB_ADAPTER_PASSTHRU _far *) iorb)->ControllerCmdLen,
-        "ahci_execute_cdb(%d.%d.%d): ", a, p, d);
+        TRACE_MINOR_EXEC_CDB, "ahci_execute_cdb(%d.%d.%d): ", a, p, d);
 
   if (ad_infos[a].ports[p].devs[d].atapi) {
@@ -1572,5 +1573,5 @@
   dphex(((IORB_ADAPTER_PASSTHRU _far *) iorb)->pControllerCmd,
         ((IORB_ADAPTER_PASSTHRU _far *) iorb)->ControllerCmdLen,
-        "ahci_execute_ata(%d.%d.%d): ", a, p, d);
+        TRACE_MINOR_EXEC_ATA, "ahci_execute_ata(%d.%d.%d): ", a, p, d);
 
   ahci_exec_iorb(iorb, 0, ata_execute_ata);
Index: trunk/src/os2ahci/ata.c
===================================================================
--- trunk/src/os2ahci/ata.c	(revision 110)
+++ trunk/src/os2ahci/ata.c	(revision 111)
@@ -279,11 +279,13 @@
   if (debug >= 2) {
     printf("ATA command for %d.%d.%d:\n", ad_no(ai), p, d);
-    phex(cmd_hdr, offsetof(AHCI_CMD_HDR, reserved), "cmd_hdr:   ");
-    phex(&ata_cmd, sizeof(ata_cmd), "ata_cmd:   ");
+    phex(cmd_hdr, offsetof(AHCI_CMD_HDR, reserved), 
+         TRACE_MINOR_CMD_HDR, "cmd_hdr:   ");
+    phex(&ata_cmd, sizeof(ata_cmd), TRACE_MINOR_ATA_CMD, "ata_cmd:   ");
     if (atapi_cmd != NULL) {
-      phex(atapi_cmd, atapi_cmd_len, "atapi_cmd: ");
+      phex(atapi_cmd, atapi_cmd_len, TRACE_MINOR_ATAPI_CMD, "atapi_cmd: ");
     }
     if (n > 0) {
-      phex(cmd_tbl->sg_list, sizeof(*cmd_tbl->sg_list) * n, "sg_list:   ");
+      phex(cmd_tbl->sg_list, sizeof(*cmd_tbl->sg_list) * n, 
+           TRACE_MINOR_SG_LIST, "sg_list:   ");
     }
   }
Index: trunk/src/os2ahci/atapi.c
===================================================================
--- trunk/src/os2ahci/atapi.c	(revision 110)
+++ trunk/src/os2ahci/atapi.c	(revision 111)
@@ -340,5 +340,5 @@
   ATAPI_SENSE_DATA *psd = (ATAPI_SENSE_DATA *) aws->buf;
 
-  dphex(psd, sizeof(*psd), "sense buffer:\n");
+  dphex(psd, sizeof(*psd), TRACE_MINOR_SENSE_BUF, "sense buffer:\n");
 
   if ((iorb->RequestControl & IORB_REQ_STATUSBLOCK) &&
Index: trunk/src/os2ahci/libc.c
===================================================================
--- trunk/src/os2ahci/libc.c	(revision 110)
+++ trunk/src/os2ahci/libc.c	(revision 111)
@@ -58,4 +58,5 @@
                                                 ULONG parm2);
 static int              mdelay_cal_end         (void);
+static int              trace_enabled          (void);
 
 /* ------------------------ global/static variables ------------------------ */
@@ -98,4 +99,8 @@
 static ULONG heap_phys_addr;
 
+/* global info segment */
+volatile PGINFOSEG gis;
+
+
 /* ----------------------------- start of code ----------------------------- */
 
@@ -105,8 +110,16 @@
 void init_libc(void)
 {
+  PSEL p;
+
   DevHelp_CreateSpinLock(&mem_lock);
   DevHelp_CreateSpinLock(&com_lock);
 
   DevHelp_VirtToPhys(heap_buf, &heap_phys_addr);
+
+  /* get global info segment */
+  if (DevHelp_GetDOSVar(DHGETDOSV_SYSINFOSEG, 0, (PPVOID) &p) == 0) {
+    gis = (PGINFOSEG) ((u32) *p << 16);
+  }
+
 }
 
@@ -263,8 +276,16 @@
   static char buf[1024];
   char *s;
+  int len;
 
   spin_lock(com_lock);
 
-  vsprintf(buf, fmt, va);
+  len = vsprintf(buf, fmt, va);
+
+   if (com_base == 0) {
+    /* write debug message to trace buffer, not COM port */
+    trace(debug, len, buf);
+    spin_unlock(com_lock);
+    return;
+  }
 
   /* write debug message to serial port */
@@ -329,5 +350,5 @@
   vsprintf(buf, fmt, va);
 
-  if (debug) {
+  if (debug && com_base != 0) {
     /* print the same message to COM1 as well */
     printf("%s", buf);
@@ -346,5 +367,5 @@
  * Print hex buffer to COM port.
  */
-void phex(const void _far *p, int len, const char *fmt, ...)
+void phex(const void _far *p, int len, u16 trace_minor_code, const char *fmt, ...)
 {
   va_list va;
@@ -353,4 +374,16 @@
 
   if (!debug) {
+    return;
+  }
+
+  if (!com_base) {
+    /* dump to kernel trace buffer, not serial port;
+     * just dump the buffer, it is formatted by TRACEFMT 
+     *
+     * NOTE: writing the header to the trace buffer causes
+     *       the trace facility to hick up and swallow the
+     *       binary data that follows...
+     */
+    trace(trace_minor_code, len, buf);
     return;
   }
@@ -705,15 +738,13 @@
 void msleep(u32 millies)
 {
-  volatile PGINFOSEG gis;
   ULONG start;
   ULONG end;
-  PSEL p;
-
-  if (DevHelp_GetDOSVar(DHGETDOSV_SYSINFOSEG, 0, (PPVOID) &p)) {
+
+  if (gis == NULL) {
     /* no global info segment; use mdelay() */
     mdelay(millies);
     return;
   }
-  gis = (PGINFOSEG) ((u32) *p << 16);
+
   start = gis->msecs;
   end = start + millies;
@@ -834,2 +865,38 @@
   return(mdelay_cal_status == MD_CALIBRATION_END);
 }
+
+/******************************************************************************
+ * is_trace_enabled - checks if kernel tracing is enabled
+ */
+int is_trace_enabled(void)
+{
+  int ret = 1; /* if global info seg is not present/known, 
+                * we enable tracing for now */
+
+  /* check global info segment's trace enabled bitmap if our
+   * major trace code is enabled 
+   */
+  if (gis) {
+    u8 trace_bitmap = gis->amecRAS[AHCI_TRACE_MAJOR / 8];
+    if (trace_bitmap & (0x80 >> (AHCI_TRACE_MAJOR % 8))) { 
+      ret = 1;
+    } else {
+      ret = 0;
+    }
+  }
+
+  return ret;
+}
+
+/******************************************************************************
+ * trace - write a buffer to the kernel trace buffer
+ */
+void trace(u16 minor_code, u16 cb_buf, const char _far *buf)
+{
+  if (!is_trace_enabled()) {
+    return;
+  }
+
+  DevHelp_RAS(AHCI_TRACE_MAJOR, minor_code, cb_buf, (PBYTE) buf);
+}
+
Index: trunk/src/os2ahci/os2ahci.c
===================================================================
--- trunk/src/os2ahci/os2ahci.c	(revision 110)
+++ trunk/src/os2ahci/os2ahci.c	(revision 111)
@@ -307,6 +307,6 @@
 
       default:
-        cprintf("unknown option: /%c - ignored\n", *s);
-        break;
+        cprintf("unknown option: /%c\n", *s);
+        goto init_fail;
       }
     }
Index: trunk/src/os2ahci/os2ahci.h
===================================================================
--- trunk/src/os2ahci/os2ahci.h	(revision 110)
+++ trunk/src/os2ahci/os2ahci.h	(revision 111)
@@ -250,4 +250,21 @@
 #define ANSI_CLR_WHITE  "\x1b[37m"
 #define ANSI_RESET      "\x1b[0m"
+
+/******************************************************************************
+ * trace constants
+ */
+#define AHCI_TRACE_MAJOR 0x00faU
+#define TRACE_MINOR_ATA_IDENTIFY  0x0020
+#define TRACE_MINOR_EXEC_CDB      0x0021
+#define TRACE_MINOR_EXEC_ATA      0x0022
+#define TRACE_MINOR_ATA_CMD       0x0023
+#define TRACE_MINOR_ATAPI_CMD     0x0024
+#define TRACE_MINOR_SG_LIST       0x0025
+#define TRACE_MINOR_SENSE_BUF     0x0026
+#define TRACE_MINOR_OEMHLP_PARM   0x0027
+#define TRACE_MINOR_OEMHLP_DATA   0x0028
+#define TRACE_MINOR_CMD_HDR       0x0029
+
+
 
 /* ------------------------ typedefs and structures ------------------------ */
@@ -447,5 +464,5 @@
 extern void        cprintf       (const char *fmt, ...);
 extern void        phex          (const void _far *p, int len,
-                                  const char *fmt, ...);
+                                  u16 trace_minor_code, const char *fmt, ...);
 extern size_t      strlen        (const char _far *s);
 extern char _far  *strcpy        (char _far *dst, const char _far *src);
@@ -465,4 +482,6 @@
 extern int         disable       (void);
 extern void        enable        (void);
+extern void        trace         (u16 minor_code, u16 cb_buf, 
+                                  const char _far *buf);
 
 /* pci.c */
@@ -488,4 +507,5 @@
 extern USHORT      ioctl_passthrough  (RP_GENIOCTL _far *ioctl);
 
+
 /* ---------------------------- global variables --------------------------- */
 
Index: trunk/src/os2ahci/pci.c
===================================================================
--- trunk/src/os2ahci/pci.c	(revision 110)
+++ trunk/src/os2ahci/pci.c	(revision 111)
@@ -937,6 +937,6 @@
   }
 
-  dddphex(parm, sizeof(*parm), "oemhlp_parm: ");
-  dddphex(data, sizeof(*data), "oemhlp_data: ");
+  dddphex(parm, sizeof(*parm), TRACE_MINOR_OEMHLP_PARM, "oemhlp_parm: ");
+  dddphex(data, sizeof(*data), TRACE_MINOR_OEMHLP_DATA, "oemhlp_data: ");
 
   if (ioctl.rph.Status & STERR) {
Index: trunk/src/os2ahci/version.h
===================================================================
--- trunk/src/os2ahci/version.h	(revision 110)
+++ trunk/src/os2ahci/version.h	(revision 111)
@@ -14,4 +14,4 @@
 
 
-#define VERSION            115       /* driver version (2 implied decimals) */
+#define VERSION            116       /* driver version (2 implied decimals) */
 
