3 ;;; MAKE-NLX-SP-TN -- Interface
5 ;;; Make an environment-live stack TN for saving the SP for NLX entry.
7 (!def-vm-support-routine make-nlx-sp-tn (env)
9 (make-representation-tn *fixnum-primitive-type* immediate-arg-scn)
12 ;;; Make-NLX-Entry-Argument-Start-Location -- Interface
14 ;;; Make a TN for the argument count passing location for a
17 (!def-vm-support-routine make-nlx-entry-arg-start-location ()
18 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn ocfp-offset))
21 ;;; Save and restore dynamic environment.
23 ;;; These VOPs are used in the reentered function to restore the appropriate
24 ;;; dynamic environment. Currently we only save the Current-Catch and binding
25 ;;; stack pointer. We don't need to save/restore the current unwind-protect,
26 ;;; since unwind-protects are implicitly processed during unwinding. If there
27 ;;; were any additional stacks, then this would be the place to restore the top
31 ;;; Make-Dynamic-State-TNs -- Interface
33 ;;; Return a list of TNs that can be used to snapshot the dynamic state for
34 ;;; use with the Save/Restore-Dynamic-Environment VOPs.
36 (!def-vm-support-routine make-dynamic-state-tns ()
37 (make-n-tns 4 *backend-t-primitive-type*))
39 (define-vop (save-dynamic-state)
40 (:results (catch :scs (descriptor-reg))
41 (nfp :scs (descriptor-reg))
42 (nsp :scs (descriptor-reg)))
45 (load-symbol-value catch *current-catch-block*)
46 (let ((cur-nfp (current-nfp-tn vop)))
51 (define-vop (restore-dynamic-state)
52 (:args (catch :scs (descriptor-reg))
53 (nfp :scs (descriptor-reg))
54 (nsp :scs (descriptor-reg)))
57 (store-symbol-value catch *current-catch-block*)
58 (let ((cur-nfp (current-nfp-tn vop)))
63 (define-vop (current-stack-pointer)
64 (:results (res :scs (any-reg descriptor-reg)))
68 (define-vop (current-binding-pointer)
69 (:results (res :scs (any-reg descriptor-reg)))
75 ;;;; Unwind block hackery:
77 ;;; Compute the address of the catch block from its TN, then store into the
78 ;;; block the current Fp, Env, Unwind-Protect, and the entry PC.
80 (define-vop (make-unwind-block)
83 (:results (block :scs (any-reg)))
84 (:temporary (:scs (descriptor-reg)) temp)
85 (:temporary (:scs (non-descriptor-reg)) ndescr)
87 (inst addu block cfp-tn (* (tn-offset tn) n-word-bytes))
88 (load-symbol-value temp *current-unwind-protect-block*)
89 (storew temp block unwind-block-current-uwp-slot)
90 (storew cfp-tn block unwind-block-current-cont-slot)
91 (storew code-tn block unwind-block-current-code-slot)
92 (inst compute-lra-from-code temp code-tn entry-label ndescr)
93 (storew temp block catch-block-entry-pc-slot)))
96 ;;; Like Make-Unwind-Block, except that we also store in the specified tag, and
97 ;;; link the block into the Current-Catch list.
99 (define-vop (make-catch-block)
101 (tag :scs (any-reg descriptor-reg)))
103 (:results (block :scs (any-reg)))
104 (:temporary (:scs (descriptor-reg)) temp)
105 (:temporary (:scs (descriptor-reg) :target block :to (:result 0)) result)
106 (:temporary (:scs (non-descriptor-reg)) ndescr)
108 (inst addu result cfp-tn (* (tn-offset tn) n-word-bytes))
109 (load-symbol-value temp *current-unwind-protect-block*)
110 (storew temp result catch-block-current-uwp-slot)
111 (storew cfp-tn result catch-block-current-cont-slot)
112 (storew code-tn result catch-block-current-code-slot)
113 (inst compute-lra-from-code temp code-tn entry-label ndescr)
114 (storew temp result catch-block-entry-pc-slot)
116 (storew tag result catch-block-tag-slot)
117 (load-symbol-value temp *current-catch-block*)
118 (storew temp result catch-block-previous-catch-slot)
119 (store-symbol-value result *current-catch-block*)
121 (move block result)))
124 ;;; Just set the current unwind-protect to TN's address. This instantiates an
125 ;;; unwind block as an unwind-protect.
127 (define-vop (set-unwind-protect)
129 (:temporary (:scs (descriptor-reg)) new-uwp)
131 (inst addu new-uwp cfp-tn (* (tn-offset tn) n-word-bytes))
132 (store-symbol-value new-uwp *current-unwind-protect-block*)))
135 (define-vop (unlink-catch-block)
136 (:temporary (:scs (any-reg)) block)
138 (:translate %catch-breakup)
140 (load-symbol-value block *current-catch-block*)
141 (loadw block block catch-block-previous-catch-slot)
142 (store-symbol-value block *current-catch-block*)))
144 (define-vop (unlink-unwind-protect)
145 (:temporary (:scs (any-reg)) block)
147 (:translate %unwind-protect-breakup)
149 (load-symbol-value block *current-unwind-protect-block*)
150 (loadw block block unwind-block-current-uwp-slot)
151 (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)
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 (inst beq count zero-tn no-values)
174 (move (tn-ref-tn values) null-tn)
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 beq count zero-tn default-lab)
187 (inst addu count count (fixnumize -1))
189 ((descriptor-reg any-reg)
192 (loadw move-temp start i)
193 (store-stack-tn tn move-temp)))))
195 (let ((defaulting-done (gen-label)))
197 (emit-label defaulting-done)
199 (assemble (*elsewhere*)
200 (dolist (def (defaults))
201 (emit-label (car def))
202 (let ((tn (cdr def)))
204 ((descriptor-reg any-reg)
207 (store-stack-tn tn null-tn)))))
208 (inst b defaulting-done)
210 (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 new-start dst))
239 (control-stack (store-stack-tn new-start dst)))
240 (inst beq num zero-tn done)
242 (any-reg (inst move new-count num))
243 (control-stack (store-stack-tn new-count num)))
245 ;; Copy stuff on stack.
248 (inst addu src src n-word-bytes)
250 (inst addu num num (fixnumize -1))
251 (inst bne num zero-tn loop)
252 (inst addu dst dst n-word-bytes)
255 (inst move csp-tn dst))))
258 ;;; This VOP is just to force the TNs used in the cleanup onto the stack.
260 (define-vop (uwp-entry)
262 (:save-p :force-to-stack)
263 (:results (block) (start) (count))
264 (:ignore block start count)
267 (emit-return-pc label)
268 (note-this-location vop :non-local-entry)))