close Warning: Can't use blame annotator:
No changeset 2935 in the repository

source: release/1.11/source/compiler/X86/X8664/x8664-arch.lisp

Last change on this file was 16688, checked in by R. Matthew Emerson, 9 years ago

Merge copyright/license header changes to 1.11 release branch.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 46.8 KB
RevLine 
1;;;-*- Mode: Lisp; Package: (X8664 :use CL) -*-
2;;;
3;;; Copyright 2005-2009 Clozure Associates
4;;;
5;;; Licensed under the Apache License, Version 2.0 (the "License");
6;;; you may not use this file except in compliance with the License.
7;;; You may obtain a copy of the License at
8;;;
9;;; http://www.apache.org/licenses/LICENSE-2.0
10;;;
11;;; Unless required by applicable law or agreed to in writing, software
12;;; distributed under the License is distributed on an "AS IS" BASIS,
13;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14;;; See the License for the specific language governing permissions and
15;;; limitations under the License.
16
17(defpackage "X8664"
18 (:use "CL")
19 #+x8664-target
20 (:nicknames "TARGET"))
21
22(in-package "X8664")
23
24(eval-when (:compile-toplevel :load-toplevel :execute)
25 (require "X86-ARCH")
26 (require "X86-LAP")
27
28(defparameter *x8664-symbolic-register-names*
29 (make-hash-table :test #'equal)
30 "For the disassembler, mostly")
31
32;;; define integer constants which map to
33;;; indices in the X86::*X8664-REGISTER-ENTRIES* array.
34(ccl::defenum ()
35 rax
36 rcx
37 rdx
38 rbx
39 rsp
40 rbp
41 rsi
42 rdi
43 r8
44 r9
45 r10
46 r11
47 r12
48 r13
49 r14
50 r15
51 ;; 32-bit registers
52 eax
53 ecx
54 edx
55 ebx
56 esp
57 ebp
58 esi
59 edi
60 r8d
61 r9d
62 r10d
63 r11d
64 r12d
65 r13d
66 r14d
67 r15d
68 ;; 16-bit-registers
69 ax
70 cx
71 dx
72 bx
73 sp
74 bp
75 si
76 di
77 r8w
78 r9w
79 r10w
80 r11w
81 r12w
82 r13w
83 r14w
84 r15w
85 ;; 8-bit registers
86 al
87 cl
88 dl
89 bl
90 spl
91 bpl
92 sil
93 dil
94 r8b
95 r9b
96 r10b
97 r11b
98 r12b
99 r13b
100 r14b
101 r15b
102 ;;; xmm registers
103 xmm0
104 xmm1
105 xmm2
106 xmm3
107 xmm4
108 xmm5
109 xmm6
110 xmm7
111 xmm8
112 xmm9
113 xmm10
114 xmm11
115 xmm12
116 xmm13
117 xmm14
118 xmm15
119 ;; MMX registers
120 mm0
121 mm1
122 mm2
123 mm3
124 mm4
125 mm5
126 mm6
127 mm7
128 ;; x87 FP regs. May or may not be useful.
129 st[0]
130 st[1]
131 st[2]
132 st[3]
133 st[4]
134 st[5]
135 st[6]
136 st[7]
137 ;; Segment registers
138 cs
139 ds
140 ss
141 es
142 fs
143 gs
144 rip
145 )
146
147(defmacro defx86reg (alias known)
148 (let* ((known-entry (gensym)))
149 `(let* ((,known-entry (gethash ,(string known) x86::*x8664-registers*)))
150 (unless ,known-entry
151 (error "register ~a not defined" ',known))
152 (setf (gethash ,(string alias) x86::*x8664-registers*) ,known-entry)
153 (unless (gethash ,(string-downcase (string known)) *x8664-symbolic-register-names*)
154 (setf (gethash ,(string-downcase (string known)) *x8664-symbolic-register-names*)
155 (string-downcase ,(string alias))))
156 (defconstant ,alias ,known))))
157
158(defx86reg imm0 rax)
159(defx86reg imm0.l eax)
160(defx86reg imm0.w ax)
161(defx86reg imm0.b al)
162
163(defx86reg temp0 rbx)
164(defx86reg temp0.l ebx)
165(defx86reg temp0.w bx)
166(defx86reg temp0.b bl)
167
168(defx86reg imm2 rcx)
169(defx86reg nargs ecx)
170(defx86reg imm2.l ecx)
171(defx86reg nargs.w cx)
172(defx86reg nargs.q rcx)
173(defx86reg imm2.w cx)
174(defx86reg imm2.b cl)
175(defx86reg shift cl)
176
177(defx86reg imm1 rdx)
178(defx86reg imm1.l edx)
179(defx86reg imm1.w dx)
180(defx86reg imm1.b dl)
181
182(defx86reg arg_z rsi)
183(defx86reg arg_z.l esi)
184(defx86reg arg_z.w si)
185(defx86reg arg_z.b sil)
186
187(defx86reg arg_y rdi)
188(defx86reg arg_y.l edi)
189(defx86reg arg_y.w di)
190(defx86reg arg_y.b dil)
191
192(defx86reg arg_x r8)
193(defx86reg arg_x.l r8d)
194(defx86reg arg_x.w r8w)
195(defx86reg arg_x.b r8b)
196
197(defx86reg temp1 r9)
198(defx86reg temp1.l r9d)
199(defx86reg temp1.w r9w)
200(defx86reg temp1.b r9b)
201
202(defx86reg temp2 r10)
203(defx86reg temp2.l r10d)
204(defx86reg temp2.w r10w)
205(defx86reg temp2.b r10b)
206
207(defx86reg ra0 r10)
208(defx86reg ra0.l r10d)
209(defx86reg ra0.w r10w)
210(defx86reg ra0.b r10b)
211
212#+(or darwin-target windows-target)
213(defx86reg rcontext r11)
214
215(defx86reg save3 r11)
216(defx86reg save3.l r11d)
217(defx86reg save3.w r11w)
218(defx86reg save3.b r11b)
219
220
221(defx86reg save2 r12)
222(defx86reg save2.l r12d)
223(defx86reg save2.w r12w)
224(defx86reg save2.b r12b)
225
226(defx86reg fn r13)
227(defx86reg fn.l r13d)
228(defx86reg fn.w r13w)
229(defx86reg fn.b r13b)
230
231(defx86reg save1 r14)
232(defx86reg save1.l r14d)
233(defx86reg save1.w r14w)
234(defx86reg save1.b r14b)
235
236(defx86reg save0 r15)
237(defx86reg save0.l r15d)
238(defx86reg save0.w r15w)
239(defx86reg save0.b r15b)
240
241;;; Use xmm regs for floating-point. (They can also hold integer values.)
242(defx86reg fp0 xmm0)
243(defx86reg fp1 xmm1)
244(defx86reg fp2 xmm2)
245(defx86reg fp3 xmm3)
246(defx86reg fp4 xmm4)
247(defx86reg fp5 xmm5)
248(defx86reg fp6 xmm6)
249(defx86reg fp7 xmm7)
250(defx86reg fp8 xmm8)
251(defx86reg fp9 xmm9)
252(defx86reg fp10 xmm10)
253(defx86reg fp11 xmm11)
254(defx86reg fp12 xmm12)
255(defx86reg fp13 xmm13)
256(defx86reg fp14 xmm14)
257(defx86reg fpzero xmm15)
258(defx86reg fp15 xmm15)
259
260;;; There are only 8 mmx registers, and they overlap the x87 FPU.
261(defx86reg stack-temp mm7)
262
263
264;;; NEXT-METHOD-CONTEXT is passed from gf-dispatch code to the method
265;;; functions that it funcalls. FNAME is only meaningful when calling
266;;; globally named functions through the function cell of a symbol.
267;;; It appears that they're never live at the same time.
268;;; (We can also consider passing next-method context on the stack.)
269
270(defx86reg fname temp0)
271(defx86reg next-method-context temp0)
272;;; We rely one at least one of %ra0/%fn pointing to the current function
273;;; (or to a TRA that references the function) at all times. When we
274;;; tail call something, we want %RA0 to point to our caller's TRA and
275;;; %FN to point to the new function. Unless we go out of line to
276;;; do tail calls, we need some register not involved in the calling
277;;; sequence to hold the current function, since it might get GCed otherwise.
278;;; (The odds of this happening are low, but non-zero.)
279(defx86reg xfn temp1)
280
281(defx86reg ra1 fn)
282
283(defx86reg allocptr temp0)
284
285
286(defconstant nbits-in-word 64)
287(defconstant nbits-in-byte 8)
288(defconstant ntagbits 4)
289(defconstant nlisptagbits 3)
290(defconstant nfixnumtagbits 3)
291(defconstant num-subtag-bits 8)
292(defconstant fixnumshift 3)
293(defconstant fixnum-shift 3)
294(defconstant fulltagmask 15)
295(defconstant tagmask 7)
296(defconstant fixnummask 7)
297(defconstant ncharcodebits 8)
298(defconstant charcode-shift 8)
299(defconstant word-shift 3)
300(defconstant word-size-in-bytes 8)
301(defconstant node-size word-size-in-bytes)
302(defconstant dnode-size 16)
303(defconstant dnode-align-bits 4)
304(defconstant dnode-shift dnode-align-bits)
305(defconstant bitmap-shift 6)
306
307(defconstant fixnumone (ash 1 fixnumshift))
308(defconstant fixnum-one fixnumone)
309(defconstant fixnum1 fixnumone)
310
311(defconstant target-most-negative-fixnum (ash -1 (1- (- nbits-in-word nfixnumtagbits))))
312(defconstant target-most-positive-fixnum (1- (ash 1 (1- (- nbits-in-word nfixnumtagbits)))))
313
314;;; 3-bit "lisptag" values
315
316(defconstant tag-fixnum 0)
317(defconstant tag-imm-0 1) ;subtag-single-float ONLY
318(defconstant tag-imm-1 2) ;subtag-character, internal markers
319(defconstant tag-list 3) ;fulltag-cons or NIL
320(defconstant tag-tra 4) ;tagged return-address
321(defconstant tag-misc 5) ;random uvector
322(defconstant tag-symbol 6) ;non-null symbol
323(defconstant tag-function 7) ;function entry point
324
325(defconstant tag-single-float tag-imm-0)
326
327;;; 4-bit "fulltag" values
328(defconstant fulltag-even-fixnum 0)
329(defconstant fulltag-imm-0 1) ;subtag-single-float ONLY
330(defconstant fulltag-imm-1 2) ;characters, markers
331(defconstant fulltag-cons 3)
332(defconstant fulltag-tra-0 4) ;tagged return address
333(defconstant fulltag-nodeheader-0 5)
334(defconstant fulltag-nodeheader-1 6)
335(defconstant fulltag-immheader-0 7)
336(defconstant fulltag-odd-fixnum 8)
337(defconstant fulltag-immheader-1 9)
338(defconstant fulltag-immheader-2 10)
339(defconstant fulltag-nil 11)
340(defconstant fulltag-tra-1 12)
341(defconstant fulltag-misc 13)
342(defconstant fulltag-symbol 14)
343(defconstant fulltag-function 15)
344
345(defconstant fulltag-single-float fulltag-imm-0)
346
347(defmacro define-subtag (name tag value)
348 `(defconstant ,(ccl::form-symbol "SUBTAG-" name) (logior ,tag (ash ,value ntagbits))))
349
350
351(define-subtag arrayH fulltag-nodeheader-0 10)
352(define-subtag vectorH fulltag-nodeheader-1 10)
353(define-subtag simple-vector fulltag-nodeheader-1 11)
354
355(defconstant ivector-class-64-bit fulltag-immheader-2)
356(defconstant ivector-class-32-bit fulltag-immheader-1)
357(defconstant ivector-class-other-bit fulltag-immheader-0)
358
359(define-subtag complex-single-float-vector ivector-class-64-bit 11)
360(define-subtag fixnum-vector ivector-class-64-bit 12)
361(define-subtag s64-vector ivector-class-64-bit 13)
362(define-subtag u64-vector ivector-class-64-bit 14)
363(define-subtag double-float-vector ivector-class-64-bit 15)
364
365(define-subtag simple-base-string ivector-class-32-bit 12)
366(define-subtag s32-vector ivector-class-32-bit 13)
367(define-subtag u32-vector ivector-class-32-bit 14)
368(define-subtag single-float-vector ivector-class-32-bit 15)
369
370(define-subtag complex-double-float-vector ivector-class-other-bit 9)
371(define-subtag s16-vector ivector-class-other-bit 10)
372(define-subtag u16-vector ivector-class-other-bit 11)
373
374(defconstant min-cl-ivector-subtag subtag-complex-double-float-vector)
375
376(define-subtag s8-vector ivector-class-other-bit 13)
377(define-subtag u8-vector ivector-class-other-bit 14)
378(defconstant min-8-bit-ivector-subtag subtag-s8-vector)
379(defconstant max-8-bit-ivector-subtag subtag-u8-vector)
380(define-subtag bit-vector ivector-class-other-bit 15)
381
382
383;;; There's some room for expansion in non-array ivector space.
384(define-subtag macptr ivector-class-64-bit 1)
385(define-subtag dead-macptr ivector-class-64-bit 2)
386(define-subtag bignum ivector-class-32-bit 1)
387(define-subtag double-float ivector-class-32-bit 2)
388(define-subtag xcode-vector ivector-class-32-bit 3)
389(define-subtag complex-single-float ivector-class-32-bit 4)
390(define-subtag complex-double-float ivector-class-32-bit 5)
391
392
393
394;;; Note the difference between (e.g) fulltag-function - which
395;;; defines what the low 4 bytes of a function pointer look like -
396;;; and subtag-function - which describes what the subtag byte
397;;; in a function header looks like. (Likewise for fulltag-symbol
398;;; and subtag-symbol)
399
400;;; don't use nodheader/0, since that would conflict with tag-misc
401(define-subtag symbol fulltag-nodeheader-0 1)
402(define-subtag catch-frame fulltag-nodeheader-0 2)
403(define-subtag hash-vector fulltag-nodeheader-0 3)
404(define-subtag pool fulltag-nodeheader-0 4)
405(define-subtag weak fulltag-nodeheader-0 5)
406(define-subtag package fulltag-nodeheader-0 6)
407(define-subtag slot-vector fulltag-nodeheader-0 7)
408(define-subtag basic-stream fulltag-nodeheader-0 8)
409(define-subtag function fulltag-nodeheader-0 9)
410
411(define-subtag ratio fulltag-nodeheader-1 1)
412(define-subtag complex fulltag-nodeheader-1 2)
413(define-subtag struct fulltag-nodeheader-1 3)
414(define-subtag istruct fulltag-nodeheader-1 4)
415(define-subtag value-cell fulltag-nodeheader-1 5)
416(define-subtag xfunction fulltag-nodeheader-1 6)
417(define-subtag lock fulltag-nodeheader-1 7)
418(define-subtag instance fulltag-nodeheader-1 8)
419
420
421(defconstant canonical-nil-value (+ #x13000 fulltag-nil))
422(defconstant canonical-t-value (+ #x13020 fulltag-symbol))
423(defconstant misc-bias fulltag-misc)
424(defconstant cons-bias fulltag-cons)
425(defconstant t-offset (- canonical-t-value canonical-nil-value))
426
427
428(defconstant misc-header-offset (- fulltag-misc))
429(defconstant misc-data-offset (+ misc-header-offset node-size))
430(defconstant misc-subtag-offset misc-header-offset)
431(defconstant misc-dfloat-offset misc-data-offset)
432(defconstant misc-symbol-offset (- node-size fulltag-symbol))
433(defconstant misc-function-offset (- node-size fulltag-function))
434
435(define-subtag single-float fulltag-imm-0 0)
436
437(define-subtag character fulltag-imm-1 0)
438
439(define-subtag unbound fulltag-imm-1 1)
440(defconstant unbound-marker subtag-unbound)
441(defconstant undefined unbound-marker)
442(define-subtag slot-unbound fulltag-imm-1 2)
443(defconstant slot-unbound-marker subtag-slot-unbound)
444(define-subtag illegal fulltag-imm-1 3)
445(defconstant illegal-marker subtag-illegal)
446(define-subtag no-thread-local-binding fulltag-imm-1 4)
447(defconstant no-thread-local-binding-marker subtag-no-thread-local-binding)
448(define-subtag reserved-frame fulltag-imm-1 5)
449(defconstant reserved-frame-marker subtag-reserved-frame)
450
451;;; This has two functions: it tells the link-inverting marker where the
452;;; code ends and the constants start, and it ensures that the 0th constant
453;;; will never be in the same memozized dnode as some (unboxed) word of
454;;; machine code. I'm not sure if there's a better way to do either of those
455;;; things.
456;;; Depending on how you look at it, we either lose 8 bytes per function, or gain
457;;; 7 bytes of otherwise unused space for debugging info.
458(define-subtag function-boundary-marker fulltag-imm-1 15)
459(defconstant function-boundary-marker subtag-function-boundary-marker)
460
461(defconstant max-64-bit-constant-index (ash (+ #x7fffffff x8664::misc-dfloat-offset) -3))
462(defconstant max-32-bit-constant-index (ash (+ #x7fffffff x8664::misc-data-offset) -2))
463(defconstant max-16-bit-constant-index (ash (+ #x7fffffff x8664::misc-data-offset) -1))
464(defconstant max-8-bit-constant-index (+ #x7fffffff x8664::misc-data-offset))
465(defconstant max-1-bit-constant-index (ash (+ #x7fffffff x8664::misc-data-offset) 3))
466
467)
468(defmacro define-storage-layout (name origin &rest cells)
469 `(progn
470 (ccl::defenum (:start ,origin :step 8)
471 ,@(mapcar #'(lambda (cell) (ccl::form-symbol name "." cell)) cells))
472 (defconstant ,(ccl::form-symbol name ".SIZE") ,(* (length cells)
473 8))))
474
475(defmacro define-lisp-object (name tagname &rest cells)
476 `(define-storage-layout ,name ,(- (symbol-value tagname)) ,@cells))
477
478(defmacro define-fixedsized-object (name (&optional (fulltag 'fulltag-misc))
479 &rest non-header-cells)
480 `(progn
481 (define-lisp-object ,name ,fulltag header ,@non-header-cells)
482 (ccl::defenum ()
483 ,@(mapcar #'(lambda (cell) (ccl::form-symbol name "." cell "-CELL")) non-header-cells))
484 (defconstant ,(ccl::form-symbol name ".ELEMENT-COUNT") ,(length non-header-cells))))
485
486;;; Order of CAR and CDR doesn't seem to matter much - there aren't
487;;; too many tricks to be played with predecrement/preincrement addressing.
488;;; Keep them in the confusing MCL 3.0 order, to avoid confusion.
489(define-lisp-object cons fulltag-cons
490 cdr
491 car)
492
493(define-fixedsized-object ratio ()
494 numer
495 denom)
496
497;;; It's slightly easier (for bootstrapping reasons)
498;;; to view a DOUBLE-FLOAT as being UVECTOR with 2 32-bit elements
499;;; (rather than 1 64-bit element).
500
501(defconstant double-float.value misc-data-offset)
502(defconstant double-float.value-cell 0)
503(defconstant double-float.val-low double-float.value)
504(defconstant double-float.val-low-cell 0)
505(defconstant double-float.val-high (+ double-float.value 4))
506(defconstant double-float.val-high-cell 1)
507(defconstant double-float.element-count 2)
508(defconstant double-float.size 16)
509
510(define-fixedsized-object complex ()
511 realpart
512 imagpart
513)
514
515(define-fixedsized-object complex-single-float ()
516 value)
517
518(defconstant complex-single-float.realpart complex-single-float.value)
519(defconstant complex-single-float.imagpart (+ complex-single-float.value 4))
520
521(define-fixedsized-object complex-double-float ()
522 pad
523 realpart
524 imagpart)
525
526
527;;; There are two kinds of macptr; use the length field of the header if you
528;;; need to distinguish between them
529(define-fixedsized-object macptr ()
530 address
531 domain
532 type
533)
534
535(define-fixedsized-object xmacptr ()
536 address
537 domain
538 type
539 flags
540 link
541)
542
543
544;;; Need to think about catch frames on x8664.
545(define-fixedsized-object catch-frame ()
546 catch-tag ; #<unbound> -> unwind-protect, else catch
547 link ; tagged pointer to next older catch frame
548 mvflag ; 0 if single-value, 1 if uwp or multiple-value
549 rsp ;
550 rbp
551 foreign-sp
552 db-link ; value of dynamic-binding link on thread entry.
553 save-save3 ; saved nvrs
554 save-save2
555 save-save1
556 save-save0
557 xframe ; exception-frame link
558 pc ; tra of catch exit/unwind cleanup
559)
560
561(define-fixedsized-object lock ()
562 _value ;finalizable pointer to kernel object
563 kind ; '0 = recursive-lock, '1 = rwlock
564 writer ;tcr of owning thread or 0
565 name
566 whostate
567 whostate-2
568 )
569
570
571
572;;; If we're pointing at the "symbol-vector", we can use these
573(define-fixedsized-object symptr ()
574 pname
575 vcell
576 fcell
577 package-predicate
578 flags
579 plist
580 binding-index
581)
582
583(define-fixedsized-object symbol (fulltag-symbol)
584 pname
585 vcell
586 fcell
587 package-predicate
588 flags
589 plist
590 binding-index
591)
592
593(defconstant nilsym-offset (+ t-offset symbol.size))
594
595
596(define-fixedsized-object vectorH ()
597 logsize ; fillpointer if it has one, physsize otherwise
598 physsize ; total size of (possibly displaced) data vector
599 data-vector ; object this header describes
600 displacement ; true displacement or 0
601 flags ; has-fill-pointer,displaced-to,adjustable bits; subtype of underlying simple vector.
602)
603
604(define-lisp-object arrayH fulltag-misc
605 header ; subtag = subtag-arrayH
606 rank ; NEVER 1
607 physsize ; total size of (possibly displaced) data vector
608 data-vector ; object this header describes
609 displacement ; true displacement or 0
610 flags ; has-fill-pointer,displaced-to,adjustable bits; subtype of underlying simple vector.
611 ;; Dimensions follow
612)
613
614(defconstant arrayH.rank-cell 0)
615(defconstant arrayH.physsize-cell 1)
616(defconstant arrayH.data-vector-cell 2)
617(defconstant arrayH.displacement-cell 3)
618(defconstant arrayH.flags-cell 4)
619(defconstant arrayH.dim0-cell 5)
620
621(defconstant arrayH.flags-cell-bits-byte (byte 8 0))
622(defconstant arrayH.flags-cell-subtag-byte (byte 8 8))
623
624(define-fixedsized-object value-cell ()
625 value)
626
627
628(define-storage-layout lisp-frame 0
629 backptr
630 return-address
631 xtra)
632
633(define-storage-layout tsp-frame 0
634 backptr
635 rbp)
636
637(define-storage-layout csp-frame 0
638 backptr
639 rbp)
640
641
642(define-storage-layout xcf 0 ;"exception callback frame"
643 backptr
644 return-address ; always 0
645 nominal-function
646 relative-pc
647 containing-object
648 xp
649 ra0
650 foreign-sp ; value of tcr.foreign_sp
651 prev-xframe ; tcr.xframe before exception
652 ; (last 2 needed by apply-in-frame)
653 pc-low ;fixnum low half of absolute pc
654 pc-high ;and the high half
655 )
656
657;;; The kernel uses these (rather generically named) structures
658;;; to keep track of various memory regions it (or the lisp) is
659;;; interested in.
660
661
662(define-storage-layout area 0
663 pred ; pointer to preceding area in DLL
664 succ ; pointer to next area in DLL
665 low ; low bound on area addresses
666 high ; high bound on area addresses.
667 active ; low limit on stacks, high limit on heaps
668 softlimit ; overflow bound
669 hardlimit ; another one
670 code ; an area-code; see below
671 markbits ; bit vector for GC
672 ndnodes ; "active" size of dynamic area or stack
673 older ; in EGC sense
674 younger ; also for EGC
675 h ; Handle or null pointer
676 softprot ; protected_area structure pointer
677 hardprot ; another one.
678 owner ; fragment (library) which "owns" the area
679 refbits ; bitvector for intergenerational refernces
680 threshold ; for egc
681 gc-count ; generational gc count.
682 static-dnodes ; for honsing. etc
683 static-used ; bitvector
684)
685
686
687(define-storage-layout protected-area 0
688 next
689 start ; first byte (page-aligned) that might be protected
690 end ; last byte (page-aligned) that could be protected
691 nprot ; Might be 0
692 protsize ; number of bytes to protect
693 why)
694
695(eval-when (:compile-toplevel :load-toplevel :execute)
696(defconstant tcr-bias 0)
697)
698
699(define-storage-layout tcr (- tcr-bias)
700 prev ; in doubly-linked list
701 next ; in doubly-linked list
702 single-float-convert ; faster to box/unbox through memory
703 linear
704 save-rbp ; lisp frame ptr for foreign code
705 lisp-fpscr-high
706 db-link ; special binding chain head
707 catch-top ; top catch frame
708 save-vsp ; SP when in foreign code
709 save-tsp ; TSP, at all times
710 foreign-sp ; SP when in lisp code
711 cs-area ; cstack area pointer
712 vs-area ; vstack area pointer
713 ts-area ; tstack area pointer
714 cs-limit ; cstack overflow limit
715 total-bytes-allocated
716 log2-allocation-quantum ; unboxed
717 interrupt-pending ; fixnum
718 xframe ; exception frame linked list
719 errno-loc ; thread-private, maybe
720 ffi-exception ; fpscr bits from ff-call.
721 osid ; OS thread id
722 valence ; odd when in foreign code
723 foreign-exception-status
724 native-thread-info
725 native-thread-id
726 last-allocptr
727 save-allocptr
728 save-allocbase
729 reset-completion
730 activate
731 suspend-count
732 suspend-context
733 pending-exception-context
734 suspend ; semaphore for suspension notify
735 resume ; sempahore for resumption notify
736 flags ; foreign, being reset, ...
737 gc-context
738 termination-semaphore
739 unwinding
740 tlb-limit
741 tlb-pointer
742 shutdown-count
743 next-tsp
744 safe-ref-address
745 pending-io-info
746 io-datum
747 nfp
748)
749
750(defconstant tcr.single-float-convert.value (+ 4 tcr.single-float-convert))
751
752
753(defconstant interrupt-level-binding-index (ash 1 fixnumshift))
754
755(define-storage-layout lockptr 0
756 avail
757 owner
758 count
759 signal
760 waiting
761 malloced-ptr
762 spinlock)
763
764(define-storage-layout rwlock 0
765 spin
766 state
767 blocked-writers
768 blocked-readers
769 writer
770 reader-signal
771 writer-signal
772 malloced-ptr
773 )
774
775(defmacro define-header (name element-count subtag)
776 `(defconstant ,name (logior (ash ,element-count num-subtag-bits) ,subtag)))
777
778(define-header double-float-header double-float.element-count subtag-double-float)
779
780;;; We could possibly have a one-digit bignum header when dealing
781;;; with "small bignums" in some bignum code. Like other cases of
782;;; non-normalized bignums, they should never escape from the lab.
783(define-header one-digit-bignum-header 1 subtag-bignum)
784(define-header two-digit-bignum-header 2 subtag-bignum)
785(define-header three-digit-bignum-header 3 subtag-bignum)
786(define-header four-digit-bignum-header 4 subtag-bignum)
787(define-header five-digit-bignum-header 5 subtag-bignum)
788(define-header symbol-header symbol.element-count subtag-symbol)
789(define-header value-cell-header value-cell.element-count subtag-value-cell)
790(define-header macptr-header macptr.element-count subtag-macptr)
791
792
793(defconstant gf-code-size 18)
794
795(defun %kernel-global (sym)
796 (let* ((pos (position sym x86::*x86-kernel-globals* :test #'string=)))
797 (if pos
798 (- (+ fulltag-nil (* (1+ pos) node-size)))
799 (error "Unknown kernel global : ~s ." sym))))
800
801(defmacro kernel-global (sym)
802 (let* ((pos (position sym x86::*x86-kernel-globals* :test #'string=)))
803 (if pos
804 (- (+ fulltag-nil (* (1+ pos) node-size)))
805 (error "Unknown kernel global : ~s ." sym))))
806
807(ccl::defenum (:prefix "KERNEL-IMPORT-" :start 0 :step node-size)
808 fd-setsize-bytes
809 do-fd-set
810 do-fd-clr
811 do-fd-is-set
812 do-fd-zero
813 MakeDataExecutable
814 GetSharedLibrary
815 FindSymbol
816 malloc
817 free
818 wait-for-signal
819 tcr-frame-ptr
820 register-xmacptr-dispose-function
821 open-debug-output
822 get-r-debug
823 restore-soft-stack-limit
824 egc-control
825 lisp-bug
826 NewThread
827 YieldToThread
828 DisposeThread
829 ThreadCurrentStackSpace
830 usage-exit
831 save-fp-context
832 restore-fp-context
833 put-altivec-registers
834 get-altivec-registers
835 new-semaphore
836 wait-on-semaphore
837 signal-semaphore
838 destroy-semaphore
839 new-recursive-lock
840 lock-recursive-lock
841 unlock-recursive-lock
842 destroy-recursive-lock
843 suspend-other-threads
844 resume-other-threads
845 suspend-tcr
846 resume-tcr
847 rwlock-new
848 rwlock-destroy
849 rwlock-rlock
850 rwlock-wlock
851 rwlock-unlock
852 recursive-lock-trylock
853 foreign-name-and-offset
854 lisp-read
855 lisp-write
856 lisp-open
857 lisp-fchmod
858 lisp-lseek
859 lisp-close
860 lisp-ftruncate
861 lisp-stat
862 lisp-fstat
863 lisp-futex
864 lisp-opendir
865 lisp-readdir
866 lisp-closedir
867 lisp-pipe
868 lisp-gettimeofday
869 lisp-sigexit
870 jvm-init
871)
872
873(defmacro nrs-offset (name)
874 (let* ((pos (position name x86::*x86-nilreg-relative-symbols* :test #'eq)))
875 (if pos (* (1- pos) symbol.size))))
876
877(defparameter *x8664-target-uvector-subtags*
878 `((:bignum . ,subtag-bignum)
879 (:ratio . ,subtag-ratio)
880 (:single-float . ,subtag-single-float)
881 (:double-float . ,subtag-double-float)
882 (:complex . ,subtag-complex )
883 (:complex-single-float . ,subtag-complex-single-float)
884 (:complex-double-float . ,subtag-complex-double-float)
885 (:symbol . ,subtag-symbol)
886 (:function . ,subtag-function )
887 (:xcode-vector . ,subtag-xcode-vector)
888 (:macptr . ,subtag-macptr )
889 (:catch-frame . ,subtag-catch-frame)
890 (:struct . ,subtag-struct )
891 (:istruct . ,subtag-istruct )
892 (:pool . ,subtag-pool )
893 (:population . ,subtag-weak )
894 (:hash-vector . ,subtag-hash-vector )
895 (:package . ,subtag-package )
896 (:value-cell . ,subtag-value-cell)
897 (:instance . ,subtag-instance )
898 (:lock . ,subtag-lock )
899 (:basic-stream . ,subtag-basic-stream)
900 (:slot-vector . ,subtag-slot-vector)
901 (:simple-string . ,subtag-simple-base-string )
902 (:bit-vector . ,subtag-bit-vector )
903 (:signed-8-bit-vector . ,subtag-s8-vector )
904 (:unsigned-8-bit-vector . ,subtag-u8-vector )
905 (:signed-16-bit-vector . ,subtag-s16-vector )
906 (:unsigned-16-bit-vector . ,subtag-u16-vector )
907 (:signed-32-bit-vector . ,subtag-s32-vector )
908 (:unsigned-32-bit-vector . ,subtag-u32-vector )
909 (:signed-64-bit-vector . ,subtag-s64-vector)
910 (:fixnum-vector . ,subtag-fixnum-vector)
911 (:unsigned-64-bit-vector . ,subtag-u64-vector)
912 (:single-float-vector . ,subtag-single-float-vector)
913 (:double-float-vector . ,subtag-double-float-vector )
914 (:simple-vector . ,subtag-simple-vector )
915 (:complex-single-float-vector . ,subtag-complex-single-float-vector)
916 (:complex-double-float-vector . ,subtag-complex-double-float-vector)
917 (:vector-header . ,subtag-vectorH)
918 (:array-header . ,subtag-arrayH)
919 (:min-cl-ivector-subtag . ,min-cl-ivector-subtag)))
920
921;;; This should return NIL unless it's sure of how the indicated
922;;; type would be represented (in particular, it should return
923;;; NIL if the element type is unknown or unspecified at compile-time.
924(defun x8664-array-type-name-from-ctype (ctype)
925 (when (typep ctype 'ccl::array-ctype)
926 (let* ((element-type (ccl::array-ctype-element-type ctype)))
927 (typecase element-type
928 (ccl::class-ctype
929 (let* ((class (ccl::class-ctype-class element-type)))
930 (if (or (eq class ccl::*character-class*)
931 (eq class ccl::*base-char-class*)
932 (eq class ccl::*standard-char-class*))
933 :simple-string
934 :simple-vector)))
935 (ccl::numeric-ctype
936 (if (eq (ccl::numeric-ctype-complexp element-type) :complex)
937 (case (ccl::numeric-ctype-format element-type)
938 (single-float :complex-single-float-vector)
939 (double-float :complex-double-float-vector)
940 (t :simple-vector))
941 (case (ccl::numeric-ctype-class element-type)
942 (integer
943 (let* ((low (ccl::numeric-ctype-low element-type))
944 (high (ccl::numeric-ctype-high element-type)))
945 (cond ((or (null low) (null high))
946 :simple-vector)
947 ((and (>= low 0) (<= high 1))
948 :bit-vector)
949 ((and (>= low 0) (<= high 255))
950 :unsigned-8-bit-vector)
951 ((and (>= low 0) (<= high 65535))
952 :unsigned-16-bit-vector)
953 ((and (>= low 0) (<= high #xffffffff))
954 :unsigned-32-bit-vector)
955 ((and (>= low 0) (<= high #xffffffffffffffff))
956 :unsigned-64-bit-vector)
957 ((and (>= low -128) (<= high 127))
958 :signed-8-bit-vector)
959 ((and (>= low -32768) (<= high 32767))
960 :signed-16-bit-vector)
961 ((and (>= low (ash -1 31)) (<= high (1- (ash 1 31))))
962 :signed-32-bit-vector)
963 ((and (>= low target-most-negative-fixnum)
964 (<= high target-most-positive-fixnum))
965 :fixnum-vector)
966 ((and (>= low (ash -1 63)) (<= high (1- (ash 1 63))))
967 :signed-64-bit-vector)
968 (t :simple-vector))))
969 (float
970 (case (ccl::numeric-ctype-format element-type)
971 ((double-float long-float) :double-float-vector)
972 ((single-float short-float) :single-float-vector)
973 (t :simple-vector)))
974 (t :simple-vector))))
975 (ccl::unknown-ctype)
976 (ccl::named-ctype
977 (if (eq element-type ccl::*universal-type*)
978 :simple-vector))
979 (t)))))
980
981(defun x8664-misc-byte-count (subtag element-count)
982 (declare (fixnum subtag))
983 (if (logbitp (logand subtag fulltagmask)
984 (logior (ash 1 fulltag-nodeheader-0)
985 (ash 1 fulltag-nodeheader-1)))
986 (ash element-count 3)
987 (case (logand subtag fulltagmask)
988 (#.ivector-class-64-bit (ash element-count 3))
989 (#.ivector-class-32-bit (ash element-count 2))
990 (t
991 (if (= subtag subtag-bit-vector)
992 (ash (+ 7 element-count) -3)
993 (if (= subtag subtag-complex-double-float-vector)
994 (ash element-count 4)
995 (if (>= subtag min-8-bit-ivector-subtag)
996 element-count
997 (ash element-count 1))))))))
998
999(defparameter *x8664-subprims-shift* 3)
1000(defconstant x8664-subprims-base #x15000)
1001
1002
1003(declaim (special *x8664-subprims*))
1004
1005;;; For now, nothing's nailed down and we don't say anything about
1006;;; registers clobbered.
1007(let* ((origin x8664-subprims-base)
1008 (step (ash 1 *x8664-subprims-shift*)))
1009 (flet ((define-x8664-subprim (name)
1010 (ccl::make-subprimitive-info :name (string name)
1011 :offset (prog1 origin
1012 (incf origin step)))))
1013 (macrolet ((defx8664subprim (name)
1014 `(define-x8664-subprim ',name)))
1015 (defparameter *x8664-subprims*
1016 (vector
1017 (defx8664subprim .SPjmpsym)
1018 (defx8664subprim .SPjmpnfn)
1019 (defx8664subprim .SPfuncall)
1020 (defx8664subprim .SPmkcatch1v)
1021 (defx8664subprim .SPmkunwind)
1022 (defx8664subprim .SPmkcatchmv)
1023 (defx8664subprim .SPthrow)
1024 (defx8664subprim .SPnthrowvalues)
1025 (defx8664subprim .SPnthrow1value)
1026 (defx8664subprim .SPbind)
1027 (defx8664subprim .SPbind-self)
1028 (defx8664subprim .SPbind-nil)
1029 (defx8664subprim .SPbind-self-boundp-check)
1030 (defx8664subprim .SPrplaca)
1031 (defx8664subprim .SPrplacd)
1032 (defx8664subprim .SPconslist)
1033 (defx8664subprim .SPconslist-star)
1034 (defx8664subprim .SPstkconslist)
1035 (defx8664subprim .SPstkconslist-star)
1036 (defx8664subprim .SPmkstackv)
1037 (defx8664subprim .SPsubtag-misc-ref)
1038 (defx8664subprim .SPsetqsym)
1039 (defx8664subprim .SPprogvsave)
1040 (defx8664subprim .SPstack-misc-alloc)
1041 (defx8664subprim .SPgvector)
1042 (defx8664subprim .SPnvalret)
1043 (defx8664subprim .SPmvpass)
1044 (defx8664subprim .SPrecover-values-for-mvcall)
1045 (defx8664subprim .SPnthvalue)
1046 (defx8664subprim .SPvalues)
1047 (defx8664subprim .SPdefault-optional-args)
1048 (defx8664subprim .SPopt-supplied-p)
1049 (defx8664subprim .SPheap-rest-arg)
1050 (defx8664subprim .SPreq-heap-rest-arg)
1051 (defx8664subprim .SPheap-cons-rest-arg)
1052 (defx8664subprim .SPsimple-keywords)
1053 (defx8664subprim .SPkeyword-args)
1054 (defx8664subprim .SPkeyword-bind)
1055 (defx8664subprim .SPffcall)
1056 (defx8664subprim .SParef2)
1057 (defx8664subprim .SPksignalerr)
1058 (defx8664subprim .SPstack-rest-arg)
1059 (defx8664subprim .SPreq-stack-rest-arg)
1060 (defx8664subprim .SPstack-cons-rest-arg)
1061 (defx8664subprim .SPpoweropen-callbackX)
1062 (defx8664subprim .SPcall-closure)
1063 (defx8664subprim .SPgetXlong)
1064 (defx8664subprim .SPspreadargz)
1065 (defx8664subprim .SPtfuncallgen)
1066 (defx8664subprim .SPtfuncallslide)
1067 (defx8664subprim .SPtfuncallvsp)
1068 (defx8664subprim .SPtcallsymgen)
1069 (defx8664subprim .SPtcallsymslide)
1070 (defx8664subprim .SPtcallsymvsp)
1071 (defx8664subprim .SPtcallnfngen)
1072 (defx8664subprim .SPtcallnfnslide)
1073 (defx8664subprim .SPtcallnfnvsp)
1074 (defx8664subprim .SPmisc-ref)
1075 (defx8664subprim .SPmisc-set)
1076 (defx8664subprim .SPstkconsyz)
1077 (defx8664subprim .SPstkvcell0)
1078 (defx8664subprim .SPstkvcellvsp)
1079 (defx8664subprim .SPmakestackblock)
1080 (defx8664subprim .SPmakestackblock0)
1081 (defx8664subprim .SPmakestacklist)
1082 (defx8664subprim .SPstkgvector)
1083 (defx8664subprim .SPmisc-alloc)
1084 (defx8664subprim .SPpoweropen-ffcallX)
1085 (defx8664subprim .SPgvset)
1086 (defx8664subprim .SPmacro-bind)
1087 (defx8664subprim .SPdestructuring-bind)
1088 (defx8664subprim .SPdestructuring-bind-inner)
1089 (defx8664subprim .SPrecover-values)
1090 (defx8664subprim .SPvpopargregs)
1091 (defx8664subprim .SPinteger-sign)
1092 (defx8664subprim .SPsubtag-misc-set)
1093 (defx8664subprim .SPspread-lexpr-z)
1094 (defx8664subprim .SPstore-node-conditional)
1095 (defx8664subprim .SPreset)
1096 (defx8664subprim .SPmvslide)
1097 (defx8664subprim .SPsave-values)
1098 (defx8664subprim .SPadd-values)
1099 (defx8664subprim .SPcallback)
1100 (defx8664subprim .SPmisc-alloc-init)
1101 (defx8664subprim .SPstack-misc-alloc-init)
1102 (defx8664subprim .SPset-hash-key)
1103 (defx8664subprim .SPaset2)
1104 (defx8664subprim .SPcallbuiltin)
1105 (defx8664subprim .SPcallbuiltin0)
1106 (defx8664subprim .SPcallbuiltin1)
1107 (defx8664subprim .SPcallbuiltin2)
1108 (defx8664subprim .SPcallbuiltin3)
1109 (defx8664subprim .SPpopj)
1110 (defx8664subprim .SPrestorefullcontext)
1111 (defx8664subprim .SPsavecontextvsp)
1112 (defx8664subprim .SPsavecontext0)
1113 (defx8664subprim .SPrestorecontext)
1114 (defx8664subprim .SPlexpr-entry)
1115 (defx8664subprim .SPpoweropen-syscall)
1116 (defx8664subprim .SPbuiltin-plus)
1117 (defx8664subprim .SPbuiltin-minus)
1118 (defx8664subprim .SPbuiltin-times)
1119 (defx8664subprim .SPbuiltin-div)
1120 (defx8664subprim .SPbuiltin-eq)
1121 (defx8664subprim .SPbuiltin-ne)
1122 (defx8664subprim .SPbuiltin-gt)
1123 (defx8664subprim .SPbuiltin-ge)
1124 (defx8664subprim .SPbuiltin-lt)
1125 (defx8664subprim .SPbuiltin-le)
1126 (defx8664subprim .SPbuiltin-eql)
1127 (defx8664subprim .SPbuiltin-length)
1128 (defx8664subprim .SPbuiltin-seqtype)
1129 (defx8664subprim .SPbuiltin-assq)
1130 (defx8664subprim .SPbuiltin-memq)
1131 (defx8664subprim .SPbuiltin-logbitp)
1132 (defx8664subprim .SPbuiltin-logior)
1133 (defx8664subprim .SPbuiltin-logand)
1134 (defx8664subprim .SPbuiltin-ash)
1135 (defx8664subprim .SPbuiltin-negate)
1136 (defx8664subprim .SPbuiltin-logxor)
1137 (defx8664subprim .SPbuiltin-aref1)
1138 (defx8664subprim .SPbuiltin-aset1)
1139 (defx8664subprim .SPbreakpoint)
1140 (defx8664subprim .SPeabi-ff-call)
1141 (defx8664subprim .SPeabi-callback)
1142 (defx8664subprim .SPsyscall)
1143 (defx8664subprim .SPgetu64)
1144 (defx8664subprim .SPgets64)
1145 (defx8664subprim .SPmakeu64)
1146 (defx8664subprim .SPmakes64)
1147 (defx8664subprim .SPspecref)
1148 (defx8664subprim .SPspecset)
1149 (defx8664subprim .SPspecrefcheck)
1150 (defx8664subprim .SPrestoreintlevel)
1151 (defx8664subprim .SPmakes32)
1152 (defx8664subprim .SPmakeu32)
1153 (defx8664subprim .SPgets32)
1154 (defx8664subprim .SPgetu32)
1155 (defx8664subprim .SPfix-overflow)
1156 (defx8664subprim .SPmvpasssym)
1157 (defx8664subprim .SParef3)
1158 (defx8664subprim .SPaset3)
1159 (defx8664subprim .SPffcall-return-registers)
1160 (defx8664subprim .SPunused-5)
1161 (defx8664subprim .SPset-hash-key-conditional)
1162 (defx8664subprim .SPunbind-interrupt-level)
1163 (defx8664subprim .SPunbind)
1164 (defx8664subprim .SPunbind-n)
1165 (defx8664subprim .SPunbind-to)
1166 (defx8664subprim .SPbind-interrupt-level-m1)
1167 (defx8664subprim .SPbind-interrupt-level)
1168 (defx8664subprim .SPbind-interrupt-level-0)
1169 (defx8664subprim .SPprogvrestore)
1170 (defx8664subprim .SPnmkunwind)
1171
1172 )))))
1173
1174(defparameter *x8664-target-arch*
1175 (arch::make-target-arch :name :x8664
1176 :lisp-node-size 8
1177 :nil-value canonical-nil-value
1178 :fixnum-shift fixnumshift
1179 :most-positive-fixnum (1- (ash 1 (1- (- 64 fixnumshift))))
1180 :most-negative-fixnum (- (ash 1 (1- (- 64 fixnumshift))))
1181 :misc-data-offset misc-data-offset
1182 :misc-dfloat-offset misc-dfloat-offset
1183 :nbits-in-word 64
1184 :ntagbits 4
1185 :nlisptagbits 3
1186 :uvector-subtags *x8664-target-uvector-subtags*
1187 :max-64-bit-constant-index max-64-bit-constant-index
1188 :max-32-bit-constant-index max-32-bit-constant-index
1189 :max-16-bit-constant-index max-16-bit-constant-index
1190 :max-8-bit-constant-index max-8-bit-constant-index
1191 :max-1-bit-constant-index max-1-bit-constant-index
1192 :word-shift 3
1193 :code-vector-prefix nil
1194 :gvector-types '(:ratio :complex :symbol :function
1195 :catch-frame :struct :istruct
1196 :pool :population :hash-vector
1197 :package :value-cell :instance
1198 :lock :slot-vector
1199 :simple-vector)
1200 :1-bit-ivector-types '(:bit-vector)
1201 :8-bit-ivector-types '(:signed-8-bit-vector
1202 :unsigned-8-bit-vector)
1203 :16-bit-ivector-types '(:signed-16-bit-vector
1204 :unsigned-16-bit-vector)
1205 :32-bit-ivector-types '(:signed-32-bit-vector
1206 :unsigned-32-bit-vector
1207 :single-float-vector
1208 :double-float
1209 :bignum
1210 :simple-string)
1211 :64-bit-ivector-types '(:double-float-vector
1212 :complex-single-float-vector
1213 :unsigned-64-bit-vector
1214 :signed-64-bit-vector
1215 :fixnum-vector)
1216 :array-type-name-from-ctype-function
1217 #'x8664-array-type-name-from-ctype
1218 :package-name "X8664"
1219 :t-offset t-offset
1220 :array-data-size-function #'x8664-misc-byte-count
1221 :fpr-mask-function 'x86::fpr-mask
1222 :subprims-base x8664-subprims-base
1223 :subprims-shift x8664::*x8664-subprims-shift*
1224 :subprims-table x8664::*x8664-subprims*
1225 :primitive->subprims `(((0 . 23) . ,(ccl::%subprim-name->offset '.SPbuiltin-plus x8664::*x8664-subprims*)))
1226 :unbound-marker-value unbound-marker
1227 :slot-unbound-marker-value slot-unbound-marker
1228 :fixnum-tag tag-fixnum
1229 :single-float-tag subtag-single-float
1230 :single-float-tag-is-subtag nil
1231 :double-float-tag subtag-double-float
1232 :cons-tag fulltag-cons
1233 :null-tag fulltag-nil
1234 :symbol-tag fulltag-symbol
1235 :symbol-tag-is-subtag nil
1236 :function-tag fulltag-function
1237 :function-tag-is-subtag nil
1238 :big-endian nil
1239 :misc-subtag-offset misc-subtag-offset
1240 :car-offset cons.car
1241 :cdr-offset cons.cdr
1242 :subtag-char subtag-character
1243 :charcode-shift charcode-shift
1244 :fulltagmask fulltagmask
1245 :fulltag-misc fulltag-misc
1246 :char-code-limit #x110000
1247 ))
1248
1249;;; arch macros
1250(defmacro defx8664archmacro (name lambda-list &body body)
1251 `(arch::defarchmacro :x8664 ,name ,lambda-list ,@body))
1252
1253(defx8664archmacro ccl::%make-sfloat ()
1254 (error "~s shouldn't be used in code targeting :X8664" 'ccl::%make-sfloat))
1255
1256(defx8664archmacro ccl::%make-dfloat ()
1257 `(ccl::%alloc-misc x8664::double-float.element-count x8664::subtag-double-float))
1258
1259(defx8664archmacro ccl::%numerator (x)
1260 `(ccl::%svref ,x x8664::ratio.numer-cell))
1261
1262(defx8664archmacro ccl::%denominator (x)
1263 `(ccl::%svref ,x x8664::ratio.denom-cell))
1264
1265(defx8664archmacro ccl::%realpart (x)
1266 (let* ((thing (gensym)))
1267 `(let* ((,thing ,x))
1268 (case (ccl::typecode ,thing)
1269 (#.x8664::subtag-complex-single-float (ccl::%complex-single-float-realpart ,thing))
1270 (#.x8664::subtag-complex-double-float (ccl::%complex-double-float-realpart ,thing))
1271 (t (ccl::%svref ,thing x8664::complex.realpart-cell))))))
1272
1273(defx8664archmacro ccl::%imagpart (x)
1274 (let* ((thing (gensym)))
1275 `(let* ((,thing ,x))
1276 (case (ccl::typecode ,thing)
1277 (#.x8664::subtag-complex-single-float (ccl::%complex-single-float-imagpart ,thing))
1278 (#.x8664::subtag-complex-double-float (ccl::%complex-double-float-imagpart ,thing))
1279 (t (ccl::%svref ,thing x8664::complex.imagpart-cell))))))
1280
1281;;;
1282(defx8664archmacro ccl::%get-single-float-from-double-ptr (ptr offset)
1283 `(ccl::%double-float->short-float (ccl::%get-double-float ,ptr ,offset)))
1284
1285(defx8664archmacro ccl::codevec-header-p (word)
1286 (declare (ignore word))
1287 (error "~s makes no sense on :X8664" 'ccl::codevec-header-p))
1288
1289;;;
1290
1291(defx8664archmacro ccl::immediate-p-macro (thing)
1292 (let* ((tag (gensym)))
1293 `(let* ((,tag (ccl::lisptag ,thing)))
1294 (declare (type (unsigned-byte 3) ,tag))
1295 (logbitp ,tag (logior (ash 1 x8664::tag-fixnum)
1296 (ash 1 x8664::tag-imm-0)
1297 (ash 1 x8664::tag-imm-1))))))
1298
1299(defx8664archmacro ccl::hashed-by-identity (thing)
1300 (let* ((typecode (gensym)))
1301 `(let* ((,typecode (ccl::typecode ,thing)))
1302 (declare (fixnum ,typecode))
1303 (or (= ,typecode x8664::subtag-instance)
1304 (and (<= ,typecode x8664::fulltag-symbol)
1305 (logbitp (the (integer 0 #.x8664::fulltag-symbol) ,typecode)
1306 (logior (ash 1 x8664::tag-fixnum)
1307 (ash 1 x8664::tag-imm-0)
1308 (ash 1 x8664::tag-imm-1)
1309 (ash 1 x8664::fulltag-symbol))))))))
1310
1311;;;
1312(defx8664archmacro ccl::%get-kernel-global (name)
1313 `(ccl::%fixnum-ref 0 (+ ,(ccl::target-nil-value)
1314 ,(%kernel-global
1315 (if (ccl::quoted-form-p name)
1316 (cadr name)
1317 name)))))
1318
1319(defx8664archmacro ccl::%get-kernel-global-ptr (name dest)
1320 `(ccl::%setf-macptr
1321 ,dest
1322 (ccl::%int-to-ptr (ccl::%fixnum-ref-natural 0 (+ ,(ccl::target-nil-value)
1323 ,(%kernel-global
1324 (if (ccl::quoted-form-p name)
1325 (cadr name)
1326 name)))))))
1327
1328(defx8664archmacro ccl::%target-kernel-global (name)
1329 `(x8664::%kernel-global ,name))
1330
1331(defx8664archmacro ccl::lfun-vector (fun)
1332 `(ccl::%function-to-function-vector ,fun))
1333
1334(defx8664archmacro ccl::lfun-vector-lfun (lfv)
1335 `(ccl::%function-vector-to-function ,lfv))
1336
1337(defx8664archmacro ccl::area-code ()
1338 area.code)
1339
1340(defx8664archmacro ccl::area-succ ()
1341 area.succ)
1342
1343(defx8664archmacro ccl::nth-immediate (f i)
1344 `(ccl::%nth-immediate ,f (the fixnum (- (the fixnum ,i) 1))))
1345
1346(defx8664archmacro ccl::set-nth-immediate (f i new)
1347 `(ccl::%set-nth-immediate ,f (the fixnum (- (the fixnum ,i) 1)) ,new))
1348
1349(defx8664archmacro ccl::symptr->symvector (s)
1350 `(ccl::%symptr->symvector ,s))
1351
1352(defx8664archmacro ccl::symvector->symptr (s)
1353 `(ccl::%symvector->symptr ,s))
1354
1355(defx8664archmacro ccl::function-to-function-vector (f)
1356 `(ccl::%function-to-function-vector ,f))
1357
1358(defx8664archmacro ccl::function-vector-to-function (v)
1359 `(ccl::%function-vector-to-function ,v))
1360
1361(defx8664archmacro ccl::with-ffcall-results ((buf) &body body)
1362 ;; Reserve space for rax,rdx,xmm0,xmm1 only.
1363 (let* ((size (+ (* 2 8) (* 2 8))))
1364 `(ccl::%stack-block ((,buf ,size :clear t))
1365 ,@body)))
1366
1367;;; an (lea (@ disp (% rip)) (% fn)) instruction following a tagged
1368;;; return address helps the runtime map from the return address to
1369;;; the containing function. That instuction is 7 bytes long: 3
1370;;; bytes of code followed by 4 bytes of displacement. The constant
1371;;; part of that - assuming that FN is R13 - looks like #x4c #x8d #x2d.
1372
1373(defconstant recover-fn-from-rip-length 7)
1374(defconstant recover-fn-from-rip-disp-offset 3)
1375(defconstant recover-fn-from-rip-word0 #x8d4c)
1376(defconstant recover-fn-from-rip-byte2 #x2d)
1377
1378;;; For backtrace: the relative PC of an argument-check trap
1379;;; must be less than or equal to this value. (Because of
1380;;; the way that we do "anchored" UUOs, it should always be =.)
1381
1382(defconstant arg-check-trap-pc-limit 7)
1383
1384(defconstant fasl-version #x60)
1385(defconstant fasl-max-version #x60)
1386(defconstant fasl-min-version #x60)
1387(defparameter *image-abi-version* 1039)
1388
1389(provide "X8664-ARCH")
Note: See TracBrowser for help on using the repository browser.