Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Release 1.0
[palacios.git] / palacios / src / vmboot / rombios / rombios.c
index b8322d0..f754bad 100644 (file)
@@ -1,5 +1,6 @@
+//  -*- fundamental -*-
 /////////////////////////////////////////////////////////////////////////
-// $Id: rombios.c,v 1.1 2007/11/29 20:26:38 pdinda Exp $
+// $Id: rombios.c,v 1.16 2008/08/14 20:04:33 cuizheng Exp $
 /////////////////////////////////////////////////////////////////////////
 //
 //  Copyright (C) 2002  MandrakeSoft S.A.
@@ -58,7 +59,7 @@
 // $f859 ; INT 15h System Services Entry Point
 // $fa6e ; Character Font for 320x200 & 640x200 Graphics (lower 128 characters)
 // $fe6e ; INT 1Ah Time-of-day Service Entry Point
-// $fea5 ; INT 08h System Timer ISR Entry Point
+/// $fea5 ; INT 08h System Timer ISR Entry Point
 // $fef3 ; Initial Interrupt Vector Offsets Loaded by POST
 // $ff53 ; IRET Instruction for Dummy Interrupt Handler
 // $ff54 ; INT 05h Print Screen Service Entry Point
 //
 //   BCC Bug: find a generic way to handle the bug of #asm after an "if"  (fixed in 0.16.7)
 
-#define DEBUG_ROMBIOS      0
+#define DEBUG_ROMBIOS      1
 
+#define DEBUG_RAMDISK     0
 #define DEBUG_ATA          0
 #define DEBUG_INT13_HD     0
 #define DEBUG_INT13_CD     0
@@ -944,10 +946,10 @@ Bit16u cdrom_boot();
 
 #endif // BX_ELTORITO_BOOT
 
-static char bios_cvs_version_string[] = "$Revision: 1.1 $";
-static char bios_date_string[] = "$Date: 2007/11/29 20:26:38 $";
+static char bios_cvs_version_string[] = "$Revision: 1.16 $";
+static char bios_date_string[] = "$Date: 2008/08/14 20:04:33 $";
 
-static char CVSID[] = "$Id: rombios.c,v 1.1 2007/11/29 20:26:38 pdinda Exp $";
+static char CVSID[] = "$Id: rombios.c,v 1.16 2008/08/14 20:04:33 cuizheng Exp $";
 
 /* Offset to skip the CVS $Id: prefix */ 
 #define bios_version_string  (CVSID + 4)
@@ -957,7 +959,7 @@ static char CVSID[] = "$Id: rombios.c,v 1.1 2007/11/29 20:26:38 pdinda Exp $";
 #define BIOS_PRINTF_INFO     4
 #define BIOS_PRINTF_DEBUG    8
 #define BIOS_PRINTF_ALL      (BIOS_PRINTF_SCREEN | BIOS_PRINTF_INFO)
-#define BIOS_PRINTF_DEBHALT  (BIOS_PRINTF_SCREEN | BIOS_PRINTF_INFO | BIOS_PRINTF_HALT)
+#define BIOS_PRINTF_DEBHALT  (BIOS_PRINTF_SCREEN | BIOS_PRINTF_INFO | BIOS_PRINTF_HALT) 
 
 #define printf(format, p...)  bios_printf(BIOS_PRINTF_SCREEN, format, ##p)
 
@@ -965,13 +967,22 @@ static char CVSID[] = "$Id: rombios.c,v 1.1 2007/11/29 20:26:38 pdinda Exp $";
 // BX_DEBUG goes to INFO port until we can easily choose debug info on a 
 // per-device basis. Debug info are sent only in debug mode
 #if DEBUG_ROMBIOS
-#  define BX_DEBUG(format, p...)  bios_printf(BIOS_PRINTF_INFO, format, ##p)    
+#  define BX_DEBUG(format, p...)  bios_printf(BIOS_PRINTF_ALL, format, ##p)    
 #else
 #  define BX_DEBUG(format, p...) 
 #endif
 #define BX_INFO(format, p...)   bios_printf(BIOS_PRINTF_INFO, format, ##p)
 #define BX_PANIC(format, p...)  bios_printf(BIOS_PRINTF_DEBHALT, format, ##p)
 
+/*Zheng 07/2008*/
+
+#if DEBUG_RAMDISK
+#   define debug_outb(a...) outb(a)
+#else
+#   define debug_outb(a...)
+#endif  
+
+
 #if DEBUG_ATA
 #  define BX_DEBUG_ATA(a...) BX_DEBUG(a)
 #else
@@ -1399,12 +1410,13 @@ ASM_END
 }
 
 //  Bit16u
-//get_DS()
-//{
-//ASM_START
-//  mov  ax, ds
-//ASM_END
-//}
+get_DS()
+{
+ASM_START
+  mov  ax, ds
+ASM_END
+}
+
 //
 //  void
 //set_DS(ds_selector)
@@ -1668,7 +1680,7 @@ keyboard_init()
     Bit16u max;
     int rc;
 
-    printf("rombios: keyboard_init\n");
+    BX_DEBUG("rombios: keyboard_init\n");
 
     /* printf("Assuming keyboard already inited and returning\n");
        return; */
@@ -1679,9 +1691,11 @@ keyboard_init()
     while ( (inb(0x64) & 0x02) && (--max>0)) outb(0x80, 0x00); 
 
     /* flush incoming keys */
-    max=0x2000;
+    // temporarily chaged for debug -PAD
+    //    max=0x2000;  
+    max=10;
     while (--max > 0) {
-        outb(0x80, 0x00);
+        outb(0x80, 0x01);
         if (inb(0x64) & 0x01) {
             inb(0x60);
             max = 0x2000;
@@ -1699,12 +1713,12 @@ keyboard_init()
 
     /* Wait until buffer is empty */
     max=0xffff;
-    while ( (inb(0x64) & 0x02) && (--max>0)) outb(0x80, 0x00);
+    while ( (inb(0x64) & 0x02) && (--max>0)) outb(0x80, 0x02);
     if (max==0x0) keyboard_panic(00);
 
     /* Wait for data */
     max=0xffff;
-    while ( ((inb(0x64) & 0x01) == 0) && (--max>0) ) outb(0x80, 0x01);
+    while ( ((inb(0x64) & 0x01) == 0) && (--max>0) ) outb(0x80, 0x03);
     if (max==0x0) keyboard_panic(01);
 
     /* read self-test result, 0x55 should be returned from 0x60 */
@@ -2127,7 +2141,7 @@ void ata_init( )
   Bit16u ebda_seg=read_word(0x0040,0x000E);
   Bit8u  channel, device;
 
-  printf("rom_bios: ata_init\n");
+  //BX_DEBUG("rombios: ata_init\n");
 
   // Channels info init. 
   for (channel=0; channel<BX_MAX_ATA_INTERFACES; channel++) {
@@ -2176,6 +2190,10 @@ void ata_detect( )
   Bit8u  hdcount, cdcount, device, type;
   Bit8u  buffer[0x0200];
 
+  debug_outb(0x3e8, 0xf0);
+
+  //BX_DEBUG("rombios: ata_detect\n");
+
 #if BX_MAX_ATA_INTERFACES > 0
   write_byte(ebda_seg,&EbdaData->ata.channels[0].iface,ATA_IFACE_ISA);
   write_word(ebda_seg,&EbdaData->ata.channels[0].iobase1,0x1f0);
@@ -2430,6 +2448,8 @@ void ata_detect( )
           break;
         }
 
+       debug_outb(0x2ed, device);
+       debug_outb(0x2ee, type);
       switch (type) {
         case ATA_TYPE_ATA:
           printf("ata%d %s: ",channel,slave?" slave":"master");
@@ -2446,6 +2466,8 @@ void ata_detect( )
           break;
         case ATA_TYPE_UNKNOWN:
           printf("ata%d %s: Unknown device\n",channel,slave?" slave":"master");
+         if(device == 3) {
+         }
           break;
         }
       }
@@ -2457,6 +2479,7 @@ void ata_detect( )
   write_byte(0x40,0x75, hdcount);
  
   printf("\n");
+  debug_outb(0x3e8, 0xf0);
 
   // FIXME : should use bios=cmos|auto|disable bits
   // FIXME : should know about translation bits
@@ -2478,6 +2501,8 @@ Bit16u device;
   Bit8u  channel, slave, sn, sc; 
   Bit16u max;
 
+  debug_outb(0x3e9, 0xf1);
+
   channel = device / 2;
   slave = device % 2;
 
@@ -2527,6 +2552,8 @@ Bit16u device;
 
   // Enable interrupts
   outb(iobase2+ATA_CB_DC, ATA_CB_DC_HD15);
+
+  debug_outb(0x3e9, 0xf1);
 }
 
 // ---------------------------------------------------------------------------
