Add rudimentary support for building FreeBSD/arm64 with COMPAT_FREEBSD32.

Right now I'm using two Raspberry Pi's (2 and 3) to test CloudABI
support for armv6, armv7 and aarch64. It would be nice if I could
restrict this to just a single instance when testing smaller changes.
This is why I'd like to get COMPAT_CLOUDABI32 to work on arm64.

As COMPAT_CLOUDABI32 depends on COMPAT_FREEBSD32, at least for the ELF
loading, this change adds all of the bits necessary to at least build a
kernel with COMPAT_FREEBSD32. All of the machine dependent system calls
are still stubbed out, for the reason that implementations for these are
only useful if actual support for running FreeBSD binaries is added.
This is outside the scope of this work.

Reviewed by:	andrew
Differential Revision:	https://reviews.freebsd.org/D13144
This commit is contained in:
Ed Schouten 2017-11-24 13:50:53 +00:00
parent ad15e1548f
commit 9dcf90f8ad
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=326165
11 changed files with 203 additions and 1 deletions

View File

@ -0,0 +1,38 @@
/*-
* Copyright (c) 2017 Nuxi, https://nuxi.nl/
*
* 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 AUTHOR 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 AUTHOR 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>
__FBSDID("$FreeBSD$");
#include <sys/types.h>
#define __ELF_WORD_SIZE 32
#include <sys/imgact_elf.h>
void
elf32_dump_thread(struct thread *td __unused, void *dst __unused,
size_t *off __unused)
{
}

View File

@ -0,0 +1,70 @@
/*-
* Copyright (c) 2017 Nuxi, https://nuxi.nl/
*
* 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 AUTHOR 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 AUTHOR 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>
__FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <compat/freebsd32/freebsd32_proto.h>
/*
* Stubs for machine dependent 32-bits system calls.
*/
int
freebsd32_getcontext(struct thread *td, struct freebsd32_getcontext_args *uap)
{
return (ENOSYS);
}
int
freebsd32_setcontext(struct thread *td, struct freebsd32_setcontext_args *uap)
{
return (ENOSYS);
}
int
freebsd32_sigreturn(struct thread *td, struct freebsd32_sigreturn_args *uap)
{
return (ENOSYS);
}
int
freebsd32_swapcontext(struct thread *td, struct freebsd32_swapcontext_args *uap)
{
return (ENOSYS);
}
int
freebsd32_sysarch(struct thread *td, struct freebsd32_sysarch_args *uap)
{
return (ENOSYS);
}

View File

