RTEMS 7.0-rc1
Loading...
Searching...
No Matches
cpuIdent.h
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 * Copyright (C) 1999 Eric Valette (eric.valette@free.fr)
5 * Copyright (C) 2000 Andy Dachs <a.dachs@sstl.co.uk>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef _LIBCPU_CPUIDENT_H
30#define _LIBCPU_CPUIDENT_H
31
32#include <stdbool.h>
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38#ifndef ASM
39typedef enum
40{
41 PPC_601 = 0x1,
42 PPC_5XX = 0x2,
43 PPC_603 = 0x3,
44 PPC_604 = 0x4,
45 PPC_603e = 0x6,
46 PPC_603ev = 0x7,
47 PPC_750 = 0x8,
48 PPC_750_IBM = 0x7000,
49 PPC_604e = 0x9,
50 PPC_604r = 0xA,
51 PPC_7400 = 0xC,
52 PPC_405 = 0x2001, /* Xilinx Virtex-II Pro or -4 */
53 PPC_405EX = 0x1291, /* + 405EXr */
54 PPC_405GP = 0x4011, /* + 405CR */
55 PPC_405GPr = 0x5091,
56 PPC_405EZ = 0x4151,
57 PPC_405EP = 0x5121,
58 PPC_440 = 0x7ff2, /* Xilinx Virtex-5*/
59 PPC_7455 = 0x8001, /* Kate Feng */
60 PPC_7457 = 0x8002,
61 PPC_620 = 0x16,
62 PPC_860 = 0x50,
63 PPC_821 = PPC_860,
64 PPC_823 = PPC_860,
65 PPC_8260 = 0x81,
66 PPC_8240 = PPC_8260,
67 PPC_8245 = 0x8081,
68 PPC_8540 = 0x8020,
69 PPC_e500v2 = 0x8021,
70 PPC_e6500 = 0x8040,
71 PPC_603le = 0x8082, /* 603le core, in MGT5100 and MPC5200 */
72 PPC_e300c1 = 0x8083, /* e300c1 core, in MPC83xx*/
73 PPC_e300c2 = 0x8084, /* e300c2 core */
74 PPC_e300c3 = 0x8085, /* e300c3 core */
75 PPC_e200z0 = 0x8170,
76 PPC_e200z1 = 0x8140,
77 PPC_e200z4 = 0x8150,
78 PPC_e200z6 = 0x8110,
79 PPC_e200z7 = 0x8160,
80 PPC_PSIM = 0xfffe, /* GDB PowerPC simulator -- fake version */
81 PPC_UNKNOWN = 0xffff
82} ppc_cpu_id_t;
83
84/* Bitfield of for identifying features or groups of cpu flavors.
85 * DO NOT USE DIRECTLY (as implementation may change)
86 * only use the 'ppc_is_xxx() / ppc_has_xxx()' macros/inlines
87 * below.
88 */
89
90typedef struct {
91 unsigned has_altivec : 1;
92 unsigned has_fpu : 1;
93 unsigned has_hw_ptbl_lkup : 1;
94#define PPC_BOOKE_405 1 /* almost like booke but with some significant differences */
95#define PPC_BOOKE_STD 2
96#define PPC_BOOKE_E500 3 /* bookE with extensions */
97 unsigned is_bookE : 2;
98 unsigned has_16byte_clne : 1;
99 unsigned is_60x : 1;
100 unsigned has_8_bats : 1;
101 unsigned has_epic : 1;
102 unsigned has_shadowed_gprs : 1;
104
105extern ppc_feature_t current_ppc_features;
106extern ppc_cpu_id_t current_ppc_cpu;
107
108typedef unsigned short ppc_cpu_revision_t;
109
110extern ppc_cpu_id_t get_ppc_cpu_type (void);
111extern const char *get_ppc_cpu_type_name(ppc_cpu_id_t cpu);
112extern ppc_cpu_revision_t get_ppc_cpu_revision (void);
113extern ppc_cpu_revision_t current_ppc_revision;
114
115/* PUBLIC ACCESS ROUTINES */
116#define _PPC_FEAT_DECL(x) \
117static inline unsigned ppc_cpu_##x(void) { \
118 if ( PPC_UNKNOWN == current_ppc_cpu ) \
119 get_ppc_cpu_type(); \
120 return current_ppc_features.x; \
121}
122
123_PPC_FEAT_DECL(has_altivec)
124/* has_fpu not implemented yet */
125_PPC_FEAT_DECL(has_hw_ptbl_lkup)
126_PPC_FEAT_DECL(is_bookE)
127_PPC_FEAT_DECL(is_60x)
128_PPC_FEAT_DECL(has_8_bats)
129_PPC_FEAT_DECL(has_epic)
130_PPC_FEAT_DECL(has_shadowed_gprs)
131
132#undef _PPC_FEAT_DECL
133
134static inline ppc_cpu_id_t ppc_cpu_current(void)
135{
136 return current_ppc_cpu;
137}
138
139static inline bool ppc_cpu_is_e200(void)
140{
141 return (ppc_cpu_current() & 0xff80) == 0x8100;
142}
143
144static inline bool ppc_cpu_is_specific_e200(ppc_cpu_id_t id)
145{
146 return (ppc_cpu_current() & 0xfff0) == id;
147}
148
149static inline bool ppc_cpu_is_e300(void)
150{
151 return ppc_cpu_current() == PPC_e300c1
152 || ppc_cpu_current() == PPC_e300c2
153 || ppc_cpu_current() == PPC_e300c3;
154}
155
156static inline bool ppc_cpu_is_e500(void)
157{
158 return ppc_cpu_current() == PPC_8540
159 || ppc_cpu_current() == PPC_e500v2;
160}
161
162static inline bool ppc_cpu_is(ppc_cpu_id_t cpu)
163{
164 return ppc_cpu_current() == cpu;
165}
166
167#endif /* ASM */
168
169#ifdef __cplusplus
170}
171#endif
172
173#endif
Definition: cpuIdent.h:90