Improve some debugging output.
authorKevin O'Connor <kevin@koconnor.net>
Sat, 28 Jun 2008 16:15:57 +0000 (12:15 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Sat, 28 Jun 2008 16:15:57 +0000 (12:15 -0400)
Replace DEBUGF calls with dprintf calls.
Make ata calls consistently use 'int' return codes.
Make each error return code in ata.c use a unique negative number.

src/ata.c
src/boot.c
src/cdrom.c
src/clock.c
src/disk.c
src/disk.h
src/floppy.c
src/mouse.c

index 4d3c66070594f2c29b3064b33efce3ddd920e82a..724ad6252a2082e9b059f60fc296d237bdbc3cea 100644 (file)
--- a/src/ata.c
+++ b/src/ata.c
@@ -24,9 +24,6 @@
 
 #define IDE_TIMEOUT 32000u //32 seconds max for IDE ops
 
-#define DEBUGF1(fmt, args...) bprintf(0, fmt , ##args)
-#define DEBUGF(fmt, args...)
-
 
 /****************************************************************
  * Helper functions
@@ -57,21 +54,21 @@ await_ide(u8 when_done, u16 base, u16 timeout)
         // mod 2048 each 16 ms
         if (time>>16 != last) {
             last = time >>16;
-            DEBUGF("await_ide: (TIMEOUT,BSY,!BSY,!BSY_DRQ,!BSY_!DRQ,!BSY_RDY)"
-                   " %d time= %d timeout= %d\n"
-                   , when_done, time>>11, timeout);
+            dprintf(6, "await_ide: (TIMEOUT,BSY,!BSY,!BSY_DRQ"
+                    ",!BSY_!DRQ,!BSY_RDY) %d time= %d timeout= %d\n"
+                    , when_done, time>>11, timeout);
         }
         if (status & ATA_CB_STAT_ERR) {
-            DEBUGF("await_ide: ERROR (TIMEOUT,BSY,!BSY,!BSY_DRQ"
-                   ",!BSY_!DRQ,!BSY_RDY) %d time= %d timeout= %d\n"
-                   , when_done, time>>11, timeout);
+            dprintf(1, "await_ide: ERROR (TIMEOUT,BSY,!BSY,!BSY_DRQ"
+                    ",!BSY_!DRQ,!BSY_RDY) %d status=%x time= %d timeout= %d\n"
+                    , when_done, status, time>>11, timeout);
             return -1;
         }
         if (timeout == 0 || (time>>11) > timeout)
             break;
     }
     dprintf(1, "IDE time out\n");
-    return -1;
+    return -2;
 }
 
 // Wait for ide state - pauses for one ata cycle first.
@@ -188,7 +185,7 @@ send_cmd(int driveid, struct ata_pio_command *cmd)
 
     int status = inb(iobase1 + ATA_CB_STAT);
     if (status & ATA_CB_STAT_BSY)
-        return 1;
+        return -3;
 
     // Disable interrupts
     outb(ATA_CB_DC_HD15 | ATA_CB_DC_NIEN, iobase2 + ATA_CB_DC);
@@ -196,7 +193,7 @@ send_cmd(int driveid, struct ata_pio_command *cmd)
     // Select device
     u8 device = inb(iobase1 + ATA_CB_DH);
     outb(cmd->device, iobase1 + ATA_CB_DH);
-    if ((device ^ cmd->device) & (1UL << 4))
+    if ((device ^ cmd->device) & (1 << 4))
         // Wait for device to become active.
         msleep(50);
 
@@ -219,13 +216,13 @@ send_cmd(int driveid, struct ata_pio_command *cmd)
         return status;
 
     if (status & ATA_CB_STAT_ERR) {
-        DEBUGF("send_cmd : read error\n");
-        return 2;
+        dprintf(6, "send_cmd : read error\n");
+        return -4;
     }
     if (!(status & ATA_CB_STAT_DRQ)) {
-        DEBUGF("send_cmd : DRQ not set (status %02x)\n"
-               , (unsigned) status);
-        return 3;
+        dprintf(6, "send_cmd : DRQ not set (status %02x)\n"
+                , (unsigned) status);
+        return -5;
     }
 
     return 0;
@@ -261,10 +258,10 @@ static __always_inline int
 ata_transfer(int driveid, int iswrite, int count, int blocksize
              , int skipfirst, int skiplast, void *far_buffer)
 {
-    DEBUGF("ata_transfer id=%d write=%d count=%d bs=%d"
-           " skipf=%d skipl=%d buf=%p\n"
-           , driveid, iswrite, count, blocksize
-           , skipfirst, skiplast, far_buffer);
+    dprintf(16, "ata_transfer id=%d write=%d count=%d bs=%d"
+            " skipf=%d skipl=%d buf=%p\n"
+            , driveid, iswrite, count, blocksize
+            , skipfirst, skiplast, far_buffer);
 
     // Reset count of transferred data
     SET_EBDA(ata.trsfsectors, 0);
@@ -286,14 +283,14 @@ ata_transfer(int driveid, int iswrite, int count, int blocksize
 
         if (iswrite) {
             // Write data to controller
-            DEBUGF("Write sector id=%d dest=%p\n", driveid, far_buffer);
+            dprintf(16, "Write sector id=%d dest=%p\n", driveid, far_buffer);
             if (mode == ATA_MODE_PIO32)
                 outsl_far(iobase1, far_buffer, bsize / 4);
             else
                 outsw_far(iobase1, far_buffer, bsize / 2);
         } else {
             // Read data from controller
-            DEBUGF("Read sector id=%d dest=%p\n", driveid, far_buffer);
+            dprintf(16, "Read sector id=%d dest=%p\n", driveid, far_buffer);
             if (mode == ATA_MODE_PIO32)
                 insl_far(iobase1, far_buffer, bsize / 4);
             else
@@ -316,9 +313,9 @@ ata_transfer(int driveid, int iswrite, int count, int blocksize
         status &= (ATA_CB_STAT_BSY | ATA_CB_STAT_RDY | ATA_CB_STAT_DRQ
                    | ATA_CB_STAT_ERR);
         if (status != (ATA_CB_STAT_RDY | ATA_CB_STAT_DRQ)) {
-            DEBUGF("ata_transfer : more sectors left (status %02x)\n"
-                   , (unsigned) status);
-            return 5;
+            dprintf(6, "ata_transfer : more sectors left (status %02x)\n"
+                    , (unsigned) status);
+            return -6;
         }
     }
 
@@ -327,9 +324,9 @@ ata_transfer(int driveid, int iswrite, int count, int blocksize
     if (!iswrite)
         status &= ~ATA_CB_STAT_DF;
     if (status != ATA_CB_STAT_RDY ) {
-        DEBUGF("ata_transfer : no sectors left (status %02x)\n"
-               , (unsigned) status);
-        return 4;
+        dprintf(6, "ata_transfer : no sectors left (status %02x)\n"
+                , (unsigned) status);
+        return -7;
     }
 
     // Enable interrupts
@@ -510,10 +507,10 @@ cdrom_read_512(int driveid, u32 vlba, u32 vcount, void *far_buffer)
     op.count = count;
     op.far_buffer = far_buffer;
 
-    DEBUGF("cdrom_read_512: id=%d vlba=%d vcount=%d buf=%p lba=%d elba=%d"
-           " count=%d before=%d after=%d\n"
-           , driveid, vlba, vcount, far_buffer, lba, elba
-           , count, before, after);
+    dprintf(16, "cdrom_read_512: id=%d vlba=%d vcount=%d buf=%p lba=%d elba=%d"
+            " count=%d before=%d after=%d\n"
+            , driveid, vlba, vcount, far_buffer, lba, elba
+            , count, before, after);
 
     int ret = send_cmd_cdrom(&op);
     if (ret)
@@ -813,9 +810,9 @@ init_drive_ata(int driveid)
     report_model(driveid, buffer);
     u8 version = get_ata_version(buffer);
     if (sizeinmb < (1 << 16))
-        printf(" ATA-%d Hard-Disk (%u MBytes)\n", version, (u32)sizeinmb);
+        printf(" ATA-%d Hard-Disk (%u MiBytes)\n", version, (u32)sizeinmb);
     else
-        printf(" ATA-%d Hard-Disk (%u GBytes)\n", version
+        printf(" ATA-%d Hard-Disk (%u GiBytes)\n", version
                , (u32)(sizeinmb >> 10));
 }
 
index 3ee957bf94e4f9fc64f4de1457cfa560521b8d52..ff41930b17e5e1a095d1655ccc75b1464592aa0f 100644 (file)
@@ -147,7 +147,7 @@ try_boot(u16 seq_nr)
         /* CD-ROM */
         if (! CONFIG_CDROM_BOOT)
             break;
-        u16 status = cdrom_boot();
+        int status = cdrom_boot();
         if (status) {
             printf("CDROM boot failure code : %04x\n", status);
             print_boot_failure(type, 1);
index ef81bb376f24af9b8e87f577c05fb555c76c09e1..adb2cfcac2d62decf8ebfd85ef6a7f356d1ddbc2 100644 (file)
@@ -9,9 +9,6 @@
 #include "util.h" // memset
 #include "ata.h" // ATA_CMD_READ_SECTORS
 
-#define DEBUGF1(fmt, args...) bprintf(0, fmt , ##args)
-#define DEBUGF(fmt, args...)
-
 
 /****************************************************************
  * CDROM functions
@@ -302,7 +299,7 @@ cdemu_134b(struct bregs *regs)
  ****************************************************************/
 
 // Request SENSE
-static u16
+static int
 atapi_get_sense(u16 device, u8 *asc, u8 *ascq)
 {
     u8 buffer[18];
@@ -310,10 +307,10 @@ atapi_get_sense(u16 device, u8 *asc, u8 *ascq)
     memset(atacmd, 0, sizeof(atacmd));
     atacmd[0] = ATA_CMD_REQUEST_SENSE;
     atacmd[4] = sizeof(buffer);
-    u16 ret = ata_cmd_packet(device, atacmd, sizeof(atacmd), sizeof(buffer)
+    int ret = ata_cmd_packet(device, atacmd, sizeof(atacmd), sizeof(buffer)
                              , MAKE_FARPTR(GET_SEG(SS), (u32)buffer));
     if (ret != 0)
-        return 0x0002;
+        return ret;
 
     *asc = buffer[12];
     *ascq = buffer[13];
@@ -321,7 +318,7 @@ atapi_get_sense(u16 device, u8 *asc, u8 *ascq)
     return 0;
 }
 
-static u16
+static int
 atapi_is_ready(u16 device)
 {
     if (GET_EBDA(ata.devices[device].type) != ATA_TYPE_ATAPI) {
@@ -329,7 +326,7 @@ atapi_is_ready(u16 device)
         return -1;
     }
 
-    DEBUGF("ata_detect_medium: begin\n");
+    dprintf(6, "ata_detect_medium: begin\n");
     u8 packet[12];
     memset(packet, 0, sizeof(packet));
     packet[0] = 0x25; /* READ CAPACITY */
@@ -343,10 +340,10 @@ atapi_is_ready(u16 device)
     u8 in_progress = 0;
     for (;; time+=100) {
         if (time >= timeout) {
-            DEBUGF("read capacity failed\n");
+            dprintf(1, "read capacity failed\n");
             return -1;
         }
-        u16 ret = ata_cmd_packet(device, packet, sizeof(packet), sizeof(buf)
+        int ret = ata_cmd_packet(device, packet, sizeof(packet), sizeof(buf)
                                  , MAKE_FARPTR(GET_SEG(SS), (u32)buf));
         if (ret == 0)
             break;
@@ -357,7 +354,7 @@ atapi_is_ready(u16 device)
             continue;
 
         if (asc == 0x3a) { /* MEDIUM NOT PRESENT */
-            DEBUGF("Device reports MEDIUM NOT PRESENT\n");
+            dprintf(1, "Device reports MEDIUM NOT PRESENT\n");
             return -1;
         }
 
@@ -386,7 +383,7 @@ atapi_is_ready(u16 device)
         | (u32) buf[2] << 8
         | (u32) buf[3] << 0;
 
-    DEBUGF("sectors=%u\n", sectors);
+    dprintf(6, "sectors=%u\n", sectors);
     if (block_len == 2048)
         sectors <<= 2; /* # of sectors in 512-byte "soft" sector */
     if (sectors != GET_EBDA(ata.devices[device].sectors))
@@ -395,7 +392,7 @@ atapi_is_ready(u16 device)
     return 0;
 }
 
-static u16
+static int
 atapi_is_cdrom(u8 device)
 {
     if (device >= CONFIG_MAX_ATA_DEVICES)
@@ -425,7 +422,7 @@ streq_cs(u8 *s1, char *cs_s2)
     }
 }
 
-u16
+int
 cdrom_boot()
 {
     // Find out the first cdrom
@@ -434,7 +431,7 @@ cdrom_boot()
         if (atapi_is_cdrom(device))
             break;
 
-    u16 ret = atapi_is_ready(device);
+    int ret = atapi_is_ready(device);
     if (ret)
         dprintf(1, "ata_is_ready returned %d\n", ret);
 
@@ -557,7 +554,7 @@ cdrom_boot()
 
     // everything is ok, so from now on, the emulation is active
     SET_EBDA(cdemu.active, 0x01);
-    DEBUGF("cdemu media=%d\n", media);
+    dprintf(6, "cdemu media=%d\n", media);
 
     return 0;
 }
index 605d436739402ab82307596c47b88f982aa1a86f..4162570494947766ebfa38810fb3f173bbeb7ffe 100644 (file)
@@ -11,9 +11,6 @@
 #include "cmos.h" // inb_cmos
 #include "pic.h" // unmask_pic1
 
-#define DEBUGF1(fmt, args...) bprintf(0, fmt , ##args)
-#define DEBUGF(fmt, args...)
-
 // RTC register flags
 #define RTC_A_UIP 0x80
 #define RTC_B_SET 0x80
index 983a392c5f56f8524cc9ef43e3af220f99cce29b..8f26c4b0b67255852c4dec550e57298084451430 100644 (file)
@@ -12,9 +12,6 @@
 #include "ata.h" // ATA_*
 #include "pic.h" // eoi_pic2
 
-#define DEBUGF1(fmt, args...) bprintf(0, fmt , ##args)
-#define DEBUGF(fmt, args...)
-
 
 /****************************************************************
  * Helper functions
index e70d3a70d150b64e950f7e544d41f3de9d2b1b74..3339b0d4c7e5378d98858f7c4cd634c0a55d9896 100644 (file)
@@ -112,7 +112,7 @@ int cdrom_read_emu(u16 device, u32 lba, u32 count, void *far_buffer);
 void cdrom_13(struct bregs *regs, u8 device);
 void cdemu_13(struct bregs *regs);
 void cdemu_134b(struct bregs *regs);
-u16 cdrom_boot();
+int cdrom_boot();
 
 
 #endif // disk.h
index efe9592f5927060b1fff17ff502316372529b78f..afb87786cf28b7c9fd63b2018cc15683d2d87549 100644 (file)
@@ -13,9 +13,6 @@
 #include "cmos.h" // inb_cmos
 #include "pic.h" // unmask_pic1
 
-#define DEBUGF1(fmt, args...) bprintf(0, fmt , ##args)
-#define DEBUGF(fmt, args...)
-
 #define BX_FLOPPY_ON_CNT 37   /* 2 seconds */
 
 // New diskette parameter table adding 3 parameters from IBM
@@ -553,7 +550,7 @@ floppy_1304(struct bregs *regs, u8 drive)
 static void
 floppy_1305(struct bregs *regs, u8 drive)
 {
-    DEBUGF("floppy f05\n");
+    dprintf(3, "floppy f05\n");
 
     if (check_drive(regs, drive))
         return;
@@ -598,7 +595,7 @@ floppy_1305(struct bregs *regs, u8 drive)
 static void
 floppy_1308(struct bregs *regs, u8 drive)
 {
-    DEBUGF("floppy f08\n");
+    dprintf(3, "floppy f08\n");
 
     u8 drive_type = inb_cmos(CMOS_FLOPPY_DRIVE_TYPE);
     u8 num_floppies = 0;
@@ -690,7 +687,7 @@ floppy_1308(struct bregs *regs, u8 drive)
 static void
 floppy_1315(struct bregs *regs, u8 drive)
 {
-    DEBUGF("floppy f15\n");
+    dprintf(6, "floppy f15\n");
     if (drive > 1) {
         set_fail(regs);
         regs->ah = 0; // only 2 drives supported
@@ -707,7 +704,6 @@ floppy_1315(struct bregs *regs, u8 drive)
 static void
 floppy_1316(struct bregs *regs, u8 drive)
 {
-    DEBUGF("floppy f16\n");
     if (drive > 1) {
         floppy_ret(regs, DISK_RET_EPARAM);
         return;
index 8f6775f24f1683a8c6d42371c8f72d5b75e007e3..163d849d671e058989f6737f0a7b27f8f7df3ebc 100644 (file)
@@ -9,9 +9,6 @@
 #include "util.h" // debug_isr
 #include "pic.h" // unmask_pic2
 
-#define DEBUGF1(fmt, args...) bprintf(0, fmt , ##args)
-#define DEBUGF(fmt, args...)
-
 static char panic_msg_keyb_buffer_full[] = "%s: keyboard input buffer full\n";
 
 void