Interrupt system fixed up and installed.

This commit is contained in:
shivers 1996-11-10 13:58:46 +00:00
parent 7e66a68afa
commit ea9745ee2f
6 changed files with 72 additions and 36 deletions

View File

@ -107,6 +107,7 @@ SCSHOBJS = \
scsh/flock.o scsh/flock1.o \ scsh/flock.o scsh/flock1.o \
scsh/machine/stdio_dep.o \ scsh/machine/stdio_dep.o \
scsh/machine/time_dep1.o \ scsh/machine/time_dep1.o \
scsh/machine/signals1.o \
scsh/machine/libansi.o \ scsh/machine/libansi.o \
scsh/network.o scsh/network1.o \ scsh/network.o scsh/network1.o \
scsh/putenv.o \ scsh/putenv.o \
@ -635,11 +636,13 @@ scsh/scsh.image: $(VM) $(SCHEME) $(CIG).image
echo ",load $(srcdir)/scsh/scsh-interfaces.scm"; \ echo ",load $(srcdir)/scsh/scsh-interfaces.scm"; \
echo ",load $(srcdir)/scsh/machine/packages.scm"; \ echo ",load $(srcdir)/scsh/machine/packages.scm"; \
echo ",load $(srcdir)/scsh/scsh-package.scm"; \ echo ",load $(srcdir)/scsh/scsh-package.scm"; \
echo ",user"; \
echo ",load-package scsh"; \ echo ",load-package scsh"; \
echo ",load-package scsh-here-string-hax"; \ echo ",load-package scsh-here-string-hax"; \
echo ",open scsh"; \
echo ",translate =scheme48/ $(LIB)/"; \ echo ",translate =scheme48/ $(LIB)/"; \
echo ",in scsh-level-0"; \
echo "(%install-scsh-handlers)"; \
echo ",user"; \
echo ",open scsh"; \
echo "(dump-scsh \"scsh/scsh.image\")") \ echo "(dump-scsh \"scsh/scsh.image\")") \
| ./$(VM) -o ./$(VM) -i $(CIG).image | ./$(VM) -o ./$(VM) -i $(CIG).image

View File

@ -28,3 +28,6 @@
(usr1 30) ; user defined signal 1 (usr1 30) ; user defined signal 1
(usr2 31) ; user defined signal 2 (usr2 31) ; user defined signal 2
) )
(define signals-ignored-by-default
(list signal/chld signal/cont)) ; These are Posix.

View File

@ -707,7 +707,8 @@
(define (init-scsh-hindbrain relink-ff?) (define (init-scsh-hindbrain relink-ff?)
(if relink-ff? (lookup-all-externals)) ; Re-link C calls. (if relink-ff? (lookup-all-externals)) ; Re-link C calls.
(init-fdports!)) (init-fdports!)
(%install-unix-scsh-handlers))
;;; Some globals: ;;; Some globals:

View File

