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
11 (!def-vm-support-routine make-nlx-entry-arg-start-location ()
12 (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
25 ;;; Return a list of TNs that can be used to snapshot the dynamic state for
26 ;;; use with the Save/Restore-DYNAMIC-ENVIRONMENT VOPs.
27 (!def-vm-support-routine make-dynamic-state-tns ()
28 (make-n-tns 4 *backend-t-primitive-type*))
30 (define-vop (save-dynamic-state)
31 (:results (catch :scs (descriptor-reg))
32 (nfp :scs (descriptor-reg))
33 (nsp :scs (descriptor-reg)))
36 (load-symbol-value catch *current-catch-block*)
37 (let ((cur-nfp (current-nfp-tn vop)))
42 (define-vop (restore-dynamic-state)
43 (:args (catch :scs (descriptor-reg))
44 (nfp :scs (descriptor-reg))
45 (nsp :scs (descriptor-reg)))
48 (store-symbol-value catch *current-catch-block*)
49 (let ((cur-nfp (current-nfp-tn vop)))
54 (define-vop (current-stack-pointer)
55 (:results (res :scs (any-reg descriptor-reg)))
59 (define-vop (current-binding-pointer)
60 (:results (res :scs (any-reg descriptor-reg)))
65 ;;;; Unwind block hackery:
67 ;;; Compute the address of the catch block from its TN, then store into the
68 ;;; block the current Fp, Env, Unwind-Protect, and the entry PC.
70 (define-vop (make-unwind-block)
73 (:results (block :scs (any-reg)))
74 (:temporary (:scs (descriptor-reg)) temp)
75 (:temporary (:scs (non-descriptor-reg)) ndescr)
77 (inst addi (* (tn-offset tn) n-word-bytes) cfp-tn block)
78 (load-symbol-value temp *current-unwind-protect-block*)
79 (storew temp block unwind-block-current-uwp-slot)
80 (storew cfp-tn block unwind-block-current-cont-slot)
81 (storew code-tn block unwind-block-current-code-slot)
82 (inst compute-lra-from-code code-tn entry-label ndescr temp)
83 (storew temp block catch-block-entry-pc-slot)))
85 ;;; Like Make-Unwind-Block, except that we also store in the specified tag, and
86 ;;; link the block into the Current-Catch list.
88 (define-vop (make-catch-block)
90 (tag :scs (any-reg descriptor-reg)))
92 (:results (block :scs (any-reg) :from (:argument 0)))
93 (:temporary (:scs (descriptor-reg)) temp)
94 (:temporary (:scs (non-descriptor-reg)) ndescr)
96 (inst addi (* (tn-offset tn) n-word-bytes) cfp-tn block)
97 (load-symbol-value temp *current-unwind-protect-block*)
98 (storew temp block catch-block-current-uwp-slot)
99 (storew cfp-tn block catch-block-current-cont-slot)
100 (storew code-tn block catch-block-current-code-slot)
101 (inst compute-lra-from-code code-tn entry-label ndescr temp)
102 (storew temp block catch-block-entry-pc-slot)
104 (storew tag block catch-block-tag-slot)
105 (load-symbol-value temp *current-catch-block*)
106 (storew temp block catch-block-previous-catch-slot)
107 (store-symbol-value block *current-catch-block*)))
110 ;;; Just set the current unwind-protect to TN's address. This instantiates an
111 ;;; unwind block as an unwind-protect.
113 (define-vop (set-unwind-protect)
115 (:temporary (:scs (descriptor-reg)) new-uwp)
117 (inst addi (* (tn-offset tn) n-word-bytes) cfp-tn new-uwp)
118 (store-symbol-value new-uwp *current-unwind-protect-block*)))
121 (define-vop (unlink-catch-block)
122 (:temporary (:scs (any-reg)) block)
124 (:translate %catch-breakup)
126 (load-symbol-value block *current-catch-block*)
127 (loadw block block catch-block-previous-catch-slot)
128 (store-symbol-value block *current-catch-block*)))
130 (define-vop (unlink-unwind-protect)
131 (:temporary (:scs (any-reg)) block)
133 (:translate %unwind-protect-breakup)
135 (load-symbol-value block *current-unwind-protect-block*)
136 (loadw block block unwind-block-current-uwp-slot)
137 (store-symbol-value block *current-unwind-protect-block*)))
143 (define-vop (nlx-entry)
144 (:args (sp) ; Note: we can't list an sc-restriction, 'cause any load vops
145 ; would be inserted before the LRA.
148 (:results (values :more t))
149 (:temporary (:scs (descriptor-reg)) move-temp)
151 (:save-p :force-to-stack)
154 (emit-return-pc label)
155 (note-this-location vop :non-local-entry)
156 (cond ((zerop nvals))
158 (inst comclr count zero-tn zero-tn :<>)
159 (inst move null-tn (tn-ref-tn values) :tr)
160 (loadw (tn-ref-tn values) start))
162 (collect ((defaults))
164 (tn-ref values (tn-ref-across tn-ref)))
166 (let ((default-lab (gen-label))
167 (tn (tn-ref-tn tn-ref)))
168 (defaults (cons default-lab tn))
170 (inst bci := nil (fixnumize i) count default-lab)
172 ((descriptor-reg any-reg)
175 (loadw move-temp start i)
176 (store-stack-tn tn move-temp)))))
178 (let ((defaulting-done (gen-label)))
179 (emit-label defaulting-done)
181 (assemble (*elsewhere*)
182 (do ((defs (defaults) (cdr defs)))
184 (let ((def (car defs)))
185 (emit-label (car def))
187 (inst b defaulting-done))
188 (let ((tn (cdr def)))
190 ((descriptor-reg any-reg)
193 (store-stack-tn tn null-tn)))))))))))
194 (load-stack-tn csp-tn sp)))
197 (define-vop (nlx-entry-multiple)
198 (:args (top :target dst) (start :target src) (count :target num))
199 ;; Again, no SC restrictions for the args, 'cause the loading would
200 ;; happen before the entry label.
202 (:temporary (:scs (any-reg) :from (:argument 0)) dst)
203 (:temporary (:scs (any-reg) :from (:argument 1)) src)
204 (:temporary (:scs (any-reg) :from (:argument 2)) num)
205 (:temporary (:scs (descriptor-reg)) temp)
206 (:results (new-start) (new-count))
207 (:save-p :force-to-stack)
210 (emit-return-pc label)
211 (note-this-location vop :non-local-entry)
214 (load-stack-tn dst top)
218 ;; Establish results.
220 (any-reg (move dst new-start))
221 (control-stack (store-stack-tn new-start dst)))
222 (inst comb := num zero-tn done)
224 (any-reg (inst move num new-count))
225 (control-stack (store-stack-tn new-count num)))
226 ;; Load the first word.
227 (inst ldwm n-word-bytes src temp)
229 ;; Copy stuff on stack.
231 (inst stwm temp n-word-bytes dst)
232 (inst addib :<> (fixnumize -1) num loop :nullify t)
233 (inst ldwm n-word-bytes src temp)
236 (inst move dst csp-tn)))
239 ;;; This VOP is just to force the TNs used in the cleanup onto the stack.
241 (define-vop (uwp-entry)
243 (:save-p :force-to-stack)
244 (:results (block) (start) (count))
245 (:ignore block start count)
248 (emit-return-pc label)
249 (note-this-location vop :non-local-entry)))