source: rtems/cpukit/score/cpu/moxie/rtems/score/cpu.h @ a5bbd3ac

4.115
Last change on this file since a5bbd3ac was a5bbd3ac, checked in by Joel Sherrill <joel.sherrill@…>, on 10/07/14 at 22:41:52

moxiertems/score/cpu.h: _CPU_Context_switch needed RTEMS_COMPILER_NO_RETURN_ATTRIBUTE plus fix warnings on unimplemented ISR enable/disable

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