@@ -2557,6 +2584,9 @@ Bit32u lba;
   Bit8u  channel, slave;
   Bit8u  status, current, mode;
 
+  debug_outb(0x3ea, 0xf2); 
+
+
   channel = device / 2;
   slave   = device % 2;
 
@@ -2600,9 +2630,11 @@ Bit32u lba;
 
   if (status & ATA_CB_STAT_ERR) {
     BX_DEBUG_ATA("ata_cmd_data_in : read error\n");
+      debug_outb(0x3ea, 0xf2); 
     return 2;
     } else if ( !(status & ATA_CB_STAT_DRQ) ) {
     BX_DEBUG_ATA("ata_cmd_data_in : DRQ not set (status %02x)\n", (unsigned) status);
+  debug_outb(0x3ea, 0xf2); 
     return 3;
   }
 
@@ -2661,6 +2693,7 @@ ASM_END
       if ( (status & (ATA_CB_STAT_BSY | ATA_CB_STAT_RDY | ATA_CB_STAT_DRQ | ATA_CB_STAT_ERR) ) 
           != ATA_CB_STAT_RDY ) {
         BX_DEBUG_ATA("ata_cmd_data_in : no sectors left (status %02x)\n", (unsigned) status);
+        debug_outb(0x3ea, 0xf2); 
         return 4;
         }
       break;
@@ -2669,6 +2702,7 @@ ASM_END
       if ( (status & (ATA_CB_STAT_BSY | ATA_CB_STAT_RDY | ATA_CB_STAT_DRQ | ATA_CB_STAT_ERR) ) 
           != (ATA_CB_STAT_RDY | ATA_CB_STAT_DRQ) ) {
         BX_DEBUG_ATA("ata_cmd_data_in : more sectors left (status %02x)\n", (unsigned) status);
+        debug_outb(0x3ea, 0xf2); 
         return 5;
       }
       continue;
@@ -2676,6 +2710,7 @@ ASM_END
   }
   // Enable interrupts
   outb(iobase2+ATA_CB_DC, ATA_CB_DC_HD15);
+  debug_outb(0x3ea, 0xf2); 
   return 0;
 }
 
@@ -2700,6 +2735,8 @@ Bit32u lba;
   Bit8u  channel, slave;
   Bit8u  status, current, mode;
 
+  debug_outb(0x3eb, 0xf3);
+
   channel = device / 2;
   slave   = device % 2;
 
@@ -2743,9 +2780,11 @@ Bit32u lba;
 
   if (status & ATA_CB_STAT_ERR) {
     BX_DEBUG_ATA("ata_cmd_data_out : read error\n");
+    debug_outb(0x3eb, 0xf3);
     return 2;
     } else if ( !(status & ATA_CB_STAT_DRQ) ) {
     BX_DEBUG_ATA("ata_cmd_data_out : DRQ not set (status %02x)\n", (unsigned) status);
+    debug_outb(0x3eb, 0xf3);
     return 3;
     }
 
@@ -2806,6 +2845,7 @@ ASM_END
       if ( (status & (ATA_CB_STAT_BSY | ATA_CB_STAT_RDY | ATA_CB_STAT_DF | ATA_CB_STAT_DRQ | ATA_CB_STAT_ERR) ) 
           != ATA_CB_STAT_RDY ) {
         BX_DEBUG_ATA("ata_cmd_data_out : no sectors left (status %02x)\n", (unsigned) status);
+       debug_outb(0x3eb, 0xf3);
         return 6;
         }
       break;
@@ -2814,6 +2854,7 @@ ASM_END
       if ( (status & (ATA_CB_STAT_BSY | ATA_CB_STAT_RDY | ATA_CB_STAT_DRQ | ATA_CB_STAT_ERR) ) 
           != (ATA_CB_STAT_RDY | ATA_CB_STAT_DRQ) ) {
         BX_DEBUG_ATA("ata_cmd_data_out : more sectors left (status %02x)\n", (unsigned) status);
+       debug_outb(0x3eb, 0xf3);
         return 7;
       }
       continue;
@@ -2821,6 +2862,7 @@ ASM_END
   }
   // Enable interrupts
   outb(iobase2+ATA_CB_DC, ATA_CB_DC_HD15);
+  debug_outb(0x3eb, 0xf3);
   return 0;
 }
 
@@ -2843,21 +2885,25 @@ Bit32u length;
   Bit16u iobase1, iobase2;
   Bit16u lcount, lbefore, lafter, count;
   Bit8u  channel, slave;
-  Bit8u  status, mode, lmode;
+  Bit8u  status, error, mode, lmode;
   Bit32u total, transfer;
 
+  debug_outb(0x3ec, 0xf4);
+
   channel = device / 2;
   slave = device % 2;
 
   // Data out is not supported yet
   if (inout == ATA_DATA_OUT) {
     BX_INFO("ata_cmd_packet: DATA_OUT not supported yet\n");
+  debug_outb(0x3ec, 0xf4);
     return 1;
     }
 
   // The header length must be even
   if (header & 1) {
     BX_DEBUG_ATA("ata_cmd_packet : header must be even (%04x)\n",header);
+  debug_outb(0x3ec, 0xf4);
     return 1;
     }
 
@@ -2874,31 +2920,72 @@ Bit32u length;
   write_word(ebda_seg, &EbdaData->ata.trsfsectors,0);
   write_dword(ebda_seg, &EbdaData->ata.trsfbytes,0L);
 
-  status = inb(iobase1 + ATA_CB_STAT);
-  if (status & ATA_CB_STAT_BSY) return 2;
+#define STATUS_WAIT_FOR(x) do { status=inb(iobase1+ATA_CB_STAT); } while (!(x)) 
+#define ALT_STATUS_WAIT_FOR(x) do { status=inb(iobase2+ATA_CB_ASTAT); } while (!(x)) 
+#define ERROR_UPDATE() do { error=inb(iobase1+ATA_CB_ERR); } while (0)
+#define STATUS_UPDATE() do { status=inb(iobase1+ATA_CB_STAT); } while (0)
+#define ALT_STATUS_UPDATE() do { status=inb(iobase1+ATA_CB_STAT); } while (0)
+#define WAIT_FOR_NOT_BUSY() STATUS_WAIT_FOR((status&ATA_CB_STAT_BSY)==0)
+#define WAIT_FOR_DATA_REQUEST() STATUS_WAIT_FOR((status&ATA_CB_STAT_DRQ))
+#define WAIT_FOR_DRIVE_READY() STATUS_WAIT_FOR((status&ATA_CB_STAT_RDY))
+#define WAIT_FOR_NOT_BUSY_AND_DRIVE_READY() STATUS_WAIT_FOR(((status&ATA_CB_STAT_BSY)==0)&&((status&ATA_CB_STAT_RDY)))
+#define WAIT_FOR_NOT_BUSY_AND_DATA_REQUEST() STATUS_WAIT_FOR((status&ATA_CB_STAT_BSY)==0)&&((status&ATA_CB_STAT_DRQ)))
 
+
+
+retry_on_media_change:
+
+  WAIT_FOR_NOT_BUSY();
+
+  //BX_DEBUG_ATA("ata_cmd_packet: not busy done\n");
+
+  // We have already selected the appropriate controller (iobase1,2)
+  // select master or slave
+  outb(iobase1 + ATA_CB_DH, slave ? ATA_CB_DH_DEV1 : ATA_CB_DH_DEV0);
+
+  STATUS_UPDATE();
+
+  //BX_DEBUG_ATA("ata_cmd_packet: drive selected (%d) status=0x%x\n", slave,(unsigned)status);
+
+
+  // Technically, we should be calling this here
+  // but QEMU's device model appears to be broken and RDY never is assserted
+  // on a drive change
+  // WAIT_FOR_NOT_BUSY_AND_DRIVE_READY();
+  WAIT_FOR_NOT_BUSY();
+   
+  BX_DEBUG_ATA("ata_cmd_packet: not busy\n");
+
+  // set "noninterruptable"
   outb(iobase2 + ATA_CB_DC, ATA_CB_DC_HD15 | ATA_CB_DC_NIEN);
-  // outb(iobase1 + ATA_CB_FR, 0x00);
-  // outb(iobase1 + ATA_CB_SC, 0x00);
-  // outb(iobase1 + ATA_CB_SN, 0x00);
+  // no DMA
+  outb(iobase1 + ATA_CB_FR, 0x00);
+  // This conveys the maximum bytecount.  count&0xff in low, count>>8 in high
+  // it is not actually doing anything with cylinders
   outb(iobase1 + ATA_CB_CL, 0xfff0 & 0x00ff);
   outb(iobase1 + ATA_CB_CH, 0xfff0 >> 8);
