1.0.19.7: refactor stack allocation decisions
[sbcl.git] / src / compiler / sparc / call.lisp
1 ;;;; the VM definition of function call for the Sparc
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
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.
11
12 (in-package "SB!VM")
13
14 \f
15 ;;;; Interfaces to IR2 conversion:
16
17 ;;; Return a wired TN describing the N'th full call argument passing
18 ;;; location.
19 (!def-vm-support-routine standard-arg-location (n)
20   (declare (type unsigned-byte n))
21   (if (< n register-arg-count)
22       (make-wired-tn *backend-t-primitive-type* register-arg-scn
23                      (elt *register-arg-offsets* n))
24       (make-wired-tn *backend-t-primitive-type* control-stack-arg-scn n)))
25
26
27 ;;; Make a passing location TN for a local call return PC.  If
28 ;;; standard is true, then use the standard (full call) location,
29 ;;; otherwise use any legal location.  Even in the non-standard case,
30 ;;; this may be restricted by a desire to use a subroutine call
31 ;;; instruction.
32 (!def-vm-support-routine make-return-pc-passing-location (standard)
33   (if 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)))
36
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
41 ;;; the arg pointer.
42 (!def-vm-support-routine make-old-fp-passing-location (standard)
43   (if standard
44       (make-wired-tn *fixnum-primitive-type* immediate-arg-scn ocfp-offset)
45       (make-normal-tn *fixnum-primitive-type*)))
46
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)
51   (specify-save-tn
52    (physenv-debug-live-tn (make-normal-tn *fixnum-primitive-type*) env)
53    (make-wired-tn *fixnum-primitive-type*
54                   control-stack-arg-scn
55                   ocfp-save-offset)))
56
57 (!def-vm-support-routine make-return-pc-save-location (env)
58   (specify-save-tn
59    (physenv-debug-live-tn (make-normal-tn *backend-t-primitive-type*) env)
60    (make-wired-tn *backend-t-primitive-type*
61                   control-stack-arg-scn
62                   lra-save-offset)))
63
64 ;;; Make a TN for the standard argument count passing location.  We
65 ;;; only need to make the standard location, since a count is never
66 ;;; passed when we are using non-standard conventions.
67 (!def-vm-support-routine make-arg-count-location ()
68   (make-wired-tn *fixnum-primitive-type* immediate-arg-scn nargs-offset))
69
70
71 ;;; Make a TN to hold the number-stack frame pointer.  This is
72 ;;; allocated once per component, and is component-live.
73 (!def-vm-support-routine make-nfp-tn ()
74   (component-live-tn
75    (make-wired-tn *fixnum-primitive-type* immediate-arg-scn nfp-offset)))
76
77 (!def-vm-support-routine make-stack-pointer-tn ()
78   (make-normal-tn *fixnum-primitive-type*))
79
80 (!def-vm-support-routine make-number-stack-pointer-tn ()
81   (make-normal-tn *fixnum-primitive-type*))
82
83 ;;; Return a list of TNs that can be used to represent an
84 ;;; unknown-values continuation within a function.
85 (!def-vm-support-routine make-unknown-values-locations ()
86   (list (make-stack-pointer-tn)
87         (make-normal-tn *fixnum-primitive-type*)))
88
89
90 ;;; This function is called by the ENTRY-ANALYZE phase, allowing
91 ;;; VM-dependent initialization of the IR2-COMPONENT structure.  We push
92 ;;; placeholder entries in the CONSTANTS to leave room for additional
93 ;;; noise in the code object header.
94 (!def-vm-support-routine select-component-format (component)
95   (declare (type component component))
96   (dotimes (i code-constants-offset)
97     (vector-push-extend nil
98                         (ir2-component-constants (component-info component))))
99   (values))
100 \f
101 ;;;; Frame hackery:
102
103 ;;; Return the number of bytes needed for the current non-descriptor
104 ;;; stack frame.  Non-descriptor stack frames must be multiples of 8
105 ;;; bytes on the PMAX.
106 (defun bytes-needed-for-non-descriptor-stack-frame ()
107   (* (logandc2 (1+ (sb-allocated-size 'non-descriptor-stack)) 1)
108      n-word-bytes))
109
110 ;;; Used for setting up the Old-FP in local call.
111 (define-vop (current-fp)
112   (:results (val :scs (any-reg)))
113   (:generator 1
114     (move val cfp-tn)))
115
116 ;;; Used for computing the caller's NFP for use in known-values return.  Only
117 ;;; works assuming there is no variable size stuff on the nstack.
118 ;;;
119 (define-vop (compute-old-nfp)
120   (:results (val :scs (any-reg)))
121   (:vop-var vop)
122   (:generator 1
123     (let ((nfp (current-nfp-tn vop)))
124       (when nfp
125         (inst add val nfp (bytes-needed-for-non-descriptor-stack-frame))))))
126
127
128 (define-vop (xep-allocate-frame)
129   (:info start-lab copy-more-arg-follows)
130   (:ignore copy-more-arg-follows)
131   (:vop-var vop)
132   (:temporary (:scs (non-descriptor-reg)) temp)
133   (:generator 1
134     ;; Make sure the function is aligned, and drop a label pointing to this
135     ;; function header.
136     (align n-lowtag-bits)
137     (trace-table-entry trace-table-fun-prologue)
138     (emit-label start-lab)
139     ;; Allocate function header.
140     (inst simple-fun-header-word)
141     (dotimes (i (1- simple-fun-code-offset))
142       (inst word 0))
143     ;; The start of the actual code.
144     ;; Fix CODE, cause the function object was passed in.
145     (inst compute-code-from-fn code-tn code-tn start-lab temp)
146     ;; Build our stack frames.
147     (inst add csp-tn cfp-tn
148           (* n-word-bytes (sb-allocated-size 'control-stack)))
149     (let ((nfp-tn (current-nfp-tn vop)))
150       (when nfp-tn
151         (inst sub nsp-tn (bytes-needed-for-non-descriptor-stack-frame))
152         (inst add nfp-tn nsp-tn number-stack-displacement)))
153     (trace-table-entry trace-table-normal)))
154
155 (define-vop (allocate-frame)
156   (:results (res :scs (any-reg))
157             (nfp :scs (any-reg)))
158   (:info callee)
159   (:generator 2
160     (trace-table-entry trace-table-fun-prologue)
161     (move res csp-tn)
162     (inst add csp-tn csp-tn
163           (* n-word-bytes (sb-allocated-size 'control-stack)))
164     (when (ir2-physenv-number-stack-p callee)
165       (inst sub nsp-tn (bytes-needed-for-non-descriptor-stack-frame))
166       (inst add nfp nsp-tn number-stack-displacement))
167     (trace-table-entry trace-table-normal)))
168
169 ;;; Allocate a partial frame for passing stack arguments in a full call.  Nargs
170 ;;; is the number of arguments passed.  If no stack arguments are passed, then
171 ;;; we don't have to do anything.
172 ;;;
173 (define-vop (allocate-full-call-frame)
174   (:info nargs)
175   (:results (res :scs (any-reg)))
176   (:generator 2
177     (when (> nargs register-arg-count)
178       (move res csp-tn)
179       (inst add csp-tn csp-tn (* nargs n-word-bytes)))))
180
181
182
183 \f
184 ;;; Emit code needed at the return-point from an unknown-values call
185 ;;; for a fixed number of values.  Values is the head of the TN-REF
186 ;;; list for the locations that the values are to be received into.
187 ;;; Nvals is the number of values that are to be received (should
188 ;;; equal the length of Values).
189 ;;;
190 ;;; Move-Temp is a Descriptor-Reg TN used as a temporary.
191 ;;;
192 ;;; This code exploits the fact that in the unknown-values convention,
193 ;;; a single value return returns at the return PC + 8, whereas a
194 ;;; return of other than one value returns directly at the return PC.
195 ;;;
196 ;;; If 0 or 1 values are expected, then we just emit an instruction to
197 ;;; reset the SP (which will only be executed when other than 1 value
198 ;;; is returned.)
199 ;;;
200 ;;; In the general case, we have to do three things:
201 ;;;  -- Default unsupplied register values.  This need only be done when a
202 ;;;     single value is returned, since register values are defaulted by the
203 ;;;     called in the non-single case.
204 ;;;  -- Default unsupplied stack values.  This needs to be done whenever there
205 ;;;     are stack values.
206 ;;;  -- Reset SP.  This must be done whenever other than 1 value is returned,
207 ;;;     regardless of the number of values desired.
208 ;;;
209 ;;; The general-case code looks like this:
210 #|
211         b regs-defaulted                ; Skip if MVs
212         nop
213
214         move a1 null-tn                 ; Default register values
215         ...
216         loadi nargs 1                   ; Force defaulting of stack values
217         move old-fp csp                 ; Set up args for SP resetting
218
219 regs-defaulted
220         subcc temp nargs register-arg-count
221
222         b :lt default-value-7   ; jump to default code
223         loadw move-temp ocfp-tn 6       ; Move value to correct location.
224         subcc temp 1
225         store-stack-tn val4-tn move-temp
226
227         b :lt default-value-8
228         loadw move-temp ocfp-tn 7
229         subcc temp 1
230         store-stack-tn val5-tn move-temp
231
232         ...
233
234 defaulting-done
235         move csp ocfp                   ; Reset SP.
236 <end of code>
237
238 <elsewhere>
239 default-value-7
240         store-stack-tn val4-tn null-tn  ; Nil out 7'th value. (first on stack)
241
242 default-value-8
243         store-stack-tn val5-tn null-tn  ; Nil out 8'th value.
244
245         ...
246
247         br defaulting-done
248         nop
249 |#
250 (defun default-unknown-values (vop values nvals move-temp temp lra-label)
251   (declare (type (or tn-ref null) values)
252            (type unsigned-byte nvals) (type tn move-temp temp))
253   (if (<= nvals 1)
254       (progn
255         (without-scheduling ()
256           (note-this-location vop :single-value-return)
257           (move csp-tn ocfp-tn)
258           (inst nop))
259         (inst compute-code-from-lra code-tn code-tn lra-label temp))
260       (let ((regs-defaulted (gen-label))
261             (defaulting-done (gen-label))
262             (default-stack-vals (gen-label)))
263         ;; Branch off to the MV case.
264         (without-scheduling ()
265           (note-this-location vop :unknown-return)
266           (inst b regs-defaulted)
267           (if (> nvals register-arg-count)
268               (inst subcc temp nargs-tn (fixnumize register-arg-count))
269               (move csp-tn ocfp-tn)))
270
271         ;; Do the single value calse.
272         (do ((i 1 (1+ i))
273              (val (tn-ref-across values) (tn-ref-across val)))
274             ((= i (min nvals register-arg-count)))
275           (move (tn-ref-tn val) null-tn))
276         (when (> nvals register-arg-count)
277           (inst b default-stack-vals)
278           (move ocfp-tn csp-tn))
279
280         (emit-label regs-defaulted)
281         (when (> nvals register-arg-count)
282           (collect ((defaults))
283             (do ((i register-arg-count (1+ i))
284                  (val (do ((i 0 (1+ i))
285                            (val values (tn-ref-across val)))
286                           ((= i register-arg-count) val))
287                       (tn-ref-across val)))
288                 ((null val))
289
290               (let ((default-lab (gen-label))
291                     (tn (tn-ref-tn val)))
292                 (defaults (cons default-lab tn))
293
294                 (inst b :le default-lab)
295                 (inst ld move-temp ocfp-tn (* i n-word-bytes))
296                 (inst subcc temp (fixnumize 1))
297                 (store-stack-tn tn move-temp)))
298
299             (emit-label defaulting-done)
300             (move csp-tn ocfp-tn)
301
302             (let ((defaults (defaults)))
303               (when defaults
304                 (assemble (*elsewhere*)
305                   (emit-label default-stack-vals)
306                   (trace-table-entry trace-table-fun-prologue)
307                   (do ((remaining defaults (cdr remaining)))
308                       ((null remaining))
309                     (let ((def (car remaining)))
310                       (emit-label (car def))
311                       (when (null (cdr remaining))
312                         (inst b defaulting-done))
313                       (store-stack-tn (cdr def) null-tn)))
314                   (trace-table-entry trace-table-normal))))))
315
316         (inst compute-code-from-lra code-tn code-tn lra-label temp)))
317   (values))
318
319 \f
320 ;;; Emit code needed at the return point for an unknown-values call
321 ;;; for an arbitrary number of values.
322 ;;;
323 ;;; We do the single and non-single cases with no shared code: there
324 ;;; doesn't seem to be any potential overlap, and receiving a single
325 ;;; value is more important efficiency-wise.
326 ;;;
327 ;;; When there is a single value, we just push it on the stack,
328 ;;; returning the old SP and 1.
329 ;;;
330 ;;; When there is a variable number of values, we move all of the
331 ;;; argument registers onto the stack, and return ARGS and NARGS.
332 ;;;
333 ;;; ARGS and NARGS are TNs wired to the named locations.  We must
334 ;;; explicitly allocate these TNs, since their lifetimes overlap with
335 ;;; the results START and COUNT. (Also, it's nice to be able to target
336 ;;; them.)
337 (defun receive-unknown-values (args nargs start count lra-label temp)
338   (declare (type tn args nargs start count temp))
339   (let ((variable-values (gen-label))
340         (done (gen-label)))
341     (without-scheduling ()
342       (inst b variable-values)
343       (inst nop))
344
345     (inst compute-code-from-lra code-tn code-tn lra-label temp)
346     (inst add csp-tn 4)
347     (storew (first *register-arg-tns*) csp-tn -1)
348     (inst sub start csp-tn 4)
349     (inst li count (fixnumize 1))
350
351     (emit-label done)
352
353     (assemble (*elsewhere*)
354       (trace-table-entry trace-table-fun-prologue)
355       (emit-label variable-values)
356       (inst compute-code-from-lra code-tn code-tn lra-label temp)
357       (do ((arg *register-arg-tns* (rest arg))
358            (i 0 (1+ i)))
359           ((null arg))
360         (storew (first arg) args i))
361       (move start args)
362       (move count nargs)
363       (inst b done)
364       (inst nop)
365       (trace-table-entry trace-table-normal)))
366   (values))
367
368
369 ;;; VOP that can be inherited by unknown values receivers.  The main
370 ;;; thing this handles is allocation of the result temporaries.
371 (define-vop (unknown-values-receiver)
372   (:results
373    (start :scs (any-reg))
374    (count :scs (any-reg)))
375   (:temporary (:sc descriptor-reg :offset ocfp-offset
376                    :from :eval :to (:result 0))
377               values-start)
378   (:temporary (:sc any-reg :offset nargs-offset
379                :from :eval :to (:result 1))
380               nvals)
381   (:temporary (:scs (non-descriptor-reg)) temp))
382
383
384 \f
385 ;;;; Local call with unknown values convention return:
386
387 ;;; Non-TR local call for a fixed number of values passed according to the
388 ;;; unknown values convention.
389 ;;;
390 ;;; Args are the argument passing locations, which are specified only to
391 ;;; terminate their lifetimes in the caller.
392 ;;;
393 ;;; Values are the return value locations (wired to the standard passing
394 ;;; locations).
395 ;;;
396 ;;; Save is the save info, which we can ignore since saving has been done.
397 ;;; Return-PC is the TN that the return PC should be passed in.
398 ;;; Target is a continuation pointing to the start of the called function.
399 ;;; Nvals is the number of values received.
400 ;;;
401 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
402 ;;; registers may be tied up by the more operand.  Instead, we use
403 ;;; MAYBE-LOAD-STACK-TN.
404 (define-vop (call-local)
405   (:args (fp)
406          (nfp)
407          (args :more t))
408   (:results (values :more t))
409   (:save-p t)
410   (:move-args :local-call)
411   (:info arg-locs callee target nvals)
412   (:vop-var vop)
413   (:temporary (:scs (descriptor-reg) :from (:eval 0)) move-temp)
414   (:temporary (:scs (non-descriptor-reg)) temp)
415   (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
416   (:temporary (:sc any-reg :offset ocfp-offset :from (:eval 0)) ocfp)
417   (:ignore arg-locs args ocfp)
418   (:generator 5
419     (trace-table-entry trace-table-call-site)
420     (let ((label (gen-label))
421           (cur-nfp (current-nfp-tn vop)))
422       (when cur-nfp
423         (store-stack-tn nfp-save cur-nfp))
424       (let ((callee-nfp (callee-nfp-tn callee)))
425         (when callee-nfp
426           (maybe-load-stack-tn callee-nfp nfp)))
427       (maybe-load-stack-tn cfp-tn fp)
428       (inst compute-lra-from-code
429             (callee-return-pc-tn callee) code-tn label temp)
430       (note-this-location vop :call-site)
431       (inst b target)
432       (inst nop)
433       (emit-return-pc label)
434       (default-unknown-values vop values nvals move-temp temp label)
435       (when cur-nfp
436         (load-stack-tn cur-nfp nfp-save)))
437     (trace-table-entry trace-table-normal)))
438
439
440 ;;; Non-TR local call for a variable number of return values passed according
441 ;;; to the unknown values convention.  The results are the start of the values
442 ;;; glob and the number of values received.
443 ;;;
444 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
445 ;;; registers may be tied up by the more operand.  Instead, we use
446 ;;; MAYBE-LOAD-STACK-TN.
447 (define-vop (multiple-call-local unknown-values-receiver)
448   (:args (fp)
449          (nfp)
450          (args :more t))
451   (:save-p t)
452   (:move-args :local-call)
453   (:info save callee target)
454   (:ignore args save)
455   (:vop-var vop)
456   (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
457   (:generator 20
458     (trace-table-entry trace-table-call-site)
459     (let ((label (gen-label))
460           (cur-nfp (current-nfp-tn vop)))
461       (when cur-nfp
462         (store-stack-tn nfp-save cur-nfp))
463       (let ((callee-nfp (callee-nfp-tn callee)))
464         (when callee-nfp
465           (maybe-load-stack-tn callee-nfp nfp)))
466       (maybe-load-stack-tn cfp-tn fp)
467       (inst compute-lra-from-code
468             (callee-return-pc-tn callee) code-tn label temp)
469       (note-this-location vop :call-site)
470       (inst b target)
471       (inst nop)
472       (emit-return-pc label)
473       (note-this-location vop :unknown-return)
474       (receive-unknown-values values-start nvals start count label temp)
475       (when cur-nfp
476         (load-stack-tn cur-nfp nfp-save)))
477     (trace-table-entry trace-table-normal)))
478
479 \f
480 ;;;; Local call with known values return:
481
482 ;;; Non-TR local call with known return locations.  Known-value return works
483 ;;; just like argument passing in local call.
484 ;;;
485 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
486 ;;; registers may be tied up by the more operand.  Instead, we use
487 ;;; MAYBE-LOAD-STACK-TN.
488 (define-vop (known-call-local)
489   (:args (fp)
490          (nfp)
491          (args :more t))
492   (:results (res :more t))
493   (:move-args :local-call)
494   (:save-p t)
495   (:info save callee target)
496   (:ignore args res save)
497   (:vop-var vop)
498   (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)
499   (:temporary (:scs (non-descriptor-reg)) temp)
500   (:generator 5
501     (trace-table-entry trace-table-call-site)
502     (let ((label (gen-label))
503           (cur-nfp (current-nfp-tn vop)))
504       (when cur-nfp
505         (store-stack-tn nfp-save cur-nfp))
506       (let ((callee-nfp (callee-nfp-tn callee)))
507         (when callee-nfp
508           (maybe-load-stack-tn callee-nfp nfp)))
509       (maybe-load-stack-tn cfp-tn fp)
510       (inst compute-lra-from-code
511             (callee-return-pc-tn callee) code-tn label temp)
512       (note-this-location vop :call-site)
513       (inst b target)
514       (inst nop)
515       (emit-return-pc label)
516       (note-this-location vop :known-return)
517       (when cur-nfp
518         (load-stack-tn cur-nfp nfp-save)))
519     (trace-table-entry trace-table-normal)))
520
521 ;;; Return from known values call.  We receive the return locations as
522 ;;; arguments to terminate their lifetimes in the returning function.  We
523 ;;; restore FP and CSP and jump to the Return-PC.
524 ;;;
525 ;;; Note: we can't use normal load-tn allocation for the fixed args, since all
526 ;;; registers may be tied up by the more operand.  Instead, we use
527 ;;; MAYBE-LOAD-STACK-TN.
528 (define-vop (known-return)
529   (:args (old-fp :target old-fp-temp)
530          (return-pc :target return-pc-temp)
531          (vals :more t))
532   (:temporary (:sc any-reg :from (:argument 0)) old-fp-temp)
533   (:temporary (:sc descriptor-reg :from (:argument 1)) return-pc-temp)
534   (:move-args :known-return)
535   (:info val-locs)
536   (:ignore val-locs vals)
537   (:vop-var vop)
538   (:generator 6
539     (trace-table-entry trace-table-fun-epilogue)
540     (maybe-load-stack-tn old-fp-temp old-fp)
541     (maybe-load-stack-tn return-pc-temp return-pc)
542     (move csp-tn cfp-tn)
543     (let ((cur-nfp (current-nfp-tn vop)))
544       (when cur-nfp
545         (inst add nsp-tn cur-nfp
546               (- (bytes-needed-for-non-descriptor-stack-frame)
547                  number-stack-displacement))))
548     (inst j return-pc-temp (- n-word-bytes other-pointer-lowtag))
549     (move cfp-tn old-fp-temp)
550     (trace-table-entry trace-table-normal)))
551
552 \f
553 ;;;; Full call:
554 ;;;
555 ;;; There is something of a cross-product effect with full calls.
556 ;;; Different versions are used depending on whether we know the
557 ;;; number of arguments or the name of the called function, and
558 ;;; whether we want fixed values, unknown values, or a tail call.
559 ;;;
560 ;;; In full call, the arguments are passed creating a partial frame on
561 ;;; the stack top and storing stack arguments into that frame.  On
562 ;;; entry to the callee, this partial frame is pointed to by FP.  If
563 ;;; there are no stack arguments, we don't bother allocating a partial
564 ;;; frame, and instead set FP to SP just before the call.
565
566 ;;; This macro helps in the definition of full call VOPs by avoiding code
567 ;;; replication in defining the cross-product VOPs.
568 ;;;
569 ;;; Name is the name of the VOP to define.
570 ;;;
571 ;;; Named is true if the first argument is a symbol whose global function
572 ;;; definition is to be called.
573 ;;;
574 ;;; Return is either :Fixed, :Unknown or :Tail:
575 ;;; -- If :Fixed, then the call is for a fixed number of values, returned in
576 ;;;    the standard passing locations (passed as result operands).
577 ;;; -- If :Unknown, then the result values are pushed on the stack, and the
578 ;;;    result values are specified by the Start and Count as in the
579 ;;;    unknown-values continuation representation.
580 ;;; -- If :Tail, then do a tail-recursive call.  No values are returned.
581 ;;;    The Old-Fp and Return-PC are passed as the second and third arguments.
582 ;;;
583 ;;; In non-tail calls, the pointer to the stack arguments is passed as the last
584 ;;; fixed argument.  If Variable is false, then the passing locations are
585 ;;; passed as a more arg.  Variable is true if there are a variable number of
586 ;;; arguments passed on the stack.  Variable cannot be specified with :Tail
587 ;;; return.  TR variable argument call is implemented separately.
588 ;;;
589 ;;; In tail call with fixed arguments, the passing locations are passed as a
590 ;;; more arg, but there is no new-FP, since the arguments have been set up in
591 ;;; the current frame.
592 (defmacro define-full-call (name named return variable)
593   (aver (not (and variable (eq return :tail))))
594   `(define-vop (,name
595                 ,@(when (eq return :unknown)
596                     '(unknown-values-receiver)))
597      (:args
598       ,@(unless (eq return :tail)
599           '((new-fp :scs (any-reg) :to :eval)))
600
601       ,(if named
602            '(name :target name-pass)
603            '(arg-fun :target lexenv))
604
605       ,@(when (eq return :tail)
606           '((old-fp :target old-fp-pass)
607             (return-pc :target return-pc-pass)))
608
609       ,@(unless variable '((args :more t :scs (descriptor-reg)))))
610
611      ,@(when (eq return :fixed)
612          '((:results (values :more t))))
613
614      (:save-p ,(if (eq return :tail) :compute-only t))
615
616      ,@(unless (or (eq return :tail) variable)
617          '((:move-args :full-call)))
618
619      (:vop-var vop)
620      (:info ,@(unless (or variable (eq return :tail)) '(arg-locs))
621             ,@(unless variable '(nargs))
622             ,@(when (eq return :fixed) '(nvals))
623             step-instrumenting)
624
625      (:ignore
626       ,@(unless (or variable (eq return :tail)) '(arg-locs))
627       ,@(unless variable '(args)))
628
629      (:temporary (:sc descriptor-reg
630                   :offset ocfp-offset
631                   :from (:argument 1)
632                   ,@(unless (eq return :fixed)
633                       '(:to :eval)))
634                  old-fp-pass)
635
636      (:temporary (:sc descriptor-reg
637                   :offset lra-offset
638                   :from (:argument ,(if (eq return :tail) 2 1))
639                   :to :eval)
640                  return-pc-pass)
641
642      ,(if named
643           `(:temporary (:sc descriptor-reg :offset cname-offset
644                             :from (:argument ,(if (eq return :tail) 0 1))
645                             :to :eval)
646                        name-pass)
647           `(:temporary (:sc descriptor-reg :offset lexenv-offset
648                             :from (:argument ,(if (eq return :tail) 0 1))
649                             :to :eval)
650                        lexenv))
651
652      (:temporary (:scs (descriptor-reg) :from (:argument 0) :to :eval)
653                  function)
654      (:temporary (:sc any-reg :offset nargs-offset :to :eval)
655                  nargs-pass)
656
657      ,@(when variable
658          (mapcar #'(lambda (name offset)
659                      `(:temporary (:sc descriptor-reg
660                                    :offset ,offset
661                                    :to :eval)
662                          ,name))
663                  register-arg-names *register-arg-offsets*))
664      ,@(when (eq return :fixed)
665          '((:temporary (:scs (descriptor-reg) :from :eval) move-temp)))
666
667      (:temporary (:scs (descriptor-reg) :to :eval) stepping)
668
669      ,@(unless (eq return :tail)
670          '((:temporary (:scs (non-descriptor-reg)) temp)
671            (:temporary (:sc control-stack :offset nfp-save-offset) nfp-save)))
672
673      (:generator ,(+ (if named 5 0)
674                      (if variable 19 1)
675                      (if (eq return :tail) 0 10)
676                      15
677                      (if (eq return :unknown) 25 0))
678        (trace-table-entry trace-table-call-site)
679        (let* ((cur-nfp (current-nfp-tn vop))
680               ,@(unless (eq return :tail)
681                   '((lra-label (gen-label))))
682               (step-done-label (gen-label))
683               (filler
684                (remove nil
685                        (list :load-nargs
686                              ,@(if (eq return :tail)
687                                    '((unless (location= old-fp old-fp-pass)
688                                        :load-old-fp)
689                                      (unless (location= return-pc
690                                                         return-pc-pass)
691                                        :load-return-pc)
692                                      (when cur-nfp
693                                        :frob-nfp))
694                                    '(:comp-lra
695                                      (when cur-nfp
696                                        :frob-nfp)
697                                      :save-fp
698                                      :load-fp))))))
699          (flet ((do-next-filler ()
700                   (let* ((next (pop filler))
701                          (what (if (consp next) (car next) next)))
702                     (ecase what
703                       (:load-nargs
704                        ,@(if variable
705                              `((inst sub nargs-pass csp-tn new-fp)
706                                ,@(let ((index -1))
707                                    (mapcar #'(lambda (name)
708                                                `(loadw ,name new-fp
709                                                        ,(incf index)))
710                                            register-arg-names)))
711                              '((inst li nargs-pass (fixnumize nargs)))))
712                       ,@(if (eq return :tail)
713                             '((:load-old-fp
714                                (sc-case old-fp
715                                  (any-reg
716                                   (inst move old-fp-pass old-fp))
717                                  (control-stack
718                                   (loadw old-fp-pass cfp-tn
719                                          (tn-offset old-fp)))))
720                               (:load-return-pc
721                                (sc-case return-pc
722                                  (descriptor-reg
723                                   (inst move return-pc-pass return-pc))
724                                  (control-stack
725                                   (loadw return-pc-pass cfp-tn
726                                          (tn-offset return-pc)))))
727                               (:frob-nfp
728                                (inst add nsp-tn cur-nfp
729                                      (- (bytes-needed-for-non-descriptor-stack-frame)
730                                         number-stack-displacement))))
731                             `((:comp-lra
732                                (inst compute-lra-from-code
733                                      return-pc-pass code-tn lra-label temp))
734                               (:frob-nfp
735                                (store-stack-tn nfp-save cur-nfp))
736                               (:save-fp
737                                (inst move old-fp-pass cfp-tn))
738                               (:load-fp
739                                ,(if variable
740                                     '(move cfp-tn new-fp)
741                                     '(if (> nargs register-arg-count)
742                                          (move cfp-tn new-fp)
743                                          (move cfp-tn csp-tn))))))
744                       ((nil)))))
745                 (insert-step-instrumenting (callable-tn)
746                   ;; Conditionally insert a conditional trap:
747                   (when step-instrumenting
748                     ;; Get the symbol-value of SB!IMPL::*STEPPING*
749                     (load-symbol-value stepping sb!impl::*stepping*)
750                     (inst cmp stepping null-tn)
751                     ;; If it's not null, trap.
752                     (inst b :eq step-done-label)
753                     (inst nop)
754                     ;; FIXME: this doesn't look right.
755                     (note-this-location vop :step-before-vop)
756                     ;; Construct a trap code with the low bits from
757                     ;; SINGLE-STEP-AROUND-TRAP and the high bits from
758                     ;; the register number of CALLABLE-TN.
759                     (inst unimp (logior single-step-around-trap
760                                         (ash (reg-tn-encoding callable-tn)
761                                              5)))
762                     (emit-label step-done-label))))
763
764
765            ,@(if named
766                  `((sc-case name
767                      (descriptor-reg (move name-pass name))
768                      (control-stack
769                       (loadw name-pass cfp-tn (tn-offset name))
770                       (do-next-filler))
771                      (constant
772                       (loadw name-pass code-tn (tn-offset name)
773                              other-pointer-lowtag)
774                       (do-next-filler)))
775                    (insert-step-instrumenting name-pass)
776                    (loadw function name-pass fdefn-raw-addr-slot
777                           other-pointer-lowtag)
778                    (do-next-filler))
779                  `((sc-case arg-fun
780                      (descriptor-reg (move lexenv arg-fun))
781                      (control-stack
782                       (loadw lexenv cfp-tn (tn-offset arg-fun))
783                       (do-next-filler))
784                      (constant
785                       (loadw lexenv code-tn (tn-offset arg-fun)
786                              other-pointer-lowtag)
787                       (do-next-filler)))
788                    (loadw function lexenv closure-fun-slot
789                           fun-pointer-lowtag)
790                    (do-next-filler)
791                    (insert-step-instrumenting function)))
792            (loop
793              (if filler
794                  (do-next-filler)
795                  (return)))
796
797            (note-this-location vop :call-site)
798            (inst j function
799                  (- (ash simple-fun-code-offset word-shift)
800                     fun-pointer-lowtag))
801            (inst move code-tn function))
802
803          ,@(ecase return
804              (:fixed
805               '((emit-return-pc lra-label)
806                 (default-unknown-values vop values nvals move-temp
807                                         temp lra-label)
808                 (when cur-nfp
809                   (load-stack-tn cur-nfp nfp-save))))
810              (:unknown
811               '((emit-return-pc lra-label)
812                 (note-this-location vop :unknown-return)
813                 (receive-unknown-values values-start nvals start count
814                                         lra-label temp)
815                 (when cur-nfp
816                   (load-stack-tn cur-nfp nfp-save))))
817              (:tail)))
818        (trace-table-entry trace-table-normal))))
819
820
821 (define-full-call call nil :fixed nil)
822 (define-full-call call-named t :fixed nil)
823 (define-full-call multiple-call nil :unknown nil)
824 (define-full-call multiple-call-named t :unknown nil)
825 (define-full-call tail-call nil :tail nil)
826 (define-full-call tail-call-named t :tail nil)
827
828 (define-full-call call-variable nil :fixed t)
829 (define-full-call multiple-call-variable nil :unknown t)
830
831
832 ;;; Defined separately, since needs special code that BLT's the
833 ;;; arguments down.
834 (define-vop (tail-call-variable)
835   (:args
836    (args-arg :scs (any-reg) :target args)
837    (function-arg :scs (descriptor-reg) :target lexenv)
838    (old-fp-arg :scs (any-reg) :target old-fp)
839    (lra-arg :scs (descriptor-reg) :target lra))
840
841   (:temporary (:sc any-reg :offset nl0-offset :from (:argument 0)) args)
842   (:temporary (:sc any-reg :offset lexenv-offset :from (:argument 1)) lexenv)
843   (:temporary (:sc any-reg :offset ocfp-offset :from (:argument 2)) old-fp)
844   (:temporary (:sc any-reg :offset lra-offset :from (:argument 3)) lra)
845
846   (:temporary (:scs (any-reg) :from :eval) temp)
847
848   (:vop-var vop)
849
850   (:generator 75
851
852     ;; Move these into the passing locations if they are not already there.
853     (move args args-arg)
854     (move lexenv function-arg)
855     (move old-fp old-fp-arg)
856     (move lra lra-arg)
857
858     ;; Clear the number stack if anything is there.
859     (let ((cur-nfp (current-nfp-tn vop)))
860       (when cur-nfp
861         (inst add nsp-tn cur-nfp
862               (- (bytes-needed-for-non-descriptor-stack-frame)
863                  number-stack-displacement))))
864
865     ;; And jump to the assembly-routine that does the bliting.
866     (inst ji temp (make-fixup 'tail-call-variable :assembly-routine))
867     (inst nop)))
868
869 \f
870 ;;;; Unknown values return:
871
872
873 ;;; Return a single value using the unknown-values convention.
874 (define-vop (return-single)
875   (:args (old-fp :scs (any-reg))
876          (return-pc :scs (descriptor-reg))
877          (value))
878   (:ignore value)
879   (:vop-var vop)
880   (:generator 6
881     (trace-table-entry trace-table-fun-epilogue)
882     ;; Clear the number stack.
883     (let ((cur-nfp (current-nfp-tn vop)))
884       (when cur-nfp
885         (inst add nsp-tn cur-nfp
886               (- (bytes-needed-for-non-descriptor-stack-frame)
887                  number-stack-displacement))))
888     ;; Clear the control stack, and restore the frame pointer.
889     (move csp-tn cfp-tn)
890     (move cfp-tn old-fp)
891     ;; Out of here.
892     (lisp-return return-pc :offset 2)
893     (trace-table-entry trace-table-normal)))
894
895 ;;; Do unknown-values return of a fixed number of values.  The Values are
896 ;;; required to be set up in the standard passing locations.  Nvals is the
897 ;;; number of values returned.
898 ;;;
899 ;;; If returning a single value, then deallocate the current frame, restore
900 ;;; FP and jump to the single-value entry at Return-PC + 8.
901 ;;;
902 ;;; If returning other than one value, then load the number of values returned,
903 ;;; NIL out unsupplied values registers, restore FP and return at Return-PC.
904 ;;; When there are stack values, we must initialize the argument pointer to
905 ;;; point to the beginning of the values block (which is the beginning of the
906 ;;; current frame.)
907 (define-vop (return)
908   (:args
909    (old-fp :scs (any-reg))
910    (return-pc :scs (descriptor-reg) :to (:eval 1))
911    (values :more t))
912   (:ignore values)
913   (:info nvals)
914   (:temporary (:sc descriptor-reg :offset a0-offset :from (:eval 0)) a0)
915   (:temporary (:sc descriptor-reg :offset a1-offset :from (:eval 0)) a1)
916   (:temporary (:sc descriptor-reg :offset a2-offset :from (:eval 0)) a2)
917   (:temporary (:sc descriptor-reg :offset a3-offset :from (:eval 0)) a3)
918   (:temporary (:sc descriptor-reg :offset a4-offset :from (:eval 0)) a4)
919   (:temporary (:sc descriptor-reg :offset a5-offset :from (:eval 0)) a5)
920   (:temporary (:sc any-reg :offset nargs-offset) nargs)
921   (:temporary (:sc any-reg :offset ocfp-offset) val-ptr)
922   (:vop-var vop)
923   (:generator 6
924     (trace-table-entry trace-table-fun-epilogue)
925     ;; Clear the number stack.
926     (let ((cur-nfp (current-nfp-tn vop)))
927       (when cur-nfp
928         (inst add nsp-tn cur-nfp
929               (- (bytes-needed-for-non-descriptor-stack-frame)
930                  number-stack-displacement))))
931     (cond ((= nvals 1)
932            ;; Clear the control stack, and restore the frame pointer.
933            (move csp-tn cfp-tn)
934            (move cfp-tn old-fp)
935            ;; Out of here.
936            (lisp-return return-pc :offset 2))
937           (t
938            ;; Establish the values pointer and values count.
939            (move val-ptr cfp-tn)
940            (inst li nargs (fixnumize nvals))
941            ;; restore the frame pointer and clear as much of the control
942            ;; stack as possible.
943            (move cfp-tn old-fp)
944            (inst add csp-tn val-ptr (* nvals n-word-bytes))
945            ;; pre-default any argument register that need it.
946            (when (< nvals register-arg-count)
947              (dolist (reg (subseq (list a0 a1 a2 a3 a4 a5) nvals))
948                (move reg null-tn)))
949            ;; And away we go.
950            (lisp-return return-pc)))
951     (trace-table-entry trace-table-normal)))
952
953 ;;; Do unknown-values return of an arbitrary number of values (passed on the
954 ;;; stack.)  We check for the common case of a single return value, and do that
955 ;;; inline using the normal single value return convention.  Otherwise, we
956 ;;; branch off to code that calls an assembly-routine.
957 (define-vop (return-multiple)
958   (:args
959    (old-fp-arg :scs (any-reg) :to (:eval 1))
960    (lra-arg :scs (descriptor-reg) :to (:eval 1))
961    (vals-arg :scs (any-reg) :target vals)
962    (nvals-arg :scs (any-reg) :target nvals))
963
964   (:temporary (:sc any-reg :offset nl1-offset :from (:argument 0)) old-fp)
965   (:temporary (:sc descriptor-reg :offset lra-offset :from (:argument 1)) lra)
966   (:temporary (:sc any-reg :offset nl0-offset :from (:argument 2)) vals)
967   (:temporary (:sc any-reg :offset nargs-offset :from (:argument 3)) nvals)
968   (:temporary (:sc descriptor-reg :offset a0-offset) a0)
969
970   (:temporary (:scs (any-reg) :from (:eval 1)) temp)
971
972   (:vop-var vop)
973
974   (:generator 13
975     (trace-table-entry trace-table-fun-epilogue)
976     (let ((not-single (gen-label)))
977       ;; Clear the number stack.
978       (let ((cur-nfp (current-nfp-tn vop)))
979         (when cur-nfp
980           (inst add nsp-tn cur-nfp
981                 (- (bytes-needed-for-non-descriptor-stack-frame)
982                    number-stack-displacement))))
983
984       ;; Check for the single case.
985       (inst cmp nvals-arg (fixnumize 1))
986       (inst b :ne not-single)
987       (inst ld a0 vals-arg)
988
989       ;; Return with one value.
990       (move csp-tn cfp-tn)
991       (move cfp-tn old-fp-arg)
992       (lisp-return lra-arg :offset 2)
993
994       ;; Nope, not the single case.
995       (emit-label not-single)
996       (move old-fp old-fp-arg)
997       (move lra lra-arg)
998       (move vals vals-arg)
999       (move nvals nvals-arg)
1000       (inst ji temp (make-fixup 'return-multiple :assembly-routine))
1001       (inst nop))
1002     (trace-table-entry trace-table-normal)))
1003
1004
1005 \f
1006 ;;;; XEP hackery:
1007
1008
1009 ;;; We don't need to do anything special for regular functions.
1010 (define-vop (setup-environment)
1011   (:info label)
1012   (:ignore label)
1013   (:generator 0
1014     ;; Don't bother doing anything.
1015     ))
1016
1017 ;;; Get the lexical environment from it's passing location.
1018 (define-vop (setup-closure-environment)
1019   (:temporary (:sc descriptor-reg :offset lexenv-offset :target closure
1020                :to (:result 0))
1021               lexenv)
1022   (:results (closure :scs (descriptor-reg)))
1023   (:info label)
1024   (:ignore label)
1025   (:generator 6
1026     ;; Get result.
1027     (move closure lexenv)))
1028
1029 ;;; Copy a more arg from the argument area to the end of the current frame.
1030 ;;; Fixed is the number of non-more arguments.
1031 (define-vop (copy-more-arg)
1032   (:temporary (:sc any-reg :offset nl0-offset) result)
1033   (:temporary (:sc any-reg :offset nl1-offset) count)
1034   (:temporary (:sc any-reg :offset nl2-offset) src)
1035   (:temporary (:sc any-reg :offset nl3-offset) dst)
1036   (:temporary (:sc descriptor-reg :offset l0-offset) temp)
1037   (:info fixed)
1038   (:generator 20
1039     (let ((loop (gen-label))
1040           (do-regs (gen-label))
1041           (done (gen-label)))
1042       (when (< fixed register-arg-count)
1043         ;; Save a pointer to the results so we can fill in register args.
1044         ;; We don't need this if there are more fixed args than reg args.
1045         (move result csp-tn))
1046       ;; Allocate the space on the stack.
1047       (cond ((zerop fixed)
1048              (inst cmp nargs-tn)
1049              (inst b :eq done)
1050              (inst add csp-tn csp-tn nargs-tn))
1051             (t
1052              (inst subcc count nargs-tn (fixnumize fixed))
1053              (inst b :le done)
1054              (inst nop)
1055              (inst add csp-tn csp-tn count)))
1056       (when (< fixed register-arg-count)
1057         ;; We must stop when we run out of stack args, not when we run out of
1058         ;; more args.
1059         (inst subcc count nargs-tn (fixnumize register-arg-count))
1060         ;; Everything of interest in registers.
1061         (inst b :le do-regs))
1062       ;; Initialize dst to be end of stack.
1063       (move dst csp-tn)
1064       ;; Initialize src to be end of args.
1065       (inst add src cfp-tn nargs-tn)
1066
1067       (emit-label loop)
1068       ;; *--dst = *--src, --count
1069       (inst add src src (- n-word-bytes))
1070       (inst subcc count count (fixnumize 1))
1071       (loadw temp src)
1072       (inst add dst dst (- n-word-bytes))
1073       (inst b :gt loop)
1074       (storew temp dst)
1075
1076       (emit-label do-regs)
1077       (when (< fixed register-arg-count)
1078         ;; Now we have to deposit any more args that showed up in registers.
1079         (inst subcc count nargs-tn (fixnumize fixed))
1080         (do ((i fixed (1+ i)))
1081             ((>= i register-arg-count))
1082           ;; Don't deposit any more than there are.
1083           (inst b :eq done)
1084           (inst subcc count (fixnumize 1))
1085           ;; Store it relative to the pointer saved at the start.
1086           (storew (nth i *register-arg-tns*) result (- i fixed))))
1087       (emit-label done))))
1088
1089
1090 ;;; More args are stored consequtively on the stack, starting immediately at
1091 ;;; the context pointer.  The context pointer is not typed, so the lowtag is 0.
1092 (define-vop (more-arg word-index-ref)
1093   (:variant 0 0)
1094   (:translate %more-arg))
1095
1096 ;;; Turn more arg (context, count) into a list.
1097 (define-vop (listify-rest-args)
1098   (:args (context-arg :target context :scs (descriptor-reg))
1099          (count-arg :target count :scs (any-reg)))
1100   (:arg-types * tagged-num)
1101   (:temporary (:scs (any-reg) :from (:argument 0)) context)
1102   (:temporary (:scs (any-reg) :from (:argument 1)) count)
1103   (:temporary (:scs (descriptor-reg) :from :eval) temp)
1104   (:temporary (:scs (non-descriptor-reg) :from :eval) dst)
1105   (:results (result :scs (descriptor-reg)))
1106   (:translate %listify-rest-args)
1107   (:policy :safe)
1108   (:node-var node)
1109   (:generator 20
1110     (let* ((enter (gen-label))
1111            (loop (gen-label))
1112            (done (gen-label))
1113            (dx-p (node-stack-allocate-p node))
1114            (alloc-area-tn (if dx-p csp-tn alloc-tn)))
1115       (move context context-arg)
1116       (move count count-arg)
1117       ;; Check to see if there are any arguments.
1118       (inst cmp count)
1119       (inst b :eq done)
1120       (move result null-tn)
1121
1122       ;; We need to do this atomically.
1123       (pseudo-atomic ()
1124         (when dx-p
1125           (align-csp temp))
1126         ;; Allocate a cons (2 words) for each item.
1127         (inst andn result alloc-area-tn lowtag-mask)
1128         (inst or result list-pointer-lowtag)
1129         (move dst result)
1130         (inst sll temp count 1)
1131         (inst b enter)
1132         (inst add alloc-area-tn temp)
1133
1134         ;; Compute the next cons and store it in the current one.
1135         (emit-label loop)
1136         (inst add dst dst (* 2 n-word-bytes))
1137         (storew dst dst -1 list-pointer-lowtag)
1138
1139         ;; Grab one value.
1140         (emit-label enter)
1141         (loadw temp context)
1142         (inst add context context n-word-bytes)
1143
1144         ;; Dec count, and if != zero, go back for more.
1145         (inst subcc count (fixnumize 1))
1146         (inst b :gt loop)
1147
1148         ;; Store the value into the car of the current cons (in the delay
1149         ;; slot).
1150         (storew temp dst 0 list-pointer-lowtag)
1151
1152         ;; NIL out the last cons.
1153         (storew null-tn dst 1 list-pointer-lowtag))
1154       (emit-label done))))
1155
1156
1157 ;;; Return the location and size of the more arg glob created by Copy-More-Arg.
1158 ;;; Supplied is the total number of arguments supplied (originally passed in
1159 ;;; NARGS.)  Fixed is the number of non-rest arguments.
1160 ;;;
1161 ;;; We must duplicate some of the work done by Copy-More-Arg, since at that
1162 ;;; time the environment is in a pretty brain-damaged state, preventing this
1163 ;;; info from being returned as values.  What we do is compute
1164 ;;; supplied - fixed, and return a pointer that many words below the current
1165 ;;; stack top.
1166 (define-vop (more-arg-context)
1167   (:policy :fast-safe)
1168   (:translate sb!c::%more-arg-context)
1169   (:args (supplied :scs (any-reg)))
1170   (:arg-types tagged-num (:constant fixnum))
1171   (:info fixed)
1172   (:results (context :scs (descriptor-reg))
1173             (count :scs (any-reg)))
1174   (:result-types t tagged-num)
1175   (:note "more-arg-context")
1176   (:generator 5
1177     (inst sub count supplied (fixnumize fixed))
1178     (inst sub context csp-tn count)))
1179
1180
1181 ;;; Signal wrong argument count error if Nargs isn't = to Count.
1182 ;;;
1183 (define-vop (verify-arg-count)
1184   (:policy :fast-safe)
1185   (:translate sb!c::%verify-arg-count)
1186   (:args (nargs :scs (any-reg)))
1187   (:arg-types positive-fixnum (:constant t))
1188   (:info count)
1189   (:vop-var vop)
1190   (:save-p :compute-only)
1191   (:generator 3
1192     (let ((err-lab
1193            (generate-error-code vop invalid-arg-count-error nargs)))
1194       (inst cmp nargs (fixnumize count))
1195       (if (member :sparc-v9 *backend-subfeatures*)
1196           ;; Assume we don't take the branch
1197           (inst b :ne err-lab :pn)
1198           (inst b :ne err-lab))
1199       (inst nop))))
1200
1201 ;;; Signal various errors.
1202 (macrolet ((frob (name error translate &rest args)
1203              `(define-vop (,name)
1204                 ,@(when translate
1205                     `((:policy :fast-safe)
1206                       (:translate ,translate)))
1207                 (:args ,@(mapcar #'(lambda (arg)
1208                                      `(,arg :scs (any-reg descriptor-reg)))
1209                                  args))
1210                 (:vop-var vop)
1211                 (:save-p :compute-only)
1212                 (:generator 1000
1213                   (error-call vop ,error ,@args)))))
1214   (frob arg-count-error invalid-arg-count-error
1215     sb!c::%arg-count-error nargs)
1216   (frob type-check-error object-not-type-error sb!c::%type-check-error
1217     object type)
1218   (frob layout-invalid-error layout-invalid-error sb!c::%layout-invalid-error
1219     object layout)
1220   (frob odd-key-args-error odd-key-args-error
1221     sb!c::%odd-key-args-error)
1222   (frob unknown-key-arg-error unknown-key-arg-error
1223     sb!c::%unknown-key-arg-error key)
1224   (frob nil-fun-returned-error nil-fun-returned-error nil fun))
1225
1226 ;;; Single-stepping
1227
1228 (define-vop (step-instrument-before-vop)
1229   (:temporary (:scs (descriptor-reg)) stepping)
1230   (:policy :fast-safe)
1231   (:vop-var vop)
1232   (:generator 3
1233     (load-symbol-value stepping sb!impl::*stepping*)
1234     (inst cmp stepping null-tn)
1235     (inst b :eq DONE)
1236     (inst nop)
1237     (note-this-location vop :step-before-vop)
1238     (inst unimp single-step-before-trap)
1239     DONE))