]> git.sur5r.net Git - cc65/commitdiff
Add signal() and raise()
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Fri, 14 Mar 2003 00:02:58 +0000 (00:02 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Fri, 14 Mar 2003 00:02:58 +0000 (00:02 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@2017 b7a2c559-68d2-44c3-8de9-860c34a00d81

libsrc/common/Makefile
libsrc/common/raise.s [new file with mode: 0644]
libsrc/common/signal.s [new file with mode: 0644]
libsrc/common/sigtable.s [new file with mode: 0644]

index fac52576ccce68eea43c47ae941f3090aff35903..5e5953e322575e931ea08ed7811aeeb301dbfc94 100644 (file)
@@ -44,8 +44,11 @@ C_OBJS =     _afailed.o      \
                putchar.o       \
                puts.o          \
                qsort.o         \
+                raise.o         \
                realloc.o       \
                rewind.o        \
+                signal.o        \
+                sigtable.o      \
                sscanf.o        \
                 strftime.o      \
                strxfrm.o       \
diff --git a/libsrc/common/raise.s b/libsrc/common/raise.s
new file mode 100644 (file)
index 0000000..753def8
--- /dev/null
@@ -0,0 +1,44 @@
+;
+; Ullrich von Bassewitz, 2003-03-14
+;
+; int __fastcall__ raise (int sig);
+;
+
+        .import         jmpvec
+
+        .include        "signal.inc"
+
+
+;----------------------------------------------------------------------------
+; int __fastcall__ raise (int sig);
+
+
+_raise:
+        cpx     #0
+        bne     invalidsig
+        cmp     #SIGCOUNT
+        bcs     invalidsig
+
+; Save the signal number low byte, then setup the function vector
+
+        pha
+        asl     a
+        tax
+        lda     sigtable,x
+        sta     jmpvec+1
+        lda     sigtable+1,x
+        sta     jmpvec+2
+
+; Restore the signal number and call the function
+
+        pla                     ; Low byte
+        ldx     #0              ; High byte
+        jsr     jmpvec          ; Call signal function
+
+; raise() returns zero on success and any other value on failure
+
+        lda     #0
+        tax
+invalidsig:
+        rts
+
diff --git a/libsrc/common/signal.s b/libsrc/common/signal.s
new file mode 100644 (file)
index 0000000..e776742
--- /dev/null
@@ -0,0 +1,68 @@
+;
+; Ullrich von Bassewitz, 2002-12-16
+;
+; __sigfunc __fastcall__ signal (int sig, __sigfunc func);
+;
+
+       .import         popax
+       .importzp       ptr1
+
+        .include        "signal.inc"
+        .include        "errno.inc"
+
+
+; Default signal functions: The standard specifies explicitly that the values
+; for SIG_IGN and SIG_DFL must be distinct, so we make them so by using both
+; rts exits we have. This works because signal functions are __fastcall__, so
+; we don't have arguments on the stack.
+
+
+;----------------------------------------------------------------------------
+; __sigfunc __fastcall__ signal (int sig, __sigfunc func);
+
+
+_signal:
+        sta     ptr1
+        stx     ptr1+1          ; Remember func
+
+        jsr     popax           ; Get sig
+
+        cpx     #0
+        bne     invalidsig
+        cmp     #SIGCOUNT
+        bcs     invalidsig
+
+; Signal number is valid. Replace the pointer in the table saving the old
+; value temporarily on the stack.
+
+        asl     a               ; Prepare for word access
+        tax
+
+        lda     sigtable,x
+        pha
+        lda     ptr1
+        sta     sigtable,x
+        lda     sigtable+1,x
+        pha
+        lda     ptr1+1
+        sta     sigtable+1,x
+
+; Get the old value from the stack and return it
+
+        pla
+        tax
+        pla
+__sig_ign:
+        rts
+
+; Error entry: We use our knowledge that SIG_ERR is zero here to save a byte
+
+invalidsig:
+        lda     #<EINVAL
+        sta     __errno
+        lda     #>EINVAL        ; A = 0
+        sta     __errno+1
+        tax                     ; A/X = 0
+__sig_dfl:
+        rts
+
diff --git a/libsrc/common/sigtable.s b/libsrc/common/sigtable.s
new file mode 100644 (file)
index 0000000..7780ef6
--- /dev/null
@@ -0,0 +1,24 @@
+;
+; Ullrich von Bassewitz, 2002-12-16
+;
+; Signal vector table
+;
+
+        .export         sigtable
+
+        .include        "signal.inc"
+
+;----------------------------------------------------------------------------
+;
+
+.data
+
+sigtable:
+        .word   __sig_dfl       ; SIGABRT
+        .word   __sig_dfl       ; SIGFPE
+        .word   __sig_dfl       ; SIGILL
+        .word   __sig_dfl       ; SIGINT
+        .word   __sig_dfl       ; SIGSEGV
+        .word   __sig_dfl       ; SIGTERM
+
+