Writing Device Drivers

Reading and Writing

The PROM provides a variety of 8-bit, 16-bit, and 32-bit operations. In general, a c (character) prefix indicates an 8-bit (one byte) operation; a w (word) prefix indicates a 16-bit (two byte) operation; and an L (longword) prefix indicates a 32-bit (four byte) operation.

A suffix of ! is used to indicate a write operation. The write operation takes the first two items off the stack; the first item is the address, and the second item is the value.

ok 55 ffe98000 c!

A suffix of @ is used to indicate a read operation. The read operation takes one argument (the address) off the stack.

ok ffe98000 c@ok .s55

A suffix of ? is used to display the value, without affecting the stack.

ok ffe98000 c?55

Be careful when trying to query the device. If the mappings are not set up correctly, trying to read or write could cause errors. There are special words provided to handle these cases. cprobe, wprobe, and lprobe, for example, read from the given address but return zero if the location does not respond, or nonzero if it does.

ok fffa4000 c@Data Access Error

ok fffa4000 cprobeok .s0

ok ffe98000 cprobeok .s0 ffffffffffffffff

A region of memory can be shown with the dump word. This takes an address and a length, and displays the contents of the memory region in bytes.

In the following example, the fill word is used to fill video memory with a pattern. fill takes the address, the number of bytes to fill, and the byte to use (there is also a wfill and an Lfill for words and longwords). This causes the cgsix to display simple patterns based on the byte passed.

ok " /sbus" select-dev
ok 800000 2 100000 map-in
ok constant fbok fb 10000 ff fillok fb 20000 0 fillok fb 18000 55 fillok fb 15000 3 fillok fb 10000 5 fillok fb 5000 f9 fill


Certain machine-specific interrupt levels are ignored when the Open Boot PROM controls the machine.