-  outb(iobase1 + ATA_CB_DH, slave ? ATA_CB_DH_DEV1 : ATA_CB_DH_DEV0);
+  // Not sure about these 
+  outb(iobase1 + ATA_CB_SC, 0x00);
+  outb(iobase1 + ATA_CB_SN, 0x00);
+
+  BX_DEBUG_ATA("ata_cmd_packet: configuration done\n");
+
+  // Issue command for packet 
   outb(iobase1 + ATA_CB_CMD, ATA_CMD_PACKET);
 
-  // Device should ok to receive command
-  while (1) {
-    status = inb(iobase1 + ATA_CB_STAT);
-    if ( !(status & ATA_CB_STAT_BSY) ) break;
-    }
+  BX_DEBUG_ATA("ata_cmd_packet: A0 issued to drive\n");
+  ALT_STATUS_WAIT_FOR((status&ATA_CB_STAT_BSY)==0);
 
-  if (status & ATA_CB_STAT_ERR) {
-    BX_DEBUG_ATA("ata_cmd_packet : error, status is %02x\n",status);
-    return 3;
-    } else if ( !(status & ATA_CB_STAT_DRQ) ) {
-    BX_DEBUG_ATA("ata_cmd_packet : DRQ not set (status %02x)\n", (unsigned) status);
-    return 4;
-    }
+  BX_DEBUG_ATA("ata_cmd_packet: alt status shows not busy\n");
+
+  STATUS_UPDATE();
+
+  BX_DEBUG_ATA("ata_cmd_packet: main status shows 0x%x\n",(unsigned)status);
+
+  WAIT_FOR_DATA_REQUEST();
+
+  BX_DEBUG_ATA("ata_cmd_packet: data request is set\n");
 
   // Normalize address
   cmdseg += (cmdoff / 16);
@@ -2925,61 +3012,111 @@ ASM_START
       pop  bp
 ASM_END
 
+
+  ALT_STATUS_WAIT_FOR((status&ATA_CB_STAT_BSY)==0);
+
+  STATUS_UPDATE();
+  ERROR_UPDATE();
+
+  BX_DEBUG_ATA("ata_cmd_packet: after packet: 0x%x error 0x%x\n",(unsigned)status,(unsigned)error);
+
+  if (status&ATA_CB_STAT_ERR && error&ATA_CB_ER_MC) {
+     BX_DEBUG_ATA("ata_cmd_packet: caught unexpected media change.  Retrying\n");      
+     goto retry_on_media_change;
+  }
+       
+
+
   if (inout == ATA_DATA_NO) {
-    status = inb(iobase1 + ATA_CB_STAT);
+       STATUS_UPDATE();
     }
   else {
-  while (1) {
+    
+    while (1) {
+    
+      // This while loop is quite bizarre
+      // Under both success and failure, you'll go through it once
+      // and then just a wee bit the second time - PAD
+
+      
+      ALT_STATUS_WAIT_FOR((status&ATA_CB_STAT_BSY)==0);
+      
+      STATUS_UPDATE();
+      ERROR_UPDATE();
+      BX_DEBUG_ATA("ata_cmd_packet/dataxferloop: status=0x%x, error=0x%x\n",(unsigned)status,(unsigned)error);
+
 
-      status = inb(iobase1 + ATA_CB_STAT);
+
+#if 0
+//
+// According to specatapi, the following is how you're supposed
+// To tell when there is no more data for you
+// But it doesn't work on at least some hardware - PAD
+      if ((status&ATA_CB_STAT_BSY) && !(status&ATA_CB_STAT_DRQ)) { 
+         // done with data tranfer
+         // we wait for it to flip
+        ALT_STATUS_WAIT_FOR((status&ATA_CB_STAT_BSY)==0);
+         // then read one more time
+         STATUS_UPDATE();
+         // then we are done
+         break;
+       }
+
+#else
 
       // Check if command completed
       if ( (status & (ATA_CB_STAT_BSY | ATA_CB_STAT_DRQ) ) ==0 ) break;
 
+#endif      
       if (status & ATA_CB_STAT_ERR) {
         BX_DEBUG_ATA("ata_cmd_packet : error (status %02x)\n",status);
+  debug_outb(0x3ec, 0xf4);
         return 3;
       }
-
+      
+      // If we get here, we are ready and should have DRQ
+      // and so data is available
       // Device must be ready to send data
       if ( (status & (ATA_CB_STAT_BSY | ATA_CB_STAT_RDY | ATA_CB_STAT_DRQ | ATA_CB_STAT_ERR) ) 
-            != (ATA_CB_STAT_RDY | ATA_CB_STAT_DRQ) ) {
-        BX_DEBUG_ATA("ata_cmd_packet : not ready (status %02x)\n", status);
+          != (ATA_CB_STAT_RDY | ATA_CB_STAT_DRQ) ) {
+        BX_DEBUG_ATA("ata_cmd_packet 1: not ready (status %02x)\n", status);
+  debug_outb(0x3ec, 0xf4);
         return 4;
-        }
-
+      }
+      
       // Normalize address
       bufseg += (bufoff / 16);
       bufoff %= 16;
-    
+      
       // Get the byte count
       lcount =  ((Bit16u)(inb(iobase1 + ATA_CB_CH))<<8)+inb(iobase1 + ATA_CB_CL);
-
+      
       // adjust to read what we want
       if(header>lcount) {
-         lbefore=lcount;
-         header-=lcount;
-         lcount=0;
-         }
+       lbefore=lcount;
+       header-=lcount;
+       lcount=0;
+      }
       else {
         lbefore=header;
         header=0;
         lcount-=lbefore;
-        }
-
+      }
+      
       if(lcount>length) {
         lafter=lcount-length;
         lcount=length;
         length=0;
-        }
+      }
       else {
         lafter=0;
         length-=lcount;
-        }
-
+      }
+      
       // Save byte count
       count = lcount;
-
+      
       BX_DEBUG_ATA("Trying to read %04x bytes (%04x %04x %04x) ",lbefore+lcount+lafter,lbefore,lcount,lafter);
       BX_DEBUG_ATA("to 0x%04x:0x%04x\n",bufseg,bufoff);
 
@@ -3082,25 +3219,29 @@ ASM_END
       // Save transferred bytes count
       transfer += count;
       write_dword(ebda_seg, &EbdaData->ata.trsfbytes,transfer);
-      }
-    }
+      } //while(1)
+    }//else
 
   // Final check, device must be ready
   if ( (status & (ATA_CB_STAT_BSY | ATA_CB_STAT_RDY | ATA_CB_STAT_DF | ATA_CB_STAT_DRQ | ATA_CB_STAT_ERR) ) 
          != ATA_CB_STAT_RDY ) {
-    BX_DEBUG_ATA("ata_cmd_packet : not ready (status %02x)\n", (unsigned) status);
-    return 4;
+    BX_DEBUG_ATA("ata_cmd_packet 2 : not ready (status %02x)\n", (unsigned) status);
+  debug_outb(0x3ec, 0xf4);
+       return 4;
     }
 
   // Enable interrupts
   outb(iobase2+ATA_CB_DC, ATA_CB_DC_HD15);
+  debug_outb(0x3ec, 0xf4);
   return 0;
+
 }
 
 // ---------------------------------------------------------------------------
 // End of ATA/ATAPI Driver
 // ---------------------------------------------------------------------------
 
+
 // ---------------------------------------------------------------------------
 // Start of ATA/ATAPI generic functions
 // ---------------------------------------------------------------------------
@@ -3113,18 +3254,24 @@ atapi_get_sense(device)
   Bit8u  buffer[16];
   Bit8u i;
 
+  debug_outb(0x3ed, 0xf5);
+
   memsetb(get_SS(),atacmd,0,12);
 
   // Request SENSE 
   atacmd[0]=0x03;    
   atacmd[4]=0x20;    
-  if (ata_cmd_packet(device, 12, get_SS(), atacmd, 0, 16L, ATA_DATA_IN, get_SS(), buffer) != 0)
+  if (ata_cmd_packet(device, 12, get_SS(), atacmd, 0, 16L, ATA_DATA_IN, get_SS(), buffer) != 0) {
+  debug_outb(0x3ed, 0xf5);
     return 0x0002;
+  }
 
   if ((buffer[0] & 0x7e) == 0x70) {
+       debug_outb(0x3ed, 0xf5);
     return (((Bit16u)buffer[2]&0x0f)*0x100)+buffer[12];
     }
 
+  debug_outb(0x3ed, 0xf5);
   return 0;
 }
 
@@ -3135,21 +3282,29 @@ atapi_is_ready(device)
   Bit8u  atacmd[12];
   Bit8u  buffer[];
 
