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.)
16 ;;;; primitive SAP operations
20 "Return T iff the SAP X points to a smaller address then the SAP Y."
21 (declare (type system-area-pointer x y))
26 "Return T iff the SAP X points to a smaller or the same address as
28 (declare (type system-area-pointer x y))
33 "Return T iff the SAP X points to the same address as the SAP Y."
34 (declare (type system-area-pointer x y))
39 "Return T iff the SAP X points to a larger or the same address as
41 (declare (type system-area-pointer x y))
46 "Return T iff the SAP X points to a larger address then the SAP Y."
47 (declare (type system-area-pointer x y))
50 (defun sap+ (sap offset)
52 "Return a new sap OFFSET bytes from SAP."
53 (declare (type system-area-pointer sap)
57 (defun sap- (sap1 sap2)
59 "Return the byte offset between SAP1 and SAP2."
60 (declare (type system-area-pointer sap1 sap2))
65 "Converts a System Area Pointer into an integer."
66 (declare (type system-area-pointer sap))
71 "Converts an integer into a System Area Pointer."
72 (declare (type sap-int-type int))
75 (defun sap-ref-8 (sap offset)
77 "Returns the 8-bit byte at OFFSET bytes from SAP."
78 (declare (type system-area-pointer sap)
80 (sap-ref-8 sap offset))
82 (defun sap-ref-16 (sap offset)
84 "Returns the 16-bit word at OFFSET bytes from SAP."
85 (declare (type system-area-pointer sap)
87 (sap-ref-16 sap offset))
89 (defun sap-ref-32 (sap offset)
91 "Returns the 32-bit dualword at OFFSET bytes from SAP."
92 (declare (type system-area-pointer sap)
94 (sap-ref-32 sap offset))
97 (defun sap-ref-64 (sap offset)
99 "Returns the 64-bit quadword at OFFSET bytes from SAP."
100 (declare (type system-area-pointer sap)
102 (sap-ref-64 sap offset))
104 (defun sap-ref-sap (sap offset)
106 "Returns the 32-bit system-area-pointer at OFFSET bytes from SAP."
107 (declare (type system-area-pointer sap)
109 (sap-ref-sap sap offset))
111 (defun sap-ref-single (sap offset)
113 "Returns the 32-bit single-float at OFFSET bytes from SAP."
114 (declare (type system-area-pointer sap)
116 (sap-ref-single sap offset))
118 (defun sap-ref-double (sap offset)
120 "Returns the 64-bit double-float at OFFSET bytes from SAP."
121 (declare (type system-area-pointer sap)
123 (sap-ref-double sap offset))
125 #!+(or x86 long-float)
126 (defun sap-ref-long (sap offset)
128 "Returns the long-float at OFFSET bytes from SAP."
129 (declare (type system-area-pointer sap)
131 (sap-ref-long sap offset))
133 (defun signed-sap-ref-8 (sap offset)
135 "Returns the signed 8-bit byte at OFFSET bytes from SAP."
136 (declare (type system-area-pointer sap)
138 (signed-sap-ref-8 sap offset))
140 (defun signed-sap-ref-16 (sap offset)
142 "Returns the signed 16-bit word at OFFSET bytes from SAP."
143 (declare (type system-area-pointer sap)
145 (signed-sap-ref-16 sap offset))
147 (defun signed-sap-ref-32 (sap offset)
149 "Returns the signed 32-bit dualword at OFFSET bytes from SAP."
150 (declare (type system-area-pointer sap)
152 (signed-sap-ref-32 sap offset))
155 (defun signed-sap-ref-64 (sap offset)
157 "Returns the signed 64-bit quadword at OFFSET bytes from SAP."
158 (declare (type system-area-pointer sap)
160 (signed-sap-ref-64 sap offset))
162 (defun %set-sap-ref-8 (sap offset new-value)
163 (declare (type system-area-pointer sap)
165 (type (unsigned-byte 8) new-value))
166 (setf (sap-ref-8 sap offset) new-value))
168 (defun %set-sap-ref-16 (sap offset new-value)
169 (declare (type system-area-pointer sap)
171 (type (unsigned-byte 16) new-value))
172 (setf (sap-ref-16 sap offset) new-value))
174 (defun %set-sap-ref-32 (sap offset new-value)
175 (declare (type system-area-pointer sap)
177 (type (unsigned-byte 32) new-value))
178 (setf (sap-ref-32 sap offset) new-value))
181 (defun %set-sap-ref-64 (sap offset new-value)
182 (declare (type system-area-pointer sap)
184 (type (unsigned-byte 64) new-value))
185 (setf (sap-ref-64 sap offset) new-value))
187 (defun %set-signed-sap-ref-8 (sap offset new-value)
188 (declare (type system-area-pointer sap)
190 (type (signed-byte 8) new-value))
191 (setf (signed-sap-ref-8 sap offset) new-value))
193 (defun %set-signed-sap-ref-16 (sap offset new-value)
194 (declare (type system-area-pointer sap)
196 (type (signed-byte 16) new-value))
197 (setf (signed-sap-ref-16 sap offset) new-value))
199 (defun %set-signed-sap-ref-32 (sap offset new-value)
200 (declare (type system-area-pointer sap)
202 (type (signed-byte 32) new-value))
203 (setf (signed-sap-ref-32 sap offset) new-value))
206 (defun %set-signed-sap-ref-64 (sap offset new-value)
207 (declare (type system-area-pointer sap)
209 (type (signed-byte 64) new-value))
210 (setf (signed-sap-ref-64 sap offset) new-value))
212 (defun %set-sap-ref-sap (sap offset new-value)
213 (declare (type system-area-pointer sap new-value)
215 (setf (sap-ref-sap sap offset) new-value))
217 (defun %set-sap-ref-single (sap offset new-value)
218 (declare (type system-area-pointer sap)
220 (type single-float new-value))
221 (setf (sap-ref-single sap offset) new-value))
223 (defun %set-sap-ref-double (sap offset new-value)
224 (declare (type system-area-pointer sap)
226 (type double-float new-value))
227 (setf (sap-ref-double sap offset) new-value))
230 (defun %set-sap-ref-long (sap offset new-value)
231 (declare (type system-area-pointer sap)
233 (type long-float new-value))
234 (setf (sap-ref-long sap offset) new-value))
236 ;;;; system memory allocation
238 (sb!alien:def-alien-routine ("os_allocate" allocate-system-memory)
240 (bytes sb!c-call:unsigned-long))
242 (sb!alien:def-alien-routine ("os_allocate_at" allocate-system-memory-at)
244 (address system-area-pointer)
245 (bytes sb!c-call:unsigned-long))
247 (sb!alien:def-alien-routine ("os_reallocate" reallocate-system-memory)
249 (old system-area-pointer)
250 (old-size sb!c-call:unsigned-long)
251 (new-size sb!c-call:unsigned-long))
253 (sb!alien:def-alien-routine ("os_deallocate" deallocate-system-memory)
255 (addr system-area-pointer)
256 (bytes sb!c-call:unsigned-long))