ack/tests/plat/rck_e.e
George Koehler 26de4c1ab1 Add test for EM _rck_. Fix traps in PowerPC ncg.
The new test rck_e.e segfaults on PowerPC unless I make some changes.
The inline code for _rck_ was wrong because it didn't allow the trap
handler to return.  _sig_ forgot to push the old trap handler.

Move plat/linuxppc/libsys/trap.s to mach/powerpc/libem/trp.s and
rewrite it with simplified/extended mnemonics.  Remove .trap alias for
.trp procedure.  Add a missing `mtspr lr, r0` so we can return from
the trap handler.  Call write() and _exit() so trp.s works with both
linuxppc and osxppc.  Before, Mac OS X was wrongly using the trap.s
for Linux.

In powerpc/libem, simplify .aar4; teach .csa and .csb to raise the
trap if the default target is zero.

C programs don't need these changes.  You may relink your C programs
with the changed .csa and .csb, but C code doesn't raise the trap.
Modula-2 code can raise traps, so you may want to relink your Modula-2
programs with the changed libem, but you might keep your old .o files
from Modula-2.  You may need to recompile your Pascal programs (delete
old .o files from Pascal) because the Pascal compiler might use _rck_.
2017-12-24 22:37:52 -05:00

187 lines
3.1 KiB
Plaintext

#
mes 2, EM_WSIZE, EM_PSIZE
/*
* Uses _rck_ for range checks. Catches the EM trap if a value is out
* of range, and continues with the next instruction after _rck_.
*
* Some back ends, like i80, ignore _rck_, so this test fails.
*/
testnr
con 1 ; test number
caught
con 0 ; number of caught traps
inp $next
inp $catch
inp $never
exp $_m_a_i_n
pro $_m_a_i_n,0
lim ; load ignore mask
loc 2
and EM_WSIZE ; check bit 1 << ERANGE
zeq *1 ; fail if ignoring ERANGE
.1
rom 1I4
lae .1
loi 4
cal $fail
asp 4
1
cal $next ; increment testnr, catch next trap
loc 10125
.2
rom 4283, 13644
lae .2
rck EM_WSIZE ; testnr 2 in range
asp EM_WSIZE
cal $next
loc 4282
lae .2
rck EM_WSIZE ; testnr 3 out of range
asp EM_WSIZE
cal $next
loc 4283
lae .2
rck EM_WSIZE ; testnr 4 in range
asp EM_WSIZE
cal $next
loc 13644
lae .2
rck EM_WSIZE ; testnr 5 in range
asp EM_WSIZE
cal $next
loc 13655
lae .2
rck EM_WSIZE ; testnr 6 out of range
asp EM_WSIZE
cal $next
loc -13015
.7
rom -31344, -1898
lae .7
rck EM_WSIZE ; testnr 7 in range
asp EM_WSIZE
cal $next
loc 8580
.8
rom -26315, 4588
lae .8
rck EM_WSIZE ; testnr 8 out of range
asp EM_WSIZE
; The last test raised a trap, so now there is no trap handler.
lpi $never
sig ; push old trap handler
loc 0
loc EM_WSIZE
loc EM_PSIZE
cuu ; push NULL pointer
cmp
zeq *17 ; fail unless old handler is NULL
.17
rom 17I4
lae .17
loi 4
cal $fail
asp 4
17
; Change the trap handler from $never to $catch.
lpi $catch
sig
lpi $never
cmp
zeq *18
.18
rom 18I4
lae .18
loi 4
cal $fail
asp 4
18
; Begin ignoring range traps.
loc 2 ; 1 << ERANGE
sim
loc 18
ste testnr
loc 8580
lae .8
rck EM_WSIZE ; testnr 18 out of range but ignored
; Fail if we caught the wrong number of traps.
loe caught
loc 3
beq *20
.20
rom 20I4
lae .20
loi 4
cal $fail
asp 4
20
cal $finished
end
pro $next,0
ine testnr ; next test
lpi $catch
sig ; catch next EM trap (only one trap)
asp EM_PSIZE
ret 0
end
pro $catch,0
ine caught ; count this trap
lol 0 ; load trap number
loc 1
beq *1 ; fail if trap != ERANGE
.101
rom 257I4
lae .101
loi 4
cal $fail
; Wrong type of trap. _rtt_ might not work, so exit now.
cal $finished
1
; Fail if the wrong test raised this trap.
loe testnr
loc 3
beq *2
loe testnr
loc 6
beq *2
loe testnr
loc 8
beq *2
loc 256
loe testnr
adi EM_WSIZE ; 0x100 + testnr
loc EM_WSIZE
loc 4
cuu
cal $fail
asp 4
2
rtt ; return from trap handler
end
pro $never,0
.200
rom 200I4
lae .200
loi 4
cal $fail
asp 4
rtt
end