source: rtems/cpukit/score/cpu/epiphany/rtems/score/cpu.h @ af3847a

5
Last change on this file since af3847a was af3847a, checked in by Sebastian Huber <sebastian.huber@…>, on 02/03/16 at 10:39:23

epiphany: Delete superfluous _CPU_Null_fp_context

Update #2559.

  • Property mode set to 100644
File size: 34.0 KB
Line 
1/**
2 * @file rtems/score/cpu.h
3 */
4
5/*
6 *
7 * Copyright (c) 2015 University of York.
8 * Hesham ALMatary <hmka501@york.ac.uk>
9 *
10 * COPYRIGHT (c) 1989-1999.
11 * On-Line Applications Research Corporation (OAR).
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 *    notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 *    notice, this list of conditions and the following disclaimer in the
20 *    documentation and/or other materials provided with the distribution.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35#ifndef _EPIPHANY_CPU_H
36#define _EPIPHANY_CPU_H
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42#include <rtems/score/epiphany.h> /* pick up machine definitions */
43#include <rtems/score/types.h>
44#ifndef ASM
45#include <rtems/bspIo.h>
46#include <stdint.h>
47#include <stdio.h> /* for printk */
48#endif
49
50/* conditional compilation parameters */
51
52/*
53 *  Should the calls to _Thread_Enable_dispatch be inlined?
54 *
55 *  If TRUE, then they are inlined.
56 *  If FALSE, then a subroutine call is made.
57 *
58 *  Basically this is an example of the classic trade-off of size
59 *  versus speed.  Inlining the call (TRUE) typically increases the
60 *  size of RTEMS while speeding up the enabling of dispatching.
61 *  [NOTE: In general, the _Thread_Dispatch_disable_level will
62 *  only be 0 or 1 unless you are in an interrupt handler and that
63 *  interrupt handler invokes the executive.]  When not inlined
64 *  something calls _Thread_Enable_dispatch which in turns calls
65 *  _Thread_Dispatch.  If the enable dispatch is inlined, then
66 *  one subroutine call is avoided entirely.]
67 *
68 */
69
70#define CPU_INLINE_ENABLE_DISPATCH       FALSE
71
72/*
73 *  Does RTEMS manage a dedicated interrupt stack in software?
74 *
75 *  If TRUE, then a stack is allocated in _ISR_Handler_initialization.
76 *  If FALSE, nothing is done.
77 *
78 *  If the CPU supports a dedicated interrupt stack in hardware,
79 *  then it is generally the responsibility of the BSP to allocate it
80 *  and set it up.
81 *
82 *  If the CPU does not support a dedicated interrupt stack, then
83 *  the porter has two options: (1) execute interrupts on the
84 *  stack of the interrupted task, and (2) have RTEMS manage a dedicated
85 *  interrupt stack.
86 *
87 *  If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
88 *
89 *  Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
90 *  CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
91 *  possible that both are FALSE for a particular CPU.  Although it
92 *  is unclear what that would imply about the interrupt processing
93 *  procedure on that CPU.
94 *
95 *  Currently, for epiphany port, _ISR_Handler is responsible for switching to
96 *  RTEMS dedicated interrupt task.
97 *
98 */
99
100#define CPU_HAS_SOFTWARE_INTERRUPT_STACK TRUE
101
102/*
103 *  Does this CPU have hardware support for a dedicated interrupt stack?
104 *
105 *  If TRUE, then it must be installed during initialization.
106 *  If FALSE, then no installation is performed.
107 *
108 *  If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
109 *
110 *  Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
111 *  CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
112 *  possible that both are FALSE for a particular CPU.  Although it
113 *  is unclear what that would imply about the interrupt processing
114 *  procedure on that CPU.
115 *
116 */
117
118#define CPU_HAS_HARDWARE_INTERRUPT_STACK FALSE
119
120/*
121 *  Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
122 *
123 *  If TRUE, then the memory is allocated during initialization.
124 *  If FALSE, then the memory is allocated during initialization.
125 *
126 *  This should be TRUE is CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE
127 *  or CPU_INSTALL_HARDWARE_INTERRUPT_STACK is TRUE.
128 *
129 */
130
131#define CPU_ALLOCATE_INTERRUPT_STACK TRUE
132
133/*
134 *  Does the RTEMS invoke the user's ISR with the vector number and
135 *  a pointer to the saved interrupt frame (1) or just the vector
136 *  number (0)?
137 *
138 */
139
140#define CPU_ISR_PASSES_FRAME_POINTER 1
141
142/*
143 *  Does the CPU have hardware floating point?
144 *
145 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
146 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
147 *
148 *  If there is a FP coprocessor such as the i387 or mc68881, then
149 *  the answer is TRUE.
150 *
151 *  The macro name "epiphany_HAS_FPU" should be made CPU specific.
152 *  It indicates whether or not this CPU model has FP support.  For
153 *  example, it would be possible to have an i386_nofp CPU model
154 *  which set this to false to indicate that you have an i386 without
155 *  an i387 and wish to leave floating point support out of RTEMS.
156 *
157 *  The CPU_SOFTWARE_FP is used to indicate whether or not there
158 *  is software implemented floating point that must be context
159 *  switched.  The determination of whether or not this applies
160 *  is very tool specific and the state saved/restored is also
161 *  compiler specific.
162 *
163 *  epiphany Specific Information:
164 *
165 *  At this time there are no implementations of Epiphany that are
166 *  expected to implement floating point.
167 */
168
169#define CPU_HARDWARE_FP     FALSE
170#define CPU_SOFTWARE_FP     FALSE
171
172/*
173 *  Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
174 *
175 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
176 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
177 *
178 *  If CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
179 *
180 */
181
182#define CPU_ALL_TASKS_ARE_FP     FALSE
183
184/*
185 *  Should the IDLE task have a floating point context?
186 *
187 *  If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
188 *  and it has a floating point context which is switched in and out.
189 *  If FALSE, then the IDLE task does not have a floating point context.
190 *
191 *  Setting this to TRUE negatively impacts the time required to preempt
192 *  the IDLE task from an interrupt because the floating point context
193 *  must be saved as part of the preemption.
194 *
195 */
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 */
225
226#define CPU_USE_DEFERRED_FP_SWITCH       FALSE
227
228/*
229 *  Does this port provide a CPU dependent IDLE task implementation?
230 *
231 *  If TRUE, then the routine _CPU_Thread_Idle_body
232 *  must be provided and is the default IDLE thread body instead of
233 *  _CPU_Thread_Idle_body.
234 *
235 *  If FALSE, then use the generic IDLE thread body if the BSP does
236 *  not provide one.
237 *
238 *  This is intended to allow for supporting processors which have
239 *  a low power or idle mode.  When the IDLE thread is executed, then
240 *  the CPU can be powered down.
241 *
242 *  The order of precedence for selecting the IDLE thread body is:
243 *
244 *    1.  BSP provided
245 *    2.  CPU dependent (if provided)
246 *    3.  generic (if no BSP and no CPU dependent)
247 *
248 */
249
250#define CPU_PROVIDES_IDLE_THREAD_BODY    TRUE
251
252/*
253 *  Does the stack grow up (toward higher addresses) or down
254 *  (toward lower addresses)?
255 *
256 *  If TRUE, then the grows upward.
257 *  If FALSE, then the grows toward smaller addresses.
258 *
259 */
260
261#define CPU_STACK_GROWS_UP               FALSE
262
263/* FIXME: Is this the right value? */
264#define CPU_CACHE_LINE_BYTES 64
265
266#define CPU_STRUCTURE_ALIGNMENT RTEMS_ALIGNED( CPU_CACHE_LINE_BYTES )
267
268/*
269 *  Define what is required to specify how the network to host conversion
270 *  routines are handled.
271 *
272 *  epiphany Specific Information:
273 *
274 *  This version of RTEMS is designed specifically to run with
275 *  big endian architectures. If you want little endian, you'll
276 *  have to make the appropriate adjustments here and write
277 *  efficient routines for byte swapping. The epiphany architecture
278 *  doesn't do this very well.
279 */
280
281#define CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES     FALSE
282#define CPU_BIG_ENDIAN                           FALSE
283#define CPU_LITTLE_ENDIAN                        TRUE
284
285/*
286 *  The following defines the number of bits actually used in the
287 *  interrupt field of the task mode.  How those bits map to the
288 *  CPU interrupt levels is defined by the routine _CPU_ISR_Set_level().
289 *
290 */
291
292#define CPU_MODES_INTERRUPT_MASK   0x00000001
293
294/*
295 *  Processor defined structures required for cpukit/score.
296 */
297
298/*
299 * Contexts
300 *
301 *  Generally there are 2 types of context to save.
302 *     1. Interrupt registers to save
303 *     2. Task level registers to save
304 *
305 *  This means we have the following 3 context items:
306 *     1. task level context stuff::  Context_Control
307 *     2. floating point task stuff:: Context_Control_fp
308 *     3. special interrupt level context :: Context_Control_interrupt
309 *
310 *  On some processors, it is cost-effective to save only the callee
311 *  preserved registers during a task context switch.  This means
312 *  that the ISR code needs to save those registers which do not
313 *  persist across function calls.  It is not mandatory to make this
314 *  distinctions between the caller/callee saves registers for the
315 *  purpose of minimizing context saved during task switch and on interrupts.
316 *  If the cost of saving extra registers is minimal, simplicity is the
317 *  choice.  Save the same context on interrupt entry as for tasks in
318 *  this case.
319 *
320 *  Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
321 *  care should be used in designing the context area.
322 *
323 *  On some CPUs with hardware floating point support, the Context_Control_fp
324 *  structure will not be used or it simply consist of an array of a
325 *  fixed number of bytes.   This is done when the floating point context
326 *  is dumped by a "FP save context" type instruction and the format
327 *  is not really defined by the CPU.  In this case, there is no need
328 *  to figure out the exact format -- only the size.  Of course, although
329 *  this is enough information for RTEMS, it is probably not enough for
330 *  a debugger such as gdb.  But that is another problem.
331 *
332 *
333 */
334#ifndef ASM
335
336typedef struct {
337  uint32_t  r[64];
338
339  uint32_t status;
340  uint32_t config;
341  uint32_t iret;
342
343#ifdef RTEMS_SMP
344    /**
345     * @brief On SMP configurations the thread context must contain a boolean
346     * indicator to signal if this context is executing on a processor.
347     *
348     * This field must be updated during a context switch.  The context switch
349     * to the heir must wait until the heir context indicates that it is no
350     * longer executing on a processor.  The context switch must also check if
351     * a thread dispatch is necessary to honor updates of the heir thread for
352     * this processor.  This indicator must be updated using an atomic test and
353     * set operation to ensure that at most one processor uses the heir
354     * context at the same time.
355     *
356     * @code
357     * void _CPU_Context_switch(
358     *   Context_Control *executing,
359     *   Context_Control *heir
360     * )
361     * {
362     *   save( executing );
363     *
364     *   executing->is_executing = false;
365     *   memory_barrier();
366     *
367     *   if ( test_and_set( &heir->is_executing ) ) {
368     *     do {
369     *       Per_CPU_Control *cpu_self = _Per_CPU_Get_snapshot();
370     *
371     *       if ( cpu_self->dispatch_necessary ) {
372     *         heir = _Thread_Get_heir_and_make_it_executing( cpu_self );
373     *       }
374     *     } while ( test_and_set( &heir->is_executing ) );
375     *   }
376     *
377     *   restore( heir );
378     * }
379     * @endcode
380     */
381    volatile bool is_executing;
382#endif
383} Context_Control;
384
385#define _CPU_Context_Get_SP( _context ) \
386  (_context)->r[13]
387
388typedef struct {
389  /** FPU registers are listed here */
390  double  some_float_register;
391} Context_Control_fp;
392
393typedef Context_Control CPU_Interrupt_frame;
394
395/*
396 *  The size of the floating point context area.  On some CPUs this
397 *  will not be a "sizeof" because the format of the floating point
398 *  area is not defined -- only the size is.  This is usually on
399 *  CPUs with a "floating point save context" instruction.
400 *
401 *  epiphany Specific Information:
402 *
403 */
404
405#define CPU_CONTEXT_FP_SIZE  0
406
407/*
408 *  Amount of extra stack (above minimum stack size) required by
409 *  MPCI receive server thread.  Remember that in a multiprocessor
410 *  system this thread must exist and be able to process all directives.
411 *
412 */
413
414#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
415
416/*
417 *  Should be large enough to run all RTEMS tests.  This insures
418 *  that a "reasonable" small application should not have any problems.
419 *
420 */
421
422#define CPU_STACK_MINIMUM_SIZE  4096
423
424/*
425 *  CPU's worst alignment requirement for data types on a byte boundary.  This
426 *  alignment does not take into account the requirements for the stack.
427 *
428 */
429
430#define CPU_ALIGNMENT 8
431
432/*
433 *  This is defined if the port has a special way to report the ISR nesting
434 *  level.  Most ports maintain the variable _ISR_Nest_level.
435 */
436#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
437
438/*
439 *  This number corresponds to the byte alignment requirement for the
440 *  heap handler.  This alignment requirement may be stricter than that
441 *  for the data types alignment specified by CPU_ALIGNMENT.  It is
442 *  common for the heap to follow the same alignment requirement as
443 *  CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict enough for the heap,
444 *  then this should be set to CPU_ALIGNMENT.
445 *
446 *  NOTE:  This does not have to be a power of 2 although it should be
447 *         a multiple of 2 greater than or equal to 2.  The requirement
448 *         to be a multiple of 2 is because the heap uses the least
449 *         significant field of the front and back flags to indicate
450 *         that a block is in use or free.  So you do not want any odd
451 *         length blocks really putting length data in that bit.
452 *
453 *         On byte oriented architectures, CPU_HEAP_ALIGNMENT normally will
454 *         have to be greater or equal to than CPU_ALIGNMENT to ensure that
455 *         elements allocated from the heap meet all restrictions.
456 *
457 */
458
459#define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
460
461/*
462 *  This number corresponds to the byte alignment requirement for memory
463 *  buffers allocated by the partition manager.  This alignment requirement
464 *  may be stricter than that for the data types alignment specified by
465 *  CPU_ALIGNMENT.  It is common for the partition to follow the same
466 *  alignment requirement as CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict
467 *  enough for the partition, then this should be set to CPU_ALIGNMENT.
468 *
469 *  NOTE:  This does not have to be a power of 2.  It does have to
470 *         be greater or equal to than CPU_ALIGNMENT.
471 *
472 */
473
474#define CPU_PARTITION_ALIGNMENT    CPU_ALIGNMENT
475
476/*
477 *  This number corresponds to the byte alignment requirement for the
478 *  stack.  This alignment requirement may be stricter than that for the
479 *  data types alignment specified by CPU_ALIGNMENT.  If the CPU_ALIGNMENT
480 *  is strict enough for the stack, then this should be set to 0.
481 *
482 *  NOTE:  This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
483 *
484 */
485
486#define CPU_STACK_ALIGNMENT        8
487
488/* ISR handler macros */
489
490/*
491 *  Support routine to initialize the RTEMS vector table after it is allocated.
492 *
493 *  NO_CPU Specific Information:
494 *
495 *  XXX document implementation including references if appropriate
496 */
497
498#define _CPU_Initialize_vectors()
499
500/*
501 *  Disable all interrupts for an RTEMS critical section.  The previous
502 *  level is returned in _level.
503 *
504 */
505
506static inline uint32_t epiphany_interrupt_disable( void )
507{
508  uint32_t sr;
509  __asm__ __volatile__ ("movfs %[sr], status \n" : [sr] "=r" (sr):);
510  __asm__ __volatile__("gid \n");
511  return sr;
512}
513
514static inline void epiphany_interrupt_enable(uint32_t level)
515{
516  __asm__ __volatile__("gie \n");
517  __asm__ __volatile__ ("movts status, %[level] \n" :: [level] "r" (level):);
518}
519
520#define _CPU_ISR_Disable( _level ) \
521    _level = epiphany_interrupt_disable()
522
523/*
524 *  Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
525 *  This indicates the end of an RTEMS critical section.  The parameter
526 *  _level is not modified.
527 *
528 */
529
530#define _CPU_ISR_Enable( _level )  \
531  epiphany_interrupt_enable( _level )
532
533/*
534 *  This temporarily restores the interrupt to _level before immediately
535 *  disabling them again.  This is used to divide long RTEMS critical
536 *  sections into two or more parts.  The parameter _level is not
537 *  modified.
538 *
539 */
540
541#define _CPU_ISR_Flash( _level ) \
542  do{ \
543      if ( (_level & 0x2) != 0 ) \
544        _CPU_ISR_Enable( _level ); \
545      epiphany_interrupt_disable(); \
546    } while(0)
547
548/*
549 *  Map interrupt level in task mode onto the hardware that the CPU
550 *  actually provides.  Currently, interrupt levels which do not
551 *  map onto the CPU in a generic fashion are undefined.  Someday,
552 *  it would be nice if these were "mapped" by the application
553 *  via a callout.  For example, m68k has 8 levels 0 - 7, levels
554 *  8 - 255 would be available for bsp/application specific meaning.
555 *  This could be used to manage a programmable interrupt controller
556 *  via the rtems_task_mode directive.
557 *
558 *  The get routine usually must be implemented as a subroutine.
559 *
560 */
561
562void _CPU_ISR_Set_level( uint32_t level );
563
564uint32_t _CPU_ISR_Get_level( void );
565
566/* end of ISR handler macros */
567
568/* Context handler macros */
569
570/*
571 *  Initialize the context to a state suitable for starting a
572 *  task after a context restore operation.  Generally, this
573 *  involves:
574 *
575 *     - setting a starting address
576 *     - preparing the stack
577 *     - preparing the stack and frame pointers
578 *     - setting the proper interrupt level in the context
579 *     - initializing the floating point context
580 *
581 *  This routine generally does not set any unnecessary register
582 *  in the context.  The state of the "general data" registers is
583 *  undefined at task start time.
584 *
585 *  NOTE: This is_fp parameter is TRUE if the thread is to be a floating
586 *        point thread.  This is typically only used on CPUs where the
587 *        FPU may be easily disabled by software such as on the SPARC
588 *        where the PSR contains an enable FPU bit.
589 *
590 */
591
592/**
593 * @brief Account for GCC red-zone
594 *
595 * The following macro is used when initializing task's stack
596 * to account for GCC red-zone.
597 */
598
599#define EPIPHANY_GCC_RED_ZONE_SIZE 128
600
601/**
602 * @brief Initializes the CPU context.
603 *
604 * The following steps are performed:
605 *  - setting a starting address
606 *  - preparing the stack
607 *  - preparing the stack and frame pointers
608 *  - setting the proper interrupt level in the context
609 *
610 * @param[in] context points to the context area
611 * @param[in] stack_area_begin is the low address of the allocated stack area
612 * @param[in] stack_area_size is the size of the stack area in bytes
613 * @param[in] new_level is the interrupt level for the task
614 * @param[in] entry_point is the task's entry point
615 * @param[in] is_fp is set to @c true if the task is a floating point task
616 * @param[in] tls_area is the thread-local storage (TLS) area
617 */
618void _CPU_Context_Initialize(
619  Context_Control *context,
620  void *stack_area_begin,
621  size_t stack_area_size,
622  uint32_t new_level,
623  void (*entry_point)( void ),
624  bool is_fp,
625  void *tls_area
626);
627
628/*
629 *  This routine is responsible for somehow restarting the currently
630 *  executing task.  If you are lucky, then all that is necessary
631 *  is restoring the context.  Otherwise, there will need to be
632 *  a special assembly routine which does something special in this
633 *  case.  Context_Restore should work most of the time.  It will
634 *  not work if restarting self conflicts with the stack frame
635 *  assumptions of restoring a context.
636 *
637 */
638
639#define _CPU_Context_Restart_self( _the_context ) \
640   _CPU_Context_restore( (_the_context) )
641
642/*
643 *  The purpose of this macro is to allow the initial pointer into
644 *  a floating point context area (used to save the floating point
645 *  context) to be at an arbitrary place in the floating point
646 *  context area.
647 *
648 *  This is necessary because some FP units are designed to have
649 *  their context saved as a stack which grows into lower addresses.
650 *  Other FP units can be saved by simply moving registers into offsets
651 *  from the base of the context area.  Finally some FP units provide
652 *  a "dump context" instruction which could fill in from high to low
653 *  or low to high based on the whim of the CPU designers.
654 *
655 */
656
657#define _CPU_Context_Fp_start( _base, _offset ) \
658   ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
659
660#define _CPU_Context_Initialize_fp( _destination ) \
661  memset( *( _destination ), 0, CPU_CONTEXT_FP_SIZE );
662
663/* end of Context handler macros */
664
665/* Fatal Error manager macros */
666
667/*
668 *  This routine copies _error into a known place -- typically a stack
669 *  location or a register, optionally disables interrupts, and
670 *  halts/stops the CPU.
671 *
672 */
673
674#define _CPU_Fatal_halt(_source, _error ) \
675          printk("Fatal Error %d.%d Halted\n",_source, _error); \
676          asm("trap 3" :: "r" (_error)); \
677          for(;;)
678
679/* end of Fatal Error manager macros */
680
681/* Bitfield handler macros */
682
683/*
684 *  This routine sets _output to the bit number of the first bit
685 *  set in _value.  _value is of CPU dependent type Priority_Bit_map_control.
686 *  This type may be either 16 or 32 bits wide although only the 16
687 *  least significant bits will be used.
688 *
689 *  There are a number of variables in using a "find first bit" type
690 *  instruction.
691 *
692 *    (1) What happens when run on a value of zero?
693 *    (2) Bits may be numbered from MSB to LSB or vice-versa.
694 *    (3) The numbering may be zero or one based.
695 *    (4) The "find first bit" instruction may search from MSB or LSB.
696 *
697 *  RTEMS guarantees that (1) will never happen so it is not a concern.
698 *  (2),(3), (4) are handled by the macros _CPU_Priority_mask() and
699 *  _CPU_Priority_bits_index().  These three form a set of routines
700 *  which must logically operate together.  Bits in the _value are
701 *  set and cleared based on masks built by _CPU_Priority_mask().
702 *  The basic major and minor values calculated by _Priority_Major()
703 *  and _Priority_Minor() are "massaged" by _CPU_Priority_bits_index()
704 *  to properly range between the values returned by the "find first bit"
705 *  instruction.  This makes it possible for _Priority_Get_highest() to
706 *  calculate the major and directly index into the minor table.
707 *  This mapping is necessary to ensure that 0 (a high priority major/minor)
708 *  is the first bit found.
709 *
710 *  This entire "find first bit" and mapping process depends heavily
711 *  on the manner in which a priority is broken into a major and minor
712 *  components with the major being the 4 MSB of a priority and minor
713 *  the 4 LSB.  Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
714 *  priority.  And (15 << 4) + 14 corresponds to priority 254 -- the next
715 *  to the lowest priority.
716 *
717 *  If your CPU does not have a "find first bit" instruction, then
718 *  there are ways to make do without it.  Here are a handful of ways
719 *  to implement this in software:
720 *
721 *    - a series of 16 bit test instructions
722 *    - a "binary search using if's"
723 *    - _number = 0
724 *      if _value > 0x00ff
725 *        _value >>=8
726 *        _number = 8;
727 *
728 *      if _value > 0x0000f
729 *        _value >=8
730 *        _number += 4
731 *
732 *      _number += bit_set_table[ _value ]
733 *
734 *    where bit_set_table[ 16 ] has values which indicate the first
735 *      bit set
736 *
737 */
738
739  /* #define CPU_USE_GENERIC_BITFIELD_CODE FALSE */
740#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
741#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
742
743#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
744
745#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
746  { \
747    (_output) = 0;   /* do something to prevent warnings */ \
748  }
749#endif
750
751/* end of Bitfield handler macros */
752
753/*
754 *  This routine builds the mask which corresponds to the bit fields
755 *  as searched by _CPU_Bitfield_Find_first_bit().  See the discussion
756 *  for that routine.
757 *
758 */
759
760#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
761
762#define _CPU_Priority_Mask( _bit_number ) \
763    (1 << _bit_number)
764
765#endif
766
767/*
768 *  This routine translates the bit numbers returned by
769 *  _CPU_Bitfield_Find_first_bit() into something suitable for use as
770 *  a major or minor component of a priority.  See the discussion
771 *  for that routine.
772 *
773 */
774
775#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
776
777#define _CPU_Priority_bits_index( _priority ) \
778  (_priority)
779
780#endif
781
782typedef struct {
783/* There is no CPU specific per-CPU state */
784} CPU_Per_CPU_control;
785#endif /* ASM */
786
787/**
788 * Size of a pointer.
789 *
790 * This must be an integer literal that can be used by the assembler.  This
791 * value will be used to calculate offsets of structure members.  These
792 * offsets will be used in assembler code.
793 */
794#define CPU_SIZEOF_POINTER 4
795#define CPU_EXCEPTION_FRAME_SIZE 260
796#define CPU_PER_CPU_CONTROL_SIZE 0
797
798#ifndef ASM
799typedef uint16_t Priority_bit_map_Word;
800
801typedef struct {
802  uint32_t r[62];
803  uint32_t status;
804  uint32_t config;
805  uint32_t iret;
806} CPU_Exception_frame;
807
808/**
809 * @brief Prints the exception frame via printk().
810 *
811 * @see rtems_fatal() and RTEMS_FATAL_SOURCE_EXCEPTION.
812 */
813void _CPU_Exception_frame_print( const CPU_Exception_frame *frame );
814
815
816/* end of Priority handler macros */
817
818/* functions */
819
820/*
821 *  _CPU_Initialize
822 *
823 *  This routine performs CPU dependent initialization.
824 *
825 */
826
827void _CPU_Initialize(
828  void
829);
830
831/*
832 *  _CPU_ISR_install_raw_handler
833 *
834 *  This routine installs a "raw" interrupt handler directly into the
835 *  processor's vector table.
836 *
837 */
838
839void _CPU_ISR_install_raw_handler(
840  uint32_t    vector,
841  proc_ptr    new_handler,
842  proc_ptr   *old_handler
843);
844
845/*
846 *  _CPU_ISR_install_vector
847 *
848 *  This routine installs an interrupt vector.
849 *
850 *  NO_CPU Specific Information:
851 *
852 *  XXX document implementation including references if appropriate
853 */
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 */
870
871void _CPU_Install_interrupt_stack( void );
872
873/*
874 *  _CPU_Thread_Idle_body
875 *
876 *  This routine is the CPU dependent IDLE thread body.
877 *
878 *  NOTE:  It need only be provided if CPU_PROVIDES_IDLE_THREAD_BODY
879 *         is TRUE.
880 *
881 */
882
883void *_CPU_Thread_Idle_body( uintptr_t ignored );
884
885/*
886 *  _CPU_Context_switch
887 *
888 *  This routine switches from the run context to the heir context.
889 *
890 *  epiphany Specific Information:
891 *
892 *  Please see the comments in the .c file for a description of how
893 *  this function works. There are several things to be aware of.
894 */
895
896void _CPU_Context_switch(
897  Context_Control  *run,
898  Context_Control  *heir
899);
900
901/*
902 *  _CPU_Context_restore
903 *
904 *  This routine is generally used only to restart self in an
905 *  efficient manner.  It may simply be a label in _CPU_Context_switch.
906 *
907 *  NOTE: May be unnecessary to reload some registers.
908 *
909 */
910
911void _CPU_Context_restore(
912  Context_Control *new_context
913) RTEMS_NO_RETURN;
914
915/*
916 *  _CPU_Context_save_fp
917 *
918 *  This routine saves the floating point context passed to it.
919 *
920 */
921
922void _CPU_Context_save_fp(
923  void **fp_context_ptr
924);
925
926/*
927 *  _CPU_Context_restore_fp
928 *
929 *  This routine restores the floating point context passed to it.
930 *
931 */
932
933void _CPU_Context_restore_fp(
934  void **fp_context_ptr
935);
936
937/*  The following routine swaps the endian format of an unsigned int.
938 *  It must be static because it is referenced indirectly.
939 *
940 *  This version will work on any processor, but if there is a better
941 *  way for your CPU PLEASE use it.  The most common way to do this is to:
942 *
943 *     swap least significant two bytes with 16-bit rotate
944 *     swap upper and lower 16-bits
945 *     swap most significant two bytes with 16-bit rotate
946 *
947 *  Some CPUs have special instructions which swap a 32-bit quantity in
948 *  a single instruction (e.g. i486).  It is probably best to avoid
949 *  an "endian swapping control bit" in the CPU.  One good reason is
950 *  that interrupts would probably have to be disabled to insure that
951 *  an interrupt does not try to access the same "chunk" with the wrong
952 *  endian.  Another good reason is that on some CPUs, the endian bit
953 *  endianness for ALL fetches -- both code and data -- so the code
954 *  will be fetched incorrectly.
955 *
956 */
957
958static inline unsigned int CPU_swap_u32(
959  unsigned int value
960)
961{
962  uint32_t   byte1, byte2, byte3, byte4, swapped;
963
964  byte4 = (value >> 24) & 0xff;
965  byte3 = (value >> 16) & 0xff;
966  byte2 = (value >> 8)  & 0xff;
967  byte1 =  value        & 0xff;
968
969  swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
970  return( swapped );
971}
972
973#define CPU_swap_u16( value ) \
974  (((value&0xff) << 8) | ((value >> 8)&0xff))
975
976static inline void _CPU_Context_volatile_clobber( uintptr_t pattern )
977{
978  /* TODO */
979}
980
981static inline void _CPU_Context_validate( uintptr_t pattern )
982{
983  while (1) {
984    /* TODO */
985  }
986}
987
988typedef uint32_t CPU_Counter_ticks;
989
990CPU_Counter_ticks _CPU_Counter_read( void );
991
992static inline CPU_Counter_ticks _CPU_Counter_difference(
993  CPU_Counter_ticks second,
994  CPU_Counter_ticks first
995)
996{
997  return second - first;
998}
999
1000#ifdef RTEMS_SMP
1001  /**
1002   * @brief Performs CPU specific SMP initialization in the context of the boot
1003   * processor.
1004   *
1005   * This function is invoked on the boot processor during system
1006   * initialization.  All interrupt stacks are allocated at this point in case
1007   * the CPU port allocates the interrupt stacks.  This function is called
1008   * before _CPU_SMP_Start_processor() or _CPU_SMP_Finalize_initialization() is
1009   * used.
1010   *
1011   * @return The count of physically or virtually available processors.
1012   * Depending on the configuration the application may use not all processors.
1013   */
1014  uint32_t _CPU_SMP_Initialize( void );
1015
1016  /**
1017   * @brief Starts a processor specified by its index.
1018   *
1019   * This function is invoked on the boot processor during system
1020   * initialization.
1021   *
1022   * This function will be called after _CPU_SMP_Initialize().
1023   *
1024   * @param[in] cpu_index The processor index.
1025   *
1026   * @retval true Successful operation.
1027   * @retval false Unable to start this processor.
1028   */
1029  bool _CPU_SMP_Start_processor( uint32_t cpu_index );
1030
1031  /**
1032   * @brief Performs final steps of CPU specific SMP initialization in the
1033   * context of the boot processor.
1034   *
1035   * This function is invoked on the boot processor during system
1036   * initialization.
1037   *
1038   * This function will be called after all processors requested by the
1039   * application have been started.
1040   *
1041   * @param[in] cpu_count The minimum value of the count of processors
1042   * requested by the application configuration and the count of physically or
1043   * virtually available processors.
1044   */
1045  void _CPU_SMP_Finalize_initialization( uint32_t cpu_count );
1046
1047  /**
1048   * @brief Returns the index of the current processor.
1049   *
1050   * An architecture specific method must be used to obtain the index of the
1051   * current processor in the system.  The set of processor indices is the
1052   * range of integers starting with zero up to the processor count minus one.
1053   */
1054   uint32_t _CPU_SMP_Get_current_processor( void );
1055
1056  /**
1057   * @brief Sends an inter-processor interrupt to the specified target
1058   * processor.
1059   *
1060   * This operation is undefined for target processor indices out of range.
1061   *
1062   * @param[in] target_processor_index The target processor index.
1063   */
1064  void _CPU_SMP_Send_interrupt( uint32_t target_processor_index );
1065
1066  /**
1067   * @brief Broadcasts a processor event.
1068   *
1069   * Some architectures provide a low-level synchronization primitive for
1070   * processors in a multi-processor environment.  Processors waiting for this
1071   * event may go into a low-power state and stop generating system bus
1072   * transactions.  This function must ensure that preceding store operations
1073   * can be observed by other processors.
1074   *
1075   * @see _CPU_SMP_Processor_event_receive().
1076   */
1077  void _CPU_SMP_Processor_event_broadcast( void );
1078
1079  /**
1080   * @brief Receives a processor event.
1081   *
1082   * This function will wait for the processor event and may wait forever if no
1083   * such event arrives.
1084   *
1085   * @see _CPU_SMP_Processor_event_broadcast().
1086   */
1087  static inline void _CPU_SMP_Processor_event_receive( void )
1088  {
1089    __asm__ volatile ( "" : : : "memory" );
1090  }
1091
1092  /**
1093   * @brief Gets the is executing indicator of the thread context.
1094   *
1095   * @param[in] context The context.
1096   */
1097  static inline bool _CPU_Context_Get_is_executing(
1098    const Context_Control *context
1099  )
1100  {
1101    return context->is_executing;
1102  }
1103
1104  /**
1105   * @brief Sets the is executing indicator of the thread context.
1106   *
1107   * @param[in] context The context.
1108   * @param[in] is_executing The new value for the is executing indicator.
1109   */
1110  static inline void _CPU_Context_Set_is_executing(
1111    Context_Control *context,
1112    bool is_executing
1113  )
1114  {
1115    context->is_executing = is_executing;
1116  }
1117#endif /* RTEMS_SMP */
1118
1119#endif /* ASM */
1120
1121#ifdef __cplusplus
1122}
1123#endif
1124
1125#endif
Note: See TracBrowser for help on using the repository browser.