Index: /trunk/src/VBox/Devices/PC/BIOS-new/ahci.c
===================================================================
--- /trunk/src/VBox/Devices/PC/BIOS-new/ahci.c	(revision 39582)
+++ /trunk/src/VBox/Devices/PC/BIOS-new/ahci.c	(revision 39583)
@@ -26,10 +26,8 @@
 #include "vds.h"
 
-#define VBOX_AHCI_DEBUG         0
-
-#if VBOX_AHCI_DEBUG
-# define VBOXAHCI_DEBUG(...)        BX_INFO(__VA_ARGS__)
+#if DEBUG_AHCI
+# define DBG_AHCI(...)        BX_INFO(__VA_ARGS__)
 #else
-# define VBOXAHCI_DEBUG(...)
+# define DBG_AHCI(...)
 #endif
 
@@ -258,5 +256,5 @@
 
         /* Wait for a D2H FIS. */
-        VBOXAHCI_DEBUG("AHCI: Waiting for D2H FIS\n");
+        DBG_AHCI("AHCI: Waiting for D2H FIS\n");
         while (ahci_ctrl_is_bit_set(io_base, AHCI_PORT_REG(port, AHCI_REG_PORT_IS),
                                     AHCI_REG_PORT_IS_DHRS) == 0)
@@ -275,5 +273,5 @@
     }
     else
-        VBOXAHCI_DEBUG("AHCI: Invalid port given\n");
+        DBG_AHCI("AHCI: Invalid port given\n");
 }
 
@@ -353,5 +351,5 @@
                                     AHCI_REG_PORT_CMD_FRE | AHCI_REG_PORT_CMD_ST | AHCI_REG_PORT_CMD_FR | AHCI_REG_PORT_CMD_CR) == 1)
         {
-            VBOXAHCI_DEBUG("AHCI: Waiting for the port to idle\n");
+            DBG_AHCI("AHCI: Waiting for the port to idle\n");
         }
 
@@ -394,5 +392,5 @@
                                 AHCI_REG_PORT_CMD_FRE | AHCI_REG_PORT_CMD_ST | AHCI_REG_PORT_CMD_FR | AHCI_REG_PORT_CMD_CR) == 1)
     {
-        VBOXAHCI_DEBUG("AHCI: Waiting for the port to idle\n");
+        DBG_AHCI("AHCI: Waiting for the port to idle\n");
     }
 
@@ -406,9 +404,10 @@
     _fmemset(&ahci->abFisRecv[0], 0, sizeof(ahci->abFisRecv));
 
-    VBOXAHCI_DEBUG("AHCI: FIS receive area %lx from %x:%x\n", ahci_addr_to_phys(&ahci->abFisRecv), FP_SEG(ahci), &AhciData->abFisRecv);
+    DBG_AHCI("AHCI: FIS receive area %lx from %x:%x\n",
+             ahci_addr_to_phys(&ahci->abFisRecv), FP_SEG(ahci), &AhciData->abFisRecv);
     VBOXAHCI_PORT_WRITE_REG(ahci->iobase, u8Port, AHCI_REG_PORT_FB, ahci_addr_to_phys(&ahci->abFisRecv));
     VBOXAHCI_PORT_WRITE_REG(ahci->iobase, u8Port, AHCI_REG_PORT_FBU, 0);
 
-    VBOXAHCI_DEBUG("AHCI: CMD list area %lx\n", ahci_addr_to_phys(&ahci->aCmdHdr));
+    DBG_AHCI("AHCI: CMD list area %lx\n", ahci_addr_to_phys(&ahci->aCmdHdr));
     VBOXAHCI_PORT_WRITE_REG(ahci->iobase, u8Port, AHCI_REG_PORT_CLB, ahci_addr_to_phys(&ahci->aCmdHdr));
     VBOXAHCI_PORT_WRITE_REG(ahci->iobase, u8Port, AHCI_REG_PORT_CLBU, 0);
@@ -438,7 +437,7 @@
         BX_PANIC("%s: device_id out of range %d\n", __func__, device_id);
 
-    VBOXAHCI_DEBUG("%s: %u sectors @ LBA %lu, device %d, port %d\n", __func__,
-                   bios_dsk->drqp.nsect, bios_dsk->drqp.lba, device_id,
-                   bios_dsk->ahcidev[device_id].port);
+    DBG_AHCI("%s: %u sectors @ LBA %lu, device %d, port %d\n", __func__,
+             bios_dsk->drqp.nsect, bios_dsk->drqp.lba, device_id,
+             bios_dsk->ahcidev[device_id].port);
 
     ahci_port_init(bios_dsk->ahci_seg :> 0, bios_dsk->ahcidev[device_id].port);
