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
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)))
59 ;;;; Unwind block hackery:
61 ;;; Compute the address of the catch block from its TN, then store into the
62 ;;; block the current Fp, Env, Unwind-Protect, and the entry PC.
64 (define-vop (make-unwind-block)
67 (:results (block :scs (any-reg)))
68 (:temporary (:scs (descriptor-reg)) temp)
69 (:temporary (:scs (non-descriptor-reg)) ndescr)
71 (inst addi (* (tn-offset tn) n-word-bytes) cfp-tn block)
72 (load-symbol-value temp *current-unwind-protect-block*)
73 (storew temp block unwind-block-current-uwp-slot)
74 (storew cfp-tn block unwind-block-current-cont-slot)
75 (storew code-tn block unwind-block-current-code-slot)
76 (inst compute-lra-from-code code-tn entry-label ndescr temp)
77 (storew temp block catch-block-entry-pc-slot)))
79 ;;; Like Make-Unwind-Block, except that we also store in the specified tag, and
80 ;;; link the block into the Current-Catch list.
82 (define-vop (make-catch-block)
84 (tag :scs (any-reg descriptor-reg)))
86 (:results (block :scs (any-reg) :from (:argument 0)))
87 (:temporary (:scs (descriptor-reg)) temp)
88 (:temporary (:scs (non-descriptor-reg)) ndescr)
90 (inst addi (* (tn-offset tn) n-word-bytes) cfp-tn block)
91 (load-symbol-value temp *current-unwind-protect-block*)
92 (storew temp block catch-block-current-uwp-slot)
93 (storew cfp-tn block catch-block-current-cont-slot)
94 (storew code-tn block catch-block-current-code-slot)
95 (inst compute-lra-from-code code-tn entry-label ndescr temp)
96 (storew temp block catch-block-entry-pc-slot)
98 (storew tag block catch-block-tag-slot)
99 (load-symbol-value temp *current-catch-block*)
100 (storew temp block catch-block-previous-catch-slot)
101 (store-symbol-value block *current-catch-block*)))
104 ;;; Just set the current unwind-protect to TN's address. This instantiates an
105 ;;; unwind block as an unwind-protect.
107 (define-vop (set-unwind-protect)
109 (:temporary (:scs (descriptor-reg)) new-uwp)
111 (inst addi (* (tn-offset tn) n-word-bytes) cfp-tn new-uwp)
112 (store-symbol-value new-uwp *current-unwind-protect-block*)))
115 (define-vop (unlink-catch-block)
116 (:temporary (:scs (any-reg)) block)
118 (:translate %catch-breakup)
120 (load-symbol-value block *current-catch-block*)
121 (loadw block block catch-block-previous-catch-slot)
122 (store-symbol-value block *current-catch-block*)))
124 (define-vop (unlink-unwind-protect)
125 (:temporary (:scs (any-reg)) block)
127 (:translate %unwind-protect-breakup)
129 (load-symbol-value block *current-unwind-protect-block*)
130 (loadw block block unwind-block-current-uwp-slot)
131 (store-symbol-value block *current-unwind-protect-block*)))
137 (define-vop (nlx-entry)
138 (:args (sp) ; Note: we can't list an sc-restriction, 'cause any load vops
139 ; would be inserted before the LRA.
142 (:results (values :more t))
143 (:temporary (:scs (descriptor-reg)) move-temp)
145 (:save-p :force-to-stack)
148 (emit-return-pc label)
149 (note-this-location vop :non-local-entry)
150 (cond ((zerop nvals))
152 (inst comclr count zero-tn zero-tn :<>)
153 (inst move null-tn (tn-ref-tn values) :tr)
154 (loadw (tn-ref-tn values) start))
156 (collect ((defaults))
158 (tn-ref values (tn-ref-across tn-ref)))
160 (let ((default-lab (gen-label))
161 (tn (tn-ref-tn tn-ref)))
162 (defaults (cons default-lab tn))
164 (inst bci := nil (fixnumize i) count default-lab)
166 ((descriptor-reg any-reg)
169 (loadw move-temp start i)
170 (store-stack-tn tn move-temp)))))
172 (let ((defaulting-done (gen-label)))
173 (emit-label defaulting-done)
175 (assemble (*elsewhere*)
176 (do ((defs (defaults) (cdr defs)))
178 (let ((def (car defs)))
179 (emit-label (car def))
181 (inst b defaulting-done))
182 (let ((tn (cdr def)))
184 ((descriptor-reg any-reg)
187 (store-stack-tn tn null-tn)))))))))))
188 (load-stack-tn csp-tn sp)))
191 (define-vop (nlx-entry-multiple)
192 (:args (top :target dst) (start :target src) (count :target num))
193 ;; Again, no SC restrictions for the args, 'cause the loading would
194 ;; happen before the entry label.
196 (:temporary (:scs (any-reg) :from (:argument 0)) dst)
197 (:temporary (:scs (any-reg) :from (:argument 1)) src)
198 (:temporary (:scs (any-reg) :from (:argument 2)) num)
199 (:temporary (:scs (descriptor-reg)) temp)
200 (:results (new-start) (new-count))
201 (:save-p :force-to-stack)
204 (emit-return-pc label)
205 (note-this-location vop :non-local-entry)
208 (load-stack-tn dst top)
212 ;; Establish results.
214 (any-reg (move dst new-start))
215 (control-stack (store-stack-tn new-start dst)))
216 (inst comb := num zero-tn done)
218 (any-reg (inst move num new-count))
219 (control-stack (store-stack-tn new-count num)))
220 ;; Load the first word.
221 (inst ldwm n-word-bytes src temp)
223 ;; Copy stuff on stack.
225 (inst stwm temp n-word-bytes dst)
226 (inst addib :<> (fixnumize -1) num loop :nullify t)
227 (inst ldwm n-word-bytes src temp)
230 (inst move dst csp-tn)))
233 ;;; This VOP is just to force the TNs used in the cleanup onto the stack.
235 (define-vop (uwp-entry)
237 (:save-p :force-to-stack)
238 (:results (block) (start) (count))
239 (:ignore block start count)
242 (emit-return-pc label)
243 (note-this-location vop :non-local-entry)))