• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * \file       trc_core_arch_map.cpp
3  * \brief      OpenCSD : Map core names to architecture profiles
4  *
5  * \copyright  Copyright (c) 2015, ARM Limited. All Rights Reserved.
6  */
7 
8 /*
9  * Redistribution and use in source and binary forms, with or without modification,
10  * are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3. Neither the name of the copyright holder nor the names of its contributors
20  * may be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #include "common/trc_core_arch_map.h"
36 
37 typedef struct _ap_map_elements {
38     const char *name;
39     ocsd_arch_profile_t ap;
40 } ap_map_elem_t;
41 
42 static ap_map_elem_t ap_map_array[] =
43 {
44     { "Cortex-A77", { ARCH_V8r3, profile_CortexA } },
45     { "Cortex-A76", { ARCH_V8r3, profile_CortexA } },
46     { "Cortex-A75", { ARCH_V8r3, profile_CortexA } },
47     { "Cortex-A73", { ARCH_V8, profile_CortexA } },
48     { "Cortex-A72", { ARCH_V8, profile_CortexA } },
49     { "Cortex-A65", { ARCH_V8r3, profile_CortexA } },
50     { "Cortex-A57", { ARCH_V8, profile_CortexA } },
51     { "Cortex-A55", { ARCH_V8r3, profile_CortexA } },
52     { "Cortex-A53", { ARCH_V8, profile_CortexA } },
53     { "Cortex-A35", { ARCH_V8, profile_CortexA } },
54     { "Cortex-A32", { ARCH_V8, profile_CortexA } },
55     { "Cortex-A17", { ARCH_V7, profile_CortexA } },
56     { "Cortex-A15", { ARCH_V7, profile_CortexA } },
57     { "Cortex-A12", { ARCH_V7, profile_CortexA } },
58     { "Cortex-A9", { ARCH_V7, profile_CortexA } },
59     { "Cortex-A8", { ARCH_V7, profile_CortexA } },
60     { "Cortex-A7", { ARCH_V7, profile_CortexA } },
61     { "Cortex-A5", { ARCH_V7, profile_CortexA } },
62     { "Cortex-R52", { ARCH_V8, profile_CortexR } },
63     { "Cortex-R8", { ARCH_V7, profile_CortexR } },
64     { "Cortex-R7", { ARCH_V7, profile_CortexR } },
65     { "Cortex-R5", { ARCH_V7, profile_CortexR } },
66     { "Cortex-R4", { ARCH_V7, profile_CortexR } },
67     { "Cortex-M33", { ARCH_V8, profile_CortexM } },
68     { "Cortex-M23", { ARCH_V8, profile_CortexM } },
69     { "Cortex-M0", { ARCH_V7, profile_CortexM } },
70     { "Cortex-M0+", { ARCH_V7, profile_CortexM } },
71     { "Cortex-M3", { ARCH_V7, profile_CortexM } },
72     { "Cortex-M4", { ARCH_V7, profile_CortexM } }
73 };
74 
CoreArchProfileMap()75 CoreArchProfileMap::CoreArchProfileMap()
76 {
77     unsigned i;
78     for (i = 0; i < sizeof(ap_map_array) / sizeof(_ap_map_elements); i++)
79     {
80         core_profiles[ap_map_array[i].name] = ap_map_array[i].ap;
81     }
82 }
83 
getArchProfile(const std::string & coreName)84 ocsd_arch_profile_t CoreArchProfileMap::getArchProfile(const std::string &coreName)
85 {
86     ocsd_arch_profile_t ap = { ARCH_UNKNOWN, profile_Unknown };
87     bool bFound = false;
88 
89     std::map<std::string, ocsd_arch_profile_t>::const_iterator it;
90 
91     /* match against the core name map. */
92     it = core_profiles.find(coreName);
93     if (it != core_profiles.end())
94     {
95         ap = it->second;
96         bFound = true;
97     }
98 
99     /* try a pattern match on core name - pick up ARMvM[.m]-P and ARM-{aa|AA}64[-P] */
100     if (!bFound)
101         ap = getPatternMatchCoreName(coreName);
102 
103     return ap;
104 }
getPatternMatchCoreName(const std::string & coreName)105 ocsd_arch_profile_t CoreArchProfileMap::getPatternMatchCoreName(const std::string &coreName)
106 {
107     ocsd_arch_profile_t ap = { ARCH_UNKNOWN, profile_Unknown };
108     size_t pos;
109 
110     /* look for ARMvM[.m]-P */
111     pos = coreName.find("ARMv");
112     if (pos == 0)
113     {
114         int majver = coreName[4] - '0';
115         int minver = 0;
116         int dotoffset = 0;
117 
118         pos = coreName.find_first_of(".");
119         if (pos == 5) {
120             minver = coreName[6] - '0';
121             dotoffset = 2;
122         }
123         else if (pos != std::string::npos)
124             return ap;
125 
126         if (majver == 7)
127             ap.arch = ARCH_V7;
128         else if (majver >= 8) {
129             ap.arch = ARCH_AA64; /* default to 8.3+*/
130             if (majver == 8) {
131                 if (minver < 3)
132                     ap.arch = ARCH_V8;
133                 else if (minver == 3)
134                     ap.arch = ARCH_V8r3;
135             }
136         }
137         else
138             return ap; /* no valid version  - return unknown */
139 
140         if (coreName.find_first_of("-", 4) == (size_t)(5 + dotoffset)) {
141             int profile_idx = 6 + dotoffset;
142             if (coreName[profile_idx] == 'A')
143                 ap.profile = profile_CortexA;
144             else if (coreName[profile_idx] == 'R')
145                 ap.profile = profile_CortexR;
146             else if (coreName[profile_idx] == 'M')
147                 ap.profile = profile_CortexM;
148             else
149                 ap.arch = ARCH_UNKNOWN; /*reset arch, return unknown*/
150         }
151         else
152             ap.arch = ARCH_UNKNOWN; /*reset arch, return unknown*/
153         return ap;
154     }
155 
156     /* look for ARM-{AA|aa}64[-P] */
157     pos = coreName.find("ARM-");
158     if (pos == 0)
159     {
160         pos = coreName.find("aa64");
161         if (pos != 4)
162             pos = coreName.find("AA64");
163         if (pos == 4)
164         {
165             ap.arch = ARCH_AA64;
166             ap.profile = profile_CortexA;
167             if (coreName.find_first_of("-", 7) == 8) {
168                 if (coreName[9] == 'R')
169                     ap.profile = profile_CortexR;
170                 else if (coreName[9] == 'M')
171                     ap.profile = profile_CortexM;
172             }
173         }
174     }
175     return ap;
176 }
177 /* End of File trc_core_arch_map.cpp */
178