Skip to content

Commit efff2f1

Browse files
committed
added assembly include files for <errno.h> <fenv.h> and <math.h>
1 parent b4c5566 commit efff2f1

14 files changed

Lines changed: 234 additions & 19 deletions

File tree

src/crt/ltod.src

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.assume adl=1
22

3+
.include "fenv.inc"
4+
35
.section .text
46

57
.global __ulltod
@@ -59,16 +61,18 @@ __lltod:
5961
.L.round_up:
6062
inc b ; round up after shifting
6163
.L.no_round:
64+
6265
.if 0 ; FE_INEXACT
6366
adc a, a ; test sticky and round bits
6467
jr z, .L.result_is_exact
6568
.L.no_round_inexact:
6669
ld hl, ___fe_cur_env
67-
set 5, (hl) ; FE_INEXACT
70+
set FE_INEXACT_BIT, (hl)
6871
.L.result_is_exact:
6972
.else
7073
.L.no_round_inexact:
7174
.endif
75+
7276
ld h, b
7377
ld a, c
7478
ld l, c

src/crt/makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ OBJECTS_CE += $(patsubst %.c,build/%.c.ce.o,$(wildcard *.c))
2626
OBJECTS_CE += $(patsubst %.cpp,build/%.cpp.ce.o,$(wildcard *.cpp))
2727
OBJECTS_CE += $(patsubst %.src,build/%.ce.o,$(wildcard *.src))
2828

29+
EZASFLAGS += -I$(call NATIVEPATH,$(CURDIR)/../libc)
30+
2931
.SECONDARY:
3032

3133
all: build/libcrt.a build/libcrt_os.a

src/libc/acosf.src

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
.assume adl=1
22

3+
.include "errno.inc"
4+
5+
.if EDOM & 0xFF != EDOM
6+
.print "EDOM is assumed to be between 1 and 255"
7+
.err
8+
.endif
9+
310
.section .text
411
.global _acos
512
.type _acos, @function
@@ -36,7 +43,7 @@ _acosf:
3643
jp p, .L2
3744

3845
.L1:
39-
ld hl,4
46+
ld hl, EDOM
4047
ld (_errno),hl
4148
ld l,h
4249
ld e,h

src/libc/errno.inc

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
.ifndef __ERRNO_INC__
2+
.set __ERRNO_INC__, 1
3+
4+
; errno.inc
5+
; Assembly errno equates for libc <errno.h>
6+
; Remember to keep this file in sync with <errno.h>
7+
8+
; Note that many routines assume that EDOM and ERANGE are between 1 and 255.
9+
10+
.equ EPERM , 1 ; permission error
11+
.equ EINVAL , 2 ; invalid argument
12+
.equ EIO , 3 ; io error
13+
.equ EDOM , 4 ; math domain error
14+
.equ ERANGE , 5 ; math range error
15+
.equ EILSEQ , 6 ; Illegal byte sequence (C95)
16+
.equ E2BIG , 7 ; Argument list too long
17+
.equ EACCES , 8 ; Permission denied
18+
.equ EADDRINUSE , 9 ; Address in use
19+
.equ EADDRNOTAVAIL , 10 ; Address not available
20+
.equ EAFNOSUPPORT , 11 ; Address family not supported
21+
.equ EAGAIN , 12 ; Resource unavailable, try again
22+
.equ EALREADY , 13 ; Connection already in progress
23+
.equ EBADF , 14 ; Bad file descriptor
24+
.equ EBADMSG , 15 ; Bad message
25+
.equ EBUSY , 16 ; Device or resource busy
26+
.equ ECANCELED , 17 ; Operation canceled
27+
.equ ECHILD , 18 ; No child processes
28+
.equ ECONNABORTED , 19 ; Connection aborted
29+
.equ ECONNREFUSED , 20 ; Connection refused
30+
.equ ECONNRESET , 21 ; Connection reset
31+
.equ EDEADLK , 22 ; Resource deadlock avoided
32+
.equ EDESTADDRREQ , 23 ; Destination address required
33+
.equ EEXIST , 24 ; File exists
34+
.equ EFAULT , 25 ; Bad address
35+
.equ EFBIG , 26 ; File too large
36+
.equ EHOSTUNREACH , 27 ; Host is unreachable
37+
.equ EIDRM , 28 ; Identifier removed
38+
.equ EINPROGRESS , 29 ; Operation in progress
39+
.equ EINTR , 30 ; Interrupted function
40+
.equ EISCONN , 31 ; Socket is connected
41+
.equ EISDIR , 32 ; Is a directory
42+
.equ ELOOP , 33 ; Too many levels of symbolic links
43+
.equ EMFILE , 34 ; Too many open files
44+
.equ EMLINK , 35 ; Too many links
45+
.equ EMSGSIZE , 36 ; Message too long
46+
.equ ENAMETOOLONG , 37 ; Filename too long
47+
.equ ENETDOWN , 38 ; Network is down
48+
.equ ENETRESET , 39 ; Connection aborted by network
49+
.equ ENETUNREACH , 40 ; Network is unreachable
50+
.equ ENFILE , 41 ; Too many open files in system
51+
.equ ENOBUFS , 42 ; No buffer space available
52+
.equ ENODATA , 43 ; No message is available on the STREAM head read queue
53+
.equ ENODEV , 44 ; No such device
54+
.equ ENOENT , 45 ; No such file or directory
55+
.equ ENOEXEC , 46 ; Executable file format error
56+
.equ ENOLCK , 47 ; No locks available
57+
.equ ENOLINK , 48 ; Link has been severed
58+
.equ ENOMEM , 49 ; Not enough space
59+
.equ ENOMSG , 50 ; No message of desired type
60+
.equ ENOPROTOOPT , 51 ; Protocol not available
61+
.equ ENOSPC , 52 ; No space left on device
62+
.equ ENOSR , 53 ; No stream resources
63+
.equ ENOSTR , 54 ; Not a stream
64+
.equ ENOSYS , 55 ; Function not implemented
65+
.equ ENOTCONN , 56 ; The socket is not connected
66+
.equ ENOTDIR , 57 ; Not a directory
67+
.equ ENOTEMPTY , 58 ; Directory not empty
68+
.equ ENOTRECOVERABLE , 59 ; State not recoverable
69+
.equ ENOTSOCK , 60 ; Not a socket
70+
.equ ENOTSUP , 61 ; Not supported
71+
.equ ENOTTY , 62 ; Inappropriate I/O control operation
72+
.equ ENXIO , 63 ; No such device or address
73+
.equ EOPNOTSUPP , 64 ; Operation not supported on socket
74+
.equ EOVERFLOW , 65 ; Value too large to be stored in data type
75+
.equ EOWNERDEAD , 66 ; Previous owner died
76+
.equ EPIPE , 67 ; Broken pipe
77+
.equ EPROTO , 68 ; Protocol error
78+
.equ EPROTONOSUPPORT , 69 ; Protocol not supported
79+
.equ EPROTOTYPE , 70 ; Protocol wrong type for socket
80+
.equ EROFS , 71 ; Read-only file system
81+
.equ ESPIPE , 72 ; Invalid seek
82+
.equ ESRCH , 73 ; No such process
83+
.equ ETIME , 74 ; Stream ioctl() timeout
84+
.equ ETIMEDOUT , 75 ; Connection timed out
85+
.equ ETXTBSY , 76 ; Text file busy
86+
.equ EWOULDBLOCK , 77 ; Operation would block
87+
.equ EXDEV , 78 ; Cross-device link
88+
89+
.if ERANGE & 0xFF != ERANGE
90+
.print "ERANGE is assumed to be between 1 and 255"
91+
.err
92+
.endif
93+
.if EDOM & 0xFF != EDOM
94+
.print "EDOM is assumed to be between 1 and 255"
95+
.err
96+
.endif
97+
98+
.endif

