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 (!def-vm-support-routine standard-arg-location (n)
19 (declare (type unsigned-byte n))
20 (if (< n register-arg-count)
21 (make-wired-tn *backend-t-primitive-type* descriptor-reg-sc-number
22 (nth n *register-arg-offsets*))
23 (make-wired-tn *backend-t-primitive-type* control-stack-sc-number n)))
25 ;;; Make a passing location TN for a local call return PC.
27 ;;; Always wire the return PC location to the stack in its standard
29 (!def-vm-support-routine make-return-pc-passing-location (standard)
30 (declare (ignore standard))
31 (make-wired-tn (primitive-type-or-lose 'system-area-pointer)
32 sap-stack-sc-number return-pc-save-offset))
34 ;;; This is similar to MAKE-RETURN-PC-PASSING-LOCATION, but makes a
35 ;;; location to pass OLD-FP in.
37 ;;; This is wired in both the standard and the local-call conventions,
38 ;;; because we want to be able to assume it's always there. Besides,
39 ;;; the x86 doesn't have enough registers to really make it profitable
40 ;;; to pass it in a register.
41 (!def-vm-support-routine make-old-fp-passing-location (standard)
42 (declare (ignore standard))
43 (make-wired-tn *fixnum-primitive-type* control-stack-sc-number
46 ;;; Make the TNs used to hold OLD-FP and RETURN-PC within the current
47 ;;; function. We treat these specially so that the debugger can find
48 ;;; them at a known location.
50 ;;; Without using a save-tn - which does not make much sense if it is
51 ;;; wired to the stack?
52 (!def-vm-support-routine make-old-fp-save-location (physenv)
53 (physenv-debug-live-tn (make-wired-tn *fixnum-primitive-type*
54 control-stack-sc-number
57 (!def-vm-support-routine make-return-pc-save-location (physenv)
58 (physenv-debug-live-tn
59 (make-wired-tn (primitive-type-or-lose 'system-area-pointer)
60 sap-stack-sc-number return-pc-save-offset)
63 ;;; Make a TN for the standard argument count passing location. We only
64 ;;; need to make the standard location, since a count is never passed when we
65 ;;; are using non-standard conventions.
66 (!def-vm-support-routine make-arg-count-location ()
67 (make-wired-tn *fixnum-primitive-type* any-reg-sc-number rcx-offset))
69 ;;; Make a TN to hold the number-stack frame pointer. This is allocated
70 ;;; once per component, and is component-live.
71 (!def-vm-support-routine make-nfp-tn ()
72 (make-restricted-tn *fixnum-primitive-type* ignore-me-sc-number))
74 (!def-vm-support-routine make-stack-pointer-tn ()
75 (make-normal-tn *fixnum-primitive-type*))
77 (!def-vm-support-routine make-number-stack-pointer-tn ()
78 (make-restricted-tn *fixnum-primitive-type* ignore-me-sc-number))
80 ;;; Return a list of TNs that can be used to represent an unknown-values
81 ;;; continuation within a function.
82 (!def-vm-support-routine make-unknown-values-locations ()
83 (list (make-stack-pointer-tn)
84 (make-normal-tn *fixnum-primitive-type*)))
86 ;;; This function is called by the ENTRY-ANALYZE phase, allowing
87 ;;; VM-dependent initialization of the IR2-COMPONENT structure. We
88 ;;; push placeholder entries in the CONSTANTS to leave room for
89 ;;; additional noise in the code object header.
90 (!def-vm-support-routine select-component-format (component)
91 (declare (type component component))
92 (dotimes (i code-constants-offset)
93 (vector-push-extend nil
94 (ir2-component-constants (component-info component))))
99 ;;; This is used for setting up the Old-FP in local call.
100 (define-vop (current-fp)
101 (:results (val :scs (any-reg control-stack)))
105 ;;; We don't have a separate NFP, so we don't need to do anything here.
106 (define-vop (compute-old-nfp)
112 ;;; Accessing a slot from an earlier stack frame is definite hackery.
113 (define-vop (ancestor-frame-ref)
114 (:args (frame-pointer :scs (descriptor-reg))
115 (variable-home-tn :load-if nil))
116 (:results (value :scs (descriptor-reg any-reg)))
119 (aver (sc-is variable-home-tn control-stack))
120 (loadw value frame-pointer
121 (frame-word-offset (tn-offset variable-home-tn)))))
122 (define-vop (ancestor-frame-set)
123 (:args (frame-pointer :scs (descriptor-reg))
124 (value :scs (descriptor-reg any-reg)))
125 (:results (variable-home-tn :load-if nil))
128 (aver (sc-is variable-home-tn control-stack))
129 (storew value frame-pointer
130 (frame-word-offset (tn-offset variable-home-tn)))))
132 (macrolet ((define-frame-op
133 (suffix sc stack-sc instruction
137 :disp (frame-byte-offset
138 (tn-offset variable-home-tn)))))
139 (let ((reffer (symbolicate 'ancestor-frame-ref '/ suffix))
140 (setter (symbolicate 'ancestor-frame-set '/ suffix)))
142 (define-vop (,reffer ancestor-frame-ref)
143 (:results (value :scs (,sc)))
145 (aver (sc-is variable-home-tn ,stack-sc))
146 (inst ,instruction value
148 (define-vop (,setter ancestor-frame-set)
149 (:args (frame-pointer :scs (descriptor-reg))
152 (aver (sc-is variable-home-tn ,stack-sc))
153 (inst ,instruction ,ea value)))))))
154 (define-frame-op double-float double-reg double-stack movsd)
155 (define-frame-op single-float single-reg single-stack movss)
156 (define-frame-op complex-double-float complex-double-reg complex-double-stack
157 movupd (ea-for-cdf-data-stack variable-home-tn frame-pointer))
158 (define-frame-op complex-single-float complex-single-reg complex-single-stack
159 movq (ea-for-csf-data-stack variable-home-tn frame-pointer))
160 (define-frame-op signed-byte-64 signed-reg signed-stack mov)
161 (define-frame-op unsigned-byte-64 unsigned-reg unsigned-stack mov)
162 (define-frame-op system-area-pointer sap-reg sap-stack mov))
164 (defun primitive-type-indirect-cell-type (ptype)
165 (declare (type primitive-type ptype))
166 (macrolet ((foo (&body data)
167 `(case (primitive-type-name ptype)
168 ,@(loop for (name stack-sc ref set) in data
172 (list (primitive-type-or-lose ',name)
173 (sc-or-lose ',stack-sc)
174 (lambda (node block fp value res)
175 (sb!c::vop ,ref node block
177 (lambda (node block fp new-val value)
178 (sb!c::vop ,set node block
179 fp new-val value)))))))))
180 (foo (double-float double-stack
181 ancestor-frame-ref/double-float
182 ancestor-frame-set/double-float)
183 (single-float single-stack
184 ancestor-frame-ref/single-float
185 ancestor-frame-set/single-float)
186 (complex-double-float complex-double-stack
187 ancestor-frame-ref/complex-double-float
188 ancestor-frame-set/complex-double-float)
189 (complex-single-float complex-single-stack
190 ancestor-frame-ref/complex-single-float
191 ancestor-frame-set/complex-single-float)
192 (signed-byte-64 signed-stack
193 ancestor-frame-ref/signed-byte-64
194 ancestor-frame-set/signed-byte-64)
195 (unsigned-byte-64 unsigned-stack
196 ancestor-frame-ref/unsigned-byte-64
197 ancestor-frame-set/unsigned-byte-64)
198 (unsigned-byte-63 unsigned-stack
199 ancestor-frame-ref/unsigned-byte-64
200 ancestor-frame-set/unsigned-byte-64)
201 (system-area-pointer sap-stack
202 ancestor-frame-ref/system-area-pointer
203 ancestor-frame-set/system-area-pointer))))
205 (define-vop (xep-allocate-frame)
206 (:info start-lab copy-more-arg-follows)
209 (emit-alignment n-lowtag-bits)
210 (trace-table-entry trace-table-fun-prologue)
211 (emit-label start-lab)
212 ;; Skip space for the function header.
213 (inst simple-fun-header-word)
214 (dotimes (i (* n-word-bytes (1- simple-fun-code-offset)))
217 ;; The start of the actual code.
218 ;; Save the return-pc.
219 (popw rbp-tn (frame-word-offset return-pc-save-offset))
221 ;; If copy-more-arg follows it will allocate the correct stack
222 ;; size. The stack is not allocated first here as this may expose
223 ;; args on the stack if they take up more space than the frame!
224 (unless copy-more-arg-follows
225 ;; The args fit within the frame so just allocate the frame.
227 (make-ea :qword :base rbp-tn
228 :disp (- (* n-word-bytes
229 (- (max 3 (sb-allocated-size 'stack))
232 (trace-table-entry trace-table-normal)))
234 ;;; This is emitted directly before either a known-call-local, call-local,
235 ;;; or a multiple-call-local. All it does is allocate stack space for the
236 ;;; callee (who has the same size stack as us).
237 (define-vop (allocate-frame)
238 (:results (res :scs (any-reg))
243 (inst lea res (make-ea :qword :base rsp-tn
244 :disp (- (* sp->fp-offset n-word-bytes))))
245 (inst sub rsp-tn (* n-word-bytes (sb-allocated-size 'stack)))))
247 ;;; Allocate a partial frame for passing stack arguments in a full
248 ;;; call. NARGS is the number of arguments passed. We allocate at
249 ;;; least 3 slots, because the XEP noise is going to want to use them
250 ;;; before it can extend the stack.
251 (define-vop (allocate-full-call-frame)
253 (:results (res :scs (any-reg)))
255 (inst lea res (make-ea :qword :base rsp-tn
256 :disp (- (* sp->fp-offset n-word-bytes))))
257 (inst sub rsp-tn (* (max nargs 3) n-word-bytes))))
259 ;;; Emit code needed at the return-point from an unknown-values call
260 ;;; for a fixed number of values. Values is the head of the TN-REF
261 ;;; list for the locations that the values are to be received into.
262 ;;; Nvals is the number of values that are to be received (should
263 ;;; equal the length of Values).
265 ;;; If 0 or 1 values are expected, then we just emit an instruction to
266 ;;; reset the SP (which will only be executed when other than 1 value
269 ;;; In the general case we have to do three things:
270 ;;; -- Default unsupplied register values. This need only be done
271 ;;; when a single value is returned, since register values are
272 ;;; defaulted by the called in the non-single case.
273 ;;; -- Default unsupplied stack values. This needs to be done whenever
274 ;;; there are stack values.
275 ;;; -- Reset SP. This must be done whenever other than 1 value is
276 ;;; returned, regardless of the number of values desired.
277 (defun default-unknown-values (vop values nvals node)
278 (declare (type (or tn-ref null) values)
279 (type unsigned-byte nvals))
280 (let ((type (sb!c::basic-combination-derived-type node)))
283 (note-this-location vop :single-value-return)
285 ((<= (sb!kernel:values-type-max-value-count type)
287 (when (and (named-type-p type)
288 (eq nil (named-type-name type)))
289 ;; The function never returns, it may happen that the code
290 ;; ends right here leavig the :SINGLE-VALUE-RETURN note
291 ;; dangling. Let's emit a NOP.
293 ((not (sb!kernel:values-type-may-be-single-value-p type))
294 (inst mov rsp-tn rbx-tn))
296 (inst cmov :c rsp-tn rbx-tn))))
297 ((<= nvals register-arg-count)
298 (note-this-location vop :unknown-return)
299 (when (sb!kernel:values-type-may-be-single-value-p type)
300 (let ((regs-defaulted (gen-label)))
301 (inst jmp :c regs-defaulted)
302 ;; Default the unsupplied registers.
303 (let* ((2nd-tn-ref (tn-ref-across values))
304 (2nd-tn (tn-ref-tn 2nd-tn-ref)))
305 (inst mov 2nd-tn nil-value)
308 for tn-ref = (tn-ref-across 2nd-tn-ref)
309 then (tn-ref-across tn-ref)
310 for count from 2 below register-arg-count
311 do (inst mov (tn-ref-tn tn-ref) 2nd-tn))))
312 (inst mov rbx-tn rsp-tn)
313 (emit-label regs-defaulted)))
314 (when (< register-arg-count
315 (sb!kernel:values-type-max-value-count type))
316 (inst mov rsp-tn rbx-tn)))
318 ;; The number of bytes depends on the relative jump instructions.
319 ;; Best case is 31+(n-3)*14, worst case is 35+(n-3)*18. For
320 ;; NVALS=6 that is 73/89 bytes, and for NVALS=7 that is 87/107
321 ;; bytes which is likely better than using the blt below.
322 (let ((regs-defaulted (gen-label))
323 (defaulting-done (gen-label))
324 (default-stack-slots (gen-label)))
325 (note-this-location vop :unknown-return)
326 ;; Branch off to the MV case.
327 (inst jmp :c regs-defaulted)
328 ;; Do the single value case.
329 ;; Default the register args
330 (inst mov rax-tn nil-value)
332 (val (tn-ref-across values) (tn-ref-across val)))
333 ((= i (min nvals register-arg-count)))
334 (inst mov (tn-ref-tn val) rax-tn))
335 ;; Fake other registers so it looks like we returned with all the
336 ;; registers filled in.
338 (inst jmp default-stack-slots)
339 (emit-label regs-defaulted)
340 (inst mov rax-tn nil-value)
341 (collect ((defaults))
342 (do ((i register-arg-count (1+ i))
343 (val (do ((i 0 (1+ i))
344 (val values (tn-ref-across val)))
345 ((= i register-arg-count) val))
346 (tn-ref-across val)))
348 (let ((default-lab (gen-label))
350 (first-stack-arg-p (= i register-arg-count)))
351 (defaults (cons default-lab
352 (cons tn first-stack-arg-p)))
353 (inst cmp rcx-tn (fixnumize i))
354 (inst jmp :be default-lab)
355 (when first-stack-arg-p
356 ;; There are stack args so the frame of the callee is
357 ;; still there, save RDX in its first slot temporalily.
358 (storew rdx-tn rbx-tn (frame-word-offset sp->fp-offset)))
359 (loadw rdx-tn rbx-tn (frame-word-offset (+ sp->fp-offset i)))
360 (inst mov tn rdx-tn)))
361 (emit-label defaulting-done)
362 (loadw rdx-tn rbx-tn (frame-word-offset sp->fp-offset))
364 (let ((defaults (defaults)))
366 (assemble (*elsewhere*)
367 (trace-table-entry trace-table-fun-prologue)
368 (emit-label default-stack-slots)
369 (dolist (default defaults)
370 (emit-label (car default))
372 ;; We are setting the first stack argument to NIL.
373 ;; The callee's stack frame is dead, save RDX by
374 ;; pushing it to the stack, it will end up at same
375 ;; place as in the (STOREW RDX-TN RBX-TN -1) case
378 (inst mov (second default) rax-tn))
379 (inst jmp defaulting-done)
380 (trace-table-entry trace-table-normal)))))))
382 (let ((regs-defaulted (gen-label))
383 (restore-edi (gen-label))
384 (no-stack-args (gen-label))
385 (default-stack-vals (gen-label))
386 (count-okay (gen-label)))
387 (note-this-location vop :unknown-return)
388 ;; Branch off to the MV case.
389 (inst jmp :c regs-defaulted)
390 ;; Default the register args, and set up the stack as if we
391 ;; entered the MV return point.
392 (inst mov rbx-tn rsp-tn)
393 (inst mov rdi-tn nil-value)
394 (inst mov rsi-tn rdi-tn)
395 ;; Compute a pointer to where to put the [defaulted] stack values.
396 (emit-label no-stack-args)
400 (make-ea :qword :base rbp-tn
401 :disp (frame-byte-offset register-arg-count)))
402 ;; Load RAX with NIL so we can quickly store it, and set up
403 ;; stuff for the loop.
404 (inst mov rax-tn nil-value)
406 (inst mov rcx-tn (- nvals register-arg-count))
407 ;; Jump into the default loop.
408 (inst jmp default-stack-vals)
409 ;; The regs are defaulted. We need to copy any stack arguments,
410 ;; and then default the remaining stack arguments.
411 (emit-label regs-defaulted)
412 ;; Compute the number of stack arguments, and if it's zero or
413 ;; less, don't copy any stack arguments.
414 (inst sub rcx-tn (fixnumize register-arg-count))
415 (inst jmp :le no-stack-args)
417 (storew rdi-tn rbx-tn (frame-word-offset (+ sp->fp-offset 1)))
418 ;; Throw away any unwanted args.
419 (inst cmp rcx-tn (fixnumize (- nvals register-arg-count)))
420 (inst jmp :be count-okay)
421 (inst mov rcx-tn (fixnumize (- nvals register-arg-count)))
422 (emit-label count-okay)
423 ;; Save the number of stack values.
424 (inst mov rax-tn rcx-tn)
425 ;; Compute a pointer to where the stack args go.
427 (make-ea :qword :base rbp-tn
428 :disp (frame-byte-offset register-arg-count)))
429 ;; Save ESI, and compute a pointer to where the args come from.
430 (storew rsi-tn rbx-tn (frame-word-offset (+ sp->fp-offset 2)))
432 (make-ea :qword :base rbx-tn
433 :disp (frame-byte-offset
434 (+ sp->fp-offset register-arg-count))))
436 (inst shr rcx-tn n-fixnum-tag-bits) ; make word count
441 (loadw rsi-tn rbx-tn (frame-word-offset (+ sp->fp-offset 2)))
442 ;; Now we have to default the remaining args. Find out how many.
443 (inst sub rax-tn (fixnumize (- nvals register-arg-count)))
445 ;; If none, then just blow out of here.
446 (inst jmp :le restore-edi)
447 (inst mov rcx-tn rax-tn)
448 (inst shr rcx-tn n-fixnum-tag-bits) ; word count
449 ;; Load RAX with NIL for fast storing.
450 (inst mov rax-tn nil-value)
452 (emit-label default-stack-vals)
455 ;; Restore EDI, and reset the stack.
456 (emit-label restore-edi)
457 (loadw rdi-tn rbx-tn (frame-word-offset (+ sp->fp-offset 1)))
458 (inst mov rsp-tn rbx-tn)
462 ;;;; unknown values receiving
464 ;;; Emit code needed at the return point for an unknown-values call
465 ;;; for an arbitrary number of values.
467 ;;; We do the single and non-single cases with no shared code: there
468 ;;; doesn't seem to be any potential overlap, and receiving a single
469 ;;; value is more important efficiency-wise.
471 ;;; When there is a single value, we just push it on the stack,
472 ;;; returning the old SP and 1.
474 ;;; When there is a variable number of values, we move all of the
475 ;;; argument registers onto the stack, and return ARGS and NARGS.
477 ;;; ARGS and NARGS are TNs wired to the named locations. We must
478 ;;; explicitly allocate these TNs, since their lifetimes overlap with
479 ;;; the results start and count. (Also, it's nice to be able to target
481 (defun receive-unknown-values (args nargs start count node)
482 (declare (type tn args nargs start count))
483 (let ((type (sb!c::basic-combination-derived-type node))
484 (variable-values (gen-label))
485 (stack-values (gen-label))
487 (when (sb!kernel:values-type-may-be-single-value-p type)
488 (inst jmp :c variable-values)
489 (cond ((location= start (first *register-arg-tns*))
490 (inst push (first *register-arg-tns*))
491 (inst lea start (make-ea :qword :base rsp-tn :disp n-word-bytes)))
492 (t (inst mov start rsp-tn)
493 (inst push (first *register-arg-tns*))))
494 (inst mov count (fixnumize 1))
496 (emit-label variable-values))
497 ;; The stack frame is burnt and RETurned from if there are no
498 ;; stack values. In this case quickly reallocate sufficient space.
499 (when (<= (sb!kernel:values-type-min-value-count type)
501 (inst cmp nargs (fixnumize register-arg-count))
502 (inst jmp :g stack-values)
503 #!+#.(cl:if (cl:= sb!vm:word-shift sb!vm:n-fixnum-tag-bits) '(and) '(or))
504 (inst sub rsp-tn nargs)
505 #!-#.(cl:if (cl:= sb!vm:word-shift sb!vm:n-fixnum-tag-bits) '(and) '(or))
507 ;; FIXME: This can't be efficient, but LEA (my first choice)
508 ;; doesn't do subtraction.
509 (inst shl nargs (- word-shift n-fixnum-tag-bits))
510 (inst sub rsp-tn nargs)
511 (inst shr nargs (- word-shift n-fixnum-tag-bits)))
512 (emit-label stack-values))
513 ;; dtc: this writes the registers onto the stack even if they are
514 ;; not needed, only the number specified in rcx are used and have
515 ;; stack allocated to them. No harm is done.
517 for arg in *register-arg-tns*
519 for j below (sb!kernel:values-type-max-value-count type)
520 do (storew arg args i))
527 ;;; VOP that can be inherited by unknown values receivers. The main thing this
528 ;;; handles is allocation of the result temporaries.
529 (define-vop (unknown-values-receiver)
530 (:temporary (:sc descriptor-reg :offset rbx-offset
531 :from :eval :to (:result 0))
533 (:temporary (:sc any-reg :offset rcx-offset
534 :from :eval :to (:result 1))
536 (:results (start :scs (any-reg control-stack))
537 (count :scs (any-reg control-stack))))
539 ;;;; local call with unknown values convention return
541 (defun check-ocfp-and-return-pc (old-fp return-pc)
543 (format t "*known-return: old-fp ~S, tn-kind ~S; ~S ~S~%"
544 old-fp (sb!c::tn-kind old-fp) (sb!c::tn-save-tn old-fp)
545 (sb!c::tn-kind (sb!c::tn-save-tn old-fp)))
547 (format t "*known-return: return-pc ~S, tn-kind ~S; ~S ~S~%"
548 return-pc (sb!c::tn-kind return-pc)
549 (sb!c::tn-save-tn return-pc)
550 (sb!c::tn-kind (sb!c::tn-save-tn return-pc)))
551 (unless (and (sc-is old-fp control-stack)
552 (= (tn-offset old-fp) ocfp-save-offset))
553 (error "ocfp not on stack in standard save location?"))
554 (unless (and (sc-is return-pc sap-stack)
555 (= (tn-offset return-pc) return-pc-save-offset))
556 (error "return-pc not on stack in standard save location?")))
558 ;;; The local call convention doesn't fit that well with x86-style
559 ;;; calls. Emit a header for local calls to pop the return address
560 ;;; in the right place.
561 (defun emit-block-header (start-label trampoline-label fall-thru-p alignp)
562 (when (and fall-thru-p trampoline-label)
563 (inst jmp start-label))
564 (when trampoline-label
565 (emit-label trampoline-label)
566 (popw rbp-tn (frame-word-offset return-pc-save-offset)))
568 (emit-alignment n-lowtag-bits :long-nop))
569 (emit-label start-label))
571 ;;; Non-TR local call for a fixed number of values passed according to
572 ;;; the unknown values convention.
574 ;;; FP is the frame pointer in install before doing the call.
576 ;;; NFP would be the number-stack frame pointer if we had a separate
579 ;;; Args are the argument passing locations, which are specified only
580 ;;; to terminate their lifetimes in the caller.
582 ;;; VALUES are the return value locations (wired to the standard
583 ;;; passing locations). NVALS is the number of values received.
585 ;;; Save is the save info, which we can ignore since saving has been
588 ;;; TARGET is a continuation pointing to the start of the called
590 (define-vop (call-local)
594 (:results (values :more t))
596 (:move-args :local-call)
597 (:info arg-locs callee target nvals)
599 (:ignore nfp arg-locs args callee)
602 (trace-table-entry trace-table-call-site)
604 (note-this-location vop :call-site)
606 (default-unknown-values vop values nvals node)
607 (trace-table-entry trace-table-normal)))
609 ;;; Non-TR local call for a variable number of return values passed according
610 ;;; to the unknown values convention. The results are the start of the values
611 ;;; glob and the number of values received.
612 (define-vop (multiple-call-local unknown-values-receiver)
617 (:move-args :local-call)
618 (:info save callee target)
619 (:ignore args save nfp callee)
623 (trace-table-entry trace-table-call-site)
625 (note-this-location vop :call-site)
627 (note-this-location vop :unknown-return)
628 (receive-unknown-values values-start nvals start count node)
629 (trace-table-entry trace-table-normal)))
631 ;;;; local call with known values return
633 ;;; Non-TR local call with known return locations. Known-value return
634 ;;; works just like argument passing in local call.
636 ;;; Note: we can't use normal load-tn allocation for the fixed args,
637 ;;; since all registers may be tied up by the more operand. Instead,
638 ;;; we use MAYBE-LOAD-STACK-TN.
639 (define-vop (known-call-local)
643 (:results (res :more t))
644 (:move-args :local-call)
646 (:info save callee target)
647 (:ignore args res save nfp callee)
650 (trace-table-entry trace-table-call-site)
652 (note-this-location vop :call-site)
654 (note-this-location vop :known-return)
655 (trace-table-entry trace-table-normal)))
657 ;;; From Douglas Crosher
658 ;;; Return from known values call. We receive the return locations as
659 ;;; arguments to terminate their lifetimes in the returning function. We
660 ;;; restore FP and CSP and jump to the Return-PC.
661 (define-vop (known-return)
665 (:move-args :known-return)
667 (:ignore val-locs vals)
670 (check-ocfp-and-return-pc old-fp return-pc)
671 (trace-table-entry trace-table-fun-epilogue)
672 ;; Zot all of the stack except for the old-fp and return-pc.
673 (inst mov rsp-tn rbp-tn)
676 (trace-table-entry trace-table-normal)))
680 ;;; There is something of a cross-product effect with full calls.
681 ;;; Different versions are used depending on whether we know the
682 ;;; number of arguments or the name of the called function, and
683 ;;; whether we want fixed values, unknown values, or a tail call.
685 ;;; In full call, the arguments are passed creating a partial frame on
686 ;;; the stack top and storing stack arguments into that frame. On
687 ;;; entry to the callee, this partial frame is pointed to by FP.
689 ;;; This macro helps in the definition of full call VOPs by avoiding
690 ;;; code replication in defining the cross-product VOPs.
692 ;;; NAME is the name of the VOP to define.
694 ;;; NAMED is true if the first argument is an fdefinition object whose
695 ;;; definition is to be called.
697 ;;; RETURN is either :FIXED, :UNKNOWN or :TAIL:
698 ;;; -- If :FIXED, then the call is for a fixed number of values, returned in
699 ;;; the standard passing locations (passed as result operands).
700 ;;; -- If :UNKNOWN, then the result values are pushed on the stack, and the
701 ;;; result values are specified by the Start and Count as in the
702 ;;; unknown-values continuation representation.
703 ;;; -- If :TAIL, then do a tail-recursive call. No values are returned.
704 ;;; The Old-Fp and Return-PC are passed as the second and third arguments.
706 ;;; In non-tail calls, the pointer to the stack arguments is passed as
707 ;;; the last fixed argument. If Variable is false, then the passing
708 ;;; locations are passed as a more arg. Variable is true if there are
709 ;;; a variable number of arguments passed on the stack. Variable
710 ;;; cannot be specified with :TAIL return. TR variable argument call
711 ;;; is implemented separately.
713 ;;; In tail call with fixed arguments, the passing locations are
714 ;;; passed as a more arg, but there is no new-FP, since the arguments
715 ;;; have been set up in the current frame.
716 (macrolet ((define-full-call (name named return variable)
717 (aver (not (and variable (eq return :tail))))
719 ,@(when (eq return :unknown)
720 '(unknown-values-receiver)))
722 ,@(unless (eq return :tail)
723 '((new-fp :scs (any-reg) :to (:argument 1))))
725 (fun :scs (descriptor-reg control-stack)
726 :target rax :to (:argument 0))
728 ,@(when (eq return :tail)
732 ,@(unless variable '((args :more t :scs (descriptor-reg)))))
734 ,@(when (eq return :fixed)
735 '((:results (values :more t))))
737 (:save-p ,(if (eq return :tail) :compute-only t))
739 ,@(unless (or (eq return :tail) variable)
740 '((:move-args :full-call)))
744 ,@(unless (or variable (eq return :tail)) '(arg-locs))
745 ,@(unless variable '(nargs))
746 ,@(when (eq return :fixed) '(nvals))
750 ,@(unless (or variable (eq return :tail)) '(arg-locs))
751 ,@(unless variable '(args)))
753 ;; We pass either the fdefn object (for named call) or
754 ;; the actual function object (for unnamed call) in
755 ;; RAX. With named call, closure-tramp will replace it
756 ;; with the real function and invoke the real function
757 ;; for closures. Non-closures do not need this value,
758 ;; so don't care what shows up in it.
766 ;; We pass the number of arguments in RCX.
767 (:temporary (:sc unsigned-reg :offset rcx-offset :to :eval) rcx)
769 ;; With variable call, we have to load the
770 ;; register-args out of the (new) stack frame before
771 ;; doing the call. Therefore, we have to tell the
772 ;; lifetime stuff that we need to use them.
774 (mapcar (lambda (name offset)
775 `(:temporary (:sc descriptor-reg
780 *register-arg-names* *register-arg-offsets*))
782 ,@(when (eq return :tail)
783 '((:temporary (:sc unsigned-reg
787 ,@(unless (eq return :tail)
790 (:generator ,(+ (if named 5 0)
792 (if (eq return :tail) 0 10)
794 (if (eq return :unknown) 25 0))
795 (trace-table-entry trace-table-call-site)
797 ;; This has to be done before the frame pointer is
798 ;; changed! RAX stores the 'lexical environment' needed
804 ;; For variable call, compute the number of
805 ;; arguments and move some of the arguments to
808 ;; Compute the number of arguments.
809 (noise '(inst mov rcx new-fp))
810 (noise '(inst sub rcx rsp-tn))
811 #.(unless (= word-shift n-fixnum-tag-bits)
812 '(noise '(inst shr rcx
813 (- word-shift n-fixnum-tag-bits))))
814 ;; Move the necessary args to registers,
815 ;; this moves them all even if they are
818 for name in *register-arg-names*
819 for index downfrom -1
820 do (noise `(loadw ,name new-fp ,index)))
824 (inst mov rcx (fixnumize nargs)))))
825 ,@(cond ((eq return :tail)
826 '(;; Python has figured out what frame we should
827 ;; return to so might as well use that clue.
828 ;; This seems really important to the
829 ;; implementation of things like
830 ;; (without-interrupts ...)
832 ;; dtc; Could be doing a tail call from a
833 ;; known-local-call etc in which the old-fp
834 ;; or ret-pc are in regs or in non-standard
835 ;; places. If the passing location were
836 ;; wired to the stack in standard locations
837 ;; then these moves will be un-necessary;
838 ;; this is probably best for the x86.
841 (unless (= ocfp-save-offset
843 ;; FIXME: FORMAT T for stale
844 ;; diagnostic output (several of
845 ;; them around here), ick
846 (error "** tail-call old-fp not S0~%")
847 (move old-fp-tmp old-fp)
850 (frame-word-offset ocfp-save-offset))))
851 ((any-reg descriptor-reg)
852 (error "** tail-call old-fp in reg not S0~%")
855 (frame-word-offset ocfp-save-offset))))
857 ;; For tail call, we have to push the
858 ;; return-pc so that it looks like we CALLed
859 ;; despite the fact that we are going to JMP.
860 (inst push return-pc)
863 ;; For non-tail call, we have to save our
864 ;; frame pointer and install the new frame
865 ;; pointer. We can't load stack tns after this
867 `(;; Python doesn't seem to allocate a frame
868 ;; here which doesn't leave room for the
871 ;; The variable args are on the stack and
872 ;; become the frame, but there may be <3
873 ;; args and 3 stack slots are assumed
874 ;; allocate on the call. So need to ensure
875 ;; there are at least 3 slots. This hack
878 '(inst sub rsp-tn (* 3 n-word-bytes)))
880 ;; Bias the new-fp for use as an fp
882 '(inst sub new-fp (* sp->fp-offset n-word-bytes)))
885 (storew rbp-tn new-fp
886 (frame-word-offset ocfp-save-offset))
888 (move rbp-tn new-fp) ; NB - now on new stack frame.
891 (when step-instrumenting
892 (emit-single-step-test)
894 (inst break single-step-around-trap))
897 (note-this-location vop :call-site)
899 (inst ,(if (eq return :tail) 'jmp 'call)
900 (make-ea :qword :base rax
902 '(- (* fdefn-raw-addr-slot
904 other-pointer-lowtag)
905 '(- (* closure-fun-slot n-word-bytes)
906 fun-pointer-lowtag))))
909 '((default-unknown-values vop values nvals node)))
911 '((note-this-location vop :unknown-return)
912 (receive-unknown-values values-start nvals start count
915 (trace-table-entry trace-table-normal)))))
917 (define-full-call call nil :fixed nil)
918 (define-full-call call-named t :fixed nil)
919 (define-full-call multiple-call nil :unknown nil)
920 (define-full-call multiple-call-named t :unknown nil)
921 (define-full-call tail-call nil :tail nil)
922 (define-full-call tail-call-named t :tail nil)
924 (define-full-call call-variable nil :fixed t)
925 (define-full-call multiple-call-variable nil :unknown t))
927 ;;; This is defined separately, since it needs special code that BLT's
928 ;;; the arguments down. All the real work is done in the assembly
929 ;;; routine. We just set things up so that it can find what it needs.
930 (define-vop (tail-call-variable)
931 (:args (args :scs (any-reg control-stack) :target rsi)
932 (function :scs (descriptor-reg control-stack) :target rax)
935 (:temporary (:sc unsigned-reg :offset rsi-offset :from (:argument 0)) rsi)
936 (:temporary (:sc unsigned-reg :offset rax-offset :from (:argument 1)) rax)
937 (:temporary (:sc unsigned-reg) call-target)
939 (check-ocfp-and-return-pc old-fp return-pc)
940 ;; Move these into the passing locations if they are not already there.
943 ;; And jump to the assembly routine.
944 (inst lea call-target
946 :disp (make-fixup 'tail-call-variable :assembly-routine)))
947 (inst jmp call-target)))
949 ;;;; unknown values return
951 ;;; Return a single-value using the Unknown-Values convention.
953 ;;; pfw--get wired-tn conflicts sometimes if register sc specd for args
954 ;;; having problems targeting args to regs -- using temps instead.
956 ;;; First off, modifying the return-pc defeats the branch-prediction
957 ;;; optimizations on modern CPUs quite handily. Second, we can do all
958 ;;; this without needing a temp register. Fixed the latter, at least.
959 ;;; -- AB 2006/Feb/04
960 (define-vop (return-single)
966 (check-ocfp-and-return-pc old-fp return-pc)
967 (trace-table-entry trace-table-fun-epilogue)
968 ;; Drop stack above old-fp
969 (inst mov rsp-tn rbp-tn)
970 ;; Clear the multiple-value return flag
972 ;; Restore the old frame pointer
977 ;;; Do unknown-values return of a fixed (other than 1) number of
978 ;;; values. The VALUES are required to be set up in the standard
979 ;;; passing locations. NVALS is the number of values returned.
981 ;;; Basically, we just load RCX with the number of values returned and
982 ;;; RBX with a pointer to the values, set RSP to point to the end of
983 ;;; the values, and jump directly to return-pc.
986 (return-pc :to (:eval 1))
990 ;; In the case of other than one value, we need these registers to
991 ;; tell the caller where they are and how many there are.
992 (:temporary (:sc unsigned-reg :offset rbx-offset) rbx)
993 (:temporary (:sc unsigned-reg :offset rcx-offset) rcx)
994 ;; We need to stretch the lifetime of return-pc past the argument
995 ;; registers so that we can default the argument registers without
996 ;; trashing return-pc.
997 (:temporary (:sc unsigned-reg :offset (first *register-arg-offsets*)
999 (:temporary (:sc unsigned-reg :offset (second *register-arg-offsets*)
1001 (:temporary (:sc unsigned-reg :offset (third *register-arg-offsets*)
1005 (check-ocfp-and-return-pc old-fp return-pc)
1007 ;; This is handled in RETURN-SINGLE.
1008 (error "nvalues is 1"))
1009 (trace-table-entry trace-table-fun-epilogue)
1010 ;; Establish the values pointer and values count.
1011 (inst lea rbx (make-ea :qword :base rbp-tn
1012 :disp (* sp->fp-offset n-word-bytes)))
1014 (zeroize rcx) ; smaller
1015 (inst mov rcx (fixnumize nvals)))
1016 ;; Pre-default any argument register that need it.
1017 (when (< nvals register-arg-count)
1018 (let* ((arg-tns (nthcdr nvals (list a0 a1 a2)))
1019 (first (first arg-tns)))
1020 (inst mov first nil-value)
1021 (dolist (tn (cdr arg-tns))
1022 (inst mov tn first))))
1023 ;; Set the multiple value return flag.
1025 ;; And away we go. Except that return-pc is still on the
1026 ;; stack and we've changed the stack pointer. So we have to
1027 ;; tell it to index off of RBX instead of RBP.
1028 (cond ((<= nvals register-arg-count)
1029 (inst mov rsp-tn rbp-tn)
1033 ;; Some values are on the stack after RETURN-PC and OLD-FP,
1034 ;; can't return normally and some slots of the frame will
1035 ;; be used as temporaries by the receiver.
1037 ;; Clear as much of the stack as possible, but not past the
1038 ;; old frame address.
1040 (make-ea :qword :base rbp-tn
1041 :disp (frame-byte-offset (1- nvals))))
1042 (move rbp-tn old-fp)
1043 (inst push (make-ea :qword :base rbx
1044 :disp (frame-byte-offset
1046 (tn-offset return-pc)))))
1049 (trace-table-entry trace-table-normal)))
1051 ;;; Do unknown-values return of an arbitrary number of values (passed
1052 ;;; on the stack.) We check for the common case of a single return
1053 ;;; value, and do that inline using the normal single value return
1054 ;;; convention. Otherwise, we branch off to code that calls an
1055 ;;; assembly-routine.
1057 ;;; The assembly routine takes the following args:
1058 ;;; RCX -- number of values to find there.
1059 ;;; RSI -- pointer to where to find the values.
1060 (define-vop (return-multiple)
1063 (vals :scs (any-reg) :target rsi)
1064 (nvals :scs (any-reg) :target rcx))
1065 (:temporary (:sc unsigned-reg :offset rsi-offset :from (:argument 2)) rsi)
1066 (:temporary (:sc unsigned-reg :offset rcx-offset :from (:argument 3)) rcx)
1067 (:temporary (:sc unsigned-reg) return-asm)
1068 (:temporary (:sc descriptor-reg :offset (first *register-arg-offsets*)
1069 :from (:eval 0)) a0)
1072 (check-ocfp-and-return-pc old-fp return-pc)
1073 (trace-table-entry trace-table-fun-epilogue)
1074 (unless (policy node (> space speed))
1075 ;; Check for the single case.
1076 (let ((not-single (gen-label)))
1077 (inst cmp nvals (fixnumize 1))
1078 (inst jmp :ne not-single)
1079 ;; Return with one value.
1081 ;; Clear the stack until ocfp.
1082 (inst mov rsp-tn rbp-tn)
1083 ;; clear the multiple-value return flag
1088 ;; Nope, not the single case. Jump to the assembly routine.
1089 (emit-label not-single)))
1092 (inst lea return-asm
1093 (make-ea :qword :disp (make-fixup 'return-multiple
1094 :assembly-routine)))
1095 (inst jmp return-asm)
1096 (trace-table-entry trace-table-normal)))
1100 ;;; We don't need to do anything special for regular functions.
1101 (define-vop (setup-environment)
1105 ;; Don't bother doing anything.
1108 ;;; Get the lexical environment from its passing location.
1109 (define-vop (setup-closure-environment)
1110 (:results (closure :scs (descriptor-reg)))
1115 (move closure rax-tn)))
1117 ;;; Copy a &MORE arg from the argument area to the end of the current
1118 ;;; frame. FIXED is the number of non-&MORE arguments.
1119 (define-vop (copy-more-arg)
1120 (:temporary (:sc any-reg :offset r8-offset) copy-index)
1121 (:temporary (:sc any-reg :offset r9-offset) source)
1122 (:temporary (:sc descriptor-reg :offset r10-offset) temp)
1125 ;; Avoid the copy if there are no more args.
1126 (cond ((zerop fixed)
1127 (inst jrcxz JUST-ALLOC-FRAME))
1129 (inst cmp rcx-tn (fixnumize fixed))
1130 (inst jmp :be JUST-ALLOC-FRAME)))
1132 ;; Create a negated copy of the number of arguments to allow us to
1133 ;; use EA calculations in order to do scaled subtraction.
1134 (inst mov temp rcx-tn)
1137 ;; Allocate the space on the stack.
1138 ;; stack = rbp + sp->fp-offset - (max 3 frame-size) - (nargs - fixed)
1140 (make-ea :qword :base rbp-tn
1141 :index temp :scale (ash 1 (- word-shift n-fixnum-tag-bits))
1142 :disp (* n-word-bytes
1143 (- (+ sp->fp-offset fixed)
1144 (max 3 (sb-allocated-size 'stack))))))
1146 ;; Now: nargs>=1 && nargs>fixed
1148 ;; Save the original count of args.
1149 (inst mov rbx-tn rcx-tn)
1151 (cond ((< fixed register-arg-count)
1152 ;; We must stop when we run out of stack args, not when we
1153 ;; run out of more args.
1154 ;; Number to copy = nargs-3
1155 (inst sub rcx-tn (fixnumize register-arg-count))
1156 ;; Everything of interest in registers.
1157 (inst jmp :be DO-REGS))
1159 ;; Number to copy = nargs-fixed
1160 (inst sub rcx-tn (fixnumize fixed))))
1162 ;; Initialize R8 to be the end of args.
1163 (inst lea source (make-ea :qword :base rbp-tn
1164 :index temp :scale (ash 1 (- word-shift n-fixnum-tag-bits))
1165 :disp (* sp->fp-offset n-word-bytes)))
1167 ;; We need to copy from downwards up to avoid overwriting some of
1168 ;; the yet uncopied args. So we need to use R9 as the copy index
1169 ;; and RCX as the loop counter, rather than using RCX for both.
1170 (zeroize copy-index)
1172 ;; We used to use REP MOVS here, but on modern x86 it performs
1173 ;; much worse than an explicit loop for small blocks.
1175 (inst mov temp (make-ea :qword :base source :index copy-index))
1176 (inst mov (make-ea :qword :base rsp-tn :index copy-index) temp)
1177 (inst add copy-index n-word-bytes)
1178 (inst sub rcx-tn (fixnumize 1))
1179 (inst jmp :nz COPY-LOOP)
1184 (inst mov rcx-tn rbx-tn)
1186 ;; Here: nargs>=1 && nargs>fixed
1187 (when (< fixed register-arg-count)
1188 ;; Now we have to deposit any more args that showed up in
1192 ;; Store it relative to rbp
1193 (inst mov (make-ea :qword :base rbp-tn
1194 :disp (* n-word-bytes
1198 (max 3 (sb-allocated-size
1200 (nth i *register-arg-tns*))
1203 (when (>= i register-arg-count)
1206 ;; Don't deposit any more than there are.
1208 (inst test rcx-tn rcx-tn)
1209 (inst cmp rcx-tn (fixnumize i)))
1210 (inst jmp :eq DONE)))
1216 (make-ea :qword :base rbp-tn
1217 :disp (* n-word-bytes
1219 (max 3 (sb-allocated-size 'stack))))))
1223 (define-vop (more-kw-arg)
1224 (:translate sb!c::%more-kw-arg)
1225 (:policy :fast-safe)
1226 (:args (object :scs (descriptor-reg) :to (:result 1))
1227 (index :scs (any-reg) :to (:result 1) :target keyword))
1228 (:arg-types * tagged-num)
1229 (:results (value :scs (descriptor-reg any-reg))
1230 (keyword :scs (descriptor-reg any-reg)))
1233 (inst mov value (make-ea :qword :base object :index index
1234 :scale (ash 1 (- word-shift n-fixnum-tag-bits))))
1235 (inst mov keyword (make-ea :qword :base object :index index
1236 :scale (ash 1 (- word-shift n-fixnum-tag-bits))
1237 :disp n-word-bytes))))
1239 (define-vop (more-arg)
1240 (:translate sb!c::%more-arg)
1241 (:policy :fast-safe)
1242 (:args (object :scs (descriptor-reg) :to (:result 1))
1243 (index :scs (any-reg) :to (:result 1) :target value))
1244 (:arg-types * tagged-num)
1245 (:results (value :scs (descriptor-reg any-reg)))
1250 (inst mov value (make-ea :qword :base object :index value
1251 :scale (ash 1 (- word-shift n-fixnum-tag-bits))))))
1253 ;;; Turn more arg (context, count) into a list.
1254 (define-vop (listify-rest-args)
1255 (:translate %listify-rest-args)
1257 (:args (context :scs (descriptor-reg) :target src)
1258 (count :scs (any-reg) :target rcx))
1259 (:arg-types * tagged-num)
1260 (:temporary (:sc unsigned-reg :offset rsi-offset :from (:argument 0)) src)
1261 (:temporary (:sc unsigned-reg :offset rcx-offset :from (:argument 1)) rcx)
1262 (:temporary (:sc unsigned-reg :offset rax-offset) rax)
1263 (:temporary (:sc unsigned-reg) dst)
1264 (:results (result :scs (descriptor-reg)))
1267 (let ((enter (gen-label))
1270 (stack-allocate-p (node-stack-allocate-p node)))
1273 ;; Check to see whether there are no args, and just return NIL if so.
1274 (inst mov result nil-value)
1276 (inst lea dst (make-ea :qword :index rcx :scale (ash 2 (- word-shift n-fixnum-tag-bits))))
1277 (maybe-pseudo-atomic stack-allocate-p
1278 (allocation dst dst node stack-allocate-p list-pointer-lowtag)
1279 ;; Set decrement mode (successive args at lower addresses)
1281 ;; Set up the result.
1283 ;; Jump into the middle of the loop, 'cause that's where we want
1287 ;; Compute a pointer to the next cons.
1288 (inst add dst (* cons-size n-word-bytes))
1289 ;; Store a pointer to this cons in the CDR of the previous cons.
1290 (storew dst dst -1 list-pointer-lowtag)
1292 ;; Grab one value and stash it in the car of this cons.
1293 (inst mov rax (make-ea :qword :base src))
1294 (inst sub src n-word-bytes)
1295 (storew rax dst 0 list-pointer-lowtag)
1296 ;; Go back for more.
1297 (inst sub rcx (fixnumize 1))
1299 ;; NIL out the last cons.
1300 (storew nil-value dst 1 list-pointer-lowtag)
1302 (emit-label done))))
1304 ;;; Return the location and size of the &MORE arg glob created by
1305 ;;; COPY-MORE-ARG. SUPPLIED is the total number of arguments supplied
1306 ;;; (originally passed in RCX). FIXED is the number of non-rest
1309 ;;; We must duplicate some of the work done by COPY-MORE-ARG, since at
1310 ;;; that time the environment is in a pretty brain-damaged state,
1311 ;;; preventing this info from being returned as values. What we do is
1312 ;;; compute supplied - fixed, and return a pointer that many words
1313 ;;; below the current stack top.
1314 (define-vop (more-arg-context)
1315 (:policy :fast-safe)
1316 (:translate sb!c::%more-arg-context)
1317 (:args (supplied :scs (any-reg) :target count))
1318 (:arg-types positive-fixnum (:constant fixnum))
1320 (:results (context :scs (descriptor-reg))
1321 (count :scs (any-reg)))
1322 (:result-types t tagged-num)
1323 (:note "more-arg-context")
1325 (move count supplied)
1326 ;; SP at this point points at the last arg pushed.
1327 ;; Point to the first more-arg, not above it.
1328 (inst lea context (make-ea :qword :base rsp-tn
1330 :scale (ash 1 (- word-shift n-fixnum-tag-bits))
1331 :disp (- (* (1+ fixed) n-word-bytes))))
1332 (unless (zerop fixed)
1333 (inst sub count (fixnumize fixed)))))
1335 ;;; Signal wrong argument count error if NARGS isn't equal to COUNT.
1336 (define-vop (verify-arg-count)
1337 (:policy :fast-safe)
1338 (:translate sb!c::%verify-arg-count)
1339 (:args (nargs :scs (any-reg)))
1340 (:arg-types positive-fixnum (:constant t))
1343 (:save-p :compute-only)
1346 (generate-error-code vop 'invalid-arg-count-error nargs)))
1348 (inst test nargs nargs) ; smaller instruction
1349 (inst cmp nargs (fixnumize count)))
1350 (inst jmp :ne err-lab))))
1352 ;;; Various other error signallers.
1353 (macrolet ((def (name error translate &rest args)
1354 `(define-vop (,name)
1356 `((:policy :fast-safe)
1357 (:translate ,translate)))
1358 (:args ,@(mapcar (lambda (arg)
1359 `(,arg :scs (any-reg descriptor-reg)))
1362 (:save-p :compute-only)
1364 (error-call vop ',error ,@args)))))
1365 (def arg-count-error invalid-arg-count-error
1366 sb!c::%arg-count-error nargs)
1367 (def type-check-error object-not-type-error sb!c::%type-check-error
1369 (def layout-invalid-error layout-invalid-error sb!c::%layout-invalid-error
1371 (def odd-key-args-error odd-key-args-error
1372 sb!c::%odd-key-args-error)
1373 (def unknown-key-arg-error unknown-key-arg-error
1374 sb!c::%unknown-key-arg-error key)
1375 (def nil-fun-returned-error nil-fun-returned-error nil fun))
1379 (defun emit-single-step-test ()
1380 ;; We use different ways of representing whether stepping is on on
1381 ;; +SB-THREAD / -SB-THREAD: on +SB-THREAD, we use a slot in the
1382 ;; thread structure. On -SB-THREAD we use the value of a static
1383 ;; symbol. Things are done this way, since reading a thread-local
1384 ;; slot from a symbol would require an extra register on +SB-THREAD,
1385 ;; and reading a slot from a thread structure would require an extra
1386 ;; register on -SB-THREAD. While this isn't critical for x86-64,
1387 ;; it's more serious for x86.
1389 (inst cmp (make-ea :qword
1390 :base thread-base-tn
1391 :disp (* thread-stepping-slot n-word-bytes))
1394 (inst cmp (make-ea :qword
1395 :disp (+ nil-value (static-symbol-offset
1396 'sb!impl::*stepping*)
1397 (* symbol-value-slot n-word-bytes)
1398 (- other-pointer-lowtag)))
1401 (define-vop (step-instrument-before-vop)
1402 (:policy :fast-safe)
1405 (emit-single-step-test)
1407 (inst break single-step-before-trap)
1409 (note-this-location vop :step-before-vop)))