1 <!-- Copyright (C) 2002 Red Hat, Inc. -->
2 <!-- This material may be distributed only subject to the terms -->
3 <!-- and conditions set forth in the Open Publication License, v1.0 -->
4 <!-- or later (the latest version is presently available at -->
5 <!-- http://www.opencontent.org/openpub/). -->
6 <!-- Distribution of the work or derivative of the work in any -->
7 <!-- standard (paper) book form is prohibited unless prior -->
8 <!-- permission is obtained from the copyright holder. -->
13 ><meta name="MSSmartTagsPreventParsing" content="TRUE">
16 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
19 TITLE="eCos Synthetic Target"
20 HREF="hal-synth-arch.html"><LINK
22 TITLE="The Console Device"
23 HREF="synth-console.html"><LINK
25 TITLE="Writing New Devices - target"
26 HREF="synth-new-target.html"></HEAD
37 SUMMARY="Header navigation table"
46 >eCos Synthetic Target</TH
54 HREF="synth-console.html"
68 HREF="synth-new-target.html"
79 NAME="SYNTH-SYSCALLS">System Calls</H1
87 >cyg_hal_sys_xyz -- Access Linux system facilities</DIV
89 CLASS="REFSYNOPSISDIV"
105 CLASS="FUNCSYNOPSISINFO"
106 >#include <cyg/hal/hal_io.h
115 >int cyg_hal_sys_xyzzy</CODE
125 NAME="SYNTH-SYSCALLS-DESCRIPTION"
130 >On a real embedded target eCos interacts with the hardware by peeking
131 and poking various registers, manipulating special regions of memory,
132 and so on. The synthetic target does not access hardware directly.
133 Instead I/O and other operations are emulated by making appropriate
134 Linux system calls. The HAL package exports a number of functions
135 which allow other packages, or even application code, to make these
136 same system calls. However this facility must be used with care: any
137 code which calls, for example, <TT
139 >cyg_hal_sys_write</TT
141 will only ever run on the synthetic target; that functionality is
142 obviously not provided on any real hardware because there is no
143 underlying Linux kernel to implement it.
146 >The synthetic target only provides a subset of the available system
147 calls, specifically those calls which have proved useful to implement
148 I/O emulation. This subset can be extended fairly easily if necessary.
149 All of the available calls, plus associated data structures and
150 macros, are defined in the header file <TT
152 >cyg/hal/hal_io.h</TT
154 convention: given a Linux system call such as
158 >, the synthetic target will prefix
162 > and provide a function with that name.
163 The second argument to the <TT
167 a set of flags such as <TT
171 file will define a matching constant
174 >CYG_HAL_SYS_O_RDONLY</TT
175 >. There are also data
176 structures such as <SPAN
178 >cyg_hal_sys_sigset_t</SPAN
180 matching the Linux data structure <SPAN
186 >In most cases the functions provided by the synthetic target behave as
187 per the documentation for the Linux system calls, and section 2 of the
188 Linux man pages can be consulted for more information. There is one
189 important difference: typically the documentation will say that a
193 > to indicate an error, with the
194 actual error code held in <TT
198 underlying system call and hence the
202 > provided by eCos instead returns
203 a negative number to indicate an error, with the absolute value of
204 that number corresponding to the error code; usually it is the C
205 library which handles this and manipulates errno, but of course
206 synthetic target applications are not linked with that Linux library.
209 >However, there are some exceptions. The Linux kernel has evolved over
210 the years, and some of the original system call interfaces are no
211 longer appropriate. For example the original
215 > system call has been superseded by
219 >, and that is what the
223 > function in the C library actually uses.
224 The old call is still available to preserve binary compatibility but,
225 like the C library, eCos makes use of the new one because it provides
226 the appropriate functionality. In an attempt to reduce confusion the
227 eCos function is called <TT
229 >cyg_hal_sys__newselect</TT
231 in other words it matches the official system call naming scheme. The
232 authoritive source of information on such matters is the Linux kernel
233 sources themselves, and especially its header files.
236 >eCos packages and applications should never
240 > Linux header files directly. For example,
243 >#include </usr/include/fcntl.h></TT
245 to access additional macros or structure definitions, or alternatively
246 manipulating the header file search path, will lead to problems
247 because the Linux header files are likely to duplicate and clash with
248 definitions in the eCos headers. Instead the appropriate functionality
249 should be extracted from the Linux headers and moved into either
252 >cyg/hal/hal_io.h</TT
254 application code, with suitable renaming to avoid clashes with eCos
255 names. Users should be aware that large-scale copying may involve
256 licensing complications.
259 >Adding more system calls is usually straightforward and involves
260 adding one or more lines to the platform-specific file in the
261 appropriate platform HAL, for example
264 >syscall-i386-linux-1.0.S</TT
265 >. However it is necessary
266 to do some research first about the exact interface implemented by the
267 system call, because of issues such as old system calls that have been
268 superseded. The required information can usually be found fairly
269 easily by searching through the Linux kernel sources and possibly the
270 GNU C library sources.
278 SUMMARY="Footer navigation table"
289 HREF="synth-console.html"
298 HREF="hal-synth-arch.html"
307 HREF="synth-new-target.html"
317 >The Console Device</TD
327 >Writing New Devices - target</TD