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

source: release/1.11/source/compiler/PPC/PPC64/ppc64-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: 38.2 KB
RevLine 
1;;;-*- Mode: Lisp; Package: (PPC64 :use CL) -*-
2;;;
3;;; Copyright 1994-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;;; This file matches "ccl:lisp-kernel;constants64.h" &
18;;; "ccl:lisp-kernel;constants64.s"
19
20(defpackage "PPC64"
21 (:use "CL")
22 #+ppc64-target
23 (:nicknames "TARGET"))
24
25
26(in-package "PPC64")
27
28(eval-when (:compile-toplevel :load-toplevel :execute)
29(defconstant rcontext 2) ;sigh. Could use r13+bias on Linux,
30 ; but Apple hasn't invented tls yet.
31(defconstant nbits-in-word 64)
32(defconstant least-significant-bit 63)
33(defconstant nbits-in-byte 8)
34(defconstant ntagbits 4)
35(defconstant nlisptagbits 3)
36(defconstant nfixnumtagbits 3) ; See ?
37(defconstant nlowtagbits 2)
38(defconstant num-subtag-bits 8) ; tag part of header is 8 bits wide
39(defconstant fixnumshift nfixnumtagbits)
40(defconstant fixnum-shift fixnumshift) ; A pet name for it.
41(defconstant fulltagmask (1- (ash 1 ntagbits))) ; Only needed by GC/very low-level code
42(defconstant full-tag-mask fulltagmask)
43(defconstant tagmask (1- (ash 1 nlisptagbits)))
44(defconstant tag-mask tagmask)
45(defconstant fixnummask (1- (ash 1 nfixnumtagbits)))
46(defconstant fixnum-mask fixnummask)
47(defconstant subtag-mask (1- (ash 1 num-subtag-bits)))
48(defconstant ncharcodebits 8) ;24
49(defconstant charcode-shift 8)
50(defconstant word-shift 3)
51(defconstant word-size-in-bytes 8)
52(defconstant node-size word-size-in-bytes)
53(defconstant dnode-size 16)
54(defconstant dnode-align-bits 4)
55(defconstant dnode-shift dnode-align-bits)
56(defconstant bitmap-shift 6)
57
58(defconstant target-most-negative-fixnum (ash -1 (1- (- nbits-in-word nfixnumtagbits))))
59(defconstant target-most-positive-fixnum (1- (ash 1 (1- (- nbits-in-word nfixnumtagbits)))))
60(defmacro define-subtag (name tag value)
61 `(defconstant ,(ccl::form-symbol "SUBTAG-" name) (logior ,tag (ash ,value ntagbits))))
62
63;;; PPC64 stuff and tags.
64
65;;; There are several ways to look at the 4 tag bits of any object or
66;;; header. Looking at the low 2 bits, we can classify things as
67;;; follows (I'm not sure if we'd ever want to do this) :
68;;;
69;;; #b00 a "primary" object: fixnum, cons, uvector
70;;; #b01 an immediate
71;;; #b10 the header on an immediate uvector
72;;; #b11 the header on a node (pointer-containing) uvector
73;;
74;;; Note that the ppc64's LD and STD instructions require that the low
75;;; two bits of the constant displacement be #b00. If we want to use constant
76;;; offsets to access CONS and UVECTOR fields, we're pretty much obligated
77;;; to ensure that CONS and UVECTOR have tags that also end in #b00, and
78;;; fixnum addition and subtraction work better when fixnum tags are all 0.
79;;; We generally have to look at all 4 tag bits before we really know what
80;;; class of "potentially primary" object we're looking at.
81;;; If we look at 3 tag bits, we can see:
82;;;
83;;; #b000 fixnum
84;;; #b001 immediate
85;;; #b010 immedate-header
86;;; #b011 node-header
87;;; #b100 CONS or UVECTOR
88;;; #b101 immediate
89;;; #b110 immediate-header
90;;; #b111 node-header
91;;;
92
93(defconstant tag-fixnum 0)
94(defconstant tag-imm-0 1)
95(defconstant tag-immheader-0 2)
96(defconstant tag-nodeheader-0 3)
97(defconstant tag-memory 4)
98(defconstant tag-imm-2 5)
99(defconstant tag-immheader2 6)
100(defconstant tag-nodeheader2 7)
101
102
103;;; Note how we're already winding up with lots of header and immediate
104;;; "classes". That might actually be useful.
105;;
106;;; When we move to 4 bits, we wind up (obviously) with 4 tags of the form
107;;; #bxx00. There are two partitionings that make (some) sense: we can either
108;;; use 2 of these for (even and odd) fixnums, or we can give NIL a tag
109;;; that's congruent (mod 16) with CONS. There seem to be a lot of tradeoffs
110;;; involved, but it ultimately seems best to be able to treat 64-bit
111;;; aligned addresses as fixnums: we don't want the VSP to look like a
112;;; vector. That basically requires that NIL really be a symbol (good
113;;; bye, nilsym) and that we ensure that there are NILs where its CAR and
114;;; CDR would be (-4, 4 bytes from the tagged pointer.) That means that
115;;; CONS is 4 and UVECTOR is 12, and we have even more immediate/header types.
116
117(defconstant fulltag-even-fixnum #b0000)
118(defconstant fulltag-imm-0 #b0001)
119(defconstant fulltag-immheader-0 #b0010)
120(defconstant fulltag-nodeheader-0 #b0011)
121(defconstant fulltag-cons #b0100)
122(defconstant fulltag-imm-1 #b0101)
123(defconstant fulltag-immheader-1 #b0110)
124(defconstant fulltag-nodeheader-1 #b0111)
125(defconstant fulltag-odd-fixnum #b1000)
126(defconstant fulltag-imm-2 #b1001)
127(defconstant fulltag-immheader-2 #b1010)
128(defconstant fulltag-nodeheader-2 #b1011)
129(defconstant fulltag-misc #b1100)
130(defconstant fulltag-imm-3 #b1101)
131(defconstant fulltag-immheader-3 #b1110)
132(defconstant fulltag-nodeheader-3 #b1111)
133
134(defconstant lowtagmask (1- (ash 1 nlowtagbits)))
135(defconstant lowtag-mask lowtagmask)
136(defconstant lowtag-primary 0)
137(defconstant lowtag-imm 1)
138(defconstant lowtag-immheader 2)
139(defconstant lowtag-nodeheader 3)
140
141;;; The general algorithm for determining the (primary) type of an
142;;; object is something like:
143;;; (clrldi tag node 60)
144;;; (cmpwi tag fulltag-misc)
145;;; (clrldi tag tag 61)
146;;; (bne @done)
147;;; (lbz tag misc-subtag-offset node)
148;;; @done
149;;
150;;; That's good enough to identify FIXNUM, "generally immediate", cons,
151;;; or a header tag from a UVECTOR. In some cases, we may need to hold
152;;; on to the full 4-bit tag.
153;;; In no specific order:
154;;; - it's important to be able to quickly recognize fixnums; that's
155;;; simple
156;;; - it's important to be able to quickly recognize lists (for CAR/CDR)
157;;; and somewhat important to be able to quickly recognize conses.
158;;; Also simple, though we have to special-case NIL.
159;;; - it's desirable to be able to do VECTORP, ARRAYP, and specific-array-type-
160;;; p. We need at least 12 immediate CL vector types (SIGNED/UNSIGNED-BYTE
161;;; 8/16/32/64, SINGLE-FLOAT, DOUBLE-FLOAT, BIT, and at least one CHARACTER;
162;;; we need SIMPLE-ARRAY, VECTOR-HEADER, and ARRAY-HEADER as node
163;;; array types. That's suspciciously close to 16
164;;; - it's desirable to be able (in FUNCALL) to quickly recognize
165;;; functions/symbols/other, and probably desirable to trap on other.
166;;; Pretty much have to do a memory reference and at least one comparison
167;;; here.
168;;; - it's sometimes desirable to recognize numbers and distinct numeric
169;;; types (other than FIXNUM) quickly.
170;;; - The GC (especially) needs to be able to determine the size of
171;;; ivectors (ivector elements) fairly cheaply. Most ivectors are CL
172;;; arrays, but code-vectors are fairly common (and have 32-bit elements,
173;;; naturally.)
174;;; - We have a fairly large number of non-array gvector types, and it's
175;;; always desirable to have room for expansion.
176;;; - we basically have 8 classes of header subtags, each of which has
177;;; 16 possible values. If we stole the high bit of the subtag to
178;;; indicate CL-array-ness, we'd still have 6 bits to encode non-CL
179;;; array types.
180
181(defconstant cl-array-subtag-bit 7)
182(defconstant cl-array-subtag-mask (ash 1 cl-array-subtag-bit))
183(defmacro define-cl-array-subtag (name tag value)
184 `(defconstant ,(ccl::form-symbol "SUBTAG-" name)
185 (logior cl-array-subtag-mask (logior ,tag (ash ,value ntagbits)))))
186
187(define-cl-array-subtag arrayH fulltag-nodeheader-1 0)
188(define-cl-array-subtag vectorH fulltag-nodeheader-2 0)
189(define-cl-array-subtag simple-vector fulltag-nodeheader-3 0)
190
191
192;;; bits: 64 32 16 8 1
193;;; CL-array ivector types DOUBLE-FLOAT SINGLE s16 CHAR BIT
194;;; s64 s32 u16 s8
195;;; u64 u32 u8
196;;; Other ivector types MACPTR CODE-VECTOR
197;;; DEAD-MACPTR XCODE-VECTOR
198;;; BIGNUM
199;;; DOUBLE-FLOAT
200;;; There might possibly be ivectors with 128-bit (VMX/AltiVec) elements
201;;; someday, and there might be multiple character sizes (16/32 bits).
202;;; That sort of suggests that we use the four immheader classes to
203;;; encode the ivector size (64, 32, 8, other) and make BIT an easily-
204;;; detected case of OTHER.
205
206(defconstant ivector-class-64-bit fulltag-immheader-3)
207(defconstant ivector-class-32-bit fulltag-immheader-2)
208(defconstant ivector-class-other-bit fulltag-immheader-1)
209(defconstant ivector-class-8-bit fulltag-immheader-0)
210
211(define-cl-array-subtag s64-vector ivector-class-64-bit 1)
212(define-cl-array-subtag u64-vector ivector-class-64-bit 2)
213(define-cl-array-subtag fixnum-vector ivector-class-64-bit 3)
214(define-cl-array-subtag double-float-vector ivector-class-64-bit 4)
215(define-cl-array-subtag complex-single-float-vector ivector-class-64-bit 5)
216(define-cl-array-subtag s32-vector ivector-class-32-bit 1)
217(define-cl-array-subtag u32-vector ivector-class-32-bit 2)
218(define-cl-array-subtag single-float-vector ivector-class-32-bit 3)
219(define-cl-array-subtag simple-base-string ivector-class-32-bit 5)
220(define-cl-array-subtag s16-vector ivector-class-other-bit 1)
221(define-cl-array-subtag u16-vector ivector-class-other-bit 2)
222(define-cl-array-subtag complex-double-float-vector ivector-class-other-bit 3)
223(define-cl-array-subtag bit-vector ivector-class-other-bit 7)
224(define-cl-array-subtag s8-vector ivector-class-8-bit 1)
225(define-cl-array-subtag u8-vector ivector-class-8-bit 2)
226
227(defconstant min-cl-ivector-subtag subtag-s8-vector)
228
229;;; There's some room for expansion in non-array ivector space.
230(define-subtag macptr ivector-class-64-bit 1)
231(define-subtag dead-macptr ivector-class-64-bit 2)
232
233(define-subtag code-vector ivector-class-32-bit 0)
234(define-subtag xcode-vector ivector-class-32-bit 1)
235(define-subtag bignum ivector-class-32-bit 2)
236(define-subtag double-float ivector-class-32-bit 3)
237(define-subtag complex-single-float ivector-class-32-bit 4)
238(define-subtag complex-double-float ivector-class-32-bit 5)
239
240;;; Size doesn't matter for non-CL-array gvectors; I can't think of a good
241;;; reason to classify them in any particular way. Let's put funcallable
242;;; things in the first slice by themselves, though it's not clear that
243;;; that helps FUNCALL much.
244(defconstant gvector-funcallable fulltag-nodeheader-0)
245(define-subtag function gvector-funcallable 0)
246(define-subtag symbol gvector-funcallable 1)
247
248(define-subtag catch-frame fulltag-nodeheader-1 0)
249(define-subtag basic-stream fulltag-nodeheader-1 1)
250(define-subtag lock fulltag-nodeheader-1 2)
251(define-subtag hash-vector fulltag-nodeheader-1 3)
252(define-subtag pool fulltag-nodeheader-1 4)
253(define-subtag weak fulltag-nodeheader-1 5)
254(define-subtag package fulltag-nodeheader-1 6)
255(define-subtag slot-vector fulltag-nodeheader-2 0)
256(define-subtag instance fulltag-nodeheader-2 1)
257(define-subtag struct fulltag-nodeheader-2 2)
258(define-subtag istruct fulltag-nodeheader-2 3)
259(define-subtag value-cell fulltag-nodeheader-2 4)
260(define-subtag xfunction fulltag-nodeheader-2 5)
261
262(define-subtag ratio fulltag-nodeheader-3 0)
263(define-subtag complex fulltag-nodeheader-3 1)
264
265
266
267(eval-when (:compile-toplevel :load-toplevel :execute)
268 (require "PPC-ARCH")
269 (defmacro define-storage-layout (name origin &rest cells)
270 `(progn
271 (ccl::defenum (:start ,origin :step 8)
272 ,@(mapcar #'(lambda (cell) (ccl::form-symbol name "." cell)) cells))
273 (defconstant ,(ccl::form-symbol name ".SIZE") ,(* (length cells)
274 8))))
275
276(defmacro define-lisp-object (name tagname &rest cells)
277 `(define-storage-layout ,name ,(- (symbol-value tagname)) ,@cells))
278
279
280
281(defmacro define-fixedsized-object (name &rest non-header-cells)
282 `(progn
283 (define-lisp-object ,name fulltag-misc header ,@non-header-cells)
284 (ccl::defenum ()
285 ,@(mapcar #'(lambda (cell) (ccl::form-symbol name "." cell "-CELL")) non-header-cells))
286 (defconstant ,(ccl::form-symbol name ".ELEMENT-COUNT") ,(length non-header-cells))))
287
288
289
290
291
292
293
294(defconstant misc-header-offset (- fulltag-misc))
295(defconstant misc-subtag-offset (+ misc-header-offset 7 ))
296(defconstant misc-data-offset (+ misc-header-offset 8))
297(defconstant misc-dfloat-offset (+ misc-header-offset 8))
298
299
300
301(define-subtag single-float fulltag-imm-0 0)
302
303(define-subtag character fulltag-imm-1 0)
304
305;;; FULLTAG-IMM-2 is unused, so the only type with lisptag (3-bit tag)
306;;; TAG-IMM-0 should be SINGLE-FLOAT.
307
308(define-subtag unbound fulltag-imm-3 0)
309(defconstant unbound-marker subtag-unbound)
310(defconstant undefined unbound-marker)
311(define-subtag slot-unbound fulltag-imm-3 1)
312(defconstant slot-unbound-marker subtag-slot-unbound)
313(define-subtag illegal fulltag-imm-3 2)
314(defconstant illegal-marker subtag-illegal)
315
316(define-subtag no-thread-local-binding fulltag-imm-3 3)
317(define-subtag forward-marker fulltag-imm-3 7)
318
319
320(defconstant max-64-bit-constant-index (ash (+ #x7fff ppc64::misc-dfloat-offset) -3))
321(defconstant max-32-bit-constant-index (ash (+ #x7fff ppc64::misc-data-offset) -2))
322(defconstant max-16-bit-constant-index (ash (+ #x7fff ppc64::misc-data-offset) -1))
323(defconstant max-8-bit-constant-index (+ #x7fff ppc64::misc-data-offset))
324(defconstant max-1-bit-constant-index (ash (+ #x7fff ppc64::misc-data-offset) 5))
325
326
327; The objects themselves look something like this:
328
329; Order of CAR and CDR doesn't seem to matter much - there aren't
330; too many tricks to be played with predecrement/preincrement addressing.
331; Keep them in the confusing MCL 3.0 order, to avoid confusion.
332(define-lisp-object cons fulltag-cons
333 cdr
334 car)
335
336
337(define-fixedsized-object ratio
338 numer
339 denom)
340
341;;; It's slightly easier (for bootstrapping reasons)
342;;; to view a DOUBLE-FLOAT as being UVECTOR with 2 32-bit elements
343;;; (rather than 1 64-bit element).
344
345(defconstant double-float.value misc-data-offset)
346(defconstant double-float.value-cell 0)
347(defconstant double-float.val-high double-float.value)
348(defconstant double-float.val-high-cell double-float.value-cell)
349(defconstant double-float.val-low (+ double-float.value 4))
350(defconstant double-float.val-low-cell 1)
351(defconstant double-float.element-count 2)
352(defconstant double-float.size 16)
353
354(define-fixedsized-object complex
355 realpart
356 imagpart
357)
358
359(define-fixedsized-object complex-single-float
360 value)
361
362(defconstant complex-single-float.realpart complex-single-float.value)
363(defconstant complex-single-float.imagpart (+ complex-single-float.value 4))
364
365(define-fixedsized-object complex-double-float
366 pad
367 realpart
368 imagpart)
369
370
371; There are two kinds of macptr; use the length field of the header if you
372; need to distinguish between them
373(define-fixedsized-object macptr
374 address
375 domain
376 type
377)
378
379(define-fixedsized-object xmacptr
380 address
381 domain
382 type
383 flags
384 link
385)
386
387; Catch frames go on the tstack; they point to a minimal lisp-frame
388; on the cstack. (The catch/unwind-protect PC is on the cstack, where
389; the GC expects to find it.)
390(define-fixedsized-object catch-frame
391 catch-tag ; #<unbound> -> unwind-protect, else catch
392 link ; tagged pointer to next older catch frame
393 mvflag ; 0 if single-value, 1 if uwp or multiple-value
394 csp ; pointer to control stack
395 db-link ; value of dynamic-binding link on thread entry.
396 save-save7 ; saved registers
397 save-save6
398 save-save5
399 save-save4
400 save-save3
401 save-save2
402 save-save1
403 save-save0
404 xframe ; exception-frame link
405 nfp
406)
407
408(define-fixedsized-object lock
409 _value ;finalizable pointer to kernel object
410 kind ; '0 = recursive-lock, '1 = rwlock
411 writer ;tcr of owning thread or 0
412 name
413 whostate
414 whostate-2
415 )
416
417
418
419(define-fixedsized-object symbol
420 pname
421 vcell
422 fcell
423 package-predicate
424 flags
425 plist
426 binding-index
427)
428
429
430(defconstant t-offset (- symbol.size))
431
432
433
434
435(define-fixedsized-object vectorH
436 logsize ; fillpointer if it has one, physsize otherwise
437 physsize ; total size of (possibly displaced) data vector
438 data-vector ; object this header describes
439 displacement ; true displacement or 0
440 flags ; has-fill-pointer,displaced-to,adjustable bits; subtype of underlying simple vector.
441)
442
443(define-lisp-object arrayH fulltag-misc
444 header ; subtag = subtag-arrayH
445 rank ; NEVER 1
446 physsize ; total size of (possibly displaced) data vector
447 data-vector ; object this header describes
448 displacement ; true displacement or 0
449 flags ; has-fill-pointer,displaced-to,adjustable bits; subtype of underlying simple vector.
450 ;; Dimensions follow
451)
452
453(defconstant arrayH.rank-cell 0)
454(defconstant arrayH.physsize-cell 1)
455(defconstant arrayH.data-vector-cell 2)
456(defconstant arrayH.displacement-cell 3)
457(defconstant arrayH.flags-cell 4)
458(defconstant arrayH.dim0-cell 5)
459
460(defconstant arrayH.flags-cell-bits-byte (byte 8 0))
461(defconstant arrayH.flags-cell-subtag-byte (byte 8 8))
462
463
464(define-fixedsized-object value-cell
465 value)
466
467
468;;; The kernel uses these (rather generically named) structures
469;;; to keep track of various memory regions it (or the lisp) is
470;;; interested in.
471
472
473(define-storage-layout area 0
474 pred ; pointer to preceding area in DLL
475 succ ; pointer to next area in DLL
476 low ; low bound on area addresses
477 high ; high bound on area addresses.
478 active ; low limit on stacks, high limit on heaps
479 softlimit ; overflow bound
480 hardlimit ; another one
481 code ; an area-code; see below
482 markbits ; bit vector for GC
483 ndnodes ; "active" size of dynamic area or stack
484 older ; in EGC sense
485 younger ; also for EGC
486 h ; Handle or null pointer
487 softprot ; protected_area structure pointer
488 hardprot ; another one.
489 owner ; fragment (library) which "owns" the area
490 refbits ; bitvector for intergenerational refernces
491 threshold ; for egc
492 gc-count ; generational gc count.
493 static-dnodes ; for honsing. etc
494 static-used ; bitvector
495)
496
497
498
499
500
501(define-storage-layout protected-area 0
502 next
503 start ; first byte (page-aligned) that might be protected
504 end ; last byte (page-aligned) that could be protected
505 nprot ; Might be 0
506 protsize ; number of bytes to protect
507 why)
508
509(defconstant tcr-bias 0)
510
511(define-storage-layout tcr (- tcr-bias)
512 prev ; in doubly-linked list
513 next ; in doubly-linked list
514 single-float-convert ; per-thread scratch space.
515 lisp-fpscr-high
516 db-link ; special binding chain head
517 catch-top ; top catch frame
518 save-vsp ; VSP when in foreign code
519 save-tsp ; TSP when in foreign code
520 cs-area ; cstack area pointer
521 vs-area ; vstack area pointer
522 ts-area ; tstack area pointer
523 cs-limit ; cstack overflow limit
524 total-bytes-allocated-high
525 log2-allocation-quantum ; unboxed
526 interrupt-pending ; fixnum
527 xframe ; exception frame linked list
528 errno-loc ; thread-private, maybe
529 ffi-exception ; fpscr bits from ff-call.
530 osid ; OS thread id
531 valence ; odd when in foreign code
532 foreign-exception-status
533 native-thread-info
534 native-thread-id
535 last-allocptr
536 save-allocptr
537 save-allocbase
538 reset-completion
539 activate
540 suspend-count
541 suspend-context
542 pending-exception-context
543 suspend ; semaphore for suspension notify
544 resume ; sempahore for resumption notify
545 flags ; foreign, being reset, ...
546 gc-context
547 termination-semaphore
548 unwinding
549 tlb-limit
550 tlb-pointer
551 shutdown-count
552 safe-ref-address
553 nfp
554)
555
556(defconstant interrupt-level-binding-index (ash 1 fixnumshift))
557
558(defconstant tcr.lisp-fpscr-low (+ tcr.lisp-fpscr-high 4))
559(defconstant tcr.total-bytes-allocated-low (+ tcr.total-bytes-allocated-high 4))
560
561(define-storage-layout lockptr 0
562 avail
563 owner
564 count
565 signal
566 waiting
567 malloced-ptr
568 spinlock)
569
570(define-storage-layout rwlock 0
571 spin
572 state
573 blocked-writers
574 blocked-readers
575 writer
576 reader-signal
577 writer-signal
578 malloced-ptr
579 )
580
581;;; For the eabi port: mark this stack frame as Lisp's (since EABI
582;;; foreign frames can be the same size as a lisp frame.)
583
584
585(ppc64::define-storage-layout lisp-frame 0
586 backlink
587 savefn
588 savelr
589 savevsp
590)
591
592(ppc64::define-storage-layout c-frame 0
593 backlink
594 crsave
595 savelr
596 unused-1
597 unused-2
598 savetoc
599 param0
600 param1
601 param2
602 param3
603 param4
604 param5
605 param6
606 param7
607)
608
609(defconstant c-frame.minsize c-frame.size)
610
611(defmacro define-header (name element-count subtag)
612 `(defconstant ,name (logior (ash ,element-count num-subtag-bits) ,subtag)))
613
614(define-header double-float-header double-float.element-count subtag-double-float)
615;;; We could possibly have a one-digit bignum header when dealing
616;;; with "small bignums" in some bignum code. Like other cases of
617;;; non-normalized bignums, they should never escape from the lab.
618(define-header one-digit-bignum-header 1 subtag-bignum)
619(define-header two-digit-bignum-header 2 subtag-bignum)
620(define-header three-digit-bignum-header 3 subtag-bignum)
621(define-header four-digit-bignum-header 4 subtag-bignum)
622(define-header five-digit-bignum-header 5 subtag-bignum)
623(define-header symbol-header symbol.element-count subtag-symbol)
624(define-header value-cell-header value-cell.element-count subtag-value-cell)
625(define-header macptr-header macptr.element-count subtag-macptr)
626
627
628
629)
630)
631
632
633
634
635
636
637(defun %kernel-global (sym)
638 (let* ((pos (position sym ppc::*ppc-kernel-globals* :test #'string=)))
639 (if pos
640 (- (+ symbol.size fulltag-misc (* (1+ pos) word-size-in-bytes)))
641 (error "Unknown kernel global : ~s ." sym))))
642
643(defmacro kernel-global (sym)
644 (let* ((pos (position sym ppc::*ppc-kernel-globals* :test #'string=)))
645 (if pos
646 (- (+ symbol.size fulltag-misc (* (1+ pos) word-size-in-bytes)))
647 (error "Unknown kernel global : ~s ." sym))))
648
649;;; The kernel imports things that are defined in various other
650;;; libraries for us. The objects in question are generally
651;;; fixnum-tagged; the entries in the "kernel-imports" vector are 8
652;;; bytes apart.
653(ccl::defenum (:prefix "KERNEL-IMPORT-" :start 0 :step word-size-in-bytes)
654 fd-setsize-bytes
655 do-fd-set
656 do-fd-clr
657 do-fd-is-set
658 do-fd-zero
659 MakeDataExecutable
660 GetSharedLibrary
661 FindSymbol
662 malloc
663 free
664 wait-for-signal
665 tcr-frame-ptr
666 register-xmacptr-dispose-function
667 open-debug-output
668 get-r-debug
669 restore-soft-stack-limit
670 egc-control
671 lisp-bug
672 NewThread
673 YieldToThread
674 DisposeThread
675 ThreadCurrentStackSpace
676 usage-exit
677 save-fp-context
678 restore-fp-context
679 put-altivec-registers
680 get-altivec-registers
681 new-semaphore
682 wait-on-semaphore
683 signal-semaphore
684 destroy-semaphore
685 new-recursive-lock
686 lock-recursive-lock
687 unlock-recursive-lock
688 destroy-recursive-lock
689 suspend-other-threads
690 resume-other-threads
691 suspend-tcr
692 resume-tcr
693 rwlock-new
694 rwlock-destroy
695 rwlock-rlock
696 rwlock-wlock
697 rwlock-unlock
698 recursive-lock-trylock
699 foreign-name-and-offset
700 lisp-read
701 lisp-write
702 lisp-open
703 lisp-fchmod
704 lisp-lseek
705 lisp-close
706 lisp-ftruncate
707 lisp-stat
708 lisp-fstat
709 lisp-futex
710 lisp-opendir
711 lisp-readdir
712 lisp-closedir
713 lisp-pipe
714 lisp-gettimeofday
715 lisp-sigexit
716 jvm-init
717)
718
719(defmacro nrs-offset (name)
720 (let* ((pos (position name ppc::*ppc-nilreg-relative-symbols* :test #'eq)))
721 (if pos (* (1- pos) symbol.size))))
722
723(defconstant canonical-nil-value (+ #x3000 symbol.size fulltag-misc))
724
725
726(defconstant reservation-discharge #x2008)
727
728(defparameter *ppc64-target-uvector-subtags*
729 `((:bignum . ,subtag-bignum)
730 (:ratio . ,subtag-ratio)
731 (:single-float . ,subtag-single-float)
732 (:double-float . ,subtag-double-float)
733 (:complex . ,subtag-complex )
734 (:complex-single-float . ,subtag-complex-single-float)
735 (:complex-double-float . ,subtag-complex-double-float)
736 (:symbol . ,subtag-symbol)
737 (:function . ,subtag-function )
738 (:code-vector . ,subtag-code-vector)
739 (:xcode-vector . ,subtag-xcode-vector)
740 (:macptr . ,subtag-macptr )
741 (:catch-frame . ,subtag-catch-frame)
742 (:struct . ,subtag-struct )
743 (:istruct . ,subtag-istruct )
744 (:pool . ,subtag-pool )
745 (:population . ,subtag-weak )
746 (:hash-vector . ,subtag-hash-vector )
747 (:package . ,subtag-package )
748 (:value-cell . ,subtag-value-cell)
749 (:instance . ,subtag-instance )
750 (:lock . ,subtag-lock )
751 (:basic-stream . ,subtag-basic-stream)
752 (:slot-vector . ,subtag-slot-vector)
753 (:simple-string . ,subtag-simple-base-string )
754 (:bit-vector . ,subtag-bit-vector )
755 (:signed-8-bit-vector . ,subtag-s8-vector )
756 (:unsigned-8-bit-vector . ,subtag-u8-vector )
757 (:signed-16-bit-vector . ,subtag-s16-vector )
758 (:unsigned-16-bit-vector . ,subtag-u16-vector )
759 (:signed-32-bit-vector . ,subtag-s32-vector )
760 (:unsigned-32-bit-vector . ,subtag-u32-vector )
761 (:fixnum-vector . ,subtag-fixnum-vector)
762 (:signed-64-bit-vector . ,subtag-s64-vector)
763 (:unsigned-64-bit-vector . ,subtag-u64-vector)
764 (:single-float-vector . ,subtag-single-float-vector)
765 (:double-float-vector . ,subtag-double-float-vector )
766 (:simple-vector . ,subtag-simple-vector )
767 (:complex-single-float-vector . ,subtag-complex-single-float-vector)
768 (:complex-double-float-vector . ,subtag-complex-double-float-vector)
769 (:vector-header . ,subtag-vectorH)
770 (:array-header . ,subtag-arrayH)
771 (:min-cl-ivector-subtag . ,min-cl-ivector-subtag)))
772
773;;; This should return NIL unless it's sure of how the indicated
774;;; type would be represented (in particular, it should return
775;;; NIL if the element type is unknown or unspecified at compile-time.
776(defun ppc64-array-type-name-from-ctype (ctype)
777 (when (typep ctype 'ccl::array-ctype)
778 (let* ((element-type (ccl::array-ctype-element-type ctype)))
779 (typecase element-type
780 (ccl::class-ctype
781 (let* ((class (ccl::class-ctype-class element-type)))
782 (if (or (eq class ccl::*character-class*)
783 (eq class ccl::*base-char-class*)
784 (eq class ccl::*standard-char-class*))
785 :simple-string
786 :simple-vector)))
787 (ccl::numeric-ctype
788 (if (eq (ccl::numeric-ctype-complexp element-type) :complex)
789 (case (ccl::numeric-ctype-format element-type)
790 (single-float :complex-single-float-vector)
791 (double-float :complex-double-float-vector)
792 (t :simple-vector))
793 (case (ccl::numeric-ctype-class element-type)
794 (integer
795 (let* ((low (ccl::numeric-ctype-low element-type))
796 (high (ccl::numeric-ctype-high element-type)))
797 (cond ((or (null low) (null high))
798 :simple-vector)
799 ((and (>= low 0) (<= high 1))
800 :bit-vector)
801 ((and (>= low 0) (<= high 255))
802 :unsigned-8-bit-vector)
803 ((and (>= low 0) (<= high 65535))
804 :unsigned-16-bit-vector)
805 ((and (>= low 0) (<= high #xffffffff))
806 :unsigned-32-bit-vector)
807 ((and (>= low 0) (<= high #xffffffffffffffff))
808 :unsigned-64-bit-vector)
809 ((and (>= low -128) (<= high 127))
810 :signed-8-bit-vector)
811 ((and (>= low -32768) (<= high 32767))
812 :signed-16-bit-vector)
813 ((and (>= low (ash -1 31)) (<= high (1- (ash 1 31))))
814 :signed-32-bit-vector)
815 ((and (>= low target-most-negative-fixnum)
816 (<= high target-most-positive-fixnum))
817 :fixnum-vector)
818 ((and (>= low (ash -1 63)) (<= high (1- (ash 1 63))))
819 :signed-64-bit-vector)
820 (t :simple-vector))))
821 (float
822 (case (ccl::numeric-ctype-format element-type)
823 ((double-float long-float) :double-float-vector)
824 ((single-float short-float) :single-float-vector)
825 (t :simple-vector)))
826 (t :simple-vector))))
827 (ccl::unknown-ctype)
828 (ccl::named-ctype
829 (if (eq element-type ccl::*universal-type*)
830 :simple-vector))
831 (t)))))
832
833(defun ppc64-misc-byte-count (subtag element-count)
834 (declare (fixnum subtag))
835 (if (= lowtag-nodeheader (logand subtag lowtagmask))
836 (ash element-count 3)
837 (case (logand subtag fulltagmask)
838 (#.ivector-class-64-bit (ash element-count 3))
839 (#.ivector-class-32-bit (ash element-count 2))
840 (#.ivector-class-8-bit element-count)
841 (t
842 (if (= subtag subtag-bit-vector)
843 (ash (+ 7 element-count) -3)
844 (if (= subtag subtag-complex-double-float-vector)
845 (ash element-count 4)
846 (ash element-count 1)))))))
847
848(defparameter *ppc64-target-arch*
849 (arch::make-target-arch :name :ppc64
850 :lisp-node-size 8
851 :nil-value canonical-nil-value
852 :fixnum-shift fixnumshift
853 :most-positive-fixnum (1- (ash 1 (1- (- 64 fixnumshift))))
854 :most-negative-fixnum (- (ash 1 (1- (- 64 fixnumshift))))
855 :misc-data-offset misc-data-offset
856 :misc-dfloat-offset misc-dfloat-offset
857 :nbits-in-word 64
858 :ntagbits 4
859 :nlisptagbits 3
860 :uvector-subtags *ppc64-target-uvector-subtags*
861 :max-64-bit-constant-index max-64-bit-constant-index
862 :max-32-bit-constant-index max-32-bit-constant-index
863 :max-16-bit-constant-index max-16-bit-constant-index
864 :max-8-bit-constant-index max-8-bit-constant-index
865 :max-1-bit-constant-index max-1-bit-constant-index
866 :word-shift 3
867 :code-vector-prefix '(#$"CODE")
868 :gvector-types '(:ratio :complex :symbol :function
869 :catch-frame :struct :istruct
870 :pool :population :hash-vector
871 :package :value-cell :instance
872 :lock :slot-vector
873 :simple-vector)
874 :1-bit-ivector-types '(:bit-vector)
875 :8-bit-ivector-types '(:signed-8-bit-vector
876 :unsigned-8-bit-vector)
877 :16-bit-ivector-types '(:signed-16-bit-vector
878 :unsigned-16-bit-vector)
879 :32-bit-ivector-types '(:signed-32-bit-vector
880 :unsigned-32-bit-vector
881 :single-float-vector
882 :double-float
883 :bignum
884 :simple-string)
885 :64-bit-ivector-types '(:double-float-vector
886 :unsigned-64-bit-vector
887 :signed-64-bit-vector
888 :complex-single-float-vector
889 :fixnum-vector)
890 :array-type-name-from-ctype-function
891 #'ppc64-array-type-name-from-ctype
892 :package-name "PPC64"
893 :t-offset t-offset
894 :array-data-size-function #'ppc64-misc-byte-count
895 :fpr-mask-function 'ppc::fpr-mask
896 :subprims-base ppc::*ppc-subprims-base*
897 :subprims-shift ppc::*ppc-subprims-shift*
898 :subprims-table ppc::*ppc-subprims*
899 :primitive->subprims `(((0 . 23) . ,(ccl::%subprim-name->offset '.SPbuiltin-plus ppc::*ppc-subprims*)))
900 :unbound-marker-value unbound-marker
901 :slot-unbound-marker-value slot-unbound-marker
902 :fixnum-tag tag-fixnum
903 :single-float-tag subtag-single-float
904 :single-float-tag-is-subtag nil
905 :double-float-tag subtag-double-float
906 :cons-tag fulltag-cons
907 :null-tag subtag-symbol
908 :symbol-tag subtag-symbol
909 :symbol-tag-is-subtag t
910 :function-tag subtag-function
911 :function-tag-is-subtag t
912 :big-endian t
913 :misc-subtag-offset misc-subtag-offset
914 :car-offset cons.car
915 :cdr-offset cons.cdr
916 :subtag-char subtag-character
917 :charcode-shift charcode-shift
918 :fulltagmask fulltagmask
919 :fulltag-misc fulltag-misc
920 :char-code-limit #x110000
921 ))
922
923;;; arch macros
924(defmacro defppc64archmacro (name lambda-list &body body)
925 `(arch::defarchmacro :ppc64 ,name ,lambda-list ,@body))
926
927(defppc64archmacro ccl::%make-sfloat ()
928 (error "~s shouldn't be used in code targeting :PPC64" 'ccl::%make-sfloat))
929
930(defppc64archmacro ccl::%make-dfloat ()
931 `(ccl::%alloc-misc ppc64::double-float.element-count ppc64::subtag-double-float))
932
933(defppc64archmacro ccl::%numerator (x)
934 `(ccl::%svref ,x ppc64::ratio.numer-cell))
935
936(defppc64archmacro ccl::%denominator (x)
937 `(ccl::%svref ,x ppc64::ratio.denom-cell))
938
939(defppc64archmacro ccl::%realpart (x)
940 (let* ((thing (gensym)))
941 `(let* ((,thing ,x))
942 (case (ccl::typecode ,thing)
943 (#.ppc64::subtag-complex-single-float (ccl::%complex-single-float-realpart ,thing))
944 (#.ppc64::subtag-complex-double-float (ccl::%complex-double-float-realpart ,thing))
945 (t (ccl::%svref ,thing ppc64::complex.realpart-cell))))))
946
947(defppc64archmacro ccl::%imagpart (x)
948 (let* ((thing (gensym)))
949 `(let* ((,thing ,x))
950 (case (ccl::typecode ,thing)
951 (#.ppc64::subtag-complex-single-float (ccl::%complex-single-float-imagpart ,thing))
952 (#.ppc64::subtag-complex-double-float (ccl::%complex-double-float-imagpart ,thing))
953 (t (ccl::%svref ,thing ppc64::complex.imagpart-cell))))))
954
955;;;
956(defppc64archmacro ccl::%get-single-float-from-double-ptr (ptr offset)
957 `(ccl::%double-float->short-float (ccl::%get-double-float ,ptr ,offset)))
958
959(defppc64archmacro ccl::codevec-header-p (word)
960 `(eql ,word #$"CODE"))
961
962;;;
963
964(defppc64archmacro ccl::immediate-p-macro (thing)
965 (let* ((tag (gensym)))
966 `(let* ((,tag (ccl::lisptag ,thing)))
967 (declare (fixnum ,tag))
968 (or (= ,tag ppc64::tag-fixnum)
969 (= (logand ,tag ppc64::lowtagmask) ppc64::lowtag-imm)))))
970
971(defppc64archmacro ccl::hashed-by-identity (thing)
972 (let* ((typecode (gensym)))
973 `(let* ((,typecode (ccl::typecode ,thing)))
974 (declare (fixnum ,typecode))
975 (or
976 (= ,typecode ppc64::tag-fixnum)
977 (= (logand ,typecode ppc64::lowtagmask) ppc64::lowtag-imm)
978 (= ,typecode ppc64::subtag-symbol)
979 (= ,typecode ppc64::subtag-instance)))))
980
981;;;
982(defppc64archmacro ccl::%get-kernel-global (name)
983 `(ccl::%fixnum-ref 0 (+ ,(ccl::target-nil-value)
984 ,(%kernel-global
985 (if (ccl::quoted-form-p name)
986 (cadr name)
987 name)))))
988
989(defppc64archmacro ccl::%get-kernel-global-ptr (name dest)
990 `(ccl::%setf-macptr
991 ,dest
992 (ccl::%fixnum-ref-macptr 0 (+ ,(ccl::target-nil-value)
993 ,(%kernel-global
994 (if (ccl::quoted-form-p name)
995 (cadr name)
996 name))))))
997
998(defppc64archmacro ccl::%target-kernel-global (name)
999 `(ppc64::%kernel-global ,name))
1000
1001(defppc64archmacro ccl::lfun-vector (fn)
1002 fn)
1003
1004(defppc64archmacro ccl::lfun-vector-lfun (lfv)
1005 lfv)
1006
1007(defppc64archmacro ccl::area-code ()
1008 area.code)
1009
1010(defppc64archmacro ccl::area-succ ()
1011 area.succ)
1012
1013
1014(defppc64archmacro ccl::nth-immediate (f i)
1015 `(ccl::%svref ,f ,i))
1016
1017(defppc64archmacro ccl::set-nth-immediate (f i new)
1018 `(setf (ccl::%svref ,f ,i) ,new))
1019
1020
1021(defppc64archmacro ccl::symptr->symvector (s)
1022 s)
1023
1024(defppc64archmacro ccl::symvector->symptr (s)
1025 s)
1026
1027(defppc64archmacro ccl::function-to-function-vector (f)
1028 f)
1029
1030(defppc64archmacro ccl::function-vector-to-function (v)
1031 v)
1032
1033(defppc64archmacro ccl::with-ffcall-results ((buf) &body body)
1034 (let* ((size (+ (* 8 8) (* 13 8))))
1035 `(ccl::%stack-block ((,buf ,size))
1036 ,@body)))
1037
1038(defconstant arg-check-trap-pc-limit 8)
1039
1040(defconstant fasl-version #x60)
1041(defconstant fasl-max-version #x60)
1042(defconstant fasl-min-version #x60)
1043(defparameter *image-abi-version* 1040)
1044
1045(provide "PPC64-ARCH")
Note: See TracBrowser for help on using the repository browser.