[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.
This commit is contained in:
Brandon Bergren 2020-09-22 23:55:34 +00:00
parent b75abea4d0
commit a662559264
5 changed files with 38 additions and 3 deletions

View File

@ -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__

View File

@ -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

View File

@ -572,6 +572,10 @@ OF_initial_setup(void *fdt_ptr, void *junk, int (*openfirm)(void *))
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;

View File

@ -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)

View File

@ -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);
}