OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [exec/] [score/] [cpu/] [i386/] [rtems/] [score/] [cpu.h] - Blame information for rev 173

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.