source: rtems/cpukit/score/cpu/lm32/include/rtems/score/cpu.h @ c8df844

5
Last change on this file since c8df844 was c8df844, checked in by Sebastian Huber <sebastian.huber@…>, on 06/19/18 at 12:59:51

score: Add CPU_INTERRUPT_STACK_ALIGNMENT

Add CPU port define for the interrupt stack alignment. The alignment
should take the stack ABI and the cache line size into account.

Update #3459.

  • Property mode set to 100644
File size: 31.4 KB
Line 
1/**
2 * @file
3 *
4 * @brief LM32 CPU Department Source
5 *
6 * This include file contains information pertaining to the LM32
7 * processor.
8 */
9
10/*
11 *  COPYRIGHT (c) 1989-2008.
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
23extern "C" {
24#endif
25
26#include <rtems/score/basedefs.h>
27#include <rtems/score/lm32.h>
28
29/* conditional compilation parameters */
30
31/**
32 * Does RTEMS manage a dedicated interrupt stack in software?
33 *
34 * If TRUE, then a stack is allocated in @ref _ISR_Handler_initialization.
35 * If FALSE, nothing is done.
36 *
37 * If the CPU supports a dedicated interrupt stack in hardware,
38 * then it is generally the responsibility of the BSP to allocate it
39 * and set it up.
40 *
41 * If the CPU does not support a dedicated interrupt stack, then
42 * the porter has two options: (1) execute interrupts on the
43 * stack of the interrupted task, and (2) have RTEMS manage a dedicated
44 * interrupt stack.
45 *
46 * If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
47 *
48 * Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
49 * @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
50 * possible that both are FALSE for a particular CPU.  Although it
51 * is unclear what that would imply about the interrupt processing
52 * procedure on that CPU.
53 *
54 * Port Specific Information:
55 *
56 * XXX document implementation including references if appropriate
57 */
58#define CPU_HAS_SOFTWARE_INTERRUPT_STACK TRUE
59
60/**
61 * Does the CPU follow the simple vectored interrupt model?
62 *
63 * If TRUE, then RTEMS allocates the vector table it internally manages.
64 * If FALSE, then the BSP is assumed to allocate and manage the vector
65 * table
66 *
67 * Port Specific Information:
68 *
69 * XXX document implementation including references if appropriate
70 */
71#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
72
73/**
74 * Does this CPU have hardware support for a dedicated interrupt stack?
75 *
76 * If TRUE, then it must be installed during initialization.
77 * If FALSE, then no installation is performed.
78 *
79 * If this is TRUE, @ref CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
80 *
81 * Only one of @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK and
82 * @ref CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
83 * possible that both are FALSE for a particular CPU.  Although it
84 * is unclear what that would imply about the interrupt processing
85 * procedure on that CPU.
86 *
87 * Port Specific Information:
88 *
89 * XXX document implementation including references if appropriate
90 */
91#define CPU_HAS_HARDWARE_INTERRUPT_STACK FALSE
92
93/**
94 * Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
95 *
96 * If TRUE, then the memory is allocated during initialization.
97 * If FALSE, then the memory is allocated during initialization.
98 *
99 * This should be TRUE is CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE.
100 *
101 * Port Specific Information:
102 *
103 * XXX document implementation including references if appropriate
104 */
105#define CPU_ALLOCATE_INTERRUPT_STACK TRUE
106
107/**
108 * Does the RTEMS invoke the user's ISR with the vector number and
109 * a pointer to the saved interrupt frame (1) or just the vector
110 * number (0)?
111 *
112 * Port Specific Information:
113 *
114 * XXX document implementation including references if appropriate
115 */
116#define CPU_ISR_PASSES_FRAME_POINTER TRUE
117
118/**
119 * @def CPU_HARDWARE_FP
120 *
121 * Does the CPU have hardware floating point?
122 *
123 * If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
124 * If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
125 *
126 * If there is a FP coprocessor such as the i387 or mc68881, then
127 * the answer is TRUE.
128 *
129 * The macro name "NO_CPU_HAS_FPU" should be made CPU specific.
130 * It indicates whether or not this CPU model has FP support.  For
131 * example, it would be possible to have an i386_nofp CPU model
132 * which set this to false to indicate that you have an i386 without
133 * an i387 and wish to leave floating point support out of RTEMS.
134 */
135
136/**
137 * @def CPU_SOFTWARE_FP
138 *
139 * Does the CPU have no hardware floating point and GCC provides a
140 * software floating point implementation which must be context
141 * switched?
142 *
143 * This feature conditional is used to indicate whether or not there
144 * is software implemented floating point that must be context
145 * switched.  The determination of whether or not this applies
146 * is very tool specific and the state saved/restored is also
147 * compiler specific.
148 *
149 * Port Specific Information:
150 *
151 * XXX document implementation including references if appropriate
152 */
153#define CPU_HARDWARE_FP     FALSE
154#define CPU_SOFTWARE_FP     FALSE
155
156/**
157 * Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
158 *
159 * If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
160 * If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
161 *
162 * So far, the only CPUs in which this option has been used are the
163 * HP PA-RISC and PowerPC.  On the PA-RISC, The HP C compiler and
164 * gcc both implicitly used the floating point registers to perform
165 * integer multiplies.  Similarly, the PowerPC port of gcc has been
166 * seen to allocate floating point local variables and touch the FPU
167 * even when the flow through a subroutine (like vfprintf()) might
168 * not use floating point formats.
169 *
170 * If a function which you would not think utilize the FP unit DOES,
171 * then one can not easily predict which tasks will use the FP hardware.
172 * In this case, this option should be TRUE.
173 *
174 * If @ref CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
175 *
176 * Port Specific Information:
177 *
178 * XXX document implementation including references if appropriate
179 */
180#define CPU_ALL_TASKS_ARE_FP     FALSE
181
182/**
183 * Should the IDLE task have a floating point context?
184 *
185 * If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
186 * and it has a floating point context which is switched in and out.
187 * If FALSE, then the IDLE task does not have a floating point context.
188 *
189 * Setting this to TRUE negatively impacts the time required to preempt
190 * the IDLE task from an interrupt because the floating point context
191 * must be saved as part of the preemption.
192 *
193 * Port Specific Information:
194 *
195 * XXX document implementation including references if appropriate
196 */
197#define CPU_IDLE_TASK_IS_FP      FALSE
198
199/**
200 * Should the saving of the floating point registers be deferred
201 * until a context switch is made to another different floating point
202 * task?
203 *
204 * If TRUE, then the floating point context will not be stored until
205 * necessary.  It will remain in the floating point registers and not
206 * disturned until another floating point task is switched to.
207 *
208 * If FALSE, then the floating point context is saved when a floating
209 * point task is switched out and restored when the next floating point
210 * task is restored.  The state of the floating point registers between
211 * those two operations is not specified.
212 *
213 * If the floating point context does NOT have to be saved as part of
214 * interrupt dispatching, then it should be safe to set this to TRUE.
215 *
216 * Setting this flag to TRUE results in using a different algorithm
217 * for deciding when to save and restore the floating point context.
218 * The deferred FP switch algorithm minimizes the number of times
219 * the FP context is saved and restored.  The FP context is not saved
220 * until a context switch is made to another, different FP task.
221 * Thus in a system with only one FP task, the FP context will never
222 * be saved or restored.
223 *
224 * Port Specific Information:
225 *
226 * XXX document implementation including references if appropriate
227 */
228#define CPU_USE_DEFERRED_FP_SWITCH       TRUE
229
230#define CPU_ENABLE_ROBUST_THREAD_DISPATCH FALSE
231
232/**
233 * Does this port provide a CPU dependent IDLE task implementation?
234 *
235 * If TRUE, then the routine @ref _CPU_Thread_Idle_body
236 * must be provided and is the default IDLE thread body instead of
237 * @ref _CPU_Thread_Idle_body.
238 *
239 * If FALSE, then use the generic IDLE thread body if the BSP does
240 * not provide one.
241 *
242 * This is intended to allow for supporting processors which have
243 * a low power or idle mode.  When the IDLE thread is executed, then
244 * the CPU can be powered down.
245 *
246 * The order of precedence for selecting the IDLE thread body is:
247 *
248 *   -#  BSP provided
249 *   -#  CPU dependent (if provided)
250 *   -#  generic (if no BSP and no CPU dependent)
251 *
252 * Port Specific Information:
253 *
254 * XXX document implementation including references if appropriate
255 */
256#define CPU_PROVIDES_IDLE_THREAD_BODY    TRUE
257
258/**
259 * Does the stack grow up (toward higher addresses) or down
260 * (toward lower addresses)?
261 *
262 * If TRUE, then the grows upward.
263 * If FALSE, then the grows toward smaller addresses.
264 *
265 * Port Specific Information:
266 *
267 * XXX document implementation including references if appropriate
268 */
269#define CPU_STACK_GROWS_UP               FALSE
270
271/* L2 cache lines are 32 bytes in Milkymist SoC */
272#define CPU_CACHE_LINE_BYTES 32
273
274#define CPU_STRUCTURE_ALIGNMENT RTEMS_ALIGNED( CPU_CACHE_LINE_BYTES )
275
276/**
277 * @ingroup CPUInterrupt
278 * The following defines the number of bits actually used in the
279 * interrupt field of the task mode.  How those bits map to the
280 * CPU interrupt levels is defined by the routine @ref _CPU_ISR_Set_level.
281 *
282 * Port Specific Information:
283 *
284 * XXX document implementation including references if appropriate
285 */
286#define CPU_MODES_INTERRUPT_MASK   0x00000001
287
288#define CPU_MAXIMUM_PROCESSORS 32
289
290/*
291 *  Processor defined structures required for cpukit/score.
292 *
293 *  Port Specific Information:
294 *
295 *  XXX document implementation including references if appropriate
296 */
297
298/* may need to put some structures here.  */
299
300/**
301 * @defgroup CPUContext Processor Dependent Context Management
302 *
303 * From the highest level viewpoint, there are 2 types of context to save.
304 *
305 *    -# Interrupt registers to save
306 *    -# Task level registers to save
307 *
308 * Since RTEMS handles integer and floating point contexts separately, this
309 * means we have the following 3 context items:
310 *
311 *    -# task level context stuff::  Context_Control
312 *    -# floating point task stuff:: Context_Control_fp
313 *    -# special interrupt level context :: CPU_Interrupt_frame
314 *
315 * On some processors, it is cost-effective to save only the callee
316 * preserved registers during a task context switch.  This means
317 * that the ISR code needs to save those registers which do not
318 * persist across function calls.  It is not mandatory to make this
319 * distinctions between the caller/callee saves registers for the
320 * purpose of minimizing context saved during task switch and on interrupts.
321 * If the cost of saving extra registers is minimal, simplicity is the
322 * choice.  Save the same context on interrupt entry as for tasks in
323 * this case.
324 *
325 * Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
326 * care should be used in designing the context area.
327 *
328 * On some CPUs with hardware floating point support, the Context_Control_fp
329 * structure will not be used or it simply consist of an array of a
330 * fixed number of bytes.   This is done when the floating point context
331 * is dumped by a "FP save context" type instruction and the format
332 * is not really defined by the CPU.  In this case, there is no need
333 * to figure out the exact format -- only the size.  Of course, although
334 * this is enough information for RTEMS, it is probably not enough for
335 * a debugger such as gdb.  But that is another problem.
336 *
337 * Port Specific Information:
338 *
339 * XXX document implementation including references if appropriate
340 */
341/**@{**/
342
343/**
344 * This defines the minimal set of integer and processor state registers
345 * that must be saved during a voluntary context switch from one thread
346 * to another.
347 */
348typedef struct {
349  uint32_t r11;
350  uint32_t r12;
351  uint32_t r13;
352  uint32_t r14;
353  uint32_t r15;
354  uint32_t r16;
355  uint32_t r17;
356  uint32_t r18;
357  uint32_t r19;
358  uint32_t r20;
359  uint32_t r21;
360  uint32_t r22;
361  uint32_t r23;
362  uint32_t r24;
363  uint32_t r25;
364  uint32_t gp;
365  uint32_t fp;
366  uint32_t sp;
367  uint32_t ra;
368  uint32_t ie;
369  uint32_t epc;
370} Context_Control;
371
372/**
373 *
374 * This macro returns the stack pointer associated with @a _context.
375 *
376 * @param[in] _context is the thread context area to access
377 *
378 * @return This method returns the stack pointer.
379 */
380#define _CPU_Context_Get_SP( _context ) \
381  (_context)->sp
382
383/**
384 * This defines the complete set of floating point registers that must
385 * be saved during any context switch from one thread to another.
386 */
387typedef struct {
388} Context_Control_fp;
389
390/**
391 * This defines the set of integer and processor state registers that must
392 * be saved during an interrupt.  This set does not include any which are
393 * in @ref Context_Control.
394 */
395typedef struct {
396  uint32_t r1;
397  uint32_t r2;
398  uint32_t r3;
399  uint32_t r4;
400  uint32_t r5;
401  uint32_t r6;
402  uint32_t r7;
403  uint32_t r8;
404  uint32_t r9;
405  uint32_t r10;
406  uint32_t ra;
407  uint32_t ba;
408  uint32_t ea;
409} CPU_Interrupt_frame;
410
411/**
412 * This variable is optional.  It is used on CPUs on which it is difficult
413 * to generate an "uninitialized" FP context.  It is filled in by
414 * @ref _CPU_Initialize and copied into the task's FP context area during
415 * @ref _CPU_Context_Initialize.
416 *
417 * Port Specific Information:
418 *
419 * XXX document implementation including references if appropriate
420 */
421#if 0
422extern Context_Control_fp _CPU_Null_fp_context;
423#endif
424
425/** @} */
426
427/**
428 * @defgroup CPUInterrupt Processor Dependent Interrupt Management
429 *
430 * On some CPUs, RTEMS supports a software managed interrupt stack.
431 * This stack is allocated by the Interrupt Manager and the switch
432 * is performed in @ref _ISR_Handler.  These variables contain pointers
433 * to the lowest and highest addresses in the chunk of memory allocated
434 * for the interrupt stack.  Since it is unknown whether the stack
435 * grows up or down (in general), this give the CPU dependent
436 * code the option of picking the version it wants to use.
437 *
438 * NOTE: These two variables are required if the macro
439 *       @ref CPU_HAS_SOFTWARE_INTERRUPT_STACK is defined as TRUE.
440 *
441 * Port Specific Information:
442 *
443 * XXX document implementation including references if appropriate
444 */
445/**@{**/
446
447/*
448 * Nothing prevents the porter from declaring more CPU specific variables.
449 *
450 * Port Specific Information:
451 *
452 * XXX document implementation including references if appropriate
453 */
454
455/* XXX: if needed, put more variables here */
456
457/**
458 * @ingroup CPUContext
459 * The size of the floating point context area.  On some CPUs this
460 * will not be a "sizeof" because the format of the floating point
461 * area is not defined -- only the size is.  This is usually on
462 * CPUs with a "floating point save context" instruction.
463 *
464 * Port Specific Information:
465 *
466 * XXX document implementation including references if appropriate
467 */
468#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
469
470/**
471 * Amount of extra stack (above minimum stack size) required by
472 * MPCI receive server thread.  Remember that in a multiprocessor
473 * system this thread must exist and be able to process all directives.
474 *
475 * Port Specific Information:
476 *
477 * XXX document implementation including references if appropriate
478 */
479#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
480
481/**
482 * This defines the number of entries in the @ref _ISR_Vector_table managed
483 * by RTEMS.
484 *
485 * Port Specific Information:
486 *
487 * XXX document implementation including references if appropriate
488 */
489#define CPU_INTERRUPT_NUMBER_OF_VECTORS      32
490
491/**
492 * This defines the highest interrupt vector number for this port.
493 */
494#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER  (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
495
496/**
497 * This is defined if the port has a special way to report the ISR nesting
498 * level.  Most ports maintain the variable @a _ISR_Nest_level.
499 */
500#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
501
502/** @} */
503
504/**
505 * @ingroup CPUContext
506 * Should be large enough to run all RTEMS tests.  This ensures
507 * that a "reasonable" small application should not have any problems.
508 *
509 * Port Specific Information:
510 *
511 * XXX document implementation including references if appropriate
512 */
513#define CPU_STACK_MINIMUM_SIZE          (1024*4)
514
515#define CPU_SIZEOF_POINTER 4
516
517/**
518 * CPU's worst alignment requirement for data types on a byte boundary.  This
519 * alignment does not take into account the requirements for the stack.
520 *
521 * Port Specific Information:
522 * The LM32 architecture manual simply states: "All memory accesses must be
523 * aligned to the size of the access", and there is no hardware support
524 * whatsoever for 64-bit numbers.
525 * (lm32_archman.pdf, July 2009, p. 15)
526 */
527#define CPU_ALIGNMENT              4
528
529/**
530 * This number corresponds to the byte alignment requirement for the
531 * heap handler.  This alignment requirement may be stricter than that
532 * for the data types alignment specified by @ref CPU_ALIGNMENT.  It is
533 * common for the heap to follow the same alignment requirement as
534 * @ref CPU_ALIGNMENT.  If the @ref CPU_ALIGNMENT is strict enough for
535 * the heap, then this should be set to @ref CPU_ALIGNMENT.
536 *
537 * NOTE:  This does not have to be a power of 2 although it should be
538 *        a multiple of 2 greater than or equal to 2.  The requirement
539 *        to be a multiple of 2 is because the heap uses the least
540 *        significant field of the front and back flags to indicate
541 *        that a block is in use or free.  So you do not want any odd
542 *        length blocks really putting length data in that bit.
543 *
544 *        On byte oriented architectures, @ref CPU_HEAP_ALIGNMENT normally will
545 *        have to be greater or equal to than @ref CPU_ALIGNMENT to ensure that
546 *        elements allocated from the heap meet all restrictions.
547 *
548 * Port Specific Information:
549 *
550 * XXX document implementation including references if appropriate
551 */
552#define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
553
554/**
555 * This number corresponds to the byte alignment requirement for memory
556 * buffers allocated by the partition manager.  This alignment requirement
557 * may be stricter than that for the data types alignment specified by
558 * @ref CPU_ALIGNMENT.  It is common for the partition to follow the same
559 * alignment requirement as @ref CPU_ALIGNMENT.  If the @ref CPU_ALIGNMENT is
560 * strict enough for the partition, then this should be set to
561 * @ref CPU_ALIGNMENT.
562 *
563 * NOTE:  This does not have to be a power of 2.  It does have to
564 *        be greater or equal to than @ref CPU_ALIGNMENT.
565 *
566 * Port Specific Information:
567 *
568 * XXX document implementation including references if appropriate
569 */
570#define CPU_PARTITION_ALIGNMENT    CPU_ALIGNMENT
571
572/**
573 * This number corresponds to the byte alignment requirement for the
574 * stack.  This alignment requirement may be stricter than that for the
575 * data types alignment specified by @ref CPU_ALIGNMENT.
576 *
577 *
578 * Port Specific Information:
579 *
580 * Stack is software-managed
581 */
582#define CPU_STACK_ALIGNMENT        CPU_ALIGNMENT
583
584#define CPU_INTERRUPT_STACK_ALIGNMENT CPU_CACHE_LINE_BYTES
585
586/*
587 *  ISR handler macros
588 */
589
590/**
591 * @addtogroup CPUInterrupt
592 */
593/**@{**/
594
595/**
596 * Support routine to initialize the RTEMS vector table after it is allocated.
597 *
598 * Port Specific Information:
599 *
600 * XXX document implementation including references if appropriate
601 */
602#define _CPU_Initialize_vectors()
603
604/**
605 * Disable all interrupts for an RTEMS critical section.  The previous
606 * level is returned in @a _isr_cookie.
607 *
608 * @param[out] _isr_cookie will contain the previous level cookie
609 *
610 * Port Specific Information:
611 *
612 * XXX document implementation including references if appropriate
613 */
614#define _CPU_ISR_Disable( _isr_cookie ) \
615  lm32_disable_interrupts( _isr_cookie );
616
617/**
618 * Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
619 * This indicates the end of an RTEMS critical section.  The parameter
620 * @a _isr_cookie is not modified.
621 *
622 * @param[in] _isr_cookie contain the previous level cookie
623 *
624 * Port Specific Information:
625 *
626 * XXX document implementation including references if appropriate
627 */
628#define _CPU_ISR_Enable( _isr_cookie ) \
629  lm32_enable_interrupts( _isr_cookie );
630
631/**
632 * This temporarily restores the interrupt to @a _isr_cookie before immediately
633 * disabling them again.  This is used to divide long RTEMS critical
634 * sections into two or more parts.  The parameter @a _isr_cookie is not
635 * modified.
636 *
637 * @param[in] _isr_cookie contain the previous level cookie
638 *
639 * Port Specific Information:
640 *
641 * XXX document implementation including references if appropriate
642 */
643#define _CPU_ISR_Flash( _isr_cookie ) \
644  lm32_flash_interrupts( _isr_cookie );
645
646RTEMS_INLINE_ROUTINE bool _CPU_ISR_Is_enabled( uint32_t level )
647{
648  return ( level & 0x0001 ) != 0;
649}
650
651/**
652 * This routine and @ref _CPU_ISR_Get_level
653 * Map the interrupt level in task mode onto the hardware that the CPU
654 * actually provides.  Currently, interrupt levels which do not
655 * map onto the CPU in a generic fashion are undefined.  Someday,
656 * it would be nice if these were "mapped" by the application
657 * via a callout.  For example, m68k has 8 levels 0 - 7, levels
658 * 8 - 255 would be available for bsp/application specific meaning.
659 * This could be used to manage a programmable interrupt controller
660 * via the rtems_task_mode directive.
661 *
662 * Port Specific Information:
663 *
664 * XXX document implementation including references if appropriate
665 */
666#define _CPU_ISR_Set_level( new_level ) \
667  { \
668    _CPU_ISR_Enable( ( new_level==0 ) ? 1 : 0 ); \
669  }
670
671/**
672 * Return the current interrupt disable level for this task in
673 * the format used by the interrupt level portion of the task mode.
674 *
675 * NOTE: This routine usually must be implemented as a subroutine.
676 *
677 * Port Specific Information:
678 *
679 * XXX document implementation including references if appropriate
680 */
681uint32_t   _CPU_ISR_Get_level( void );
682
683/* end of ISR handler macros */
684
685/** @} */
686
687/* Context handler macros */
688
689/**
690 * @ingroup CPUContext
691 * Initialize the context to a state suitable for starting a
692 * task after a context restore operation.  Generally, this
693 * involves:
694 *
695 *    - setting a starting address
696 *    - preparing the stack
697 *    - preparing the stack and frame pointers
698 *    - setting the proper interrupt level in the context
699 *    - initializing the floating point context
700 *
701 * This routine generally does not set any unnecessary register
702 * in the context.  The state of the "general data" registers is
703 * undefined at task start time.
704 *
705 * @param[in] _the_context is the context structure to be initialized
706 * @param[in] _stack_base is the lowest physical address of this task's stack
707 * @param[in] _size is the size of this task's stack
708 * @param[in] _isr is the interrupt disable level
709 * @param[in] _entry_point is the thread's entry point.  This is
710 *        always @a _Thread_Handler
711 * @param[in] _is_fp is TRUE if the thread is to be a floating
712 *       point thread.  This is typically only used on CPUs where the
713 *       FPU may be easily disabled by software such as on the SPARC
714 *       where the PSR contains an enable FPU bit.
715 *
716 * Port Specific Information:
717 *
718 * XXX document implementation including references if appropriate
719 */
720extern char _gp[];
721
722#define _CPU_Context_Initialize( _the_context, _stack_base, _size, \
723                                 _isr, _entry_point, _is_fp, _tls_area ) \
724   do { \
725     uint32_t _stack = (uint32_t)(_stack_base) + (_size) - 4; \
726     \
727     (void) _is_fp; /* avoid warning for being unused */ \
728     (void) _isr;  /* avoid warning for being unused */ \
729     (_the_context)->gp = (uint32_t)_gp; \
730     (_the_context)->fp = (uint32_t)_stack; \
731     (_the_context)->sp = (uint32_t)_stack; \
732     (_the_context)->ra = (uint32_t)(_entry_point); \
733   } while ( 0 )
734
735/**
736 * This routine is responsible for somehow restarting the currently
737 * executing task.  If you are lucky, then all that is necessary
738 * is restoring the context.  Otherwise, there will need to be
739 * a special assembly routine which does something special in this
740 * case.  For many ports, simply adding a label to the restore path
741 * of @ref _CPU_Context_switch will work.  On other ports, it may be
742 * possibly to load a few arguments and jump to the restore path. It will
743 * not work if restarting self conflicts with the stack frame
744 * assumptions of restoring a context.
745 *
746 * Port Specific Information:
747 *
748 * XXX document implementation including references if appropriate
749 */
750#define _CPU_Context_Restart_self( _the_context ) \
751   _CPU_Context_restore( (_the_context) );
752
753/**
754 * This routine initializes the FP context area passed to it to.
755 * There are a few standard ways in which to initialize the
756 * floating point context.  The code included for this macro assumes
757 * that this is a CPU in which a "initial" FP context was saved into
758 * @a _CPU_Null_fp_context and it simply copies it to the destination
759 * context passed to it.
760 *
761 * Other floating point context save/restore models include:
762 *   -# not doing anything, and
763 *   -# putting a "null FP status word" in the correct place in the FP context.
764 *
765 * @param[in] _destination is the floating point context area
766 *
767 * Port Specific Information:
768 *
769 * XXX document implementation including references if appropriate
770 */
771#define _CPU_Context_Initialize_fp( _destination )
772#if 0
773  { \
774   *(*(_destination)) = _CPU_Null_fp_context; \
775  }
776#endif
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 * Port Specific Information:
788 *
789 * XXX document implementation including references if appropriate
790 */
791#define _CPU_Fatal_halt( _source, _error ) \
792  { \
793  }
794
795/* end of Fatal Error manager macros */
796
797#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
798
799/* functions */
800
801/**
802 * This routine performs CPU dependent initialization.
803 *
804 * Port Specific Information:
805 *
806 * XXX document implementation including references if appropriate
807 */
808void _CPU_Initialize(void);
809
810/**
811 * @addtogroup CPUInterrupt
812 */
813/**@{**/
814
815/**
816 * This routine installs a "raw" interrupt handler directly into the
817 * processor's vector table.
818 *
819 * @param[in] vector is the vector number
820 * @param[in] new_handler is the raw ISR handler to install
821 * @param[in] old_handler is the previously installed ISR Handler
822 *
823 * Port Specific Information:
824 *
825 * XXX document implementation including references if appropriate
826 */
827void _CPU_ISR_install_raw_handler(
828  uint32_t    vector,
829  proc_ptr    new_handler,
830  proc_ptr   *old_handler
831);
832
833/**
834 * This routine installs an interrupt vector.
835 *
836 * @param[in] vector is the vector number
837 * @param[in] new_handler is the RTEMS ISR handler to install
838 * @param[in] old_handler is the previously installed ISR Handler
839 *
840 * Port Specific Information:
841 *
842 * XXX document implementation including references if appropriate
843 */
844void _CPU_ISR_install_vector(
845  uint32_t    vector,
846  proc_ptr    new_handler,
847  proc_ptr   *old_handler
848);
849
850/**
851 * This routine installs the hardware interrupt stack pointer.
852 *
853 * NOTE:  It need only be provided if @ref CPU_HAS_HARDWARE_INTERRUPT_STACK
854 *        is TRUE.
855 *
856 * Port Specific Information:
857 *
858 * XXX document implementation including references if appropriate
859 */
860void _CPU_Install_interrupt_stack( void );
861
862/** @} */
863
864/**
865 * This routine is the CPU dependent IDLE thread body.
866 *
867 * NOTE:  It need only be provided if @ref CPU_PROVIDES_IDLE_THREAD_BODY
868 *        is TRUE.
869 *
870 * Port Specific Information:
871 *
872 * XXX document implementation including references if appropriate
873 */
874void *_CPU_Thread_Idle_body( uintptr_t ignored );
875
876/**
877 * @ingroup CPUContext
878 * This routine switches from the run context to the heir context.
879 *
880 * @param[in] run points to the context of the currently executing task
881 * @param[in] heir points to the context of the heir task
882 *
883 * Port Specific Information:
884 *
885 * XXX document implementation including references if appropriate
886 */
887void _CPU_Context_switch(
888  Context_Control  *run,
889  Context_Control  *heir
890);
891
892/**
893 * @addtogroup CPUContext
894 */
895/**@{**/
896
897/**
898 * This routine is generally used only to restart self in an
899 * efficient manner.  It may simply be a label in @ref _CPU_Context_switch.
900 *
901 * @param[in] new_context points to the context to be restored.
902 *
903 * NOTE: May be unnecessary to reload some registers.
904 *
905 * Port Specific Information:
906 *
907 * XXX document implementation including references if appropriate
908 */
909void _CPU_Context_restore(
910  Context_Control *new_context
911) RTEMS_NO_RETURN;
912
913/**
914 * This routine saves the floating point context passed to it.
915 *
916 * @param[in] fp_context_ptr is a pointer to a pointer to a floating
917 * point context area
918 *
919 * @return on output @a *fp_context_ptr will contain the address that
920 * should be used with @ref _CPU_Context_restore_fp to restore this context.
921 *
922 * Port Specific Information:
923 *
924 * XXX document implementation including references if appropriate
925 */
926void _CPU_Context_save_fp(
927  Context_Control_fp **fp_context_ptr
928);
929
930/**
931 * This routine restores the floating point context passed to it.
932 *
933 * @param[in] fp_context_ptr is a pointer to a pointer to a floating
934 * point context area to restore
935 *
936 * @return on output @a *fp_context_ptr will contain the address that
937 * should be used with @ref _CPU_Context_save_fp to save this context.
938 *
939 * Port Specific Information:
940 *
941 * XXX document implementation including references if appropriate
942 */
943void _CPU_Context_restore_fp(
944  Context_Control_fp **fp_context_ptr
945);
946
947static inline void _CPU_Context_volatile_clobber( uintptr_t pattern )
948{
949  /* TODO */
950}
951
952static inline void _CPU_Context_validate( uintptr_t pattern )
953{
954  while (1) {
955    /* TODO */
956  }
957}
958
959/** @} */
960
961/* FIXME */
962typedef CPU_Interrupt_frame CPU_Exception_frame;
963
964void _CPU_Exception_frame_print( const CPU_Exception_frame *frame );
965
966/**
967 * @ingroup CPUEndian
968 * The following routine swaps the endian format of an unsigned int.
969 * It must be static because it is referenced indirectly.
970 *
971 * This version will work on any processor, but if there is a better
972 * way for your CPU PLEASE use it.  The most common way to do this is to:
973 *
974 *    swap least significant two bytes with 16-bit rotate
975 *    swap upper and lower 16-bits
976 *    swap most significant two bytes with 16-bit rotate
977 *
978 * Some CPUs have special instructions which swap a 32-bit quantity in
979 * a single instruction (e.g. i486).  It is probably best to avoid
980 * an "endian swapping control bit" in the CPU.  One good reason is
981 * that interrupts would probably have to be disabled to ensure that
982 * an interrupt does not try to access the same "chunk" with the wrong
983 * endian.  Another good reason is that on some CPUs, the endian bit
984 * endianness for ALL fetches -- both code and data -- so the code
985 * will be fetched incorrectly.
986 *
987 * @param[in] value is the value to be swapped
988 * @return the value after being endian swapped
989 *
990 * Port Specific Information:
991 *
992 * XXX document implementation including references if appropriate
993 */
994static inline uint32_t CPU_swap_u32(
995  uint32_t value
996)
997{
998  uint32_t byte1, byte2, byte3, byte4, swapped;
999
1000  byte4 = (value >> 24) & 0xff;
1001  byte3 = (value >> 16) & 0xff;
1002  byte2 = (value >> 8)  & 0xff;
1003  byte1 =  value        & 0xff;
1004
1005  swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
1006  return swapped;
1007}
1008
1009/**
1010 * @ingroup CPUEndian
1011 * This routine swaps a 16 bir quantity.
1012 *
1013 * @param[in] value is the value to be swapped
1014 * @return the value after being endian swapped
1015 */
1016static inline uint16_t CPU_swap_u16(uint16_t v)
1017{
1018    return v << 8 | v >> 8;
1019}
1020
1021typedef uint32_t CPU_Counter_ticks;
1022
1023uint32_t _CPU_Counter_frequency( void );
1024
1025CPU_Counter_ticks _CPU_Counter_read( void );
1026
1027static inline CPU_Counter_ticks _CPU_Counter_difference(
1028  CPU_Counter_ticks second,
1029  CPU_Counter_ticks first
1030)
1031{
1032  return second - first;
1033}
1034
1035/** Type that can store a 32-bit integer or a pointer. */
1036typedef uintptr_t CPU_Uint32ptr;
1037
1038#ifdef __cplusplus
1039}
1040#endif
1041
1042#endif
Note: See TracBrowser for help on using the repository browser.