@@ -465,7 +464,7 @@
         BX_PANIC("%s: device_id out of range %d\n", __func__, device_id);
 
-    VBOXAHCI_DEBUG("%s: %u sectors @ LBA %lu, device %d, port %d\n", __func__,
-                   bios_dsk->drqp.nsect, bios_dsk->drqp.lba, device_id,
-                   bios_dsk->ahcidev[device_id].port);
+    DBG_AHCI("%s: %u sectors @ LBA %lu, device %d, port %d\n", __func__,
+             bios_dsk->drqp.nsect, bios_dsk->drqp.lba, device_id,
+             bios_dsk->ahcidev[device_id].port);
 
     ahci_port_init(bios_dsk->ahci_seg :> 0, bios_dsk->ahcidev[device_id].port);
@@ -493,5 +492,5 @@
     /* The header length must be even. */
     if (header & 1) {
-        VBOXAHCI_DEBUG("%s: header must be even (%04x)\n", __func__, header);
+        DBG_AHCI("%s: header must be even (%04x)\n", __func__, header);
         return 1;
     }
@@ -500,11 +499,13 @@
     device_id = device_id - BX_MAX_ATA_DEVICES - BX_MAX_SCSI_DEVICES;
 
-    VBOXAHCI_DEBUG("%s: reading %lu bytes, header %u, device %d, port %d\n", __func__,
-                   length, header, device_id, bios_dsk->ahcidev[device_id].port);
+    DBG_AHCI("%s: reading %lu bytes, header %u, device %d, port %d\n", __func__,
+             length, header, device_id, bios_dsk->ahcidev[device_id].port);
+    DBG_AHCI("%s: reading %u %u-byte sectors\n", __func__,
+             bios_dsk->drqp.nsect, bios_dsk->drqp.sect_sz);
 
     bios_dsk->drqp.lba     = (uint32_t)length << 8;     //@todo: xfer length limit
     bios_dsk->drqp.buffer  = buffer;
-    bios_dsk->drqp.nsect   = length / 2048;
-    bios_dsk->drqp.sect_sz = 2048;
+//    bios_dsk->drqp.nsect   = length / 2048;
+//    bios_dsk->drqp.sect_sz = 2048;
 
     ahci_port_init(bios_dsk->ahci_seg :> 0, bios_dsk->ahcidev[device_id].port);
@@ -519,5 +520,5 @@
 
     ahci_cmd_data(bios_dsk, ATA_CMD_PACKET);
-    VBOXAHCI_DEBUG("%s: transferred %lu bytes\n", __func__, ahci->aCmdHdr[1]);
+    DBG_AHCI("%s: transferred %lu bytes\n", __func__, ahci->aCmdHdr[1]);
     bios_dsk->drqp.trsfbytes = ahci->aCmdHdr[1];
 #ifdef DMA_WORKAROUND
@@ -556,5 +557,5 @@
         devcount_ahci = bios_dsk->ahci_devcnt;
 
-        VBOXAHCI_DEBUG("AHCI: Device detected on port %d\n", u8Port);
+        DBG_AHCI("AHCI: Device detected on port %d\n", u8Port);
 
         //@todo: Merge common HD/CDROM detection code
@@ -573,5 +574,5 @@
                 uint8_t     idxCmosChsBase;
 
-                VBOXAHCI_DEBUG("AHCI: Detected hard disk\n");
+                DBG_AHCI("AHCI: Detected hard disk\n");
 
                 /* Identify device. */
@@ -595,5 +596,5 @@
                     cSectors = *(uint16_t *)(abBuffer+(100*2)); // words 100 to 103 (someday)
 
-                VBOXAHCI_DEBUG("AHCI: %ld sectors\n", cSectors);
+                DBG_AHCI("AHCI: %ld sectors\n", cSectors);
 
                 bios_dsk->ahcidev[devcount_ahci].port = u8Port;
@@ -640,6 +641,6 @@
                     cSectorsPerTrack = 0;
                 }
-                VBOXAHCI_DEBUG("AHCI: Dev %d LCHS=%d/%d/%d\n", 
-                               devcount_ahci, cCylinders, cHeads, cSectorsPerTrack);
+                DBG_AHCI("AHCI: Dev %d LCHS=%d/%d/%d\n", 
+                         devcount_ahci, cCylinders, cHeads, cSectorsPerTrack);
 
                 bios_dsk->devices[hd_index].lchs.heads     = cHeads;
