COMPAT_NETBSD32 support for ARM. Which is strange since ARM is already

32-bits.  But the newer ARM ABI AAPCS changes the alignment of 64-bit
fields so structures need to copied in and out to deal with the alignment
change.  This is a kludge but makes debugging of AAPCS support much easier.
This commit is contained in:
matt 2012-08-03 07:59:22 +00:00
parent 576b2b8edd
commit 9fae3660d0
9 changed files with 292 additions and 11 deletions

View File

@ -0,0 +1,93 @@
/* $NetBSD: cpu_exec.c,v 1.1 2012/08/03 07:59:22 matt Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: cpu_exec.c,v 1.1 2012/08/03 07:59:22 matt Exp $");
#include "opt_compat_netbsd.h"
#include "opt_compat_netbsd32.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/exec.h>
#include <uvm/uvm_extern.h>
#include <compat/common/compat_util.h>
#include <sys/exec_elf.h> /* mandatory */
#ifdef COMPAT_NETBSD32
#include <compat/netbsd32/netbsd32_exec.h>
#endif
#if EXEC_ELF32
int
arm_netbsd_elf32_probe(struct lwp *l, struct exec_package *epp, void *eh0,
char *itp, vaddr_t *start_p)
{
const char *itp_suffix = NULL;
const bool elf_aapcs_p = (epp->ep_flags & EXEC_ARM_AAPCS) != 0;
#ifdef COMPAT_NETBSD32
const bool netbsd32_p = (epp->ep_esch->es_emul == &emul_netbsd32);
#else
const bool netbsd32_p = false;
#endif
#ifdef __ARM_EABI__
const bool aapcs_p = true;
#else
const bool aapcs_p = false;
#endif
/*
* This is subtle. If are netbsd32, then we don't want to match the
* same ABI as the kernel. If we aren't (netbsd32 == false), then we
* don't want to be different from the kernel's ABI.
* true true true ENOEXEC
* true false true 0
* true true false 0
* true false false ENOEXEC
* false true true 0
* false false true ENOEXEC
* false true false ENOEXEC
* false false false 0
*/
if (netbsd32_p ^ elf_aapcs_p ^ aapcs_p)
return ENOEXEC;
if (netbsd32_p)
itp_suffix = (elf_aapcs_p) ? "eabi" : "apcs32";
if (itp_suffix != NULL)
(void)compat_elf_check_interp(epp, itp, itp_suffix);
return 0;
}
#endif

View File

