source: rtems-docs/cpu-supplement/intel_amd_x86.rst @ ec95748

5
Last change on this file since ec95748 was e52906b, checked in by Sebastian Huber <sebastian.huber@…>, on 01/09/19 at 15:14:06

Simplify SPDX-License-Identifier comment

  • Property mode set to 100644
File size: 11.9 KB
Line 
1.. SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. Copyright (C) 1988, 2002 On-Line Applications Research Corporation (OAR)
4.. COMMENT: Jukka Pietarinen <jukka.pietarinen@mrf.fi>, 2008,
5.. COMMENT: Micro-Research Finland Oy
6
7Intel/AMD x86 Specific Information
8**********************************
9
10This chapter discusses the Intel x86 architecture dependencies in this port of
11RTEMS.  This family has multiple implementations from multiple vendors and
12suffers more from having evolved rather than being designed for growth.
13
14For information on the i386 processor, refer to the following documents:
15
16- *386 Programmer's Reference Manual, Intel, Order No.  230985-002*.
17
18- *386 Microprocessor Hardware Reference Manual, Intel,
19  Order No. 231732-003*.
20
21- *80386 System Software Writer's Guide, Intel, Order No.  231499-001*.
22
23- *80387 Programmer's Reference Manual, Intel, Order No.  231917-001*.
24
25CPU Model Dependent Features
26============================
27
28This section presents the set of features which vary across i386
29implementations and are of importance to RTEMS.  The set of CPU model feature
30macros are defined in the :file:`cpukit/score/cpu/i386/i386.h` based upon the
31particular CPU model specified on the compilation command line.
32
33bswap Instruction
34-----------------
35
36The macro ``I386_HAS_BSWAP`` is set to 1 to indicate that this CPU model has
37the ``bswap`` instruction which endian swaps a thirty-two bit quantity.  This
38instruction appears to be present in all CPU models i486's and above.
39
40Calling Conventions
41===================
42
43Processor Background
44--------------------
45
46The i386 architecture supports a simple yet effective call and return
47mechanism.  A subroutine is invoked via the call (``call``) instruction.  This
48instruction pushes the return address on the stack.  The return from subroutine
49(``ret``) instruction pops the return address off the current stack and
50transfers control to that instruction.  It is is important to note that the
51i386 call and return mechanism does not automatically save or restore any
52registers.  It is the responsibility of the high-level language compiler to
53define the register preservation and usage convention.
54
55Calling Mechanism
56-----------------
57
58All RTEMS directives are invoked using a call instruction and return to the
59user application via the ret instruction.
60
61Register Usage
62--------------
63
64As discussed above, the call instruction does not automatically save any
65registers.  RTEMS uses the registers EAX, ECX, and EDX as scratch registers.
66These registers are not preserved by RTEMS directives therefore, the contents
67of these registers should not be assumed upon return from any RTEMS directive.
68
69Parameter Passing
70-----------------
71
72RTEMS assumes that arguments are placed on the current stack before the
73directive is invoked via the call instruction.  The first argument is assumed
74to be closest to the return address on the stack.  This means that the first
75argument of the C calling sequence is pushed last.  The following pseudo-code
76illustrates the typical sequence used to call a RTEMS directive with three (3)
77arguments:
78
79.. code-block:: c
80
81    push third argument
82    push second argument
83    push first argument
84    invoke directive
85    remove arguments from the stack
86
87The arguments to RTEMS are typically pushed onto the stack using a push
88instruction.  These arguments must be removed from the stack after control is
89returned to the caller.  This removal is typically accomplished by adding the
90size of the argument list in bytes to the stack pointer.
91
92Memory Model
93============
94
95Flat Memory Model
96-----------------
97
98RTEMS supports the i386 protected mode, flat memory model with paging disabled.
99In this mode, the i386 automatically converts every address from a logical to a
100physical address each time it is used.  The i386 uses information provided in
101the segment registers and the Global Descriptor Table to convert these
102addresses.  RTEMS assumes the existence of the following segments:
103
104- a single code segment at protection level (0) which contains all application
105  and executive code.
106
107- a single data segment at protection level zero (0) which contains all
108  application and executive data.
109
110The i386 segment registers and associated selectors must be initialized when
111the initialize_executive directive is invoked.  RTEMS treats the segment
112registers as system registers and does not modify or context switch them.
113
114This i386 memory model supports a flat 32-bit address space with addresses
115ranging from 0x00000000 to 0xFFFFFFFF (4 gigabytes).  Each address is
116represented by a 32-bit value and is byte addressable.  The address may be used
117to reference a single byte, half-word (2-bytes), or word (4 bytes).
118
119Interrupt Processing
120====================
121
122Although RTEMS hides many of the processor dependent details of interrupt
123processing, it is important to understand how the RTEMS interrupt manager is
124mapped onto the processor's unique architecture. Discussed in this chapter are
125the the processor's response and control mechanisms as they pertain to RTEMS.
126
127Vectoring of Interrupt Handler
128------------------------------
129
130Although the i386 supports multiple privilege levels, RTEMS and all user
131software executes at privilege level 0.  This decision was made by the RTEMS
132designers to enhance compatibility with processors which do not provide
133sophisticated protection facilities like those of the i386.  This decision
134greatly simplifies the discussion of i386 processing, as one need only consider
135interrupts without privilege transitions.
136
137Upon receipt of an interrupt the i386 automatically performs the following
138actions:
139
140- pushes the EFLAGS register
141
142- pushes the far address of the interrupted instruction
143
144- vectors to the interrupt service routine (ISR).
145
146A nested interrupt is processed similarly by the i386.
147
148Interrupt Stack Frame
149---------------------
150
151The structure of the Interrupt Stack Frame for the i386 which is placed on the
152interrupt stack by the processor in response to an interrupt is as follows:
153
154+----------------------+-------+
155| Old EFLAGS Register  | ESP+8 |
156+----------+-----------+-------+
157|   UNUSED |  Old CS   | ESP+4 |
158+----------+-----------+-------+
159|       Old EIP        | ESP   |
160+----------------------+-------+
161
162
163Interrupt Levels
164----------------
165
166Although RTEMS supports 256 interrupt levels, the i386 only supports two -
167enabled and disabled.  Interrupts are enabled when the interrupt-enable flag
168(IF) in the extended flags (EFLAGS) is set.  Conversely, interrupt processing
169is inhibited when the IF is cleared.  During a non-maskable interrupt, all
170other interrupts, including other non-maskable ones, are inhibited.
171
172RTEMS interrupt levels 0 and 1 such that level zero
173(0) indicates that interrupts are fully enabled and level one that interrupts
174are disabled.  All other RTEMS interrupt levels are undefined and their
175behavior is unpredictable.
176
177Interrupt Stack
178---------------
179
180The i386 family does not support a dedicated hardware interrupt stack.  On this
181processor, RTEMS allocates and manages a dedicated interrupt stack.  As part of
182vectoring a non-nested interrupt service routine, RTEMS switches from the stack
183of the interrupted task to a dedicated interrupt stack.  When a non-nested
184interrupt returns, RTEMS switches back to the stack of the interrupted stack.
185The current stack pointer is not altered by RTEMS on nested interrupt.
186
187Default Fatal Error Processing
188==============================
189
190The default fatal error handler for this architecture disables processor
191interrupts, places the error code in EAX, and executes a HLT instruction to
192halt the processor.
193
194Symmetric Multiprocessing
195=========================
196
197SMP is not supported.
198
199Thread-Local Storage
200====================
201
202Thread-local storage is supported.
203
204Board Support Packages
205======================
206
207System Reset
208------------
209
210An RTEMS based application is initiated when the i386 processor is reset.  When
211the i386 is reset,
212
213- The EAX register is set to indicate the results of the processor's power-up
214  self test.  If the self-test was not executed, the contents of this register
215  are undefined.  Otherwise, a non-zero value indicates the processor is faulty
216  and a zero value indicates a successful self-test.
217
218- The DX register holds a component identifier and revision level.  DH contains
219  3 to indicate an i386 component and DL contains a unique revision level
220  indicator.
221
222- Control register zero (CR0) is set such that the processor is in real mode
223  with paging disabled.  Other portions of CR0 are used to indicate the
224  presence of a numeric coprocessor.
225
226- All bits in the extended flags register (EFLAG) which are not permanently set
227  are cleared.  This inhibits all maskable interrupts.
228
229- The Interrupt Descriptor Register (IDTR) is set to point at address zero.
230
231- All segment registers are set to zero.
232
233- The instruction pointer is set to 0x0000FFF0.  The first instruction executed
234  after a reset is actually at 0xFFFFFFF0 because the i386 asserts the upper
235  twelve address until the first intersegment (FAR) JMP or CALL instruction.
236  When a JMP or CALL is executed, the upper twelve address lines are lowered
237  and the processor begins executing in the first megabyte of memory.
238
239Typically, an intersegment JMP to the application's initialization code is
240placed at address 0xFFFFFFF0.
241
242Processor Initialization
243------------------------
244
245This initialization code is responsible for initializing all data structures
246required by the i386 in protected mode and for actually entering protected
247mode.  The i386 must be placed in protected mode and the segment registers and
248associated selectors must be initialized before the initialize_executive
249directive is invoked.
250
251The initialization code is responsible for initializing the Global Descriptor
252Table such that the i386 is in the thirty-two bit flat memory model with paging
253disabled.  In this mode, the i386 automatically converts every address from a
254logical to a physical address each time it is used.  For more information on
255the memory model used by RTEMS, please refer to the Memory Model chapter in
256this document.
257
258Since the processor is in real mode upon reset, the processor must be switched
259to protected mode before RTEMS can execute.  Before switching to protected
260mode, at least one descriptor table and two descriptors must be created.
261Descriptors are needed for a code segment and a data segment. ( This will give
262you the flat memory model.)  The stack can be placed in a normal read/write
263data segment, so no descriptor for the stack is needed.  Before the GDT can be
264used, the base address and limit must be loaded into the GDTR register using an
265LGDT instruction.
266
267If the hardware allows an NMI to be generated, you need to create the IDT and a
268gate for the NMI interrupt handler.  Before the IDT can be used, the base
269address and limit for the idt must be loaded into the IDTR register using an
270LIDT instruction.
271
272Protected mode is entered by setting thye PE bit in the CR0 register.  Either a
273LMSW or MOV CR0 instruction may be used to set this bit. Because the processor
274overlaps the interpretation of several instructions, it is necessary to discard
275the instructions from the read-ahead cache. A JMP instruction immediately after
276the LMSW changes the flow and empties the processor if intructions which have
277been pre-fetched and/or decoded.  At this point, the processor is in protected
278mode and begins to perform protected mode application initialization.
279
280If the application requires that the IDTR be some value besides zero, then it
281should set it to the required value at this point.  All tasks share the same
282i386 IDTR value.  Because interrupts are enabled automatically by RTEMS as part
283of the initialize_executive directive, the IDTR MUST be set properly before
284this directive is invoked to insure correct interrupt vectoring.  If processor
285caching is to be utilized, then it should be enabled during the reset
286application initialization code.  The reset code which is executed before the
287call to initialize_executive has the following requirements:
288
289For more information regarding the i386 data structures and their contents,
290refer to Intel's 386 Programmer's Reference Manual.
Note: See TracBrowser for help on using the repository browser.