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))
26 ;;;; save and restoring the dynamic environment
28 ;;;; These VOPs are used in the reentered function to restore the
29 ;;;; appropriate dynamic environment. Currently we only save the
30 ;;;; CURRENT-CATCH and binding stack pointer. We don't need to
31 ;;;; save/restore the current UNWIND-PROTECT, since UNWIND-PROTECTS
32 ;;;; are implicitly processed during unwinding. If there were any
33 ;;;; additional stacks (as e.g. there was an interpreter "eval stack"
34 ;;;; before sbcl-0.7.0), then this would be the place to restore the
37 ;;; Return a list of TNs that can be used to snapshot the dynamic
38 ;;; state for use with the SAVE- and RESTORE-DYNAMIC-ENVIRONMENT VOPs.
39 (!def-vm-support-routine make-dynamic-state-tns ()
40 (list (make-normal-tn *backend-t-primitive-type*)
41 (make-normal-tn *backend-t-primitive-type*)
42 (make-normal-tn *backend-t-primitive-type*)
43 (make-normal-tn *backend-t-primitive-type*)))
45 (define-vop (save-dynamic-state)
46 (:results (catch :scs (descriptor-reg))
47 (nfp :scs (descriptor-reg))
48 (nsp :scs (descriptor-reg)))
51 (load-symbol-value catch *current-catch-block*)
52 (let ((cur-nfp (current-nfp-tn vop)))
54 (inst mskll cur-nfp 4 nfp)))
55 (inst mskll nsp-tn 4 nsp)))
57 (define-vop (restore-dynamic-state)
58 (:args (catch :scs (descriptor-reg))
59 (nfp :scs (descriptor-reg))
60 (nsp :scs (descriptor-reg)))
62 (:temporary (:sc any-reg) temp)
64 (store-symbol-value catch *current-catch-block*)
65 (inst mskll nsp-tn 0 temp)
66 (let ((cur-nfp (current-nfp-tn vop)))
68 (inst bis nfp temp cur-nfp)))
69 (inst bis nsp temp nsp-tn)))
71 (define-vop (current-stack-pointer)
72 (:results (res :scs (any-reg descriptor-reg)))
76 (define-vop (current-binding-pointer)
77 (:results (res :scs (any-reg descriptor-reg)))
81 ;;;; unwind block hackery
83 ;;; Compute the address of the catch block from its TN, then store
84 ;;; into the block the current Fp, Env, Unwind-Protect, and the entry PC.
85 (define-vop (make-unwind-block)
88 (:results (block :scs (any-reg)))
89 (:temporary (:scs (descriptor-reg)) temp)
90 (:temporary (:scs (non-descriptor-reg)) ndescr)
92 (inst lda block (* (tn-offset tn) sb!vm:n-word-bytes) cfp-tn)
93 (load-symbol-value temp *current-unwind-protect-block*)
94 (storew temp block sb!vm:unwind-block-current-uwp-slot)
95 (storew cfp-tn block sb!vm:unwind-block-current-cont-slot)
96 (storew code-tn block sb!vm:unwind-block-current-code-slot)
97 (inst compute-lra-from-code temp code-tn entry-label ndescr)
98 (storew temp block sb!vm:catch-block-entry-pc-slot)))
101 ;;; This is like Make-Unwind-Block, except that we also store in the
102 ;;; specified tag, and link the block into the Current-Catch list.
103 (define-vop (make-catch-block)
105 (tag :scs (any-reg descriptor-reg)))
107 (:results (block :scs (any-reg)))
108 (:temporary (:scs (descriptor-reg)) temp)
109 (:temporary (:scs (descriptor-reg) :target block :to (:result 0)) result)
110 (:temporary (:scs (non-descriptor-reg)) ndescr)
112 (inst lda result (* (tn-offset tn) sb!vm:n-word-bytes) cfp-tn)
113 (load-symbol-value temp *current-unwind-protect-block*)
114 (storew temp result sb!vm:catch-block-current-uwp-slot)
115 (storew cfp-tn result sb!vm:catch-block-current-cont-slot)
116 (storew code-tn result sb!vm:catch-block-current-code-slot)
117 (inst compute-lra-from-code temp code-tn entry-label ndescr)
118 (storew temp result sb!vm:catch-block-entry-pc-slot)
120 (storew tag result sb!vm:catch-block-tag-slot)
121 (load-symbol-value temp *current-catch-block*)
122 (storew temp result sb!vm:catch-block-previous-catch-slot)
123 (store-symbol-value result *current-catch-block*)
125 (move result block)))
127 ;;; Just set the current unwind-protect to TN's address. This
128 ;;; instantiates an unwind block as an unwind-protect.
129 (define-vop (set-unwind-protect)
131 (:temporary (:scs (descriptor-reg)) new-uwp)
133 (inst lda new-uwp (* (tn-offset tn) sb!vm:n-word-bytes) cfp-tn)
134 (store-symbol-value new-uwp *current-unwind-protect-block*)))
136 (define-vop (unlink-catch-block)
137 (:temporary (:scs (any-reg)) block)
139 (:translate %catch-breakup)
141 (load-symbol-value block *current-catch-block*)
142 (loadw block block sb!vm:catch-block-previous-catch-slot)
143 (store-symbol-value block *current-catch-block*)))
145 (define-vop (unlink-unwind-protect)
146 (:temporary (:scs (any-reg)) block)
148 (:translate %unwind-protect-breakup)
150 (load-symbol-value block *current-unwind-protect-block*)
151 (loadw block block sb!vm:unwind-block-current-uwp-slot)
152 (store-symbol-value block *current-unwind-protect-block*)))
156 (define-vop (nlx-entry)
157 (:args (sp) ; Note: we can't list an sc-restriction, 'cause any load vops
158 ; would be inserted before the LRA.
161 (:results (values :more t))
162 (:temporary (:scs (descriptor-reg)) move-temp)
163 (:temporary (:sc non-descriptor-reg) temp)
165 (:save-p :force-to-stack)
168 (emit-return-pc label)
169 (note-this-location vop :non-local-entry)
170 (cond ((zerop nvals))
172 (let ((no-values (gen-label)))
173 (move null-tn (tn-ref-tn values))
174 (inst beq count no-values)
175 (loadw (tn-ref-tn values) start)
176 (emit-label no-values)))
178 (collect ((defaults))
180 (tn-ref values (tn-ref-across tn-ref)))
182 (let ((default-lab (gen-label))
183 (tn (tn-ref-tn tn-ref)))
184 (defaults (cons default-lab tn))
186 (inst move count temp)
187 (inst lda count (fixnumize -1) count)
188 (inst beq temp default-lab)
190 ((descriptor-reg any-reg)
193 (loadw move-temp start i)
194 (store-stack-tn tn move-temp)))))
196 (let ((defaulting-done (gen-label)))
198 (emit-label defaulting-done)
200 (assemble (*elsewhere*)
201 (dolist (def (defaults))
202 (emit-label (car def))
203 (let ((tn (cdr def)))
205 ((descriptor-reg any-reg)
208 (store-stack-tn tn null-tn)))))
209 (inst br zero-tn defaulting-done))))))
210 (load-stack-tn csp-tn sp)))
212 (define-vop (nlx-entry-multiple)
213 (:args (top :target dst) (start :target src) (count :target num))
214 ;; Again, no SC restrictions for the args, 'cause the loading would
215 ;; happen before the entry label.
217 (:temporary (:scs (any-reg) :from (:argument 0)) dst)
218 (:temporary (:scs (any-reg) :from (:argument 1)) src)
219 (:temporary (:scs (any-reg) :from (:argument 2)) num)
220 (:temporary (:scs (descriptor-reg)) temp)
221 (:results (new-start) (new-count))
222 (:save-p :force-to-stack)
225 (emit-return-pc label)
226 (note-this-location vop :non-local-entry)
227 (let ((loop (gen-label))
231 (load-stack-tn dst top)
235 ;; Establish results.
237 (any-reg (move dst new-start))
238 (control-stack (store-stack-tn new-start dst)))
240 (any-reg (inst move num new-count))
241 (control-stack (store-stack-tn new-count num)))
244 ;; Copy stuff on stack.
247 (inst lda src sb!vm:n-word-bytes src)
249 (inst lda num (fixnumize -1) num)
250 (inst lda dst sb!vm:n-word-bytes dst)
254 (inst move dst csp-tn))))
256 ;;; This VOP is just to force the TNs used in the cleanup onto the stack.
257 (define-vop (uwp-entry)
259 (:save-p :force-to-stack)
260 (:results (block) (start) (count))
261 (:ignore block start count)
264 (emit-return-pc label)
265 (note-this-location vop :non-local-entry)))