source: rtems/c/src/exec/score/cpu/m68k/cpu.h @ 803de41

4.104.114.84.95
Last change on this file since 803de41 was 803de41, checked in by Joel Sherrill <joel.sherrill@…>, on 06/24/98 at 17:58:56

Suggestion from Robin Kirkham <Robin.Kirkham@…> to improve
clarity.

  • Property mode set to 100644
File size: 15.8 KB
Line 
1/*  cpu.h
2 *
3 *  This include file contains information pertaining to the Motorola
4 *  m68xxx processor family.
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/m68k.h>              /* pick up machine definitions */
25#ifndef ASM
26#include <rtems/score/m68ktypes.h>
27#endif
28
29/* conditional compilation parameters */
30
31#define CPU_INLINE_ENABLE_DISPATCH       TRUE
32#define CPU_UNROLL_ENQUEUE_PRIORITY      FALSE
33
34/*
35 *  Use the m68k's hardware interrupt stack support and have the
36 *  interrupt manager allocate the memory for it.
37 */
38
39#if ( M68K_HAS_SEPARATE_STACKS == 1)
40#define CPU_HAS_SOFTWARE_INTERRUPT_STACK 0
41#define CPU_HAS_HARDWARE_INTERRUPT_STACK 1
42#else
43#define CPU_HAS_SOFTWARE_INTERRUPT_STACK 1
44#define CPU_HAS_HARDWARE_INTERRUPT_STACK 0
45#endif
46#define CPU_ALLOCATE_INTERRUPT_STACK     1
47
48/*
49 *  Does the RTEMS invoke the user's ISR with the vector number and
50 *  a pointer to the saved interrupt frame (1) or just the vector
51 *  number (0)?
52 */
53
54#define CPU_ISR_PASSES_FRAME_POINTER 0
55
56/*
57 *  Some family members have no FP, some have an FPU such as the
58 *  MC68881/MC68882 for the MC68020, others have it built in (MC68030, 040).
59 *
60 *  NOTE:  If on a CPU without hardware FP, then one can use software
61 *         emulation.  The gcc software FP emulation code has data which
62 *         must be contexted switched on a per task basis.
63 */
64
65#if ( M68K_HAS_FPU == 1 )
66#define CPU_HARDWARE_FP     TRUE
67#define CPU_SOFTWARE_FP     FALSE
68#else
69#define CPU_HARDWARE_FP     FALSE
70#if defined(__GCC__)
71#define CPU_SOFTWARE_FP     TRUE
72#else
73#define CPU_SOFTWARE_FP     FALSE
74#endif
75#endif
76
77/*
78 *  All tasks are not by default floating point tasks on this CPU.
79 *  The IDLE task does not have a floating point context on this CPU.
80 *  It is safe to use the deferred floating point context switch
81 *  algorithm on this CPU.
82 */
83
84#define CPU_ALL_TASKS_ARE_FP             FALSE
85#define CPU_IDLE_TASK_IS_FP              FALSE
86#define CPU_USE_DEFERRED_FP_SWITCH       TRUE
87
88#define CPU_PROVIDES_IDLE_THREAD_BODY    FALSE
89#define CPU_STACK_GROWS_UP               FALSE
90#define CPU_STRUCTURE_ALIGNMENT
91
92/*
93 *  Define what is required to specify how the network to host conversion
94 *  routines are handled.
95 */
96
97#define CPU_CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES FALSE
98#define CPU_BIG_ENDIAN                           TRUE
99#define CPU_LITTLE_ENDIAN                        FALSE
100
101#ifndef ASM
102/* structures */
103
104/*
105 *  Basic integer context for the m68k family.
106 */
107
108typedef struct {
109  unsigned32  sr;                /* (sr) status register */
110  unsigned32  d2;                /* (d2) data register 2 */
111  unsigned32  d3;                /* (d3) data register 3 */
112  unsigned32  d4;                /* (d4) data register 4 */
113  unsigned32  d5;                /* (d5) data register 5 */
114  unsigned32  d6;                /* (d6) data register 6 */
115  unsigned32  d7;                /* (d7) data register 7 */
116  void       *a2;                /* (a2) address register 2 */
117  void       *a3;                /* (a3) address register 3 */
118  void       *a4;                /* (a4) address register 4 */
119  void       *a5;                /* (a5) address register 5 */
120  void       *a6;                /* (a6) address register 6 */
121  void       *a7_msp;            /* (a7) master stack pointer */
122}   Context_Control;
123
124/*
125 *  Floating point context ares
126 */
127
128#if (CPU_SOFTWARE_FP == TRUE)
129
130/*
131 *  This is the same as gcc's view of the software FP condition code
132 *  register _fpCCR.  The implementation of the emulation code is
133 *  in the gcc-VERSION/config/m68k directory.  This structure is
134 *  correct as of gcc 2.7.2.2.
135 */
136
137typedef struct {
138  unsigned16   _exception_bits;
139  unsigned16   _trap_enable_bits;
140  unsigned16   _sticky_bits;
141  unsigned16   _rounding_mode;
142  unsigned16   _format;
143  unsigned16   _last_operation;
144  union {
145    float sf;
146    double df;
147  } _operand1;
148  union {
149    float sf;
150    double df;
151  } _operand2;
152} Context_Control_fp;
153
154#else
155
156/*
157 *  FP context save area for the M68881/M68882 numeric coprocessors.
158 */
159
160typedef struct {
161  unsigned8   fp_save_area[332];    /*   216 bytes for FSAVE/FRESTORE    */
162                                    /*    96 bytes for FMOVEM FP0-7      */
163                                    /*    12 bytes for FMOVEM CREGS      */
164                                    /*     4 bytes for non-null flag     */
165} Context_Control_fp;
166#endif
167
168/*
169 *  The following structure defines the set of information saved
170 *  on the current stack by RTEMS upon receipt of each interrupt.
171 */
172
173typedef struct {
174  unsigned32   TBD;   /* XXX Fix for this CPU */
175} CPU_Interrupt_frame;
176
177/*
178 *  The following table contains the information required to configure
179 *  the m68k specific parameters.
180 */
181
182typedef 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   interrupt_stack_size;
189  unsigned32   extra_mpci_receive_server_stack;
190  void *     (*stack_allocate_hook)( unsigned32 );
191  void       (*stack_free_hook)( void* );
192  /* end of fields required on all CPUs */
193
194  m68k_isr    *interrupt_vector_table;
195}   rtems_cpu_table;
196
197/* variables */
198
199SCORE_EXTERN void                   *_CPU_Interrupt_stack_low;
200SCORE_EXTERN void                   *_CPU_Interrupt_stack_high;
201
202extern char                         _VBR[];
203
204#if ( M68K_HAS_VBR == 0 )
205
206/*
207 * Table of ISR handler entries that resides in RAM. The FORMAT/ID is
208 * pushed onto the stack. This is not is the same order as VBR processors.
209 * The ISR handler takes the format and uses it for dispatching the user
210 * handler.
211 *
212 * FIXME : should be moved to below CPU_INTERRUPT_NUMBER_OF_VECTORS
213 *
214 */
215
216typedef struct {
217  unsigned16 move_a7;            /* move #FORMAT_ID,%a7@- */
218  unsigned16 format_id;
219  unsigned16 jmp;                /* jmp  _ISR_Handlers */
220  unsigned32 isr_handler;
221} _CPU_ISR_handler_entry;
222
223#define M68K_MOVE_A7 0x3F3C
224#define M68K_JMP     0x4EF9
225
226      /* points to jsr-exception-table in targets wo/ VBR register */
227SCORE_EXTERN _CPU_ISR_handler_entry _CPU_ISR_jump_table[256];
228
229#endif /* M68K_HAS_VBR */
230#endif /* ASM */
231
232/* constants */
233
234/*
235 *  This defines the number of levels and the mask used to pick those
236 *  bits out of a thread mode.
237 */
238
239#define CPU_MODES_INTERRUPT_LEVEL  0x00000007 /* interrupt level in mode */
240#define CPU_MODES_INTERRUPT_MASK   0x00000007 /* interrupt level in mode */
241
242/*
243 *  context size area for floating point
244 */
245
246#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
247
248/*
249 *  extra stack required by the MPCI receive server thread
250 */
251
252#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 1024
253
254/*
255 *  m68k family supports 256 distinct vectors.
256 */
257
258#define CPU_INTERRUPT_NUMBER_OF_VECTORS      256
259#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER  (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
260
261/*
262 *  Minimum size of a thread's stack.
263 */
264
265#define CPU_STACK_MINIMUM_SIZE           2048
266
267/*
268 *  m68k is pretty tolerant of alignment.  Just put things on 4 byte boundaries.
269 */
270
271#define CPU_ALIGNMENT                    4
272#define CPU_HEAP_ALIGNMENT               CPU_ALIGNMENT
273#define CPU_PARTITION_ALIGNMENT          CPU_ALIGNMENT
274
275/*
276 *  On m68k thread stacks require no further alignment after allocation
277 *  from the Workspace.
278 */
279
280#define CPU_STACK_ALIGNMENT        0
281
282#ifndef ASM
283
284/* macros */
285
286/*
287 *  ISR handler macros
288 *
289 *  These macros perform the following functions:
290 *     + disable all maskable CPU interrupts
291 *     + restore previous interrupt level (enable)
292 *     + temporarily restore interrupts (flash)
293 *     + set a particular level
294 */
295
296#define _CPU_ISR_Disable( _level ) \
297  m68k_disable_interrupts( _level )
298
299#define _CPU_ISR_Enable( _level ) \
300  m68k_enable_interrupts( _level )
301
302#define _CPU_ISR_Flash( _level ) \
303  m68k_flash_interrupts( _level )
304
305#define _CPU_ISR_Set_level( _newlevel ) \
306   m68k_set_interrupt_level( _newlevel )
307
308unsigned32 _CPU_ISR_Get_level( void );
309
310/* end of ISR handler macros */
311
312/*
313 *  Context handler macros
314 *
315 *  These macros perform the following functions:
316 *     + initialize a context area
317 *     + restart the current thread
318 *     + calculate the initial pointer into a FP context area
319 *     + initialize an FP context area
320 */
321
322#define _CPU_Context_Initialize( _the_context, _stack_base, _size, \
323                                 _isr, _entry_point, _is_fp ) \
324   do { \
325     unsigned32 _stack; \
326     \
327     (_the_context)->sr      = 0x3000 | ((_isr) << 8); \
328     _stack                  = (unsigned32)(_stack_base) + (_size) - 4; \
329     (_the_context)->a7_msp  = (void *)_stack; \
330     *(void **)_stack        = (void *)(_entry_point); \
331   } while ( 0 )
332
333#define _CPU_Context_Restart_self( _the_context ) \
334  { asm volatile( "movew %0,%%sr ; " \
335                  "moval %1,%%a7 ; " \
336                  "rts"  \
337        : "=d" ((_the_context)->sr), "=d" ((_the_context)->a7_msp) \
338        : "0" ((_the_context)->sr), "1" ((_the_context)->a7_msp) ); \
339  }
340
341/*
342 *  Floating Point Context Area Support routines
343 */
344
345#if (CPU_SOFTWARE_FP == TRUE)
346
347/*
348 *  This software FP implementation is only for GCC.
349 */
350
351#define _CPU_Context_Fp_start( _base, _offset ) \
352   ((void *) _Addresses_Add_offset( (_base), (_offset) ) )
353
354
355#define _CPU_Context_Initialize_fp( _fp_area ) \
356   { \
357   Context_Control_fp *_fp; \
358   _fp = *(Context_Control_fp **)_fp_area; \
359   _fp->_exception_bits = 0; \
360   _fp->_trap_enable_bits = 0; \
361   _fp->_sticky_bits = 0; \
362   _fp->_rounding_mode = 0;  /* ROUND_TO_NEAREST */ \
363   _fp->_format = 0;         /* NIL */ \
364   _fp->_last_operation = 0;  /* NOOP */ \
365   _fp->_operand1.df = 0; \
366   _fp->_operand2.df = 0; \
367   }
368#else
369#define _CPU_Context_Fp_start( _base, _offset ) \
370   ((void *) \
371     _Addresses_Add_offset( \
372        (_base), \
373        (_offset) + CPU_CONTEXT_FP_SIZE - 4 \
374     ) \
375   )
376
377#define _CPU_Context_Initialize_fp( _fp_area ) \
378   { unsigned32 *_fp_context = (unsigned32 *)*(_fp_area); \
379     \
380     *(--(_fp_context)) = 0; \
381     *(_fp_area) = (unsigned8 *)(_fp_context); \
382   }
383#endif
384
385/* end of Context handler macros */
386
387/*
388 *  Fatal Error manager macros
389 *
390 *  These macros perform the following functions:
391 *    + disable interrupts and halt the CPU
392 */
393
394#define _CPU_Fatal_halt( _error ) \
395  { asm volatile( "movl  %0,%%d0; " \
396                  "orw   #0x0700,%%sr; " \
397                  "stop  #0x2700" : "=d" ((_error)) : "0" ((_error)) ); \
398  }
399
400/* end of Fatal Error manager macros */
401
402/*
403 *  Bitfield handler macros
404 *
405 *  These macros perform the following functions:
406 *     + scan for the highest numbered (MSB) set in a 16 bit bitfield
407 *
408 *  NOTE:
409 *
410 *    It appears that on the M68020 bitfield are always 32 bits wide
411 *    when in a register.  This code forces the bitfield to be in
412 *    memory (it really always is anyway). This allows us to
413 *    have a real 16 bit wide bitfield which operates "correctly."
414 */
415
416#define CPU_USE_GENERIC_BITFIELD_CODE FALSE
417#define CPU_USE_GENERIC_BITFIELD_DATA FALSE
418
419#if ( M68K_HAS_BFFFO == 1 )
420
421#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
422  asm volatile( "bfffo (%1),#0,#16,%0" : "=d" (_output) : "a" (&_value));
423#else
424
425/* duplicates BFFFO results for 16 bits (i.e., 15-(_priority) in
426   _CPU_Priority_bits_index is not needed), handles the 0 case, and
427   does not molest _value -- jsg */
428#if ( M68K_HAS_EXTB_L == 1 )
429#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
430  { \
431    extern const unsigned char __BFFFOtable[256]; \
432    register int dumby; \
433    \
434    asm volatile ( "   move.w  %2,%1\n"        \
435       "   lsr.w   #8,%1\n"        \
436       "   beq.s   1f\n"           \
437       "   move.b  (%3,%1.w),%0\n" \
438       "   extb.l  %0\n"           \
439       "   bra.s   0f\n"           \
440       "1: moveq.l #8,%0\n"        \
441       "   add.b   (%3,%2.w),%0\n" \
442       "0:\n"                      \
443       : "=&d" ((_output)), "=&d" ((dumby)) \
444       : "d" ((_value)), "ao" ((__BFFFOtable)) \
445       : "cc" ) ; \
446  }
447#else
448#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
449  { \
450    extern const unsigned char __BFFFOtable[256]; \
451    register int dumby; \
452    \
453    asm volatile ( "   move.w  %2,%1\n"        \
454       "   lsr.w   #8,%1\n"        \
455       "   beq.s   1f\n"           \
456       "   move.b  (%3,%1.w),%0\n" \
457       "   and.l   #0x000000ff,%0\n"\
458       "   bra.s   0f\n"           \
459       "1: moveq.l #8,%0\n"        \
460       "   add.b   (%3,%2.w),%0\n" \
461       "0:\n"                      \
462       : "=&d" ((_output)), "=&d" ((dumby)) \
463       : "d" ((_value)), "ao" ((__BFFFOtable)) \
464       : "cc" ) ; \
465  }
466#endif /* M68K_HAS_EXTB_L */
467
468#endif
469
470/* end of Bitfield handler macros */
471
472/*
473 *  Priority handler macros
474 *
475 *  These macros perform the following functions:
476 *    + return a mask with the bit for this major/minor portion of
477 *      of thread priority set.
478 *    + translate the bit number returned by "Bitfield_find_first_bit"
479 *      into an index into the thread ready chain bit maps
480 */
481
482#define _CPU_Priority_Mask( _bit_number ) \
483  ( 0x8000 >> (_bit_number) )
484
485#define _CPU_Priority_bits_index( _priority ) \
486  (_priority)
487
488/* end of Priority handler macros */
489
490/* functions */
491
492/*
493 *  _CPU_Initialize
494 *
495 *  This routine performs CPU dependent initialization.
496 */
497
498void _CPU_Initialize(
499  rtems_cpu_table  *cpu_table,
500  void      (*thread_dispatch)
501);
502
503/*
504 *  _CPU_ISR_install_raw_handler
505 *
506 *  This routine installs a "raw" interrupt handler directly into the
507 *  processor's vector table.
508 */
509 
510void _CPU_ISR_install_raw_handler(
511  unsigned32  vector,
512  proc_ptr    new_handler,
513  proc_ptr   *old_handler
514);
515
516/*
517 *  _CPU_ISR_install_vector
518 *
519 *  This routine installs an interrupt vector.
520 */
521
522void _CPU_ISR_install_vector(
523  unsigned32       vector,
524  proc_ptr         new_handler,
525  proc_ptr        *old_handler
526);
527
528/*
529 *  _CPU_Install_interrupt_stack
530 *
531 *  This routine installs the hardware interrupt stack pointer.
532 */
533
534void _CPU_Install_interrupt_stack( void );
535
536/*
537 *  _CPU_Context_switch
538 *
539 *  This routine switches from the run context to the heir context.
540 */
541
542void _CPU_Context_switch(
543  Context_Control  *run,
544  Context_Control  *heir
545);
546
547/*
548 *  _CPU_Context_save_fp
549 *
550 *  This routine saves the floating point context passed to it.
551 */
552
553void _CPU_Context_save_fp(
554  void **fp_context_ptr
555);
556
557/*
558 *  _CPU_Context_restore_fp
559 *
560 *  This routine restores the floating point context passed to it.
561 */
562
563void _CPU_Context_restore_fp(
564  void **fp_context_ptr
565);
566
567#if (M68K_HAS_FPSP_PACKAGE == 1)
568/*
569 *  Hooks for the Floating Point Support Package (FPSP) provided by Motorola
570 *
571 *  NOTES: 
572 *
573 *  Motorola 68k family CPU's before the 68040 used a coprocessor
574 *  (68881 or 68882) to handle floating point.  The 68040 has internal
575 *  floating point support -- but *not* the complete support provided by
576 *  the 68881 or 68882.  The leftover functions are taken care of by the
577 *  M68040 Floating Point Support Package.  Quoting from the MC68040
578 *  Microprocessors User's Manual, Section 9, Floating-Point Unit (MC68040):
579 *
580 *    "When used with the M68040FPSP, the MC68040 FPU is fully
581 *    compliant with IEEE floating-point standards."
582 *
583 *  M68KFPSPInstallExceptionHandlers is in libcpu/m68k/MODEL/fpsp and
584 *  is invoked early in the application code to insure that proper FP
585 *  behavior is installed.  This is not left to the BSP to call, since
586 *  this would force all applications using that BSP to use FPSP which
587 *  is not necessarily desirable.
588 *
589 *  There is a similar package for the 68060 but RTEMS does not yet
590 *  support the 68060.
591 */
592
593void M68KFPSPInstallExceptionHandlers (void);
594
595SCORE_EXTERN int (*_FPSP_install_raw_handler)(
596  unsigned32 vector,
597  proc_ptr new_handler,
598  proc_ptr *old_handler
599);
600
601#endif
602
603
604#endif
605
606#ifdef __cplusplus
607}
608#endif
609
610#endif
611/* end of include file */
Note: See TracBrowser for help on using the repository browser.