Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/arm Fix confusions related to encoding of instructi...



details:   https://anonhg.NetBSD.org/src/rev/dc1c715001e6
branches:  trunk
changeset: 957514:dc1c715001e6
user:      rin <rin%NetBSD.org@localhost>
date:      Tue Dec 01 02:48:28 2020 +0000

description:
Fix confusions related to encoding of instructions.

For __ARMEB__ in BE8 mode, instructions are encoded in little-endian.
Therefore, we need to swap bytes against these in native byte order.

In other cases, i.e., __ARMEL__ and __ARMEB__ in BE32 mode, instructions
are in native byte order, and we don't need to swap them.

diffstat:

 sys/arch/arm/arm/disassem.c       |   6 +++---
 sys/arch/arm/arm32/db_interface.c |  10 +++++-----
 sys/arch/arm/include/db_machdep.h |   7 ++++++-
 sys/arch/arm/include/locore.h     |   6 +++---
 sys/arch/arm/include/ptrace.h     |  13 ++++++++++---
 sys/arch/arm/include/trap.h       |   8 +++++++-
 6 files changed, 34 insertions(+), 16 deletions(-)

diffs (183 lines):

diff -r 3b5609714f83 -r dc1c715001e6 sys/arch/arm/arm/disassem.c
--- a/sys/arch/arm/arm/disassem.c       Tue Dec 01 02:46:19 2020 +0000
+++ b/sys/arch/arm/arm/disassem.c       Tue Dec 01 02:48:28 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disassem.c,v 1.41 2019/10/24 18:34:22 christos Exp $   */
+/*     $NetBSD: disassem.c,v 1.42 2020/12/01 02:48:28 rin Exp $        */
 
 /*
  * Copyright (c) 1996 Mark Brinicombe.
@@ -49,7 +49,7 @@
 
 #include <sys/param.h>
 
-__KERNEL_RCSID(0, "$NetBSD: disassem.c,v 1.41 2019/10/24 18:34:22 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: disassem.c,v 1.42 2020/12/01 02:48:28 rin Exp $");
 
 #include <sys/systm.h>
 
@@ -447,7 +447,7 @@
        fmt = 0;
        matchp = 0;
        insn = di->di_readword(loc);
-#if defined(__ARMEB__) && defined(CPU_ARMV7)
+#ifdef _ARM_ARCH_BE8
        insn = bswap32(insn);
 #endif
        char neonfmt = 'd';
diff -r 3b5609714f83 -r dc1c715001e6 sys/arch/arm/arm32/db_interface.c
--- a/sys/arch/arm/arm32/db_interface.c Tue Dec 01 02:46:19 2020 +0000
+++ b/sys/arch/arm/arm32/db_interface.c Tue Dec 01 02:48:28 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_interface.c,v 1.61 2020/06/20 15:45:22 skrll Exp $  */
+/*     $NetBSD: db_interface.c,v 1.62 2020/12/01 02:48:29 rin Exp $    */
 
 /*
  * Copyright (c) 1996 Scott K. Stevens
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.61 2020/06/20 15:45:22 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.62 2020/12/01 02:48:29 rin Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -303,10 +303,10 @@
 void
 cpu_Debugger(void)
 {
-#if _BYTE_ORDER == _LITTLE_ENDIAN
+#ifdef _ARM_ARCH_BE8
+       __asm(".word    0xffffffe7");
+#else
        __asm(".word    0xe7ffffff");
-#else
-       __asm(".word    0xffffffe7");
 #endif
 }
 
diff -r 3b5609714f83 -r dc1c715001e6 sys/arch/arm/include/db_machdep.h
--- a/sys/arch/arm/include/db_machdep.h Tue Dec 01 02:46:19 2020 +0000
+++ b/sys/arch/arm/include/db_machdep.h Tue Dec 01 02:48:28 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_machdep.h,v 1.27 2018/04/01 04:35:04 ryo Exp $      */
+/*     $NetBSD: db_machdep.h,v 1.28 2020/12/01 02:48:29 rin Exp $      */
 
 /*
  * Copyright (c) 1996 Scott K Stevens
@@ -39,6 +39,7 @@
 #include <sys/types.h>
 #include <uvm/uvm_extern.h>
 #include <arm/armreg.h>
+#include <arm/cdefs.h>
 #include <machine/frame.h>
 #include <machine/trap.h>
 
@@ -70,7 +71,11 @@
 #define BKPT_INST      (GDB5_BREAKPOINT)
 #endif
 #define        BKPT_SIZE       (INSN_SIZE)             /* size of breakpoint inst */
