source: rtems/cpukit/score/cpu/powerpc/rtems/old-exceptions/cpu.h @ a031fc22

4.104.114.84.95
Last change on this file since a031fc22 was a031fc22, checked in by Till Straumann <strauman@…>, on 07/13/06 at 00:36:15
  • rtems/old-exceptions/cpu.h, rtems/powerpc/registers.h: Checked inline assembly; added early-clobber '&' to output operands of multi-instruction asms.
  • Property mode set to 100644
File size: 15.3 KB
Line 
1/*  cpu.h
2 *
3 *  This include file contains information pertaining to the PowerPC
4 *  processor.
5 *
6 *  Author:     Andrew Bray <andy@i-cubed.co.uk>
7 *
8 *  COPYRIGHT (c) 1995 by i-cubed ltd.
9 *
10 *  To anyone who acknowledges that this file is provided "AS IS"
11 *  without any express or implied warranty:
12 *      permission to use, copy, modify, and distribute this file
13 *      for any purpose is hereby granted without fee, provided that
14 *      the above copyright notice and this notice appears in all
15 *      copies, and that the name of i-cubed limited not be used in
16 *      advertising or publicity pertaining to distribution of the
17 *      software without specific, written prior permission.
18 *      i-cubed limited makes no representations about the suitability
19 *      of this software for any purpose.
20 *
21 *  Derived from c/src/exec/cpu/no_cpu/cpu.h:
22 *
23 *  COPYRIGHT (c) 1989-2006.
24 *  On-Line Applications Research Corporation (OAR).
25 *
26 *  The license and distribution terms for this file may in
27 *  the file LICENSE in this distribution or at
28 *  http://www.rtems.com/license/LICENSE.
29 *
30 *  $Id$
31 */
32
33#ifndef _RTEMS_OLD_EXCEPTIONS_CPU_H
34#define _RTEMS_OLD_EXCEPTIONS_CPU_H
35
36#ifndef _RTEMS_SCORE_CPU_H
37#error "You should include <rtems/score/cpu.h>"
38#endif
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44#ifndef ASM
45struct CPU_Interrupt_frame;
46typedef void ( *ppc_isr_entry )( int, struct CPU_Interrupt_frame * );
47#endif
48
49/* conditional compilation parameters */
50
51/*
52 *  Does RTEMS manage a dedicated interrupt stack in software?
53 *
54 *  If TRUE, then a stack is allocated in _ISR_Handler_initialization.
55 *  If FALSE, nothing is done.
56 *
57 *  If the CPU supports a dedicated interrupt stack in hardware,
58 *  then it is generally the responsibility of the BSP to allocate it
59 *  and set it up.
60 *
61 *  If the CPU does not support a dedicated interrupt stack, then
62 *  the porter has two options: (1) execute interrupts on the
63 *  stack of the interrupted task, and (2) have RTEMS manage a dedicated
64 *  interrupt stack.
65 *
66 *  If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
67 *
68 *  Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
69 *  CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
70 *  possible that both are FALSE for a particular CPU.  Although it
71 *  is unclear what that would imply about the interrupt processing
72 *  procedure on that CPU.
73 */
74
75#define CPU_HAS_SOFTWARE_INTERRUPT_STACK FALSE
76
77/*
78 *  Does this CPU have hardware support for a dedicated interrupt stack?
79 *
80 *  If TRUE, then it must be installed during initialization.
81 *  If FALSE, then no installation is performed.
82 *
83 *  If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
84 *
85 *  Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
86 *  CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
87 *  possible that both are FALSE for a particular CPU.  Although it
88 *  is unclear what that would imply about the interrupt processing
89 *  procedure on that CPU.
90 */
91
92/*
93 *  ACB: This is a lie, but it gets us a handle on a call to set up
94 *  a variable derived from the top of the interrupt stack.
95 */
96
97#define CPU_HAS_HARDWARE_INTERRUPT_STACK TRUE
98
99/*
100 *  Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
101 *
102 *  If TRUE, then the memory is allocated during initialization.
103 *  If FALSE, then the memory is allocated during initialization.
104 *
105 *  This should be TRUE is CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE.
106 */
107
108#define CPU_ALLOCATE_INTERRUPT_STACK TRUE
109
110/*
111 *  Does the RTEMS invoke the user's ISR with the vector number and
112 *  a pointer to the saved interrupt frame (1) or just the vector
113 *  number (0)?
114 */
115
116#define CPU_ISR_PASSES_FRAME_POINTER 1
117
118/*
119 *  Should the saving of the floating point registers be deferred
120 *  until a context switch is made to another different floating point
121 *  task?
122 *
123 *  If TRUE, then the floating point context will not be stored until
124 *  necessary.  It will remain in the floating point registers and not
125 *  disturned until another floating point task is switched to.
126 *
127 *  If FALSE, then the floating point context is saved when a floating
128 *  point task is switched out and restored when the next floating point
129 *  task is restored.  The state of the floating point registers between
130 *  those two operations is not specified.
131 *
132 *  If the floating point context does NOT have to be saved as part of
133 *  interrupt dispatching, then it should be safe to set this to TRUE.
134 *
135 *  Setting this flag to TRUE results in using a different algorithm
136 *  for deciding when to save and restore the floating point context.
137 *  The deferred FP switch algorithm minimizes the number of times
138 *  the FP context is saved and restored.  The FP context is not saved
139 *  until a context switch is made to another, different FP task.
140 *  Thus in a system with only one FP task, the FP context will never
141 *  be saved or restored.
142 */
143/*
144 *  ACB Note:  This could make debugging tricky..
145 */
146
147#define CPU_USE_DEFERRED_FP_SWITCH       TRUE
148
149/*
150 *  The following defines the number of bits actually used in the
151 *  interrupt field of the task mode.  How those bits map to the
152 *  CPU interrupt levels is defined by the routine _CPU_ISR_Set_level().
153 *
154 *  The interrupt level is bit mapped for the PowerPC family. The
155 *  bits are set to 0 to indicate that a particular exception source
156 *  enabled and 1 if it is disabled.  This keeps with RTEMS convention
157 *  that interrupt level 0 means all sources are enabled.
158 *
159 *  The bits are assigned to correspond to enable bits in the MSR.
160 */
161
162#define PPC_INTERRUPT_LEVEL_ME   0x01
163#define PPC_INTERRUPT_LEVEL_EE   0x02
164#define PPC_INTERRUPT_LEVEL_CE   0x04
165
166/* XXX should these be maskable? */
167#if 0
168#define PPC_INTERRUPT_LEVEL_DE   0x08
169#define PPC_INTERRUPT_LEVEL_BE   0x10
170#define PPC_INTERRUPT_LEVEL_SE   0x20
171#endif
172
173#define CPU_MODES_INTERRUPT_MASK   0x00000007
174
175/*
176 *  Processor defined structures required for cpukit/score.
177 */
178
179#ifndef ASM
180/*
181 *  The following table contains the information required to configure
182 *  the PowerPC processor specific parameters.
183 */
184
185typedef struct {
186  void       (*pretasking_hook)( void );
187  void       (*predriver_hook)( void );
188  void       (*postdriver_hook)( void );
189  void       (*idle_task)( void );
190  boolean      do_zero_of_workspace;
191  uint32_t     idle_task_stack_size;
192  uint32_t     interrupt_stack_size;
193  uint32_t     extra_mpci_receive_server_stack;
194  void *     (*stack_allocate_hook)( uint32_t   );
195  void       (*stack_free_hook)( void* );
196  /* end of fields required on all CPUs */
197
198  uint32_t     clicks_per_usec;        /* Timer clicks per microsecond */
199  void       (*spurious_handler)(uint32_t   vector, CPU_Interrupt_frame *);
200  boolean      exceptions_in_RAM;     /* TRUE if in RAM */
201
202#if (defined(ppc403) || defined(ppc405) \
203  || defined(mpc860) || defined(mpc821) || defined(mpc8260))
204  uint32_t     serial_per_sec;         /* Serial clocks per second */
205  boolean      serial_external_clock;
206  boolean      serial_xon_xoff;
207  boolean      serial_cts_rts;
208  uint32_t     serial_rate;
209  uint32_t     timer_average_overhead; /* Average overhead of timer in ticks */
210  uint32_t     timer_least_valid;      /* Least valid number from timer      */
211  boolean      timer_internal_clock;   /* TRUE, when timer runs with CPU clk */
212#endif
213
214#if (defined(mpc555) \
215  || defined(mpc860) || defined(mpc821) || defined(mpc8260))
216  uint32_t     clock_speed;            /* Speed of CPU in Hz */
217#endif
218}   rtems_cpu_table;
219#endif
220
221/*
222 *  Macros to access required entires in the CPU Table are in
223 *  the file rtems/system.h.
224 */
225
226/*
227 *  Macros to access PowerPC specific additions to the CPU Table
228 */
229
230#ifndef ASM
231#define rtems_cpu_configuration_get_spurious_handler() \
232   (_CPU_Table.spurious_handler)
233#endif /* ASM */
234
235/*
236 *  The following type defines an entry in the PPC's trap table.
237 *
238 *  NOTE: The instructions chosen are RTEMS dependent although one is
239 *        obligated to use two of the four instructions to perform a
240 *        long jump.  The other instructions load one register with the
241 *        trap type (a.k.a. vector) and another with the psr.
242 */
243 
244#ifndef ASM
245typedef struct {
246  uint32_t     stwu_r1;                       /* stwu  %r1, -(??+IP_END)(%1)*/
247  uint32_t     stw_r0;                        /* stw   %r0, IP_0(%r1)       */
248  uint32_t     li_r0_IRQ;                     /* li    %r0, _IRQ            */
249  uint32_t     b_Handler;                     /* b     PROC (_ISR_Handler)  */
250} CPU_Trap_table_entry;
251#endif
252
253/*
254 *  This variable is optional.  It is used on CPUs on which it is difficult
255 *  to generate an "uninitialized" FP context.  It is filled in by
256 *  _CPU_Initialize and copied into the task's FP context area during
257 *  _CPU_Context_Initialize.
258 */
259
260#ifndef ASM
261/* EXTERN Context_Control_fp  _CPU_Null_fp_context; */
262#endif
263
264/*
265 *  On some CPUs, RTEMS supports a software managed interrupt stack.
266 *  This stack is allocated by the Interrupt Manager and the switch
267 *  is performed in _ISR_Handler.  These variables contain pointers
268 *  to the lowest and highest addresses in the chunk of memory allocated
269 *  for the interrupt stack.  Since it is unknown whether the stack
270 *  grows up or down (in general), this give the CPU dependent
271 *  code the option of picking the version it wants to use.
272 *
273 *  NOTE: These two variables are required if the macro
274 *        CPU_HAS_SOFTWARE_INTERRUPT_STACK is defined as TRUE.
275 */
276
277#ifndef ASM
278SCORE_EXTERN void               *_CPU_Interrupt_stack_low;
279SCORE_EXTERN void               *_CPU_Interrupt_stack_high;
280#endif
281
282/*
283 *  With some compilation systems, it is difficult if not impossible to
284 *  call a high-level language routine from assembly language.  This
285 *  is especially true of commercial Ada compilers and name mangling
286 *  C++ ones.  This variable can be optionally defined by the CPU porter
287 *  and contains the address of the routine _Thread_Dispatch.  This
288 *  can make it easier to invoke that routine at the end of the interrupt
289 *  sequence (if a dispatch is necessary).
290 */
291
292#ifndef ASM
293/* EXTERN void           (*_CPU_Thread_dispatch_pointer)(); */
294#endif
295
296/*
297 *  Nothing prevents the porter from declaring more CPU specific variables.
298 */
299
300
301#ifndef ASM
302SCORE_EXTERN struct {
303  uint32_t   volatile* Nest_level;
304  uint32_t   volatile* Disable_level;
305  void *Vector_table;
306  void *Stack;
307  uint32_t   Default_r2;
308  uint32_t   Default_r13;
309  volatile boolean *Switch_necessary;
310  boolean *Signal;
311
312  uint32_t   msr_initial;
313} _CPU_IRQ_info CPU_STRUCTURE_ALIGNMENT;
314#endif
315
316/*
317 *  The size of the floating point context area.  On some CPUs this
318 *  will not be a "sizeof" because the format of the floating point
319 *  area is not defined -- only the size is.  This is usually on
320 *  CPUs with a "floating point save context" instruction.
321 */
322
323#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
324
325/*
326 * (Optional) # of bytes for libmisc/stackchk to check
327 * If not specifed, then it defaults to something reasonable
328 * for most architectures.
329 */
330
331#define CPU_STACK_CHECK_SIZE    (128)
332
333/*
334 *  Amount of extra stack (above minimum stack size) required by
335 *  MPCI receive server thread.  Remember that in a multiprocessor
336 *  system this thread must exist and be able to process all directives.
337 */
338
339#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
340
341/*
342 *  This defines the number of entries in the ISR_Vector_table managed
343 *  by RTEMS.
344 */
345
346#define CPU_INTERRUPT_NUMBER_OF_VECTORS     (PPC_INTERRUPT_MAX)
347#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER (PPC_INTERRUPT_MAX - 1)
348
349/*
350 *  This is defined if the port has a special way to report the ISR nesting
351 *  level.  Most ports maintain the variable _ISR_Nest_level.
352 */
353
354#define CPU_PROVIDES_ISR_IS_IN_PROGRESS TRUE
355
356/*
357 *  ISR handler macros
358 */
359
360#ifndef ASM
361void _CPU_Initialize_vectors(void);
362#endif
363
364/*
365 *  Disable all interrupts for an RTEMS critical section.  The previous
366 *  level is returned in _isr_cookie.
367 */
368
369#ifndef ASM
370extern const unsigned int _PPC_MSR_DISABLE_MASK;
371
372#define _CPU_MSR_GET( _msr_value ) \
373  do { \
374    _msr_value = 0; \
375    asm volatile ("mfmsr %0" : "=&r" ((_msr_value)) : "0" ((_msr_value))); \
376  } while (0)
377
378/* FIXME: Backward compatibility
379 * new-exception-processing uses _CPU_MSR_GET
380 * old-exception-processing had used _CPU_MSR_Value
381 */
382#define _CPU_MSR_Value(_msr_value) _CPU_MSR_GET(_msr_value)
383
384#define _CPU_MSR_SET( _msr_value ) \
385{ asm volatile ("mtmsr %0" : "=&r" ((_msr_value)) : "0" ((_msr_value))); }
386
387#if 0
388#define _CPU_ISR_Disable( _isr_cookie ) \
389  { register unsigned int _disable_mask = _PPC_MSR_DISABLE_MASK; \
390    _isr_cookie = 0; \
391    asm volatile (
392        "mfmsr %0" : \
393        "=r" ((_isr_cookie)) : \
394        "0" ((_isr_cookie)) \
395    ); \
396    asm volatile (
397        "andc %1,%0,%1" : \
398        "=r" ((_isr_cookie)), "=&r" ((_disable_mask)) : \
399        "0" ((_isr_cookie)), "1" ((_disable_mask)) \
400    ); \
401    asm volatile (
402        "mtmsr %1" : \
403        "=r" ((_disable_mask)) : \
404        "0" ((_disable_mask)) \
405    ); \
406  }
407#endif
408
409#define _CPU_ISR_Disable( _isr_cookie ) \
410  { register unsigned int _disable_mask = _PPC_MSR_DISABLE_MASK; \
411    _isr_cookie = 0; \
412    asm volatile ( \
413        "mfmsr %0; andc %1,%0,%1; mtmsr %1" : \
414        "=&r" ((_isr_cookie)), "=&r" ((_disable_mask)) : \
415        "0" ((_isr_cookie)), "1" ((_disable_mask)) \
416        ); \
417  }
418#endif
419
420/*
421 *  Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
422 *  This indicates the end of an RTEMS critical section.  The parameter
423 *  _isr_cookie is not modified.
424 */
425
426#ifndef ASM
427#define _CPU_ISR_Enable( _isr_cookie )  \
428  { \
429     asm volatile ( "mtmsr %0" : \
430                   "=r" ((_isr_cookie)) : \
431                   "0" ((_isr_cookie))); \
432  }
433#endif
434
435/*
436 *  This temporarily restores the interrupt to _isr_cookie before immediately
437 *  disabling them again.  This is used to divide long RTEMS critical
438 *  sections into two or more parts.  The parameter _isr_cookie is not
439 *  modified.
440 *
441 *  NOTE:  The version being used is not very optimized but it does
442 *         not trip a problem in gcc where the disable mask does not
443 *         get loaded.  Check this for future (post 10/97 gcc versions.
444 */
445
446#ifndef ASM
447#define _CPU_ISR_Flash( _isr_cookie ) \
448  { register unsigned int _disable_mask = _PPC_MSR_DISABLE_MASK; \
449    asm volatile ( \
450      "mtmsr %0; andc %1,%0,%1; mtmsr %1" : \
451      "=&r" ((_isr_cookie)), "=&r" ((_disable_mask)) : \
452      "0" ((_isr_cookie)), "1" ((_disable_mask)) \
453    ); \
454  }
455#endif
456
457/*
458 *  Map interrupt level in task mode onto the hardware that the CPU
459 *  actually provides.  Currently, interrupt levels which do not
460 *  map onto the CPU in a generic fashion are undefined.  Someday,
461 *  it would be nice if these were "mapped" by the application
462 *  via a callout.  For example, m68k has 8 levels 0 - 7, levels
463 *  8 - 255 would be available for bsp/application specific meaning.
464 *  This could be used to manage a programmable interrupt controller
465 *  via the rtems_task_mode directive.
466 */
467
468#ifndef ASM
469uint32_t   _CPU_ISR_Calculate_level(
470  uint32_t   new_level
471);
472
473void _CPU_ISR_Set_level(
474  uint32_t   new_level
475);
476 
477uint32_t   _CPU_ISR_Get_level( void );
478
479void _CPU_ISR_install_raw_handler(
480  uint32_t    vector,
481  proc_ptr    new_handler,
482  proc_ptr   *old_handler
483);
484#endif
485
486/* end of ISR handler macros */
487
488/* Fatal Error manager macros */
489
490/*
491 *  This routine copies _error into a known place -- typically a stack
492 *  location or a register, optionally disables interrupts, and
493 *  halts/stops the CPU.
494 */
495
496#define _CPU_Fatal_halt( _error ) \
497  _CPU_Fatal_error(_error)
498
499/* end of Fatal Error manager macros */
500
501
502#ifdef __cplusplus
503}
504#endif
505
506#endif
Note: See TracBrowser for help on using the repository browser.