1 ;;;; function call for the x86 VM
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
* descriptor-reg-sc-number
22 (nth n
*register-arg-offsets
*))
23 (make-wired-tn *backend-t-primitive-type
* control-stack-sc-number n
)))
25 (defun standard-arg-location-sc (n)
26 (declare (type unsigned-byte n
))
27 (if (< n register-arg-count
)
28 (make-sc-offset descriptor-reg-sc-number
29 (nth n
*register-arg-offsets
*))
30 (make-sc-offset control-stack-sc-number n
)))
32 (defconstant arg-count-sc
(make-sc-offset any-reg-sc-number ecx-offset
))
33 (defconstant closure-sc
(make-sc-offset descriptor-reg-sc-number eax-offset
))
35 ;;; Make a passing location TN for a local call return PC.
37 ;;; Always wire the return PC location to the stack in its standard
39 (defun make-return-pc-passing-location (standard)
40 (declare (ignore standard
))
41 (make-wired-tn (primitive-type-or-lose 'system-area-pointer
)
42 sap-stack-sc-number return-pc-save-offset
))
44 (defconstant return-pc-passing-offset
45 (make-sc-offset sap-stack-sc-number return-pc-save-offset
))
47 ;;; This is similar to MAKE-RETURN-PC-PASSING-LOCATION, but makes a
48 ;;; location to pass OLD-FP in.
50 ;;; This is wired in both the standard and the local-call conventions,
51 ;;; because we want to be able to assume it's always there. Besides,
52 ;;; the x86 doesn't have enough registers to really make it profitable
53 ;;; to pass it in a register.
54 (defun make-old-fp-passing-location (standard)
55 (declare (ignore standard
))
56 (make-wired-tn *fixnum-primitive-type
* control-stack-sc-number
59 (defconstant old-fp-passing-offset
60 (make-sc-offset control-stack-sc-number ocfp-save-offset
))
62 ;;; Make the TNs used to hold OLD-FP and RETURN-PC within the current
63 ;;; function. We treat these specially so that the debugger can find
64 ;;; them at a known location.
66 ;;; Without using a save-tn - which does not make much sense if it is
67 ;;; wired to the stack?
68 (defun make-old-fp-save-location (physenv)
69 (physenv-debug-live-tn (make-wired-tn *fixnum-primitive-type
*
70 control-stack-sc-number
73 (defun make-return-pc-save-location (physenv)
74 (physenv-debug-live-tn
75 (make-wired-tn (primitive-type-or-lose 'system-area-pointer
)
76 sap-stack-sc-number return-pc-save-offset
)
79 ;;; Make a TN for the standard argument count passing location. We only
80 ;;; need to make the standard location, since a count is never passed when we
81 ;;; are using non-standard conventions.
82 (defun make-arg-count-location ()
83 (make-wired-tn *fixnum-primitive-type
* any-reg-sc-number ecx-offset
))
85 ;;; Make a TN to hold the number-stack frame pointer. This is allocated
86 ;;; once per component, and is component-live.
88 (make-restricted-tn *fixnum-primitive-type
* ignore-me-sc-number
))
90 (defun make-stack-pointer-tn ()
91 (make-normal-tn *fixnum-primitive-type
*))
93 (defun make-number-stack-pointer-tn ()
94 (make-restricted-tn *fixnum-primitive-type
* ignore-me-sc-number
))
96 ;;; Return a list of TNs that can be used to represent an unknown-values
97 ;;; continuation within a function.
98 (defun make-unknown-values-locations ()
99 (list (make-stack-pointer-tn)
100 (make-normal-tn *fixnum-primitive-type
*)))
102 ;;; This function is called by the ENTRY-ANALYZE phase, allowing
103 ;;; VM-dependent initialization of the IR2-COMPONENT structure. We
104 ;;; push placeholder entries in the CONSTANTS to leave room for
105 ;;; additional noise in the code object header.
106 (defun select-component-format (component)
107 (declare (type component component
))
108 ;; The 1+ here is because for the x86 the first constant is a
109 ;; pointer to a list of fixups, or NIL if the code object has none.
110 ;; (If I understand correctly, the fixups are needed at GC copy
111 ;; time because the X86 code isn't relocatable.)
113 ;; KLUDGE: It'd be cleaner to have the fixups entry be a named
114 ;; element of the CODE (aka component) primitive object. However,
115 ;; it's currently a large, tricky, error-prone chore to change
116 ;; the layout of any primitive object, so for the foreseeable future
117 ;; we'll just live with this ugliness. -- WHN 2002-01-02
118 (dotimes (i (1+ code-constants-offset
))
119 (vector-push-extend nil
120 (ir2-component-constants (component-info component
))))
125 ;;; This is used for setting up the Old-FP in local call.
126 (define-vop (current-fp)
127 (:results
(val :scs
(any-reg control-stack
)))
131 ;;; We don't have a separate NFP, so we don't need to do anything here.
132 (define-vop (compute-old-nfp)
138 ;;; Accessing a slot from an earlier stack frame is definite hackery.
139 (define-vop (ancestor-frame-ref)
140 (:args
(frame-pointer :scs
(descriptor-reg))
141 (variable-home-tn :load-if nil
))
142 (:results
(value :scs
(descriptor-reg any-reg
)))
145 (aver (sc-is variable-home-tn control-stack
))
146 (loadw value frame-pointer
147 (frame-word-offset (tn-offset variable-home-tn
)))))
148 (define-vop (ancestor-frame-set)
149 (:args
(frame-pointer :scs
(descriptor-reg))
150 (value :scs
(descriptor-reg any-reg
)))
151 (:results
(variable-home-tn :load-if nil
))
154 (aver (sc-is variable-home-tn control-stack
))
155 (storew value frame-pointer
156 (frame-word-offset (tn-offset variable-home-tn
)))))
158 (macrolet ((define-frame-op
159 (suffix sc stack-sc instruction
163 :disp
(frame-byte-offset
164 (tn-offset variable-home-tn
)))))
165 (let ((reffer (symbolicate 'ancestor-frame-ref
'/ suffix
))
166 (setter (symbolicate 'ancestor-frame-set
'/ suffix
)))
168 (define-vop (,reffer ancestor-frame-ref
)
169 (:results
(value :scs
(,sc
)))
171 (aver (sc-is variable-home-tn
,stack-sc
))
172 (inst ,instruction value
174 (define-vop (,setter ancestor-frame-set
)
175 (:args
(frame-pointer :scs
(descriptor-reg))
178 (aver (sc-is variable-home-tn
,stack-sc
))
179 (inst ,instruction
,ea value
))))))
181 (suffix sc stack-sc
(load set
)
185 :disp
(frame-byte-offset
186 (tn-offset variable-home-tn
)))))
187 (let ((reffer (symbolicate 'ancestor-frame-ref
'/ suffix
))
188 (setter (symbolicate 'ancestor-frame-set
'/ suffix
)))
190 (define-vop (,reffer ancestor-frame-ref
)
191 (:results
(value :scs
(,sc
)))
193 (aver (sc-is variable-home-tn
,stack-sc
))
195 `(with-empty-tn@fp-top
(value)
198 (define-vop (,setter ancestor-frame-set
)
199 (:args
(frame-pointer :scs
(descriptor-reg))
202 (aver (sc-is variable-home-tn
,stack-sc
))
204 `(with-tn@fp-top
(value)
207 (define-frame-op signed-byte-32 signed-reg signed-stack mov
)
208 (define-frame-op unsigned-byte-32 unsigned-reg unsigned-stack mov
)
209 (define-frame-op system-area-pointer sap-reg sap-stack mov
)
211 (define-x87-frame-op double-float double-reg double-stack
212 (fldd fstd
) (make-ea :dword
214 :disp
(frame-byte-offset
215 (1+ (tn-offset variable-home-tn
)))))
216 (define-x87-frame-op single-float single-reg single-stack
219 (define-x87-frame-op complex-double-float complex-double-reg
221 ((let ((real (complex-double-reg-real-tn value
))
222 (imag (complex-double-reg-imag-tn value
)))
223 (with-empty-tn@fp-top
(real)
224 (inst fldd
(ea-for-cdf-real-stack variable-home-tn frame-pointer
)))
225 (with-empty-tn@fp-top
(imag)
226 (inst fldd
(ea-for-cdf-imag-stack variable-home-tn frame-pointer
))))
227 (let ((real (complex-double-reg-real-tn value
))
228 (imag (complex-double-reg-imag-tn value
)))
229 (with-tn@fp-top
(real)
230 (inst fstd
(ea-for-cdf-real-stack variable-home-tn frame-pointer
)))
231 (with-tn@fp-top
(imag)
232 (inst fstd
(ea-for-cdf-imag-stack variable-home-tn frame-pointer
))))))
233 (define-x87-frame-op complex-single-float complex-single-reg
235 ((let ((real (complex-single-reg-real-tn value
))
236 (imag (complex-single-reg-imag-tn value
)))
237 (with-empty-tn@fp-top
(real)
238 (inst fld
(ea-for-csf-real-stack variable-home-tn frame-pointer
)))
239 (with-empty-tn@fp-top
(imag)
240 (inst fld
(ea-for-csf-imag-stack variable-home-tn frame-pointer
))))
241 (let ((real (complex-single-reg-real-tn value
))
242 (imag (complex-single-reg-imag-tn value
)))
243 (with-tn@fp-top
(real)
244 (inst fst
(ea-for-csf-real-stack variable-home-tn frame-pointer
)))
245 (with-tn@fp-top
(imag)
246 (inst fst
(ea-for-csf-imag-stack variable-home-tn frame-pointer
)))))))
248 (defun primitive-type-indirect-cell-type (ptype)
249 (declare (type primitive-type ptype
))
250 (macrolet ((foo (&body data
)
251 `(case (primitive-type-name ptype
)
252 ,@(loop for
(name stack-sc ref set
) in data
256 (list (primitive-type-or-lose ',name
)
257 (sc-or-lose ',stack-sc
)
258 (lambda (node block fp value res
)
259 (sb!c
::vop
,ref node block
261 (lambda (node block fp new-val value
)
262 (sb!c
::vop
,set node block
263 fp new-val value
)))))))))
264 (foo (double-float double-stack
265 ancestor-frame-ref
/double-float
266 ancestor-frame-set
/double-float
)
267 (single-float single-stack
268 ancestor-frame-ref
/single-float
269 ancestor-frame-set
/single-float
)
270 (complex-double-float complex-double-stack
271 ancestor-frame-ref
/complex-double-float
272 ancestor-frame-set
/complex-double-float
)
273 (complex-single-float complex-single-stack
274 ancestor-frame-ref
/complex-single-float
275 ancestor-frame-set
/complex-single-float
)
276 (signed-byte-32 signed-stack
277 ancestor-frame-ref
/signed-byte-32
278 ancestor-frame-set
/signed-byte-32
)
279 (unsigned-byte-32 unsigned-stack
280 ancestor-frame-ref
/unsigned-byte-32
281 ancestor-frame-set
/unsigned-byte-32
)
282 (unsigned-byte-31 unsigned-stack
283 ancestor-frame-ref
/unsigned-byte-32
284 ancestor-frame-set
/unsigned-byte-32
)
285 (system-area-pointer sap-stack
286 ancestor-frame-ref
/system-area-pointer
287 ancestor-frame-set
/system-area-pointer
))))
289 (define-vop (xep-allocate-frame)
292 (emit-alignment n-lowtag-bits
)
293 (emit-label start-lab
)
294 ;; Skip space for the function header.
295 (inst simple-fun-header-word
)
296 (dotimes (i (1- simple-fun-code-offset
))
299 ;; The start of the actual code.
300 ;; Save the return-pc.
301 (popw ebp-tn
(frame-word-offset return-pc-save-offset
))))
303 (define-vop (xep-setup-sp)
306 (make-ea :dword
:base ebp-tn
307 :disp
(- (* n-word-bytes
308 (- (max 3 (sb-allocated-size 'stack
))
311 ;;; This is emitted directly before either a known-call-local, call-local,
312 ;;; or a multiple-call-local. All it does is allocate stack space for the
313 ;;; callee (who has the same size stack as us).
314 (define-vop (allocate-frame)
315 (:results
(res :scs
(any-reg))
320 (inst lea res
(make-ea :dword
:base esp-tn
321 :disp
(- (* sp-
>fp-offset n-word-bytes
))))
322 (inst sub esp-tn
(* n-word-bytes
(sb-allocated-size 'stack
)))))
324 ;;; Allocate a partial frame for passing stack arguments in a full
325 ;;; call. NARGS is the number of arguments passed. We allocate at
326 ;;; least 3 slots, because the XEP noise is going to want to use them
327 ;;; before it can extend the stack.
328 (define-vop (allocate-full-call-frame)
330 (:results
(res :scs
(any-reg)))
332 (inst lea res
(make-ea :dword
:base esp-tn
333 :disp
(- (* sp-
>fp-offset n-word-bytes
))))
334 (inst sub esp-tn
(* (max nargs
3) n-word-bytes
))))
336 ;;; Emit code needed at the return-point from an unknown-values call
337 ;;; for a fixed number of values. Values is the head of the TN-REF
338 ;;; list for the locations that the values are to be received into.
339 ;;; Nvals is the number of values that are to be received (should
340 ;;; equal the length of Values).
342 ;;; If 0 or 1 values are expected, then we just emit an instruction to
343 ;;; reset the SP (which will only be executed when other than 1 value
346 ;;; In the general case we have to do three things:
347 ;;; -- Default unsupplied register values. This need only be done
348 ;;; when a single value is returned, since register values are
349 ;;; defaulted by the called in the non-single case.
350 ;;; -- Default unsupplied stack values. This needs to be done whenever
351 ;;; there are stack values.
352 ;;; -- Reset SP. This must be done whenever other than 1 value is
353 ;;; returned, regardless of the number of values desired.
354 (defun default-unknown-values (vop values nvals node
)
355 (declare (type (or tn-ref null
) values
)
356 (type unsigned-byte nvals
))
357 (let ((type (sb!c
::basic-combination-derived-type node
)))
360 (note-this-location vop
:single-value-return
)
362 ((<= (values-type-max-value-count type
)
364 (when (and (named-type-p type
)
365 (eq nil
(named-type-name type
)))
366 ;; The function never returns, it may happen that the code
367 ;; ends right here leavig the :SINGLE-VALUE-RETURN note
368 ;; dangling. Let's emit a NOP.
370 ((not (values-type-may-be-single-value-p type
))
371 (inst mov esp-tn ebx-tn
))
372 ((member :cmov
*backend-subfeatures
*)
373 (inst cmov
:c esp-tn ebx-tn
))
375 (let ((single-value (gen-label)))
376 (inst jmp
:nc single-value
)
377 (inst mov esp-tn ebx-tn
)
378 (emit-label single-value
)))))
379 ((<= nvals register-arg-count
)
380 (note-this-location vop
:unknown-return
)
381 (when (values-type-may-be-single-value-p type
)
382 (let ((regs-defaulted (gen-label)))
383 (inst jmp
:c regs-defaulted
)
384 ;; Default the unsupplied registers.
385 (let* ((2nd-tn-ref (tn-ref-across values
))
386 (2nd-tn (tn-ref-tn 2nd-tn-ref
)))
387 (inst mov
2nd-tn nil-value
)
390 for tn-ref
= (tn-ref-across 2nd-tn-ref
)
391 then
(tn-ref-across tn-ref
)
392 for count from
2 below register-arg-count
393 do
(inst mov
(tn-ref-tn tn-ref
) 2nd-tn
))))
394 (inst mov ebx-tn esp-tn
)
395 (emit-label regs-defaulted
)))
396 (when (< register-arg-count
397 (values-type-max-value-count type
))
398 (inst mov esp-tn ebx-tn
)))
400 ;; The number of bytes depends on the relative jump instructions.
401 ;; Best case is 31+(n-3)*14, worst case is 35+(n-3)*18. For
402 ;; NVALS=6 that is 73/89 bytes, and for NVALS=7 that is 87/107
403 ;; bytes which is likely better than using the blt below.
404 (let ((regs-defaulted (gen-label))
405 (defaulting-done (gen-label))
406 (default-stack-slots (gen-label)))
407 (note-this-location vop
:unknown-return
)
408 ;; Branch off to the MV case.
409 (inst jmp
:c regs-defaulted
)
410 ;; Do the single value case.
411 ;; Default the register args
412 (inst mov eax-tn nil-value
)
414 (val (tn-ref-across values
) (tn-ref-across val
)))
415 ((= i
(min nvals register-arg-count
)))
416 (inst mov
(tn-ref-tn val
) eax-tn
))
417 ;; Fake other registers so it looks like we returned with all the
418 ;; registers filled in.
420 (inst jmp default-stack-slots
)
421 (emit-label regs-defaulted
)
422 (inst mov eax-tn nil-value
)
423 (collect ((defaults))
424 (do ((i register-arg-count
(1+ i
))
425 (val (do ((i 0 (1+ i
))
426 (val values
(tn-ref-across val
)))
427 ((= i register-arg-count
) val
))
428 (tn-ref-across val
)))
430 (let ((default-lab (gen-label))
432 (first-stack-arg-p (= i register-arg-count
)))
433 (defaults (cons default-lab
434 (cons tn first-stack-arg-p
)))
435 (inst cmp ecx-tn
(fixnumize i
))
436 (inst jmp
:be default-lab
)
437 (when first-stack-arg-p
438 ;; There are stack args so the frame of the callee is
439 ;; still there, save EDX in its first slot temporalily.
440 (storew edx-tn ebx-tn
(frame-word-offset sp-
>fp-offset
)))
441 (loadw edx-tn ebx-tn
(frame-word-offset (+ sp-
>fp-offset i
)))
442 (inst mov tn edx-tn
)))
443 (emit-label defaulting-done
)
444 (loadw edx-tn ebx-tn
(frame-word-offset sp-
>fp-offset
))
446 (let ((defaults (defaults)))
448 (assemble (*elsewhere
*)
449 (emit-label default-stack-slots
)
450 (dolist (default defaults
)
451 (emit-label (car default
))
453 ;; We are setting the first stack argument to NIL.
454 ;; The callee's stack frame is dead, save EDX by
455 ;; pushing it to the stack, it will end up at same
456 ;; place as in the (STOREW EDX-TN EBX-TN -1) case
459 (inst mov
(second default
) eax-tn
))
460 (inst jmp defaulting-done
)))))))
462 ;; 91 bytes for this branch.
463 (let ((regs-defaulted (gen-label))
464 (restore-edi (gen-label))
465 (no-stack-args (gen-label))
466 (default-stack-vals (gen-label))
467 (count-okay (gen-label)))
468 (note-this-location vop
:unknown-return
)
469 ;; Branch off to the MV case.
470 (inst jmp
:c regs-defaulted
)
471 ;; Default the register args, and set up the stack as if we
472 ;; entered the MV return point.
473 (inst mov ebx-tn esp-tn
)
474 (inst mov edi-tn nil-value
)
475 (inst mov esi-tn edi-tn
)
476 ;; Compute a pointer to where to put the [defaulted] stack values.
477 (emit-label no-stack-args
)
481 (make-ea :dword
:base ebp-tn
482 :disp
(frame-byte-offset register-arg-count
)))
483 ;; Load EAX with NIL so we can quickly store it, and set up
484 ;; stuff for the loop.
485 (inst mov eax-tn nil-value
)
487 (inst mov ecx-tn
(- nvals register-arg-count
))
488 ;; Jump into the default loop.
489 (inst jmp default-stack-vals
)
490 ;; The regs are defaulted. We need to copy any stack arguments,
491 ;; and then default the remaining stack arguments.
492 (emit-label regs-defaulted
)
493 ;; Compute the number of stack arguments, and if it's zero or
494 ;; less, don't copy any stack arguments.
495 (inst sub ecx-tn
(fixnumize register-arg-count
))
496 (inst jmp
:le no-stack-args
)
498 (storew edi-tn ebx-tn
(frame-word-offset (+ sp-
>fp-offset
1)))
499 ;; Throw away any unwanted args.
500 (inst cmp ecx-tn
(fixnumize (- nvals register-arg-count
)))
501 (inst jmp
:be count-okay
)
502 (inst mov ecx-tn
(fixnumize (- nvals register-arg-count
)))
503 (emit-label count-okay
)
504 ;; Save the number of stack values.
505 (inst mov eax-tn ecx-tn
)
506 ;; Compute a pointer to where the stack args go.
508 (make-ea :dword
:base ebp-tn
509 :disp
(frame-byte-offset register-arg-count
)))
510 ;; Save ESI, and compute a pointer to where the args come from.
511 (storew esi-tn ebx-tn
(frame-word-offset (+ sp-
>fp-offset
2)))
513 (make-ea :dword
:base ebx-tn
514 :disp
(frame-byte-offset
515 (+ sp-
>fp-offset register-arg-count
))))
517 (inst shr ecx-tn word-shift
) ; make word count
522 (loadw esi-tn ebx-tn
(frame-word-offset (+ sp-
>fp-offset
2)))
523 ;; Now we have to default the remaining args. Find out how many.
524 (inst sub eax-tn
(fixnumize (- nvals register-arg-count
)))
526 ;; If none, then just blow out of here.
527 (inst jmp
:le restore-edi
)
528 (inst mov ecx-tn eax-tn
)
529 (inst shr ecx-tn word-shift
) ; word count
530 ;; Load EAX with NIL for fast storing.
531 (inst mov eax-tn nil-value
)
533 (emit-label default-stack-vals
)
536 ;; Restore EDI, and reset the stack.
537 (emit-label restore-edi
)
538 (loadw edi-tn ebx-tn
(frame-word-offset (+ sp-
>fp-offset
1)))
539 (inst mov esp-tn ebx-tn
)
543 ;;;; unknown values receiving
545 ;;; Emit code needed at the return point for an unknown-values call
546 ;;; for an arbitrary number of values.
548 ;;; We do the single and non-single cases with no shared code: there
549 ;;; doesn't seem to be any potential overlap, and receiving a single
550 ;;; value is more important efficiency-wise.
552 ;;; When there is a single value, we just push it on the stack,
553 ;;; returning the old SP and 1.
555 ;;; When there is a variable number of values, we move all of the
556 ;;; argument registers onto the stack, and return ARGS and NARGS.
558 ;;; ARGS and NARGS are TNs wired to the named locations. We must
559 ;;; explicitly allocate these TNs, since their lifetimes overlap with
560 ;;; the results start and count. (Also, it's nice to be able to target
562 (defun receive-unknown-values (args nargs start count node
)
563 (declare (type tn args nargs start count
))
564 (let ((type (sb!c
::basic-combination-derived-type node
))
565 (variable-values (gen-label))
566 (stack-values (gen-label))
568 (when (values-type-may-be-single-value-p type
)
569 (inst jmp
:c variable-values
)
570 (cond ((location= start
(first *register-arg-tns
*))
571 (inst push
(first *register-arg-tns
*))
572 (inst lea start
(make-ea :dword
:base esp-tn
:disp n-word-bytes
)))
573 (t (inst mov start esp-tn
)
574 (inst push
(first *register-arg-tns
*))))
575 (inst mov count
(fixnumize 1))
577 (emit-label variable-values
))
578 ;; The stack frame is burnt and RETurned from if there are no
579 ;; stack values. In this case quickly reallocate sufficient space.
580 (when (<= (values-type-min-value-count type
)
582 (inst cmp nargs
(fixnumize register-arg-count
))
583 (inst jmp
:g stack-values
)
584 (inst sub esp-tn nargs
)
585 (emit-label stack-values
))
586 ;; dtc: this writes the registers onto the stack even if they are
587 ;; not needed, only the number specified in ecx are used and have
588 ;; stack allocated to them. No harm is done.
590 for arg in
*register-arg-tns
*
592 for j below
(values-type-max-value-count type
)
593 do
(storew arg args i
))
600 ;;; VOP that can be inherited by unknown values receivers. The main thing this
601 ;;; handles is allocation of the result temporaries.
602 (define-vop (unknown-values-receiver)
603 (:temporary
(:sc descriptor-reg
:offset ebx-offset
604 :from
:eval
:to
(:result
0))
606 (:temporary
(:sc any-reg
:offset ecx-offset
607 :from
:eval
:to
(:result
1))
609 (:results
(start :scs
(any-reg control-stack
))
610 (count :scs
(any-reg control-stack
))))
612 ;;;; local call with unknown values convention return
614 (defun check-ocfp-and-return-pc (old-fp return-pc
)
616 (format t
"*known-return: old-fp ~S, tn-kind ~S; ~S ~S~%"
617 old-fp
(sb!c
::tn-kind old-fp
) (sb!c
::tn-save-tn old-fp
)
618 (sb!c
::tn-kind
(sb!c
::tn-save-tn old-fp
)))
620 (format t
"*known-return: return-pc ~S, tn-kind ~S; ~S ~S~%"
621 return-pc
(sb!c
::tn-kind return-pc
)
622 (sb!c
::tn-save-tn return-pc
)
623 (sb!c
::tn-kind
(sb!c
::tn-save-tn return-pc
)))
624 (unless (and (sc-is old-fp control-stack
)
625 (= (tn-offset old-fp
) ocfp-save-offset
))
626 (error "ocfp not on stack in standard save location?"))
627 (unless (and (sc-is return-pc sap-stack
)
628 (= (tn-offset return-pc
) return-pc-save-offset
))
629 (error "return-pc not on stack in standard save location?")))
631 ;;; The local call convention doesn't fit that well with x86-style
632 ;;; calls. Emit a header for local calls to pop the return address
633 ;;; in the right place.
634 (defun emit-block-header (start-label trampoline-label fall-thru-p alignp
)
635 (declare (ignore alignp
))
636 (when trampoline-label
638 (inst jmp start-label
))
639 (emit-label trampoline-label
)
640 (popw ebp-tn
(frame-word-offset return-pc-save-offset
)))
641 (emit-label start-label
))
643 ;;; Non-TR local call for a fixed number of values passed according to
644 ;;; the unknown values convention.
646 ;;; FP is the frame pointer in install before doing the call.
648 ;;; NFP would be the number-stack frame pointer if we had a separate
651 ;;; Args are the argument passing locations, which are specified only
652 ;;; to terminate their lifetimes in the caller.
654 ;;; VALUES are the return value locations (wired to the standard
655 ;;; passing locations). NVALS is the number of values received.
657 ;;; Save is the save info, which we can ignore since saving has been
660 ;;; TARGET is a continuation pointing to the start of the called
662 (define-vop (call-local)
666 (:results
(values :more t
))
668 (:move-args
:local-call
)
669 (:info arg-locs callee target nvals
)
671 (:ignore nfp arg-locs args callee
)
675 (note-this-location vop
:call-site
)
677 (default-unknown-values vop values nvals node
)))
679 ;;; Non-TR local call for a variable number of return values passed according
680 ;;; to the unknown values convention. The results are the start of the values
681 ;;; glob and the number of values received.
682 (define-vop (multiple-call-local unknown-values-receiver
)
687 (:move-args
:local-call
)
688 (:info save callee target
)
689 (:ignore args save nfp callee
)
694 (note-this-location vop
:call-site
)
696 (note-this-location vop
:unknown-return
)
697 (receive-unknown-values values-start nvals start count node
)))
699 ;;;; local call with known values return
701 ;;; Non-TR local call with known return locations. Known-value return
702 ;;; works just like argument passing in local call.
704 ;;; Note: we can't use normal load-tn allocation for the fixed args,
705 ;;; since all registers may be tied up by the more operand. Instead,
706 ;;; we use MAYBE-LOAD-STACK-TN.
707 (define-vop (known-call-local)
711 (:results
(res :more t
))
712 (:move-args
:local-call
)
714 (:info save callee target
)
715 (:ignore args res save nfp callee
)
719 (note-this-location vop
:call-site
)
721 (note-this-location vop
:known-return
)))
723 ;;; From Douglas Crosher
724 ;;; Return from known values call. We receive the return locations as
725 ;;; arguments to terminate their lifetimes in the returning function. We
726 ;;; restore FP and CSP and jump to the Return-PC.
727 (define-vop (known-return)
731 (:move-args
:known-return
)
733 (:ignore val-locs vals
)
736 (check-ocfp-and-return-pc old-fp return-pc
)
737 ;; Zot all of the stack except for the old-fp and return-pc.
738 (inst mov esp-tn ebp-tn
)
744 ;;; There is something of a cross-product effect with full calls.
745 ;;; Different versions are used depending on whether we know the
746 ;;; number of arguments or the name of the called function, and
747 ;;; whether we want fixed values, unknown values, or a tail call.
749 ;;; In full call, the arguments are passed creating a partial frame on
750 ;;; the stack top and storing stack arguments into that frame. On
751 ;;; entry to the callee, this partial frame is pointed to by FP.
753 ;;; This macro helps in the definition of full call VOPs by avoiding
754 ;;; code replication in defining the cross-product VOPs.
756 ;;; NAME is the name of the VOP to define.
758 ;;; NAMED is true if the first argument is an fdefinition object whose
759 ;;; definition is to be called.
761 ;;; RETURN is either :FIXED, :UNKNOWN or :TAIL:
762 ;;; -- If :FIXED, then the call is for a fixed number of values, returned in
763 ;;; the standard passing locations (passed as result operands).
764 ;;; -- If :UNKNOWN, then the result values are pushed on the stack, and the
765 ;;; result values are specified by the Start and Count as in the
766 ;;; unknown-values continuation representation.
767 ;;; -- If :TAIL, then do a tail-recursive call. No values are returned.
768 ;;; The Old-Fp and Return-PC are passed as the second and third arguments.
770 ;;; In non-tail calls, the pointer to the stack arguments is passed as
771 ;;; the last fixed argument. If Variable is false, then the passing
772 ;;; locations are passed as a more arg. Variable is true if there are
773 ;;; a variable number of arguments passed on the stack. Variable
774 ;;; cannot be specified with :TAIL return. TR variable argument call
775 ;;; is implemented separately.
777 ;;; In tail call with fixed arguments, the passing locations are
778 ;;; passed as a more arg, but there is no new-FP, since the arguments
779 ;;; have been set up in the current frame.
780 (macrolet ((define-full-call (name named return variable
)
781 (aver (not (and variable
(eq return
:tail
))))
783 ,@(when (eq return
:unknown
)
784 '(unknown-values-receiver)))
786 ,@(unless (eq return
:tail
)
787 '((new-fp :scs
(any-reg) :to
(:argument
1))))
789 (fun :scs
(descriptor-reg control-stack
)
790 :target eax
:to
(:argument
0))
792 ,@(when (eq return
:tail
)
796 ,@(unless variable
'((args :more t
:scs
(descriptor-reg)))))
798 ,@(when (eq return
:fixed
)
799 '((:results
(values :more t
))))
801 (:save-p
,(if (eq return
:tail
) :compute-only t
))
803 ,@(unless (or (eq return
:tail
) variable
)
804 '((:move-args
:full-call
)))
808 ,@(unless (or variable
(eq return
:tail
)) '(arg-locs))
809 ,@(unless variable
'(nargs))
810 ,@(when (eq return
:fixed
) '(nvals))
814 ,@(unless (or variable
(eq return
:tail
)) '(arg-locs))
815 ,@(unless variable
'(args)))
817 ;; We pass either the fdefn object (for named call) or
818 ;; the actual function object (for unnamed call) in
819 ;; EAX. With named call, closure-tramp will replace it
820 ;; with the real function and invoke the real function
821 ;; for closures. Non-closures do not need this value,
822 ;; so don't care what shows up in it.
830 ;; We pass the number of arguments in ECX.
831 (:temporary
(:sc unsigned-reg
:offset ecx-offset
:to
:eval
) ecx
)
833 ;; With variable call, we have to load the
834 ;; register-args out of the (new) stack frame before
835 ;; doing the call. Therefore, we have to tell the
836 ;; lifetime stuff that we need to use them.
838 (mapcar (lambda (name offset
)
839 `(:temporary
(:sc descriptor-reg
844 *register-arg-names
* *register-arg-offsets
*))
846 ,@(when (eq return
:tail
)
847 '((:temporary
(:sc unsigned-reg
851 ,@(unless (eq return
:tail
)
854 (:generator
,(+ (if named
5 0)
856 (if (eq return
:tail
) 0 10)
858 (if (eq return
:unknown
) 25 0))
860 ;; This has to be done before the frame pointer is
861 ;; changed! EAX stores the 'lexical environment' needed
867 ;; For variable call, compute the number of
868 ;; arguments and move some of the arguments to
871 ;; Compute the number of arguments.
872 (noise '(inst mov ecx new-fp
))
873 (noise '(inst sub ecx esp-tn
))
874 ;; Move the necessary args to registers,
875 ;; this moves them all even if they are
878 for name in
*register-arg-names
*
879 for index downfrom -
1
880 do
(noise `(loadw ,name new-fp
,index
)))
884 (inst mov ecx
(fixnumize nargs
)))))
885 ,@(cond ((eq return
:tail
)
886 '(;; Python has figured out what frame we should
887 ;; return to so might as well use that clue.
888 ;; This seems really important to the
889 ;; implementation of things like
890 ;; (without-interrupts ...)
892 ;; dtc; Could be doing a tail call from a
893 ;; known-local-call etc in which the old-fp
894 ;; or ret-pc are in regs or in non-standard
895 ;; places. If the passing location were
896 ;; wired to the stack in standard locations
897 ;; then these moves will be un-necessary;
898 ;; this is probably best for the x86.
901 (unless (= ocfp-save-offset
903 ;; FIXME: FORMAT T for stale
904 ;; diagnostic output (several of
905 ;; them around here), ick
906 (error "** tail-call old-fp not S0~%")
907 (move old-fp-tmp old-fp
)
910 (frame-word-offset ocfp-save-offset
))))
911 ((any-reg descriptor-reg
)
912 (error "** tail-call old-fp in reg not S0~%")
915 (frame-word-offset ocfp-save-offset
))))
917 ;; For tail call, we have to push the
918 ;; return-pc so that it looks like we CALLed
919 ;; despite the fact that we are going to JMP.
920 (inst push return-pc
)
923 ;; For non-tail call, we have to save our
924 ;; frame pointer and install the new frame
925 ;; pointer. We can't load stack tns after this
927 `(;; Python doesn't seem to allocate a frame
928 ;; here which doesn't leave room for the
931 ;; The variable args are on the stack and
932 ;; become the frame, but there may be <3
933 ;; args and 3 stack slots are assumed
934 ;; allocate on the call. So need to ensure
935 ;; there are at least 3 slots. This hack
938 '(inst sub esp-tn
(fixnumize 3)))
940 ;; Bias the new-fp for use as an fp
942 '(inst sub new-fp
(fixnumize sp-
>fp-offset
)))
945 (storew ebp-tn new-fp
946 (frame-word-offset ocfp-save-offset
))
948 (move ebp-tn new-fp
) ; NB - now on new stack frame.
951 (when step-instrumenting
952 (emit-single-step-test)
954 (inst break single-step-around-trap
))
957 (note-this-location vop
:call-site
)
959 (inst ,(if (eq return
:tail
) 'jmp
'call
)
961 '(make-ea-for-object-slot eax fdefn-raw-addr-slot
962 other-pointer-lowtag
)
963 '(make-ea-for-object-slot eax closure-fun-slot
964 fun-pointer-lowtag
)))
967 '((default-unknown-values vop values nvals node
)))
969 '((note-this-location vop
:unknown-return
)
970 (receive-unknown-values values-start nvals start count
974 (define-full-call call nil
:fixed nil
)
975 (define-full-call call-named t
:fixed nil
)
976 (define-full-call multiple-call nil
:unknown nil
)
977 (define-full-call multiple-call-named t
:unknown nil
)
978 (define-full-call tail-call nil
:tail nil
)
979 (define-full-call tail-call-named t
:tail nil
)
981 (define-full-call call-variable nil
:fixed t
)
982 (define-full-call multiple-call-variable nil
:unknown t
))
984 ;;; This is defined separately, since it needs special code that BLT's
985 ;;; the arguments down. All the real work is done in the assembly
986 ;;; routine. We just set things up so that it can find what it needs.
987 (define-vop (tail-call-variable)
988 (:args
(args :scs
(any-reg control-stack
) :target esi
)
989 (function :scs
(descriptor-reg control-stack
) :target eax
)
992 (:temporary
(:sc unsigned-reg
:offset esi-offset
:from
(:argument
0)) esi
)
993 (:temporary
(:sc unsigned-reg
:offset eax-offset
:from
(:argument
1)) eax
)
995 (check-ocfp-and-return-pc old-fp return-pc
)
996 ;; Move these into the passing locations if they are not already there.
999 ;; And jump to the assembly routine.
1000 (inst jmp
(make-fixup 'tail-call-variable
:assembly-routine
))))
1002 ;;;; unknown values return
1004 ;;; Return a single-value using the Unknown-Values convention.
1006 ;;; pfw--get wired-tn conflicts sometimes if register sc specd for args
1007 ;;; having problems targeting args to regs -- using temps instead.
1009 ;;; First off, modifying the return-pc defeats the branch-prediction
1010 ;;; optimizations on modern CPUs quite handily. Second, we can do all
1011 ;;; this without needing a temp register. Fixed the latter, at least.
1012 ;;; -- AB 2006/Feb/04
1013 (define-vop (return-single)
1019 (check-ocfp-and-return-pc old-fp return-pc
)
1020 ;; Drop stack above old-fp
1021 (inst mov esp-tn ebp-tn
)
1022 ;; Clear the multiple-value return flag
1024 ;; Restore the old frame pointer
1029 ;;; Do unknown-values return of a fixed (other than 1) number of
1030 ;;; values. The VALUES are required to be set up in the standard
1031 ;;; passing locations. NVALS is the number of values returned.
1033 ;;; Basically, we just load ECX with the number of values returned and
1034 ;;; EBX with a pointer to the values, set ESP to point to the end of
1035 ;;; the values, and jump directly to return-pc.
1036 (define-vop (return)
1038 (return-pc :to
(:eval
1))
1042 ;; In the case of other than one value, we need these registers to
1043 ;; tell the caller where they are and how many there are.
1044 (:temporary
(:sc unsigned-reg
:offset ebx-offset
) ebx
)
1045 (:temporary
(:sc unsigned-reg
:offset ecx-offset
) ecx
)
1046 ;; We need to stretch the lifetime of return-pc past the argument
1047 ;; registers so that we can default the argument registers without
1048 ;; trashing return-pc.
1049 (:temporary
(:sc unsigned-reg
:offset
(first *register-arg-offsets
*)
1051 (:temporary
(:sc unsigned-reg
:offset
(second *register-arg-offsets
*)
1053 (:temporary
(:sc unsigned-reg
:offset
(third *register-arg-offsets
*)
1057 (check-ocfp-and-return-pc old-fp return-pc
)
1059 ;; This is handled in RETURN-SINGLE.
1060 (error "nvalues is 1"))
1061 ;; Establish the values pointer and values count.
1062 (inst lea ebx
(make-ea :dword
:base ebp-tn
1063 :disp
(* sp-
>fp-offset n-word-bytes
)))
1065 (inst xor ecx ecx
) ; smaller
1066 (inst mov ecx
(fixnumize nvals
)))
1067 ;; Pre-default any argument register that need it.
1068 (when (< nvals register-arg-count
)
1069 (let* ((arg-tns (nthcdr nvals
(list a0 a1 a2
)))
1070 (first (first arg-tns
)))
1071 (inst mov first nil-value
)
1072 (dolist (tn (cdr arg-tns
))
1073 (inst mov tn first
))))
1074 ;; Set the multiple value return flag.
1076 ;; And away we go. Except that return-pc is still on the
1077 ;; stack and we've changed the stack pointer. So we have to
1078 ;; tell it to index off of EBX instead of EBP.
1079 (cond ((<= nvals register-arg-count
)
1080 (inst mov esp-tn ebp-tn
)
1084 ;; Some values are on the stack after RETURN-PC and OLD-FP,
1085 ;; can't return normally and some slots of the frame will
1086 ;; be used as temporaries by the receiver.
1088 ;; Clear as much of the stack as possible, but not past the
1089 ;; old frame address.
1091 (make-ea :dword
:base ebp-tn
1092 :disp
(frame-byte-offset (1- nvals
))))
1093 (move ebp-tn old-fp
)
1094 (inst push
(make-ea :dword
:base ebx
1095 :disp
(frame-byte-offset
1097 (tn-offset return-pc
)))))
1100 ;;; Do unknown-values return of an arbitrary number of values (passed
1101 ;;; on the stack.) We check for the common case of a single return
1102 ;;; value, and do that inline using the normal single value return
1103 ;;; convention. Otherwise, we branch off to code that calls an
1104 ;;; assembly-routine.
1106 ;;; The assembly routine takes the following args:
1107 ;;; ECX -- number of values to find there.
1108 ;;; ESI -- pointer to where to find the values.
1109 (define-vop (return-multiple)
1112 (vals :scs
(any-reg) :target esi
)
1113 (nvals :scs
(any-reg) :target ecx
))
1114 (:temporary
(:sc unsigned-reg
:offset esi-offset
:from
(:argument
2)) esi
)
1115 (:temporary
(:sc unsigned-reg
:offset ecx-offset
:from
(:argument
3)) ecx
)
1116 (:temporary
(:sc descriptor-reg
:offset
(first *register-arg-offsets
*)
1117 :from
(:eval
0)) a0
)
1120 (check-ocfp-and-return-pc old-fp return-pc
)
1121 (unless (policy node
(> space speed
))
1122 ;; Check for the single case.
1123 (let ((not-single (gen-label)))
1124 (inst cmp nvals
(fixnumize 1))
1125 (inst jmp
:ne not-single
)
1126 ;; Return with one value.
1128 ;; Clear the stack until ocfp.
1129 (inst mov esp-tn ebp-tn
)
1130 ;; clear the multiple-value return flag
1135 ;; Nope, not the single case. Jump to the assembly routine.
1136 (emit-label not-single
)))
1139 (inst jmp
(make-fixup 'return-multiple
:assembly-routine
))))
1143 ;;; Get the lexical environment from its passing location.
1144 (define-vop (setup-closure-environment)
1145 (:results
(closure :scs
(descriptor-reg)))
1150 (move closure eax-tn
)))
1152 ;;; Copy a &MORE arg from the argument area to the end of the current
1153 ;;; frame. FIXED is the number of non-&MORE arguments.
1155 ;;; The tricky part is doing this without trashing any of the calling
1156 ;;; convention registers that are still needed. This vop is emitted
1157 ;;; directly after the xep-allocate frame. That means the registers
1158 ;;; are in use as follows:
1160 ;;; EAX -- The lexenv.
1161 ;;; EBX -- Available.
1162 ;;; ECX -- The total number of arguments * N-WORD-BYTES.
1163 ;;; EDX -- The first arg.
1164 ;;; EDI -- The second arg.
1165 ;;; ESI -- The third arg.
1167 ;;; So basically, we have one register available for our use: EBX.
1169 ;;; What we can do is push the other regs onto the stack, and then
1170 ;;; restore their values by looking directly below where we put the
1172 (define-vop (copy-more-arg)
1175 ;; Avoid the copy if there are no more args.
1176 (cond ((zerop fixed
)
1177 (inst jecxz JUST-ALLOC-FRAME
))
1179 (inst cmp ecx-tn
(fixnumize fixed
))
1180 (inst jmp
:be JUST-ALLOC-FRAME
)))
1182 ;; Allocate the space on the stack.
1183 ;; stack = ebp + sp->fp-offset - (max 3 frame-size) - (nargs - fixed)
1185 ;; Problem: this might leave some &more args outside esp, so
1186 ;; clamp the movement for now. If fixed > frame-size, reset
1187 ;; esp to the end of the current &more args (which *should*
1188 ;; be a noop?), and only set esp to its final value after the
1189 ;; stack-stack memmove loop. Otherwise, an unlucky signal
1190 ;; could end up overwriting the &more arguments before they're
1191 ;; moved in their final place.
1193 (make-ea :dword
:base ebp-tn
1194 :disp
(* n-word-bytes
1197 (- (max 3 (sb-allocated-size 'stack
))
1199 (inst sub ebx-tn ecx-tn
) ; Got the new stack in ebx
1200 (inst mov esp-tn ebx-tn
)
1202 ;; Now: nargs>=1 && nargs>fixed
1204 ;; Save the original count of args.
1205 (inst mov ebx-tn ecx-tn
)
1207 (cond ((< fixed register-arg-count
)
1208 ;; We must stop when we run out of stack args, not when we
1209 ;; run out of more args.
1210 ;; Number to copy = nargs-3
1211 (inst sub ecx-tn
(fixnumize register-arg-count
))
1212 ;; Everything of interest in registers.
1213 (inst jmp
:be DO-REGS
))
1215 ;; Number to copy = nargs-fixed
1216 (inst sub ecx-tn
(fixnumize fixed
))))
1218 (let ((delta (* n-word-bytes
1219 (- (max 3 (sb-allocated-size 'stack
))
1222 (cond ((zerop delta
)
1226 ;; stack frame smaller than fixed; moving args to higher
1227 ;; addresses (stack grows downard), so copy from the
1228 ;; end. Moreover, because we'd have to shrink the frame,
1229 ;; esp currently points at the end of the source args.
1233 (inst sub ecx-tn n-word-bytes
)
1234 (inst mov ebx-tn
(make-ea :dword
1235 :base esp-tn
:index ecx-tn
1236 ;; compensate for PUSH above
1237 :disp n-word-bytes
))
1238 (inst mov
(make-ea :dword
1239 :base esp-tn
:index ecx-tn
1240 ;; compensate for PUSH, and
1242 :disp
(- n-word-bytes delta
))
1248 ;; stack frame larger than fixed. Moving args to lower
1249 ;; addresses, so copy from the lowest address. esp
1250 ;; already points to the lowest address of the destination.
1254 (inst xor ebx-tn ebx-tn
)
1256 (inst mov esi-tn
(make-ea :dword
1257 :base esp-tn
:index ebx-tn
1259 :disp
(+ (* 2 n-word-bytes
)
1261 (inst mov
(make-ea :dword
1262 :base esp-tn
:index ebx-tn
1263 :disp
(* 2 n-word-bytes
))
1265 (inst add ebx-tn n-word-bytes
)
1266 (inst sub ecx-tn n-word-bytes
)
1270 (inst pop ebx-tn
))))
1272 ;; stack can now be set to its final size
1273 (when (< (max 3 (sb-allocated-size 'stack
)) fixed
)
1274 (inst add esp-tn
(* n-word-bytes
1276 (max 3 (sb-allocated-size 'stack
))))))
1279 (inst mov ecx-tn ebx-tn
)
1281 ;; Here: nargs>=1 && nargs>fixed
1282 (when (< fixed register-arg-count
)
1283 ;; Now we have to deposit any more args that showed up in
1287 ;; Store it relative to ebp
1288 (inst mov
(make-ea :dword
:base ebp-tn
1289 :disp
(* n-word-bytes
1293 (max 3 (sb-allocated-size
1295 (nth i
*register-arg-tns
*))
1298 (when (>= i register-arg-count
)
1301 ;; Don't deposit any more than there are.
1303 (inst test ecx-tn ecx-tn
)
1304 (inst cmp ecx-tn
(fixnumize i
)))
1305 (inst jmp
:eq DONE
)))
1311 (make-ea :dword
:base ebp-tn
1312 :disp
(* n-word-bytes
1314 (max 3 (sb-allocated-size 'stack
))))))
1318 (define-vop (more-kw-arg)
1319 (:translate sb
!c
::%more-kw-arg
)
1320 (:policy
:fast-safe
)
1321 (:args
(object :scs
(descriptor-reg) :to
(:result
1))
1322 (index :scs
(any-reg immediate
) :to
(:result
1) :target keyword
))
1323 (:arg-types
* tagged-num
)
1324 (:results
(value :scs
(descriptor-reg any-reg
))
1325 (keyword :scs
(descriptor-reg any-reg
)))
1330 (inst mov value
(make-ea :dword
:base object
:disp
(tn-value index
)))
1331 (inst mov keyword
(make-ea :dword
:base object
1332 :disp
(+ (tn-value index
) n-word-bytes
))))
1334 (inst mov value
(make-ea :dword
:base object
:index index
))
1335 (inst mov keyword
(make-ea :dword
:base object
:index index
1336 :disp n-word-bytes
))))))
1338 (define-vop (more-arg/c
)
1339 (:translate sb
!c
::%more-arg
)
1340 (:policy
:fast-safe
)
1341 (:args
(object :scs
(descriptor-reg) :to
(:result
1)))
1343 (:arg-types
* (:constant
(signed-byte 32)))
1344 (:results
(value :scs
(descriptor-reg any-reg
)))
1347 (inst mov value
(make-ea :dword
:base object
1348 :disp
(- (* index n-word-bytes
))))))
1350 (define-vop (more-arg)
1351 (:translate sb
!c
::%more-arg
)
1352 (:policy
:fast-safe
)
1353 (:args
(object :scs
(descriptor-reg) :to
(:result
1))
1354 (index :scs
(any-reg) :to
(:result
1) :target value
))
1355 (:arg-types
* tagged-num
)
1356 (:results
(value :scs
(descriptor-reg any-reg
)))
1361 (inst mov value
(make-ea :dword
:base object
:index value
))))
1363 ;;; Turn more arg (context, count) into a list.
1364 (define-vop (listify-rest-args)
1365 (:translate %listify-rest-args
)
1367 (:args
(context :scs
(descriptor-reg) :target src
)
1368 (count :scs
(any-reg) :target ecx
))
1369 (:arg-types
* tagged-num
)
1370 (:temporary
(:sc unsigned-reg
:offset esi-offset
:from
(:argument
0)) src
)
1371 (:temporary
(:sc unsigned-reg
:offset ecx-offset
:from
(:argument
1)) ecx
)
1372 (:temporary
(:sc unsigned-reg
:offset eax-offset
) eax
)
1373 (:temporary
(:sc unsigned-reg
) dst
)
1374 (:results
(result :scs
(descriptor-reg)))
1377 (let ((enter (gen-label))
1380 (stack-allocate-p (node-stack-allocate-p node
)))
1383 ;; Check to see whether there are no args, and just return NIL if so.
1384 (inst mov result nil-value
)
1386 (inst lea dst
(make-ea :dword
:base ecx
:index ecx
))
1387 (maybe-pseudo-atomic stack-allocate-p
1388 (allocation dst dst node stack-allocate-p list-pointer-lowtag
)
1389 ;; Set decrement mode (successive args at lower addresses)
1391 ;; Set up the result.
1393 ;; Jump into the middle of the loop, 'cause that's where we want
1397 ;; Compute a pointer to the next cons.
1398 (inst add dst
(* cons-size n-word-bytes
))
1399 ;; Store a pointer to this cons in the CDR of the previous cons.
1400 (storew dst dst -
1 list-pointer-lowtag
)
1402 ;; Grab one value and stash it in the car of this cons.
1404 (storew eax dst
0 list-pointer-lowtag
)
1405 ;; Go back for more.
1406 (inst sub ecx n-word-bytes
)
1408 ;; NIL out the last cons.
1409 (storew nil-value dst
1 list-pointer-lowtag
)
1411 (emit-label done
))))
1413 ;;; Return the location and size of the &MORE arg glob created by
1414 ;;; COPY-MORE-ARG. SUPPLIED is the total number of arguments supplied
1415 ;;; (originally passed in ECX). FIXED is the number of non-rest
1418 ;;; We must duplicate some of the work done by COPY-MORE-ARG, since at
1419 ;;; that time the environment is in a pretty brain-damaged state,
1420 ;;; preventing this info from being returned as values. What we do is
1421 ;;; compute supplied - fixed, and return a pointer that many words
1422 ;;; below the current stack top.
1423 (define-vop (more-arg-context)
1424 (:policy
:fast-safe
)
1425 (:translate sb
!c
::%more-arg-context
)
1426 (:args
(supplied :scs
(any-reg) :target count
))
1427 (:arg-types positive-fixnum
(:constant fixnum
))
1429 (:results
(context :scs
(descriptor-reg))
1430 (count :scs
(any-reg)))
1431 (:result-types t tagged-num
)
1432 (:note
"more-arg-context")
1434 (move count supplied
)
1435 ;; SP at this point points at the last arg pushed.
1436 ;; Point to the first more-arg, not above it.
1437 (inst lea context
(make-ea :dword
:base esp-tn
1438 :index count
:scale
1
1439 :disp
(- (+ (fixnumize fixed
) n-word-bytes
))))
1440 (unless (zerop fixed
)
1441 (inst sub count
(fixnumize fixed
)))))
1443 ;;; Signal wrong argument count error if NARGS isn't equal to COUNT.
1444 (define-vop (verify-arg-count)
1445 (:policy
:fast-safe
)
1446 (:args
(nargs :scs
(any-reg)))
1447 (:arg-types positive-fixnum
(:constant t
) (:constant t
))
1450 (:save-p
:compute-only
)
1453 (generate-error-code vop
'invalid-arg-count-error nargs
)))
1456 (inst test nargs nargs
)
1457 (inst cmp nargs
(fixnumize max
)))
1458 (inst jmp
:ne err-lab
))
1461 (inst cmp nargs
(fixnumize min
))
1462 (inst jmp
:b err-lab
))
1463 (inst cmp nargs
(fixnumize max
))
1464 (inst jmp
:a err-lab
))
1466 (inst cmp nargs
(fixnumize min
))
1467 (inst jmp
:b err-lab
))))))
1469 ;;; Various other error signallers.
1470 (macrolet ((def (name error translate
&rest args
)
1471 `(define-vop (,name
)
1473 `((:policy
:fast-safe
)
1474 (:translate
,translate
)))
1475 (:args
,@(mapcar (lambda (arg)
1476 `(,arg
:scs
(any-reg descriptor-reg
)))
1479 (:save-p
:compute-only
)
1481 (error-call vop
',error
,@args
)))))
1482 (def arg-count-error invalid-arg-count-error
1483 sb
!c
::%arg-count-error nargs fname
)
1484 (def type-check-error object-not-type-error sb
!c
::%type-check-error
1486 (def layout-invalid-error layout-invalid-error sb
!c
::%layout-invalid-error
1488 (def odd-key-args-error odd-key-args-error
1489 sb
!c
::%odd-key-args-error
)
1490 (def unknown-key-arg-error unknown-key-arg-error
1491 sb
!c
::%unknown-key-arg-error key
)
1492 (def nil-fun-returned-error nil-fun-returned-error nil fun
))
1496 (defun emit-single-step-test ()
1497 ;; We use different ways of representing whether stepping is on on
1498 ;; +SB-THREAD / -SB-THREAD: on +SB-THREAD, we use a slot in the
1499 ;; thread structure. On -SB-THREAD we use the value of a static
1500 ;; symbol. Things are done this way, since reading a thread-local
1501 ;; slot from a symbol would require an extra register on +SB-THREAD,
1502 ;; and reading a slot from a thread structure would require an extra
1503 ;; register on -SB-THREAD.
1506 #!+win32
(inst push eax-tn
)
1507 (with-tls-ea (EA :base
#!+win32 eax-tn
#!-win32
:unused
1508 :disp-type
:constant
1509 :disp
(* thread-stepping-slot n-word-bytes
))
1510 (inst cmp EA nil-value
:maybe-fs
))
1511 #!+win32
(inst pop eax-tn
))
1513 (inst cmp
(make-ea-for-symbol-value sb
!impl
::*stepping
*)
1516 (define-vop (step-instrument-before-vop)
1517 (:policy
:fast-safe
)
1520 (emit-single-step-test)
1522 (inst break single-step-before-trap
)
1524 (note-this-location vop
:step-before-vop
)))