@@ -660,5 +661,5 @@
             else if (val == 0xeb140101)
             {
-                VBOXAHCI_DEBUG("AHCI: Detected ATAPI device\n");
+                DBG_AHCI("AHCI: Detected ATAPI device\n");
 
                 /* Identify packet device. */
@@ -687,5 +688,5 @@
             }
             else
-                VBOXAHCI_DEBUG("AHCI: Ignoring unknown device\n");
+                DBG_AHCI("AHCI: Ignoring unknown device\n");
 
             devcount_ahci++;
@@ -693,5 +694,5 @@
         }
         else
-            VBOXAHCI_DEBUG("AHCI: Reached maximum device count, skipping\n");
+            DBG_AHCI("AHCI: Reached maximum device count, skipping\n");
     }
 }
@@ -707,5 +708,5 @@
     base_mem_kb = read_word(0x00, 0x0413);
 
-    VBOXAHCI_DEBUG("AHCI: %dK of base mem\n", base_mem_kb);
+    DBG_AHCI("AHCI: %dK of base mem\n", base_mem_kb);
 
     if (base_mem_kb == 0)
@@ -733,7 +734,7 @@
 
     AHCI_READ_REG(io_base, AHCI_REG_VS, val);
-    VBOXAHCI_DEBUG("AHCI: Controller has version: 0x%x (major) 0x%x (minor)\n",
-                   ahci_ctrl_extract_bits(val, 0xffff0000, 16),
-                   ahci_ctrl_extract_bits(val, 0x0000ffff,  0));
+    DBG_AHCI("AHCI: Controller version: 0x%x (major) 0x%x (minor)\n",
+             ahci_ctrl_extract_bits(val, 0xffff0000, 16),
+             ahci_ctrl_extract_bits(val, 0x0000ffff,  0));
 
     /* Allocate 1K of base memory. */
@@ -741,9 +742,9 @@
     if (ahci_seg == 0)
     {
-        VBOXAHCI_DEBUG("AHCI: Could not allocate 1K of memory, can't boot from controller\n");
+        DBG_AHCI("AHCI: Could not allocate 1K of memory, can't boot from controller\n");
         return 0;
     }
-    VBOXAHCI_DEBUG("AHCI: ahci_seg=%04x, size=%04x, pointer at EBDA:%04x (EBDA size=%04x)\n", 
-                   ahci_seg, sizeof(ahci_t), (uint16_t)&EbdaData->bdisk.ahci_seg, sizeof(ebda_data_t));
+    DBG_AHCI("AHCI: ahci_seg=%04x, size=%04x, pointer at EBDA:%04x (EBDA size=%04x)\n", 
+             ahci_seg, sizeof(ahci_t), (uint16_t)&EbdaData->bdisk.ahci_seg, sizeof(ebda_data_t));
 
     write_word(ebda_seg, (uint16_t)&EbdaData->bdisk.ahci_seg, ahci_seg);
@@ -762,5 +763,5 @@
     cPorts = ahci_ctrl_extract_bits(val, 0x1f, 0) + 1; /* Extract number of ports.*/
 
-    VBOXAHCI_DEBUG("AHCI: HBA has %u ports\n", cPorts);
+    DBG_AHCI("AHCI: HBA has %u ports\n", cPorts);
 
     /* Go through the ports. */
@@ -770,5 +771,5 @@
         if (ahci_ctrl_is_bit_set(io_base, AHCI_REG_PI, RT_BIT_32(i)) != 0)
         {
-            VBOXAHCI_DEBUG("AHCI: Port %u is present\n", i);
+            DBG_AHCI("AHCI: Port %u is present\n", i);
             ahci_port_detect_device(ahci_seg :> 0, i);
             cPorts--;
@@ -798,5 +799,5 @@
         u8DevFn = busdevfn & 0x00ff;
 
-        VBOXAHCI_DEBUG("AHCI HBA at Bus %u DevFn 0x%x (raw 0x%x)\n", u8Bus, u8DevFn, busdevfn);
+        DBG_AHCI("AHCI HBA at Bus %u DevFn 0x%x (raw 0x%x)\n", u8Bus, u8DevFn, busdevfn);
 
         /* Examine the capability list and search for the Serial ATA Capability Register. */
@@ -807,5 +808,5 @@
             uint8_t     u8PciCapId = pci_read_config_byte(u8Bus, u8DevFn, u8PciCapOff);
 
-            VBOXAHCI_DEBUG("Capability ID 0x%x at 0x%x\n", u8PciCapId, u8PciCapOff);
+            DBG_AHCI("Capability ID 0x%x at 0x%x\n", u8PciCapId, u8PciCapOff);
 
             if (u8PciCapId == PCI_CAP_ID_SATACR)
@@ -820,5 +821,5 @@
             uint8_t     u8Rev;
 
-            VBOXAHCI_DEBUG("AHCI HBA with SATA Capability register at 0x%x\n", u8PciCapOff);
+            DBG_AHCI("AHCI HBA with SATA Capability register at 0x%x\n", u8PciCapOff);
 
             /* Advance to the stuff behind the id and next capability pointer. */
@@ -833,5 +834,5 @@
                 uint16_t    u16BarOff = pci_read_config_word(u8Bus, u8DevFn, u8PciCapOff + 2);
 
-                VBOXAHCI_DEBUG("SATACR1: 0x%x\n", u16BarOff);
+                DBG_AHCI("SATACR1: 0x%x\n", u16BarOff);
 
                 switch (u16BarOff & 0xf)
@@ -858,5 +859,5 @@
                     default:
                         /* Reserved or unsupported. */
-                        VBOXAHCI_DEBUG("BAR 0x%x unsupported\n", u16BarOff & 0xf);
+                        DBG_AHCI("BAR 0x%x unsupported\n", u16BarOff & 0xf);
                 }
 
