svn commit: r366033 - in head/sys/powerpc: aim ofw pseries

Brandon Bergren bdragon at FreeBSD.org
Tue Sep 22 23:55:36 UTC 2020


Author: bdragon
Date: Tue Sep 22 23:55:34 2020
New Revision: 366033
URL: https://svnweb.freebsd.org/changeset/base/366033

Log:
  [PowerPC64LE] LE bringup work: locore / machdep / platform
  
  This is the initial LE changes required in the machdep code to get as far
  as platform attachment on qemu pseries.
  
  Sponsored by:	Tag1 Consulting, Inc.

Modified:
  head/sys/powerpc/aim/aim_machdep.c
  head/sys/powerpc/aim/locore64.S
  head/sys/powerpc/ofw/ofw_machdep.c
  head/sys/powerpc/ofw/ofwcall64.S
  head/sys/powerpc/pseries/platform_chrp.c

Modified: head/sys/powerpc/aim/aim_machdep.c
==============================================================================
--- head/sys/powerpc/aim/aim_machdep.c	Tue Sep 22 23:49:30 2020	(r366032)
+++ head/sys/powerpc/aim/aim_machdep.c	Tue Sep 22 23:55:34 2020	(r366033)
@@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$");
 #include "opt_kstack_pages.h"
 #include "opt_platform.h"
 
+#include <sys/endian.h>
 #include <sys/param.h>
 #include <sys/proc.h>
 #include <sys/systm.h>
@@ -257,6 +258,11 @@ aim_cpu_init(vm_offset_t toc)
 	psl_kernset |= PSL_SF;
 	if (mfmsr() & PSL_HV)
 		psl_kernset |= PSL_HV;
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+	psl_kernset |= PSL_LE;
+#endif
+
 #endif
 	psl_userset = psl_kernset | PSL_PR;
 #ifdef __powerpc64__

Modified: head/sys/powerpc/aim/locore64.S
==============================================================================
--- head/sys/powerpc/aim/locore64.S	Tue Sep 22 23:49:30 2020	(r366032)
+++ head/sys/powerpc/aim/locore64.S	Tue Sep 22 23:55:34 2020	(r366033)
@@ -133,7 +133,11 @@ btext:
  * r7: Magic cookie (0xfb5d104d) to indicate that r6 has loader metadata
  */
 	.text
-ASENTRY_NOPROF(__start)
+_NAKED_ENTRY(__start)
+
+#ifdef	__LITTLE_ENDIAN__
+	RETURN_TO_NATIVE_ENDIAN
+#endif
 	/* Set 64-bit mode if not yet set before branching to C */
 	mfmsr	%r20
 	li	%r21,1

Modified: head/sys/powerpc/ofw/ofw_machdep.c
==============================================================================
--- head/sys/powerpc/ofw/ofw_machdep.c	Tue Sep 22 23:49:30 2020	(r366032)
+++ head/sys/powerpc/ofw/ofw_machdep.c	Tue Sep 22 23:55:34 2020	(r366033)
@@ -572,6 +572,10 @@ OF_initial_setup(void *fdt_ptr, void *junk, int (*open
 	ofmsr[0] = mfmsr();
 	#ifdef __powerpc64__
 	ofmsr[0] &= ~PSL_SF;
+	#ifdef __LITTLE_ENDIAN__
+	/* Assume OFW is BE. */
+	ofmsr[0] &= ~PSL_LE;
+	#endif
 	#else
 	__asm __volatile("mfsprg0 %0" : "=&r"(ofmsr[1]));
 	#endif
@@ -645,7 +649,7 @@ OF_bootstrap()
 		 * of its auto-remapping function once the kernel is loaded.
 		 * This is a dirty hack, but what we have.
 		 */
-#ifdef _LITTLE_ENDIAN
+#ifdef __LITTLE_ENDIAN__
 		fdt_bt = &bs_le_tag;
 #else
 		fdt_bt = &bs_be_tag;

Modified: head/sys/powerpc/ofw/ofwcall64.S
==============================================================================
--- head/sys/powerpc/ofw/ofwcall64.S	Tue Sep 22 23:49:30 2020	(r366032)
+++ head/sys/powerpc/ofw/ofwcall64.S	Tue Sep 22 23:55:34 2020	(r366033)
@@ -113,6 +113,7 @@ ASENTRY_NOPROF(ofwcall)
 	/*
 	 * Set the MSR to the OF value. This has the side effect of disabling
 	 * exceptions, which is important for the next few steps.
+	 * This does NOT, however, cause us to switch endianness.
 	 */
 
 	addis	%r5,%r2,TOC_REF(ofmsr)@ha
@@ -138,9 +139,28 @@ ASENTRY_NOPROF(ofwcall)
 	stw	%r5,4(%r1)
 	stw	%r5,0(%r1)
 
+#ifdef __LITTLE_ENDIAN__
+	/* Atomic context switch w/ endian change */
+	mtmsrd	%r5, 1	/* Clear PSL_EE|PSL_RI */
+	addis	%r5,%r2,TOC_REF(ofmsr)@ha
+	ld	%r5,TOC_REF(ofmsr)@l(%r5)
+	ld	%r5,0(%r5)
+	mtsrr0	%r4
+	mtsrr1	%r5
+	LOAD_LR_NIA
+1:
+	mflr	%r5
+	addi	%r5, %r5, (2f-1b)
+	mtlr	%r5
+	li	%r5, 0
+	rfid
+2:
+	RETURN_TO_NATIVE_ENDIAN
+#else
 	/* Finally, branch to OF */
 	mtctr	%r4
 	bctrl
+#endif
 
 	/* Reload stack pointer, MSR, and reference PC from the OFW stack */
 	ld	%r7,32(%r1)

Modified: head/sys/powerpc/pseries/platform_chrp.c
==============================================================================
--- head/sys/powerpc/pseries/platform_chrp.c	Tue Sep 22 23:49:30 2020	(r366032)
+++ head/sys/powerpc/pseries/platform_chrp.c	Tue Sep 22 23:55:34 2020	(r366033)
@@ -30,6 +30,7 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
+#include <sys/endian.h>
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
@@ -414,7 +415,7 @@ chrp_cpuref_init(void)
 	/* /chosen/cpu */
 	if (OF_getproplen(chosen, "cpu") == sizeof(ihandle_t)) {
 		OF_getprop(chosen, "cpu", &ibsp, sizeof(ibsp));
-		pbsp = OF_instance_to_package(ibsp);
+		pbsp = OF_instance_to_package(be32toh(ibsp));
 		if (pbsp != -1)
 			get_cpu_reg(pbsp, &bsp_reg);
 	}


More information about the svn-src-head mailing list