Improve debugging output.
authorKevin O'Connor <kevin@koconnor.net>
Tue, 8 Jul 2008 01:37:10 +0000 (21:37 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Tue, 8 Jul 2008 01:37:10 +0000 (21:37 -0400)
Return the line number of the debug_fail() / debug_stub() call site on
    each call.
Show the return status on set_code_fail() calls.
Also, the floppy_1305() code should not clear AL.

src/bregs.h
src/disk.c
src/disk.h
src/floppy.c
src/output.c
src/util.c
src/util.h

index 8da6c524943a6336b32b85bcdefbb753feabdd61..f7060e8a08a0d6536b91053f576e927def31df83 100644 (file)
@@ -79,12 +79,12 @@ set_code_fail_silent(struct bregs *regs, u8 code)
 }
 
 #define set_fail(regs) \
-    __set_fail(__func__, (regs))
+    __set_fail(__func__, __LINE__, (regs))
 #define set_code_fail(regs, code)               \
-    __set_code_fail(__func__, (regs), (code))
+    __set_code_fail(__func__, __LINE__, (regs), (code))
 
-// util.c
-void __set_fail(const char *fname, struct bregs *regs);
-void __set_code_fail(const char *fname, struct bregs *regs, u8 code);
+// output.c
+void __set_fail(const char *fname, int lineno, struct bregs *regs);
+void __set_code_fail(const char *fname, int lineno, struct bregs *regs, u8 code);
 
 #endif // bregs.h
index e22afd7ebe8c4f5a0207cbdc78c690ea848dafeb..d9060efacc4316bc4d3e38480166bf2b53c823ef 100644 (file)
  ****************************************************************/
 
 void
-__disk_ret(const char *fname, struct bregs *regs, u8 code)
+__disk_ret(const char *fname, int lineno, struct bregs *regs, u8 code)
 {
     SET_BDA(disk_last_status, code);
     if (code)
-        __set_code_fail(fname, regs, code);
+        __set_code_fail(fname, lineno, regs, code);
     else
         set_code_success(regs);
 }
 
 static void
-__disk_stub(const char *fname, struct bregs *regs)
+__disk_stub(const char *fname, int lineno, struct bregs *regs)
 {
-    __debug_stub(fname, regs);
-    __disk_ret(fname, regs, DISK_RET_SUCCESS);
+    __debug_stub(fname, lineno, regs);
+    __disk_ret(fname, lineno, regs, DISK_RET_SUCCESS);
 }
 
 #define DISK_STUB(regs) \
-    __disk_stub(__func__, (regs))
+    __disk_stub(__func__, __LINE__, (regs))
 
 static void
 basic_access(struct bregs *regs, u8 device, u16 command)
index 54df9cdfc93145fa75261a12e94ffb0836c7ac87..1a3f91db4b77cc73edf5e6bb69417455e1a59ef1 100644 (file)
@@ -92,9 +92,9 @@ struct floppy_ext_dbt_s {
 
 // Helper function for setting up a return code.
 struct bregs;
-void __disk_ret(const char *fname, struct bregs *regs, u8 code);
+void __disk_ret(const char *fname, int lineno, struct bregs *regs, u8 code);
 #define disk_ret(regs, code) \
-    __disk_ret(__func__, (regs), (code))
+    __disk_ret(__func__, __LINE__, (regs), (code))
 
 // floppy.c
 extern struct floppy_ext_dbt_s diskette_param_table2;
index a7908dc574c523b357fb351c3cd929f2b8c06d88..5313b96607b5695322e6f169e9b01f3a0d755c8c 100644 (file)
@@ -155,7 +155,7 @@ floppy_prepare_controller(u8 drive)
     }
 }
 
-static u8
+static int
 floppy_pio(u8 *cmd, u8 cmdlen)
 {
     floppy_prepare_controller(cmd[1] & 1);
@@ -171,7 +171,7 @@ floppy_pio(u8 *cmd, u8 cmdlen)
         if (!GET_BDA(floppy_motor_counter)) {
             irq_disable();
             floppy_reset_controller();
-            return DISK_RET_ETIMEOUT;
+            return -1;
         }
         v = GET_BDA(floppy_recalibration_status);
         if (v & FRS_TIMEOUT)
@@ -186,7 +186,20 @@ floppy_pio(u8 *cmd, u8 cmdlen)
     return 0;
 }
 
