Using newlib (was: [Efi332] Building newlib/libgloss for MPC555)

David Eicher sailors3
Wed Aug 17 14:09:25 UTC 2005


New info:

In newlib/libc/include/sys/config.h we have:

#define _REENT_SMALL

Which makes the code down below in newlib/libc/include/sys/reent.h set the
macro _REENT_SMALL_CHECK_INIT(fp) = CHECK_INIT(fp), but I confirmed that
there is no code in printf that calls _sinit(). Printf calls this macro just
before calling vfprintf( ) where the work is done. 

We need CHECK_INIT(fp) to run because it calls _sinit( ) which initializes
the entire stdio environment. It appears the macro is not getting expanded
or something, not sure why there is no call to _sinit( ).

CHECK_INIT() looks like this:

#define CHECK_INIT(fp) \
  do						\
    {						\
      if (_REENT && !_REENT->__sdidinit)	\
	__sinit (_REENT);			\
    }						\
  while (0)

Maybe this if statement is failing to call _sinit( )?


Thanks,

Dave


#ifdef _REENT_SMALL
/*
 * struct __sFILE_fake is the start of a struct __sFILE, with only the
 * minimal fields allocated.  In __sinit() we really allocate the 3
 * standard streams, etc., and point away from this fake.
 */
struct __sFILE_fake {
  unsigned char *_p;	/* current position in (some) buffer */
  int	_r;		/* read space left for getc() */
  int	_w;		/* write space left for putc() */
  short	_flags;		/* flags, below; this FILE is free if 0 */
  short	_file;		/* fileno, if Unix descriptor, else -1 */
  struct __sbuf _bf;	/* the buffer (at least 1 byte, if !NULL) */
  int	_lbfsize;	/* 0 or -_bf._size, for inline putc */

  struct _reent *_data;
};
/* CHECK_INIT() comes from stdio/local.h; be sure to include that.  */
# define _REENT_SMALL_CHECK_INIT(fp) CHECK_INIT(fp)
#else
# define _REENT_SMALL_CHECK_INIT(fp) /* nothing */
#endif

-----Original Message-----
From: efi332-bounces at diy-efi.org [mailto:efi332-bounces at diy-efi.org] On
Behalf Of David Eicher
Sent: Tuesday, August 16, 2005 7:33 PM
To: efi332 at diy-efi.org
Subject: RE: Using newlib (was: [Efi332] Building newlib/libgloss for
MPC555)

Hi Gunter,

Thanks for the insight here.

I've discovered so far that _reent is defined in reent.h in:

Newlib/libc/include/sys/ directory.

I agree with you wholeheartedly, I need to figure out how to initialize
stdout and stdin. I am getting the feeling that is my problem as I dig into
this further.

New info: it appears a function called _sinit(  ) must run to initialize all
stuff for stdio, including stdout stdin, and stderr. CHECK_INIT( ) is a
macro that calls _sinit( ). Printf calls:

_REENT_SMALL_CHECK_INIT (_stdout_r (ptr));

Rather than calling CHECK_INIT, it appears this call is failing somehow. My
next task is to single step through this code and see if I can figure out
why, and more importantly, what to do about it.

More later,

Thanks,

Dave


-----Original Message-----
From: efi332-bounces at diy-efi.org [mailto:efi332-bounces at diy-efi.org] On
Behalf Of Gunter Magin
Sent: Tuesday, August 16, 2005 11:48 AM
To: efi332 at diy-efi.org
Subject: Re: Using newlib (was: [Efi332] Building newlib/libgloss for
MPC555)

Hi David,

(have been out all day...)

On Mon, Aug 15, 2005 at 08:13:59PM -0700, David Eicher wrote:
> Making some progress. I've discovered that the __sfvwrite ( ) function
> accepts as input two parameters (fp and uio) as shown in this code
snippet.
> 
> _DEFUN(__sfvwrite, (fp, uio),
>        register FILE *fp _AND
>        register struct __suio *uio)
> 
> It appears in the code that one of the parameters is passed to the
function
> in register r3, which gets copied to r27. I put a breakpoint at the
> beginning of __sfvwrite (which is in file fvwrite.c) and discovered that
r3
> is 0xFFFFFFFF at the beginning of execution. 

It is fp which has the wrong value.

Did you initialize in any way stdin/stdout? 

No, I don't know precisely how to do that, but plain printf() expands
the call to vfprintf (_stdout_r (_REENT), fmt, ap);

So it has to do with _stdout_r, which actually is a macro defined in
newlib-1.13.0/newlib/libc/include/stdio.h

It uses a parameter _REENT, but I haven't found out where this is
defined, and where and how it is initialized. I strongly guess this is
the key for getting further.

It can be as easy, as the implicit fopen() call for stdout is missing,
but it also can be more. I have to bail out here.

> So..., that is more background on why __sfvwrite is crashing. I have not
> been able to tell which parameter is passed in r3 yet (working on it). 

See above. Parameter passing is part of the PowerPC-EABI specification.
I think I have that in form of a .pdf from some IBM website, I forgot. But
it is not essential at this point.

gm
_______________________________________________
Efi332 mailing list
Efi332 at diy-efi.org
http://lists.diy-efi.org/mailman/listinfo/efi332

_______________________________________________
Efi332 mailing list
Efi332 at diy-efi.org
http://lists.diy-efi.org/mailman/listinfo/efi332





More information about the Efi332 mailing list