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

📄 kernel-exceptions.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>Exception handling</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="The eCos Kernel"HREF="kernel.html"><LINKREL="PREVIOUS"TITLE="Thread destructors"HREF="kernel-thread-destructors.html"><LINKREL="NEXT"TITLE="Counters"HREF="kernel-counters.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="kernel-thread-destructors.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="kernel-counters.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><H1><ANAME="KERNEL-EXCEPTIONS">Exception handling</H1><DIVCLASS="REFNAMEDIV"><ANAME="AEN782"></A><H2>Name</H2>cyg_exception_set_handler, cyg_exception_clear_handler, cyg_exception_call_handler&nbsp;--&nbsp;Handle processor exceptions</DIV><DIVCLASS="REFSYNOPSISDIV"><ANAME="AEN787"><H2>Synopsis</H2><DIVCLASS="FUNCSYNOPSIS"><ANAME="AEN788"><P></P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="FUNCSYNOPSISINFO">#include &lt;cyg/kernel/kapi.h&gt;        </PRE></TD></TR></TABLE><P><CODE><CODECLASS="FUNCDEF">void cyg_exception_set_handler</CODE>(cyg_code_t exception_number, cyg_exception_handler_t* new_handler, cyg_addrword_t new_data, cyg_exception_handler_t** old_handler, cyg_addrword_t* old_data);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void cyg_exception_clear_handler</CODE>(cyg_code_t exception_number);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void cyg_exception_call_handler</CODE>(cyg_handle_t thread, cyg_code_t exception_number, cyg_addrword_t exception_info);</CODE></P><P></P></DIV></DIV><DIVCLASS="REFSECT1"><ANAME="AEN817"></A><H2>Description</H2><P>Sometimes code attempts operations that are not legal on the currenthardware, for example dividing by zero, or accessing data through apointer that is not properly aligned. When this happens the hardwarewill raise an exception. This is very similar to an interrupt, buthappens synchronously with code execution rather than asynchronouslyand hence can be tied to the thread that is currently running.      </P><P>The exceptions that can be raised depend very much on the hardware,especially the processor. The corresponding documentation should beconsulted for more details. Alternatively the architectural HAL headerfile <TTCLASS="FILENAME">hal_intr.h</TT>, or one of thevariant or platform header files it includes, will contain appropriatedefinitions. The details of how to handle exceptions, includingwhether or not it is possible to recover from them, also depend on thehardware.       </P><P>Exception handling is optional, and can be disabled through theconfiguration option <TTCLASS="VARNAME">CYGPKG_KERNEL_EXCEPTIONS</TT>. Ifan application has been exhaustively tested and is trusted never toraise a hardware exception then this option can be disabled and codeand data sizes will be reduced somewhat. If exceptions are leftenabled then the system will provide default handlers for the variousexceptions, but these do nothing. Even the specific type of exceptionis ignored, so there is no point in attempting to decode this anddistinguish between say a divide-by-zero and an unaligned access.If the application installs its own handlers and wants details of thespecific exception being raised then the configuration option<TTCLASS="VARNAME">CYGSEM_KERNEL_EXCEPTIONS_DECODE</TT> has to be enabled.      </P><P>An alternative handler can be installed using<TTCLASS="FUNCTION">cyg_exception_set_handler</TT>. This requires a codefor the exception, a function pointer for the new exception handler,and a parameter to be passed to this handler. Details of thepreviously installed exception handler will be returned via theremaining two arguments, allowing that handler to be reinstated, ornull pointers can be used if this information is of no interest. Anexception handling function should take the following form:      </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">voidmy_exception_handler(cyg_addrword_t data, cyg_code_t exception, cyg_addrword_t info){    &#8230;}      </PRE></TD></TR></TABLE><P>The data argument corresponds to the <TTCLASS="PARAMETER"><I>new_data</I></TT> parameter supplied to <TTCLASS="FUNCTION">cyg_exception_set_handler</TT>.The exception code is provided as well, in case a single handler isexpected to support multiple exceptions. The <TTCLASS="PARAMETER"><I>info</I></TT> argument will depend on the hardware and on the specific exception.      </P><P><TTCLASS="FUNCTION">cyg_exception_clear_handler</TT> can be used torestore the default handler, if desired. It is also possible forsoftware to raise an exception and cause the current handler to beinvoked, but generally this is useful only for testing.      </P><P>By default the system maintains a single set of global exceptionhandlers. However, since exceptions occur synchronously it issometimes useful to handle them on a per-thread basis, and have adifferent set of handlers for each thread. This behaviour can beobtained by disabling the configuration option<TTCLASS="VARNAME">CYGSEM_KERNEL_EXCEPTIONS_GLOBAL</TT>. If per-threadexception handlers are being used then<TTCLASS="FUNCTION">cyg_exception_set_handler</TT> and<TTCLASS="FUNCTION">cyg_exception_clear_handler</TT> apply to the currentthread. Otherwise they apply to the global set of handlers.      </P><DIVCLASS="CAUTION"><P></P><TABLECLASS="CAUTION"BORDER="1"WIDTH="100%"><TR><TDALIGN="CENTER"><B>Caution</B></TD></TR><TR><TDALIGN="LEFT"><P>In the current implementation<TTCLASS="FUNCTION">cyg_exception_call_handler</TT> can only be used onthe current thread. There is no support for delivering an exception toanother thread.      </P></TD></TR></TABLE></DIV><DIVCLASS="NOTE"><BLOCKQUOTECLASS="NOTE"><P><B>Note: </B>Exceptions at the eCos kernel level refer specifically tohardware-related events such as unaligned accesses to memory ordivision by zero. There is no relation with other concepts that arealso known as exceptions, for example the <TTCLASS="LITERAL">throw</TT> and<TTCLASS="LITERAL">catch</TT> facilities associated with C++.      </P></BLOCKQUOTE></DIV></DIV><DIVCLASS="REFSECT1"><ANAME="KERNEL-EXCEPTIONS-CONTEXT"></A><H2>Valid contexts</H2><P>If the system is configured with a single set of global exceptionhandlers then<TTCLASS="FUNCTION">cyg_exception_set_handler</TT> and<TTCLASS="FUNCTION">cyg_exception_clear_handler</TT> may be called duringinitialization or from thread context. If instead per-thread exceptionhandlers are being used then it is not possible to install newhandlers during initialization because the functions operateimplicitly on the current thread, so they can only be called fromthread context. <TTCLASS="FUNCTION">cyg_exception_call_handler</TT> shouldonly be called from thread context.      </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="kernel-thread-destructors.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="kernel-counters.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Thread destructors</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="kernel.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Counters</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

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