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 ;;;; primitive SAP operations
16 ;;; Return T iff the SAP X points to a smaller address then the SAP Y.
18 (declare (type system-area-pointer x y))
21 ;;; Return T iff the SAP X points to a smaller or the same address as
24 (declare (type system-area-pointer x y))
27 ;;; Return T iff the SAP X points to the same address as the SAP Y.
29 (declare (type system-area-pointer x y))
32 ;;; Return T iff the SAP X points to a larger or the same address as
35 (declare (type system-area-pointer x y))
38 ;;; Return T iff the SAP X points to a larger address then the SAP Y.
40 (declare (type system-area-pointer x y))
43 ;;; Return a new SAP, OFFSET bytes from SAP.
44 (defun sap+ (sap offset)
45 (declare (type system-area-pointer sap)
49 ;;; Return the byte offset between SAP1 and SAP2.
50 (defun sap- (sap1 sap2)
51 (declare (type system-area-pointer sap1 sap2))
54 ;;; Convert SAP into an integer.
56 (declare (type system-area-pointer sap))
59 ;;; Convert an integer into a SAP.
61 (declare (type sap-int-type int))
64 ;;; Return the 8-bit byte at OFFSET bytes from SAP.
65 (defun sap-ref-8 (sap offset)
66 (declare (type system-area-pointer sap)
68 (sap-ref-8 sap offset))
70 ;;; Return the 16-bit word at OFFSET bytes from SAP.
71 (defun sap-ref-16 (sap offset)
72 (declare (type system-area-pointer sap)
74 (sap-ref-16 sap offset))
76 ;;; Returns the 32-bit dualword at OFFSET bytes from SAP.
77 (defun sap-ref-32 (sap offset)
78 (declare (type system-area-pointer sap)
80 (sap-ref-32 sap offset))
82 ;;; Return the 64-bit quadword at OFFSET bytes from SAP.
84 (defun sap-ref-64 (sap offset)
85 (declare (type system-area-pointer sap)
87 (sap-ref-64 sap offset))
89 ;;; Return the 32-bit SAP at OFFSET bytes from SAP.
90 (defun sap-ref-sap (sap offset)
91 (declare (type system-area-pointer sap)
93 (sap-ref-sap sap offset))
95 ;;; Return the 32-bit SINGLE-FLOAT at OFFSET bytes from SAP.
96 (defun sap-ref-single (sap offset)
97 (declare (type system-area-pointer sap)
99 (sap-ref-single sap offset))
101 ;;; Return the 64-bit DOUBLE-FLOAT at OFFSET bytes from SAP.
102 (defun sap-ref-double (sap offset)
103 (declare (type system-area-pointer sap)
105 (sap-ref-double sap offset))
107 ;;; Return the LONG-FLOAT at OFFSET bytes from SAP.
108 #!+(or x86 long-float)
109 (defun sap-ref-long (sap offset)
110 (declare (type system-area-pointer sap)
112 (sap-ref-long sap offset))
114 ;;; Return the signed 8-bit byte at OFFSET bytes from SAP.
115 (defun signed-sap-ref-8 (sap offset)
116 (declare (type system-area-pointer sap)
118 (signed-sap-ref-8 sap offset))
120 ;;; Return the signed 16-bit word at OFFSET bytes from SAP.
121 (defun signed-sap-ref-16 (sap offset)
122 (declare (type system-area-pointer sap)
124 (signed-sap-ref-16 sap offset))
126 ;;; Return the signed 32-bit dualword at OFFSET bytes from SAP.
127 (defun signed-sap-ref-32 (sap offset)
128 (declare (type system-area-pointer sap)
130 (signed-sap-ref-32 sap offset))
132 ;;; Return the signed 64-bit quadword at OFFSET bytes from SAP.
134 (defun signed-sap-ref-64 (sap offset)
135 (declare (type system-area-pointer sap)
137 (signed-sap-ref-64 sap offset))
139 (defun %set-sap-ref-8 (sap offset new-value)
140 (declare (type system-area-pointer sap)
142 (type (unsigned-byte 8) new-value))
143 (setf (sap-ref-8 sap offset) new-value))
145 (defun %set-sap-ref-16 (sap offset new-value)
146 (declare (type system-area-pointer sap)
148 (type (unsigned-byte 16) new-value))
149 (setf (sap-ref-16 sap offset) new-value))
151 (defun %set-sap-ref-32 (sap offset new-value)
152 (declare (type system-area-pointer sap)
154 (type (unsigned-byte 32) new-value))
155 (setf (sap-ref-32 sap offset) new-value))
158 (defun %set-sap-ref-64 (sap offset new-value)
159 (declare (type system-area-pointer sap)
161 (type (unsigned-byte 64) new-value))
162 (setf (sap-ref-64 sap offset) new-value))
164 (defun %set-signed-sap-ref-8 (sap offset new-value)
165 (declare (type system-area-pointer sap)
167 (type (signed-byte 8) new-value))
168 (setf (signed-sap-ref-8 sap offset) new-value))
170 (defun %set-signed-sap-ref-16 (sap offset new-value)
171 (declare (type system-area-pointer sap)
173 (type (signed-byte 16) new-value))
174 (setf (signed-sap-ref-16 sap offset) new-value))
176 (defun %set-signed-sap-ref-32 (sap offset new-value)
177 (declare (type system-area-pointer sap)
179 (type (signed-byte 32) new-value))
180 (setf (signed-sap-ref-32 sap offset) new-value))
183 (defun %set-signed-sap-ref-64 (sap offset new-value)
184 (declare (type system-area-pointer sap)
186 (type (signed-byte 64) new-value))
187 (setf (signed-sap-ref-64 sap offset) new-value))
189 (defun %set-sap-ref-sap (sap offset new-value)
190 (declare (type system-area-pointer sap new-value)
192 (setf (sap-ref-sap sap offset) new-value))
194 (defun %set-sap-ref-single (sap offset new-value)
195 (declare (type system-area-pointer sap)
197 (type single-float new-value))
198 (setf (sap-ref-single sap offset) new-value))
200 (defun %set-sap-ref-double (sap offset new-value)
201 (declare (type system-area-pointer sap)
203 (type double-float new-value))
204 (setf (sap-ref-double sap offset) new-value))
207 (defun %set-sap-ref-long (sap offset new-value)
208 (declare (type system-area-pointer sap)
210 (type long-float new-value))
211 (setf (sap-ref-long sap offset) new-value))
213 ;;;; system memory allocation
215 (sb!alien:def-alien-routine ("os_allocate" allocate-system-memory)
217 (bytes sb!c-call:unsigned-long))
219 (sb!alien:def-alien-routine ("os_allocate_at" allocate-system-memory-at)
221 (address system-area-pointer)
222 (bytes sb!c-call:unsigned-long))
224 (sb!alien:def-alien-routine ("os_reallocate" reallocate-system-memory)
226 (old system-area-pointer)
227 (old-size sb!c-call:unsigned-long)
228 (new-size sb!c-call:unsigned-long))
230 (sb!alien:def-alien-routine ("os_deallocate" deallocate-system-memory)
232 (addr system-area-pointer)
233 (bytes sb!c-call:unsigned-long))