Fix more C warnings
[sbcl.git] / src / compiler / arm64 / call.lisp
blob49725ec8d991bdae597ca147b56fd2fe35659f7d
1 ;;;; the VM definition of function call for the ARM
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
12 (in-package "SB-VM")
14 (defconstant arg-count-sc (make-sc+offset immediate-arg-scn nargs-offset))
15 (defconstant closure-sc (make-sc+offset descriptor-reg-sc-number lexenv-offset))
17 (defconstant return-pc-passing-offset
18 (make-sc+offset control-stack-sc-number lra-save-offset))
20 (defconstant old-fp-passing-offset
21 (make-sc+offset control-stack-sc-number ocfp-save-offset))
23 ;;; Make the TNs used to hold OLD-FP and RETURN-PC within the current
24 ;;; function. We treat these specially so that the debugger can find
25 ;;; them at a known location.
26 (defun make-old-fp-save-location ()
27 ;; Unlike the other backends, ARM function calling is designed to
28 ;; pass OLD-FP within the stack frame rather than in a register. As
29 ;; such, in order for lifetime analysis not to screw up, we need it
30 ;; to be a stack TN wired to the save offset, not a normal TN with a
31 ;; wired SAVE-TN.
32 (let ((tn (make-wired-tn *fixnum-primitive-type*
33 control-stack-arg-scn
34 ocfp-save-offset)))
35 (setf (tn-kind tn) :environment)
36 tn))
37 (defun make-return-pc-save-location ()
38 (let ((tn (make-wired-tn *backend-t-primitive-type* control-stack-sc-number
39 lra-save-offset)))
40 (setf (tn-kind tn) :environment)
41 tn))
43 ;;; Make a TN for the standard argument count passing location. We
44 ;;; only need to make the standard location, since a count is never
45 ;;; passed when we are using non-standard conventions.
46 (defun make-arg-count-location ()
47 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn nargs-offset))
49 ;;;; Frame hackery:
51 ;;; Return the number of bytes needed for the current non-descriptor
52 ;;; stack frame.
53 (defun bytes-needed-for-non-descriptor-stack-frame ()
54 (logandc2 (+ (* (sb-allocated-size 'non-descriptor-stack) n-word-bytes)
55 +number-stack-alignment-mask+)
56 +number-stack-alignment-mask+))
58 ;;; Used for setting up the Old-FP in local call.
59 (define-vop (current-fp)
60 (:results (val :scs (any-reg)))
61 (:generator 1
62 (move val cfp-tn)))
64 ;;; Used for computing the caller's NFP for use in known-values return. Only
65 ;;; works assuming there is no variable size stuff on the nstack.
66 (define-vop (compute-old-nfp)
67 (:results (val :scs (any-reg)))
68 (:vop-var vop)
69 (:generator 1
70 (let ((nfp (current-nfp-tn vop)))
71 (when nfp
72 ;; FIXME-ARM: taken form MIPS is this correct? (phs)
73 (inst add val nfp (bytes-needed-for-non-descriptor-stack-frame))))))
75 ;;; Accessing a slot from an earlier stack frame is definite hackery.
76 (define-vop (ancestor-frame-ref)
77 (:args (frame-pointer :scs (descriptor-reg))
78 (variable-home-tn :load-if nil))
79 (:results (value :scs (descriptor-reg any-reg)))
80 (:policy :fast-safe)
81 (:generator 4
82 (aver (sc-is variable-home-tn control-stack))
83 (load-stack-offset value frame-pointer variable-home-tn)))
85 (define-vop (ancestor-frame-set)
86 (:args (frame-pointer :scs (descriptor-reg))
87 (value :scs (descriptor-reg any-reg)))
88 (:results (variable-home-tn :load-if nil))
89 (:policy :fast-safe)
90 (:generator 4
91 (aver (sc-is variable-home-tn control-stack))
92 (store-stack-offset value frame-pointer variable-home-tn)))
94 (define-vop (xep-allocate-frame)
95 (:temporary (:sc non-descriptor-reg :offset lr-offset) lr)
96 (:info start-lab)
97 (:generator 1
98 ;; Make sure the function is aligned, and drop a label pointing to this
99 ;; function header.
100 (emit-alignment n-lowtag-bits)
101 (emit-label start-lab)
102 ;; Allocate function header.
103 (inst simple-fun-header-word)
104 (inst .skip (* (1- simple-fun-insts-offset) n-word-bytes))
105 (inst str lr (@ cfp-tn (* lra-save-offset n-word-bytes)))))
107 (define-vop (xep-setup-sp)
108 (:vop-var vop)
109 (:generator 1
110 (inst add csp-tn cfp-tn
111 (add-sub-immediate (* n-word-bytes (sb-allocated-size 'control-stack))))
112 (let ((nfp-tn (current-nfp-tn vop)))
113 (when nfp-tn
114 (let ((nbytes (bytes-needed-for-non-descriptor-stack-frame)))
115 (inst sub nfp-tn nsp-tn nbytes)
116 (inst mov-sp nsp-tn nfp-tn))))))
118 (define-vop (allocate-frame)
119 (:results (res :scs (any-reg))
120 (nfp :scs (any-reg)))
121 (:info callee)
122 (:generator 2
123 (move res csp-tn)
124 (let ((size (add-sub-immediate (* (max 1 (sb-allocated-size 'control-stack)) n-word-bytes))))
125 (cond ((typep size '(signed-byte 9))
126 (inst str cfp-tn (@ csp-tn size :post-index)))
128 (inst add csp-tn csp-tn size)
129 (storew cfp-tn res ocfp-save-offset))))
130 (when (ir2-environment-number-stack-p callee)
131 (inst sub nfp nsp-tn (add-sub-immediate
132 (bytes-needed-for-non-descriptor-stack-frame)))
133 (inst mov-sp nsp-tn nfp))))
135 ;;; Allocate a partial frame for passing stack arguments in a full call. Nargs
136 ;;; is the number of arguments passed. If no stack arguments are passed, then
137 ;;; we don't have to do anything.
138 ;;; LR and CFP are always saved on the stack, but it's safe to have two words above CSP.
139 (define-vop (allocate-full-call-frame)
140 (:info nargs)
141 (:results (res :scs (any-reg)))
142 (:generator 2
143 (if (<= nargs register-arg-count)
144 ;; Don't touch RES, the call vops would use CSP-TN in this case.
145 (storew cfp-tn csp-tn ocfp-save-offset)
146 (let ((size (add-sub-immediate (* nargs n-word-bytes))))
147 (move res csp-tn)
148 (cond ((typep size '(signed-byte 9))
149 (inst str cfp-tn (@ csp-tn size :post-index)))
151 (inst add csp-tn csp-tn size)
152 (storew cfp-tn res ocfp-save-offset)))))))
154 ;;; Emit code needed at the return-point from an unknown-values call
155 ;;; for a fixed number of values. VALUES is the head of the TN-REF
156 ;;; list for the locations that the values are to be received into.
157 ;;; NVALS is the number of values that are to be received (should
158 ;;; equal the length of Values).
160 ;;; MOVE-TEMP is a DESCRIPTOR-REG TN used as a temporary.
162 ;;; This code exploits the fact that in the unknown-values convention,
163 ;;; a single value return returns with all of the condition flags
164 ;;; clear, whereas a return of other than one value returns with the
165 ;;; condition flags set.
167 ;;; If 0 or 1 values are expected, then we just emit an instruction to
168 ;;; reset the SP (which will only be executed when other than 1 value
169 ;;; is returned.)
171 ;;; In the general case, we have to do three things:
172 ;;; -- Default unsupplied register values. This need only be done when a
173 ;;; single value is returned, since register values are defaulted by the
174 ;;; callee in the non-single case.
175 ;;; -- Default unsupplied stack values. This needs to be done whenever there
176 ;;; are stack values.
177 ;;; -- Reset SP. This must be done whenever other than 1 value is returned,
178 ;;; regardless of the number of values desired.
180 (defun default-unknown-values (vop values nvals move-temp node)
181 (declare (type (or tn-ref null) values)
182 (type unsigned-byte nvals) (type tn move-temp))
183 (multiple-value-bind (type name leaf) (sb-c::lvar-fun-type (sb-c::basic-combination-fun node))
184 (let* ((verify (and leaf
185 (policy node (and (>= safety 1)
186 (= debug 3)))
187 (memq (sb-c::leaf-where-from leaf) '(:declared-verify :defined-here))))
188 (type (if verify
189 (if (fun-type-p type)
190 (fun-type-returns type)
191 *wild-type*)
192 (sb-c::node-derived-type node)))
193 (min-values (values-type-min-value-count type))
194 (max-values (values-type-max-value-count type))
195 (trust (or (and (= min-values 0)
196 (= max-values call-arguments-limit))
197 (not verify)))
198 (expecting-values-on-stack (> nvals register-arg-count)))
200 (note-this-location vop (if (<= nvals 1)
201 :single-value-return
202 :unknown-return))
203 (flet ((check-nargs ()
204 (assemble ()
205 (let* ((*location-context* (list* name
206 (type-specifier type)
207 (make-restart-location SKIP)))
208 (err-lab (generate-error-code vop 'invalid-arg-count-error))
209 (min min-values)
210 (max (and (< max-values call-arguments-limit)
211 max-values)))
212 (labels ((load-immediate (x)
213 (add-sub-immediate (fixnumize x))))
214 (cond ((eql max 0)
215 (inst cbnz nargs-tn err-lab))
216 ((eql min max)
217 (inst cmp nargs-tn (load-immediate max))
218 (inst b :ne err-lab))
219 (max
220 (let ((nargs tmp-tn))
221 (if (zerop min)
222 (setf nargs nargs-tn)
223 (inst sub tmp-tn nargs-tn (load-immediate min)))
224 (inst cmp nargs (load-immediate (- max min))))
225 (inst b :hi err-lab))
227 (cond ((= min 1)
228 (inst cbz nargs-tn err-lab))
229 ((plusp min)
230 (inst cmp nargs-tn (load-immediate min))
231 (inst b :lo err-lab)))))))
232 SKIP)))
233 ;; Pick off the single-value case first.
234 (assemble ()
235 (sb-assem:without-scheduling ()
237 ;; Default register values for single-value return case.
238 ;; The callee returns with condition bits CLEAR in the
239 ;; single-value case.
240 (when values
241 (do ((i 1 (1+ i))
242 (val (tn-ref-across values) (tn-ref-across val)))
243 ((= i (min nvals register-arg-count)))
244 (unless (eq (tn-kind (tn-ref-tn val)) :unused)
245 (cond
246 ((and trust
247 (> min-values i)))
249 (inst csel (tn-ref-tn val) null-tn (tn-ref-tn val) :ne))))))
251 ;; If we're not expecting values on the stack, all that
252 ;; remains is to clear the stack frame (for the multiple-
253 ;; value return case).
254 (unless (or expecting-values-on-stack
255 (and trust
256 (type-single-value-p type)))
257 (cond ((or (not trust)
258 (values-type-may-be-single-value-p type))
259 (inst csel csp-tn ocfp-tn csp-tn :eq)
260 (unless trust
261 (inst mov tmp-tn (fixnumize 1))
262 (inst csel nargs-tn tmp-tn nargs-tn :ne)
263 (check-nargs)))
264 ((eq type *empty-type*))
266 (inst mov csp-tn ocfp-tn))))
267 (macrolet ((map-stack-values (&body body)
268 `(do ((i register-arg-count (1+ i))
269 (val (do ((i 0 (1+ i))
270 (val values (tn-ref-across val)))
271 ((= i register-arg-count) val))
272 (tn-ref-across val)))
273 ((null val))
274 (let ((tn (tn-ref-tn val)))
275 ,@body))))
276 ;; If we ARE expecting values on the stack, we need to
277 ;; either move them to their result location or to set their
278 ;; result location to the default.
279 (when expecting-values-on-stack
280 (let ((decrement (fixnumize (1+ register-arg-count)))
281 (stack-targets-p (map-stack-values
282 (when (and (>= i min-values)
283 (neq (tn-kind tn) :unused)
284 (sc-is tn control-stack))
285 (return t)))))
286 ;; If all destinations are registers move NIL into all
287 ;; of them before checking for single value return, that
288 ;; way it doesn't need to set up NARGS and OCFP.
289 (unless stack-targets-p
290 (map-stack-values
291 (when (and (>= i min-values)
292 (neq (tn-kind tn) :unused))
293 (inst mov tn null-tn))))
294 (cond ((and trust
295 (> min-values 1)))
296 ((or (not trust)
297 stack-targets-p)
298 (inst csel ocfp-tn csp-tn ocfp-tn :ne)
299 (inst mov tmp-tn (fixnumize 1))
300 (inst csel nargs-tn tmp-tn nargs-tn :ne)
301 (unless trust
302 (check-nargs)))
304 (inst b :ne DONE)))
305 (map-stack-values
306 (cond ((eq (tn-kind tn) :unused)
307 (incf decrement (fixnumize 1)))
308 ((< i min-values)
309 (incf decrement (fixnumize 1))
310 (sc-case tn
311 (control-stack
312 (let* ((next (and (< (1+ i) min-values)
313 (tn-ref-across val)))
314 (next-tn (and next
315 (tn-ref-tn next))))
316 (cond ((and next-tn
317 (not (sc-is next-tn control-stack))
318 (neq (tn-kind next-tn) :unused)
319 (ldp-stp-offset-p (* i n-word-bytes) n-word-bits))
320 (inst ldp move-temp next-tn
321 (@ ocfp-tn (* i n-word-bytes)))
322 (store-stack-tn tn move-temp)
323 (setf val next)
324 (incf i)
325 (incf decrement (fixnumize 1)))
327 (loadw move-temp ocfp-tn i)
328 (store-stack-tn tn move-temp)))))
330 (let* ((next (and (< (1+ i) min-values)
331 (tn-ref-across val)))
332 (next-tn (and next
333 (tn-ref-tn next))))
334 (cond ((and next-tn
335 (neq (tn-kind next-tn) :unused)
336 (ldp-stp-offset-p (* i n-word-bytes) n-word-bits))
337 (let ((stack (sc-is next-tn control-stack)))
338 (inst ldp tn (if stack
339 move-temp
340 next-tn)
341 (@ ocfp-tn (* i n-word-bytes)))
342 (when stack
343 (store-stack-tn next-tn move-temp)))
344 (setf val next)
345 (incf i)
346 (incf decrement (fixnumize 1)))
348 (loadw tn ocfp-tn i)))))))
350 (let ((dst move-temp))
351 (assemble ()
352 ;; ... Load it if there is a stack value available, or
353 ;; default it if there isn't.
354 (inst subs nargs-tn nargs-tn decrement)
355 (setf decrement (fixnumize 1))
356 (unless (sc-is tn control-stack)
357 (setf dst tn))
358 (when stack-targets-p
359 (move dst null-tn))
360 (inst b :lt NONE)
361 (loadw dst ocfp-tn i)
362 NONE
363 (when (sc-is tn control-stack)
364 (store-stack-tn tn dst))))))))
365 ;; Deallocate the callee stack frame.
366 (move csp-tn ocfp-tn))))
367 DONE))))
368 (values))
370 ;;;; Unknown values receiving:
372 ;;; Emit code needed at the return point for an unknown-values call for an
373 ;;; arbitrary number of values.
375 ;;; We do the single and non-single cases with no shared code: there doesn't
376 ;;; seem to be any potential overlap, and receiving a single value is more
377 ;;; important efficiency-wise.
379 ;;; When there is a single value, we just push it on the stack, returning
380 ;;; the old SP and 1.
382 ;;; When there is a variable number of values, we move all of the argument
383 ;;; registers onto the stack, and return Args and Nargs.
385 ;;; Args and Nargs are TNs wired to the named locations. We must
386 ;;; explicitly allocate these TNs, since their lifetimes overlap with the
387 ;;; results Start and Count (also, it's nice to be able to target them).
388 (defun receive-unknown-values (node args nargs start count)
389 (declare (type tn args nargs start count))
390 (let ((unused-count-p (eq (tn-kind count) :unused))
391 (unused-start-p (eq (tn-kind start) :unused))
392 (type (sb-c::node-derived-type node)))
393 (if (type-single-value-p type)
394 (assemble ()
395 (unless unused-start-p
396 (move start csp-tn))
397 (unless unused-count-p
398 (inst mov count (fixnumize 1)))
399 (inst str (first *register-arg-tns*) (@ csp-tn n-word-bytes :post-index)))
400 (assemble ()
401 (inst b :eq MULTIPLE)
402 (unless unused-start-p
403 (move start csp-tn))
404 (inst str (first *register-arg-tns*) (@ csp-tn n-word-bytes :post-index))
405 (unless unused-count-p
406 (inst mov count (fixnumize 1)))
407 (inst b DONE)
408 MULTIPLE
409 #.(assert (evenp register-arg-count))
410 (do ((arg *register-arg-tns* (cddr arg))
411 (i 0 (+ i 2)))
412 ((null arg))
413 (inst stp (first arg) (second arg)
414 (@ args (* i n-word-bytes))))
415 (unless unused-start-p
416 (move start args))
417 (unless unused-count-p
418 (move count nargs))
419 DONE))))
421 ;;; VOP that can be inherited by unknown values receivers. The main
422 ;;; thing this handles is allocation of the result temporaries.
423 (define-vop (unknown-values-receiver)
424 (:results
425 (start :scs (any-reg))
426 (count :scs (any-reg)))
427 (:temporary (:sc any-reg :offset ocfp-offset :from :result) values-start)
428 (:temporary (:sc any-reg :offset nargs-offset :from :result) nvals)
429 ;; Avoid being clobbered by RECEIVE-UNKNOWN-VALUES
430 (:temporary (:sc descriptor-reg :offset r0-offset :from :result) r0-temp))
432 ;;; This hook in the codegen pass lets us insert code before fall-thru entry
433 ;;; points, local-call entry points, and tail-call entry points. The default
434 ;;; does nothing.
435 (defun emit-block-header (start-label trampoline-label fall-thru-p alignp)
436 (declare (ignore alignp))
437 (when (and fall-thru-p trampoline-label)
438 (inst b start-label))
439 (when trampoline-label
440 (emit-label trampoline-label)
441 (inst str lr-tn (@ cfp-tn (* lra-save-offset n-word-bytes))))
442 (emit-label start-label))
445 ;;;; XEP hackery:
447 ;;; Get the lexical environment from its passing location.
448 (define-vop (setup-closure-environment)
449 (:temporary (:sc descriptor-reg :offset lexenv-offset :target closure
450 :to (:result 0))
451 lexenv)
452 (:results (closure :scs (descriptor-reg)))
453 (:info label)
454 (:ignore label)
455 (:generator 6
456 ;; Get result.
457 (move closure lexenv)))
459 ;;; Copy a more arg from the argument area to the end of the current frame.
460 ;;; Fixed is the number of non-more arguments.
461 (define-vop (copy-more-arg)
462 ;; The environment here-and-now is not properly initialized. The
463 ;; stack frame is not yet fully allocated, and even if it were most
464 ;; of the slots have live data in them that PACK does not know
465 ;; about, so we cannot afford a register spill. As far as the boxed
466 ;; registers go, the arg-passing registers (R0, R1, and R2) are
467 ;; live, LEXENV is live, and LRA is live. On the unboxed front,
468 ;; NARGS is live. FP has been set up by the caller, SP is
469 ;; protecting our stack arguments, but is otherwise not set up. NFP
470 ;; is not yet set up. CODE and NULL are set up. SP and NFP must be
471 ;; correctly set up by the time we're done, and OCFP and R9 are
472 ;; available for use as temporaries. If we were any more register
473 ;; constrained, we'd be spilling registers manually (rather than
474 ;; allowing PACK to do it for us). -- AJB, 2012-Oct-30
475 (:vop-var vop)
476 ;; Pack COUNT and DEST into the same register, being careful to tell
477 ;; PACK that their lifetimes do not overlap (we're lying to PACK, as
478 ;; COUNT is live both before and after DEST, but not while DEST is
479 ;; live).
480 (:temporary (:sc any-reg :offset ocfp-offset :to :eval) count)
481 (:temporary (:sc any-reg :offset ocfp-offset :from :eval) dest)
482 (:temporary (:sc descriptor-reg :offset r9-offset) temp)
483 (:info fixed)
484 (:generator 20
485 ;; We open up with a LET to obtain a TN for NFP. We'll call it
486 ;; RESULT, to distinguish it from NFP-as-NFP and to roughly
487 ;; parallel the PPC implementation. We can't use a :TEMPORARY
488 ;; here because it would conflict with the existing NFP if there
489 ;; is a number-stack frame in play, but we only use it prior to
490 ;; actually setting up the "real" NFP.
491 (let ((result (make-random-tn :kind :normal
492 :sc (sc-or-lose 'any-reg)
493 :offset nfp-offset))
494 (delta (- (sb-allocated-size 'control-stack) fixed)))
495 (assemble ()
496 ;; Compute the end of the fixed stack frame (start of the MORE
497 ;; arg area) into RESULT.
498 (inst add result cfp-tn (add-sub-immediate
499 (* n-word-bytes (sb-allocated-size 'control-stack))))
500 ;; Compute the end of the MORE arg area (and our overall frame
501 ;; allocation) into the stack pointer.
502 (cond ((zerop fixed)
503 (inst add dest result (lsl nargs-tn (- word-shift n-fixnum-tag-bits)))
504 (move csp-tn dest)
505 (inst cbz nargs-tn done))
507 (inst subs count nargs-tn (fixnumize fixed))
508 (inst csel csp-tn result csp-tn :le)
509 (inst b :le DONE)
510 (inst add dest result (lsl count (- word-shift n-fixnum-tag-bits)))
511 ;; Don't leave the arguments unprotected when moving below the stack pointer
512 (when (>= delta 0)
513 (move csp-tn dest))))
515 (when (< fixed register-arg-count)
516 ;; We must stop when we run out of stack args, not when we
517 ;; run out of more args.
518 (inst add result result (* (- register-arg-count fixed) n-word-bytes)))
520 ;; We are copying at most (- NARGS FIXED) values, from last to
521 ;; first, in order to shift them out of the allocated part of
522 ;; the stack frame. The FIXED values remain where they are,
523 ;; as they are part of the allocated stack frame. Any
524 ;; remaining values are being moved to just beyond the end of
525 ;; the allocated stack frame, for a distance of (-
526 ;; (sb-allocated-size 'control-stack) fixed) words. There is
527 ;; a constant displacement of a single word in the loop below,
528 ;; because DEST points to the space AFTER the value being
529 ;; moved.
531 LOOP
532 (cond ((zerop delta)) ;; nothing to move
533 ((plusp delta) ;; copy backward
534 (inst cmp dest result)
535 (inst b :le DO-REGS)
536 (inst ldr temp (@ dest (load-store-offset
537 (- (* (1+ delta) n-word-bytes)))))
538 (inst str temp (@ dest (- n-word-bytes) :pre-index))
539 (inst b LOOP))
540 (t ;; copy forward
541 (assemble ()
542 (inst cmp dest result)
543 (inst b :le INNER-LOOP-DONE)
544 (inst ldr temp (@ result (load-store-offset
545 (- (* delta n-word-bytes)))))
546 (inst str temp (@ result n-word-bytes :post-index))
547 (inst b LOOP)
548 INNER-LOOP-DONE
549 (inst mov csp-tn dest))))
551 DO-REGS
552 (when (< fixed register-arg-count)
553 ;; Now we have to deposit any more args that showed up in registers.
554 (loop with i = fixed
555 for offset = (+ delta i)
557 (cond ((and (< (1+ i) register-arg-count)
558 (ldp-stp-offset-p (* offset n-word-bytes) n-word-bits))
559 (inst stp
560 (nth i *register-arg-tns*)
561 (nth (1+ i) *register-arg-tns*)
562 (@ cfp-tn (* offset n-word-bytes)))
563 (incf i 2))
565 (storew (nth i *register-arg-tns*) cfp-tn offset)
566 (incf i)))
567 while (< i register-arg-count)))
568 DONE
570 ;; Now that we're done with the &MORE args, we can set up the
571 ;; number stack frame.
572 (let ((nfp-tn (current-nfp-tn vop)))
573 (when nfp-tn
574 (inst sub nfp-tn nsp-tn (add-sub-immediate (bytes-needed-for-non-descriptor-stack-frame)))
575 (inst mov-sp nsp-tn nfp-tn)))))))
577 ;;; More args are stored consecutively on the stack, starting
578 ;;; immediately at the context pointer. The context pointer is not
579 ;;; typed, so the lowtag is 0.
580 (define-vop (more-arg)
581 (:translate %more-arg)
582 (:policy :fast-safe)
583 (:args (context :scs (descriptor-reg))
584 (index :scs (any-reg immediate)))
585 (:arg-types * tagged-num)
586 (:temporary (:scs (any-reg)) temp)
587 (:results (value :scs (descriptor-reg any-reg)))
588 (:result-types *)
589 (:generator 5
590 (sc-case index
591 (immediate
592 (inst ldr value
593 (@ context
594 (load-store-offset
595 (ash (tn-value index) word-shift)))))
597 (inst add temp context (lsl index (- word-shift n-fixnum-tag-bits)))
598 (loadw value temp)))))
600 (define-vop ()
601 (:translate sb-c::%more-kw-arg)
602 (:policy :fast-safe)
603 (:args (context :scs (descriptor-reg))
604 (index :scs (any-reg)))
605 (:arg-types * tagged-num)
606 (:temporary (:scs (any-reg)) temp)
607 (:results (value :scs (descriptor-reg any-reg))
608 (keyword :scs (descriptor-reg any-reg)))
609 (:result-types * *)
610 (:generator 5
611 (inst add temp context (lsl index (- word-shift n-fixnum-tag-bits)))
612 (inst ldp keyword value (@ temp))))
614 (define-vop (more-arg-or-nil)
615 (:policy :fast-safe)
616 (:args (object :scs (descriptor-reg) :to (:result 1))
617 (count :scs (any-reg) :to (:result 1)))
618 (:arg-types * tagged-num)
619 (:info index)
620 (:results (value :scs (descriptor-reg any-reg)))
621 (:result-types *)
622 (:generator 3
623 (inst mov value null-tn)
624 (cond ((zerop index)
625 (inst cbz count done))
627 (inst cmp count (fixnumize index))
628 (inst b :le done)))
629 (inst ldr value
630 (@ object
631 (load-store-offset
632 (ash index word-shift))))
633 done))
635 ;;; Turn more arg (context, count) into a list.
636 (define-vop ()
637 (:translate %listify-rest-args)
638 (:args (context-arg :target context :scs (descriptor-reg))
639 (count-arg :target count :scs (any-reg)))
640 (:arg-types * tagged-num)
641 (:temporary (:scs (descriptor-reg) :from (:argument 0)) context)
642 (:temporary (:scs (any-reg) :from (:argument 1)) count)
643 (:temporary (:scs (descriptor-reg) :from :eval) temp)
644 (:temporary (:scs (any-reg) :from :eval) dst)
645 (:temporary (:sc non-descriptor-reg :offset lr-offset) lr)
646 (:results (result :scs (descriptor-reg)))
647 (:policy :safe)
648 (:node-var node)
649 (:generator 20
650 (move context context-arg)
651 (move count count-arg)
652 ;; Check to see if there are any arguments.
653 (move result null-tn)
654 (inst cbz count DONE)
656 (pseudo-atomic (lr :sync nil :elide-if (node-stack-allocate-p node))
657 (assemble ()
658 ;; Allocate a cons (2 words) for each item.
659 (let* ((dx-p (node-stack-allocate-p node))
660 (size (cond (dx-p
661 (lsl count (1+ (- word-shift n-fixnum-tag-bits))))
663 (inst lsl temp count (1+ (- word-shift n-fixnum-tag-bits)))
664 temp))))
665 (allocation 'list size list-pointer-lowtag dst
666 :flag-tn lr
667 :stack-allocate-p dx-p
668 :overflow
669 (lambda ()
670 ;; The size will be computed by subtracting from CSP
671 (inst mov tmp-tn context)
672 (invoke-asm-routine (if (system-tlab-p 0 node) 'sys-listify-&rest 'listify-&rest) lr)
673 (inst mov result tmp-tn)
674 (inst b ALLOC-DONE))))
675 (move result dst)
677 (inst b ENTER)
679 ;; Compute the next cons and store it in the current one.
680 LOOP
681 (inst add dst dst (* 2 n-word-bytes))
682 (storew dst dst -1 list-pointer-lowtag)
684 ;; Grab one value.
685 ENTER
686 (inst ldr temp (@ context n-word-bytes :post-index))
688 ;; Dec count, and if != zero, go back for more.
689 (inst subs count count (fixnumize 1))
690 ;; Store the value into the car of the current cons.
691 (storew temp dst 0 list-pointer-lowtag)
692 (inst b :gt LOOP)
694 ;; NIL out the last cons.
695 (storew null-tn dst 1 list-pointer-lowtag)
696 ALLOC-DONE))
697 DONE))
699 ;;; Return the location and size of the more arg glob created by
700 ;;; Copy-More-Arg. Supplied is the total number of arguments supplied
701 ;;; (originally passed in NARGS.) Fixed is the number of non-rest
702 ;;; arguments.
704 ;;; We must duplicate some of the work done by Copy-More-Arg, since at
705 ;;; that time the environment is in a pretty brain-damaged state,
706 ;;; preventing this info from being returned as values. What we do is
707 ;;; compute supplied - fixed, and return a pointer that many words
708 ;;; below the current stack top.
709 (define-vop ()
710 (:policy :fast-safe)
711 (:translate sb-c::%more-arg-context)
712 (:args (supplied :scs (any-reg)))
713 (:arg-types tagged-num (:constant fixnum))
714 (:info fixed)
715 (:results (context :scs (descriptor-reg))
716 (count :scs (any-reg)))
717 (:result-types t tagged-num)
718 (:note "more-arg-context")
719 (:generator 5
720 (inst sub count supplied (fixnumize fixed))
721 (inst sub context csp-tn (lsl count (- word-shift n-fixnum-tag-bits)))))
723 (define-vop (verify-arg-count)
724 (:policy :fast-safe)
725 (:args (nargs :scs (any-reg)))
726 (:arg-types positive-fixnum (:constant t) (:constant t))
727 (:info min max)
728 (:vop-var vop)
729 (:temporary (:sc unsigned-reg :offset nl0-offset) temp)
730 (:save-p :compute-only)
731 (:generator 3
732 (let ((err-lab
733 (generate-error-code vop 'invalid-arg-count-error)))
734 (labels ((load-immediate (x)
735 (add-sub-immediate (fixnumize x))))
736 (cond ((eql max 0)
737 (inst cbnz nargs err-lab))
738 ((not min)
739 (inst cmp nargs (load-immediate max))
740 (inst b :ne err-lab))
741 (max
742 (if (zerop min)
743 (setf temp nargs)
744 (inst sub temp nargs (load-immediate min)))
745 (inst cmp temp (load-immediate (- max min)))
746 (inst b :hi err-lab))
748 (cond ((= min 1)
749 (inst cbz nargs err-lab))
750 ((plusp min)
751 (inst cmp nargs (load-immediate min))
752 (inst b :lo err-lab)))))))))
754 ;;;; Local call with unknown values convention return:
756 ;;; Non-TR local call for a fixed number of values passed according to the
757 ;;; unknown values convention.
759 ;;; Args are the argument passing locations, which are specified only to
760 ;;; terminate their lifetimes in the caller.
762 ;;; Values are the return value locations (wired to the standard passing
763 ;;; locations).
765 ;;; Save is the save info, which we can ignore since saving has been done.
766 ;;; Return-PC is the TN that the return PC should be passed in.
767 ;;; Target is a continuation pointing to the start of the called function.
768 ;;; Nvals is the number of values received.
770 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
771 ;;; registers may be tied up by the more operand. Instead, we use
772 ;;; MAYBE-LOAD-STACK-TN.
773 (define-vop (call-local)
774 (:args (fp)
775 (nfp)
776 (args :more t))
777 (:results (values :more t))
778 (:save-p t)
779 (:move-args :local-call)
780 (:info arg-locs callee target nvals)
781 (:vop-var vop)
782 (:node-var node)
783 (:temporary (:scs (descriptor-reg) :from (:eval 0)) move-temp)
784 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
785 (:temporary (:sc any-reg :offset ocfp-offset :from (:eval 0)) ocfp)
786 (:ignore arg-locs args ocfp)
787 (:generator 5
788 (let ((cur-nfp (current-nfp-tn vop)))
789 (when cur-nfp
790 (store-stack-tn nfp-save cur-nfp))
791 (let ((callee-nfp (callee-nfp-tn callee)))
792 (when callee-nfp
793 (maybe-load-stack-tn callee-nfp nfp)))
794 (maybe-load-stack-tn cfp-tn fp)
795 (note-this-location vop :call-site)
796 (inst bl target)
797 (default-unknown-values vop values nvals move-temp node)
798 (when cur-nfp
799 (load-stack-tn cur-nfp nfp-save)))))
802 ;;; Non-TR local call for a variable number of return values passed according
803 ;;; to the unknown values convention. The results are the start of the values
804 ;;; glob and the number of values received.
806 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
807 ;;; registers may be tied up by the more operand. Instead, we use
808 ;;; MAYBE-LOAD-STACK-TN.
809 (define-vop (multiple-call-local unknown-values-receiver)
810 (:args (fp)
811 (nfp)
812 (args :more t))
813 (:save-p t)
814 (:move-args :local-call)
815 (:info save callee target)
816 (:ignore args save r0-temp)
817 (:vop-var vop)
818 (:node-var node)
819 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
820 (:generator 20
821 (let ((cur-nfp (current-nfp-tn vop)))
822 (when cur-nfp
823 (store-stack-tn nfp-save cur-nfp))
824 (let ((callee-nfp (callee-nfp-tn callee)))
825 ;; alpha doesn't test this before the maybe-load
826 (when callee-nfp
827 (maybe-load-stack-tn callee-nfp nfp)))
828 (maybe-load-stack-tn cfp-tn fp)
829 (note-this-location vop :call-site)
830 (inst bl target)
831 (note-this-location vop :unknown-return)
832 (receive-unknown-values node values-start nvals start count)
833 (when cur-nfp
834 (load-stack-tn cur-nfp nfp-save)))))
836 ;;;; Local call with known values return:
838 ;;; Non-TR local call with known return locations. Known-value return works
839 ;;; just like argument passing in local call.
841 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
842 ;;; registers may be tied up by the more operand. Instead, we use
843 ;;; MAYBE-LOAD-STACK-TN.
844 (define-vop (known-call-local)
845 (:args (fp)
846 (nfp)
847 (args :more t))
848 (:results (res :more t))
849 (:move-args :local-call)
850 (:save-p t)
851 (:info save callee target)
852 (:ignore args res save)
853 (:vop-var vop)
854 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
855 (:generator 5
856 (let ((cur-nfp (current-nfp-tn vop)))
857 (when cur-nfp
858 (store-stack-tn nfp-save cur-nfp))
859 (let ((callee-nfp (callee-nfp-tn callee)))
860 (when callee-nfp
861 (maybe-load-stack-tn callee-nfp nfp)))
862 (maybe-load-stack-tn cfp-tn fp)
863 (note-this-location vop :call-site)
864 (inst bl target)
865 (note-this-location vop :known-return)
866 (when cur-nfp
867 (load-stack-tn cur-nfp nfp-save)))))
869 ;;; Return from known values call. We receive the return locations as
870 ;;; arguments to terminate their lifetimes in the returning function. We
871 ;;; restore FP and CSP and jump to the Return-PC.
873 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
874 ;;; registers may be tied up by the more operand. Instead, we use
875 ;;; MAYBE-LOAD-STACK-TN.
876 (define-vop (known-return)
877 (:args (old-fp)
878 (return-pc)
879 (vals :more t))
880 (:temporary (:sc non-descriptor-reg :offset lr-offset) lr)
881 (:move-args :known-return)
882 (:info val-locs)
883 (:ignore old-fp return-pc val-locs vals)
884 (:vop-var vop)
885 (:generator 6
886 (move csp-tn cfp-tn)
887 (loadw-pair cfp-tn ocfp-save-offset lr lra-save-offset cfp-tn)
888 (let ((cur-nfp (current-nfp-tn vop)))
889 (when cur-nfp
890 (inst add nsp-tn cur-nfp (add-sub-immediate
891 (bytes-needed-for-non-descriptor-stack-frame)))))
892 (lisp-return lr :known)))
894 ;;;; Full call:
896 ;;; There is something of a cross-product effect with full calls.
897 ;;; Different versions are used depending on whether we know the
898 ;;; number of arguments or the name of the called function, and
899 ;;; whether we want fixed values, unknown values, or a tail call.
901 ;;; In full call, the arguments are passed creating a partial frame on
902 ;;; the stack top and storing stack arguments into that frame. On
903 ;;; entry to the callee, this partial frame is pointed to by FP. If
904 ;;; there are no stack arguments, we don't bother allocating a partial
905 ;;; frame, and instead set FP to SP just before the call.
907 ;;; This macro helps in the definition of full call VOPs by avoiding code
908 ;;; replication in defining the cross-product VOPs.
910 ;;; Name is the name of the VOP to define.
912 ;;; Named is true if the first argument is a symbol whose global function
913 ;;; definition is to be called.
915 ;;; Return is either :Fixed, :Unknown or :Tail:
916 ;;; -- If :Fixed, then the call is for a fixed number of values, returned in
917 ;;; the standard passing locations (passed as result operands).
918 ;;; -- If :Unknown, then the result values are pushed on the stack, and the
919 ;;; result values are specified by the Start and Count as in the
920 ;;; unknown-values continuation representation.
921 ;;; -- If :Tail, then do a tail-recursive call. No values are returned.
922 ;;; The Old-Fp and Return-PC are passed as the second and third arguments.
924 ;;; In non-tail calls, the pointer to the stack arguments is passed as the last
925 ;;; fixed argument. If Variable is false, then the passing locations are
926 ;;; passed as a more arg. Variable is true if there are a variable number of
927 ;;; arguments passed on the stack. Variable cannot be specified with :Tail
928 ;;; return. TR variable argument call is implemented separately.
930 ;;; In tail call with fixed arguments, the passing locations are passed as a
931 ;;; more arg, but there is no new-FP, since the arguments have been set up in
932 ;;; the current frame.
933 (defmacro define-full-call (name named return variable &optional args)
934 (aver (not (and variable (eq return :tail))))
935 `(define-vop (,name
936 ,@(when (eq return :unknown)
937 '(unknown-values-receiver)))
938 (:args
939 ,@(unless (eq return :tail)
940 '((new-fp :scs (any-reg) :to :eval)))
942 ,@(case named
943 ((nil)
944 '((arg-fun :target lexenv)))
945 (:direct)
947 '((name :target name-pass))))
949 ,@(when (eq return :tail)
950 '((old-fp)
951 (return-pc)))
953 ,@(unless variable `((args :more t ,@(unless (eq args :fixed)
954 '(:scs (descriptor-reg control-stack)))))))
956 ,@(when (memq return '(:fixed :unboxed))
957 '((:results (values :more t))))
959 (:save-p ,(if (eq return :tail) :compute-only t))
961 ,@(unless (or (eq return :tail)
962 variable)
963 `((:move-args ,(if (eq args :fixed)
964 :fixed
965 :full-call))))
968 (:vop-var vop)
969 (:node-var node)
970 (:info ,@(unless (or variable (eq return :tail)) '(arg-locs))
971 ,@(unless variable '(nargs))
972 ,@(when (eq named :direct) '(fun))
973 ,@(when (eq return :fixed) '(nvals))
974 step-instrumenting
975 ,@(unless named
976 '(fun-type)))
978 (:ignore
979 ,@(unless (or variable (eq return :tail)) '(arg-locs))
980 ,@(unless variable '(args))
981 ,@(ecase return
982 (:fixed '(ocfp-temp))
983 (:unboxed '(ocfp-temp node values))
984 (:tail '(old-fp return-pc node))
985 (:unknown '(r0-temp))))
987 ,@(unless (eq named :direct)
988 `((:temporary (:sc descriptor-reg :offset lexenv-offset
989 :from (:argument ,(if (eq return :tail) 0 1))
990 :to :eval)
991 ,(if named 'name-pass 'lexenv))))
993 (:temporary (:sc any-reg :offset nargs-offset :to
994 ,(if (eq return :fixed)
995 :save
996 :eval))
997 nargs-pass)
999 ,@(when variable
1000 (mapcar #'(lambda (name offset)
1001 `(:temporary (:sc descriptor-reg
1002 :offset ,offset
1003 :to :result)
1004 ,name))
1005 *register-arg-names* *register-arg-offsets*))
1006 ,@(when (eq return :fixed)
1007 '((:temporary (:scs (descriptor-reg) :from :eval) move-temp)
1008 (:temporary (:sc any-reg :from :eval :offset ocfp-offset) ocfp-temp)))
1009 ,@(when (eq return :unboxed)
1010 '((:temporary (:sc any-reg :from :eval :offset ocfp-offset) ocfp-temp)))
1011 ,@(unless (eq return :tail)
1012 '((:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)))
1014 (:temporary (:sc non-descriptor-reg :offset lr-offset) lr)
1016 (:generator ,(+ (if named 5 0)
1017 (if variable 19 1)
1018 (if (eq return :tail) 0 10)
1020 (if (eq return :unknown) 25 0))
1021 (let* ((cur-nfp (current-nfp-tn vop))
1022 (filler
1023 (remove nil
1024 (list ,@(if (eq return :tail)
1025 '(:load-nargs
1026 (when cur-nfp
1027 :frob-nfp))
1028 '(:load-nargs
1029 (when cur-nfp
1030 :frob-nfp)
1031 :load-fp))))))
1032 (flet ((do-next-filler ()
1033 (let* ((next (pop filler))
1034 (what (if (consp next) (car next) next)))
1035 (ecase what
1036 (:load-nargs
1037 ,@(if variable
1038 `((inst sub nargs-pass csp-tn new-fp)
1039 (inst asr nargs-pass nargs-pass (- word-shift n-fixnum-tag-bits))
1040 ,@(do ((arg *register-arg-names* (cddr arg))
1041 (i 0 (+ i 2))
1042 (insts))
1043 ((null arg) (nreverse insts))
1044 #.(assert (evenp register-arg-count))
1045 (push `(inst ldp ,(first arg) ,(second arg)
1046 (@ new-fp ,(* i n-word-bytes)))
1047 insts))
1048 (storew cfp-tn new-fp ocfp-save-offset))
1049 '((unless (consp nargs)
1050 (load-immediate-word nargs-pass (fixnumize nargs))))))
1051 ,@(if (eq return :tail)
1052 '((:frob-nfp
1053 (inst add nsp-tn cur-nfp (add-sub-immediate
1054 (bytes-needed-for-non-descriptor-stack-frame)))))
1055 `((:frob-nfp
1056 (store-stack-tn nfp-save cur-nfp))
1057 (:load-fp
1058 (move cfp-tn (cond ,@(and
1059 (not variable)
1060 '(((<= (if (consp nargs)
1061 (car nargs)
1062 nargs) register-arg-count)
1063 csp-tn)))
1065 new-fp))))))
1066 ((nil)))))
1067 (insert-step-instrumenting ()
1068 ;; Conditionally insert a conditional trap:
1069 (when step-instrumenting
1070 (assemble ()
1071 #-sb-thread
1072 (load-symbol-value tmp-tn sb-impl::*stepping*)
1073 #+sb-thread
1074 (loadw tmp-tn thread-tn thread-stepping-slot)
1075 (inst cbz tmp-tn step-done-label)
1076 ;; CONTEXT-PC will be pointing here when the
1077 ;; interrupt is handled, not after the
1078 ;; DEBUG-TRAP.
1079 (note-this-location vop :internal-error)
1080 (inst brk single-step-around-trap)
1081 STEP-DONE-LABEL))))
1082 (declare (ignorable #'insert-step-instrumenting))
1083 ,@(case named
1084 ((t)
1085 `((sc-case name
1086 (descriptor-reg (move name-pass name))
1087 (control-stack
1088 (load-stack-tn name-pass name)
1089 (do-next-filler))
1090 (constant
1091 (load-constant vop name name-pass)
1092 (do-next-filler)))
1093 (do-next-filler)
1094 (insert-step-instrumenting)))
1095 ((nil)
1096 `((sc-case arg-fun
1097 (descriptor-reg (move lexenv arg-fun))
1098 (control-stack
1099 (load-stack-tn lexenv arg-fun)
1100 (do-next-filler))
1101 (constant
1102 (load-constant vop arg-fun lexenv)
1103 (do-next-filler)))
1104 (insert-step-instrumenting)
1105 (do-next-filler))))
1106 (loop
1107 (if filler
1108 (do-next-filler)
1109 (return)))
1110 ,@(case named
1111 ((t)
1112 `((loadw lr name-pass fdefn-raw-addr-slot other-pointer-lowtag)
1113 ,(if (eq return :tail)
1114 `(inst add lr lr 4))))
1115 (:direct
1116 `((inst ldr lr (@ null-tn (load-store-offset (static-fun-offset fun))))
1117 ,(if (eq return :tail)
1118 `(inst add lr lr 4)))))
1120 (note-this-location vop :call-site)
1122 ,(if named
1123 (if (eq return :tail)
1124 `(inst br lr)
1125 `(inst blr lr))
1126 (if (eq return :tail)
1127 `(tail-call-unnamed lexenv lr fun-type)
1128 `(call-unnamed lexenv lr fun-type))))
1130 ,@(ecase return
1131 (:fixed
1132 '((default-unknown-values vop values nvals move-temp node)
1133 (when cur-nfp
1134 (load-stack-tn cur-nfp nfp-save))))
1135 (:unknown
1136 '((note-this-location vop :unknown-return)
1137 (receive-unknown-values node values-start nvals start count)
1138 (when cur-nfp
1139 (load-stack-tn cur-nfp nfp-save))))
1140 ((:unboxed)
1141 '((when cur-nfp
1142 (load-stack-tn cur-nfp nfp-save))))
1143 ((:tail)))))))
1145 (define-full-call call nil :fixed nil)
1146 (define-full-call call-named t :fixed nil)
1147 (define-full-call static-call-named :direct :fixed nil)
1148 (define-full-call multiple-call nil :unknown nil)
1149 (define-full-call multiple-call-named t :unknown nil)
1150 (define-full-call static-multiple-call-named :direct :unknown nil)
1151 (define-full-call tail-call nil :tail nil)
1152 (define-full-call tail-call-named t :tail nil)
1153 (define-full-call static-tail-call-named :direct :tail nil)
1155 (define-full-call call-variable nil :fixed t)
1156 (define-full-call multiple-call-variable nil :unknown t)
1158 (define-full-call fixed-call-named t :fixed nil :fixed)
1159 (define-full-call fixed-tail-call-named t :tail nil :fixed)
1161 (define-full-call unboxed-call-named t :unboxed nil)
1162 (define-full-call fixed-unboxed-call-named t :unboxed nil :fixed)
1164 ;;; Defined separately, since needs special code that BLT's the
1165 ;;; arguments down.
1166 (define-vop (tail-call-variable)
1167 (:args
1168 (args-arg :scs (any-reg) :target args)
1169 (function-arg :scs (descriptor-reg) :target lexenv)
1170 (old-fp-arg :scs (any-reg) :load-if nil)
1171 (lra-arg :scs (descriptor-reg) :load-if nil))
1172 (:info fun-type)
1173 (:temporary (:sc any-reg :offset nl2-offset :from (:argument 0)) args)
1174 (:temporary (:sc descriptor-reg :offset lexenv-offset :from (:argument 1)) lexenv)
1175 (:ignore old-fp-arg lra-arg)
1176 (:vop-var vop)
1177 (:generator 75
1178 ;; Move these into the passing locations if they are not already there.
1179 (move args args-arg)
1180 (move lexenv function-arg)
1181 ;; Clear the number stack if anything is there.
1182 (let ((cur-nfp (current-nfp-tn vop)))
1183 (when cur-nfp
1184 (inst add nsp-tn cur-nfp (add-sub-immediate
1185 (bytes-needed-for-non-descriptor-stack-frame)))))
1186 (invoke-asm-routine (if (eq fun-type :function)
1187 'tail-call-variable
1188 'tail-call-callable-variable)
1189 tmp-tn
1190 :tail t)))
1192 ;;; Invoke the function-designator FUN.
1193 (defun tail-call-unnamed (lexenv lr type)
1194 (case type
1195 (:symbol
1196 (invoke-asm-routine 'tail-call-symbol tmp-tn :tail t))
1198 (assemble ()
1199 (when (eq type :designator)
1200 (inst and tmp-tn lexenv lowtag-mask)
1201 (inst cmp tmp-tn fun-pointer-lowtag)
1202 (inst b :eq call)
1203 (invoke-asm-routine 'tail-call-symbol tmp-tn :tail t))
1204 call
1205 (loadw lr lexenv closure-fun-slot fun-pointer-lowtag)
1206 (inst add lr lr 4)
1207 (inst br lr)))))
1209 (defun call-unnamed (lexenv lr type)
1210 (case type
1211 (:symbol
1212 (invoke-asm-routine 'call-symbol tmp-tn))
1214 (assemble ()
1215 (when (eq type :designator)
1216 (inst and tmp-tn lexenv lowtag-mask)
1217 (inst cmp tmp-tn fun-pointer-lowtag)
1218 (inst b :eq call)
1219 (invoke-asm-routine 'call-symbol tmp-tn)
1220 (inst b ret))
1221 call
1222 (loadw lr lexenv closure-fun-slot fun-pointer-lowtag)
1223 (inst blr lr)
1224 ret))))
1226 ;;;; Unknown values return:
1228 ;;; Return a single value using the unknown-values convention.
1229 (define-vop (return-single)
1230 (:args (old-fp)
1231 (return-pc)
1232 (value))
1233 (:temporary (:sc non-descriptor-reg :offset lr-offset) lr)
1234 (:ignore value old-fp return-pc)
1235 (:vop-var vop)
1236 (:generator 6
1237 ;; Clear the number stack.
1238 (let ((cur-nfp (current-nfp-tn vop)))
1239 (when cur-nfp
1240 (inst add nsp-tn cur-nfp (add-sub-immediate
1241 (bytes-needed-for-non-descriptor-stack-frame)))))
1242 ;; Interrupts leave two words of space for the new frame, so it's safe
1243 ;; to deallocate the frame before accessing OCFP/LR.
1244 (move csp-tn cfp-tn)
1245 (loadw-pair cfp-tn ocfp-save-offset lr lra-save-offset cfp-tn)
1246 ;; Clear the control stack, and restore the frame pointer.
1248 ;; Out of here.
1249 (lisp-return lr :single-value)))
1251 ;;; Do unknown-values return of a fixed number of values. The Values are
1252 ;;; required to be set up in the standard passing locations. Nvals is the
1253 ;;; number of values returned.
1255 ;;; If returning a single value, then deallocate the current frame, restore
1256 ;;; FP and jump to the single-value entry at Return-PC + 8.
1258 ;;; If returning other than one value, then load the number of values returned,
1259 ;;; NIL out unsupplied values registers, restore FP and return at Return-PC.
1260 ;;; When there are stack values, we must initialize the argument pointer to
1261 ;;; point to the beginning of the values block (which is the beginning of the
1262 ;;; current frame.)
1263 (define-vop (return)
1264 (:args
1265 (old-fp)
1266 (return-pc)
1267 (values :more t))
1268 (:ignore values old-fp return-pc)
1269 (:info nvals)
1270 (:temporary (:sc descriptor-reg :offset r0-offset :from (:eval 0)) r0)
1271 (:temporary (:sc descriptor-reg :offset r1-offset :from (:eval 0)) r1)
1272 (:temporary (:sc descriptor-reg :offset r2-offset :from (:eval 0)) r2)
1273 (:temporary (:sc descriptor-reg :offset r3-offset :from (:eval 0)) r3)
1274 (:temporary (:sc non-descriptor-reg :offset lr-offset) lr)
1275 (:temporary (:sc any-reg :offset nargs-offset) nargs)
1276 (:temporary (:sc any-reg :offset ocfp-offset) val-ptr)
1277 (:vop-var vop)
1278 (:generator 6
1279 ;; Clear the number stack.
1280 (let ((cur-nfp (current-nfp-tn vop)))
1281 (when cur-nfp
1282 (inst add nsp-tn cur-nfp (add-sub-immediate
1283 (bytes-needed-for-non-descriptor-stack-frame)))))
1284 (cond ((= nvals 1)
1285 ;; Clear the control stack, and restore the frame pointer.
1286 (move csp-tn cfp-tn)
1287 (loadw-pair cfp-tn ocfp-save-offset lr lra-save-offset cfp-tn)
1288 ;; Out of here.
1289 (lisp-return lr :single-value))
1291 ;; Establish the values pointer.
1292 (move val-ptr cfp-tn)
1293 ;; restore the frame pointer and clear as much of the control
1294 ;; stack as possible.
1295 (loadw-pair cfp-tn ocfp-save-offset lr lra-save-offset cfp-tn)
1296 (inst add csp-tn val-ptr (add-sub-immediate (* nvals n-word-bytes)))
1297 ;; Establish the values count.
1298 (load-immediate-word nargs (fixnumize nvals))
1299 ;; pre-default any argument register that need it.
1300 (when (< nvals register-arg-count)
1301 (dolist (reg (subseq (list r0 r1 r2 r3) nvals))
1302 (move reg null-tn)))
1303 ;; And away we go.
1304 (lisp-return lr :multiple-values)))))
1306 ;;; Do unknown-values return of an arbitrary number of values (passed
1307 ;;; on the stack.) We check for the common case of a single return
1308 ;;; value, and do that inline using the normal single value return
1309 ;;; convention. Otherwise, we branch off to code that calls an
1310 ;;; assembly-routine.
1311 (define-vop (return-multiple)
1312 (:args
1313 (old-fp-arg :scs (any-reg) :to (:eval 1))
1314 (lra-arg)
1315 (vals-arg :scs (any-reg) :target vals)
1316 (nvals-arg :scs (any-reg) :target nvals))
1317 (:temporary (:sc any-reg :offset nl2-offset :from (:argument 0)) old-fp)
1318 (:temporary (:sc any-reg :offset nl1-offset :from (:argument 2)) vals)
1319 (:temporary (:sc any-reg :offset nargs-offset :from (:argument 3)) nvals)
1320 (:temporary (:sc descriptor-reg :offset r0-offset) r0)
1321 (:temporary (:sc non-descriptor-reg :offset lr-offset) lr)
1322 (:vop-var vop)
1323 (:generator 13
1324 (maybe-load-stack-tn lr lra-arg)
1325 ;; Clear the number stack.
1326 (let ((cur-nfp (current-nfp-tn vop)))
1327 (when cur-nfp
1328 (inst add nsp-tn cur-nfp (add-sub-immediate
1329 (bytes-needed-for-non-descriptor-stack-frame)))))
1331 ;; Check for the single case.
1332 (inst cmp nvals-arg (fixnumize 1))
1333 (inst b :ne NOT-SINGLE)
1335 ;; Return with one value.
1336 (inst ldr r0 (@ vals-arg))
1337 (move csp-tn cfp-tn)
1338 (move cfp-tn old-fp-arg)
1339 (lisp-return lr :single-value)
1341 NOT-SINGLE
1342 (move old-fp old-fp-arg)
1343 (move vals vals-arg)
1344 (move nvals nvals-arg)
1345 (invoke-asm-routine 'return-multiple tmp-tn :tail t)))
1347 ;;; Single-stepping
1349 (define-vop (step-instrument-before-vop)
1350 (:policy :fast-safe)
1351 (:vop-var vop)
1352 (:generator 3
1353 #-sb-thread
1354 (load-symbol-value tmp-tn sb-impl::*stepping*)
1355 #+sb-thread
1356 (loadw tmp-tn thread-tn thread-stepping-slot)
1357 (inst cbz tmp-tn DONE)
1358 ;; CONTEXT-PC will be pointing here when the interrupt is handled,
1359 ;; not after the BREAK.
1360 (note-this-location vop :internal-error)
1361 ;; A best-guess effort at a debug trap suitable for a
1362 ;; single-step-before-trap.
1363 (inst brk single-step-before-trap)
1364 DONE))