source: rtems/cpukit/score/cpu/sh/include/rtems/score/cpu.h @ 27bbc05

5
Last change on this file since 27bbc05 was 27bbc05, checked in by Sebastian Huber <sebastian.huber@…>, on 08/02/18 at 12:49:01

score: Remove CPU_PARTITION_ALIGNMENT

Use the CPU_SIZEOF_POINTER alignment instead. The internal alignment
requirement is defined by the use of Chain_Node (consisting of two
pointers) to manage the free chain of partitions.

It seems that previously the condition

CPU_PARTITION_ALIGNMENT >= sizeof(Chain_Node)

was true on all CPU ports. Now, we need an additional check.

Update #3482.

  • Property mode set to 100644
File size: 18.9 KB
Line 
1/**
2 * @file rtems/score/cpu.h
3 */
4
5/*
6 *  This include file contains information pertaining to the Hitachi SH
7 *  processor.
8 *
9 *  Authors: Ralf Corsepius (corsepiu@faw.uni-ulm.de) and
10 *           Bernd Becker (becker@faw.uni-ulm.de)
11 *
12 *  COPYRIGHT (c) 1997-1998, FAW Ulm, Germany
13 *
14 *  This program is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 *
18 *
19 *  COPYRIGHT (c) 1998-2006.
20 *  On-Line Applications Research Corporation (OAR).
21 *
22 *  The license and distribution terms for this file may be
23 *  found in the file LICENSE in this distribution or at
24 *  http://www.rtems.org/license/LICENSE.
25 */
26
27#ifndef _RTEMS_SCORE_CPU_H
28#define _RTEMS_SCORE_CPU_H
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#include <rtems/score/basedefs.h>
35#include <rtems/score/sh.h>
36
37/* conditional compilation parameters */
38
39/*
40 *  Does the CPU follow the simple vectored interrupt model?
41 *
42 *  If TRUE, then RTEMS allocates the vector table it internally manages.
43 *  If FALSE, then the BSP is assumed to allocate and manage the vector
44 *  table
45 *
46 *  SH Specific Information:
47 *
48 *  XXX document implementation including references if appropriate
49 */
50#define CPU_SIMPLE_VECTORED_INTERRUPTS TRUE
51
52/*
53 *  Does the RTEMS invoke the user's ISR with the vector number and
54 *  a pointer to the saved interrupt frame (1) or just the vector
55 *  number (0)?
56 */
57
58#define CPU_ISR_PASSES_FRAME_POINTER FALSE
59
60/*
61 *  Does the CPU have hardware floating point?
62 *
63 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
64 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
65 *
66 *  We currently support sh1 only, which has no FPU, other SHes have an FPU
67 *
68 *  The macro name "SH_HAS_FPU" should be made CPU specific.
69 *  It indicates whether or not this CPU model has FP support.  For
70 *  example, it would be possible to have an i386_nofp CPU model
71 *  which set this to false to indicate that you have an i386 without
72 *  an i387 and wish to leave floating point support out of RTEMS.
73 */
74
75#if SH_HAS_FPU
76#define CPU_HARDWARE_FP TRUE
77#define CPU_SOFTWARE_FP FALSE
78#else
79#define CPU_SOFTWARE_FP FALSE
80#define CPU_HARDWARE_FP FALSE
81#endif
82
83/*
84 *  Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
85 *
86 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
87 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
88 *
89 *  If CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
90 */
91
92#if SH_HAS_FPU
93#define CPU_ALL_TASKS_ARE_FP     TRUE
94#else
95#define CPU_ALL_TASKS_ARE_FP     FALSE
96#endif
97
98/*
99 *  Should the IDLE task have a floating point context?
100 *
101 *  If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
102 *  and it has a floating point context which is switched in and out.
103 *  If FALSE, then the IDLE task does not have a floating point context.
104 *
105 *  Setting this to TRUE negatively impacts the time required to preempt
106 *  the IDLE task from an interrupt because the floating point context
107 *  must be saved as part of the preemption.
108 */
109
110#if SH_HAS_FPU
111#define CPU_IDLE_TASK_IS_FP     TRUE
112#else
113#define CPU_IDLE_TASK_IS_FP      FALSE
114#endif
115
116/*
117 *  Should the saving of the floating point registers be deferred
118 *  until a context switch is made to another different floating point
119 *  task?
120 *
121 *  If TRUE, then the floating point context will not be stored until
122 *  necessary.  It will remain in the floating point registers and not
123 *  disturned until another floating point task is switched to.
124 *
125 *  If FALSE, then the floating point context is saved when a floating
126 *  point task is switched out and restored when the next floating point
127 *  task is restored.  The state of the floating point registers between
128 *  those two operations is not specified.
129 *
130 *  If the floating point context does NOT have to be saved as part of
131 *  interrupt dispatching, then it should be safe to set this to TRUE.
132 *
133 *  Setting this flag to TRUE results in using a different algorithm
134 *  for deciding when to save and restore the floating point context.
135 *  The deferred FP switch algorithm minimizes the number of times
136 *  the FP context is saved and restored.  The FP context is not saved
137 *  until a context switch is made to another, different FP task.
138 *  Thus in a system with only one FP task, the FP context will never
139 *  be saved or restored.
140 */
141
142#if SH_HAS_FPU
143#define CPU_USE_DEFERRED_FP_SWITCH      FALSE
144#else
145#define CPU_USE_DEFERRED_FP_SWITCH      TRUE
146#endif
147
148#define CPU_ENABLE_ROBUST_THREAD_DISPATCH FALSE
149
150/*
151 *  Does this port provide a CPU dependent IDLE task implementation?
152 *
153 *  If TRUE, then the routine _CPU_Thread_Idle_body
154 *  must be provided and is the default IDLE thread body instead of
155 *  _CPU_Thread_Idle_body.
156 *
157 *  If FALSE, then use the generic IDLE thread body if the BSP does
158 *  not provide one.
159 *
160 *  This is intended to allow for supporting processors which have
161 *  a low power or idle mode.  When the IDLE thread is executed, then
162 *  the CPU can be powered down.
163 *
164 *  The order of precedence for selecting the IDLE thread body is:
165 *
166 *    1.  BSP provided
167 *    2.  CPU dependent (if provided)
168 *    3.  generic (if no BSP and no CPU dependent)
169 */
170
171#define CPU_PROVIDES_IDLE_THREAD_BODY    TRUE
172
173/*
174 *  Does the stack grow up (toward higher addresses) or down
175 *  (toward lower addresses)?
176 *
177 *  If TRUE, then the grows upward.
178 *  If FALSE, then the grows toward smaller addresses.
179 */
180
181#define CPU_STACK_GROWS_UP               FALSE
182
183/* FIXME: Is this the right value? */
184#define CPU_CACHE_LINE_BYTES 16
185
186#define CPU_STRUCTURE_ALIGNMENT RTEMS_ALIGNED( CPU_CACHE_LINE_BYTES )
187
188/*
189 *  The following defines the number of bits actually used in the
190 *  interrupt field of the task mode.  How those bits map to the
191 *  CPU interrupt levels is defined by the routine _CPU_ISR_Set_level().
192 */
193
194#define CPU_MODES_INTERRUPT_MASK   0x0000000f
195
196#define CPU_MAXIMUM_PROCESSORS 32
197
198/*
199 *  Processor defined structures required for cpukit/score.
200 */
201
202/* may need to put some structures here.  */
203
204/*
205 * Contexts
206 *
207 *  Generally there are 2 types of context to save.
208 *     1. Interrupt registers to save
209 *     2. Task level registers to save
210 *
211 *  This means we have the following 3 context items:
212 *     1. task level context stuff::  Context_Control
213 *     2. floating point task stuff:: Context_Control_fp
214 *     3. special interrupt level context :: Context_Control_interrupt
215 *
216 *  On some processors, it is cost-effective to save only the callee
217 *  preserved registers during a task context switch.  This means
218 *  that the ISR code needs to save those registers which do not
219 *  persist across function calls.  It is not mandatory to make this
220 *  distinctions between the caller/callee saves registers for the
221 *  purpose of minimizing context saved during task switch and on interrupts.
222 *  If the cost of saving extra registers is minimal, simplicity is the
223 *  choice.  Save the same context on interrupt entry as for tasks in
224 *  this case.
225 *
226 *  Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
227 *  care should be used in designing the context area.
228 *
229 *  On some CPUs with hardware floating point support, the Context_Control_fp
230 *  structure will not be used or it simply consist of an array of a
231 *  fixed number of bytes.   This is done when the floating point context
232 *  is dumped by a "FP save context" type instruction and the format
233 *  is not really defined by the CPU.  In this case, there is no need
234 *  to figure out the exact format -- only the size.  Of course, although
235 *  this is enough information for RTEMS, it is probably not enough for
236 *  a debugger such as gdb.  But that is another problem.
237 */
238
239typedef struct {
240  uint32_t   *r15;      /* stack pointer */
241
242  uint32_t   macl;
243  uint32_t   mach;
244  uint32_t   *pr;
245
246  uint32_t   *r14;      /* frame pointer/call saved */
247
248  uint32_t   r13;       /* call saved */
249  uint32_t   r12;       /* call saved */
250  uint32_t   r11;       /* call saved */
251  uint32_t   r10;       /* call saved */
252  uint32_t   r9;        /* call saved */
253  uint32_t   r8;        /* call saved */
254
255  uint32_t   *r7;       /* arg in */
256  uint32_t   *r6;       /* arg in */
257
258#if 0
259  uint32_t   *r5;       /* arg in */
260  uint32_t   *r4;       /* arg in */
261#endif
262
263  uint32_t   *r3;       /* scratch */
264  uint32_t   *r2;       /* scratch */
265  uint32_t   *r1;       /* scratch */
266
267  uint32_t   *r0;       /* arg return */
268
269  uint32_t   gbr;
270  uint32_t   sr;
271
272} Context_Control;
273
274#define _CPU_Context_Get_SP( _context ) \
275  (_context)->r15
276
277typedef struct {
278#if SH_HAS_FPU
279#ifdef SH4_USE_X_REGISTERS
280  union {
281    float f[16];
282    double d[8];
283  } x;
284#endif
285  union {
286    float f[16];
287    double d[8];
288  } r;
289  float fpul;       /* fp communication register */
290  uint32_t   fpscr; /* fp control register */
291#endif /* SH_HAS_FPU */
292} Context_Control_fp;
293
294typedef struct {
295} CPU_Interrupt_frame;
296
297/*
298 *  This variable is optional.  It is used on CPUs on which it is difficult
299 *  to generate an "uninitialized" FP context.  It is filled in by
300 *  _CPU_Initialize and copied into the task's FP context area during
301 *  _CPU_Context_Initialize.
302 */
303
304#if SH_HAS_FPU
305extern Context_Control_fp _CPU_Null_fp_context;
306#endif
307
308/*
309 *  Nothing prevents the porter from declaring more CPU specific variables.
310 */
311
312/* XXX: if needed, put more variables here */
313void CPU_delay( uint32_t   microseconds );
314
315/*
316 *  The size of the floating point context area.  On some CPUs this
317 *  will not be a "sizeof" because the format of the floating point
318 *  area is not defined -- only the size is.  This is usually on
319 *  CPUs with a "floating point save context" instruction.
320 */
321
322#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
323
324/*
325 *  Amount of extra stack (above minimum stack size) required by
326 *  MPCI receive server thread.  Remember that in a multiprocessor
327 *  system this thread must exist and be able to process all directives.
328 */
329
330#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
331
332/*
333 *  This defines the number of entries in the ISR_Vector_table managed
334 *  by RTEMS.
335 */
336
337#define CPU_INTERRUPT_NUMBER_OF_VECTORS      256
338#define CPU_INTERRUPT_MAXIMUM_VECTOR_NUMBER  (CPU_INTERRUPT_NUMBER_OF_VECTORS - 1)
339
340/*
341 *  This is defined if the port has a special way to report the ISR nesting
342 *  level.  Most ports maintain the variable _ISR_Nest_level.
343 */
344
345#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
346
347/*
348 *  Should be large enough to run all RTEMS tests.  This ensures
349 *  that a "reasonable" small application should not have any problems.
350 *
351 *  We have been able to run the sptests with this value, but have not
352 *  been able to run the tmtest suite.
353 */
354
355#define CPU_STACK_MINIMUM_SIZE          4096
356
357#define CPU_SIZEOF_POINTER 4
358
359/*
360 *  CPU's worst alignment requirement for data types on a byte boundary.  This
361 *  alignment does not take into account the requirements for the stack.
362 */
363#if defined(__SH4__)
364/* FIXME: sh3 and SH3E? */
365#define CPU_ALIGNMENT              8
366#else
367#define CPU_ALIGNMENT              4
368#endif
369
370/*
371 *  This number corresponds to the byte alignment requirement for the
372 *  heap handler.  This alignment requirement may be stricter than that
373 *  for the data types alignment specified by CPU_ALIGNMENT.  It is
374 *  common for the heap to follow the same alignment requirement as
375 *  CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict enough for the heap,
376 *  then this should be set to CPU_ALIGNMENT.
377 *
378 *  NOTE:  This does not have to be a power of 2.  It does have to
379 *         be greater or equal to than CPU_ALIGNMENT.
380 */
381
382#define CPU_HEAP_ALIGNMENT         CPU_ALIGNMENT
383
384/*
385 *  This number corresponds to the byte alignment requirement for the
386 *  stack.  This alignment requirement may be stricter than that for the
387 *  data types alignment specified by CPU_ALIGNMENT.  If the CPU_ALIGNMENT
388 *  is strict enough for the stack, then this should be set to 0.
389 *
390 *  NOTE:  This must be a power of 2 either 0 or greater than CPU_ALIGNMENT.
391 */
392
393#define CPU_STACK_ALIGNMENT        CPU_ALIGNMENT
394
395#define CPU_INTERRUPT_STACK_ALIGNMENT CPU_CACHE_LINE_BYTES
396
397/*
398 *  ISR handler macros
399 */
400
401/*
402 *  Support routine to initialize the RTEMS vector table after it is allocated.
403 *
404 *  SH Specific Information: NONE
405 */
406
407#define _CPU_Initialize_vectors()
408
409/*
410 *  Disable all interrupts for an RTEMS critical section.  The previous
411 *  level is returned in _level.
412 */
413
414#define _CPU_ISR_Disable( _level) \
415  sh_disable_interrupts( _level )
416
417/*
418 *  Enable interrupts to the previous level (returned by _CPU_ISR_Disable).
419 *  This indicates the end of an RTEMS critical section.  The parameter
420 *  _level is not modified.
421 */
422
423#define _CPU_ISR_Enable( _level) \
424   sh_enable_interrupts( _level)
425
426/*
427 *  This temporarily restores the interrupt to _level before immediately
428 *  disabling them again.  This is used to divide long RTEMS critical
429 *  sections into two or more parts.  The parameter _level is not
430 * modified.
431 */
432
433#define _CPU_ISR_Flash( _level) \
434  sh_flash_interrupts( _level)
435
436RTEMS_INLINE_ROUTINE bool _CPU_ISR_Is_enabled( uint32_t level )
437{
438  sh_get_interrupt_level( level );
439  return level == 0;
440}
441
442/*
443 *  Map interrupt level in task mode onto the hardware that the CPU
444 *  actually provides.  Currently, interrupt levels which do not
445 *  map onto the CPU in a generic fashion are undefined.  Someday,
446 *  it would be nice if these were "mapped" by the application
447 *  via a callout.  For example, m68k has 8 levels 0 - 7, levels
448 *  8 - 255 would be available for bsp/application specific meaning.
449 *  This could be used to manage a programmable interrupt controller
450 *  via the rtems_task_mode directive.
451 */
452
453#define _CPU_ISR_Set_level( _newlevel) \
454  sh_set_interrupt_level(_newlevel)
455
456uint32_t   _CPU_ISR_Get_level( void );
457
458/* end of ISR handler macros */
459
460/* Context handler macros */
461
462/*
463 *  Initialize the context to a state suitable for starting a
464 *  task after a context restore operation.  Generally, this
465 *  involves:
466 *
467 *     - setting a starting address
468 *     - preparing the stack
469 *     - preparing the stack and frame pointers
470 *     - setting the proper interrupt level in the context
471 *     - initializing the floating point context
472 *
473 *  This routine generally does not set any unnecessary register
474 *  in the context.  The state of the "general data" registers is
475 *  undefined at task start time.
476 *
477 *  NOTE: This is_fp parameter is TRUE if the thread is to be a floating
478 *        point thread.  This is typically only used on CPUs where the
479 *        FPU may be easily disabled by software such as on the SPARC
480 *        where the PSR contains an enable FPU bit.
481 */
482
483/*
484 * FIXME: defined as a function for debugging - should be a macro
485 */
486void _CPU_Context_Initialize(
487  Context_Control       *_the_context,
488  void                  *_stack_base,
489  uint32_t              _size,
490  uint32_t              _isr,
491  void    (*_entry_point)(void),
492  int                   _is_fp,
493  void                  *_tls_area );
494
495/*
496 *  This routine is responsible for somehow restarting the currently
497 *  executing task.  If you are lucky, then all that is necessary
498 *  is restoring the context.  Otherwise, there will need to be
499 *  a special assembly routine which does something special in this
500 *  case.  Context_Restore should work most of the time.  It will
501 *  not work if restarting self conflicts with the stack frame
502 *  assumptions of restoring a context.
503 */
504
505#define _CPU_Context_Restart_self( _the_context ) \
506   _CPU_Context_restore( (_the_context) );
507
508/*
509 *  This routine initializes the FP context area passed to it to.
510 *  There are a few standard ways in which to initialize the
511 *  floating point context.  The code included for this macro assumes
512 *  that this is a CPU in which a "initial" FP context was saved into
513 *  _CPU_Null_fp_context and it simply copies it to the destination
514 *  context passed to it.
515 *
516 *  Other models include (1) not doing anything, and (2) putting
517 *  a "null FP status word" in the correct place in the FP context.
518 *  SH1, SH2, SH3 have no FPU, but the SH3e and SH4 have.
519 */
520
521#if SH_HAS_FPU
522#define _CPU_Context_Initialize_fp( _destination ) \
523  do { \
524     *(*(_destination)) = _CPU_Null_fp_context;\
525  } while(0)
526#else
527#define _CPU_Context_Initialize_fp( _destination ) \
528  {  }
529#endif
530
531/* end of Context handler macros */
532
533/* Fatal Error manager macros */
534
535/*
536 * FIXME: Trap32 ???
537 *
538 *  This routine copies _error into a known place -- typically a stack
539 *  location or a register, optionally disables interrupts, and
540 *  invokes a Trap32 Instruction which returns to the breakpoint
541 *  routine of cmon.
542 */
543
544#ifdef BSP_FATAL_HALT
545  /* we manage the fatal error in the board support package */
546  void bsp_fatal_halt( uint32_t   _error);
547#define _CPU_Fatal_halt( _source, _error ) bsp_fatal_halt( _error)
548#else
549#define _CPU_Fatal_halt( _source, _error)\
550{ \
551  __asm__ volatile("mov.l %0,r0"::"m" (_error)); \
552  __asm__ volatile("mov #1, r4"); \
553  __asm__ volatile("trapa #34"); \
554}
555#endif
556
557/* end of Fatal Error manager macros */
558
559#define CPU_USE_GENERIC_BITFIELD_CODE TRUE
560
561/* functions */
562
563/*
564 *  @brief CPU Initialize
565 *
566 *  _CPU_Initialize
567 *
568 *  This routine performs CPU dependent initialization.
569 */
570void _CPU_Initialize(void);
571
572/*
573 *  _CPU_ISR_install_raw_handler
574 *
575 *  This routine installs a "raw" interrupt handler directly into the
576 *  processor's vector table.
577 */
578
579void _CPU_ISR_install_raw_handler(
580  uint32_t    vector,
581  proc_ptr    new_handler,
582  proc_ptr   *old_handler
583);
584
585/*
586 *  _CPU_ISR_install_vector
587 *
588 *  This routine installs an interrupt vector.
589 */
590
591void _CPU_ISR_install_vector(
592  uint32_t    vector,
593  proc_ptr    new_handler,
594  proc_ptr   *old_handler
595);
596
597/*
598 *  _CPU_Thread_Idle_body
599 *
600 *  This routine is the CPU dependent IDLE thread body.
601 *
602 *  NOTE:  It need only be provided if CPU_PROVIDES_IDLE_THREAD_BODY
603 *         is TRUE.
604 */
605
606void *_CPU_Thread_Idle_body( uintptr_t ignored );
607
608/*
609 *  _CPU_Context_switch
610 *
611 *  This routine switches from the run context to the heir context.
612 */
613
614void _CPU_Context_switch(
615  Context_Control  *run,
616  Context_Control  *heir
617);
618
619/*
620 *  _CPU_Context_restore
621 *
622 *  This routine is generally used only to restart self in an
623 *  efficient manner.  It may simply be a label in _CPU_Context_switch.
624 */
625
626void _CPU_Context_restore(
627  Context_Control *new_context
628) RTEMS_NO_RETURN;
629
630/*
631 *  @brief This routine saves the floating point context passed to it.
632 *
633 *  _CPU_Context_save_fp
634 *
635 */
636void _CPU_Context_save_fp(
637  Context_Control_fp **fp_context_ptr
638);
639
640/*
641 *  @brief This routine restores the floating point context passed to it.
642 *
643 *  _CPU_Context_restore_fp
644 *
645 */
646void _CPU_Context_restore_fp(
647  Context_Control_fp **fp_context_ptr
648);
649
650/* FIXME */
651typedef CPU_Interrupt_frame CPU_Exception_frame;
652
653void _CPU_Exception_frame_print( const CPU_Exception_frame *frame );
654
655typedef uint32_t CPU_Counter_ticks;
656
657uint32_t _CPU_Counter_frequency( void );
658
659CPU_Counter_ticks _CPU_Counter_read( void );
660
661static inline CPU_Counter_ticks _CPU_Counter_difference(
662  CPU_Counter_ticks second,
663  CPU_Counter_ticks first
664)
665{
666  return second - first;
667}
668
669/** Type that can store a 32-bit integer or a pointer. */
670typedef uintptr_t CPU_Uint32ptr;
671
672/** Types related to SH specific ISRs */
673typedef void sh_isr;
674typedef void ( *sh_isr_entry )( void );
675
676#ifdef __cplusplus
677}
678#endif
679
680#endif
Note: See TracBrowser for help on using the repository browser.