@@ -868,5 +869,5 @@
                     uint32_t    u32Bar = pci_read_config_dword(u8Bus, u8DevFn, u8Bar);
 
-                    VBOXAHCI_DEBUG("BAR at 0x%x : 0x%x\n", u8Bar, u32Bar);
+                    DBG_AHCI("BAR at 0x%x : 0x%x\n", u8Bar, u32Bar);
 
                     if ((u32Bar & 0x01) != 0)
@@ -875,18 +876,18 @@
                         uint16_t    u16AhciIoBase = (u32Bar & 0xfff0) + u16Off;
 
-                        VBOXAHCI_DEBUG("I/O base: 0x%x\n", u16AhciIoBase);
+                        DBG_AHCI("I/O base: 0x%x\n", u16AhciIoBase);
                         rc = ahci_hba_init(u16AhciIoBase);
                     }
                     else
-                        VBOXAHCI_DEBUG("BAR is MMIO\n");
+                        DBG_AHCI("BAR is MMIO\n");
                 }
             }
             else
-                VBOXAHCI_DEBUG("Invalid revision 0x%x\n", u8Rev);
+                DBG_AHCI("Invalid revision 0x%x\n", u8Rev);
         }
         else
-            VBOXAHCI_DEBUG("AHCI HBA with no usable Index/Data register pair!\n");
+            DBG_AHCI("AHCI HBA with no usable Index/Data register pair!\n");
     }
     else
-        VBOXAHCI_DEBUG("No AHCI HBA!\n");
-}
+        DBG_AHCI("No AHCI HBA!\n");
+}
Index: /trunk/src/VBox/Devices/PC/BIOS-new/biosint.h
===================================================================
--- /trunk/src/VBox/Devices/PC/BIOS-new/biosint.h	(revision 39582)
+++ /trunk/src/VBox/Devices/PC/BIOS-new/biosint.h	(revision 39583)
@@ -52,4 +52,6 @@
 
 #define DEBUG_ATA       0
+#define DEBUG_AHCI      0
+#define DEBUG_CD_BOOT   0
 #define DEBUG_ELTORITO  0
 #define DEBUG_INT13_HD  0
Index: /trunk/src/VBox/Devices/PC/BIOS-new/eltorito.c
===================================================================
--- /trunk/src/VBox/Devices/PC/BIOS-new/eltorito.c	(revision 39582)
+++ /trunk/src/VBox/Devices/PC/BIOS-new/eltorito.c	(revision 39583)
@@ -59,6 +59,5 @@
 #endif
 
-//@todo: call this something else? ET_BOOT?
-#if DEBUG_ELTORITO
+#if DEBUG_CD_BOOT
 #  define BX_DEBUG_ELTORITO(...)    BX_DEBUG(__VA_ARGS__)
 #else
