public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Accessing odd bytes
@ 2002-06-14 12:31 Robert Schwebel
  2002-06-14 14:02 ` Richard B. Johnson
  2002-06-14 14:40 ` Ian Stirling
  0 siblings, 2 replies; 3+ messages in thread
From: Robert Schwebel @ 2002-06-14 12:31 UTC (permalink / raw)
  To: linux-kernel

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
-- 
 +--------------------------------------------------------+
 | 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    |
 +--------------------------------------------------------+

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Accessing odd bytes
  2002-06-14 12:31 Accessing odd bytes Robert Schwebel
@ 2002-06-14 14:02 ` Richard B. Johnson
  2002-06-14 14:40 ` Ian Stirling
  1 sibling, 0 replies; 3+ messages in thread
From: Richard B. Johnson @ 2002-06-14 14:02 UTC (permalink / raw)
  To: Robert Schwebel; +Cc: linux-kernel

On Fri, 14 Jun 2002, Robert Schwebel wrote:

> 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

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).

>     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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Accessing odd bytes
  2002-06-14 12:31 Accessing odd bytes Robert Schwebel
  2002-06-14 14:02 ` Richard B. Johnson
@ 2002-06-14 14:40 ` Ian Stirling
  1 sibling, 0 replies; 3+ messages in thread
From: Ian Stirling @ 2002-06-14 14:40 UTC (permalink / raw)
  To: Robert Schwebel; +Cc: linux-kernel

> 
> 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>
> 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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-06-14 14:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-06-14 12:31 Accessing odd bytes Robert Schwebel
2002-06-14 14:02 ` Richard B. Johnson
2002-06-14 14:40 ` Ian Stirling

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox