1 ;;;; support for System Area Pointers (SAPs) in the target machine
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
12 (in-package "SB!KERNEL")
14 ;;; Return T iff the SAP X points to a smaller address then the SAP Y.
16 (declare (type system-area-pointer x y))
19 ;;; Return T iff the SAP X points to a smaller or the same address as
22 (declare (type system-area-pointer x y))
25 ;;; Return T iff the SAP X points to the same address as the SAP Y.
27 (declare (type system-area-pointer x y))
30 ;;; Return T iff the SAP X points to a larger or the same address as
33 (declare (type system-area-pointer x y))
36 ;;; Return T iff the SAP X points to a larger address then the SAP Y.
38 (declare (type system-area-pointer x y))
41 ;;; Return a new SAP, OFFSET bytes from SAP.
42 (defun sap+ (sap offset)
43 (declare (type system-area-pointer sap)
44 (type (signed-byte #.sb!vm:n-word-bits) offset))
47 ;;; Return the byte offset between SAP1 and SAP2.
48 (defun sap- (sap1 sap2)
49 (declare (type system-area-pointer sap1 sap2))
52 ;;; Convert SAP into an integer.
54 (declare (type system-area-pointer sap))
57 ;;; Convert an integer into a SAP.
59 (declare (type sap-int int))
62 ;;; Return the 8-bit byte at OFFSET bytes from SAP.
63 (defun sap-ref-8 (sap offset)
64 (declare (type system-area-pointer sap)
66 (sap-ref-8 sap offset))
68 (defun sap-ref-octets (sap offset count)
69 (declare (type system-area-pointer sap)
70 (fixnum offset count))
71 (let ((buffer (make-array count :element-type '(unsigned-byte 8))))
73 (setf (aref buffer i) (sap-ref-8 sap (+ offset i))))
76 ;;; Return the 16-bit word at OFFSET bytes from SAP.
77 (defun sap-ref-16 (sap offset)
78 (declare (type system-area-pointer sap)
80 (sap-ref-16 sap offset))
82 ;;; Returns the 32-bit dualword at OFFSET bytes from SAP.
83 (defun sap-ref-32 (sap offset)
84 (declare (type system-area-pointer sap)
86 (sap-ref-32 sap offset))
88 ;;; Return the 64-bit quadword at OFFSET bytes from SAP.
89 (defun sap-ref-64 (sap offset)
90 (declare (type system-area-pointer sap)
92 (sap-ref-64 sap offset))
94 ;;; Return the unsigned word of natural size OFFSET bytes from SAP.
95 (defun sap-ref-word (sap offset)
96 (declare (type system-area-pointer sap)
98 (sap-ref-word sap offset))
100 ;;; Return the 32-bit SAP at OFFSET bytes from SAP.
101 (defun sap-ref-sap (sap offset)
102 (declare (type system-area-pointer sap)
104 (sap-ref-sap sap offset))
106 ;; Return the LISPOBJ at OFFSET bytes from SAP.
107 (defun sap-ref-lispobj (sap offset)
108 (declare (type system-area-pointer sap)
110 (sap-ref-lispobj sap offset))
112 ;;; Return the 32-bit SINGLE-FLOAT at OFFSET bytes from SAP.
113 (defun sap-ref-single (sap offset)
114 (declare (type system-area-pointer sap)
116 (sap-ref-single sap offset))
118 ;;; Return the 64-bit DOUBLE-FLOAT at OFFSET bytes from SAP.
119 (defun sap-ref-double (sap offset)
120 (declare (type system-area-pointer sap)
122 (sap-ref-double sap offset))
124 ;;; Return the LONG-FLOAT at OFFSET bytes from SAP.
125 #!+(or x86 long-float)
126 (defun sap-ref-long (sap offset)
127 (declare (type system-area-pointer sap)
129 (sap-ref-long sap offset))
131 ;;; Return the signed 8-bit byte at OFFSET bytes from SAP.
132 (defun signed-sap-ref-8 (sap offset)
133 (declare (type system-area-pointer sap)
135 (signed-sap-ref-8 sap offset))
137 ;;; Return the signed 16-bit word at OFFSET bytes from SAP.
138 (defun signed-sap-ref-16 (sap offset)
139 (declare (type system-area-pointer sap)
141 (signed-sap-ref-16 sap offset))
143 ;;; Return the signed 32-bit dualword at OFFSET bytes from SAP.
144 (defun signed-sap-ref-32 (sap offset)
145 (declare (type system-area-pointer sap)
147 (signed-sap-ref-32 sap offset))
149 ;;; Return the signed 64-bit quadword at OFFSET bytes from SAP.
150 (defun signed-sap-ref-64 (sap offset)
151 (declare (type system-area-pointer sap)
153 (signed-sap-ref-64 sap offset))
155 ;;; Return the signed word of natural size OFFSET bytes from SAP.
156 (defun signed-sap-ref-word (sap offset)
157 (declare (type system-area-pointer sap)
159 (signed-sap-ref-word sap offset))
161 (defun %set-sap-ref-8 (sap offset new-value)
162 (declare (type system-area-pointer sap)
164 (type (unsigned-byte 8) new-value))
165 (setf (sap-ref-8 sap offset) new-value))
167 (defun %set-sap-ref-16 (sap offset new-value)
168 (declare (type system-area-pointer sap)
170 (type (unsigned-byte 16) new-value))
171 (setf (sap-ref-16 sap offset) new-value))
173 (defun %set-sap-ref-32 (sap offset new-value)
174 (declare (type system-area-pointer sap)
176 (type (unsigned-byte 32) new-value))
177 (setf (sap-ref-32 sap offset) new-value))
179 (defun %set-sap-ref-64 (sap offset new-value)
180 (declare (type system-area-pointer sap)
182 (type (unsigned-byte 64) new-value))
183 (setf (sap-ref-64 sap offset) new-value))
185 (defun %set-sap-ref-word (sap offset new-value)
186 (declare (type system-area-pointer sap)
188 (type (unsigned-byte #.sb!vm:n-machine-word-bits) new-value))
189 (setf (sap-ref-word sap offset) new-value))
191 (defun %set-signed-sap-ref-8 (sap offset new-value)
192 (declare (type system-area-pointer sap)
194 (type (signed-byte 8) new-value))
195 (setf (signed-sap-ref-8 sap offset) new-value))
197 (defun %set-signed-sap-ref-16 (sap offset new-value)
198 (declare (type system-area-pointer sap)
200 (type (signed-byte 16) new-value))
201 (setf (signed-sap-ref-16 sap offset) new-value))
203 (defun %set-signed-sap-ref-32 (sap offset new-value)
204 (declare (type system-area-pointer sap)
206 (type (signed-byte 32) new-value))
207 (setf (signed-sap-ref-32 sap offset) new-value))
209 (defun %set-signed-sap-ref-64 (sap offset new-value)
210 (declare (type system-area-pointer sap)
212 (type (signed-byte 64) new-value))
213 (setf (signed-sap-ref-64 sap offset) new-value))
215 (defun %set-signed-sap-ref-word (sap offset new-value)
216 (declare (type system-area-pointer sap)
218 (type (signed-byte #.sb!vm:n-machine-word-bits) new-value))
219 (setf (signed-sap-ref-word sap offset) new-value))
221 (defun %set-sap-ref-sap (sap offset new-value)
222 (declare (type system-area-pointer sap new-value)
224 (setf (sap-ref-sap sap offset) new-value))
226 (defun %set-sap-ref-lispobj (sap offset new-value)
227 (declare (type system-area-pointer sap)
230 (setf (sap-ref-lispobj sap offset) new-value))
232 (defun %set-sap-ref-single (sap offset new-value)
233 (declare (type system-area-pointer sap)
235 (type single-float new-value))
236 (setf (sap-ref-single sap offset) new-value))
238 (defun %set-sap-ref-double (sap offset new-value)
239 (declare (type system-area-pointer sap)
241 (type double-float new-value))
242 (setf (sap-ref-double sap offset) new-value))
245 (defun %set-sap-ref-long (sap offset new-value)
246 (declare (type system-area-pointer sap)
248 (type long-float new-value))
249 (setf (sap-ref-long sap offset) new-value))