3 ;;; Make an environment-live stack TN for saving the SP for NLX entry.
4 (!def-vm-support-routine make-nlx-sp-tn (env)
6 (make-representation-tn *fixnum-primitive-type* immediate-arg-scn)
9 ;;; Make a TN for the argument count passing location for a
12 (!def-vm-support-routine make-nlx-entry-arg-start-location ()
13 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn ocfp-offset))
16 ;;; Save and restore dynamic environment.
18 ;;; These VOPs are used in the reentered function to restore the appropriate
19 ;;; dynamic environment. Currently we only save the Current-Catch and binding
20 ;;; stack pointer. We don't need to save/restore the current unwind-protect,
21 ;;; since unwind-protects are implicitly processed during unwinding. If there
22 ;;; were any additional stacks, then this would be the place to restore the top
26 ;;; Return a list of TNs that can be used to snapshot the dynamic state for
27 ;;; use with the Save/Restore-DYNAMIC-ENVIRONMENT VOPs.
28 (!def-vm-support-routine make-dynamic-state-tns ()
29 (make-n-tns 4 *backend-t-primitive-type*))
31 (define-vop (save-dynamic-state)
32 (:results (catch :scs (descriptor-reg))
33 (nfp :scs (descriptor-reg))
34 (nsp :scs (descriptor-reg)))
37 (load-symbol-value catch *current-catch-block*)
38 (let ((cur-nfp (current-nfp-tn vop)))
43 (define-vop (restore-dynamic-state)
44 (:args (catch :scs (descriptor-reg))
45 (nfp :scs (descriptor-reg))
46 (nsp :scs (descriptor-reg)))
49 (store-symbol-value catch *current-catch-block*)
50 (let ((cur-nfp (current-nfp-tn vop)))
55 (define-vop (current-stack-pointer)
56 (:results (res :scs (any-reg descriptor-reg)))
60 (define-vop (current-binding-pointer)
61 (:results (res :scs (any-reg descriptor-reg)))
67 ;;;; Unwind block hackery:
69 ;;; Compute the address of the catch block from its TN, then store into the
70 ;;; block the current Fp, Env, Unwind-Protect, and the entry PC.
72 (define-vop (make-unwind-block)
75 (:results (block :scs (any-reg)))
76 (:temporary (:scs (descriptor-reg)) temp)
77 (:temporary (:scs (non-descriptor-reg)) ndescr)
79 (inst addu block cfp-tn (* (tn-offset tn) n-word-bytes))
80 (load-symbol-value temp *current-unwind-protect-block*)
81 (storew temp block unwind-block-current-uwp-slot)
82 (storew cfp-tn block unwind-block-current-cont-slot)
83 (storew code-tn block unwind-block-current-code-slot)
84 (inst compute-lra-from-code temp code-tn entry-label ndescr)
85 (storew temp block catch-block-entry-pc-slot)))
88 ;;; Like Make-Unwind-Block, except that we also store in the specified tag, and
89 ;;; link the block into the Current-Catch list.
91 (define-vop (make-catch-block)
93 (tag :scs (any-reg descriptor-reg)))
95 (:results (block :scs (any-reg)))
96 (:temporary (:scs (descriptor-reg)) temp)
97 (:temporary (:scs (descriptor-reg) :target block :to (:result 0)) result)
98 (:temporary (:scs (non-descriptor-reg)) ndescr)
100 (inst addu result cfp-tn (* (tn-offset tn) n-word-bytes))
101 (load-symbol-value temp *current-unwind-protect-block*)
102 (storew temp result catch-block-current-uwp-slot)
103 (storew cfp-tn result catch-block-current-cont-slot)
104 (storew code-tn result catch-block-current-code-slot)
105 (inst compute-lra-from-code temp code-tn entry-label ndescr)
106 (storew temp result catch-block-entry-pc-slot)
108 (storew tag result catch-block-tag-slot)
109 (load-symbol-value temp *current-catch-block*)
110 (storew temp result catch-block-previous-catch-slot)
111 (store-symbol-value result *current-catch-block*)
113 (move block result)))
116 ;;; Just set the current unwind-protect to TN's address. This instantiates an
117 ;;; unwind block as an unwind-protect.
119 (define-vop (set-unwind-protect)
121 (:temporary (:scs (descriptor-reg)) new-uwp)
123 (inst addu new-uwp cfp-tn (* (tn-offset tn) n-word-bytes))
124 (store-symbol-value new-uwp *current-unwind-protect-block*)))
127 (define-vop (unlink-catch-block)
128 (:temporary (:scs (any-reg)) block)
130 (:translate %catch-breakup)
132 (load-symbol-value block *current-catch-block*)
133 (loadw block block catch-block-previous-catch-slot)
134 (store-symbol-value block *current-catch-block*)))
136 (define-vop (unlink-unwind-protect)
137 (:temporary (:scs (any-reg)) block)
139 (:translate %unwind-protect-breakup)
141 (load-symbol-value block *current-unwind-protect-block*)
142 (loadw block block unwind-block-current-uwp-slot)
143 (store-symbol-value block *current-unwind-protect-block*)))
149 (define-vop (nlx-entry)
150 (:args (sp) ; Note: we can't list an sc-restriction, 'cause any load vops
151 ; would be inserted before the LRA.
154 (:results (values :more t))
155 (:temporary (:scs (descriptor-reg)) move-temp)
157 (:save-p :force-to-stack)
160 (emit-return-pc label)
161 (note-this-location vop :non-local-entry)
162 (cond ((zerop nvals))
164 (let ((no-values (gen-label)))
165 (inst beq count zero-tn no-values)
166 (move (tn-ref-tn values) null-tn)
167 (loadw (tn-ref-tn values) start)
168 (emit-label no-values)))
170 (collect ((defaults))
172 (tn-ref values (tn-ref-across tn-ref)))
174 (let ((default-lab (gen-label))
175 (tn (tn-ref-tn tn-ref)))
176 (defaults (cons default-lab tn))
178 (inst beq count zero-tn default-lab)
179 (inst addu count count (fixnumize -1))
181 ((descriptor-reg any-reg)
184 (loadw move-temp start i)
185 (store-stack-tn tn move-temp)))))
187 (let ((defaulting-done (gen-label)))
189 (emit-label defaulting-done)
191 (assemble (*elsewhere*)
192 (dolist (def (defaults))
193 (emit-label (car def))
194 (let ((tn (cdr def)))
196 ((descriptor-reg any-reg)
199 (store-stack-tn tn null-tn)))))
200 (inst b defaulting-done)
202 (load-stack-tn csp-tn sp)))
205 (define-vop (nlx-entry-multiple)
206 (:args (top :target dst) (start :target src) (count :target num))
207 ;; Again, no SC restrictions for the args, 'cause the loading would
208 ;; happen before the entry label.
210 (:temporary (:scs (any-reg) :from (:argument 0)) dst)
211 (:temporary (:scs (any-reg) :from (:argument 1)) src)
212 (:temporary (:scs (any-reg) :from (:argument 2)) num)
213 (:temporary (:scs (descriptor-reg)) temp)
214 (:results (new-start) (new-count))
215 (:save-p :force-to-stack)
218 (emit-return-pc label)
219 (note-this-location vop :non-local-entry)
220 (let ((loop (gen-label))
224 (load-stack-tn dst top)
228 ;; Establish results.
230 (any-reg (move new-start dst))
231 (control-stack (store-stack-tn new-start dst)))
232 (inst beq num zero-tn done)
234 (any-reg (inst move new-count num))
235 (control-stack (store-stack-tn new-count num)))
237 ;; Copy stuff on stack.
240 (inst addu src src n-word-bytes)
242 (inst addu num num (fixnumize -1))
243 (inst bne num zero-tn loop)
244 (inst addu dst dst n-word-bytes)
247 (inst move csp-tn dst))))
250 ;;; This VOP is just to force the TNs used in the cleanup onto the stack.
252 (define-vop (uwp-entry)
254 (:save-p :force-to-stack)
255 (:results (block) (start) (count))
256 (:ignore block start count)
259 (emit-return-pc label)
260 (note-this-location vop :non-local-entry)))