+  debug_outb(0x3ee, 0xf6);
+
   memsetb(get_SS(),atacmd,0,12);
  
   // Test Unit Ready
-  if (ata_cmd_packet(device, 12, get_SS(), atacmd, 0, 0L, ATA_DATA_NO, get_SS(), buffer) != 0)
+  if (ata_cmd_packet(device, 12, get_SS(), atacmd, 0, 0L, ATA_DATA_NO, get_SS(), buffer) != 0) {
+     debug_outb(0x3ee, 0xf6);
     return 0x000f;
+    }
 
   if (atapi_get_sense(device) !=0 ) {
     memsetb(get_SS(),atacmd,0,12);
 
     // try to send Test Unit Ready again
-    if (ata_cmd_packet(device, 12, get_SS(), atacmd, 0, 0L, ATA_DATA_NO, get_SS(), buffer) != 0)
+    if (ata_cmd_packet(device, 12, get_SS(), atacmd, 0, 0L, ATA_DATA_NO, get_SS(), buffer) != 0) {
+      debug_outb(0x3ee, 0xf6);
       return 0x000f;
+      }
 
+    debug_outb(0x3ee, 0xf6);
     return atapi_get_sense(device);
     }
+  debug_outb(0x3ee, 0xf6);
   return 0;
 }
 
@@ -3157,17 +3312,28 @@ atapi_is_ready(device)
 atapi_is_cdrom(device)
   Bit8u device;
 {
+
+
   Bit16u ebda_seg=read_word(0x0040,0x000E);
 
-  if (device >= BX_MAX_ATA_DEVICES)
+  debug_outb(0x3ef, 0xf7);
+
+  if (device >= BX_MAX_ATA_DEVICES) {
+    debug_outb(0x3ef, 0xf7);
     return 0;
+    }
 
-  if (read_byte(ebda_seg,&EbdaData->ata.devices[device].type) != ATA_TYPE_ATAPI)
+  if (read_byte(ebda_seg,&EbdaData->ata.devices[device].type) != ATA_TYPE_ATAPI) {
+     debug_outb(0x3ef, 0xf7);
     return 0;
+    }
 
-  if (read_byte(ebda_seg,&EbdaData->ata.devices[device].device) != ATA_DEVICE_CDROM)
+  if (read_byte(ebda_seg,&EbdaData->ata.devices[device].device) != ATA_DEVICE_CDROM) {
+    debug_outb(0x3ef, 0xf7);
     return 0;
+    }
 
+    debug_outb(0x3ef, 0xf7);
   return 1;
 }
 
@@ -3186,27 +3352,39 @@ atapi_is_cdrom(device)
   void
 cdemu_init()
 {
+
+
   Bit16u ebda_seg=read_word(0x0040,0x000E);
 
-  printf("rombios: cdemu_init\n");
+       debug_outb(0x2e8, 0xf8);
+
+  //BX_DEBUG("rombios: cdemu_init\n");
 
   // the only important data is this one for now
   write_byte(ebda_seg,&EbdaData->cdemu.active,0x00);
+       debug_outb(0x2e8, 0xf8);
+
+
 }
 
   Bit8u
 cdemu_isactive()
 {
+
   Bit16u ebda_seg=read_word(0x0040,0x000E);
 
+       outb(0x2e9, 0xf9);
   return(read_byte(ebda_seg,&EbdaData->cdemu.active));
 }
 
   Bit8u
 cdemu_emulated_drive()
 {
+
   Bit16u ebda_seg=read_word(0x0040,0x000E);
 
+       debug_outb(0x2ea, 0xfa);
+       debug_outb(0x2ea, 0xfa);
   return(read_byte(ebda_seg,&EbdaData->cdemu.emulated_drive));
 }
 
@@ -3224,33 +3402,50 @@ cdrom_boot()
   Bit16u boot_segment, nbsectors, i, error;
   Bit8u  device;
 
+  debug_outb(0x2eb, 0xfb);
+
   // Find out the first cdrom
   for (device=0; device<BX_MAX_ATA_DEVICES;device++) {
     if (atapi_is_cdrom(device)) break;
     }
   
   // if not found
-  if(device >= BX_MAX_ATA_DEVICES) return 2;
+  if(device >= BX_MAX_ATA_DEVICES) {
+    debug_outb(0x2eb, 0xfb);
+      return 2;
+      }
+
+
 
   // Read the Boot Record Volume Descriptor
   memsetb(get_SS(),atacmd,0,12);
   atacmd[0]=0x28;                      // READ command
+  atacmd[1]=0x0 ;                      // reserved - not sure why this wasn't zeroed to begin with -PAD
+  atacmd[6]=0x0 ;                      // reserved - ... -PAD
   atacmd[7]=(0x01 & 0xff00) >> 8;      // Sectors
   atacmd[8]=(0x01 & 0x00ff);           // Sectors
   atacmd[2]=(0x11 & 0xff000000) >> 24; // LBA
   atacmd[3]=(0x11 & 0x00ff0000) >> 16;
   atacmd[4]=(0x11 & 0x0000ff00) >> 8;
   atacmd[5]=(0x11 & 0x000000ff);
-  if((error = ata_cmd_packet(device, 12, get_SS(), atacmd, 0, 2048L, ATA_DATA_IN, get_SS(), buffer)) != 0)
+  atacmd[9]=atacmd[10]=atacmd[11]=0x0;  // just to be safe -PAD
+  if((error = ata_cmd_packet(device, 12, get_SS(), atacmd, 0, 2048L, ATA_DATA_IN, get_SS(), buffer)) != 0) {
+    debug_outb(0x2eb, 0xfb);
     return 3;
+    }
+
 
   // Validity checks
   if(buffer[0]!=0)return 4;
   for(i=0;i<5;i++){
-    if(buffer[1+i]!=read_byte(0xf000,&isotag[i]))return 5;
+    if(buffer[1+i]!=read_byte(0xf000,&isotag[i])) {  
+    debug_outb(0x2eb, 0xfb); return 5;
+    }
    }
   for(i=0;i<23;i++)
-    if(buffer[7+i]!=read_byte(0xf000,&eltorito[i]))return 6;
+    if(buffer[7+i]!=read_byte(0xf000,&eltorito[i])) {  
+               debug_outb(0x2eb, 0xfb); return 6;
+       }
   
   // ok, now we calculate the Boot catalog address
   lba=buffer[0x4A]*0x1000000+buffer[0x49]*0x10000+buffer[0x48]*0x100+buffer[0x47];
@@ -3264,17 +3459,21 @@ cdrom_boot()
   atacmd[3]=(lba & 0x00ff0000) >> 16;
   atacmd[4]=(lba & 0x0000ff00) >> 8;
   atacmd[5]=(lba & 0x000000ff);
-  if((error = ata_cmd_packet(device, 12, get_SS(), atacmd, 0, 2048L, ATA_DATA_IN, get_SS(), buffer)) != 0)
+  if((error = ata_cmd_packet(device, 12, get_SS(), atacmd, 0, 2048L, ATA_DATA_IN, get_SS(), buffer)) != 0) {
+    debug_outb(0x2eb, 0xfb);
     return 7;
+    }
+
+
  
   // Validation entry
-  if(buffer[0x00]!=0x01)return 8;   // Header
-  if(buffer[0x01]!=0x00)return 9;   // Platform
-  if(buffer[0x1E]!=0x55)return 10;  // key 1
-  if(buffer[0x1F]!=0xAA)return 10;  // key 2
+  if(buffer[0x00]!=0x01) {  debug_outb(0x2eb, 0xfb); return 8;}   // Header
+  if(buffer[0x01]!=0x00){  debug_outb(0x2eb, 0xfb); return 9;}   // Platform
+  if(buffer[0x1E]!=0x55) {  debug_outb(0x2eb, 0xfb); return 10;}  // key 1
+  if(buffer[0x1F]!=0xAA) {  debug_outb(0x2eb, 0xfb); return 10;}  // key 2
 
   // Initial/Default Entry
