summaryrefslogtreecommitdiffstats
path: root/printmsg.asm
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2013-03-04 22:51:46 -0800
committerH. Peter Anvin <hpa@zytor.com>2013-03-04 22:51:46 -0800
commit796e816fb8eec0ddde4e1002ac0d913c57751918 (patch)
tree6cc711c438b3b16166b4d244b05a1ffd3640a168 /printmsg.asm
parent513bae9bfbe8d38c935e42ec6d192b83f9476e47 (diff)
downloadvirtio9p-796e816fb8eec0ddde4e1002ac0d913c57751918.tar.gz
virtio9p-796e816fb8eec0ddde4e1002ac0d913c57751918.tar.xz
virtio9p-796e816fb8eec0ddde4e1002ac0d913c57751918.zip
Rename *.S to *.asm to support case-insensitive filesystems
Allow building on case-insensitive filesystems by avoiding the *.S/*.s distinction.
Diffstat (limited to 'printmsg.asm')
-rw-r--r--printmsg.asm191
1 files changed, 191 insertions, 0 deletions
diff --git a/printmsg.asm b/printmsg.asm
new file mode 100644
index 0000000..4293877
--- /dev/null
+++ b/printmsg.asm
@@ -0,0 +1,191 @@
+/* -*- asm -*- ----------------------------------------------------------- *
+ *
+ * Copyright 2013 H. Peter Anvin - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * ----------------------------------------------------------------------- */
+
+#include "v9fs.h"
+
+ .code16
+ .section ".text","ax"
+
+/* ------------------------------------------------------------------------- *
+ * puterr
+ *
+ * Print a message (pointer on the stack) on standard error, prefixed by
+ * "v9fs: "
+ * ------------------------------------------------------------------------- */
+ .globl puterr
+puterr:
+ printmsg "v9fs: "
+ /* Fall through */
+ .size puterr,.-puterr
+ .type puterr,@function
+
+/* ------------------------------------------------------------------------- *
+ * puts
+ *
+ * Print a message (pointer on the stack) on standard error.
+ * ------------------------------------------------------------------------- */
+ .globl puts
+puts:
+ pushaw
+ movw %sp,%bp
+ movw 18(%bp),%di
+ movw %di,%dx
+ xorb %al,%al
+ movw %di,%cx
+ notw %cx
+ cld
+ repne scasb
+ /* Now %di points to the byte *after* the terminating null */
+ leaw -1(%di),%cx
+ subw %dx,%cx
+ movw $2,%bx /* 2 = stderr */
+ movb $0x40,%ah
+1:
+ jcxz 2f
+ int $0x21
+ jc 2f
+ subw %ax,%cx
+ jmp 1b
+2:
+ popaw
+ retw $2
+
+ .size puts,.-puts
+ .type puts,@function
+
+/* ------------------------------------------------------------------------- *
+ * printnum
+ *
+ * Print an unsigned 32-bit integer on the stack
+ * ------------------------------------------------------------------------- */
+ .globl printnum
+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 puts
+
+ addw $12,%sp
+ popw %di
+ popl %ecx
+ popl %edx
+ popl %eax
+ retw $4
+
+ .size printnum,.-printnum
+ .type printnum,@function
+
+/* ------------------------------------------------------------------------- *
+ * printhex4
+ *
+ * Print an hexadecimal 4-digit number from the stack
+ * ------------------------------------------------------------------------- */
+ .globl printhex4
+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 puts
+
+ addw $6,%sp
+ popw %di
+ popw %dx
+ popw %cx
+ popw %ax
+ retw $2
+
+ .size printhex4,.-printhex4
+ .type printhex4,@function
+
+/* ------------------------------------------------------------------------- *
+ * printhex8
+ *
+ * Print an hexadecimal 8-digit number from the stack
+ * ------------------------------------------------------------------------- */
+ .globl printhex8
+printhex8:
+ pushw %bp
+ movw %sp,%bp
+ pushw 6(%bp)
+ call printhex4
+ pushw 4(%bp)
+ call printhex4
+ popw %bp
+ retw $4
+
+ .size printhex8,.-printhex8
+ .type printhex8,@function
+
+/* ------------------------------------------------------------------------- *
+ * crlf
+ *
+ * Print a newline
+ * ------------------------------------------------------------------------- */
+ .globl crlf
+crlf:
+ printmsg "\r\n"
+ retw
+
+ .size crlf,.-crlf
+ .type crlf,@function