readded with-enabled-interrupts

This commit is contained in:
marting 1999-11-04 20:28:06 +00:00
parent 539638acbd
commit 6f15160aac
1 changed files with 33 additions and 51 deletions

View File

@ -64,7 +64,7 @@
(define *enabled-interrupts* (define *enabled-interrupts*
(let lp ((i 0) (mask 0)) (let lp ((i 0) (mask 0))
(if (= i (number-of-interrupts)) (if (= i number-of-interrupts)
mask mask
(lp (+ i 1) (interrupt-enable i mask))))) (lp (+ i 1) (interrupt-enable i mask)))))
@ -77,7 +77,6 @@
;;; ;;;
;;; I think you should... ;;; I think you should...
(define (set-enabled-interrupts new-enabled-interrupts) (define (set-enabled-interrupts new-enabled-interrupts)
(let ((number-of-interrupts (number-of-interrupts)))
(do ((int 0 (+ int 1))) (do ((int 0 (+ int 1)))
((= int number-of-interrupts) new-enabled-interrupts) ((= int number-of-interrupts) new-enabled-interrupts)
(let ((old-state (interrupt-enabled? int *enabled-interrupts*)) (let ((old-state (interrupt-enabled? int *enabled-interrupts*))
@ -90,7 +89,7 @@
(error "there was no blockade" int)) (error "there was no blockade" int))
(unblock-interrupt blockade) (unblock-interrupt blockade)
(vector-set! blockade-vector int #f))) (vector-set! blockade-vector int #f)))
(else 'unchanged))))) (else 'unchanged))))
(set! *enabled-interrupts* new-enabled-interrupts)) (set! *enabled-interrupts* new-enabled-interrupts))
;;; Enableing/Disableing = Unblocking/Blocking ;;; Enableing/Disableing = Unblocking/Blocking
@ -118,7 +117,7 @@
(pending? #f)) (pending? #f))
(define blockade-vector (make-vector (number-of-interrupts) #f)) (define blockade-vector (make-vector number-of-interrupts #f))
;;; do nothing in low-interrupt, the new handler will be recorded in the ;;; do nothing in low-interrupt, the new handler will be recorded in the
;;; interrupt-handler-vector however ;;; interrupt-handler-vector however
@ -150,80 +149,63 @@
; install the handler that resides in the vector ; install the handler that resides in the vector
(let ((low-int-set! (blockade:low-int-set! blockade))) (let ((low-int-set! (blockade:low-int-set! blockade)))
(low-int-set! handler) (low-int-set! handler)
; resinstall the low-interrupt-setter ; reinstall the low-interrupt-setter
(set-cdr! (blockade:interrupt-vector-cell blockade) (set-cdr! (blockade:interrupt-vector-cell blockade)
low-int-set!) low-int-set!)
(if (blockade:pending? blockade) (if (blockade:pending? blockade)
(apply handler (blockade:pending? blockade)))))) (apply handler (blockade:pending? blockade))))))
;(define-simple-syntax (with-enabled-interrupts mask body ...) (define-simple-syntax (with-enabled-interrupts interrupt-set body ...)
; (with-interrupts mask (lambda () body ...)))
(define-simple-syntax (with-enabled-interrupts mask body ...)
(begin (begin
;(display "JMG: use of w-e-i") (with-enabled-interrupts* interrupt-set (lambda () body ...))))
body ...))
(define (with-enabled-interrupts* thunk thunk) (define (with-enabled-interrupts* interrupt-set thunk)
(warn "JMG: use of with-enabled-interrupts*") (let ((before *enabled-interrupts*))
(thunk)) (set-enabled-interrupts interrupt-set)
(let ((return (thunk)))
(set-enabled-interrupts before)
return)))
; Fakes vm vector ; Fakes vm vector
;;; car is the actual handler, cdr is a proc to set handler in low-interrupt system ;;; car is the actual handler, cdr is a proc to set handler in
;;; low-interrupt system
(define *interrupt-handlers-vector* (define *interrupt-handlers-vector*
(make-vector (number-of-interrupts) (cons #f #f))) (make-vector number-of-interrupts (cons #f #f)))
(define (interrupt-handlers-vector) (define (interrupt-handlers-vector)
*interrupt-handlers-vector*) *interrupt-handlers-vector*)
(define (interrupt-handler-ref int) (define (interrupt-handler-ref int)
(if (or (< int 0) (>= int (number-of-interrupts))) (if (or (< int 0) (>= int number-of-interrupts))
(error "ill signum in interrupt-handler-ref" int) (error "ill signum in interrupt-handler-ref" int)
(car (vector-ref *interrupt-handlers-vector* int)))) (car (vector-ref *interrupt-handlers-vector* int))))
;;; the handler is not interested in the enabled interupts of the vm
;;; but in those managed here
(define (make-handler handler)
(lambda (enabled-low)
(handler (enabled-interrupts))))
(define (set-interrupt-handler! int handler) (define (set-interrupt-handler! int handler)
(if (or (< int 0) (>= int (number-of-interrupts))) (if (or (< int 0) (>= int number-of-interrupts))
(error "ill signum in set-interrupt-handler!" int) (error "ill signum in set-interrupt-handler!" int)
(let ((old (vector-ref *interrupt-handlers-vector* int))) (let ((handler-setter (vector-ref *interrupt-handlers-vector* int))
(if (not (cdr old)) ; not yet registered? (handler-enabled-here (make-handler handler)))
(if (not (cdr handler-setter)) ; not yet registered?
(let ((setter (low-interrupt-register (let ((setter (low-interrupt-register
int handler))) int handler-enabled-here)))
(vector-set! *interrupt-handlers-vector* (vector-set! *interrupt-handlers-vector*
int int
(cons handler setter))) (cons handler setter)))
(begin (begin
((cdr old) handler) ; set it with setter ((cdr handler-setter) handler-enabled-here) ; set it with setter
(set-car! (vector-ref *interrupt-handlers-vector* int) (set-car! (vector-ref *interrupt-handlers-vector* int)
handler)))))) handler))))))
;(define (init-interrupt)
; (do ((sig 32 (- sig 1)))
; ((< sig 0))
; (set-scsh-low-interrupt-handler!
; sig
; (lambda (x) #t)))
; (set-interrupt-handler!
; (enum interrupt os-signal)
; (lambda (type arg enabled-interrupts)
; (if (= type (enum scsh-os-signal chld))
; (begin
; (procobj-handler enabled-interrupts)))
; ((scsh-os-signal-handler-ref type) enabled-interrupts)
; ))
; (display "sighandler installed")
; #t)
;;; Get/Set signal handlers ;;; Get/Set signal handlers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -352,7 +334,7 @@
(define (%install-scsh-handlers) (define (%install-scsh-handlers)
(do ((int 0 (+ int 1))) (do ((int 0 (+ int 1)))
((= int (number-of-interrupts))) ((= int number-of-interrupts))
(set-interrupt-handler (set-interrupt-handler
int int
(lambda a #f))) (lambda a #f)))