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))
15 ;;; Save and restore dynamic environment.
17 ;;; These VOPs are used in the reentered function to restore the appropriate
18 ;;; dynamic environment. Currently we only save the Current-Catch and binding
19 ;;; stack pointer. We don't need to save/restore the current unwind-protect,
20 ;;; since unwind-protects are implicitly processed during unwinding. If there
21 ;;; were any additional stacks, then this would be the place to restore the top
24 (define-vop (save-dynamic-state)
25 (:results (catch :scs (descriptor-reg))
26 (nfp :scs (descriptor-reg))
27 (nsp :scs (descriptor-reg)))
30 (load-symbol-value catch *current-catch-block*)
31 (let ((cur-nfp (current-nfp-tn vop)))
36 (define-vop (restore-dynamic-state)
37 (:args (catch :scs (descriptor-reg))
38 (nfp :scs (descriptor-reg))
39 (nsp :scs (descriptor-reg)))
42 (store-symbol-value catch *current-catch-block*)
43 (let ((cur-nfp (current-nfp-tn vop)))
48 (define-vop (current-stack-pointer)
49 (:results (res :scs (any-reg descriptor-reg)))
53 (define-vop (current-binding-pointer)
54 (:results (res :scs (any-reg descriptor-reg)))
60 ;;;; Unwind block hackery:
62 ;;; Compute the address of the catch block from its TN, then store into the
63 ;;; block the current Fp, Env, Unwind-Protect, and the entry PC.
65 (define-vop (make-unwind-block)
68 (:results (block :scs (any-reg)))
69 (:temporary (:scs (descriptor-reg)) temp)
70 (:temporary (:scs (non-descriptor-reg)) ndescr)
72 (inst addu block cfp-tn (* (tn-offset tn) n-word-bytes))
73 (load-symbol-value temp *current-unwind-protect-block*)
74 (storew temp block unwind-block-current-uwp-slot)
75 (storew cfp-tn block unwind-block-current-cont-slot)
76 (storew code-tn block unwind-block-current-code-slot)
77 (inst compute-lra-from-code temp code-tn entry-label ndescr)
78 (storew temp block catch-block-entry-pc-slot)))
81 ;;; Like Make-Unwind-Block, except that we also store in the specified tag, and
82 ;;; link the block into the Current-Catch list.
84 (define-vop (make-catch-block)
86 (tag :scs (any-reg descriptor-reg)))
88 (:results (block :scs (any-reg)))
89 (:temporary (:scs (descriptor-reg)) temp)
90 (:temporary (:scs (descriptor-reg) :target block :to (:result 0)) result)
91 (:temporary (:scs (non-descriptor-reg)) ndescr)
93 (inst addu result cfp-tn (* (tn-offset tn) n-word-bytes))
94 (load-symbol-value temp *current-unwind-protect-block*)
95 (storew temp result catch-block-current-uwp-slot)
96 (storew cfp-tn result catch-block-current-cont-slot)
97 (storew code-tn result catch-block-current-code-slot)
98 (inst compute-lra-from-code temp code-tn entry-label ndescr)
99 (storew temp result catch-block-entry-pc-slot)
101 (storew tag result catch-block-tag-slot)
102 (load-symbol-value temp *current-catch-block*)
103 (storew temp result catch-block-previous-catch-slot)
104 (store-symbol-value result *current-catch-block*)
106 (move block result)))
109 ;;; Just set the current unwind-protect to TN's address. This instantiates an
110 ;;; unwind block as an unwind-protect.
112 (define-vop (set-unwind-protect)
114 (:temporary (:scs (descriptor-reg)) new-uwp)
116 (inst addu new-uwp cfp-tn (* (tn-offset tn) n-word-bytes))
117 (store-symbol-value new-uwp *current-unwind-protect-block*)))
120 (define-vop (unlink-catch-block)
121 (:temporary (:scs (any-reg)) block)
123 (:translate %catch-breakup)
125 (load-symbol-value block *current-catch-block*)
126 (loadw block block catch-block-previous-catch-slot)
127 (store-symbol-value block *current-catch-block*)))
129 (define-vop (unlink-unwind-protect)
130 (:temporary (:scs (any-reg)) block)
132 (:translate %unwind-protect-breakup)
134 (load-symbol-value block *current-unwind-protect-block*)
135 (loadw block block unwind-block-current-uwp-slot)
136 (store-symbol-value block *current-unwind-protect-block*)))
142 (define-vop (nlx-entry)
143 (:args (sp) ; Note: we can't list an sc-restriction, 'cause any load vops
144 ; would be inserted before the LRA.
147 (:results (values :more t))
148 (:temporary (:scs (descriptor-reg)) move-temp)
150 (:save-p :force-to-stack)
153 (emit-return-pc label)
154 (note-this-location vop :non-local-entry)
155 (cond ((zerop nvals))
157 (let ((no-values (gen-label)))
158 (inst beq count zero-tn no-values)
159 (move (tn-ref-tn values) null-tn)
160 (loadw (tn-ref-tn values) start)
161 (emit-label no-values)))
163 (collect ((defaults))
165 (tn-ref values (tn-ref-across tn-ref)))
167 (let ((default-lab (gen-label))
168 (tn (tn-ref-tn tn-ref)))
169 (defaults (cons default-lab tn))
171 (inst beq count zero-tn default-lab)
172 (inst addu count count (fixnumize -1))
174 ((descriptor-reg any-reg)
177 (loadw move-temp start i)
178 (store-stack-tn tn move-temp)))))
180 (let ((defaulting-done (gen-label)))
182 (emit-label defaulting-done)
184 (assemble (*elsewhere*)
185 (dolist (def (defaults))
186 (emit-label (car def))
187 (let ((tn (cdr def)))
189 ((descriptor-reg any-reg)
192 (store-stack-tn tn null-tn)))))
193 (inst b defaulting-done)
195 (load-stack-tn csp-tn sp)))
198 (define-vop (nlx-entry-multiple)
199 (:args (top :target dst) (start :target src) (count :target num))
200 ;; Again, no SC restrictions for the args, 'cause the loading would
201 ;; happen before the entry label.
203 (:temporary (:scs (any-reg) :from (:argument 0)) dst)
204 (:temporary (:scs (any-reg) :from (:argument 1)) src)
205 (:temporary (:scs (any-reg) :from (:argument 2)) num)
206 (:temporary (:scs (descriptor-reg)) temp)
207 (:results (new-start) (new-count))
208 (:save-p :force-to-stack)
211 (emit-return-pc label)
212 (note-this-location vop :non-local-entry)
213 (let ((loop (gen-label))
217 (load-stack-tn dst top)
221 ;; Establish results.
223 (any-reg (move new-start dst))
224 (control-stack (store-stack-tn new-start dst)))
225 (inst beq num zero-tn done)
227 (any-reg (inst move new-count num))
228 (control-stack (store-stack-tn new-count num)))
230 ;; Copy stuff on stack.
233 (inst addu src src n-word-bytes)
235 (inst addu num num (fixnumize -1))
236 (inst bne num zero-tn loop)
237 (inst addu dst dst n-word-bytes)
240 (inst move csp-tn dst))))
243 ;;; This VOP is just to force the TNs used in the cleanup onto the stack.
245 (define-vop (uwp-entry)
247 (:save-p :force-to-stack)
248 (:results (block) (start) (count))
249 (:ignore block start count)
252 (emit-return-pc label)
253 (note-this-location vop :non-local-entry)))