Subject: Re: bus.h style question
To: None <jonathan@DSG.Stanford.EDU, ignatios@cs.uni-bonn.de>
From: Wolfgang Solfrank <ws@kurt.tools.de>
List: tech-kern
Date: 08/20/1997 13:51:16
> a) On machines, which _can_ have alien-endianness busses (more corretly: 
> busses handled by bus_space_xxx of different endiannesses), the only
> functions which _can_ be implemented as efficient inline macros are 
> bus_space_xxx_1().

Well, this depends on the implementation, as there are cpus that can access
memory (or io for that matter) with special instructions that do the byte
swapping on the fly.

> b) Independent of CPU endianness, the normal ISA bus bus_space_read_2(t, h, o)
> function is equivalent to
> 
> 	(bus_space_read_1(t, h, o) | (bus_space_read_1(t, h, (o)+1)<<8))
> 
> that is, it reads little-endian data items.

Depending on the bus this wouldn't work.  Consider for example the isa bus
where accessing 16-bit values might do something totally different from
accessing 8-bit values.  One prominent example is the ide (or even the old
wd disk) interface with its data port.  This one is normally accessed by
reading 16-bit values at port offset 0 (maybe 32-bit accesses on newer ide
interfaces).  Your method would access an 8-bit data item (which IIRC is
totally ok, you can access the data by doing twice as many reads via 8-bit
accesses) and or in the contents of the error register (which happens to
be the 8-bit register at port offset 1).

> [Little-Endian CPUs can implement this more efficiently, but this is not the
> point here]
> 
> c) Jonathan proposes to provide a bus_space_read_swapped_2(), which would be,
> on little-endian busses like ISA, be equivalent to:
> 
> 	(bus_space_read_1(t, h, (o)+1) | (bus_space_read_1(t, h, o)<<8))

Again depending on the bus this might not yield the intended results.

Hope it helps.
-- 
ws@TooLs.DE     (Wolfgang Solfrank, TooLs GmbH) 	+49-228-985800