HD driver (was: Re: [movitz-devel] Re: Suggested "filesystem")

Peter Minten peter.minten at wanadoo.nl
Sun Apr 18 17:30:05 UTC 2004


Frode Vatvedt Fjeld wrote:
> Which brings me to my second point, which is that if someone was to
> write a simple interface to the IDE disk drives (that primarily works
> with bochs), this would be an excellent starting-point for actually
> experimenting with these concepts. I don't want to come across as
> whining, but I have to say I'm slightly disappointed so far when it
> comes to the apparent disinterest in contributing code (or even just
> bug/feature-reports) here. Hopefully this might change when the
> platform becomes more mature, but obviously contributions from others
> would speed up this process also, and not to mention increase the
> chances of removing bad design decisions of mine before they are
> embedded to deep in the system.

Ok, you asked for it :-). I wrote a little IDE driver for ATA-1 compatible LBA
capable disks (AFAIK Bochs disks are of that type), it's at
'http://www.il.fontys.nl/~silvernerd/harddisk.lisp'. Currently async read and
write of 1-256 sectors in one go is implemented.

The code does not compile due to a strange error about a variable (data) not
being defined. The code is this:

(defstruct hd-read-sectors-task
   (start-sector 0 :type (unsigned-byte 28))
   (count 1 :type (integer 1 256))
   (data #() :type data-vector)
   (offset 0 :type (integer 0 *)))

(defmethod hd-controller-handle-task-signal (hdc (task hd-read-sectors-task))
   (with-slots (count data offset) task
     (let ((status (io-port (hd-controller-command-register hdc 'status)
           (read-data (io-port (hd-controller-command-register hdc 'status)
       ;; by now the drive is getting the next piece, if necessary,
       ;; so I hope this code is reentrant
       (if (= 0 (logand (power 2 (hd-controller-status 'error))
           ;; read 512 bytes
           (dotimes (i 256)
             (setf (aref data offset) (logand read-data #xFF))
             (setf (aref data (1+ offset)) (logand read-data #xFF00))
             (incf offset 2))
           (= offset (1- (* count 512)))) ;return value, are we done or not?
         (error "Harddrive read-sectors returned error. Controller nr ~A, HD number:
~A, error register: ~A."
                (hd-controller-number hdc)
                (hd-controller-active-hd hdc)
                (io-port (hd-controller-command-register hdc 'error)

I know that using with-slots on a structure is not exactly common (though as I
understand the HyperSpec it's legal) so I tried replacing it with let for a
moment to see if the error was in the with-slots. Let gave the same result:
symbol 'data' undefined. When I removed data from the code altogether it started
complaining about offset.

Furthermore on my box there is a problem with binary-types:

On CMUCL 18e, custom core.
Binary-types and Movitz version: CVS 17-apr-2004.

Slime error message:

Execution of a form compiled with errors:
    [Condition of type KERNEL:SIMPLE-PROGRAM-ERROR]

The error disappears when I abort and do (load "load") again.


Peter Minten

More information about the movitz-devel mailing list