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