1 ;;;; the VM definition of function call for 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*
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))))
101 ;;; bytes-needed-for-non-descriptor-stack-frame is the amount
102 ;;; we grow or shrink the NSP/NFP stack. This stack is used
103 ;;; by C-code so the convention (grow direction, grow size)
104 ;;; is governed by the hpux+hppa ABI or linux+hppa ABI.
105 ;;; Return the number of bytes needed for the current non-descriptor stack.
106 ;;; We have to allocate multiples of 64 bytes
107 (defun bytes-needed-for-non-descriptor-stack-frame ()
108 (logandc2 (+ (* (sb-allocated-size 'non-descriptor-stack) n-word-bytes) 63)
111 ;;; Used for setting up the Old-FP in local call.
113 (define-vop (current-fp)
114 (:results (val :scs (any-reg)))
118 ;;; Used for computing the caller's NFP for use in known-values return. Only
119 ;;; works assuming there is no variable size stuff on the nstack.
121 (define-vop (compute-old-nfp)
122 (:results (val :scs (any-reg)))
125 (let ((nfp (current-nfp-tn vop)))
127 (inst addi (- (bytes-needed-for-non-descriptor-stack-frame))
130 (define-vop (xep-allocate-frame)
131 (:info start-lab copy-more-arg-follows)
132 (:ignore copy-more-arg-follows)
134 (:temporary (:scs (non-descriptor-reg)) temp)
136 ;; Make sure the function is aligned, and drop a label pointing to this
138 (emit-alignment n-lowtag-bits)
139 (trace-table-entry trace-table-fun-prologue)
140 (emit-label start-lab)
141 ;; Allocate function header.
142 (inst simple-fun-header-word)
143 (dotimes (i (1- simple-fun-code-offset))
145 ;; The start of the actual code.
146 ;; Fix CODE, cause the function object was passed in.
147 (let ((entry-point (gen-label)))
148 (emit-label entry-point)
149 (inst compute-code-from-lip lip-tn entry-point temp code-tn)
150 ;; ### We should also save it on the stack so that the garbage
151 ;; collector won't forget about us if we call anyone else.
153 ;; Build our stack frames.
154 (inst addi (* n-word-bytes (sb-allocated-size 'control-stack))
156 (let ((nfp (current-nfp-tn vop)))
159 (inst addi (bytes-needed-for-non-descriptor-stack-frame)
161 (trace-table-entry trace-table-normal)))
163 (define-vop (allocate-frame)
164 (:results (res :scs (any-reg))
165 (nfp :scs (any-reg)))
168 (trace-table-entry trace-table-fun-prologue)
170 (inst addi (* n-word-bytes (sb-allocated-size 'control-stack))
172 (when (ir2-physenv-number-stack-p callee)
174 (inst addi (bytes-needed-for-non-descriptor-stack-frame)
176 (trace-table-entry trace-table-normal)))
178 ;;; Allocate a partial frame for passing stack arguments in a full call. Nargs
179 ;;; is the number of arguments passed. If no stack arguments are passed, then
180 ;;; we don't have to do anything.
182 (define-vop (allocate-full-call-frame)
184 (:results (res :scs (any-reg)))
186 (when (> nargs register-arg-count)
188 (inst addi (* nargs n-word-bytes) csp-tn csp-tn))))
191 ;;; Fix: boil down below notes into something nicer
192 ;;; Emit code needed at the return-point from an unknown-values call for a
193 ;;; fixed number of values. VALUES is the head of the TN-REF list for the
194 ;;; locations that the values are to be received into. NVALS is the number of
195 ;;; values that are to be received (should equal the length of VALUES).
197 ;;; MOVE-TEMP is a DESCRIPTOR-REG TN used as a temporary.
199 ;;; This code exploits the fact that in the unknown-values convention, a
200 ;;; single value return returns at the return PC + 8, whereas a return of other
201 ;;; than one value returns directly at the return PC.
203 ;;; If 0 or 1 values are expected, then we just emit an instruction to reset
204 ;;; the SP (which will only be executed when other than 1 value is returned.)
206 ;;; In the general case, we have to do three things:
207 ;;; -- Default unsupplied register values. This need only be done when a
208 ;;; single value is returned, since register values are defaulted by the
209 ;;; called in the non-single case.
210 ;;; -- Default unsupplied stack values. This needs to be done whenever there
211 ;;; are stack values.
212 ;;; -- Reset SP. This must be done whenever other than 1 value is returned,
213 ;;; regardless of the number of values desired.
215 ;;; The general-case code looks like this:
217 b regs-defaulted ; Skip if MVs
220 move a1 null-tn ; Default register values
222 loadi nargs 1 ; Force defaulting of stack values
223 move old-fp csp ; Set up args for SP resetting
226 subu temp nargs register-arg-count
228 bltz temp default-value-7 ; jump to default code
230 loadw move-temp old-fp-tn 6 ; Move value to correct location.
231 store-stack-tn val4-tn move-temp
233 bltz temp default-value-8
235 loadw move-temp old-fp-tn 7
236 store-stack-tn val5-tn move-temp
241 move sp old-fp ; Reset SP.
246 store-stack-tn val4-tn null-tn ; Nil out 7'th value. (first on stack)
249 store-stack-tn val5-tn null-tn ; Nil out 8'th value.
257 (defun default-unknown-values (vop values nvals move-temp temp lra-label)
258 (declare (type (or tn-ref null) values)
259 (type unsigned-byte nvals)
260 (type tn move-temp temp))
263 ;; Note that this is a single-value return point. This is actually
264 ;; the multiple-value entry point for a single desired value, but
265 ;; the code location has to be here, or the debugger backtrace
267 (without-scheduling ()
268 (note-this-location vop :single-value-return)
269 (move ocfp-tn csp-tn t)
272 (inst compute-code-from-lra code-tn lra-label temp code-tn)))
274 (let ((regs-defaulted (gen-label))
275 (defaulting-done (gen-label))
276 (default-stack-vals (gen-label)))
277 (without-scheduling ()
278 ;; Note that this is an unknown-values return point.
279 (note-this-location vop :unknown-return)
280 ;; Branch off to the MV case.
281 (inst b regs-defaulted) ; dont nullify
282 ;; If there are no stack results, clear the stack before branch.
283 (if (> nvals register-arg-count) ; what inst to late-branch-exec
284 (inst addi (fixnumize (- register-arg-count)) nargs-tn temp)
285 (move ocfp-tn csp-tn t)))
286 ;; Do the single value case.
288 (val (tn-ref-across values) (tn-ref-across val)))
289 ((= i (min nvals register-arg-count)))
290 (move null-tn (tn-ref-tn val)))
291 (when (> nvals register-arg-count)
292 (inst b default-stack-vals)
293 (move csp-tn ocfp-tn t))
295 (emit-label regs-defaulted)
297 (when (> nvals register-arg-count)
298 ;; If there are stack results, we have to default them
299 ;; and clear the stack.
300 (collect ((defaults))
301 (do ((i register-arg-count (1+ i))
302 (val (do ((i 0 (1+ i))
303 (val values (tn-ref-across val)))
304 ((= i register-arg-count) val))
305 (tn-ref-across val)))
308 (let ((default-lab (gen-label))
309 (tn (tn-ref-tn val)))
310 (defaults (cons default-lab tn))
312 (inst ldw (* i n-word-bytes) ocfp-tn move-temp)
313 (inst bc :<= nil temp zero-tn default-lab)
314 (inst addi (fixnumize -1) temp temp)
315 (store-stack-tn tn move-temp)))
317 (emit-label defaulting-done)
318 (move ocfp-tn csp-tn)
320 (let ((defaults (defaults)))
322 (assemble (*elsewhere*)
323 (emit-label default-stack-vals)
324 (trace-table-entry trace-table-fun-prologue)
325 (do ((remaining defaults (cdr remaining)))
327 (let ((def (car remaining)))
328 (emit-label (car def))
329 (when (null (cdr remaining))
330 (inst b defaulting-done))
331 (store-stack-tn (cdr def) null-tn)))
332 (trace-table-entry trace-table-normal)))))
334 (inst compute-code-from-lra code-tn lra-label temp code-tn)))))
338 ;;;; Unknown values receiving:
340 ;;; Emit code needed at the return point for an unknown-values call for an
341 ;;; arbitrary number of values.
343 ;;; We do the single and non-single cases with no shared code: there doesn't
344 ;;; seem to be any potential overlap, and receiving a single value is more
345 ;;; important efficiency-wise.
347 ;;; When there is a single value, we just push it on the stack, returning
348 ;;; the old SP and 1.
350 ;;; When there is a variable number of values, we move all of the argument
351 ;;; registers onto the stack, and return Args and Nargs.
353 ;;; Args and Nargs are TNs wired to the named locations. We must
354 ;;; explicitly allocate these TNs, since their lifetimes overlap with the
355 ;;; 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 (let ((variable-values (gen-label))
360 (without-scheduling ()
361 (inst b variable-values :nullify t)
362 (inst nop)) ; nop because of emit-return-pc alignment
365 (inst compute-code-from-lra code-tn lra-label temp code-tn))
366 (inst addi n-word-bytes csp-tn csp-tn)
367 (storew (first *register-arg-tns*) csp-tn -1)
368 (inst addi (- n-word-bytes) csp-tn start)
369 (inst li (fixnumize 1) count)
373 (assemble (*elsewhere*)
374 (trace-table-entry trace-table-fun-prologue)
375 (emit-label variable-values)
377 (inst compute-code-from-lra code-tn lra-label temp code-tn))
378 (do ((arg *register-arg-tns* (rest arg))
381 (storew (first arg) args i))
385 (trace-table-entry trace-table-normal)))
388 ;;; VOP that can be inherited by unknown values receivers. The main thing this
389 ;;; handles is allocation of the result temporaries.
391 (define-vop (unknown-values-receiver)
392 (:results (start :scs (any-reg))
393 (count :scs (any-reg)))
394 (:temporary (:sc descriptor-reg :offset ocfp-offset
395 :from :eval :to (:result 0))
397 (:temporary (:sc any-reg :offset nargs-offset
398 :from :eval :to (:result 1))
400 (:temporary (:scs (non-descriptor-reg)) temp))
404 ;;;; Local call with unknown values convention return:
406 ;;; Non-TR local call for a fixed number of values passed according to the
407 ;;; unknown values convention.
409 ;;; Args are the argument passing locations, which are specified only to
410 ;;; terminate their lifetimes in the caller.
412 ;;; Values are the return value locations (wired to the standard passing
415 ;;; Save is the save info, which we can ignore since saving has been done.
416 ;;; Return-PC is the TN that the return PC should be passed in.
417 ;;; Target is a continuation pointing to the start of the called function.
418 ;;; Nvals is the number of values received.
420 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
421 ;;; registers may be tied up by the more operand. Instead, we use
422 ;;; MAYBE-LOAD-STACK-TN.
424 (define-vop (call-local)
428 (:results (values :more t))
430 (:move-args :local-call)
431 (:info arg-locs callee target nvals)
433 (:temporary (:scs (descriptor-reg) :from :eval) move-temp)
434 (:temporary (:scs (non-descriptor-reg)) temp)
435 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
436 (:temporary (:sc any-reg :offset ocfp-offset :from :eval) ocfp)
437 (:ignore arg-locs args ocfp)
439 (let ((label (gen-label))
440 (cur-nfp (current-nfp-tn vop)))
442 (store-stack-tn nfp-save cur-nfp))
443 (let ((callee-nfp (callee-nfp-tn callee)))
445 (maybe-load-stack-tn callee-nfp nfp)))
446 (maybe-load-stack-tn cfp-tn cfp)
447 (trace-table-entry trace-table-call-site)
448 (inst compute-lra-from-code code-tn label temp
449 (callee-return-pc-tn callee))
450 (note-this-location vop :call-site)
451 (inst b target :nullify t)
452 (trace-table-entry trace-table-normal)
453 (emit-return-pc label)
454 (default-unknown-values vop values nvals move-temp temp label)
456 (load-stack-tn cur-nfp nfp-save)))))
458 ;;; Non-TR local call for a variable number of return values passed according
459 ;;; to the unknown values convention. The results are the start of the values
460 ;;; glob and the number of values received.
462 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
463 ;;; registers may be tied up by the more operand. Instead, we use
464 ;;; MAYBE-LOAD-STACK-TN.
466 (define-vop (multiple-call-local unknown-values-receiver)
471 (:move-args :local-call)
472 (:info save callee target)
475 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
476 (:temporary (:scs (non-descriptor-reg)) temp)
478 (let ((label (gen-label))
479 (cur-nfp (current-nfp-tn vop)))
481 (store-stack-tn nfp-save cur-nfp))
482 (let ((callee-nfp (callee-nfp-tn callee)))
484 (maybe-load-stack-tn callee-nfp nfp)))
485 (maybe-load-stack-tn cfp-tn cfp)
486 (trace-table-entry trace-table-call-site)
487 (inst compute-lra-from-code code-tn label temp
488 (callee-return-pc-tn callee))
489 (note-this-location vop :call-site)
490 (inst b target :nullify t)
491 (trace-table-entry trace-table-normal)
492 (emit-return-pc label)
493 (note-this-location vop :unknown-return)
494 (receive-unknown-values values-start nvals start count label temp)
496 (load-stack-tn cur-nfp nfp-save)))))
499 ;;;; Local call with known values return:
501 ;;; Non-TR local call with known return locations. Known-value return works
502 ;;; just like argument passing in local call.
504 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
505 ;;; registers may be tied up by the more operand. Instead, we use
506 ;;; MAYBE-LOAD-STACK-TN.
508 (define-vop (known-call-local)
512 (:results (res :more t))
513 (:move-args :local-call)
515 (:info save callee target)
516 (:ignore args res save)
518 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
519 (:temporary (:scs (non-descriptor-reg)) temp)
521 (let ((label (gen-label))
522 (cur-nfp (current-nfp-tn vop)))
524 (store-stack-tn nfp-save cur-nfp))
525 (let ((callee-nfp (callee-nfp-tn callee)))
527 (maybe-load-stack-tn callee-nfp nfp)))
528 (maybe-load-stack-tn cfp-tn cfp)
529 (trace-table-entry trace-table-call-site)
530 (inst compute-lra-from-code code-tn label temp
531 (callee-return-pc-tn callee))
532 (note-this-location vop :call-site)
533 (inst b target :nullify t)
534 (trace-table-entry trace-table-normal)
535 (emit-return-pc label)
536 (note-this-location vop :known-return)
538 (load-stack-tn cur-nfp nfp-save)))))
540 ;;; Return from known values call. We receive the return locations as
541 ;;; arguments to terminate their lifetimes in the returning function. We
542 ;;; restore FP and CSP and jump to the Return-PC.
544 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
545 ;;; registers may be tied up by the more operand. Instead, we use
546 ;;; MAYBE-LOAD-STACK-TN.
548 (define-vop (known-return)
549 (:args (ocfp :target ocfp-temp)
550 (return-pc :target return-pc-temp)
552 (:temporary (:sc any-reg :from (:argument 0)) ocfp-temp)
553 (:temporary (:sc descriptor-reg :from (:argument 1)) return-pc-temp)
554 (:temporary (:scs (interior-reg)) lip)
555 (:move-args :known-return)
557 (:ignore val-locs vals)
560 (trace-table-entry trace-table-fun-epilogue)
561 (maybe-load-stack-tn ocfp-temp ocfp)
562 (maybe-load-stack-tn return-pc-temp return-pc)
564 (let ((cur-nfp (current-nfp-tn vop)))
566 (move cur-nfp nsp-tn)))
567 (inst addi (- n-word-bytes other-pointer-lowtag) return-pc-temp lip)
569 (move ocfp-temp cfp-tn t)
570 (trace-table-entry trace-table-normal)))
575 ;;; There is something of a cross-product effect with full calls. Different
576 ;;; versions are used depending on whether we know the number of arguments or
577 ;;; the name of the called function, and whether we want fixed values, unknown
578 ;;; values, or a tail call.
580 ;;; In full call, the arguments are passed creating a partial frame on the
581 ;;; stack top and storing stack arguments into that frame. On entry to the
582 ;;; callee, this partial frame is pointed to by FP. If there are no stack
583 ;;; arguments, we don't bother allocating a partial frame, and instead set FP
584 ;;; to SP just before the call.
586 ;;; This macro helps in the definition of full call VOPs by avoiding code
587 ;;; replication in defining the cross-product VOPs.
589 ;;; Name is the name of the VOP to define.
591 ;;; Named is true if the first argument is a symbol whose global function
592 ;;; definition is to be called.
594 ;;; Return is either :Fixed, :Unknown or :Tail:
595 ;;; -- If :Fixed, then the call is for a fixed number of values, returned in
596 ;;; the standard passing locations (passed as result operands).
597 ;;; -- If :Unknown, then the result values are pushed on the stack, and the
598 ;;; result values are specified by the Start and Count as in the
599 ;;; unknown-values continuation representation.
600 ;;; -- If :Tail, then do a tail-recursive call. No values are returned.
601 ;;; The Old-Fp and Return-PC are passed as the second and third arguments.
603 ;;; In non-tail calls, the pointer to the stack arguments is passed as the last
604 ;;; fixed argument. If Variable is false, then the passing locations are
605 ;;; passed as a more arg. Variable is true if there are a variable number of
606 ;;; arguments passed on the stack. Variable cannot be specified with :Tail
607 ;;; return. TR variable argument call is implemented separately.
609 ;;; In tail call with fixed arguments, the passing locations are passed as a
610 ;;; more arg, but there is no new-FP, since the arguments have been set up in
611 ;;; the current frame.
614 (macrolet ((define-full-call (name named return variable)
615 (aver (not (and variable (eq return :tail))))
617 ,@(when (eq return :unknown)
618 '(unknown-values-receiver)))
620 ,@(unless (eq return :tail)
621 '((new-fp :scs (any-reg) :to :eval)))
624 '(name :target name-pass)
625 '(arg-fun :target lexenv))
627 ,@(when (eq return :tail)
628 '((ocfp :target ocfp-pass)
629 (return-pc :target return-pc-pass)))
631 ,@(unless variable '((args :more t :scs (descriptor-reg)))))
633 ,@(when (eq return :fixed)
634 '((:results (values :more t))))
636 (:save-p ,(if (eq return :tail) :compute-only t))
638 ,@(unless (or (eq return :tail) variable)
639 '((:move-args :full-call)))
642 (:info ,@(unless (or variable (eq return :tail)) '(arg-locs))
643 ,@(unless variable '(nargs))
644 ,@(when (eq return :fixed) '(nvals))
648 ,@(unless (or variable (eq return :tail)) '(arg-locs))
649 ,@(unless variable '(args)))
651 (:temporary (:sc descriptor-reg
654 ,@(unless (eq return :fixed)
658 (:temporary (:sc descriptor-reg
660 :from (:argument ,(if (eq return :tail) 2 1))
665 `((:temporary (:sc descriptor-reg :offset fdefn-offset
666 :from (:argument ,(if (eq return :tail) 0 1))
670 `((:temporary (:sc descriptor-reg :offset lexenv-offset
671 :from (:argument ,(if (eq return :tail) 0 1))
674 (:temporary (:scs (descriptor-reg) :from (:argument 0) :to :eval)
677 (:temporary (:sc any-reg :offset nargs-offset :to :eval)
681 (mapcar (lambda (name offset)
682 `(:temporary (:sc descriptor-reg
686 register-arg-names *register-arg-offsets*))
687 ,@(when (eq return :fixed)
688 '((:temporary (:scs (descriptor-reg) :from :eval) move-temp)))
690 (:temporary (:scs (descriptor-reg) :to :eval) stepping)
692 ,@(unless (eq return :tail)
693 '((:temporary (:scs (non-descriptor-reg)) temp)
694 (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)))
696 (:temporary (:sc interior-reg :offset lip-offset) entry-point)
698 (:generator ,(+ (if named 5 0)
700 (if (eq return :tail) 0 10)
702 (if (eq return :unknown) 25 0))
703 (let* ((cur-nfp (current-nfp-tn vop))
704 ,@(unless (eq return :tail)
705 '((lra-label (gen-label))))
706 (step-done-label (gen-label))
710 ,@(if (eq return :tail)
711 '((unless (location= ocfp ocfp-pass)
713 (unless (location= return-pc
723 (flet ((do-next-filler ()
724 (let* ((next (pop filler))
725 (what (if (consp next) (car next) next)))
729 `((inst sub csp-tn new-fp nargs-pass)
731 (mapcar (lambda (name)
732 `(inst ldw ,(ash (incf index)
736 register-arg-names)))
737 '((inst li (fixnumize nargs) nargs-pass))))
738 ,@(if (eq return :tail)
742 (move ocfp ocfp-pass t))
744 (inst ldw (ash (tn-offset ocfp)
750 (move return-pc return-pc-pass t))
752 (inst ldw (ash (tn-offset return-pc)
754 cfp-tn return-pc-pass))))
756 (inst addi (- (bytes-needed-for-non-descriptor-stack-frame))
759 (inst compute-lra-from-code code-tn lra-label
760 temp return-pc-pass))
762 (store-stack-tn nfp-save cur-nfp))
764 (move cfp-tn ocfp-pass t))
767 '(move new-fp cfp-tn)
768 '(if (> nargs register-arg-count)
770 (move csp-tn cfp-tn)))
771 (trace-table-entry trace-table-call-site))))
774 (insert-step-instrumenting (callable-tn)
775 ;; Conditionally insert a conditional trap:
776 (when step-instrumenting
777 ;; Get the symbol-value of SB!IMPL::*STEPPING*
778 (inst ldw (- (+ symbol-value-slot
779 (truncate (static-symbol-offset 'sb!impl::*stepping*)
781 other-pointer-lowtag)
783 ;; If it's not NIL, trap.
784 ;(inst comb := stepping null-tn step-done-label)
785 (inst comb := null-tn null-tn step-done-label :nullify t)
786 ;; CONTEXT-PC will be pointing here when the
787 ;; interrupt is handled, not after the BREAK.
788 (note-this-location vop :step-before-vop)
789 ;; Construct a trap code with the low bits from
790 ;; SINGLE-STEP-AROUND-TRAP and the high bits from
791 ;; the register number of CALLABLE-TN.
792 (inst break 0 (logior single-step-around-trap
793 (ash (reg-tn-encoding callable-tn)
795 (emit-label step-done-label))))
798 (descriptor-reg (move name name-pass))
800 (inst ldw (ash (tn-offset name) word-shift)
804 (inst ldw (- (ash (tn-offset name) word-shift)
805 other-pointer-lowtag)
808 ;; The step instrumenting must be done after
809 ;; FUNCTION is loaded, but before ENTRY-POINT is
811 (insert-step-instrumenting name-pass)
812 (inst ldw (- (ash fdefn-raw-addr-slot word-shift)
813 other-pointer-lowtag)
814 name-pass entry-point)
818 (move arg-fun lexenv))
820 (inst ldw (ash (tn-offset arg-fun) word-shift)
825 (- (ash (tn-offset arg-fun) word-shift)
826 other-pointer-lowtag) code-tn lexenv)
828 (inst ldw (- (ash closure-fun-slot word-shift)
832 ;; The step instrumenting must be done before
833 ;; after FUNCTION is loaded, but before ENTRY-POINT
835 (insert-step-instrumenting function)
836 (inst addi (- (ash simple-fun-code-offset word-shift)
838 function entry-point)))
845 (note-this-location vop :call-site)
846 (inst bv entry-point :nullify t))
850 '((trace-table-entry trace-table-normal)
851 (emit-return-pc lra-label)
852 (default-unknown-values vop values nvals
853 move-temp temp lra-label)
855 (load-stack-tn cur-nfp nfp-save))))
857 '((trace-table-entry trace-table-normal)
858 (emit-return-pc lra-label)
859 (note-this-location vop :unknown-return)
860 (receive-unknown-values values-start nvals start count
863 (load-stack-tn cur-nfp nfp-save))))
866 (define-full-call call nil :fixed nil)
867 (define-full-call call-named t :fixed nil)
868 (define-full-call multiple-call nil :unknown nil)
869 (define-full-call multiple-call-named t :unknown nil)
870 (define-full-call tail-call nil :tail nil)
871 (define-full-call tail-call-named t :tail nil)
873 (define-full-call call-variable nil :fixed t)
874 (define-full-call multiple-call-variable nil :unknown t))
877 ;;; Defined separately, since needs special code that blits the arguments
880 (define-vop (tail-call-variable)
881 (:args (args-arg :scs (any-reg) :target args)
882 (function-arg :scs (descriptor-reg) :target lexenv)
883 (ocfp-arg :scs (any-reg) :target ocfp)
884 (lra-arg :scs (descriptor-reg) :target lra))
886 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 0)) args)
887 (:temporary (:sc any-reg :offset lexenv-offset :from (:argument 1)) lexenv)
888 (:temporary (:sc any-reg :offset ocfp-offset :from (:argument 2)) ocfp)
889 (:temporary (:sc any-reg :offset lra-offset :from (:argument 3)) lra)
890 (:temporary (:scs (any-reg) :from (:argument 3)) tmp)
893 ;; Move these into the passing locations if they are not already there.
895 (move function-arg lexenv)
898 ;; And jump to the assembly-routine that does the bliting.
899 (let ((fixup (make-fixup 'tail-call-variable :assembly-routine)))
900 (inst ldil fixup tmp)
901 (inst be fixup lisp-heap-space tmp))
902 ;; Pull the number stack if anything is there.
903 (let ((cur-nfp (current-nfp-tn vop)))
905 ;;; NSP is restored by setting it to NSP,
906 ;;; because stack grows towards higher addresses.
907 (move cur-nfp nsp-tn)
911 ;;;; Unknown values return:
913 ;;; Return a single value using the unknown-values convention.
915 ;;; NSP is restored by setting it to NSP, because stack grows
916 ;;; towards higher addresses.
917 (define-vop (return-single)
918 (:args (ocfp :scs (any-reg))
919 (return-pc :scs (descriptor-reg))
924 ;; Clear the number stack.
925 (trace-table-entry trace-table-fun-epilogue)
926 (let ((cur-nfp (current-nfp-tn vop)))
928 (move cur-nfp nsp-tn)))
929 ;; Clear the control stack, and restore the frame pointer.
933 (lisp-return return-pc :offset 2)
934 (trace-table-entry trace-table-normal)))
936 ;;; Do unknown-values return of a fixed number of values. The Values are
937 ;;; required to be set up in the standard passing locations. Nvals is the
938 ;;; number of values returned.
940 ;;; If returning a single value, then deallocate the current frame, restore
941 ;;; FP and jump to the single-value entry at Return-PC + 8.
943 ;;; If returning other than one value, then load the number of values returned,
944 ;;; NIL out unsupplied values registers, restore FP and return at Return-PC.
945 ;;; When there are stack values, we must initialize the argument pointer to
946 ;;; point to the beginning of the values block (which is the beginning of the
950 (:args (ocfp :scs (any-reg))
951 (return-pc :scs (descriptor-reg) :to (:eval 1))
955 (:temporary (:sc descriptor-reg :offset a0-offset :from (:eval 0)) a0)
956 (:temporary (:sc descriptor-reg :offset a1-offset :from (:eval 0)) a1)
957 (:temporary (:sc descriptor-reg :offset a2-offset :from (:eval 0)) a2)
958 (:temporary (:sc descriptor-reg :offset a3-offset :from (:eval 0)) a3)
959 (:temporary (:sc descriptor-reg :offset a4-offset :from (:eval 0)) a4)
960 (:temporary (:sc descriptor-reg :offset a5-offset :from (:eval 0)) a5)
961 (:temporary (:sc any-reg :offset nargs-offset) nargs)
962 (:temporary (:sc any-reg :offset ocfp-offset) val-ptr)
966 ;; Clear the number stack.
967 (trace-table-entry trace-table-fun-epilogue)
968 (let ((cur-nfp (current-nfp-tn vop)))
970 (move cur-nfp nsp-tn)))
972 ((= nvals 1) ;; Clear the control stack, and restore the frame pointer
976 (lisp-return return-pc :offset 2))
978 ;; Establish the values pointer and values count.
979 (move cfp-tn val-ptr)
980 (inst li (fixnumize nvals) nargs)
981 ;; restore the frame pointer and clear as much of the control
982 ;; stack as possible.
984 (inst addi (* nvals n-word-bytes) val-ptr csp-tn)
985 (aver (= (* nvals n-word-bytes) (fixnumize nvals)))
986 ;; pre-default any argument register that need it.
987 (when (< nvals register-arg-count)
988 (dolist (reg (subseq (list a0 a1 a2 a3 a4 a5) nvals))
991 (lisp-return return-pc)))
992 (trace-table-entry trace-table-normal)))
994 ;;; Do unknown-values return of an arbitrary number of values (passed on the
995 ;;; stack.) We check for the common case of a single return value, and do that
996 ;;; inline using the normal single value return convention. Otherwise, we
997 ;;; branch off to code that calls an assembly-routine.
999 (define-vop (return-multiple)
1000 (:args (ocfp-arg :scs (any-reg) :target ocfp)
1001 (lra-arg :scs (descriptor-reg) :target lra)
1002 (vals-arg :scs (any-reg) :target vals)
1003 (nvals-arg :scs (any-reg) :target nvals))
1005 (:temporary (:sc any-reg :offset nl1-offset :from (:argument 0)) ocfp)
1006 (:temporary (:sc descriptor-reg :offset lra-offset :from (:argument 1)) lra)
1007 (:temporary (:sc any-reg :offset nl0-offset :from (:argument 2)) vals)
1008 (:temporary (:sc any-reg :offset nargs-offset :from (:argument 3)) nvals)
1009 (:temporary (:sc descriptor-reg :offset a0-offset) a0)
1010 (:temporary (:scs (any-reg) :from (:eval 0)) tmp)
1013 (trace-table-entry trace-table-fun-epilogue)
1014 (let ((not-single (gen-label)))
1015 ;; Clear the number stack.
1016 (let ((cur-nfp (current-nfp-tn vop)))
1018 (move cur-nfp nsp-tn)))
1019 ;; Check for the single case.
1020 (inst comib :<> (fixnumize 1) nvals-arg not-single)
1022 ;; Return with one value.
1023 (move cfp-tn csp-tn)
1024 (move ocfp-arg cfp-tn)
1025 (lisp-return lra-arg :offset 2)
1026 ;; Nope, not the single case.
1027 (emit-label not-single)
1028 ;; most of these moves will not be emitted and therefor
1029 ;; isn't suitable to put in the delay slot below. But if
1030 ;; you do, dont forget to force-emit as in (move src dst t)
1031 (move ocfp-arg ocfp)
1033 (move vals-arg vals)
1034 (move nvals-arg nvals)
1035 (let ((fixup (make-fixup 'return-multiple :assembly-routine)))
1036 (inst ldil fixup tmp)
1037 (inst be fixup lisp-heap-space tmp :nullify t)))
1038 (trace-table-entry trace-table-normal)))
1043 ;;; We don't need to do anything special for regular functions.
1045 (define-vop (setup-environment)
1049 ;; Don't bother doing anything.
1052 ;;; Get the lexical environment from its passing location.
1054 (define-vop (setup-closure-environment)
1055 (:temporary (:sc descriptor-reg :offset lexenv-offset :target closure
1058 (:results (closure :scs (descriptor-reg)))
1063 (move lexenv closure)))
1065 ;;; Copy a more arg from the argument area to the end of the current frame.
1066 ;;; Fixed is the number of non-more arguments.
1067 ;;; FIXME-lav: old hppa code look smarter.
1068 (define-vop (copy-more-arg)
1069 (:temporary (:sc any-reg :offset nl0-offset) result)
1070 (:temporary (:sc any-reg :offset nl1-offset) count)
1071 (:temporary (:sc any-reg :offset nl2-offset) src)
1072 (:temporary (:sc any-reg :offset nl3-offset) dst)
1073 (:temporary (:sc descriptor-reg :offset l0-offset) temp)
1076 (let ((loop (gen-label))
1077 (do-regs (gen-label))
1079 (when (< fixed register-arg-count)
1080 ;; Save a pointer to the results so we can fill in register args.
1081 ;; We don't need this if there are more fixed args than reg args.
1082 (move csp-tn result))
1083 ;; Allocate the space on the stack.
1084 (cond ((zerop fixed)
1085 (inst comb := nargs-tn zero-tn done)
1086 (inst add nargs-tn csp-tn csp-tn))
1088 (inst addi (fixnumize (- fixed)) nargs-tn count)
1089 (inst comb :<= count zero-tn done :nullify t)
1090 (inst add count csp-tn csp-tn)))
1091 (when (< fixed register-arg-count)
1092 ;; We must stop when we run out of stack args, not when we run out of
1094 (inst addi (fixnumize (- register-arg-count)) nargs-tn count))
1095 ;; Everything of interest in registers.
1096 (inst comb :<= count zero-tn do-regs)
1097 ;; Initialize dst to be end of stack.
1099 ;; Initialize src to be end of args.
1100 (inst add nargs-tn cfp-tn src)
1103 ;; decrease src, then load src into temp
1104 (inst ldwm (- n-word-bytes) src temp)
1105 ;; increase, compare if count >= to zero, if true, jump
1106 (inst addib :>= (fixnumize -1) count loop)
1107 ;; decrease dst, then store temp at dst
1108 (inst stwm temp (- n-word-bytes) dst)
1110 (emit-label do-regs)
1111 (when (< fixed register-arg-count)
1112 ;; Now we have to deposit any more args that showed up in registers.
1113 ;; We know there is at least one more arg, otherwise we would have
1114 ;; branched to done up at the top.
1115 (inst addi (- (fixnumize (1+ fixed))) nargs-tn count)
1116 (do ((i fixed (1+ i)))
1117 ((>= i register-arg-count))
1118 ;; Is this the last one?
1119 (inst comb := count zero-tn done)
1120 ;; Store it relative to the pointer saved at the start.
1121 (storew (nth i *register-arg-tns*) result (- i fixed))
1123 (inst addi (- (fixnumize 1)) count count)))
1124 (emit-label done))))
1126 ;;; More args are stored consequtively on the stack, starting immediately at
1127 ;;; the context pointer. The context pointer is not typed, so the lowtag is 0.
1129 (define-full-reffer more-arg * 0 0 (descriptor-reg any-reg) * %more-arg)
1131 ;;; Turn more arg (context, count) into a list.
1132 (define-vop (listify-rest-args)
1133 (:translate %listify-rest-args)
1134 (:args (context-arg :target context :scs (descriptor-reg))
1135 (count-arg :target count :scs (any-reg)))
1136 (:arg-types * tagged-num)
1137 (:temporary (:scs (any-reg) :from (:argument 0)) context)
1138 (:temporary (:scs (any-reg) :from (:argument 1)) count)
1139 (:temporary (:scs (descriptor-reg) :from :eval) temp dst)
1140 (:results (result :scs (descriptor-reg)))
1144 (let* ((enter (gen-label))
1147 (dx-p (node-stack-allocate-p node))
1148 (alloc-area-tn (if dx-p csp-tn alloc-tn)))
1149 (move context-arg context)
1150 (move count-arg count)
1151 ;; Check to see if there are any arguments.
1152 (inst comb := count zero-tn done)
1153 (move null-tn result t)
1155 ;; We need to do this atomically.
1159 ;; Allocate a cons (2 words) for each item.
1160 (set-lowtag list-pointer-lowtag alloc-area-tn result)
1162 (inst sll count 1 temp)
1164 (inst add temp alloc-area-tn alloc-area-tn)
1166 ;; Store the current cons in the cdr of the previous cons.
1168 (inst addi (* 2 n-word-bytes) dst dst)
1169 (storew dst dst -1 list-pointer-lowtag)
1173 (inst ldwm n-word-bytes context temp)
1174 ;; Dec count, and if != zero, go back for more.
1175 (inst addib :<> (fixnumize -1) count loop)
1176 ;; Store the value in the car (in delay slot)
1177 (storew temp dst 0 list-pointer-lowtag)
1179 ;; NIL out the last cons.
1180 (storew null-tn dst 1 list-pointer-lowtag))
1181 (emit-label done))))
1183 ;;; Return the location and size of the more arg glob created by Copy-More-Arg.
1184 ;;; Supplied is the total number of arguments supplied (originally passed in
1185 ;;; NARGS.) Fixed is the number of non-rest arguments.
1187 ;;; We must duplicate some of the work done by Copy-More-Arg, since at that
1188 ;;; time the environment is in a pretty brain-damaged state, preventing this
1189 ;;; info from being returned as values. What we do is compute
1190 ;;; supplied - fixed, and return a pointer that many words below the current
1193 (define-vop (more-arg-context)
1194 (:policy :fast-safe)
1195 (:translate sb!c::%more-arg-context)
1196 (:args (supplied :scs (any-reg)))
1197 (:arg-types tagged-num (:constant fixnum))
1199 (:results (context :scs (descriptor-reg))
1200 (count :scs (any-reg)))
1201 (:result-types t tagged-num)
1202 (:note "more-arg-context")
1204 (inst addi (fixnumize (- fixed)) supplied count)
1205 (inst sub csp-tn count context)))
1207 ;;; Signal wrong argument count error if Nargs isn't = to Count.
1209 (define-vop (verify-arg-count)
1210 (:policy :fast-safe)
1211 (:translate sb!c::%verify-arg-count)
1212 (:args (nargs :scs (any-reg)))
1213 (:arg-types positive-fixnum (:constant t))
1216 (:save-p :compute-only)
1219 (generate-error-code vop invalid-arg-count-error nargs)))
1220 (cond ((zerop count)
1221 (inst bc :<> nil nargs zero-tn err-lab))
1223 (inst bci :<> nil (fixnumize count) nargs err-lab))))))
1225 ;;; Signal argument errors.
1227 (macrolet ((frob (name error translate &rest args)
1228 `(define-vop (,name)
1230 `((:policy :fast-safe)
1231 (:translate ,translate)))
1232 (:args ,@(mapcar #'(lambda (arg)
1233 `(,arg :scs (any-reg descriptor-reg)))
1236 (:save-p :compute-only)
1238 (error-call vop ,error ,@args)))))
1239 (frob arg-count-error invalid-arg-count-error
1240 sb!c::%arg-count-error nargs)
1241 (frob type-check-error object-not-type-error sb!c::%type-check-error
1243 (frob layout-invalid-error layout-invalid-error sb!c::%layout-invalid-error
1245 (frob odd-key-args-error odd-key-args-error
1246 sb!c::%odd-key-args-error)
1247 (frob unknown-key-arg-error unknown-key-arg-error
1248 sb!c::%unknown-key-arg-error key)
1249 (frob nil-fun-returned-error nil-fun-returned-error nil fun))
1253 (define-vop (step-instrument-before-vop)
1254 (:temporary (:scs (descriptor-reg)) stepping)
1255 (:policy :fast-safe)
1258 ;; Get the symbol-value of SB!IMPL::*STEPPING*
1259 (inst ldw (- (+ symbol-value-slot
1260 (truncate (static-symbol-offset 'sb!impl::*stepping*)
1262 other-pointer-lowtag)
1264 ;; If it's not NIL, trap.
1265 (inst comb := stepping null-tn DONE :nullify t)
1266 ;; CONTEXT-PC will be pointing here when the interrupt is handled,
1267 ;; not after the BREAK.
1268 (note-this-location vop :step-before-vop)
1269 ;; CALLEE-REGISTER-OFFSET isn't needed for before-traps, so we
1270 ;; can just use a bare SINGLE-STEP-BEFORE-TRAP as the code.
1271 (inst break 0 single-step-before-trap)