@@ -234,14 +233,16 @@
 {
     // @TODO: a macro or a function for getting the EBDA segment
-    uint16_t        ebda_seg=read_word(0x0040,0x000E);
-    uint8_t         buffer[2048];
-    cdb_atapi       atapicmd;
-    uint32_t        lba;
-    uint16_t        boot_segment, nbsectors, i, error;
-    uint8_t         device;
-    uint8_t         read_try;
-    cdemu_t __far   *cdemu;
-
-    cdemu = ebda_seg :> &EbdaData->cdemu;
+    uint16_t            ebda_seg=read_word(0x0040,0x000E);
+    uint8_t             buffer[2048];
+    cdb_atapi           atapicmd;
+    uint32_t            lba;
+    uint16_t            boot_segment, nbsectors, i, error;
+    uint8_t             device;
+    uint8_t             read_try;
+    cdemu_t __far       *cdemu;
+    bio_dsk_t __far     *bios_dsk;
+
+    cdemu    = ebda_seg :> &EbdaData->cdemu;
+    bios_dsk = ebda_seg :> &EbdaData->bdisk;
 
     /* Find the first CD-ROM. */
@@ -259,5 +260,8 @@
     atapicmd.command = 0x28;    // READ 10 command
     atapicmd.lba     = swap_32(0x11);
-    atapicmd.nsect   = swap_16(0x01);
+    atapicmd.nsect   = swap_16(1);
+
+    bios_dsk->drqp.nsect   = 1;
+    bios_dsk->drqp.sect_sz = 2048;
 
     for (read_try = 0; read_try <= 4; ++read_try)
@@ -286,5 +290,4 @@
             return 6;
 
-    //@todo: this swaps the LBA back and forth for no good reason??!
     // ok, now we calculate the Boot catalog address
     lba = *((uint32_t *)&buffer[0x47]);
@@ -292,8 +295,12 @@
 
     /* Now we read the Boot Catalog. */
-    _fmemset(&atapicmd, 0, sizeof(atapicmd));   //@todo: should be redundant
     atapicmd.command = 0x28;    // READ 10 command
     atapicmd.lba     = swap_32(lba);
-    atapicmd.nsect   = swap_16(0x01);
+    atapicmd.nsect   = swap_16(1);
+
+#if 0   // Not necessary as long as previous values are reused
+    bios_dsk->drqp.nsect   = 1;
+    bios_dsk->drqp.sect_sz = 512;
+#endif
 
     if (device > BX_MAX_ATA_DEVICES)
@@ -352,8 +359,10 @@
 
     /* Read the disk image's boot sector into memory. */
-    _fmemset(&atapicmd, 0, sizeof(atapicmd));   //@todo: should be redundant
     atapicmd.command = 0x28;    // READ 10 command
     atapicmd.lba     = swap_32(lba);
     atapicmd.nsect   = swap_16(1 + (nbsectors - 1) / 4);
+
+    bios_dsk->drqp.nsect   = 1 + (nbsectors - 1) / 4;
+    bios_dsk->drqp.sect_sz = 512;
 
     if (device > BX_MAX_ATA_DEVICES)
@@ -419,14 +428,16 @@
 {
     // @TODO: a macro or a function for getting the EBDA segment
-    uint16_t        ebda_seg=read_word(0x0040,0x000E);
-    uint8_t         device, status;
-    uint16_t        vheads, vspt, vcylinders;
-    uint16_t        head, sector, cylinder, nbsectors;
-    uint32_t        vlba, ilba, slba, elba;
-    uint16_t        before, segment, offset;
-    cdb_atapi       atapicmd;
-    cdemu_t __far   *cdemu;
-
-    cdemu = ebda_seg :> &EbdaData->cdemu;
+    uint16_t            ebda_seg=read_word(0x0040,0x000E);
+    uint8_t             device, status;
+    uint16_t            vheads, vspt, vcylinders;
+    uint16_t            head, sector, cylinder, nbsectors;
+    uint32_t            vlba, ilba, slba, elba;
+    uint16_t            before, segment, offset;
+    cdb_atapi           atapicmd;
+    cdemu_t __far       *cdemu;
+    bio_dsk_t __far     *bios_dsk;
+
+    cdemu    = ebda_seg :> &EbdaData->cdemu;
+    bios_dsk = ebda_seg :> &EbdaData->bdisk;
 
     BX_DEBUG_INT13_ET("%s: AX=%04x BX=%04x CX=%04x DX=%04x ES=%04x\n", __func__, AX, BX, CX, DX, ES);
@@ -528,4 +539,7 @@
         atapicmd.lba     = swap_32(ilba + slba);
         atapicmd.nsect   = swap_16(elba - slba + 1);
+
+        bios_dsk->drqp.nsect   = elba - slba + 1;
+        bios_dsk->drqp.sect_sz = 512;
 
         if (device > BX_MAX_ATA_DEVICES)
@@ -726,4 +740,7 @@
         atapicmd.lba     = swap_32(lba);
         atapicmd.nsect   = swap_16(count);
+
+        bios_dsk->drqp.nsect   = count;
+        bios_dsk->drqp.sect_sz = 2048;
 
         if (device > BX_MAX_ATA_DEVICES)
