From 22c68226777b558c3cfb35a47bc2fd4675ccd65a Mon Sep 17 00:00:00 2001 From: Juli Mallett Date: Tue, 6 Mar 2012 07:47:28 +0000 Subject: [PATCH] When emulating rdhwr for TLS, use the 32-bit offset under COMPAT_FREEBSD32. --- sys/mips/include/tls.h | 7 +++++++ sys/mips/mips/trap.c | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/sys/mips/include/tls.h b/sys/mips/include/tls.h index 514a8aceabf1..97e090344dfd 100644 --- a/sys/mips/include/tls.h +++ b/sys/mips/include/tls.h @@ -32,6 +32,10 @@ #ifndef __MIPS_TLS_H__ #define __MIPS_TLS_H__ +#if defined(_KERNEL) && !defined(KLD_MODULE) && !defined(_STANDALONE) +#include "opt_compat.h" +#endif + /* * TLS parameters */ @@ -41,6 +45,9 @@ #ifdef __mips_n64 #define TLS_TCB_SIZE 16 +#ifdef COMPAT_FREEBSD32 +#define TLS_TCB_SIZE32 8 +#endif #else #define TLS_TCB_SIZE 8 #endif diff --git a/sys/mips/mips/trap.c b/sys/mips/mips/trap.c index 4e365a3325f3..a2cb1d4c9496 100644 --- a/sys/mips/mips/trap.c +++ b/sys/mips/mips/trap.c @@ -814,6 +814,11 @@ dofault: if (inst.RType.rd == 29) { frame_regs = &(trapframe->zero); frame_regs[inst.RType.rt] = (register_t)(intptr_t)td->td_md.md_tls; +#if defined(__mips_n64) && defined(COMPAT_FREEBSD32) + if (SV_PROC_FLAG(td->td_proc, SV_ILP32)) + frame_regs[inst.RType.rt] += TLS_TP_OFFSET + TLS_TCB_SIZE32; + else +#endif frame_regs[inst.RType.rt] += TLS_TP_OFFSET + TLS_TCB_SIZE; trapframe->pc += sizeof(int); goto out;