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

5
Last change on this file since ec5d7f92 was ec5d7f92, checked in by Sebastian Huber <sebastian.huber@…>, on 06/07/16 at 20:09:01

score: Delete dead copy and paste code

  • Property mode set to 100644
File size: 32.8 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/* FIXME: Is this the right value? */
315#define CPU_CACHE_LINE_BYTES 2
316
317#define CPU_STRUCTURE_ALIGNMENT RTEMS_ALIGNED( CPU_CACHE_LINE_BYTES )
318
319/**
320 * @defgroup CPUEndian Processor Dependent Endianness Support
321 *
322 * This group assists in issues related to processor endianness.
323 *
324 */
325/**@{**/
326
327/**
328 * Define what is required to specify how the network to host conversion
329 * routines are handled.
330 *
331 * NOTE: @a CPU_BIG_ENDIAN and @a CPU_LITTLE_ENDIAN should NOT have the
332 * same values.
333 *
334 * @see CPU_LITTLE_ENDIAN
335 *
336 * Port Specific Information:
337 *
338 * XXX document implementation including references if appropriate
339 */
340#define CPU_BIG_ENDIAN                           TRUE
341
342/**
343 * Define what is required to specify how the network to host conversion
344 * routines are handled.
345 *
346 * NOTE: @ref CPU_BIG_ENDIAN and @ref CPU_LITTLE_ENDIAN should NOT have the
347 * same values.
348 *
349 * @see CPU_BIG_ENDIAN
350 *
351 * Port Specific Information:
352 *
353 * XXX document implementation including references if appropriate
354 */
355#define CPU_LITTLE_ENDIAN                        FALSE
356
357/** @} */
358
359/**
360 * @ingroup CPUInterrupt
361 *
362 * The following defines the number of bits actually used in the
363 * interrupt field of the task mode.  How those bits map to the
364 * CPU interrupt levels is defined by the routine @ref _CPU_ISR_Set_level.
365 *
366 * Port Specific Information:
367 *
368 * XXX document implementation including references if appropriate
369 */
370#define CPU_MODES_INTERRUPT_MASK   0x00000001
371
372#define CPU_PER_CPU_CONTROL_SIZE 0
373
374#define CPU_MAXIMUM_PROCESSORS 32
375
376/*
377 *  Processor defined structures required for cpukit/score.
378 *
379 *  Port Specific Information:
380 *
381 *  XXX document implementation including references if appropriate
382 */
383
384/* may need to put some structures here.  */
385
386typedef struct {
387  /* There is no CPU specific per-CPU state */
388} CPU_Per_CPU_control;
389
390/**
391 * @defgroup CPUContext Processor Dependent Context Management
392 *
393 * From the highest level viewpoint, there are 2 types of context to save.
394 *
395 *    -# Interrupt registers to save
396 *    -# Task level registers to save
397 *
398 * Since RTEMS handles integer and floating point contexts separately, this
399 * means we have the following 3 context items:
400 *
401 *    -# task level context stuff::  Context_Control
402 *    -# floating point task stuff:: Context_Control_fp
403 *    -# special interrupt level context :: CPU_Interrupt_frame
404 *
405 * On some processors, it is cost-effective to save only the callee
406 * preserved registers during a task context switch.  This means
407 * that the ISR code needs to save those registers which do not
408 * persist across function calls.  It is not mandatory to make this
409 * distinctions between the caller/callee saves registers for the
410 * purpose of minimizing context saved during task switch and on interrupts.
411 * If the cost of saving extra registers is minimal, simplicity is the
412 * choice.  Save the same context on interrupt entry as for tasks in
413 * this case.
414 *
415 * Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
416 * care should be used in designing the context area.
417 *
418 * On some CPUs with hardware floating point support, the Context_Control_fp
419 * structure will not be used or it simply consist of an array of a
420 * fixed number of bytes.   This is done when the floating point context
421 * is dumped by a "FP save context" type instruction and the format
422 * is not really defined by the CPU.  In this case, there is no need
423 * to figure out the exact format -- only the size.  Of course, although
424 * this is enough information for RTEMS, it is probably not enough for
425 * a debugger such as gdb.  But that is another problem.
426 *
427 * Port Specific Information:
428 *
429 * XXX document implementation including references if appropriate
430 */
431/**@{**/
432
433/**
434 * @ingroup Management
435 *
436 * This defines the minimal set of integer and processor state registers
437 * that must be saved during a voluntary context switch from one thread
438 * to another.
439 */
440typedef struct {
441  /** This will contain the stack pointer. */
442  uint32_t sp;
443  /** This will contain the frame base pointer. */
444  uint32_t fb;
445} Context_Control;
446
447/**
448 * @ingroup Management
449 *
450 * This macro returns the stack pointer associated with @a _context.
451 *
452 * @param[in] _context is the thread context area to access
453 *
454 * @return This method returns the stack pointer.
455 */
456#define _CPU_Context_Get_SP( _context ) \
457  (_context)->sp
458
459/**
460 * @ingroup Management
461 *
462 * This defines the set of integer and processor state registers that must
463 * be saved during an interrupt.  This set does not include any which are
464 * in @ref Context_Control.
465 */
466typedef struct {
467    /**
468     * This field is a hint that a port will have a number of integer
469     * registers that need to be saved when an interrupt occurs or
470     * when a context switch occurs at the end of an ISR.
471     */
472    uint32_t   special_interrupt_register;
473} CPU_Interrupt_frame;
474
475/** @} */
476
477/**
478 * @defgroup CPUInterrupt Processor Dependent Interrupt Management
479 *
480 * On some CPUs, RTEMS supports a software managed interrupt stack.
481 * This stack is allocated by the Interrupt Manager and the switch
482 * is performed in @ref _ISR_Handler.  These variables contain pointers
483 * to the lowest and highest addresses in the chunk of memory allocated
484 * for the interrupt stack.  Since it is unknown whether the stack
485 * grows up or down (in general), this give the CPU dependent
486 * code the option of picking the version it wants to use.
487 *
488 * NOTE: These two variables are required if the macro
489 *       @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK is defined as TRUE.
490 *
491 * Port Specific Information:
492 *
493 * XXX document implementation including references if appropriate
494 *
495 */
496/**@{**/
497
498/*
499 *  Nothing prevents the porter from declaring more CPU specific variables.
500 *
501 *  Port Specific Information:
502 *
503 *  XXX document implementation including references if appropriate
504 */
505
506/* XXX: if needed, put more variables here */
507
508/**
509 * Amount of extra stack (above minimum stack size) required by
510 * MPCI receive server thread.  Remember that in a multiprocessor
511 * system this thread must exist and be able to process all directives.
512 *
513 * Port Specific Information:
514 *
515 * XXX document implementation including references if appropriate
516 */
517#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
518
519/**
520 * This defines the number of entries in the @ref _ISR_Vector_table managed
521 * by RTEMS.
522 *
523 * Port Specific Information:
524 *
525 * XXX document implementation including references if appropriate
526 */
527#define CPU_INTERRUPT_NUMBER_OF_VECTORS      32
528
529/** This defines the highest interrupt vector number for this port. */
530#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER  (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
531
532/**
533 * This is defined if the port has a special way to report the ISR nesting
534 * level.  Most ports maintain the variable @a _ISR_Nest_level.
535 */
536#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
537
538/** @} */
539
540/**
541 * @ingroup CPUContext
542 *
543 * Should be large enough to run all RTEMS tests.  This ensures
544 * that a "reasonable" small application should not have any problems.
545 *
546 * Port Specific Information:
547 *
548 * XXX document implementation including references if appropriate
549 */
550#define CPU_STACK_MINIMUM_SIZE          (2048L)
551
552#ifdef __m32cm_cpu__
553  #define CPU_SIZEOF_POINTER 4
554#else
555  #define CPU_SIZEOF_POINTER 2
556#endif
557
558/**
559 * CPU's worst alignment requirement for data types on a byte boundary.  This
560 * alignment does not take into account the requirements for the stack.
561 *
562 * Port Specific Information:
563 *
564 * XXX document implementation including references if appropriate
565 */
566#define CPU_ALIGNMENT              2
567
568/**
569 * This number corresponds to the byte alignment requirement for the
570 * heap handler.  This alignment requirement may be stricter than that
571 * for the data types alignment specified by @ref CPU_ALIGNMENT.  It is
572 * common for the heap to follow the same alignment requirement as
573 * @ref CPU_ALIGNMENT.  If the @ref CPU_ALIGNMENT is strict enough for
574 * the heap, then this should be set to @ref CPU_ALIGNMENT.
575 *
576 * NOTE:  This does not have to be a power of 2 although it should be
577 *        a multiple of 2 greater than or equal to 2.  The requirement
578 *        to be a multiple of 2 is because the heap uses the least
579 *        significant field of the front and back flags to indicate
580 *        that a block is in use or free.  So you do not want any odd
581 *        length blocks really putting length data in that bit.
582 *
583 *        On byte oriented architectures, @ref CPU_HEAP_ALIGNMENT normally will
584 *        have to be greater or equal to than @ref CPU_ALIGNMENT to ensure that
585 *        elements allocated from the heap meet all restrictions.
586 *
587 * Port Specific Information:
588 *
589 * XXX document implementation including references if appropriate
590 */
591#define CPU_HEAP_ALIGNMENT         4
592
593/**
594 * This number corresponds to the byte alignment requirement for memory
595 * buffers allocated by the partition manager.  This alignment requirement
596 * may be stricter than that for the data types alignment specified by
597 * @ref CPU_ALIGNMENT.  It is common for the partition to follow the same
598 * alignment requirement as @ref CPU_ALIGNMENT.  If the @ref CPU_ALIGNMENT is
599 * strict enough for the partition, then this should be set to
600 * @ref CPU_ALIGNMENT.
601 *
602 * NOTE:  This does not have to be a power of 2.  It does have to
603 *        be greater or equal to than @ref CPU_ALIGNMENT.
604 *
605 * Port Specific Information:
606 *
607 * XXX document implementation including references if appropriate
608 */
609#define CPU_PARTITION_ALIGNMENT    CPU_ALIGNMENT
610
611/**
612 * This number corresponds to the byte alignment requirement for the
613 * stack.  This alignment requirement may be stricter than that for the
614 * data types alignment specified by @ref CPU_ALIGNMENT.  If the
615 * @ref CPU_ALIGNMENT is strict enough for the stack, then this should be
616 * set to 0.
617 *
618 * NOTE: This must be a power of 2 either 0 or greater than @ref CPU_ALIGNMENT.
619 *
620 * Port Specific Information:
621 *
622 * XXX document implementation including references if appropriate
623 */
624#define CPU_STACK_ALIGNMENT        0
625
626/*
627 *  ISR handler macros
628 */
629
630/**
631 * @ingroup CPUInterrupt
632 *
633 * Support routine to initialize the RTEMS vector table after it is allocated.
634 *
635 * Port Specific Information:
636 *
637 * XXX document implementation including references if appropriate
638 */
639#define _CPU_Initialize_vectors()
640
641/**
642 * @ingroup CPUInterrupt
643 *
644 * Disable all interrupts for an RTEMS critical section.  The previous
645 * level is returned in @a _isr_cookie.
646 *
647 * @param[out] _isr_cookie will contain the previous level cookie
648 *
649 * Port Specific Information:
650 *
651 * XXX document implementation including references if appropriate
652 */
653#define _CPU_ISR_Disable( _isr_cookie ) \
654  do { \
655    int _flg; \
656    m32c_get_flg( _flg ); \
657    _isr_cookie = _flg; \
658    __asm__ volatile( "fclr I" ); \
659  } while(0)
660
661/**
662 * @ingroup CPUInterrupt
663 *
664 * Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
665 * This indicates the end of an RTEMS critical section.  The parameter
666 * @a _isr_cookie is not modified.
667 *
668 * @param[in] _isr_cookie contain the previous level cookie
669 *
670 * Port Specific Information:
671 *
672 * XXX document implementation including references if appropriate
673 */
674#define _CPU_ISR_Enable(_isr_cookie) \
675  do { \
676    int _flg = (int) (_isr_cookie); \
677    m32c_set_flg( _flg ); \
678  } while(0)
679
680/**
681 * @ingroup CPUInterrupt
682 *
683 * This temporarily restores the interrupt to @a _isr_cookie before immediately
684 * disabling them again.  This is used to divide long RTEMS critical
685 * sections into two or more parts.  The parameter @a _isr_cookie is not
686 * 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_Flash( _isr_cookie ) \
695  do { \
696    int _flg = (int) (_isr_cookie); \
697    m32c_set_flg( _flg ); \
698    __asm__ volatile( "fclr I" ); \
699  } while(0)
700
701/**
702 * @ingroup CPUInterrupt
703 *
704 * This routine and @ref _CPU_ISR_Get_level
705 * Map the interrupt level in task mode onto the hardware that the CPU
706 * actually provides.  Currently, interrupt levels which do not
707 * map onto the CPU in a generic fashion are undefined.  Someday,
708 * it would be nice if these were "mapped" by the application
709 * via a callout.  For example, m68k has 8 levels 0 - 7, levels
710 * 8 - 255 would be available for bsp/application specific meaning.
711 *This could be used to manage a programmable interrupt controller
712 * via the rtems_task_mode directive.
713 *
714 * Port Specific Information:
715 *
716 * XXX document implementation including references if appropriate
717 */
718#define _CPU_ISR_Set_level( _new_level ) \
719  do { \
720    if (_new_level) __asm__ volatile( "fclr I" ); \
721    else            __asm__ volatile( "fset I" ); \
722  } while(0)
723
724/**
725 * @ingroup CPUInterrupt
726 *
727 * Return the current interrupt disable level for this task in
728 * the format used by the interrupt level portion of the task mode.
729 *
730 * NOTE: This routine usually must be implemented as a subroutine.
731 *
732 * Port Specific Information:
733 *
734 * XXX document implementation including references if appropriate
735 */
736uint32_t   _CPU_ISR_Get_level( void );
737
738/* end of ISR handler macros */
739
740/* Context handler macros */
741
742/**
743 * @ingroup CPUContext
744 *
745 * Initialize the context to a state suitable for starting a
746 * task after a context restore operation.  Generally, this
747 * involves:
748 *
749 *    - setting a starting address
750 *    - preparing the stack
751 *    - preparing the stack and frame pointers
752 *    - setting the proper interrupt level in the context
753 *    - initializing the floating point context
754 *
755 * This routine generally does not set any unnecessary register
756 * in the context.  The state of the "general data" registers is
757 * undefined at task start time.
758 *
759 * @param[in] _the_context is the context structure to be initialized
760 * @param[in] _stack_base is the lowest physical address of this task's stack
761 * @param[in] _size is the size of this task's stack
762 * @param[in] _isr is the interrupt disable level
763 * @param[in] _entry_point is the thread's entry point.  This is
764 *        always @a _Thread_Handler
765 * @param[in] _is_fp is TRUE if the thread is to be a floating
766 *       point thread.  This is typically only used on CPUs where the
767 *       FPU may be easily disabled by software such as on the SPARC
768 *       where the PSR contains an enable FPU bit.
769 * @param[in] tls_area is the thread-local storage (TLS) area
770 *
771 * Port Specific Information:
772 *
773 * XXX document implementation including references if appropriate
774 */
775void _CPU_Context_Initialize(
776  Context_Control  *the_context,
777  uint32_t         *stack_base,
778  size_t            size,
779  uint32_t          new_level,
780  void             *entry_point,
781  bool              is_fp,
782  void             *tls_area
783);
784
785/**
786 * This routine is responsible for somehow restarting the currently
787 * executing task.  If you are lucky, then all that is necessary
788 * is restoring the context.  Otherwise, there will need to be
789 * a special assembly routine which does something special in this
790 * case.  For many ports, simply adding a label to the restore path
791 * of @ref _CPU_Context_switch will work.  On other ports, it may be
792 * possibly to load a few arguments and jump to the restore path. It will
793 * not work if restarting self conflicts with the stack frame
794 * assumptions of restoring a context.
795 *
796 * Port Specific Information:
797 *
798 * XXX document implementation including references if appropriate
799 */
800void _CPU_Context_Restart_self(
801  Context_Control  *the_context
802) RTEMS_NO_RETURN;
803
804/**
805 * @ingroup CPUContext
806 *
807 * The purpose of this macro is to allow the initial pointer into
808 * a floating point context area (used to save the floating point
809 * context) to be at an arbitrary place in the floating point
810 * context area.
811 *
812 * This is necessary because some FP units are designed to have
813 * their context saved as a stack which grows into lower addresses.
814 * Other FP units can be saved by simply moving registers into offsets
815 * from the base of the context area.  Finally some FP units provide
816 * a "dump context" instruction which could fill in from high to low
817 * or low to high based on the whim of the CPU designers.
818 *
819 * @param[in] _base is the lowest physical address of the floating point
820 *        context area
821 * @param[in] _offset is the offset into the floating point area
822 *
823 * Port Specific Information:
824 *
825 * XXX document implementation including references if appropriate
826 */
827#define _CPU_Context_Fp_start( _base, _offset ) \
828   ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
829
830/**
831 * This routine initializes the FP context area passed to it to.
832 * There are a few standard ways in which to initialize the
833 * floating point context.  The code included for this macro assumes
834 * that this is a CPU in which a "initial" FP context was saved into
835 * @a _CPU_Null_fp_context and it simply copies it to the destination
836 * context passed to it.
837 *
838 * Other floating point context save/restore models include:
839 *   -# not doing anything, and
840 *   -# putting a "null FP status word" in the correct place in the FP context.
841 *
842 * @param[in] _destination is the floating point context area
843 *
844 * Port Specific Information:
845 *
846 * XXX document implementation including references if appropriate
847 */
848#define _CPU_Context_Initialize_fp( _destination ) \
849  { \
850   *(*(_destination)) = _CPU_Null_fp_context; \
851  }
852
853/* end of Context handler macros */
854
855/* Fatal Error manager macros */
856
857/**
858 * This routine copies _error into a known place -- typically a stack
859 * location or a register, optionally disables interrupts, and
860 * halts/stops the CPU.
861 *
862 * Port Specific Information:
863 *
864 * XXX document implementation including references if appropriate
865 */
866#define _CPU_Fatal_halt( _source, _error ) \
867  { \
868  }
869
870/* end of Fatal Error manager macros */
871
872#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
873
874#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
875
876/* functions */
877
878/**
879 * This routine performs CPU dependent initialization.
880 *
881 * Port Specific Information:
882 *
883 * XXX document implementation including references if appropriate
884 */
885void _CPU_Initialize(void);
886
887/**
888 * @ingroup CPUInterrupt
889 *
890 * This routine installs a "raw" interrupt handler directly into the
891 * processor's vector table.
892 *
893 * @param[in] vector is the vector number
894 * @param[in] new_handler is the raw ISR handler to install
895 * @param[in] old_handler is the previously installed ISR Handler
896 *
897 * Port Specific Information:
898 *
899 * XXX document implementation including references if appropriate
900 */
901void _CPU_ISR_install_raw_handler(
902  uint32_t    vector,
903  proc_ptr    new_handler,
904  proc_ptr   *old_handler
905);
906
907/**
908 * @ingroup CPUInterrupt
909 *
910 * This routine installs an interrupt vector.
911 *
912 * @param[in] vector is the vector number
913 * @param[in] new_handler is the RTEMS ISR handler to install
914 * @param[in] old_handler is the previously installed ISR Handler
915 *
916 * Port Specific Information:
917 *
918 * XXX document implementation including references if appropriate
919 */
920void _CPU_ISR_install_vector(
921  uint32_t    vector,
922  proc_ptr    new_handler,
923  proc_ptr   *old_handler
924);
925
926/**
927 * @ingroup CPUInterrupt
928 *
929 * This routine installs the hardware interrupt stack pointer.
930 *
931 * NOTE:  It need only be provided if @ref CPU_HAS_HARDWARE_INTERRUPT_STACK
932 *        is TRUE.
933 *
934 * Port Specific Information:
935 *
936 * XXX document implementation including references if appropriate
937 */
938void _CPU_Install_interrupt_stack( void );
939
940/**
941 * This routine is the CPU dependent IDLE thread body.
942 *
943 * NOTE:  It need only be provided if @ref CPU_PROVIDES_IDLE_THREAD_BODY
944 *        is TRUE.
945 *
946 * Port Specific Information:
947 *
948 * XXX document implementation including references if appropriate
949 */
950void *_CPU_Thread_Idle_body( uintptr_t ignored );
951
952/**
953 * @ingroup CPUContext
954 *
955 * This routine switches from the run context to the heir context.
956 *
957 * @param[in] run points to the context of the currently executing task
958 * @param[in] heir points to the context of the heir task
959 *
960 * Port Specific Information:
961 *
962 * XXX document implementation including references if appropriate
963 */
964void _CPU_Context_switch(
965  Context_Control  *run,
966  Context_Control  *heir
967);
968
969/**
970 * @ingroup CPUContext
971 *
972 * This routine is generally used only to restart self in an
973 * efficient manner.  It may simply be a label in @ref _CPU_Context_switch.
974 *
975 * @param[in] new_context points to the context to be restored.
976 *
977 * NOTE: May be unnecessary to reload some registers.
978 *
979 * Port Specific Information:
980 *
981 * XXX document implementation including references if appropriate
982 */
983void _CPU_Context_restore(
984  Context_Control *new_context
985) RTEMS_NO_RETURN;
986
987static inline void _CPU_Context_volatile_clobber( uintptr_t pattern )
988{
989  /* TODO */
990}
991
992static inline void _CPU_Context_validate( uintptr_t pattern )
993{
994  while (1) {
995    /* TODO */
996  }
997}
998
999/* FIXME */
1000typedef CPU_Interrupt_frame CPU_Exception_frame;
1001
1002void _CPU_Exception_frame_print( const CPU_Exception_frame *frame );
1003
1004/**
1005 * @ingroup CPUEndian
1006 *
1007 * The following routine swaps the endian format of an unsigned int.
1008 * It must be static because it is referenced indirectly.
1009 *
1010 * This version will work on any processor, but if there is a better
1011 * way for your CPU PLEASE use it.  The most common way to do this is to:
1012 *
1013 *    swap least significant two bytes with 16-bit rotate
1014 *    swap upper and lower 16-bits
1015 *    swap most significant two bytes with 16-bit rotate
1016 *
1017 * Some CPUs have special instructions which swap a 32-bit quantity in
1018 * a single instruction (e.g. i486).  It is probably best to avoid
1019 * an "endian swapping control bit" in the CPU.  One good reason is
1020 * that interrupts would probably have to be disabled to ensure that
1021 * an interrupt does not try to access the same "chunk" with the wrong
1022 * endian.  Another good reason is that on some CPUs, the endian bit
1023 * endianness for ALL fetches -- both code and data -- so the code
1024 * will be fetched incorrectly.
1025 *
1026 * @param[in] value is the value to be swapped
1027 * @return the value after being endian swapped
1028 *
1029 * Port Specific Information:
1030 *
1031 * XXX document implementation including references if appropriate
1032 */
1033static inline uint32_t CPU_swap_u32(
1034  uint32_t value
1035)
1036{
1037  uint32_t byte1, byte2, byte3, byte4, swapped;
1038
1039  byte4 = (value >> 24) & 0xff;
1040  byte3 = (value >> 16) & 0xff;
1041  byte2 = (value >> 8)  & 0xff;
1042  byte1 =  value        & 0xff;
1043
1044  swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
1045  return swapped;
1046}
1047
1048/**
1049 * @ingroup CPUEndian
1050 *
1051 * This routine swaps a 16 bir quantity.
1052 *
1053 * @param[in] value is the value to be swapped
1054 * @return the value after being endian swapped
1055 */
1056#define CPU_swap_u16( value ) \
1057  (((value&0xff) << 8) | ((value >> 8)&0xff))
1058
1059typedef uint32_t CPU_Counter_ticks;
1060
1061CPU_Counter_ticks _CPU_Counter_read( void );
1062
1063static inline CPU_Counter_ticks _CPU_Counter_difference(
1064  CPU_Counter_ticks second,
1065  CPU_Counter_ticks first
1066)
1067{
1068  return second - first;
1069}
1070
1071#ifdef __cplusplus
1072}
1073#endif
1074
1075#endif
Note: See TracBrowser for help on using the repository browser.