linux-user: AT_BASE_PLATFORM for MIPS
cover linux-user: AT_BASE_PLATFORM for MIPS
Hi all,
This series properly filled AT_BASE_PLATFORM of MIPS. There is a checkpatch error about braces after if statement, I intentionally left it for style consistency.
Thanks.
- Jiaxun
Jiaxun Yang (2):
linux-user: Introduce stubs for ELF AT_BASE_PLATFORM
linux-user: Set ELF_BASE_PLATFORM for MIPS
linux-user/elfload.c | 60 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-)
Signature · 1 line
2.32.1 (Apple Git-133)
PATCH 1/2 linux-user: Introduce stubs for ELF AT_BASE_PLATFORM
AT_BASE_PLATFORM is a elf auxiliary vector pointing to a string to pass some architecture information.
--- linux-user/elfload.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-)
linux-user/elfload.c +27 -2
@@ -1718,6 +1718,10 @@ static inline void init_thread(struct target_pt_regs *regs,#endif /* TARGET_HEXAGON */ +#ifndef ELF_BASE_PLATFORM +#define ELF_BASE_PLATFORM (NULL) +#endif +#ifndef ELF_PLATFORM #define ELF_PLATFORM (NULL)#endif
@@ -2148,8 +2152,8 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,int i;abi_ulong u_rand_bytes;uint8_t k_rand_bytes[16 ]; -abi_ulong u_platform; -const char *k_platform; +abi_ulong u_platform, u_base_platform; +const char *k_platform, *k_base_platform;const int n =sizeof (elf_addr_t); sp = p;
@@ -2171,6 +2175,22 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, } } + u_base_platform =0 ; + k_base_platform =ELF_BASE_PLATFORM ; +if (k_base_platform) { +size_t len =strlen (k_base_platform) +1 ; +if (STACK_GROWS_DOWN ) { + sp -= (len + n -1 ) & ~(n -1 ); + u_base_platform = sp; +/* FIXME - check return value of memcpy_to_target() for failure */ +memcpy_to_target (sp, k_base_platform, len); + }else { +memcpy_to_target (sp, k_base_platform, len); + u_base_platform = sp; + sp += len +1 ; + } + } + u_platform =0 ; k_platform =ELF_PLATFORM ;if (k_platform) {
@@ -2212,6 +2232,8 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, } size = (DLINFO_ITEMS +1 ) *2 ; +if (k_base_platform) + size +=2 ;if (k_platform) size +=2 ;#ifdef DLINFO_ARCH_ITEMS
@@ -2289,6 +2311,9 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,NEW_AUX_ENT (AT_HWCAP2 , (abi_ulong )ELF_HWCAP2 );#endif +if (u_base_platform) { +NEW_AUX_ENT (AT_BASE_PLATFORM , u_base_platform); + }if (u_platform) {NEW_AUX_ENT (AT_PLATFORM , u_platform); }
Signature · 1 line
2.32.1 (Apple Git-133)
Re: [PATCH 1/2] linux-user: Introduce stubs for ELF AT_BASE_PLATFORM
Quoted 2 lines · Jiaxun Yang
AT_BASE_PLATFORMis a elf auxiliary vector pointing to a string to pass some architecture information.
We can be more specific.
"See getauxval(3) man-page."
Quoted 73 lines
Signed-off-by Jiaxun Yang <[email protected]>--- linux-user/elfload.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-)linux-user/elfload.c +27
-2@@ -1718,6 +1718,10 @@ static inline void init_thread(struct target_pt_regs *regs,#endif /* TARGET_HEXAGON */ +#ifndef ELF_BASE_PLATFORM +#define ELF_BASE_PLATFORM (NULL) +#endif +#ifndef ELF_PLATFORM #define ELF_PLATFORM (NULL)#endif @@ -2148,8 +2152,8 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,int i;abi_ulong u_rand_bytes;uint8_t k_rand_bytes[16 ]; -abi_ulong u_platform; -const char *k_platform; +abi_ulong u_platform, u_base_platform; +const char *k_platform, *k_base_platform;const int n =sizeof (elf_addr_t); sp = p;@@ -2171,6 +2175,22 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, } } + u_base_platform =0 ; + k_base_platform =ELF_BASE_PLATFORM ; +if (k_base_platform) { +size_t len =strlen (k_base_platform) +1 ; +if (STACK_GROWS_DOWN ) { + sp -= (len + n -1 ) & ~(n -1 ); + u_base_platform = sp; +/* FIXME - check return value of memcpy_to_target() for failure */ +memcpy_to_target (sp, k_base_platform, len); + }else { +memcpy_to_target (sp, k_base_platform, len); + u_base_platform = sp; + sp += len +1 ; + } + } + u_platform =0 ; k_platform =ELF_PLATFORM ;if (k_platform) {@@ -2212,6 +2232,8 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, } size = (DLINFO_ITEMS +1 ) *2 ; +if (k_base_platform) + size +=2 ;if (k_platform) size +=2 ;#ifdef DLINFO_ARCH_ITEMS @@ -2289,6 +2311,9 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,NEW_AUX_ENT (AT_HWCAP2 , (abi_ulong )ELF_HWCAP2 );#endif +if (u_base_platform) { +NEW_AUX_ENT (AT_BASE_PLATFORM , u_base_platform); + }if (u_platform) {NEW_AUX_ENT (AT_PLATFORM , u_platform); }
PATCH 2/2 linux-user: Set ELF_BASE_PLATFORM for MIPS
In reply to Jiaxun YangMatch most appropriate base platform string based on insn_flags. Logic is aligned with arch/mips/kernel/cpu-probe.c in Linux kernel.
--- linux-user/elfload.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
linux-user/elfload.c +31 -0
@@ -1050,6 +1050,37 @@ static uint32_t get_elf_hwcap(void)#define elf_check_abi (x) (!((x) & EF_MIPS_ABI2))#endif +#define ELF_BASE_PLATFORM get_elf_base_platform() + +#define MATCH_PLATFORM_INSN (_flags, _base_platform) \ + do { if ((cpu->env.insn_flags & (_flags)) == _flags) \ + { return _base_platform; } } while (0) + +static const char *get_elf_base_platform (void ) +{ +MIPSCPU *cpu =MIPS_CPU (thread_cpu); + +/* 64 bit ISAs goes first */ +MATCH_PLATFORM_INSN (CPU_MIPS64R6 ,"mips64r6" ); +MATCH_PLATFORM_INSN (CPU_MIPS64R5 ,"mips64r5" ); +MATCH_PLATFORM_INSN (CPU_MIPS64R2 ,"mips64r2" ); +MATCH_PLATFORM_INSN (CPU_MIPS64R1 ,"mips64" ); +MATCH_PLATFORM_INSN (CPU_MIPS5 ,"mips5" ); +MATCH_PLATFORM_INSN (CPU_MIPS4 ,"mips4" ); +MATCH_PLATFORM_INSN (CPU_MIPS3 ,"mips3" ); + +/* 32 bit ISAs */ +MATCH_PLATFORM_INSN (CPU_MIPS32R6 ,"mips32r6" ); +MATCH_PLATFORM_INSN (CPU_MIPS32R5 ,"mips32r5" ); +MATCH_PLATFORM_INSN (CPU_MIPS32R2 ,"mips32r2" ); +MATCH_PLATFORM_INSN (CPU_MIPS32R1 ,"mips32" ); +MATCH_PLATFORM_INSN (CPU_MIPS2 ,"mips2" ); + +/* Fallback */ +return "mips" ; +} +#undef MATCH_PLATFORM_INSN +static inline void init_thread (struct target_pt_regs *regs,struct image_info *infop) {
Signature · 1 line
2.32.1 (Apple Git-133)
Re: [PATCH 2/2] linux-user: Set ELF_BASE_PLATFORM for MIPS
On 1/8/22 22:09, Jiaxun Yang wrote:
"On MIPS, AT_BASE_PLATFORM identifies the ISA level (since Linux 5.7)."
Quoted 2 lines
Match most appropriate base platform string based on
insn_flags. Logic is aligned witharch/mips/kernel/cpu-probe.cin Linux kernel.
"... aligned with set_isa() from ..."
Quoted 47 lines
Signed-off-by Jiaxun Yang <[email protected]>--- linux-user/elfload.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)linux-user/elfload.c +31
-0@@ -1050,6 +1050,37 @@ static uint32_t get_elf_hwcap(void)#define elf_check_abi (x) (!((x) & EF_MIPS_ABI2))#endif +#define ELF_BASE_PLATFORM get_elf_base_platform() + +#define MATCH_PLATFORM_INSN (_flags, _base_platform) \ + do { if ((cpu->env.insn_flags & (_flags)) == _flags) \ + { return _base_platform; } } while (0) + +static const char *get_elf_base_platform (void ) +{ +MIPSCPU *cpu =MIPS_CPU (thread_cpu); + +/* 64 bit ISAs goes first */ +MATCH_PLATFORM_INSN (CPU_MIPS64R6 ,"mips64r6" ); +MATCH_PLATFORM_INSN (CPU_MIPS64R5 ,"mips64r5" ); +MATCH_PLATFORM_INSN (CPU_MIPS64R2 ,"mips64r2" ); +MATCH_PLATFORM_INSN (CPU_MIPS64R1 ,"mips64" ); +MATCH_PLATFORM_INSN (CPU_MIPS5 ,"mips5" ); +MATCH_PLATFORM_INSN (CPU_MIPS4 ,"mips4" ); +MATCH_PLATFORM_INSN (CPU_MIPS3 ,"mips3" ); + +/* 32 bit ISAs */ +MATCH_PLATFORM_INSN (CPU_MIPS32R6 ,"mips32r6" ); +MATCH_PLATFORM_INSN (CPU_MIPS32R5 ,"mips32r5" ); +MATCH_PLATFORM_INSN (CPU_MIPS32R2 ,"mips32r2" ); +MATCH_PLATFORM_INSN (CPU_MIPS32R1 ,"mips32" ); +MATCH_PLATFORM_INSN (CPU_MIPS2 ,"mips2" ); + +/* Fallback */ +return "mips" ; +} +#undef MATCH_PLATFORM_INSN +static inline void init_thread (struct target_pt_regs *regs,struct image_info *infop) {
Quoted 9 lines · Jiaxun Yang
Hi all,
This series properly filled
AT_BASE_PLATFORMof MIPS. There is a checkpatch error about braces after if statement, I intentionally left it for style consistency.Thanks.
- Jiaxun
Quoted 7 lines
Jiaxun Yang (2):
linux-user: Introduce stubs for ELFAT_BASE_PLATFORM
linux-user: SetELF_BASE_PLATFORMfor MIPSlinux-user/elfload.c | 60 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-)
Cc'ing qemu-ppc for completeness using cpu_specs[].platform from Linux kernel arch/powerpc/kernel/cputable.c.