source: rtems/cpukit/score/cpu/m68k/rtems/score/cpu.h @ 6805640e

4.104.114.84.95
Last change on this file since 6805640e was 6805640e, checked in by Joel Sherrill <joel.sherrill@…>, on 07/29/99 at 23:01:15

Patch from Charles-Antoine Gauthier <charles.gauthier@…>
to correct a typo CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES was actually
typed in as CPU_CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES.

  • Property mode set to 100644
File size: 16.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_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   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  m68k_isr    *interrupt_vector_table;
196}   rtems_cpu_table;
197
198/* variables */
199
200SCORE_EXTERN void                   *_CPU_Interrupt_stack_low;
201SCORE_EXTERN void                   *_CPU_Interrupt_stack_high;
202
203extern char                         _VBR[];
204
205#if ( M68K_HAS_VBR == 0 )
206
207/*
208 * Table of ISR handler entries that resides in RAM. The FORMAT/ID is
209 * pushed onto the stack. This is not is the same order as VBR processors.
210 * The ISR handler takes the format and uses it for dispatching the user
211 * handler.
212 *
213 * FIXME : should be moved to below CPU_INTERRUPT_NUMBER_OF_VECTORS
214 *
215 */
216
217typedef struct {
218  unsigned16 move_a7;            /* move #FORMAT_ID,%a7@- */
219  unsigned16 format_id;
220  unsigned16 jmp;                /* jmp  _ISR_Handlers */
221  unsigned32 isr_handler;
222} _CPU_ISR_handler_entry;
223
224#define M68K_MOVE_A7 0x3F3C
225#define M68K_JMP     0x4EF9
226
227      /* points to jsr-exception-table in targets wo/ VBR register */
228SCORE_EXTERN _CPU_ISR_handler_entry _CPU_ISR_jump_table[256];
229
230#endif /* M68K_HAS_VBR */
231#endif /* ASM */
232
233/* constants */
234
235/*
236 *  This defines the number of levels and the mask used to pick those
237 *  bits out of a thread mode.
238 */
239
240#define CPU_MODES_INTERRUPT_LEVEL  0x00000007 /* interrupt level in mode */
241#define CPU_MODES_INTERRUPT_MASK   0x00000007 /* interrupt level in mode */
242
243/*
244 *  context size area for floating point
245 */
246
247#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
248
249/*
250 *  extra stack required by the MPCI receive server thread
251 */
252
253#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 1024
254
255/*
256 *  m68k family supports 256 distinct vectors.
257 */
258
259#define CPU_INTERRUPT_NUMBER_OF_VECTORS      256
260#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER  (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
261
262/*
263 *  Minimum size of a thread's stack.
264 */
265
266#define CPU_STACK_MINIMUM_SIZE           2048
267
268/*
269 *  m68k is pretty tolerant of alignment.  Just put things on 4 byte boundaries.
270 */
271
272#define CPU_ALIGNMENT                    4
273#define CPU_HEAP_ALIGNMENT               CPU_ALIGNMENT
274#define CPU_PARTITION_ALIGNMENT          CPU_ALIGNMENT
275
276/*
277 *  On m68k thread stacks require no further alignment after allocation
278 *  from the Workspace.
279 */
280
281#define CPU_STACK_ALIGNMENT        0
282
283#ifndef ASM
284
285/* macros */
286
287/*
288 *  ISR handler macros
289 *
290 *  These macros perform the following functions:
291 *     + disable all maskable CPU interrupts
292 *     + restore previous interrupt level (enable)
293 *     + temporarily restore interrupts (flash)
294 *     + set a particular level
295 */
296
297#define _CPU_ISR_Disable( _level ) \
298  m68k_disable_interrupts( _level )
299
300#define _CPU_ISR_Enable( _level ) \
301  m68k_enable_interrupts( _level )
302
303#define _CPU_ISR_Flash( _level ) \
304  m68k_flash_interrupts( _level )
305
306#define _CPU_ISR_Set_level( _newlevel ) \
307   m68k_set_interrupt_level( _newlevel )
308
309unsigned32 _CPU_ISR_Get_level( void );
310
311/* end of ISR handler macros */
312
313/*
314 *  Context handler macros
315 *
316 *  These macros perform the following functions:
317 *     + initialize a context area
318 *     + restart the current thread
319 *     + calculate the initial pointer into a FP context area
320 *     + initialize an FP context area
321 */
322
323#define _CPU_Context_Initialize( _the_context, _stack_base, _size, \
324                                 _isr, _entry_point, _is_fp ) \
325   do { \
326     unsigned32 _stack; \
327     \
328     (_the_context)->sr      = 0x3000 | ((_isr) << 8); \
329     _stack                  = (unsigned32)(_stack_base) + (_size) - 4; \
330     (_the_context)->a7_msp  = (void *)_stack; \
331     *(void **)_stack        = (void *)(_entry_point); \
332   } while ( 0 )
333
334#define _CPU_Context_Restart_self( _the_context ) \
335  { asm volatile( "movew %0,%%sr ; " \
336                  "moval %1,%%a7 ; " \
337                  "rts"  \
338        : "=d" ((_the_context)->sr), "=d" ((_the_context)->a7_msp) \
339        : "0" ((_the_context)->sr), "1" ((_the_context)->a7_msp) ); \
340  }
341
342/*
343 *  Floating Point Context Area Support routines
344 */
345
346#if (CPU_SOFTWARE_FP == TRUE)
347
348/*
349 *  This software FP implementation is only for GCC.
350 */
351
352#define _CPU_Context_Fp_start( _base, _offset ) \
353   ((void *) _Addresses_Add_offset( (_base), (_offset) ) )
354
355
356#define _CPU_Context_Initialize_fp( _fp_area ) \
357   { \
358   Context_Control_fp *_fp; \
359   _fp = *(Context_Control_fp **)_fp_area; \
360   _fp->_exception_bits = 0; \
361   _fp->_trap_enable_bits = 0; \
362   _fp->_sticky_bits = 0; \
363   _fp->_rounding_mode = 0;  /* ROUND_TO_NEAREST */ \
364   _fp->_format = 0;         /* NIL */ \
365   _fp->_last_operation = 0;  /* NOOP */ \
366   _fp->_operand1.df = 0; \
367   _fp->_operand2.df = 0; \
368   }
369#else
370#define _CPU_Context_Fp_start( _base, _offset ) \
371   ((void *) \
372     _Addresses_Add_offset( \
373        (_base), \
374        (_offset) + CPU_CONTEXT_FP_SIZE - 4 \
375     ) \
376   )
377
378#define _CPU_Context_Initialize_fp( _fp_area ) \
379   { unsigned32 *_fp_context = (unsigned32 *)*(_fp_area); \
380     \
381     *(--(_fp_context)) = 0; \
382     *(_fp_area) = (unsigned8 *)(_fp_context); \
383   }
384#endif
385
386/* end of Context handler macros */
387
388/*
389 *  Fatal Error manager macros
390 *
391 *  These macros perform the following functions:
392 *    + disable interrupts and halt the CPU
393 */
394
395#if ( M68K_COLDFIRE_ARCH == 1 )
396#define _CPU_Fatal_halt( _error ) \
397  { asm volatile( "move.w %%sr,%%d0\n\t" \
398                  "or.l %2,%%d0\n\t" \
399                  "move.w %%d0,%%sr\n\t" \
400                  "move.l %1,%%d0\n\t" \
401                  "move.l #0xDEADBEEF,%%d1\n\t" \
402                  "halt" \
403                  : "=g" (_error) \
404                  : "0" (_error), "d"(0x0700) \
405                  : "d0", "d1" ); \
406  }
407#else
408#define _CPU_Fatal_halt( _error ) \
409  { asm volatile( "movl  %0,%%d0; " \
410                  "orw   #0x0700,%%sr; " \
411                  "stop  #0x2700" : "=d" ((_error)) : "0" ((_error)) ); \
412  }
413#endif
414
415/* end of Fatal Error manager macros */
416
417/*
418 *  Bitfield handler macros
419 *
420 *  These macros perform the following functions:
421 *     + scan for the highest numbered (MSB) set in a 16 bit bitfield
422 *
423 *  NOTE:
424 *
425 *    It appears that on the M68020 bitfield are always 32 bits wide
426 *    when in a register.  This code forces the bitfield to be in
427 *    memory (it really always is anyway). This allows us to
428 *    have a real 16 bit wide bitfield which operates "correctly."
429 */
430
431#define CPU_USE_GENERIC_BITFIELD_CODE FALSE
432#define CPU_USE_GENERIC_BITFIELD_DATA FALSE
433
434#if ( M68K_HAS_BFFFO == 1 )
435
436#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
437  asm volatile( "bfffo (%1),#0,#16,%0" : "=d" (_output) : "a" (&_value));
438#else
439
440/* duplicates BFFFO results for 16 bits (i.e., 15-(_priority) in
441   _CPU_Priority_bits_index is not needed), handles the 0 case, and
442   does not molest _value -- jsg */
443#if ( M68K_COLDFIRE_ARCH == 1 )
444#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
445  { \
446    extern const unsigned char __BFFFOtable[256]; \
447    register int dumby; \
448    \
449    asm volatile ( \
450       "   clr.l   %1\n"         \
451       "   move.w  %2,%1\n"      \
452       "   lsr.l   #8,%1\n"      \
453       "   beq.s   1f\n"         \
454       "   move.b  (%3,%1),%0\n" \
455       "   bra.s   0f\n"         \
456       "1: move.w  %2,%1\n"      \
457       "   move.b  (%3,%1),%0\n" \
458       "   addq.l  #8,%0\n"      \
459       "0: and.l   #0xff,%0\n"   \
460       : "=&d" ((_output)), "=&d" ((dumby))    \
461       : "d" ((_value)), "ao" ((__BFFFOtable)) \
462       : "cc" ) ; \
463  }
464#elif ( M68K_HAS_EXTB_L == 1 )
465#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
466  { \
467    extern const unsigned char __BFFFOtable[256]; \
468    register int dumby; \
469    \
470    asm volatile ( "   move.w  %2,%1\n"        \
471       "   lsr.w   #8,%1\n"        \
472       "   beq.s   1f\n"           \
473       "   move.b  (%3,%1.w),%0\n" \
474       "   extb.l  %0\n"           \
475       "   bra.s   0f\n"           \
476       "1: moveq.l #8,%0\n"        \
477       "   add.b   (%3,%2.w),%0\n" \
478       "0:\n"                      \
479       : "=&d" ((_output)), "=&d" ((dumby)) \
480       : "d" ((_value)), "ao" ((__BFFFOtable)) \
481       : "cc" ) ; \
482  }
483#else
484#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
485  { \
486    extern const unsigned char __BFFFOtable[256]; \
487    register int dumby; \
488    \
489    asm volatile ( "   move.w  %2,%1\n"        \
490       "   lsr.w   #8,%1\n"        \
491       "   beq.s   1f\n"           \
492       "   move.b  (%3,%1.w),%0\n" \
493       "   and.l   #0x000000ff,%0\n"\
494       "   bra.s   0f\n"           \
495       "1: moveq.l #8,%0\n"        \
496       "   add.b   (%3,%2.w),%0\n" \
497       "0:\n"                      \
498       : "=&d" ((_output)), "=&d" ((dumby)) \
499       : "d" ((_value)), "ao" ((__BFFFOtable)) \
500       : "cc" ) ; \
501  }
502#endif
503
504#endif
505
506/* end of Bitfield handler macros */
507
508/*
509 *  Priority handler macros
510 *
511 *  These macros perform the following functions:
512 *    + return a mask with the bit for this major/minor portion of
513 *      of thread priority set.
514 *    + translate the bit number returned by "Bitfield_find_first_bit"
515 *      into an index into the thread ready chain bit maps
516 */
517
518#define _CPU_Priority_Mask( _bit_number ) \
519  ( 0x8000 >> (_bit_number) )
520
521#define _CPU_Priority_bits_index( _priority ) \
522  (_priority)
523
524/* end of Priority handler macros */
525
526/* functions */
527
528/*
529 *  _CPU_Initialize
530 *
531 *  This routine performs CPU dependent initialization.
532 */
533
534void _CPU_Initialize(
535  rtems_cpu_table  *cpu_table,
536  void      (*thread_dispatch)
537);
538
539/*
540 *  _CPU_ISR_install_raw_handler
541 *
542 *  This routine installs a "raw" interrupt handler directly into the
543 *  processor's vector table.
544 */
545 
546void _CPU_ISR_install_raw_handler(
547  unsigned32  vector,
548  proc_ptr    new_handler,
549  proc_ptr   *old_handler
550);
551
552/*
553 *  _CPU_ISR_install_vector
554 *
555 *  This routine installs an interrupt vector.
556 */
557
558void _CPU_ISR_install_vector(
559  unsigned32       vector,
560  proc_ptr         new_handler,
561  proc_ptr        *old_handler
562);
563
564/*
565 *  _CPU_Install_interrupt_stack
566 *
567 *  This routine installs the hardware interrupt stack pointer.
568 */
569
570void _CPU_Install_interrupt_stack( void );
571
572/*
573 *  _CPU_Context_switch
574 *
575 *  This routine switches from the run context to the heir context.
576 */
577
578void _CPU_Context_switch(
579  Context_Control  *run,
580  Context_Control  *heir
581);
582
583/*
584 *  _CPU_Context_save_fp
585 *
586 *  This routine saves the floating point context passed to it.
587 */
588
589void _CPU_Context_save_fp(
590  void **fp_context_ptr
591);
592
593/*
594 *  _CPU_Context_restore_fp
595 *
596 *  This routine restores the floating point context passed to it.
597 */
598
599void _CPU_Context_restore_fp(
600  void **fp_context_ptr
601);
602
603#if (M68K_HAS_FPSP_PACKAGE == 1)
604/*
605 *  Hooks for the Floating Point Support Package (FPSP) provided by Motorola
606 *
607 *  NOTES: 
608 *
609 *  Motorola 68k family CPU's before the 68040 used a coprocessor
610 *  (68881 or 68882) to handle floating point.  The 68040 has internal
611 *  floating point support -- but *not* the complete support provided by
612 *  the 68881 or 68882.  The leftover functions are taken care of by the
613 *  M68040 Floating Point Support Package.  Quoting from the MC68040
614 *  Microprocessors User's Manual, Section 9, Floating-Point Unit (MC68040):
615 *
616 *    "When used with the M68040FPSP, the MC68040 FPU is fully
617 *    compliant with IEEE floating-point standards."
618 *
619 *  M68KFPSPInstallExceptionHandlers is in libcpu/m68k/MODEL/fpsp and
620 *  is invoked early in the application code to insure that proper FP
621 *  behavior is installed.  This is not left to the BSP to call, since
622 *  this would force all applications using that BSP to use FPSP which
623 *  is not necessarily desirable.
624 *
625 *  There is a similar package for the 68060 but RTEMS does not yet
626 *  support the 68060.
627 */
628
629void M68KFPSPInstallExceptionHandlers (void);
630
631SCORE_EXTERN int (*_FPSP_install_raw_handler)(
632  unsigned32 vector,
633  proc_ptr new_handler,
634  proc_ptr *old_handler
635);
636
637#endif
638
639
640#endif
641
642#ifdef __cplusplus
643}
644#endif
645
646#endif
647/* end of include file */
Note: See TracBrowser for help on using the repository browser.