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

4.104.114.84.95
Last change on this file since bf61e45c was ac7d5ef0, checked in by Joel Sherrill <joel.sherrill@…>, on 05/11/95 at 17:39:37

Initial revision

  • Property mode set to 100644
File size: 10.4 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/*
25 *  If defined, this causes some of the macros to initialize their
26 *  variables to zero before doing inline assembly.  This gets rid
27 *  of compile time warnings at the cost of a little execution time
28 *  in some time critical routines.
29 */
30
31#define NO_UNINITIALIZED_WARNINGS
32
33#include <m68k.h>
34
35/* conditional compilation parameters */
36
37#define CPU_INLINE_ENABLE_DISPATCH       TRUE
38#define CPU_UNROLL_ENQUEUE_PRIORITY      FALSE
39
40/*
41 *  Use the m68k's hardware interrupt stack support and have the
42 *  interrupt manager allocate the memory for it.
43 */
44
45#define CPU_HAS_SOFTWARE_INTERRUPT_STACK FALSE
46#define CPU_HAS_HARDWARE_INTERRUPT_STACK TRUE
47#define CPU_ALLOCATE_INTERRUPT_STACK     TRUE
48
49/*
50 *  Some family members have no FP, some have an FPU such as the
51 *  MC68881/MC68882 for the MC68020, others have it built in (MC68030, 040).
52 */
53
54#if ( M68K_HAS_FPU == 1 )
55#define CPU_HARDWARE_FP     TRUE
56#else
57#define CPU_HARDWARE_FP     FALSE
58#endif
59
60/*
61 *  All tasks are not by default floating point tasks on this CPU.
62 *  The IDLE task does not have a floating point context on this CPU.
63 *  It is safe to use the deferred floating point context switch
64 *  algorithm on this CPU.
65 */
66
67#define CPU_ALL_TASKS_ARE_FP             FALSE
68#define CPU_IDLE_TASK_IS_FP              FALSE
69#define CPU_USE_DEFERRED_FP_SWITCH       TRUE
70
71#define CPU_PROVIDES_IDLE_THREAD_BODY    FALSE
72#define CPU_STACK_GROWS_UP               FALSE
73#define CPU_STRUCTURE_ALIGNMENT
74
75/* structures */
76
77/*
78 *  Basic integer context for the m68k family.
79 */
80
81typedef struct {
82  unsigned32  sr;                /* (sr) status register */
83  unsigned32  d2;                /* (d2) data register 2 */
84  unsigned32  d3;                /* (d3) data register 3 */
85  unsigned32  d4;                /* (d4) data register 4 */
86  unsigned32  d5;                /* (d5) data register 5 */
87  unsigned32  d6;                /* (d6) data register 6 */
88  unsigned32  d7;                /* (d7) data register 7 */
89  void       *a2;                /* (a2) address register 2 */
90  void       *a3;                /* (a3) address register 3 */
91  void       *a4;                /* (a4) address register 4 */
92  void       *a5;                /* (a5) address register 5 */
93  void       *a6;                /* (a6) address register 6 */
94  void       *a7_msp;            /* (a7) master stack pointer */
95}   Context_Control;
96
97/*
98 *  FP context save area for the M68881/M68882 numeric coprocessors.
99 */
100
101typedef struct {
102  unsigned8   fp_save_area[332];    /*   216 bytes for FSAVE/FRESTORE    */
103                                    /*    96 bytes for FMOVEM FP0-7      */
104                                    /*    12 bytes for FMOVEM CREGS      */
105                                    /*     4 bytes for non-null flag     */
106} Context_Control_fp;
107
108/*
109 *  The following structure defines the set of information saved
110 *  on the current stack by RTEMS upon receipt of each interrupt.
111 */
112
113typedef struct {
114  unsigned32   TBD;   /* XXX Fix for this CPU */
115} CPU_Interrupt_frame;
116
117/*
118 *  The following table contains the information required to configure
119 *  the m68k specific parameters.
120 */
121
122typedef struct {
123  void       (*pretasking_hook)( void );
124  void       (*predriver_hook)( void );
125  void       (*postdriver_hook)( void );
126  void       (*idle_task)( void );
127  boolean      do_zero_of_workspace;
128  unsigned32   interrupt_stack_size;
129  unsigned32   extra_system_initialization_stack;
130  m68k_isr    *interrupt_vector_table;
131}   rtems_cpu_table;
132
133/* variables */
134
135EXTERN void               *_CPU_Interrupt_stack_low;
136EXTERN void               *_CPU_Interrupt_stack_high;
137
138/* constants */
139
140/*
141 *  This defines the number of levels and the mask used to pick those
142 *  bits out of a thread mode.
143 */
144
145#define CPU_MODES_INTERRUPT_LEVEL  0x00000007 /* interrupt level in mode */
146#define CPU_MODES_INTERRUPT_MASK   0x00000007 /* interrupt level in mode */
147
148/*
149 *  context size area for floating point
150 */
151
152#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
153
154/*
155 *  extra stack required by system initialization thread
156 */
157
158#define CPU_SYSTEM_INITIALIZATION_THREAD_EXTRA_STACK 1024
159
160/*
161 *  m68k family supports 256 distinct vectors.
162 */
163
164#define CPU_INTERRUPT_NUMBER_OF_VECTORS  256
165
166/*
167 *  Minimum size of a thread's stack.
168 *
169 *  NOTE:  256 bytes is probably too low in most cases.
170 */
171
172#define CPU_STACK_MINIMUM_SIZE           256
173
174/*
175 *  m68k is pretty tolerant of alignment.  Just put things on 4 byte boundaries.
176 */
177
178#define CPU_ALIGNMENT                    4
179#define CPU_HEAP_ALIGNMENT               CPU_ALIGNMENT
180#define CPU_PARTITION_ALIGNMENT          CPU_ALIGNMENT
181
182/*
183 *  On m68k thread stacks require no further alignment after allocation
184 *  from the Workspace.
185 */
186
187#define CPU_STACK_ALIGNMENT        0
188
189/* macros */
190
191/*
192 *  ISR handler macros
193 *
194 *  These macros perform the following functions:
195 *     + disable all maskable CPU interrupts
196 *     + restore previous interrupt level (enable)
197 *     + temporarily restore interrupts (flash)
198 *     + set a particular level
199 */
200
201#define _CPU_ISR_Disable( _level ) \
202  m68k_disable_interrupts( _level )
203
204#define _CPU_ISR_Enable( _level ) \
205  m68k_enable_interrupts( _level )
206
207#define _CPU_ISR_Flash( _level ) \
208  m68k_flash_interrupts( _level )
209
210#define _CPU_ISR_Set_level( _newlevel ) \
211   m68k_set_interrupt_level( _newlevel )
212
213/* end of ISR handler macros */
214
215/*
216 *  Context handler macros
217 *
218 *  These macros perform the following functions:
219 *     + initialize a context area
220 *     + restart the current thread
221 *     + calculate the initial pointer into a FP context area
222 *     + initialize an FP context area
223 */
224
225#define _CPU_Context_Initialize( _the_context, _stack_base, _size, \
226                                 _isr, _entry_point ) \
227   do { \
228     void   *_stack; \
229     \
230     (_the_context)->sr      = 0x3000 | ((_isr) << 8); \
231     _stack                  = (void *)(_stack_base) + (_size) - 4; \
232     (_the_context)->a7_msp  = _stack; \
233     *(void **)_stack = (_entry_point); \
234   } while ( 0 )
235
236#define _CPU_Context_Restart_self( _the_context ) \
237  { asm volatile( "movew %0,%%sr ; " \
238                  "moval %1,%%a7 ; " \
239                  "rts"  \
240        : "=d" ((_the_context)->sr), "=d" ((_the_context)->a7_msp) \
241        : "0" ((_the_context)->sr), "1" ((_the_context)->a7_msp) ); \
242  }
243
244#define _CPU_Context_Fp_start( _base, _offset ) \
245   ((void *) \
246     _Addresses_Add_offset( \
247        (_base), \
248        (_offset) + CPU_CONTEXT_FP_SIZE - 4 \
249     ) \
250   )
251
252#define _CPU_Context_Initialize_fp( _fp_area ) \
253   { unsigned32 *_fp_context = (unsigned32 *)*(_fp_area); \
254     \
255     *(--(_fp_context)) = 0; \
256     *(_fp_area) = (unsigned8 *)(_fp_context); \
257   }
258
259/* end of Context handler macros */
260
261/*
262 *  Fatal Error manager macros
263 *
264 *  These macros perform the following functions:
265 *    + disable interrupts and halt the CPU
266 */
267
268#define _CPU_Fatal_halt( _error ) \
269  { asm volatile( "movl  %0,%%d0; " \
270                  "orw   #0x0700,%%sr; " \
271                  "stop  #0x2700" : "=d" ((_error)) : "0" ((_error)) ); \
272  }
273
274/* end of Fatal Error manager macros */
275
276/*
277 *  Bitfield handler macros
278 *
279 *  These macros perform the following functions:
280 *     + scan for the highest numbered (MSB) set in a 16 bit bitfield
281 *
282 *  NOTE:
283 *
284 *    It appears that on the M68020 bitfield are always 32 bits wide
285 *    when in a register.  This code forces the bitfield to be in
286 *    memory (it really always is anyway). This allows us to
287 *    have a real 16 bit wide bitfield which operates "correctly."
288 */
289
290#if ( M68K_HAS_BFFFO == 1 )
291#ifdef NO_UNINITIALIZED_WARNINGS
292
293#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
294  { \
295    register void *__base = (void *)&(_value); \
296    \
297    (_output) = 0;  /* avoids warnings */ \
298    asm volatile( "bfffo (%0),#0,#16,%1" \
299                   : "=a" (__base), "=d" ((_output)) \
300                   : "0"  (__base), "1" ((_output))  ) ; \
301  }
302#else
303#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
304  { \
305    register void *__base = (void *)&(_value); \
306    \
307    asm volatile( "bfffo (%0),#0,#16,%1" \
308                   : "=a" (__base), "=d" ((_output)) \
309                   : "0"  (__base), "1" ((_output))  ) ; \
310  }
311#endif
312
313#else
314
315#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
316  (_output) = 0   /* avoids warnings */
317
318#warning "FIX ME... NEEDS A SOFTWARE BFFFO IMPLEMENTATION"
319#warning "SEE no_cpu/cpu.h FOR POSSIBLE ALGORITHMS"
320
321#endif
322
323/* end of Bitfield handler macros */
324
325/*
326 *  Priority handler macros
327 *
328 *  These macros perform the following functions:
329 *    + return a mask with the bit for this major/minor portion of
330 *      of thread priority set.
331 *    + translate the bit number returned by "Bitfield_find_first_bit"
332 *      into an index into the thread ready chain bit maps
333 */
334
335#define _CPU_Priority_Mask( _bit_number ) \
336  ( 0x8000 >> (_bit_number) )
337
338#define _CPU_Priority_Bits_index( _priority ) \
339  (_priority)
340
341/* end of Priority handler macros */
342
343/* functions */
344
345/*
346 *  _CPU_Initialize
347 *
348 *  This routine performs CPU dependent initialization.
349 */
350
351void _CPU_Initialize(
352  rtems_cpu_table  *cpu_table,
353  void      (*thread_dispatch)
354);
355
356/*
357 *  _CPU_ISR_install_vector
358 *
359 *  This routine installs an interrupt vector.
360 */
361
362void _CPU_ISR_install_vector(
363  unsigned32       vector,
364  proc_ptr         new_handler,
365  proc_ptr        *old_handler
366);
367
368/*
369 *  _CPU_Install_interrupt_stack
370 *
371 *  This routine installs the hardware interrupt stack pointer.
372 */
373
374void _CPU_Install_interrupt_stack( void );
375
376/*
377 *  _CPU_Context_switch
378 *
379 *  This routine switches from the run context to the heir context.
380 */
381
382void _CPU_Context_switch(
383  Context_Control  *run,
384  Context_Control  *heir
385);
386
387/*
388 *  _CPU_Context_save_fp
389 *
390 *  This routine saves the floating point context passed to it.
391 */
392
393void _CPU_Context_restore_fp(
394  void **fp_context_ptr
395);
396
397/*
398 *  _CPU_Context_restore_fp
399 *
400 *  This routine restores the floating point context passed to it.
401 */
402
403void _CPU_Context_save_fp(
404  void **fp_context_ptr
405);
406
407#ifdef __cplusplus
408}
409#endif
410
411#endif
412/* end of include file */
Note: See TracBrowser for help on using the repository browser.