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)
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 ;;; Return the 16-bit word at OFFSET bytes from SAP.
69 (defun sap-ref-16 (sap offset)
70 (declare (type system-area-pointer sap)
72 (sap-ref-16 sap offset))
74 ;;; Returns the 32-bit dualword at OFFSET bytes from SAP.
75 (defun sap-ref-32 (sap offset)
76 (declare (type system-area-pointer sap)
78 (sap-ref-32 sap offset))
80 ;;; Return the 64-bit quadword at OFFSET bytes from SAP.
81 (defun sap-ref-64 (sap offset)
82 (declare (type system-area-pointer sap)
84 (sap-ref-64 sap offset))
86 ;;; Return the unsigned word of natural size OFFSET bytes from SAP.
87 (defun sap-ref-word (sap offset)
88 (declare (type system-area-pointer sap)
90 (sap-ref-word sap offset))
92 ;;; Return the 32-bit SAP at OFFSET bytes from SAP.
93 (defun sap-ref-sap (sap offset)
94 (declare (type system-area-pointer sap)
96 (sap-ref-sap sap offset))
98 ;;; Return the 32-bit SINGLE-FLOAT at OFFSET bytes from SAP.
99 (defun sap-ref-single (sap offset)
100 (declare (type system-area-pointer sap)
102 (sap-ref-single sap offset))
104 ;;; Return the 64-bit DOUBLE-FLOAT at OFFSET bytes from SAP.
105 (defun sap-ref-double (sap offset)
106 (declare (type system-area-pointer sap)
108 (sap-ref-double sap offset))
110 ;;; Return the LONG-FLOAT at OFFSET bytes from SAP.
111 #!+(or x86 long-float)
112 (defun sap-ref-long (sap offset)
113 (declare (type system-area-pointer sap)
115 (sap-ref-long sap offset))
117 ;;; Return the signed 8-bit byte at OFFSET bytes from SAP.
118 (defun signed-sap-ref-8 (sap offset)
119 (declare (type system-area-pointer sap)
121 (signed-sap-ref-8 sap offset))
123 ;;; Return the signed 16-bit word at OFFSET bytes from SAP.
124 (defun signed-sap-ref-16 (sap offset)
125 (declare (type system-area-pointer sap)
127 (signed-sap-ref-16 sap offset))
129 ;;; Return the signed 32-bit dualword at OFFSET bytes from SAP.
130 (defun signed-sap-ref-32 (sap offset)
131 (declare (type system-area-pointer sap)
133 (signed-sap-ref-32 sap offset))
135 ;;; Return the signed 64-bit quadword at OFFSET bytes from SAP.
136 (defun signed-sap-ref-64 (sap offset)
137 (declare (type system-area-pointer sap)
139 (signed-sap-ref-64 sap offset))
141 ;;; Return the signed word of natural size OFFSET bytes from SAP.
142 (defun signed-sap-ref-word (sap offset)
143 (declare (type system-area-pointer sap)
145 (signed-sap-ref-word sap offset))
147 (defun %set-sap-ref-8 (sap offset new-value)
148 (declare (type system-area-pointer sap)
150 (type (unsigned-byte 8) new-value))
151 (setf (sap-ref-8 sap offset) new-value))
153 (defun %set-sap-ref-16 (sap offset new-value)
154 (declare (type system-area-pointer sap)
156 (type (unsigned-byte 16) new-value))
157 (setf (sap-ref-16 sap offset) new-value))
159 (defun %set-sap-ref-32 (sap offset new-value)
160 (declare (type system-area-pointer sap)
162 (type (unsigned-byte 32) new-value))
163 (setf (sap-ref-32 sap offset) new-value))
165 (defun %set-sap-ref-64 (sap offset new-value)
166 (declare (type system-area-pointer sap)
168 (type (unsigned-byte 64) new-value))
169 (setf (sap-ref-64 sap offset) new-value))
171 (defun %set-sap-ref-word (sap offset new-value)
172 (declare (type system-area-pointer sap)
174 (type (unsigned-byte #.sb!vm:n-machine-word-bits) new-value))
175 (setf (sap-ref-word sap offset) new-value))
177 (defun %set-signed-sap-ref-8 (sap offset new-value)
178 (declare (type system-area-pointer sap)
180 (type (signed-byte 8) new-value))
181 (setf (signed-sap-ref-8 sap offset) new-value))
183 (defun %set-signed-sap-ref-16 (sap offset new-value)
184 (declare (type system-area-pointer sap)
186 (type (signed-byte 16) new-value))
187 (setf (signed-sap-ref-16 sap offset) new-value))
189 (defun %set-signed-sap-ref-32 (sap offset new-value)
190 (declare (type system-area-pointer sap)
192 (type (signed-byte 32) new-value))
193 (setf (signed-sap-ref-32 sap offset) new-value))
195 (defun %set-signed-sap-ref-64 (sap offset new-value)
196 (declare (type system-area-pointer sap)
198 (type (signed-byte 64) new-value))
199 (setf (signed-sap-ref-64 sap offset) new-value))
201 (defun %set-signed-sap-ref-word (sap offset new-value)
202 (declare (type system-area-pointer sap)
204 (type (signed-byte #.sb!vm:n-machine-word-bits) new-value))
205 (setf (signed-sap-ref-word sap offset) new-value))
207 (defun %set-sap-ref-sap (sap offset new-value)
208 (declare (type system-area-pointer sap new-value)
210 (setf (sap-ref-sap sap offset) new-value))
212 (defun %set-sap-ref-single (sap offset new-value)
213 (declare (type system-area-pointer sap)
215 (type single-float new-value))
216 (setf (sap-ref-single sap offset) new-value))
218 (defun %set-sap-ref-double (sap offset new-value)
219 (declare (type system-area-pointer sap)
221 (type double-float new-value))
222 (setf (sap-ref-double sap offset) new-value))
225 (defun %set-sap-ref-long (sap offset new-value)
226 (declare (type system-area-pointer sap)
228 (type long-float new-value))
229 (setf (sap-ref-long sap offset) new-value))