2018-09-09 10:24:22 +00:00
|
|
|
#
|
2018-09-14 10:26:27 +00:00
|
|
|
.sect .text; .sect .rom; .sect .data; .sect .bss
|
|
|
|
|
2018-09-04 22:13:01 +00:00
|
|
|
|
2018-09-09 10:24:22 +00:00
|
|
|
.sect .text
|
2018-09-04 22:13:01 +00:00
|
|
|
.define .trap_ecase
|
|
|
|
.trap_ecase:
|
2018-09-09 23:08:25 +00:00
|
|
|
li r4, 20 ! ECASE = 20 in h/em_abs.h
|
2018-09-04 22:13:01 +00:00
|
|
|
! FALLTHROUGH to .trp
|
|
|
|
|
2018-09-14 10:26:27 +00:00
|
|
|
! Raises an EM trap.
|
|
|
|
! Expects r4 = trap number.
|
|
|
|
|
2018-09-08 21:12:57 +00:00
|
|
|
.define .trp
|
2018-09-08 20:42:06 +00:00
|
|
|
.trp:
|
2018-09-14 10:26:27 +00:00
|
|
|
andi at, r4, 0xfff0
|
|
|
|
bne at, zero, 1f ! traps > 15 can't be ignored
|
|
|
|
nop
|
|
|
|
|
|
|
|
lui at, ha16[.ignmask]
|
|
|
|
lw r5, lo16[.ignmask] (at) ! load ignore mask
|
|
|
|
srlv r5, r5, r4
|
|
|
|
andi r5, r5, 1
|
|
|
|
bne r5, zero, return ! return if ignoring trap
|
|
|
|
nop
|
|
|
|
1:
|
|
|
|
|
|
|
|
lui at, ha16[.trppc]
|
|
|
|
lw r5, lo16[.trppc] (at) ! r5 = user trap routine
|
|
|
|
sw zero, lo16[.trppc] (at) ! reset the trap routine for next time
|
|
|
|
beq r5, zero, abend ! abort if no user trap routine
|
|
|
|
nop
|
2018-09-04 22:13:01 +00:00
|
|
|
|
2018-09-14 10:26:27 +00:00
|
|
|
addiu sp, sp, -8
|
|
|
|
sw r4, 0(sp) ! push trap number
|
|
|
|
sw ra, 4(sp) ! and link register
|
|
|
|
jalr r5 ! call trap routine
|
|
|
|
nop
|
|
|
|
|
|
|
|
lw ra, 4(sp) ! ...and return
|
|
|
|
addiu sp, sp, 8
|
|
|
|
return:
|
|
|
|
jr ra
|
|
|
|
nop
|
|
|
|
|
|
|
|
! No trap handler; write error message and exit.
|
|
|
|
abend:
|
|
|
|
addiu sp, sp, -12
|
|
|
|
li at, 2
|
|
|
|
sw at, 0(sp)
|
|
|
|
lui at, hi16[message]
|
|
|
|
ori at, at, lo16[message]
|
|
|
|
sw at, 4(sp)
|
|
|
|
li at, 6
|
|
|
|
sw at, 8(sp)
|
|
|
|
jal _write ! write(2, message, 6)
|
|
|
|
nop
|
|
|
|
|
|
|
|
li at, 1
|
|
|
|
sw at, 0(sp)
|
|
|
|
j __exit ! _exit(1)
|
|
|
|
|
|
|
|
.sect .rom
|
|
|
|
message:
|
|
|
|
.ascii "TRAP!\n"
|