source: rtems/cpukit/score/cpu/i386/rtems/score/cpu.h @ effa6593

4.104.114.84.95
Last change on this file since effa6593 was effa6593, checked in by Joel Sherrill <joel.sherrill@…>, on 01/03/01 at 16:29:49

2001-01-03 Joel Sherrill <joel@…>

  • rtems/score/cpu.h: Added _CPU_Initialize_vectors().
  • Property mode set to 100644
File size: 12.6 KB
Line 
1/*  cpu.h
2 *
3 *  This include file contains information pertaining to the Intel
4 *  i386 processor.
5 *
6 *  COPYRIGHT (c) 1989-1999.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.OARcorp.com/rtems/license.html.
12 *
13 *  $Id$
14 */
15
16#ifndef __CPU_h
17#define __CPU_h
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23#include <rtems/score/i386.h>              /* pick up machine definitions */
24#include <libcpu/cpu.h>
25
26#ifndef ASM
27#include <rtems/score/i386types.h>
28#endif
29
30/* conditional compilation parameters */
31
32#define CPU_INLINE_ENABLE_DISPATCH       TRUE
33#define CPU_UNROLL_ENQUEUE_PRIORITY      FALSE
34
35/*
36 *  i386 has an RTEMS allocated and managed interrupt stack.
37 */
38
39#define CPU_HAS_SOFTWARE_INTERRUPT_STACK TRUE
40#define CPU_HAS_HARDWARE_INTERRUPT_STACK FALSE
41#define CPU_ALLOCATE_INTERRUPT_STACK     TRUE
42
43/*
44 *  Does the RTEMS invoke the user's ISR with the vector number and
45 *  a pointer to the saved interrupt frame (1) or just the vector
46 *  number (0)?
47 */
48
49#define CPU_ISR_PASSES_FRAME_POINTER 0
50
51/*
52 *  Some family members have no FP, some have an FPU such as the i387
53 *  for the i386, others have it built in (i486DX, Pentium).
54 */
55
56#if ( I386_HAS_FPU == 1 )
57#define CPU_HARDWARE_FP     TRUE    /* i387 for i386 */
58#else
59#define CPU_HARDWARE_FP     FALSE
60#endif
61#define CPU_SOFTWARE_FP     FALSE
62
63#define CPU_ALL_TASKS_ARE_FP             FALSE
64#define CPU_IDLE_TASK_IS_FP              FALSE
65#define CPU_USE_DEFERRED_FP_SWITCH       TRUE
66
67#define CPU_STACK_GROWS_UP               FALSE
68#define CPU_STRUCTURE_ALIGNMENT
69
70/*
71 *  Does this port provide a CPU dependent IDLE task implementation?
72 * 
73 *  If TRUE, then the routine _CPU_Thread_Idle_body
74 *  must be provided and is the default IDLE thread body instead of
75 *  _CPU_Thread_Idle_body.
76 *
77 *  If FALSE, then use the generic IDLE thread body if the BSP does
78 *  not provide one.
79 */
80 
81#define CPU_PROVIDES_IDLE_THREAD_BODY    TRUE
82
83/*
84 *  Define what is required to specify how the network to host conversion
85 *  routines are handled.
86 */
87
88#define CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES     FALSE
89#define CPU_BIG_ENDIAN                           FALSE
90#define CPU_LITTLE_ENDIAN                        TRUE
91
92/* structures */
93
94/*
95 *  Basic integer context for the i386 family.
96 */
97
98typedef struct {
99  unsigned32  eflags;   /* extended flags register                   */
100  void       *esp;      /* extended stack pointer register           */
101  void       *ebp;      /* extended base pointer register            */
102  unsigned32  ebx;      /* extended bx register                      */
103  unsigned32  esi;      /* extended source index register            */
104  unsigned32  edi;      /* extended destination index flags register */
105}   Context_Control;
106
107/*
108 *  FP context save area for the i387 numeric coprocessors.
109 */
110
111typedef struct {
112  unsigned8   fp_save_area[108];    /* context size area for I80387 */
113                                    /*  28 bytes for environment    */
114} Context_Control_fp;
115
116
117/*
118 *  The following structure defines the set of information saved
119 *  on the current stack by RTEMS upon receipt of execptions.
120 *
121 * idtIndex is either the interrupt number or the trap/exception number.
122 * faultCode is the code pushed by the processor on some exceptions.
123 */
124
125typedef struct {
126  unsigned32  edi;
127  unsigned32  esi;
128  unsigned32  ebp;
129  unsigned32  esp0;
130  unsigned32  ebx;
131  unsigned32  edx;
132  unsigned32  ecx;
133  unsigned32  eax;
134  unsigned32  idtIndex;
135  unsigned32  faultCode;
136  unsigned32  eip;
137  unsigned32  cs;
138  unsigned32  eflags;
139} CPU_Exception_frame;
140
141typedef void (*cpuExcHandlerType) (CPU_Exception_frame*);
142extern cpuExcHandlerType _currentExcHandler;
143extern void rtems_exception_init_mngt();
144
145/*
146 *  The following structure defines the set of information saved
147 *  on the current stack by RTEMS upon receipt of each interrupt
148 *  that will lead to re-enter the kernel to signal the thread.
149 */
150
151typedef CPU_Exception_frame CPU_Interrupt_frame;
152
153typedef enum {
154  I386_EXCEPTION_DIVIDE_BY_ZERO      = 0,
155  I386_EXCEPTION_DEBUG               = 1,
156  I386_EXCEPTION_NMI                 = 2,
157  I386_EXCEPTION_BREAKPOINT          = 3,
158  I386_EXCEPTION_OVERFLOW            = 4,
159  I386_EXCEPTION_BOUND               = 5,
160  I386_EXCEPTION_ILLEGAL_INSTR       = 6,
161  I386_EXCEPTION_MATH_COPROC_UNAVAIL = 7,
162  I386_EXCEPTION_DOUBLE_FAULT        = 8,
163  I386_EXCEPTION_I386_COPROC_SEG_ERR = 9,
164  I386_EXCEPTION_INVALID_TSS         = 10,
165  I386_EXCEPTION_SEGMENT_NOT_PRESENT = 11,
166  I386_EXCEPTION_STACK_SEGMENT_FAULT = 12,
167  I386_EXCEPTION_GENERAL_PROT_ERR    = 13,
168  I386_EXCEPTION_PAGE_FAULT          = 14,
169  I386_EXCEPTION_INTEL_RES15         = 15,
170  I386_EXCEPTION_FLOAT_ERROR         = 16,
171  I386_EXCEPTION_ALIGN_CHECK         = 17,
172  I386_EXCEPTION_MACHINE_CHECK       = 18,
173  I386_EXCEPTION_ENTER_RDBG          = 50     /* to enter manually RDBG */
174
175} Intel_symbolic_exception_name;
176 
177
178/*
179 *  The following table contains the information required to configure
180 *  the i386 specific parameters.
181 */
182
183typedef struct {
184  void       (*pretasking_hook)( void );
185  void       (*predriver_hook)( void );
186  void       (*postdriver_hook)( void );
187  void       (*idle_task)( void );
188  boolean      do_zero_of_workspace;
189  unsigned32   idle_task_stack_size;
190  unsigned32   interrupt_stack_size;
191  unsigned32   extra_mpci_receive_server_stack;
192  void *     (*stack_allocate_hook)( unsigned32 );
193  void       (*stack_free_hook)( void* );
194  /* end of fields required on all CPUs */
195
196  unsigned32   interrupt_table_segment;
197  void        *interrupt_table_offset;
198}   rtems_cpu_table;
199
200/*
201 *  Macros to access required entires in the CPU Table are in
202 *  the file rtems/system.h.
203 */
204
205/*
206 *  Macros to access i386 specific additions to the CPU Table
207 */
208
209#define rtems_cpu_configuration_get_interrupt_table_segment() \
210   (_CPU_Table.interrupt_table_segment)
211
212#define rtems_cpu_configuration_get_interrupt_table_offset() \
213   (_CPU_Table.interrupt_table_offset)
214
215/*
216 *  context size area for floating point
217 *
218 *  NOTE:  This is out of place on the i386 to avoid a forward reference.
219 */
220
221#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
222
223/* variables */
224
225SCORE_EXTERN Context_Control_fp  _CPU_Null_fp_context;
226SCORE_EXTERN void               *_CPU_Interrupt_stack_low;
227SCORE_EXTERN void               *_CPU_Interrupt_stack_high;
228
229/* constants */
230
231/*
232 *  This defines the number of levels and the mask used to pick those
233 *  bits out of a thread mode.
234 */
235
236#define CPU_MODES_INTERRUPT_LEVEL  0x00000001 /* interrupt level in mode */
237#define CPU_MODES_INTERRUPT_MASK   0x00000001 /* interrupt level in mode */
238
239/*
240 *  extra stack required by the MPCI receive server thread
241 */
242
243#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 1024
244
245/*
246 *  i386 family supports 256 distinct vectors.
247 */
248
249#define CPU_INTERRUPT_NUMBER_OF_VECTORS      256
250#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER  (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
251
252/*
253 *  Minimum size of a thread's stack.
254 */
255
256#define CPU_STACK_MINIMUM_SIZE          1024
257
258/*
259 *  i386 is pretty tolerant of alignment.  Just put things on 4 byte boundaries.
260 */
261
262#define CPU_ALIGNMENT                    4
263#define CPU_HEAP_ALIGNMENT               CPU_ALIGNMENT
264#define CPU_PARTITION_ALIGNMENT          CPU_ALIGNMENT
265
266/*
267 *  On i386 thread stacks require no further alignment after allocation
268 *  from the Workspace.
269 */
270
271#define CPU_STACK_ALIGNMENT             0
272
273/* macros */
274
275/*
276 *  ISR handler macros
277 *
278 *  These macros perform the following functions:
279 *     + initialize the RTEMS vector table
280 *     + disable all maskable CPU interrupts
281 *     + restore previous interrupt level (enable)
282 *     + temporarily restore interrupts (flash)
283 *     + set a particular level
284 */
285
286#define _CPU_Initialize_vectors()
287
288#define _CPU_ISR_Disable( _level ) i386_disable_interrupts( _level )
289
290#define _CPU_ISR_Enable( _level )  i386_enable_interrupts( _level )
291
292#define _CPU_ISR_Flash( _level )   i386_flash_interrupts( _level )
293
294#define _CPU_ISR_Set_level( _new_level ) \
295  { \
296    if ( _new_level ) asm volatile ( "cli" ); \
297    else              asm volatile ( "sti" ); \
298  }
299
300unsigned32 _CPU_ISR_Get_level( void );
301
302/* end of ISR handler macros */
303
304/*
305 *  Context handler macros
306 *
307 *  These macros perform the following functions:
308 *     + initialize a context area
309 *     + restart the current thread
310 *     + calculate the initial pointer into a FP context area
311 *     + initialize an FP context area
312 */
313
314#define CPU_EFLAGS_INTERRUPTS_ON  0x00003202
315#define CPU_EFLAGS_INTERRUPTS_OFF 0x00003002
316
317#define _CPU_Context_Initialize( _the_context, _stack_base, _size, \
318                                   _isr, _entry_point, _is_fp ) \
319  do { \
320    unsigned32 _stack; \
321    \
322    if ( (_isr) ) (_the_context)->eflags = CPU_EFLAGS_INTERRUPTS_OFF; \
323    else          (_the_context)->eflags = CPU_EFLAGS_INTERRUPTS_ON; \
324    \
325    _stack = ((unsigned32)(_stack_base)) + (_size) - 4; \
326    \
327    *((proc_ptr *)(_stack)) = (_entry_point); \
328    (_the_context)->ebp     = (void *) _stack; \
329    (_the_context)->esp     = (void *) _stack; \
330  } while (0)
331
332#define _CPU_Context_Restart_self( _the_context ) \
333   _CPU_Context_restore( (_the_context) );
334
335#define _CPU_Context_Fp_start( _base, _offset ) \
336   ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
337
338#define _CPU_Context_Initialize_fp( _fp_area ) \
339  { \
340    unsigned32 *_source      = (unsigned32 *) &_CPU_Null_fp_context; \
341    unsigned32 *_destination = *(_fp_area); \
342    unsigned32  _index; \
343    \
344    for ( _index=0 ; _index < CPU_CONTEXT_FP_SIZE/4 ; _index++ ) \
345      *_destination++ = *_source++; \
346  }
347
348/* end of Context handler macros */
349
350/*
351 *  Fatal Error manager macros
352 *
353 *  These macros perform the following functions:
354 *    + disable interrupts and halt the CPU
355 */
356
357#define _CPU_Fatal_halt( _error ) \
358  { \
359    asm volatile ( "cli ; \
360                    movl %0,%%eax ; \
361                    hlt" \
362                    : "=r" ((_error)) : "0" ((_error)) \
363    ); \
364  }
365
366/* end of Fatal Error manager macros */
367
368/*
369 *  Bitfield handler macros
370 *
371 *  These macros perform the following functions:
372 *     + scan for the highest numbered (MSB) set in a 16 bit bitfield
373 */
374
375#define CPU_USE_GENERIC_BITFIELD_CODE FALSE
376#define CPU_USE_GENERIC_BITFIELD_DATA FALSE
377
378#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
379  { \
380    register unsigned16 __value_in_register = (_value); \
381    \
382    _output = 0; \
383    \
384    asm volatile ( "bsfw    %0,%1 " \
385                    : "=r" (__value_in_register), "=r" (_output) \
386                    : "0"  (__value_in_register), "1"  (_output) \
387    ); \
388  }
389
390/* end of Bitfield handler macros */
391
392/*
393 *  Priority handler macros
394 *
395 *  These macros perform the following functions:
396 *    + return a mask with the bit for this major/minor portion of
397 *      of thread priority set.
398 *    + translate the bit number returned by "Bitfield_find_first_bit"
399 *      into an index into the thread ready chain bit maps
400 */
401
402#define _CPU_Priority_Mask( _bit_number ) \
403  ( 1 << (_bit_number) )
404
405#define _CPU_Priority_bits_index( _priority ) \
406  (_priority)
407
408/* functions */
409
410/*
411 *  _CPU_Initialize
412 *
413 *  This routine performs CPU dependent initialization.
414 */
415
416void _CPU_Initialize(
417  rtems_cpu_table  *cpu_table,
418  void      (*thread_dispatch)
419);
420
421/*
422 *  _CPU_ISR_install_raw_handler
423 *
424 *  This routine installs a "raw" interrupt handler directly into the
425 *  processor's vector table.
426 */
427 
428void _CPU_ISR_install_raw_handler(
429  unsigned32  vector,
430  proc_ptr    new_handler,
431  proc_ptr   *old_handler
432);
433
434/*
435 *  _CPU_ISR_install_vector
436 *
437 *  This routine installs an interrupt vector.
438 */
439
440void _CPU_ISR_install_vector(
441  unsigned32  vector,
442  proc_ptr    new_handler,
443  proc_ptr   *old_handler
444);
445
446/*
447 *  _CPU_Thread_Idle_body
448 *
449 *  Use the halt instruction of low power mode of a particular i386 model.
450 */
451
452#if (CPU_PROVIDES_IDLE_THREAD_BODY == TRUE)
453
454void _CPU_Thread_Idle_body( void );
455
456#endif /* CPU_PROVIDES_IDLE_THREAD_BODY */
457
458/*
459 *  _CPU_Context_switch
460 *
461 *  This routine switches from the run context to the heir context.
462 */
463
464void _CPU_Context_switch(
465  Context_Control  *run,
466  Context_Control  *heir
467);
468
469/*
470 *  _CPU_Context_restore
471 *
472 *  This routine is generally used only to restart self in an
473 *  efficient manner and avoid stack conflicts.
474 */
475
476void _CPU_Context_restore(
477  Context_Control *new_context
478);
479
480/*
481 *  _CPU_Context_save_fp
482 *
483 *  This routine saves the floating point context passed to it.
484 */
485
486void _CPU_Context_save_fp(
487  void **fp_context_ptr
488);
489
490/*
491 *  _CPU_Context_restore_fp
492 *
493 *  This routine restores the floating point context passed to it.
494 */
495
496void _CPU_Context_restore_fp(
497  void **fp_context_ptr
498);
499
500#ifdef __cplusplus
501}
502#endif
503
504#endif
505/* end of include file */
Note: See TracBrowser for help on using the repository browser.