Skip to contentSkip to conversation

Accessing odd bytes

DISCUSSION Robert Schwebel 3 participants 3 messages Jun 14, 2002

lore
Share & tools
lore
#0 lore raw

I have a strange effect on an embedded system (AMD Elan SC410, Linux-2.4.18) while accessing a static RAM. The RAM is mapped to the bus at 0x0200'0000. If I map it to user space this way:

  pSRAM  = (unsigned short *)mmap(0, 0x00040000, PROT_READ + PROT_WRITE, MAP_SHARED, FD, 0x2000000);

and fill it like this:

  pByte=(char*)pSRAM;
  for (i=0; i<10; i++) {
    *pByte++=(char)i;
  }

  pByte=(char*)pSRAM;
  for (i=0; i<10; i++) {
    printf("i: %02i -> %03i\n", i, *pByte++);
  }

I see a mirroring effect:

i: 00 -> 001
i: 01 -> 001
i: 02 -> 003
i: 03 -> 003
i: 04 -> 005
i: 05 -> 005
i: 06 -> 007
i: 07 -> 007
i: 08 -> 009
i: 09 -> 009

Now I'm wondering how the kernel/processor handles odd byte access exceptions. Can anybody give me a pointer where I could search or what my problem could be?

Robert

Signature · 6 lines
 +--------------------------------------------------------+
 | Dipl.-Ing. Robert Schwebel | http://www.pengutronix.de |
 | Pengutronix - Linux Solutions for Science and Industry |
 |   Braunschweiger Str. 79,  31134 Hildesheim, Germany   |
 |    Phone: +49-5121-28619-0 |  Fax: +49-5121-28619-4    |
 +--------------------------------------------------------+
#1 lore raw
Quoted 31 lines · Robert Schwebel

I have a strange effect on an embedded system (AMD Elan SC410, Linux-2.4.18) while accessing a static RAM. The RAM is mapped to the bus at 0x0200'0000. If I map it to user space this way:

  pSRAM  = (unsigned short *)mmap(0, 0x00040000, PROT_READ + PROT_WRITE, MAP_SHARED, FD, 0x2000000);

and fill it like this:

  pByte=(char*)pSRAM;
  for (i=0; i<10; i++) {
    *pByte++=(char)i;
  }

  pByte=(char*)pSRAM;
  for (i=0; i<10; i++) {
    printf("i: %02i -> %03i\n", i, *pByte++);
  }

I see a mirroring effect:

i: 00 -> 001
i: 01 -> 001
i: 02 -> 003
i: 03 -> 003
i: 04 -> 005
i: 05 -> 005
i: 06 -> 007
i: 07 -> 007
i: 08 -> 009
i: 09 -> 009

Quoted 5 lines

Now I'm wondering how the kernel/processor handles odd byte access exceptions. Can anybody give me a pointer where I could search or what my problem could be?

Robert

There are no odd-byte access exceptions in the SC410 or in any Intel ix86 emulation. Word accesses at odd-byte boundaries may (not always) simply take longer. You can access any size element at any alignment. The only time you will get an exception is if you attempt to access 0xffffffff as a Word (and similar boundary errors).

Quoted 1 line
    printf("i: %02i -> %03i\n", i, *pByte++);

Now, I'm not smart enough to understand what this code is supposed to show so I can't offer any suggestions. But, with all Intel machines, the lowest byte is in the lowest memory address and the lowest word is in the lowest memory address, etc.

Given: 0xdeadface

Memory:
<-- Low High -->
0xce, 0xfa, 0xad, 0xde

Also, in 32-bit code, if you are going to pass a byte to a function, the rest of the 32-bit value passed may be junk since you can't push bytes onto the stack.

Cheers,
Dick Johnson

Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).

Windows-2000/Professional isn't.

#2 lore raw
In reply to Robert Schwebel
Quoted 4 lines

I have a strange effect on an embedded system (AMD Elan SC410, Linux-2.4.18) while accessing a static RAM. The RAM is mapped to the bus at 0x0200'0000. If I map it to user space this way:

<snip>

Quoted 3 lines

Now I'm wondering how the kernel/processor handles odd byte access exceptions. Can anybody give me a pointer where I could search or what my problem could be?

It has been a while, but I believe you may need to setup the SC410s MMU to tell it it's an 8 bit (or whateve) RAM.
Reading the manuals may reveal details that I've forgotten.