-static u8
+#define floppy_ret(regs, code) \
+    __floppy_ret(__func__, __LINE__, (regs), (code))
+
+void
+__floppy_ret(const char *fname, int lineno, struct bregs *regs, u8 code)
+{
+    SET_BDA(floppy_last_status, code);
+    if (code)
+        __set_code_fail(fname, lineno, regs, code);
+    else
+        set_code_success(regs);
+}
+
+static int
 floppy_cmd(struct bregs *regs, u16 count, u8 *cmd, u8 cmdlen)
 {
     // es:bx = pointer to where to place information from diskette
@@ -202,8 +215,10 @@ floppy_cmd(struct bregs *regs, u16 count, u8 *cmd, u8 cmdlen)
 
     // check for 64K boundary overrun
     u16 last_addr = base_address + count;
-    if (last_addr < base_address)
-        return DISK_RET_EBOUNDARY;
+    if (last_addr < base_address) {
+        floppy_ret(regs, DISK_RET_EBOUNDARY);
+        return -1;
+    }
 
     u8 mode_register = 0x4a; // single mode, increment, autoinit disable,
     if (cmd[0] == 0xe6)
@@ -228,9 +243,11 @@ floppy_cmd(struct bregs *regs, u16 count, u8 *cmd, u8 cmdlen)
 
     outb(0x02, PORT_DMA1_MASK_REG); // unmask channel 2
 
-    u8 ret = floppy_pio(cmd, cmdlen);
-    if (ret)
-        return ret;
+    int ret = floppy_pio(cmd, cmdlen);
+    if (ret) {
+        floppy_ret(regs, DISK_RET_ETIMEOUT);
+        return -1;
+    }
 
     // check port 3f4 for accessibility to status bytes
     if ((inb(PORT_FD_STATUS) & 0xc0) != 0xc0)
@@ -362,40 +379,20 @@ floppy_media_sense(u8 drive)
     return rv;
 }
 
-#define floppy_ret(regs, code) \
-    __floppy_ret(__func__, (regs), (code))
-
-void
-__floppy_ret(const char *fname, struct bregs *regs, u8 code)
-{
-    SET_BDA(floppy_last_status, code);
-    if (code)
-        __set_code_fail(fname, regs, code);
-    else
-        set_code_success(regs);
-}
-
-static inline void
-floppy_fail(struct bregs *regs, u8 code)
-{
-    floppy_ret(regs, code);
-    regs->al = 0; // no sectors read
-}
-
-static u16
+static int
 check_drive(struct bregs *regs, u8 drive)
 {
     // see if drive exists
     if (drive > 1 || !get_drive_type(drive)) {
         // XXX - return type doesn't match
-        floppy_fail(regs, DISK_RET_ETIMEOUT);
-        return 1;
+        floppy_ret(regs, DISK_RET_ETIMEOUT);
+        return -1;
     }
 
     // see if media in drive, and type is known
     if (floppy_media_known(drive) == 0 && floppy_media_sense(drive) == 0) {
-        floppy_fail(regs, DISK_RET_EMEDIA);
-        return 1;
+        floppy_ret(regs, DISK_RET_EMEDIA);
+        return -1;
     }
     return 0;
 }
@@ -430,7 +427,7 @@ static void
 floppy_1302(struct bregs *regs, u8 drive)
 {
     if (check_drive(regs, drive))
-        return;
+        goto fail;
 
     u8 num_sectors = regs->al;
     u8 track       = regs->ch;
@@ -439,8 +436,8 @@ floppy_1302(struct bregs *regs, u8 drive)
 
     if (head > 1 || sector == 0 || num_sectors == 0
         || track > 79 || num_sectors > 72) {
-        floppy_fail(regs, DISK_RET_EPARAM);
-        return;
+        floppy_ret(regs, DISK_RET_EPARAM);
+        goto fail;
     }
 
     // send read-normal-data command (9 bytes) to controller
@@ -455,21 +452,22 @@ floppy_1302(struct bregs *regs, u8 drive)
     data[7] = 0; // Gap length
     data[8] = 0xff; // Gap length
 
-    u16 ret = floppy_cmd(regs, (num_sectors * 512) - 1, data, 9);
-    if (ret) {
-        floppy_fail(regs, ret);
-        return;
-    }
+    int ret = floppy_cmd(regs, (num_sectors * 512) - 1, data, 9);
+    if (ret)
+        goto fail;
 
     if (data[0] & 0xc0) {
-        floppy_fail(regs, DISK_RET_ECONTROLLER);
-        return;
+        floppy_ret(regs, DISK_RET_ECONTROLLER);
+        goto fail;
     }
 
     // ??? should track be new val from return_status[3] ?
     set_diskette_current_cyl(drive, track);
     // AL = number of sectors read (same value as passed)
     floppy_ret(regs, DISK_RET_SUCCESS);
+    return;
+fail:
+    regs->al = 0; // no sectors read
 }
 
 // Write Diskette Sectors
