Switch earmv6{,hf}eb to BE8 in kernel side.

My strategy here is to define _ARM_ARCH_BE8 macro in arm/cdefs.h, if
__ARMEB__ && _ARM_ARCH_6.

Use this macro to determine whether system is compiled for and running on
BE8 mode or not.

Note that, for __ARMEB__, some conditions become compile-time constants
determined by _ARM_ARCH_BE8 macro, e.g., whether BE8 or BE32 are accepted
as a userland binary, or unaligned memory access is possible or not.
This commit is contained in:
rin 2020-12-01 02:43:13 +00:00
parent a3e196b030
commit e092cf89bf
6 changed files with 50 additions and 32 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: arm_machdep.c,v 1.64 2020/08/14 16:18:36 skrll Exp $ */
/* $NetBSD: arm_machdep.c,v 1.65 2020/12/01 02:43:13 rin Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@ -80,7 +80,7 @@
#include <sys/param.h>
__KERNEL_RCSID(0, "$NetBSD: arm_machdep.c,v 1.64 2020/08/14 16:18:36 skrll Exp $");
__KERNEL_RCSID(0, "$NetBSD: arm_machdep.c,v 1.65 2020/12/01 02:43:13 rin Exp $");
#include <sys/atomic.h>
#include <sys/cpu.h>
@ -176,15 +176,14 @@ setregs(struct lwp *l, struct exec_package *pack, vaddr_t stack)
tf->tf_usr_lr = pack->ep_entry;
tf->tf_svc_lr = 0x77777777; /* Something we can see */
tf->tf_pc = pack->ep_entry;
#if defined(__ARMEB__)
/*
* If we are running on ARMv7, we need to set the E bit to force
* programs to start as big endian.
*/
tf->tf_spsr = PSR_USR32_MODE | (CPU_IS_ARMV7_P() ? PSR_E_BIT : 0);
#else
tf->tf_spsr = PSR_USR32_MODE;
#endif /* __ARMEB__ */
#ifdef _ARM_ARCH_BE8
/*
* If we are running on BE8 mode, we need to set the E bit to
* force programs to start as big endian.
*/
tf->tf_spsr |= PSR_E_BIT;
#endif
#ifdef THUMB_CODE
if (pack->ep_entry & 1)

View File

