summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2013-03-06 10:53:41 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2013-03-06 10:53:41 (GMT)
commit08071cd4c1a9f9f7cd0c4e882fdaa64358ae2073 (patch)
treeef7cb9aab9658bca1a47939086fd1a35490f7aed
parent88a77633e643602cdf631fb432d5e5fffbb6a48c (diff)
downloadvirtio9p-08071cd4c1a9f9f7cd0c4e882fdaa64358ae2073.zip
virtio9p-08071cd4c1a9f9f7cd0c4e882fdaa64358ae2073.tar.gz
virtio9p-08071cd4c1a9f9f7cd0c4e882fdaa64358ae2073.tar.bz2
virtio9p-08071cd4c1a9f9f7cd0c4e882fdaa64358ae2073.tar.xz
Add facility for printing debug messages
Add code to print messages on the Qemu debug console
-rw-r--r--Makefile2
-rw-r--r--printmsg.asm140
-rw-r--r--v9fs.h14
3 files changed, 155 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 328dbee..6f253c3 100644
--- a/Makefile
+++ b/Makefile
@@ -26,7 +26,7 @@
## -----------------------------------------------------------------------
CC = gcc
-CFLAGS = -m32
+CFLAGS = -m32 -DDEBUG=1
AS = as
ASFLAGS = --32
LD = ld
diff --git a/printmsg.asm b/printmsg.asm
index f936856..516b5e2 100644
--- a/printmsg.asm
+++ b/printmsg.asm
@@ -177,3 +177,143 @@ GPROC(crlf)
printmsg "\r\n"
retw
END(crlf)
+
+#ifdef DEBUG
+
+#ifndef DEBUG_PORT
+# define DEBUG_PORT 0xe9
+#endif
+
+ .section ".rtext","ax"
+
+/* ------------------------------------------------------------------------- *
+ * debug_puts
+ *
+ * Print a message (pointer on the stack) on the debug port
+ * ------------------------------------------------------------------------- */
+
+GPROC(debug_puts)
+ pushw %bp
+ movw %sp,%bp
+ pushw %si
+ pushw %ax
+ movw 4(%bp),%si
+1:
+ lodsb
+ andb %al,%al
+ jz 2f
+ outb %al,$DEBUG_PORT
+ jmp 1b
+2:
+ popw %ax
+ popw %si
+ popw %bp
+ retw $2
+END(debug_puts)
+
+/* ------------------------------------------------------------------------- *
+ * debug_printnum
+ *
+ * Print an unsigned 32-bit integer on the stack
+ * ------------------------------------------------------------------------- */
+
+GPROC(debug_printnum)
+ pushl %eax
+ pushl %edx
+ pushl %ecx
+ pushw %di
+ movw %sp,%di
+ movl (2+1*2+3*4)(%di),%eax
+ subw $12,%sp
+ decw %di
+ xorl %ecx,%ecx
+ movb %cl,(%di)
+ movb $10,%cl
+1:
+ xorl %edx,%edx
+ divl %ecx
+ decw %di
+ addb $0x30,%dl
+ movb %dl,(%di)
+ andl %eax,%eax
+ jnz 1b
+
+ pushw %di
+ call debug_puts
+
+ addw $12,%sp
+ popw %di
+ popl %ecx
+ popl %edx
+ popl %eax
+ retw $4
+END(debug_printnum)
+
+/* ------------------------------------------------------------------------- *
+ * debug_printhex4
+ *
+ * Print an hexadecimal 4-digit number from the stack
+ * ------------------------------------------------------------------------- */
+
+GPROC(debug_printhex4)
+ pushw %ax
+ pushw %cx
+ pushw %dx
+ pushw %di
+ cld
+ subw $6,%sp
+ movw %sp,%di
+ movw (2+4*2+6)(%di),%dx
+ movw $4,%cx
+1:
+ rolw $4,%dx
+ movb %dl,%al
+ andb $0x0f,%al
+ addb $0x30,%al
+ cmpb $0x3a,%al
+ jb 2f
+ addb $(0x41-0x3a),%al
+2:
+ stosb
+ loopw 1b
+ movb %cl,(%di) /* %cl == 0 */
+ pushw %sp /* %sp -> address of buffer */
+ call debug_puts
+
+ addw $6,%sp
+ popw %di
+ popw %dx
+ popw %cx
+ popw %ax
+ retw $2
+END(debug_printhex4)
+
+/* ------------------------------------------------------------------------- *
+ * debug_printhex8
+ *
+ * Print an hexadecimal 8-digit number from the stack
+ * ------------------------------------------------------------------------- */
+
+GPROC(debug_printhex8)
+ pushw %bp
+ movw %sp,%bp
+ pushw 6(%bp)
+ call debug_printhex4
+ pushw 4(%bp)
+ call debug_printhex4
+ popw %bp
+ retw $4
+END(debug_printhex8)
+
+/* ------------------------------------------------------------------------- *
+ * debug_crlf
+ *
+ * Print a newline
+ * ------------------------------------------------------------------------- */
+
+GPROC(debug_crlf)
+ debugmsg "\r\n"
+ retw
+END(debug_crlf)
+
+#endif /* DEBUG */
diff --git a/v9fs.h b/v9fs.h
index 3ef7ad5..cef0cbd 100644
--- a/v9fs.h
+++ b/v9fs.h
@@ -331,6 +331,7 @@
#define F_IP %gs:40(%bp)
#define F_CS %gs:42(%bp)
#define F_FLAGS %gs:44(%bp)
+#define F_TOS %gs:46(%bp) /* Word on stack before INT 2F */
/* Magic number we store in the CDS */
#define CDS_MAGIC 0xe882
@@ -360,6 +361,19 @@
call puterr
.endm
+#ifdef DEBUG
+ .macro debugmsg msg
+ .pushsection ".rrodata.str","a",@progbits
+101: .asciz "\msg"
+ .popsection
+ pushw $101b
+ call debug_puts
+ .endm
+#else
+ .macro debugmsg msg
+ .endm
+#endif
+
/*
* Macros to define data objects
*