-  if(buffer[0x20]!=0x88)return 11; // Bootable
+  if(buffer[0x20]!=0x88) {  debug_outb(0x2eb, 0xfb); return 11;} // Bootable
 
   write_byte(ebda_seg,&EbdaData->cdemu.media,buffer[0x21]);
   if(buffer[0x21]==0){
@@ -3311,8 +3510,11 @@ cdrom_boot()
   atacmd[3]=(lba & 0x00ff0000) >> 16;
   atacmd[4]=(lba & 0x0000ff00) >> 8;
   atacmd[5]=(lba & 0x000000ff);
-  if((error = ata_cmd_packet(device, 12, get_SS(), atacmd, 0, nbsectors*512L, ATA_DATA_IN, boot_segment,0)) != 0)
+  if((error = ata_cmd_packet(device, 12, get_SS(), atacmd, 0, nbsectors*512L, ATA_DATA_IN, boot_segment,0)) != 0) {
+    debug_outb(0x2eb, 0xfb);
     return 12;
+    }
+
 
   // Remember the media type
   switch(read_byte(ebda_seg,&EbdaData->cdemu.media)) {
@@ -3353,6 +3555,7 @@ cdrom_boot()
     write_byte(ebda_seg,&EbdaData->cdemu.active,0x01);
 
   // return the boot drive + no error
+  debug_outb(0x2eb, 0xfb);
   return (read_byte(ebda_seg,&EbdaData->cdemu.emulated_drive)*0x100)+0;
 }
 
@@ -4104,10 +4307,13 @@ ASM_END
          case 0x20: // coded by osmaker aka K.J.
             if(regs.u.r32.edx == 0x534D4150) /* SMAP */
             {
-#ifdef HVMASSIST
+#if defined(HVMASSIST) && 0
                if ((regs.u.r16.bx / 0x14) * 0x14 == regs.u.r16.bx) {
+
                    Bit16u e820_table_size = read_word(0xe000, 0x8) * 0x14;
 
+                    BX_DEBUG_INT15("OK bx=%x\n",regs.u.r16.bx);
+
                    if (regs.u.r16.bx + 0x14 <= e820_table_size) {
                        memcpyb(ES, regs.u.r16.di,
                                0xe000, 0x10 + regs.u.r16.bx, 0x14);
@@ -4821,6 +5027,7 @@ int13_harddisk(DS, ES, DI, SI, BP, ELDX, BX, DX, CX, AX, IP, CS, FLAGS)
   Bit16u size, count;
   Bit8u  device, status;
 
+  debug_outb(0x2ef, 0xff);
   BX_DEBUG_INT13_HD("int13_harddisk: AX=%04x BX=%04x CX=%04x DX=%04x ES=%04x\n", AX, BX, CX, DX, ES);
 
   write_byte(0x0040, 0x008e, 0);  // clear completion flag
@@ -5190,6 +5397,7 @@ int13_fail_noah:
     SET_DISK_RET_STATUS(GET_AH());
 int13_fail_nostatus:
     SET_CF();     // error occurred
+  debug_outb(0x2ef, 0xff);
     return;
 
 int13_success:
@@ -5197,6 +5405,7 @@ int13_success:
 int13_success_noah:
     SET_DISK_RET_STATUS(0x00);
     CLEAR_CF();   // no error
+  debug_outb(0x2ef, 0xff);
     return;
 }
 
@@ -5214,6 +5423,8 @@ int13_cdrom(EHBX, DS, ES, DI, SI, BP, ELDX, BX, DX, CX, AX, IP, CS, FLAGS)
   Bit32u lba;
   Bit16u count, segment, offset, i, size;
 
+  debug_outb(0x2f8, 0xe0);
+
   BX_DEBUG_INT13_CD("int13_cdrom: AX=%04x BX=%04x CX=%04x DX=%04x ES=%04x\n", AX, BX, CX, DX, ES);
   // BX_DEBUG_INT13_CD("int13_cdrom: SS=%04x DS=%04x ES=%04x DI=%04x SI=%04x\n",get_SS(), DS, ES, DI, SI);
   
@@ -5540,6 +5751,7 @@ int13_fail_noah:
     SET_DISK_RET_STATUS(GET_AH());
 int13_fail_nostatus:
     SET_CF();     // error occurred
+  debug_outb(0x2f8, 0xe0);
     return;
 
 int13_success:
@@ -5547,6 +5759,7 @@ int13_success:
 int13_success_noah:
     SET_DISK_RET_STATUS(0x00);
     CLEAR_CF();   // no error
+  debug_outb(0x2f8, 0xe0);
     return;
 }
 
@@ -5565,6 +5778,8 @@ int13_eltorito(DS, ES, DI, SI, BP, SP, BX, DX, CX, AX, IP, CS, FLAGS)
 {
   Bit16u ebda_seg=read_word(0x0040,0x000E);
 
+  debug_outb(0x2fa, 0xe2);
+
   BX_DEBUG_INT13_ET("int13_eltorito: AX=%04x BX=%04x CX=%04x DX=%04x ES=%04x\n", AX, BX, CX, DX, ES);
   // BX_DEBUG_INT13_ET("int13_eltorito: SS=%04x DS=%04x ES=%04x DI=%04x SI=%04x\n",get_SS(), DS, ES, DI, SI);
   
@@ -5612,12 +5827,14 @@ int13_fail:
     SET_AH(0x01); // defaults to invalid function in AH or invalid parameter
     SET_DISK_RET_STATUS(GET_AH());
     SET_CF();     // error occurred
+  debug_outb(0x2fa, 0xe2);
     return;
 
 int13_success:
     SET_AH(0x00); // no error
     SET_DISK_RET_STATUS(0x00);
     CLEAR_CF();   // no error
+  debug_outb(0x2fa, 0xe2);
     return;
 }
 
@@ -5641,6 +5858,8 @@ int13_cdemu(DS, ES, DI, SI, BP, SP, BX, DX, CX, AX, IP, CS, FLAGS)
   Bit16u before, segment, offset;
   Bit8u  atacmd[12];
 
+  debug_outb(0x2f9, 0xe1);
+
   BX_DEBUG_INT13_ET("int13_cdemu: AX=%04x BX=%04x CX=%04x DX=%04x ES=%04x\n", AX, BX, CX, DX, ES);
   //BX_DEBUG_INT13_ET("int13_cdemu: SS=%04x ES=%04x DI=%04x SI=%04x\n", get_SS(), ES, DI, SI);
   
@@ -5816,6 +6035,7 @@ int13_fail_noah:
     SET_DISK_RET_STATUS(GET_AH());
 int13_fail_nostatus:
     SET_CF();     // error occurred
+  debug_outb(0x2f9, 0xe1);
     return;
 
 int13_success:
@@ -5823,6 +6043,7 @@ int13_success:
 int13_success_noah:
     SET_DISK_RET_STATUS(0x00);
     CLEAR_CF();   // no error
+  debug_outb(0x2f9, 0xe1);
     return;
 }
 
@@ -5908,6 +6129,8 @@ int13_harddisk(DS, ES, DI, SI, BP, ELDX, BX, DX, CX, AX, IP, CS, FLAGS)
   Bit32u   lba;
   Bit16u   error;
 
+
+  debug_outb(0x2ef, 0xff);
   BX_DEBUG_INT13_HD("int13 harddisk: AX=%04x BX=%04x CX=%04x DX=%04x ES=%04x\n", AX, BX, CX, DX, ES);
 
   write_byte(0x0040, 0x008e, 0);  // clear completion flag
@@ -5926,6 +6149,7 @@ int13_harddisk(DS, ES, DI, SI, BP, ELDX, BX, DX, CX, AX, IP, CS, FLAGS)
     SET_AH(0x01);
     SET_DISK_RET_STATUS(0x01);
     SET_CF(); /* error occurred */
+  debug_outb(0x2ef, 0xff);
     return;
     }
 
@@ -5940,6 +6164,7 @@ BX_DEBUG_INT13_HD("int13_f00\n");
       set_diskette_current_cyl(0, 0); /* current cylinder, diskette 1 */
       set_diskette_current_cyl(1, 0); /* current cylinder, diskette 2 */
       CLEAR_CF(); /* successful */
+  debug_outb(0x2ef, 0xff);
       return;
       break;
 
@@ -5951,6 +6176,7 @@ BX_DEBUG_INT13_HD("int13_f01\n");
       /* set CF if error status read */
       if (status) SET_CF();
       else        CLEAR_CF();
+  debug_outb(0x2ef, 0xff);     
       return;
       break;
 
@@ -5991,24 +6217,31 @@ BX_DEBUG_INT13_HD("int13_f01\n");
         SET_AH(1);
         SET_DISK_RET_STATUS(1);
         SET_CF(); /* error occurred */
+  debug_outb(0x2ef, 0xff);
         return;
         }
 
-      if ( (num_sectors > 128) || (num_sectors == 0) )
+      if ( (num_sectors > 128) || (num_sectors == 0) ){
+  debug_outb(0x2ef, 0xff); 
         BX_PANIC("int13_harddisk(): num_sectors out of range!\n");
+       }
 
-      if (head > 15)
+      if (head > 15) {
+  debug_outb(0x2ef, 0xff);
         BX_PANIC("hard drive BIOS:(read/verify) head > 15\n");
+       }       
 
       if ( GET_AH() == 0x04 ) {
         SET_AH(0);
         SET_DISK_RET_STATUS(0);
         CLEAR_CF();
+  debug_outb(0x2ef, 0xff);
         return;
         }
 
       status = inb(0x1f7);
       if (status & 0x80) {
+  debug_outb(0x2ef, 0xff);
         BX_PANIC("hard drive BIOS:(read/verify) BUSY bit set\n");
         }
       outb(0x01f2, num_sectors);