@ -1,4 +1,4 @@
/* $NetBSD: cpu_exec.c,v 1.12 2020/11/12 01:03:22 rin Exp $ */
/* $NetBSD: cpu_exec.c,v 1.13 2020/12/01 02:43:13 rin Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: cpu_exec.c,v 1.12 2020/11/12 01:03:22 rin Exp $");
__KERNEL_RCSID(0, "$NetBSD: cpu_exec.c,v 1.13 2020/12/01 02:43:13 rin Exp $");
#include "opt_compat_netbsd.h"
@ -72,8 +72,11 @@ arm_netbsd_elf32_probe(struct lwp *l, struct exec_package *epp, void *eh0,
* If the BE-8 model is supported, CPSR[7] will be clear.
* If the BE-32 model is supported, CPSR[7] will be set.
*/
register_t ctl = armreg_sctlr_read();
if (((ctl & CPU_CONTROL_BEND_ENABLE) != 0) == be8_p)
#ifdef _ARM_ARCH_BE8
if (!be8_p)
#else
if (be8_p)
#endif
return ENOEXEC;
#endif /* __ARMEB__ */
@ -111,7 +114,14 @@ arm_netbsd_elf32_probe(struct lwp *l, struct exec_package *epp, void *eh0,
* If we are AAPCS (EABI) and armv6/armv7, we want alignment faults
* to be off.
*/
if (aapcs_p && (CPU_IS_ARMV7_P() || CPU_IS_ARMV6_P())) {
#if defined(__ARMEL__)
if (aapcs_p && (CPU_IS_ARMV7_P() || CPU_IS_ARMV6_P()))
#elif defined(_ARM_ARCH_BE8)
if (aapcs_p)
#else
if (false /* CONSTCOND */)
#endif
{
l->l_md.md_flags |= MDLWP_NOALIGNFLT;
} else {
l->l_md.md_flags &= ~MDLWP_NOALIGNFLT;

View File

@ -1,4 +1,4 @@
/* $NetBSD: arm32_boot.c,v 1.40 2020/09/11 06:40:25 skrll Exp $ */
/* $NetBSD: arm32_boot.c,v 1.41 2020/12/01 02:43:14 rin Exp $ */
/*
* Copyright (c) 2002, 2003, 2005 Genetec Corporation. All rights reserved.
@ -122,7 +122,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(1, "$NetBSD: arm32_boot.c,v 1.40 2020/09/11 06:40:25 skrll Exp $");
__KERNEL_RCSID(1, "$NetBSD: arm32_boot.c,v 1.41 2020/12/01 02:43:14 rin Exp $");
#include "opt_arm_debug.h"
#include "opt_cputypes.h"
@ -191,10 +191,9 @@ initarm_common(vaddr_t kvm_base, vsize_t kvm_size,
memset(tf, 0, sizeof(*tf));
lwp_settrapframe(l, tf);
#if defined(__ARMEB__)
tf->tf_spsr = PSR_USR32_MODE | (CPU_IS_ARMV7_P() ? PSR_E_BIT : 0);
#else
tf->tf_spsr = PSR_USR32_MODE;
#ifdef _ARM_ARCH_BE8
tf->tf_spsr |= PSR_E_BIT;
#endif
VPRINTF("bootstrap done.\n");

View File

@ -1,4 +1,4 @@
/* $NetBSD: arm32_machdep.c,v 1.138 2020/10/30 18:54:36 skrll Exp $ */
/* $NetBSD: arm32_machdep.c,v 1.139 2020/12/01 02:43:14 rin Exp $ */
/*
* Copyright (c) 1994-1998 Mark Brinicombe.
@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: arm32_machdep.c,v 1.138 2020/10/30 18:54:36 skrll Exp $");
__KERNEL_RCSID(0, "$NetBSD: arm32_machdep.c,v 1.139 2020/12/01 02:43:14 rin Exp $");
#include "opt_arm_debug.h"
#include "opt_arm_start.h"
@ -348,10 +348,9 @@ cpu_startup(void)
memset(tf, 0, sizeof(*tf));
lwp_settrapframe(l, tf);
#if defined(__ARMEB__)
tf->tf_spsr = PSR_USR32_MODE | (CPU_IS_ARMV7_P() ? PSR_E_BIT : 0);
#else
tf->tf_spsr = PSR_USR32_MODE;
#ifdef _ARM_ARCH_BE8
tf->tf_spsr |= PSR_E_BIT;
#endif
cpu_startup_hook();
@ -538,7 +537,14 @@ SYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup")
CTLTYPE_INT, "printfataltraps", NULL,
NULL, 0, &cpu_printfataltraps, 0,
CTL_MACHDEP, CTL_CREATE, CTL_EOL);
cpu_unaligned_sigbus = !CPU_IS_ARMV6_P() && !CPU_IS_ARMV7_P();
cpu_unaligned_sigbus =
#if defined(__ARMEL__)
!CPU_IS_ARMV6_P() && !CPU_IS_ARMV7_P();
#elif defined(_ARM_ARCH_BE8)
0;
#else
1;
#endif
sysctl_createv(clog, 0, NULL, NULL,
CTLFLAG_PERMANENT|CTLFLAG_READONLY,
CTLTYPE_INT, "unaligned_sigbus",

View File

@ -1,4 +1,4 @@
/* $NetBSD: kobj_machdep.c,v 1.14 2020/06/20 07:10:36 skrll Exp $ */
/* $NetBSD: kobj_machdep.c,v 1.15 2020/12/01 02:43:14 rin Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -52,7 +52,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kobj_machdep.c,v 1.14 2020/06/20 07:10:36 skrll Exp $");
__KERNEL_RCSID(0, "$NetBSD: kobj_machdep.c,v 1.15 2020/12/01 02:43:14 rin Exp $");
#define ELFSIZE ARCH_ELFSIZE
@ -209,7 +209,7 @@ kobj_reloc(kobj_t ko, uintptr_t relocbase, const void *data,
return -1;
}
#if __ARMEB__
#ifdef _ARM_ARCH_BE8
enum be8_magic_sym_type {
Other, ArmStart, ThumbStart, DataStart
@ -400,8 +400,8 @@ kobj_machdep(kobj_t ko, void *base, size_t size, bool load)
{
if (load) {
#if __ARMEB__
if (CPU_IS_ARMV7_P() && base == (void*)ko->ko_text_address)
#ifdef _ARM_ARCH_BE8
if (base == (void*)ko->ko_text_address)
kobj_be8_fixup(ko);
#endif
#ifndef _RUMPKERNEL

View File

@ -1,4 +1,4 @@
/* $NetBSD: cdefs.h,v 1.18 2020/11/03 08:34:17 skrll Exp $ */
/* $NetBSD: cdefs.h,v 1.19 2020/12/01 02:43:14 rin Exp $ */
#ifndef _ARM_CDEFS_H_
#define _ARM_CDEFS_H_
@ -55,6 +55,10 @@
#define _ARM_ARCH_DWORD_OK
#endif
#if defined (__ARMEB__) && defined (_ARM_ARCH_6)
#define _ARM_ARCH_BE8
#endif
#if defined(__ARM_PCS_AAPCS64)
#define __ALIGNBYTES (sizeof(__int128_t) - 1)
#elif defined(__ARM_EABI__)