1 ;;;; the SPARC definitions of VOPs used for non-local exit (throw,
2 ;;;; lexical exit, etc.)
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 non-local
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 restore 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 are
32 ;;; implicitly processed during unwinding. If there were any
33 ;;; additional stacks, then this would be the place to restore the top
36 (define-vop (save-dynamic-state)
37 (:results (catch :scs (descriptor-reg))
38 (nfp :scs (descriptor-reg))
39 (nsp :scs (descriptor-reg)))
42 (load-symbol-value catch *current-catch-block*)
43 (let ((cur-nfp (current-nfp-tn vop)))
48 (define-vop (restore-dynamic-state)
49 (:args (catch :scs (descriptor-reg))
50 (nfp :scs (descriptor-reg))
51 (nsp :scs (descriptor-reg)))
54 (store-symbol-value catch *current-catch-block*)
55 (let ((cur-nfp (current-nfp-tn vop)))
60 (define-vop (current-stack-pointer)
61 (:results (res :scs (any-reg descriptor-reg)))
65 (define-vop (current-binding-pointer)
66 (:results (res :scs (any-reg descriptor-reg)))
71 ;;;; unwind block hackery:
73 ;;; Compute the address of the catch block from its TN, then store
74 ;;; into the block the current Fp, Env, Unwind-Protect, and the entry
76 (define-vop (make-unwind-block)
79 (:results (block :scs (any-reg)))
80 (:temporary (:scs (descriptor-reg)) temp)
81 (:temporary (:scs (non-descriptor-reg)) ndescr)
83 (inst add block cfp-tn (* (tn-offset tn) n-word-bytes))
84 (load-symbol-value temp *current-unwind-protect-block*)
85 (storew temp block unwind-block-current-uwp-slot)
86 (storew cfp-tn block unwind-block-current-cont-slot)
87 (storew code-tn block unwind-block-current-code-slot)
88 (inst compute-lra-from-code temp code-tn entry-label ndescr)
89 (storew temp block catch-block-entry-pc-slot)))
92 ;;; Like Make-Unwind-Block, except that we also store in the specified tag, and
93 ;;; link the block into the Current-Catch list.
94 (define-vop (make-catch-block)
96 (tag :scs (any-reg descriptor-reg)))
98 (:results (block :scs (any-reg)))
99 (:temporary (:scs (descriptor-reg)) temp)
100 (:temporary (:scs (descriptor-reg) :target block :to (:result 0)) result)
101 (:temporary (:scs (non-descriptor-reg)) ndescr)
103 (inst add result cfp-tn (* (tn-offset tn) n-word-bytes))
104 (load-symbol-value temp *current-unwind-protect-block*)
105 (storew temp result catch-block-current-uwp-slot)
106 (storew cfp-tn result catch-block-current-cont-slot)
107 (storew code-tn result catch-block-current-code-slot)
108 (inst compute-lra-from-code temp code-tn entry-label ndescr)
109 (storew temp result catch-block-entry-pc-slot)
111 (storew tag result catch-block-tag-slot)
112 (load-symbol-value temp *current-catch-block*)
113 (storew temp result catch-block-previous-catch-slot)
114 (store-symbol-value result *current-catch-block*)
116 (move block result)))
119 ;;; Just set the current unwind-protect to TN's address. This instantiates an
120 ;;; unwind block as an unwind-protect.
121 (define-vop (set-unwind-protect)
123 (:temporary (:scs (descriptor-reg)) new-uwp)
125 (inst add new-uwp cfp-tn (* (tn-offset tn) n-word-bytes))
126 (store-symbol-value new-uwp *current-unwind-protect-block*)))
129 (define-vop (unlink-catch-block)
130 (:temporary (:scs (any-reg)) block)
132 (:translate %catch-breakup)
134 (load-symbol-value block *current-catch-block*)
135 (loadw block block catch-block-previous-catch-slot)
136 (store-symbol-value block *current-catch-block*)))
138 (define-vop (unlink-unwind-protect)
139 (:temporary (:scs (any-reg)) block)
141 (:translate %unwind-protect-breakup)
143 (load-symbol-value block *current-unwind-protect-block*)
144 (loadw block block unwind-block-current-uwp-slot)
145 (store-symbol-value block *current-unwind-protect-block*)))
151 (define-vop (nlx-entry)
152 (:args (sp) ; Note: we can't list an sc-restriction, 'cause any load vops
153 ; would be inserted before the LRA.
156 (:results (values :more t))
157 (:temporary (:scs (descriptor-reg)) move-temp)
159 (:save-p :force-to-stack)
162 (emit-return-pc label)
163 (note-this-location vop :non-local-entry)
164 (cond ((zerop nvals))
166 (let ((no-values (gen-label)))
168 (inst b :eq no-values)
169 (move (tn-ref-tn values) null-tn)
170 (loadw (tn-ref-tn values) start)
171 (emit-label no-values)))
173 (collect ((defaults))
174 (inst subcc count (fixnumize 1))
176 (tn-ref values (tn-ref-across tn-ref)))
178 (let ((default-lab (gen-label))
179 (tn (tn-ref-tn tn-ref)))
180 (defaults (cons default-lab tn))
182 (inst b :lt default-lab)
183 (inst subcc count (fixnumize 1))
185 ((descriptor-reg any-reg)
188 (loadw move-temp start i)
189 (store-stack-tn tn move-temp)))))
191 (let ((defaulting-done (gen-label)))
193 (emit-label defaulting-done)
195 (assemble (*elsewhere*)
196 (dolist (def (defaults))
197 (emit-label (car def))
198 (let ((tn (cdr def)))
200 ((descriptor-reg any-reg)
203 (store-stack-tn tn null-tn)))))
204 (inst b defaulting-done)
206 (load-stack-tn csp-tn sp)))
209 (define-vop (nlx-entry-multiple)
210 (:args (top :target result) (src) (count))
211 ;; Again, no SC restrictions for the args, 'cause the loading would
212 ;; happen before the entry label.
214 (:temporary (:scs (any-reg)) dst)
215 (:temporary (:scs (descriptor-reg)) temp)
216 (:results (result :scs (any-reg) :from (:argument 0))
217 (num :scs (any-reg) :from (:argument 0)))
218 (:save-p :force-to-stack)
221 (emit-return-pc label)
222 (note-this-location vop :non-local-entry)
223 (let ((loop (gen-label))
226 ;; Setup results, and test for the zero value case.
227 (load-stack-tn result top)
232 ;; Compute dst as one slot down from result, because we inc the index
234 (inst sub dst result 4)
236 ;; Copy stuff down the stack.
238 (inst ld temp src num)
239 (inst add num (fixnumize 1))
242 (inst st temp dst num)
246 (inst add csp-tn result num))))
249 ;;; This VOP is just to force the TNs used in the cleanup onto the stack.
251 (define-vop (uwp-entry)
253 (:save-p :force-to-stack)
254 (:results (block) (start) (count))
255 (:ignore block start count)
258 (emit-return-pc label)
259 (note-this-location vop :non-local-entry)))