@@ -6031,8 +6264,10 @@ BX_DEBUG_INT13_HD("CHS: %x %x %x\n", cylinder, head, sector);
         }
 
       if (status & 0x01) {
+        debug_outb(0x2ef, 0xff);
         BX_PANIC("hard drive BIOS:(read/verify) read error\n");
       } else if ( !(status & 0x08) ) {
+        debug_outb(0x2ef, 0xff);  
         BX_DEBUG_INT13_HD("status was %02x\n", (unsigned) status);
         BX_PANIC("hard drive BIOS:(read/verify) expected DRQ=1\n");
       }
@@ -6081,12 +6316,14 @@ ASM_END
         if (num_sectors == 0) {
           status = inb(0x1f7);
           if ( (status & 0xc9) != 0x40 )
+           debug_outb(0x2ef, 0xff);
             BX_PANIC("no sectors left to read/verify, status is %02x\n", (unsigned) status);
           break;
           }
         else {
           status = inb(0x1f7);
           if ( (status & 0xc9) != 0x48 )
+           debug_outb(0x2ef, 0xff);
             BX_PANIC("more sectors left to read/verify, status is %02x\n", (unsigned) status);
           continue;
           }
@@ -6096,6 +6333,7 @@ ASM_END
       SET_DISK_RET_STATUS(0);
       SET_AL(sector_count);
       CLEAR_CF(); /* successful */
+        debug_outb(0x2ef, 0xff);
       return;
       break;
 
@@ -6137,17 +6375,23 @@ BX_DEBUG_INT13_HD("int13_f03\n");
         SET_AH( 1);
         SET_DISK_RET_STATUS(1);
         SET_CF(); /* error occurred */
+         debug_outb(0x2ef, 0xff);  
         return;
         }
 
-      if ( (num_sectors > 128) || (num_sectors == 0) )
+      if ( (num_sectors > 128) || (num_sectors == 0) ) {
+        debug_outb(0x2ef, 0xff);
         BX_PANIC("int13_harddisk(): num_sectors out of range!\n");
+       }
 
-      if (head > 15)
+      if (head > 15) {
+        debug_outb(0x2ef, 0xff);
         BX_PANIC("hard drive BIOS:(read) head > 15\n");
+       }
 
       status = inb(0x1f7);
       if (status & 0x80) {
+        debug_outb(0x2ef, 0xff);
         BX_PANIC("hard drive BIOS:(read) BUSY bit set\n");
         }
 // should check for Drive Ready Bit also in status reg
@@ -6173,6 +6417,7 @@ BX_DEBUG_INT13_HD("CHS (write): %x %x %x\n", cylinder, head, sector);
         }
 
       if ( !(status & 0x08) ) {
+        debug_outb(0x2ef, 0xff);
         BX_DEBUG_INT13_HD("status was %02x\n", (unsigned) status);
         BX_PANIC("hard drive BIOS:(write) data-request bit not set\n");
         }
@@ -6220,14 +6465,18 @@ ASM_END
         num_sectors--;
         if (num_sectors == 0) {
           status = inb(0x1f7);
-          if ( (status & 0xe9) != 0x40 )
+          if ( (status & 0xe9) != 0x40 ) {
+           debug_outb(0x2ef, 0xff);
             BX_PANIC("no sectors left to write, status is %02x\n", (unsigned) status);
+           }
           break;
           }
         else {
           status = inb(0x1f7);
-          if ( (status & 0xc9) != 0x48 )
-            BX_PANIC("more sectors left to write, status is %02x\n", (unsigned) status);
+          if ( (status & 0xc9) != 0x48 ) {
+           debug_outb(0x2ef, 0xff);
+            BX_PANIC("more sectors left to write, status is %02x\n", (unsigned) status); 
+           }
           continue;
           }
         }
@@ -6236,6 +6485,7 @@ ASM_END
       SET_DISK_RET_STATUS(0);
       SET_AL(sector_count);
       CLEAR_CF(); /* successful */
+        debug_outb(0x2ef, 0xff);
       return;
       break;
 
@@ -6246,6 +6496,7 @@ BX_DEBUG_INT13_HD("int13_f05\n");
       SET_AH(0);
       SET_DISK_RET_STATUS(0);
       CLEAR_CF(); /* successful */
+        debug_outb(0x2ef, 0xff);
       return;
       break;
 
@@ -6287,7 +6538,7 @@ BX_DEBUG_INT13_HD("int13_f08\n");
       SET_AH(0);
       SET_DISK_RET_STATUS(0);
       CLEAR_CF(); /* successful */
-
+        debug_outb(0x2ef, 0xff);
       return;
       break;
 
@@ -6296,6 +6547,7 @@ BX_DEBUG_INT13_HD("int13_f09\n");
       SET_AH(0);
       SET_DISK_RET_STATUS(0);
       CLEAR_CF(); /* successful */
+        debug_outb(0x2ef, 0xff);
       return;
       break;
 
@@ -6303,6 +6555,7 @@ BX_DEBUG_INT13_HD("int13_f09\n");
 BX_DEBUG_INT13_HD("int13_f0a\n");
     case 0x0b: /* write disk sectors with ECC */
 BX_DEBUG_INT13_HD("int13_f0b\n");
+         debug_outb(0x2ef, 0xff);
       BX_PANIC("int13h Functions 0Ah & 0Bh not implemented!\n");
       return;
       break;
@@ -6313,6 +6566,7 @@ BX_DEBUG_INT13_HD("int13_f0c\n");
       SET_AH(0);
       SET_DISK_RET_STATUS(0);
       CLEAR_CF(); /* successful */
+         debug_outb(0x2ef, 0xff);
       return;
       break;
 
@@ -6321,6 +6575,7 @@ BX_DEBUG_INT13_HD("int13_f0d\n");
       SET_AH(0);
       SET_DISK_RET_STATUS(0);
       CLEAR_CF(); /* successful */
+         debug_outb(0x2ef, 0xff);
       return;
       break;
 
@@ -6338,12 +6593,14 @@ BX_DEBUG_INT13_HD("int13_f10\n");
         SET_AH(0);
         SET_DISK_RET_STATUS(0);
         CLEAR_CF(); // drive ready
+         debug_outb(0x2ef, 0xff);
         return;
         }
       else {
         SET_AH(0xAA);
         SET_DISK_RET_STATUS(0xAA);
         SET_CF(); // not ready
+         debug_outb(0x2ef, 0xff);
         return;
         }
       break;
@@ -6353,6 +6610,7 @@ BX_DEBUG_INT13_HD("int13_f11\n");
       SET_AH(0);
       SET_DISK_RET_STATUS(0);
       CLEAR_CF(); /* successful */
+         debug_outb(0x2ef, 0xff);
       return;
       break;
 
@@ -6362,6 +6620,7 @@ BX_DEBUG_INT13_HD("int13_f14\n");
       SET_DISK_RET_STATUS(0);
       CLEAR_CF(); /* successful */
       SET_AL(0);
+         debug_outb(0x2ef, 0xff);
       return;
       break;
 
@@ -6387,6 +6646,7 @@ ASM_END
       SET_AH(3);  // hard disk accessible
       SET_DISK_RET_STATUS(0); // ??? should this be 0
       CLEAR_CF(); // successful
+         debug_outb(0x2ef, 0xff);
       return;
       break;
 
@@ -6406,6 +6666,7 @@ ASM_END
       SET_AH(1);  // code=invalid function in AH or invalid parameter
       SET_DISK_RET_STATUS(1);
       SET_CF(); /* unsuccessful */
+         debug_outb(0x2ef, 0xff);
       return;
       break;
     }