@ -59,6 +59,31 @@
(define with-enabled-interrupts* with-interrupts) (define with-enabled-interrupts* with-interrupts)
(define interrupt/alarm (enum interrupt alarm))
(define interrupt/keyboard (enum interrupt keyboard))
(define interrupt/memory-shortage (enum interrupt memory-shortage))
(define interrupt/chld (enum interrupt chld))
(define interrupt/cont (enum interrupt cont))
(define interrupt/hup (enum interrupt hup))
(define interrupt/quit (enum interrupt quit))
(define interrupt/term (enum interrupt term))
(define interrupt/tstp (enum interrupt tstp))
(define interrupt/usr1 (enum interrupt usr1))
(define interrupt/usr2 (enum interrupt usr2))
(define interrupt/info (enum interrupt info))
(define interrupt/io (enum interrupt io))
(define interrupt/poll (enum interrupt poll))
(define interrupt/prof (enum interrupt prof))
(define interrupt/pwr (enum interrupt pwr))
(define interrupt/urg (enum interrupt urg))
(define interrupt/vtalrm (enum interrupt vtalrm))
(define interrupt/winch (enum interrupt winch))
(define interrupt/xcpu (enum interrupt xcpu))
(define interrupt/xfsz (enum interrupt xfsz))
(define interrupt/int interrupt/keyboard)
(define interrupt/alrm interrupt/alarm)
;;; Get/Set signal handlers ;;; Get/Set signal handlers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -76,44 +101,42 @@
(define-foreign %do-default-sigaction (do_default_sigaction (fixnum signal)) (define-foreign %do-default-sigaction (do_default_sigaction (fixnum signal))
ignore) ignore)
;;; This gives the default handler for each signal. (define default-int-handler-vec
(define default-handler-vec ;; Non-Unix-signal interrupts just get their default values from
(initialize-vector 32 (lambda (sig) ;; the current value of I-H.
;; This is the guy to call when you want signal (let ((v (copy-vector interrupt-handlers)))
;; SIG handled in the default manner. (do ((sig 31 (- sig 1))) ; For each Unix signal
(if (memv sig signals-ignored-by-default) ((< sig 0)) ; make & install a default
(lambda (enabled-interrupts) #f) (let ((i (%signal->interrupt sig))) ; signal handler.
(lambda (enabled-interrupts) (if (>= i 0) ; Don't mess with non-signal interrupts.
(%do-default-sigaction sig)))))) (vector-set! v i (if (memv sig signals-ignored-by-default)
(lambda (enabled-interrupts) #f)
(lambda (enabled-interrupts)
(%do-default-sigaction sig)))))))
v))
;;; HANDLER is #f (ignore), #t (default), or a procedure taking an integer ;;; HANDLER is #f (ignore), #t (default), or a procedure taking an integer
;;; argument. The interrupt is delivered to a procedure by (1) setting the ;;; argument. The interrupt is delivered to a procedure by (1) setting the
;;; ENABLED-INTERRUPTS register to 0 (i.e., blocking all interrupts), and (2) ;;; ENABLED-INTERRUPTS register to 0 (i.e., blocking all interrupts), and (2)
;;; applying the procedure to the previous value of the ENABLED-INTERRUPTS ;;; applying the procedure to the previous value of the ENABLED-INTERRUPTS
;;; register. If the procedure returns normally (i.e., it doesn't throw to a ;;; register. If the procedure returns normally, the ENABLED-INTERRUPTS
;;; continuation), the ENABLED-INTERRUPTS register will be restored to its ;;; register will be restored to its previous value.
;;; previous value.
;;; This handler does nothing -- used when the handler is #f. ;;; This handler does nothing -- used when the handler is #f.
(define (noop-sig-handler enabled-interrupts) #f) (define (noop-sig-handler enabled-interrupts) #f)
(define (set-signal-handler! sig handler) (define (set-interrupt-handler! int handler)
(let ((nhandler (case handler (let ((ohandler (interrupt-handler int)))
((#t) (vector-ref default-handler-vec sig)) (vector-set! interrupt-handlers int
((#f) noop-sig-handler) (case handler
(else handler))) ((#t) (vector-ref default-int-handler-vec int))
(int (signal->interrupt sig))) ((#f) noop-sig-handler)
(with-enabled-interrupts 0 (else handler)))
(let ((ohandler (vector-ref interrupt-handlers int))) ohandler))
(vector-set! interrupt-handlers int nhandler)
(cond ((eq? ohandler (vector-ref default-handler-vec sig)) #t)
((eq? ohandler noop-sig-handler) #f)
(else ohandler))))))
(define (signal-handler sig) (define (interrupt-handler int)
(let ((handler (vector-ref interrupt-handlers (signal->interrupt sig)))) (let ((handler (vector-ref interrupt-handlers int)))
(cond ((eq? handler (vector-ref default-handler-vec sig)) #t) (cond ((eq? handler (vector-ref default-int-handler-vec int)) #t)
((eq? handler noop-sig-handler) #f) ((eq? handler noop-sig-handler) #f)
(else handler)))) (else handler))))
@ -166,6 +189,8 @@
(do ((sig 32 (- sig 1))) (do ((sig 32 (- sig 1)))
((< sig 0)) ((< sig 0))
(let ((i (%signal->interrupt sig))) (let ((i (%signal->interrupt sig)))
(if (not (or (= i -1) (= sig signal/int) (= sig signal/alrm))) (if (not (or (= i -1)
(= sig signal/int) ; Leave ^c and
(= sig signal/alrm))) ; alarm handlers alone.
(vector-set! interrupt-handlers i (vector-set! interrupt-handlers i
(vector-ref default-handler-vec sig)))))) (vector-ref default-int-handler-vec i))))))

View File

@ -12,6 +12,9 @@
/* Make sure our exports match up w/the implementation: */ /* Make sure our exports match up w/the implementation: */
#include "sighandlers1.h" #include "sighandlers1.h"
/* Import the OS-dependent set of signals and their translations
** to S48 vm interrupts.
*/
#include "signals1.h" #include "signals1.h"
extern int errno; extern int errno;
@ -63,7 +66,7 @@ int get_procmask(int *old_lo_p)
static void scm_handle_sig(int sig) static void scm_handle_sig(int sig)
{ {
/* fprintf(stderr, "scm_handle_sig(%d)\n", sig); */ /*fprintf(stderr, "scm_handle_sig(%d) = int %d\n", sig, sig2int[sig]);*/
Spending_interruptsS |= (1<<sig2int[sig]); Spending_interruptsS |= (1<<sig2int[sig]);
} }
@ -169,6 +172,7 @@ void install_scsh_handlers(void)
sigemptyset(&new.sa_mask); /* WTF */ sigemptyset(&new.sa_mask); /* WTF */
new.sa_handler = scm_handle_sig; new.sa_handler = scm_handle_sig;
new.sa_flags = 0;
for(i=max_sig; i>=0; i--) for(i=max_sig; i>=0; i--)
if( sig2int[i] ) { if( sig2int[i] ) {

View File

@ -1,4 +1,4 @@
/* Exports from signals1.c */ /* Exports from signals1.c */
const int sig2int[]; extern const int sig2int[];
const int max_sig; extern const int max_sig;