1 ;;;; the VM definition of function call for the HPPA
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
18 (!def-vm-support-routine standard-arg-location (n)
19 (declare (type unsigned-byte n))
20 (if (< n register-arg-count)
21 (make-wired-tn *backend-t-primitive-type*
23 (elt *register-arg-offsets* n))
24 (make-wired-tn *backend-t-primitive-type*
25 control-stack-arg-scn n)))
28 ;;; Make a passing location TN for a local call return PC. If standard is
29 ;;; true, then use the standard (full call) location, otherwise use any legal
30 ;;; location. Even in the non-standard case, this may be restricted by a
31 ;;; desire to use a subroutine call instruction.
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*
56 (!def-vm-support-routine make-return-pc-save-location (env)
58 (physenv-debug-live-tn (make-normal-tn *backend-t-primitive-type*) env)
59 (make-wired-tn *backend-t-primitive-type*
63 ;;; Make a TN for the standard argument count passing location. We only
64 ;;; need to make the standard location, since a count is never passed when we
65 ;;; are using non-standard conventions.
66 (!def-vm-support-routine make-arg-count-location ()
67 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn nargs-offset))
70 ;;; Make a TN to hold the number-stack frame pointer. This is allocated
71 ;;; once per component, and is component-live.
72 (!def-vm-support-routine make-nfp-tn ()
74 (make-wired-tn *fixnum-primitive-type* immediate-arg-scn nfp-offset)))
76 (!def-vm-support-routine make-stack-pointer-tn ()
77 (make-normal-tn *fixnum-primitive-type*))
79 (!def-vm-support-routine make-number-stack-pointer-tn ()
80 (make-normal-tn *fixnum-primitive-type*))
82 ;;; Return a list of TNs that can be used to represent an unknown-values
83 ;;; continuation within a function.
84 (!def-vm-support-routine make-unknown-values-locations ()
85 (list (make-stack-pointer-tn)
86 (make-normal-tn *fixnum-primitive-type*)))
89 ;;; This function is called by the ENTRY-ANALYZE phase, allowing
90 ;;; VM-dependent initialization of the IR2-COMPONENT structure. We push
91 ;;; placeholder entries in the Constants to leave room for additional
92 ;;; noise in the code object header.
93 (!def-vm-support-routine select-component-format (component)
94 (declare (type component component))
95 (dotimes (i code-constants-offset)
96 (vector-push-extend nil
97 (ir2-component-constants (component-info component))))
103 ;;; Return the number of bytes needed for the current non-descriptor stack.
104 ;;; We have to allocate multiples of 64 bytes.
105 (defun bytes-needed-for-non-descriptor-stack-frame ()
106 (logandc2 (+ (* (sb-allocated-size 'non-descriptor-stack) n-word-bytes) 63)
109 ;;; 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 addi (- (bytes-needed-for-non-descriptor-stack-frame))
128 (define-vop (xep-allocate-frame)
129 (:info start-lab copy-more-arg-follows)
130 (:ignore copy-more-arg-follows)
132 (:temporary (:scs (non-descriptor-reg)) temp)
134 ;; Make sure the function is aligned, and drop a label pointing to this
136 (align n-lowtag-bits)
137 (trace-table-entry trace-table-fun-prologue)
138 (emit-label start-lab)
139 ;; Allocate function header.
140 (inst fun-header-word)
141 (dotimes (i (1- simple-fun-code-offset))
143 ;; The start of the actual code.
144 ;; Fix CODE, cause the function object was passed in.
145 (let ((entry-point (gen-label)))
146 (emit-label entry-point)
147 (inst compute-code-from-lip lip-tn entry-point temp code-tn))
148 ;; Build our stack frames.
149 (inst addi (* n-word-bytes (sb-allocated-size 'control-stack))
151 (let ((nfp (current-nfp-tn vop)))
154 (inst addi (bytes-needed-for-non-descriptor-stack-frame)
156 (trace-table-entry trace-table-normal)))
158 (define-vop (allocate-frame)
159 (:results (res :scs (any-reg))
160 (nfp :scs (any-reg)))
164 (inst addi (* n-word-bytes (sb-allocated-size 'control-stack))
166 (when (ir2-physenv-number-stack-p callee)
168 (inst addi (bytes-needed-for-non-descriptor-stack-frame)
171 ;;; Allocate a partial frame for passing stack arguments in a full call. Nargs
172 ;;; is the number of arguments passed. If no stack arguments are passed, then
173 ;;; we don't have to do anything.
175 (define-vop (allocate-full-call-frame)
177 (:results (res :scs (any-reg)))
179 (when (> nargs register-arg-count)
181 (inst addi (* nargs n-word-bytes) csp-tn csp-tn))))
184 ;;; Emit code needed at the return-point from an unknown-values call for a
185 ;;; fixed number of values. VALUES is the head of the TN-REF list for the
186 ;;; locations that the values are to be received into. NVALS is the number of
187 ;;; values that are to be received (should equal the length of VALUES).
189 ;;; MOVE-TEMP is a DESCRIPTOR-REG TN used as a temporary.
191 ;;; This code exploits the fact that in the unknown-values convention, a
192 ;;; single value return returns at the return PC + 8, whereas a return of other
193 ;;; than one value returns directly at the return PC.
195 ;;; If 0 or 1 values are expected, then we just emit an instruction to reset
196 ;;; the SP (which will only be executed when other than 1 value is returned.)
198 ;;; In the general case, we have to do three things:
199 ;;; -- Default unsupplied register values. This need only be done when a
200 ;;; single value is returned, since register values are defaulted by the
201 ;;; called in the non-single case.
202 ;;; -- Default unsupplied stack values. This needs to be done whenever there
203 ;;; are stack values.
204 ;;; -- Reset SP. This must be done whenever other than 1 value is returned,
205 ;;; regardless of the number of values desired.
207 ;;; The general-case code looks like this:
209 b regs-defaulted ; Skip if MVs
212 move a1 null-tn ; Default register values
214 loadi nargs 1 ; Force defaulting of stack values
215 move old-fp csp ; Set up args for SP resetting
218 subu temp nargs register-arg-count
220 bltz temp default-value-7 ; jump to default code
222 loadw move-temp old-fp-tn 6 ; Move value to correct location.
223 store-stack-tn val4-tn move-temp
225 bltz temp default-value-8
227 loadw move-temp old-fp-tn 7
228 store-stack-tn val5-tn move-temp
233 move sp old-fp ; Reset SP.
238 store-stack-tn val4-tn null-tn ; Nil out 7'th value. (first on stack)
241 store-stack-tn val5-tn null-tn ; Nil out 8'th value.
249 (defun default-unknown-values (vop values nvals move-temp temp lra-label)
250 (declare (type (or tn-ref null) values)
251 (type unsigned-byte nvals) (type tn move-temp temp))
255 ;; Note that this is a single-value return point. This is actually
256 ;; the multiple-value entry point for a single desired value, but
257 ;; the code location has to be here, or the debugger backtrace
259 (note-this-location vop :single-value-return)
260 (move ocfp-tn csp-tn)
261 (inst compute-code-from-lra code-tn lra-label temp code-tn)))
262 ((<= nvals register-arg-count)
264 ;; Note that this is an unknown-values return point.
265 (note-this-location vop :unknown-return)
266 ;; Branch off to the MV case.
267 (inst b regs-defaulted :nullify t)
269 ;; Default any unsupplied values.
270 (do ((val (tn-ref-across values) (tn-ref-across val)))
272 (inst move null-tn (tn-ref-tn val)
273 (if (tn-ref-across val)
279 ;; Clear the stack. Note: the last move in the single value reg
280 ;; defaulting nullifies this, so this only happens in the mv case.
281 (move ocfp-tn csp-tn)
284 (inst compute-code-from-lra code-tn lra-label temp code-tn)))
286 (collect ((defaults))
287 (assemble (nil nil :labels (default-stack-vals))
288 ;; Note that this is an unknown-values return point.
289 (note-this-location vop :unknown-return)
290 ;; Branch off to the MV case.
291 (inst b regs-defaulted :nullify t)
293 ;; Default any unsupplied register values.
295 (val (tn-ref-across values) (tn-ref-across val)))
296 ((= i register-arg-count))
297 (inst move null-tn (tn-ref-tn val)))
298 (inst b default-stack-vals)
299 (move ocfp-tn csp-tn)
303 (do ((i register-arg-count (1+ i))
304 (val (do ((i 0 (1+ i))
305 (val values (tn-ref-across val)))
306 ((= i register-arg-count) val))
307 (tn-ref-across val)))
310 (let ((default-lab (gen-label))
311 (tn (tn-ref-tn val)))
312 (defaults (cons default-lab tn))
313 (inst bci :>= nil (fixnumize i) nargs-tn default-lab)
314 (loadw move-temp ocfp-tn i)
315 (store-stack-tn tn move-temp)))
318 (move ocfp-tn csp-tn)
319 (inst compute-code-from-lra code-tn lra-label temp code-tn)
321 (let ((defaults (defaults)))
323 (assemble (*elsewhere*)
324 (trace-table-entry trace-table-call-site)
326 (do ((remaining defaults (cdr remaining)))
328 (let ((def (car remaining)))
329 (emit-label (car def))
330 (when (null (cdr remaining))
331 (inst b defaulting-done))
332 (store-stack-tn (cdr def) null-tn)))
333 (trace-table-entry trace-table-normal)))))))
337 ;;;; Unknown values receiving:
339 ;;; Emit code needed at the return point for an unknown-values call for an
340 ;;; arbitrary number of values.
342 ;;; We do the single and non-single cases with no shared code: there doesn't
343 ;;; seem to be any potential overlap, and receiving a single value is more
344 ;;; important efficiency-wise.
346 ;;; When there is a single value, we just push it on the stack, returning
347 ;;; the old SP and 1.
349 ;;; When there is a variable number of values, we move all of the argument
350 ;;; registers onto the stack, and return Args and Nargs.
352 ;;; Args and Nargs are TNs wired to the named locations. We must
353 ;;; explicitly allocate these TNs, since their lifetimes overlap with the
354 ;;; results Start and Count (also, it's nice to be able to target them).
356 (defun receive-unknown-values (args nargs start count lra-label temp)
357 (declare (type tn args nargs start count temp))
358 (assemble (nil nil :labels (variable-values))
359 (inst b variable-values :nullify t)
361 (inst compute-code-from-lra code-tn lra-label temp code-tn)
362 (inst move csp-tn start)
363 (inst stwm (first register-arg-tns) n-word-bytes csp-tn)
364 (inst li (fixnumize 1) count)
368 (assemble (*elsewhere*)
369 (trace-table-entry trace-table-call-site)
371 (inst compute-code-from-lra code-tn lra-label temp code-tn)
372 (do ((arg register-arg-tns (rest arg))
375 (storew (first arg) args i))
378 (inst b done :nullify t)
379 (trace-table-entry trace-table-normal)))
382 ;;; VOP that can be inherited by unknown values receivers. The main thing this
383 ;;; handles is allocation of the result temporaries.
385 (define-vop (unknown-values-receiver)
386 (:results (start :scs (any-reg))
387 (count :scs (any-reg)))
388 (:temporary (:sc descriptor-reg :offset ocfp-offset
389 :from :eval :to (:result 0))
391 (:temporary (:sc any-reg :offset nargs-offset
392 :from :eval :to (:result 1))
394 (:temporary (:scs (non-descriptor-reg)) temp))
398 ;;;; Local call with unknown values convention return:
400 ;;; Non-TR local call for a fixed number of values passed according to the
401 ;;; unknown values convention.
403 ;;; Args are the argument passing locations, which are specified only to
404 ;;; terminate their lifetimes in the caller.
406 ;;; Values are the return value locations (wired to the standard passing
409 ;;; Save is the save info, which we can ignore since saving has been done.
410 ;;; Return-PC is the TN that the return PC should be passed in.
411 ;;; Target is a continuation pointing to the start of the called function.
412 ;;; Nvals is the number of values received.
414 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
415 ;;; registers may be tied up by the more operand. Instead, we use
416 ;;; MAYBE-LOAD-STACK-TN.
418 (define-vop (call-local)
422 (:results (values :more t))
424 (:move-args :local-call)
425 (:info arg-locs callee target nvals)
427 (:temporary (:scs (descriptor-reg) :from :eval) move-temp)
428 (:temporary (:scs (non-descriptor-reg)) temp)
429 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
430 (:temporary (:sc any-reg :offset ocfp-offset :from :eval) ocfp)
431 (:ignore arg-locs args ocfp)
433 (trace-table-entry trace-table-call-site)
434 (let ((label (gen-label))
435 (cur-nfp (current-nfp-tn vop)))
437 (store-stack-tn nfp-save cur-nfp))
438 (let ((callee-nfp (callee-nfp-tn callee)))
440 (maybe-load-stack-tn callee-nfp nfp)))
441 (maybe-load-stack-tn cfp-tn cfp)
442 (inst compute-lra-from-code code-tn label temp
443 (callee-return-pc-tn callee))
444 (note-this-location vop :call-site)
445 (inst b target :nullify t)
446 (emit-return-pc label)
447 (default-unknown-values vop values nvals move-temp temp label)
449 (load-stack-tn cur-nfp nfp-save)))
450 (trace-table-entry trace-table-normal)))
452 ;;; Non-TR local call for a variable number of return values passed according
453 ;;; to the unknown values convention. The results are the start of the values
454 ;;; glob and the number of values received.
456 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
457 ;;; registers may be tied up by the more operand. Instead, we use
458 ;;; MAYBE-LOAD-STACK-TN.
460 (define-vop (multiple-call-local unknown-values-receiver)
465 (:move-args :local-call)
466 (:info save callee target)
469 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
471 (trace-table-entry trace-table-call-site)
472 (let ((label (gen-label))
473 (cur-nfp (current-nfp-tn vop)))
475 (store-stack-tn nfp-save cur-nfp))
476 (let ((callee-nfp (callee-nfp-tn callee)))
478 (maybe-load-stack-tn callee-nfp nfp)))
479 (maybe-load-stack-tn cfp-tn cfp)
480 (inst compute-lra-from-code code-tn label temp
481 (callee-return-pc-tn callee))
482 (note-this-location vop :call-site)
483 (inst b target :nullify t)
484 (emit-return-pc label)
485 (note-this-location vop :unknown-return)
486 (receive-unknown-values values-start nvals start count label temp)
488 (load-stack-tn cur-nfp nfp-save)))
489 (trace-table-entry trace-table-normal)))
492 ;;;; Local call with known values return:
494 ;;; Non-TR local call with known return locations. Known-value return works
495 ;;; just like argument passing in local call.
497 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
498 ;;; registers may be tied up by the more operand. Instead, we use
499 ;;; MAYBE-LOAD-STACK-TN.
501 (define-vop (known-call-local)
505 (:results (res :more t))
506 (:move-args :local-call)
508 (:info save callee target)
509 (:ignore args res save)
511 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
512 (:temporary (:scs (non-descriptor-reg)) temp)
514 (trace-table-entry trace-table-call-site)
515 (let ((label (gen-label))
516 (cur-nfp (current-nfp-tn vop)))
518 (store-stack-tn nfp-save cur-nfp))
519 (let ((callee-nfp (callee-nfp-tn callee)))
521 (maybe-load-stack-tn callee-nfp nfp)))
522 (maybe-load-stack-tn cfp-tn cfp)
523 (inst compute-lra-from-code code-tn label temp
524 (callee-return-pc-tn callee))
525 (note-this-location vop :call-site)
526 (inst b target :nullify t)
527 (emit-return-pc label)
528 (note-this-location vop :known-return)
530 (load-stack-tn cur-nfp nfp-save)))
531 (trace-table-entry trace-table-normal)))
533 ;;; Return from known values call. We receive the return locations as
534 ;;; arguments to terminate their lifetimes in the returning function. We
535 ;;; restore FP and CSP and jump to the Return-PC.
537 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
538 ;;; registers may be tied up by the more operand. Instead, we use
539 ;;; MAYBE-LOAD-STACK-TN.
541 (define-vop (known-return)
542 (:args (old-fp :target old-fp-temp)
543 (return-pc :target return-pc-temp)
545 (:temporary (:sc any-reg :from (:argument 0)) old-fp-temp)
546 (:temporary (:sc descriptor-reg :from (:argument 1)) return-pc-temp)
547 (:temporary (:scs (interior-reg)) lip)
548 (:move-args :known-return)
550 (:ignore val-locs vals)
553 (trace-table-entry trace-table-fun-epilogue)
554 (maybe-load-stack-tn old-fp-temp old-fp)
555 (maybe-load-stack-tn return-pc-temp return-pc)
557 (let ((cur-nfp (current-nfp-tn vop)))
559 (move cur-nfp nsp-tn)))
560 (inst addi (- n-word-bytes other-pointer-lowtag) return-pc-temp lip)
562 (move old-fp-temp cfp-tn)
563 (trace-table-entry trace-table-normal)))
568 ;;; There is something of a cross-product effect with full calls. Different
569 ;;; versions are used depending on whether we know the number of arguments or
570 ;;; the name of the called function, and whether we want fixed values, unknown
571 ;;; values, or a tail call.
573 ;;; In full call, the arguments are passed creating a partial frame on the
574 ;;; stack top and storing stack arguments into that frame. On entry to the
575 ;;; callee, this partial frame is pointed to by FP. If there are no stack
576 ;;; arguments, we don't bother allocating a partial frame, and instead set FP
577 ;;; to SP just before the call.
579 ;;; This macro helps in the definition of full call VOPs by avoiding code
580 ;;; replication in defining the cross-product VOPs.
582 ;;; Name is the name of the VOP to define.
584 ;;; Named is true if the first argument is a symbol whose global function
585 ;;; definition is to be called.
587 ;;; Return is either :Fixed, :Unknown or :Tail:
588 ;;; -- If :Fixed, then the call is for a fixed number of values, returned in
589 ;;; the standard passing locations (passed as result operands).
590 ;;; -- If :Unknown, then the result values are pushed on the stack, and the
591 ;;; result values are specified by the Start and Count as in the
592 ;;; unknown-values continuation representation.
593 ;;; -- If :Tail, then do a tail-recursive call. No values are returned.
594 ;;; The Old-Fp and Return-PC are passed as the second and third arguments.
596 ;;; In non-tail calls, the pointer to the stack arguments is passed as the last
597 ;;; fixed argument. If Variable is false, then the passing locations are
598 ;;; passed as a more arg. Variable is true if there are a variable number of
599 ;;; arguments passed on the stack. Variable cannot be specified with :Tail
600 ;;; return. TR variable argument call is implemented separately.
602 ;;; In tail call with fixed arguments, the passing locations are passed as a
603 ;;; more arg, but there is no new-FP, since the arguments have been set up in
604 ;;; the current frame.
606 (macrolet ((define-full-call (name named return variable)
607 (aver (not (and variable (eq return :tail))))
609 ,@(when (eq return :unknown)
610 '(unknown-values-receiver)))
612 ,@(unless (eq return :tail)
613 '((new-fp :scs (any-reg) :to :eval)))
616 '(fdefn :target fdefn-pass)
617 '(arg-fun :target lexenv))
619 ,@(when (eq return :tail)
620 '((ocfp :target ocfp-pass)
621 (lra :target lra-pass)))
623 ,@(unless variable '((args :more t :scs (descriptor-reg)))))
625 ,@(when (eq return :fixed)
626 '((:results (values :more t))))
628 (:save-p ,(if (eq return :tail) :compute-only t))
630 ,@(unless (or (eq return :tail) variable)
631 '((:move-args :full-call)))
634 (:info ,@(unless (or variable (eq return :tail)) '(arg-locs))
635 ,@(unless variable '(nargs))
636 ,@(when (eq return :fixed) '(nvals)))
639 ,@(unless (or variable (eq return :tail)) '(arg-locs))
640 ,@(unless variable '(args)))
642 (:temporary (:sc descriptor-reg
644 ,@(when (eq return :tail)
645 '(:from (:argument 1)))
646 ,@(unless (eq return :fixed)
650 (:temporary (:sc descriptor-reg
652 ,@(when (eq return :tail)
653 '(:from (:argument 2)))
658 `((:temporary (:sc descriptor-reg :offset fdefn-offset
659 :from (:argument ,(if (eq return :tail) 0 1))
663 `((:temporary (:sc descriptor-reg :offset lexenv-offset
664 :from (:argument ,(if (eq return :tail) 0 1))
667 (:temporary (:scs (descriptor-reg)
668 :from (:argument ,(if (eq return :tail) 2 1))
672 (:temporary (:sc any-reg :offset nargs-offset :to :eval)
676 (mapcar #'(lambda (name offset)
677 `(:temporary (:sc descriptor-reg
681 register-arg-names *register-arg-offsets*))
682 ,@(when (eq return :fixed)
683 '((:temporary (:scs (descriptor-reg) :from :eval) move-temp)))
685 ,@(unless (eq return :tail)
686 '((:temporary (:scs (non-descriptor-reg)) temp)
687 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)))
689 (:temporary (:scs (interior-reg) :type interior) lip)
691 (:generator ,(+ (if named 5 0)
693 (if (eq return :tail) 0 10)
695 (if (eq return :unknown) 25 0))
696 (trace-table-entry trace-table-call-site)
697 (let* ((cur-nfp (current-nfp-tn vop))
698 ,@(unless (eq return :tail)
699 '((lra-label (gen-label))))
702 ,@(if (eq return :tail)
703 '((unless (location= ocfp ocfp-pass)
705 (unless (location= lra lra-pass)
718 ((nil) (do-next-filler))
721 `((inst sub csp-tn new-fp nargs-pass)
723 (mapcar #'(lambda (name)
726 register-arg-names)))
727 '((inst li (fixnumize nargs) nargs-pass))))
728 ,@(if (eq return :tail)
732 (inst move ocfp ocfp-pass))
734 (loadw ocfp-pass cfp-tn (tn-offset ocfp)))))
738 (inst move lra lra-pass))
740 (loadw lra-pass cfp-tn (tn-offset lra)))))
742 (inst move cur-nfp nsp-tn)))
744 (store-stack-tn nfp-save cur-nfp))
746 (inst compute-lra-from-code
747 code-tn lra-label temp lra-pass))
749 (inst move cfp-tn ocfp-pass))
752 '(move new-fp cfp-tn)
753 '(if (> nargs register-arg-count)
755 (move csp-tn cfp-tn))))))))))
759 (descriptor-reg (move fdefn fdefn-pass))
761 (loadw fdefn-pass cfp-tn (tn-offset fdefn))
764 (loadw fdefn-pass code-tn (tn-offset fdefn)
765 other-pointer-lowtag)
767 (loadw lip fdefn-pass fdefn-raw-addr-slot
768 other-pointer-lowtag)
771 (descriptor-reg (move arg-fun lexenv))
773 (loadw lexenv cfp-tn (tn-offset arg-fun))
776 (loadw lexenv code-tn (tn-offset arg-fun)
777 other-pointer-lowtag)
779 (loadw function lexenv closure-fun-slot
782 (inst addi (- (ash simple-fun-code-offset word-shift)
795 (note-this-location vop :call-site)
796 (inst bv lip :nullify (null filler))
801 '((emit-return-pc lra-label)
802 (default-unknown-values vop values nvals
803 move-temp temp lra-label)
805 (load-stack-tn cur-nfp nfp-save))))
807 '((emit-return-pc lra-label)
808 (note-this-location vop :unknown-return)
809 (receive-unknown-values values-start nvals start count
812 (load-stack-tn cur-nfp nfp-save))))
814 (trace-table-entry trace-table-normal)))))
816 (define-full-call call nil :fixed nil)
817 (define-full-call call-named t :fixed nil)
818 (define-full-call multiple-call nil :unknown nil)
819 (define-full-call multiple-call-named t :unknown nil)
820 (define-full-call tail-call nil :tail nil)
821 (define-full-call tail-call-named t :tail nil)
823 (define-full-call call-variable nil :fixed t)
824 (define-full-call multiple-call-variable nil :unknown t))
827 ;;; Defined separately, since needs special code that BLT's the arguments
830 (define-vop (tail-call-variable)
831 (:args (args-arg :scs (any-reg) :target args)
832 (function-arg :scs (descriptor-reg) :target lexenv)
833 (old-fp-arg :scs (any-reg) :target old-fp)
834 (lra-arg :scs (descriptor-reg) :target lra))
836 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 0)) args)
837 (:temporary (:sc any-reg :offset lexenv-offset :from (:argument 1)) lexenv)
838 (:temporary (:sc any-reg :offset ocfp-offset :from (:argument 2)) old-fp)
839 (:temporary (:sc any-reg :offset lra-offset :from (:argument 3)) lra)
840 (:temporary (:scs (any-reg) :from (:argument 3)) tmp)
846 ;; Move these into the passing locations if they are not already there.
848 (move function-arg lexenv)
849 (move old-fp-arg old-fp)
852 ;; Clear the number stack if anything is there.
853 (let ((cur-nfp (current-nfp-tn vop)))
855 (inst move cur-nfp nsp-tn)))
857 ;; And jump to the assembly-routine that does the bliting.
858 (let ((fixup (make-fixup 'tail-call-variable :assembly-routine)))
859 (inst ldil fixup tmp)
860 (inst be fixup lisp-heap-space tmp :nullify t))))
863 ;;;; Unknown values return:
865 ;;; Return a single value using the unknown-values convention.
867 (define-vop (return-single)
868 (:args (old-fp :scs (any-reg))
869 (return-pc :scs (descriptor-reg))
874 ;; Clear the number stack.
875 (trace-table-entry trace-table-fun-epilogue)
876 (let ((cur-nfp (current-nfp-tn vop)))
878 (inst move cur-nfp nsp-tn)))
879 ;; Clear the control stack, and restore the frame pointer.
883 (lisp-return return-pc :offset 1)
884 (trace-table-entry trace-table-normal)))
886 ;;; Do unknown-values return of a fixed number of values. The Values are
887 ;;; required to be set up in the standard passing locations. Nvals is the
888 ;;; number of values returned.
890 ;;; If returning a single value, then deallocate the current frame, restore
891 ;;; FP and jump to the single-value entry at Return-PC + 8.
893 ;;; If returning other than one value, then load the number of values returned,
894 ;;; NIL out unsupplied values registers, restore FP and return at Return-PC.
895 ;;; When there are stack values, we must initialize the argument pointer to
896 ;;; point to the beginning of the values block (which is the beginning of the
901 (old-fp :scs (any-reg))
902 (return-pc :scs (descriptor-reg) :to (:eval 1))
906 (:temporary (:sc descriptor-reg :offset a0-offset :from (:eval 0)) a0)
907 (:temporary (:sc descriptor-reg :offset a1-offset :from (:eval 0)) a1)
908 (:temporary (:sc descriptor-reg :offset a2-offset :from (:eval 0)) a2)
909 (:temporary (:sc descriptor-reg :offset a3-offset :from (:eval 0)) a3)
910 (:temporary (:sc descriptor-reg :offset a4-offset :from (:eval 0)) a4)
911 (:temporary (:sc descriptor-reg :offset a5-offset :from (:eval 0)) a5)
912 (:temporary (:sc any-reg :offset nargs-offset) nargs)
913 (:temporary (:sc any-reg :offset ocfp-offset) val-ptr)
916 ;; Clear the number stack.
917 (trace-table-entry trace-table-fun-epilogue)
918 (let ((cur-nfp (current-nfp-tn vop)))
920 (inst move cur-nfp nsp-tn)))
921 ;; Establish the values pointer and values count.
922 (move cfp-tn val-ptr)
923 (inst li (fixnumize nvals) nargs)
924 ;; restore the frame pointer and clear as much of the control
925 ;; stack as possible.
927 (inst addi (* nvals n-word-bytes) val-ptr csp-tn)
928 ;; pre-default any argument register that need it.
929 (when (< nvals register-arg-count)
930 (dolist (reg (subseq (list a0 a1 a2 a3 a4 a5) nvals))
933 (lisp-return return-pc)
934 (trace-table-entry trace-table-normal)))
936 ;;; Do unknown-values return of an arbitrary number of values (passed on the
937 ;;; stack.) We check for the common case of a single return value, and do that
938 ;;; inline using the normal single value return convention. Otherwise, we
939 ;;; branch off to code that calls an assembly-routine.
941 (define-vop (return-multiple)
943 (old-fp-arg :scs (any-reg) :to (:eval 1))
944 (lra-arg :scs (descriptor-reg) :to (:eval 1))
945 (vals-arg :scs (any-reg) :target vals)
946 (nvals-arg :scs (any-reg) :target nvals))
948 (:temporary (:sc any-reg :offset nl1-offset :from (:argument 0)) old-fp)
949 (:temporary (:sc descriptor-reg :offset lra-offset :from (:argument 1)) lra)
950 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 2)) vals)
951 (:temporary (:sc any-reg :offset nargs-offset :from (:argument 3)) nvals)
952 (:temporary (:sc descriptor-reg :offset a0-offset) a0)
953 (:temporary (:scs (any-reg) :from (:eval 0)) tmp)
959 (trace-table-entry trace-table-fun-epilogue)
960 ;; Clear the number stack.
961 (let ((cur-nfp (current-nfp-tn vop)))
963 (inst move cur-nfp nsp-tn)))
965 (unless (policy node (> space speed))
966 ;; Check for the single case.
967 (inst comib :<> (fixnumize 1) nvals-arg not-single)
970 ;; Return with one value.
972 (move old-fp-arg cfp-tn)
973 (lisp-return lra-arg :offset 1))
975 ;; Nope, not the single case.
977 (move old-fp-arg old-fp)
980 (move nvals-arg nvals)
981 (let ((fixup (make-fixup 'return-multiple :assembly-routine)))
982 (inst ldil fixup tmp)
983 (inst be fixup lisp-heap-space tmp :nullify t))
984 (trace-table-entry trace-table-normal)))
990 ;;; We don't need to do anything special for regular functions.
992 (define-vop (setup-environment)
996 ;; Don't bother doing anything.
999 ;;; Get the lexical environment from it's passing location.
1001 (define-vop (setup-closure-environment)
1002 (:temporary (:sc descriptor-reg :offset lexenv-offset :target closure
1005 (:results (closure :scs (descriptor-reg)))
1010 (move lexenv closure)))
1012 ;;; Copy a more arg from the argument area to the end of the current frame.
1013 ;;; Fixed is the number of non-more arguments.
1015 (define-vop (copy-more-arg)
1016 (:temporary (:sc any-reg :offset nl0-offset) result)
1017 (:temporary (:sc any-reg :offset nl1-offset) count)
1018 (:temporary (:sc any-reg :offset nl2-offset) src)
1019 (:temporary (:sc any-reg :offset nl3-offset) dst)
1020 (:temporary (:sc descriptor-reg :offset l0-offset) temp)
1023 ;; Figure out how many things we are going to copy.
1024 (unless (zerop fixed)
1025 (inst addi (- (fixnumize fixed)) nargs-tn count))
1027 ;; Blow out of here if is nothing to copy.
1028 (inst comb :<= (if (zerop fixed) nargs-tn count) zero-tn done :nullify t)
1030 (when (< fixed register-arg-count)
1031 ;; Save a pointer to the results so we can fill in register args.
1032 ;; We don't need this if there are more fixed args than reg args.
1033 (move csp-tn result))
1035 ;; Allocate the space on the stack.
1036 (inst add csp-tn (if (zerop fixed) nargs-tn count) csp-tn)
1038 (when (< fixed register-arg-count)
1039 ;; We must stop when we run out of stack args, not when we run out of
1041 (inst addi (fixnumize (- register-arg-count)) nargs-tn count)
1042 ;; Everything of interest in registers.
1043 (inst comb :<= count zero-tn do-regs))
1044 ;; Initialize dst to be end of stack.
1047 ;; Initialize src to be end of args.
1048 (inst add cfp-tn nargs-tn src)
1051 ;; *--dst = *--src, --count
1052 (inst ldwm (- n-word-bytes) src temp)
1053 (inst addib :> (fixnumize -1) count loop)
1054 (inst stwm temp (- n-word-bytes) dst)
1057 (when (< fixed register-arg-count)
1058 ;; Now we have to deposit any more args that showed up in registers.
1059 ;; We know there is at least one more arg, otherwise we would have
1060 ;; branched to done up at the top.
1061 (inst addi (fixnumize (- fixed)) nargs-tn count)
1062 (do ((i fixed (1+ i)))
1063 ((>= i register-arg-count))
1064 ;; Is this the last one?
1065 (inst addib :<= (fixnumize -1) count done)
1066 ;; Store it relative to the pointer saved at the start.
1067 (storew (nth i register-arg-tns) result (- i fixed))))
1070 ;;; More args are stored consequtively on the stack, starting immediately at
1071 ;;; the context pointer. The context pointer is not typed, so the lowtag is 0.
1073 (define-full-reffer more-arg * 0 0 (descriptor-reg any-reg) * %more-arg)
1076 ;;; Turn more arg (context, count) into a list.
1078 (define-vop (listify-rest-args)
1079 (:args (context-arg :target context :scs (descriptor-reg))
1080 (count-arg :target count :scs (any-reg)))
1081 (:arg-types * tagged-num)
1082 (:temporary (:scs (any-reg) :from (:argument 0)) context)
1083 (:temporary (:scs (any-reg) :from (:argument 1)) count)
1084 (:temporary (:scs (descriptor-reg) :from :eval) temp)
1085 (:temporary (:scs (non-descriptor-reg) :from :eval) dst)
1086 (:results (result :scs (descriptor-reg)))
1087 (:translate %listify-rest-args)
1090 (move context-arg context)
1091 (move count-arg count)
1092 ;; Check to see if there are any arguments.
1093 (inst comb := count zero-tn done)
1094 (move null-tn result)
1096 ;; We need to do this atomically.
1099 ;; Allocate a cons (2 words) for each item.
1100 (inst move alloc-tn result)
1101 (inst dep list-pointer-lowtag 31 3 result)
1103 (inst sll count 1 temp)
1104 (inst add alloc-tn temp alloc-tn)
1107 ;; Grab one value and stash it in the car of this cons.
1108 (inst ldwm n-word-bytes context temp)
1109 (storew temp dst 0 list-pointer-lowtag)
1111 ;; Dec count, and if != zero, go back for more.
1112 (inst addi (* 2 n-word-bytes) dst dst)
1113 (inst addib :> (fixnumize -1) count loop :nullify t)
1114 (storew dst dst -1 list-pointer-lowtag)
1116 ;; NIL out the last cons.
1117 (storew null-tn dst -1 list-pointer-lowtag)
1118 ;; Clear out dst, because it points past the last cons.
1119 (move null-tn dst)))
1122 ;;; Return the location and size of the more arg glob created by Copy-More-Arg.
1123 ;;; Supplied is the total number of arguments supplied (originally passed in
1124 ;;; NARGS.) Fixed is the number of non-rest arguments.
1126 ;;; We must duplicate some of the work done by Copy-More-Arg, since at that
1127 ;;; time the environment is in a pretty brain-damaged state, preventing this
1128 ;;; info from being returned as values. What we do is compute
1129 ;;; supplied - fixed, and return a pointer that many words below the current
1133 ;;; WTF? FIXME -- CSR
1134 ;;;(setf (info function source-transform 'c::%more-arg-context) nil)
1136 (define-vop (more-arg-context)
1137 (:policy :fast-safe)
1138 (:translate sb!c::%more-arg-context)
1139 (:args (supplied :scs (any-reg)))
1140 (:arg-types tagged-num (:constant fixnum))
1142 (:results (context :scs (descriptor-reg))
1143 (count :scs (any-reg)))
1144 (:result-types t tagged-num)
1145 (:note "more-arg-context")
1147 (inst addi (fixnumize (- fixed)) supplied count)
1148 (inst sub csp-tn count context)))
1151 ;;; Signal wrong argument count error if Nargs isn't = to Count.
1153 (define-vop (verify-arg-count)
1154 (:policy :fast-safe)
1155 (:translate sb!c::%verify-arg-count)
1156 (:args (nargs :scs (any-reg)))
1157 (:arg-types positive-fixnum (:constant t))
1160 (:save-p :compute-only)
1163 (generate-error-code vop invalid-arg-count-error nargs)))
1164 (cond ((zerop count)
1165 (inst bc :<> nil nargs zero-tn err-lab))
1167 (inst bci :<> nil (fixnumize count) nargs err-lab))))))
1169 ;;; Signal an argument count error.
1171 (macrolet ((frob (name error translate &rest args)
1172 `(define-vop (,name)
1174 `((:policy :fast-safe)
1175 (:translate ,translate)))
1176 (:args ,@(mapcar #'(lambda (arg)
1177 `(,arg :scs (any-reg descriptor-reg)))
1180 (:save-p :compute-only)
1182 (error-call vop ,error ,@args)))))
1183 (frob arg-count-error invalid-arg-count-error
1184 sb!c::%arg-count-error nargs)
1185 (frob type-check-error object-not-type-error sb!c::%type-check-error
1187 (frob layout-invalid-error layout-invalid-error sb!c::%layout-invalid-error
1189 (frob odd-key-args-error odd-key-args-error
1190 sb!c::%odd-key-args-error)
1191 (frob unknown-key-arg-error unknown-key-arg-error
1192 sb!c::%unknown-key-arg-error key)
1193 (frob nil-fun-returned-error nil-fun-returned-error nil fun))