source: rtems/c/src/exec/score/cpu/m68k/cpu.h @ 5bf6ffb

4.104.114.84.95
Last change on this file since 5bf6ffb was 5bf6ffb, checked in by Joel Sherrill <joel.sherrill@…>, on 04/16/97 at 17:34:40

Added FPSP support for MC68040

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