Index: trunk/src/VBox/Devices/Storage/DevFdc.cpp
===================================================================
--- trunk/src/VBox/Devices/Storage/DevFdc.cpp	(revision 78039)
+++ trunk/src/VBox/Devices/Storage/DevFdc.cpp	(revision 78040)
@@ -65,27 +65,13 @@
 /* #define DEBUG_FLOPPY */
 
-#ifndef VBOX
-    #ifdef DEBUG_FLOPPY
-    #define FLOPPY_DPRINTF(fmt, args...) \
-        do { printf("FLOPPY: " fmt , ##args); } while (0)
-    #endif
-#else /* !VBOX */
-# ifdef LOG_ENABLED
-#  define FLOPPY_DPRINTF(...) Log(("floppy: " __VA_ARGS__))
-# else
-#  define FLOPPY_DPRINTF(...) do { } while (0)
-# endif
-#endif /* !VBOX */
-
-#ifndef VBOX
-#define FLOPPY_ERROR(fmt, args...) \
-    do { printf("FLOPPY ERROR: %s: " fmt, __func__ , ##args); } while (0)
-#else /* VBOX */
-#   define FLOPPY_ERROR RTLogPrintf
-#endif /* VBOX */
-
-#ifdef VBOX
+#ifdef LOG_ENABLED
+# define FLOPPY_DPRINTF(...) Log(("floppy: " __VA_ARGS__))
+#else
+# define FLOPPY_DPRINTF(...) do { } while (0)
+#endif
+
+#define FLOPPY_ERROR RTLogPrintf
+
 typedef struct fdctrl_t fdctrl_t;
-#endif /* VBOX */
 
 /********************************************************/
@@ -105,9 +91,7 @@
     FDRIVE_DRV_288  = 0x01,   /* 2.88 MB 3"5 drive      */
     FDRIVE_DRV_120  = 0x02,   /* 1.2  MB 5"25 drive     */
-    FDRIVE_DRV_NONE = 0x03    /* No drive connected     */
-#ifdef VBOX
-    , FDRIVE_DRV_FAKE_15_6 = 0x0e /* Fake 15.6 MB drive. */
-    , FDRIVE_DRV_FAKE_63_5 = 0x0f /* Fake 63.5 MB drive. */
-#endif
+    FDRIVE_DRV_NONE = 0x03,   /* No drive connected     */
+    FDRIVE_DRV_FAKE_15_6 = 0x0e, /* Fake 15.6 MB drive. */
+    FDRIVE_DRV_FAKE_63_5 = 0x0f  /* Fake 63.5 MB drive. */
 } fdrive_type_t;
 
@@ -130,7 +114,4 @@
  */
 typedef struct fdrive_t {
-#ifndef VBOX
-    BlockDriverState *bs;
-#else /* VBOX */
     /** Pointer to the owning device instance. */
     R3PTRTYPE(PPDMDEVINS)           pDevIns;
@@ -152,5 +133,4 @@
     /** The LED for this LUN. */
     PDMLED                          Led;
-#endif
     /* Drive status */
     fdrive_type_t drive;
@@ -176,7 +156,4 @@
 {
     /* Drive */
-#ifndef VBOX
-    drv->drive = FDRIVE_DRV_NONE;
-#else  /* VBOX */
     if (fInit) {
         /* Fixate the drive type at init time if possible. */
@@ -210,5 +187,4 @@
     } /* else: The BIOS (and others) get the drive type via the CMOS, so
                don't change it after the VM has been constructed. */
-#endif /* VBOX */
     drv->perpendicular = 0;
     /* Disk */
@@ -361,5 +337,5 @@
     { FDRIVE_DRV_144,  8, 40, 1, FDRIVE_RATE_300K,  "320 kB 3\"1/2", },
     { FDRIVE_DRV_144,  8, 40, 0, FDRIVE_RATE_300K,  "160 kB 3\"1/2", },
-#ifdef VBOX /* For larger than real life floppy images (see DrvBlock.cpp). */
+    /* For larger than real life floppy images (see DrvBlock.cpp). */
     /* 15.6 MB fake floppy disk (just need something big). */
     { FDRIVE_DRV_FAKE_15_6,  63, 255, 1, FDRIVE_RATE_1M,   "15.6 MB fake 15.6", },
@@ -407,5 +383,4 @@
     { FDRIVE_DRV_FAKE_63_5,  14,  80, 1, FDRIVE_RATE_250K, "1.12 MB fake 63.5", },
     { FDRIVE_DRV_FAKE_63_5,   9,  80, 0, FDRIVE_RATE_250K,  "360 kB fake 63.5", },
-#endif
     /* end */
     { FDRIVE_DRV_NONE, (uint8_t)-1, (uint8_t)-1, 0, (fdrive_rate_t)0, NULL, },
@@ -421,9 +396,4 @@
 
     FLOPPY_DPRINTF("revalidate\n");
-#ifndef VBOX
-    if (drv->bs != NULL && bdrv_is_inserted(drv->bs)) {
-        ro = bdrv_is_read_only(drv->bs);
-        bdrv_get_geometry_hint(drv->bs, &nb_heads, &max_track, &last_sect);
-#else /* VBOX */
     if (   drv->pDrvMedia
         && drv->pDrvMount
@@ -431,17 +401,10 @@
         ro = drv->pDrvMedia->pfnIsReadOnly (drv->pDrvMedia);
         nb_heads = max_track = last_sect = 0;
-#endif /* VBOX */
         if (nb_heads != 0 && max_track != 0 && last_sect != 0) {
             FLOPPY_DPRINTF("User defined disk (%d %d %d)",
                            nb_heads - 1, max_track, last_sect);
         } else {
-#ifndef VBOX
-            bdrv_get_geometry(drv->bs, &nb_sectors);
-#else /* VBOX */
-            {
-                uint64_t size2 = drv->pDrvMedia->pfnGetSize (drv->pDrvMedia);
-                nb_sectors = size2 / FD_SECTOR_LEN;
-            }
-#endif /* VBOX */
+            uint64_t size2 = drv->pDrvMedia->pfnGetSize (drv->pDrvMedia);
+            nb_sectors = size2 / FD_SECTOR_LEN;
             match = -1;
             first_match = -1;
@@ -473,7 +436,5 @@
             last_sect = parse->last_sect;
             drv->drive = parse->drive;
-#ifdef VBOX
             drv->media_rate = parse->rate;
-#endif
             FLOPPY_DPRINTF("%s floppy disk (%d h %d t %d s) %s\n", parse->str,
                            nb_heads, max_track, last_sect, ro ? "ro" : "rw");
@@ -503,8 +464,4 @@
 static void fdctrl_reset(fdctrl_t *fdctrl, int do_irq);
 static void fdctrl_reset_fifo(fdctrl_t *fdctrl);
-#ifndef VBOX
-static int fdctrl_transfer_handler (void *opaque, int nchan,
-                                    int dma_pos, int dma_len);
-#else /* VBOX: */
 static DECLCALLBACK(uint32_t) fdctrl_transfer_handler (PPDMDEVINS pDevIns,
                                                        void *opaque,
@@ -512,5 +469,4 @@
                                                        uint32_t dma_pos,
                                                        uint32_t dma_len);
-#endif /* VBOX */
 static void fdctrl_raise_irq(fdctrl_t *fdctrl, uint8_t status0);
 static fdrive_t *get_cur_drv(fdctrl_t *fdctrl);
@@ -686,5 +642,4 @@
 #define FD_FORMAT_CMD(state) ((state) & FD_STATE_FORMAT)
 
-#ifdef VBOX
 /**
  * Floppy controller state.
@@ -692,26 +647,13 @@
  * @implements  PDMILEDPORTS
  */
-#endif
 struct fdctrl_t {
-#ifndef VBOX
-    fdctrl_t *fdctrl;
-#endif
     /* Controller's identification */
     uint8_t version;
     /* HW */
-#ifndef VBOX
-    int irq;
-    int dma_chann;
-#else
     uint8_t irq_lvl;
     uint8_t dma_chann;
-#endif
     uint32_t io_base;
     /* Controller state */
-#ifndef VBOX
-    QEMUTimer *result_timer;
-#else
     struct TMTIMER *result_timer;
-#endif
     uint8_t sra;
     uint8_t srb;
@@ -745,5 +687,4 @@
     fdrive_t drives[MAX_FD];
     uint8_t reset_sensei;
-#ifdef VBOX
     /** Pointer to device instance. */
     PPDMDEVINS pDevIns;
@@ -755,5 +696,4 @@
     /** Status LUN: The Partner of ILeds. */
     PPDMILEDCONNECTORS pLedsConnector;
-#endif
 };
 
@@ -827,9 +767,5 @@
         return;
     FLOPPY_DPRINTF("Reset interrupt\n");
-#ifdef VBOX
     PDMDevHlpISASetIrq (fdctrl->pDevIns, fdctrl->irq_lvl, 0);
-#else
-    qemu_set_irq(fdctrl->irq, 0);
-#endif
     fdctrl->sra &= ~FD_SRA_INTPEND;
 }
@@ -839,9 +775,5 @@
     if (!(fdctrl->sra & FD_SRA_INTPEND)) {
         FLOPPY_DPRINTF("Raising interrupt...\n");
-#ifdef VBOX
         PDMDevHlpISASetIrq (fdctrl->pDevIns, fdctrl->irq_lvl, 1);
-#else
-        qemu_set_irq(fdctrl->irq, 1);
-#endif
         fdctrl->sra |= FD_SRA_INTPEND;
     }
@@ -870,9 +802,5 @@
     fdctrl->sra = 0;
     fdctrl->srb = 0xc0;
-#ifdef VBOX
     if (!fdctrl->drives[1].pDrvMedia)
-#else
-    if (!fdctrl->drives[1].bs)
-#endif
         fdctrl->sra |= FD_SRA_nDRV2;
     fdctrl->cur_drv = 0;
@@ -1083,17 +1011,5 @@
 static int fdctrl_media_changed(fdrive_t *drv)
 {
-#ifdef VBOX
     return drv->dsk_chg;
-#else
-    int ret;
-
-    if (!drv->bs)
-        return 0;
-    ret = bdrv_media_changed(drv->bs);
-    if (ret) {
-        fd_revalidate(drv);
-    }
-    return ret;
-#endif
 }
 
@@ -1103,5 +1019,4 @@
     uint32_t retval = 0;
 
-#ifdef VBOX
     /* The change line signal is reported by the currently selected
      * drive. If the corresponding motor on bit is not set, the drive
@@ -1110,13 +1025,4 @@
     if (fdctrl_media_changed(get_cur_drv(fdctrl))
      && (fdctrl->dor & (0x10 << fdctrl->cur_drv)))
-#else
-    if (fdctrl_media_changed(drv0(fdctrl))
-     || fdctrl_media_changed(drv1(fdctrl))
-#if MAX_FD == 4
-     || fdctrl_media_changed(drv2(fdctrl))
-     || fdctrl_media_changed(drv3(fdctrl))
-#endif
-        )
-#endif
         retval |= FD_DIR_DSKCHG;
     if (retval != 0)
@@ -1211,9 +1117,5 @@
     fdctrl->data_dir = FD_DIR_READ;
     if (!(fdctrl->msr & FD_MSR_NONDMA)) {
-#ifdef VBOX
         PDMDevHlpDMASetDREQ (fdctrl->pDevIns, fdctrl->dma_chann, 0);
-#else
-        DMA_release_DREQ(fdctrl->dma_chann);
-#endif
     }
     fdctrl->msr |= FD_MSR_RQM | FD_MSR_DIO;
@@ -1280,5 +1182,4 @@
      * the currently inserted medium, the operation has to fail.
      */
-#ifdef VBOX
     if ((fdctrl->dsr & FD_DSR_DRATEMASK) != cur_drv->media_rate) {
         FLOPPY_DPRINTF("data rate mismatch (fdc=%d, media=%d)\n",
@@ -1290,5 +1191,4 @@
         return;
     }
-#endif
     /* Set the FIFO state */
     fdctrl->data_dir = direction;
@@ -1317,9 +1217,5 @@
         int dma_mode;
         /* DMA transfer are enabled. Check if DMA channel is well programmed */
-#ifndef VBOX
-        dma_mode = DMA_get_channel_mode(fdctrl->dma_chann);
-#else
         dma_mode = PDMDevHlpDMAGetChannelMode (fdctrl->pDevIns, fdctrl->dma_chann);
-#endif
         dma_mode = (dma_mode >> 2) & 3;
         FLOPPY_DPRINTF("dma_mode=%d direction=%d (%d - %d)\n",
@@ -1336,11 +1232,6 @@
              * recall us...
              */
-#ifndef VBOX
-            DMA_hold_DREQ(fdctrl->dma_chann);
-            DMA_schedule(fdctrl->dma_chann);
-#else
             PDMDevHlpDMASetDREQ (fdctrl->pDevIns, fdctrl->dma_chann, 1);
             PDMDevHlpDMASchedule (fdctrl->pDevIns);
-#endif
             return;
         } else {
@@ -1433,9 +1324,5 @@
         int dma_mode;
         /* DMA transfer are enabled. Check if DMA channel is well programmed */
-#ifndef VBOX
-        dma_mode = DMA_get_channel_mode(fdctrl->dma_chann);
-#else
         dma_mode = PDMDevHlpDMAGetChannelMode (fdctrl->pDevIns, fdctrl->dma_chann);
-#endif
         dma_mode = (dma_mode >> 2) & 3;
         FLOPPY_DPRINTF("dma_mode=%d direction=%d (%d - %d)\n",
@@ -1449,11 +1336,6 @@
              * recall us...
              */
-#ifndef VBOX
-            DMA_hold_DREQ(fdctrl->dma_chann);
-            DMA_schedule(fdctrl->dma_chann);
-#else
             PDMDevHlpDMASetDREQ (fdctrl->pDevIns, fdctrl->dma_chann, 1);
             PDMDevHlpDMASchedule (fdctrl->pDevIns);
-#endif
             return;
         } else {
@@ -1481,5 +1363,4 @@
 }
 
-#ifdef VBOX
 /* Block driver read/write wrappers. */
 
@@ -1517,8 +1398,5 @@
 }
 
-#endif
-
 /* handlers for DMA transfers */
-#ifdef VBOX
 static DECLCALLBACK(uint32_t) fdctrl_transfer_handler (PPDMDEVINS pDevIns,
                                                        void *opaque,
@@ -1526,19 +1404,11 @@
                                                        uint32_t dma_pos,
                                                        uint32_t dma_len)
-#else
-static int fdctrl_transfer_handler (void *opaque, int nchan,
-                                    int dma_pos, int dma_len)
-#endif
 {
     RT_NOREF(pDevIns, dma_pos);
     fdctrl_t *fdctrl;
     fdrive_t *cur_drv;
-#ifdef VBOX
     int rc;
     uint32_t len = 0;
     uint32_t start_pos, rel_pos;
-#else
-    int len, start_pos, rel_pos;
-#endif
     uint8_t status0 = 0x00, status1 = 0x00, status2 = 0x00;
 
@@ -1554,9 +1424,5 @@
     if (dma_len > fdctrl->data_len)
         dma_len = fdctrl->data_len;
-#ifndef VBOX
-    if (cur_drv->bs == NULL)
-#else  /* !VBOX */
     if (cur_drv->pDrvMedia == NULL)
-#endif
     {
         if (fdctrl->data_dir == FD_DIR_WRITE)
@@ -1568,20 +1434,17 @@
     }
 
-#ifdef VBOX
-        if (cur_drv->ro)
+    if (cur_drv->ro)
+    {
+        if (fdctrl->data_dir == FD_DIR_WRITE || fdctrl->data_dir == FD_DIR_FORMAT)
         {
-            if (fdctrl->data_dir == FD_DIR_WRITE || fdctrl->data_dir == FD_DIR_FORMAT)
-            {
-                /* Handle readonly medium early, no need to do DMA, touch the
-                 * LED or attempt any writes. A real floppy doesn't attempt
-                 * to write to readonly media either. */
-                fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, FD_SR1_NW,
-                                     0x00);
-                Assert(len == 0);
-                goto transfer_error;
-            }
+            /* Handle readonly medium early, no need to do DMA, touch the
+             * LED or attempt any writes. A real floppy doesn't attempt
+             * to write to readonly media either. */
+            fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, FD_SR1_NW,
+                                 0x00);
+            Assert(len == 0);
+            goto transfer_error;
         }
-#endif
-
+    }
 
     rel_pos = fdctrl->data_pos % FD_SECTOR_LEN;
@@ -1599,11 +1462,6 @@
             len < FD_SECTOR_LEN || rel_pos != 0)) {
             /* READ & SCAN commands and realign to a sector for WRITE */
-#ifdef VBOX
             rc = blk_read(cur_drv, fd_sector(cur_drv), fdctrl->fifo, 1);
             if (RT_FAILURE(rc))
-#else
-            if (bdrv_read(cur_drv->bs, fd_sector(cur_drv),
-                          fdctrl->fifo, 1) < 0)
-#endif
             {
                 FLOPPY_DPRINTF("Floppy: error getting sector %d\n",
@@ -1616,5 +1474,4 @@
         case FD_DIR_READ:
             /* READ commands */
-#ifdef VBOX
             {
                 uint32_t read;
@@ -1625,14 +1482,7 @@
                 AssertMsgRC (rc2, ("DMAWriteMemory -> %Rrc\n", rc2));
             }
-#else
-            DMA_write_memory (nchan, fdctrl->fifo + rel_pos,
-                              fdctrl->data_pos, len);
-#endif
-/*          cpu_physical_memory_write(addr + fdctrl->data_pos, */
-/*                                    fdctrl->fifo + rel_pos, len); */
             break;
         case FD_DIR_WRITE:
             /* WRITE commands */
-#ifdef VBOX
             {
                 uint32_t written;
@@ -1646,10 +1496,4 @@
             rc = blk_write(cur_drv, fd_sector(cur_drv), fdctrl->fifo, 1);
             if (RT_FAILURE(rc))
-#else
-            DMA_read_memory (nchan, fdctrl->fifo + rel_pos,
-                             fdctrl->data_pos, len);
-            if (bdrv_write(cur_drv->bs, fd_sector(cur_drv),
-                           fdctrl->fifo, 1) < 0)
-#endif
             {
                 FLOPPY_ERROR("writing sector %d\n", fd_sector(cur_drv));
@@ -1658,5 +1502,4 @@
             }
             break;
-#ifdef VBOX
         case FD_DIR_FORMAT:
             /* FORMAT command */
@@ -1689,5 +1532,4 @@
             }
             break;
-#endif
         default:
             /* SCAN commands */
@@ -1695,12 +1537,8 @@
                 uint8_t tmpbuf[FD_SECTOR_LEN];
                 int ret;
-#ifdef VBOX
                 uint32_t read;
                 int rc2 = PDMDevHlpDMAReadMemory (fdctrl->pDevIns, nchan, tmpbuf,
                                                   fdctrl->data_pos, len, &read);
                 AssertMsg(RT_SUCCESS(rc2), ("DMAReadMemory -> %Rrc2\n", rc2)); NOREF(rc2);
-#else
-                DMA_read_memory (nchan, tmpbuf, fdctrl->data_pos, len);
-#endif
                 ret = memcmp(tmpbuf, fdctrl->fifo + rel_pos, len);
                 if (ret == 0) {
@@ -1747,7 +1585,5 @@
     uint32_t retval = 0;
     unsigned pos;
-#ifdef VBOX
     int rc;
-#endif
 
     cur_drv = get_cur_drv(fdctrl);
@@ -1766,10 +1602,6 @@
                     return 0;
                 }
-#ifdef VBOX
             rc = blk_read(cur_drv, fd_sector(cur_drv), fdctrl->fifo, 1);
             if (RT_FAILURE(rc))
-#else
-            if (bdrv_read(cur_drv->bs, fd_sector(cur_drv), fdctrl->fifo, 1) < 0)
-#endif
             {
                 FLOPPY_DPRINTF("error getting sector %d\n",
@@ -1802,7 +1634,5 @@
     fdrive_t *cur_drv;
     uint8_t kh, kt, ks;
-#ifdef VBOX
     int ok = 0, rc;
-#endif
 
     SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
@@ -1850,5 +1680,4 @@
     }
     memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
-#ifdef VBOX
     if (cur_drv->pDrvMedia) {
         rc = blk_write(cur_drv, fd_sector(cur_drv), fdctrl->fifo, 1);
@@ -1861,11 +1690,4 @@
     }
     if (ok) {
-#else
-    if (cur_drv->bs == NULL ||
-        bdrv_write(cur_drv->bs, fd_sector(cur_drv), fdctrl->fifo, 1) < 0) {
-        FLOPPY_ERROR("formatting sector %d\n", fd_sector(cur_drv));
-        fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
-    } else {
-#endif
         if (cur_drv->sect == cur_drv->last_sect) {
             fdctrl->data_state &= ~FD_STATE_FORMAT;
@@ -1996,10 +1818,5 @@
     fdctrl->msr &= ~FD_MSR_RQM;
     cur_drv->head = (fdctrl->fifo[1] >> 2) & 1;
-#ifdef VBOX
     TMTimerSetMillies(fdctrl->result_timer, 1000 / 50);
-#else
-    qemu_mod_timer(fdctrl->result_timer,
-                   qemu_get_clock(vm_clock) + (get_ticks_per_sec() / 50));
-#endif
 }
 
@@ -2123,5 +1940,5 @@
     cur_drv = get_cur_drv(fdctrl);
     fdctrl_reset_fifo(fdctrl);
-#ifdef VBOX
+
     /* The seek command just sends step pulses to the drive and doesn't care if
      * there's a medium inserted or if it's banging the head against the drive.
@@ -2132,13 +1949,4 @@
     /* Raise Interrupt */
     fdctrl_raise_irq(fdctrl, FD_SR0_SEEK | GET_CUR_DRV(fdctrl));
-#else
-    if (fdctrl->fifo[2] > cur_drv->max_track) {
-        fdctrl_raise_irq(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK);
-    } else {
-        cur_drv->track = fdctrl->fifo[2];
-        /* Raise Interrupt */
-        fdctrl_raise_irq(fdctrl, FD_SR0_SEEK);
-    }
-#endif
 }
 
@@ -2306,10 +2114,5 @@
         if (pos == FD_SECTOR_LEN - 1 ||
             fdctrl->data_pos == fdctrl->data_len) {
-#ifdef VBOX
             blk_write(cur_drv, fd_sector(cur_drv), fdctrl->fifo, 1);
-#else
-            bdrv_write(cur_drv->bs, fd_sector(cur_drv),
-                       fdctrl->fifo, 1);
-#endif
         }
         /* Switch from transfer mode to status mode
@@ -2359,5 +2162,4 @@
     }
     /* READ_ID can't automatically succeed! */
-#ifdef VBOX
     if (!cur_drv->max_track) {
         FLOPPY_DPRINTF("read id when no disk in drive\n");
@@ -2375,10 +2177,7 @@
     }
     else
-#endif
         fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00);
 }
 
-
-#ifdef VBOX
 
 /* -=-=-=-=-=-=-=-=- Timer Callback -=-=-=-=-=-=-=-=- */
@@ -2977,9 +2776,4 @@
         AssertMsgFailed(("Memory mapped floppy not support by now\n"));
         return VERR_NOT_SUPPORTED;
-#if 0
-        FLOPPY_ERROR("memory mapped floppy not supported by now !\n");
-        io_mem = cpu_register_io_memory(0, fdctrl_mem_read, fdctrl_mem_write);
-        cpu_register_physical_memory(base, 0x08, io_mem);
-#endif
     }
     else
@@ -3094,6 +2888,4 @@
 };
 
-#endif /* VBOX */
-
 /*
  * Local Variables:
