Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 May 2020 19:51:40 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r361291 - head/sys/mips/mips
Message-ID:  <202005201951.04KJpeYw038659@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Wed May 20 19:51:39 2020
New Revision: 361291
URL: https://svnweb.freebsd.org/changeset/base/361291

Log:
  Merge freebsd32_exec_setregs() into exec_setregs() on MIPS.
  
  The stack pointer was being decremented by 64k twice previously.
  
  Reviewed by:	brooks
  Obtained from:	CheriBSD
  Sponsored by:	DARPA
  Differential Revision:	https://reviews.freebsd.org/D24930

Modified:
  head/sys/mips/mips/freebsd32_machdep.c
  head/sys/mips/mips/pm_machdep.c

Modified: head/sys/mips/mips/freebsd32_machdep.c
==============================================================================
--- head/sys/mips/mips/freebsd32_machdep.c	Wed May 20 19:45:22 2020	(r361290)
+++ head/sys/mips/mips/freebsd32_machdep.c	Wed May 20 19:51:39 2020	(r361291)
@@ -68,8 +68,6 @@
 #include <compat/freebsd32/freebsd32_util.h>
 #include <compat/freebsd32/freebsd32_proto.h>
 
-static void freebsd32_exec_setregs(struct thread *, struct image_params *,
-    uintptr_t);
 static int get_mcontext32(struct thread *, mcontext32_t *, int);
 static int set_mcontext32(struct thread *, mcontext32_t *);
 static void freebsd32_sendsig(sig_t, ksiginfo_t *, sigset_t *);
@@ -97,7 +95,7 @@ struct sysentvec elf32_freebsd_sysvec = {
 	.sv_stackprot	= VM_PROT_ALL,
 	.sv_copyout_auxargs = __elfN(freebsd_copyout_auxargs),
 	.sv_copyout_strings = freebsd32_copyout_strings,
-	.sv_setregs	= freebsd32_exec_setregs,
+	.sv_setregs	= exec_setregs,
 	.sv_fixlimit	= NULL,
 	.sv_maxssiz	= NULL,
 	.sv_flags	= SV_ABI_FREEBSD | SV_ILP32,
@@ -125,26 +123,6 @@ static Elf32_Brandinfo freebsd_brand_info = {
 SYSINIT(elf32, SI_SUB_EXEC, SI_ORDER_FIRST,
     (sysinit_cfunc_t) elf32_insert_brand_entry,
     &freebsd_brand_info);
-
-static void
-freebsd32_exec_setregs(struct thread *td, struct image_params *imgp,
-    uintptr_t stack)
-{
-	exec_setregs(td, imgp, stack);
-
-	/*
-	 * See comment in exec_setregs about running 32-bit binaries with 64-bit
-	 * registers.
-	 */
-	td->td_frame->sp -= 65536;
-
-	/*
-	 * Clear extended address space bit for userland.
-	 */
-	td->td_frame->sr &= ~MIPS_SR_UX;
-
-	td->td_md.md_tls_tcb_offset = TLS_TP_OFFSET + TLS_TCB_SIZE32;
-}
 
 int
 set_regs32(struct thread *td, struct reg32 *regs)

Modified: head/sys/mips/mips/pm_machdep.c
==============================================================================
--- head/sys/mips/mips/pm_machdep.c	Wed May 20 19:45:22 2020	(r361290)
+++ head/sys/mips/mips/pm_machdep.c	Wed May 20 19:51:39 2020	(r361291)
@@ -441,11 +441,14 @@ exec_setregs(struct thread *td, struct image_params *i
 	td->td_frame->t9 = imgp->entry_addr & ~3; /* abicall req */
 	td->td_frame->sr = MIPS_SR_KSU_USER | MIPS_SR_EXL | MIPS_SR_INT_IE |
 	    (mips_rd_status() & MIPS_SR_INT_MASK);
-#if defined(__mips_n32) 
+#if defined(__mips_n32) || defined(__mips_n64)
 	td->td_frame->sr |= MIPS_SR_PX;
-#elif  defined(__mips_n64)
-	td->td_frame->sr |= MIPS_SR_PX | MIPS_SR_UX | MIPS_SR_KX;
 #endif
+#if defined(__mips_n64)
+	if (SV_PROC_FLAG(td->td_proc, SV_LP64))
+		td->td_frame->sr |= MIPS_SR_UX;
+	td->td_frame->sr |= MIPS_SR_KX;
+#endif
 	/*
 	 * FREEBSD_DEVELOPERS_FIXME:
 	 * Setup any other CPU-Specific registers (Not MIPS Standard)
@@ -470,7 +473,12 @@ exec_setregs(struct thread *td, struct image_params *i
 	    PCPU_SET(fpcurthread, (struct thread *)0);
 	td->td_md.md_ss_addr = 0;
 
-	td->td_md.md_tls_tcb_offset = TLS_TP_OFFSET + TLS_TCB_SIZE;
+#ifdef COMPAT_FREEBSD32
+	if (!SV_PROC_FLAG(td->td_proc, SV_LP64))
+		td->td_md.md_tls_tcb_offset = TLS_TP_OFFSET + TLS_TCB_SIZE32;
+	else
+#endif
+		td->td_md.md_tls_tcb_offset = TLS_TP_OFFSET + TLS_TCB_SIZE;
 }
 
 int



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202005201951.04KJpeYw038659>