@@ -6681,6 +6942,9 @@ floppy_drive_exists(drive)
 {
   Bit8u  drive_type;
 
+  // just tell it both drives exist - PAD
+  return 1;
+
   // check CMOS to see if drive exists
   drive_type = inb_cmos(0x10);
   if (drive == 0)
@@ -6705,19 +6969,21 @@ int13_diskette_function(DS, ES, DI, SI, BP, ELDX, BX, DX, CX, AX, IP, CS, FLAGS)
   Bit8u  drive_type, num_floppies, ah;
   Bit16u es, last_addr;
 
-  BX_DEBUG_INT13_FL("int13_diskette: AX=%04x BX=%04x CX=%04x DX=%04x ES=%04x\n", AX, BX, CX, DX, ES);
-  // BX_DEBUG_INT13_FL("int13_diskette: SS=%04x DS=%04x ES=%04x DI=%04x SI=%04x\n",get_SS(), get_DS(), ES, DI, SI);
+  debug_outb(0x2fb, 0xe3);     
+  //printf("int13_diskette: AX=%04x BX=%04x CX=%04x DX=%04x ES=%04x\n", AX, BX, CX, DX, ES);
+  BX_DEBUG_INT13_FL("int13_diskette: SS=%04x DS=%04x ES=%04x DI=%04x SI=%04x\n",get_SS(),get_DS(), ES, DI, SI);
 
   ah = GET_AH();
 
   switch ( ah ) {
     case 0x00: // diskette controller reset
-BX_DEBUG_INT13_FL("floppy f00\n");
+      BX_DEBUG_INT13_FL("floppy f00\n");
       drive = GET_ELDL();
       if (drive > 1) {
         SET_AH(1); // invalid param
         set_diskette_ret_status(1);
         SET_CF();
+         debug_outb(0x2fb, 0xe3);      
         return;
         }
       drive_type = inb_cmos(0x10);
@@ -6730,12 +6996,14 @@ BX_DEBUG_INT13_FL("floppy f00\n");
         SET_AH(0x80); // drive not responding
         set_diskette_ret_status(0x80);
         SET_CF();
+         debug_outb(0x2fb, 0xe3);      
         return;
         }
       SET_AH(0);
       set_diskette_ret_status(0);
       CLEAR_CF(); // successful
       set_diskette_current_cyl(drive, 0); // current cylinder
+        debug_outb(0x2fb, 0xe3);       
       return;
 
     case 0x01: // Read Diskette Status
@@ -6745,6 +7013,7 @@ BX_DEBUG_INT13_FL("floppy f00\n");
       if (val8) {
         SET_CF();
         }
+         debug_outb(0x2fb, 0xe3);      
       return;
 
     case 0x02: // Read Diskette Sectors
@@ -6763,6 +7032,7 @@ BX_INFO("floppy: drive>1 || head>1 ...\n");
         set_diskette_ret_status(1);
         SET_AL(0); // no sectors read
         SET_CF(); // error occurred
+         debug_outb(0x2fb, 0xe3);      
         return;
         }
 
@@ -6772,6 +7042,7 @@ BX_INFO("floppy: drive>1 || head>1 ...\n");
         set_diskette_ret_status(0x80);
         SET_AL(0); // no sectors read
         SET_CF(); // error occurred
+         debug_outb(0x2fb, 0xe3);      
         return;
         }
 
@@ -6782,6 +7053,7 @@ BX_INFO("floppy: drive>1 || head>1 ...\n");
           set_diskette_ret_status(0x0C);
           SET_AL(0); // no sectors read
           SET_CF(); // error occurred
+           debug_outb(0x2fb, 0xe3);    
           return;
           }
         }
@@ -6813,6 +7085,7 @@ BX_INFO("floppy: drive>1 || head>1 ...\n");
           set_diskette_ret_status(0x09);
           SET_AL(0); // no sectors read
           SET_CF(); // error occurred
+           debug_outb(0x2fb, 0xe3);    
           return;
           }
 
@@ -6867,8 +7140,10 @@ BX_INFO("floppy: drive>1 || head>1 ...\n");
 
         // check port 3f4 for drive readiness
         val8 = inb(0x3f4);
-        if ( (val8 & 0xf0) != 0x80 )
+        if ( (val8 & 0xf0) != 0x80 ) {
+         debug_outb(0x2fb, 0xe3);      
           BX_PANIC("int13_diskette:f02: ctrl not ready\n");
+         }
 
         // send read-normal-data command (9 bytes) to controller
         outb(0x03f5, 0xe6); // e6: read normal data
@@ -6905,8 +7180,10 @@ BX_INFO("floppy: drive>1 || head>1 ...\n");
 
         // check port 3f4 for accessibility to status bytes
         val8 = inb(0x3f4);
-        if ( (val8 & 0xc0) != 0xc0 )
+        if ( (val8 & 0xc0) != 0xc0 ) {
+         debug_outb(0x2fb, 0xe3);      
           BX_PANIC("int13_diskette: ctrl not ready\n");
+         }
 
         // read 7 return status bytes from controller
         // using loop index broken, have to unroll...
@@ -6931,6 +7208,7 @@ BX_INFO("floppy: drive>1 || head>1 ...\n");
           set_diskette_ret_status(0x20);
           SET_AL(0); // no sectors read
           SET_CF(); // error occurred
+           debug_outb(0x2fb, 0xe3);    
           return;
           }
 
@@ -6939,6 +7217,7 @@ BX_INFO("floppy: drive>1 || head>1 ...\n");
         // AL = number of sectors read (same value as passed)
         SET_AH(0x00); // success
         CLEAR_CF();   // success
+         debug_outb(0x2fb, 0xe3);      
         return;
         }
       else if (ah == 0x03) {
@@ -6968,6 +7247,7 @@ BX_INFO("floppy: drive>1 || head>1 ...\n");
           set_diskette_ret_status(0x09);
           SET_AL(0); // no sectors read
           SET_CF(); // error occurred
+           debug_outb(0x2fb, 0xe3);    
           return;
           }
 
@@ -7015,8 +7295,10 @@ BX_INFO("floppy: drive>1 || head>1 ...\n");
 
         // check port 3f4 for drive readiness
         val8 = inb(0x3f4);
-        if ( (val8 & 0xf0) != 0x80 )
+        if ( (val8 & 0xf0) != 0x80 ){
+         debug_outb(0x2fb, 0xe3);      
           BX_PANIC("int13_diskette:f03: ctrl not ready\n");
+         }
 
         // send read-normal-data command (9 bytes) to controller
         outb(0x03f5, 0xc5); // c5: write normal data
@@ -7053,8 +7335,10 @@ BX_INFO("floppy: drive>1 || head>1 ...\n");
 
         // check port 3f4 for accessibility to status bytes
         val8 = inb(0x3f4);
-        if ( (val8 & 0xc0) != 0xc0 )
+        if ( (val8 & 0xc0) != 0xc0 ) {
+         debug_outb(0x2fb, 0xe3);      
           BX_PANIC("int13_diskette: ctrl not ready\n");
+         }
 
         // read 7 return status bytes from controller
         // using loop index broken, have to unroll...
@@ -7081,8 +7365,10 @@ BX_INFO("floppy: drive>1 || head>1 ...\n");
             // AL=number of sectors written=0
             AX = 0x0300;
             SET_CF();
+             debug_outb(0x2fb, 0xe3);  
             return;
           } else {
+           debug_outb(0x2fb, 0xe3);    
             BX_PANIC("int13_diskette_function: read error\n");
           }
         }
@@ -7092,6 +7378,7 @@ BX_INFO("floppy: drive>1 || head>1 ...\n");
         // AL = number of sectors read (same value as passed)
         SET_AH(0x00); // success
         CLEAR_CF();   // success
+         debug_outb(0x2fb, 0xe3);      
         return;
         }
       else {  // if (ah == 0x04)
@@ -7102,6 +7389,7 @@ BX_INFO("floppy: drive>1 || head>1 ...\n");
         // AL = number of sectors verified (same value as passed)
         CLEAR_CF();   // success
         SET_AH(0x00); // success
+         debug_outb(0x2fb, 0xe3);      
         return;
         }
 
@@ -7126,6 +7414,7 @@ BX_DEBUG_INT13_FL("floppy f05\n");
         SET_AH(0x80); // drive not responding
         set_diskette_ret_status(0x80);
         SET_CF(); // error occurred
+         debug_outb(0x2fb, 0xe3);      
         return;
         }
 
@@ -7136,6 +7425,7 @@ BX_DEBUG_INT13_FL("floppy f05\n");
           set_diskette_ret_status(0x0C);
           SET_AL(0); // no sectors read
           SET_CF(); // error occurred
+           debug_outb(0x2fb, 0xe3);    
           return;
           }
         }
@@ -7158,6 +7448,7 @@ BX_DEBUG_INT13_FL("floppy f05\n");
         set_diskette_ret_status(0x09);
         SET_AL(0); // no sectors read
         SET_CF(); // error occurred
+         debug_outb(0x2fb, 0xe3);      
         return;
         }
 
@@ -7193,8 +7484,10 @@ BX_DEBUG_INT13_FL("floppy f05\n");
 
       // check port 3f4 for drive readiness
       val8 = inb(0x3f4);
-      if ( (val8 & 0xf0) != 0x80 )
+      if ( (val8 & 0xf0) != 0x80 ) {
+        debug_outb(0x2fb, 0xe3);       
         BX_PANIC("int13_diskette:f05: ctrl not ready\n");
+       }
 
       // send read-normal-data command (6 bytes) to controller
       outb(0x03f5, 0x4d); // 4d: format track
