source: rtems-docs/cpu_supplement/intel_amd_x86.rst @ 489740f

4.115
Last change on this file since 489740f was 489740f, checked in by Chris Johns <chrisj@…>, on 05/20/16 at 02:47:09

Set SPDX License Identifier in each source file.

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