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

📄 hal-architecture-characterization.html

📁 有关ecos2。0介绍了实时嵌入式的结构以及线程调度的实现和内存的管理等
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!-- 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>Architecture Characterization</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="HAL Interfaces"HREF="hal-interfaces.html"><LINKREL="PREVIOUS"TITLE="HAL Interfaces"HREF="hal-interfaces.html"><LINKREL="NEXT"TITLE="Interrupt Handling"HREF="hal-interrupt-handling.html"></HEAD><BODYCLASS="SECTION"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="hal-interfaces.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 9. HAL Interfaces</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="hal-interrupt-handling.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECTION"><H1CLASS="SECTION"><ANAME="HAL-ARCHITECTURE-CHARACTERIZATION">Architecture Characterization</H1><P>These are definition that are related to the basic architecture of theCPU. These include the CPU context save format, context switching, bittwiddling, breakpoints, stack sizes and address translation.</P><P>Most of these definition are found in<TTCLASS="FILENAME">cyg/hal/hal_arch.h</TT>.  This file is supplied by thearchitecture HAL. If there are variant or platform specificdefinitions then these will be found in<TTCLASS="FILENAME">cyg/hal/var_arch.h</TT> or<TTCLASS="FILENAME">cyg/hal/plf_arch.h</TT>. These files are includeautomatically by this header, so need not be included explicitly.</P><DIVCLASS="SECTION"><H2CLASS="SECTION"><ANAME="AEN7787">Register Save Format</H2><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">typedef struct HAL_SavedRegisters{    /* architecture-dependent list of registers to be saved */ } HAL_SavedRegisters;</PRE></TD></TR></TABLE><P>This structure describes the layout of a saved machine state on thestack. Such states are saved during thread context switches,interrupts and exceptions. Different quantities of state may be savedduring each of these, but usually a thread context state is a subsetof the interrupt state which is itself a subset of an exception state.For debugging purposes, the same structure is used for all threepurposes, but where these states are significantly different, thisstructure may contain a union of the three states.</P></DIV><DIVCLASS="SECTION"><H2CLASS="SECTION"><ANAME="AEN7791">Thread Context Initialization</H2><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">HAL_THREAD_INIT_CONTEXT( sp, arg, entry, id )</PRE></TD></TR></TABLE><P>This macro initializes a thread's context so thatit may be switched to by <TTCLASS="FUNCTION">HAL_THREAD_SWITCH_CONTEXT()</TT>.The arguments are:</P><P></P><DIVCLASS="VARIABLELIST"><DL><DT>sp</DT><DD><P>      A location containing the current value of the thread's stack      pointer. This should be a variable or a structure field. The SP      value will be read out of here and an adjusted value written      back.      </P></DD><DT>arg</DT><DD><P>      A value that is passed as the first argument to the entry      point function.      </P></DD><DT>entry</DT><DD><P>      The address of an entry point function. This will be called      according the C calling conventions, and the value of      <TTCLASS="PARAMETER"><I>arg</I></TT> will be passed as the first      argument. This function should have the following type signature      <TTCLASS="FUNCTION">void entry(CYG_ADDRWORD arg)</TT>.      </P></DD><DT>id</DT><DD><P>      A thread id value. This is only used for debugging purposes,      it is ORed into the initialization pattern for unused registers      and may be used to help identify the thread from its register dump.      The least significant 16 bits of this value should be zero to allow      space for a register identifier.      </P></DD></DL></DIV></DIV><DIVCLASS="SECTION"><H2CLASS="SECTION"><ANAME="HAL-CONTEXT-SWITCH">Thread Context Switching</H2><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">HAL_THREAD_LOAD_CONTEXT( to )HAL_THREAD_SWITCH_CONTEXT( from, to )</PRE></TD></TR></TABLE><P>These macros implement the thread switch code. The arguments are:</P><P></P><DIVCLASS="VARIABLELIST"><DL><DT>from</DT><DD><P>      A pointer to a location where the stack pointer of the current      thread will be stored.      </P></DD><DT>to</DT><DD><P>      A pointer to a location from where the stack pointer of the next      thread will be read.      </P></DD></DL></DIV><P>For <TTCLASS="FUNCTION">HAL_THREAD_LOAD_CONTEXT()</TT> the current CPUstate is discarded and the state of the destination thread isloaded. This is only used once, to load the first thread when thescheduler is started.</P><P>For <TTCLASS="FUNCTION">HAL_THREAD_SWITCH_CONTEXT()</TT> the state of thecurrent thread is saved onto its stack, using the current value of thestack pointer, and the address of the saved state placed in<TTCLASS="PARAMETER"><I>*from</I></TT>.  The value in<TTCLASS="PARAMETER"><I>*to</I></TT> is then read and the state of the newthread is loaded from it.</P><P>While these two operations may be implemented with inline assembler,they are normally implemented as calls to assembly code functions inthe HAL. There are two advantages to doing it this way. First, thereturn link of the call provides a convenient PC value to be used inthe saved context. Second, the calling conventions mean that thecompiler will have already saved the caller-saved registers before thecall, so the HAL need only save the callee-saved registers.</P><P>The implementation of <TTCLASS="FUNCTION">HAL_THREAD_SWITCH_CONTEXT()</TT>saves the current CPU state on the stack, including the currentinterrupt state (or at least the register that contains it). Fordebugging purposes it is useful to save the entire register set, butfor performance only the ABI-defined callee-saved registers need besaved. If it is implemented, the option<TTCLASS="LITERAL">CYGDBG_HAL_COMMON_CONTEXT_SAVE_MINIMUM</TT> controlshow many registers are saved.</P><P>The implementation of <TTCLASS="FUNCTION">HAL_THREAD_LOAD_CONTEXT()</TT>loads a thread context, destroying the current context. With a littlecare this can be implemented by sharing code with<TTCLASS="FUNCTION">HAL_THREAD_SWITCH_CONTEXT()</TT>. To load a threadcontext simply requires the saved registers to be restored from thestack and a jump or return made back to the saved PC.</P><P>Note that interrupts are not disabled during this process, anyinterrupts that occur will be delivered onto the stack to which thecurrent CPU stack pointer points. Hence the stack pointershould never be invalid, or loaded with a value that might cause thesaved state to become corrupted by an interrupt. However, the currentinterrupt state is saved and restored as part of the threadcontext. If a thread disables interrupts and does something to cause acontext switch, interrupts may be re-enabled on switching to anotherthread. Interrupts will be disabled again when the original threadregains control.</P></DIV><DIVCLASS="SECTION"><H2CLASS="SECTION"><ANAME="AEN7842">Bit indexing</H2><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">HAL_LSBIT_INDEX( index, mask )HAL_MSBIT_INDEX( index, mask )</PRE></TD></TR></TABLE><P>These macros place in <TTCLASS="PARAMETER"><I>index</I></TT> the bit index ofthe least significant bit in <TTCLASS="PARAMETER"><I>mask</I></TT>. Somearchitectures have instruction level support for one or other of theseoperations. If no architectural support is available, then thesemacros may call C functions to do the job.</P></DIV><DIVCLASS="SECTION"><H2CLASS="SECTION"><ANAME="AEN7848">Idle thread activity</H2><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">HAL_IDLE_THREAD_ACTION( count )</PRE></TD></TR

⌨️ 快捷键说明

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