Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:53

0001 /*
0002  * Copyright (C) 1999  Eric Valette (valette@crf.canon.fr)
0003  *                     Canon Centre Recherche France.
0004  *
0005  *  Added MPC8260 Andy Dachs <a.dachs@sstl.co.uk>
0006  *  Surrey Satellite Technology Limited
0007  *
0008  *
0009  *  The license and distribution terms for this file may be
0010  *  found in the file LICENSE in this distribution or at
0011  *  http://www.rtems.org/license/LICENSE.
0012  */
0013 
0014 #ifndef _LIBCPU_CPUIDENT_H
0015 #define _LIBCPU_CPUIDENT_H
0016 
0017 #include <stdbool.h>
0018 
0019 #ifdef __cplusplus
0020 extern "C" {
0021 #endif
0022 
0023 #ifndef ASM
0024 typedef enum
0025 {
0026   PPC_601 = 0x1,
0027   PPC_5XX = 0x2,
0028   PPC_603 = 0x3,
0029   PPC_604 = 0x4,
0030   PPC_603e = 0x6,
0031   PPC_603ev = 0x7,
0032   PPC_750 = 0x8,
0033   PPC_750_IBM = 0x7000,
0034   PPC_604e = 0x9,
0035   PPC_604r = 0xA,
0036   PPC_7400 = 0xC,
0037   PPC_405  = 0x2001,  /* Xilinx Virtex-II Pro or -4 */
0038   PPC_405EX = 0x1291,   /* + 405EXr */
0039   PPC_405GP = 0x4011,   /* + 405CR */
0040   PPC_405GPr = 0x5091,
0041   PPC_405EZ = 0x4151,
0042   PPC_405EP = 0x5121,
0043   PPC_440 = 0x7ff2,  /* Xilinx Virtex-5*/
0044   PPC_7455 = 0x8001, /* Kate Feng */
0045   PPC_7457 = 0x8002,
0046   PPC_620 = 0x16,
0047   PPC_860 = 0x50,
0048   PPC_821 = PPC_860,
0049   PPC_823 = PPC_860,
0050   PPC_8260 = 0x81,
0051   PPC_8240 = PPC_8260,
0052   PPC_8245 = 0x8081,
0053   PPC_8540 = 0x8020,
0054   PPC_e500v2 = 0x8021,
0055   PPC_e6500 = 0x8040,
0056   PPC_603le = 0x8082, /* 603le core, in MGT5100 and MPC5200 */
0057   PPC_e300c1  = 0x8083, /* e300c1  core, in MPC83xx*/
0058   PPC_e300c2  = 0x8084, /* e300c2  core */
0059   PPC_e300c3  = 0x8085, /* e300c3  core */
0060   PPC_e200z0  = 0x8170,
0061   PPC_e200z1  = 0x8140,
0062   PPC_e200z4  = 0x8150,
0063   PPC_e200z6  = 0x8110,
0064   PPC_e200z7  = 0x8160,
0065   PPC_PSIM    = 0xfffe,  /* GDB PowerPC simulator -- fake version */
0066   PPC_UNKNOWN = 0xffff
0067 } ppc_cpu_id_t;
0068 
0069 /* Bitfield of for identifying features or groups of cpu flavors.
0070  * DO NOT USE DIRECTLY (as implementation may change)
0071  * only use the 'ppc_is_xxx() / ppc_has_xxx()' macros/inlines
0072  * below.
0073  */
0074 
0075 typedef struct {
0076     unsigned has_altivec        : 1;
0077     unsigned has_fpu            : 1;
0078     unsigned has_hw_ptbl_lkup   : 1;
0079 #define PPC_BOOKE_405   1   /* almost like booke but with some significant differences */
0080 #define PPC_BOOKE_STD   2
0081 #define PPC_BOOKE_E500  3   /* bookE with extensions */
0082     unsigned is_bookE           : 2;
0083     unsigned has_16byte_clne    : 1;
0084     unsigned is_60x             : 1;
0085     unsigned has_8_bats         : 1;
0086     unsigned has_epic           : 1;
0087     unsigned has_shadowed_gprs  : 1;
0088 } ppc_feature_t;
0089 
0090 extern ppc_feature_t   current_ppc_features;
0091 extern ppc_cpu_id_t current_ppc_cpu;
0092 
0093 typedef unsigned short ppc_cpu_revision_t;
0094 
0095 extern ppc_cpu_id_t get_ppc_cpu_type (void);
0096 extern const char *get_ppc_cpu_type_name(ppc_cpu_id_t cpu);
0097 extern ppc_cpu_revision_t get_ppc_cpu_revision (void);
0098 extern ppc_cpu_revision_t current_ppc_revision;
0099 
0100 /* PUBLIC ACCESS ROUTINES */
0101 #define _PPC_FEAT_DECL(x) \
0102 static inline unsigned ppc_cpu_##x(void) { \
0103   if ( PPC_UNKNOWN == current_ppc_cpu ) \
0104     get_ppc_cpu_type(); \
0105   return current_ppc_features.x; \
0106 }
0107 
0108 _PPC_FEAT_DECL(has_altivec)
0109 /* has_fpu not implemented yet */
0110 _PPC_FEAT_DECL(has_hw_ptbl_lkup)
0111 _PPC_FEAT_DECL(is_bookE)
0112 _PPC_FEAT_DECL(is_60x)
0113 _PPC_FEAT_DECL(has_8_bats)
0114 _PPC_FEAT_DECL(has_epic)
0115 _PPC_FEAT_DECL(has_shadowed_gprs)
0116 
0117 #undef _PPC_FEAT_DECL
0118 
0119 static inline ppc_cpu_id_t ppc_cpu_current(void)
0120 {
0121     return current_ppc_cpu;
0122 }
0123 
0124 static inline bool ppc_cpu_is_e200(void)
0125 {
0126     return (ppc_cpu_current() & 0xff80) == 0x8100;
0127 }
0128 
0129 static inline bool ppc_cpu_is_specific_e200(ppc_cpu_id_t id)
0130 {
0131     return (ppc_cpu_current() & 0xfff0) == id;
0132 }
0133 
0134 static inline bool ppc_cpu_is_e300(void)
0135 {
0136     return ppc_cpu_current() == PPC_e300c1
0137         || ppc_cpu_current() == PPC_e300c2
0138         || ppc_cpu_current() == PPC_e300c3;
0139 }
0140 
0141 static inline bool ppc_cpu_is_e500(void)
0142 {
0143     return ppc_cpu_current() == PPC_8540
0144         || ppc_cpu_current() == PPC_e500v2;
0145 }
0146 
0147 static inline bool ppc_cpu_is(ppc_cpu_id_t cpu)
0148 {
0149     return ppc_cpu_current() == cpu;
0150 }
0151 
0152 #endif /* ASM */
0153 
0154 #ifdef __cplusplus
0155 }
0156 #endif
0157 
0158 #endif