source: rtems/cpukit/score/cpu/m32r/rtems/score/cpu.h @ 815994f

4.11
Last change on this file since 815994f was 815994f, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 25, 2012 at 4:48:11 PM

score: Add CPU_Exception_frame

Add CPU port type CPU_Exception_frame and function
_CPU_Exception_frame_print().

The CPU ports of avr, bfin, h8300, lm32, m32c, m32r, m68k, nios2, sh,
sparc64, and v850 use an empty default implementation of
_CPU_Exception_frame_print().

Add rtems_exception_frame and rtems_exception_frame_print().

Add RTEMS_FATAL_SOURCE_EXCEPTION for CPU exceptions. Use rtems_fatal()
with source RTEMS_FATAL_SOURCE_EXCEPTION in CPU ports of i386, powerpc,
and sparc for unexpected exceptions.

Add third parameter to RTEMS_BSP_CLEANUP_OPTIONS() which controls the
BSP_PRINT_EXCEPTION_CONTEXT define used in the default
bsp_fatal_extension().

Add test sptests/spfatal26.

  • Property mode set to 100644
File size: 40.8 KB
Line 
1/**
2 * @file rtems/score/cpu.h
3 */
4
5/*
6 *  This include file contains information pertaining to the XXX
7 *  processor.
8 *
9 *  @note This file is part of a porting template that is intended
10 *  to be used as the starting point when porting RTEMS to a new
11 *  CPU family.  The following needs to be done when using this as
12 *  the starting point for a new port:
13 *
14 *  + Anywhere there is an XXX, it should be replaced
15 *    with information about the CPU family being ported to.
16 *
17 *  + At the end of each comment section, there is a heading which
18 *    says "Port Specific Information:".  When porting to RTEMS,
19 *    add CPU family specific information in this section
20 */
21
22/*
23 *  COPYRIGHT (c) 1989-2008.
24 *  On-Line Applications Research Corporation (OAR).
25 *
26 *  The license and distribution terms for this file may be
27 *  found in the file LICENSE in this distribution or at
28 *  http://www.rtems.com/license/LICENSE.
29 */
30
31#ifndef _RTEMS_SCORE_CPU_H
32#define _RTEMS_SCORE_CPU_H
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38#include <rtems/score/types.h>
39#include <rtems/score/m32r.h>
40
41/* conditional compilation parameters */
42
43/**
44 *  Should the calls to @ref _Thread_Enable_dispatch be inlined?
45 *
46 *  If TRUE, then they are inlined.
47 *  If FALSE, then a subroutine call is made.
48 *
49 *  This conditional is an example of the classic trade-off of size
50 *  versus speed.  Inlining the call (TRUE) typically increases the
51 *  size of RTEMS while speeding up the enabling of dispatching.
52 *
53 *  @note In general, the @ref _Thread_Dispatch_disable_level will
54 *  only be 0 or 1 unless you are in an interrupt handler and that
55 *  interrupt handler invokes the executive.]  When not inlined
56 *  something calls @ref _Thread_Enable_dispatch which in turns calls
57 *  @ref _Thread_Dispatch.  If the enable dispatch is inlined, then
58 *  one subroutine call is avoided entirely.
59 *
60 *  Port Specific Information:
61 *
62 *  XXX document implementation including references if appropriate
63 */
64#define CPU_INLINE_ENABLE_DISPATCH       FALSE
65
66/**
67 *  Should the body of the search loops in _Thread_queue_Enqueue_priority
68 *  be unrolled one time?  In unrolled each iteration of the loop examines
69 *  two "nodes" on the chain being searched.  Otherwise, only one node
70 *  is examined per iteration.
71 *
72 *  If TRUE, then the loops are unrolled.
73 *  If FALSE, then the loops are not unrolled.
74 *
75 *  The primary factor in making this decision is the cost of disabling
76 *  and enabling interrupts (_ISR_Flash) versus the cost of rest of the
77 *  body of the loop.  On some CPUs, the flash is more expensive than
78 *  one iteration of the loop body.  In this case, it might be desirable
79 *  to unroll the loop.  It is important to note that on some CPUs, this
80 *  code is the longest interrupt disable period in RTEMS.  So it is
81 *  necessary to strike a balance when setting this parameter.
82 *
83 *  Port Specific Information:
84 *
85 *  XXX document implementation including references if appropriate
86 */
87#define CPU_UNROLL_ENQUEUE_PRIORITY      TRUE
88
89/**
90 *  Does RTEMS manage a dedicated interrupt stack in software?
91 *
92 *  If TRUE, then a stack is allocated in @ref _ISR_Handler_initialization.
93 *  If FALSE, nothing is done.
94 *
95 *  If the CPU supports a dedicated interrupt stack in hardware,
96 *  then it is generally the responsibility of the BSP to allocate it
97 *  and set it up.
98 *
99 *  If the CPU does not support a dedicated interrupt stack, then
100 *  the porter has two options: (1) execute interrupts on the
101 *  stack of the interrupted task, and (2) have RTEMS manage a dedicated
102 *  interrupt stack.
103 *
104 *  If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
105 *
106 *  Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
107 *  @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
108 *  possible that both are FALSE for a particular CPU.  Although it
109 *  is unclear what that would imply about the interrupt processing
110 *  procedure on that CPU.
111 *
112 *  Port Specific Information:
113 *
114 *  XXX document implementation including references if appropriate
115 */
116#define CPU_HAS_SOFTWARE_INTERRUPT_STACK FALSE
117
118/**
119 *  Does the CPU follow the simple vectored interrupt model?
120 *
121 *  If TRUE, then RTEMS allocates the vector table it internally manages.
122 *  If FALSE, then the BSP is assumed to allocate and manage the vector
123 *  table
124 *
125 *  Port Specific Information:
126 *
127 *  XXX document implementation including references if appropriate
128 */
129#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
130
131/**
132 *  Does this CPU have hardware support for a dedicated interrupt stack?
133 *
134 *  If TRUE, then it must be installed during initialization.
135 *  If FALSE, then no installation is performed.
136 *
137 *  If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
138 *
139 *  Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
140 *  @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
141 *  possible that both are FALSE for a particular CPU.  Although it
142 *  is unclear what that would imply about the interrupt processing
143 *  procedure on that CPU.
144 *
145 *  Port Specific Information:
146 *
147 *  XXX document implementation including references if appropriate
148 */
149#define CPU_HAS_HARDWARE_INTERRUPT_STACK TRUE
150
151/**
152 *  Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
153 *
154 *  If TRUE, then the memory is allocated during initialization.
155 *  If FALSE, then the memory is allocated during initialization.
156 *
157 *  This should be TRUE is CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE.
158 *
159 *  Port Specific Information:
160 *
161 *  XXX document implementation including references if appropriate
162 */
163#define CPU_ALLOCATE_INTERRUPT_STACK TRUE
164
165/**
166 *  Does the RTEMS invoke the user's ISR with the vector number and
167 *  a pointer to the saved interrupt frame (1) or just the vector
168 *  number (0)?
169 *
170 *  Port Specific Information:
171 *
172 *  XXX document implementation including references if appropriate
173 */
174#define CPU_ISR_PASSES_FRAME_POINTER 0
175
176/**
177 *  @def CPU_HARDWARE_FP
178 *
179 *  Does the CPU have hardware floating point?
180 *
181 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
182 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
183 *
184 *  If there is a FP coprocessor such as the i387 or mc68881, then
185 *  the answer is TRUE.
186 *
187 *  The macro name "M32R_HAS_FPU" should be made CPU specific.
188 *  It indicates whether or not this CPU model has FP support.  For
189 *  example, it would be possible to have an i386_nofp CPU model
190 *  which set this to false to indicate that you have an i386 without
191 *  an i387 and wish to leave floating point support out of RTEMS.
192 */
193
194/**
195 *  @def CPU_SOFTWARE_FP
196 *
197 *  Does the CPU have no hardware floating point and GCC provides a
198 *  software floating point implementation which must be context
199 *  switched?
200 *
201 *  This feature conditional is used to indicate whether or not there
202 *  is software implemented floating point that must be context
203 *  switched.  The determination of whether or not this applies
204 *  is very tool specific and the state saved/restored is also
205 *  compiler specific.
206 *
207 *  Port Specific Information:
208 *
209 *  XXX document implementation including references if appropriate
210 */
211#if ( M32R_HAS_FPU == 1 )
212#define CPU_HARDWARE_FP     TRUE
213#else
214#define CPU_HARDWARE_FP     FALSE
215#endif
216#define CPU_SOFTWARE_FP     FALSE
217
218/**
219 *  Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
220 *
221 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
222 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
223 *
224 *  So far, the only CPUs in which this option has been used are the
225 *  HP PA-RISC and PowerPC.  On the PA-RISC, The HP C compiler and
226 *  gcc both implicitly used the floating point registers to perform
227 *  integer multiplies.  Similarly, the PowerPC port of gcc has been
228 *  seen to allocate floating point local variables and touch the FPU
229 *  even when the flow through a subroutine (like vfprintf()) might
230 *  not use floating point formats.
231 *
232 *  If a function which you would not think utilize the FP unit DOES,
233 *  then one can not easily predict which tasks will use the FP hardware.
234 *  In this case, this option should be TRUE.
235 *
236 *  If @ref CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
237 *
238 *  Port Specific Information:
239 *
240 *  XXX document implementation including references if appropriate
241 */
242#define CPU_ALL_TASKS_ARE_FP     TRUE
243
244/**
245 *  Should the IDLE task have a floating point context?
246 *
247 *  If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
248 *  and it has a floating point context which is switched in and out.
249 *  If FALSE, then the IDLE task does not have a floating point context.
250 *
251 *  Setting this to TRUE negatively impacts the time required to preempt
252 *  the IDLE task from an interrupt because the floating point context
253 *  must be saved as part of the preemption.
254 *
255 *  Port Specific Information:
256 *
257 *  XXX document implementation including references if appropriate
258 */
259#define CPU_IDLE_TASK_IS_FP      FALSE
260
261/**
262 *  Should the saving of the floating point registers be deferred
263 *  until a context switch is made to another different floating point
264 *  task?
265 *
266 *  If TRUE, then the floating point context will not be stored until
267 *  necessary.  It will remain in the floating point registers and not
268 *  disturned until another floating point task is switched to.
269 *
270 *  If FALSE, then the floating point context is saved when a floating
271 *  point task is switched out and restored when the next floating point
272 *  task is restored.  The state of the floating point registers between
273 *  those two operations is not specified.
274 *
275 *  If the floating point context does NOT have to be saved as part of
276 *  interrupt dispatching, then it should be safe to set this to TRUE.
277 *
278 *  Setting this flag to TRUE results in using a different algorithm
279 *  for deciding when to save and restore the floating point context.
280 *  The deferred FP switch algorithm minimizes the number of times
281 *  the FP context is saved and restored.  The FP context is not saved
282 *  until a context switch is made to another, different FP task.
283 *  Thus in a system with only one FP task, the FP context will never
284 *  be saved or restored.
285 *
286 *  Port Specific Information:
287 *
288 *  XXX document implementation including references if appropriate
289 */
290#define CPU_USE_DEFERRED_FP_SWITCH       TRUE
291
292/**
293 *  Does this port provide a CPU dependent IDLE task implementation?
294 *
295 *  If TRUE, then the routine @ref _CPU_Thread_Idle_body
296 *  must be provided and is the default IDLE thread body instead of
297 *  @ref _CPU_Thread_Idle_body.
298 *
299 *  If FALSE, then use the generic IDLE thread body if the BSP does
300 *  not provide one.
301 *
302 *  This is intended to allow for supporting processors which have
303 *  a low power or idle mode.  When the IDLE thread is executed, then
304 *  the CPU can be powered down.
305 *
306 *  The order of precedence for selecting the IDLE thread body is:
307 *
308 *    -#  BSP provided
309 *    -#  CPU dependent (if provided)
310 *    -#  generic (if no BSP and no CPU dependent)
311 *
312 *  Port Specific Information:
313 *
314 *  XXX document implementation including references if appropriate
315 */
316#define CPU_PROVIDES_IDLE_THREAD_BODY    FALSE
317
318/**
319 *  Does the stack grow up (toward higher addresses) or down
320 *  (toward lower addresses)?
321 *
322 *  If TRUE, then the grows upward.
323 *  If FALSE, then the grows toward smaller addresses.
324 *
325 *  Port Specific Information:
326 *
327 *  XXX document implementation including references if appropriate
328 */
329#define CPU_STACK_GROWS_UP               TRUE
330
331/**
332 *  The following is the variable attribute used to force alignment
333 *  of critical RTEMS structures.  On some processors it may make
334 *  sense to have these aligned on tighter boundaries than
335 *  the minimum requirements of the compiler in order to have as
336 *  much of the critical data area as possible in a cache line.
337 *
338 *  The placement of this macro in the declaration of the variables
339 *  is based on the syntactically requirements of the GNU C
340 *  "__attribute__" extension.  For example with GNU C, use
341 *  the following to force a structures to a 32 byte boundary.
342 *
343 *      __attribute__ ((aligned (32)))
344 *
345 *  @note Currently only the Priority Bit Map table uses this feature.
346 *        To benefit from using this, the data must be heavily
347 *        used so it will stay in the cache and used frequently enough
348 *        in the executive to justify turning this on.
349 *
350 *  Port Specific Information:
351 *
352 *  XXX document implementation including references if appropriate
353 */
354#define CPU_STRUCTURE_ALIGNMENT
355
356#define CPU_TIMESTAMP_USE_STRUCT_TIMESPEC TRUE
357
358/**
359 *  @defgroup CPUEndian Processor Dependent Endianness Support
360 *
361 *  This group assists in issues related to processor endianness.
362 */
363
364/**
365 *  @ingroup CPUEndian
366 *  Define what is required to specify how the network to host conversion
367 *  routines are handled.
368 *
369 *  @note @a CPU_BIG_ENDIAN and @a CPU_LITTLE_ENDIAN should NOT have the
370 *  same values.
371 *
372 *  @see CPU_LITTLE_ENDIAN
373 *
374 *  Port Specific Information:
375 *
376 *  XXX document implementation including references if appropriate
377 */
378#define CPU_BIG_ENDIAN                           TRUE
379
380/**
381 *  @ingroup CPUEndian
382 *  Define what is required to specify how the network to host conversion
383 *  routines are handled.
384 *
385 *  @note @ref CPU_BIG_ENDIAN and @ref CPU_LITTLE_ENDIAN should NOT have the
386 *  same values.
387 *
388 *  @see CPU_BIG_ENDIAN
389 *
390 *  Port Specific Information:
391 *
392 *  XXX document implementation including references if appropriate
393 */
394#define CPU_LITTLE_ENDIAN                        FALSE
395
396/**
397 *  @ingroup CPUInterrupt
398 *  The following defines the number of bits actually used in the
399 *  interrupt field of the task mode.  How those bits map to the
400 *  CPU interrupt levels is defined by the routine @ref _CPU_ISR_Set_level.
401 *
402 *  Port Specific Information:
403 *
404 *  XXX document implementation including references if appropriate
405 */
406#define CPU_MODES_INTERRUPT_MASK   0x00000001
407
408/*
409 *  Processor defined structures required for cpukit/score.
410 *
411 *  Port Specific Information:
412 *
413 *  XXX document implementation including references if appropriate
414 */
415
416/* may need to put some structures here.  */
417
418/**
419 * @defgroup CPUContext Processor Dependent Context Management
420 *
421 *  From the highest level viewpoint, there are 2 types of context to save.
422 *
423 *     -# Interrupt registers to save
424 *     -# Task level registers to save
425 *
426 *  Since RTEMS handles integer and floating point contexts separately, this
427 *  means we have the following 3 context items:
428 *
429 *     -# task level context stuff::  Context_Control
430 *     -# floating point task stuff:: Context_Control_fp
431 *     -# special interrupt level context :: CPU_Interrupt_frame
432 *
433 *  On some processors, it is cost-effective to save only the callee
434 *  preserved registers during a task context switch.  This means
435 *  that the ISR code needs to save those registers which do not
436 *  persist across function calls.  It is not mandatory to make this
437 *  distinctions between the caller/callee saves registers for the
438 *  purpose of minimizing context saved during task switch and on interrupts.
439 *  If the cost of saving extra registers is minimal, simplicity is the
440 *  choice.  Save the same context on interrupt entry as for tasks in
441 *  this case.
442 *
443 *  Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
444 *  care should be used in designing the context area.
445 *
446 *  On some CPUs with hardware floating point support, the Context_Control_fp
447 *  structure will not be used or it simply consist of an array of a
448 *  fixed number of bytes.   This is done when the floating point context
449 *  is dumped by a "FP save context" type instruction and the format
450 *  is not really defined by the CPU.  In this case, there is no need
451 *  to figure out the exact format -- only the size.  Of course, although
452 *  this is enough information for RTEMS, it is probably not enough for
453 *  a debugger such as gdb.  But that is another problem.
454 *
455 *  Port Specific Information:
456 *
457 *  XXX document implementation including references if appropriate
458 */
459
460/**
461 *  @ingroup CPUContext Management
462 *  This defines the minimal set of integer and processor state registers
463 *  that must be saved during a voluntary context switch from one thread
464 *  to another.
465 */
466typedef struct {
467  /** r8 -- temporary register */
468  uint32_t r8;
469  /** r9 -- temporary register */
470  uint32_t r9;
471  /** r10 -- temporary register */
472  uint32_t r10;
473  /** r11 -- temporary register */
474  uint32_t r11;
475  /** r12 -- may be global pointer */
476  uint32_t r12;
477  /** r13 -- frame pointer */
478  uint32_t r13_fp;
479  /** r14 -- link register (aka return pointer */
480  uint32_t r14_lr;
481  /** r15 -- stack pointer */
482  uint32_t r15_sp;
483  /** dsp accumulator low order 32-bits */
484  uint32_t acc_low;
485  /** dsp accumulator high order 32-bits */
486  uint32_t acc_high;
487} Context_Control;
488
489/**
490 *  @ingroup CPUContext Management
491 *
492 *  This macro returns the stack pointer associated with @a _context.
493 *
494 *  @param[in] _context is the thread context area to access
495 *
496 *  @return This method returns the stack pointer.
497 */
498#define _CPU_Context_Get_SP( _context ) \
499  (_context)->r15_sp
500
501/**
502 *  @ingroup CPUContext Management
503 *  This defines the complete set of floating point registers that must
504 *  be saved during any context switch from one thread to another.
505 */
506typedef struct {
507    /** FPU registers are listed here */
508    double      some_float_register;
509} Context_Control_fp;
510
511/**
512 *  @ingroup CPUContext Management
513 *  This defines the set of integer and processor state registers that must
514 *  be saved during an interrupt.  This set does not include any which are
515 *  in @ref Context_Control.
516 */
517typedef struct {
518    /** This field is a hint that a port will have a number of integer
519     *  registers that need to be saved when an interrupt occurs or
520     *  when a context switch occurs at the end of an ISR.
521     */
522    uint32_t   special_interrupt_register;
523} CPU_Interrupt_frame;
524
525/**
526 *  This variable is optional.  It is used on CPUs on which it is difficult
527 *  to generate an "uninitialized" FP context.  It is filled in by
528 *  @ref _CPU_Initialize and copied into the task's FP context area during
529 *  @ref _CPU_Context_Initialize.
530 *
531 *  Port Specific Information:
532 *
533 *  XXX document implementation including references if appropriate
534 */
535SCORE_EXTERN Context_Control_fp  _CPU_Null_fp_context;
536
537/**
538 *  @defgroup CPUInterrupt Processor Dependent Interrupt Management
539 *
540 *  On some CPUs, RTEMS supports a software managed interrupt stack.
541 *  This stack is allocated by the Interrupt Manager and the switch
542 *  is performed in @ref _ISR_Handler.  These variables contain pointers
543 *  to the lowest and highest addresses in the chunk of memory allocated
544 *  for the interrupt stack.  Since it is unknown whether the stack
545 *  grows up or down (in general), this give the CPU dependent
546 *  code the option of picking the version it wants to use.
547 *
548 *  @note These two variables are required if the macro
549 *        @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK is defined as TRUE.
550 *
551 *  Port Specific Information:
552 *
553 *  XXX document implementation including references if appropriate
554 */
555
556/*
557 *  Nothing prevents the porter from declaring more CPU specific variables.
558 *
559 *  Port Specific Information:
560 *
561 *  XXX document implementation including references if appropriate
562 */
563
564/* XXX: if needed, put more variables here */
565
566/**
567 *  @ingroup CPUContext
568 *  The size of the floating point context area.  On some CPUs this
569 *  will not be a "sizeof" because the format of the floating point
570 *  area is not defined -- only the size is.  This is usually on
571 *  CPUs with a "floating point save context" instruction.
572 *
573 *  Port Specific Information:
574 *
575 *  XXX document implementation including references if appropriate
576 */
577#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
578
579/**
580 *  Amount of extra stack (above minimum stack size) required by
581 *  MPCI receive server thread.  Remember that in a multiprocessor
582 *  system this thread must exist and be able to process all directives.
583 *
584 *  Port Specific Information:
585 *
586 *  XXX document implementation including references if appropriate
587 */
588#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
589
590/**
591 *  @ingroup CPUInterrupt
592 *  This defines the number of entries in the @ref _ISR_Vector_table managed
593 *  by RTEMS.
594 *
595 *  Port Specific Information:
596 *
597 *  XXX document implementation including references if appropriate
598 */
599#define CPU_INTERRUPT_NUMBER_OF_VECTORS      32
600
601/**
602 *  @ingroup CPUInterrupt
603 *  This defines the highest interrupt vector number for this port.
604 */
605#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER  (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
606
607/**
608 *  @ingroup CPUInterrupt
609 *  This is defined if the port has a special way to report the ISR nesting
610 *  level.  Most ports maintain the variable @a _ISR_Nest_level.
611 */
612#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
613
614/**
615 *  @ingroup CPUContext
616 *  Should be large enough to run all RTEMS tests.  This ensures
617 *  that a "reasonable" small application should not have any problems.
618 *
619 *  Port Specific Information:
620 *
621 *  XXX document implementation including references if appropriate
622 */
623#define CPU_STACK_MINIMUM_SIZE          (1024)
624
625#define CPU_SIZEOF_POINTER 4
626
627/**
628 *  CPU's worst alignment requirement for data types on a byte boundary.  This
629 *  alignment does not take into account the requirements for the stack.
630 *
631 *  Port Specific Information:
632 *
633 *  XXX document implementation including references if appropriate
634 */
635#define CPU_ALIGNMENT              8
636
637/**
638 *  This number corresponds to the byte alignment requirement for the
639 *  heap handler.  This alignment requirement may be stricter than that
640 *  for the data types alignment specified by @ref CPU_ALIGNMENT.  It is
641 *  common for the heap to follow the same alignment requirement as
642 *  @ref CPU_ALIGNMENT.  If the @ref CPU_ALIGNMENT is strict enough for
643 *  the heap, then this should be set to @ref CPU_ALIGNMENT.
644 *
645 *  @note  This does not have to be a power of 2 although it should be
646 *         a multiple of 2 greater than or equal to 2.  The requirement
647 *         to be a multiple of 2 is because the heap uses the least
648 *         significant field of the front and back flags to indicate
649 *         that a block is in use or free.  So you do not want any odd
650 *         length blocks really putting length data in that bit.
651 *
652 *         On byte oriented architectures, @ref CPU_HEAP_ALIGNMENT normally will
653 *         have to be greater or equal to than @ref CPU_ALIGNMENT to ensure that
654 *         elements allocated from the heap meet all restrictions.
655 *
656 *  Port Specific Information:
657 *
658 *  XXX document implementation including references if appropriate
659 */
660#define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
661
662/**
663 *  This number corresponds to the byte alignment requirement for memory
664 *  buffers allocated by the partition manager.  This alignment requirement
665 *  may be stricter than that for the data types alignment specified by
666 *  @ref CPU_ALIGNMENT.  It is common for the partition to follow the same
667 *  alignment requirement as @ref CPU_ALIGNMENT.  If the @ref CPU_ALIGNMENT is
668 *  strict enough for the partition, then this should be set to
669 *  @ref CPU_ALIGNMENT.
670 *
671 *  @note  This does not have to be a power of 2.  It does have to
672 *         be greater or equal to than @ref CPU_ALIGNMENT.
673 *
674 *  Port Specific Information:
675 *
676 *  XXX document implementation including references if appropriate
677 */
678#define CPU_PARTITION_ALIGNMENT    CPU_ALIGNMENT
679
680/**
681 *  This number corresponds to the byte alignment requirement for the
682 *  stack.  This alignment requirement may be stricter than that for the
683 *  data types alignment specified by @ref CPU_ALIGNMENT.  If the
684 *  @ref CPU_ALIGNMENT is strict enough for the stack, then this should be
685 *  set to 0.
686 *
687 *  @note This must be a power of 2 either 0 or greater than @ref CPU_ALIGNMENT.
688 *
689 *  Port Specific Information:
690 *
691 *  XXX document implementation including references if appropriate
692 */
693#define CPU_STACK_ALIGNMENT        0
694
695/*
696 *  ISR handler macros
697 */
698
699/**
700 *  @ingroup CPUInterrupt
701 *  Support routine to initialize the RTEMS vector table after it is allocated.
702 *
703 *  Port Specific Information:
704 *
705 *  XXX document implementation including references if appropriate
706 */
707#define _CPU_Initialize_vectors()
708
709/**
710 *  @ingroup CPUInterrupt
711 *  Disable all interrupts for an RTEMS critical section.  The previous
712 *  level is returned in @a _isr_cookie.
713 *
714 *  @param[out] _isr_cookie will contain the previous level cookie
715 *
716 *  Port Specific Information:
717 *
718 *  XXX document implementation including references if appropriate
719 */
720#define _CPU_ISR_Disable( _isr_cookie ) \
721  { \
722    (_isr_cookie) = 0;   /* do something to prevent warnings */ \
723  }
724
725/**
726 *  @ingroup CPUInterrupt
727 *  Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
728 *  This indicates the end of an RTEMS critical section.  The parameter
729 *  @a _isr_cookie is not modified.
730 *
731 *  @param[in] _isr_cookie contain the previous level cookie
732 *
733 *  Port Specific Information:
734 *
735 *  XXX document implementation including references if appropriate
736 */
737#define _CPU_ISR_Enable( _isr_cookie )  \
738  { \
739    (_isr_cookie) = 0;   /* do something to prevent warnings */ \
740  }
741
742/**
743 *  @ingroup CPUInterrupt
744 *  This temporarily restores the interrupt to @a _isr_cookie before immediately
745 *  disabling them again.  This is used to divide long RTEMS critical
746 *  sections into two or more parts.  The parameter @a _isr_cookie is not
747 *  modified.
748 *
749 *  @param[in] _isr_cookie contain the previous level cookie
750 *
751 *  Port Specific Information:
752 *
753 *  XXX document implementation including references if appropriate
754 */
755#define _CPU_ISR_Flash( _isr_cookie ) \
756  { \
757  }
758
759/**
760 *  @ingroup CPUInterrupt
761 *
762 *  This routine and @ref _CPU_ISR_Get_level
763 *  Map the interrupt level in task mode onto the hardware that the CPU
764 *  actually provides.  Currently, interrupt levels which do not
765 *  map onto the CPU in a generic fashion are undefined.  Someday,
766 *  it would be nice if these were "mapped" by the application
767 *  via a callout.  For example, m68k has 8 levels 0 - 7, levels
768 *  8 - 255 would be available for bsp/application specific meaning.
769 *  This could be used to manage a programmable interrupt controller
770 *  via the rtems_task_mode directive.
771 *
772 *  Port Specific Information:
773 *
774 *  XXX document implementation including references if appropriate
775 */
776#define _CPU_ISR_Set_level( new_level ) \
777  { \
778  }
779
780/**
781 *  @ingroup CPUInterrupt
782 *  Return the current interrupt disable level for this task in
783 *  the format used by the interrupt level portion of the task mode.
784 *
785 *  @note This routine usually must be implemented as a subroutine.
786 *
787 *  Port Specific Information:
788 *
789 *  XXX document implementation including references if appropriate
790 */
791uint32_t   _CPU_ISR_Get_level( void );
792
793/* end of ISR handler macros */
794
795/* Context handler macros */
796
797/**
798 *  @ingroup CPUContext
799 *  Initialize the context to a state suitable for starting a
800 *  task after a context restore operation.  Generally, this
801 *  involves:
802 *
803 *     - setting a starting address
804 *     - preparing the stack
805 *     - preparing the stack and frame pointers
806 *     - setting the proper interrupt level in the context
807 *     - initializing the floating point context
808 *
809 *  This routine generally does not set any unnecessary register
810 *  in the context.  The state of the "general data" registers is
811 *  undefined at task start time.
812 *
813 *  @param[in] _the_context is the context structure to be initialized
814 *  @param[in] _stack_base is the lowest physical address of this task's stack
815 *  @param[in] _size is the size of this task's stack
816 *  @param[in] _isr is the interrupt disable level
817 *  @param[in] _entry_point is the thread's entry point.  This is
818 *         always @a _Thread_Handler
819 *  @param[in] _is_fp is TRUE if the thread is to be a floating
820 *        point thread.  This is typically only used on CPUs where the
821 *        FPU may be easily disabled by software such as on the SPARC
822 *        where the PSR contains an enable FPU bit.
823 *
824 *  Port Specific Information:
825 *
826 *  XXX document implementation including references if appropriate
827 */
828void _CPU_Context_Initialize(
829  Context_Control  *the_context,
830  uint32_t         *stack_base,
831  size_t            size,
832  uint32_t          new_level,
833  void             *entry_point,
834  bool              is_fp
835);
836
837/**
838 *  This routine is responsible for somehow restarting the currently
839 *  executing task.  If you are lucky, then all that is necessary
840 *  is restoring the context.  Otherwise, there will need to be
841 *  a special assembly routine which does something special in this
842 *  case.  For many ports, simply adding a label to the restore path
843 *  of @ref _CPU_Context_switch will work.  On other ports, it may be
844 *  possibly to load a few arguments and jump to the restore path. It will
845 *  not work if restarting self conflicts with the stack frame
846 *  assumptions of restoring a context.
847 *
848 *  Port Specific Information:
849 *
850 *  XXX document implementation including references if appropriate
851 */
852void _CPU_Context_Restart_self(
853  Context_Control  *the_context
854);
855
856/**
857 *  @ingroup CPUContext
858 *  The purpose of this macro is to allow the initial pointer into
859 *  a floating point context area (used to save the floating point
860 *  context) to be at an arbitrary place in the floating point
861 *  context area.
862 *
863 *  This is necessary because some FP units are designed to have
864 *  their context saved as a stack which grows into lower addresses.
865 *  Other FP units can be saved by simply moving registers into offsets
866 *  from the base of the context area.  Finally some FP units provide
867 *  a "dump context" instruction which could fill in from high to low
868 *  or low to high based on the whim of the CPU designers.
869 *
870 *  @param[in] _base is the lowest physical address of the floating point
871 *         context area
872 *  @param[in] _offset is the offset into the floating point area
873 *
874 *  Port Specific Information:
875 *
876 *  XXX document implementation including references if appropriate
877 */
878#define _CPU_Context_Fp_start( _base, _offset ) \
879   ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
880
881/**
882 *  This routine initializes the FP context area passed to it to.
883 *  There are a few standard ways in which to initialize the
884 *  floating point context.  The code included for this macro assumes
885 *  that this is a CPU in which a "initial" FP context was saved into
886 *  @a _CPU_Null_fp_context and it simply copies it to the destination
887 *  context passed to it.
888 *
889 *  Other floating point context save/restore models include:
890 *    -# not doing anything, and
891 *    -# putting a "null FP status word" in the correct place in the FP context.
892 *
893 *  @param[in] _destination is the floating point context area
894 *
895 *  Port Specific Information:
896 *
897 *  XXX document implementation including references if appropriate
898 */
899#define _CPU_Context_Initialize_fp( _destination ) \
900  { \
901   *(*(_destination)) = _CPU_Null_fp_context; \
902  }
903
904/* end of Context handler macros */
905
906/* Fatal Error manager macros */
907
908/**
909 *  This routine copies _error into a known place -- typically a stack
910 *  location or a register, optionally disables interrupts, and
911 *  halts/stops the CPU.
912 *
913 *  Port Specific Information:
914 *
915 *  XXX document implementation including references if appropriate
916 */
917#define _CPU_Fatal_halt( _error ) \
918  { \
919  }
920
921/* end of Fatal Error manager macros */
922
923/* Bitfield handler macros */
924
925/**
926 *  @defgroup CPUBitfield Processor Dependent Bitfield Manipulation
927 *
928 *  This set of routines are used to implement fast searches for
929 *  the most important ready task.
930 */
931
932/**
933 *  @ingroup CPUBitfield
934 *  This definition is set to TRUE if the port uses the generic bitfield
935 *  manipulation implementation.
936 */
937#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
938
939/**
940 *  @ingroup CPUBitfield
941 *  This definition is set to TRUE if the port uses the data tables provided
942 *  by the generic bitfield manipulation implementation.
943 *  This can occur when actually using the generic bitfield manipulation
944 *  implementation or when implementing the same algorithm in assembly
945 *  language for improved performance.  It is unlikely that a port will use
946 *  the data if it has a bitfield scan instruction.
947 */
948#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
949
950/**
951 *  @ingroup CPUBitfield
952 *  This routine sets @a _output to the bit number of the first bit
953 *  set in @a _value.  @a _value is of CPU dependent type
954 *  @a Priority_bit_map_Control.  This type may be either 16 or 32 bits
955 *  wide although only the 16 least significant bits will be used.
956 *
957 *  There are a number of variables in using a "find first bit" type
958 *  instruction.
959 *
960 *    -# What happens when run on a value of zero?
961 *    -# Bits may be numbered from MSB to LSB or vice-versa.
962 *    -# The numbering may be zero or one based.
963 *    -# The "find first bit" instruction may search from MSB or LSB.
964 *
965 *  RTEMS guarantees that (1) will never happen so it is not a concern.
966 *  (2),(3), (4) are handled by the macros @ref _CPU_Priority_Mask and
967 *  @ref _CPU_Priority_bits_index.  These three form a set of routines
968 *  which must logically operate together.  Bits in the _value are
969 *  set and cleared based on masks built by @ref _CPU_Priority_Mask.
970 *  The basic major and minor values calculated by @ref _Priority_Major
971 *  and @ref _Priority_Minor are "massaged" by @ref _CPU_Priority_bits_index
972 *  to properly range between the values returned by the "find first bit"
973 *  instruction.  This makes it possible for @ref _Priority_Get_highest to
974 *  calculate the major and directly index into the minor table.
975 *  This mapping is necessary to ensure that 0 (a high priority major/minor)
976 *  is the first bit found.
977 *
978 *  This entire "find first bit" and mapping process depends heavily
979 *  on the manner in which a priority is broken into a major and minor
980 *  components with the major being the 4 MSB of a priority and minor
981 *  the 4 LSB.  Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
982 *  priority.  And (15 << 4) + 14 corresponds to priority 254 -- the next
983 *  to the lowest priority.
984 *
985 *  If your CPU does not have a "find first bit" instruction, then
986 *  there are ways to make do without it.  Here are a handful of ways
987 *  to implement this in software:
988 *
989@verbatim
990      - a series of 16 bit test instructions
991      - a "binary search using if's"
992      - _number = 0
993        if _value > 0x00ff
994          _value >>=8
995          _number = 8;
996
997        if _value > 0x0000f
998          _value >=8
999          _number += 4
1000
1001        _number += bit_set_table[ _value ]
1002@endverbatim
1003
1004 *    where bit_set_table[ 16 ] has values which indicate the first
1005 *      bit set
1006 *
1007 *  @param[in] _value is the value to be scanned
1008 *  @param[in] _output is the first bit set
1009 *
1010 *  Port Specific Information:
1011 *
1012 *  XXX document implementation including references if appropriate
1013 */
1014
1015#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
1016#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
1017  { \
1018    (_output) = 0;   /* do something to prevent warnings */ \
1019  }
1020#endif
1021
1022/* end of Bitfield handler macros */
1023
1024/**
1025 *  This routine builds the mask which corresponds to the bit fields
1026 *  as searched by @ref _CPU_Bitfield_Find_first_bit.  See the discussion
1027 *  for that routine.
1028 *
1029 *  Port Specific Information:
1030 *
1031 *  XXX document implementation including references if appropriate
1032 */
1033#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
1034
1035#define _CPU_Priority_Mask( _bit_number ) \
1036  ( 1 << (_bit_number) )
1037
1038#endif
1039
1040/**
1041 *  @ingroup CPUBitfield
1042 *  This routine translates the bit numbers returned by
1043 *  @ref _CPU_Bitfield_Find_first_bit into something suitable for use as
1044 *  a major or minor component of a priority.  See the discussion
1045 *  for that routine.
1046 *
1047 *  @param[in] _priority is the major or minor number to translate
1048 *
1049 *  Port Specific Information:
1050 *
1051 *  XXX document implementation including references if appropriate
1052 */
1053#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
1054
1055#define _CPU_Priority_bits_index( _priority ) \
1056  (_priority)
1057
1058#endif
1059
1060/* end of Priority handler macros */
1061
1062/* functions */
1063
1064/**
1065 *  This routine performs CPU dependent initialization.
1066 *
1067 *  Port Specific Information:
1068 *
1069 *  XXX document implementation including references if appropriate
1070 */
1071void _CPU_Initialize(void);
1072
1073/**
1074 *  @ingroup CPUInterrupt
1075 *  This routine installs a "raw" interrupt handler directly into the
1076 *  processor's vector table.
1077 *
1078 *  @param[in] vector is the vector number
1079 *  @param[in] new_handler is the raw ISR handler to install
1080 *  @param[in] old_handler is the previously installed ISR Handler
1081 *
1082 *  Port Specific Information:
1083 *
1084 *  XXX document implementation including references if appropriate
1085 */
1086void _CPU_ISR_install_raw_handler(
1087  uint32_t    vector,
1088  proc_ptr    new_handler,
1089  proc_ptr   *old_handler
1090);
1091
1092/**
1093 *  @ingroup CPUInterrupt
1094 *  This routine installs an interrupt vector.
1095 *
1096 *  @param[in] vector is the vector number
1097 *  @param[in] new_handler is the RTEMS ISR handler to install
1098 *  @param[in] old_handler is the previously installed ISR Handler
1099 *
1100 *  Port Specific Information:
1101 *
1102 *  XXX document implementation including references if appropriate
1103 */
1104void _CPU_ISR_install_vector(
1105  uint32_t    vector,
1106  proc_ptr    new_handler,
1107  proc_ptr   *old_handler
1108);
1109
1110/**
1111 *  @ingroup CPUInterrupt
1112 *  This routine installs the hardware interrupt stack pointer.
1113 *
1114 *  @note  It need only be provided if @ref CPU_HAS_HARDWARE_INTERRUPT_STACK
1115 *         is TRUE.
1116 *
1117 *  Port Specific Information:
1118 *
1119 *  XXX document implementation including references if appropriate
1120 */
1121void _CPU_Install_interrupt_stack( void );
1122
1123/**
1124 *  @ingroup CPUContext
1125 *  This routine switches from the run context to the heir context.
1126 *
1127 *  @param[in] run points to the context of the currently executing task
1128 *  @param[in] heir points to the context of the heir task
1129 *
1130 *  Port Specific Information:
1131 *
1132 *  XXX document implementation including references if appropriate
1133 */
1134void _CPU_Context_switch(
1135  Context_Control  *run,
1136  Context_Control  *heir
1137);
1138
1139/**
1140 *  @ingroup CPUContext
1141 *  This routine is generally used only to restart self in an
1142 *  efficient manner.  It may simply be a label in @ref _CPU_Context_switch.
1143 *
1144 *  @param[in] new_context points to the context to be restored.
1145 *
1146 *  @note May be unnecessary to reload some registers.
1147 *
1148 *  Port Specific Information:
1149 *
1150 *  XXX document implementation including references if appropriate
1151 */
1152void _CPU_Context_restore(
1153  Context_Control *new_context
1154) RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
1155
1156/**
1157 *  @ingroup CPUContext
1158 *  This routine saves the floating point context passed to it.
1159 *
1160 *  @param[in] fp_context_ptr is a pointer to a pointer to a floating
1161 *  point context area
1162 *
1163 *  @return on output @a *fp_context_ptr will contain the address that
1164 *  should be used with @ref _CPU_Context_restore_fp to restore this context.
1165 *
1166 *  Port Specific Information:
1167 *
1168 *  XXX document implementation including references if appropriate
1169 */
1170void _CPU_Context_save_fp(
1171  Context_Control_fp **fp_context_ptr
1172);
1173
1174/**
1175 *  @ingroup CPUContext
1176 *  This routine restores the floating point context passed to it.
1177 *
1178 *  @param[in] fp_context_ptr is a pointer to a pointer to a floating
1179 *  point context area to restore
1180 *
1181 *  @return on output @a *fp_context_ptr will contain the address that
1182 *  should be used with @ref _CPU_Context_save_fp to save this context.
1183 *
1184 *  Port Specific Information:
1185 *
1186 *  XXX document implementation including references if appropriate
1187 */
1188void _CPU_Context_restore_fp(
1189  Context_Control_fp **fp_context_ptr
1190);
1191
1192/* FIXME */
1193typedef CPU_Interrupt_frame CPU_Exception_frame;
1194
1195void _CPU_Exception_frame_print( const CPU_Exception_frame *frame );
1196
1197/**
1198 *  @ingroup CPUEndian
1199 *  The following routine swaps the endian format of an unsigned int.
1200 *  It must be static because it is referenced indirectly.
1201 *
1202 *  This version will work on any processor, but if there is a better
1203 *  way for your CPU PLEASE use it.  The most common way to do this is to:
1204 *
1205 *     swap least significant two bytes with 16-bit rotate
1206 *     swap upper and lower 16-bits
1207 *     swap most significant two bytes with 16-bit rotate
1208 *
1209 *  Some CPUs have special instructions which swap a 32-bit quantity in
1210 *  a single instruction (e.g. i486).  It is probably best to avoid
1211 *  an "endian swapping control bit" in the CPU.  One good reason is
1212 *  that interrupts would probably have to be disabled to ensure that
1213 *  an interrupt does not try to access the same "chunk" with the wrong
1214 *  endian.  Another good reason is that on some CPUs, the endian bit
1215 *  endianness for ALL fetches -- both code and data -- so the code
1216 *  will be fetched incorrectly.
1217 *
1218 *  @param[in] value is the value to be swapped
1219 *  @return the value after being endian swapped
1220 *
1221 *  Port Specific Information:
1222 *
1223 *  XXX document implementation including references if appropriate
1224 */
1225static inline uint32_t CPU_swap_u32(
1226  uint32_t value
1227)
1228{
1229  uint32_t byte1, byte2, byte3, byte4, swapped;
1230
1231  byte4 = (value >> 24) & 0xff;
1232  byte3 = (value >> 16) & 0xff;
1233  byte2 = (value >> 8)  & 0xff;
1234  byte1 =  value        & 0xff;
1235
1236  swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
1237  return swapped;
1238}
1239
1240/**
1241 *  @ingroup CPUEndian
1242 *  This routine swaps a 16 bir quantity.
1243 *
1244 *  @param[in] value is the value to be swapped
1245 *  @return the value after being endian swapped
1246 */
1247#define CPU_swap_u16( value ) \
1248  (((value&0xff) << 8) | ((value >> 8)&0xff))
1249
1250#ifdef __cplusplus
1251}
1252#endif
1253
1254#endif
Note: See TracBrowser for help on using the repository browser.