Subject: Re: diff betw. bus_space_{read,write} and bus_space_{read,write}_stream?
To: Ken Nakata <kenn@synap.ne.jp>
From: Manuel Bouyer <bouyer@antioche.lip6.fr>
List: tech-kern
Date: 08/26/1998 21:50:54
On Aug 25, Ken Nakata wrote
> Ahh... This is what we differ from each other.
>
> IDE bus is a little-endian 16-bit wide bus, so the string "Ne"
> (assuming 16-bit aligned) is represented by a bit pattern 0x654e (byte
> 0 "N" is in the lower 8 bits, and byte 1 "e" in the upper 8 bits).
> Now, the same string "Ne" on the big-endian host bus is represented by
> a different bit pattern 0x4e65 (byte 0 "N" is in the upper 8 bits and
> byte 1 "e" in the lower 8 bits). Therefore, string's byte order _is_
> preserved when bytes are swapped.
>
> Make sense to you?
No. A string is endianless, it's only an array of chars.
Maybe an example is needed.
Maybe an example will help.
Consider the following C program:
main()
{
char *s = "abc";
int *i = (int*)s;
printf("char values for %s: %x %x %x %x\n", s,
s[0], s[1], s[2], s[3]);
printf("int value: %x\n", *i);
}
That is, we have a memory location of 4 bytes, where is stored the string
"abc\0"
This memory location is interpreted in 2 ways: as an array of chars and
as an integer by the C program.
On my i386 I get:
manu:/tmp>./a.out
./a.out
char values for abc: 61 62 63 0
int value: 636261
On my sparc (same endian as m68k) I get:
cordouan:/tmp>./a.out
char values for abc: 61 62 63 0
int value: 61626300
So the same string have its bytes stored in the same order on both
CPUs. But these 4 bytes gives a different integer.
So if I want to transfer a string between these 2 machines I need to copy
the bytes in the same order, if I want to tranfer a int I need to copy
the bytes in reversed order.
--
Manuel Bouyer, LIP6, Universite Paris VI. Manuel.Bouyer@lip6.fr
--