@ -0,0 +1,96 @@
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(1, "$NetBSD: netbsd32_machdep.c,v 1.1 2012/08/03 07:59:22 matt Exp $");
#include <sys/param.h>
#include <sys/core.h>
#include <sys/exec.h>
#include <sys/lwp.h>
#include <sys/signalvar.h>
#include <sys/syscallargs.h>
#include <uvm/uvm_extern.h>
#include <compat/netbsd32/netbsd32.h>
#include <compat/netbsd32/netbsd32_exec.h>
#include <compat/netbsd32/netbsd32_syscallargs.h>
const char machine32[] = MACHINE;
const char machine_arch32[] = MACHINE_ARCH;
int
cpu_coredump32(struct lwp *l, void *iocookie, struct core32 *chdr)
{
return cpu_coredump(l, iocookie, (struct core *)chdr);
}
void
netbsd32_sendsig (const ksiginfo_t *ksi, const sigset_t *ss)
{
sendsig(ksi, ss);
}
void
startlwp32(void *arg)
{
startlwp(arg);
}
int
cpu_mcontext32_validate(struct lwp *l, const mcontext32_t *mcp)
{
return cpu_mcontext_validate(l, mcp);
}
void
cpu_getmcontext32(struct lwp *l, mcontext32_t *mcp, unsigned int *flagsp)
{
cpu_getmcontext(l, mcp, flagsp);
}
int
cpu_setmcontext32(struct lwp *l, const mcontext32_t *mcp, unsigned int flags)
{
return cpu_setmcontext(l, mcp, flags);
}
int
netbsd32_sysarch(struct lwp *l, const struct netbsd32_sysarch_args *uap,
register_t *retval)
{
return sys_sysarch(l, (const struct sys_sysarch_args *)uap, retval);
}
vaddr_t
netbsd32_vm_default_addr(struct proc *p, vaddr_t base, vsize_t size)
{
return VM_DEFAULT_ADDRESS(base, size);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: vm_machdep.c,v 1.56 2012/02/19 21:06:05 rmind Exp $ */
/* $NetBSD: vm_machdep.c,v 1.57 2012/08/03 07:59:22 matt Exp $ */
/*
* Copyright (c) 1994-1998 Mark Brinicombe.
@ -44,7 +44,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.56 2012/02/19 21:06:05 rmind Exp $");
__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.57 2012/08/03 07:59:22 matt Exp $");
#include "opt_armfpe.h"
#include "opt_pmap_debug.h"
@ -184,10 +184,11 @@ cpu_lwp_fork(struct lwp *l1, struct lwp *l2, void *stack, size_t stacksize,
*tf = *pcb1->pcb_tf;
/*
* If specified, give the child a different stack.
* If specified, give the child a different stack (make sure
* it's 8-byte aligned).
*/
if (stack != NULL)
tf->tf_usr_sp = (u_int)stack + stacksize;
tf->tf_usr_sp = ((vaddr_t)(stack) + stacksize) & -8;
sf = (struct switchframe *)tf - 1;
sf->sf_r4 = (u_int)func;

View File

@ -1,4 +1,4 @@
# $NetBSD: files.arm,v 1.106 2012/07/21 12:19:15 skrll Exp $
# $NetBSD: files.arm,v 1.107 2012/08/03 07:59:22 matt Exp $
# temporary define to allow easy moving to ../arch/arm/arm32
defflag ARM32
@ -150,6 +150,7 @@ file arch/arm/arm/cpufunc_asm_xscale.S cpu_xscale_80200 |
cpu_cortex
file arch/arm/arm/cpufunc_asm_ixp12x0.S cpu_ixp12x0
file arch/arm/arm/cpufunc_asm_sheeva.S cpu_sheeva
file arch/arm/arm/cpu_exec.c
file arch/arm/arm/fusu.S
file arch/arm/arm/idle_machdep.c
file arch/arm/arm/lock_cas.S
@ -187,6 +188,10 @@ file arch/arm/arm32/cortex_pmc.c cortex_pmc
# arm32 library functions
file arch/arm/arm32/bcopy_page.S arm32
#
include "compat/netbsd32/files.netbsd32"
file arch/arm/arm32/netbsd32_machdep.c arm32 & compat_netbsd32
# Linux binary compatibility (COMPAT_LINUX)
include "compat/ossaudio/files.ossaudio"
include "compat/linux/files.linux"

View File

@ -1,4 +1,7 @@
/* $NetBSD: elf_machdep.h,v 1.8 2009/05/30 05:56:52 skrll Exp $ */
/* $NetBSD: elf_machdep.h,v 1.9 2012/08/03 07:59:23 matt Exp $ */
#ifndef _ARM_ELF_MACHDEP_H_
#define _ARM_ELF_MACHDEP_H_
#if defined(__ARMEB__)
#define ELF32_MACHDEP_ENDIANNESS ELFDATA2MSB
@ -115,3 +118,16 @@
/* Processor specific symbol types */
#define STT_ARM_TFUNC STT_LOPROC
#ifdef _KERNEL
#ifdef ELFSIZE
#define ELF_MD_PROBE_FUNC ELFNAME2(arm_netbsd,probe)
#endif
struct exec_package;
int arm_netbsd_elf32_probe(struct lwp *, struct exec_package *, void *, char *,
vaddr_t *);
#endif
#endif /* _ARM_ELF_MACHDEP_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.10 2012/02/13 17:07:45 matt Exp $ */
/* $NetBSD: mcontext.h,v 1.11 2012/08/03 07:59:23 matt Exp $ */
/*-
* Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
@ -88,7 +88,7 @@ typedef struct {
__vfpregset_t __vfpregs;
} __fpu;
__greg_t _mc_tlsbase;
} mcontext_t;
} mcontext_t, mcontext32_t;
/* Machine-dependent uc_flags */
#define _UC_ARM_VFP 0x00010000 /* FPU field is VFP */

View File

@ -0,0 +1,69 @@
/* $NetBSD: netbsd32_machdep.h,v 1.1 2012/08/03 07:59:23 matt Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas <matt@3am-software.com>.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _ARM_NETBSD32_H_
#define _ARM_NETBSD32_H_
#include <sys/types.h>
#define NETBSD32_POINTER_TYPE uint32_t
typedef struct { NETBSD32_POINTER_TYPE i32; } netbsd32_pointer_t;
#ifdef __ARM_EABI__
#define NETBSD32_INT64_ALIGN __attribute__((__aligned__(4)))
#else
#define NETBSD32_INT64_ALIGN __attribute__((__aligned__(8)))
#endif
typedef netbsd32_pointer_t netbsd32_sigcontextp_t;
/*
* The sigcode is ABI neutral.
*/
#define netbsd32_sigcode sigcode
#define netbsd32_esigcode esigcode
/*
* Note: syscall_intern and setregs do not care about COMPAT_NETBSD32.
*/
#define netbsd32_syscall_intern syscall_intern
#define netbsd32_setregs setregs
#define VM_MAXUSER_ADDRESS32 VM_MAXUSER_ADDRESS
#define NETBSD32_MID_MACHINE MID_MACHINE
#define USRSTACK32 USRSTACK
#define MAXTSIZ32 MAXTSIZ
#define DFLDSIZ32 DFLDSIZ
#define MAXDSIZ32 MAXDSIZ
#define DFLSSIZ32 DFLSSIZ
#define MAXSSIZ32 MAXSSIZ
#endif /* _ARM_NETBSD32_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: param.h,v 1.15 2012/01/24 20:03:36 christos Exp $ */
/* $NetBSD: param.h,v 1.16 2012/08/03 07:59:23 matt Exp $ */
/*
* Copyright (c) 1994,1995 Mark Brinicombe.
@ -81,6 +81,7 @@
/* ARM-specific macro to align a stack pointer (downwards). */
#define STACK_ALIGNBYTES (8 - 1)
#define ALIGNBYTES32 3
#define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
#define DEV_BSIZE (1 << DEV_BSHIFT)

View File

@ -1,4 +1,4 @@
/* $NetBSD: types.h,v 1.21 2011/11/18 16:10:02 joerg Exp $ */
/* $NetBSD: types.h,v 1.22 2012/08/03 07:59:23 matt Exp $ */
/*
* Copyright (c) 1990 The Regents of the University of California.
@ -61,7 +61,7 @@ typedef unsigned long vsize_t;
#define PRIuVSIZE "lu"
#endif
typedef int register_t;
typedef int register_t, register32_t;
#define PRIxREGISTER "x"
typedef unsigned long pmc_evid_t;