source: rtems/cpukit/score/cpu/epiphany/rtems/score/cpu.h @ 01b32d4

5
Last change on this file since 01b32d4 was 01b32d4, checked in by Sebastian Huber <sebastian.huber@…>, on 01/25/16 at 07:54:17

score: Delete obsolete CPU_TIMESTAMP_* defines

Update #2271.

  • Property mode set to 100644
File size: 35.4 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/*
264 *  The following is the variable attribute used to force alignment
265 *  of critical RTEMS structures.  On some processors it may make
266 *  sense to have these aligned on tighter boundaries than
267 *  the minimum requirements of the compiler in order to have as
268 *  much of the critical data area as possible in a cache line.
269 *
270 *  The placement of this macro in the declaration of the variables
271 *  is based on the syntactically requirements of the GNU C
272 *  "__attribute__" extension.  For example with GNU C, use
273 *  the following to force a structures to a 32 byte boundary.
274 *
275 *      __attribute__ ((aligned (32)))
276 *
277 *  NOTE:  Currently only the Priority Bit Map table uses this feature.
278 *         To benefit from using this, the data must be heavily
279 *         used so it will stay in the cache and used frequently enough
280 *         in the executive to justify turning this on.
281 *
282 */
283
284#define CPU_STRUCTURE_ALIGNMENT __attribute__ ((aligned (64)))
285
286/*
287 *  Define what is required to specify how the network to host conversion
288 *  routines are handled.
289 *
290 *  epiphany Specific Information:
291 *
292 *  This version of RTEMS is designed specifically to run with
293 *  big endian architectures. If you want little endian, you'll
294 *  have to make the appropriate adjustments here and write
295 *  efficient routines for byte swapping. The epiphany architecture
296 *  doesn't do this very well.
297 */
298
299#define CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES     FALSE
300#define CPU_BIG_ENDIAN                           FALSE
301#define CPU_LITTLE_ENDIAN                        TRUE
302
303/*
304 *  The following defines the number of bits actually used in the
305 *  interrupt field of the task mode.  How those bits map to the
306 *  CPU interrupt levels is defined by the routine _CPU_ISR_Set_level().
307 *
308 */
309
310#define CPU_MODES_INTERRUPT_MASK   0x00000001
311
312/*
313 *  Processor defined structures required for cpukit/score.
314 */
315
316/*
317 * Contexts
318 *
319 *  Generally there are 2 types of context to save.
320 *     1. Interrupt registers to save
321 *     2. Task level registers to save
322 *
323 *  This means we have the following 3 context items:
324 *     1. task level context stuff::  Context_Control
325 *     2. floating point task stuff:: Context_Control_fp
326 *     3. special interrupt level context :: Context_Control_interrupt
327 *
328 *  On some processors, it is cost-effective to save only the callee
329 *  preserved registers during a task context switch.  This means
330 *  that the ISR code needs to save those registers which do not
331 *  persist across function calls.  It is not mandatory to make this
332 *  distinctions between the caller/callee saves registers for the
333 *  purpose of minimizing context saved during task switch and on interrupts.
334 *  If the cost of saving extra registers is minimal, simplicity is the
335 *  choice.  Save the same context on interrupt entry as for tasks in
336 *  this case.
337 *
338 *  Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
339 *  care should be used in designing the context area.
340 *
341 *  On some CPUs with hardware floating point support, the Context_Control_fp
342 *  structure will not be used or it simply consist of an array of a
343 *  fixed number of bytes.   This is done when the floating point context
344 *  is dumped by a "FP save context" type instruction and the format
345 *  is not really defined by the CPU.  In this case, there is no need
346 *  to figure out the exact format -- only the size.  Of course, although
347 *  this is enough information for RTEMS, it is probably not enough for
348 *  a debugger such as gdb.  But that is another problem.
349 *
350 *
351 */
352#ifndef ASM
353
354typedef struct {
355  uint32_t  r[64];
356
357  uint32_t status;
358  uint32_t config;
359  uint32_t iret;
360
361#ifdef RTEMS_SMP
362    /**
363     * @brief On SMP configurations the thread context must contain a boolean
364     * indicator to signal if this context is executing on a processor.
365     *
366     * This field must be updated during a context switch.  The context switch
367     * to the heir must wait until the heir context indicates that it is no
368     * longer executing on a processor.  The context switch must also check if
369     * a thread dispatch is necessary to honor updates of the heir thread for
370     * this processor.  This indicator must be updated using an atomic test and
371     * set operation to ensure that at most one processor uses the heir
372     * context at the same time.
373     *
374     * @code
375     * void _CPU_Context_switch(
376     *   Context_Control *executing,
377     *   Context_Control *heir
378     * )
379     * {
380     *   save( executing );
381     *
382     *   executing->is_executing = false;
383     *   memory_barrier();
384     *
385     *   if ( test_and_set( &heir->is_executing ) ) {
386     *     do {
387     *       Per_CPU_Control *cpu_self = _Per_CPU_Get_snapshot();
388     *
389     *       if ( cpu_self->dispatch_necessary ) {
390     *         heir = _Thread_Get_heir_and_make_it_executing( cpu_self );
391     *       }
392     *     } while ( test_and_set( &heir->is_executing ) );
393     *   }
394     *
395     *   restore( heir );
396     * }
397     * @endcode
398     */
399    volatile bool is_executing;
400#endif
401} Context_Control;
402
403#define _CPU_Context_Get_SP( _context ) \
404  (_context)->r[13]
405
406typedef struct {
407  /** FPU registers are listed here */
408  double  some_float_register;
409} Context_Control_fp;
410
411typedef Context_Control CPU_Interrupt_frame;
412
413/*
414 *  The size of the floating point context area.  On some CPUs this
415 *  will not be a "sizeof" because the format of the floating point
416 *  area is not defined -- only the size is.  This is usually on
417 *  CPUs with a "floating point save context" instruction.
418 *
419 *  epiphany Specific Information:
420 *
421 */
422
423#define CPU_CONTEXT_FP_SIZE  0
424SCORE_EXTERN Context_Control_fp  _CPU_Null_fp_context;
425
426/*
427 *  Amount of extra stack (above minimum stack size) required by
428 *  MPCI receive server thread.  Remember that in a multiprocessor
429 *  system this thread must exist and be able to process all directives.
430 *
431 */
432
433#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
434
435/*
436 *  Should be large enough to run all RTEMS tests.  This insures
437 *  that a "reasonable" small application should not have any problems.
438 *
439 */
440
441#define CPU_STACK_MINIMUM_SIZE  4096
442
443/*
444 *  CPU's worst alignment requirement for data types on a byte boundary.  This
445 *  alignment does not take into account the requirements for the stack.
446 *
447 */
448
449#define CPU_ALIGNMENT 8
450
451/*
452 *  This is defined if the port has a special way to report the ISR nesting
453 *  level.  Most ports maintain the variable _ISR_Nest_level.
454 */
455#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
456
457/*
458 *  This number corresponds to the byte alignment requirement for the
459 *  heap handler.  This alignment requirement may be stricter than that
460 *  for the data types alignment specified by CPU_ALIGNMENT.  It is
461 *  common for the heap to follow the same alignment requirement as
462 *  CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict enough for the heap,
463 *  then this should be set to CPU_ALIGNMENT.
464 *
465 *  NOTE:  This does not have to be a power of 2 although it should be
466 *         a multiple of 2 greater than or equal to 2.  The requirement
467 *         to be a multiple of 2 is because the heap uses the least
468 *         significant field of the front and back flags to indicate
469 *         that a block is in use or free.  So you do not want any odd
470 *         length blocks really putting length data in that bit.
471 *
472 *         On byte oriented architectures, CPU_HEAP_ALIGNMENT normally will
473 *         have to be greater or equal to than CPU_ALIGNMENT to ensure that
474 *         elements allocated from the heap meet all restrictions.
475 *
476 */
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 */
492
493#define CPU_PARTITION_ALIGNMENT    CPU_ALIGNMENT
494
495/*
496 *  This number corresponds to the byte alignment requirement for the
497 *  stack.  This alignment requirement may be stricter than that for the
498 *  data types alignment specified by CPU_ALIGNMENT.  If the CPU_ALIGNMENT
499 *  is strict enough for the stack, then this should be set to 0.
500 *
501 *  NOTE:  This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
502 *
503 */
504
505#define CPU_STACK_ALIGNMENT        8
506
507/* ISR handler macros */
508
509/*
510 *  Support routine to initialize the RTEMS vector table after it is allocated.
511 *
512 *  NO_CPU Specific Information:
513 *
514 *  XXX document implementation including references if appropriate
515 */
516
517#define _CPU_Initialize_vectors()
518
519/*
520 *  Disable all interrupts for an RTEMS critical section.  The previous
521 *  level is returned in _level.
522 *
523 */
524
525static inline uint32_t epiphany_interrupt_disable( void )
526{
527  uint32_t sr;
528  __asm__ __volatile__ ("movfs %[sr], status \n" : [sr] "=r" (sr):);
529  __asm__ __volatile__("gid \n");
530  return sr;
531}
532
533static inline void epiphany_interrupt_enable(uint32_t level)
534{
535  __asm__ __volatile__("gie \n");
536  __asm__ __volatile__ ("movts status, %[level] \n" :: [level] "r" (level):);
537}
538
539#define _CPU_ISR_Disable( _level ) \
540    _level = epiphany_interrupt_disable()
541
542/*
543 *  Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
544 *  This indicates the end of an RTEMS critical section.  The parameter
545 *  _level is not modified.
546 *
547 */
548
549#define _CPU_ISR_Enable( _level )  \
550  epiphany_interrupt_enable( _level )
551
552/*
553 *  This temporarily restores the interrupt to _level before immediately
554 *  disabling them again.  This is used to divide long RTEMS critical
555 *  sections into two or more parts.  The parameter _level is not
556 *  modified.
557 *
558 */
559
560#define _CPU_ISR_Flash( _level ) \
561  do{ \
562      if ( (_level & 0x2) != 0 ) \
563        _CPU_ISR_Enable( _level ); \
564      epiphany_interrupt_disable(); \
565    } while(0)
566
567/*
568 *  Map interrupt level in task mode onto the hardware that the CPU
569 *  actually provides.  Currently, interrupt levels which do not
570 *  map onto the CPU in a generic fashion are undefined.  Someday,
571 *  it would be nice if these were "mapped" by the application
572 *  via a callout.  For example, m68k has 8 levels 0 - 7, levels
573 *  8 - 255 would be available for bsp/application specific meaning.
574 *  This could be used to manage a programmable interrupt controller
575 *  via the rtems_task_mode directive.
576 *
577 *  The get routine usually must be implemented as a subroutine.
578 *
579 */
580
581void _CPU_ISR_Set_level( uint32_t level );
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 */
610
611/**
612 * @brief Account for GCC red-zone
613 *
614 * The following macro is used when initializing task's stack
615 * to account for GCC red-zone.
616 */
617
618#define EPIPHANY_GCC_RED_ZONE_SIZE 128
619
620/**
621 * @brief Initializes the CPU context.
622 *
623 * The following steps are performed:
624 *  - setting a starting address
625 *  - preparing the stack
626 *  - preparing the stack and frame pointers
627 *  - setting the proper interrupt level in the context
628 *
629 * @param[in] context points to the context area
630 * @param[in] stack_area_begin is the low address of the allocated stack area
631 * @param[in] stack_area_size is the size of the stack area in bytes
632 * @param[in] new_level is the interrupt level for the task
633 * @param[in] entry_point is the task's entry point
634 * @param[in] is_fp is set to @c true if the task is a floating point task
635 * @param[in] tls_area is the thread-local storage (TLS) area
636 */
637void _CPU_Context_Initialize(
638  Context_Control *context,
639  void *stack_area_begin,
640  size_t stack_area_size,
641  uint32_t new_level,
642  void (*entry_point)( void ),
643  bool is_fp,
644  void *tls_area
645);
646
647/*
648 *  This routine is responsible for somehow restarting the currently
649 *  executing task.  If you are lucky, then all that is necessary
650 *  is restoring the context.  Otherwise, there will need to be
651 *  a special assembly routine which does something special in this
652 *  case.  Context_Restore should work most of the time.  It will
653 *  not work if restarting self conflicts with the stack frame
654 *  assumptions of restoring a context.
655 *
656 */
657
658#define _CPU_Context_Restart_self( _the_context ) \
659   _CPU_Context_restore( (_the_context) )
660
661/*
662 *  The purpose of this macro is to allow the initial pointer into
663 *  a floating point context area (used to save the floating point
664 *  context) to be at an arbitrary place in the floating point
665 *  context area.
666 *
667 *  This is necessary because some FP units are designed to have
668 *  their context saved as a stack which grows into lower addresses.
669 *  Other FP units can be saved by simply moving registers into offsets
670 *  from the base of the context area.  Finally some FP units provide
671 *  a "dump context" instruction which could fill in from high to low
672 *  or low to high based on the whim of the CPU designers.
673 *
674 */
675
676#define _CPU_Context_Fp_start( _base, _offset ) \
677   ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
678
679/*
680 *  This routine initializes the FP context area passed to it to.
681 *  There are a few standard ways in which to initialize the
682 *  floating point context.  The code included for this macro assumes
683 *  that this is a CPU in which a "initial" FP context was saved into
684 *  _CPU_Null_fp_context and it simply copies it to the destination
685 *  context passed to it.
686 *
687 *  Other models include (1) not doing anything, and (2) putting
688 *  a "null FP status word" in the correct place in the FP context.
689 *
690 */
691
692#define _CPU_Context_Initialize_fp( _destination ) \
693  { \
694   *(*(_destination)) = _CPU_Null_fp_context; \
695  }
696
697/* end of Context handler macros */
698
699/* Fatal Error manager macros */
700
701/*
702 *  This routine copies _error into a known place -- typically a stack
703 *  location or a register, optionally disables interrupts, and
704 *  halts/stops the CPU.
705 *
706 */
707
708#define _CPU_Fatal_halt(_source, _error ) \
709          printk("Fatal Error %d.%d Halted\n",_source, _error); \
710          asm("trap 3" :: "r" (_error)); \
711          for(;;)
712
713/* end of Fatal Error manager macros */
714
715/* Bitfield handler macros */
716
717/*
718 *  This routine sets _output to the bit number of the first bit
719 *  set in _value.  _value is of CPU dependent type Priority_Bit_map_control.
720 *  This type may be either 16 or 32 bits wide although only the 16
721 *  least significant bits will be used.
722 *
723 *  There are a number of variables in using a "find first bit" type
724 *  instruction.
725 *
726 *    (1) What happens when run on a value of zero?
727 *    (2) Bits may be numbered from MSB to LSB or vice-versa.
728 *    (3) The numbering may be zero or one based.
729 *    (4) The "find first bit" instruction may search from MSB or LSB.
730 *
731 *  RTEMS guarantees that (1) will never happen so it is not a concern.
732 *  (2),(3), (4) are handled by the macros _CPU_Priority_mask() and
733 *  _CPU_Priority_bits_index().  These three form a set of routines
734 *  which must logically operate together.  Bits in the _value are
735 *  set and cleared based on masks built by _CPU_Priority_mask().
736 *  The basic major and minor values calculated by _Priority_Major()
737 *  and _Priority_Minor() are "massaged" by _CPU_Priority_bits_index()
738 *  to properly range between the values returned by the "find first bit"
739 *  instruction.  This makes it possible for _Priority_Get_highest() to
740 *  calculate the major and directly index into the minor table.
741 *  This mapping is necessary to ensure that 0 (a high priority major/minor)
742 *  is the first bit found.
743 *
744 *  This entire "find first bit" and mapping process depends heavily
745 *  on the manner in which a priority is broken into a major and minor
746 *  components with the major being the 4 MSB of a priority and minor
747 *  the 4 LSB.  Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
748 *  priority.  And (15 << 4) + 14 corresponds to priority 254 -- the next
749 *  to the lowest priority.
750 *
751 *  If your CPU does not have a "find first bit" instruction, then
752 *  there are ways to make do without it.  Here are a handful of ways
753 *  to implement this in software:
754 *
755 *    - a series of 16 bit test instructions
756 *    - a "binary search using if's"
757 *    - _number = 0
758 *      if _value > 0x00ff
759 *        _value >>=8
760 *        _number = 8;
761 *
762 *      if _value > 0x0000f
763 *        _value >=8
764 *        _number += 4
765 *
766 *      _number += bit_set_table[ _value ]
767 *
768 *    where bit_set_table[ 16 ] has values which indicate the first
769 *      bit set
770 *
771 */
772
773  /* #define CPU_USE_GENERIC_BITFIELD_CODE FALSE */
774#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
775#define CPU_USE_GENERIC_BITFIELD_DATA TRUE
776
777#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
778
779#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
780  { \
781    (_output) = 0;   /* do something to prevent warnings */ \
782  }
783#endif
784
785/* end of Bitfield handler macros */
786
787/*
788 *  This routine builds the mask which corresponds to the bit fields
789 *  as searched by _CPU_Bitfield_Find_first_bit().  See the discussion
790 *  for that routine.
791 *
792 */
793
794#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
795
796#define _CPU_Priority_Mask( _bit_number ) \
797    (1 << _bit_number)
798
799#endif
800
801/*
802 *  This routine translates the bit numbers returned by
803 *  _CPU_Bitfield_Find_first_bit() into something suitable for use as
804 *  a major or minor component of a priority.  See the discussion
805 *  for that routine.
806 *
807 */
808
809#if (CPU_USE_GENERIC_BITFIELD_CODE == FALSE)
810
811#define _CPU_Priority_bits_index( _priority ) \
812  (_priority)
813
814#endif
815
816typedef struct {
817/* There is no CPU specific per-CPU state */
818} CPU_Per_CPU_control;
819#endif /* ASM */
820
821/**
822 * Size of a pointer.
823 *
824 * This must be an integer literal that can be used by the assembler.  This
825 * value will be used to calculate offsets of structure members.  These
826 * offsets will be used in assembler code.
827 */
828#define CPU_SIZEOF_POINTER 4
829#define CPU_EXCEPTION_FRAME_SIZE 260
830#define CPU_PER_CPU_CONTROL_SIZE 0
831
832#ifndef ASM
833typedef uint16_t Priority_bit_map_Word;
834
835typedef struct {
836  uint32_t r[62];
837  uint32_t status;
838  uint32_t config;
839  uint32_t iret;
840} CPU_Exception_frame;
841
842/**
843 * @brief Prints the exception frame via printk().
844 *
845 * @see rtems_fatal() and RTEMS_FATAL_SOURCE_EXCEPTION.
846 */
847void _CPU_Exception_frame_print( const CPU_Exception_frame *frame );
848
849
850/* end of Priority handler macros */
851
852/* functions */
853
854/*
855 *  _CPU_Initialize
856 *
857 *  This routine performs CPU dependent initialization.
858 *
859 */
860
861void _CPU_Initialize(
862  void
863);
864
865/*
866 *  _CPU_ISR_install_raw_handler
867 *
868 *  This routine installs a "raw" interrupt handler directly into the
869 *  processor's vector table.
870 *
871 */
872
873void _CPU_ISR_install_raw_handler(
874  uint32_t    vector,
875  proc_ptr    new_handler,
876  proc_ptr   *old_handler
877);
878
879/*
880 *  _CPU_ISR_install_vector
881 *
882 *  This routine installs an interrupt vector.
883 *
884 *  NO_CPU Specific Information:
885 *
886 *  XXX document implementation including references if appropriate
887 */
888
889void _CPU_ISR_install_vector(
890  uint32_t    vector,
891  proc_ptr   new_handler,
892  proc_ptr   *old_handler
893);
894
895/*
896 *  _CPU_Install_interrupt_stack
897 *
898 *  This routine installs the hardware interrupt stack pointer.
899 *
900 *  NOTE:  It need only be provided if CPU_HAS_HARDWARE_INTERRUPT_STACK
901 *         is TRUE.
902 *
903 */
904
905void _CPU_Install_interrupt_stack( void );
906
907/*
908 *  _CPU_Thread_Idle_body
909 *
910 *  This routine is the CPU dependent IDLE thread body.
911 *
912 *  NOTE:  It need only be provided if CPU_PROVIDES_IDLE_THREAD_BODY
913 *         is TRUE.
914 *
915 */
916
917void *_CPU_Thread_Idle_body( uintptr_t ignored );
918
919/*
920 *  _CPU_Context_switch
921 *
922 *  This routine switches from the run context to the heir context.
923 *
924 *  epiphany Specific Information:
925 *
926 *  Please see the comments in the .c file for a description of how
927 *  this function works. There are several things to be aware of.
928 */
929
930void _CPU_Context_switch(
931  Context_Control  *run,
932  Context_Control  *heir
933);
934
935/*
936 *  _CPU_Context_restore
937 *
938 *  This routine is generally used only to restart self in an
939 *  efficient manner.  It may simply be a label in _CPU_Context_switch.
940 *
941 *  NOTE: May be unnecessary to reload some registers.
942 *
943 */
944
945void _CPU_Context_restore(
946  Context_Control *new_context
947) RTEMS_NO_RETURN;
948
949/*
950 *  _CPU_Context_save_fp
951 *
952 *  This routine saves the floating point context passed to it.
953 *
954 */
955
956void _CPU_Context_save_fp(
957  void **fp_context_ptr
958);
959
960/*
961 *  _CPU_Context_restore_fp
962 *
963 *  This routine restores the floating point context passed to it.
964 *
965 */
966
967void _CPU_Context_restore_fp(
968  void **fp_context_ptr
969);
970
971/*  The following routine swaps the endian format of an unsigned int.
972 *  It must be static because it is referenced indirectly.
973 *
974 *  This version will work on any processor, but if there is a better
975 *  way for your CPU PLEASE use it.  The most common way to do this is to:
976 *
977 *     swap least significant two bytes with 16-bit rotate
978 *     swap upper and lower 16-bits
979 *     swap most significant two bytes with 16-bit rotate
980 *
981 *  Some CPUs have special instructions which swap a 32-bit quantity in
982 *  a single instruction (e.g. i486).  It is probably best to avoid
983 *  an "endian swapping control bit" in the CPU.  One good reason is
984 *  that interrupts would probably have to be disabled to insure that
985 *  an interrupt does not try to access the same "chunk" with the wrong
986 *  endian.  Another good reason is that on some CPUs, the endian bit
987 *  endianness for ALL fetches -- both code and data -- so the code
988 *  will be fetched incorrectly.
989 *
990 */
991
992static inline unsigned int CPU_swap_u32(
993  unsigned int value
994)
995{
996  uint32_t   byte1, byte2, byte3, byte4, swapped;
997
998  byte4 = (value >> 24) & 0xff;
999  byte3 = (value >> 16) & 0xff;
1000  byte2 = (value >> 8)  & 0xff;
1001  byte1 =  value        & 0xff;
1002
1003  swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
1004  return( swapped );
1005}
1006
1007#define CPU_swap_u16( value ) \
1008  (((value&0xff) << 8) | ((value >> 8)&0xff))
1009
1010static inline void _CPU_Context_volatile_clobber( uintptr_t pattern )
1011{
1012  /* TODO */
1013}
1014
1015static inline void _CPU_Context_validate( uintptr_t pattern )
1016{
1017  while (1) {
1018    /* TODO */
1019  }
1020}
1021
1022typedef uint32_t CPU_Counter_ticks;
1023
1024CPU_Counter_ticks _CPU_Counter_read( void );
1025
1026static inline CPU_Counter_ticks _CPU_Counter_difference(
1027  CPU_Counter_ticks second,
1028  CPU_Counter_ticks first
1029)
1030{
1031  return second - first;
1032}
1033
1034#ifdef RTEMS_SMP
1035  /**
1036   * @brief Performs CPU specific SMP initialization in the context of the boot
1037   * processor.
1038   *
1039   * This function is invoked on the boot processor during system
1040   * initialization.  All interrupt stacks are allocated at this point in case
1041   * the CPU port allocates the interrupt stacks.  This function is called
1042   * before _CPU_SMP_Start_processor() or _CPU_SMP_Finalize_initialization() is
1043   * used.
1044   *
1045   * @return The count of physically or virtually available processors.
1046   * Depending on the configuration the application may use not all processors.
1047   */
1048  uint32_t _CPU_SMP_Initialize( void );
1049
1050  /**
1051   * @brief Starts a processor specified by its index.
1052   *
1053   * This function is invoked on the boot processor during system
1054   * initialization.
1055   *
1056   * This function will be called after _CPU_SMP_Initialize().
1057   *
1058   * @param[in] cpu_index The processor index.
1059   *
1060   * @retval true Successful operation.
1061   * @retval false Unable to start this processor.
1062   */
1063  bool _CPU_SMP_Start_processor( uint32_t cpu_index );
1064
1065  /**
1066   * @brief Performs final steps of CPU specific SMP initialization in the
1067   * context of the boot processor.
1068   *
1069   * This function is invoked on the boot processor during system
1070   * initialization.
1071   *
1072   * This function will be called after all processors requested by the
1073   * application have been started.
1074   *
1075   * @param[in] cpu_count The minimum value of the count of processors
1076   * requested by the application configuration and the count of physically or
1077   * virtually available processors.
1078   */
1079  void _CPU_SMP_Finalize_initialization( uint32_t cpu_count );
1080
1081  /**
1082   * @brief Returns the index of the current processor.
1083   *
1084   * An architecture specific method must be used to obtain the index of the
1085   * current processor in the system.  The set of processor indices is the
1086   * range of integers starting with zero up to the processor count minus one.
1087   */
1088   uint32_t _CPU_SMP_Get_current_processor( void );
1089
1090  /**
1091   * @brief Sends an inter-processor interrupt to the specified target
1092   * processor.
1093   *
1094   * This operation is undefined for target processor indices out of range.
1095   *
1096   * @param[in] target_processor_index The target processor index.
1097   */
1098  void _CPU_SMP_Send_interrupt( uint32_t target_processor_index );
1099
1100  /**
1101   * @brief Broadcasts a processor event.
1102   *
1103   * Some architectures provide a low-level synchronization primitive for
1104   * processors in a multi-processor environment.  Processors waiting for this
1105   * event may go into a low-power state and stop generating system bus
1106   * transactions.  This function must ensure that preceding store operations
1107   * can be observed by other processors.
1108   *
1109   * @see _CPU_SMP_Processor_event_receive().
1110   */
1111  void _CPU_SMP_Processor_event_broadcast( void );
1112
1113  /**
1114   * @brief Receives a processor event.
1115   *
1116   * This function will wait for the processor event and may wait forever if no
1117   * such event arrives.
1118   *
1119   * @see _CPU_SMP_Processor_event_broadcast().
1120   */
1121  static inline void _CPU_SMP_Processor_event_receive( void )
1122  {
1123    __asm__ volatile ( "" : : : "memory" );
1124  }
1125
1126  /**
1127   * @brief Gets the is executing indicator of the thread context.
1128   *
1129   * @param[in] context The context.
1130   */
1131  static inline bool _CPU_Context_Get_is_executing(
1132    const Context_Control *context
1133  )
1134  {
1135    return context->is_executing;
1136  }
1137
1138  /**
1139   * @brief Sets the is executing indicator of the thread context.
1140   *
1141   * @param[in] context The context.
1142   * @param[in] is_executing The new value for the is executing indicator.
1143   */
1144  static inline void _CPU_Context_Set_is_executing(
1145    Context_Control *context,
1146    bool is_executing
1147  )
1148  {
1149    context->is_executing = is_executing;
1150  }
1151#endif /* RTEMS_SMP */
1152
1153#endif /* ASM */
1154
1155#ifdef __cplusplus
1156}
1157#endif
1158
1159#endif
Note: See TracBrowser for help on using the repository browser.