source: rtems/cpukit/score/cpu/powerpc/include/rtems/score/cpu.h @ a660e9dc

Last change on this file since a660e9dc was a660e9dc, checked in by Sebastian Huber <sebastian.huber@…>, on 09/08/22 at 08:37:05

Do not use RTEMS_INLINE_ROUTINE

Directly use "static inline" which is available in C99 and later. This brings
the RTEMS implementation closer to standard C.

Close #3935.

  • Property mode set to 100644
File size: 34.4 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @addtogroup RTEMSScoreCPUPowerPC
7 *
8 * @brief PowerPC CPU Department Source
9 */
10
11/*
12 *  COPYRIGHT (c) 1989-2012.
13 *  On-Line Applications Research Corporation (OAR).
14 *
15 *  COPYRIGHT (c) 1995 i-cubed ltd.
16 *
17 *  To anyone who acknowledges that this file is provided "AS IS"
18 *  without any express or implied warranty:
19 *      permission to use, copy, modify, and distribute this file
20 *      for any purpose is hereby granted without fee, provided that
21 *      the above copyright notice and this notice appears in all
22 *      copies, and that the name of i-cubed limited not be used in
23 *      advertising or publicity pertaining to distribution of the
24 *      software without specific, written prior permission.
25 *      i-cubed limited makes no representations about the suitability
26 *      of this software for any purpose.
27 *
28 *  Copyright (c) 2001 Andy Dachs <a.dachs@sstl.co.uk>.
29 *
30 *  Copyright (c) 2001 Surrey Satellite Technology Limited (SSTL).
31 *
32 *  Copyright (c) 2010, 2020 embedded brains GmbH.
33 *
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
36 * are met:
37 * 1. Redistributions of source code must retain the above copyright
38 *    notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 *    notice, this list of conditions and the following disclaimer in the
41 *    documentation and/or other materials provided with the distribution.
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
44 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
47 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
48 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
49 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
50 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
51 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
53 * POSSIBILITY OF SUCH DAMAGE.
54 */
55
56#ifndef _RTEMS_SCORE_CPU_H
57#define _RTEMS_SCORE_CPU_H
58
59#include <rtems/score/basedefs.h>
60#if defined(RTEMS_PARAVIRT)
61#include <rtems/score/paravirt.h>
62#endif
63#include <rtems/score/powerpc.h>
64#include <rtems/powerpc/registers.h>
65
66#ifndef ASM
67  #include <string.h> /* for memset() */
68#endif
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
74/* conditional compilation parameters */
75
76/*
77 *  Does the stack grow up (toward higher addresses) or down
78 *  (toward lower addresses)?
79 *
80 *  If TRUE, then the grows upward.
81 *  If FALSE, then the grows toward smaller addresses.
82 */
83
84#define CPU_STACK_GROWS_UP               FALSE
85
86#define CPU_CACHE_LINE_BYTES PPC_STRUCTURE_ALIGNMENT
87
88#define CPU_STRUCTURE_ALIGNMENT RTEMS_ALIGNED( CPU_CACHE_LINE_BYTES )
89
90/*
91 *  Does the CPU have hardware floating point?
92 *
93 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is supported.
94 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is ignored.
95 *
96 *  If there is a FP coprocessor such as the i387 or mc68881, then
97 *  the answer is TRUE.
98 *
99 *  The macro name "PPC_HAS_FPU" should be made CPU specific.
100 *  It indicates whether or not this CPU model has FP support.  For
101 *  example, it would be possible to have an i386_nofp CPU model
102 *  which set this to false to indicate that you have an i386 without
103 *  an i387 and wish to leave floating point support out of RTEMS.
104 */
105
106#if ( PPC_HAS_FPU == 1 )
107#define CPU_HARDWARE_FP     TRUE
108#define CPU_SOFTWARE_FP     FALSE
109#else
110#define CPU_HARDWARE_FP     FALSE
111#define CPU_SOFTWARE_FP     FALSE
112#endif
113
114/*
115 *  Are all tasks RTEMS_FLOATING_POINT tasks implicitly?
116 *
117 *  If TRUE, then the RTEMS_FLOATING_POINT task attribute is assumed.
118 *  If FALSE, then the RTEMS_FLOATING_POINT task attribute is followed.
119 *
120 *  If CPU_HARDWARE_FP is FALSE, then this should be FALSE as well.
121 *
122 *  PowerPC Note: It appears the GCC can implicitly generate FPU
123 *  and Altivec instructions when you least expect them.  So make
124 *  all tasks floating point.
125 */
126
127#define CPU_ALL_TASKS_ARE_FP CPU_HARDWARE_FP
128
129/*
130 *  Should the IDLE task have a floating point context?
131 *
132 *  If TRUE, then the IDLE task is created as a RTEMS_FLOATING_POINT task
133 *  and it has a floating point context which is switched in and out.
134 *  If FALSE, then the IDLE task does not have a floating point context.
135 *
136 *  Setting this to TRUE negatively impacts the time required to preempt
137 *  the IDLE task from an interrupt because the floating point context
138 *  must be saved as part of the preemption.
139 */
140
141#define CPU_IDLE_TASK_IS_FP      FALSE
142
143#define CPU_MAXIMUM_PROCESSORS 32
144
145/*
146 *  Processor defined structures required for cpukit/score.
147 */
148
149/*
150 * Contexts
151 *
152 *  Generally there are 2 types of context to save.
153 *     1. Interrupt registers to save
154 *     2. Task level registers to save
155 *
156 *  This means we have the following 3 context items:
157 *     1. task level context stuff::  Context_Control
158 *     2. floating point task stuff:: Context_Control_fp
159 *     3. special interrupt level context :: Context_Control_interrupt
160 *
161 *  On some processors, it is cost-effective to save only the callee
162 *  preserved registers during a task context switch.  This means
163 *  that the ISR code needs to save those registers which do not
164 *  persist across function calls.  It is not mandatory to make this
165 *  distinctions between the caller/callee saves registers for the
166 *  purpose of minimizing context saved during task switch and on interrupts.
167 *  If the cost of saving extra registers is minimal, simplicity is the
168 *  choice.  Save the same context on interrupt entry as for tasks in
169 *  this case.
170 *
171 *  Additionally, if gdb is to be made aware of RTEMS tasks for this CPU, then
172 *  care should be used in designing the context area.
173 *
174 *  On some CPUs with hardware floating point support, the Context_Control_fp
175 *  structure will not be used or it simply consist of an array of a
176 *  fixed number of bytes.   This is done when the floating point context
177 *  is dumped by a "FP save context" type instruction and the format
178 *  is not really defined by the CPU.  In this case, there is no need
179 *  to figure out the exact format -- only the size.  Of course, although
180 *  this is enough information for RTEMS, it is probably not enough for
181 *  a debugger such as gdb.  But that is another problem.
182 */
183
184#ifndef __SPE__
185  #define PPC_GPR_TYPE uintptr_t
186  #if defined(__powerpc64__)
187    #define PPC_GPR_SIZE 8
188    #define PPC_GPR_LOAD ld
189    #define PPC_GPR_STORE std
190  #else
191    #define PPC_GPR_SIZE 4
192    #define PPC_GPR_LOAD lwz
193    #define PPC_GPR_STORE stw
194  #endif
195#else
196  #define PPC_GPR_TYPE uint64_t
197  #define PPC_GPR_SIZE 8
198  #define PPC_GPR_LOAD evldd
199  #define PPC_GPR_STORE evstdd
200#endif
201
202#if defined(__powerpc64__)
203  #define PPC_REG_SIZE 8
204  #define PPC_REG_LOAD ld
205  #define PPC_REG_STORE std
206  #define PPC_REG_STORE_UPDATE stdu
207  #define PPC_REG_CMP cmpd
208#else
209  #define PPC_REG_SIZE 4
210  #define PPC_REG_LOAD lwz
211  #define PPC_REG_STORE stw
212  #define PPC_REG_STORE_UPDATE stwu
213  #define PPC_REG_CMP cmpw
214#endif
215
216#ifndef ASM
217
218/*
219 * Non-volatile context according to E500ABIUG, EABI and 32-bit TLS (according
220 * to "Power Architecture 32-bit Application Binary Interface Supplement 1.0 -
221 * Linux and Embedded")
222 */
223typedef struct {
224  uint32_t msr;
225  uint32_t cr;
226  uintptr_t gpr1;
227  uintptr_t lr;
228  PPC_GPR_TYPE gpr14;
229  PPC_GPR_TYPE gpr15;
230  PPC_GPR_TYPE gpr16;
231  PPC_GPR_TYPE gpr17;
232  PPC_GPR_TYPE gpr18;
233  PPC_GPR_TYPE gpr19;
234  PPC_GPR_TYPE gpr20;
235  PPC_GPR_TYPE gpr21;
236  PPC_GPR_TYPE gpr22;
237  PPC_GPR_TYPE gpr23;
238  PPC_GPR_TYPE gpr24;
239  PPC_GPR_TYPE gpr25;
240  PPC_GPR_TYPE gpr26;
241  PPC_GPR_TYPE gpr27;
242  PPC_GPR_TYPE gpr28;
243  PPC_GPR_TYPE gpr29;
244  PPC_GPR_TYPE gpr30;
245  PPC_GPR_TYPE gpr31;
246  uint32_t isr_dispatch_disable;
247  uint32_t reserved_for_alignment;
248  #if defined(PPC_MULTILIB_ALTIVEC)
249    #if !defined(__powerpc64__)
250      uint32_t reserved_for_alignment_2[4];
251    #endif
252    uint32_t vrsave;
253    uint32_t reserved_for_alignment_3[2];
254    /* This field must take stvewx/lvewx requirements into account */
255    uint32_t vscr;
256    uint8_t v20[16];
257    uint8_t v21[16];
258    uint8_t v22[16];
259    uint8_t v23[16];
260    uint8_t v24[16];
261    uint8_t v25[16];
262    uint8_t v26[16];
263    uint8_t v27[16];
264    uint8_t v28[16];
265    uint8_t v29[16];
266    uint8_t v30[16];
267    uint8_t v31[16];
268  #elif defined(__ALTIVEC__)
269    /*
270     * 12 non-volatile vector registers, cache-aligned area for vscr/vrsave
271     * and padding to ensure cache-alignment.  Unfortunately, we can't verify
272     * the cache line size here in the cpukit but altivec support code will
273     * produce an error if this is ever different from 32 bytes.
274     *
275     * Note: it is the BSP/CPU-support's responsibility to save/restore
276     *       volatile vregs across interrupts and exceptions.
277     */
278    uint8_t altivec[16*12 + 32 + PPC_DEFAULT_CACHE_LINE_SIZE];
279  #endif
280  #if defined(PPC_MULTILIB_FPU)
281    double f14;
282    double f15;
283    double f16;
284    double f17;
285    double f18;
286    double f19;
287    double f20;
288    double f21;
289    double f22;
290    double f23;
291    double f24;
292    double f25;
293    double f26;
294    double f27;
295    double f28;
296    double f29;
297    double f30;
298    double f31;
299  #endif
300  /*
301   * The following items are at the structure end, so that we can use dcbz for
302   * the previous items to optimize the context switch.  We must not set the
303   * following items to zero via the dcbz.
304   */
305  uintptr_t tp;
306  #if defined(RTEMS_SMP)
307    volatile uint32_t is_executing;
308  #endif
309} ppc_context;
310
311typedef struct {
312  uint8_t context [
313    PPC_DEFAULT_CACHE_LINE_SIZE
314      + sizeof(ppc_context)
315      + (sizeof(ppc_context) % PPC_DEFAULT_CACHE_LINE_SIZE == 0
316        ? 0
317          : PPC_DEFAULT_CACHE_LINE_SIZE
318            - sizeof(ppc_context) % PPC_DEFAULT_CACHE_LINE_SIZE)
319  ];
320} Context_Control;
321
322static inline ppc_context *ppc_get_context( const Context_Control *context )
323{
324  uintptr_t clsz = PPC_DEFAULT_CACHE_LINE_SIZE;
325  uintptr_t mask = clsz - 1;
326  uintptr_t addr = (uintptr_t) context;
327
328  return (ppc_context *) ((addr & ~mask) + clsz);
329}
330
331#define _CPU_Context_Get_SP( _context ) \
332  ppc_get_context(_context)->gpr1
333
334#ifdef RTEMS_SMP
335  static inline bool _CPU_Context_Get_is_executing(
336    const Context_Control *context
337  )
338  {
339    return ppc_get_context(context)->is_executing;
340  }
341
342  static inline void _CPU_Context_Set_is_executing(
343    Context_Control *context,
344    bool is_executing
345  )
346  {
347    ppc_get_context(context)->is_executing = is_executing;
348  }
349#endif
350#endif /* ASM */
351
352#define PPC_CONTEXT_OFFSET_MSR (PPC_DEFAULT_CACHE_LINE_SIZE)
353#define PPC_CONTEXT_OFFSET_CR (PPC_DEFAULT_CACHE_LINE_SIZE + 4)
354#define PPC_CONTEXT_OFFSET_GPR1 (PPC_DEFAULT_CACHE_LINE_SIZE + 8)
355#define PPC_CONTEXT_OFFSET_LR (PPC_DEFAULT_CACHE_LINE_SIZE + PPC_REG_SIZE + 8)
356
357#define PPC_CONTEXT_GPR_OFFSET( gpr ) \
358  (((gpr) - 14) * PPC_GPR_SIZE + \
359    PPC_DEFAULT_CACHE_LINE_SIZE + 8 + 2 * PPC_REG_SIZE)
360
361#define PPC_CONTEXT_OFFSET_GPR14 PPC_CONTEXT_GPR_OFFSET( 14 )
362#define PPC_CONTEXT_OFFSET_GPR15 PPC_CONTEXT_GPR_OFFSET( 15 )
363#define PPC_CONTEXT_OFFSET_GPR16 PPC_CONTEXT_GPR_OFFSET( 16 )
364#define PPC_CONTEXT_OFFSET_GPR17 PPC_CONTEXT_GPR_OFFSET( 17 )
365#define PPC_CONTEXT_OFFSET_GPR18 PPC_CONTEXT_GPR_OFFSET( 18 )
366#define PPC_CONTEXT_OFFSET_GPR19 PPC_CONTEXT_GPR_OFFSET( 19 )
367#define PPC_CONTEXT_OFFSET_GPR20 PPC_CONTEXT_GPR_OFFSET( 20 )
368#define PPC_CONTEXT_OFFSET_GPR21 PPC_CONTEXT_GPR_OFFSET( 21 )
369#define PPC_CONTEXT_OFFSET_GPR22 PPC_CONTEXT_GPR_OFFSET( 22 )
370#define PPC_CONTEXT_OFFSET_GPR23 PPC_CONTEXT_GPR_OFFSET( 23 )
371#define PPC_CONTEXT_OFFSET_GPR24 PPC_CONTEXT_GPR_OFFSET( 24 )
372#define PPC_CONTEXT_OFFSET_GPR25 PPC_CONTEXT_GPR_OFFSET( 25 )
373#define PPC_CONTEXT_OFFSET_GPR26 PPC_CONTEXT_GPR_OFFSET( 26 )
374#define PPC_CONTEXT_OFFSET_GPR27 PPC_CONTEXT_GPR_OFFSET( 27 )
375#define PPC_CONTEXT_OFFSET_GPR28 PPC_CONTEXT_GPR_OFFSET( 28 )
376#define PPC_CONTEXT_OFFSET_GPR29 PPC_CONTEXT_GPR_OFFSET( 29 )
377#define PPC_CONTEXT_OFFSET_GPR30 PPC_CONTEXT_GPR_OFFSET( 30 )
378#define PPC_CONTEXT_OFFSET_GPR31 PPC_CONTEXT_GPR_OFFSET( 31 )
379#define PPC_CONTEXT_OFFSET_ISR_DISPATCH_DISABLE PPC_CONTEXT_GPR_OFFSET( 32 )
380
381#ifdef PPC_MULTILIB_ALTIVEC
382  #ifdef __powerpc64__
383    #define PPC_CONTEXT_OFFSET_VRSAVE \
384      ( PPC_CONTEXT_OFFSET_ISR_DISPATCH_DISABLE + 8 )
385  #else
386    #define PPC_CONTEXT_OFFSET_VRSAVE \
387      ( PPC_CONTEXT_OFFSET_ISR_DISPATCH_DISABLE + 24 )
388  #endif
389  #define PPC_CONTEXT_OFFSET_VSCR ( PPC_CONTEXT_OFFSET_VRSAVE + 12 )
390  #define PPC_CONTEXT_OFFSET_V( v ) \
391    ( ( ( v ) - 20 ) * 16 + PPC_CONTEXT_OFFSET_VRSAVE + 16)
392  #define PPC_CONTEXT_OFFSET_V20 PPC_CONTEXT_OFFSET_V( 20 )
393  #define PPC_CONTEXT_OFFSET_V21 PPC_CONTEXT_OFFSET_V( 21 )
394  #define PPC_CONTEXT_OFFSET_V22 PPC_CONTEXT_OFFSET_V( 22 )
395  #define PPC_CONTEXT_OFFSET_V23 PPC_CONTEXT_OFFSET_V( 23 )
396  #define PPC_CONTEXT_OFFSET_V24 PPC_CONTEXT_OFFSET_V( 24 )
397  #define PPC_CONTEXT_OFFSET_V25 PPC_CONTEXT_OFFSET_V( 25 )
398  #define PPC_CONTEXT_OFFSET_V26 PPC_CONTEXT_OFFSET_V( 26 )
399  #define PPC_CONTEXT_OFFSET_V27 PPC_CONTEXT_OFFSET_V( 27 )
400  #define PPC_CONTEXT_OFFSET_V28 PPC_CONTEXT_OFFSET_V( 28 )
401  #define PPC_CONTEXT_OFFSET_V29 PPC_CONTEXT_OFFSET_V( 29 )
402  #define PPC_CONTEXT_OFFSET_V30 PPC_CONTEXT_OFFSET_V( 30 )
403  #define PPC_CONTEXT_OFFSET_V31 PPC_CONTEXT_OFFSET_V( 31 )
404  #define PPC_CONTEXT_OFFSET_F( f ) \
405    ( ( ( f ) - 14 ) * 8 + PPC_CONTEXT_OFFSET_V( 32 ) )
406#else
407  #define PPC_CONTEXT_OFFSET_F( f ) \
408    ( ( ( f ) - 14 ) * 8 + PPC_CONTEXT_OFFSET_ISR_DISPATCH_DISABLE + 8 )
409#endif
410
411#ifdef PPC_MULTILIB_FPU
412  #define PPC_CONTEXT_OFFSET_F14 PPC_CONTEXT_OFFSET_F( 14 )
413  #define PPC_CONTEXT_OFFSET_F15 PPC_CONTEXT_OFFSET_F( 15 )
414  #define PPC_CONTEXT_OFFSET_F16 PPC_CONTEXT_OFFSET_F( 16 )
415  #define PPC_CONTEXT_OFFSET_F17 PPC_CONTEXT_OFFSET_F( 17 )
416  #define PPC_CONTEXT_OFFSET_F18 PPC_CONTEXT_OFFSET_F( 18 )
417  #define PPC_CONTEXT_OFFSET_F19 PPC_CONTEXT_OFFSET_F( 19 )
418  #define PPC_CONTEXT_OFFSET_F20 PPC_CONTEXT_OFFSET_F( 20 )
419  #define PPC_CONTEXT_OFFSET_F21 PPC_CONTEXT_OFFSET_F( 21 )
420  #define PPC_CONTEXT_OFFSET_F22 PPC_CONTEXT_OFFSET_F( 22 )
421  #define PPC_CONTEXT_OFFSET_F23 PPC_CONTEXT_OFFSET_F( 23 )
422  #define PPC_CONTEXT_OFFSET_F24 PPC_CONTEXT_OFFSET_F( 24 )
423  #define PPC_CONTEXT_OFFSET_F25 PPC_CONTEXT_OFFSET_F( 25 )
424  #define PPC_CONTEXT_OFFSET_F26 PPC_CONTEXT_OFFSET_F( 26 )
425  #define PPC_CONTEXT_OFFSET_F27 PPC_CONTEXT_OFFSET_F( 27 )
426  #define PPC_CONTEXT_OFFSET_F28 PPC_CONTEXT_OFFSET_F( 28 )
427  #define PPC_CONTEXT_OFFSET_F29 PPC_CONTEXT_OFFSET_F( 29 )
428  #define PPC_CONTEXT_OFFSET_F30 PPC_CONTEXT_OFFSET_F( 30 )
429  #define PPC_CONTEXT_OFFSET_F31 PPC_CONTEXT_OFFSET_F( 31 )
430#endif
431
432#if defined(PPC_MULTILIB_FPU)
433  #define PPC_CONTEXT_VOLATILE_SIZE PPC_CONTEXT_OFFSET_F( 32 )
434#elif defined(PPC_MULTILIB_ALTIVEC)
435  #define PPC_CONTEXT_VOLATILE_SIZE PPC_CONTEXT_OFFSET_V( 33 )
436#elif defined(__ALTIVEC__)
437  #define PPC_CONTEXT_VOLATILE_SIZE \
438    (PPC_CONTEXT_GPR_OFFSET( 32 ) + 8 \
439      + 16 * 12 + 32 + PPC_DEFAULT_CACHE_LINE_SIZE)
440#else
441  #define PPC_CONTEXT_VOLATILE_SIZE (PPC_CONTEXT_GPR_OFFSET( 32 ) + 8)
442#endif
443
444#define PPC_CONTEXT_OFFSET_TP PPC_CONTEXT_VOLATILE_SIZE
445
446#ifdef RTEMS_SMP
447  #define PPC_CONTEXT_OFFSET_IS_EXECUTING \
448    (PPC_CONTEXT_OFFSET_TP + PPC_REG_SIZE)
449#endif
450
451#ifndef ASM
452typedef struct {
453#if (PPC_HAS_FPU == 1)
454    /* The ABIs (PowerOpen/SVR4/EABI) only require saving f14-f31 over
455     * procedure calls.  However, this would mean that the interrupt
456     * frame had to hold f0-f13, and the fpscr.  And as the majority
457     * of tasks will not have an FP context, we will save the whole
458     * context here.
459     */
460#if (PPC_HAS_DOUBLE == 1)
461    double      f[32];
462    uint64_t    fpscr;
463#else
464    float       f[32];
465    uint32_t    fpscr;
466#endif
467#endif /* (PPC_HAS_FPU == 1) */
468} Context_Control_fp;
469
470#endif /* ASM */
471
472/*
473 *  Does the CPU follow the simple vectored interrupt model?
474 *
475 *  If TRUE, then RTEMS allocates the vector table it internally manages.
476 *  If FALSE, then the BSP is assumed to allocate and manage the vector
477 *  table
478 *
479 *  PowerPC Specific Information:
480 *
481 *  The PowerPC and x86 were the first to use the PIC interrupt model.
482 *  They do not use the simple vectored interrupt model.
483 */
484#define CPU_SIMPLE_VECTORED_INTERRUPTS FALSE
485
486/*
487 *  Does the RTEMS invoke the user's ISR with the vector number and
488 *  a pointer to the saved interrupt frame (1) or just the vector
489 *  number (0)?
490 */
491
492#define CPU_ISR_PASSES_FRAME_POINTER FALSE
493
494/*
495 *  Should the saving of the floating point registers be deferred
496 *  until a context switch is made to another different floating point
497 *  task?
498 *
499 *  If TRUE, then the floating point context will not be stored until
500 *  necessary.  It will remain in the floating point registers and not
501 *  disturned until another floating point task is switched to.
502 *
503 *  If FALSE, then the floating point context is saved when a floating
504 *  point task is switched out and restored when the next floating point
505 *  task is restored.  The state of the floating point registers between
506 *  those two operations is not specified.
507 *
508 *  If the floating point context does NOT have to be saved as part of
509 *  interrupt dispatching, then it should be safe to set this to TRUE.
510 *
511 *  Setting this flag to TRUE results in using a different algorithm
512 *  for deciding when to save and restore the floating point context.
513 *  The deferred FP switch algorithm minimizes the number of times
514 *  the FP context is saved and restored.  The FP context is not saved
515 *  until a context switch is made to another, different FP task.
516 *  Thus in a system with only one FP task, the FP context will never
517 *  be saved or restored.
518 *
519 *  Note, however that compilers may use floating point registers/
520 *  instructions for optimization or they may save/restore FP registers
521 *  on the stack. You must not use deferred switching in these cases
522 *  and on the PowerPC attempting to do so will raise a "FP unavailable"
523 *  exception.
524 */
525/*
526 *  ACB Note:  This could make debugging tricky..
527 */
528
529/* conservative setting (FALSE); probably doesn't affect performance too much */
530#define CPU_USE_DEFERRED_FP_SWITCH       FALSE
531
532#define CPU_ENABLE_ROBUST_THREAD_DISPATCH FALSE
533
534/*
535 *  Processor defined structures required for cpukit/score.
536 */
537
538#ifndef ASM
539
540/*
541 *  This variable is optional.  It is used on CPUs on which it is difficult
542 *  to generate an "uninitialized" FP context.  It is filled in by
543 *  _CPU_Initialize and copied into the task's FP context area during
544 *  _CPU_Context_Initialize.
545 */
546
547/* EXTERN Context_Control_fp  _CPU_Null_fp_context; */
548
549#endif /* ndef ASM */
550
551/*
552 *  This defines the number of levels and the mask used to pick those
553 *  bits out of a thread mode.
554 */
555
556#define CPU_MODES_INTERRUPT_MASK   0x00000001 /* interrupt level in mode */
557
558/*
559 *  The size of the floating point context area.  On some CPUs this
560 *  will not be a "sizeof" because the format of the floating point
561 *  area is not defined -- only the size is.  This is usually on
562 *  CPUs with a "floating point save context" instruction.
563 */
564
565#define CPU_CONTEXT_FP_SIZE sizeof( Context_Control_fp )
566
567/*
568 * (Optional) # of bytes for libmisc/stackchk to check
569 * If not specifed, then it defaults to something reasonable
570 * for most architectures.
571 */
572
573#define CPU_STACK_CHECK_PATTERN_INITIALIZER \
574  { 0xFEEDF00D, 0x0BAD0D06, 0xDEADF00D, 0x600D0D06, \
575    0xFEEDF00D, 0x0BAD0D06, 0xDEADF00D, 0x600D0D06, \
576    0xFEEDF00D, 0x0BAD0D06, 0xDEADF00D, 0x600D0D06, \
577    0xFEEDF00D, 0x0BAD0D06, 0xDEADF00D, 0x600D0D06, \
578    0xFEEDF00D, 0x0BAD0D06, 0xDEADF00D, 0x600D0D06, \
579    0xFEEDF00D, 0x0BAD0D06, 0xDEADF00D, 0x600D0D06, \
580    0xFEEDF00D, 0x0BAD0D06, 0xDEADF00D, 0x600D0D06, \
581    0xFEEDF00D, 0x0BAD0D06, 0xDEADF00D, 0x600D0D06 }
582
583/*
584 *  Amount of extra stack (above minimum stack size) required by
585 *  MPCI receive server thread.  Remember that in a multiprocessor
586 *  system this thread must exist and be able to process all directives.
587 */
588
589#define CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK 0
590
591/*
592 *  This is defined if the port has a special way to report the ISR nesting
593 *  level.  Most ports maintain the variable _ISR_Nest_level. Note that
594 *  this is not an option - RTEMS/score _relies_ on _ISR_Nest_level
595 *  being maintained (e.g. watchdog queues).
596 */
597
598#define CPU_PROVIDES_ISR_IS_IN_PROGRESS FALSE
599
600/*
601 *  ISR handler macros
602 */
603
604/*
605 *  Disable all interrupts for an RTEMS critical section.  The previous
606 *  level is returned in _isr_cookie.
607 */
608
609#ifndef ASM
610
611static inline bool _CPU_ISR_Is_enabled( uint32_t level )
612{
613  return ( level & MSR_EE ) != 0;
614}
615
616#if !defined(PPC_DISABLE_INLINE_ISR_DISABLE_ENABLE)
617
618static inline uint32_t   _CPU_ISR_Get_level( void )
619{
620  uint32_t msr;
621  _CPU_MSR_GET(msr);
622  if (msr & MSR_EE) return 0;
623  else  return 1;
624}
625
626static inline void _CPU_ISR_Set_level( uint32_t   level )
627{
628  uint32_t msr;
629  _CPU_MSR_GET(msr);
630  if (!(level & CPU_MODES_INTERRUPT_MASK)) {
631    msr |= ppc_interrupt_get_disable_mask();
632  }
633  else {
634    msr &= ~ppc_interrupt_get_disable_mask();
635  }
636  _CPU_MSR_SET(msr);
637}
638#else
639/* disable, enable, etc. are in registers.h */
640uint32_t ppc_get_interrupt_level( void );
641void ppc_set_interrupt_level( uint32_t level );
642#define _CPU_ISR_Get_level( _new_level ) ppc_get_interrupt_level()
643#define _CPU_ISR_Set_level( _new_level ) ppc_set_interrupt_level(_new_level)
644#endif
645
646#endif /* ASM */
647
648/*
649 *  Should be large enough to run all RTEMS tests.  This ensures
650 *  that a "reasonable" small application should not have any problems.
651 */
652
653#define CPU_STACK_MINIMUM_SIZE          (1024*8)
654
655#if defined(__powerpc64__)
656#define CPU_SIZEOF_POINTER 8
657#else
658#define CPU_SIZEOF_POINTER 4
659#endif
660
661/*
662 *  CPU's worst alignment requirement for data types on a byte boundary.  This
663 *  alignment does not take into account the requirements for the stack.
664 */
665
666#define CPU_ALIGNMENT              (PPC_ALIGNMENT)
667
668/*
669 *  This number corresponds to the byte alignment requirement for the
670 *  heap handler.  This alignment requirement may be stricter than that
671 *  for the data types alignment specified by CPU_ALIGNMENT.  It is
672 *  common for the heap to follow the same alignment requirement as
673 *  CPU_ALIGNMENT.  If the CPU_ALIGNMENT is strict enough for the heap,
674 *  then this should be set to CPU_ALIGNMENT.
675 *
676 *  NOTE:  This does not have to be a power of 2.  It does have to
677 *         be greater or equal to than CPU_ALIGNMENT.
678 */
679
680#define CPU_HEAP_ALIGNMENT         (PPC_ALIGNMENT)
681
682#define CPU_STACK_ALIGNMENT        (PPC_STACK_ALIGNMENT)
683
684#define CPU_INTERRUPT_STACK_ALIGNMENT CPU_CACHE_LINE_BYTES
685
686#ifndef ASM
687/*  The following routine swaps the endian format of an unsigned int.
688 *  It must be static because it is referenced indirectly.
689 *
690 *  This version will work on any processor, but if there is a better
691 *  way for your CPU PLEASE use it.  The most common way to do this is to:
692 *
693 *     swap least significant two bytes with 16-bit rotate
694 *     swap upper and lower 16-bits
695 *     swap most significant two bytes with 16-bit rotate
696 *
697 *  Some CPUs have special instructions which swap a 32-bit quantity in
698 *  a single instruction (e.g. i486).  It is probably best to avoid
699 *  an "endian swapping control bit" in the CPU.  One good reason is
700 *  that interrupts would probably have to be disabled to ensure that
701 *  an interrupt does not try to access the same "chunk" with the wrong
702 *  endian.  Another good reason is that on some CPUs, the endian bit
703 *  endianness for ALL fetches -- both code and data -- so the code
704 *  will be fetched incorrectly.
705 */
706
707static inline uint32_t CPU_swap_u32(
708  uint32_t value
709)
710{
711  uint32_t   swapped;
712
713  __asm__ volatile("rlwimi %0,%1,8,24,31;"
714               "rlwimi %0,%1,24,16,23;"
715               "rlwimi %0,%1,8,8,15;"
716               "rlwimi %0,%1,24,0,7;" :
717               "=&r" ((swapped)) : "r" ((value)));
718
719  return( swapped );
720}
721
722#define CPU_swap_u16( value ) \
723  (((value&0xff) << 8) | ((value >> 8)&0xff))
724
725typedef uint32_t CPU_Counter_ticks;
726
727uint32_t _CPU_Counter_frequency( void );
728
729static inline CPU_Counter_ticks _CPU_Counter_read( void )
730{
731  CPU_Counter_ticks value;
732
733#if defined(__PPC_CPU_E6500__)
734  /* Use Alternate Time Base */
735  __asm__ volatile( "mfspr %0, 526" : "=r" (value) );
736#elif defined(mpc860)
737  __asm__ volatile( "mftb %0" : "=r" (value) );
738#else
739  __asm__ volatile( "mfspr %0, 268" : "=r" (value) );
740#endif
741
742  return value;
743}
744
745#endif /* ASM */
746
747
748#ifndef ASM
749/* Context handler macros */
750
751/*
752 *  Initialize the context to a state suitable for starting a
753 *  task after a context restore operation.  Generally, this
754 *  involves:
755 *
756 *     - setting a starting address
757 *     - preparing the stack
758 *     - preparing the stack and frame pointers
759 *     - setting the proper interrupt level in the context
760 *     - initializing the floating point context
761 *
762 *  This routine generally does not set any unnecessary register
763 *  in the context.  The state of the "general data" registers is
764 *  undefined at task start time.
765 */
766
767void _CPU_Context_Initialize(
768  Context_Control  *the_context,
769  void             *stack_base,
770  size_t            size,
771  uint32_t          new_level,
772  void             *entry_point,
773  bool              is_fp,
774  void             *tls_area
775);
776
777/*
778 *  This routine is responsible for somehow restarting the currently
779 *  executing task.  If you are lucky, then all that is necessary
780 *  is restoring the context.  Otherwise, there will need to be
781 *  a special assembly routine which does something special in this
782 *  case.  Context_Restore should work most of the time.  It will
783 *  not work if restarting self conflicts with the stack frame
784 *  assumptions of restoring a context.
785 */
786
787#define _CPU_Context_Restart_self( _the_context ) \
788   _CPU_Context_restore( (_the_context) );
789
790/*
791 *  This routine initializes the FP context area passed to it to.
792 *  There are a few standard ways in which to initialize the
793 *  floating point context.  The code included for this macro assumes
794 *  that this is a CPU in which a "initial" FP context was saved into
795 *  _CPU_Null_fp_context and it simply copies it to the destination
796 *  context passed to it.
797 *
798 *  Other models include (1) not doing anything, and (2) putting
799 *  a "null FP status word" in the correct place in the FP context.
800 */
801
802#define _CPU_Context_Initialize_fp( _destination ) \
803  memset( *(_destination), 0, sizeof( **(_destination) ) )
804
805/* end of Context handler macros */
806#endif /* ASM */
807
808#ifndef ASM
809
810#define CPU_USE_LIBC_INIT_FINI_ARRAY FALSE
811
812/* Bitfield handler macros */
813
814#define CPU_USE_GENERIC_BITFIELD_CODE FALSE
815
816/*
817 *  This routine sets _output to the bit number of the first bit
818 *  set in _value.  _value is of CPU dependent type Priority_bit_map_Word.
819 *  This type may be either 16 or 32 bits wide although only the 16
820 *  least significant bits will be used.
821 *
822 *  There are a number of variables in using a "find first bit" type
823 *  instruction.
824 *
825 *    (1) What happens when run on a value of zero?
826 *    (2) Bits may be numbered from MSB to LSB or vice-versa.
827 *    (3) The numbering may be zero or one based.
828 *    (4) The "find first bit" instruction may search from MSB or LSB.
829 *
830 *  RTEMS guarantees that (1) will never happen so it is not a concern.
831 *  (2),(3), (4) are handled by the macros _CPU_Priority_mask() and
832 *  _CPU_Priority_Bits_index().  These three form a set of routines
833 *  which must logically operate together.  Bits in the _value are
834 *  set and cleared based on masks built by _CPU_Priority_mask().
835 *  The basic major and minor values calculated by _Priority_Major()
836 *  and _Priority_Minor() are "massaged" by _CPU_Priority_Bits_index()
837 *  to properly range between the values returned by the "find first bit"
838 *  instruction.  This makes it possible for _Priority_Get_highest() to
839 *  calculate the major and directly index into the minor table.
840 *  This mapping is necessary to ensure that 0 (a high priority major/minor)
841 *  is the first bit found.
842 *
843 *  This entire "find first bit" and mapping process depends heavily
844 *  on the manner in which a priority is broken into a major and minor
845 *  components with the major being the 4 MSB of a priority and minor
846 *  the 4 LSB.  Thus (0 << 4) + 0 corresponds to priority 0 -- the highest
847 *  priority.  And (15 << 4) + 14 corresponds to priority 254 -- the next
848 *  to the lowest priority.
849 *
850 *  If your CPU does not have a "find first bit" instruction, then
851 *  there are ways to make do without it.  Here are a handful of ways
852 *  to implement this in software:
853 *
854 *    - a series of 16 bit test instructions
855 *    - a "binary search using if's"
856 *    - _number = 0
857 *      if _value > 0x00ff
858 *        _value >>=8
859 *        _number = 8;
860 *
861 *      if _value > 0x0000f
862 *        _value >=8
863 *        _number += 4
864 *
865 *      _number += bit_set_table[ _value ]
866 *
867 *    where bit_set_table[ 16 ] has values which indicate the first
868 *      bit set
869 */
870
871#define _CPU_Bitfield_Find_first_bit( _value, _output ) \
872  { \
873    __asm__ volatile ("cntlzw %0, %1" : "=r" ((_output)), "=r" ((_value)) : \
874                  "1" ((_value))); \
875    (_output) = (_output) - 16; \
876  }
877
878/* end of Bitfield handler macros */
879
880/*
881 *  This routine builds the mask which corresponds to the bit fields
882 *  as searched by _CPU_Bitfield_Find_first_bit().  See the discussion
883 *  for that routine.
884 */
885
886#define _CPU_Priority_Mask( _bit_number ) \
887  ( 0x8000u >> (_bit_number) )
888
889/*
890 *  This routine translates the bit numbers returned by
891 *  _CPU_Bitfield_Find_first_bit() into something suitable for use as
892 *  a major or minor component of a priority.  See the discussion
893 *  for that routine.
894 */
895
896#define _CPU_Priority_bits_index( _priority ) \
897  (_priority)
898
899/* end of Priority handler macros */
900#endif /* ASM */
901
902/* functions */
903
904#ifndef ASM
905
906/*
907 *  _CPU_Initialize
908 *
909 *  This routine performs CPU dependent initialization.
910 */
911
912void _CPU_Initialize(void);
913
914void *_CPU_Thread_Idle_body( uintptr_t ignored );
915
916/*
917 *  _CPU_Context_switch
918 *
919 *  This routine switches from the run context to the heir context.
920 */
921
922void _CPU_Context_switch(
923  Context_Control  *run,
924  Context_Control  *heir
925);
926
927RTEMS_NO_RETURN void _CPU_Context_switch_no_return(
928  Context_Control *executing,
929  Context_Control *heir
930);
931
932/*
933 *  _CPU_Context_restore
934 *
935 *  This routine is generallu used only to restart self in an
936 *  efficient manner.  It may simply be a label in _CPU_Context_switch.
937 *
938 *  NOTE: May be unnecessary to reload some registers.
939 */
940
941RTEMS_NO_RETURN void _CPU_Context_restore( Context_Control *new_context );
942
943/*
944 *  _CPU_Context_save_fp
945 *
946 *  This routine saves the floating point context passed to it.
947 */
948
949void _CPU_Context_save_fp(
950  Context_Control_fp **fp_context_ptr
951);
952
953/*
954 *  _CPU_Context_restore_fp
955 *
956 *  This routine restores the floating point context passed to it.
957 */
958
959void _CPU_Context_restore_fp(
960  Context_Control_fp **fp_context_ptr
961);
962
963#ifdef RTEMS_SMP
964  uint32_t _CPU_SMP_Initialize( void );
965
966  bool _CPU_SMP_Start_processor( uint32_t cpu_index );
967
968  void _CPU_SMP_Finalize_initialization( uint32_t cpu_count );
969
970  void _CPU_SMP_Prepare_start_multitasking( void );
971
972  static inline uint32_t _CPU_SMP_Get_current_processor( void )
973  {
974    uint32_t pir;
975
976    /* Use Book E Processor ID Register (PIR) */
977    __asm__ volatile (
978      "mfspr %[pir], 286"
979      : [pir] "=&r" (pir)
980    );
981
982    return pir;
983  }
984
985  void _CPU_SMP_Send_interrupt( uint32_t target_processor_index );
986#endif
987
988typedef struct {
989  uintptr_t EXC_SRR0;
990  uintptr_t EXC_SRR1;
991  uint32_t _EXC_number;
992  uint32_t RESERVED_FOR_ALIGNMENT_0;
993  uint32_t EXC_CR;
994  uint32_t EXC_XER;
995  uintptr_t EXC_CTR;
996  uintptr_t EXC_LR;
997  uintptr_t RESERVED_FOR_ALIGNMENT_1;
998  #ifdef __SPE__
999    uint32_t EXC_SPEFSCR;
1000    uint64_t EXC_ACC;
1001  #endif
1002  PPC_GPR_TYPE GPR0;
1003  PPC_GPR_TYPE GPR1;
1004  PPC_GPR_TYPE GPR2;
1005  PPC_GPR_TYPE GPR3;
1006  PPC_GPR_TYPE GPR4;
1007  PPC_GPR_TYPE GPR5;
1008  PPC_GPR_TYPE GPR6;
1009  PPC_GPR_TYPE GPR7;
1010  PPC_GPR_TYPE GPR8;
1011  PPC_GPR_TYPE GPR9;
1012  PPC_GPR_TYPE GPR10;
1013  PPC_GPR_TYPE GPR11;
1014  PPC_GPR_TYPE GPR12;
1015  PPC_GPR_TYPE GPR13;
1016  PPC_GPR_TYPE GPR14;
1017  PPC_GPR_TYPE GPR15;
1018  PPC_GPR_TYPE GPR16;
1019  PPC_GPR_TYPE GPR17;
1020  PPC_GPR_TYPE GPR18;
1021  PPC_GPR_TYPE GPR19;
1022  PPC_GPR_TYPE GPR20;
1023  PPC_GPR_TYPE GPR21;
1024  PPC_GPR_TYPE GPR22;
1025  PPC_GPR_TYPE GPR23;
1026  PPC_GPR_TYPE GPR24;
1027  PPC_GPR_TYPE GPR25;
1028  PPC_GPR_TYPE GPR26;
1029  PPC_GPR_TYPE GPR27;
1030  PPC_GPR_TYPE GPR28;
1031  PPC_GPR_TYPE GPR29;
1032  PPC_GPR_TYPE GPR30;
1033  PPC_GPR_TYPE GPR31;
1034  uintptr_t RESERVED_FOR_ALIGNMENT_2;
1035  #ifdef PPC_MULTILIB_ALTIVEC
1036    uint32_t VRSAVE;
1037    uint32_t RESERVED_FOR_ALIGNMENT_3[3];
1038
1039    /* This field must take stvewx/lvewx requirements into account */
1040    uint32_t RESERVED_FOR_ALIGNMENT_4[3];
1041    uint32_t VSCR;
1042
1043    uint8_t V0[16];
1044    uint8_t V1[16];
1045    uint8_t V2[16];
1046    uint8_t V3[16];
1047    uint8_t V4[16];
1048    uint8_t V5[16];
1049    uint8_t V6[16];
1050    uint8_t V7[16];
1051    uint8_t V8[16];
1052    uint8_t V9[16];
1053    uint8_t V10[16];
1054    uint8_t V11[16];
1055    uint8_t V12[16];
1056    uint8_t V13[16];
1057    uint8_t V14[16];
1058    uint8_t V15[16];
1059    uint8_t V16[16];
1060    uint8_t V17[16];
1061    uint8_t V18[16];
1062    uint8_t V19[16];
1063    uint8_t V20[16];
1064    uint8_t V21[16];
1065    uint8_t V22[16];
1066    uint8_t V23[16];
1067    uint8_t V24[16];
1068    uint8_t V25[16];
1069    uint8_t V26[16];
1070    uint8_t V27[16];
1071    uint8_t V28[16];
1072    uint8_t V29[16];
1073    uint8_t V30[16];
1074    uint8_t V31[16];
1075  #endif
1076  #ifdef PPC_MULTILIB_FPU
1077    double F0;
1078    double F1;
1079    double F2;
1080    double F3;
1081    double F4;
1082    double F5;
1083    double F6;
1084    double F7;
1085    double F8;
1086    double F9;
1087    double F10;
1088    double F11;
1089    double F12;
1090    double F13;
1091    double F14;
1092    double F15;
1093    double F16;
1094    double F17;
1095    double F18;
1096    double F19;
1097    double F20;
1098    double F21;
1099    double F22;
1100    double F23;
1101    double F24;
1102    double F25;
1103    double F26;
1104    double F27;
1105    double F28;
1106    double F29;
1107    double F30;
1108    double F31;
1109    uint64_t FPSCR;
1110    uint64_t RESERVED_FOR_ALIGNMENT_5;
1111  #endif
1112} CPU_Exception_frame;
1113
1114void _CPU_Exception_frame_print( const CPU_Exception_frame *frame );
1115
1116/*
1117 * _CPU_Initialize_altivec()
1118 *
1119 * Global altivec-related initialization.
1120 */
1121void
1122_CPU_Initialize_altivec(void);
1123
1124/*
1125 * _CPU_Context_switch_altivec
1126 *
1127 * This routine switches the altivec contexts passed to it.
1128 */
1129
1130void
1131_CPU_Context_switch_altivec(
1132  ppc_context *from,
1133  ppc_context *to
1134);
1135
1136/*
1137 * _CPU_Context_restore_altivec
1138 *
1139 * This routine restores the altivec context passed to it.
1140 */
1141
1142void
1143_CPU_Context_restore_altivec(
1144  ppc_context *ctxt
1145);
1146
1147/*
1148 * _CPU_Context_initialize_altivec
1149 *
1150 * This routine initializes the altivec context passed to it.
1151 */
1152
1153void
1154_CPU_Context_initialize_altivec(
1155  ppc_context *ctxt
1156);
1157
1158void _CPU_Fatal_error(
1159  uint32_t   _error
1160);
1161
1162/** Type that can store a 32-bit integer or a pointer. */
1163typedef uintptr_t CPU_Uint32ptr;
1164
1165#endif /* ASM */
1166
1167#ifdef __cplusplus
1168}
1169#endif
1170
1171#endif /* _RTEMS_SCORE_CPU_H */
Note: See TracBrowser for help on using the repository browser.