source: rtems/cpukit/score/cpu/or1k/rtems/score/cpu.h @ 2711914f

5
Last change on this file since 2711914f was 84e6f15, checked in by Sebastian Huber <sebastian.huber@…>, on 11/10/16 at 11:02:28

score: Robust thread dispatch

On SMP configurations, it is a fatal error to call blocking operating
system with interrupts disabled, since this prevents delivery of
inter-processor interrupts. This could lead to executing threads which
are not allowed to execute resulting in undefined behaviour.

The ARM Cortex-M port has a similar problem, since the interrupt state
is not a part of the thread context.

Update #2811.

  • Property mode set to 100644
File size: 25.1 KB
Line 
1/**
2 * @file rtems/score/cpu.h
3 */
4
5/*
6 *  This include file contains macros pertaining to the Opencores
7 *  or1k processor family.
8 *
9 *  COPYRIGHT (c) 2014 Hesham ALMatary <heshamelmatary@gmail.com>
10 *  COPYRIGHT (c) 1989-1999.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.org/license/LICENSE.
16 *
17 *  This file adapted from no_cpu example of the RTEMS distribution.
18 *  The body has been modified for the Opencores OR1k implementation by
19 *  Chris Ziomkowski. <chris@asics.ws>
20 *
21 */
22
23#ifndef _OR1K_CPU_H
24#define _OR1K_CPU_H
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30
31#include <rtems/score/or1k.h>            /* pick up machine definitions */
32#include <rtems/score/or1k-utility.h>
33#include <rtems/score/types.h>
34#ifndef ASM
35#include <rtems/bspIo.h>
36#include <stdint.h>
37#include <stdio.h> /* for printk */
38#endif
39
40/* conditional compilation parameters */
41
42/*
43 *  Does RTEMS manage a dedicated interrupt stack in software?
44 *
45 *  If TRUE, then a stack is allocated in _ISR_Handler_initialization.
46 *  If FALSE, nothing is done.
47 *
48 *  If the CPU supports a dedicated interrupt stack in hardware,
49 *  then it is generally the responsibility of the BSP to allocate it
50 *  and set it up.
51 *
52 *  If the CPU does not support a dedicated interrupt stack, then
53 *  the porter has two options: (1) execute interrupts on the
54 *  stack of the interrupted task, and (2) have RTEMS manage a dedicated
55 *  interrupt stack.
56 *
57 *  If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
58 *
59 *  Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
60 *  CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
61 *  possible that both are FALSE for a particular CPU.  Although it
62 *  is unclear what that would imply about the interrupt processing
63 *  procedure on that CPU.
64 *
65 *  Currently, for or1k port, _ISR_Handler is responsible for switching to
66 *  RTEMS dedicated interrupt task.
67 *
68 */
69
70#define CPU_HAS_SOFTWARE_INTERRUPT_STACK TRUE
71
72/*
73 *  Does this CPU have hardware support for a dedicated interrupt stack?
74 *
75 *  If TRUE, then it must be installed during initialization.
76 *  If FALSE, then no installation is performed.
77 *
78 *  If this is TRUE, CPU_ALLOCATE_INTERRUPT_STACK should also be TRUE.
79 *
80 *  Only one of CPU_HAS_SOFTWARE_INTERRUPT_STACK and
81 *  CPU_HAS_HARDWARE_INTERRUPT_STACK should be set to TRUE.  It is
82 *  possible that both are FALSE for a particular CPU.  Although it
83 *  is unclear what that would imply about the interrupt processing
84 *  procedure on that CPU.
85 *
86 */
87
88#define CPU_HAS_HARDWARE_INTERRUPT_STACK FALSE
89
90/*
91 *  Does RTEMS allocate a dedicated interrupt stack in the Interrupt Manager?
92 *
93 *  If TRUE, then the memory is allocated during initialization.
94 *  If FALSE, then the memory is allocated during initialization.
95 *
96 *  This should be TRUE is CPU_HAS_SOFTWARE_INTERRUPT_STACK is TRUE
97 *  or CPU_INSTALL_HARDWARE_INTERRUPT_STACK is TRUE.
98 *
99 */
100
101#define CPU_ALLOCATE_INTERRUPT_STACK TRUE
102
103/*
104 *  Does the RTEMS invoke the user's ISR with the vector number and
105 *  a pointer to the saved interrupt frame (1) or just the vector
106 *  number (0)?
107 *
108 */
109
110#define CPU_ISR_PASSES_FRAME_POINTER TRUE
111
112/*
113 *  Does the CPU have hardware floating point?
114 *
115 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
116 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
117 *
118 *  If there is a FP coprocessor such as the i387 or mc68881, then
119 *  the answer is TRUE.
120 *
121 *  The macro name "OR1K_HAS_FPU" should be made CPU specific.
122 *  It indicates whether or not this CPU model has FP support.  For
123 *  example, it would be possible to have an i386_nofp CPU model
124 *  which set this to false to indicate that you have an i386 without
125 *  an i387 and wish to leave floating point support out of RTEMS.
126 *
127 *  The CPU_SOFTWARE_FP is used to indicate whether or not there
128 *  is software implemented floating point that must be context
129 *  switched.  The determination of whether or not this applies
130 *  is very tool specific and the state saved/restored is also
131 *  compiler specific.
132 *
133 *  Or1k Specific Information:
134 *
135 *  At this time there are no implementations of Or1k that are
136 *  expected to implement floating point. More importantly, the
137 *  floating point architecture is expected to change significantly
138 *  before such chips are fabricated.
139 */
140
141#define CPU_HARDWARE_FP     FALSE
142#define CPU_SOFTWARE_FP     FALSE
143
144/*
145 *  Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
146 *
147 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
148 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
149 *
150 *  If CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
151 *
152 */
153
154#define CPU_ALL_TASKS_ARE_FP     FALSE
155
156/*
157 *  Should the IDLE task have a floating point context?
158 *
159 *  If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
160 *  and it has a floating point context which is switched in and out.
161 *  If FALSE, then the IDLE task does not have a floating point context.
162 *
163 *  Setting this to TRUE negatively impacts the time required to preempt
164 *  the IDLE task from an interrupt because the floating point context
165 *  must be saved as part of the preemption.
166 *
167 */
168
169#define CPU_IDLE_TASK_IS_FP      FALSE
170
171/*
172 *  Should the saving of the floating point registers be deferred
173 *  until a context switch is made to another different floating point
174 *  task?
175 *
176 *  If TRUE, then the floating point context will not be stored until
177 *  necessary.  It will remain in the floating point registers and not
178 *  disturned until another floating point task is switched to.
179 *
180 *  If FALSE, then the floating point context is saved when a floating
181 *  point task is switched out and restored when the next floating point
182 *  task is restored.  The state of the floating point registers between
183 *  those two operations is not specified.
184 *
185 *  If the floating point context does NOT have to be saved as part of
186 *  interrupt dispatching, then it should be safe to set this to TRUE.
187 *
188 *  Setting this flag to TRUE results in using a different algorithm
189 *  for deciding when to save and restore the floating point context.
190 *  The deferred FP switch algorithm minimizes the number of times
191 *  the FP context is saved and restored.  The FP context is not saved
192 *  until a context switch is made to another, different FP task.
193 *  Thus in a system with only one FP task, the FP context will never
194 *  be saved or restored.
195 *
196 */
197
198#define CPU_USE_DEFERRED_FP_SWITCH       TRUE
199
200#define CPU_ENABLE_ROBUST_THREAD_DISPATCH FALSE
201
202/*
203 *  Does this port provide a CPU dependent IDLE task implementation?
204 *
205 *  If TRUE, then the routine _CPU_Thread_Idle_body
206 *  must be provided and is the default IDLE thread body instead of
207 *  _CPU_Thread_Idle_body.
208 *
209 *  If FALSE, then use the generic IDLE thread body if the BSP does
210 *  not provide one.
211 *
212 *  This is intended to allow for supporting processors which have
213 *  a low power or idle mode.  When the IDLE thread is executed, then
214 *  the CPU can be powered down.
215 *
216 *  The order of precedence for selecting the IDLE thread body is:
217 *
218 *    1.  BSP provided
219 *    2.  CPU dependent (if provided)
220 *    3.  generic (if no BSP and no CPU dependent)
221 *
222 */
223
224#define CPU_PROVIDES_IDLE_THREAD_BODY    TRUE
225
226/*
227 *  Does the stack grow up (toward higher addresses) or down
228 *  (toward lower addresses)?
229 *
230 *  If TRUE, then the grows upward.
231 *  If FALSE, then the grows toward smaller addresses.
232 *
233 */
234
235#define CPU_STACK_GROWS_UP               FALSE
236
237/* FIXME: Is this the right value? */
238#define CPU_CACHE_LINE_BYTES 32
239
240#define CPU_STRUCTURE_ALIGNMENT RTEMS_ALIGNED( CPU_CACHE_LINE_BYTES )
241
242/*
243 *  Define what is required to specify how the network to host conversion
244 *  routines are handled.
245 *
246 *  Or1k Specific Information:
247 *
248 *  This version of RTEMS is designed specifically to run with
249 *  big endian architectures. If you want little endian, you'll
250 *  have to make the appropriate adjustments here and write
251 *  efficient routines for byte swapping. The Or1k architecture
252 *  doesn't do this very well.
253 */
254
255#define CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES     FALSE
256#define CPU_BIG_ENDIAN                           TRUE
257#define CPU_LITTLE_ENDIAN                        FALSE
258
259/*
260 *  The following defines the number of bits actually used in the
261 *  interrupt field of the task mode.  How those bits map to the
262 *  CPU interrupt levels is defined by the routine _CPU_ISR_Set_level().
263 *
264 */
265
266#define CPU_MODES_INTERRUPT_MASK   0x00000001
267
268/*
269 *  Processor defined structures required for cpukit/score.
270 */
271
272
273/*
274 * Contexts
275 *
276 *  Generally there are 2 types of context to save.
277 *     1. Interrupt registers to save
278 *     2. Task level registers to save
279 *
280 *  This means we have the following 3 context items:
281 *     1. task level context stuff::  Context_Control
282 *     2. floating point task stuff:: Context_Control_fp
283 *     3. special interrupt level context :: Context_Control_interrupt
284 *
285 *  On some processors, it is cost-effective to save only the callee
286 *  preserved registers during a task context switch.  This means
287 *  that the ISR code needs to save those registers which do not
288 *  persist across function calls.  It is not mandatory to make this
289 *  distinctions between the caller/callee saves registers for the
290 *  purpose of minimizing context saved during task switch and on interrupts.
291 *  If the cost of saving extra registers is minimal, simplicity is the
292 *  choice.  Save the same context on interrupt entry as for tasks in
293 *  this case.
294 *
295 *  Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
296 *  care should be used in designing the context area.
297 *
298 *  On some CPUs with hardware floating point support, the Context_Control_fp
299 *  structure will not be used or it simply consist of an array of a
300 *  fixed number of bytes.   This is done when the floating point context
301 *  is dumped by a "FP save context" type instruction and the format
302 *  is not really defined by the CPU.  In this case, there is no need
303 *  to figure out the exact format -- only the size.  Of course, although
304 *  this is enough information for RTEMS, it is probably not enough for
305 *  a debugger such as gdb.  But that is another problem.
306 *
307 *
308 */
309#ifndef ASM
310#ifdef OR1K_64BIT_ARCH
311#define or1kreg uint64_t
312#else
313#define or1kreg uint32_t
314#endif
315
316typedef struct {
317  uint32_t  r1;     /* Stack pointer */
318  uint32_t  r2;     /* Frame pointer */
319  uint32_t  r3;
320  uint32_t  r4;
321  uint32_t  r5;
322  uint32_t  r6;
323  uint32_t  r7;
324  uint32_t  r8;
325  uint32_t  r9;
326  uint32_t  r10;
327  uint32_t  r11;
328  uint32_t  r12;
329  uint32_t  r13;
330  uint32_t  r14;
331  uint32_t  r15;
332  uint32_t  r16;
333  uint32_t  r17;
334  uint32_t  r18;
335  uint32_t  r19;
336  uint32_t  r20;
337  uint32_t  r21;
338  uint32_t  r22;
339  uint32_t  r23;
340  uint32_t  r24;
341  uint32_t  r25;
342  uint32_t  r26;
343  uint32_t  r27;
344  uint32_t  r28;
345  uint32_t  r29;
346  uint32_t  r30;
347  uint32_t  r31;
348
349  uint32_t  sr;  /* Current supervision register non persistent values */
350  uint32_t  epcr;
351  uint32_t  eear;
352  uint32_t  esr;
353} Context_Control;
354
355#define _CPU_Context_Get_SP( _context ) \
356  (_context)->r1
357
358typedef struct {
359  /** FPU registers are listed here */
360  double      some_float_register;
361} Context_Control_fp;
362
363typedef Context_Control CPU_Interrupt_frame;
364
365/*
366 *  The size of the floating point context area.  On some CPUs this
367 *  will not be a "sizeof" because the format of the floating point
368 *  area is not defined -- only the size is.  This is usually on
369 *  CPUs with a "floating point save context" instruction.
370 *
371 *  Or1k Specific Information:
372 *
373 */
374
375#define CPU_CONTEXT_FP_SIZE  0
376
377/*
378 *  Amount of extra stack (above minimum stack size) required by
379 *  MPCI receive server thread.  Remember that in a multiprocessor
380 *  system this thread must exist and be able to process all directives.
381 *
382 */
383
384#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
385
386/*
387 *  Should be large enough to run all RTEMS tests.  This insures
388 *  that a "reasonable" small application should not have any problems.
389 *
390 */
391
392#define CPU_STACK_MINIMUM_SIZE  4096
393
394/*
395 *  CPU's worst alignment requirement for data types on a byte boundary.  This
396 *  alignment does not take into account the requirements for the stack.
397 *
398 */
399
400#define CPU_ALIGNMENT  8
401
402/*
403 *  This is defined if the port has a special way to report the ISR nesting
404 *  level.  Most ports maintain the variable _ISR_Nest_level.
405 */
406#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
407
408/**
409 * Size of a pointer.
410 *
411 * This must be an integer literal that can be used by the assembler.  This
412 * value will be used to calculate offsets of structure members.  These
413 * offsets will be used in assembler code.
414 */
415#define CPU_SIZEOF_POINTER         4
416
417/*
418 *  This number corresponds to the byte alignment requirement for the
419 *  heap handler.  This alignment requirement may be stricter than that
420 *  for the data types alignment specified by CPU_ALIGNMENT.  It is
421 *  common for the heap to follow the same alignment requirement as
422 *  CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict enough for the heap,
423 *  then this should be set to CPU_ALIGNMENT.
424 *
425 *  NOTE:  This does not have to be a power of 2 although it should be
426 *         a multiple of 2 greater than or equal to 2.  The requirement
427 *         to be a multiple of 2 is because the heap uses the least
428 *         significant field of the front and back flags to indicate
429 *         that a block is in use or free.  So you do not want any odd
430 *         length blocks really putting length data in that bit.
431 *
432 *         On byte oriented architectures, CPU_HEAP_ALIGNMENT normally will
433 *         have to be greater or equal to than CPU_ALIGNMENT to ensure that
434 *         elements allocated from the heap meet all restrictions.
435 *
436 */
437
438#define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
439
440/*
441 *  This number corresponds to the byte alignment requirement for memory
442 *  buffers allocated by the partition manager.  This alignment requirement
443 *  may be stricter than that for the data types alignment specified by
444 *  CPU_ALIGNMENT.  It is common for the partition to follow the same
445 *  alignment requirement as CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict
446 *  enough for the partition, then this should be set to CPU_ALIGNMENT.
447 *
448 *  NOTE:  This does not have to be a power of 2.  It does have to
449 *         be greater or equal to than CPU_ALIGNMENT.
450 *
451 */
452
453#define CPU_PARTITION_ALIGNMENT    CPU_ALIGNMENT
454
455/*
456 *  This number corresponds to the byte alignment requirement for the
457 *  stack.  This alignment requirement may be stricter than that for the
458 *  data types alignment specified by CPU_ALIGNMENT.  If the CPU_ALIGNMENT
459 *  is strict enough for the stack, then this should be set to 0.
460 *
461 *  NOTE:  This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
462 *
463 */
464
465#define CPU_STACK_ALIGNMENT        0
466
467/* ISR handler macros */
468
469/*
470 *  Support routine to initialize the RTEMS vector table after it is allocated.
471 *
472 *  NO_CPU Specific Information:
473 *
474 *  XXX document implementation including references if appropriate
475 */
476
477#define _CPU_Initialize_vectors()
478
479/*
480 *  Disable all interrupts for an RTEMS critical section.  The previous
481 *  level is returned in _level.
482 *
483 */
484
485static inline uint32_t or1k_interrupt_disable( void )
486{
487  uint32_t sr;
488  sr = _OR1K_mfspr(CPU_OR1K_SPR_SR);
489
490  _OR1K_mtspr(CPU_OR1K_SPR_SR, (sr & ~CPU_OR1K_SPR_SR_IEE));
491
492  return sr;
493}
494
495static inline void or1k_interrupt_enable(uint32_t level)
496{
497  uint32_t sr;
498
499  /* Enable interrupts and restore rs */
500  sr = level | CPU_OR1K_SPR_SR_IEE | CPU_OR1K_SPR_SR_TEE;
501  _OR1K_mtspr(CPU_OR1K_SPR_SR, sr);
502
503}
504
505#define _CPU_ISR_Disable( _level ) \
506    _level = or1k_interrupt_disable()
507
508
509/*
510 *  Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
511 *  This indicates the end of an RTEMS critical section.  The parameter
512 *  _level is not modified.
513 *
514 */
515
516#define _CPU_ISR_Enable( _level )  \
517  or1k_interrupt_enable( _level )
518
519/*
520 *  This temporarily restores the interrupt to _level before immediately
521 *  disabling them again.  This is used to divide long RTEMS critical
522 *  sections into two or more parts.  The parameter _level is not
523 *  modified.
524 *
525 */
526
527#define _CPU_ISR_Flash( _level ) \
528  do{ \
529      _CPU_ISR_Enable( _level ); \
530      _OR1K_mtspr(CPU_OR1K_SPR_SR, (_level & ~CPU_OR1K_SPR_SR_IEE)); \
531    } while(0)
532
533RTEMS_INLINE_ROUTINE bool _CPU_ISR_Is_enabled( uint32_t level )
534{
535  return ( level & CPU_OR1K_SPR_SR ) != 0;
536}
537
538/*
539 *  Map interrupt level in task mode onto the hardware that the CPU
540 *  actually provides.  Currently, interrupt levels which do not
541 *  map onto the CPU in a generic fashion are undefined.  Someday,
542 *  it would be nice if these were "mapped" by the application
543 *  via a callout.  For example, m68k has 8 levels 0 - 7, levels
544 *  8 - 255 would be available for bsp/application specific meaning.
545 *  This could be used to manage a programmable interrupt controller
546 *  via the rtems_task_mode directive.
547 *
548 *  The get routine usually must be implemented as a subroutine.
549 *
550 */
551
552void _CPU_ISR_Set_level( uint32_t level );
553
554uint32_t _CPU_ISR_Get_level( void );
555
556/* end of ISR handler macros */
557
558/* Context handler macros */
559
560#define OR1K_FAST_CONTEXT_SWITCH_ENABLED FALSE
561/*
562 *  Initialize the context to a state suitable for starting a
563 *  task after a context restore operation.  Generally, this
564 *  involves:
565 *
566 *     - setting a starting address
567 *     - preparing the stack
568 *     - preparing the stack and frame pointers
569 *     - setting the proper interrupt level in the context
570 *     - initializing the floating point context
571 *
572 *  This routine generally does not set any unnecessary register
573 *  in the context.  The state of the "general data" registers is
574 *  undefined at task start time.
575 *
576 *  NOTE: This is_fp parameter is TRUE if the thread is to be a floating
577 *        point thread.  This is typically only used on CPUs where the
578 *        FPU may be easily disabled by software such as on the SPARC
579 *        where the PSR contains an enable FPU bit.
580 *
581 */
582
583/**
584 * @brief Initializes the CPU context.
585 *
586 * The following steps are performed:
587 *  - setting a starting address
588 *  - preparing the stack
589 *  - preparing the stack and frame pointers
590 *  - setting the proper interrupt level in the context
591 *
592 * @param[in] context points to the context area
593 * @param[in] stack_area_begin is the low address of the allocated stack area
594 * @param[in] stack_area_size is the size of the stack area in bytes
595 * @param[in] new_level is the interrupt level for the task
596 * @param[in] entry_point is the task's entry point
597 * @param[in] is_fp is set to @c true if the task is a floating point task
598 * @param[in] tls_area is the thread-local storage (TLS) area
599 */
600void _CPU_Context_Initialize(
601  Context_Control *context,
602  void *stack_area_begin,
603  size_t stack_area_size,
604  uint32_t new_level,
605  void (*entry_point)( void ),
606  bool is_fp,
607  void *tls_area
608);
609
610/*
611 *  This routine is responsible for somehow restarting the currently
612 *  executing task.  If you are lucky, then all that is necessary
613 *  is restoring the context.  Otherwise, there will need to be
614 *  a special assembly routine which does something special in this
615 *  case.  Context_Restore should work most of the time.  It will
616 *  not work if restarting self conflicts with the stack frame
617 *  assumptions of restoring a context.
618 *
619 */
620
621#define _CPU_Context_Restart_self( _the_context ) \
622   _CPU_Context_restore( (_the_context) );
623
624/*
625 *  The purpose of this macro is to allow the initial pointer into
626 *  a floating point context area (used to save the floating point
627 *  context) to be at an arbitrary place in the floating point
628 *  context area.
629 *
630 *  This is necessary because some FP units are designed to have
631 *  their context saved as a stack which grows into lower addresses.
632 *  Other FP units can be saved by simply moving registers into offsets
633 *  from the base of the context area.  Finally some FP units provide
634 *  a "dump context" instruction which could fill in from high to low
635 *  or low to high based on the whim of the CPU designers.
636 *
637 */
638
639#define _CPU_Context_Fp_start( _base, _offset ) \
640   ( (void *) _Addresses_Add_offset( (_base), (_offset) ) )
641
642#define _CPU_Context_Initialize_fp( _destination ) \
643  memset( *( _destination ), 0, CPU_CONTEXT_FP_SIZE );
644
645/* end of Context handler macros */
646
647/* Fatal Error manager macros */
648
649/*
650 *  This routine copies _error into a known place -- typically a stack
651 *  location or a register, optionally disables interrupts, and
652 *  halts/stops the CPU.
653 *
654 */
655
656#define _CPU_Fatal_halt(_source, _error ) \
657        printk("Fatal Error %d.%d Halted\n",_source, _error); \
658        _OR1KSIM_CPU_Halt(); \
659        for(;;)
660
661/* end of Fatal Error manager macros */
662
663#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
664
665#endif /* ASM */
666
667#define CPU_SIZEOF_POINTER 4
668
669#define CPU_MAXIMUM_PROCESSORS 32
670
671#ifndef ASM
672typedef uint32_t CPU_Counter_ticks;
673
674typedef struct {
675  uint32_t r[32];
676
677  /* The following registers must be saved if we have
678  fast context switch disabled and nested interrupt
679  levels are enabled.
680  */
681#if !OR1K_FAST_CONTEXT_SWITCH_ENABLED
682  uint32_t epcr; /* exception PC register */
683  uint32_t eear; /* exception effective address register */
684  uint32_t esr; /* exception supervision register */
685#endif
686
687} CPU_Exception_frame;
688
689/**
690 * @brief Prints the exception frame via printk().
691 *
692 * @see rtems_fatal() and RTEMS_FATAL_SOURCE_EXCEPTION.
693 */
694void _CPU_Exception_frame_print( const CPU_Exception_frame *frame );
695
696
697/* end of Priority handler macros */
698
699/* functions */
700
701/*
702 *  _CPU_Initialize
703 *
704 *  This routine performs CPU dependent initialization.
705 *
706 */
707
708void _CPU_Initialize(
709  void
710);
711
712/*
713 *  _CPU_ISR_install_raw_handler
714 *
715 *  This routine installs a "raw" interrupt handler directly into the
716 *  processor's vector table.
717 *
718 */
719
720void _CPU_ISR_install_raw_handler(
721  uint32_t    vector,
722  proc_ptr    new_handler,
723  proc_ptr   *old_handler
724);
725
726/*
727 *  _CPU_ISR_install_vector
728 *
729 *  This routine installs an interrupt vector.
730 *
731 *  NO_CPU Specific Information:
732 *
733 *  XXX document implementation including references if appropriate
734 */
735
736void _CPU_ISR_install_vector(
737  uint32_t    vector,
738  proc_ptr   new_handler,
739  proc_ptr   *old_handler
740);
741
742/*
743 *  _CPU_Install_interrupt_stack
744 *
745 *  This routine installs the hardware interrupt stack pointer.
746 *
747 *  NOTE:  It need only be provided if CPU_HAS_HARDWARE_INTERRUPT_STACK
748 *         is TRUE.
749 *
750 */
751
752void _CPU_Install_interrupt_stack( void );
753
754/*
755 *  _CPU_Thread_Idle_body
756 *
757 *  This routine is the CPU dependent IDLE thread body.
758 *
759 *  NOTE:  It need only be provided if CPU_PROVIDES_IDLE_THREAD_BODY
760 *         is TRUE.
761 *
762 */
763
764void *_CPU_Thread_Idle_body( uintptr_t ignored );
765
766/*
767 *  _CPU_Context_switch
768 *
769 *  This routine switches from the run context to the heir context.
770 *
771 *  Or1k Specific Information:
772 *
773 *  Please see the comments in the .c file for a description of how
774 *  this function works. There are several things to be aware of.
775 */
776
777void _CPU_Context_switch(
778  Context_Control  *run,
779  Context_Control  *heir
780);
781
782/*
783 *  _CPU_Context_restore
784 *
785 *  This routine is generally used only to restart self in an
786 *  efficient manner.  It may simply be a label in _CPU_Context_switch.
787 *
788 *  NOTE: May be unnecessary to reload some registers.
789 *
790 */
791
792void _CPU_Context_restore(
793  Context_Control *new_context
794) RTEMS_NO_RETURN;
795
796/*
797 *  _CPU_Context_save_fp
798 *
799 *  This routine saves the floating point context passed to it.
800 *
801 */
802
803void _CPU_Context_save_fp(
804  void **fp_context_ptr
805);
806
807/*
808 *  _CPU_Context_restore_fp
809 *
810 *  This routine restores the floating point context passed to it.
811 *
812 */
813
814void _CPU_Context_restore_fp(
815  void **fp_context_ptr
816);
817
818/*  The following routine swaps the endian format of an unsigned int.
819 *  It must be static because it is referenced indirectly.
820 *
821 *  This version will work on any processor, but if there is a better
822 *  way for your CPU PLEASE use it.  The most common way to do this is to:
823 *
824 *     swap least significant two bytes with 16-bit rotate
825 *     swap upper and lower 16-bits
826 *     swap most significant two bytes with 16-bit rotate
827 *
828 *  Some CPUs have special instructions which swap a 32-bit quantity in
829 *  a single instruction (e.g. i486).  It is probably best to avoid
830 *  an "endian swapping control bit" in the CPU.  One good reason is
831 *  that interrupts would probably have to be disabled to insure that
832 *  an interrupt does not try to access the same "chunk" with the wrong
833 *  endian.  Another good reason is that on some CPUs, the endian bit
834 *  endianness for ALL fetches -- both code and data -- so the code
835 *  will be fetched incorrectly.
836 *
837 */
838
839void _CPU_Context_volatile_clobber( uintptr_t pattern );
840
841void _CPU_Context_validate( uintptr_t pattern );
842
843static inline unsigned int CPU_swap_u32(
844  unsigned int value
845)
846{
847  uint32_t   byte1, byte2, byte3, byte4, swapped;
848
849  byte4 = (value >> 24) & 0xff;
850  byte3 = (value >> 16) & 0xff;
851  byte2 = (value >> 8)  & 0xff;
852  byte1 =  value        & 0xff;
853
854  swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
855  return( swapped );
856}
857
858#define CPU_swap_u16( value ) \
859  (((value&0xff) << 8) | ((value >> 8)&0xff))
860
861typedef uint32_t CPU_Counter_ticks;
862
863CPU_Counter_ticks _CPU_Counter_read( void );
864
865CPU_Counter_ticks _CPU_Counter_difference(
866  CPU_Counter_ticks second,
867  CPU_Counter_ticks first
868);
869
870#endif /* ASM */
871
872#ifdef __cplusplus
873}
874#endif
875
876#endif
Note: See TracBrowser for help on using the repository browser.