linux-user/elfload: Implement ELF_HWCAP for RISC-V
PATCH v2 1/1 linux-user/elfload: Implement ELF_HWCAP for RISC-V
Set I, M, A, F, D and C bit for hwcap if misa is set.
V2 Changes:
- Only set imafdc bits, sync with upstream linux kernel.
Signed-off-by Kito Cheng <[email protected]>
--- linux-user/elfload.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
linux-user/elfload.c +29 -1
@@ -1426,7 +1426,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,#ifdef TARGET_RISCV #define ELF_START_MMAP 0x80000000 -#define ELF_ARCH EM_RISCV +#define ELF_ARCH EM_RISCV#ifdef TARGET_RISCV32 #define ELF_CLASS ELFCLASS32
@@ -1434,6 +1434,34 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,#define ELF_CLASS ELFCLASS64#endif +#define ELF_HWCAP get_elf_hwcap() + +static uint32_t get_elf_hwcap (void ) +{ +RISCVCPU *cpu =RISCV_CPU (thread_cpu); +uint32_t hwcap =0 ; + +#define MISA_BIT (EXT ) (1 << (EXT - 'A')) +#define GET_EXT (EXT ) \ + do { \ + if (cpu->env.misa & MISA_BIT(EXT)) { \ + hwcap |= MISA_BIT(EXT); \ + } \ + } while (0) + +GET_EXT ('I' ); +GET_EXT ('M' ); +GET_EXT ('A' ); +GET_EXT ('F' ); +GET_EXT ('D' ); +GET_EXT ('C' ); + +#undef MISA_BIT +#undef GET_EXT + +return hwcap; +} +static inline void init_thread (struct target_pt_regs *regs,struct image_info *infop) {
Signature · 1 line
2.31.1
Quoted 9 lines · Kito Cheng
linux-user/elfload.c +9
-0+static uint32_t get_elf_hwcap (void ) +{ +RISCVCPU *cpu =RISCV_CPU (thread_cpu); +uint32_t hwcap =0 ; + +#define MISA_BIT (EXT ) (1 << (EXT - 'A')) +#define GET_EXT (EXT ) \ + do { \ + if (cpu->env.misa & MISA_BIT(EXT)) { \
linux-user/elfload.c static void elf_core_copy_regs(target_elf_gregset_t *regs, · line 1457
Quoted 10 lines
linux-user/elfload.c +10
-0+ hwcap |=MISA_BIT (EXT ); \ + } \ + }while (0 ) + +GET_EXT ('I' ); +GET_EXT ('M' ); +GET_EXT ('A' ); +GET_EXT ('F' ); +GET_EXT ('D' ); +GET_EXT ('C' );
You're not transforming the bits; there's no reason to be so around-the-bush about this. Just use
uint32_t mask = MISA_BIT('I') | ...
return cpu->env.misa & mask;r~