svn commit: r205870 - projects/ppc64/sys/boot/powerpc/ps3
Nathan Whitehorn
nwhitehorn at FreeBSD.org
Tue Mar 30 05:46:32 UTC 2010
Author: nwhitehorn
Date: Tue Mar 30 05:46:31 2010
New Revision: 205870
URL: http://svn.freebsd.org/changeset/base/205870
Log:
Patch some miscellaneous bugs. This gets thing going somewhat on real
hardware. lv1_insert_htab_entry() is hanging for some incomprehensible
reason, however, so we're not quite to a working MMU on hardware yet.
Note also that lv1call.S is an ugly abomination and should be revisited.
Added:
projects/ppc64/sys/boot/powerpc/ps3/lv1call.S
Modified:
projects/ppc64/sys/boot/powerpc/ps3/Makefile
projects/ppc64/sys/boot/powerpc/ps3/lv1call.h
projects/ppc64/sys/boot/powerpc/ps3/lv1call_fake.c
projects/ppc64/sys/boot/powerpc/ps3/main.c
projects/ppc64/sys/boot/powerpc/ps3/ps3mmu.c
projects/ppc64/sys/boot/powerpc/ps3/start.S
Modified: projects/ppc64/sys/boot/powerpc/ps3/Makefile
==============================================================================
--- projects/ppc64/sys/boot/powerpc/ps3/Makefile Mon Mar 29 23:36:34 2010 (r205869)
+++ projects/ppc64/sys/boot/powerpc/ps3/Makefile Tue Mar 30 05:46:31 2010 (r205870)
@@ -9,7 +9,8 @@ BINDIR?= /boot
INSTALLFLAGS= -b
# Architecture-specific loader code
-SRCS= start.S conf.c metadata.c vers.c main.c lv1call_fake.c ps3mmu.c
+SRCS= start.S conf.c metadata.c vers.c main.c lv1call.S ps3mmu.c
+#SRCS= start.S conf.c metadata.c vers.c main.c lv1call_fake.c ps3mmu.c
SRCS+= ucmpdi2.c
LOADER_DISK_SUPPORT?= no
Added: projects/ppc64/sys/boot/powerpc/ps3/lv1call.S
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/ppc64/sys/boot/powerpc/ps3/lv1call.S Tue Mar 30 05:46:31 2010 (r205870)
@@ -0,0 +1,126 @@
+/* Hypercall stubs. Note: this is all a hack and should die. */
+
+#define hc .long 0x44000022
+
+.global lv1_get_logical_pu_id
+lv1_get_logical_pu_id:
+ mflr %r0
+ stw %r0,4(%r1)
+
+ stw %r3,-4(%r1)
+ li %r11,69
+ hc
+ extsw %r3,%r3
+ lwz %r5,-4(%r1)
+ std %r4,0(%r5)
+
+ lwz %r0,4(%r1)
+ mtlr %r0
+ blr
+
+.global lv1_get_logical_partition_id
+lv1_get_logical_partition_id:
+ mflr %r0
+ stw %r0,4(%r1)
+
+ stw %r3,-4(%r1)
+ li %r11,74
+ hc
+ extsw %r3,%r3
+ lwz %r5,-4(%r1)
+ std %r4,0(%r5)
+
+ lwz %r0,4(%r1)
+ mtlr %r0
+ blr
+
+.global lv1_insert_htab_entry
+lv1_insert_htab_entry:
+ mflr %r0
+ stw %r0,4(%r1)
+
+ /* Zero high-order bits of arguments */
+ clrldi %r3,%r3,32
+ clrldi %r4,%r4,32
+ clrldi %r5,%r5,32
+ clrldi %r6,%r6,32
+ clrldi %r7,%r7,32
+ clrldi %r8,%r8,32
+ clrldi %r9,%r9,32
+ clrldi %r10,%r10,32
+ /* Move high 32 bits of args 3 and 4 into position */
+ sldi %r5,%r5,32
+ or %r5,%r5,%r6
+ sldi %r6,%r7,32
+ or %r6,%r6,%r8
+ /* Shift remaining args in */
+ mr %r7,%r9
+ mr %r8,%r10
+
+ li %r11,158
+ hc
+ extsw %r3,%r3
+
+ lwz %r0,4(%r1)
+ mtlr %r0
+ blr
+
+.global lv1_construct_virtual_address_space
+lv1_construct_virtual_address_space:
+ mflr %r0
+ stw %r0,4(%r1)
+ stwu %r1,-16(%r1)
+ stw %r7,8(%r1)
+ stw %r8,12(%r1)
+
+ clrldi %r3,%r3,32
+ clrldi %r4,%r4,32
+ clrldi %r5,%r5,32
+ clrldi %r6,%r6,32
+ sldi %r5,%r5,32
+ or %r5,%r5,%r6
+
+ li %r11,2
+ hc
+ extsw %r3,%r3
+
+ lwz %r7,8(%r1)
+ lwz %r8,12(%r1)
+ std %r4,0(%r7)
+ std %r5,0(%r8)
+ lwz %r1,0(%r1)
+
+ lwz %r0,4(%r1)
+ mtlr %r0
+ blr
+
+.global lv1_select_virtual_address_space
+lv1_select_virtual_address_space:
+ mflr %r0
+ stw %r0,4(%r1)
+
+ clrldi %r3,%r3,32
+ clrldi %r4,%r4,32
+ sldi %r3,%r3,32
+ or %r3,%r3,%r4
+
+ li %r11,7
+ hc
+ extsw %r3,%r3
+ lwz %r0,4(%r1)
+ mtlr %r0
+ blr
+
+.global lv1_panic
+lv1_panic:
+ mflr %r0
+ stw %r0,4(%r1)
+
+ li %r11,255
+ hc
+ extsw %r3,%r3
+
+ lwz %r0,4(%r1)
+ mtlr %r0
+ blr
+
Modified: projects/ppc64/sys/boot/powerpc/ps3/lv1call.h
==============================================================================
--- projects/ppc64/sys/boot/powerpc/ps3/lv1call.h Mon Mar 29 23:36:34 2010 (r205869)
+++ projects/ppc64/sys/boot/powerpc/ps3/lv1call.h Tue Mar 30 05:46:31 2010 (r205870)
@@ -26,13 +26,15 @@
#ifndef _PS3_LV1CALL_H
#define _PS3_LV1CALL_H
+int lv1_get_logical_pu_id(uint64_t *puid);
+int lv1_get_logical_partition_id(uint64_t *puid);
int lv1_insert_htab_entry(register_t htab_id, register_t ptegidx,
uint64_t pte_hi, uint64_t pte_lo, register_t lockflags,
- register_t flags, uint64_t *evict_index, uint64_t *ev_pte_hi,
- uint64_t *ev_pte_lo);
+ register_t flags);
int lv1_construct_virtual_address_space(int htab_size, int npgsizes,
uint64_t page_sizes, uint64_t *as_id, uint64_t *ptsize);
int lv1_select_virtual_address_space(uint64_t as);
+int lv1_panic(int reboot);
#endif
Modified: projects/ppc64/sys/boot/powerpc/ps3/lv1call_fake.c
==============================================================================
--- projects/ppc64/sys/boot/powerpc/ps3/lv1call_fake.c Mon Mar 29 23:36:34 2010 (r205869)
+++ projects/ppc64/sys/boot/powerpc/ps3/lv1call_fake.c Tue Mar 30 05:46:31 2010 (r205870)
@@ -38,14 +38,13 @@ __FBSDID("$FreeBSD: head/sys/boot/powerp
static struct lpteg *pagetable = (struct lpteg *)0x80000;
- int mambocall(int, ...);
- #define mambo_print(a) mambocall(0,a,strlen(a));
+int mambocall(int, ...);
+#define mambo_print(a) mambocall(0,a,strlen(a));
int
lv1_insert_htab_entry(register_t htab_id, register_t ptegidx,
uint64_t pte_hi, uint64_t pte_lo, register_t lockflags,
- register_t flags, uint64_t *evict_index, uint64_t *ev_pte_hi,
- uint64_t *ev_pte_lo)
+ register_t flags)
{
struct lpte *pt;
int i;
@@ -95,3 +94,8 @@ lv1_select_virtual_address_space(uint64_
return (0);
}
+int
+lv1_panic(int val)
+{
+ mambo_print("lv1_panic\n");
+}
Modified: projects/ppc64/sys/boot/powerpc/ps3/main.c
==============================================================================
--- projects/ppc64/sys/boot/powerpc/ps3/main.c Mon Mar 29 23:36:34 2010 (r205869)
+++ projects/ppc64/sys/boot/powerpc/ps3/main.c Tue Mar 30 05:46:31 2010 (r205870)
@@ -28,6 +28,7 @@ __FBSDID("$FreeBSD: head/sys/boot/powerp
#include <stand.h>
#include "bootstrap.h"
+#include "lv1call.h"
int mambocall(int, ...);
__asm(".text; .globl mambocall; mambocall: .long 0x000EAEB0; blr");
@@ -40,7 +41,13 @@ int ps3mmu_init(int maxmem);
int
main(void)
{
- ps3mmu_init(128*1024*1024);
+ int maxmem = 16*1024*1024;
+ uint64_t puid, lpar_id;
+
+ lv1_get_logical_pu_id(&puid);
+ lv1_get_logical_partition_id(&lpar_id);
+
+ ps3mmu_init(maxmem);
mambo_print("Hello world\n");
return (0);
Modified: projects/ppc64/sys/boot/powerpc/ps3/ps3mmu.c
==============================================================================
--- projects/ppc64/sys/boot/powerpc/ps3/ps3mmu.c Mon Mar 29 23:36:34 2010 (r205869)
+++ projects/ppc64/sys/boot/powerpc/ps3/ps3mmu.c Tue Mar 30 05:46:31 2010 (r205870)
@@ -41,51 +41,57 @@ __FBSDID("$FreeBSD: head/sys/boot/powerp
#define PS3_LPAR_VAS_ID_CURRENT 0
register_t pteg_count, pteg_mask;
+uint64_t as_id;
void
ps3mmu_map(uint64_t va, uint64_t pa)
{
- struct lpte pt, expt;
- struct lpteg pteg;
- uint64_t idx, vsid, ptegidx;
+ struct lpte pt;
+ int shift;
+ uint64_t vsid, ptegidx;
if (pa < 0x8000000) { /* Phys mem? */
pt.pte_hi = LPTE_BIG;
pt.pte_lo = LPTE_M;
+ shift = 24;
vsid = 0;
} else {
pt.pte_hi = 0;
pt.pte_lo = LPTE_I | LPTE_G;
+ shift = ADDR_PIDX_SHFT;
vsid = 1;
}
pt.pte_hi |= (vsid << LPTE_VSID_SHIFT) |
(((uint64_t)(va & ADDR_PIDX) >> ADDR_API_SHFT64) & LPTE_API);
- pt.pte_hi |= LPTE_VALID;
+ pt.pte_lo |= pa;
+ ptegidx = vsid ^ (((uint64_t)va & ADDR_PIDX) >> shift);
- ptegidx = vsid ^ (((uint64_t)va & ADDR_PIDX) >> ADDR_PIDX_SHFT);
+ pt.pte_hi |= LPTE_LOCKED | LPTE_VALID;
ptegidx &= pteg_mask;
- lv1_insert_htab_entry(PS3_LPAR_VAS_ID_CURRENT, ptegidx, pt.pte_hi,
- pt.pte_lo, 0x10, 0, &idx, &expt.pte_hi, &expt.pte_lo);
+ i = lv1_insert_htab_entry(0, ptegidx * 8, pt.pte_hi, pt.pte_lo,
+ LPTE_LOCKED, 0);
}
int
ps3mmu_init(int maxmem)
{
- uint64_t as, ptsize;
+ uint64_t ptsize;
int i;
- lv1_construct_virtual_address_space(18 /* log2 256 KB */, 1,
- 24ULL << 56, &as, &ptsize);
+ lv1_construct_virtual_address_space(18 /* log2 256 KB */, 2,
+ (24ULL << 56) | (16ULL << 48), &as_id, &ptsize);
pteg_count = ptsize / sizeof(struct lpteg);
pteg_mask = pteg_count - 1;
- lv1_select_virtual_address_space(as);
+ lv1_select_virtual_address_space(as_id);
+
for (i = 0; i < maxmem; i += 16*1024*1024)
ps3mmu_map(i,i);
+
__asm __volatile ("slbia; slbmte %0, %1; slbmte %2,%3" ::
- "r"(0 | SLBV_L), "r"(0 | SLBE_VALID),
+ "r"((0 << SLBV_VSID_SHIFT) | SLBV_L), "r"(0 | SLBE_VALID),
"r"(1 << SLBV_VSID_SHIFT),
"r"((0xf << SLBE_ESID_SHIFT) | SLBE_VALID | 1));
Modified: projects/ppc64/sys/boot/powerpc/ps3/start.S
==============================================================================
--- projects/ppc64/sys/boot/powerpc/ps3/start.S Mon Mar 29 23:36:34 2010 (r205869)
+++ projects/ppc64/sys/boot/powerpc/ps3/start.S Tue Mar 30 05:46:31 2010 (r205870)
@@ -43,6 +43,10 @@
/* KBoot thread 0 entry -- do relocation, then jump to main */
.global _start
_start:
+ mfmsr %r31
+ clrldi %r31,%r31,1
+ mtmsrd %r31
+ isync
cmpwi %r4,0
bne relocate_self
relocated_start:
@@ -50,20 +54,25 @@ relocated_start:
addi %r1,%r1,(tmpstk+TMPSTKSZ-16)@l
bl main
-. = 0x20
+. = 0x40
.global secondary_spin_sem
secondary_spin_sem:
.long 0
. = 0x60
thread1_start_kboot:
+ mfmsr %r31
+ clrldi %r31,%r31,1
+ mtmsrd %r31
+ isync
+
ba thread1_start /* kboot copies the first 256 bytes to
* address 0, so we are safe to jump
* (and stay) there */
thread1_start:
- li %r0,secondary_spin_sem at l
-1: lwz %r1,0(%r0) /* Spin on SECONDARY_SPIN_SEM_ADDRESS */
+ li %r3,secondary_spin_sem at l
+1: lwz %r1,0(%r3) /* Spin on SECONDARY_SPIN_SEM_ADDRESS */
cmpwi %r1,0
beq 1b
li %r0,0x100 /* Invalidate reset vector cache line */
@@ -72,6 +81,11 @@ thread1_start:
. = 0x100
exc_rst:
+ mfmsr %r31
+ clrldi %r31,%r31,1
+ mtmsrd %r31
+ isync
+
mfspr %r0,SPR_CTRL
/* The first two bits of r0 are 01 (thread 1) or 10 (thread 0) */
cntlzd %r0,%r0 /* Now 0 for thread 0, 1 for thread 1 */
More information about the svn-src-projects
mailing list