@@ -477,7 +475,7 @@ static void
 floppy_1303(struct bregs *regs, u8 drive)
 {
     if (check_drive(regs, drive))
-        return;
+        goto fail;
 
     u8 num_sectors = regs->al;
     u8 track       = regs->ch;
@@ -486,8 +484,8 @@ floppy_1303(struct bregs *regs, u8 drive)
 
     if (head > 1 || sector == 0 || num_sectors == 0
         || track > 79 || num_sectors > 72) {
-        floppy_fail(regs, DISK_RET_EPARAM);
-        return;
+        floppy_ret(regs, DISK_RET_EPARAM);
+        goto fail;
     }
 
     // send write-normal-data command (9 bytes) to controller
@@ -502,17 +500,14 @@ floppy_1303(struct bregs *regs, u8 drive)
     data[7] = 0; // Gap length
     data[8] = 0xff; // Gap length
 
-    u8 ret = floppy_cmd(regs, (num_sectors * 512) - 1, data, 9);
-    if (ret) {
-        floppy_fail(regs, ret);
-        return;
-    }
+    int ret = floppy_cmd(regs, (num_sectors * 512) - 1, data, 9);
+    if (ret)
+        goto fail;
 
     if (data[0] & 0xc0) {
         if (data[1] & 0x02) {
-            set_fail(regs);
-            regs->ax = 0x0300;
-            return;
+            floppy_ret(regs, DISK_RET_EWRITEPROTECT);
+            goto fail;
         }
         BX_PANIC("int13_diskette_function: read error\n");
     }
@@ -521,6 +516,9 @@ floppy_1303(struct bregs *regs, u8 drive)
     set_diskette_current_cyl(drive, track);
     // AL = number of sectors read (same value as passed)
     floppy_ret(regs, DISK_RET_SUCCESS);
+    return;
+fail:
+    regs->al = 0; // no sectors read
 }
 
 // Verify Diskette Sectors
@@ -528,7 +526,7 @@ static void
 floppy_1304(struct bregs *regs, u8 drive)
 {
     if (check_drive(regs, drive))
-        return;
+        goto fail;
 
     u8 num_sectors = regs->al;
     u8 track       = regs->ch;
@@ -537,14 +535,17 @@ floppy_1304(struct bregs *regs, u8 drive)
 
     if (head > 1 || sector == 0 || num_sectors == 0
         || track > 79 || num_sectors > 72) {
-        floppy_fail(regs, DISK_RET_EPARAM);
-        return;
+        floppy_ret(regs, DISK_RET_EPARAM);
+        goto fail;
     }
 
     // ??? should track be new val from return_status[3] ?
     set_diskette_current_cyl(drive, track);
     // AL = number of sectors verified (same value as passed)
     floppy_ret(regs, DISK_RET_SUCCESS);
+    return;
+fail:
+    regs->al = 0; // no sectors read
 }
 
 // format diskette track
@@ -560,7 +561,7 @@ floppy_1305(struct bregs *regs, u8 drive)
     u8 head        = regs->dh;
 
     if (head > 1 || num_sectors == 0 || num_sectors > 18) {
-        floppy_fail(regs, DISK_RET_EPARAM);
+        floppy_ret(regs, DISK_RET_EPARAM);
         return;
     }
 
@@ -573,16 +574,13 @@ floppy_1305(struct bregs *regs, u8 drive)
     data[4] = 0; // Gap length
     data[5] = 0xf6; // Fill byte
 
