summaryrefslogtreecommitdiffstats
path: root/printmsg.S
blob: 467c6e1046cfe5a87e8b0f2625c5191311dbe4f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#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