+#ifdef __ARM_ARCH_BE8
+#define        BKPT_SET(inst, addr)    (bswap32(BKPT_INST))
+#else
 #define        BKPT_SET(inst, addr)    (BKPT_INST)
+#endif
 
 /*#define FIXUP_PC_AFTER_BREAK(regs)   ((regs)->tf_pc -= BKPT_SIZE)*/
 
diff -r 3b5609714f83 -r dc1c715001e6 sys/arch/arm/include/locore.h
--- a/sys/arch/arm/include/locore.h     Tue Dec 01 02:46:19 2020 +0000
+++ b/sys/arch/arm/include/locore.h     Tue Dec 01 02:48:28 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.h,v 1.34 2020/10/30 18:54:36 skrll Exp $        */
+/*     $NetBSD: locore.h,v 1.35 2020/12/01 02:48:29 rin Exp $  */
 
 /*
  * Copyright (c) 1994-1996 Mark Brinicombe.
@@ -202,7 +202,7 @@
        } else {
                insn = *(const uint32_t *)va;
        }
-#if defined(__ARMEB__) && defined(_ARM_ARCH_7)
+#ifdef _ARM_ARCH_BE8
        insn = bswap32(insn);
 #endif
        return insn;
@@ -232,7 +232,7 @@
        } else {
                insn = *(const uint16_t *)va;
        }
-#if defined(__ARMEB__) && defined(_ARM_ARCH_7)
+#ifdef _ARM_ARCH_BE8
        insn = bswap16(insn);
 #endif
        return insn;
diff -r 3b5609714f83 -r dc1c715001e6 sys/arch/arm/include/ptrace.h
--- a/sys/arch/arm/include/ptrace.h     Tue Dec 01 02:46:19 2020 +0000
+++ b/sys/arch/arm/include/ptrace.h     Tue Dec 01 02:48:28 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ptrace.h,v 1.15 2019/06/18 21:18:12 kamil Exp $        */
+/*     $NetBSD: ptrace.h,v 1.16 2020/12/01 02:48:29 rin Exp $  */
 
 /*
  * Copyright (c) 1995 Frank Lancaster
@@ -31,6 +31,8 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <arm/cdefs.h>
+
 /*
  * arm-dependent ptrace definitions
  */
@@ -67,12 +69,17 @@
 
 #define PTRACE_ILLEGAL_ASM     __asm __volatile ("udf #0" : : : "memory")
 
-#ifdef __ARMEB__
+#if defined(__ARMEL__) || defined(_ARM_ARCH_BE8)
 #define PTRACE_BREAKPOINT      ((const uint8_t[]) { 0xfe, 0xde, 0xff, 0xe7 })
-#define PTRACE_BREAKPOINT_INSN 0xfedeffe7
 #else
 #define PTRACE_BREAKPOINT      ((const uint8_t[]) { 0xe7, 0xff, 0xde, 0xfe })
+#endif
+
+#ifdef _ARM_ARCH_BE8
+#define PTRACE_BREAKPOINT_INSN 0xfedeffe7
+#else
 #define PTRACE_BREAKPOINT_INSN 0xe7ffdefe
 #endif
+
 #define PTRACE_BREAKPOINT_ASM  __asm __volatile (".word " ___STRING(PTRACE_BREAKPOINT_INSN) )
 #define PTRACE_BREAKPOINT_SIZE 4
diff -r 3b5609714f83 -r dc1c715001e6 sys/arch/arm/include/trap.h
--- a/sys/arch/arm/include/trap.h       Tue Dec 01 02:46:19 2020 +0000
+++ b/sys/arch/arm/include/trap.h       Tue Dec 01 02:48:28 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.h,v 1.9 2014/03/15 05:54:20 ozaki-r Exp $ */
+/*     $NetBSD: trap.h,v 1.10 2020/12/01 02:48:29 rin Exp $    */
 
 /*
  * Copyright (c) 1995 Mark Brinicombe.
@@ -38,6 +38,8 @@
  * Various trap definitions
  */
 
+#include <arm/cdefs.h>
+
 /*
  * Instructions used for breakpoints.
  *
@@ -70,7 +72,11 @@
 #define DTRACE_BREAKPOINT_MASK 0xfffffff0
 #define DTRACE_IS_BREAKPOINT(insn)     ((insn & DTRACE_BREAKPOINT_MASK) == DTRACE_BREAKPOINT)
 
+#ifdef _ARM_ARCH_BE8
+#define KBPT_ASM               ".word 0xfedeffe7"
+#else
 #define KBPT_ASM               ".word 0xe7ffdefe"
+#endif
 
 #define USER_BREAKPOINT                GDB_BREAKPOINT
 



Home | Main Index | Thread Index | Old Index