1 ;;;; the VM definition of function call for the Sparc
3 ;;;; This software is part of the SBCL system. See the README file for
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.
15 ;;;; Interfaces to IR2 conversion:
17 ;;; Return a wired TN describing the N'th full call argument passing
19 (!def-vm-support-routine standard-arg-location (n)
20 (declare (type unsigned-byte n))
21 (if (< n register-arg-count)
22 (make-wired-tn *backend-t-primitive-type* register-arg-scn
23 (elt *register-arg-offsets* n))
24 (make-wired-tn *backend-t-primitive-type* control-stack-arg-scn n)))
27 ;;; Make a passing location TN for a local call return PC. If
28 ;;; standard is true, then use the standard (full call) location,
29 ;;; otherwise use any legal location. Even in the non-standard case,
30 ;;; this may be restricted by a desire to use a subroutine call
32 (!def-vm-support-routine make-return-pc-passing-location (standard)
34 (make-wired-tn *backend-t-primitive-type* register-arg-scn lra-offset)
35 (make-restricted-tn *backend-t-primitive-type* register-arg-scn)))
37 ;;; This is similar to MAKE-RETURN-PC-PASSING-LOCATION, but makes a
38 ;;; location to pass OLD-FP in. This is (obviously) wired in the
39 ;;; standard convention, but is totally unrestricted in non-standard
40 ;;; conventions, since we can always fetch it off of the stack using
42 (!def-vm-support-routine make-old-fp-passing-location (standard)
44 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn ocfp-offset)
45 (make-normal-tn *fixnum-primitive-type*)))
47 ;;; Make the TNs used to hold Old-FP and Return-PC within the current
48 ;;; function. We treat these specially so that the debugger can find
49 ;;; them at a known location.
50 (!def-vm-support-routine make-old-fp-save-location (env)
52 (physenv-debug-live-tn (make-normal-tn *fixnum-primitive-type*) env)
53 (make-wired-tn *fixnum-primitive-type*
57 (!def-vm-support-routine make-return-pc-save-location (env)
59 (physenv-debug-live-tn (make-normal-tn *backend-t-primitive-type*) env)
60 (make-wired-tn *backend-t-primitive-type*
64 ;;; Make a TN for the standard argument count passing location. We
65 ;;; only need to make the standard location, since a count is never
66 ;;; passed when we are using non-standard conventions.
67 (!def-vm-support-routine make-arg-count-location ()
68 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn nargs-offset))
71 ;;; Make a TN to hold the number-stack frame pointer. This is
72 ;;; allocated once per component, and is component-live.
73 (!def-vm-support-routine make-nfp-tn ()
75 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn nfp-offset)))
77 (!def-vm-support-routine make-stack-pointer-tn ()
78 (make-normal-tn *fixnum-primitive-type*))
80 (!def-vm-support-routine make-number-stack-pointer-tn ()
81 (make-normal-tn *fixnum-primitive-type*))
83 ;;; Return a list of TNs that can be used to represent an
84 ;;; unknown-values continuation within a function.
85 (!def-vm-support-routine make-unknown-values-locations ()
86 (list (make-stack-pointer-tn)
87 (make-normal-tn *fixnum-primitive-type*)))
90 ;;; This function is called by the ENTRY-ANALYZE phase, allowing
91 ;;; VM-dependent initialization of the IR2-COMPONENT structure. We push
92 ;;; placeholder entries in the CONSTANTS to leave room for additional
93 ;;; noise in the code object header.
94 (!def-vm-support-routine select-component-format (component)
95 (declare (type component component))
96 (dotimes (i code-constants-offset)
97 (vector-push-extend nil
98 (ir2-component-constants (component-info component))))
103 ;;; Return the number of bytes needed for the current non-descriptor
104 ;;; stack frame. Non-descriptor stack frames must be multiples of 8
105 ;;; bytes on the PMAX.
106 (defun bytes-needed-for-non-descriptor-stack-frame ()
107 (* (logandc2 (1+ (sb-allocated-size 'non-descriptor-stack)) 1)
110 ;;; Used for setting up the Old-FP in local call.
111 (define-vop (current-fp)
112 (:results (val :scs (any-reg)))
116 ;;; Used for computing the caller's NFP for use in known-values return. Only
117 ;;; works assuming there is no variable size stuff on the nstack.
119 (define-vop (compute-old-nfp)
120 (:results (val :scs (any-reg)))
123 (let ((nfp (current-nfp-tn vop)))
125 (inst add val nfp (bytes-needed-for-non-descriptor-stack-frame))))))
127 ;;; Accessing a slot from an earlier stack frame is definite hackery.
128 (define-vop (ancestor-frame-ref)
129 (:args (frame-pointer :scs (descriptor-reg))
130 (variable-home-tn :load-if nil))
131 (:results (value :scs (descriptor-reg any-reg)))
134 (aver (sc-is variable-home-tn control-stack))
135 (loadw value frame-pointer (tn-offset variable-home-tn))))
136 (define-vop (ancestor-frame-set)
137 (:args (frame-pointer :scs (descriptor-reg))
138 (value :scs (descriptor-reg any-reg)))
139 (:results (variable-home-tn :load-if nil))
142 (aver (sc-is variable-home-tn control-stack))
143 (storew value frame-pointer (tn-offset variable-home-tn))))
145 (define-vop (xep-allocate-frame)
146 (:info start-lab copy-more-arg-follows)
147 (:ignore copy-more-arg-follows)
149 (:temporary (:scs (non-descriptor-reg)) temp)
151 ;; Make sure the function is aligned, and drop a label pointing to this
153 (emit-alignment n-lowtag-bits)
154 (trace-table-entry trace-table-fun-prologue)
155 (emit-label start-lab)
156 ;; Allocate function header.
157 (inst simple-fun-header-word)
158 (dotimes (i (1- simple-fun-code-offset))
160 ;; The start of the actual code.
161 ;; Fix CODE, cause the function object was passed in.
162 (inst compute-code-from-fn code-tn code-tn start-lab temp)
163 ;; Build our stack frames.
164 (inst add csp-tn cfp-tn
165 (* n-word-bytes (sb-allocated-size 'control-stack)))
166 (let ((nfp-tn (current-nfp-tn vop)))
168 (inst sub nsp-tn (bytes-needed-for-non-descriptor-stack-frame))
169 (inst add nfp-tn nsp-tn number-stack-displacement)))
170 (trace-table-entry trace-table-normal)))
172 (define-vop (allocate-frame)
173 (:results (res :scs (any-reg))
174 (nfp :scs (any-reg)))
177 (trace-table-entry trace-table-fun-prologue)
179 (inst add csp-tn csp-tn
180 (* n-word-bytes (sb-allocated-size 'control-stack)))
181 (when (ir2-physenv-number-stack-p callee)
182 (inst sub nsp-tn (bytes-needed-for-non-descriptor-stack-frame))
183 (inst add nfp nsp-tn number-stack-displacement))
184 (trace-table-entry trace-table-normal)))
186 ;;; Allocate a partial frame for passing stack arguments in a full call. Nargs
187 ;;; is the number of arguments passed. If no stack arguments are passed, then
188 ;;; we don't have to do anything.
190 (define-vop (allocate-full-call-frame)
192 (:results (res :scs (any-reg)))
194 (when (> nargs register-arg-count)
196 (inst add csp-tn csp-tn (* nargs n-word-bytes)))))
201 ;;; Emit code needed at the return-point from an unknown-values call
202 ;;; for a fixed number of values. Values is the head of the TN-REF
203 ;;; list for the locations that the values are to be received into.
204 ;;; Nvals is the number of values that are to be received (should
205 ;;; equal the length of Values).
207 ;;; Move-Temp is a Descriptor-Reg TN used as a temporary.
209 ;;; This code exploits the fact that in the unknown-values convention,
210 ;;; a single value return returns at the return PC + 8, whereas a
211 ;;; return of other than one value returns directly at the return PC.
213 ;;; If 0 or 1 values are expected, then we just emit an instruction to
214 ;;; reset the SP (which will only be executed when other than 1 value
217 ;;; In the general case, we have to do three things:
218 ;;; -- Default unsupplied register values. This need only be done when a
219 ;;; single value is returned, since register values are defaulted by the
220 ;;; called in the non-single case.
221 ;;; -- Default unsupplied stack values. This needs to be done whenever there
222 ;;; are stack values.
223 ;;; -- Reset SP. This must be done whenever other than 1 value is returned,
224 ;;; regardless of the number of values desired.
226 ;;; The general-case code looks like this:
228 b regs-defaulted ; Skip if MVs
231 move a1 null-tn ; Default register values
233 loadi nargs 1 ; Force defaulting of stack values
234 move old-fp csp ; Set up args for SP resetting
237 subcc temp nargs register-arg-count
239 b :lt default-value-7 ; jump to default code
240 loadw move-temp ocfp-tn 6 ; Move value to correct location.
242 store-stack-tn val4-tn move-temp
244 b :lt default-value-8
245 loadw move-temp ocfp-tn 7
247 store-stack-tn val5-tn move-temp
252 move csp ocfp ; Reset SP.
257 store-stack-tn val4-tn null-tn ; Nil out 7'th value. (first on stack)
260 store-stack-tn val5-tn null-tn ; Nil out 8'th value.
267 (defun default-unknown-values (vop values nvals move-temp temp lra-label)
268 (declare (type (or tn-ref null) values)
269 (type unsigned-byte nvals) (type tn move-temp temp))
272 (without-scheduling ()
273 (note-this-location vop :single-value-return)
274 (move csp-tn ocfp-tn)
276 (inst compute-code-from-lra code-tn code-tn lra-label temp))
277 (let ((regs-defaulted (gen-label))
278 (defaulting-done (gen-label))
279 (default-stack-vals (gen-label)))
280 ;; Branch off to the MV case.
281 (without-scheduling ()
282 (note-this-location vop :unknown-return)
283 (inst b regs-defaulted)
284 (if (> nvals register-arg-count)
285 (inst subcc temp nargs-tn (fixnumize register-arg-count))
286 (move csp-tn ocfp-tn)))
288 ;; Do the single value calse.
290 (val (tn-ref-across values) (tn-ref-across val)))
291 ((= i (min nvals register-arg-count)))
292 (move (tn-ref-tn val) null-tn))
293 (when (> nvals register-arg-count)
294 (inst b default-stack-vals)
295 (move ocfp-tn csp-tn))
297 (emit-label regs-defaulted)
298 (when (> nvals register-arg-count)
299 (collect ((defaults))
300 (do ((i register-arg-count (1+ i))
301 (val (do ((i 0 (1+ i))
302 (val values (tn-ref-across val)))
303 ((= i register-arg-count) val))
304 (tn-ref-across val)))
307 (let ((default-lab (gen-label))
308 (tn (tn-ref-tn val)))
309 (defaults (cons default-lab tn))
311 (inst b :le default-lab)
312 (inst ld move-temp ocfp-tn (* i n-word-bytes))
313 (inst subcc temp (fixnumize 1))
314 (store-stack-tn tn move-temp)))
316 (emit-label defaulting-done)
317 (move csp-tn ocfp-tn)
319 (let ((defaults (defaults)))
321 (assemble (*elsewhere*)
322 (emit-label default-stack-vals)
323 (trace-table-entry trace-table-fun-prologue)
324 (do ((remaining defaults (cdr remaining)))
326 (let ((def (car remaining)))
327 (emit-label (car def))
328 (when (null (cdr remaining))
329 (inst b defaulting-done))
330 (store-stack-tn (cdr def) null-tn)))
331 (trace-table-entry trace-table-normal))))))
333 (inst compute-code-from-lra code-tn code-tn lra-label temp)))
337 ;;; Emit code needed at the return point for an unknown-values call
338 ;;; for an arbitrary number of values.
340 ;;; We do the single and non-single cases with no shared code: there
341 ;;; doesn't seem to be any potential overlap, and receiving a single
342 ;;; value is more important efficiency-wise.
344 ;;; When there is a single value, we just push it on the stack,
345 ;;; returning the old SP and 1.
347 ;;; When there is a variable number of values, we move all of the
348 ;;; argument registers onto the stack, and return ARGS and NARGS.
350 ;;; ARGS and NARGS are TNs wired to the named locations. We must
351 ;;; explicitly allocate these TNs, since their lifetimes overlap with
352 ;;; the results START and COUNT. (Also, it's nice to be able to target
354 (defun receive-unknown-values (args nargs start count lra-label temp)
355 (declare (type tn args nargs start count temp))
356 (let ((variable-values (gen-label))
358 (without-scheduling ()
359 (inst b variable-values)
362 (inst compute-code-from-lra code-tn code-tn lra-label temp)
364 (storew (first *register-arg-tns*) csp-tn -1)
365 (inst sub start csp-tn 4)
366 (inst li count (fixnumize 1))
370 (assemble (*elsewhere*)
371 (trace-table-entry trace-table-fun-prologue)
372 (emit-label variable-values)
373 (inst compute-code-from-lra code-tn code-tn lra-label temp)
374 (do ((arg *register-arg-tns* (rest arg))
377 (storew (first arg) args i))
382 (trace-table-entry trace-table-normal)))
386 ;;; VOP that can be inherited by unknown values receivers. The main
387 ;;; thing this handles is allocation of the result temporaries.
388 (define-vop (unknown-values-receiver)
390 (start :scs (any-reg))
391 (count :scs (any-reg)))
392 (:temporary (:sc descriptor-reg :offset ocfp-offset
393 :from :eval :to (:result 0))
395 (:temporary (:sc any-reg :offset nargs-offset
396 :from :eval :to (:result 1))
398 (:temporary (:scs (non-descriptor-reg)) temp))
402 ;;;; Local call with unknown values convention return:
404 ;;; Non-TR local call for a fixed number of values passed according to the
405 ;;; unknown values convention.
407 ;;; Args are the argument passing locations, which are specified only to
408 ;;; terminate their lifetimes in the caller.
410 ;;; Values are the return value locations (wired to the standard passing
413 ;;; Save is the save info, which we can ignore since saving has been done.
414 ;;; Return-PC is the TN that the return PC should be passed in.
415 ;;; Target is a continuation pointing to the start of the called function.
416 ;;; Nvals is the number of values received.
418 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
419 ;;; registers may be tied up by the more operand. Instead, we use
420 ;;; MAYBE-LOAD-STACK-TN.
421 (define-vop (call-local)
425 (:results (values :more t))
427 (:move-args :local-call)
428 (:info arg-locs callee target nvals)
430 (:temporary (:scs (descriptor-reg) :from (:eval 0)) move-temp)
431 (:temporary (:scs (non-descriptor-reg)) temp)
432 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
433 (:temporary (:sc any-reg :offset ocfp-offset :from (:eval 0)) ocfp)
434 (:ignore arg-locs args ocfp)
436 (trace-table-entry trace-table-call-site)
437 (let ((label (gen-label))
438 (cur-nfp (current-nfp-tn vop)))
440 (store-stack-tn nfp-save cur-nfp))
441 (let ((callee-nfp (callee-nfp-tn callee)))
443 (maybe-load-stack-tn callee-nfp nfp)))
444 (maybe-load-stack-tn cfp-tn fp)
445 (inst compute-lra-from-code
446 (callee-return-pc-tn callee) code-tn label temp)
447 (note-this-location vop :call-site)
450 (emit-return-pc label)
451 (default-unknown-values vop values nvals move-temp temp label)
453 (load-stack-tn cur-nfp nfp-save)))
454 (trace-table-entry trace-table-normal)))
457 ;;; Non-TR local call for a variable number of return values passed according
458 ;;; to the unknown values convention. The results are the start of the values
459 ;;; glob and the number of values received.
461 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
462 ;;; registers may be tied up by the more operand. Instead, we use
463 ;;; MAYBE-LOAD-STACK-TN.
464 (define-vop (multiple-call-local unknown-values-receiver)
469 (:move-args :local-call)
470 (:info save callee target)
473 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
475 (trace-table-entry trace-table-call-site)
476 (let ((label (gen-label))
477 (cur-nfp (current-nfp-tn vop)))
479 (store-stack-tn nfp-save cur-nfp))
480 (let ((callee-nfp (callee-nfp-tn callee)))
482 (maybe-load-stack-tn callee-nfp nfp)))
483 (maybe-load-stack-tn cfp-tn fp)
484 (inst compute-lra-from-code
485 (callee-return-pc-tn callee) code-tn label temp)
486 (note-this-location vop :call-site)
489 (emit-return-pc label)
490 (note-this-location vop :unknown-return)
491 (receive-unknown-values values-start nvals start count label temp)
493 (load-stack-tn cur-nfp nfp-save)))
494 (trace-table-entry trace-table-normal)))
497 ;;;; Local call with known values return:
499 ;;; Non-TR local call with known return locations. Known-value return works
500 ;;; just like argument passing in local call.
502 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
503 ;;; registers may be tied up by the more operand. Instead, we use
504 ;;; MAYBE-LOAD-STACK-TN.
505 (define-vop (known-call-local)
509 (:results (res :more t))
510 (:move-args :local-call)
512 (:info save callee target)
513 (:ignore args res save)
515 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
516 (:temporary (:scs (non-descriptor-reg)) temp)
518 (trace-table-entry trace-table-call-site)
519 (let ((label (gen-label))
520 (cur-nfp (current-nfp-tn vop)))
522 (store-stack-tn nfp-save cur-nfp))
523 (let ((callee-nfp (callee-nfp-tn callee)))
525 (maybe-load-stack-tn callee-nfp nfp)))
526 (maybe-load-stack-tn cfp-tn fp)
527 (inst compute-lra-from-code
528 (callee-return-pc-tn callee) code-tn label temp)
529 (note-this-location vop :call-site)
532 (emit-return-pc label)
533 (note-this-location vop :known-return)
535 (load-stack-tn cur-nfp nfp-save)))
536 (trace-table-entry trace-table-normal)))
538 ;;; Return from known values call. We receive the return locations as
539 ;;; arguments to terminate their lifetimes in the returning function. We
540 ;;; restore FP and CSP and jump to the Return-PC.
542 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
543 ;;; registers may be tied up by the more operand. Instead, we use
544 ;;; MAYBE-LOAD-STACK-TN.
545 (define-vop (known-return)
546 (:args (old-fp :target old-fp-temp)
547 (return-pc :target return-pc-temp)
549 (:temporary (:sc any-reg :from (:argument 0)) old-fp-temp)
550 (:temporary (:sc descriptor-reg :from (:argument 1)) return-pc-temp)
551 (:move-args :known-return)
553 (:ignore val-locs vals)
556 (trace-table-entry trace-table-fun-epilogue)
557 (maybe-load-stack-tn old-fp-temp old-fp)
558 (maybe-load-stack-tn return-pc-temp return-pc)
560 (let ((cur-nfp (current-nfp-tn vop)))
562 (inst add nsp-tn cur-nfp
563 (- (bytes-needed-for-non-descriptor-stack-frame)
564 number-stack-displacement))))
565 (inst j return-pc-temp (- n-word-bytes other-pointer-lowtag))
566 (move cfp-tn old-fp-temp)
567 (trace-table-entry trace-table-normal)))
572 ;;; There is something of a cross-product effect with full calls.
573 ;;; Different versions are used depending on whether we know the
574 ;;; number of arguments or the name of the called function, and
575 ;;; whether we want fixed values, unknown values, or a tail call.
577 ;;; In full call, the arguments are passed creating a partial frame on
578 ;;; the stack top and storing stack arguments into that frame. On
579 ;;; entry to the callee, this partial frame is pointed to by FP. If
580 ;;; there are no stack arguments, we don't bother allocating a partial
581 ;;; frame, and instead set FP to SP just before the call.
583 ;;; This macro helps in the definition of full call VOPs by avoiding code
584 ;;; replication in defining the cross-product VOPs.
586 ;;; Name is the name of the VOP to define.
588 ;;; Named is true if the first argument is a symbol whose global function
589 ;;; definition is to be called.
591 ;;; Return is either :Fixed, :Unknown or :Tail:
592 ;;; -- If :Fixed, then the call is for a fixed number of values, returned in
593 ;;; the standard passing locations (passed as result operands).
594 ;;; -- If :Unknown, then the result values are pushed on the stack, and the
595 ;;; result values are specified by the Start and Count as in the
596 ;;; unknown-values continuation representation.
597 ;;; -- If :Tail, then do a tail-recursive call. No values are returned.
598 ;;; The Old-Fp and Return-PC are passed as the second and third arguments.
600 ;;; In non-tail calls, the pointer to the stack arguments is passed as the last
601 ;;; fixed argument. If Variable is false, then the passing locations are
602 ;;; passed as a more arg. Variable is true if there are a variable number of
603 ;;; arguments passed on the stack. Variable cannot be specified with :Tail
604 ;;; return. TR variable argument call is implemented separately.
606 ;;; In tail call with fixed arguments, the passing locations are passed as a
607 ;;; more arg, but there is no new-FP, since the arguments have been set up in
608 ;;; the current frame.
609 (defmacro define-full-call (name named return variable)
610 (aver (not (and variable (eq return :tail))))
612 ,@(when (eq return :unknown)
613 '(unknown-values-receiver)))
615 ,@(unless (eq return :tail)
616 '((new-fp :scs (any-reg) :to :eval)))
619 '(name :target name-pass)
620 '(arg-fun :target lexenv))
622 ,@(when (eq return :tail)
623 '((old-fp :target old-fp-pass)
624 (return-pc :target return-pc-pass)))
626 ,@(unless variable '((args :more t :scs (descriptor-reg)))))
628 ,@(when (eq return :fixed)
629 '((:results (values :more t))))
631 (:save-p ,(if (eq return :tail) :compute-only t))
633 ,@(unless (or (eq return :tail) variable)
634 '((:move-args :full-call)))
637 (:info ,@(unless (or variable (eq return :tail)) '(arg-locs))
638 ,@(unless variable '(nargs))
639 ,@(when (eq return :fixed) '(nvals))
643 ,@(unless (or variable (eq return :tail)) '(arg-locs))
644 ,@(unless variable '(args)))
646 (:temporary (:sc descriptor-reg
649 ,@(unless (eq return :fixed)
653 (:temporary (:sc descriptor-reg
655 :from (:argument ,(if (eq return :tail) 2 1))
660 `(:temporary (:sc descriptor-reg :offset cname-offset
661 :from (:argument ,(if (eq return :tail) 0 1))
664 `(:temporary (:sc descriptor-reg :offset lexenv-offset
665 :from (:argument ,(if (eq return :tail) 0 1))
669 (:temporary (:scs (descriptor-reg) :from (:argument 0) :to :eval)
671 (:temporary (:sc any-reg :offset nargs-offset :to :eval)
675 (mapcar #'(lambda (name offset)
676 `(:temporary (:sc descriptor-reg
680 register-arg-names *register-arg-offsets*))
681 ,@(when (eq return :fixed)
682 '((:temporary (:scs (descriptor-reg) :from :eval) move-temp)))
684 (:temporary (:scs (descriptor-reg) :to :eval) stepping)
686 ,@(unless (eq return :tail)
687 '((:temporary (:scs (non-descriptor-reg)) temp)
688 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)))
690 (:generator ,(+ (if named 5 0)
692 (if (eq return :tail) 0 10)
694 (if (eq return :unknown) 25 0))
695 (trace-table-entry trace-table-call-site)
696 (let* ((cur-nfp (current-nfp-tn vop))
697 ,@(unless (eq return :tail)
698 '((lra-label (gen-label))))
699 (step-done-label (gen-label))
703 ,@(if (eq return :tail)
704 '((unless (location= old-fp old-fp-pass)
706 (unless (location= return-pc
716 (flet ((do-next-filler ()
717 (let* ((next (pop filler))
718 (what (if (consp next) (car next) next)))
722 `((inst sub nargs-pass csp-tn new-fp)
724 (mapcar #'(lambda (name)
727 register-arg-names)))
728 '((inst li nargs-pass (fixnumize nargs)))))
729 ,@(if (eq return :tail)
733 (inst move old-fp-pass old-fp))
735 (loadw old-fp-pass cfp-tn
736 (tn-offset old-fp)))))
740 (inst move return-pc-pass return-pc))
742 (loadw return-pc-pass cfp-tn
743 (tn-offset return-pc)))))
745 (inst add nsp-tn cur-nfp
746 (- (bytes-needed-for-non-descriptor-stack-frame)
747 number-stack-displacement))))
749 (inst compute-lra-from-code
750 return-pc-pass code-tn lra-label temp))
752 (store-stack-tn nfp-save cur-nfp))
754 (inst move old-fp-pass cfp-tn))
757 '(move cfp-tn new-fp)
758 '(if (> nargs register-arg-count)
760 (move cfp-tn csp-tn))))))
762 (insert-step-instrumenting (callable-tn)
763 ;; Conditionally insert a conditional trap:
764 (when step-instrumenting
765 ;; Get the symbol-value of SB!IMPL::*STEPPING*
766 (load-symbol-value stepping sb!impl::*stepping*)
767 (inst cmp stepping null-tn)
768 ;; If it's not null, trap.
769 (inst b :eq step-done-label)
771 ;; FIXME: this doesn't look right.
772 (note-this-location vop :step-before-vop)
773 ;; Construct a trap code with the low bits from
774 ;; SINGLE-STEP-AROUND-TRAP and the high bits from
775 ;; the register number of CALLABLE-TN.
776 (inst unimp (logior single-step-around-trap
777 (ash (reg-tn-encoding callable-tn)
779 (emit-label step-done-label))))
784 (descriptor-reg (move name-pass name))
786 (loadw name-pass cfp-tn (tn-offset name))
789 (loadw name-pass code-tn (tn-offset name)
790 other-pointer-lowtag)
792 (insert-step-instrumenting name-pass)
793 (loadw function name-pass fdefn-raw-addr-slot
794 other-pointer-lowtag)
797 (descriptor-reg (move lexenv arg-fun))
799 (loadw lexenv cfp-tn (tn-offset arg-fun))
802 (loadw lexenv code-tn (tn-offset arg-fun)
803 other-pointer-lowtag)
805 (loadw function lexenv closure-fun-slot
808 (insert-step-instrumenting function)))
814 (note-this-location vop :call-site)
816 (- (ash simple-fun-code-offset word-shift)
818 (inst move code-tn function))
822 '((emit-return-pc lra-label)
823 (default-unknown-values vop values nvals move-temp
826 (load-stack-tn cur-nfp nfp-save))))
828 '((emit-return-pc lra-label)
829 (note-this-location vop :unknown-return)
830 (receive-unknown-values values-start nvals start count
833 (load-stack-tn cur-nfp nfp-save))))
835 (trace-table-entry trace-table-normal))))
838 (define-full-call call nil :fixed nil)
839 (define-full-call call-named t :fixed nil)
840 (define-full-call multiple-call nil :unknown nil)
841 (define-full-call multiple-call-named t :unknown nil)
842 (define-full-call tail-call nil :tail nil)
843 (define-full-call tail-call-named t :tail nil)
845 (define-full-call call-variable nil :fixed t)
846 (define-full-call multiple-call-variable nil :unknown t)
849 ;;; Defined separately, since needs special code that BLT's the
851 (define-vop (tail-call-variable)
853 (args-arg :scs (any-reg) :target args)
854 (function-arg :scs (descriptor-reg) :target lexenv)
855 (old-fp-arg :scs (any-reg) :target old-fp)
856 (lra-arg :scs (descriptor-reg) :target lra))
858 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 0)) args)
859 (:temporary (:sc any-reg :offset lexenv-offset :from (:argument 1)) lexenv)
860 (:temporary (:sc any-reg :offset ocfp-offset :from (:argument 2)) old-fp)
861 (:temporary (:sc any-reg :offset lra-offset :from (:argument 3)) lra)
863 (:temporary (:scs (any-reg) :from :eval) temp)
869 ;; Move these into the passing locations if they are not already there.
871 (move lexenv function-arg)
872 (move old-fp old-fp-arg)
875 ;; Clear the number stack if anything is there.
876 (let ((cur-nfp (current-nfp-tn vop)))
878 (inst add nsp-tn cur-nfp
879 (- (bytes-needed-for-non-descriptor-stack-frame)
880 number-stack-displacement))))
882 ;; And jump to the assembly-routine that does the bliting.
883 (inst ji temp (make-fixup 'tail-call-variable :assembly-routine))
887 ;;;; Unknown values return:
890 ;;; Return a single value using the unknown-values convention.
891 (define-vop (return-single)
892 (:args (old-fp :scs (any-reg))
893 (return-pc :scs (descriptor-reg))
898 (trace-table-entry trace-table-fun-epilogue)
899 ;; Clear the number stack.
900 (let ((cur-nfp (current-nfp-tn vop)))
902 (inst add nsp-tn cur-nfp
903 (- (bytes-needed-for-non-descriptor-stack-frame)
904 number-stack-displacement))))
905 ;; Clear the control stack, and restore the frame pointer.
909 (lisp-return return-pc :offset 2)
910 (trace-table-entry trace-table-normal)))
912 ;;; Do unknown-values return of a fixed number of values. The Values are
913 ;;; required to be set up in the standard passing locations. Nvals is the
914 ;;; number of values returned.
916 ;;; If returning a single value, then deallocate the current frame, restore
917 ;;; FP and jump to the single-value entry at Return-PC + 8.
919 ;;; If returning other than one value, then load the number of values returned,
920 ;;; NIL out unsupplied values registers, restore FP and return at Return-PC.
921 ;;; When there are stack values, we must initialize the argument pointer to
922 ;;; point to the beginning of the values block (which is the beginning of the
926 (old-fp :scs (any-reg))
927 (return-pc :scs (descriptor-reg) :to (:eval 1))
931 (:temporary (:sc descriptor-reg :offset a0-offset :from (:eval 0)) a0)
932 (:temporary (:sc descriptor-reg :offset a1-offset :from (:eval 0)) a1)
933 (:temporary (:sc descriptor-reg :offset a2-offset :from (:eval 0)) a2)
934 (:temporary (:sc descriptor-reg :offset a3-offset :from (:eval 0)) a3)
935 (:temporary (:sc descriptor-reg :offset a4-offset :from (:eval 0)) a4)
936 (:temporary (:sc descriptor-reg :offset a5-offset :from (:eval 0)) a5)
937 (:temporary (:sc any-reg :offset nargs-offset) nargs)
938 (:temporary (:sc any-reg :offset ocfp-offset) val-ptr)
941 (trace-table-entry trace-table-fun-epilogue)
942 ;; Clear the number stack.
943 (let ((cur-nfp (current-nfp-tn vop)))
945 (inst add nsp-tn cur-nfp
946 (- (bytes-needed-for-non-descriptor-stack-frame)
947 number-stack-displacement))))
949 ;; Clear the control stack, and restore the frame pointer.
953 (lisp-return return-pc :offset 2))
955 ;; Establish the values pointer and values count.
956 (move val-ptr cfp-tn)
957 (inst li nargs (fixnumize nvals))
958 ;; restore the frame pointer and clear as much of the control
959 ;; stack as possible.
961 (inst add csp-tn val-ptr (* nvals n-word-bytes))
962 ;; pre-default any argument register that need it.
963 (when (< nvals register-arg-count)
964 (dolist (reg (subseq (list a0 a1 a2 a3 a4 a5) nvals))
967 (lisp-return return-pc)))
968 (trace-table-entry trace-table-normal)))
970 ;;; Do unknown-values return of an arbitrary number of values (passed on the
971 ;;; stack.) We check for the common case of a single return value, and do that
972 ;;; inline using the normal single value return convention. Otherwise, we
973 ;;; branch off to code that calls an assembly-routine.
974 (define-vop (return-multiple)
976 (old-fp-arg :scs (any-reg) :to (:eval 1))
977 (lra-arg :scs (descriptor-reg) :to (:eval 1))
978 (vals-arg :scs (any-reg) :target vals)
979 (nvals-arg :scs (any-reg) :target nvals))
981 (:temporary (:sc any-reg :offset nl1-offset :from (:argument 0)) old-fp)
982 (:temporary (:sc descriptor-reg :offset lra-offset :from (:argument 1)) lra)
983 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 2)) vals)
984 (:temporary (:sc any-reg :offset nargs-offset :from (:argument 3)) nvals)
985 (:temporary (:sc descriptor-reg :offset a0-offset) a0)
987 (:temporary (:scs (any-reg) :from (:eval 1)) temp)
992 (trace-table-entry trace-table-fun-epilogue)
993 (let ((not-single (gen-label)))
994 ;; Clear the number stack.
995 (let ((cur-nfp (current-nfp-tn vop)))
997 (inst add nsp-tn cur-nfp
998 (- (bytes-needed-for-non-descriptor-stack-frame)
999 number-stack-displacement))))
1001 ;; Check for the single case.
1002 (inst cmp nvals-arg (fixnumize 1))
1003 (inst b :ne not-single)
1004 (inst ld a0 vals-arg)
1006 ;; Return with one value.
1007 (move csp-tn cfp-tn)
1008 (move cfp-tn old-fp-arg)
1009 (lisp-return lra-arg :offset 2)
1011 ;; Nope, not the single case.
1012 (emit-label not-single)
1013 (move old-fp old-fp-arg)
1015 (move vals vals-arg)
1016 (move nvals nvals-arg)
1017 (inst ji temp (make-fixup 'return-multiple :assembly-routine))
1019 (trace-table-entry trace-table-normal)))
1026 ;;; We don't need to do anything special for regular functions.
1027 (define-vop (setup-environment)
1031 ;; Don't bother doing anything.
1034 ;;; Get the lexical environment from it's passing location.
1035 (define-vop (setup-closure-environment)
1036 (:temporary (:sc descriptor-reg :offset lexenv-offset :target closure
1039 (:results (closure :scs (descriptor-reg)))
1044 (move closure lexenv)))
1046 ;;; Copy a more arg from the argument area to the end of the current frame.
1047 ;;; Fixed is the number of non-more arguments.
1048 (define-vop (copy-more-arg)
1049 (:temporary (:sc any-reg :offset nl0-offset) result)
1050 (:temporary (:sc any-reg :offset nl1-offset) count)
1051 (:temporary (:sc any-reg :offset nl2-offset) src)
1052 (:temporary (:sc any-reg :offset nl3-offset) dst)
1053 (:temporary (:sc descriptor-reg :offset l0-offset) temp)
1056 (let ((loop (gen-label))
1057 (do-regs (gen-label))
1059 (when (< fixed register-arg-count)
1060 ;; Save a pointer to the results so we can fill in register args.
1061 ;; We don't need this if there are more fixed args than reg args.
1062 (move result csp-tn))
1063 ;; Allocate the space on the stack.
1064 (cond ((zerop fixed)
1067 (inst add csp-tn csp-tn nargs-tn))
1069 (inst subcc count nargs-tn (fixnumize fixed))
1072 (inst add csp-tn csp-tn count)))
1073 (when (< fixed register-arg-count)
1074 ;; We must stop when we run out of stack args, not when we run out of
1076 (inst subcc count nargs-tn (fixnumize register-arg-count))
1077 ;; Everything of interest in registers.
1078 (inst b :le do-regs))
1079 ;; Initialize dst to be end of stack.
1081 ;; Initialize src to be end of args.
1082 (inst add src cfp-tn nargs-tn)
1085 ;; *--dst = *--src, --count
1086 (inst add src src (- n-word-bytes))
1087 (inst subcc count count (fixnumize 1))
1089 (inst add dst dst (- n-word-bytes))
1093 (emit-label do-regs)
1094 (when (< fixed register-arg-count)
1095 ;; Now we have to deposit any more args that showed up in registers.
1096 (inst subcc count nargs-tn (fixnumize fixed))
1097 (do ((i fixed (1+ i)))
1098 ((>= i register-arg-count))
1099 ;; Don't deposit any more than there are.
1101 (inst subcc count (fixnumize 1))
1102 ;; Store it relative to the pointer saved at the start.
1103 (storew (nth i *register-arg-tns*) result (- i fixed))))
1104 (emit-label done))))
1107 ;;; More args are stored consequtively on the stack, starting immediately at
1108 ;;; the context pointer. The context pointer is not typed, so the lowtag is 0.
1109 (define-vop (more-arg word-index-ref)
1111 (:translate %more-arg))
1113 ;;; Turn more arg (context, count) into a list.
1114 (define-vop (listify-rest-args)
1115 (:args (context-arg :target context :scs (descriptor-reg))
1116 (count-arg :target count :scs (any-reg)))
1117 (:arg-types * tagged-num)
1118 (:temporary (:scs (any-reg) :from (:argument 0)) context)
1119 (:temporary (:scs (any-reg) :from (:argument 1)) count)
1120 (:temporary (:scs (descriptor-reg) :from :eval) temp)
1121 (:temporary (:scs (non-descriptor-reg) :from :eval) dst)
1122 (:results (result :scs (descriptor-reg)))
1123 (:translate %listify-rest-args)
1127 (let* ((enter (gen-label))
1130 (dx-p (node-stack-allocate-p node))
1131 (alloc-area-tn (if dx-p csp-tn alloc-tn)))
1132 (move context context-arg)
1133 (move count count-arg)
1134 ;; Check to see if there are any arguments.
1137 (move result null-tn)
1139 ;; We need to do this atomically.
1143 ;; Allocate a cons (2 words) for each item.
1144 (inst andn result alloc-area-tn lowtag-mask)
1145 (inst or result list-pointer-lowtag)
1147 (inst sll temp count 1)
1149 (inst add alloc-area-tn temp)
1151 ;; Compute the next cons and store it in the current one.
1153 (inst add dst dst (* 2 n-word-bytes))
1154 (storew dst dst -1 list-pointer-lowtag)
1158 (loadw temp context)
1159 (inst add context context n-word-bytes)
1161 ;; Dec count, and if != zero, go back for more.
1162 (inst subcc count (fixnumize 1))
1165 ;; Store the value into the car of the current cons (in the delay
1167 (storew temp dst 0 list-pointer-lowtag)
1169 ;; NIL out the last cons.
1170 (storew null-tn dst 1 list-pointer-lowtag))
1171 (emit-label done))))
1174 ;;; Return the location and size of the more arg glob created by Copy-More-Arg.
1175 ;;; Supplied is the total number of arguments supplied (originally passed in
1176 ;;; NARGS.) Fixed is the number of non-rest arguments.
1178 ;;; We must duplicate some of the work done by Copy-More-Arg, since at that
1179 ;;; time the environment is in a pretty brain-damaged state, preventing this
1180 ;;; info from being returned as values. What we do is compute
1181 ;;; supplied - fixed, and return a pointer that many words below the current
1183 (define-vop (more-arg-context)
1184 (:policy :fast-safe)
1185 (:translate sb!c::%more-arg-context)
1186 (:args (supplied :scs (any-reg)))
1187 (:arg-types tagged-num (:constant fixnum))
1189 (:results (context :scs (descriptor-reg))
1190 (count :scs (any-reg)))
1191 (:result-types t tagged-num)
1192 (:note "more-arg-context")
1194 (inst sub count supplied (fixnumize fixed))
1195 (inst sub context csp-tn count)))
1198 ;;; Signal wrong argument count error if Nargs isn't = to Count.
1200 (define-vop (verify-arg-count)
1201 (:policy :fast-safe)
1202 (:translate sb!c::%verify-arg-count)
1203 (:args (nargs :scs (any-reg)))
1204 (:arg-types positive-fixnum (:constant t))
1207 (:save-p :compute-only)
1210 (generate-error-code vop invalid-arg-count-error nargs)))
1211 (inst cmp nargs (fixnumize count))
1212 (if (member :sparc-v9 *backend-subfeatures*)
1213 ;; Assume we don't take the branch
1214 (inst b :ne err-lab :pn)
1215 (inst b :ne err-lab))
1218 ;;; Signal various errors.
1219 (macrolet ((frob (name error translate &rest args)
1220 `(define-vop (,name)
1222 `((:policy :fast-safe)
1223 (:translate ,translate)))
1224 (:args ,@(mapcar #'(lambda (arg)
1225 `(,arg :scs (any-reg descriptor-reg)))
1228 (:save-p :compute-only)
1230 (error-call vop ,error ,@args)))))
1231 (frob arg-count-error invalid-arg-count-error
1232 sb!c::%arg-count-error nargs)
1233 (frob type-check-error object-not-type-error sb!c::%type-check-error
1235 (frob layout-invalid-error layout-invalid-error sb!c::%layout-invalid-error
1237 (frob odd-key-args-error odd-key-args-error
1238 sb!c::%odd-key-args-error)
1239 (frob unknown-key-arg-error unknown-key-arg-error
1240 sb!c::%unknown-key-arg-error key)
1241 (frob nil-fun-returned-error nil-fun-returned-error nil fun))
1245 (define-vop (step-instrument-before-vop)
1246 (:temporary (:scs (descriptor-reg)) stepping)
1247 (:policy :fast-safe)
1250 (load-symbol-value stepping sb!impl::*stepping*)
1251 (inst cmp stepping null-tn)
1254 (note-this-location vop :step-before-vop)
1255 (inst unimp single-step-before-trap)