m68knommu: add support for elf-fdpic
Subsystems (5)
cover m68knommu: add support for elf-fdpic
Add support to the m68k architecture code for the elf-fdpic loader. As of commit 1bde925d2354 ("fs/binfmt_elf_fdpic.c: provide NOMMU loader for regular ELF binaries") it is possible to run normal ELF executables on nommu systems. These are simple enough to generate and test - even without actual elf-fdpic toolchain support.
A few minor changes are required to have everything in place, all on the architecture code side. The largest required addition is minimal regset support (for elf-fdpic core dumping), otherwise a couple of cleanups and some definitions is all that is required.
Note that this is only supporting nommu mode on the m68k at this time. Changes will be required to the mm_context_t type to support elf-fdpic with MMU enabled on m68k.
--- arch/m68k/include/asm/elf.h | 9 +++++ arch/m68k/include/asm/mmu.h | 4 -- arch/m68k/include/uapi/asm/ptrace.h | 5 +++ arch/m68k/kernel/ptrace.c | 58 ++++++++++++++++++++++++++++++++++++ fs/Kconfig.binfmt | 2 - 5 files changed, 74 insertions(+), 4 deletions(-)
PATCH 1/4 m68knommu: use asm-generic/mmu.h for nommu setups
The nommu case defines its own local mm_context_t structure. There is nothing special or different about the m68knommu version of this and it can easily use the common asm-generic version.
Remove the local mmu_context struct and include the asm-generic version instead. This will also make it easier to support ELF format executables in the future (since the asm-generic version has support for this already).
--- arch/m68k/include/asm/mmu.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
arch/m68k/include/asm/mmu.h +1 -3
@@ -6,9 +6,7 @@/* Default "unsigned long" context */ typedef unsigned long mm_context_t ;#else -typedef struct { -unsigned long end_brk; -}mm_context_t ; +#include <asm-generic/mmu.h> #endif #endif
Signature · 1 line
2.25.1
Re: [PATCH 1/4] m68knommu: use asm-generic/mmu.h for nommu setups
Quoted 10 lines · Greg Ungerer
The nommu case defines its own local
mm_context_tstructure. There is nothing special or different about the m68knommu version of this and it can easily use the common asm-generic version.Remove the local
mmu_contextstruct and include the asm-generic version instead. This will also make it easier to support ELF format executables in the future (since the asm-generic version has support for this already).Signed-off-by Greg Ungerer <[email protected]>
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
PATCH 2/4 m68knommu: implement minimal regset support
In reply to Greg UngererAdd code support to the m68k architecture for regsets.
Currently the only thing that will need to use regsets for m68k will be coredump support of the elf_fdpic loader. So the changes are conditional on that. The added support is the minimum definitions required to support just that.
--- arch/m68k/kernel/ptrace.c | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+)
arch/m68k/kernel/ptrace.c +58 -0
@@ -19,6 +19,8 @@#include <linux/ptrace.h> #include <linux/user.h> #include <linux/signal.h> +#include <linux/regset.h> +#include <linux/elf.h> #include <linux/uaccess.h> #include <asm/page.h>
@@ -291,3 +293,59 @@ asmlinkage void syscall_trace_leave(void)ptrace_report_syscall_exit (task_pt_regs (current),0 ); }#endif /* CONFIG_COLDFIRE */ + +#if defined(CONFIG_BINFMT_ELF_FDPIC ) && defined(CONFIG_ELF_CORE ) +/* +* Currently the only thing that needs to use regsets for m68k is the +* coredump support of the elf_fdpic loader. Implement the minimum +* definitions required for that. +*/ +static int m68k_regset_get (struct task_struct *target, +const struct user_regset *regset, +struct membuf to) +{ +struct pt_regs *ptregs =task_pt_regs (target); +u32 uregs[ELF_NGREG ]; + +ELF_CORE_COPY_REGS (uregs, ptregs); +return membuf_write (&to, uregs,sizeof (uregs)); +} + +enum m68k_regset { +REGSET_GPR , +#ifdef CONFIG_FPU +REGSET_FPU , +#endif +}; + +static const struct user_regset m68k_user_regsets[] = { + [REGSET_GPR ] = { + .core_note_type =NT_PRSTATUS , + .n =ELF_NGREG , + .size =sizeof (u32), + .align =sizeof (u16), + .regset_get = m68k_regset_get, + }, +#ifdef CONFIG_FPU + [REGSET_FPU] = { + .core_note_type =NT_PRFPREG , + .n =sizeof (struct user_m68kfp_struct ) /sizeof (u32), + .size =sizeof (u32), + .align =sizeof (u32), + } +#endif /* CONFIG_FPU */ +}; + +static const struct user_regset_view user_m68k_view = { + .name ="m68k" , + .e_machine =EM_68K , + .ei_osabi =ELF_OSABI , + .regsets = m68k_user_regsets, + .n =ARRAY_SIZE (m68k_user_regsets) +}; + +const struct user_regset_view *task_user_regset_view (struct task_struct *task) +{ +return &user_m68k_view; +} +#endif /* CONFIG_BINFMT_ELF_FDPIC && CONFIG_ELF_CORE */
Signature · 1 line
2.25.1
PATCH 3/4 m68knommu: add definitions to support elf_fdpic program loader
In reply to Greg UngererAdd a few required defines to support using the binfmt_elf_fdpic loader on the m68k architecture. The values are defined to be consistent with those used on arm and sh which support this too.
The most important m68k specific change is the register initialization. The pt_reg structure only contains a subset of the architecture general registers, so we are more limited than to be expected on what can be used.
--- arch/m68k/include/asm/elf.h | 9 +++++++++ arch/m68k/include/uapi/asm/ptrace.h | 5 +++++ 2 files changed, 14 insertions(+)
arch/m68k/include/asm/elf.h +9 -0
@@ -60,6 +60,13 @@ typedef struct user_m68kfp_struct elf_fpregset_t;is actually used on ASV. */ #define ELF_PLAT_INIT (_r, load_addr) _r->a1 = 0 +#define ELF_FDPIC_PLAT_INIT (_r, _exec_map_addr, _interp_map_addr, dynamic_addr) \ + do { \ + (_r)->d3 = _exec_map_addr; \ + (_r)->d4 = _interp_map_addr; \ + (_r)->d5 = dynamic_addr; \ + } while(0) +#if defined(CONFIG_SUN3 ) || defined(CONFIG_COLDFIRE )#define ELF_EXEC_PAGESIZE 8192#else
@@ -114,4 +121,6 @@ typedef struct user_m68kfp_struct elf_fpregset_t;#define ELF_PLATFORM (NULL) +#define ELF_FDPIC_CORE_EFLAGS 0 +#endif
arch/m68k/include/uapi/asm/ptrace.h +5 -0
@@ -74,7 +74,12 @@ struct switch_stack {#define PTRACE_GET_THREAD_AREA 25 +#define PTRACE_GETFDPIC 31 +#define PTRACE_SINGLEBLOCK 33/* resume execution until next branch */ +#define PTRACE_GETFDPIC_EXEC 0 +#define PTRACE_GETFDPIC_INTERP 1 +#endif /* __ASSEMBLY__ */ #endif /* _UAPI_M68K_PTRACE_H */
Signature · 1 line
2.25.1
PATCH 4/4 m68knommu: allow elf_fdpic loader to be selected
In reply to Greg UngererThe m68k architecture code is capable of supporting the binfmt_elf_fdpic loader, so allow it to be configured. It is restricted to nommu configurations at this time due to the MMU context structures/code not supporting everything elf_fdpic needs when MMU is enabled.
--- fs/Kconfig.binfmt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/Kconfig.binfmt +1 -1
@@ -58,7 +58,7 @@ config ARCH_USE_GNU_PROPERTY config BINFMT_ELF_FDPIC bool "Kernel support for FDPIC ELF binaries" default y if !BINFMT_ELF - depends on (ARM || (SUPERH && !MMU)) + depends on (ARM || ((M68K || SUPERH) && !MMU)) select ELFCORE help ELF FDPIC binaries are based on ELF, but allow the individual load
Signature · 1 line
2.25.1
Re: [PATCH 4/4] m68knommu: allow elf_fdpic loader to be selected
Hi Greg,
Quoted 6 lines · Greg Ungerer
The m68k architecture code is capable of supporting the
binfmt_elf_fdpicloader, so allow it to be configured. It is restricted to nommu configurations at this time due to the MMU context structures/code not supporting everythingelf_fdpicneeds when MMU is enabled.Signed-off-by Greg Ungerer <[email protected]>
fs/Kconfig.binfmt config ARCH_USE_GNU_PROPERTY · line 61
Quoted 8 lines
fs/Kconfig.binfmt +1
-1@@ -58,7 +58,7 @@ config ARCH_USE_GNU_PROPERTY config BINFMT_ELF_FDPIC bool "Kernel support for FDPIC ELF binaries" default y if !BINFMT_ELF - depends on (ARM || (SUPERH && !MMU)) + depends on (ARM || ((M68K || SUPERH) && !MMU))
While at it, you may want to drop the unneeded outer parentheses, as they make the expression harder to round, IMHO.
fs/Kconfig.binfmt config ARCH_USE_GNU_PROPERTY · line 64
Quoted 3 lines
fs/Kconfig.binfmt +0
-0select ELFCORE help ELF FDPIC binaries are based on ELF, but allow the individual load
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Re: [PATCH 4/4] m68knommu: allow elf_fdpic loader to be selected
Hi Geert,
Quoted 12 lines · Geert Uytterhoeven
Hi Greg,
Quoted 6 lines · Greg Ungerer
The m68k architecture code is capable of supporting the
binfmt_elf_fdpicloader, so allow it to be configured. It is restricted to nommu configurations at this time due to the MMU context structures/code not supporting everythingelf_fdpicneeds when MMU is enabled.Signed-off-by Greg Ungerer <[email protected]>Reviewed-by Geert Uytterhoeven <[email protected]>
Quoted 11 lines
fs/Kconfig.binfmt config ARCH_USE_GNU_PROPERTY · line 61
Quoted 8 lines
fs/Kconfig.binfmt +1
-1@@ -58,7 +58,7 @@ config ARCH_USE_GNU_PROPERTY config BINFMT_ELF_FDPIC bool "Kernel support for FDPIC ELF binaries" default y if !BINFMT_ELF - depends on (ARM || (SUPERH && !MMU)) + depends on (ARM || ((M68K || SUPERH) && !MMU))While at it, you may want to drop the unneeded outer parentheses, as they make the expression harder to round, IMHO.
Sure thing, will do,
Regards
Greg
Quoted 14 lines
fs/Kconfig.binfmt config ARCH_USE_GNU_PROPERTY · line 64
Quoted 3 lines
fs/Kconfig.binfmt +0
-0select ELFCORE help ELF FDPIC binaries are based on ELF, but allow the individual loadGr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds