OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [doc/] [html/] [ref/] [libc-implementation-details.html] - Diff between revs 28 and 174

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 28 Rev 174
<!-- Copyright (C) 2003 Red Hat, Inc.                                -->
<!-- Copyright (C) 2003 Red Hat, Inc.                                -->
<!-- This material may be distributed only subject to the terms      -->
<!-- This material may be distributed only subject to the terms      -->
<!-- and conditions set forth in the Open Publication License, v1.0  -->
<!-- and conditions set forth in the Open Publication License, v1.0  -->
<!-- or later (the latest version is presently available at          -->
<!-- or later (the latest version is presently available at          -->
<!-- http://www.opencontent.org/openpub/).                           -->
<!-- http://www.opencontent.org/openpub/).                           -->
<!-- Distribution of the work or derivative of the work in any       -->
<!-- Distribution of the work or derivative of the work in any       -->
<!-- standard (paper) book form is prohibited unless prior           -->
<!-- standard (paper) book form is prohibited unless prior           -->
<!-- permission is obtained from the copyright holder.               -->
<!-- permission is obtained from the copyright holder.               -->
<HTML
<HTML
><HEAD
><HEAD
><TITLE
><TITLE
>Some implementation details</TITLE
>Some implementation details</TITLE
><meta name="MSSmartTagsPreventParsing" content="TRUE">
><meta name="MSSmartTagsPreventParsing" content="TRUE">
<META
<META
NAME="GENERATOR"
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
"><LINK
"><LINK
REL="HOME"
REL="HOME"
TITLE="eCos Reference Manual"
TITLE="eCos Reference Manual"
HREF="ecos-ref.html"><LINK
HREF="ecos-ref.html"><LINK
REL="UP"
REL="UP"
TITLE="C and math library overview"
TITLE="C and math library overview"
HREF="c-and-math-library-overview.html"><LINK
HREF="c-and-math-library-overview.html"><LINK
REL="PREVIOUS"
REL="PREVIOUS"
TITLE="Math library compatibility modes"
TITLE="Math library compatibility modes"
HREF="math-library-compatibility-modes.html"><LINK
HREF="math-library-compatibility-modes.html"><LINK
REL="NEXT"
REL="NEXT"
TITLE="Thread safety"
TITLE="Thread safety"
HREF="libc-thread-safety.html"></HEAD
HREF="libc-thread-safety.html"></HEAD
><BODY
><BODY
CLASS="SECT1"
CLASS="SECT1"
BGCOLOR="#FFFFFF"
BGCOLOR="#FFFFFF"
TEXT="#000000"
TEXT="#000000"
LINK="#0000FF"
LINK="#0000FF"
VLINK="#840084"
VLINK="#840084"
ALINK="#0000FF"
ALINK="#0000FF"
><DIV
><DIV
CLASS="NAVHEADER"
CLASS="NAVHEADER"
><TABLE
><TABLE
SUMMARY="Header navigation table"
SUMMARY="Header navigation table"
WIDTH="100%"
WIDTH="100%"
BORDER="0"
BORDER="0"
CELLPADDING="0"
CELLPADDING="0"
CELLSPACING="0"
CELLSPACING="0"
><TR
><TR
><TH
><TH
COLSPAN="3"
COLSPAN="3"
ALIGN="center"
ALIGN="center"
>eCos Reference Manual</TH
>eCos Reference Manual</TH
></TR
></TR
><TR
><TR
><TD
><TD
WIDTH="10%"
WIDTH="10%"
ALIGN="left"
ALIGN="left"
VALIGN="bottom"
VALIGN="bottom"
><A
><A
HREF="math-library-compatibility-modes.html"
HREF="math-library-compatibility-modes.html"
ACCESSKEY="P"
ACCESSKEY="P"
>Prev</A
>Prev</A
></TD
></TD
><TD
><TD
WIDTH="80%"
WIDTH="80%"
ALIGN="center"
ALIGN="center"
VALIGN="bottom"
VALIGN="bottom"
>Chapter 13. C and math library overview</TD
>Chapter 13. C and math library overview</TD
><TD
><TD
WIDTH="10%"
WIDTH="10%"
ALIGN="right"
ALIGN="right"
VALIGN="bottom"
VALIGN="bottom"
><A
><A
HREF="libc-thread-safety.html"
HREF="libc-thread-safety.html"
ACCESSKEY="N"
ACCESSKEY="N"
>Next</A
>Next</A
></TD
></TD
></TR
></TR
></TABLE
></TABLE
><HR
><HR
ALIGN="LEFT"
ALIGN="LEFT"
WIDTH="100%"></DIV
WIDTH="100%"></DIV
><DIV
><DIV
CLASS="SECT1"
CLASS="SECT1"
><H1
><H1
CLASS="SECT1"
CLASS="SECT1"
><A
><A
NAME="LIBC-IMPLEMENTATION-DETAILS">Some implementation details</H1
NAME="LIBC-IMPLEMENTATION-DETAILS">Some implementation details</H1
><P
><P
>Here are some details about the implementation
>Here are some details about the implementation
which might be interesting, although they do not affect the ISO-defined
which might be interesting, although they do not affect the ISO-defined
semantics of the library. </P
semantics of the library. </P
><P
><P
></P
></P
><UL
><UL
><LI
><LI
><P
><P
>It is possible to configure
>It is possible to configure
<SPAN
<SPAN
CLASS="emphasis"
CLASS="emphasis"
><I
><I
CLASS="EMPHASIS"
CLASS="EMPHASIS"
>eCos</I
>eCos</I
></SPAN
></SPAN
>
>
 to have the standard C library without the kernel. You might want
 to have the standard C library without the kernel. You might want
to do this to use less memory. But if you disable the kernel, you
to do this to use less memory. But if you disable the kernel, you
will be unable to use memory allocation, thread-safety and certain
will be unable to use memory allocation, thread-safety and certain
stdio functions such as input. Other C library functionality is
stdio functions such as input. Other C library functionality is
unaffected.</P
unaffected.</P
></LI
></LI
><LI
><LI
><P
><P
>The opaque type returned by
>The opaque type returned by
<TT
<TT
CLASS="FUNCTION"
CLASS="FUNCTION"
>clock()</TT
>clock()</TT
>
>
 is called clock_t, and is implemented as a 64 bit integer.
 is called clock_t, and is implemented as a 64 bit integer.
The value returned by
The value returned by
<TT
<TT
CLASS="FUNCTION"
CLASS="FUNCTION"
>clock()</TT
>clock()</TT
>
>
 is only correct if the kernel is configured with real-time clock
 is only correct if the kernel is configured with real-time clock
support, as determined by the CYGVAR_KERNEL_COUNTERS_CLOCK
support, as determined by the CYGVAR_KERNEL_COUNTERS_CLOCK
configuration option in
configuration option in
<TT
<TT
CLASS="FILENAME"
CLASS="FILENAME"
>kernel.h</TT
>kernel.h</TT
>
>
.</P
.</P
></LI
></LI
><LI
><LI
><P
><P
>The FILE type is not implemented as a structure, but rather
>The FILE type is not implemented as a structure, but rather
as a CYG_ADDRESS. </P
as a CYG_ADDRESS. </P
></LI
></LI
><LI
><LI
><P
><P
>The GNU C compiler will place its own <SPAN
>The GNU C compiler will place its own <SPAN
CLASS="emphasis"
CLASS="emphasis"
><I
><I
CLASS="EMPHASIS"
CLASS="EMPHASIS"
>built-in</I
>built-in</I
></SPAN
></SPAN
> implementations
> implementations
instead of some C library functions. This can be turned off with
instead of some C library functions. This can be turned off with
the <SPAN
the <SPAN
CLASS="emphasis"
CLASS="emphasis"
><I
><I
CLASS="EMPHASIS"
CLASS="EMPHASIS"
>-fno-builtin</I
>-fno-builtin</I
></SPAN
></SPAN
> option. The functions affected
> option. The functions affected
by this are
by this are
<TT
<TT
CLASS="FUNCTION"
CLASS="FUNCTION"
>abs()</TT
>abs()</TT
>
>
,
,
<TT
<TT
CLASS="FUNCTION"
CLASS="FUNCTION"
>cos()</TT
>cos()</TT
>
>
,
,
<TT
<TT
CLASS="FUNCTION"
CLASS="FUNCTION"
>fabs()</TT
>fabs()</TT
>
>
,
,
<TT
<TT
CLASS="FUNCTION"
CLASS="FUNCTION"
>labs()</TT
>labs()</TT
>
>
,
,
<TT
<TT
CLASS="FUNCTION"
CLASS="FUNCTION"
>memcmp()</TT
>memcmp()</TT
>
>
,
,
<TT
<TT
CLASS="FUNCTION"
CLASS="FUNCTION"
>memcpy()</TT
>memcpy()</TT
>
>
,
,
<TT
<TT
CLASS="FUNCTION"
CLASS="FUNCTION"
>sin()</TT
>sin()</TT
>
>
,
,
<TT
<TT
CLASS="FUNCTION"
CLASS="FUNCTION"
>sqrt()</TT
>sqrt()</TT
>
>
,
,
<TT
<TT
CLASS="FUNCTION"
CLASS="FUNCTION"
>strcmp()</TT
>strcmp()</TT
>
>
,
,
<TT
<TT
CLASS="FUNCTION"
CLASS="FUNCTION"
>strcpy()</TT
>strcpy()</TT
>
>
, and
, and
<TT
<TT
CLASS="FUNCTION"
CLASS="FUNCTION"
>strlen()</TT
>strlen()</TT
>
>
.</P
.</P
></LI
></LI
><LI
><LI
><P
><P
>For faster execution speed you should avoid this option
>For faster execution speed you should avoid this option
and let the compiler use its built-ins. This can be turned off by
and let the compiler use its built-ins. This can be turned off by
invoking
invoking
<SPAN
<SPAN
CLASS="emphasis"
CLASS="emphasis"
><I
><I
CLASS="EMPHASIS"
CLASS="EMPHASIS"
>GCC</I
>GCC</I
></SPAN
></SPAN
>
>
 with the <SPAN
 with the <SPAN
CLASS="emphasis"
CLASS="emphasis"
><I
><I
CLASS="EMPHASIS"
CLASS="EMPHASIS"
>-fno-builtin</I
>-fno-builtin</I
></SPAN
></SPAN
> option. </P
> option. </P
></LI
></LI
><LI
><LI
><P
><P
><TT
><TT
CLASS="FUNCTION"
CLASS="FUNCTION"
>memcpy()</TT
>memcpy()</TT
>
>
 and
 and
<TT
<TT
CLASS="FUNCTION"
CLASS="FUNCTION"
>memset()</TT
>memset()</TT
>
>
 are located in the infrastructure package, not in the C library
 are located in the infrastructure package, not in the C library
package. This is because the compiler calls these functions, and
package. This is because the compiler calls these functions, and
the kernel needs to resolve them even if the C library is not configured. </P
the kernel needs to resolve them even if the C library is not configured. </P
></LI
></LI
><LI
><LI
><P
><P
>Error codes such as EDOM and ERANGE, as well as
>Error codes such as EDOM and ERANGE, as well as
<TT
<TT
CLASS="FUNCTION"
CLASS="FUNCTION"
>strerror()</TT
>strerror()</TT
>
>
, are implemented in the <SPAN
, are implemented in the <SPAN
CLASS="emphasis"
CLASS="emphasis"
><I
><I
CLASS="EMPHASIS"
CLASS="EMPHASIS"
>error</I
>error</I
></SPAN
></SPAN
> package. The
> package. The
error package is separate from the rest of the C and math libraries
error package is separate from the rest of the C and math libraries
so that the rest of
so that the rest of
<SPAN
<SPAN
CLASS="emphasis"
CLASS="emphasis"
><I
><I
CLASS="EMPHASIS"
CLASS="EMPHASIS"
>eCos</I
>eCos</I
></SPAN
></SPAN
>
>
 can use these error handling facilities even if the C library is
 can use these error handling facilities even if the C library is
not configured. </P
not configured. </P
></LI
></LI
><LI
><LI
><P
><P
>When
>When
<TT
<TT
CLASS="FUNCTION"
CLASS="FUNCTION"
>free()</TT
>free()</TT
>
>
 is invoked, heap memory will normally be coalesced. If the CYGSEM_KERNEL_MEMORY_COALESCE
 is invoked, heap memory will normally be coalesced. If the CYGSEM_KERNEL_MEMORY_COALESCE
configuration parameter is not set, memory will not be coalesced,
configuration parameter is not set, memory will not be coalesced,
which might cause programs to fail. </P
which might cause programs to fail. </P
></LI
></LI
><LI
><LI
><P
><P
>Signals, as implemented by
>Signals, as implemented by
<TT
<TT
CLASS="FILENAME"
CLASS="FILENAME"
>&lt;signal.h&gt;</TT
>&lt;signal.h&gt;</TT
>, are guaranteed to work
>, are guaranteed to work
correctly if raised using the
correctly if raised using the
<TT
<TT
CLASS="FUNCTION"
CLASS="FUNCTION"
>raise()</TT
>raise()</TT
>
>
 function from a normal working program context. Using signals from
 function from a normal working program context. Using signals from
within an ISR or DSR context is not expected to work. Also, it is
within an ISR or DSR context is not expected to work. Also, it is
not guaranteed that if CYGSEM_LIBC_SIGNALS_HWEXCEPTIONS
not guaranteed that if CYGSEM_LIBC_SIGNALS_HWEXCEPTIONS
is set, that handling a signal using
is set, that handling a signal using
<TT
<TT
CLASS="FUNCTION"
CLASS="FUNCTION"
>signal()</TT
>signal()</TT
>
>
 will necessarily catch that form of exception. For example, it
 will necessarily catch that form of exception. For example, it
may be expected that a divide-by-zero error would be caught by handling
may be expected that a divide-by-zero error would be caught by handling
<TT
<TT
CLASS="VARNAME"
CLASS="VARNAME"
>SIGFPE</TT
>SIGFPE</TT
>. However it depends on the underlying HAL implementation to implement
>. However it depends on the underlying HAL implementation to implement
the required hardware exception. And indeed the hardware itself
the required hardware exception. And indeed the hardware itself
may not be capable of detecting these exceptions so it may not be
may not be capable of detecting these exceptions so it may not be
possible for the HAL implementer to do this in any case. Despite
possible for the HAL implementer to do this in any case. Despite
this lack of guarantees in this respect, the signals implementation
this lack of guarantees in this respect, the signals implementation
is still ISO C compliant since ISO C does not offer any such guarantees
is still ISO C compliant since ISO C does not offer any such guarantees
either. </P
either. </P
></LI
></LI
><LI
><LI
><P
><P
>The
>The
<TT
<TT
CLASS="FUNCTION"
CLASS="FUNCTION"
>getenv()</TT
>getenv()</TT
>
>
 function is implemented (unless the CYGPKG_LIBC_ENVIRONMENT configuration
 function is implemented (unless the CYGPKG_LIBC_ENVIRONMENT configuration
option is turned off), but there is no shell or
option is turned off), but there is no shell or
<TT
<TT
CLASS="FUNCTION"
CLASS="FUNCTION"
>putenv()</TT
>putenv()</TT
>
>
 function to set the environment dynamically. The environment is
 function to set the environment dynamically. The environment is
set in a global variable environ, declared as:</P
set in a global variable environ, declared as:</P
><TABLE
><TABLE
BORDER="5"
BORDER="5"
BGCOLOR="#E0E0F0"
BGCOLOR="#E0E0F0"
WIDTH="70%"
WIDTH="70%"
><TR
><TR
><TD
><TD
><PRE
><PRE
CLASS="PROGRAMLISTING"
CLASS="PROGRAMLISTING"
>extern char **environ; // Standard environment definition</PRE
>extern char **environ; // Standard environment definition</PRE
></TD
></TD
></TR
></TR
></TABLE
></TABLE
><P
><P
>The environment can be statically initialized at startup time
>The environment can be statically initialized at startup time
using the CYGDAT_LIBC_DEFAULT_ENVIRONMENT
using the CYGDAT_LIBC_DEFAULT_ENVIRONMENT
option. If so, remember that the final entry of the array initializer
option. If so, remember that the final entry of the array initializer
must be NULL. </P
must be NULL. </P
></LI
></LI
></UL
></UL
><P
><P
>Here is a minimal <SPAN
>Here is a minimal <SPAN
CLASS="emphasis"
CLASS="emphasis"
><I
><I
CLASS="EMPHASIS"
CLASS="EMPHASIS"
>eCos</I
>eCos</I
></SPAN
></SPAN
> program which
> program which
demonstrates the use of environments (see also the test case in <TT
demonstrates the use of environments (see also the test case in <TT
CLASS="FILENAME"
CLASS="FILENAME"
>language/c/libc/current/tests/stdlib/getenv.c</TT
>language/c/libc/current/tests/stdlib/getenv.c</TT
>): </P
>): </P
><TABLE
><TABLE
BORDER="5"
BORDER="5"
BGCOLOR="#E0E0F0"
BGCOLOR="#E0E0F0"
WIDTH="70%"
WIDTH="70%"
><TR
><TR
><TD
><TD
><PRE
><PRE
CLASS="PROGRAMLISTING"
CLASS="PROGRAMLISTING"
>#include &lt;stdio.h&gt;
>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt; // Main header for stdlib functions
#include &lt;stdlib.h&gt; // Main header for stdlib functions
 
 
extern char **environ; // Standard environment definition
extern char **environ; // Standard environment definition
 
 
int
int
main( int argc, char *argv[] )
main( int argc, char *argv[] )
{
{
 char *str;
 char *str;
 char *env[] = { "PATH=/usr/local/bin:/usr/bin",
 char *env[] = { "PATH=/usr/local/bin:/usr/bin",
 "HOME=/home/fred",
 "HOME=/home/fred",
 "TEST=1234=5678",
 "TEST=1234=5678",
 "home=hatstand",
 "home=hatstand",
 NULL };
 NULL };
 
 
 printf("Display the current PATH environment variable\n");
 printf("Display the current PATH environment variable\n");
 
 
 environ = (char **)&amp;env;
 environ = (char **)&amp;env;
 
 
 str = getenv("PATH");
 str = getenv("PATH");
 
 
 if (str==NULL) {
 if (str==NULL) {
  printf("The current PATH is unset\n");
  printf("The current PATH is unset\n");
 } else {
 } else {
  printf("The current PATH is \"%s\"\n", str);
  printf("The current PATH is \"%s\"\n", str);
 }
 }
 return 0;
 return 0;
} </PRE
} </PRE
></TD
></TD
></TR
></TR
></TABLE
></TABLE
></DIV
></DIV
><DIV
><DIV
CLASS="NAVFOOTER"
CLASS="NAVFOOTER"
><HR
><HR
ALIGN="LEFT"
ALIGN="LEFT"
WIDTH="100%"><TABLE
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
SUMMARY="Footer navigation table"
WIDTH="100%"
WIDTH="100%"
BORDER="0"
BORDER="0"
CELLPADDING="0"
CELLPADDING="0"
CELLSPACING="0"
CELLSPACING="0"
><TR
><TR
><TD
><TD
WIDTH="33%"
WIDTH="33%"
ALIGN="left"
ALIGN="left"
VALIGN="top"
VALIGN="top"
><A
><A
HREF="math-library-compatibility-modes.html"
HREF="math-library-compatibility-modes.html"
ACCESSKEY="P"
ACCESSKEY="P"
>Prev</A
>Prev</A
></TD
></TD
><TD
><TD
WIDTH="34%"
WIDTH="34%"
ALIGN="center"
ALIGN="center"
VALIGN="top"
VALIGN="top"
><A
><A
HREF="ecos-ref.html"
HREF="ecos-ref.html"
ACCESSKEY="H"
ACCESSKEY="H"
>Home</A
>Home</A
></TD
></TD
><TD
><TD
WIDTH="33%"
WIDTH="33%"
ALIGN="right"
ALIGN="right"
VALIGN="top"
VALIGN="top"
><A
><A
HREF="libc-thread-safety.html"
HREF="libc-thread-safety.html"
ACCESSKEY="N"
ACCESSKEY="N"
>Next</A
>Next</A
></TD
></TD
></TR
></TR
><TR
><TR
><TD
><TD
WIDTH="33%"
WIDTH="33%"
ALIGN="left"
ALIGN="left"
VALIGN="top"
VALIGN="top"
>Math library compatibility modes</TD
>Math library compatibility modes</TD
><TD
><TD
WIDTH="34%"
WIDTH="34%"
ALIGN="center"
ALIGN="center"
VALIGN="top"
VALIGN="top"
><A
><A
HREF="c-and-math-library-overview.html"
HREF="c-and-math-library-overview.html"
ACCESSKEY="U"
ACCESSKEY="U"
>Up</A
>Up</A
></TD
></TD
><TD
><TD
WIDTH="33%"
WIDTH="33%"
ALIGN="right"
ALIGN="right"
VALIGN="top"
VALIGN="top"
>Thread safety</TD
>Thread safety</TD
></TR
></TR
></TABLE
></TABLE
></DIV
></DIV
></BODY
></BODY
></HTML
></HTML
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.