1 ;;;; the VM definition of function call for MIPS
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*
57 (!def-vm-support-routine make-return-pc-save-location (env)
58 (let ((ptype *backend-t-primitive-type*))
60 (physenv-debug-live-tn (make-normal-tn ptype) env)
61 (make-wired-tn ptype control-stack-arg-scn lra-save-offset))))
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 ;;; BYTES-NEEDED-FOR-NON-DESCRIPTOR-STACK-FRAME -- internal
105 ;;; Return the number of bytes needed for the current non-descriptor stack
106 ;;; frame. Non-descriptor stack frames must be multiples of 8 bytes on
109 (defun bytes-needed-for-non-descriptor-stack-frame ()
110 (* (logandc2 (1+ (sb-allocated-size 'non-descriptor-stack)) 1)
113 ;;; Used for setting up the Old-FP in local call.
115 (define-vop (current-fp)
116 (:results (val :scs (any-reg)))
120 ;;; Used for computing the caller's NFP for use in known-values return. Only
121 ;;; works assuming there is no variable size stuff on the nstack.
123 (define-vop (compute-old-nfp)
124 (:results (val :scs (any-reg)))
127 (let ((nfp (current-nfp-tn vop)))
129 (inst addu val nfp (bytes-needed-for-non-descriptor-stack-frame))))))
131 ;;; Accessing a slot from an earlier stack frame is definite hackery.
132 (define-vop (ancestor-frame-ref)
133 (:args (frame-pointer :scs (descriptor-reg))
134 (variable-home-tn :load-if nil))
135 (:results (value :scs (descriptor-reg any-reg)))
138 (aver (sc-is variable-home-tn control-stack))
139 (loadw value frame-pointer (tn-offset variable-home-tn))))
140 (define-vop (ancestor-frame-set)
141 (:args (frame-pointer :scs (descriptor-reg))
142 (value :scs (descriptor-reg any-reg)))
143 (:results (variable-home-tn :load-if nil))
146 (aver (sc-is variable-home-tn control-stack))
147 (storew value frame-pointer (tn-offset variable-home-tn))))
149 (define-vop (xep-allocate-frame)
150 (:info start-lab copy-more-arg-follows)
151 (:ignore copy-more-arg-follows)
153 (:temporary (:scs (non-descriptor-reg)) temp)
155 ;; Make sure the function is aligned, and drop a label pointing to this
157 (emit-alignment n-lowtag-bits)
158 (trace-table-entry trace-table-fun-prologue)
159 (emit-label start-lab)
160 ;; Allocate function header.
161 (inst simple-fun-header-word)
162 (dotimes (i (1- simple-fun-code-offset))
164 ;; The start of the actual code.
165 ;; Compute CODE from the address of this entry point.
166 (let ((entry-point (gen-label)))
167 (emit-label entry-point)
168 (inst compute-code-from-lip code-tn lip-tn entry-point temp)
169 ;; ### We should also save it on the stack so that the garbage collector
170 ;; won't forget about us if we call anyone else.
172 ;; Build our stack frames.
173 (inst addu csp-tn cfp-tn
174 (* n-word-bytes (sb-allocated-size 'control-stack)))
175 (let ((nfp (current-nfp-tn vop)))
177 (inst addu nsp-tn nsp-tn
178 (- (bytes-needed-for-non-descriptor-stack-frame)))
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 addu csp-tn csp-tn
190 (* n-word-bytes (sb-allocated-size 'control-stack)))
191 (when (ir2-physenv-number-stack-p callee)
192 (inst addu nsp-tn nsp-tn
193 (- (bytes-needed-for-non-descriptor-stack-frame)))
195 (trace-table-entry trace-table-normal)))
197 ;;; Allocate a partial frame for passing stack arguments in a full call. Nargs
198 ;;; is the number of arguments passed. If no stack arguments are passed, then
199 ;;; we don't have to do anything.
201 (define-vop (allocate-full-call-frame)
203 (:results (res :scs (any-reg)))
205 (when (> nargs register-arg-count)
207 (inst addu csp-tn csp-tn (* nargs n-word-bytes)))))
212 ;;; Emit code needed at the return-point from an unknown-values call for a
213 ;;; fixed number of values. Values is the head of the TN-Ref list for the
214 ;;; locations that the values are to be received into. Nvals is the number of
215 ;;; values that are to be received (should 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, a
220 ;;; single value return returns at the return PC + 8, whereas a return of other
221 ;;; than one value returns directly at the return PC.
223 ;;; If 0 or 1 values are expected, then we just emit an instruction to reset
224 ;;; the SP (which will only be executed when other than 1 value is returned.)
226 ;;; In the general case, we have to do three things:
227 ;;; -- Default unsupplied register values. This need only be done when a
228 ;;; single value is returned, since register values are defaulted by the
229 ;;; callee in the non-single case.
230 ;;; -- Default unsupplied stack values. This needs to be done whenever there
231 ;;; are stack values.
232 ;;; -- Reset SP. This must be done whenever other than 1 value is returned,
233 ;;; regardless of the number of values desired.
235 ;;; The general-case code looks like this:
237 b regs-defaulted ; Skip if MVs
240 move a1 null-tn ; Default register values
242 loadi nargs 1 ; Force defaulting of stack values
243 move ocfp csp ; Set up args for SP resetting
246 subu temp nargs register-arg-count
248 bltz temp default-value-7 ; jump to default code
250 loadw move-temp ocfp-tn 6 ; Move value to correct location.
251 store-stack-tn val4-tn move-temp
253 bltz temp default-value-8
255 loadw move-temp ocfp-tn 7
256 store-stack-tn val5-tn move-temp
261 move csp ocfp ; Reset SP.
266 store-stack-tn val4-tn null-tn ; Nil out 7'th value. (first on stack)
269 store-stack-tn val5-tn null-tn ; Nil out 8'th value.
277 (defun default-unknown-values (vop values nvals move-temp temp lra-label)
278 (declare (type (or tn-ref null) values)
279 (type unsigned-byte nvals) (type tn move-temp temp))
282 ;; Note that this is a single-value return point. This is actually
283 ;; the multiple-value entry point for a single desired value, but
284 ;; the code location has to be here, or the debugger backtrace
286 (without-scheduling ()
287 (note-this-location vop :single-value-return)
288 (move csp-tn ocfp-tn t)
291 (inst compute-code-from-lra code-tn code-tn lra-label temp)))
292 (let ((regs-defaulted (gen-label))
293 (defaulting-done (gen-label))
294 (default-stack-vals (gen-label)))
295 (without-scheduling ()
296 ;; Note that this is an unknown-values return point.
297 (note-this-location vop :unknown-return)
298 ;; Branch off to the MV case.
299 (inst b regs-defaulted)
300 ;; If there are no stack results, clear the stack now.
301 (if (> nvals register-arg-count)
302 (inst addu temp nargs-tn (fixnumize (- register-arg-count)))
303 (move csp-tn ocfp-tn t)))
305 ;; Do the single value case.
307 (val (tn-ref-across values) (tn-ref-across val)))
308 ((= i (min nvals register-arg-count)))
309 (move (tn-ref-tn val) null-tn))
310 (when (> nvals register-arg-count)
311 (inst b default-stack-vals)
312 (move ocfp-tn csp-tn t))
314 (emit-label regs-defaulted)
316 (when (> nvals register-arg-count)
317 ;; If there are stack results, we have to default them
318 ;; and clear the stack.
319 (collect ((defaults))
320 (do ((i register-arg-count (1+ i))
321 (val (do ((i 0 (1+ i))
322 (val values (tn-ref-across val)))
323 ((= i register-arg-count) val))
324 (tn-ref-across val)))
327 (let ((default-lab (gen-label))
328 (tn (tn-ref-tn val)))
329 (defaults (cons default-lab tn))
331 (inst blez temp default-lab)
332 (inst lw move-temp ocfp-tn (* i n-word-bytes))
333 (inst addu temp temp (fixnumize -1))
334 (store-stack-tn tn move-temp)))
336 (emit-label defaulting-done)
337 (move csp-tn ocfp-tn)
339 (let ((defaults (defaults)))
341 (assemble (*elsewhere*)
342 (emit-label default-stack-vals)
343 (trace-table-entry trace-table-fun-prologue)
344 (do ((remaining defaults (cdr remaining)))
346 (let ((def (car remaining)))
347 (emit-label (car def))
348 (when (null (cdr remaining))
349 (inst b defaulting-done))
350 (store-stack-tn (cdr def) null-tn)))
351 (trace-table-entry trace-table-normal)))))
354 (inst compute-code-from-lra code-tn code-tn lra-label temp))))
358 ;;;; Unknown values receiving:
360 ;;; Emit code needed at the return point for an unknown-values call for an
361 ;;; arbitrary number of values.
363 ;;; We do the single and non-single cases with no shared code: there doesn't
364 ;;; seem to be any potential overlap, and receiving a single value is more
365 ;;; important efficiency-wise.
367 ;;; When there is a single value, we just push it on the stack, returning
368 ;;; the old SP and 1.
370 ;;; When there is a variable number of values, we move all of the argument
371 ;;; registers onto the stack, and return Args and Nargs.
373 ;;; Args and Nargs are TNs wired to the named locations. We must
374 ;;; explicitly allocate these TNs, since their lifetimes overlap with the
375 ;;; results Start and Count (also, it's nice to be able to target them).
377 (defun receive-unknown-values (args nargs start count lra-label temp)
378 (declare (type tn args nargs start count temp))
379 (let ((variable-values (gen-label))
381 (without-scheduling ()
382 (inst b variable-values)
386 (inst compute-code-from-lra code-tn code-tn lra-label temp))
387 (inst addu csp-tn csp-tn n-word-bytes)
388 (storew (first *register-arg-tns*) csp-tn -1)
389 (inst addu start csp-tn (- n-word-bytes))
390 (inst li count (fixnumize 1))
394 (assemble (*elsewhere*)
395 (trace-table-entry trace-table-fun-prologue)
396 (emit-label variable-values)
398 (inst compute-code-from-lra code-tn code-tn lra-label temp))
399 (do ((arg *register-arg-tns* (rest arg))
402 (storew (first arg) args i))
406 (trace-table-entry trace-table-normal)))
410 ;;; VOP that can be inherited by unknown values receivers. The main thing this
411 ;;; handles is allocation of the result temporaries.
413 (define-vop (unknown-values-receiver)
415 (start :scs (any-reg))
416 (count :scs (any-reg)))
417 (:temporary (:sc descriptor-reg :offset ocfp-offset
418 :from :eval :to (:result 0))
420 (:temporary (:sc any-reg :offset nargs-offset
421 :from :eval :to (:result 1))
423 (:temporary (:scs (non-descriptor-reg)) temp))
427 ;;;; Local call with unknown values convention return:
429 ;;; Non-TR local call for a fixed number of values passed according to the
430 ;;; unknown values convention.
432 ;;; Args are the argument passing locations, which are specified only to
433 ;;; terminate their lifetimes in the caller.
435 ;;; Values are the return value locations (wired to the standard passing
438 ;;; Save is the save info, which we can ignore since saving has been done.
439 ;;; Return-PC is the TN that the return PC should be passed in.
440 ;;; Target is a continuation pointing to the start of the called function.
441 ;;; Nvals is the number of values received.
443 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
444 ;;; registers may be tied up by the more operand. Instead, we use
445 ;;; MAYBE-LOAD-STACK-TN.
447 (define-vop (call-local)
451 (:results (values :more t))
453 (:move-args :local-call)
454 (:info arg-locs callee target nvals)
456 (:temporary (:scs (descriptor-reg) :from :eval) move-temp)
457 (:temporary (:scs (non-descriptor-reg)) temp)
458 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
459 (:temporary (:sc any-reg :offset ocfp-offset :from :eval) ocfp)
460 (:ignore arg-locs args ocfp)
462 (let ((label (gen-label))
463 (cur-nfp (current-nfp-tn vop)))
465 (store-stack-tn nfp-save cur-nfp))
466 (let ((callee-nfp (callee-nfp-tn callee)))
468 (maybe-load-stack-tn callee-nfp nfp)))
469 (maybe-load-stack-tn cfp-tn fp)
470 (trace-table-entry trace-table-call-site)
471 (inst compute-lra-from-code
472 (callee-return-pc-tn callee) code-tn label temp)
473 (note-this-location vop :call-site)
476 (trace-table-entry trace-table-normal)
477 (emit-return-pc label)
478 (default-unknown-values vop values nvals move-temp temp label)
480 (load-stack-tn cur-nfp nfp-save)))))
483 ;;; Non-TR local call for a variable number of return values passed according
484 ;;; to the unknown values convention. The results are the start of the values
485 ;;; glob and the number of values received.
487 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
488 ;;; registers may be tied up by the more operand. Instead, we use
489 ;;; MAYBE-LOAD-STACK-TN.
491 (define-vop (multiple-call-local unknown-values-receiver)
496 (:move-args :local-call)
497 (:info save callee target)
500 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
501 (:temporary (:scs (non-descriptor-reg)) temp)
503 (let ((label (gen-label))
504 (cur-nfp (current-nfp-tn vop)))
506 (store-stack-tn nfp-save cur-nfp))
507 (let ((callee-nfp (callee-nfp-tn callee)))
509 (maybe-load-stack-tn callee-nfp nfp)))
510 (maybe-load-stack-tn cfp-tn fp)
511 (trace-table-entry trace-table-call-site)
512 (inst compute-lra-from-code
513 (callee-return-pc-tn callee) code-tn label temp)
514 (note-this-location vop :call-site)
517 (trace-table-entry trace-table-normal)
518 (emit-return-pc label)
519 (note-this-location vop :unknown-return)
520 (receive-unknown-values values-start nvals start count label temp)
522 (load-stack-tn cur-nfp nfp-save)))))
525 ;;;; Local call with known values return:
527 ;;; Non-TR local call with known return locations. Known-value return works
528 ;;; just like argument passing in local call.
530 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
531 ;;; registers may be tied up by the more operand. Instead, we use
532 ;;; MAYBE-LOAD-STACK-TN.
534 (define-vop (known-call-local)
538 (:results (res :more t))
539 (:move-args :local-call)
541 (:info save callee target)
542 (:ignore args res save)
544 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
545 (:temporary (:scs (non-descriptor-reg)) temp)
547 (let ((label (gen-label))
548 (cur-nfp (current-nfp-tn vop)))
550 (store-stack-tn nfp-save cur-nfp))
551 (let ((callee-nfp (callee-nfp-tn callee)))
553 (maybe-load-stack-tn callee-nfp nfp)))
554 (maybe-load-stack-tn cfp-tn fp)
555 (trace-table-entry trace-table-call-site)
556 (inst compute-lra-from-code
557 (callee-return-pc-tn callee) code-tn label temp)
558 (note-this-location vop :call-site)
561 (trace-table-entry trace-table-normal)
562 (emit-return-pc label)
563 (note-this-location vop :known-return)
565 (load-stack-tn cur-nfp nfp-save)))))
567 ;;; Return from known values call. We receive the return locations as
568 ;;; arguments to terminate their lifetimes in the returning function. We
569 ;;; restore FP and CSP and jump to the Return-PC.
571 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
572 ;;; registers may be tied up by the more operand. Instead, we use
573 ;;; MAYBE-LOAD-STACK-TN.
575 (define-vop (known-return)
576 (:args (ocfp :target ocfp-temp)
577 (return-pc :target return-pc-temp)
579 (:temporary (:sc any-reg :from (:argument 0)) ocfp-temp)
580 (:temporary (:sc descriptor-reg :from (:argument 1))
582 (:temporary (:scs (interior-reg)) lip)
583 (:move-args :known-return)
585 (:ignore val-locs vals)
588 (trace-table-entry trace-table-fun-epilogue)
589 (maybe-load-stack-tn ocfp-temp ocfp)
590 (maybe-load-stack-tn return-pc-temp return-pc)
592 (let ((cur-nfp (current-nfp-tn vop)))
594 (inst addu nsp-tn cur-nfp
595 (bytes-needed-for-non-descriptor-stack-frame))))
596 (inst addu lip return-pc-temp (- n-word-bytes other-pointer-lowtag))
598 (move cfp-tn ocfp-temp t)
599 (trace-table-entry trace-table-normal)))
604 ;;; There is something of a cross-product effect with full calls. Different
605 ;;; versions are used depending on whether we know the number of arguments or
606 ;;; the name of the called function, and whether we want fixed values, unknown
607 ;;; values, or a tail call.
609 ;;; In full call, the arguments are passed creating a partial frame on the
610 ;;; stack top and storing stack arguments into that frame. On entry to the
611 ;;; callee, this partial frame is pointed to by FP. If there are no stack
612 ;;; arguments, we don't bother allocating a partial frame, and instead set FP
613 ;;; to SP just before the call.
615 ;;; This macro helps in the definition of full call VOPs by avoiding code
616 ;;; replication in defining the cross-product VOPs.
618 ;;; Name is the name of the VOP to define.
620 ;;; Named is true if the first argument is a symbol whose global function
621 ;;; definition is to be called.
623 ;;; Return is either :Fixed, :Unknown or :Tail:
624 ;;; -- If :Fixed, then the call is for a fixed number of values, returned in
625 ;;; the standard passing locations (passed as result operands).
626 ;;; -- If :Unknown, then the result values are pushed on the stack, and the
627 ;;; result values are specified by the Start and Count as in the
628 ;;; unknown-values continuation representation.
629 ;;; -- If :Tail, then do a tail-recursive call. No values are returned.
630 ;;; The Ocfp and Return-PC are passed as the second and third arguments.
632 ;;; In non-tail calls, the pointer to the stack arguments is passed as the last
633 ;;; fixed argument. If Variable is false, then the passing locations are
634 ;;; passed as a more arg. Variable is true if there are a variable number of
635 ;;; arguments passed on the stack. Variable cannot be specified with :Tail
636 ;;; return. TR variable argument call is implemented separately.
638 ;;; In tail call with fixed arguments, the passing locations are passed as a
639 ;;; more arg, but there is no new-FP, since the arguments have been set up in
640 ;;; the current frame.
642 (defmacro define-full-call (name named return variable)
643 (aver (not (and variable (eq return :tail))))
645 ,@(when (eq return :unknown)
646 '(unknown-values-receiver)))
648 ,@(unless (eq return :tail)
649 '((new-fp :scs (any-reg) :to :eval)))
652 '(name :target name-pass)
653 '(arg-fun :target lexenv))
655 ,@(when (eq return :tail)
656 '((ocfp :target ocfp-pass)
657 (return-pc :target return-pc-pass)))
659 ,@(unless variable '((args :more t :scs (descriptor-reg)))))
661 ,@(when (eq return :fixed)
662 '((:results (values :more t))))
664 (:save-p ,(if (eq return :tail) :compute-only t))
666 ,@(unless (or (eq return :tail) variable)
667 '((:move-args :full-call)))
670 (:info ,@(unless (or variable (eq return :tail)) '(arg-locs))
671 ,@(unless variable '(nargs))
672 ,@(when (eq return :fixed) '(nvals))
675 (:ignore ,@(unless (or variable (eq return :tail)) '(arg-locs))
676 ,@(unless variable '(args)))
678 (:temporary (:sc descriptor-reg
681 ,@(unless (eq return :fixed)
685 (:temporary (:sc descriptor-reg
687 :from (:argument ,(if (eq return :tail) 2 1))
692 `((:temporary (:sc descriptor-reg :offset fdefn-offset
693 :from (:argument ,(if (eq return :tail) 0 1))
697 `((:temporary (:sc descriptor-reg :offset lexenv-offset
698 :from (:argument ,(if (eq return :tail) 0 1))
701 (:temporary (:scs (descriptor-reg) :from (:argument 0) :to :eval)
704 (:temporary (:sc any-reg :offset nargs-offset :to :eval)
708 (mapcar #'(lambda (name offset)
709 `(:temporary (:sc descriptor-reg
713 register-arg-names *register-arg-offsets*))
714 ,@(when (eq return :fixed)
715 '((:temporary (:scs (descriptor-reg) :from :eval) move-temp)))
717 (:temporary (:scs (descriptor-reg) :to :eval) stepping)
719 ,@(unless (eq return :tail)
720 '((:temporary (:scs (non-descriptor-reg)) temp)
721 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)))
723 (:temporary (:sc interior-reg) entry-point)
725 (:generator ,(+ (if named 5 0)
727 (if (eq return :tail) 0 10)
729 (if (eq return :unknown) 25 0))
730 (let* ((cur-nfp (current-nfp-tn vop))
731 ,@(unless (eq return :tail)
732 '((lra-label (gen-label))))
733 (step-done-label (gen-label))
737 ,@(if (eq return :tail)
738 '((unless (location= ocfp ocfp-pass)
740 (unless (location= return-pc
750 (flet ((do-next-filler ()
751 (let* ((next (pop filler))
752 (what (if (consp next) (car next) next)))
756 `((inst subu nargs-pass csp-tn new-fp)
758 (mapcar #'(lambda (name)
759 `(inst lw ,name new-fp
762 register-arg-names)))
763 '((inst li nargs-pass (fixnumize nargs)))))
764 ,@(if (eq return :tail)
768 (move ocfp-pass ocfp t))
770 (inst lw ocfp-pass cfp-tn
771 (ash (tn-offset ocfp)
776 (move return-pc-pass return-pc t))
778 (inst lw return-pc-pass cfp-tn
779 (ash (tn-offset return-pc)
782 (inst addu nsp-tn cur-nfp
783 (bytes-needed-for-non-descriptor-stack-frame))))
785 (inst compute-lra-from-code
786 return-pc-pass code-tn lra-label temp))
788 (store-stack-tn nfp-save cur-nfp))
790 (move ocfp-pass cfp-tn t))
793 '(move cfp-tn new-fp)
794 '(if (> nargs register-arg-count)
796 (move cfp-tn csp-tn)))
797 (trace-table-entry trace-table-call-site))))
800 (insert-step-instrumenting (callable-tn)
801 ;; Conditionally insert a conditional trap:
802 (when step-instrumenting
803 (load-symbol-value stepping sb!impl::*stepping*)
804 ;; If it's not NIL, trap.
805 (inst beq stepping null-tn step-done-label)
807 ;; CONTEXT-PC will be pointing here when the
808 ;; interrupt is handled, not after the BREAK.
809 (note-this-location vop :step-before-vop)
810 ;; Construct a trap code with the low bits from
811 ;; SINGLE-STEP-AROUND-TRAP and the high bits from
812 ;; the register number of CALLABLE-TN.
813 (inst break 0 (logior single-step-around-trap
814 (ash (reg-tn-encoding callable-tn)
816 (emit-label step-done-label))))
820 (descriptor-reg (move name-pass name))
822 (inst lw name-pass cfp-tn
823 (ash (tn-offset name) word-shift))
826 (inst lw name-pass code-tn
827 (- (ash (tn-offset name) word-shift)
828 other-pointer-lowtag))
830 ;; The step instrumenting must be done after
831 ;; FUNCTION is loaded, but before ENTRY-POINT is
833 (insert-step-instrumenting name-pass)
834 (inst lw entry-point name-pass
835 (- (ash fdefn-raw-addr-slot word-shift)
836 other-pointer-lowtag))
839 (descriptor-reg (move lexenv arg-fun))
841 (inst lw lexenv cfp-tn
842 (ash (tn-offset arg-fun) word-shift))
845 (inst lw lexenv code-tn
846 (- (ash (tn-offset arg-fun) word-shift)
847 other-pointer-lowtag))
849 (inst lw function lexenv
850 (- (ash closure-fun-slot word-shift)
853 ;; The step instrumenting must be done before
854 ;; after FUNCTION is loaded, but before ENTRY-POINT
856 (insert-step-instrumenting function)
857 (inst addu entry-point function
858 (- (ash simple-fun-code-offset word-shift)
859 fun-pointer-lowtag))))
866 (note-this-location vop :call-site)
872 '((trace-table-entry trace-table-normal)
873 (emit-return-pc lra-label)
874 (default-unknown-values vop values nvals
875 move-temp temp lra-label)
877 (load-stack-tn cur-nfp nfp-save))))
879 '((trace-table-entry trace-table-normal)
880 (emit-return-pc lra-label)
881 (note-this-location vop :unknown-return)
882 (receive-unknown-values values-start nvals start count
885 (load-stack-tn cur-nfp nfp-save))))
889 (define-full-call call nil :fixed nil)
890 (define-full-call call-named t :fixed nil)
891 (define-full-call multiple-call nil :unknown nil)
892 (define-full-call multiple-call-named t :unknown nil)
893 (define-full-call tail-call nil :tail nil)
894 (define-full-call tail-call-named t :tail nil)
896 (define-full-call call-variable nil :fixed t)
897 (define-full-call multiple-call-variable nil :unknown t)
900 ;;; Defined separately, since needs special code that BLT's the arguments
903 (define-vop (tail-call-variable)
905 (args-arg :scs (any-reg) :target args)
906 (function-arg :scs (descriptor-reg) :target lexenv)
907 (ocfp-arg :scs (any-reg) :target ocfp)
908 (lra-arg :scs (descriptor-reg) :target lra))
910 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 0)) args)
911 (:temporary (:sc any-reg :offset lexenv-offset :from (:argument 1)) lexenv)
912 (:temporary (:sc any-reg :offset ocfp-offset :from (:argument 2)) ocfp)
913 (:temporary (:sc any-reg :offset lra-offset :from (:argument 3)) lra)
919 ;; Move these into the passing locations if they are not already there.
921 (move lexenv function-arg)
925 ;; Clear the number stack if anything is there and jump to the
926 ;; assembly-routine that does the bliting.
927 (inst j (make-fixup 'tail-call-variable :assembly-routine))
928 (let ((cur-nfp (current-nfp-tn vop)))
930 (inst addu nsp-tn cur-nfp
931 (bytes-needed-for-non-descriptor-stack-frame))
935 ;;;; Unknown values return:
937 ;;; Return a single value using the unknown-values convention.
939 (define-vop (return-single)
940 (:args (ocfp :scs (any-reg))
941 (return-pc :scs (descriptor-reg))
944 (:temporary (:scs (interior-reg)) lip)
947 ;; Clear the number stack.
948 (trace-table-entry trace-table-fun-epilogue)
949 (let ((cur-nfp (current-nfp-tn vop)))
951 (inst addu nsp-tn cur-nfp
952 (bytes-needed-for-non-descriptor-stack-frame))))
953 ;; Clear the control stack, and restore the frame pointer.
957 (lisp-return return-pc lip :offset 2)
958 (trace-table-entry trace-table-normal)))
961 ;;; Do unknown-values return of a fixed number of values. The Values are
962 ;;; required to be set up in the standard passing locations. Nvals is the
963 ;;; number of values returned.
965 ;;; If returning a single value, then deallocate the current frame, restore
966 ;;; FP and jump to the single-value entry at Return-PC + 8.
968 ;;; If returning other than one value, then load the number of values returned,
969 ;;; NIL out unsupplied values registers, restore FP and return at Return-PC.
970 ;;; When there are stack values, we must initialize the argument pointer to
971 ;;; point to the beginning of the values block (which is the beginning of the
975 (:args (ocfp :scs (any-reg))
976 (return-pc :scs (descriptor-reg) :to (:eval 1))
980 (:temporary (:sc descriptor-reg :offset a0-offset :from (:eval 0)) a0)
981 (:temporary (:sc descriptor-reg :offset a1-offset :from (:eval 0)) a1)
982 (:temporary (:sc descriptor-reg :offset a2-offset :from (:eval 0)) a2)
983 (:temporary (:sc descriptor-reg :offset a3-offset :from (:eval 0)) a3)
984 (:temporary (:sc descriptor-reg :offset a4-offset :from (:eval 0)) a4)
985 (:temporary (:sc descriptor-reg :offset a5-offset :from (:eval 0)) a5)
986 (:temporary (:sc any-reg :offset nargs-offset) nargs)
987 (:temporary (:sc any-reg :offset ocfp-offset) val-ptr)
988 (:temporary (:scs (interior-reg)) lip)
991 ;; Clear the number stack.
992 (trace-table-entry trace-table-fun-epilogue)
993 (let ((cur-nfp (current-nfp-tn vop)))
995 (inst addu nsp-tn cur-nfp
996 (bytes-needed-for-non-descriptor-stack-frame))))
998 ;; Clear the control stack, and restore the frame pointer.
1002 (lisp-return return-pc lip :offset 2))
1004 ;; Establish the values pointer and values count.
1005 (move val-ptr cfp-tn)
1006 (inst li nargs (fixnumize nvals))
1007 ;; restore the frame pointer and clear as much of the control
1008 ;; stack as possible.
1010 (inst addu csp-tn val-ptr (* nvals n-word-bytes))
1011 ;; pre-default any argument register that need it.
1012 (when (< nvals register-arg-count)
1013 (dolist (reg (subseq (list a0 a1 a2 a3 a4 a5) nvals))
1014 (move reg null-tn)))
1016 (lisp-return return-pc lip)))
1017 (trace-table-entry trace-table-normal)))
1019 ;;; Do unknown-values return of an arbitrary number of values (passed on the
1020 ;;; stack.) We check for the common case of a single return value, and do that
1021 ;;; inline using the normal single value return convention. Otherwise, we
1022 ;;; branch off to code that calls an assembly-routine.
1024 (define-vop (return-multiple)
1025 (:args (ocfp-arg :scs (any-reg) :target ocfp)
1026 (lra-arg :scs (descriptor-reg) :target lra)
1027 (vals-arg :scs (any-reg) :target vals)
1028 (nvals-arg :scs (any-reg) :target nvals))
1030 (:temporary (:sc any-reg :offset nl1-offset :from (:argument 0)) ocfp)
1031 (:temporary (:sc descriptor-reg :offset lra-offset :from (:argument 1)) lra)
1032 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 2)) vals)
1033 (:temporary (:sc any-reg :offset nargs-offset :from (:argument 3)) nvals)
1034 (:temporary (:sc descriptor-reg :offset a0-offset) a0)
1035 (:temporary (:scs (interior-reg)) lip)
1040 (trace-table-entry trace-table-fun-epilogue)
1041 (let ((not-single (gen-label)))
1042 ;; Clear the number stack.
1043 (let ((cur-nfp (current-nfp-tn vop)))
1045 (inst addu nsp-tn cur-nfp
1046 (bytes-needed-for-non-descriptor-stack-frame))))
1048 ;; Check for the single case.
1049 (inst li a0 (fixnumize 1))
1050 (inst bne nvals-arg a0 not-single)
1051 (inst lw a0 vals-arg)
1053 ;; Return with one value.
1054 (move csp-tn cfp-tn)
1055 (move cfp-tn ocfp-arg)
1056 (lisp-return lra-arg lip :offset 2)
1058 ;; Nope, not the single case.
1059 (emit-label not-single)
1060 (move ocfp ocfp-arg)
1062 (move vals vals-arg)
1064 (inst j (make-fixup 'return-multiple :assembly-routine))
1065 (move nvals nvals-arg t))
1066 (trace-table-entry trace-table-normal)))
1073 ;;; We don't need to do anything special for regular functions.
1075 (define-vop (setup-environment)
1079 ;; Don't bother doing anything.
1082 ;;; Get the lexical environment from its passing location.
1084 (define-vop (setup-closure-environment)
1085 (:temporary (:sc descriptor-reg :offset lexenv-offset :target closure
1088 (:results (closure :scs (descriptor-reg)))
1093 (move closure lexenv)))
1095 ;;; Copy a more arg from the argument area to the end of the current frame.
1096 ;;; Fixed is the number of non-more arguments.
1098 (define-vop (copy-more-arg)
1099 (:temporary (:sc any-reg :offset nl0-offset) result)
1100 (:temporary (:sc any-reg :offset nl1-offset) count)
1101 (:temporary (:sc any-reg :offset nl2-offset) src)
1102 (:temporary (:sc any-reg :offset nl3-offset) dst)
1103 (:temporary (:sc descriptor-reg :offset l0-offset) temp)
1106 (let ((loop (gen-label))
1107 (do-regs (gen-label))
1109 (when (< fixed register-arg-count)
1110 ;; Save a pointer to the results so we can fill in register args.
1111 ;; We don't need this if there are more fixed args than reg args.
1112 (move result csp-tn))
1113 ;; Allocate the space on the stack.
1114 (cond ((zerop fixed)
1115 (inst beq nargs-tn done)
1116 (inst addu csp-tn csp-tn nargs-tn))
1118 (inst addu count nargs-tn (fixnumize (- fixed)))
1119 (inst blez count done)
1121 (inst addu csp-tn csp-tn count)))
1122 (when (< fixed register-arg-count)
1123 ;; We must stop when we run out of stack args, not when we run out of
1125 (inst addu count nargs-tn (fixnumize (- register-arg-count))))
1126 ;; Everything of interest in registers.
1127 (inst blez count do-regs)
1128 ;; Initialize dst to be end of stack.
1130 ;; Initialize src to be end of args.
1131 (inst addu src cfp-tn nargs-tn)
1134 ;; *--dst = *--src, --count
1135 (inst addu src src (- n-word-bytes))
1136 (inst addu count count (fixnumize -1))
1138 (inst addu dst dst (- n-word-bytes))
1139 (inst bgtz count loop)
1142 (emit-label do-regs)
1143 (when (< fixed register-arg-count)
1144 ;; Now we have to deposit any more args that showed up in registers.
1145 ;; We know there is at least one more arg, otherwise we would have
1146 ;; branched to done up at the top.
1147 (inst subu count nargs-tn (fixnumize (1+ fixed)))
1148 (do ((i fixed (1+ i)))
1149 ((>= i register-arg-count))
1150 ;; Is this the last one?
1151 (inst beq count done)
1152 ;; Store it relative to the pointer saved at the start.
1153 (storew (nth i *register-arg-tns*) result (- i fixed))
1155 (inst subu count (fixnumize 1))))
1156 (emit-label done))))
1159 ;;; More args are stored consecutively on the stack, starting
1160 ;;; immediately at the context pointer. The context pointer is not
1161 ;;; typed, so the lowtag is 0.
1162 (define-full-reffer more-arg * 0 0 (descriptor-reg any-reg) * %more-arg)
1164 ;;; Turn more arg (context, count) into a list.
1165 (define-vop (listify-rest-args)
1166 (:args (context-arg :target context :scs (descriptor-reg))
1167 (count-arg :target count :scs (any-reg)))
1168 (:arg-types * tagged-num)
1169 (:temporary (:scs (any-reg) :from (:argument 0)) context)
1170 (:temporary (:scs (any-reg) :from (:argument 1)) count)
1171 (:temporary (:scs (descriptor-reg) :from :eval) temp dst)
1172 (:temporary (:sc non-descriptor-reg :offset nl4-offset) pa-flag)
1173 (:results (result :scs (descriptor-reg)))
1174 (:translate %listify-rest-args)
1178 (let* ((enter (gen-label))
1181 (dx-p (node-stack-allocate-p node))
1182 (alloc-area-tn (if dx-p csp-tn alloc-tn)))
1183 (move context context-arg)
1184 (move count count-arg)
1185 ;; Check to see if there are any arguments.
1186 (inst beq count done)
1187 (move result null-tn t)
1189 ;; We need to do this atomically.
1190 (pseudo-atomic (pa-flag)
1193 ;; Allocate a cons (2 words) for each item.
1194 (inst srl result alloc-area-tn n-lowtag-bits)
1195 (inst sll result n-lowtag-bits)
1196 (inst or result list-pointer-lowtag)
1198 (inst sll temp count 1)
1200 (inst addu alloc-area-tn temp)
1202 ;; Store the current cons in the cdr of the previous cons.
1204 (inst addu dst dst (* 2 n-word-bytes))
1205 (storew dst dst -1 list-pointer-lowtag)
1209 (loadw temp context)
1210 (inst addu context n-word-bytes)
1212 ;; Dec count, and if != zero, go back for more.
1213 (inst addu count count (fixnumize -1))
1214 (inst bne count loop)
1216 ;; Store the value in the car (in delay slot)
1217 (storew temp dst 0 list-pointer-lowtag)
1219 ;; NIL out the last cons.
1220 (storew null-tn dst 1 list-pointer-lowtag))
1221 (emit-label done))))
1223 ;;; Return the location and size of the more arg glob created by Copy-More-Arg.
1224 ;;; Supplied is the total number of arguments supplied (originally passed in
1225 ;;; NARGS.) Fixed is the number of non-rest arguments.
1227 ;;; We must duplicate some of the work done by Copy-More-Arg, since at that
1228 ;;; time the environment is in a pretty brain-damaged state, preventing this
1229 ;;; info from being returned as values. What we do is compute
1230 ;;; supplied - fixed, and return a pointer that many words below the current
1233 (define-vop (more-arg-context)
1234 (:policy :fast-safe)
1235 (:translate sb!c::%more-arg-context)
1236 (:args (supplied :scs (any-reg)))
1237 (:arg-types tagged-num (:constant fixnum))
1239 (:results (context :scs (descriptor-reg))
1240 (count :scs (any-reg)))
1241 (:result-types t tagged-num)
1242 (:note "more-arg-context")
1244 (inst addu count supplied (fixnumize (- fixed)))
1245 (inst subu context csp-tn count)))
1248 ;;; Signal wrong argument count error if Nargs isn't = to Count.
1250 (define-vop (verify-arg-count)
1251 (:policy :fast-safe)
1252 (:translate sb!c::%verify-arg-count)
1253 (:args (nargs :scs (any-reg)))
1254 (:arg-types positive-fixnum (:constant t))
1255 (:temporary (:scs (any-reg) :type fixnum) temp)
1258 (:save-p :compute-only)
1261 (generate-error-code vop invalid-arg-count-error nargs)))
1262 (cond ((zerop count)
1263 (inst bne nargs err-lab)
1266 (inst li temp (fixnumize count))
1267 (inst bne nargs temp err-lab)
1270 ;;; Various other error signalers.
1272 (macrolet ((frob (name error translate &rest args)
1273 `(define-vop (,name)
1275 `((:policy :fast-safe)
1276 (:translate ,translate)))
1277 (:args ,@(mapcar #'(lambda (arg)
1278 `(,arg :scs (any-reg descriptor-reg)))
1281 (:save-p :compute-only)
1283 (error-call vop ,error ,@args)))))
1284 (frob arg-count-error invalid-arg-count-error
1285 sb!c::%arg-count-error nargs)
1286 (frob type-check-error object-not-type-error sb!c::%type-check-error
1288 (frob layout-invalid-error layout-invalid-error sb!c::%layout-invalid-error
1290 (frob odd-key-args-error odd-key-args-error
1291 sb!c::%odd-key-args-error)
1292 (frob unknown-key-arg-error unknown-key-arg-error
1293 sb!c::%unknown-key-arg-error key)
1294 (frob nil-fun-returned-error nil-fun-returned-error nil fun))
1298 (define-vop (step-instrument-before-vop)
1299 (:temporary (:scs (descriptor-reg)) stepping)
1300 (:policy :fast-safe)
1303 (load-symbol-value stepping sb!impl::*stepping*)
1304 ;; If it's not NIL, trap.
1305 (inst beq stepping null-tn DONE)
1307 ;; CONTEXT-PC will be pointing here when the interrupt is handled,
1308 ;; not after the BREAK.
1309 (note-this-location vop :step-before-vop)
1310 ;; CALLEE-REGISTER-OFFSET isn't needed for before-traps, so we
1311 ;; can just use a bare SINGLE-STEP-BEFORE-TRAP as the code.
1312 (inst break 0 single-step-before-trap)