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.
13 ;;; FIXME: Shouldn't these be IN-PACKAGE SB!KERNEL instead? (They're
14 ;;; not dependent on the OS, only on the CPU architecture.)
19 ;;;; primitive SAP operations
23 "Return T iff the SAP X points to a smaller address then the SAP Y."
24 (declare (type system-area-pointer x y))
29 "Return T iff the SAP X points to a smaller or the same address as
31 (declare (type system-area-pointer x y))
36 "Return T iff the SAP X points to the same address as the SAP Y."
37 (declare (type system-area-pointer x y))
42 "Return T iff the SAP X points to a larger or the same address as
44 (declare (type system-area-pointer x y))
49 "Return T iff the SAP X points to a larger address then the SAP Y."
50 (declare (type system-area-pointer x y))
53 (defun sap+ (sap offset)
55 "Return a new sap OFFSET bytes from SAP."
56 (declare (type system-area-pointer sap)
60 (defun sap- (sap1 sap2)
62 "Return the byte offset between SAP1 and SAP2."
63 (declare (type system-area-pointer sap1 sap2))
68 "Converts a System Area Pointer into an integer."
69 (declare (type system-area-pointer sap))
74 "Converts an integer into a System Area Pointer."
75 (declare (type sap-int-type int))
78 (defun sap-ref-8 (sap offset)
80 "Returns the 8-bit byte at OFFSET bytes from SAP."
81 (declare (type system-area-pointer sap)
83 (sap-ref-8 sap offset))
85 (defun sap-ref-16 (sap offset)
87 "Returns the 16-bit word at OFFSET bytes from SAP."
88 (declare (type system-area-pointer sap)
90 (sap-ref-16 sap offset))
92 (defun sap-ref-32 (sap offset)
94 "Returns the 32-bit dualword at OFFSET bytes from SAP."
95 (declare (type system-area-pointer sap)
97 (sap-ref-32 sap offset))
100 (defun sap-ref-64 (sap offset)
102 "Returns the 64-bit quadword at OFFSET bytes from SAP."
103 (declare (type system-area-pointer sap)
105 (sap-ref-64 sap offset))
107 (defun sap-ref-sap (sap offset)
109 "Returns the 32-bit system-area-pointer at OFFSET bytes from SAP."
110 (declare (type system-area-pointer sap)
112 (sap-ref-sap sap offset))
114 (defun sap-ref-single (sap offset)
116 "Returns the 32-bit single-float at OFFSET bytes from SAP."
117 (declare (type system-area-pointer sap)
119 (sap-ref-single sap offset))
121 (defun sap-ref-double (sap offset)
123 "Returns the 64-bit double-float at OFFSET bytes from SAP."
124 (declare (type system-area-pointer sap)
126 (sap-ref-double sap offset))
128 #!+(or x86 long-float)
129 (defun sap-ref-long (sap offset)
131 "Returns the long-float at OFFSET bytes from SAP."
132 (declare (type system-area-pointer sap)
134 (sap-ref-long sap offset))
136 (defun signed-sap-ref-8 (sap offset)
138 "Returns the signed 8-bit byte at OFFSET bytes from SAP."
139 (declare (type system-area-pointer sap)
141 (signed-sap-ref-8 sap offset))
143 (defun signed-sap-ref-16 (sap offset)
145 "Returns the signed 16-bit word at OFFSET bytes from SAP."
146 (declare (type system-area-pointer sap)
148 (signed-sap-ref-16 sap offset))
150 (defun signed-sap-ref-32 (sap offset)
152 "Returns the signed 32-bit dualword at OFFSET bytes from SAP."
153 (declare (type system-area-pointer sap)
155 (signed-sap-ref-32 sap offset))
158 (defun signed-sap-ref-64 (sap offset)
160 "Returns the signed 64-bit quadword at OFFSET bytes from SAP."
161 (declare (type system-area-pointer sap)
163 (signed-sap-ref-64 sap offset))
165 (defun %set-sap-ref-8 (sap offset new-value)
166 (declare (type system-area-pointer sap)
168 (type (unsigned-byte 8) new-value))
169 (setf (sap-ref-8 sap offset) new-value))
171 (defun %set-sap-ref-16 (sap offset new-value)
172 (declare (type system-area-pointer sap)
174 (type (unsigned-byte 16) new-value))
175 (setf (sap-ref-16 sap offset) new-value))
177 (defun %set-sap-ref-32 (sap offset new-value)
178 (declare (type system-area-pointer sap)
180 (type (unsigned-byte 32) new-value))
181 (setf (sap-ref-32 sap offset) new-value))
184 (defun %set-sap-ref-64 (sap offset new-value)
185 (declare (type system-area-pointer sap)
187 (type (unsigned-byte 64) new-value))
188 (setf (sap-ref-64 sap offset) new-value))
190 (defun %set-signed-sap-ref-8 (sap offset new-value)
191 (declare (type system-area-pointer sap)
193 (type (signed-byte 8) new-value))
194 (setf (signed-sap-ref-8 sap offset) new-value))
196 (defun %set-signed-sap-ref-16 (sap offset new-value)
197 (declare (type system-area-pointer sap)
199 (type (signed-byte 16) new-value))
200 (setf (signed-sap-ref-16 sap offset) new-value))
202 (defun %set-signed-sap-ref-32 (sap offset new-value)
203 (declare (type system-area-pointer sap)
205 (type (signed-byte 32) new-value))
206 (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-sap-ref-sap (sap offset new-value)
216 (declare (type system-area-pointer sap new-value)
218 (setf (sap-ref-sap sap offset) new-value))
220 (defun %set-sap-ref-single (sap offset new-value)
221 (declare (type system-area-pointer sap)
223 (type single-float new-value))
224 (setf (sap-ref-single sap offset) new-value))
226 (defun %set-sap-ref-double (sap offset new-value)
227 (declare (type system-area-pointer sap)
229 (type double-float new-value))
230 (setf (sap-ref-double sap offset) new-value))
233 (defun %set-sap-ref-long (sap offset new-value)
234 (declare (type system-area-pointer sap)
236 (type long-float new-value))
237 (setf (sap-ref-long sap offset) new-value))
239 ;;;; system memory allocation
241 (sb!alien:def-alien-routine ("os_allocate" allocate-system-memory)
243 (bytes sb!c-call:unsigned-long))
245 (sb!alien:def-alien-routine ("os_allocate_at" allocate-system-memory-at)
247 (address system-area-pointer)
248 (bytes sb!c-call:unsigned-long))
250 (sb!alien:def-alien-routine ("os_reallocate" reallocate-system-memory)
252 (old system-area-pointer)
253 (old-size sb!c-call:unsigned-long)
254 (new-size sb!c-call:unsigned-long))
256 (sb!alien:def-alien-routine ("os_deallocate" deallocate-system-memory)
258 (addr system-area-pointer)
259 (bytes sb!c-call:unsigned-long))