1 ;;;; the definitions of VOPs used for non-local exit (THROW, lexical
4 ;;;; This software is part of the SBCL system. See the README file for
7 ;;;; This software is derived from the CMU CL system, which was
8 ;;;; written at Carnegie Mellon University and released into the
9 ;;;; public domain. The software is in the public domain and is
10 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
11 ;;;; files for more information.
15 ;;; Make an environment-live stack TN for saving the SP for NLX entry.
16 (!def-vm-support-routine make-nlx-sp-tn (env)
18 (make-representation-tn *fixnum-primitive-type* immediate-arg-scn)
21 ;;; Make a TN for the argument count passing location for a
23 (!def-vm-support-routine make-nlx-entry-arg-start-location ()
24 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn ocfp-offset))
27 ;;;; save and restoring the dynamic environment
29 ;;;; These VOPs are used in the reentered function to restore the
30 ;;;; appropriate dynamic environment. Currently we only save the
31 ;;;; CURRENT-CATCH and binding stack pointer. We don't need to
32 ;;;; save/restore the current UNWIND-PROTECT, since UNWIND-PROTECTS
33 ;;;; are implicitly processed during unwinding. If there were any
34 ;;;; additional stacks (as e.g. there was an interpreter "eval stack"
35 ;;;; before sbcl-0.7.0), then this would be the place to restore the
38 ;;; Return a list of TNs that can be used to snapshot the dynamic
39 ;;; state for use with the SAVE- and RESTORE-DYNAMIC-ENVIRONMENT VOPs.
40 (!def-vm-support-routine make-dynamic-state-tns ()
41 (list (make-normal-tn *backend-t-primitive-type*)
42 (make-normal-tn *backend-t-primitive-type*)
43 (make-normal-tn *backend-t-primitive-type*)
44 (make-normal-tn *backend-t-primitive-type*)))
46 (define-vop (save-dynamic-state)
47 (:results (catch :scs (descriptor-reg))
48 (nfp :scs (descriptor-reg))
49 (nsp :scs (descriptor-reg)))
52 (load-symbol-value catch *current-catch-block*)
53 (let ((cur-nfp (current-nfp-tn vop)))
55 (inst mskll cur-nfp 4 nfp)))
56 (inst mskll nsp-tn 4 nsp)))
58 (define-vop (restore-dynamic-state)
59 (:args (catch :scs (descriptor-reg))
60 (nfp :scs (descriptor-reg))
61 (nsp :scs (descriptor-reg)))
63 (:temporary (:sc any-reg) temp)
65 (store-symbol-value catch *current-catch-block*)
66 (inst mskll nsp-tn 0 temp)
67 (let ((cur-nfp (current-nfp-tn vop)))
69 (inst bis nfp temp cur-nfp)))
70 (inst bis nsp temp nsp-tn)))
72 (define-vop (current-stack-pointer)
73 (:results (res :scs (any-reg descriptor-reg)))
77 (define-vop (current-binding-pointer)
78 (:results (res :scs (any-reg descriptor-reg)))
82 ;;;; unwind block hackery
84 ;;; Compute the address of the catch block from its TN, then store
85 ;;; into the block the current Fp, Env, Unwind-Protect, and the entry PC.
86 (define-vop (make-unwind-block)
89 (:results (block :scs (any-reg)))
90 (:temporary (:scs (descriptor-reg)) temp)
91 (:temporary (:scs (non-descriptor-reg)) ndescr)
93 (inst lda block (* (tn-offset tn) sb!vm:n-word-bytes) cfp-tn)
94 (load-symbol-value temp *current-unwind-protect-block*)
95 (storew temp block sb!vm:unwind-block-current-uwp-slot)
96 (storew cfp-tn block sb!vm:unwind-block-current-cont-slot)
97 (storew code-tn block sb!vm:unwind-block-current-code-slot)
98 (inst compute-lra-from-code temp code-tn entry-label ndescr)
99 (storew temp block sb!vm:catch-block-entry-pc-slot)))
102 ;;; This is like Make-Unwind-Block, except that we also store in the
103 ;;; specified tag, and link the block into the Current-Catch list.
104 (define-vop (make-catch-block)
106 (tag :scs (any-reg descriptor-reg)))
108 (:results (block :scs (any-reg)))
109 (:temporary (:scs (descriptor-reg)) temp)
110 (:temporary (:scs (descriptor-reg) :target block :to (:result 0)) result)
111 (:temporary (:scs (non-descriptor-reg)) ndescr)
113 (inst lda result (* (tn-offset tn) sb!vm:n-word-bytes) cfp-tn)
114 (load-symbol-value temp *current-unwind-protect-block*)
115 (storew temp result sb!vm:catch-block-current-uwp-slot)
116 (storew cfp-tn result sb!vm:catch-block-current-cont-slot)
117 (storew code-tn result sb!vm:catch-block-current-code-slot)
118 (inst compute-lra-from-code temp code-tn entry-label ndescr)
119 (storew temp result sb!vm:catch-block-entry-pc-slot)
121 (storew tag result sb!vm:catch-block-tag-slot)
122 (load-symbol-value temp *current-catch-block*)
123 (storew temp result sb!vm:catch-block-previous-catch-slot)
124 (store-symbol-value result *current-catch-block*)
126 (move result block)))
128 ;;; Just set the current unwind-protect to TN's address. This
129 ;;; instantiates an unwind block as an unwind-protect.
130 (define-vop (set-unwind-protect)
132 (:temporary (:scs (descriptor-reg)) new-uwp)
134 (inst lda new-uwp (* (tn-offset tn) sb!vm:n-word-bytes) cfp-tn)
135 (store-symbol-value new-uwp *current-unwind-protect-block*)))
137 (define-vop (unlink-catch-block)
138 (:temporary (:scs (any-reg)) block)
140 (:translate %catch-breakup)
142 (load-symbol-value block *current-catch-block*)
143 (loadw block block sb!vm:catch-block-previous-catch-slot)
144 (store-symbol-value block *current-catch-block*)))
146 (define-vop (unlink-unwind-protect)
147 (:temporary (:scs (any-reg)) block)
149 (:translate %unwind-protect-breakup)
151 (load-symbol-value block *current-unwind-protect-block*)
152 (loadw block block sb!vm:unwind-block-current-uwp-slot)
153 (store-symbol-value block *current-unwind-protect-block*)))
157 (define-vop (nlx-entry)
158 (:args (sp) ; Note: we can't list an sc-restriction, 'cause any load vops
159 ; would be inserted before the LRA.
162 (:results (values :more t))
163 (:temporary (:scs (descriptor-reg)) move-temp)
164 (:temporary (:sc non-descriptor-reg) temp)
166 (:save-p :force-to-stack)
169 (emit-return-pc label)
170 (note-this-location vop :non-local-entry)
171 (cond ((zerop nvals))
173 (let ((no-values (gen-label)))
174 (move null-tn (tn-ref-tn values))
175 (inst beq count no-values)
176 (loadw (tn-ref-tn values) start)
177 (emit-label no-values)))
179 (collect ((defaults))
181 (tn-ref values (tn-ref-across tn-ref)))
183 (let ((default-lab (gen-label))
184 (tn (tn-ref-tn tn-ref)))
185 (defaults (cons default-lab tn))
187 (inst move count temp)
188 (inst lda count (fixnumize -1) count)
189 (inst beq temp default-lab)
191 ((descriptor-reg any-reg)
194 (loadw move-temp start i)
195 (store-stack-tn tn move-temp)))))
197 (let ((defaulting-done (gen-label)))
199 (emit-label defaulting-done)
201 (assemble (*elsewhere*)
202 (dolist (def (defaults))
203 (emit-label (car def))
204 (let ((tn (cdr def)))
206 ((descriptor-reg any-reg)
209 (store-stack-tn tn null-tn)))))
210 (inst br zero-tn defaulting-done))))))
211 (load-stack-tn csp-tn sp)))
213 (define-vop (nlx-entry-multiple)
214 (:args (top :target dst) (start :target src) (count :target num))
215 ;; Again, no SC restrictions for the args, 'cause the loading would
216 ;; happen before the entry label.
218 (:temporary (:scs (any-reg) :from (:argument 0)) dst)
219 (:temporary (:scs (any-reg) :from (:argument 1)) src)
220 (:temporary (:scs (any-reg) :from (:argument 2)) num)
221 (:temporary (:scs (descriptor-reg)) temp)
222 (:results (new-start) (new-count))
223 (:save-p :force-to-stack)
226 (emit-return-pc label)
227 (note-this-location vop :non-local-entry)
228 (let ((loop (gen-label))
232 (load-stack-tn dst top)
236 ;; Establish results.
238 (any-reg (move dst new-start))
239 (control-stack (store-stack-tn new-start dst)))
241 (any-reg (inst move num new-count))
242 (control-stack (store-stack-tn new-count num)))
245 ;; Copy stuff on stack.
248 (inst lda src sb!vm:n-word-bytes src)
250 (inst lda num (fixnumize -1) num)
251 (inst lda dst sb!vm:n-word-bytes dst)
255 (inst move dst csp-tn))))
257 ;;; This VOP is just to force the TNs used in the cleanup onto the stack.
258 (define-vop (uwp-entry)
260 (:save-p :force-to-stack)
261 (:results (block) (start) (count))
262 (:ignore block start count)
265 (emit-return-pc label)
266 (note-this-location vop :non-local-entry)))