1 ;;;; the VM definition of function call for the PPC
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
14 ;;;; Interfaces to IR2 conversion:
16 ;;; Return a wired TN describing the N'th full call argument passing
18 (defun standard-arg-location (n)
19 (declare (type unsigned-byte n
))
20 (if (< n register-arg-count
)
21 (make-wired-tn *backend-t-primitive-type
* register-arg-scn
22 (elt *register-arg-offsets
* n
))
23 (make-wired-tn *backend-t-primitive-type
* control-stack-arg-scn n
)))
26 ;;; Make a passing location TN for a local call return PC. If
27 ;;; standard is true, then use the standard (full call) location,
28 ;;; otherwise use any legal location. Even in the non-standard case,
29 ;;; this may be restricted by a desire to use a subroutine call
31 (defun make-return-pc-passing-location (standard)
33 (make-wired-tn *backend-t-primitive-type
* register-arg-scn lra-offset
)
34 (make-restricted-tn *backend-t-primitive-type
* register-arg-scn
)))
36 ;;; This is similar to MAKE-RETURN-PC-PASSING-LOCATION, but makes a
37 ;;; location to pass OLD-FP in. This is (obviously) wired in the
38 ;;; standard convention, but is totally unrestricted in non-standard
39 ;;; conventions, since we can always fetch it off of the stack using
41 (defun make-old-fp-passing-location (standard)
43 (make-wired-tn *fixnum-primitive-type
* immediate-arg-scn ocfp-offset
)
44 (make-normal-tn *fixnum-primitive-type
*)))
46 ;;; Make the TNs used to hold OLD-FP and RETURN-PC within the current
47 ;;; function. We treat these specially so that the debugger can find
48 ;;; them at a known location.
49 (defun make-old-fp-save-location (env)
51 (physenv-debug-live-tn (make-normal-tn *fixnum-primitive-type
*) env
)
52 (make-wired-tn *fixnum-primitive-type
*
55 (defun make-return-pc-save-location (env)
57 (physenv-debug-live-tn (make-normal-tn *backend-t-primitive-type
*) env
)
58 (make-wired-tn *backend-t-primitive-type
*
62 ;;; Make a TN for the standard argument count passing location. We
63 ;;; only need to make the standard location, since a count is never
64 ;;; passed when we are using non-standard conventions.
65 (defun make-arg-count-location ()
66 (make-wired-tn *fixnum-primitive-type
* immediate-arg-scn nargs-offset
))
69 ;;; Make a TN to hold the number-stack frame pointer. This is
70 ;;; allocated once per component, and is component-live.
73 (make-wired-tn *fixnum-primitive-type
* immediate-arg-scn nfp-offset
)))
75 (defun make-stack-pointer-tn ()
76 (make-normal-tn *fixnum-primitive-type
*))
78 (defun make-number-stack-pointer-tn ()
79 (make-normal-tn *fixnum-primitive-type
*))
81 ;;; Return a list of TNs that can be used to represent an unknown-values
82 ;;; continuation within a function.
83 (defun make-unknown-values-locations ()
84 (list (make-stack-pointer-tn)
85 (make-normal-tn *fixnum-primitive-type
*)))
87 ;;; This function is called by the ENTRY-ANALYZE phase, allowing
88 ;;; VM-dependent initialization of the IR2-COMPONENT structure. We push
89 ;;; placeholder entries in the Constants to leave room for additional
90 ;;; noise in the code object header.
91 (defun select-component-format (component)
92 (declare (type component component
))
93 (dotimes (i code-constants-offset
)
94 (vector-push-extend nil
95 (ir2-component-constants (component-info component
))))
100 ;;; this is the first function in this file that differs materially from
101 ;;; ../alpha/call.lisp
102 (defun bytes-needed-for-non-descriptor-stack-frame ()
103 (logandc2 (+ +stack-alignment-bytes
+ number-stack-displacement
104 (* (sb-allocated-size 'non-descriptor-stack
) n-word-bytes
))
105 +stack-alignment-bytes
+))
108 ;;; Used for setting up the Old-FP in local call.
109 (define-vop (current-fp)
110 (:results
(val :scs
(any-reg)))
114 ;;; Used for computing the caller's NFP for use in known-values return. Only
115 ;;; works assuming there is no variable size stuff on the nstack.
116 (define-vop (compute-old-nfp)
117 (:results
(val :scs
(any-reg)))
120 (let ((nfp (current-nfp-tn vop
)))
122 (inst addi val nfp
(bytes-needed-for-non-descriptor-stack-frame))))))
124 ;;; Accessing a slot from an earlier stack frame is definite hackery.
125 (define-vop (ancestor-frame-ref)
126 (:args
(frame-pointer :scs
(descriptor-reg))
127 (variable-home-tn :load-if nil
))
128 (:results
(value :scs
(descriptor-reg any-reg
)))
131 (aver (sc-is variable-home-tn control-stack
))
132 (loadw value frame-pointer
(tn-offset variable-home-tn
))))
133 (define-vop (ancestor-frame-set)
134 (:args
(frame-pointer :scs
(descriptor-reg))
135 (value :scs
(descriptor-reg any-reg
)))
136 (:results
(variable-home-tn :load-if nil
))
139 (aver (sc-is variable-home-tn control-stack
))
140 (storew value frame-pointer
(tn-offset variable-home-tn
))))
142 (define-vop (xep-allocate-frame)
143 (:info start-lab copy-more-arg-follows
)
144 (:ignore copy-more-arg-follows
)
146 (:temporary
(:scs
(non-descriptor-reg)) temp
)
148 ;; Make sure the function is aligned, and drop a label pointing to this
150 (emit-alignment n-lowtag-bits
)
151 (trace-table-entry trace-table-fun-prologue
)
152 (emit-label start-lab
)
153 ;; Allocate function header.
154 (inst simple-fun-header-word
)
155 (dotimes (i (1- simple-fun-code-offset
))
157 (let* ((entry-point (gen-label)))
158 (emit-label entry-point
)
159 (inst compute-code-from-lip code-tn lip-tn entry-point temp
))
160 ;; FIXME alpha port has a ### note here saying we should "save it
161 ;; on the stack" so that GC sees it. No idea what "it" is -dan 20020110
162 ;; Build our stack frames.
163 (inst addi csp-tn cfp-tn
164 (* n-word-bytes
(sb-allocated-size 'control-stack
)))
165 (let ((nfp-tn (current-nfp-tn vop
)))
167 (let* ((nbytes (bytes-needed-for-non-descriptor-stack-frame)))
168 (when (> nbytes number-stack-displacement
)
169 (inst stwu nsp-tn nsp-tn
(- nbytes
))
170 (inst addi nfp-tn nsp-tn number-stack-displacement
)))))
171 (trace-table-entry trace-table-normal
)))
173 (define-vop (allocate-frame)
174 (:results
(res :scs
(any-reg))
175 (nfp :scs
(any-reg)))
178 (trace-table-entry trace-table-fun-prologue
)
180 (inst addi csp-tn csp-tn
181 (* n-word-bytes
(sb-allocated-size 'control-stack
)))
182 (when (ir2-physenv-number-stack-p callee
)
183 (let* ((nbytes (bytes-needed-for-non-descriptor-stack-frame)))
184 (when (> nbytes number-stack-displacement
)
185 (inst stwu nsp-tn nsp-tn
(- (bytes-needed-for-non-descriptor-stack-frame)))
186 (inst addi nfp nsp-tn number-stack-displacement
))))
187 (trace-table-entry trace-table-normal
)))
189 ;;; Allocate a partial frame for passing stack arguments in a full call. Nargs
190 ;;; is the number of arguments passed. If no stack arguments are passed, then
191 ;;; we don't have to do anything.
192 (define-vop (allocate-full-call-frame)
194 (:results
(res :scs
(any-reg)))
196 (when (> nargs register-arg-count
)
198 (inst addi csp-tn csp-tn
(* nargs n-word-bytes
)))))
200 ;;; Emit code needed at the return-point from an unknown-values call
201 ;;; for a fixed number of values. Values is the head of the TN-REF
202 ;;; list for the locations that the values are to be received into.
203 ;;; Nvals is the number of values that are to be received (should
204 ;;; equal the length of Values).
206 ;;; MOVE-TEMP is a DESCRIPTOR-REG TN used as a temporary.
208 ;;; This code exploits the fact that in the unknown-values convention,
209 ;;; a single value return returns at the return PC + 8, whereas a
210 ;;; return of other than one value returns directly at the return PC.
212 ;;; If 0 or 1 values are expected, then we just emit an instruction to
213 ;;; reset the SP (which will only be executed when other than 1 value
216 ;;; In the general case, we have to do three things:
217 ;;; -- Default unsupplied register values. This need only be done when a
218 ;;; single value is returned, since register values are defaulted by the
219 ;;; callee in the non-single case.
220 ;;; -- Default unsupplied stack values. This needs to be done whenever there
221 ;;; are stack values.
222 ;;; -- Reset SP. This must be done whenever other than 1 value is returned,
223 ;;; regardless of the number of values desired.
225 ;;; The general-case code looks like this:
227 b regs-defaulted
; Skip if MVs
230 move a1 null-tn
; Default register values
232 loadi nargs
1 ; Force defaulting of stack values
233 move old-fp csp
; Set up args for SP resetting
236 subcc temp nargs register-arg-count
238 b
:lt default-value-7
; jump to default code
239 loadw move-temp ocfp-tn
6 ; Move value to correct location.
241 store-stack-tn val4-tn move-temp
243 b
:lt default-value-8
244 loadw move-temp ocfp-tn
7
246 store-stack-tn val5-tn move-temp
251 move csp ocfp
; Reset SP.
256 store-stack-tn val4-tn null-tn
; Nil out 7'th value. (first on stack)
259 store-stack-tn val5-tn null-tn
; Nil out 8'th value.
266 ;;; differences from alpha: (1) alpha tests for lra-label before
267 ;;; compute-code-from-lra and skips if nil. (2) loop termination is
268 ;;; different when clearing stack defaults
270 (defun default-unknown-values (vop values nvals move-temp temp lra-label
)
271 (declare (type (or tn-ref null
) values
)
272 (type unsigned-byte nvals
) (type tn move-temp temp
))
275 (sb!assem
:without-scheduling
()
276 (note-this-location vop
:single-value-return
)
277 (move csp-tn ocfp-tn
)
279 (inst compute-code-from-lra code-tn lra-tn lra-label temp
))
280 (let ((regs-defaulted (gen-label))
281 (defaulting-done (gen-label))
282 (default-stack-vals (gen-label)))
283 ;; Branch off to the MV case.
284 (sb!assem
:without-scheduling
()
285 (note-this-location vop
:unknown-return
)
286 (if (> nvals register-arg-count
)
287 (inst addic. temp nargs-tn
(- (fixnumize register-arg-count
)))
288 (move csp-tn ocfp-tn
))
289 (inst b regs-defaulted
))
291 ;; Do the single value case.
293 (val (tn-ref-across values
) (tn-ref-across val
)))
294 ((= i
(min nvals register-arg-count
)))
295 (move (tn-ref-tn val
) null-tn
))
296 (when (> nvals register-arg-count
)
297 (move ocfp-tn csp-tn
)
298 (inst b default-stack-vals
))
300 (emit-label regs-defaulted
)
301 (when (> nvals register-arg-count
)
302 (collect ((defaults))
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
))
314 (inst lwz move-temp ocfp-tn
(* i n-word-bytes
))
315 (inst ble default-lab
)
316 (inst addic. temp temp
(- (fixnumize 1)))
317 (store-stack-tn tn move-temp
)))
319 (emit-label defaulting-done
)
320 (move csp-tn ocfp-tn
)
322 (let ((defaults (defaults)))
324 (assemble (*elsewhere
*)
325 (emit-label default-stack-vals
)
326 (trace-table-entry trace-table-fun-prologue
)
327 (do ((remaining defaults
(cdr remaining
)))
329 (let ((def (car remaining
)))
330 (emit-label (car def
))
331 (store-stack-tn (cdr def
) null-tn
)))
332 (inst b defaulting-done
)
333 (trace-table-entry trace-table-normal
))))))
335 (inst compute-code-from-lra code-tn lra-tn lra-label temp
)))
339 ;;;; Unknown values receiving:
341 ;;; Emit code needed at the return point for an unknown-values call for an
342 ;;; arbitrary number of values.
344 ;;; We do the single and non-single cases with no shared code: there doesn't
345 ;;; seem to be any potential overlap, and receiving a single value is more
346 ;;; important efficiency-wise.
348 ;;; When there is a single value, we just push it on the stack, returning
349 ;;; the old SP and 1.
351 ;;; When there is a variable number of values, we move all of the argument
352 ;;; registers onto the stack, and return Args and Nargs.
354 ;;; Args and Nargs are TNs wired to the named locations. We must
355 ;;; explicitly allocate these TNs, since their lifetimes overlap with the
356 ;;; results Start and Count (also, it's nice to be able to target them).
357 (defun receive-unknown-values (args nargs start count lra-label temp
)
358 (declare (type tn args nargs start count temp
))
359 (let ((variable-values (gen-label))
361 (sb!assem
:without-scheduling
()
362 (inst b variable-values
)
365 (inst compute-code-from-lra code-tn lra-tn lra-label temp
)
366 (inst addi csp-tn csp-tn
4)
367 (storew (first *register-arg-tns
*) csp-tn -
1)
368 (inst subi start csp-tn
4)
369 (inst li count
(fixnumize 1))
373 (assemble (*elsewhere
*)
374 (trace-table-entry trace-table-fun-prologue
)
375 (emit-label variable-values
)
376 (inst compute-code-from-lra code-tn lra-tn lra-label temp
)
377 (do ((arg *register-arg-tns
* (rest arg
))
380 (storew (first arg
) args i
))
384 (trace-table-entry trace-table-normal
)))
388 ;;; VOP that can be inherited by unknown values receivers. The main
389 ;;; thing this handles is allocation of the result temporaries.
390 (define-vop (unknown-values-receiver)
392 (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
))
403 ;;; This hook in the codegen pass lets us insert code before fall-thru entry
404 ;;; points, local-call entry points, and tail-call entry points. The default
406 (defun emit-block-header (start-label trampoline-label fall-thru-p alignp
)
407 (declare (ignore fall-thru-p alignp
))
408 (when trampoline-label
409 (emit-label trampoline-label
))
410 (emit-label start-label
))
413 ;;;; Local call with unknown values convention return:
415 ;;; Non-TR local call for a fixed number of values passed according to the
416 ;;; unknown values convention.
418 ;;; Args are the argument passing locations, which are specified only to
419 ;;; terminate their lifetimes in the caller.
421 ;;; Values are the return value locations (wired to the standard passing
424 ;;; Save is the save info, which we can ignore since saving has been done.
425 ;;; Return-PC is the TN that the return PC should be passed in.
426 ;;; Target is a continuation pointing to the start of the called function.
427 ;;; Nvals is the number of values received.
429 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
430 ;;; registers may be tied up by the more operand. Instead, we use
431 ;;; MAYBE-LOAD-STACK-TN.
432 (define-vop (call-local)
436 (:results
(values :more t
))
438 (:move-args
:local-call
)
439 (:info arg-locs callee target nvals
)
441 (:temporary
(:scs
(descriptor-reg) :from
(:eval
0)) move-temp
)
442 (:temporary
(:scs
(non-descriptor-reg)) temp
)
443 (:temporary
(:sc control-stack
:offset nfp-save-offset
) nfp-save
)
444 (:temporary
(:sc any-reg
:offset ocfp-offset
:from
(:eval
0)) ocfp
)
445 (:ignore arg-locs args ocfp
)
447 (trace-table-entry trace-table-call-site
)
448 (let ((label (gen-label))
449 (cur-nfp (current-nfp-tn vop
)))
451 (store-stack-tn nfp-save cur-nfp
))
452 (let ((callee-nfp (callee-nfp-tn callee
)))
454 (maybe-load-stack-tn callee-nfp nfp
)))
455 (maybe-load-stack-tn cfp-tn fp
)
456 (inst compute-lra-from-code
457 (callee-return-pc-tn callee
) code-tn label temp
)
458 (note-this-location vop
:call-site
)
460 (emit-return-pc label
)
461 (default-unknown-values vop values nvals move-temp temp label
)
462 ;; alpha uses (maybe-load-stack-nfp-tn cur-nfp nfp-save temp)
463 ;; instead of the clause below
465 (load-stack-tn cur-nfp nfp-save
)))
466 (trace-table-entry trace-table-normal
)))
469 ;;; Non-TR local call for a variable number of return values passed according
470 ;;; to the unknown values convention. The results are the start of the values
471 ;;; glob and the number of values received.
473 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
474 ;;; registers may be tied up by the more operand. Instead, we use
475 ;;; MAYBE-LOAD-STACK-TN.
476 (define-vop (multiple-call-local unknown-values-receiver
)
481 (:move-args
:local-call
)
482 (:info save callee target
)
485 (:temporary
(:sc control-stack
:offset nfp-save-offset
) nfp-save
)
486 (:temporary
(:scs
(non-descriptor-reg)) temp
)
488 (trace-table-entry trace-table-call-site
)
489 (let ((label (gen-label))
490 (cur-nfp (current-nfp-tn vop
)))
492 (store-stack-tn nfp-save cur-nfp
))
493 (let ((callee-nfp (callee-nfp-tn callee
)))
494 ;; alpha doesn't test this before the maybe-load
496 (maybe-load-stack-tn callee-nfp nfp
)))
497 (maybe-load-stack-tn cfp-tn fp
)
498 (inst compute-lra-from-code
499 (callee-return-pc-tn callee
) code-tn label temp
)
500 (note-this-location vop
:call-site
)
502 (emit-return-pc label
)
503 (note-this-location vop
:unknown-return
)
504 (receive-unknown-values values-start nvals start count label temp
)
506 (load-stack-tn cur-nfp nfp-save
)))
507 (trace-table-entry trace-table-normal
)))
510 ;;;; Local call with known values return:
512 ;;; Non-TR local call with known return locations. Known-value return works
513 ;;; just like argument passing in local call.
515 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
516 ;;; registers may be tied up by the more operand. Instead, we use
517 ;;; MAYBE-LOAD-STACK-TN.
518 (define-vop (known-call-local)
522 (:results
(res :more t
))
523 (:move-args
:local-call
)
525 (:info save callee target
)
526 (:ignore args res save
)
528 (:temporary
(:sc control-stack
:offset nfp-save-offset
) nfp-save
)
529 (:temporary
(:scs
(non-descriptor-reg)) temp
)
531 (trace-table-entry trace-table-call-site
)
532 (let ((label (gen-label))
533 (cur-nfp (current-nfp-tn vop
)))
535 (store-stack-tn nfp-save cur-nfp
))
536 (let ((callee-nfp (callee-nfp-tn callee
)))
538 (maybe-load-stack-tn callee-nfp nfp
)))
539 (maybe-load-stack-tn cfp-tn fp
)
540 (inst compute-lra-from-code
541 (callee-return-pc-tn callee
) code-tn label temp
)
542 (note-this-location vop
:call-site
)
544 (emit-return-pc label
)
545 (note-this-location vop
:known-return
)
547 (load-stack-tn cur-nfp nfp-save
)))
548 (trace-table-entry trace-table-normal
)))
550 ;;; Return from known values call. We receive the return locations as
551 ;;; arguments to terminate their lifetimes in the returning function. We
552 ;;; restore FP and CSP and jump to the Return-PC.
554 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
555 ;;; registers may be tied up by the more operand. Instead, we use
556 ;;; MAYBE-LOAD-STACK-TN.
557 (define-vop (known-return)
558 (:args
(old-fp :target old-fp-temp
)
559 (return-pc :target return-pc-temp
)
561 (:temporary
(:sc any-reg
:from
(:argument
0)) old-fp-temp
)
562 (:temporary
(:sc descriptor-reg
:from
(:argument
1)) return-pc-temp
)
563 (:move-args
:known-return
)
565 (:ignore val-locs vals
)
568 (trace-table-entry trace-table-fun-epilogue
)
569 (maybe-load-stack-tn old-fp-temp old-fp
)
570 (maybe-load-stack-tn return-pc-temp return-pc
)
572 (let ((cur-nfp (current-nfp-tn vop
)))
574 (inst addi nsp-tn cur-nfp
575 (- (bytes-needed-for-non-descriptor-stack-frame)
576 number-stack-displacement
))))
577 (move cfp-tn old-fp-temp
)
578 (inst j return-pc-temp
(- n-word-bytes other-pointer-lowtag
))
579 (trace-table-entry trace-table-normal
)))
584 ;;; There is something of a cross-product effect with full calls. Different
585 ;;; versions are used depending on whether we know the number of arguments or
586 ;;; the name of the called function, and whether we want fixed values, unknown
587 ;;; values, or a tail call.
589 ;;; In full call, the arguments are passed creating a partial frame on the
590 ;;; stack top and storing stack arguments into that frame. On entry to the
591 ;;; callee, this partial frame is pointed to by FP. If there are no stack
592 ;;; arguments, we don't bother allocating a partial frame, and instead set FP
593 ;;; to SP just before the call.
595 ;;; This macro helps in the definition of full call VOPs by avoiding code
596 ;;; replication in defining the cross-product VOPs.
598 ;;; NAME is the name of the VOP to define.
600 ;;; NAMED is true if the first argument is a symbol whose global function
601 ;;; definition is to be called.
603 ;;; RETURN is either :FIXED, :UNKNOWN or :TAIL:
604 ;;; -- If :FIXED, then the call is for a fixed number of values, returned in
605 ;;; the standard passing locations (passed as result operands).
606 ;;; -- If :UNKNOWN, then the result values are pushed on the stack, and the
607 ;;; result values are specified by the Start and Count as in the
608 ;;; unknown-values continuation representation.
609 ;;; -- If :TAIL, then do a tail-recursive call. No values are returned.
610 ;;; The Old-Fp and Return-PC are passed as the second and third arguments.
612 ;;; In non-tail calls, the pointer to the stack arguments is passed as the last
613 ;;; fixed argument. If VARIABLE is false, then the passing locations are
614 ;;; passed as a more arg. VARIABLE is true if there are a variable number of
615 ;;; arguments passed on the stack. VARIABLE cannot be specified with :TAIL
616 ;;; return. TR variable argument call is implemented separately.
618 ;;; In tail call with fixed arguments, the passing locations are passed as a
619 ;;; more arg, but there is no new-FP, since the arguments have been set up in
620 ;;; the current frame.
621 (defmacro define-full-call
(name named return variable
)
622 (aver (not (and variable
(eq return
:tail
))))
624 ,@(when (eq return
:unknown
)
625 '(unknown-values-receiver)))
627 ,@(unless (eq return
:tail
)
628 '((new-fp :scs
(any-reg) :to
:eval
)))
631 '(name :target name-pass
)
632 '(arg-fun :target lexenv
))
634 ,@(when (eq return
:tail
)
635 '((old-fp :target old-fp-pass
)
636 (return-pc :target return-pc-pass
)))
638 ,@(unless variable
'((args :more t
:scs
(descriptor-reg)))))
640 ,@(when (eq return
:fixed
)
641 '((:results
(values :more t
))))
643 (:save-p
,(if (eq return
:tail
) :compute-only t
))
645 ,@(unless (or (eq return
:tail
) variable
)
646 '((:move-args
:full-call
)))
649 (:info
,@(unless (or variable
(eq return
:tail
)) '(arg-locs))
650 ,@(unless variable
'(nargs))
651 ,@(when (eq return
:fixed
) '(nvals))
655 ,@(unless (or variable
(eq return
:tail
)) '(arg-locs))
656 ,@(unless variable
'(args)))
658 (:temporary
(:sc descriptor-reg
661 ,@(unless (eq return
:fixed
)
665 (:temporary
(:sc descriptor-reg
667 :from
(:argument
,(if (eq return
:tail
) 2 1))
672 `(:temporary
(:sc descriptor-reg
:offset fdefn-offset
; -dan
673 :from
(:argument
,(if (eq return
:tail
) 0 1))
676 `(:temporary
(:sc descriptor-reg
:offset lexenv-offset
677 :from
(:argument
,(if (eq return
:tail
) 0 1))
680 (:temporary
(:scs
(descriptor-reg) :from
(:argument
0) :to
:eval
)
682 (:temporary
(:sc any-reg
:offset nargs-offset
:to
:eval
)
686 (mapcar #'(lambda (name offset
)
687 `(:temporary
(:sc descriptor-reg
691 register-arg-names
*register-arg-offsets
*))
692 ,@(when (eq return
:fixed
)
693 '((:temporary
(:scs
(descriptor-reg) :from
:eval
) move-temp
)))
695 (:temporary
(:scs
(descriptor-reg) :to
:eval
) stepping
)
697 ,@(unless (eq return
:tail
)
698 '((:temporary
(:scs
(non-descriptor-reg)) temp
)
699 (:temporary
(:sc control-stack
:offset nfp-save-offset
) nfp-save
)))
701 (:temporary
(:sc interior-reg
:offset lip-offset
) entry-point
)
703 (:generator
,(+ (if named
5 0)
705 (if (eq return
:tail
) 0 10)
707 (if (eq return
:unknown
) 25 0))
708 (trace-table-entry trace-table-call-site
)
710 (let* ((cur-nfp (current-nfp-tn vop
))
711 ,@(unless (eq return
:tail
)
712 '((lra-label (gen-label))))
713 (step-done-label (gen-label))
717 ,@(if (eq return
:tail
)
718 '((unless (location= old-fp old-fp-pass
)
720 (unless (location= return-pc
730 (flet ((do-next-filler ()
731 (let* ((next (pop filler
))
732 (what (if (consp next
) (car next
) next
)))
736 `((inst sub nargs-pass csp-tn new-fp
)
738 (mapcar #'(lambda (name)
741 register-arg-names
)))
742 '((inst lr nargs-pass
(fixnumize nargs
)))))
743 ,@(if (eq return
:tail
)
747 (inst mr old-fp-pass old-fp
))
749 (loadw old-fp-pass cfp-tn
750 (tn-offset old-fp
)))))
754 (inst mr return-pc-pass return-pc
))
756 (loadw return-pc-pass cfp-tn
757 (tn-offset return-pc
)))))
759 (inst addi nsp-tn cur-nfp
760 (- (bytes-needed-for-non-descriptor-stack-frame)
761 number-stack-displacement
))))
763 (inst compute-lra-from-code
764 return-pc-pass code-tn lra-label temp
))
766 (store-stack-tn nfp-save cur-nfp
))
768 (inst mr old-fp-pass cfp-tn
))
771 '(move cfp-tn new-fp
)
772 '(if (> nargs register-arg-count
)
774 (move cfp-tn csp-tn
))))))
776 (insert-step-instrumenting (callable-tn)
777 ;; Conditionally insert a conditional trap:
778 (when step-instrumenting
779 ;; Get the symbol-value of SB!IMPL::*STEPPING*
781 (load-symbol-value stepping sb
!impl
::*stepping
*)
783 (loadw stepping thread-base-tn thread-stepping-slot
)
784 (inst cmpw stepping null-tn
)
785 ;; If it's not null, trap.
786 (inst beq step-done-label
)
787 ;; CONTEXT-PC will be pointing here when the
788 ;; interrupt is handled, not after the UNIMP.
789 (note-this-location vop
:step-before-vop
)
790 ;; Construct a trap code with the low bits from
791 ;; SINGLE-STEP-AROUND-TRAP and the high bits from
792 ;; the register number of CALLABLE-TN.
793 (inst unimp
(logior single-step-around-trap
794 (ash (reg-tn-encoding callable-tn
)
796 (emit-label step-done-label
))))
799 (descriptor-reg (move name-pass name
))
801 (loadw name-pass cfp-tn
(tn-offset name
))
804 (loadw name-pass code-tn
(tn-offset name
)
805 other-pointer-lowtag
)
807 ;; The step instrumenting must be done after
808 ;; FUNCTION is loaded, but before ENTRY-POINT is
810 (insert-step-instrumenting name-pass
)
811 ;; The raw-addr (ENTRY-POINT) will be one of:
812 ;; closure_tramp, undefined_tramp, or somewhere
813 ;; within a simple-fun object. If the latter, then
814 ;; it is essential (due to it being an interior
815 ;; pointer) that the function itself be in a
816 ;; register before the raw-addr is loaded.
817 (sb!assem
:without-scheduling
()
818 (loadw function name-pass fdefn-fun-slot
819 other-pointer-lowtag
)
820 (loadw entry-point name-pass fdefn-raw-addr-slot
821 other-pointer-lowtag
))
824 (descriptor-reg (move lexenv arg-fun
))
826 (loadw lexenv cfp-tn
(tn-offset arg-fun
))
829 (loadw lexenv code-tn
(tn-offset arg-fun
)
830 other-pointer-lowtag
)
832 (loadw function lexenv closure-fun-slot
835 ;; The step instrumenting must be done before
836 ;; after FUNCTION is loaded, but before ENTRY-POINT
838 (insert-step-instrumenting function
)
839 (inst addi entry-point function
840 (- (ash simple-fun-code-offset word-shift
)
848 (note-this-location vop
:call-site
)
849 (inst mtctr entry-point
)
850 ;; this following line is questionable. or else the alpha
851 ;; code (which doesn't do it) is questionable
852 ;; (inst mr code-tn function)
857 '((emit-return-pc lra-label
)
858 (default-unknown-values vop values nvals move-temp
861 (load-stack-tn cur-nfp nfp-save
))))
863 '((emit-return-pc lra-label
)
864 (note-this-location vop
:unknown-return
)
865 (receive-unknown-values values-start nvals start count
868 (load-stack-tn cur-nfp nfp-save
))))
870 (trace-table-entry trace-table-normal
))))
873 (define-full-call call nil
:fixed nil
)
874 (define-full-call call-named t
:fixed nil
)
875 (define-full-call multiple-call nil
:unknown nil
)
876 (define-full-call multiple-call-named t
:unknown nil
)
877 (define-full-call tail-call nil
:tail nil
)
878 (define-full-call tail-call-named t
:tail nil
)
880 (define-full-call call-variable nil
:fixed t
)
881 (define-full-call multiple-call-variable nil
:unknown t
)
883 ;;; Defined separately, since needs special code that BLT's the
885 (define-vop (tail-call-variable)
887 (args-arg :scs
(any-reg) :target args
)
888 (function-arg :scs
(descriptor-reg) :target lexenv
)
889 (old-fp-arg :scs
(any-reg) :target old-fp
)
890 (lra-arg :scs
(descriptor-reg) :target lra
))
891 (:temporary
(:sc any-reg
:offset nl0-offset
:from
(:argument
0)) args
)
892 (:temporary
(:sc any-reg
:offset lexenv-offset
:from
(:argument
1)) lexenv
)
893 (:temporary
(:sc any-reg
:offset ocfp-offset
:from
(:argument
2)) old-fp
)
894 (:temporary
(:sc any-reg
:offset lra-offset
:from
(:argument
3)) lra
)
895 (:temporary
(:sc any-reg
) temp
)
898 ;; Move these into the passing locations if they are not already there.
900 (move lexenv function-arg
)
901 (move old-fp old-fp-arg
)
903 ;; Clear the number stack if anything is there.
904 (let ((cur-nfp (current-nfp-tn vop
)))
906 (inst addi nsp-tn cur-nfp
907 (- (bytes-needed-for-non-descriptor-stack-frame)
908 number-stack-displacement
))))
909 (inst lr temp
(make-fixup 'tail-call-variable
:assembly-routine
))
914 ;;;; Unknown values return:
916 ;;; Return a single value using the unknown-values convention.
917 (define-vop (return-single)
918 (:args
(old-fp :scs
(any-reg) :to
:eval
)
919 (return-pc :scs
(descriptor-reg) :target lra
)
922 (:temporary
(:sc descriptor-reg
:offset lra-offset
:from
(:argument
1)) lra
)
923 (:temporary
(:scs
(interior-reg)) lip
)
926 (trace-table-entry trace-table-fun-epilogue
)
928 ;; Clear the number stack.
929 (let ((cur-nfp (current-nfp-tn vop
)))
931 (inst addi nsp-tn cur-nfp
932 (- (bytes-needed-for-non-descriptor-stack-frame)
933 number-stack-displacement
))))
934 ;; Clear the control stack, and restore the frame pointer.
938 (lisp-return lra lip
:offset
2)
939 (trace-table-entry trace-table-normal
)))
941 ;;; Do unknown-values return of a fixed number of values. The Values are
942 ;;; required to be set up in the standard passing locations. Nvals is the
943 ;;; number of values returned.
945 ;;; If returning a single value, then deallocate the current frame, restore
946 ;;; FP and jump to the single-value entry at Return-PC + 8.
948 ;;; If returning other than one value, then load the number of values returned,
949 ;;; NIL out unsupplied values registers, restore FP and return at Return-PC.
950 ;;; When there are stack values, we must initialize the argument pointer to
951 ;;; point to the beginning of the values block (which is the beginning of the
955 (old-fp :scs
(any-reg))
956 (return-pc :scs
(descriptor-reg) :to
(:eval
1) :target lra
)
960 (:temporary
(:sc descriptor-reg
:offset a0-offset
:from
(:eval
0)) a0
)
961 (:temporary
(:sc descriptor-reg
:offset a1-offset
:from
(:eval
0)) a1
)
962 (:temporary
(:sc descriptor-reg
:offset a2-offset
:from
(:eval
0)) a2
)
963 (:temporary
(:sc descriptor-reg
:offset a3-offset
:from
(:eval
0)) a3
)
964 (:temporary
(:sc descriptor-reg
:offset lra-offset
:from
(:eval
1)) lra
)
965 (:temporary
(:sc any-reg
:offset nargs-offset
) nargs
)
966 (:temporary
(:sc any-reg
:offset ocfp-offset
) val-ptr
)
967 (:temporary
(:scs
(interior-reg)) lip
)
970 (trace-table-entry trace-table-fun-epilogue
)
972 ;; Clear the number stack.
973 (let ((cur-nfp (current-nfp-tn vop
)))
975 (inst addi nsp-tn cur-nfp
976 (- (bytes-needed-for-non-descriptor-stack-frame)
977 number-stack-displacement
))))
979 ;; Clear the control stack, and restore the frame pointer.
983 (lisp-return lra lip
:offset
2))
985 ;; Establish the values pointer and values count.
986 (move val-ptr cfp-tn
)
987 (inst lr nargs
(fixnumize nvals
))
988 ;; restore the frame pointer and clear as much of the control
989 ;; stack as possible.
991 (inst addi csp-tn val-ptr
(* nvals n-word-bytes
))
992 ;; pre-default any argument register that need it.
993 (when (< nvals register-arg-count
)
994 (dolist (reg (subseq (list a0 a1 a2 a3
) nvals
))
997 (lisp-return lra lip
)))
998 (trace-table-entry trace-table-normal
)))
1000 ;;; Do unknown-values return of an arbitrary number of values (passed
1001 ;;; on the stack.) We check for the common case of a single return
1002 ;;; value, and do that inline using the normal single value return
1003 ;;; convention. Otherwise, we branch off to code that calls an
1004 ;;; assembly-routine.
1005 (define-vop (return-multiple)
1007 (old-fp-arg :scs
(any-reg) :to
(:eval
1))
1008 (lra-arg :scs
(descriptor-reg) :to
(:eval
1))
1009 (vals-arg :scs
(any-reg) :target vals
)
1010 (nvals-arg :scs
(any-reg) :target nvals
))
1011 (:temporary
(:sc any-reg
:offset nl1-offset
:from
(:argument
0)) old-fp
)
1012 (:temporary
(:sc descriptor-reg
:offset lra-offset
:from
(:argument
1)) lra
)
1013 (:temporary
(:sc any-reg
:offset nl0-offset
:from
(:argument
2)) vals
)
1014 (:temporary
(:sc any-reg
:offset nargs-offset
:from
(:argument
3)) nvals
)
1015 (:temporary
(:sc descriptor-reg
:offset a0-offset
) a0
)
1016 (:temporary
(:scs
(interior-reg)) lip
)
1017 (:temporary
(:sc any-reg
) temp
)
1020 (trace-table-entry trace-table-fun-epilogue
)
1022 (let ((not-single (gen-label)))
1023 ;; Clear the number stack.
1024 (let ((cur-nfp (current-nfp-tn vop
)))
1026 (inst addi nsp-tn cur-nfp
1027 (- (bytes-needed-for-non-descriptor-stack-frame)
1028 number-stack-displacement
))))
1029 ;; Check for the single case.
1030 (inst cmpwi nvals-arg
(fixnumize 1))
1031 (inst lwz a0 vals-arg
0)
1032 (inst bne not-single
)
1033 ;; Return with one value.
1034 (move csp-tn cfp-tn
)
1035 (move cfp-tn old-fp-arg
)
1036 (lisp-return lra-arg lip
:offset
2)
1037 ;; Nope, not the single case.
1038 (emit-label not-single
)
1039 (move old-fp old-fp-arg
)
1040 (move vals vals-arg
)
1041 (move nvals nvals-arg
)
1042 (inst lr temp
(make-fixup 'return-multiple
:assembly-routine
))
1045 (trace-table-entry trace-table-normal
)))
1049 ;;; We don't need to do anything special for regular functions.
1050 (define-vop (setup-environment)
1054 ;; Don't bother doing anything.
1057 ;;; Get the lexical environment from its passing location.
1058 (define-vop (setup-closure-environment)
1059 (:temporary
(:sc descriptor-reg
:offset lexenv-offset
:target closure
1062 (:results
(closure :scs
(descriptor-reg)))
1067 (move closure lexenv
)))
1069 ;;; Copy a more arg from the argument area to the end of the current frame.
1070 ;;; Fixed is the number of non-more arguments.
1071 (define-vop (copy-more-arg)
1072 (:temporary
(:sc any-reg
:offset nl0-offset
) result
)
1073 (:temporary
(:sc any-reg
:offset nl1-offset
) count
)
1074 (:temporary
(:sc any-reg
:offset nl2-offset
) src
)
1075 (:temporary
(:sc any-reg
:offset nl3-offset
) dst
)
1076 (:temporary
(:sc descriptor-reg
:offset l0-offset
) temp
)
1079 (let ((loop (gen-label))
1080 (do-regs (gen-label))
1082 (when (< fixed register-arg-count
)
1083 ;; Save a pointer to the results so we can fill in register args.
1084 ;; We don't need this if there are more fixed args than reg args.
1085 (move result csp-tn
))
1086 ;; Allocate the space on the stack.
1087 (cond ((zerop fixed
)
1088 (inst cmpwi nargs-tn
0)
1089 (inst add csp-tn csp-tn nargs-tn
)
1092 (inst addic. count nargs-tn
(- (fixnumize fixed
)))
1094 (inst add csp-tn csp-tn count
)))
1095 (when (< fixed register-arg-count
)
1096 ;; We must stop when we run out of stack args, not when we run out of
1098 (inst addic. count nargs-tn
(- (fixnumize register-arg-count
)))
1099 ;; Everything of interest is in registers.
1101 ;; Initialize dst to be end of stack.
1103 ;; Initialize src to be end of args.
1104 (inst add src cfp-tn nargs-tn
)
1107 ;; *--dst = *--src, --count
1108 (inst lwzu temp src
(- n-word-bytes
))
1109 (inst addic. count count
(- (fixnumize 1)))
1110 (inst stwu temp dst
(- n-word-bytes
))
1113 (emit-label do-regs
)
1114 (when (< fixed register-arg-count
)
1115 ;; Now we have to deposit any more args that showed up in registers.
1116 (inst subic. count nargs-tn
(fixnumize fixed
))
1117 (do ((i fixed
(1+ i
)))
1118 ((>= i register-arg-count
))
1119 ;; Don't deposit any more than there are.
1121 (inst subic. count count
(fixnumize 1))
1122 ;; Store it relative to the pointer saved at the start.
1123 (storew (nth i
*register-arg-tns
*) result
(- i fixed
))))
1124 (emit-label done
))))
1127 ;;; More args are stored consecutively on the stack, starting
1128 ;;; immediately at the context pointer. The context pointer is not
1129 ;;; typed, so the lowtag is 0.
1130 (define-vop (more-arg word-index-ref
)
1132 (:translate %more-arg
))
1134 ;;; Turn more arg (context, count) into a list.
1135 (define-vop (listify-rest-args)
1136 (:args
(context-arg :target context
:scs
(descriptor-reg))
1137 (count-arg :target count
:scs
(any-reg)))
1138 (:arg-types
* tagged-num
)
1139 (:temporary
(:scs
(any-reg) :from
(:argument
0)) context
)
1140 (:temporary
(:scs
(any-reg) :from
(:argument
1)) count
)
1141 (:temporary
(:scs
(descriptor-reg) :from
:eval
) temp
)
1142 (:temporary
(:scs
(non-descriptor-reg) :from
:eval
) dst
)
1143 (:temporary
(:sc non-descriptor-reg
:offset nl3-offset
) pa-flag
)
1144 (:results
(result :scs
(descriptor-reg)))
1145 (:translate %listify-rest-args
)
1149 (let* ((enter (gen-label))
1152 (dx-p (node-stack-allocate-p node
)))
1153 (move context context-arg
)
1154 (move count count-arg
)
1155 ;; Check to see if there are any arguments.
1156 (inst cmpwi count
0)
1157 (move result null-tn
)
1160 ;; We need to do this atomically.
1161 (pseudo-atomic (pa-flag)
1162 ;; Allocate a cons (2 words) for each item.
1166 (inst clrrwi result csp-tn n-lowtag-bits
)
1167 (inst ori result result list-pointer-lowtag
)
1169 (inst slwi temp count
1)
1170 (inst add csp-tn csp-tn temp
))
1172 (inst slwi temp count
1)
1173 (allocation result temp list-pointer-lowtag
1179 ;; Compute the next cons and store it in the current one.
1181 (inst addi dst dst
(* 2 n-word-bytes
))
1182 (storew dst dst -
1 list-pointer-lowtag
)
1186 (loadw temp context
)
1187 (inst addi context context n-word-bytes
)
1189 ;; Dec count, and if != zero, go back for more.
1190 (inst addic. count count
(- (fixnumize 1)))
1191 ;; Store the value into the car of the current cons (in the delay
1193 (storew temp dst
0 list-pointer-lowtag
)
1196 ;; NIL out the last cons.
1197 (storew null-tn dst
1 list-pointer-lowtag
))
1198 (emit-label done
))))
1201 ;;; Return the location and size of the more arg glob created by
1202 ;;; COPY-MORE-ARG. SUPPLIED is the total number of arguments supplied
1203 ;;; (originally passed in NARGS.) Fixed is the number of non-rest
1206 ;;; We must duplicate some of the work done by COPY-MORE-ARG, since at
1207 ;;; that time the environment is in a pretty brain-damaged state,
1208 ;;; preventing this info from being returned as values. What we do is
1209 ;;; compute (- SUPPLIED FIXED), and return a pointer that many words
1210 ;;; below the current stack top.
1211 (define-vop (more-arg-context)
1212 (:policy
:fast-safe
)
1213 (:translate sb
!c
::%more-arg-context
)
1214 (:args
(supplied :scs
(any-reg)))
1215 (:arg-types tagged-num
(:constant fixnum
))
1217 (:results
(context :scs
(descriptor-reg))
1218 (count :scs
(any-reg)))
1219 (:result-types t tagged-num
)
1220 (:note
"more-arg-context")
1222 (inst subi count supplied
(fixnumize fixed
))
1223 (inst sub context csp-tn count
)))
1225 (define-vop (verify-arg-count)
1226 (:policy
:fast-safe
)
1227 (:translate sb
!c
::%verify-arg-count
)
1228 (:args
(nargs :scs
(any-reg)))
1229 (:arg-types positive-fixnum
(:constant t
))
1232 (:save-p
:compute-only
)
1234 (inst twi
:ne nargs
(fixnumize count
))))
1236 ;;; Signal various errors.
1237 (macrolet ((frob (name error translate
&rest args
)
1238 `(define-vop (,name
)
1240 `((:policy
:fast-safe
)
1241 (:translate
,translate
)))
1242 (:args
,@(mapcar #'(lambda (arg)
1243 `(,arg
:scs
(any-reg descriptor-reg
)))
1246 (:save-p
:compute-only
)
1248 (error-call vop
',error
,@args
)))))
1249 (frob arg-count-error invalid-arg-count-error
1250 sb
!c
::%arg-count-error nargs
)
1251 (frob type-check-error object-not-type-error sb
!c
::%type-check-error
1253 (frob layout-invalid-error layout-invalid-error sb
!c
::%layout-invalid-error
1255 (frob odd-key-args-error odd-key-args-error
1256 sb
!c
::%odd-key-args-error
)
1257 (frob unknown-key-arg-error unknown-key-arg-error
1258 sb
!c
::%unknown-key-arg-error key
)
1259 (frob nil-fun-returned-error nil-fun-returned-error nil fun
))
1261 (define-vop (step-instrument-before-vop)
1262 (:temporary
(:scs
(descriptor-reg)) stepping
)
1263 (:policy
:fast-safe
)
1266 ;; Get the symbol-value of SB!IMPL::*STEPPING*
1268 (load-symbol-value stepping sb
!impl
::*stepping
*)
1270 (loadw stepping thread-base-tn thread-stepping-slot
)
1271 (inst cmpw stepping null-tn
)
1272 ;; If it's not null, trap.
1274 ;; CONTEXT-PC will be pointing here when the interrupt is handled,
1275 ;; not after the UNIMP.
1276 (note-this-location vop
:step-before-vop
)
1277 ;; CALLEE-REGISTER-OFFSET isn't needed for before-traps, so we
1278 ;; can just use a bare SINGLE-STEP-BEFORE-TRAP as the code.
1279 (inst unimp single-step-before-trap
)