src/libc/fenv.inc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.ifndef __FENV_INC__
2+
.set __FENV_INC__, 1
3+
4+
; fenv.inc
5+
; Assembly fenv equates for libc <fenv.h>
6+
; Remember to keep this file in sync with <fenv.h>
7+
8+
.equ FE_DIVBYZERO_BIT , 6
9+
.equ FE_INEXACT_BIT , 5
10+
.equ FE_INVALID_BIT , 4
11+
.equ FE_OVERFLOW_BIT , 3
12+
.equ FE_UNDERFLOW_BIT , 2
13+
14+
.equ FE_DIVBYZERO_MASK , 1 << FE_DIVBYZERO_BIT
15+
.equ FE_INEXACT_MASK , 1 << FE_INEXACT_BIT
16+
.equ FE_INVALID_MASK , 1 << FE_INVALID_BIT
17+
.equ FE_OVERFLOW_MASK , 1 << FE_OVERFLOW_BIT
18+
.equ FE_UNDERFLOW_MASK , 1 << FE_UNDERFLOW_BIT
19+
20+
.equ FE_ALL_EXCEPT , FE_DIVBYZERO_MASK | FE_INEXACT_MASK | FE_INVALID_MASK | FE_OVERFLOW_MASK | FE_UNDERFLOW_MASK
21+
22+
.equ FE_TONEAREST , 0
23+
.equ FE_TOWARDZERO , 1
24+
.equ FE_DOWNWARD , 2
25+
.equ FE_UPWARD , 3
26+
27+
.endif

src/libc/ilogbf.src

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
.assume adl=1
22

3+
.include "errno.inc"
4+
.include "fenv.inc"
5+
.include "math.inc"
6+
7+
.if !(FP_ILOGBNAN == 0x7FFFFF)
8+
.print "ilogbf/ilogb assumes that FP_ILOGBNAN == 0x7FFFFF (INT_MAX)"
9+
.err
10+
.endif
11+
.if !(FP_ILOGB0 - 1 == FP_ILOGBNAN)
12+
.print "ilogbf/ilogb assumes FP_ILOGB0 - 1 == FP_ILOGBNAN"
13+
.err
14+
.endif
15+
316
.section .text
417

