From owner-svn-src-head@freebsd.org Fri Nov 24 13:50:56 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6C247DE6D6D; Fri, 24 Nov 2017 13:50:56 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 25C56759C9; Fri, 24 Nov 2017 13:50:56 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id vAODotE2031828; Fri, 24 Nov 2017 13:50:55 GMT (envelope-from ed@FreeBSD.org) Received: (from ed@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vAODosSD031816; Fri, 24 Nov 2017 13:50:54 GMT (envelope-from ed@FreeBSD.org) Message-Id: <201711241350.vAODosSD031816@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ed set sender to ed@FreeBSD.org using -f From: Ed Schouten Date: Fri, 24 Nov 2017 13:50:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r326165 - in head/sys: arm64/arm64 arm64/include conf sys X-SVN-Group: head X-SVN-Commit-Author: ed X-SVN-Commit-Paths: in head/sys: arm64/arm64 arm64/include conf sys X-SVN-Commit-Revision: 326165 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Nov 2017 13:50:56 -0000 Author: ed Date: Fri Nov 24 13:50:53 2017 New Revision: 326165 URL: https://svnweb.freebsd.org/changeset/base/326165 Log: 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 Added: head/sys/arm64/arm64/elf32_machdep.c (contents, props changed) head/sys/arm64/arm64/freebsd32_machdep.c (contents, props changed) Modified: head/sys/arm64/arm64/machdep.c head/sys/arm64/include/elf.h head/sys/arm64/include/param.h head/sys/arm64/include/proc.h head/sys/arm64/include/reg.h head/sys/arm64/include/vdso.h head/sys/conf/files.arm64 head/sys/conf/options.arm64 head/sys/sys/sysctl.h Added: head/sys/arm64/arm64/elf32_machdep.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/arm64/arm64/elf32_machdep.c Fri Nov 24 13:50:53 2017 (r326165) @@ -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 +__FBSDID("$FreeBSD$"); + +#include +#define __ELF_WORD_SIZE 32 +#include + +void +elf32_dump_thread(struct thread *td __unused, void *dst __unused, + size_t *off __unused) +{ + +} Added: head/sys/arm64/arm64/freebsd32_machdep.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/arm64/arm64/freebsd32_machdep.c Fri Nov 24 13:50:53 2017 (r326165) @@ -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 +__FBSDID("$FreeBSD$"); + +#include + +#include + +/* + * 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); +} Modified: head/sys/arm64/arm64/machdep.c ============================================================================== --- head/sys/arm64/arm64/machdep.c Fri Nov 24 12:27:48 2017 (r326164) +++ head/sys/arm64/arm64/machdep.c Fri Nov 24 13:50:53 2017 (r326165) @@ -26,6 +26,7 @@ */ #include "opt_acpi.h" +#include "opt_compat.h" #include "opt_platform.h" #include "opt_ddb.h" @@ -277,6 +278,56 @@ set_dbregs(struct thread *td, struct dbreg *regs) printf("ARM64TODO: set_dbregs"); 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) Modified: head/sys/arm64/include/elf.h ============================================================================== --- head/sys/arm64/include/elf.h Fri Nov 24 12:27:48 2017 (r326164) +++ head/sys/arm64/include/elf.h Fri Nov 24 13:50:53 2017 (r326165) @@ -36,7 +36,10 @@ #include /* Definitions common to all 32 bit architectures. */ #include /* Definitions common to all 64 bit architectures. */ +#ifndef __ELF_WORD_SIZE #define __ELF_WORD_SIZE 64 /* Used by */ +#endif + #include /* @@ -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 Modified: head/sys/arm64/include/param.h ============================================================================== --- head/sys/arm64/include/param.h Fri Nov 24 12:27:48 2017 (r326164) +++ head/sys/arm64/include/param.h Fri Nov 24 13:50:53 2017 (r326165) @@ -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 Modified: head/sys/arm64/include/proc.h ============================================================================== --- head/sys/arm64/include/proc.h Fri Nov 24 12:27:48 2017 (r326164) +++ head/sys/arm64/include/proc.h Fri Nov 24 13:50:53 2017 (r326165) @@ -44,6 +44,7 @@ struct mdproc { }; #define KINFO_PROC_SIZE 1088 +#define KINFO_PROC32_SIZE 816 #define MAXARGS 8 struct syscall_args { Modified: head/sys/arm64/include/reg.h ============================================================================== --- head/sys/arm64/include/reg.h Fri Nov 24 12:27:48 2017 (r326164) +++ head/sys/arm64/include/reg.h Fri Nov 24 13:50:53 2017 (r326165) @@ -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_ */ Modified: head/sys/arm64/include/vdso.h ============================================================================== --- head/sys/arm64/include/vdso.h Fri Nov 24 12:27:48 2017 (r326164) +++ head/sys/arm64/include/vdso.h Fri Nov 24 13:50:53 2017 (r326165) @@ -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_ */ Modified: head/sys/conf/files.arm64 ============================================================================== --- head/sys/conf/files.arm64 Fri Nov 24 12:27:48 2017 (r326164) +++ head/sys/conf/files.arm64 Fri Nov 24 13:50:53 2017 (r326165) @@ -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 Modified: head/sys/conf/options.arm64 ============================================================================== --- head/sys/conf/options.arm64 Fri Nov 24 12:27:48 2017 (r326164) +++ head/sys/conf/options.arm64 Fri Nov 24 13:50:53 2017 (r326165) @@ -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 Modified: head/sys/sys/sysctl.h ============================================================================== --- head/sys/sys/sysctl.h Fri Nov 24 12:27:48 2017 (r326164) +++ head/sys/sys/sysctl.h Fri Nov 24 13:50:53 2017 (r326165) @@ -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