This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Open Mode translation


Prasad Venkata Boddupalli wrote:
> 
> Hi,
>     In the gdb arm emulator, the open mode value obtained from the binary
> (compiled using newlib) is translated to another number using,
> 
> static int translate_open_mode[] =
> {
>   O_RDONLY,                          /* "r"   */
>   O_RDONLY+O_BINARY,                 /* "rb"  */
>   O_RDWR,                            /* "r+"  */
>   O_RDWR  +O_BINARY,                 /* "r+b" */
>   O_WRONLY         +O_CREAT+O_TRUNC, /* "w"   */
>   O_WRONLY+O_BINARY+O_CREAT+O_TRUNC, /* "wb"  */
>   O_RDWR           +O_CREAT+O_TRUNC, /* "w+"  */
>   O_RDWR  +O_BINARY+O_CREAT+O_TRUNC, /* "w+b" */
>   O_WRONLY         +O_APPEND+O_CREAT,/* "a"   */
>   O_WRONLY+O_BINARY+O_APPEND+O_CREAT,/* "ab"  */
>   O_RDWR           +O_APPEND+O_CREAT,/* "a+"  */
>   O_RDWR  +O_BINARY+O_APPEND+O_CREAT /* "a+b" */
> };
> 
> Can someone please write as what exactly is going on ? Why this mapping ?
> 
> thanks,
> Prasad.

Prasad,

  If you look further in sim/arm/armos.c you will see the translation is between the open flags used
by the Demon open SWI interface and the flags needed by the native open() call used to simulate it. 
The mode flags for the Demon open SWI have specific hard-coded values.  The simulator must use the
native O_ flags for the platform where the simulator runs.  

You should note that _swiopen() in newlib/libc/sys/arm/syscalls.c translates the target open-mode
flags to the SWI interface flags before invoking the SWI.

>From sim/arm/armos.c:

/* This file contains a model of Demon, ARM Ltd's Debug Monitor,
   including all the SWI's required to support the C library.
  
.
.

static void
SWIopen (ARMul_State * state, ARMword name, ARMword SWIflags)
{
  struct OSblock *OSptr = (struct OSblock *) state->OSptr;
  char dummy[2000];
  int flags;
  int i;

  for (i = 0; (dummy[i] = ARMul_SafeReadByte (state, name + i)); i++)
    ;

  /* Now we need to decode the Demon open mode.  */
  flags = translate_open_mode[SWIflags];


-- Jeff J.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]