From ee628685e855987a12719ddfbb8f1145e89c2959 Mon Sep 17 00:00:00 2001 From: Brandon Bergren Date: Sat, 18 Jan 2020 04:12:41 +0000 Subject: [PATCH] D23057: [PowerPC] Fix offset calculations in bridge mode In rS354701, I replaced text relocations with offsets from &generictrap. Unfortunately, the magic variable I was using doesn't actually mean the address of &generictrap, in bridge mode it actually means &generictrap64. So, for bridge mode to work, it is necessary to differentiate between "where do we need to branch to to handle a trap" and "where is &generictrap for purposes of doing relative math". Introduce a new TRAP_ENTRY and use it instead of TRAP_GENTRAP for doing actual calls to the generic trap handler. Reported by: Mark Millard Reviewed by: jhibbits Sponsored by: Tag1 Consulting, Inc. Differential Revision: https://reviews.freebsd.org/D23057 --- sys/powerpc/aim/aim_machdep.c | 8 +++++--- sys/powerpc/aim/trap_subr32.S | 4 ++-- sys/powerpc/aim/trap_subr64.S | 8 ++++---- sys/powerpc/include/trap.h | 5 +++-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/sys/powerpc/aim/aim_machdep.c b/sys/powerpc/aim/aim_machdep.c index b132c9d819ab..22704dff29ac 100644 --- a/sys/powerpc/aim/aim_machdep.c +++ b/sys/powerpc/aim/aim_machdep.c @@ -388,16 +388,18 @@ aim_cpu_init(vm_offset_t toc) bcopy(&dsitrap, (void *)(EXC_DSI + trap_offset), (size_t)&dsiend - (size_t)&dsitrap); + /* Set address of generictrap for self-reloc calculations */ + *((void **)TRAP_GENTRAP) = &generictrap; #ifdef __powerpc64__ /* Set TOC base so that the interrupt code can get at it */ - *((void **)TRAP_GENTRAP) = &generictrap; + *((void **)TRAP_ENTRY) = &generictrap; *((register_t *)TRAP_TOCBASE) = toc; #else /* Set branch address for trap code */ if (cpu_features & PPC_FEATURE_64) - *((void **)TRAP_GENTRAP) = &generictrap64; + *((void **)TRAP_ENTRY) = &generictrap64; else - *((void **)TRAP_GENTRAP) = &generictrap; + *((void **)TRAP_ENTRY) = &generictrap; *((void **)TRAP_TOCBASE) = _GLOBAL_OFFSET_TABLE_; /* G2-specific TLB miss helper handlers */ diff --git a/sys/powerpc/aim/trap_subr32.S b/sys/powerpc/aim/trap_subr32.S index 990d438b643c..8dd52b952aa2 100644 --- a/sys/powerpc/aim/trap_subr32.S +++ b/sys/powerpc/aim/trap_subr32.S @@ -348,7 +348,7 @@ CNAME(trapcode): mtsprg1 %r1 /* save SP */ mflr %r1 /* Save the old LR in r1 */ mtsprg2 %r1 /* And then in SPRG2 */ - lwz %r1, TRAP_GENTRAP(0) /* Get branch address */ + lwz %r1, TRAP_ENTRY(0) /* Get branch address */ mtlr %r1 li %r1, 0xe0 /* How to get the vector from LR */ blrl /* LR & (0xff00 | r1) is exception # */ @@ -908,7 +908,7 @@ CNAME(dblow): mflr %r1 /* save LR */ mtsprg2 %r1 /* And then in SPRG2 */ - lwz %r1, TRAP_GENTRAP(0) /* Get branch address */ + lwz %r1, TRAP_ENTRY(0) /* Get branch address */ mtlr %r1 li %r1, 0 /* How to get the vector from LR */ blrl /* LR & (0xff00 | r1) is exception # */ diff --git a/sys/powerpc/aim/trap_subr64.S b/sys/powerpc/aim/trap_subr64.S index 9af1c4eca18a..69a146ece703 100644 --- a/sys/powerpc/aim/trap_subr64.S +++ b/sys/powerpc/aim/trap_subr64.S @@ -318,7 +318,7 @@ CNAME(rstcode): * It is software reset when 46:47 = 0b00 */ /* 0x00 */ - ld %r2,TRAP_GENTRAP(0) /* Real-mode &generictrap */ + ld %r2,TRAP_ENTRY(0) /* Real-mode &generictrap */ mfsrr1 %r9 /* Load SRR1 into r9 */ andis. %r9,%r9,0x3 /* Logic AND with 46:47 bits */ @@ -446,7 +446,7 @@ CNAME(trapcode): mtsprg1 %r1 /* save SP */ mflr %r1 /* Save the old LR in r1 */ mtsprg2 %r1 /* And then in SPRG2 */ - ld %r1,TRAP_GENTRAP(0) + ld %r1,TRAP_ENTRY(0) mtlr %r1 li %r1, 0xe0 /* How to get the vector from LR */ blrl /* Branch to generictrap */ @@ -493,7 +493,7 @@ CNAME(slbtrap): mflr %r1 /* 0x30 */ mtsprg2 %r1 /* save LR in SPRG2 */ - ld %r1,TRAP_GENTRAP(0) /* real-mode &generictrap */ + ld %r1,TRAP_ENTRY(0) /* real-mode &generictrap */ mtlr %r1 li %r1, 0x80 /* How to get the vector from LR */ /* 0x40 */ @@ -955,7 +955,7 @@ CNAME(dblow): mflr %r1 /* save LR */ mtsprg2 %r1 /* And then in SPRG2 */ - ld %r1, TRAP_GENTRAP(0) /* Get branch address */ + ld %r1, TRAP_ENTRY(0) /* Get branch address */ mtlr %r1 li %r1, 0 /* How to get the vector from LR */ blrl /* Branch to generictrap */ diff --git a/sys/powerpc/include/trap.h b/sys/powerpc/include/trap.h index 56b789c248ef..d507bb27c771 100644 --- a/sys/powerpc/include/trap.h +++ b/sys/powerpc/include/trap.h @@ -147,8 +147,9 @@ #define EXC_DTRACE 0x7ffff808 /* Magic pointer to store TOC base and other info for trap handlers on ppc64 */ -#define TRAP_GENTRAP 0x1f0 -#define TRAP_TOCBASE 0x1f8 +#define TRAP_ENTRY 0x1e8 +#define TRAP_GENTRAP 0x1f0 +#define TRAP_TOCBASE 0x1f8 #ifndef LOCORE struct trapframe;