source: rtems/cpukit/score/cpu/m32c/rtems/score/cpu.h @ 8ac3549

4.115
Last change on this file since 8ac3549 was 8ac3549, checked in by Sebastian Huber <sebastian.huber@…>, on 03/04/15 at 15:13:49

score: Delete unused CPU_UNROLL_ENQUEUE_PRIORITY

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