-
-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy patherrno_str.src
More file actions
208 lines (188 loc) · 3.87 KB
/
errno_str.src
File metadata and controls
208 lines (188 loc) · 3.87 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
.assume adl=1
;-------------------------------------------------------------------------------
.section .text
.global _perror
.type _perror, @function
; void perror(const char*)
_perror:
pop de
ex (sp), hl
push de
add hl, bc
xor a, a
sbc hl, bc
jr z, .L.null_string
cp a, (hl)
jr z, .L.empty_string
; fprintf(stderr, "%s: ", str)
call .L.errchar_puts
ld hl, _perror_colon_space_str
call .L.errchar_puts
.L.null_string:
.L.empty_string:
ld hl, (_errno)
call _strerror.hijack_perror
call .L.errchar_puts
ld a, $0A ; '\n'
.L.errchar_putchar:
; input:
; - A = character to display
; - HL = nul terminated string to display afterward
; output:
; - HL points to nul terminator
push hl
ld l, a
push hl
call _errchar
pop hl
pop hl
.L.errchar_puts:
ld a, (hl)
or a, a
ret z
inc hl
jr .L.errchar_putchar
.extern _errno
.extern _errchar
;-------------------------------------------------------------------------------
.section .rodata._perror_colon_space_str
.local _perror_colon_space_str
_perror_colon_space_str:
.asciz ": "
;-------------------------------------------------------------------------------
.section .text
.global _strerror
.type _strerror, @function
; supports a maximum of 255 strings
.equ errno_strings_count, 79
_strerror:
pop de
ex (sp), hl
push de
.local _strerror.hijack_perror
_strerror.hijack_perror:
; HL = errnum
ld bc, -errno_strings_count
push hl
add hl, bc
jr c, .L.unknown_errnum
pop de
ld hl, _errno_strings
xor a, a
; test if errnum is zero
cp a, e
ret z
.L.loop:
; skip to the start of the next string
cpir
dec e
jr nz, .L.loop
ret
.L.unknown_errnum:
; errnum < 0 || errnum >= errno_strings_count
ld hl, _percent_d
push hl
; overwrites the numeric portion of "unknown error -8388608"
ld hl, _unknown_errno_string + 14
push hl
call _boot_sprintf
pop hl
pop hl
pop hl
ld hl, _unknown_errno_string
ret
.extern _boot_sprintf
;-------------------------------------------------------------------------------
.section .data._unknown_errno_string
.local _unknown_errno_string
_unknown_errno_string:
.asciz "unknown error -8388608"
;-------------------------------------------------------------------------------
.section .rodata._percent_d
.local _percent_d
_percent_d:
.asciz "%d"
;-------------------------------------------------------------------------------
.section .rodata._errno_strings
.local _errno_strings
; make sure to update errno_strings_count
_errno_strings:
.db "no error", 0
.db "EPERM", 0
.db "EINVAL", 0
.db "EIO", 0
.db "EDOM", 0
.db "ERANGE", 0
.db "EILSEQ", 0
.db "E2BIG", 0
.db "EACCES", 0
.db "EADDRINUSE", 0
.db "EADDRNOTAVAIL", 0
.db "EAFNOSUPPORT", 0
.db "EAGAIN", 0
.db "EALREADY", 0
.db "EBADF", 0
.db "EBADMSG", 0
.db "EBUSY", 0
.db "ECANCELED", 0
.db "ECHILD", 0
.db "ECONNABORTED", 0
.db "ECONNREFUSED", 0
.db "ECONNRESET", 0
.db "EDEADLK", 0
.db "EDESTADDRREQ", 0
.db "EEXIST", 0
.db "EFAULT", 0
.db "EFBIG", 0
.db "EHOSTUNREACH", 0
.db "EIDRM", 0
.db "EINPROGRESS", 0
.db "EINTR", 0
.db "EISCONN", 0
.db "EISDIR", 0
.db "ELOOP", 0
.db "EMFILE", 0
.db "EMLINK", 0
.db "EMSGSIZE", 0
.db "ENAMETOOLONG", 0
.db "ENETDOWN", 0
.db "ENETRESET", 0
.db "ENETUNREACH", 0
.db "ENFILE", 0
.db "ENOBUFS", 0
.db "ENODATA", 0
.db "ENODEV", 0
.db "ENOENT", 0
.db "ENOEXEC", 0
.db "ENOLCK", 0
.db "ENOLINK", 0
.db "ENOMEM", 0
.db "ENOMSG", 0
.db "ENOPROTOOPT", 0
.db "ENOSPC", 0
.db "ENOSR", 0
.db "ENOSTR", 0
.db "ENOSYS", 0
.db "ENOTCONN", 0
.db "ENOTDIR", 0
.db "ENOTEMPTY", 0
.db "ENOTRECOVERABLE", 0
.db "ENOTSOCK", 0
.db "ENOTSUP", 0
.db "ENOTTY", 0
.db "ENXIO", 0
.db "EOPNOTSUPP", 0
.db "EOVERFLOW", 0
.db "EOWNERDEAD", 0
.db "EPIPE", 0
.db "EPROTO", 0
.db "EPROTONOSUPPORT", 0
.db "EPROTOTYPE", 0
.db "EROFS", 0
.db "ESPIPE", 0
.db "ESRCH", 0
.db "ETIME", 0
.db "ETIMEDOUT", 0
.db "ETXTBSY", 0
.db "EWOULDBLOCK", 0
.db "EXDEV", 0