Mercurial > hg > Members > kono > nitros9-code
view 3rdparty/packages/cc/sources/signal.a @ 1942:b41df77588b0
printer is now scbbp
sio is now scbbt
All references changed in various files
author | boisy |
---|---|
date | Sat, 26 Nov 2005 22:51:50 +0000 |
parents | 0198655f2552 |
children |
line wrap: on
line source
use ..../defs/os9defs.a * signal system call * * The main objective here is to maintain a table of * signals and the user functions to be executed * when the respective signals are received. * * Because OS-9 signals can range from 0 to 255 * the table will have to be dynamic to conserve space. * psect signal,0,0,2,0,0 * 'Signal' and 'intercept' are definitely incompatible and * use of both in a program will have undefined results. * In order to protect the programmer from this a dummy global * label is declared in both relocatable modules which will produce * an 'entry name clash' error in the loader if an attempt is made * to use both. MAXENTS equ 20 maximum number of simultaneous signal traps Zero equ %00000100 * table entry structure * csect 0 *sig rmb 1 signal number to be trapped *func rmb 2 address of trap function *entsiz equ * * endsect sig equ 0 func equ 1 entsiz equ 3 vsect table rmb entsiz*MAXENTS etable rmb 0 end of table flag rmb 1 indicates 'intercept' already done endsect * signal(sig,func) _sigint: signal: ldd 2,s get the signal number tstb lsb 0? beq sigerr signal 0 can't be caught or ignored tsta greater than 255? bne sigerr bsr lookup find a suitable entry bne signal10 branch if entry found sigerr ldd #-1 error indication rts signal10 ldd func,x get the old entry function pshs d save it ldd 6,s get the new function std func,x store in the structure bne signal20 if not 0 branch * the new 'function' is reset (0) clr sig,x reset the signal byte sigexit puls d,pc return the old entry * value for 'func' is 1 or a real address - set it signal20 ldb 5,s get the signal stb sig,x store it tst flag,y have we intercepted before? bne sigexit yes - no more to do exg y,u set the local storage into u leax intrupt,pcr get the address of the interrupt routine os9 F$ICPT exg y,u reset local storage into y puls d get the old value into d bcs sigerr error? inc flag,y indicate that we've done it rts all done * Table lookup function: * * find an entry in the table whose 'sig' matches the b reg. * failing that, the first empty entry * failing that, zero * return result in x reg. and set the z bit accordingly * lookup clr ,-s set up a null clr ,-s 'empty' pointer leax etable,y get table end address pshs x save it leax table,y start at the beginning loop cmpx 0,s end yet? beq eloop yes - exit loop cmpb sig,x match? bne signal30 no - continue leas 4,s clean up stack andcc #^Zero indicate success rts and return signal30 lda sig,x if the entry is not empty ora 2,s or the 'empty' pointer ora 3,s is not null bne signal40 then continue stx 2,s else save address of empty entry signal40 leax entsiz,x bump to next bra loop and round again eloop * we have traversed the table without finding a match ldx 2,s get the empty entry pointer leas 4,s clean the stack rts and return * This is the entry point for all received signals. * If an entry is found matching the signal then * if the function address is not 1 then * the function is executed * an 'rti' is executed * else * the program exits with the signal as status * intrupt leay 0,u point to the data bsr lookup beq intr10 any entry returned? pshs x save the entry pointer ldx func,x get the function address bne intr30 empty entry? * no matching entry - simulate condition of no 'intercept' intr10 os9 F$EXIT status still in B reg. intr20 cmpx #1 is it 'ignore'? bne intr30 no - execute leas 2,s reset stack rti and resume intr30 clra clear the MSB of the signal arg pshs d put it on the stack for the function jsr 0,x go run the function puls d,x get the entry pointer back clra clrb sta sig,x clear the entry std func,x and its func. address rti and that's it! endsect