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

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

score: Introduce CPU_CACHE_LINE_BYTES

Add CPU_CACHE_LINE_BYTES for the maximum cache line size in bytes. The
actual processor may use no cache or a smaller cache line size.

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