1 ;;; -*- Package: PPC -*-
3 ;;; **********************************************************************
4 ;;; This code was written as part of the CMU Common Lisp project at
5 ;;; Carnegie Mellon University, and has been placed in the public domain.
6 ;;; If you want to use this code or any part of CMU Common Lisp, please contact
7 ;;; Scott Fahlman or slisp-group@cs.cmu.edu.
10 "$Header: src/compiler/ppc/system.lisp $")
12 ;;; **********************************************************************
14 ;;; PPC VM definitions of various system hacking operations.
16 ;;; Written by Rob MacLachlan
18 ;;; Mips conversion by William Lott and Christopher Hoover.
24 ;;;; Type frobbing VOPs
26 (define-vop (get-lowtag)
27 (:translate get-lowtag)
29 (:args (object :scs (any-reg descriptor-reg)))
30 (:results (result :scs (unsigned-reg)))
31 (:result-types positive-fixnum)
33 (inst andi. result object vm:lowtag-mask)))
35 (define-vop (get-type)
38 (:args (object :scs (descriptor-reg) :to (:eval 1)))
39 (:results (result :scs (unsigned-reg) :from (:eval 0)))
40 (:result-types positive-fixnum)
43 (inst andi. result object lowtag-mask)
44 ;; Check for various pointer types.
45 (inst cmpwi result list-pointer-type)
47 (inst cmpwi result other-pointer-type)
48 (inst beq other-pointer)
49 (inst cmpwi result function-pointer-type)
50 (inst beq function-pointer)
51 (inst cmpwi result instance-pointer-type)
53 ;; Okay, it is an immediate. If fixnum, we want zero. Otherwise,
54 ;; we want the low 8 bits.
55 (inst andi. result object #b11)
57 ;; It wasn't a fixnum, so get the low 8 bits.
58 (inst andi. result object type-mask)
62 (load-type result object (- function-pointer-type))
66 (load-type result object (- other-pointer-type))
71 (define-vop (function-subtype)
72 (:translate function-subtype)
74 (:args (function :scs (descriptor-reg)))
75 (:results (result :scs (unsigned-reg)))
76 (:result-types positive-fixnum)
78 (load-type result function (- vm:function-pointer-type))))
80 (define-vop (set-function-subtype)
81 (:translate (setf function-subtype))
83 (:args (type :scs (unsigned-reg) :target result)
84 (function :scs (descriptor-reg)))
85 (:arg-types positive-fixnum *)
86 (:results (result :scs (unsigned-reg)))
87 (:result-types positive-fixnum)
89 (inst stb type function (- 3 function-pointer-type))
92 (define-vop (get-header-data)
93 (:translate get-header-data)
95 (:args (x :scs (descriptor-reg)))
96 (:results (res :scs (unsigned-reg)))
97 (:result-types positive-fixnum)
99 (loadw res x 0 vm:other-pointer-type)
100 (inst srwi res res vm:type-bits)))
102 (define-vop (get-closure-length)
103 (:translate get-closure-length)
105 (:args (x :scs (descriptor-reg)))
106 (:results (res :scs (unsigned-reg)))
107 (:result-types positive-fixnum)
109 (loadw res x 0 vm:function-pointer-type)
110 (inst srwi res res vm:type-bits)))
112 (define-vop (set-header-data)
113 (:translate set-header-data)
115 (:args (x :scs (descriptor-reg) :target res)
116 (data :scs (any-reg immediate zero)))
117 (:arg-types * positive-fixnum)
118 (:results (res :scs (descriptor-reg)))
119 (:temporary (:scs (non-descriptor-reg)) t1 t2)
121 (loadw t1 x 0 vm:other-pointer-type)
122 (inst andi. t1 t1 vm:type-mask)
125 (inst slwi t2 data (- vm:type-bits 2))
128 (inst ori t1 t1 (ash (tn-value data) vm:type-bits)))
130 (storew t1 x 0 vm:other-pointer-type)
134 (define-vop (make-fixnum)
135 (:args (ptr :scs (any-reg descriptor-reg)))
136 (:results (res :scs (any-reg descriptor-reg)))
139 ;; Some code (the hash table code) depends on this returning a
140 ;; positive number so make sure it does.
141 (inst slwi res ptr 3)
142 (inst srwi res res 1)))
144 (define-vop (make-other-immediate-type)
145 (:args (val :scs (any-reg descriptor-reg))
146 (type :scs (any-reg descriptor-reg immediate)
148 (:results (res :scs (any-reg descriptor-reg)))
149 (:temporary (:scs (non-descriptor-reg)) temp)
153 (inst slwi temp val vm:type-bits)
154 (inst ori res temp (tn-value type)))
156 (inst srawi temp type 2)
157 (inst slwi res val (- vm:type-bits 2))
158 (inst or res res temp)))))
163 (define-vop (dynamic-space-free-pointer)
164 (:results (int :scs (sap-reg)))
165 (:result-types system-area-pointer)
166 (:translate dynamic-space-free-pointer)
169 (move int alloc-tn)))
171 (define-vop (binding-stack-pointer-sap)
172 (:results (int :scs (sap-reg)))
173 (:result-types system-area-pointer)
174 (:translate binding-stack-pointer-sap)
179 (define-vop (control-stack-pointer-sap)
180 (:results (int :scs (sap-reg)))
181 (:result-types system-area-pointer)
182 (:translate control-stack-pointer-sap)
188 ;;;; Code object frobbing.
190 (define-vop (code-instructions)
191 (:translate code-instructions)
193 (:args (code :scs (descriptor-reg)))
194 (:temporary (:scs (non-descriptor-reg)) ndescr)
195 (:results (sap :scs (sap-reg)))
196 (:result-types system-area-pointer)
198 (loadw ndescr code 0 vm:other-pointer-type)
199 (inst srwi ndescr ndescr vm:type-bits)
200 (inst slwi ndescr ndescr vm:word-shift)
201 (inst subi ndescr ndescr vm:other-pointer-type)
202 (inst add sap code ndescr)))
204 (define-vop (compute-function)
205 (:args (code :scs (descriptor-reg))
206 (offset :scs (signed-reg unsigned-reg)))
207 (:arg-types * positive-fixnum)
208 (:results (func :scs (descriptor-reg)))
209 (:temporary (:scs (non-descriptor-reg)) ndescr)
211 (loadw ndescr code 0 vm:other-pointer-type)
212 (inst srwi ndescr ndescr vm:type-bits)
213 (inst slwi ndescr ndescr vm:word-shift)
214 (inst add ndescr ndescr offset)
215 (inst addi ndescr ndescr (- vm:function-pointer-type vm:other-pointer-type))
216 (inst add func code ndescr)))
220 ;;;; Other random VOPs.
223 (defknown unix::do-pending-interrupt () (values))
224 (define-vop (unix::do-pending-interrupt)
226 (:translate unix::do-pending-interrupt)
228 (inst unimp pending-interrupt-trap)))
233 (inst unimp halt-trap)))
237 ;;;; Dynamic vop count collection support
239 (define-vop (count-me)
240 (:args (count-vector :scs (descriptor-reg)))
242 (:temporary (:scs (non-descriptor-reg)) count)
245 (- (* (+ index vector-data-offset) word-bytes) other-pointer-type)))
246 (assert (typep offset '(signed-byte 16)))
247 (inst lwz count count-vector offset)
248 (inst addi count count 1)
249 (inst stw count count-vector offset))))
251 (defknown read-time-base ()
252 (values (unsigned-byte 32) (unsigned-byte 32)))
254 (define-vop (read-time-base)
255 (:translate read-time-base)
258 (:results (lo :scs (unsigned-reg))
259 (hi :scs (unsigned-reg)))
260 (:result-types unsigned-num unsigned-num)
261 (:temporary (:sc unsigned-reg) temp)
262 (:temporary (:sc unsigned-reg :target hi) temp-hi)
263 (:temporary (:sc unsigned-reg :target lo) temp-lo)
266 (let ((loop (gen-label)))
271 (inst cmpw temp temp-hi)
276 (defun read-cycle-counter ()