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

4.104.114.84.95
Last change on this file since 67a2288 was 67a2288, checked in by Joel Sherrill <joel.sherrill@…>, on 07/23/98 at 22:02:34

Patch from Eric VALETTE <valette@…>:

Here is a enhanced version of my previous patch. This patch enables
to potentially share the new interrupt management code for all Intel targets
(pc386, go32 and force386) bsp.

Note : this patch is complete only for pc386. It still needs to

be completed for go32 and force386. I carrefully checked
that anything needed is in for force386 (only some function
name changes for IDT manipulation and GDT segment
manipulation). But anyway I will not be able to test any
of theses targets...

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