⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 synth-syscalls.html

📁 有关ecos2。0介绍了实时嵌入式的结构以及线程调度的实现和内存的管理等
💻 HTML
字号:
<!-- Copyright (C) 2003 Red Hat, Inc.                                --><!-- This material may be distributed only subject to the terms      --><!-- and conditions set forth in the Open Publication License, v1.0  --><!-- or later (the latest version is presently available at          --><!-- http://www.opencontent.org/openpub/).                           --><!-- Distribution of the work or derivative of the work in any       --><!-- standard (paper) book form is prohibited unless prior           --><!-- permission is obtained from the copyright holder.               --><HTML><HEAD><TITLE>System Calls</TITLE><meta name="MSSmartTagsPreventParsing" content="TRUE"><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="eCos Reference Manual"HREF="ecos-ref.html"><LINKREL="UP"TITLE="eCos Synthetic Target"HREF="hal-synth-arch.html"><LINKREL="PREVIOUS"TITLE="The Console Device"HREF="synth-console.html"><LINKREL="NEXT"TITLE="Writing New Devices - target"HREF="synth-new-target.html"></HEAD><BODYCLASS="REFENTRY"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">eCos Reference Manual</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="synth-console.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="synth-new-target.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><H1><ANAME="SYNTH-SYSCALLS">System Calls</H1><DIVCLASS="REFNAMEDIV"><ANAME="AEN18139"></A><H2>Name</H2>cyg_hal_sys_xyz&nbsp;--&nbsp;Access Linux system facilities</DIV><DIVCLASS="REFSYNOPSISDIV"><ANAME="AEN18142"><H2>Synopsis</H2><DIVCLASS="FUNCSYNOPSIS"><ANAME="AEN18143"><P></P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="FUNCSYNOPSISINFO">#include &lt;cyg/hal/hal_io.h&gt;      </PRE></TD></TR></TABLE><P><CODE><CODECLASS="FUNCDEF">int cyg_hal_sys_xyzzy</CODE>(...);</CODE></P><P></P></DIV></DIV><DIVCLASS="REFSECT1"><ANAME="SYNTH-SYSCALLS-DESCRIPTION"></A><H2>Description</H2><P>On a real embedded target eCos interacts with the hardware by peekingand poking various registers, manipulating special regions of memory,and so on. The synthetic target does not access hardware directly.Instead I/O and other operations are emulated by making appropriateLinux system calls. The HAL package exports a number of functionswhich allow other packages, or even application code, to make thesesame system calls. However this facility must be used with care: anycode which calls, for example, <TTCLASS="FUNCTION">cyg_hal_sys_write</TT>will only ever run on the synthetic target; that functionality isobviously not provided on any real hardware because there is nounderlying Linux kernel to implement it.    </P><P>The synthetic target only provides a subset of the available systemcalls, specifically those calls which have proved useful to implementI/O emulation. This subset can be extended fairly easily if necessary.All of the available calls, plus associated data structures andmacros, are defined in the header file <TTCLASS="FILENAME">cyg/hal/hal_io.h</TT>. There is a simpleconvention: given a Linux system call such as<TTCLASS="FUNCTION">open</TT>, the synthetic target will prefix<TTCLASS="LITERAL">cyg_hal_sys</TT> and provide a function with that name.The second argument to the <TTCLASS="FUNCTION">open</TT> system call isa set of flags such as <TTCLASS="CONSTANT">O_RDONLY</TT>, and the headerfile will define a matching constant<TTCLASS="CONSTANT">CYG_HAL_SYS_O_RDONLY</TT>. There are also datastructures such as <SPANCLASS="STRUCTNAME">cyg_hal_sys_sigset_t</SPAN>,matching the Linux data structure <SPANCLASS="STRUCTNAME">sigset_t</SPAN>.    </P><P>In most cases the functions provided by the synthetic target behave asper the documentation for the Linux system calls, and section 2 of theLinux man pages can be consulted for more information. There is oneimportant difference: typically the documentation will say that afunction returns <TTCLASS="LITERAL">-1</TT> to indicate an error, with theactual error code held in <TTCLASS="VARNAME">errno</TT>; the actualunderlying system call and hence the<TTCLASS="FUNCTION">cyg_hal_sys_xyz</TT> provided by eCos instead returnsa negative number to indicate an error, with the absolute value ofthat number corresponding to the error code; usually it is the Clibrary which handles this and manipulates errno, but of coursesynthetic target applications are not linked with that Linux library.    </P><P>However, there are some exceptions. The Linux kernel has evolved overthe years, and some of the original system call interfaces are nolonger appropriate. For example the original<TTCLASS="FUNCTION">select</TT> system call has been superseded by<TTCLASS="FUNCTION">_newselect</TT>, and that is what the<TTCLASS="FUNCTION">select</TT> function in the C library actually uses.The old call is still available to preserve binary compatibility but,like the C library, eCos makes use of the new one because it providesthe appropriate functionality. In an attempt to reduce confusion theeCos function is called <TTCLASS="FUNCTION">cyg_hal_sys__newselect</TT>,in other words it matches the official system call naming scheme. Theauthoritive source of information on such matters is the Linux kernelsources themselves, and especially its header files.    </P><P>eCos packages and applications should never<TTCLASS="LITERAL">#include</TT> Linux header files directly. For example,doing a <TTCLASS="LITERAL">#include&nbsp;&lt;/usr/include/fcntl.h&gt;</TT>to access additional macros or structure definitions, or alternativelymanipulating the header file search path, will lead to problemsbecause the Linux header files are likely to duplicate and clash withdefinitions in the eCos headers. Instead the appropriate functionalityshould be extracted from the Linux headers and moved into either<TTCLASS="FILENAME">cyg/hal/hal_io.h</TT> or intoapplication code, with suitable renaming to avoid clashes with eCosnames. Users should be aware that large-scale copying may involvelicensing complications.    </P><P>Adding more system calls is usually straightforward and involvesadding one or more lines to the platform-specific file in theappropriate platform HAL, for example<TTCLASS="FILENAME">syscall-i386-linux-1.0.S</TT>. However it is necessaryto do some research first about the exact interface implemented by thesystem call, because of issues such as old system calls that have beensuperseded. The required information can usually be found fairlyeasily by searching through the Linux kernel sources and possibly theGNU C library sources.    </P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="synth-console.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ecos-ref.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="synth-new-target.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">The Console Device</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="hal-synth-arch.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Writing New Devices - target</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -