<!-- 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
|
>System Calls</TITLE
|
>System Calls</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="eCos Synthetic Target"
|
TITLE="eCos Synthetic Target"
|
HREF="hal-synth-arch.html"><LINK
|
HREF="hal-synth-arch.html"><LINK
|
REL="PREVIOUS"
|
REL="PREVIOUS"
|
TITLE="The Console Device"
|
TITLE="The Console Device"
|
HREF="synth-console.html"><LINK
|
HREF="synth-console.html"><LINK
|
REL="NEXT"
|
REL="NEXT"
|
TITLE="Writing New Devices - target"
|
TITLE="Writing New Devices - target"
|
HREF="synth-new-target.html"></HEAD
|
HREF="synth-new-target.html"></HEAD
|
><BODY
|
><BODY
|
CLASS="REFENTRY"
|
CLASS="REFENTRY"
|
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="synth-console.html"
|
HREF="synth-console.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"
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="synth-new-target.html"
|
HREF="synth-new-target.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
|
><H1
|
><H1
|
><A
|
><A
|
NAME="SYNTH-SYSCALLS">System Calls</H1
|
NAME="SYNTH-SYSCALLS">System Calls</H1
|
><DIV
|
><DIV
|
CLASS="REFNAMEDIV"
|
CLASS="REFNAMEDIV"
|
><A
|
><A
|
NAME="AEN18139"
|
NAME="AEN18139"
|
></A
|
></A
|
><H2
|
><H2
|
>Name</H2
|
>Name</H2
|
>cyg_hal_sys_xyz -- Access Linux system facilities</DIV
|
>cyg_hal_sys_xyz -- Access Linux system facilities</DIV
|
><DIV
|
><DIV
|
CLASS="REFSYNOPSISDIV"
|
CLASS="REFSYNOPSISDIV"
|
><A
|
><A
|
NAME="AEN18142"><H2
|
NAME="AEN18142"><H2
|
>Synopsis</H2
|
>Synopsis</H2
|
><DIV
|
><DIV
|
CLASS="FUNCSYNOPSIS"
|
CLASS="FUNCSYNOPSIS"
|
><A
|
><A
|
NAME="AEN18143"><P
|
NAME="AEN18143"><P
|
></P
|
></P
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="FUNCSYNOPSISINFO"
|
CLASS="FUNCSYNOPSISINFO"
|
>#include <cyg/hal/hal_io.h>
|
>#include <cyg/hal/hal_io.h>
|
</PRE
|
</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><P
|
><P
|
><CODE
|
><CODE
|
><CODE
|
><CODE
|
CLASS="FUNCDEF"
|
CLASS="FUNCDEF"
|
>int cyg_hal_sys_xyzzy</CODE
|
>int cyg_hal_sys_xyzzy</CODE
|
>(...);</CODE
|
>(...);</CODE
|
></P
|
></P
|
><P
|
><P
|
></P
|
></P
|
></DIV
|
></DIV
|
></DIV
|
></DIV
|
><DIV
|
><DIV
|
CLASS="REFSECT1"
|
CLASS="REFSECT1"
|
><A
|
><A
|
NAME="SYNTH-SYSCALLS-DESCRIPTION"
|
NAME="SYNTH-SYSCALLS-DESCRIPTION"
|
></A
|
></A
|
><H2
|
><H2
|
>Description</H2
|
>Description</H2
|
><P
|
><P
|
>On a real embedded target eCos interacts with the hardware by peeking
|
>On a real embedded target eCos interacts with the hardware by peeking
|
and poking various registers, manipulating special regions of memory,
|
and poking various registers, manipulating special regions of memory,
|
and so on. The synthetic target does not access hardware directly.
|
and so on. The synthetic target does not access hardware directly.
|
Instead I/O and other operations are emulated by making appropriate
|
Instead I/O and other operations are emulated by making appropriate
|
Linux system calls. The HAL package exports a number of functions
|
Linux system calls. The HAL package exports a number of functions
|
which allow other packages, or even application code, to make these
|
which allow other packages, or even application code, to make these
|
same system calls. However this facility must be used with care: any
|
same system calls. However this facility must be used with care: any
|
code which calls, for example, <TT
|
code which calls, for example, <TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>cyg_hal_sys_write</TT
|
>cyg_hal_sys_write</TT
|
>
|
>
|
will only ever run on the synthetic target; that functionality is
|
will only ever run on the synthetic target; that functionality is
|
obviously not provided on any real hardware because there is no
|
obviously not provided on any real hardware because there is no
|
underlying Linux kernel to implement it.
|
underlying Linux kernel to implement it.
|
</P
|
</P
|
><P
|
><P
|
>The synthetic target only provides a subset of the available system
|
>The synthetic target only provides a subset of the available system
|
calls, specifically those calls which have proved useful to implement
|
calls, specifically those calls which have proved useful to implement
|
I/O emulation. This subset can be extended fairly easily if necessary.
|
I/O emulation. This subset can be extended fairly easily if necessary.
|
All of the available calls, plus associated data structures and
|
All of the available calls, plus associated data structures and
|
macros, are defined in the header file <TT
|
macros, are defined in the header file <TT
|
CLASS="FILENAME"
|
CLASS="FILENAME"
|
>cyg/hal/hal_io.h</TT
|
>cyg/hal/hal_io.h</TT
|
>. There is a simple
|
>. There is a simple
|
convention: given a Linux system call such as
|
convention: given a Linux system call such as
|
<TT
|
<TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>open</TT
|
>open</TT
|
>, the synthetic target will prefix
|
>, the synthetic target will prefix
|
<TT
|
<TT
|
CLASS="LITERAL"
|
CLASS="LITERAL"
|
>cyg_hal_sys</TT
|
>cyg_hal_sys</TT
|
> and provide a function with that name.
|
> and provide a function with that name.
|
The second argument to the <TT
|
The second argument to the <TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>open</TT
|
>open</TT
|
> system call is
|
> system call is
|
a set of flags such as <TT
|
a set of flags such as <TT
|
CLASS="CONSTANT"
|
CLASS="CONSTANT"
|
>O_RDONLY</TT
|
>O_RDONLY</TT
|
>, and the header
|
>, and the header
|
file will define a matching constant
|
file will define a matching constant
|
<TT
|
<TT
|
CLASS="CONSTANT"
|
CLASS="CONSTANT"
|
>CYG_HAL_SYS_O_RDONLY</TT
|
>CYG_HAL_SYS_O_RDONLY</TT
|
>. There are also data
|
>. There are also data
|
structures such as <SPAN
|
structures such as <SPAN
|
CLASS="STRUCTNAME"
|
CLASS="STRUCTNAME"
|
>cyg_hal_sys_sigset_t</SPAN
|
>cyg_hal_sys_sigset_t</SPAN
|
>,
|
>,
|
matching the Linux data structure <SPAN
|
matching the Linux data structure <SPAN
|
CLASS="STRUCTNAME"
|
CLASS="STRUCTNAME"
|
>sigset_t</SPAN
|
>sigset_t</SPAN
|
>.
|
>.
|
</P
|
</P
|
><P
|
><P
|
>In most cases the functions provided by the synthetic target behave as
|
>In most cases the functions provided by the synthetic target behave as
|
per the documentation for the Linux system calls, and section 2 of the
|
per the documentation for the Linux system calls, and section 2 of the
|
Linux man pages can be consulted for more information. There is one
|
Linux man pages can be consulted for more information. There is one
|
important difference: typically the documentation will say that a
|
important difference: typically the documentation will say that a
|
function returns <TT
|
function returns <TT
|
CLASS="LITERAL"
|
CLASS="LITERAL"
|
>-1</TT
|
>-1</TT
|
> to indicate an error, with the
|
> to indicate an error, with the
|
actual error code held in <TT
|
actual error code held in <TT
|
CLASS="VARNAME"
|
CLASS="VARNAME"
|
>errno</TT
|
>errno</TT
|
>; the actual
|
>; the actual
|
underlying system call and hence the
|
underlying system call and hence the
|
<TT
|
<TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>cyg_hal_sys_xyz</TT
|
>cyg_hal_sys_xyz</TT
|
> provided by eCos instead returns
|
> provided by eCos instead returns
|
a negative number to indicate an error, with the absolute value of
|
a negative number to indicate an error, with the absolute value of
|
that number corresponding to the error code; usually it is the C
|
that number corresponding to the error code; usually it is the C
|
library which handles this and manipulates errno, but of course
|
library which handles this and manipulates errno, but of course
|
synthetic target applications are not linked with that Linux library.
|
synthetic target applications are not linked with that Linux library.
|
</P
|
</P
|
><P
|
><P
|
>However, there are some exceptions. The Linux kernel has evolved over
|
>However, there are some exceptions. The Linux kernel has evolved over
|
the years, and some of the original system call interfaces are no
|
the years, and some of the original system call interfaces are no
|
longer appropriate. For example the original
|
longer appropriate. For example the original
|
<TT
|
<TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>select</TT
|
>select</TT
|
> system call has been superseded by
|
> system call has been superseded by
|
<TT
|
<TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>_newselect</TT
|
>_newselect</TT
|
>, and that is what the
|
>, and that is what the
|
<TT
|
<TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>select</TT
|
>select</TT
|
> function in the C library actually uses.
|
> function in the C library actually uses.
|
The old call is still available to preserve binary compatibility but,
|
The old call is still available to preserve binary compatibility but,
|
like the C library, eCos makes use of the new one because it provides
|
like the C library, eCos makes use of the new one because it provides
|
the appropriate functionality. In an attempt to reduce confusion the
|
the appropriate functionality. In an attempt to reduce confusion the
|
eCos function is called <TT
|
eCos function is called <TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>cyg_hal_sys__newselect</TT
|
>cyg_hal_sys__newselect</TT
|
>,
|
>,
|
in other words it matches the official system call naming scheme. The
|
in other words it matches the official system call naming scheme. The
|
authoritive source of information on such matters is the Linux kernel
|
authoritive source of information on such matters is the Linux kernel
|
sources themselves, and especially its header files.
|
sources themselves, and especially its header files.
|
</P
|
</P
|
><P
|
><P
|
>eCos packages and applications should never
|
>eCos packages and applications should never
|
<TT
|
<TT
|
CLASS="LITERAL"
|
CLASS="LITERAL"
|
>#include</TT
|
>#include</TT
|
> Linux header files directly. For example,
|
> Linux header files directly. For example,
|
doing a <TT
|
doing a <TT
|
CLASS="LITERAL"
|
CLASS="LITERAL"
|
>#include </usr/include/fcntl.h></TT
|
>#include </usr/include/fcntl.h></TT
|
>
|
>
|
to access additional macros or structure definitions, or alternatively
|
to access additional macros or structure definitions, or alternatively
|
manipulating the header file search path, will lead to problems
|
manipulating the header file search path, will lead to problems
|
because the Linux header files are likely to duplicate and clash with
|
because the Linux header files are likely to duplicate and clash with
|
definitions in the eCos headers. Instead the appropriate functionality
|
definitions in the eCos headers. Instead the appropriate functionality
|
should be extracted from the Linux headers and moved into either
|
should be extracted from the Linux headers and moved into either
|
<TT
|
<TT
|
CLASS="FILENAME"
|
CLASS="FILENAME"
|
>cyg/hal/hal_io.h</TT
|
>cyg/hal/hal_io.h</TT
|
> or into
|
> or into
|
application code, with suitable renaming to avoid clashes with eCos
|
application code, with suitable renaming to avoid clashes with eCos
|
names. Users should be aware that large-scale copying may involve
|
names. Users should be aware that large-scale copying may involve
|
licensing complications.
|
licensing complications.
|
</P
|
</P
|
><P
|
><P
|
>Adding more system calls is usually straightforward and involves
|
>Adding more system calls is usually straightforward and involves
|
adding one or more lines to the platform-specific file in the
|
adding one or more lines to the platform-specific file in the
|
appropriate platform HAL, for example
|
appropriate platform HAL, for example
|
<TT
|
<TT
|
CLASS="FILENAME"
|
CLASS="FILENAME"
|
>syscall-i386-linux-1.0.S</TT
|
>syscall-i386-linux-1.0.S</TT
|
>. However it is necessary
|
>. However it is necessary
|
to do some research first about the exact interface implemented by the
|
to do some research first about the exact interface implemented by the
|
system call, because of issues such as old system calls that have been
|
system call, because of issues such as old system calls that have been
|
superseded. The required information can usually be found fairly
|
superseded. The required information can usually be found fairly
|
easily by searching through the Linux kernel sources and possibly the
|
easily by searching through the Linux kernel sources and possibly the
|
GNU C library sources.
|
GNU C library sources.
|
</P
|
</P
|
></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="synth-console.html"
|
HREF="synth-console.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="synth-new-target.html"
|
HREF="synth-new-target.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"
|
>The Console Device</TD
|
>The Console Device</TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="hal-synth-arch.html"
|
HREF="hal-synth-arch.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"
|
>Writing New Devices - target</TD
|
>Writing New Devices - target</TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
></DIV
|
></DIV
|
></BODY
|
></BODY
|
></HTML
|
></HTML
|
|
|