1*1541d87dSWarner Losh /*
2*1541d87dSWarner Losh  * ARM AArch64 ELF definitions for bsd-user
3*1541d87dSWarner Losh  *
4*1541d87dSWarner Losh  * Copyright (c) 2015 Stacey D. Son
5*1541d87dSWarner Losh  *
6*1541d87dSWarner Losh  * This library is free software; you can redistribute it and/or
7*1541d87dSWarner Losh  * modify it under the terms of the GNU Lesser General Public
8*1541d87dSWarner Losh  * License as published by the Free Software Foundation; either
9*1541d87dSWarner Losh  * version 2 of the License, or (at your option) any later version.
10*1541d87dSWarner Losh  *
11*1541d87dSWarner Losh  * This library is distributed in the hope that it will be useful,
12*1541d87dSWarner Losh  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13*1541d87dSWarner Losh  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14*1541d87dSWarner Losh  * Lesser General Public License for more details.
15*1541d87dSWarner Losh  *
16*1541d87dSWarner Losh  * You should have received a copy of the GNU Lesser General Public
17*1541d87dSWarner Losh  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18*1541d87dSWarner Losh  */
19*1541d87dSWarner Losh 
20*1541d87dSWarner Losh #ifndef TARGET_ARCH_ELF_H
21*1541d87dSWarner Losh #define TARGET_ARCH_ELF_H
22*1541d87dSWarner Losh 
23*1541d87dSWarner Losh #define ELF_START_MMAP 0x80000000
24*1541d87dSWarner Losh #define ELF_ET_DYN_LOAD_ADDR    0x100000
25*1541d87dSWarner Losh 
26*1541d87dSWarner Losh #define elf_check_arch(x) ((x) == EM_AARCH64)
27*1541d87dSWarner Losh 
28*1541d87dSWarner Losh #define ELF_CLASS       ELFCLASS64
29*1541d87dSWarner Losh #define ELF_DATA        ELFDATA2LSB
30*1541d87dSWarner Losh #define ELF_ARCH        EM_AARCH64
31*1541d87dSWarner Losh 
32*1541d87dSWarner Losh #define USE_ELF_CORE_DUMP
33*1541d87dSWarner Losh #define ELF_EXEC_PAGESIZE       4096
34*1541d87dSWarner Losh 
35*1541d87dSWarner Losh enum {
36*1541d87dSWarner Losh     ARM_HWCAP_A64_FP            = 1 << 0,
37*1541d87dSWarner Losh     ARM_HWCAP_A64_ASIMD         = 1 << 1,
38*1541d87dSWarner Losh     ARM_HWCAP_A64_EVTSTRM       = 1 << 2,
39*1541d87dSWarner Losh     ARM_HWCAP_A64_AES           = 1 << 3,
40*1541d87dSWarner Losh     ARM_HWCAP_A64_PMULL         = 1 << 4,
41*1541d87dSWarner Losh     ARM_HWCAP_A64_SHA1          = 1 << 5,
42*1541d87dSWarner Losh     ARM_HWCAP_A64_SHA2          = 1 << 6,
43*1541d87dSWarner Losh     ARM_HWCAP_A64_CRC32         = 1 << 7,
44*1541d87dSWarner Losh     ARM_HWCAP_A64_ATOMICS       = 1 << 8,
45*1541d87dSWarner Losh     ARM_HWCAP_A64_FPHP          = 1 << 9,
46*1541d87dSWarner Losh     ARM_HWCAP_A64_ASIMDHP       = 1 << 10,
47*1541d87dSWarner Losh     ARM_HWCAP_A64_CPUID         = 1 << 11,
48*1541d87dSWarner Losh     ARM_HWCAP_A64_ASIMDRDM      = 1 << 12,
49*1541d87dSWarner Losh     ARM_HWCAP_A64_JSCVT         = 1 << 13,
50*1541d87dSWarner Losh     ARM_HWCAP_A64_FCMA          = 1 << 14,
51*1541d87dSWarner Losh     ARM_HWCAP_A64_LRCPC         = 1 << 15,
52*1541d87dSWarner Losh     ARM_HWCAP_A64_DCPOP         = 1 << 16,
53*1541d87dSWarner Losh     ARM_HWCAP_A64_SHA3          = 1 << 17,
54*1541d87dSWarner Losh     ARM_HWCAP_A64_SM3           = 1 << 18,
55*1541d87dSWarner Losh     ARM_HWCAP_A64_SM4           = 1 << 19,
56*1541d87dSWarner Losh     ARM_HWCAP_A64_ASIMDDP       = 1 << 20,
57*1541d87dSWarner Losh     ARM_HWCAP_A64_SHA512        = 1 << 21,
58*1541d87dSWarner Losh     ARM_HWCAP_A64_SVE           = 1 << 22,
59*1541d87dSWarner Losh     ARM_HWCAP_A64_ASIMDFHM      = 1 << 23,
60*1541d87dSWarner Losh     ARM_HWCAP_A64_DIT           = 1 << 24,
61*1541d87dSWarner Losh     ARM_HWCAP_A64_USCAT         = 1 << 25,
62*1541d87dSWarner Losh     ARM_HWCAP_A64_ILRCPC        = 1 << 26,
63*1541d87dSWarner Losh     ARM_HWCAP_A64_FLAGM         = 1 << 27,
64*1541d87dSWarner Losh     ARM_HWCAP_A64_SSBS          = 1 << 28,
65*1541d87dSWarner Losh     ARM_HWCAP_A64_SB            = 1 << 29,
66*1541d87dSWarner Losh     ARM_HWCAP_A64_PACA          = 1 << 30,
67*1541d87dSWarner Losh     ARM_HWCAP_A64_PACG          = 1UL << 31,
68*1541d87dSWarner Losh 
69*1541d87dSWarner Losh     ARM_HWCAP2_A64_DCPODP       = 1 << 0,
70*1541d87dSWarner Losh     ARM_HWCAP2_A64_SVE2         = 1 << 1,
71*1541d87dSWarner Losh     ARM_HWCAP2_A64_SVEAES       = 1 << 2,
72*1541d87dSWarner Losh     ARM_HWCAP2_A64_SVEPMULL     = 1 << 3,
73*1541d87dSWarner Losh     ARM_HWCAP2_A64_SVEBITPERM   = 1 << 4,
74*1541d87dSWarner Losh     ARM_HWCAP2_A64_SVESHA3      = 1 << 5,
75*1541d87dSWarner Losh     ARM_HWCAP2_A64_SVESM4       = 1 << 6,
76*1541d87dSWarner Losh     ARM_HWCAP2_A64_FLAGM2       = 1 << 7,
77*1541d87dSWarner Losh     ARM_HWCAP2_A64_FRINT        = 1 << 8,
78*1541d87dSWarner Losh     ARM_HWCAP2_A64_SVEI8MM      = 1 << 9,
79*1541d87dSWarner Losh     ARM_HWCAP2_A64_SVEF32MM     = 1 << 10,
80*1541d87dSWarner Losh     ARM_HWCAP2_A64_SVEF64MM     = 1 << 11,
81*1541d87dSWarner Losh     ARM_HWCAP2_A64_SVEBF16      = 1 << 12,
82*1541d87dSWarner Losh     ARM_HWCAP2_A64_I8MM         = 1 << 13,
83*1541d87dSWarner Losh     ARM_HWCAP2_A64_BF16         = 1 << 14,
84*1541d87dSWarner Losh     ARM_HWCAP2_A64_DGH          = 1 << 15,
85*1541d87dSWarner Losh     ARM_HWCAP2_A64_RNG          = 1 << 16,
86*1541d87dSWarner Losh     ARM_HWCAP2_A64_BTI          = 1 << 17,
87*1541d87dSWarner Losh     ARM_HWCAP2_A64_MTE          = 1 << 18,
88*1541d87dSWarner Losh };
89*1541d87dSWarner Losh 
90*1541d87dSWarner Losh #define ELF_HWCAP   get_elf_hwcap()
91*1541d87dSWarner Losh #define ELF_HWCAP2  get_elf_hwcap2()
92*1541d87dSWarner Losh 
93*1541d87dSWarner Losh #define GET_FEATURE_ID(feat, hwcap) \
94*1541d87dSWarner Losh     do { if (cpu_isar_feature(feat, cpu)) { hwcaps |= hwcap; } } while (0)
95*1541d87dSWarner Losh 
get_elf_hwcap(void)96*1541d87dSWarner Losh static uint32_t get_elf_hwcap(void)
97*1541d87dSWarner Losh {
98*1541d87dSWarner Losh     ARMCPU *cpu = ARM_CPU(thread_cpu);
99*1541d87dSWarner Losh     uint32_t hwcaps = 0;
100*1541d87dSWarner Losh 
101*1541d87dSWarner Losh     hwcaps |= ARM_HWCAP_A64_FP;
102*1541d87dSWarner Losh     hwcaps |= ARM_HWCAP_A64_ASIMD;
103*1541d87dSWarner Losh     hwcaps |= ARM_HWCAP_A64_CPUID;
104*1541d87dSWarner Losh 
105*1541d87dSWarner Losh     /* probe for the extra features */
106*1541d87dSWarner Losh 
107*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_aes, ARM_HWCAP_A64_AES);
108*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_pmull, ARM_HWCAP_A64_PMULL);
109*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_sha1, ARM_HWCAP_A64_SHA1);
110*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_sha256, ARM_HWCAP_A64_SHA2);
111*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_sha512, ARM_HWCAP_A64_SHA512);
112*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_crc32, ARM_HWCAP_A64_CRC32);
113*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_sha3, ARM_HWCAP_A64_SHA3);
114*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_sm3, ARM_HWCAP_A64_SM3);
115*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_sm4, ARM_HWCAP_A64_SM4);
116*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_fp16, ARM_HWCAP_A64_FPHP | ARM_HWCAP_A64_ASIMDHP);
117*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_atomics, ARM_HWCAP_A64_ATOMICS);
118*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_rdm, ARM_HWCAP_A64_ASIMDRDM);
119*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_dp, ARM_HWCAP_A64_ASIMDDP);
120*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_fcma, ARM_HWCAP_A64_FCMA);
121*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_sve, ARM_HWCAP_A64_SVE);
122*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_pauth, ARM_HWCAP_A64_PACA | ARM_HWCAP_A64_PACG);
123*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_fhm, ARM_HWCAP_A64_ASIMDFHM);
124*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_jscvt, ARM_HWCAP_A64_JSCVT);
125*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_sb, ARM_HWCAP_A64_SB);
126*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_condm_4, ARM_HWCAP_A64_FLAGM);
127*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_dcpop, ARM_HWCAP_A64_DCPOP);
128*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_rcpc_8_3, ARM_HWCAP_A64_LRCPC);
129*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_rcpc_8_4, ARM_HWCAP_A64_ILRCPC);
130*1541d87dSWarner Losh 
131*1541d87dSWarner Losh     return hwcaps;
132*1541d87dSWarner Losh }
133*1541d87dSWarner Losh 
get_elf_hwcap2(void)134*1541d87dSWarner Losh static uint32_t get_elf_hwcap2(void)
135*1541d87dSWarner Losh {
136*1541d87dSWarner Losh     ARMCPU *cpu = ARM_CPU(thread_cpu);
137*1541d87dSWarner Losh     uint32_t hwcaps = 0;
138*1541d87dSWarner Losh 
139*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_dcpodp, ARM_HWCAP2_A64_DCPODP);
140*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_sve2, ARM_HWCAP2_A64_SVE2);
141*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_sve2_aes, ARM_HWCAP2_A64_SVEAES);
142*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_sve2_pmull128, ARM_HWCAP2_A64_SVEPMULL);
143*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_sve2_bitperm, ARM_HWCAP2_A64_SVEBITPERM);
144*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_sve2_sha3, ARM_HWCAP2_A64_SVESHA3);
145*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_sve2_sm4, ARM_HWCAP2_A64_SVESM4);
146*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_condm_5, ARM_HWCAP2_A64_FLAGM2);
147*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_frint, ARM_HWCAP2_A64_FRINT);
148*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_sve_i8mm, ARM_HWCAP2_A64_SVEI8MM);
149*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_sve_f32mm, ARM_HWCAP2_A64_SVEF32MM);
150*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_sve_f64mm, ARM_HWCAP2_A64_SVEF64MM);
151*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_sve_bf16, ARM_HWCAP2_A64_SVEBF16);
152*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_i8mm, ARM_HWCAP2_A64_I8MM);
153*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_bf16, ARM_HWCAP2_A64_BF16);
154*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_rndr, ARM_HWCAP2_A64_RNG);
155*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_bti, ARM_HWCAP2_A64_BTI);
156*1541d87dSWarner Losh     GET_FEATURE_ID(aa64_mte, ARM_HWCAP2_A64_MTE);
157*1541d87dSWarner Losh 
158*1541d87dSWarner Losh     return hwcaps;
159*1541d87dSWarner Losh }
160*1541d87dSWarner Losh 
161*1541d87dSWarner Losh #undef GET_FEATURE_ID
162*1541d87dSWarner Losh 
163*1541d87dSWarner Losh #endif /* TARGET_ARCH_ELF_H */
164