1.0.16.10: function-ify ERROR-CALL and GENERATE-ERROR-CODE on x86
[sbcl.git] / src / compiler / x86 / macros.lisp
1 ;;;; a bunch of handy macros for the x86
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
11
12 (in-package "SB!VM")
13
14 ;;; We can load/store into fp registers through the top of stack
15 ;;; %st(0) (fr0 here). Loads imply a push to an empty register which
16 ;;; then changes all the reg numbers. These macros help manage that.
17
18 ;;; Use this when we don't have to load anything. It preserves old tos
19 ;;; value, but probably destroys tn with operation.
20 (defmacro with-tn@fp-top((tn) &body body)
21   `(progn
22     (unless (zerop (tn-offset ,tn))
23       (inst fxch ,tn))
24     ,@body
25     (unless (zerop (tn-offset ,tn))
26       (inst fxch ,tn))))
27
28 ;;; Use this to prepare for load of new value from memory. This
29 ;;; changes the register numbering so the next instruction had better
30 ;;; be a FP load from memory; a register load from another register
31 ;;; will probably be loading the wrong register!
32 (defmacro with-empty-tn@fp-top((tn) &body body)
33   `(progn
34     (inst fstp ,tn)
35     ,@body
36     (unless (zerop (tn-offset ,tn))
37       (inst fxch ,tn))))                ; save into new dest and restore st(0)
38 \f
39 ;;;; instruction-like macros
40
41 (defmacro move (dst src)
42   #!+sb-doc
43   "Move SRC into DST unless they are location=."
44   (once-only ((n-dst dst)
45               (n-src src))
46     `(unless (location= ,n-dst ,n-src)
47        (inst mov ,n-dst ,n-src))))
48
49 (defmacro align-stack-pointer (tn)
50   #!-darwin (declare (ignore tn))
51   #!+darwin
52   ;; 16 byte alignment.
53   `(inst and ,tn #xfffffff0))
54
55 (defmacro make-ea-for-object-slot (ptr slot lowtag &optional (size :dword))
56   `(make-ea ,size :base ,ptr :disp (- (* ,slot n-word-bytes) ,lowtag)))
57
58 (defmacro loadw (value ptr &optional (slot 0) (lowtag 0))
59   `(inst mov ,value (make-ea-for-object-slot ,ptr ,slot ,lowtag)))
60
61 (defmacro storew (value ptr &optional (slot 0) (lowtag 0))
62   (once-only ((value value))
63     `(inst mov (make-ea-for-object-slot ,ptr ,slot ,lowtag) ,value)))
64
65 ;;; A handy macro for storing widetags.
66 (defmacro storeb (value ptr &optional (slot 0) (lowtag 0))
67   (once-only ((value value))
68     `(inst mov (make-ea-for-object-slot ,ptr ,slot ,lowtag :byte) ,value)))
69
70 (defmacro pushw (ptr &optional (slot 0) (lowtag 0))
71   `(inst push (make-ea-for-object-slot ,ptr ,slot ,lowtag)))
72
73 (defmacro popw (ptr &optional (slot 0) (lowtag 0))
74   `(inst pop (make-ea-for-object-slot ,ptr ,slot ,lowtag)))
75
76 (defmacro make-ea-for-vector-data (object &key (size :dword) (offset 0)
77                                    index (scale (ash (width-bits size) -3)))
78   `(make-ea ,size :base ,object :index ,index :scale ,scale
79             :disp (- (+ (* vector-data-offset n-word-bytes)
80                         (* ,offset ,scale))
81                      other-pointer-lowtag)))
82 \f
83 ;;;; macros to generate useful values
84
85 (defmacro load-symbol (reg symbol)
86   `(inst mov ,reg (+ nil-value (static-symbol-offset ,symbol))))
87
88 (defmacro make-ea-for-symbol-value (symbol &optional (width :dword))
89   (declare (type symbol symbol))
90   `(make-ea ,width
91     :disp (+ nil-value
92            (static-symbol-offset ',symbol)
93            (ash symbol-value-slot word-shift)
94            (- other-pointer-lowtag))))
95
96 (defmacro load-symbol-value (reg symbol)
97   `(inst mov ,reg (make-ea-for-symbol-value ,symbol)))
98
99 (defmacro store-symbol-value (reg symbol)
100   `(inst mov (make-ea-for-symbol-value ,symbol) ,reg))
101
102 #!+sb-thread
103 (defmacro make-ea-for-symbol-tls-index (symbol)
104   (declare (type symbol symbol))
105   `(make-ea :dword
106     :disp (+ nil-value
107            (static-symbol-offset ',symbol)
108            (ash symbol-tls-index-slot word-shift)
109            (- other-pointer-lowtag))))
110
111 #!+sb-thread
112 (defmacro load-tl-symbol-value (reg symbol)
113   `(progn
114     (inst mov ,reg (make-ea-for-symbol-tls-index ,symbol))
115     (inst fs-segment-prefix)
116     (inst mov ,reg (make-ea :dword :base ,reg))))
117 #!-sb-thread
118 (defmacro load-tl-symbol-value (reg symbol) `(load-symbol-value ,reg ,symbol))
119
120 #!+sb-thread
121 (defmacro store-tl-symbol-value (reg symbol temp)
122   `(progn
123     (inst mov ,temp (make-ea-for-symbol-tls-index ,symbol))
124     (inst fs-segment-prefix)
125     (inst mov (make-ea :dword :base ,temp) ,reg)))
126 #!-sb-thread
127 (defmacro store-tl-symbol-value (reg symbol temp)
128   (declare (ignore temp))
129   `(store-symbol-value ,reg ,symbol))
130
131 (defmacro load-binding-stack-pointer (reg)
132   #!+sb-thread
133   `(progn
134      (inst fs-segment-prefix)
135      (inst mov ,reg (make-ea :dword
136                              :disp (* 4 thread-binding-stack-pointer-slot))))
137   #!-sb-thread
138   `(load-symbol-value ,reg *binding-stack-pointer*))
139
140 (defmacro store-binding-stack-pointer (reg)
141   #!+sb-thread
142   `(progn
143      (inst fs-segment-prefix)
144      (inst mov (make-ea :dword
145                         :disp (* 4 thread-binding-stack-pointer-slot))
146            ,reg))
147   #!-sb-thread
148   `(store-symbol-value ,reg *binding-stack-pointer*))
149
150 (defmacro load-type (target source &optional (offset 0))
151   #!+sb-doc
152   "Loads the type bits of a pointer into target independent of
153    byte-ordering issues."
154   (once-only ((n-target target)
155               (n-source source)
156               (n-offset offset))
157     (ecase *backend-byte-order*
158       (:little-endian
159        `(inst mov ,n-target
160               (make-ea :byte :base ,n-source :disp ,n-offset)))
161       (:big-endian
162        `(inst mov ,n-target
163               (make-ea :byte :base ,n-source
164                              :disp (+ ,n-offset (1- n-word-bytes))))))))
165 \f
166 ;;;; allocation helpers
167
168 ;;; Allocation within alloc_region (which is thread local) can be done
169 ;;; inline.  If the alloc_region is overflown allocation is done by
170 ;;; calling the C alloc() function.
171
172 ;;; C calls for allocation don't /seem/ to make an awful lot of
173 ;;; difference to speed. On pure consing it's about a 25%
174 ;;; gain. Guessing from historical context, it looks like inline
175 ;;; allocation was introduced before pseudo-atomic, at which time all
176 ;;; calls to alloc() would have needed a syscall to mask signals for
177 ;;; the duration.  Now we have pseudoatomic there's no need for that
178 ;;; overhead.
179
180 (defun allocation-dynamic-extent (alloc-tn size)
181   (inst sub esp-tn size)
182   ;; FIXME: SIZE _should_ be double-word aligned (suggested but
183   ;; unfortunately not enforced by PAD-DATA-BLOCK and
184   ;; WITH-FIXED-ALLOCATION), so that ESP is always divisible by 8 (for
185   ;; 32-bit lispobjs).  In that case, this AND instruction is
186   ;; unneccessary and could be removed.  If not, explain why.  -- CSR,
187   ;; 2004-03-30
188   (inst and esp-tn (lognot lowtag-mask))
189   (aver (not (location= alloc-tn esp-tn)))
190   (inst mov alloc-tn esp-tn)
191   (values))
192
193 (defun allocation-notinline (alloc-tn size)
194   (let* ((alloc-tn-offset (tn-offset alloc-tn))
195          ;; C call to allocate via dispatch routines. Each
196          ;; destination has a special entry point. The size may be a
197          ;; register or a constant.
198          (tn-text (ecase alloc-tn-offset
199                     (#.eax-offset "eax")
200                     (#.ecx-offset "ecx")
201                     (#.edx-offset "edx")
202                     (#.ebx-offset "ebx")
203                     (#.esi-offset "esi")
204                     (#.edi-offset "edi")))
205          (size-text (case size (8 "8_") (16 "16_") (t ""))))
206     (unless (or (eql size 8) (eql size 16))
207       (unless (and (tn-p size) (location= alloc-tn size))
208         (inst mov alloc-tn size)))
209     (inst call (make-fixup (concatenate 'string
210                                          "alloc_" size-text
211                                          "to_" tn-text)
212                            :foreign))))
213
214 (defun allocation-inline (alloc-tn size)
215   (let ((ok (gen-label))
216         (done (gen-label))
217         (free-pointer
218          (make-ea :dword :disp
219                   #!+sb-thread (* n-word-bytes thread-alloc-region-slot)
220                   #!-sb-thread (make-fixup "boxed_region" :foreign)
221                   :scale 1)) ; thread->alloc_region.free_pointer
222         (end-addr
223          (make-ea :dword :disp
224                   #!+sb-thread (* n-word-bytes (1+ thread-alloc-region-slot))
225                   #!-sb-thread (make-fixup "boxed_region" :foreign 4)
226                   :scale 1)))   ; thread->alloc_region.end_addr
227     (unless (and (tn-p size) (location= alloc-tn size))
228       (inst mov alloc-tn size))
229     #!+sb-thread (inst fs-segment-prefix)
230     (inst add alloc-tn free-pointer)
231     #!+sb-thread (inst fs-segment-prefix)
232     (inst cmp alloc-tn end-addr)
233     (inst jmp :be ok)
234     (let ((dst (ecase (tn-offset alloc-tn)
235                  (#.eax-offset "alloc_overflow_eax")
236                  (#.ecx-offset "alloc_overflow_ecx")
237                  (#.edx-offset "alloc_overflow_edx")
238                  (#.ebx-offset "alloc_overflow_ebx")
239                  (#.esi-offset "alloc_overflow_esi")
240                  (#.edi-offset "alloc_overflow_edi"))))
241       (inst call (make-fixup dst :foreign)))
242     (inst jmp-short done)
243     (emit-label ok)
244     ;; Swap ALLOC-TN and FREE-POINTER
245     (cond ((and (tn-p size) (location= alloc-tn size))
246            ;; XCHG is extremely slow, use the xor swap trick
247            #!+sb-thread (inst fs-segment-prefix)
248            (inst xor alloc-tn free-pointer)
249            #!+sb-thread (inst fs-segment-prefix)
250            (inst xor free-pointer alloc-tn)
251            #!+sb-thread (inst fs-segment-prefix)
252            (inst xor alloc-tn free-pointer))
253           (t
254            ;; It's easier if SIZE is still available.
255            #!+sb-thread (inst fs-segment-prefix)
256            (inst mov free-pointer alloc-tn)
257            (inst sub alloc-tn size)))
258     (emit-label done))
259   (values))
260
261
262 ;;; Emit code to allocate an object with a size in bytes given by
263 ;;; SIZE.  The size may be an integer or a TN. If Inline is a VOP
264 ;;; node-var then it is used to make an appropriate speed vs size
265 ;;; decision.
266
267 ;;; Allocation should only be used inside a pseudo-atomic section, which
268 ;;; should also cover subsequent initialization of the object.
269
270 ;;; (FIXME: so why aren't we asserting this?)
271
272 (defun allocation (alloc-tn size &optional inline dynamic-extent)
273   (cond
274     (dynamic-extent (allocation-dynamic-extent alloc-tn size))
275     ((or (null inline) (policy inline (>= speed space)))
276      (allocation-inline alloc-tn size))
277     (t (allocation-notinline alloc-tn size)))
278   (values))
279
280 ;;; Allocate an other-pointer object of fixed SIZE with a single word
281 ;;; header having the specified WIDETAG value. The result is placed in
282 ;;; RESULT-TN.
283 (defmacro with-fixed-allocation ((result-tn widetag size &optional inline stack-allocate-p)
284                                  &body forms)
285   (unless forms
286     (bug "empty &body in WITH-FIXED-ALLOCATION"))
287   (once-only ((result-tn result-tn) (size size) (stack-allocate-p stack-allocate-p))
288     `(maybe-pseudo-atomic ,stack-allocate-p
289       (allocation ,result-tn (pad-data-block ,size) ,inline ,stack-allocate-p)
290       (storew (logior (ash (1- ,size) n-widetag-bits) ,widetag)
291               ,result-tn)
292       (inst lea ,result-tn
293             (make-ea :byte :base ,result-tn :disp other-pointer-lowtag))
294       ,@forms)))
295 \f
296 ;;;; error code
297 (defun emit-error-break (vop kind code values)
298   (assemble ()
299     #-darwin
300     (inst int 3)                        ; i386 breakpoint instruction
301     ;; CLH 20060314
302     ;; On Darwin, we need to use #x0b0f instead of int3 in order
303     ;; to generate a SIGILL instead of a SIGTRAP as darwin/x86
304     ;; doesn't seem to be reliably firing SIGTRAP
305     ;; handlers. Hopefully this will be fixed by Apple at a
306     ;; later date.
307     #+darwin
308     (inst word #x0b0f)
309     (when vop
310       (note-this-location vop :internal-error))
311     (inst byte kind)                    ; e.g. trap_xyyy
312     (with-adjustable-vector (vector)    ; interr arguments
313       (write-var-integer code vector)
314       (dolist (tn values)
315         (write-var-integer (make-sc-offset (sc-number (tn-sc tn))
316                                            (or (tn-offset tn) 0))
317                            vector))
318       (inst byte (length vector))
319       (dotimes (i (length vector))
320         (inst byte (aref vector i))))))
321
322 #+nil
323 (eval-when (#-sb-xc :compile-toplevel :load-toplevel :execute)
324   (defun emit-error-break (vop kind code values)
325     (let ((vector (gensym)))
326       `((progn
327           #-darwin (inst int 3)         ; i386 breakpoint instruction
328           ;; CLH 20060314
329           ;; On Darwin, we need to use #x0b0f instead of int3 in order
330           ;; to generate a SIGILL instead of a SIGTRAP as darwin/x86
331           ;; doesn't seem to be reliably firing SIGTRAP
332           ;; handlers. Hopefully this will be fixed by Apple at a
333           ;; later date.
334           #+darwin (inst word #x0b0f))
335         ;; The return PC points here; note the location for the debugger.
336         (let ((vop ,vop))
337           (when vop
338                 (note-this-location vop :internal-error)))
339         (inst byte ,kind)                       ; eg trap_Xyyy
340         (with-adjustable-vector (,vector)       ; interr arguments
341           (write-var-integer (error-number-or-lose ',code) ,vector)
342           ,@(mapcar (lambda (tn)
343                       `(let ((tn ,tn))
344                          ;; classic CMU CL comment:
345                          ;;   zzzzz jrd here. tn-offset is zero for constant
346                          ;;   tns.
347                          (write-var-integer (make-sc-offset (sc-number
348                                                              (tn-sc tn))
349                                                             (or (tn-offset tn)
350                                                                 0))
351                                             ,vector)))
352                     values)
353           (inst byte (length ,vector))
354           (dotimes (i (length ,vector))
355             (inst byte (aref ,vector i))))))))
356
357 (defun error-call (vop error-code &rest values)
358   #!+sb-doc
359   "Cause an error. ERROR-CODE is the error to cause."
360   (emit-error-break vop error-trap (error-number-or-lose error-code) values))
361
362 (defun generate-error-code (vop error-code &rest values)
363   #!+sb-doc
364   "Generate-Error-Code Error-code Value*
365   Emit code for an error with the specified Error-Code and context Values."
366   (assemble (*elsewhere*)
367     (let ((start-lab (gen-label)))
368       (emit-label start-lab)
369       (emit-error-break vop error-trap (error-number-or-lose error-code) values)
370       start-lab)))
371
372 \f
373 ;;;; PSEUDO-ATOMIC
374
375 ;;; This is used to wrap operations which leave untagged memory lying
376 ;;; around.  It's an operation which the AOP weenies would describe as
377 ;;; having "cross-cutting concerns", meaning it appears all over the
378 ;;; place and there's no logical single place to attach documentation.
379 ;;; grep (mostly in src/runtime) is your friend
380
381 ;;; KLUDGE: since the stack on the x86 is treated conservatively, it
382 ;;; does not matter whether a signal occurs during construction of a
383 ;;; dynamic-extent object, as the half-finished construction of the
384 ;;; object will not cause any difficulty.  We can therefore elide
385 (defmacro maybe-pseudo-atomic (really-p &body forms)
386   `(if ,really-p
387        (progn ,@forms)
388        (pseudo-atomic ,@forms)))
389
390 #!+sb-thread
391 (defmacro pseudo-atomic (&rest forms)
392   (with-unique-names (label)
393     `(let ((,label (gen-label)))
394        (inst fs-segment-prefix)
395        (inst or (make-ea :byte :disp (* 4 thread-pseudo-atomic-bits-slot))
396             (fixnumize 1))
397        ,@forms
398        (inst fs-segment-prefix)
399        (inst xor (make-ea :byte :disp (* 4 thread-pseudo-atomic-bits-slot))
400              (fixnumize 1))
401        (inst jmp :z ,label)
402        ;; if PAI was set, interrupts were disabled at the same
403        ;; time using the process signal mask.
404        (inst break pending-interrupt-trap)
405        (emit-label ,label))))
406
407 #!-sb-thread
408 (defmacro pseudo-atomic (&rest forms)
409   (with-unique-names (label)
410     `(let ((,label (gen-label)))
411        (inst or (make-ea-for-symbol-value *pseudo-atomic-bits* :byte)
412              (fixnumize 1))
413        ,@forms
414        (inst xor (make-ea-for-symbol-value *pseudo-atomic-bits* :byte)
415              (fixnumize 1))
416        (inst jmp :z ,label)
417        ;; if PAI was set, interrupts were disabled at the same
418        ;; time using the process signal mask.
419        (inst break pending-interrupt-trap)
420        (emit-label ,label))))
421 \f
422 ;;;; indexed references
423
424 (defmacro define-full-compare-and-swap
425     (name type offset lowtag scs el-type &optional translate)
426   `(progn
427      (define-vop (,name)
428          ,@(when translate `((:translate ,translate)))
429        (:policy :fast-safe)
430        (:args (object :scs (descriptor-reg) :to :eval)
431               (index :scs (any-reg immediate unsigned-reg) :to :result)
432               (old-value :scs ,scs :target eax)
433               (new-value :scs ,scs))
434        (:arg-types ,type tagged-num ,el-type ,el-type)
435        (:temporary (:sc descriptor-reg :offset eax-offset
436                         :from (:argument 2) :to :result :target value)  eax)
437        (:results (value :scs ,scs))
438        (:result-types ,el-type)
439        (:generator 5
440          (move eax old-value)
441          #!+sb-thread
442          (inst lock)
443          (let ((ea (sc-case index
444                      (immediate
445                       (make-ea :dword :base object
446                                :disp (- (* (+ ,offset (tn-value index))
447                                            n-word-bytes)
448                                         ,lowtag)))
449                      (unsigned-reg
450                       (make-ea :dword :base object :index index :scale 4
451                                :disp (- (* ,offset n-word-bytes)
452                                         ,lowtag)))
453                      (t
454                       (make-ea :dword :base object :index index
455                                :disp (- (* ,offset n-word-bytes)
456                                         ,lowtag))))))
457            (inst cmpxchg ea new-value))
458          (move value eax)))))
459
460 (defmacro define-full-reffer (name type offset lowtag scs el-type &optional translate)
461   `(progn
462      (define-vop (,name)
463        ,@(when translate
464            `((:translate ,translate)))
465        (:policy :fast-safe)
466        (:args (object :scs (descriptor-reg))
467               (index :scs (any-reg immediate unsigned-reg)))
468        (:arg-types ,type tagged-num)
469        (:results (value :scs ,scs))
470        (:result-types ,el-type)
471        (:generator 3                    ; pw was 5
472          (sc-case index
473            (immediate
474             (inst mov value (make-ea :dword :base object
475                                      :disp (- (* (+ ,offset (tn-value index))
476                                                  n-word-bytes)
477                                               ,lowtag))))
478            (unsigned-reg
479             (inst mov value (make-ea :dword :base object :index index :scale 4
480                                      :disp (- (* ,offset n-word-bytes)
481                                               ,lowtag))))
482            (t
483             (inst mov value (make-ea :dword :base object :index index
484                                      :disp (- (* ,offset n-word-bytes)
485                                               ,lowtag)))))))))
486
487 (defmacro define-full-reffer+offset (name type offset lowtag scs el-type &optional translate)
488   `(progn
489      (define-vop (,name)
490        ,@(when translate
491            `((:translate ,translate)))
492        (:policy :fast-safe)
493        (:args (object :scs (descriptor-reg))
494               (index :scs (any-reg immediate unsigned-reg)))
495        (:arg-types ,type tagged-num
496                    (:constant (constant-displacement ,lowtag sb!vm:n-word-bytes ,offset)))
497        (:info offset)
498        (:results (value :scs ,scs))
499        (:result-types ,el-type)
500        (:generator 3                    ; pw was 5
501          (sc-case index
502            (immediate
503             (inst mov value (make-ea :dword :base object
504                                      :disp (- (* (+ ,offset
505                                                     (tn-value index)
506                                                     offset)
507                                                  n-word-bytes)
508                                               ,lowtag))))
509            (unsigned-reg
510             (inst mov value (make-ea :dword :base object :index index :scale 4
511                                      :disp (- (* (+ ,offset offset)
512                                                  n-word-bytes)
513                                               ,lowtag))))
514            (t
515             (inst mov value (make-ea :dword :base object :index index
516                                      :disp (- (* (+ ,offset offset)
517                                                  n-word-bytes)
518                                               ,lowtag)))))))))
519
520 (defmacro define-full-setter (name type offset lowtag scs el-type &optional translate)
521   `(progn
522      (define-vop (,name)
523        ,@(when translate
524            `((:translate ,translate)))
525        (:policy :fast-safe)
526        (:args (object :scs (descriptor-reg))
527               (index :scs (any-reg immediate))
528               (value :scs ,scs :target result))
529        (:arg-types ,type tagged-num ,el-type)
530        (:results (result :scs ,scs))
531        (:result-types ,el-type)
532        (:generator 4                    ; was 5
533          (sc-case index
534            (immediate
535             (inst mov (make-ea :dword :base object
536                                :disp (- (* (+ ,offset (tn-value index))
537                                            n-word-bytes)
538                                         ,lowtag))
539                   value))
540            (t
541             (inst mov (make-ea :dword :base object :index index
542                                :disp (- (* ,offset n-word-bytes) ,lowtag))
543                   value)))
544         (move result value)))))
545
546 (defmacro define-full-setter+offset (name type offset lowtag scs el-type &optional translate)
547   `(progn
548      (define-vop (,name)
549        ,@(when translate
550            `((:translate ,translate)))
551        (:policy :fast-safe)
552        (:args (object :scs (descriptor-reg))
553               (index :scs (any-reg immediate))
554               (value :scs ,scs :target result))
555        (:info offset)
556        (:arg-types ,type tagged-num
557                    (:constant (constant-displacement ,lowtag sb!vm:n-word-bytes ,offset)) ,el-type)
558        (:results (result :scs ,scs))
559        (:result-types ,el-type)
560        (:generator 4                    ; was 5
561          (sc-case index
562            (immediate
563             (inst mov (make-ea :dword :base object
564                                :disp (- (* (+ ,offset (tn-value index) offset)
565                                            n-word-bytes)
566                                         ,lowtag))
567                   value))
568            (t
569             (inst mov (make-ea :dword :base object :index index
570                                :disp (- (* (+ ,offset offset)
571                                            n-word-bytes) ,lowtag))
572                   value)))
573         (move result value)))))
574
575 ;;; helper for alien stuff.
576
577 (def!macro with-pinned-objects ((&rest objects) &body body)
578   "Arrange with the garbage collector that the pages occupied by
579 OBJECTS will not be moved in memory for the duration of BODY.
580 Useful for e.g. foreign calls where another thread may trigger
581 collection."
582   (if objects
583       (let ((pins (make-gensym-list (length objects)))
584             (wpo (block-gensym "WPO")))
585         ;; BODY is stuffed in a function to preserve the lexical
586         ;; environment.
587         `(flet ((,wpo () (progn ,@body)))
588            ;; PINS are dx-allocated in case the compiler for some
589            ;; unfathomable reason decides to allocate value-cells
590            ;; for them -- since we have DX value-cells on x86oid
591            ;; platforms this still forces them on the stack.
592            (dx-let ,(mapcar #'list pins objects)
593              (multiple-value-prog1 (,wpo)
594                ;; TOUCH-OBJECT has a VOP with an empty body: compiler
595                ;; thinks we're using the argument and doesn't flush
596                ;; the variable, but we don't have to pay any extra
597                ;; beyond that -- and MULTIPLE-VALUE-PROG1 keeps them
598                ;; live till the body has finished. *whew*
599                ,@(mapcar (lambda (pin)
600                            `(touch-object ,pin))
601                          pins)))))
602       `(progn ,@body)))