Pascal Bourguignon <pjb@informatimago.com> wrote:
+---------------
| George Neuner <gneuner2/@comcast.net> writes:
| > But it *isn't* powerful enough to directly program that hardware -
| > only to program an abstraction of the hardware. It has no support
| > for raw access to the hardware and no direct support for placing
| > code or data.
|
| Not Common Lisp the standard, right.
| But that doesn't prevent me to do things like:
|
| (com.informatimago.clisp.raw-memory:POKE-UINT8 #\x10001234
| (mod (1+ (com.informatimago.clisp.raw-memory:PEEK-UINT8 #\x10001234)) 256))
|
| or to use these peek and poke to communicate thru shared memory
| between different processes. And right, I implemetned these funtions
| as external C functions, but I could have used a LAP written in lisp
| instead.
+---------------
One of the reasons I really like CMUCL is that these functions are
built-in [albeit as extensions to CL]. The SYSTEM:SAP-REF-{8,16,32}
functions do "peek", and they're SETF-able for "poke". I mostly use my
inlined wrapper functions R{8,16,32} & W{8,16,32} which automatically
convert an integer address argument to a SAP (with SYSTEM:INT-SAP) so I
can write (R8 FOO) instead of (SYSTEM:SAP-REF-8 (SYSTEM:INT-SAP FOO) 0).
;;; Used for things like polling for a "done" flag.
;;; BUG: Assumes contents of ADDR will change within fixnum polls.
(defun spin-until-change (addr)
(declare (optimize (speed 3) (debug 0) (safety 0)))
(loop with v0 of-type (unsigned-byte 32) = (r32 addr)
with counts fixnum = 0
while (= v0 (r32 addr))
do (setf counts (the fixnum (1+ counts)))
finally (return counts)))
And since CMUCL's "UNIX" package also provides built-in access to
OPEN/CLOSE/IOCTL/MMAP/etc., I find that for even the lowest-level
hardware bit-banging code I almost never need external C functions.
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607