518
.global _ilogbf
@@ -42,10 +55,10 @@ _ilogb:
4255
.L.inf_nan:
4356
scf
4457
.L.ret_zero:
45-
ld hl, 4 ; EDOM
58+
ld hl, EDOM
4659
ld (_errno), hl
4760
ld hl, ___fe_cur_env
48-
set 4, (hl) ; FE_INVALID
61+
set FE_INVALID_BIT, (hl)
4962
ld hl, $800000 ; FP_ILOGB0
5063
ret nc
5164
; FP_ILOGBNAN or INT_MAX when carry is set

src/libc/ilogbl.src

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
.assume adl=1
22

3+
.include "errno.inc"
4+
.include "fenv.inc"
5+
.include "math.inc"
6+
7+
.if EDOM & 0xFF != EDOM
8+
.print "EDOM is assumed to be between 1 and 255"
9+
.err
10+
.endif
11+
12+
.if !(FP_ILOGBNAN == 0x7FFFFF)
13+
.print "ilogbl assumes that FP_ILOGBNAN == 0x7FFFFF (INT_MAX)"
14+
.err
15+
.endif
16+
.if !(FP_ILOGB0 - 1 == FP_ILOGBNAN)
17+
.print "ilogbl assumes FP_ILOGB0 - 1 == FP_ILOGBNAN"
18+
.err
19+
.endif
20+
321
.section .text
422

523
.global _ilogbl
@@ -58,10 +76,10 @@ _ilogbl:
5876
add hl, de ; FP_ILOGB0 when DE is one
5977
ex de, hl
6078
; DE was zero or one, so HL is now zero or one
61-
ld l, 4 ; EDOM
79+
ld l, EDOM
6280
ld (_errno), hl
6381
ld hl, ___fe_cur_env
64-
set 4, (hl) ; FE_INVALID
82+
set FE_INVALID_BIT, (hl)
6583
ex de, hl
6684
ret
6785

src/libc/ldexpf.src

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
.assume adl=1
22

3+
.include "errno.inc"
4+
.include "fenv.inc"
5+
36
.section .text
47
.global _ldexpf
58
.type _ldexpf, @function
@@ -132,20 +135,20 @@ _ldexpf:
132135
; .underflow:
133136
inc b ; ld b, 0 ; sets Z
134137
.L.overflow_to_inf: ; <-- NZ is set when infinite
135-
ld a, $28 ; FE_OVERFLOW | FE_INEXACT
138+
ld a, FE_OVERFLOW_MASK | FE_INEXACT_MASK
136139
.L.underflow_to_zero: ; <-- Z is set when underflowing to zero
137140
.L.raise_erange:
138141
ld hl, $800000
139142
jr nz, .L.overflow
140-
ld a, $24 ; FE_UNDERFLOW | FE_INEXACT
143+
ld a, FE_UNDERFLOW_MASK | FE_INEXACT_MASK
141144
add hl, hl ; ld hl, 0
142145
.if __ldexpf_avoid_negative_zero
143146
; prevents negative zero from being emitted on underflow
144147
res 7, (iy + 6)
145148
.endif
146149
.L.overflow:
147150
ex de, hl
148-
ld hl, 5 ; ERANGE
151+
ld hl, ERANGE
149152
ld (_errno), hl
150153
.L.raise_inexact:
151154
ld hl, ___fe_cur_env
@@ -218,7 +221,7 @@ _ldexpf:
218221
ld a, c ; UDE
219222
or a, d
220223
or a, e
221-
ld a, $20 ; FE_INEXACT
224+
ld a, FE_INEXACT_MASK
222225
jr nz, .L.raise_inexact
223226
; NZ needs to be set here
224227
jr .L.raise_erange

src/libc/logbf.src

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
.assume adl=1
22

3+
.include "errno.inc"
4+
.include "fenv.inc"
5+
6+
.if EDOM & 0xFF != EDOM
7+
.print "EDOM is assumed to be between 1 and 255"
8+
.err
9+
.endif
10+
311
.section .text
412

513
.global _logbf
@@ -46,11 +54,10 @@ _logbf:
4654

4755
.L.ret_zero:
4856
; HL is zero here
49-
ld l, 4 ; EDOM
57+
ld l, EDOM
5058
ld (_errno), hl
51-
; FE_DIVBYZERO
5259
ld hl, ___fe_cur_env
53-
set 6, (hl)
60+
set FE_DIVBYZERO_BIT, (hl)
5461
; -HUGE_VALF
5562
ld hl, $800000
5663
ld e, b ; ld e, $FF

src/libc/math.inc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.ifndef __MATH_INC__
2+
.set __MATH_INC__, 1
3+
4+
; math.inc
5+
; Assembly equates for libc <math.h>
6+
; Remember to keep this file in sync with <math.h>
7+
8+
; note that FP_ILOGBINF is INT_MAX
9+
.equ FP_ILOGB0 , 0x800000
10+
.equ FP_ILOGBNAN , 0x7FFFFF
11+
12+
.equ FP_ZERO , 0x0
13+
.equ FP_INFINITE , 0x1
14+
.equ FP_SUBNORMAL , 0x2
15+
.equ FP_NAN , 0x3
16+
.equ FP_NORMAL , 0x4
17+
18+
.endif

0 commit comments

Comments
 (0)