source: rtems/c/src/exec/score/cpu/i386/cpu.h @ ac7d5ef0

4.104.114.84.95
Last change on this file since ac7d5ef0 was ac7d5ef0, checked in by Joel Sherrill <joel.sherrill@…>, on 05/11/95 at 17:39:37

Initial revision

  • Property mode set to 100644
File size: 8.9 KB
Line 
1/*  cpu.h
2 *
3 *  This include file contains information pertaining to the Intel
4 *  i386 processor.
5 *
6 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
7 *  On-Line Applications Research Corporation (OAR).
8 *  All rights assigned to U.S. Government, 1994.
9 *
10 *  This material may be reproduced by or for the U.S. Government pursuant
11 *  to the copyright license under the clause at DFARS 252.227-7013.  This
12 *  notice must appear in all copies of this file and its derivatives.
13 *
14 *  $Id$
15 */
16
17#ifndef __CPU_h
18#define __CPU_h
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24#include <i386.h>
25
26/* conditional compilation parameters */
27
28#define CPU_INLINE_ENABLE_DISPATCH       TRUE
29#define CPU_UNROLL_ENQUEUE_PRIORITY      FALSE
30
31/*
32 *  i386 has an RTEMS allocated and managed interrupt stack.
33 */
34
35#define CPU_HAS_SOFTWARE_INTERRUPT_STACK TRUE
36#define CPU_HAS_HARDWARE_INTERRUPT_STACK FALSE
37#define CPU_ALLOCATE_INTERRUPT_STACK     TRUE
38
39/*
40 *  Some family members have no FP, some have an FPU such as the i387
41 *  for the i386, others have it built in (i486DX, Pentium).
42 */
43
44#if ( I386_HAS_FPU == 1 )
45#define CPU_HARDWARE_FP     TRUE    /* i387 for i386 */
46#else
47#define CPU_HARDWARE_FP     FALSE
48#endif
49
50#define CPU_ALL_TASKS_ARE_FP             FALSE
51#define CPU_IDLE_TASK_IS_FP              FALSE
52#define CPU_USE_DEFERRED_FP_SWITCH       TRUE
53
54#define CPU_PROVIDES_IDLE_THREAD_BODY    FALSE
55#define CPU_STACK_GROWS_UP               FALSE
56#define CPU_STRUCTURE_ALIGNMENT
57
58/* structures */
59
60/*
61 *  Basic integer context for the i386 family.
62 */
63
64typedef struct {
65  unsigned32  eflags;   /* extended flags register                   */
66  void       *esp;      /* extended stack pointer register           */
67  void       *ebp;      /* extended base pointer register            */
68  unsigned32  ebx;      /* extended bx register                      */
69  unsigned32  esi;      /* extended source index register            */
70  unsigned32  edi;      /* extended destination index flags register */
71}   Context_Control;
72
73/*
74 *  FP context save area for the i387 numeric coprocessors.
75 */
76
77typedef struct {
78  unsigned8   fp_save_area[108];    /* context size area for I80387 */
79                                    /*  28 bytes for environment    */
80} Context_Control_fp;
81
82/*
83 *  The following structure defines the set of information saved
84 *  on the current stack by RTEMS upon receipt of each interrupt.
85 */
86
87typedef struct {
88  unsigned32   TBD;   /* XXX Fix for this CPU */
89} CPU_Interrupt_frame;
90
91/*
92 *  The following table contains the information required to configure
93 *  the i386 specific parameters.
94 */
95
96typedef struct {
97  void       (*pretasking_hook)( void );
98  void       (*predriver_hook)( void );
99  void       (*postdriver_hook)( void );
100  void       (*idle_task)( void );
101  boolean      do_zero_of_workspace;
102  unsigned32   interrupt_stack_size;
103  unsigned32   extra_system_initialization_stack;
104
105  unsigned32   interrupt_table_segment;
106  void        *interrupt_table_offset;
107}   rtems_cpu_table;
108
109/*
110 *  context size area for floating point
111 *
112 *  NOTE:  This is out of place on the i386 to avoid a forward reference.
113 */
114
115#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
116
117/* variables */
118
119EXTERN unsigned8  _CPU_Null_fp_context[ CPU_CONTEXT_FP_SIZE ];
120EXTERN void      *_CPU_Interrupt_stack_low;
121EXTERN void      *_CPU_Interrupt_stack_high;
122
123/* constants */
124
125/*
126 *  This defines the number of levels and the mask used to pick those
127 *  bits out of a thread mode.
128 */
129
130#define CPU_MODES_INTERRUPT_LEVEL  0x00000001 /* interrupt level in mode */
131#define CPU_MODES_INTERRUPT_MASK   0x00000001 /* interrupt level in mode */
132
133/*
134 *  extra stack required by system initialization thread
135 */
136
137#define CPU_SYSTEM_INITIALIZATION_THREAD_EXTRA_STACK 1024
138
139/*
140 *  i386 family supports 256 distinct vectors.
141 */
142
143#define CPU_INTERRUPT_NUMBER_OF_VECTORS 256
144
145/*
146 *  Minimum size of a thread's stack.
147 *
148 *  NOTE:  256 bytes is probably too low in most cases.
149 */
150
151#define CPU_STACK_MINIMUM_SIZE          256
152
153/*
154 *  i386 is pretty tolerant of alignment.  Just put things on 4 byte boundaries.
155 */
156
157#define CPU_ALIGNMENT                    4
158#define CPU_HEAP_ALIGNMENT               CPU_ALIGNMENT
159#define CPU_PARTITION_ALIGNMENT          CPU_ALIGNMENT
160
161/*
162 *  On i386 thread stacks require no further alignment after allocation
163 *  from the Workspace.
164 */
165
166#define CPU_STACK_ALIGNMENT             0
167
168/* macros */
169
170/*
171 *  ISR handler macros
172 *
173 *  These macros perform the following functions:
174 *     + disable all maskable CPU interrupts
175 *     + restore previous interrupt level (enable)
176 *     + temporarily restore interrupts (flash)
177 *     + set a particular level
178 */
179
180#define _CPU_ISR_Disable( _level ) i386_disable_interrupts( _level )
181
182#define _CPU_ISR_Enable( _level )  i386_enable_interrupts( _level )
183
184#define _CPU_ISR_Flash( _level )   i386_flash_interrupts( _level )
185
186#define _CPU_ISR_Set_level( _new_level ) \
187  { \
188    if ( _new_level ) asm volatile ( "cli" ); \
189    else              asm volatile ( "sti" ); \
190  }
191
192/* end of ISR handler macros */
193
194/*
195 *  Context handler macros
196 *
197 *  These macros perform the following functions:
198 *     + initialize a context area
199 *     + restart the current thread
200 *     + calculate the initial pointer into a FP context area
201 *     + initialize an FP context area
202 */
203
204#define CPU_EFLAGS_INTERRUPTS_ON  0x00003202
205#define CPU_EFLAGS_INTERRUPTS_OFF 0x00003002
206
207#define _CPU_Context_Initialize( _the_context, _stack_base, _size, \
208                                   _isr, _entry_point ) \
209  do { \
210    unsigned32 _stack; \
211    \
212    if ( (_isr) ) (_the_context)->eflags = CPU_EFLAGS_INTERRUPTS_OFF; \
213    else          (_the_context)->eflags = CPU_EFLAGS_INTERRUPTS_ON; \
214    \
215    _stack = ((unsigned32)(_stack_base)) + (_size) - 4; \
216    \
217    *((proc_ptr *)(_stack)) = (_entry_point); \
218    (_the_context)->ebp     = (void *) _stack; \
219    (_the_context)->esp     = (void *) _stack; \
220  } while (0)
221
222#define _CPU_Context_Restart_self( _the_context ) \
223   _CPU_Context_restore( (_the_context) );
224
225#define _CPU_Context_Fp_start( _base, _offset ) \
226   ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
227
228#define _CPU_Context_Initialize_fp( _fp_area ) \
229  { \
230    unsigned32 *_source      = (unsigned32 *) _CPU_Null_fp_context; \
231    unsigned32 *_destination = (unsigned32 *) *(_fp_area); \
232    unsigned32  _index; \
233    \
234    for ( _index=0 ; _index < CPU_CONTEXT_FP_SIZE/4 ; _index++ ) \
235      *_destination++ = *_source++; \
236  }
237
238/* end of Context handler macros */
239
240/*
241 *  Fatal Error manager macros
242 *
243 *  These macros perform the following functions:
244 *    + disable interrupts and halt the CPU
245 */
246
247#define _CPU_Fatal_halt( _error ) \
248  { \
249    asm volatile ( "cli ; \
250                    movl %0,%%eax ; \
251                    hlt" \
252                    : "=r" ((_error)) : "0" ((_error)) \
253    ); \
254  }
255
256/* end of Fatal Error manager macros */
257
258/*
259 *  Bitfield handler macros
260 *
261 *  These macros perform the following functions:
262 *     + scan for the highest numbered (MSB) set in a 16 bit bitfield
263 */
264
265#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
266  { \
267    register unsigned16 __value_in_register = (_value); \
268    \
269    _output = 0; \
270    \
271    asm volatile ( "bsfw    %0,%1 " \
272                    : "=r" (__value_in_register), "=r" (_output) \
273                    : "0"  (__value_in_register), "1"  (_output) \
274    ); \
275  }
276
277/* end of Bitfield handler macros */
278
279/*
280 *  Priority handler macros
281 *
282 *  These macros perform the following functions:
283 *    + return a mask with the bit for this major/minor portion of
284 *      of thread priority set.
285 *    + translate the bit number returned by "Bitfield_find_first_bit"
286 *      into an index into the thread ready chain bit maps
287 */
288
289#define _CPU_Priority_Mask( _bit_number ) \
290  ( 1 << (_bit_number) )
291
292#define _CPU_Priority_Bits_index( _priority ) \
293  (_priority)
294
295/* functions */
296
297/*
298 *  _CPU_Initialize
299 *
300 *  This routine performs CPU dependent initialization.
301 */
302
303void _CPU_Initialize(
304  rtems_cpu_table  *cpu_table,
305  void      (*thread_dispatch)
306);
307
308/*
309 *  _CPU_ISR_install_vector
310 *
311 *  This routine installs an interrupt vector.
312 */
313
314void _CPU_ISR_install_vector(
315  unsigned32  vector,
316  proc_ptr    new_handler,
317  proc_ptr   *old_handler
318);
319
320/*
321 *  _CPU_Context_switch
322 *
323 *  This routine switches from the run context to the heir context.
324 */
325
326void _CPU_Context_switch(
327  Context_Control  *run,
328  Context_Control  *heir
329);
330
331/*
332 *  _CPU_Context_restore
333 *
334 *  This routine is generallu used only to restart self in an
335 *  efficient manner and avoid stack conflicts.
336 */
337
338void _CPU_Context_restore(
339  Context_Control *new_context
340);
341
342/*
343 *  _CPU_Context_save_fp
344 *
345 *  This routine saves the floating point context passed to it.
346 */
347
348void _CPU_Context_save_fp(
349  void **fp_context_ptr
350);
351
352/*
353 *  _CPU_Context_restore_fp
354 *
355 *  This routine restores the floating point context passed to it.
356 */
357
358void _CPU_Context_restore_fp(
359  void **fp_context_ptr
360);
361
362#ifdef __cplusplus
363}
364#endif
365
366#endif
367/* end of include file */
Note: See TracBrowser for help on using the repository browser.