1 ;;;; the VM definition of function call for the PPC
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.
14 ;;;; Interfaces to IR2 conversion:
16 ;;; 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
33 (!def-vm-support-routine make-return-pc-passing-location (standard)
35 (make-wired-tn *backend-t-primitive-type* register-arg-scn lra-offset)
36 (make-restricted-tn *backend-t-primitive-type* register-arg-scn)))
38 ;;; Make-Old-FP-Passing-Location -- Interface
40 ;;; Similar to Make-Return-PC-Passing-Location, but makes a location to pass
41 ;;; Old-FP in. This is (obviously) wired in the standard convention, but is
42 ;;; totally unrestricted in non-standard conventions, since we can always fetch
43 ;;; it off of the stack using the arg pointer.
45 (!def-vm-support-routine make-old-fp-passing-location (standard)
47 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn ocfp-offset)
48 (make-normal-tn *fixnum-primitive-type*)))
50 ;;; Make-Old-FP-Save-Location, Make-Return-PC-Save-Location -- Interface
52 ;;; Make the TNs used to hold Old-FP and Return-PC within the current
53 ;;; function. We treat these specially so that the debugger can find them at a
56 (!def-vm-support-routine make-old-fp-save-location (env)
58 (physenv-debug-live-tn (make-normal-tn *fixnum-primitive-type*) env)
59 (make-wired-tn *fixnum-primitive-type*
63 (!def-vm-support-routine make-return-pc-save-location (env)
65 (physenv-debug-live-tn (make-normal-tn *backend-t-primitive-type*) env)
66 (make-wired-tn *backend-t-primitive-type*
70 ;;; Make a TN for the standard argument count passing location. We
71 ;;; only need to make the standard location, since a count is never
72 ;;; passed when we are using non-standard conventions.
73 (!def-vm-support-routine make-arg-count-location ()
74 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn nargs-offset))
77 ;;; Make a TN to hold the number-stack frame pointer. This is
78 ;;; allocated once per component, and is component-live.
79 (!def-vm-support-routine make-nfp-tn ()
81 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn nfp-offset)))
83 (!def-vm-support-routine make-stack-pointer-tn ()
84 (make-normal-tn *fixnum-primitive-type*))
86 (!def-vm-support-routine make-number-stack-pointer-tn ()
87 (make-normal-tn *fixnum-primitive-type*))
89 ;;; Make-Unknown-Values-Locations -- Interface
91 ;;; Return a list of TNs that can be used to represent an unknown-values
92 ;;; continuation within a function.
94 (!def-vm-support-routine make-unknown-values-locations ()
95 (list (make-stack-pointer-tn)
96 (make-normal-tn *fixnum-primitive-type*)))
99 ;;; Select-Component-Format -- Interface
101 ;;; This function is called by the Entry-Analyze phase, allowing
102 ;;; VM-dependent initialization of the IR2-Component structure. We push
103 ;;; placeholder entries in the Constants to leave room for additional
104 ;;; noise in the code object header.
106 (!def-vm-support-routine select-component-format (component)
107 (declare (type component component))
108 (dotimes (i code-constants-offset)
109 (vector-push-extend nil
110 (ir2-component-constants (component-info component))))
116 ;;; Return the number of bytes needed for the current non-descriptor stack
117 ;;; frame. Non-descriptor stack frames must be multiples of 16 bytes under
118 ;;; the PPC SVr4 ABI (though the EABI may be less restrictive.) Two words
119 ;;; are reserved for the stack backlink and saved LR (see SB!VM::NUMBER-STACK-
122 ;;; Duh. PPC Linux (and VxWorks) adhere to the EABI.
124 ;;; this is the first function in this file that differs materially from
125 ;;; ../alpha/call.lisp
126 (defun bytes-needed-for-non-descriptor-stack-frame ()
127 (logandc2 (+ 7 number-stack-displacement
128 (* (sb-allocated-size 'non-descriptor-stack) sb!vm:n-word-bytes))
132 ;;; Used for setting up the Old-FP in local call.
134 (define-vop (current-fp)
135 (:results (val :scs (any-reg)))
139 ;;; Used for computing the caller's NFP for use in known-values return. Only
140 ;;; works assuming there is no variable size stuff on the nstack.
142 (define-vop (compute-old-nfp)
143 (:results (val :scs (any-reg)))
146 (let ((nfp (current-nfp-tn vop)))
148 (inst addi val nfp (bytes-needed-for-non-descriptor-stack-frame))))))
151 (define-vop (xep-allocate-frame)
152 (:info start-lab copy-more-arg-follows)
153 (:ignore copy-more-arg-follows)
155 (:temporary (:scs (non-descriptor-reg)) temp)
157 ;; Make sure the function is aligned, and drop a label pointing to this
159 (align n-lowtag-bits)
160 (trace-table-entry trace-table-fun-prologue)
161 (emit-label start-lab)
162 ;; Allocate function header.
163 (inst simple-fun-header-word)
164 (dotimes (i (1- sb!vm:simple-fun-code-offset))
166 (let* ((entry-point (gen-label)))
167 (emit-label entry-point)
168 (inst compute-code-from-fn code-tn lip-tn entry-point temp))
169 ;; FIXME alpha port has a ### note here saying we should "save it
170 ;; on the stack" so that GC sees it. No idea what "it" is -dan 20020110
171 ;; Build our stack frames.
172 (inst addi csp-tn cfp-tn
173 (* n-word-bytes (sb-allocated-size 'control-stack)))
174 (let ((nfp-tn (current-nfp-tn vop)))
176 (let* ((nbytes (bytes-needed-for-non-descriptor-stack-frame)))
177 (when (> nbytes number-stack-displacement)
178 (inst stwu nsp-tn nsp-tn (- nbytes))
179 (inst addi nfp-tn nsp-tn number-stack-displacement)))))
180 (trace-table-entry trace-table-normal)))
182 (define-vop (allocate-frame)
183 (:results (res :scs (any-reg))
184 (nfp :scs (any-reg)))
187 (trace-table-entry trace-table-fun-prologue)
189 (inst addi csp-tn csp-tn
190 (* n-word-bytes (sb-allocated-size 'control-stack)))
191 (when (ir2-physenv-number-stack-p callee)
192 (let* ((nbytes (bytes-needed-for-non-descriptor-stack-frame)))
193 (when (> nbytes number-stack-displacement)
194 (inst stwu nsp-tn nsp-tn (- (bytes-needed-for-non-descriptor-stack-frame)))
195 (inst addi nfp nsp-tn number-stack-displacement))))
196 (trace-table-entry trace-table-normal)))
198 ;;; Allocate a partial frame for passing stack arguments in a full call. Nargs
199 ;;; is the number of arguments passed. If no stack arguments are passed, then
200 ;;; we don't have to do anything.
202 (define-vop (allocate-full-call-frame)
204 (:results (res :scs (any-reg)))
206 (when (> nargs register-arg-count)
208 (inst addi csp-tn csp-tn (* nargs n-word-bytes)))))
211 ;;; Emit code needed at the return-point from an unknown-values call
212 ;;; for a fixed number of values. Values is the head of the TN-Ref
213 ;;; list for the locations that the values are to be received into.
214 ;;; Nvals is the number of values that are to be received (should
215 ;;; equal the length of Values).
217 ;;; Move-Temp is a Descriptor-Reg TN used as a temporary.
219 ;;; This code exploits the fact that in the unknown-values convention,
220 ;;; a single value return returns at the return PC + 8, whereas a
221 ;;; return of other than one value returns directly at the return PC.
223 ;;; If 0 or 1 values are expected, then we just emit an instruction to
224 ;;; reset the SP (which will only be executed when other than 1 value
227 ;;; In the general case, we have to do three things:
228 ;;; -- Default unsupplied register values. This need only be done when a
229 ;;; single value is returned, since register values are defaulted by the
230 ;;; callee in the non-single case.
231 ;;; -- Default unsupplied stack values. This needs to be done whenever there
232 ;;; are stack values.
233 ;;; -- Reset SP. This must be done whenever other than 1 value is returned,
234 ;;; regardless of the number of values desired.
236 ;;; The general-case code looks like this:
238 b regs-defaulted ; Skip if MVs
241 move a1 null-tn ; Default register values
243 loadi nargs 1 ; Force defaulting of stack values
244 move old-fp csp ; Set up args for SP resetting
247 subcc temp nargs register-arg-count
249 b :lt default-value-7 ; jump to default code
250 loadw move-temp ocfp-tn 6 ; Move value to correct location.
252 store-stack-tn val4-tn move-temp
254 b :lt default-value-8
255 loadw move-temp ocfp-tn 7
257 store-stack-tn val5-tn move-temp
262 move csp ocfp ; Reset SP.
267 store-stack-tn val4-tn null-tn ; Nil out 7'th value. (first on stack)
270 store-stack-tn val5-tn null-tn ; Nil out 8'th value.
277 ;;; differences from alpha: (1) alpha tests for lra-label before
278 ;;; compute-code-from-lra and skips if nil. (2) loop termination is
279 ;;; different when clearing stack defaults
281 (defun default-unknown-values (vop values nvals move-temp temp lra-label)
282 (declare (type (or tn-ref null) values)
283 (type unsigned-byte nvals) (type tn move-temp temp))
286 (sb!assem:without-scheduling ()
287 (note-this-location vop :single-value-return)
288 (move csp-tn ocfp-tn)
290 (inst compute-code-from-lra code-tn code-tn lra-label temp))
291 (let ((regs-defaulted (gen-label))
292 (defaulting-done (gen-label))
293 (default-stack-vals (gen-label)))
294 ;; Branch off to the MV case.
295 (sb!assem:without-scheduling ()
296 (note-this-location vop :unknown-return)
297 (if (> nvals register-arg-count)
298 (inst addic. temp nargs-tn (- (fixnumize register-arg-count)))
299 (move csp-tn ocfp-tn))
300 (inst b regs-defaulted))
302 ;; Do the single value case.
304 (val (tn-ref-across values) (tn-ref-across val)))
305 ((= i (min nvals register-arg-count)))
306 (move (tn-ref-tn val) null-tn))
307 (when (> nvals register-arg-count)
308 (move ocfp-tn csp-tn)
309 (inst b default-stack-vals))
311 (emit-label regs-defaulted)
312 (when (> nvals register-arg-count)
313 (collect ((defaults))
314 (do ((i register-arg-count (1+ i))
315 (val (do ((i 0 (1+ i))
316 (val values (tn-ref-across val)))
317 ((= i register-arg-count) val))
318 (tn-ref-across val)))
321 (let ((default-lab (gen-label))
322 (tn (tn-ref-tn val)))
323 (defaults (cons default-lab tn))
325 (inst lwz move-temp ocfp-tn (* i n-word-bytes))
326 (inst ble default-lab)
327 (inst addic. temp temp (- (fixnumize 1)))
328 (store-stack-tn tn move-temp)))
330 (emit-label defaulting-done)
331 (move csp-tn ocfp-tn)
333 (let ((defaults (defaults)))
335 (assemble (*elsewhere*)
336 (emit-label default-stack-vals)
337 (trace-table-entry trace-table-fun-prologue)
338 (do ((remaining defaults (cdr remaining)))
340 (let ((def (car remaining)))
341 (emit-label (car def))
342 (when (null (cdr remaining))
343 (inst b defaulting-done))
344 (store-stack-tn (cdr def) null-tn)))
345 (trace-table-entry trace-table-normal))))))
347 (inst compute-code-from-lra code-tn code-tn lra-label temp)))
351 ;;;; Unknown values receiving:
353 ;;; Receive-Unknown-Values -- Internal
355 ;;; Emit code needed at the return point for an unknown-values call for an
356 ;;; arbitrary number of values.
358 ;;; We do the single and non-single cases with no shared code: there doesn't
359 ;;; seem to be any potential overlap, and receiving a single value is more
360 ;;; important efficiency-wise.
362 ;;; When there is a single value, we just push it on the stack, returning
363 ;;; the old SP and 1.
365 ;;; When there is a variable number of values, we move all of the argument
366 ;;; registers onto the stack, and return Args and Nargs.
368 ;;; Args and Nargs are TNs wired to the named locations. We must
369 ;;; explicitly allocate these TNs, since their lifetimes overlap with the
370 ;;; results Start and Count (also, it's nice to be able to target them).
372 (defun receive-unknown-values (args nargs start count lra-label temp)
373 (declare (type tn args nargs start count temp))
374 (let ((variable-values (gen-label))
376 (sb!assem:without-scheduling ()
377 (inst b variable-values)
380 (inst compute-code-from-lra code-tn code-tn lra-label temp)
381 (inst addi csp-tn csp-tn 4)
382 (storew (first *register-arg-tns*) csp-tn -1)
383 (inst subi start csp-tn 4)
384 (inst li count (fixnumize 1))
388 (assemble (*elsewhere*)
389 (trace-table-entry trace-table-fun-prologue)
390 (emit-label variable-values)
391 (inst compute-code-from-lra code-tn code-tn lra-label temp)
392 (do ((arg *register-arg-tns* (rest arg))
395 (storew (first arg) args i))
399 (trace-table-entry trace-table-normal)))
403 ;;; VOP that can be inherited by unknown values receivers. The main thing this
404 ;;; handles is allocation of the result temporaries.
406 (define-vop (unknown-values-receiver)
408 (start :scs (any-reg))
409 (count :scs (any-reg)))
410 (:temporary (:sc descriptor-reg :offset ocfp-offset
411 :from :eval :to (:result 0))
413 (:temporary (:sc any-reg :offset nargs-offset
414 :from :eval :to (:result 1))
416 (:temporary (:scs (non-descriptor-reg)) temp))
420 ;;;; Local call with unknown values convention return:
422 ;;; Non-TR local call for a fixed number of values passed according to the
423 ;;; unknown values convention.
425 ;;; Args are the argument passing locations, which are specified only to
426 ;;; terminate their lifetimes in the caller.
428 ;;; Values are the return value locations (wired to the standard passing
431 ;;; Save is the save info, which we can ignore since saving has been done.
432 ;;; Return-PC is the TN that the return PC should be passed in.
433 ;;; Target is a continuation pointing to the start of the called function.
434 ;;; Nvals is the number of values received.
436 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
437 ;;; registers may be tied up by the more operand. Instead, we use
438 ;;; MAYBE-LOAD-STACK-TN.
440 (define-vop (call-local)
444 (:results (values :more t))
446 (:move-args :local-call)
447 (:info arg-locs callee target nvals)
449 (:temporary (:scs (descriptor-reg) :from (:eval 0)) move-temp)
450 (:temporary (:scs (non-descriptor-reg)) temp)
451 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
452 (:temporary (:sc any-reg :offset ocfp-offset :from (:eval 0)) ocfp)
453 (:ignore arg-locs args ocfp)
455 (trace-table-entry trace-table-call-site)
456 (let ((label (gen-label))
457 (cur-nfp (current-nfp-tn vop)))
459 (store-stack-tn nfp-save cur-nfp))
460 (let ((callee-nfp (callee-nfp-tn callee)))
462 (maybe-load-stack-tn callee-nfp nfp)))
463 (maybe-load-stack-tn cfp-tn fp)
464 (inst compute-lra-from-code
465 (callee-return-pc-tn callee) code-tn label temp)
466 (note-this-location vop :call-site)
468 (emit-return-pc label)
469 (default-unknown-values vop values nvals move-temp temp label)
470 ;; alpha uses (maybe-load-stack-nfp-tn cur-nfp nfp-save temp)
471 ;; instead of the clause below
473 (load-stack-tn cur-nfp nfp-save)))
474 (trace-table-entry trace-table-normal)))
477 ;;; Non-TR local call for a variable number of return values passed according
478 ;;; to the unknown values convention. The results are the start of the values
479 ;;; glob and the number of values received.
481 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
482 ;;; registers may be tied up by the more operand. Instead, we use
483 ;;; MAYBE-LOAD-STACK-TN.
485 (define-vop (multiple-call-local unknown-values-receiver)
490 (:move-args :local-call)
491 (:info save callee target)
494 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
495 (:temporary (:scs (non-descriptor-reg)) temp)
497 (trace-table-entry trace-table-call-site)
498 (let ((label (gen-label))
499 (cur-nfp (current-nfp-tn vop)))
501 (store-stack-tn nfp-save cur-nfp))
502 (let ((callee-nfp (callee-nfp-tn callee)))
503 ;; alpha doesn't test this before the maybe-load
505 (maybe-load-stack-tn callee-nfp nfp)))
506 (maybe-load-stack-tn cfp-tn fp)
507 (inst compute-lra-from-code
508 (callee-return-pc-tn callee) code-tn label temp)
509 (note-this-location vop :call-site)
511 (emit-return-pc label)
512 (note-this-location vop :unknown-return)
513 (receive-unknown-values values-start nvals start count label temp)
515 (load-stack-tn cur-nfp nfp-save)))
516 (trace-table-entry trace-table-normal)))
519 ;;;; Local call with known values return:
521 ;;; Non-TR local call with known return locations. Known-value return works
522 ;;; just like argument passing in local call.
524 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
525 ;;; registers may be tied up by the more operand. Instead, we use
526 ;;; MAYBE-LOAD-STACK-TN.
528 (define-vop (known-call-local)
532 (:results (res :more t))
533 (:move-args :local-call)
535 (:info save callee target)
536 (:ignore args res save)
538 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
539 (:temporary (:scs (non-descriptor-reg)) temp)
541 (trace-table-entry trace-table-call-site)
542 (let ((label (gen-label))
543 (cur-nfp (current-nfp-tn vop)))
545 (store-stack-tn nfp-save cur-nfp))
546 (let ((callee-nfp (callee-nfp-tn callee)))
548 (maybe-load-stack-tn callee-nfp nfp)))
549 (maybe-load-stack-tn cfp-tn fp)
550 (inst compute-lra-from-code
551 (callee-return-pc-tn callee) code-tn label temp)
552 (note-this-location vop :call-site)
554 (emit-return-pc label)
555 (note-this-location vop :known-return)
557 (load-stack-tn cur-nfp nfp-save)))
558 (trace-table-entry trace-table-normal)))
560 ;;; Return from known values call. We receive the return locations as
561 ;;; arguments to terminate their lifetimes in the returning function. We
562 ;;; restore FP and CSP and jump to the Return-PC.
564 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
565 ;;; registers may be tied up by the more operand. Instead, we use
566 ;;; MAYBE-LOAD-STACK-TN.
568 (define-vop (known-return)
569 (:args (old-fp :target old-fp-temp)
570 (return-pc :target return-pc-temp)
572 (:temporary (:sc any-reg :from (:argument 0)) old-fp-temp)
573 (:temporary (:sc descriptor-reg :from (:argument 1)) return-pc-temp)
574 (:move-args :known-return)
576 (:ignore val-locs vals)
579 (trace-table-entry trace-table-fun-epilogue)
580 (maybe-load-stack-tn old-fp-temp old-fp)
581 (maybe-load-stack-tn return-pc-temp return-pc)
583 (let ((cur-nfp (current-nfp-tn vop)))
585 (inst addi nsp-tn cur-nfp
586 (- (bytes-needed-for-non-descriptor-stack-frame)
587 number-stack-displacement))))
588 (move cfp-tn old-fp-temp)
589 (inst j return-pc-temp (- n-word-bytes other-pointer-lowtag))
590 (trace-table-entry trace-table-normal)))
595 ;;; There is something of a cross-product effect with full calls. Different
596 ;;; versions are used depending on whether we know the number of arguments or
597 ;;; the name of the called function, and whether we want fixed values, unknown
598 ;;; values, or a tail call.
600 ;;; In full call, the arguments are passed creating a partial frame on the
601 ;;; stack top and storing stack arguments into that frame. On entry to the
602 ;;; callee, this partial frame is pointed to by FP. If there are no stack
603 ;;; arguments, we don't bother allocating a partial frame, and instead set FP
604 ;;; to SP just before the call.
606 ;;; Define-Full-Call -- Internal
608 ;;; This macro helps in the definition of full call VOPs by avoiding code
609 ;;; replication in defining the cross-product VOPs.
611 ;;; Name is the name of the VOP to define.
613 ;;; Named is true if the first argument is a symbol whose global function
614 ;;; definition is to be called.
616 ;;; Return is either :Fixed, :Unknown or :Tail:
617 ;;; -- If :Fixed, then the call is for a fixed number of values, returned in
618 ;;; the standard passing locations (passed as result operands).
619 ;;; -- If :Unknown, then the result values are pushed on the stack, and the
620 ;;; result values are specified by the Start and Count as in the
621 ;;; unknown-values continuation representation.
622 ;;; -- If :Tail, then do a tail-recursive call. No values are returned.
623 ;;; The Old-Fp and Return-PC are passed as the second and third arguments.
625 ;;; In non-tail calls, the pointer to the stack arguments is passed as the last
626 ;;; fixed argument. If Variable is false, then the passing locations are
627 ;;; passed as a more arg. Variable is true if there are a variable number of
628 ;;; arguments passed on the stack. Variable cannot be specified with :Tail
629 ;;; return. TR variable argument call is implemented separately.
631 ;;; In tail call with fixed arguments, the passing locations are passed as a
632 ;;; more arg, but there is no new-FP, since the arguments have been set up in
633 ;;; the current frame.
635 (defmacro define-full-call (name named return variable)
636 (assert (not (and variable (eq return :tail))))
638 ,@(when (eq return :unknown)
639 '(unknown-values-receiver)))
641 ,@(unless (eq return :tail)
642 '((new-fp :scs (any-reg) :to :eval)))
645 '(name :target name-pass)
646 '(arg-fun :target lexenv))
648 ,@(when (eq return :tail)
649 '((old-fp :target old-fp-pass)
650 (return-pc :target return-pc-pass)))
652 ,@(unless variable '((args :more t :scs (descriptor-reg)))))
654 ,@(when (eq return :fixed)
655 '((:results (values :more t))))
657 (:save-p ,(if (eq return :tail) :compute-only t))
659 ,@(unless (or (eq return :tail) variable)
660 '((:move-args :full-call)))
663 (:info ,@(unless (or variable (eq return :tail)) '(arg-locs))
664 ,@(unless variable '(nargs))
665 ,@(when (eq return :fixed) '(nvals)))
668 ,@(unless (or variable (eq return :tail)) '(arg-locs))
669 ,@(unless variable '(args)))
671 (:temporary (:sc descriptor-reg
674 ,@(unless (eq return :fixed)
678 (:temporary (:sc descriptor-reg
680 :from (:argument ,(if (eq return :tail) 2 1))
685 `(:temporary (:sc descriptor-reg :offset fdefn-offset ; -dan
686 :from (:argument ,(if (eq return :tail) 0 1))
689 `(:temporary (:sc descriptor-reg :offset lexenv-offset
690 :from (:argument ,(if (eq return :tail) 0 1))
693 ;; alpha code suggests that function tn is not needed for named call
694 (:temporary (:scs (descriptor-reg) :from (:argument 0) :to :eval)
696 (:temporary (:sc any-reg :offset nargs-offset :to :eval)
700 (mapcar #'(lambda (name offset)
701 `(:temporary (:sc descriptor-reg
705 register-arg-names *register-arg-offsets*))
706 ,@(when (eq return :fixed)
707 '((:temporary (:scs (descriptor-reg) :from :eval) move-temp)))
709 ,@(unless (eq return :tail)
710 '((:temporary (:scs (non-descriptor-reg)) temp)
711 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)))
713 (:temporary (:sc interior-reg :offset lip-offset) entry-point)
715 (:generator ,(+ (if named 5 0)
717 (if (eq return :tail) 0 10)
719 (if (eq return :unknown) 25 0))
720 (trace-table-entry trace-table-call-site)
721 (let* ((cur-nfp (current-nfp-tn vop))
722 ,@(unless (eq return :tail)
723 '((lra-label (gen-label))))
727 ,@(if (eq return :tail)
728 '((unless (location= old-fp old-fp-pass)
730 (unless (location= return-pc
740 (flet ((do-next-filler ()
741 (let* ((next (pop filler))
742 (what (if (consp next) (car next) next)))
746 `((inst sub nargs-pass csp-tn new-fp)
748 (mapcar #'(lambda (name)
751 register-arg-names)))
752 '((inst lr nargs-pass (fixnumize nargs)))))
753 ,@(if (eq return :tail)
757 (inst mr old-fp-pass old-fp))
759 (loadw old-fp-pass cfp-tn
760 (tn-offset old-fp)))))
764 (inst mr return-pc-pass return-pc))
766 (loadw return-pc-pass cfp-tn
767 (tn-offset return-pc)))))
769 (inst addi nsp-tn cur-nfp
770 (- (bytes-needed-for-non-descriptor-stack-frame)
771 number-stack-displacement))))
773 (inst compute-lra-from-code
774 return-pc-pass code-tn lra-label temp))
776 (store-stack-tn nfp-save cur-nfp))
778 (inst mr old-fp-pass cfp-tn))
781 '(move cfp-tn new-fp)
782 '(if (> nargs register-arg-count)
784 (move cfp-tn csp-tn))))))
788 (descriptor-reg (move name-pass name))
790 (loadw name-pass cfp-tn (tn-offset name))
793 (loadw name-pass code-tn (tn-offset name)
794 other-pointer-lowtag)
796 (loadw entry-point name-pass fdefn-raw-addr-slot
797 other-pointer-lowtag)
800 (descriptor-reg (move lexenv arg-fun))
802 (loadw lexenv cfp-tn (tn-offset arg-fun))
805 (loadw lexenv code-tn (tn-offset arg-fun)
806 sb!vm:other-pointer-lowtag)
808 (loadw function lexenv sb!vm:closure-fun-slot
809 sb!vm:fun-pointer-lowtag)
811 (inst addi entry-point function
812 (- (ash simple-fun-code-offset word-shift)
820 (note-this-location vop :call-site)
821 (inst mtctr entry-point)
822 ;; this following line is questionable. or else the alpha
823 ;; code (which doesn't do it) is questionable
824 ;; (inst mr code-tn function)
829 '((emit-return-pc lra-label)
830 (default-unknown-values vop values nvals move-temp
833 (load-stack-tn cur-nfp nfp-save))))
835 '((emit-return-pc lra-label)
836 (note-this-location vop :unknown-return)
837 (receive-unknown-values values-start nvals start count
840 (load-stack-tn cur-nfp nfp-save))))
842 (trace-table-entry trace-table-normal))))
845 (define-full-call call nil :fixed nil)
846 (define-full-call call-named t :fixed nil)
847 (define-full-call multiple-call nil :unknown nil)
848 (define-full-call multiple-call-named t :unknown nil)
849 (define-full-call tail-call nil :tail nil)
850 (define-full-call tail-call-named t :tail nil)
852 (define-full-call call-variable nil :fixed t)
853 (define-full-call multiple-call-variable nil :unknown t)
856 ;;; Defined separately, since needs special code that BLT's the arguments
859 (define-vop (tail-call-variable)
861 (args-arg :scs (any-reg) :target args)
862 (function-arg :scs (descriptor-reg) :target lexenv)
863 (old-fp-arg :scs (any-reg) :target old-fp)
864 (lra-arg :scs (descriptor-reg) :target lra))
866 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 0)) args)
867 (:temporary (:sc any-reg :offset lexenv-offset :from (:argument 1)) lexenv)
868 (:temporary (:sc any-reg :offset ocfp-offset :from (:argument 2)) old-fp)
869 (:temporary (:sc any-reg :offset lra-offset :from (:argument 3)) lra)
876 ;; Move these into the passing locations if they are not already there.
878 (move lexenv function-arg)
879 (move old-fp old-fp-arg)
883 ;; Clear the number stack if anything is there.
884 (let ((cur-nfp (current-nfp-tn vop)))
886 (inst addi nsp-tn cur-nfp
887 (- (bytes-needed-for-non-descriptor-stack-frame)
888 number-stack-displacement))))
891 (inst ba (make-fixup 'tail-call-variable :assembly-routine))))
894 ;;;; Unknown values return:
897 ;;; Return a single value using the unknown-values convention.
899 (define-vop (return-single)
900 (:args (old-fp :scs (any-reg))
901 (return-pc :scs (descriptor-reg))
904 (:temporary (:scs (interior-reg)) lip)
907 (trace-table-entry trace-table-fun-epilogue)
908 ;; Clear the number stack.
909 (let ((cur-nfp (current-nfp-tn vop)))
911 (inst addi nsp-tn cur-nfp
912 (- (bytes-needed-for-non-descriptor-stack-frame)
913 number-stack-displacement))))
914 ;; Clear the control stack, and restore the frame pointer.
918 (lisp-return return-pc lip :offset 2)
919 (trace-table-entry trace-table-normal)))
921 ;;; Do unknown-values return of a fixed number of values. The Values are
922 ;;; required to be set up in the standard passing locations. Nvals is the
923 ;;; number of values returned.
925 ;;; If returning a single value, then deallocate the current frame, restore
926 ;;; FP and jump to the single-value entry at Return-PC + 8.
928 ;;; If returning other than one value, then load the number of values returned,
929 ;;; NIL out unsupplied values registers, restore FP and return at Return-PC.
930 ;;; When there are stack values, we must initialize the argument pointer to
931 ;;; point to the beginning of the values block (which is the beginning of the
936 (old-fp :scs (any-reg))
937 (return-pc :scs (descriptor-reg) :to (:eval 1))
941 (:temporary (:sc descriptor-reg :offset a0-offset :from (:eval 0)) a0)
942 (:temporary (:sc descriptor-reg :offset a1-offset :from (:eval 0)) a1)
943 (:temporary (:sc descriptor-reg :offset a2-offset :from (:eval 0)) a2)
944 (:temporary (:sc descriptor-reg :offset a3-offset :from (:eval 0)) a3)
945 (:temporary (:sc any-reg :offset nargs-offset) nargs)
946 (:temporary (:sc any-reg :offset ocfp-offset) val-ptr)
947 (:temporary (:scs (interior-reg)) lip)
950 (trace-table-entry trace-table-fun-epilogue)
951 ;; Clear the number stack.
952 (let ((cur-nfp (current-nfp-tn vop)))
954 (inst addi nsp-tn cur-nfp
955 (- (bytes-needed-for-non-descriptor-stack-frame)
956 number-stack-displacement))))
958 ;; Clear the control stack, and restore the frame pointer.
962 (lisp-return return-pc lip :offset 2))
964 ;; Establish the values pointer and values count.
965 (move val-ptr cfp-tn)
966 (inst lr nargs (fixnumize nvals))
967 ;; restore the frame pointer and clear as much of the control
968 ;; stack as possible.
970 (inst addi csp-tn val-ptr (* nvals n-word-bytes))
971 ;; pre-default any argument register that need it.
972 (when (< nvals register-arg-count)
973 (dolist (reg (subseq (list a0 a1 a2 a3) nvals))
976 (lisp-return return-pc lip)))
977 (trace-table-entry trace-table-normal)))
979 ;;; Do unknown-values return of an arbitrary number of values (passed on the
980 ;;; stack.) We check for the common case of a single return value, and do that
981 ;;; inline using the normal single value return convention. Otherwise, we
982 ;;; branch off to code that calls an assembly-routine.
984 (define-vop (return-multiple)
986 (old-fp-arg :scs (any-reg) :to (:eval 1))
987 (lra-arg :scs (descriptor-reg) :to (:eval 1))
988 (vals-arg :scs (any-reg) :target vals)
989 (nvals-arg :scs (any-reg) :target nvals))
991 (:temporary (:sc any-reg :offset nl1-offset :from (:argument 0)) old-fp)
992 (:temporary (:sc descriptor-reg :offset lra-offset :from (:argument 1)) lra)
993 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 2)) vals)
994 (:temporary (:sc any-reg :offset nargs-offset :from (:argument 3)) nvals)
995 (:temporary (:sc descriptor-reg :offset a0-offset) a0)
996 (:temporary (:scs (interior-reg)) lip)
1002 (trace-table-entry trace-table-fun-epilogue)
1003 (let ((not-single (gen-label)))
1004 ;; Clear the number stack.
1005 (let ((cur-nfp (current-nfp-tn vop)))
1007 (inst addi nsp-tn cur-nfp
1008 (- (bytes-needed-for-non-descriptor-stack-frame)
1009 number-stack-displacement))))
1011 ;; Check for the single case.
1012 (inst cmpwi nvals-arg (fixnumize 1))
1013 (inst lwz a0 vals-arg 0)
1014 (inst bne not-single)
1016 ;; Return with one value.
1017 (move csp-tn cfp-tn)
1018 (move cfp-tn old-fp-arg)
1019 (lisp-return lra-arg lip :offset 2)
1021 ;; Nope, not the single case.
1022 (emit-label not-single)
1023 (move old-fp old-fp-arg)
1025 (move vals vals-arg)
1026 (move nvals nvals-arg)
1027 (inst ba (make-fixup 'return-multiple :assembly-routine)))
1028 (trace-table-entry trace-table-normal)))
1035 ;;; We don't need to do anything special for regular functions.
1037 (define-vop (setup-environment)
1041 ;; Don't bother doing anything.
1044 ;;; Get the lexical environment from its passing location.
1046 (define-vop (setup-closure-environment)
1047 (:temporary (:sc descriptor-reg :offset lexenv-offset :target closure
1050 (:results (closure :scs (descriptor-reg)))
1055 (move closure lexenv)))
1057 ;;; Copy a more arg from the argument area to the end of the current frame.
1058 ;;; Fixed is the number of non-more arguments.
1060 (define-vop (copy-more-arg)
1061 (:temporary (:sc any-reg :offset nl0-offset) result)
1062 (:temporary (:sc any-reg :offset nl1-offset) count)
1063 (:temporary (:sc any-reg :offset nl2-offset) src)
1064 (:temporary (:sc any-reg :offset nl3-offset) dst)
1065 (:temporary (:sc descriptor-reg :offset l0-offset) temp)
1068 (let ((loop (gen-label))
1069 (do-regs (gen-label))
1071 (when (< fixed register-arg-count)
1072 ;; Save a pointer to the results so we can fill in register args.
1073 ;; We don't need this if there are more fixed args than reg args.
1074 (move result csp-tn))
1075 ;; Allocate the space on the stack.
1076 (cond ((zerop fixed)
1077 (inst cmpwi nargs-tn 0)
1078 (inst add csp-tn csp-tn nargs-tn)
1081 (inst addic. count nargs-tn (- (fixnumize fixed)))
1083 (inst add csp-tn csp-tn count)))
1084 (when (< fixed register-arg-count)
1085 ;; We must stop when we run out of stack args, not when we run out of
1087 (inst addic. count nargs-tn (- (fixnumize register-arg-count)))
1088 ;; Everything of interest is in registers.
1090 ;; Initialize dst to be end of stack.
1092 ;; Initialize src to be end of args.
1093 (inst add src cfp-tn nargs-tn)
1096 ;; *--dst = *--src, --count
1097 (inst addi src src (- sb!vm:n-word-bytes))
1098 (inst addic. count count (- (fixnumize 1)))
1100 (inst addi dst dst (- sb!vm:n-word-bytes))
1104 (emit-label do-regs)
1105 (when (< fixed register-arg-count)
1106 ;; Now we have to deposit any more args that showed up in registers.
1107 (inst subic. count nargs-tn (fixnumize fixed))
1108 (do ((i fixed (1+ i)))
1109 ((>= i register-arg-count))
1110 ;; Don't deposit any more than there are.
1112 (inst subic. count count (fixnumize 1))
1113 ;; Store it relative to the pointer saved at the start.
1114 (storew (nth i *register-arg-tns*) result (- i fixed))))
1115 (emit-label done))))
1118 ;;; More args are stored consecutively on the stack, starting immediately at
1119 ;;; the context pointer. The context pointer is not typed, so the lowtag is 0.
1121 (define-vop (more-arg word-index-ref)
1123 (:translate %more-arg))
1126 ;;; Turn more arg (context, count) into a list.
1128 (define-vop (listify-rest-args)
1129 (:args (context-arg :target context :scs (descriptor-reg))
1130 (count-arg :target count :scs (any-reg)))
1131 (:arg-types * tagged-num)
1132 (:temporary (:scs (any-reg) :from (:argument 0)) context)
1133 (:temporary (:scs (any-reg) :from (:argument 1)) count)
1134 (:temporary (:scs (descriptor-reg) :from :eval) temp)
1135 (:temporary (:scs (non-descriptor-reg) :from :eval) dst)
1136 (:temporary (:sc non-descriptor-reg :offset nl3-offset) pa-flag)
1137 (:results (result :scs (descriptor-reg)))
1138 (:translate %listify-rest-args)
1141 (move context context-arg)
1142 (move count count-arg)
1143 ;; Check to see if there are any arguments.
1144 (inst cmpwi count 0)
1145 (move result null-tn)
1148 ;; We need to do this atomically.
1149 (pseudo-atomic (pa-flag)
1151 ;; Allocate a cons (2 words) for each item.
1152 (inst clrrwi result alloc-tn n-lowtag-bits)
1153 (inst ori result result list-pointer-lowtag)
1155 (inst slwi temp count 1)
1156 (inst add alloc-tn alloc-tn temp)
1159 ;; Compute the next cons and store it in the current one.
1161 (inst addi dst dst (* 2 n-word-bytes))
1162 (storew dst dst -1 list-pointer-lowtag)
1166 (loadw temp context)
1167 (inst addi context context n-word-bytes)
1169 ;; Dec count, and if != zero, go back for more.
1170 (inst addic. count count (- (fixnumize 1)))
1171 ;; Store the value into the car of the current cons (in the delay
1173 (storew temp dst 0 list-pointer-lowtag)
1177 ;; NIL out the last cons.
1178 (storew null-tn dst 1 list-pointer-lowtag)))
1182 ;;; Return the location and size of the more arg glob created by Copy-More-Arg.
1183 ;;; Supplied is the total number of arguments supplied (originally passed in
1184 ;;; NARGS.) Fixed is the number of non-rest arguments.
1186 ;;; We must duplicate some of the work done by Copy-More-Arg, since at that
1187 ;;; time the environment is in a pretty brain-damaged state, preventing this
1188 ;;; info from being returned as values. What we do is compute
1189 ;;; supplied - fixed, and return a pointer that many words below the current
1192 (define-vop (more-arg-context)
1193 (:policy :fast-safe)
1194 (:translate sb!c::%more-arg-context)
1195 (:args (supplied :scs (any-reg)))
1196 (:arg-types tagged-num (:constant fixnum))
1198 (:results (context :scs (descriptor-reg))
1199 (count :scs (any-reg)))
1200 (:result-types t tagged-num)
1201 (:note "more-arg-context")
1203 (inst subi count supplied (fixnumize fixed))
1204 (inst sub context csp-tn count)))
1207 ;;; Signal wrong argument count error if Nargs isn't = to Count.
1210 (define-vop (verify-argument-count)
1211 (:policy :fast-safe)
1212 (:translate sb!c::%verify-argument-count)
1213 (:args (nargs :scs (any-reg)))
1214 (:arg-types positive-fixnum (:constant t))
1217 (:save-p :compute-only)
1220 (generate-error-code vop invalid-argument-count-error nargs)))
1221 (inst cmpwi nargs (fixnumize count))
1222 (inst bne err-lab))))
1224 (define-vop (verify-arg-count)
1225 (:policy :fast-safe)
1226 (:translate sb!c::%verify-arg-count)
1227 (:args (nargs :scs (any-reg)))
1228 (:arg-types positive-fixnum (:constant t))
1231 (:save-p :compute-only)
1233 (inst twi :ne nargs (fixnumize count))))
1236 ;;; Signal various errors.
1238 (macrolet ((frob (name error translate &rest args)
1239 `(define-vop (,name)
1241 `((:policy :fast-safe)
1242 (:translate ,translate)))
1243 (:args ,@(mapcar #'(lambda (arg)
1244 `(,arg :scs (any-reg descriptor-reg)))
1247 (:save-p :compute-only)
1249 (error-call vop ,error ,@args)))))
1250 (frob arg-count-error invalid-arg-count-error
1251 sb!c::%arg-count-error nargs)
1252 (frob type-check-error object-not-type-error sb!c::%type-check-error
1254 (frob layout-invalid-error layout-invalid-error sb!c::%layout-invalid-error
1256 (frob odd-key-args-error odd-key-args-error
1257 sb!c::%odd-key-args-error)
1258 (frob unknown-key-arg-error unknown-key-arg-error
1259 sb!c::%unknown-key-arg-error key)
1260 (frob nil-fun-returned-error nil-fun-returned-error nil fun))