source: rtems/cpukit/score/cpu/m68k/rtems/score/cpu.h @ e339d8b

4.104.114.95
Last change on this file since e339d8b was e339d8b, checked in by Chris Johns <chrisj@…>, on 06/11/08 at 08:19:13

hris Johns <chrisj@…>

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