-
Notifications
You must be signed in to change notification settings - Fork 12
/
aarch
executable file
·264 lines (255 loc) · 8.04 KB
/
aarch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#! /usr/bin/env lua
if _VERSION ~= "Lua 5.3" then
print( _VERSION )
print( "Please install Lua >=5.3" )
print( "" )
os.exit( 1 )
else
if #arg <= 0 then
print( "Use :" )
print( arg[ 0 ] .. " < cpushow | march | mtune >" )
print( "" )
os.exit( 1 )
end
end
local CPUINFO
local CPUS = {}
local MACHINE = {}
MACHINE.big = {}
MACHINE.LITTLE = {}
-- 0xc09
MACHINE.big[ 3081 ] = { tune = "cortex-a9", arch = "armv7-a" }
-- 0xc0f
MACHINE.big[ 3087 ] = { tune = "cortex-a15", arch = "armv7-a" }
-- 0xc0e
MACHINE.big[ 3086 ] = { tune = "cortex-a17", arch = "armv7-a" }
-- 0xd07
MACHINE.big[ 3335 ] = { tune = "cortex-a57", arch = "armv8-a+crc"}
-- 0xd08
MACHINE.big[ 3336 ] = { tune = "cortex-a72", arch = "armv8-a+crc"}
-- 0xd09
MACHINE.big[ 3337 ] = { tune = "cortex-a73", arch = "armv8-a+crc"}
-- 0xd0a
MACHINE.big[ 3338 ] = { tune = "cortex-a75", arch = "armv8.2-a" }
-- 0xd0b
MACHINE.big[ 3339 ] = { tune = "cortex-a76", arch = "armv8.2-a" }
-- 0xd0d
MACHINE.big[ 3341 ] = { tune = "cortex-a77", arch = "armv8.2-a" }
-- 0xd47
MACHINE.big[ 3399 ] = { tune = "cortex-a710", arch = "armv9-a" }
-- 0xb76
MACHINE.LITTLE[ 2934 ] = { tune = "arm1176jzf-s", arch = "armv6" }
-- 0xc07
MACHINE.LITTLE[ 3079 ] = { tune = "cortex-a7", arch = "armv7-a" }
-- 0xd04
MACHINE.LITTLE[ 3332 ] = { tune = "cortex-a35", arch = "armv8-a+crc"}
-- 0xd03
MACHINE.LITTLE[ 3331 ] = { tune = "cortex-a53", arch = "armv8-a+crc"}
-- 0xd05
MACHINE.LITTLE[ 3333 ] = { tune = "cortex-a55", arch = "armv8.2-a" }
-- 0xd46
MACHINE.LITTLE[ 3398 ] = { tune = "cortex-a510", arch = "armv9-a" }
-- Implementer Manufacturer ID
local manIdimplementer = {
{ mask = 0xff000000, val = 0x41000000, id = "ARM" },
{ mask = 0xff000000, val = 0x42000000, id = "Broadcom" },
{ mask = 0xff000000, val = 0x43000000, id = "Cavium" },
{ mask = 0xff000000, val = 0x4d000000, id = "Motorola" },
{ mask = 0xff000000, val = 0x4e000000, id = "Nvidia" },
{ mask = 0xff000000, val = 0x50000000, id = "Applied Micro" },
{ mask = 0xff000000, val = 0x51000000, id = "Qualcomm" },
{ mask = 0xff000000, val = 0x53000000, id = "Samsung" },
{ mask = 0xff000000, val = 0x61000000, id = "Apple" }
}
-- Part Manufacturer ID
local manIdpart = {
-- ARM
{ mask = 0xff00fff0, val = 0x4100b760, id = "arm1176jzf-s" },
{ mask = 0xff00fff0, val = 0x4100c070, id = "Cortex-A7" },
{ mask = 0xff00fff0, val = 0x4100c090, id = "Cortex-A9" },
{ mask = 0xff00fff0, val = 0x4100c0e0, id = "Cortex-A17" },
{ mask = 0xff00fff0, val = 0x4100c0f0, id = "Cortex-A15" },
{ mask = 0xff00fff0, val = 0x4100d030, id = "Cortex-A53" },
{ mask = 0xff00fff0, val = 0x4100d040, id = "Cortex-A35" },
{ mask = 0xff00fff0, val = 0x4100d050, id = "Cortex-A55" },
{ mask = 0xff00fff0, val = 0x4100d070, id = "Cortex-A57" },
{ mask = 0xff00fff0, val = 0x4100d080, id = "Cortex-A72" },
{ mask = 0xff00fff0, val = 0x4100d090, id = "Cortex-A73" },
{ mask = 0xff00fff0, val = 0x4100d0a0, id = "Cortex-A75" },
{ mask = 0xff00fff0, val = 0x4100d0b0, id = "Cortex-A76" },
{ mask = 0xff00fff0, val = 0x4100d0d0, id = "Cortex-A77" },
{ mask = 0xff00fff0, val = 0x4100d460, id = "Cortex-A510" },
{ mask = 0xff00fff0, val = 0x4100d470, id = "Cortex-A710" },
-- Broadcom
{ mask = 0xff00fff0, val = 0x42001000, id = "Brahma-B53" },
{ mask = 0xff00fff0, val = 0x42005160, id = "ThunderX2" },
-- Cavium
{ mask = 0xff00fff0, val = 0x43000a00, id = "ThunderX" },
{ mask = 0xff00fff0, val = 0x43000a10, id = "ThunderX 88xx" },
{ mask = 0xff00fff0, val = 0x43000a20, id = "ThunderX 81xx" },
{ mask = 0xff00fff0, val = 0x43000a30, id = "ThunderX 83xx" },
{ mask = 0xff00fff0, val = 0x43000af0, id = "ThunderX2 99xx" },
-- Motorola
-- Nvidia
{ mask = 0xff00fff0, val = 0x4e000000, id = "Denver" },
{ mask = 0xff00fff0, val = 0x4e000030, id = "Denver 2" },
-- Applied Micro
{ mask = 0xff00fff0, val = 0x50000000, id = "X-Gene" },
-- Qualcomm
{ mask = 0xff00fff0, val = 0x51002010, id = "Kryo" },
{ mask = 0xff00fff0, val = 0x51002050, id = "Kryo" },
{ mask = 0xff00fff0, val = 0x51002110, id = "Kryo" },
{ mask = 0xff00fff0, val = 0x51008000, id = "Falkor V1/Kryo" },
{ mask = 0xff00fff0, val = 0x51008010, id = "Kryo V2" },
{ mask = 0xff00fff0, val = 0x5100c000, id = "Falkor" },
{ mask = 0xff00fff0, val = 0x5100c010, id = "Saphira" },
-- Samsung
{ mask = 0xff00fff0, val = 0x53000010, id = "M1" },
-- Apple
{ mask = 0xff00fff0, val = 0x61000010, id = "Cyclone" },
{ mask = 0xff00fff0, val = 0x61000020, id = "Typhoon" },
{ mask = 0xff00fff0, val = 0x61000030, id = "Typhoon/Capri" },
{ mask = 0xff00fff0, val = 0x61000040, id = "Twister" },
{ mask = 0xff00fff0, val = 0x61000050, id = "Twister/Elba/Malta" },
{ mask = 0xff00fff0, val = 0x61000060, id = "Hurricane" },
{ mask = 0xff00fff0, val = 0x61000070, id = "Hurricane/Myst" }
}
----
--- Get CPU Information
--
function getCpuinfo()
handle = io.open( "/proc/cpuinfo", "r")
if ( handle ~= nil )
then
CPUINFO = handle:read( "*a" )
handle:close()
end
end
----
--- Initialize CPUS content
--
function initialize()
local snr
for line in string.gmatch( CPUINFO, "[^%c]+[^\r\n\r\n]+" )
do
local aux = string.match( line, "^processor[%s]+:[%s]+([%d]+)$" )
if aux ~= nil then
snr = aux
CPUS[ snr ] = {}
CPUS[ snr ].nr = snr
end
aux = string.match( line, "^model name[%s]+:[%s]+([%g%s]+)" )
if aux ~= nil then CPUS[ snr ].name = aux; end
aux = string.match( line, "^Features[%s]+:[%s]+([%g%s]+)" )
if aux ~= nil then CPUS[ snr ].features = aux; end
aux = string.match( line, "^CPU implementer[%s]+:[%s]+0x([%w]+[^%s])$" )
if aux ~= nil then CPUS[ snr ].implementer = ( tonumber( aux, 16 ) << 24 ); end
aux = string.match( line, "^CPU architecture[%s]*:[%s]*([%d]+)" )
if aux ~= nil then CPUS[ snr ].arch = aux; end
aux = string.match( line, "^CPU variant[%s]*:[%s]*0x([%w]+)" )
if aux ~= nil then CPUS[ snr ].variant = tonumber( aux, 16 ); end
aux = string.match( line, "^CPU part[%s]*:[%s]+0x([%w]+)" )
if aux ~= nil then CPUS[ snr ].part = tonumber( aux, 16 ); end
aux = string.match( line, "^CPU revision[%s]*:[%s]+([%d]+)" )
if aux ~= nil then CPUS[ snr ].revision = aux; end
end
CPUINFO = nil
end
----
---- MAIN
---
-- Get CPU Information to CPUINFO string
getCpuinfo()
-- Parse CPUINFO string and fullfill CPUS table
initialize()
local switch = {
---
-- Print CPUS content
cpushow = function ()
for i,t in pairs( CPUS )
do
for k,v in pairs( t )
do
print( "Core " .. i .. " : " .. k .. " = " .. v )
end
end
end,
---
-- Get machine-option arch
march = function ()
local machinearch
local arch = {
big = {},
LITTLE = {}
}
for i,c in pairs( CPUS )
do
for k,m in pairs( MACHINE.big )
do
if c.part == k and arch.big[ k ] ~= m.arch
then
arch.big[ k ] = m.arch
end
end
for k,m in pairs( MACHINE.LITTLE )
do
if c.part == k and arch.LITTLE[ k ] ~= m.arch
then
arch.LITTLE[ k ] = m.arch
end
end
end
for k,m in pairs( arch.big )
do
machinearch = m
end
for k,m in pairs( arch.LITTLE )
do
if machinearch ~= m then
machinearch = m
end
end
print( machinearch )
end,
---
-- Get machine-option tune
mtune = function ()
local machinetune
local tune = {
big = {},
LITTLE = {}
}
for i,c in pairs( CPUS )
do
for k,m in pairs( MACHINE.big )
do
if c.part == k and tune.big[ k ] ~= m.tune
then
tune.big[ k ] = m.tune
end
end
for k,m in pairs( MACHINE.LITTLE )
do
if c.part == k and tune.LITTLE[ k ] ~= m.tune
then
tune.LITTLE[ k ] = m.tune
end
end
end
for k,m in pairs( tune.LITTLE )
do
machinetune = m
end
for k,m in pairs( tune.big )
do
if machinetune ~= nil then
machinetune = m .. "." .. machinetune
else
machinetune = m
end
end
print( machinetune )
end
}
switch[ arg[ 1 ] ]()
os.exit( 0 )