| [9] | 1 | #
 | 
|---|
 | 2 | 
 | 
|---|
 | 3 | 
 | 
|---|
 | 4 | ; $Header: /cvsup/minix/src/lib/ack/libp/encaps.e,v 1.1 2005/10/10 15:27:46 beng Exp $
 | 
|---|
 | 5 | ;  (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
 | 
|---|
 | 6 | ; 
 | 
|---|
 | 7 | ;           This product is part of the Amsterdam Compiler Kit.
 | 
|---|
 | 8 | ; 
 | 
|---|
 | 9 | ;  Permission to use, sell, duplicate or disclose this software must be
 | 
|---|
 | 10 | ;  obtained in writing. Requests for such permissions may be sent to
 | 
|---|
 | 11 | ; 
 | 
|---|
 | 12 | ;       Dr. Andrew S. Tanenbaum
 | 
|---|
 | 13 | ;       Wiskundig Seminarium
 | 
|---|
 | 14 | ;       Vrije Universiteit
 | 
|---|
 | 15 | ;       Postbox 7161
 | 
|---|
 | 16 | ;       1007 MC Amsterdam
 | 
|---|
 | 17 | ;       The Netherlands
 | 
|---|
 | 18 | ; 
 | 
|---|
 | 19 | 
 | 
|---|
 | 20 |  mes 2,_EM_WSIZE,_EM_PSIZE
 | 
|---|
 | 21 | 
 | 
|---|
 | 22 | ; procedure encaps(procedure p; procedure(q(n:integer));
 | 
|---|
 | 23 | ; {call q if a trap occurs during the execution of p}
 | 
|---|
 | 24 | ; {if q returns, continue execution of p}
 | 
|---|
 | 25 | 
 | 
|---|
 | 26 | 
 | 
|---|
 | 27 |  inp $handler
 | 
|---|
 | 28 | 
 | 
|---|
 | 29 | #define PIISZ   2*_EM_PSIZE
 | 
|---|
 | 30 | 
 | 
|---|
 | 31 | #define PARG    0
 | 
|---|
 | 32 | #define QARG    PIISZ
 | 
|---|
 | 33 | #define E_ELB   0-_EM_PSIZE
 | 
|---|
 | 34 | #define E_EHA   -2*_EM_PSIZE
 | 
|---|
 | 35 | 
 | 
|---|
 | 36 | ; encaps is called with two parameters:
 | 
|---|
 | 37 | ;       - procedure instance identifier of q (QARG)
 | 
|---|
 | 38 | ;       - procedure instance identifier of p (PARG)
 | 
|---|
 | 39 | ; and two local variables:
 | 
|---|
 | 40 | ;       - the lb of the previous encaps      (E_ELB)
 | 
|---|
 | 41 | ;       - the procedure identifier of the previous handler (E_EHA)
 | 
|---|
 | 42 | ;
 | 
|---|
 | 43 | ; One static variable:
 | 
|---|
 | 44 | ;       - the lb of the currently active encaps (enc_lb)
 | 
|---|
 | 45 | 
 | 
|---|
 | 46 | enc_lb
 | 
|---|
 | 47 |         bss _EM_PSIZE,0,0
 | 
|---|
 | 48 | 
 | 
|---|
 | 49 |  exp $encaps
 | 
|---|
 | 50 |  pro $encaps,PIISZ
 | 
|---|
 | 51 |  ; save lb of previous encaps
 | 
|---|
 | 52 |  lae enc_lb
 | 
|---|
 | 53 |  loi _EM_PSIZE
 | 
|---|
 | 54 |  lal E_ELB
 | 
|---|
 | 55 |  sti _EM_PSIZE
 | 
|---|
 | 56 |  ; set new lb
 | 
|---|
 | 57 |  lxl 0
 | 
|---|
 | 58 |  lae enc_lb
 | 
|---|
 | 59 |  sti _EM_PSIZE
 | 
|---|
 | 60 |  ; save old handler id while setting up the new handler
 | 
|---|
 | 61 |  lpi $handler
 | 
|---|
 | 62 |  sig
 | 
|---|
 | 63 |  lal E_EHA
 | 
|---|
 | 64 |  sti _EM_PSIZE
 | 
|---|
 | 65 |  ; handler is ready, p can be called
 | 
|---|
 | 66 |  ; p doesn't expect parameters except possibly the static link
 | 
|---|
 | 67 |  ; always passing the link won't hurt
 | 
|---|
 | 68 |  lal PARG
 | 
|---|
 | 69 |  loi PIISZ
 | 
|---|
 | 70 |  cai
 | 
|---|
 | 71 |  asp _EM_PSIZE
 | 
|---|
 | 72 |  ; reinstate old handler
 | 
|---|
 | 73 |  lal E_ELB
 | 
|---|
 | 74 |  loi _EM_PSIZE
 | 
|---|
 | 75 |  lae enc_lb
 | 
|---|
 | 76 |  sti _EM_PSIZE
 | 
|---|
 | 77 |  lal E_EHA
 | 
|---|
 | 78 |  loi _EM_PSIZE
 | 
|---|
 | 79 |  sig
 | 
|---|
 | 80 |  asp _EM_PSIZE
 | 
|---|
 | 81 |  ret 0
 | 
|---|
 | 82 |  end ?
 | 
|---|
 | 83 | 
 | 
|---|
 | 84 | #define TRAP    0
 | 
|---|
 | 85 | #define H_ELB   0-_EM_PSIZE
 | 
|---|
 | 86 | 
 | 
|---|
 | 87 | ; handler is called with one parameter:
 | 
|---|
 | 88 | ;       - trap number (TRAP)
 | 
|---|
 | 89 | ; one local variable
 | 
|---|
 | 90 | ;       - the current LB of the enclosing encaps (H_ELB)
 | 
|---|
 | 91 | 
 | 
|---|
 | 92 | 
 | 
|---|
 | 93 |  pro $handler,_EM_PSIZE
 | 
|---|
 | 94 |  ; save LB of nearest encaps
 | 
|---|
 | 95 |  lae enc_lb
 | 
|---|
 | 96 |  loi _EM_PSIZE
 | 
|---|
 | 97 |  lal H_ELB
 | 
|---|
 | 98 |  sti _EM_PSIZE
 | 
|---|
 | 99 |  ; fetch setting for previous encaps via LB of nearest
 | 
|---|
 | 100 |  lal H_ELB
 | 
|---|
 | 101 |  loi _EM_PSIZE
 | 
|---|
 | 102 |  adp E_ELB
 | 
|---|
 | 103 |  loi _EM_PSIZE   ; LB of previous encaps
 | 
|---|
 | 104 |  lae enc_lb
 | 
|---|
 | 105 |  sti _EM_PSIZE
 | 
|---|
 | 106 |  lal H_ELB
 | 
|---|
 | 107 |  loi _EM_PSIZE
 | 
|---|
 | 108 |  adp E_EHA
 | 
|---|
 | 109 |  loi _EM_PSIZE   ; previous handler
 | 
|---|
 | 110 |  sig
 | 
|---|
 | 111 |  asp _EM_PSIZE
 | 
|---|
 | 112 |  ; previous handler is re-instated, time to call Q
 | 
|---|
 | 113 |  lol TRAP       ; the one and only real parameter
 | 
|---|
 | 114 |  lal H_ELB
 | 
|---|
 | 115 |  loi _EM_PSIZE
 | 
|---|
 | 116 |  lpb            ; argument base of enclosing encaps
 | 
|---|
 | 117 |  adp QARG
 | 
|---|
 | 118 |  loi PIISZ
 | 
|---|
 | 119 |  exg _EM_PSIZE
 | 
|---|
 | 120 |  dup _EM_PSIZE   ; The static link is now on top
 | 
|---|
 | 121 |  zer _EM_PSIZE
 | 
|---|
 | 122 |  cmp
 | 
|---|
 | 123 |  zeq *1
 | 
|---|
 | 124 |  ; non-zero LB
 | 
|---|
 | 125 |  exg _EM_PSIZE
 | 
|---|
 | 126 |  cai
 | 
|---|
 | 127 |  asp _EM_WSIZE+_EM_PSIZE
 | 
|---|
 | 128 |  bra *2
 | 
|---|
 | 129 | 1
 | 
|---|
 | 130 |  ; zero LB
 | 
|---|
 | 131 |  asp _EM_PSIZE
 | 
|---|
 | 132 |  cai
 | 
|---|
 | 133 |  asp _EM_WSIZE
 | 
|---|
 | 134 | 2
 | 
|---|
 | 135 |  ; now reinstate handler for continued execution of p
 | 
|---|
 | 136 |  lal H_ELB
 | 
|---|
 | 137 |  loi _EM_PSIZE
 | 
|---|
 | 138 |  lae enc_lb
 | 
|---|
 | 139 |  sti _EM_PSIZE
 | 
|---|
 | 140 |  lpi $handler
 | 
|---|
 | 141 |  sig
 | 
|---|
 | 142 |  asp _EM_PSIZE
 | 
|---|
 | 143 |  rtt
 | 
|---|
 | 144 |  end ?
 | 
|---|