source: rtems/cpukit/score/cpu/i386/rtems/score/cpu.h @ 8c82fa79

4.104.114.84.95
Last change on this file since 8c82fa79 was 8c82fa79, checked in by Joel Sherrill <joel.sherrill@…>, on 04/03/02 at 14:04:21

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

  • Per PR94, all rtems/score/CPUtypes.h are named rtems/score/types.h.
  • rtems/score/i386types.h: Removed.
  • rtems/score/types.h: New file via CVS magic.
  • Makefile.am, rtems/score/cpu.h: Account for name change.
  • Property mode set to 100644
File size: 12.8 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/types.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 *  This is defined if the port has a special way to report the ISR nesting
254 *  level.  Most ports maintain the variable _ISR_Nest_level.
255 */
256
257#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
258
259/*
260 *  Minimum size of a thread's stack.
261 */
262
263#define CPU_STACK_MINIMUM_SIZE          1024
264
265/*
266 *  i386 is pretty tolerant of alignment.  Just put things on 4 byte boundaries.
267 */
268
269#define CPU_ALIGNMENT                    4
270#define CPU_HEAP_ALIGNMENT               CPU_ALIGNMENT
271#define CPU_PARTITION_ALIGNMENT          CPU_ALIGNMENT
272
273/*
274 *  On i386 thread stacks require no further alignment after allocation
275 *  from the Workspace.
276 */
277
278#define CPU_STACK_ALIGNMENT             0
279
280/* macros */
281
282/*
283 *  ISR handler macros
284 *
285 *  These macros perform the following functions:
286 *     + initialize the RTEMS vector table
287 *     + disable all maskable CPU interrupts
288 *     + restore previous interrupt level (enable)
289 *     + temporarily restore interrupts (flash)
290 *     + set a particular level
291 */
292
293#define _CPU_Initialize_vectors()
294
295#define _CPU_ISR_Disable( _level ) i386_disable_interrupts( _level )
296
297#define _CPU_ISR_Enable( _level )  i386_enable_interrupts( _level )
298
299#define _CPU_ISR_Flash( _level )   i386_flash_interrupts( _level )
300
301#define _CPU_ISR_Set_level( _new_level ) \
302  { \
303    if ( _new_level ) asm volatile ( "cli" ); \
304    else              asm volatile ( "sti" ); \
305  }
306
307unsigned32 _CPU_ISR_Get_level( void );
308
309/* end of ISR handler macros */
310
311/*
312 *  Context handler macros
313 *
314 *  These macros perform the following functions:
315 *     + initialize a context area
316 *     + restart the current thread
317 *     + calculate the initial pointer into a FP context area
318 *     + initialize an FP context area
319 */
320
321#define CPU_EFLAGS_INTERRUPTS_ON  0x00003202
322#define CPU_EFLAGS_INTERRUPTS_OFF 0x00003002
323
324#define _CPU_Context_Initialize( _the_context, _stack_base, _size, \
325                                   _isr, _entry_point, _is_fp ) \
326  do { \
327    unsigned32 _stack; \
328    \
329    if ( (_isr) ) (_the_context)->eflags = CPU_EFLAGS_INTERRUPTS_OFF; \
330    else          (_the_context)->eflags = CPU_EFLAGS_INTERRUPTS_ON; \
331    \
332    _stack = ((unsigned32)(_stack_base)) + (_size) - 4; \
333    \
334    *((proc_ptr *)(_stack)) = (_entry_point); \
335    (_the_context)->ebp     = (void *) _stack; \
336    (_the_context)->esp     = (void *) _stack; \
337  } while (0)
338
339#define _CPU_Context_Restart_self( _the_context ) \
340   _CPU_Context_restore( (_the_context) );
341
342#define _CPU_Context_Fp_start( _base, _offset ) \
343   ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
344
345#define _CPU_Context_Initialize_fp( _fp_area ) \
346  { \
347    unsigned32 *_source      = (unsigned32 *) &_CPU_Null_fp_context; \
348    unsigned32 *_destination = *(_fp_area); \
349    unsigned32  _index; \
350    \
351    for ( _index=0 ; _index < CPU_CONTEXT_FP_SIZE/4 ; _index++ ) \
352      *_destination++ = *_source++; \
353  }
354
355/* end of Context handler macros */
356
357/*
358 *  Fatal Error manager macros
359 *
360 *  These macros perform the following functions:
361 *    + disable interrupts and halt the CPU
362 */
363
364#define _CPU_Fatal_halt( _error ) \
365  { \
366    asm volatile ( "cli ; \
367                    movl %0,%%eax ; \
368                    hlt" \
369                    : "=r" ((_error)) : "0" ((_error)) \
370    ); \
371  }
372
373/* end of Fatal Error manager macros */
374
375/*
376 *  Bitfield handler macros
377 *
378 *  These macros perform the following functions:
379 *     + scan for the highest numbered (MSB) set in a 16 bit bitfield
380 */
381
382#define CPU_USE_GENERIC_BITFIELD_CODE FALSE
383#define CPU_USE_GENERIC_BITFIELD_DATA FALSE
384
385#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
386  { \
387    register unsigned16 __value_in_register = (_value); \
388    \
389    _output = 0; \
390    \
391    asm volatile ( "bsfw    %0,%1 " \
392                    : "=r" (__value_in_register), "=r" (_output) \
393                    : "0"  (__value_in_register), "1"  (_output) \
394    ); \
395  }
396
397/* end of Bitfield handler macros */
398
399/*
400 *  Priority handler macros
401 *
402 *  These macros perform the following functions:
403 *    + return a mask with the bit for this major/minor portion of
404 *      of thread priority set.
405 *    + translate the bit number returned by "Bitfield_find_first_bit"
406 *      into an index into the thread ready chain bit maps
407 */
408
409#define _CPU_Priority_Mask( _bit_number ) \
410  ( 1 << (_bit_number) )
411
412#define _CPU_Priority_bits_index( _priority ) \
413  (_priority)
414
415/* functions */
416
417/*
418 *  _CPU_Initialize
419 *
420 *  This routine performs CPU dependent initialization.
421 */
422
423void _CPU_Initialize(
424  rtems_cpu_table  *cpu_table,
425  void      (*thread_dispatch)
426);
427
428/*
429 *  _CPU_ISR_install_raw_handler
430 *
431 *  This routine installs a "raw" interrupt handler directly into the
432 *  processor's vector table.
433 */
434 
435void _CPU_ISR_install_raw_handler(
436  unsigned32  vector,
437  proc_ptr    new_handler,
438  proc_ptr   *old_handler
439);
440
441/*
442 *  _CPU_ISR_install_vector
443 *
444 *  This routine installs an interrupt vector.
445 */
446
447void _CPU_ISR_install_vector(
448  unsigned32  vector,
449  proc_ptr    new_handler,
450  proc_ptr   *old_handler
451);
452
453/*
454 *  _CPU_Thread_Idle_body
455 *
456 *  Use the halt instruction of low power mode of a particular i386 model.
457 */
458
459#if (CPU_PROVIDES_IDLE_THREAD_BODY == TRUE)
460
461void _CPU_Thread_Idle_body( void );
462
463#endif /* CPU_PROVIDES_IDLE_THREAD_BODY */
464
465/*
466 *  _CPU_Context_switch
467 *
468 *  This routine switches from the run context to the heir context.
469 */
470
471void _CPU_Context_switch(
472  Context_Control  *run,
473  Context_Control  *heir
474);
475
476/*
477 *  _CPU_Context_restore
478 *
479 *  This routine is generally used only to restart self in an
480 *  efficient manner and avoid stack conflicts.
481 */
482
483void _CPU_Context_restore(
484  Context_Control *new_context
485);
486
487/*
488 *  _CPU_Context_save_fp
489 *
490 *  This routine saves the floating point context passed to it.
491 */
492
493void _CPU_Context_save_fp(
494  void **fp_context_ptr
495);
496
497/*
498 *  _CPU_Context_restore_fp
499 *
500 *  This routine restores the floating point context passed to it.
501 */
502
503void _CPU_Context_restore_fp(
504  void **fp_context_ptr
505);
506
507#ifdef __cplusplus
508}
509#endif
510
511#endif
512/* end of include file */
Note: See TracBrowser for help on using the repository browser.