Simplify the .trp API to make it a bit smaller.

This commit is contained in:
David Given 2019-06-11 20:02:03 +02:00
parent 4e90de00e9
commit 3feb79ad0c
4 changed files with 13 additions and 16 deletions

View file

@ -2475,5 +2475,6 @@ with hlreg
gen shld {label,".reghp"} gen shld {label,".reghp"}
pat trp pat trp
kills ALL with areg
gen Call {label,".trp"} kills ALL
gen Call {label,".trp"}

View file

@ -170,8 +170,7 @@ _cpm_cmdline = 0x0081
! Some magic data. All EM systems need these. ! Some magic data. All EM systems need these.
.define .trppc, .ignmask, _errno .define .ignmask, _errno
.comm .trppc, 2
.comm .ignmask, 2 .comm .ignmask, 2
.comm _errno, 2 .comm _errno, 2
@ -184,11 +183,10 @@ envp: .space 2 ! envp array (always empty, must be after argv)
! These are used specifically by the i80 code generator. ! These are used specifically by the i80 code generator.
.define .trapproc, .retadr, .retadr1 .define .retadr, .retadr1
.define .bcreg, .areg .define .bcreg, .areg
.define .tmp1, .fra, block1, block2, block3 .define .tmp1, .fra, block1, block2, block3
.comm .trapproc, 2
.comm .retadr, 2 ! used to save return address .comm .retadr, 2 ! used to save return address
.comm .retadr1, 2 ! reserve .comm .retadr1, 2 ! reserve
.comm .bcreg, 2 .comm .bcreg, 2

View file

@ -13,7 +13,8 @@
.define EUNIMPL .define EUNIMPL
! Trap routine ! Trap routine
! Expects trap number on stack. ! Expects trap number in A, and must be called directly from the code
! where execution should resume (for those traps which support it).
! Just returns if trap has to be ignored. ! Just returns if trap has to be ignored.
! Otherwise it calls a user-defined trap handler if provided. ! Otherwise it calls a user-defined trap handler if provided.
! When no user-defined trap handler is provided or when the user-defined ! When no user-defined trap handler is provided or when the user-defined
@ -46,9 +47,6 @@
EUNIMPL = 63 ! unimplemented em-instruction called EUNIMPL = 63 ! unimplemented em-instruction called
.trp: .trp:
pop h
xthl
push h ! trap number and return address exchanged
mov a,l mov a,l
cpi 16 cpi 16
jnc 3f ! jump if trap cannot be ignored jnc 3f ! jump if trap cannot be ignored
@ -66,10 +64,12 @@
ret ! OGEN DICHT EN ... SPRING!!! ret ! OGEN DICHT EN ... SPRING!!!
3: 3:
lhld .trapproc ! user defined trap handler? .define .trapproc
.trapproc = . + 1
lxi h, 0 ! user defined trap handler held inline here
mov a,l mov a,l
ora h ora h
jz 1f ! jump if there was not jz 1f ! jump if there was not
xra a xra a
sta .trapproc ! .trapproc := 0 sta .trapproc ! .trapproc := 0
sta .trapproc+1 sta .trapproc+1

View file

@ -4,9 +4,7 @@ cat <<EOF
#include "asm.h" #include "asm.h"
.define $1 .define $1
$1: $1:
lxi h, $2 mvi a, $2
push h jmp .trp
call .trp
ret
EOF EOF