-    u8 ret = floppy_cmd(regs, (num_sectors * 4) - 1, data, 6);
-    if (ret) {
-        floppy_fail(regs, ret);
+    int ret = floppy_cmd(regs, (num_sectors * 4) - 1, data, 6);
+    if (ret)
         return;
-    }
 
     if (data[0] & 0xc0) {
         if (data[1] & 0x02) {
-            set_fail(regs);
-            regs->ax = 0x0300;
+            floppy_ret(regs, DISK_RET_EWRITEPROTECT);
             return;
         }
         BX_PANIC("int13_diskette_function: read error\n");
index 27fca330f1c8ec5ab4f12de56895341f3dce838d..8b584859ddd5caa148e81065e42b3b8ac72b35e5 100644 (file)
@@ -250,14 +250,14 @@ printf(const char *fmt, ...)
 }
 
 static void
-dump_regs(const char *fname, const char *type, struct bregs *regs)
+dump_regs(struct bregs *regs)
 {
     if (!regs) {
-        dprintf(1, "%s %s: NULL\n", type, fname);
+        dprintf(1, "  NULL\n");
         return;
     }
-    dprintf(1, "%s %s: a=%x b=%x c=%x d=%x si=%x di=%x\n"
-            , type, fname, regs->eax, regs->ebx, regs->ecx, regs->edx
+    dprintf(1, "  a=%x b=%x c=%x d=%x si=%x di=%x\n"
+            , regs->eax, regs->ebx, regs->ecx, regs->edx
             , regs->esi, regs->edi);
     dprintf(1, "  ds=%x es=%x ip=%x cs=%x f=%x r=%p\n"
             , regs->ds, regs->es, regs->ip, regs->cs, regs->flags, regs);
@@ -274,18 +274,29 @@ __debug_isr(const char *fname)
 void
 __debug_enter(const char *fname, struct bregs *regs)
 {
-    // XXX - implement run time suppression test
-    dump_regs(fname, "enter", regs);
+    dprintf(1, "enter %s:\n", fname);
+    dump_regs(regs);
 }
 
 void
-__debug_fail(const char *fname, struct bregs *regs)
+__debug_stub(const char *fname, int lineno, struct bregs *regs)
 {
-    dump_regs(fname, "fail", regs);
+    dprintf(1, "stub %s:%d:\n", fname, lineno);
+    dump_regs(regs);
 }
 
 void
-__debug_stub(const char *fname, struct bregs *regs)
+__set_fail(const char *fname, int lineno, struct bregs *regs)
 {
-    dump_regs(fname, "stub", regs);
+    dprintf(1, "fail %s:%d:\n", fname, lineno);
+    dump_regs(regs);
+    set_fail_silent(regs);
+}
+
+void
+__set_code_fail(const char *fname, int lineno, struct bregs *regs, u8 code)
+{
+    dprintf(1, "fail %s:%d(%x):\n", fname, lineno, code);
+    dump_regs(regs);
+    set_code_fail_silent(regs, code);
 }
index c4f61c5a92eb08e47b7072e1661f9a74e1e9a5a9..6ae6965d8bdc7821d7e074be53148c2e0be512f6 100644 (file)
@@ -83,17 +83,3 @@ memmove(void *d, const void *s, size_t len)
 
     return d;
 }
-
-void
-__set_fail(const char *fname, struct bregs *regs)
-{
-    __debug_fail(fname, regs);
-    set_fail_silent(regs);
-}
-
-void
-__set_code_fail(const char *fname, struct bregs *regs, u8 code)
-{
-    __debug_fail(fname, regs);
-    set_code_fail_silent(regs, code);
-}
index d134e19e2452bd1913a0a210d414e6e7ea2e8a53..88ecc0eebfbae4c8d96568773a64a08ed119c458 100644 (file)
@@ -84,19 +84,18 @@ void __dprintf(const char *fmt, ...)
             __dprintf((fmt) , ##args );                         \
     } while (0)
 void __debug_enter(const char *fname, struct bregs *regs);
-void __debug_fail(const char *fname, struct bregs *regs);
-void __debug_stub(const char *fname, struct bregs *regs);
+void __debug_stub(const char *fname, int lineno, struct bregs *regs);
 void __debug_isr(const char *fname);
 #define debug_enter(regs, lvl) do {                     \
         if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL)       \
-            __debug_enter(__func__, regs);              \
+            __debug_enter(__func__, (regs));            \
     } while (0)
 #define debug_isr(lvl) do {                             \
         if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL)       \
             __debug_isr(__func__);                      \
     } while (0)
 #define debug_stub(regs) \
-    __debug_stub(__func__, regs)
+    __debug_stub(__func__, __LINE__, (regs))
 
 // kbd.c
 void kbd_setup();