@ -26,6 +26,7 @@
*/
#include "opt_acpi.h"
#include "opt_compat.h"
#include "opt_platform.h"
#include "opt_ddb.h"
@ -278,6 +279,56 @@ set_dbregs(struct thread *td, struct dbreg *regs)
return (EDOOFUS);
}
#ifdef COMPAT_FREEBSD32
int
fill_regs32(struct thread *td, struct reg32 *regs)
{
printf("ARM64TODO: fill_regs32");
return (EDOOFUS);
}
int
set_regs32(struct thread *td, struct reg32 *regs)
{
printf("ARM64TODO: set_regs32");
return (EDOOFUS);
}
int
fill_fpregs32(struct thread *td, struct fpreg32 *regs)
{
printf("ARM64TODO: fill_fpregs32");
return (EDOOFUS);
}
int
set_fpregs32(struct thread *td, struct fpreg32 *regs)
{
printf("ARM64TODO: set_fpregs32");
return (EDOOFUS);
}
int
fill_dbregs32(struct thread *td, struct dbreg32 *regs)
{
printf("ARM64TODO: fill_dbregs32");
return (EDOOFUS);
}
int
set_dbregs32(struct thread *td, struct dbreg32 *regs)
{
printf("ARM64TODO: set_dbregs32");
return (EDOOFUS);
}
#endif
int
ptrace_set_pc(struct thread *td, u_long addr)
{

View File

@ -36,7 +36,10 @@
#include <sys/elf32.h> /* Definitions common to all 32 bit architectures. */
#include <sys/elf64.h> /* Definitions common to all 64 bit architectures. */
#ifndef __ELF_WORD_SIZE
#define __ELF_WORD_SIZE 64 /* Used by <sys/elf_generic.h> */
#endif
#include <sys/elf_generic.h>
/*
@ -97,10 +100,17 @@ __ElfType(Auxinfo);
#define AT_COUNT 27 /* Count of defined aux entry types. */
/* Define "machine" characteristics */
#if __ELF_WORD_SIZE == 64
#define ELF_TARG_CLASS ELFCLASS64
#define ELF_TARG_DATA ELFDATA2LSB
#define ELF_TARG_MACH EM_AARCH64
#define ELF_TARG_VER 1
#else
#define ELF_TARG_CLASS ELFCLASS32
#define ELF_TARG_DATA ELFDATA2LSB
#define ELF_TARG_MACH EM_ARM
#define ELF_TARG_VER 1
#endif
#define ET_DYN_LOAD_ADDR 0x100000

View File

@ -50,6 +50,9 @@
#ifndef MACHINE_ARCH
#define MACHINE_ARCH "aarch64"
#endif
#ifndef MACHINE_ARCH32
#define MACHINE_ARCH32 "armv7"
#endif
#if defined(SMP) || defined(KLD_MODULE)
#ifndef MAXCPU

View File

@ -44,6 +44,7 @@ struct mdproc {
};
#define KINFO_PROC_SIZE 1088
#define KINFO_PROC32_SIZE 816
#define MAXARGS 8
struct syscall_args {

View File

@ -41,16 +41,30 @@ struct reg {
uint32_t spsr;
};
struct reg32 {
int dummy;
};
struct fpreg {
__uint128_t fp_q[32];
uint32_t fp_sr;
uint32_t fp_cr;
};
struct fpreg32 {
int dummy;
};
struct dbreg {
int dummy;
};
struct dbreg32 {
int dummy;
};
#define __HAVE_REG32
#ifdef _KERNEL
/*
* XXX these interfaces are MI, so they should be declared in a MI place.
@ -61,6 +75,14 @@ int fill_fpregs(struct thread *, struct fpreg *);
int set_fpregs(struct thread *, struct fpreg *);
int fill_dbregs(struct thread *, struct dbreg *);
int set_dbregs(struct thread *, struct dbreg *);
#ifdef COMPAT_FREEBSD32
int fill_regs32(struct thread *, struct reg32 *);
int set_regs32(struct thread *, struct reg32 *);
int fill_fpregs32(struct thread *, struct fpreg32 *);
int set_fpregs32(struct thread *, struct fpreg32 *);
int fill_dbregs32(struct thread *, struct dbreg32 *);
int set_dbregs32(struct thread *, struct dbreg32 *);
#endif
#endif
#endif /* !_MACHINE_REG_H_ */

View File

@ -34,4 +34,6 @@
#define VDSO_TH_ALGO_ARM_GENTIM VDSO_TH_ALGO_1
#define VDSO_TIMEHANDS_MD32 VDSO_TIMEHANDS_MD
#endif /* !_MACHINE_VDSO_H_ */

View File

@ -96,8 +96,10 @@ arm64/arm64/debug_monitor.c optional ddb
arm64/arm64/disassem.c optional ddb
arm64/arm64/dump_machdep.c standard
arm64/arm64/efirt_machdep.c optional efirt
arm64/arm64/elf32_machdep.c optional compat_freebsd32
arm64/arm64/elf_machdep.c standard
arm64/arm64/exception.S standard
arm64/arm64/freebsd32_machdep.c optional compat_freebsd32
arm64/arm64/gicv3_its.c optional intrng fdt
arm64/arm64/gic_v3.c standard
arm64/arm64/gic_v3_fdt.c optional fdt

View File

@ -7,6 +7,9 @@ SOCDEV_VA opt_global.h
THUNDERX_PASS_1_1_ERRATA opt_global.h
VFP opt_global.h
# Binary compatibility
COMPAT_FREEBSD32 opt_compat.h
# EFI Runtime services support
EFIRT opt_efirt.h

View File

@ -147,7 +147,7 @@ struct ctlname {
#define REQ_WIRED 2
/* definitions for sysctl_req 'flags' member */
#if defined(__amd64__) || defined(__powerpc64__) ||\
#if defined(__aarch64__) || defined(__amd64__) || defined(__powerpc64__) ||\
(defined(__mips__) && defined(__mips_n64))
#define SCTL_MASK32 1 /* 32 bit emulation */
#endif