source: rtems/cpukit/score/cpu/epiphany/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: 34.6 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
406SCORE_EXTERN Context_Control_fp  _CPU_Null_fp_context;
407
408/*
409 *  Amount of extra stack (above minimum stack size) required by
410 *  MPCI receive server thread.  Remember that in a multiprocessor
411 *  system this thread must exist and be able to process all directives.
412 *
413 */
414
415#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
416
417/*
418 *  Should be large enough to run all RTEMS tests.  This insures
419 *  that a "reasonable" small application should not have any problems.
420 *
421 */
422
423#define CPU_STACK_MINIMUM_SIZE  4096
424
425/*
426 *  CPU's worst alignment requirement for data types on a byte boundary.  This
427 *  alignment does not take into account the requirements for the stack.
428 *
429 */
430
431#define CPU_ALIGNMENT 8
432
433/*
434 *  This is defined if the port has a special way to report the ISR nesting
435 *  level.  Most ports maintain the variable _ISR_Nest_level.
436 */
437#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
438
439/*
440 *  This number corresponds to the byte alignment requirement for the
441 *  heap handler.  This alignment requirement may be stricter than that
442 *  for the data types alignment specified by CPU_ALIGNMENT.  It is
443 *  common for the heap to follow the same alignment requirement as
444 *  CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict enough for the heap,
445 *  then this should be set to CPU_ALIGNMENT.
446 *
447 *  NOTE:  This does not have to be a power of 2 although it should be
448 *         a multiple of 2 greater than or equal to 2.  The requirement
449 *         to be a multiple of 2 is because the heap uses the least
450 *         significant field of the front and back flags to indicate
451 *         that a block is in use or free.  So you do not want any odd
452 *         length blocks really putting length data in that bit.
453 *
454 *         On byte oriented architectures, CPU_HEAP_ALIGNMENT normally will
455 *         have to be greater or equal to than CPU_ALIGNMENT to ensure that
456 *         elements allocated from the heap meet all restrictions.
457 *
458 */
459
460#define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
461
462/*
463 *  This number corresponds to the byte alignment requirement for memory
464 *  buffers allocated by the partition manager.  This alignment requirement
465 *  may be stricter than that for the data types alignment specified by
466 *  CPU_ALIGNMENT.  It is common for the partition to follow the same
467 *  alignment requirement as CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict
468 *  enough for the partition, then this should be set to CPU_ALIGNMENT.
469 *
470 *  NOTE:  This does not have to be a power of 2.  It does have to
471 *         be greater or equal to than CPU_ALIGNMENT.
472 *
473 */
474
475#define CPU_PARTITION_ALIGNMENT    CPU_ALIGNMENT
476
477/*
478 *  This number corresponds to the byte alignment requirement for the
479 *  stack.  This alignment requirement may be stricter than that for the
480 *  data types alignment specified by CPU_ALIGNMENT.  If the CPU_ALIGNMENT
481 *  is strict enough for the stack, then this should be set to 0.
482 *
483 *  NOTE:  This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
484 *
485 */
486
487#define CPU_STACK_ALIGNMENT        8
488
489/* ISR handler macros */
490
491/*
492 *  Support routine to initialize the RTEMS vector table after it is allocated.
493 *
494 *  NO_CPU Specific Information:
495 *
496 *  XXX document implementation including references if appropriate
497 */
498
499#define _CPU_Initialize_vectors()
500
501/*
502 *  Disable all interrupts for an RTEMS critical section.  The previous
503 *  level is returned in _level.
504 *
505 */
506
507static inline uint32_t epiphany_interrupt_disable( void )
508{
509  uint32_t sr;
510  __asm__ __volatile__ ("movfs %[sr], status \n" : [sr] "=r" (sr):);
511  __asm__ __volatile__("gid \n");
512  return sr;
513}
514
515static inline void epiphany_interrupt_enable(uint32_t level)
516{
517  __asm__ __volatile__("gie \n");
518  __asm__ __volatile__ ("movts status, %[level] \n" :: [level] "r" (level):);
519}
520
521#define _CPU_ISR_Disable( _level ) \
522    _level = epiphany_interrupt_disable()
523
524/*
525 *  Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
526 *  This indicates the end of an RTEMS critical section.  The parameter
527 *  _level is not modified.
528 *
529 */
530
531#define _CPU_ISR_Enable( _level )  \
532  epiphany_interrupt_enable( _level )
533
534/*
535 *  This temporarily restores the interrupt to _level before immediately
536 *  disabling them again.  This is used to divide long RTEMS critical
537 *  sections into two or more parts.  The parameter _level is not
538 *  modified.
539 *
540 */
541
542#define _CPU_ISR_Flash( _level ) \
543  do{ \
544      if ( (_level & 0x2) != 0 ) \
545        _CPU_ISR_Enable( _level ); \
546      epiphany_interrupt_disable(); \
547    } while(0)
548
549/*
550 *  Map interrupt level in task mode onto the hardware that the CPU
551 *  actually provides.  Currently, interrupt levels which do not
552 *  map onto the CPU in a generic fashion are undefined.  Someday,
553 *  it would be nice if these were "mapped" by the application
554 *  via a callout.  For example, m68k has 8 levels 0 - 7, levels
555 *  8 - 255 would be available for bsp/application specific meaning.
556 *  This could be used to manage a programmable interrupt controller
557 *  via the rtems_task_mode directive.
558 *
559 *  The get routine usually must be implemented as a subroutine.
560 *
561 */
562
563void _CPU_ISR_Set_level( uint32_t level );
564
565uint32_t _CPU_ISR_Get_level( void );
566
567/* end of ISR handler macros */
568
569/* Context handler macros */
570
571/*
572 *  Initialize the context to a state suitable for starting a
573 *  task after a context restore operation.  Generally, this
574 *  involves:
575 *
576 *     - setting a starting address
577 *     - preparing the stack
578 *     - preparing the stack and frame pointers
579 *     - setting the proper interrupt level in the context
580 *     - initializing the floating point context
581 *
582 *  This routine generally does not set any unnecessary register
583 *  in the context.  The state of the "general data" registers is
584 *  undefined at task start time.
585 *
586 *  NOTE: This is_fp parameter is TRUE if the thread is to be a floating
587 *        point thread.  This is typically only used on CPUs where the
588 *        FPU may be easily disabled by software such as on the SPARC
589 *        where the PSR contains an enable FPU bit.
590 *
591 */
592
593/**
594 * @brief Account for GCC red-zone
595 *
596 * The following macro is used when initializing task's stack
597 * to account for GCC red-zone.
598 */
599
600#define EPIPHANY_GCC_RED_ZONE_SIZE 128
601
602/**
603 * @brief Initializes the CPU context.
604 *
605 * The following steps are performed:
606 *  - setting a starting address
607 *  - preparing the stack
608 *  - preparing the stack and frame pointers
609 *  - setting the proper interrupt level in the context
610 *
611 * @param[in] context points to the context area
612 * @param[in] stack_area_begin is the low address of the allocated stack area
613 * @param[in] stack_area_size is the size of the stack area in bytes
614 * @param[in] new_level is the interrupt level for the task
615 * @param[in] entry_point is the task's entry point
616 * @param[in] is_fp is set to @c true if the task is a floating point task
617 * @param[in] tls_area is the thread-local storage (TLS) area
618 */
619void _CPU_Context_Initialize(
620  Context_Control *context,
621  void *stack_area_begin,
622  size_t stack_area_size,
623  uint32_t new_level,
624  void (*entry_point)( void ),
625  bool is_fp,
626  void *tls_area
627);
628
629/*
630 *  This routine is responsible for somehow restarting the currently
631 *  executing task.  If you are lucky, then all that is necessary
632 *  is restoring the context.  Otherwise, there will need to be
633 *  a special assembly routine which does something special in this
634 *  case.  Context_Restore should work most of the time.  It will
635 *  not work if restarting self conflicts with the stack frame
636 *  assumptions of restoring a context.
637 *
638 */
639
640#define _CPU_Context_Restart_self( _the_context ) \
641   _CPU_Context_restore( (_the_context) )
642
643/*
644 *  The purpose of this macro is to allow the initial pointer into
645 *  a floating point context area (used to save the floating point
646 *  context) to be at an arbitrary place in the floating point
647 *  context area.
648 *
649 *  This is necessary because some FP units are designed to have
650 *  their context saved as a stack which grows into lower addresses.
651 *  Other FP units can be saved by simply moving registers into offsets
652 *  from the base of the context area.  Finally some FP units provide
653 *  a "dump context" instruction which could fill in from high to low
654 *  or low to high based on the whim of the CPU designers.
655 *
656 */
657
658#define _CPU_Context_Fp_start( _base, _offset ) \
659   ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
660
661/*
662 *  This routine initializes the FP context area passed to it to.
663 *  There are a few standard ways in which to initialize the
664 *  floating point context.  The code included for this macro assumes
665 *  that this is a CPU in which a "initial" FP context was saved into
666 *  _CPU_Null_fp_context and it simply copies it to the destination
667 *  context passed to it.
668 *
669 *  Other models include (1) not doing anything, and (2) putting
670 *  a "null FP status word" in the correct place in the FP context.
671 *
672 */
673
674#define _CPU_Context_Initialize_fp( _destination ) \
675  { \
676   *(*(_destination)) = _CPU_Null_fp_context; \
677  }
678
679/* end of Context handler macros */
680
681/* Fatal Error manager macros */
682
683/*
684 *  This routine copies _error into a known place -- typically a stack
685 *  location or a register, optionally disables interrupts, and
686 *  halts/stops the CPU.
687 *
688 */
689
690#define _CPU_Fatal_halt(_source, _error ) \
691          printk("Fatal Error %d.%d Halted\n",_source, _error); \
692          asm("trap 3" :: "r" (_error)); \
693          for(;;)
694
695/* end of Fatal Error manager macros */
696
697/* Bitfield handler macros */
698
699/*
700 *  This routine sets _output to the bit number of the first bit
701 *  set in _value.  _value is of CPU dependent type Priority_Bit_map_control.
702 *  This type may be either 16 or 32 bits wide although only the 16
703 *  least significant bits will be used.
704 *
705 *  There are a number of variables in using a "find first bit" type
706 *  instruction.
707 *
708 *    (1) What happens when run on a value of zero?
709 *    (2) Bits may be numbered from MSB to LSB or vice-versa.
710 *    (3) The numbering may be zero or one based.
711 *    (4) The "find first bit" instruction may search from MSB or LSB.
712 *
713 *  RTEMS guarantees that (1) will never happen so it is not a concern.
714 *  (2),(3), (4) are handled by the macros _CPU_Priority_mask() and
715 *  _CPU_Priority_bits_index().  These three form a set of routines
716 *  which must logically operate together.  Bits in the _value are
717 *  set and cleared based on masks built by _CPU_Priority_mask().
718 *  The basic major and minor values calculated by _Priority_Major()
719 *  and _Priority_Minor() are "massaged" by _CPU_Priority_bits_index()
720 *  to properly range between the values returned by the "find first bit"
721 *  instruction.  This makes it possible for _Priority_Get_highest() to
722 *  calculate the major and directly index into the minor table.
723 *  This mapping is necessary to ensure that 0 (a high priority major/minor)
724 *  is the first bit found.
725 *
726 *  This entire "find first bit" and mapping process depends heavily
727 *  on the manner in which a priority is broken into a major and minor
728 *  components with the major being the 4 MSB of a priority and minor
729 *  the 4 LSB.  Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
730 *  priority.  And (15 << 4) + 14 corresponds to priority 254 -- the next
731 *  to the lowest priority.
732 *
733 *  If your CPU does not have a "find first bit" instruction, then
734 *  there are ways to make do without it.  Here are a handful of ways
735 *  to implement this in software:
736 *
737 *    - a series of 16 bit test instructions
738 *    - a "binary search using if's"
739 *    - _number = 0
740 *      if _value > 0x00ff
741 *        _value >>=8
742 *        _number = 8;
743 *
744 *      if _value > 0x0000f
745 *        _value >=8
746 *        _number += 4
747 *
748 *      _number += bit_set_table[ _value ]
749 *
750 *    where bit_set_table[ 16 ] has values which indicate the first
751 *      bit set
752 *
753 */
754
755  /* #define CPU_USE_GENERIC_BITFIELD_CODE FALSE */
756#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
757#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
758
759#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
760
761#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
762  { \
763    (_output) = 0;   /* do something to prevent warnings */ \
764  }
765#endif
766
767/* end of Bitfield handler macros */
768
769/*
770 *  This routine builds the mask which corresponds to the bit fields
771 *  as searched by _CPU_Bitfield_Find_first_bit().  See the discussion
772 *  for that routine.
773 *
774 */
775
776#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
777
778#define _CPU_Priority_Mask( _bit_number ) \
779    (1 << _bit_number)
780
781#endif
782
783/*
784 *  This routine translates the bit numbers returned by
785 *  _CPU_Bitfield_Find_first_bit() into something suitable for use as
786 *  a major or minor component of a priority.  See the discussion
787 *  for that routine.
788 *
789 */
790
791#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
792
793#define _CPU_Priority_bits_index( _priority ) \
794  (_priority)
795
796#endif
797
798typedef struct {
799/* There is no CPU specific per-CPU state */
800} CPU_Per_CPU_control;
801#endif /* ASM */
802
803/**
804 * Size of a pointer.
805 *
806 * This must be an integer literal that can be used by the assembler.  This
807 * value will be used to calculate offsets of structure members.  These
808 * offsets will be used in assembler code.
809 */
810#define CPU_SIZEOF_POINTER 4
811#define CPU_EXCEPTION_FRAME_SIZE 260
812#define CPU_PER_CPU_CONTROL_SIZE 0
813
814#ifndef ASM
815typedef uint16_t Priority_bit_map_Word;
816
817typedef struct {
818  uint32_t r[62];
819  uint32_t status;
820  uint32_t config;
821  uint32_t iret;
822} CPU_Exception_frame;
823
824/**
825 * @brief Prints the exception frame via printk().
826 *
827 * @see rtems_fatal() and RTEMS_FATAL_SOURCE_EXCEPTION.
828 */
829void _CPU_Exception_frame_print( const CPU_Exception_frame *frame );
830
831
832/* end of Priority handler macros */
833
834/* functions */
835
836/*
837 *  _CPU_Initialize
838 *
839 *  This routine performs CPU dependent initialization.
840 *
841 */
842
843void _CPU_Initialize(
844  void
845);
846
847/*
848 *  _CPU_ISR_install_raw_handler
849 *
850 *  This routine installs a "raw" interrupt handler directly into the
851 *  processor's vector table.
852 *
853 */
854
855void _CPU_ISR_install_raw_handler(
856  uint32_t    vector,
857  proc_ptr    new_handler,
858  proc_ptr   *old_handler
859);
860
861/*
862 *  _CPU_ISR_install_vector
863 *
864 *  This routine installs an interrupt vector.
865 *
866 *  NO_CPU Specific Information:
867 *
868 *  XXX document implementation including references if appropriate
869 */
870
871void _CPU_ISR_install_vector(
872  uint32_t    vector,
873  proc_ptr   new_handler,
874  proc_ptr   *old_handler
875);
876
877/*
878 *  _CPU_Install_interrupt_stack
879 *
880 *  This routine installs the hardware interrupt stack pointer.
881 *
882 *  NOTE:  It need only be provided if CPU_HAS_HARDWARE_INTERRUPT_STACK
883 *         is TRUE.
884 *
885 */
886
887void _CPU_Install_interrupt_stack( void );
888
889/*
890 *  _CPU_Thread_Idle_body
891 *
892 *  This routine is the CPU dependent IDLE thread body.
893 *
894 *  NOTE:  It need only be provided if CPU_PROVIDES_IDLE_THREAD_BODY
895 *         is TRUE.
896 *
897 */
898
899void *_CPU_Thread_Idle_body( uintptr_t ignored );
900
901/*
902 *  _CPU_Context_switch
903 *
904 *  This routine switches from the run context to the heir context.
905 *
906 *  epiphany Specific Information:
907 *
908 *  Please see the comments in the .c file for a description of how
909 *  this function works. There are several things to be aware of.
910 */
911
912void _CPU_Context_switch(
913  Context_Control  *run,
914  Context_Control  *heir
915);
916
917/*
918 *  _CPU_Context_restore
919 *
920 *  This routine is generally used only to restart self in an
921 *  efficient manner.  It may simply be a label in _CPU_Context_switch.
922 *
923 *  NOTE: May be unnecessary to reload some registers.
924 *
925 */
926
927void _CPU_Context_restore(
928  Context_Control *new_context
929) RTEMS_NO_RETURN;
930
931/*
932 *  _CPU_Context_save_fp
933 *
934 *  This routine saves the floating point context passed to it.
935 *
936 */
937
938void _CPU_Context_save_fp(
939  void **fp_context_ptr
940);
941
942/*
943 *  _CPU_Context_restore_fp
944 *
945 *  This routine restores the floating point context passed to it.
946 *
947 */
948
949void _CPU_Context_restore_fp(
950  void **fp_context_ptr
951);
952
953/*  The following routine swaps the endian format of an unsigned int.
954 *  It must be static because it is referenced indirectly.
955 *
956 *  This version will work on any processor, but if there is a better
957 *  way for your CPU PLEASE use it.  The most common way to do this is to:
958 *
959 *     swap least significant two bytes with 16-bit rotate
960 *     swap upper and lower 16-bits
961 *     swap most significant two bytes with 16-bit rotate
962 *
963 *  Some CPUs have special instructions which swap a 32-bit quantity in
964 *  a single instruction (e.g. i486).  It is probably best to avoid
965 *  an "endian swapping control bit" in the CPU.  One good reason is
966 *  that interrupts would probably have to be disabled to insure that
967 *  an interrupt does not try to access the same "chunk" with the wrong
968 *  endian.  Another good reason is that on some CPUs, the endian bit
969 *  endianness for ALL fetches -- both code and data -- so the code
970 *  will be fetched incorrectly.
971 *
972 */
973
974static inline unsigned int CPU_swap_u32(
975  unsigned int value
976)
977{
978  uint32_t   byte1, byte2, byte3, byte4, swapped;
979
980  byte4 = (value >> 24) & 0xff;
981  byte3 = (value >> 16) & 0xff;
982  byte2 = (value >> 8)  & 0xff;
983  byte1 =  value        & 0xff;
984
985  swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
986  return( swapped );
987}
988
989#define CPU_swap_u16( value ) \
990  (((value&0xff) << 8) | ((value >> 8)&0xff))
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
1004typedef uint32_t CPU_Counter_ticks;
1005
1006CPU_Counter_ticks _CPU_Counter_read( void );
1007
1008static inline CPU_Counter_ticks _CPU_Counter_difference(
1009  CPU_Counter_ticks second,
1010  CPU_Counter_ticks first
1011)
1012{
1013  return second - first;
1014}
1015
1016#ifdef RTEMS_SMP
1017  /**
1018   * @brief Performs CPU specific SMP initialization in the context of the boot
1019   * processor.
1020   *
1021   * This function is invoked on the boot processor during system
1022   * initialization.  All interrupt stacks are allocated at this point in case
1023   * the CPU port allocates the interrupt stacks.  This function is called
1024   * before _CPU_SMP_Start_processor() or _CPU_SMP_Finalize_initialization() is
1025   * used.
1026   *
1027   * @return The count of physically or virtually available processors.
1028   * Depending on the configuration the application may use not all processors.
1029   */
1030  uint32_t _CPU_SMP_Initialize( void );
1031
1032  /**
1033   * @brief Starts a processor specified by its index.
1034   *
1035   * This function is invoked on the boot processor during system
1036   * initialization.
1037   *
1038   * This function will be called after _CPU_SMP_Initialize().
1039   *
1040   * @param[in] cpu_index The processor index.
1041   *
1042   * @retval true Successful operation.
1043   * @retval false Unable to start this processor.
1044   */
1045  bool _CPU_SMP_Start_processor( uint32_t cpu_index );
1046
1047  /**
1048   * @brief Performs final steps of CPU specific SMP initialization in the
1049   * context of the boot processor.
1050   *
1051   * This function is invoked on the boot processor during system
1052   * initialization.
1053   *
1054   * This function will be called after all processors requested by the
1055   * application have been started.
1056   *
1057   * @param[in] cpu_count The minimum value of the count of processors
1058   * requested by the application configuration and the count of physically or
1059   * virtually available processors.
1060   */
1061  void _CPU_SMP_Finalize_initialization( uint32_t cpu_count );
1062
1063  /**
1064   * @brief Returns the index of the current processor.
1065   *
1066   * An architecture specific method must be used to obtain the index of the
1067   * current processor in the system.  The set of processor indices is the
1068   * range of integers starting with zero up to the processor count minus one.
1069   */
1070   uint32_t _CPU_SMP_Get_current_processor( void );
1071
1072  /**
1073   * @brief Sends an inter-processor interrupt to the specified target
1074   * processor.
1075   *
1076   * This operation is undefined for target processor indices out of range.
1077   *
1078   * @param[in] target_processor_index The target processor index.
1079   */
1080  void _CPU_SMP_Send_interrupt( uint32_t target_processor_index );
1081
1082  /**
1083   * @brief Broadcasts a processor event.
1084   *
1085   * Some architectures provide a low-level synchronization primitive for
1086   * processors in a multi-processor environment.  Processors waiting for this
1087   * event may go into a low-power state and stop generating system bus
1088   * transactions.  This function must ensure that preceding store operations
1089   * can be observed by other processors.
1090   *
1091   * @see _CPU_SMP_Processor_event_receive().
1092   */
1093  void _CPU_SMP_Processor_event_broadcast( void );
1094
1095  /**
1096   * @brief Receives a processor event.
1097   *
1098   * This function will wait for the processor event and may wait forever if no
1099   * such event arrives.
1100   *
1101   * @see _CPU_SMP_Processor_event_broadcast().
1102   */
1103  static inline void _CPU_SMP_Processor_event_receive( void )
1104  {
1105    __asm__ volatile ( "" : : : "memory" );
1106  }
1107
1108  /**
1109   * @brief Gets the is executing indicator of the thread context.
1110   *
1111   * @param[in] context The context.
1112   */
1113  static inline bool _CPU_Context_Get_is_executing(
1114    const Context_Control *context
1115  )
1116  {
1117    return context->is_executing;
1118  }
1119
1120  /**
1121   * @brief Sets the is executing indicator of the thread context.
1122   *
1123   * @param[in] context The context.
1124   * @param[in] is_executing The new value for the is executing indicator.
1125   */
1126  static inline void _CPU_Context_Set_is_executing(
1127    Context_Control *context,
1128    bool is_executing
1129  )
1130  {
1131    context->is_executing = is_executing;
1132  }
1133#endif /* RTEMS_SMP */
1134
1135#endif /* ASM */
1136
1137#ifdef __cplusplus
1138}
1139#endif
1140
1141#endif
Note: See TracBrowser for help on using the repository browser.