@@ -7223,8 +7516,10 @@ BX_DEBUG_INT13_FL("floppy f05\n");
       write_byte(0x0000, 0x043e, val8);
       // check port 3f4 for accessibility to status bytes
       val8 = inb(0x3f4);
-      if ( (val8 & 0xc0) != 0xc0 )
+      if ( (val8 & 0xc0) != 0xc0 ) {
+        debug_outb(0x2fb, 0xe3);       
         BX_PANIC("int13_diskette: ctrl not ready\n");
+       }
 
       // read 7 return status bytes from controller
       // using loop index broken, have to unroll...
@@ -7251,8 +7546,10 @@ BX_DEBUG_INT13_FL("floppy f05\n");
           // AL=number of sectors written=0
           AX = 0x0300;
           SET_CF();
+           debug_outb(0x2fb, 0xe3);    
           return;
         } else {
+         debug_outb(0x2fb, 0xe3);      
           BX_PANIC("int13_diskette_function: write error\n");
         }
       }
@@ -7261,6 +7558,7 @@ BX_DEBUG_INT13_FL("floppy f05\n");
       set_diskette_ret_status(0);
       set_diskette_current_cyl(drive, 0);
       CLEAR_CF(); // successful
+        debug_outb(0x2fb, 0xe3);       
       return;
 
 
@@ -7277,6 +7575,7 @@ BX_DEBUG_INT13_FL("floppy f08\n");
         DI = 0;
         SET_DL(num_floppies);
         SET_CF();
+         debug_outb(0x2fb, 0xe3);      
         return;
         }
 
@@ -7345,6 +7644,7 @@ BX_DEBUG_INT13_FL("floppy f08\n");
           break;
 
         default: // ?
+         debug_outb(0x2fb, 0xe3);      
           BX_PANIC("floppy: int13: bad floppy type\n");
         }
 
@@ -7359,6 +7659,7 @@ ASM_START
 ASM_END
       CLEAR_CF(); // success
       /* disk status not changed upon success */
+        debug_outb(0x2fb, 0xe3);       
       return;
 
 
@@ -7369,6 +7670,7 @@ BX_DEBUG_INT13_FL("floppy f15\n");
         SET_AH(0); // only 2 drives supported
         // set_diskette_ret_status here ???
         SET_CF();
+         debug_outb(0x2fb, 0xe3);      
         return;
         }
       drive_type = inb_cmos(0x10);
@@ -7394,12 +7696,14 @@ BX_DEBUG_INT13_FL("floppy f16\n");
         SET_AH(0x01); // invalid drive
         set_diskette_ret_status(0x01);
         SET_CF();
+         debug_outb(0x2fb, 0xe3);      
         return;
         }
 
       SET_AH(0x06); // change line not supported
       set_diskette_ret_status(0x06);
       SET_CF();
+        debug_outb(0x2fb, 0xe3);       
       return;
 
     case 0x17: // set diskette type for format(old)
@@ -7408,6 +7712,7 @@ BX_DEBUG_INT13_FL("floppy f17\n");
       SET_AH(0x01); // not supported
       set_diskette_ret_status(1); /* not supported */
       SET_CF();
+        debug_outb(0x2fb, 0xe3);       
       return;
 
     case 0x18: // set diskette type for format(new)
@@ -7415,6 +7720,7 @@ BX_DEBUG_INT13_FL("floppy f18\n");
       SET_AH(0x01); // do later
       set_diskette_ret_status(1);
       SET_CF();
+        debug_outb(0x2fb, 0xe3);       
       return;
 
     default:
@@ -7424,6 +7730,7 @@ BX_DEBUG_INT13_FL("floppy f18\n");
         SET_AH(0x01); // ???
         set_diskette_ret_status(1);
         SET_CF();
+         debug_outb(0x2fb, 0xe3);      
         return;
       //   }
     }
@@ -7444,6 +7751,7 @@ int13_diskette_function(DS, ES, DI, SI, BP, ELDX, BX, DX, CX, AX, IP, CS, FLAGS)
       if (val8) {
         SET_CF();
         }
+         debug_outb(0x2fb, 0xe3);      
       return;
 
     default:
@@ -7451,6 +7759,7 @@ int13_diskette_function(DS, ES, DI, SI, BP, ELDX, BX, DX, CX, AX, IP, CS, FLAGS)
       write_byte(0x0000, 0x0441, 0x01);
       SET_AH(0x01);
     }
+      debug_outb(0x2fb, 0xe3); 
 }
 #endif  // #if BX_SUPPORT_FLOPPY
 
@@ -7574,6 +7883,8 @@ Bit8u bseqnr;
   Bit16u bootseg;
   Bit16u status;
   Bit8u  lastdrive=0;
+  //  BX_DEBUG("rombios: int19 (%d)\n",bseqnr);
 
   // if BX_ELTORITO_BOOT is not defined, old behavior
   //   check bit 5 in CMOS reg 0x2d.  load either 0x00 or 0x80 into DL
@@ -7623,16 +7934,19 @@ Bit8u bseqnr;
   if (bootcd != 0) {
     status = cdrom_boot();
 
+    BX_DEBUG("CDBoot:%x\n",status);
+       
+
     // If failure
     if ( (status & 0x00ff) !=0 ) {
       print_cdromboot_failure(status);
       print_boot_failure(bootcd, bootdrv, 1, lastdrive);
       return 0x00000000;
-      }
-
+    }
+    
     bootseg = read_word(ebda_seg,&EbdaData->cdemu.load_segment);
     bootdrv = (Bit8u)(status>>8);
-    }
+  }
 
 #endif // BX_ELTORITO_BOOT
 
@@ -7640,6 +7954,8 @@ Bit8u bseqnr;
   if (bootcd == 0) {
     bootseg=0x07c0;
 
+    
+
 ASM_START
     push bp
     mov  bp, sp
@@ -7664,6 +7980,7 @@ int19_load_done:
     pop  bp
 ASM_END
     
+
     if (status != 0) {
       print_boot_failure(bootcd, bootdrv, 1, lastdrive);
       return 0x00000000;
@@ -7691,11 +8008,14 @@ ASM_END
   
 #if BX_ELTORITO_BOOT
   // Print out the boot string
+  BX_DEBUG("cdrom_boot: %x\n",status);
   print_boot_device(bootcd, bootdrv);
 #else // BX_ELTORITO_BOOT
   print_boot_device(0, bootdrv);
 #endif // BX_ELTORITO_BOOT
 
+  BX_DEBUG("boot to %x\n", (((Bit32u)bootdrv) << 16) + bootseg);
+
   // return the boot segment
   return (((Bit32u)bootdrv) << 16) + bootseg;
 }
@@ -8223,7 +8543,9 @@ boot_setup:
   mov [bp],  ax      ;; set bp to zero
   mov ax,    #0xaa55 ;; set ok flag
 
+
   pop bp
+
   iret               ;; Beam me up Scotty
 
 ;----------
@@ -8315,6 +8637,16 @@ hard_drive_post:
   // IRQ 14 = INT 76h
   // INT 76h calls INT 15h function ax=9100
 
+#if DEBUG_RAMDISK
+
+  mov al, #0xfc
+  mov dx, #0x02ec
+  out dx, al
+  mov ax, #0x0000
+  mov dx, #0x0000
+
+#endif
+
   mov  al, #0x0a   ; 0000 1010 = reserved, disable IRQ 14
   mov  dx, #0x03f6
   out  dx, al
@@ -8760,7 +9092,7 @@ int76_handler:
   mov   ds, ax
   mov   0x008E, #0xff
   call  eoi_both_pics
-  pop   ds
+  pop   ds  
   pop   ax
   iret
 
@@ -9426,6 +9758,7 @@ rom_scan_loop:
   jne  rom_scan_increment
   call rom_checksum
   jnz  rom_scan_increment
+
   mov  al, [2]  ;; change increment to ROM length in 512-byte blocks
 
   ;; We want our increment in 512-byte quantities, rounded to
@@ -9753,6 +10086,8 @@ post_default_ints:
   ;; Video setup
   SET_INT_VECTOR(0x10, #0xF000, #int10_handler)
 
+
+
   ;; PIC
   mov al, #0x11 ; send initialisation commands
   out 0x20, al
@@ -9784,6 +10119,19 @@ post_default_ints:
 
   call rom_scan
 
+
+  ;; JRL CHANGE
+  ;;push ax
+  ;;push bx
+  ;;mov  ah, #0x0e
+  ;;mov  al, #0x41
+  ;;xor  bx,bx
+  ;;int  #0x10
+  ;;pop  bx
+  ;;pop ax
+
+
+
   call _print_bios_banner 
 
   ;;