source: rtems/cpukit/score/cpu/m32c/rtems/score/cpu.h @ c03e2bc

4.104.115
Last change on this file since c03e2bc was c03e2bc, checked in by Joel Sherrill <joel.sherrill@…>, on 02/11/09 at 21:45:05

2009-02-11 Joel Sherrill <joel.sherrill@…>

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