From a68aeaf68c152a602e048256811f5b10e8d02d6e Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 7 Jul 2008 21:37:10 -0400 Subject: [PATCH] Improve debugging output. 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 | 10 ++-- src/disk.c | 12 ++--- src/disk.h | 4 +- src/floppy.c | 126 +++++++++++++++++++++++++-------------------------- src/output.c | 31 +++++++++---- src/util.c | 14 ------ src/util.h | 7 ++- 7 files changed, 99 insertions(+), 105 deletions(-) diff --git a/src/bregs.h b/src/bregs.h index 8da6c52..f7060e8 100644 --- a/src/bregs.h +++ b/src/bregs.h @@ -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 diff --git a/src/disk.c b/src/disk.c index e22afd7..d9060ef 100644 --- a/src/disk.c +++ b/src/disk.c @@ -19,24 +19,24 @@ ****************************************************************/ 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) diff --git a/src/disk.h b/src/disk.h index 54df9cd..1a3f91d 100644 --- a/src/disk.h +++ b/src/disk.h @@ -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; diff --git a/src/floppy.c b/src/floppy.c index a7908dc..5313b96 100644 --- a/src/floppy.c +++ b/src/floppy.c @@ -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"); diff --git a/src/output.c b/src/output.c index 27fca33..8b58485 100644 --- a/src/output.c +++ b/src/output.c @@ -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); } diff --git a/src/util.c b/src/util.c index c4f61c5..6ae6965 100644 --- a/src/util.c +++ b/src/util.c @@ -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); -} diff --git a/src/util.h b/src/util.h index d134e19..88ecc0e 100644 --- a/src/util.h +++ b/src/util.h @@ -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(); -- 2.25.1