PPC64 Linux bringup patches v4
cover PPC64 Linux bringup patches v4
After spending even more time trying to get qemu-system-ppc64 to run Linux, I get up to userspace now :-).
I am aware that this patchset is not 100% accurate and perfect for emulation, but I think that it can't get worse than it is now.
This patchset enhances MMU support to work with large pages, implement tlbiel, and fixes random issues I ran into while getting closer to the kernel running userspace code :).
Keep in mind that this also requires an OpenBIOS update, as the current code is not aware that it gets run in 64 bit mode.
For now booting into userspace from an initrd works fine. I didn't try to get IDE working, but it looks like that's broken. Also console=ttyPZ0 doesn't work for me, because the pmz doesn't initialize properly (probably an OpenBIOS issue).
So as long as you use graphical mode and run code from an initrd, you're fine.
I also removed the lwsync patch from this patchset, as it only fixed symptoms and no causes. It would be great if anyone would step up to find out how to fix that, as it's not a ppc-only problem.
v4 fixes:
- guarded is NX after all
- remove SLB bridge writing
- make ppc32 build again
Alexander Graf (11):
PPC64: Implement slbmte
PPC64: Implement large pages
PPC64: Implment tlbiel
Activate uninorth AGP bridge
PPC64: Nop some SPRs on 970fx
PPC64: Enable 64bit mode on interrupts
PPC64: Implement mtfsf.L encoding
PPC64: Fix RFI(d)
PPC64: Fix NX bit
PPC64: Keep SLB in-CPU
PPC64: Disable BAT for 970
hw/unin_pci.c | 27 ++--- target-ppc/cpu.h | 11 ++- target-ppc/helper.c | 274 ++++++++++++++++++++++++++----------------- target-ppc/op_helper.c | 14 ++- target-ppc/translate.c | 45 ++++++- target-ppc/translate_init.c | 14 ++- 6 files changed, 247 insertions(+), 138 deletions(-)
PATCH 1/11 PPC64: Implement slbmte
In order to modify SLB entries on recent PPC64 machines, the slbmte instruction is used.
This patch implements the slbmte instruction and makes the "bridge" mode code use the slb set functions, so we can move the SLB into the CPU struct later.
This is required for Linux to run on PPC64.
--- target-ppc/cpu.h | 3 +- target-ppc/helper.c | 60 +++++++++++++++++++++++++++++++++++++---------- target-ppc/op_helper.c | 8 ++++- target-ppc/translate.c | 23 +++++++++++++++--- 4 files changed, 74 insertions(+), 20 deletions(-)
target-ppc/cpu.h +2 -1
@@ -714,7 +714,8 @@ void ppc_store_sdr1 (CPUPPCState *env, target_ulong value);#if defined(TARGET_PPC64 )void ppc_store_asr (CPUPPCState *env,target_ulong value);target_ulong ppc_load_slb (CPUPPCState *env,int slb_nr); -void ppc_store_slb (CPUPPCState *env,int slb_nr,target_ulong rs); +target_ulong ppc_load_sr (CPUPPCState *env,int sr_nr); +void ppc_store_slb (CPUPPCState *env,target_ulong rb,target_ulong rs);#endif /* defined(TARGET_PPC64) */ void ppc_store_sr (CPUPPCState *env,int srnum,target_ulong value);#endif /* !defined(CONFIG_USER_ONLY) */
target-ppc/helper.c +47 -13
84 lines not on this page · raw message
target-ppc/op_helper.c +6 -2
@@ -3752,6 +3752,10 @@ void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr)/* Segment registers load and store */ target_ulong helper_load_sr (target_ulong sr_num) { +#if defined(TARGET_PPC64 ) +if (env->mmu_model &POWERPC_MMU_64 ) +return ppc_load_sr (env, sr_num); +#endif return env->sr[sr_num]; }
@@ -3767,9 +3771,9 @@ target_ulong helper_load_slb (target_ulong slb_nr)return ppc_load_slb (env, slb_nr); } -void helper_store_slb (target_ulong slb_nr,target_ulong rs) +void helper_store_slb (target_ulong rb,target_ulong rs) { -ppc_store_slb (env, slb_nr, rs); +ppc_store_slb (env, rb, rs); }void helper_slbia (void )
target-ppc/translate.c +19 -4
@@ -4296,7 +4296,7 @@ GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B) return; } t0 =tcg_const_tl (SR (ctx->opcode)); -gen_helper_load_slb (cpu_gpr[rD (ctx->opcode)], t0); +gen_helper_load_sr (cpu_gpr[rD (ctx->opcode)], t0);tcg_temp_free (t0);#endif }
@@ -4316,7 +4316,7 @@ GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001, t0 =tcg_temp_new ();tcg_gen_shri_tl (t0, cpu_gpr[rB (ctx->opcode)],28 );tcg_gen_andi_tl (t0, t0,0xF ); -gen_helper_load_slb (cpu_gpr[rD (ctx->opcode)], t0); +gen_helper_load_sr (cpu_gpr[rD (ctx->opcode)], t0);tcg_temp_free (t0);#endif }
@@ -4333,7 +4333,7 @@ GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B) return; } t0 =tcg_const_tl (SR (ctx->opcode)); -gen_helper_store_slb (t0, cpu_gpr[rS (ctx->opcode)]); +gen_helper_store_sr (t0, cpu_gpr[rS (ctx->opcode)]);tcg_temp_free (t0);#endif }
@@ -4353,10 +4353,25 @@ GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001, t0 =tcg_temp_new ();tcg_gen_shri_tl (t0, cpu_gpr[rB (ctx->opcode)],28 );tcg_gen_andi_tl (t0, t0,0xF ); -gen_helper_store_slb (t0, cpu_gpr[rS (ctx->opcode)]); +gen_helper_store_sr (t0, cpu_gpr[rS (ctx->opcode)]);tcg_temp_free (t0);#endif } + +/* slbmte */ +GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x00000000, PPC_SEGMENT_64B) +{ +#if defined(CONFIG_USER_ONLY ) +gen_inval_exception (ctx,POWERPC_EXCP_PRIV_REG ); +#else +if (unlikely (!ctx->mem_idx)) { +gen_inval_exception (ctx,POWERPC_EXCP_PRIV_REG ); +return ; + } +gen_helper_store_slb (cpu_gpr[rB (ctx->opcode)], cpu_gpr[rS (ctx->opcode)]); +#endif +} +#endif /* defined(TARGET_PPC64) */ /*** Lookaside buffer management ***/
Signature · 1 line
1.6.0.2
PATCH 2/11 PPC64: Implement large pages
The current SLB/PTE code does not support large pages, which are required by Linux, as it boots up with the kernel regions up as large.
This patch implements large page support, so we can run Linux.
--- target-ppc/cpu.h | 1 + target-ppc/helper.c | 78 +++++++++++++++++++++++++++++++------------------- 2 files changed, 49 insertions(+), 30 deletions(-)
target-ppc/cpu.h +1 -0
@@ -675,6 +675,7 @@ struct CPUPPCState {typedef struct mmu_ctx_t mmu_ctx_t ;struct mmu_ctx_t {target_phys_addr_t raddr;/* Real address */ +target_phys_addr_t eaddr;/* Effective address */ int prot;/* Protection bits */ target_phys_addr_t pg_addr[2 ];/* PTE tables base addresses */ target_ulong ptem;/* Virtual segment ID | API */
target-ppc/helper.c +48 -30
176 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 3/11 PPC64: Implment tlbiel
Linux uses tlbiel to flush TLB entries in PPC64 mode. This special TLB flush opcode only flushes an entry for the CPU it runs on, not across all CPUs in the system.
--- target-ppc/translate.c | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-)
target-ppc/translate.c +14 -0
@@ -4390,6 +4390,20 @@ GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA)#endif } +/* tlbiel */ +GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE) +{ +#if defined(CONFIG_USER_ONLY ) +gen_inval_exception (ctx,POWERPC_EXCP_PRIV_OPC ); +#else +if (unlikely (!ctx->mem_idx)) { +gen_inval_exception (ctx,POWERPC_EXCP_PRIV_OPC ); +return ; + } +gen_helper_tlbie (cpu_gpr[rB (ctx->opcode)]); +#endif +} +/* tlbie */ GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE) {
Signature · 1 line
1.6.0.2
PATCH 4/11 Activate uninorth AGP bridge
Linux tries to poke the AGP bridge port and is pretty sad when it can't, so let's activate the old code again and throw out the bit modifications, as we don't really do anything with the values anyways.
--- hw/unin_pci.c | 27 ++++++++------------------- 1 files changed, 8 insertions(+), 19 deletions(-)
hw/unin_pci.c +8 -19
@@ -92,17 +92,12 @@ static CPUReadMemoryFunc *pci_unin_main_read[] = { &pci_host_data_readl, }; -#if 0 -static void pci_unin_config_writel (void *opaque,target_phys_addr_t addr,uint32_t val) {UNINState *s = opaque; -#ifdef TARGET_WORDS_BIGENDIAN - val =bswap32 (val); -#endif - s->config_reg =0x80000000 | (val & ~0x00000001 ); + s->config_reg = val; } static uint32_t pci_unin_config_readl (void *opaque,
@@ -111,12 +106,7 @@ static uint32_t pci_unin_config_readl (void *opaque,UNINState *s = opaque;uint32_t val; - val = (s->config_reg |0x00000001 ) & ~0x80000000 ; -#ifdef TARGET_WORDS_BIGENDIAN - val =bswap32 (val); -#endif - -return val; +return s->config_reg; }static CPUWriteMemoryFunc *pci_unin_config_write[] = {
@@ -131,6 +121,7 @@ static CPUReadMemoryFunc *pci_unin_config_read[] = { &pci_unin_config_readl, }; +#if 0 static CPUWriteMemoryFunc *pci_unin_write[] = { &pci_host_pci_writeb, &pci_host_pci_writew,
@@ -233,18 +224,17 @@ PCIBus *pci_pmac_init(qemu_irq *pic) d->config[0x27 ] =0x7F ;// d->config[0x34] = 0xdc // capabilities_pointer #endif -#if 0 // XXX: not needed for now +/* Uninorth AGP bus */ - s = &pci_bridge[1 ]; pci_mem_config =cpu_register_io_memory (0 , pci_unin_config_read, pci_unin_config_write, s); - pci_mem_data =cpu_register_io_memory (0 , pci_unin_read, - pci_unin_write, s); + pci_mem_data =cpu_register_io_memory (0 , pci_unin_main_read, + pci_unin_main_write, s);cpu_register_physical_memory (0xf0800000 ,0x1000 , pci_mem_config);cpu_register_physical_memory (0xf0c00000 ,0x1000 , pci_mem_data); - d =pci_register_device ("Uni-north AGP" ,sizeof (PCIDevice),0 ,11 <<3 , -NULL ,NULL ); + d =pci_register_device (s->bus,"Uni-north AGP" ,sizeof (PCIDevice), +11 <<3 ,NULL ,NULL );pci_config_set_vendor_id (d->config,PCI_VENDOR_ID_APPLE );pci_config_set_device_id (d->config,PCI_DEVICE_ID_APPLE_UNI_N_AGP ); d->config[0x08 ] =0x00 ;// revision
@@ -253,7 +243,6 @@ PCIBus *pci_pmac_init(qemu_irq *pic) d->config[0x0D ] =0x10 ;// latency_timer d->config[0x0E ] =0x00 ;// header_type // d->config[0x34] = 0x80; // capabilities_pointer -#endif #if 0 // XXX: not needed for now /* Uninorth internal bus */
Signature · 1 line
1.6.0.2
PATCH 5/11 PPC64: Nop some SPRs on 970fx
Linux tries to access some SPRs on PPC64 boot. Let's just ignore those for the 970fx for now to make it happy.
--- target-ppc/translate_init.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)
target-ppc/translate_init.c +12 -0
@@ -6043,6 +6043,18 @@ static void init_proc_970FX (CPUPPCState *env)SPR_NOACCESS ,SPR_NOACCESS , &spr_read_hior, &spr_write_hior, 0x00000000); +spr_register (env,SPR_CTRL ,"SPR_CTRL" , +SPR_NOACCESS ,SPR_NOACCESS , + &spr_read_generic, &spr_write_generic, +0x00000000 ); +spr_register (env,SPR_UCTRL ,"SPR_UCTRL" , +SPR_NOACCESS ,SPR_NOACCESS , + &spr_read_generic, &spr_write_generic, +0x00000000 ); +spr_register (env,SPR_VRSAVE ,"SPR_VRSAVE" , + &spr_read_generic, &spr_write_generic, + &spr_read_generic, &spr_write_generic, +0x00000000 );#if !defined(CONFIG_USER_ONLY ) env->slb_nr =32 ;#endif
Signature · 1 line
1.6.0.2
PATCH 6/11 PPC64: Enable 64bit mode on interrupts
Real 970s enable MSR_SF on all interrupts. The current code didn't do this until now, so let's activate it!
--- target-ppc/helper.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
target-ppc/helper.c +5 -1
@@ -2612,7 +2612,7 @@ static always_inline void powerpc_excp (CPUState *env, new_msr |= (target_ulong )1 <<MSR_CM ; } }else { -if (!msr_isf) { +if (!msr_isf && !(env->mmu_model &POWERPC_MMU_64 )) { new_msr &= ~((target_ulong )1 <<MSR_SF ); vector = (uint32_t )vector; }else {
@@ -2793,6 +2793,10 @@ void cpu_ppc_reset (void *opaque)ppc_tlb_invalidate_all (env);#endif env->msr = msr & env->msr_mask; +#if defined(TARGET_PPC64 ) +if (env->mmu_model &POWERPC_MMU_64 ) + env->msr |= (1ULL <<MSR_SF ); +#endif hreg_compute_hflags (env); env->reserve = (target_ulong)-1ULL ;/* Be sure no exception or interrupt is pending */
Signature · 1 line
1.6.0.2
PATCH 7/11 PPC64: Implement mtfsf.L encoding
Mtfsf can have the L bit set, so all the register contents get stored in FPSCR. Linux uses it, so let's implement it.
--- target-ppc/translate.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
target-ppc/translate.c +6 -2
@@ -2416,9 +2416,10 @@ GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT) }/* mtfsf */ -GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x02010000, PPC_FLOAT) +GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x00010000, PPC_FLOAT) {TCGv_i32 t0; +int L = ctx->opcode &0x02000000 ;if (unlikely (!ctx->fpu_enabled)) {gen_exception (ctx,POWERPC_EXCP_FPU );
@@ -2427,7 +2428,10 @@ GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x02010000, PPC_FLOAT)/* NIP cannot be restored if the memory exception comes from an helper */ gen_update_nip (ctx, ctx->nip -4 );gen_reset_fpstatus (); - t0 =tcg_const_i32 (FM (ctx->opcode)); +if (L ) + t0 =tcg_const_i32 (0xff ); +else + t0 =tcg_const_i32 (FM (ctx->opcode));gen_helper_store_fpscr (cpu_fpr[rB (ctx->opcode)], t0);tcg_temp_free_i32 (t0);if (unlikely (Rc (ctx->opcode) !=0 )) {
Signature · 1 line
1.6.0.2
PATCH 8/11 PPC64: Fix RFI(d)
The current implementation masks some MSR bits from SRR1 as it is given on rfi(d). This looks pretty wrong and breaks Altivec.
--- target-ppc/op_helper.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
target-ppc/op_helper.c +3 -3
@@ -1671,20 +1671,20 @@ static always_inline void do_rfi (target_ulong nip, target_ulong msr,void helper_rfi (void ) {do_rfi (env->spr[SPR_SRR0 ], env->spr[SPR_SRR1 ], - ~((target_ulong )0xFFFF0000 ),1 ); + ~((target_ulong )0x0 ),1 ); }#if defined(TARGET_PPC64 )void helper_rfid (void ) {do_rfi (env->spr[SPR_SRR0 ], env->spr[SPR_SRR1 ], - ~((target_ulong )0xFFFF0000 ),0 ); + ~((target_ulong )0x0 ),0 ); }void helper_hrfid (void ) {do_rfi (env->spr[SPR_HSRR0 ], env->spr[SPR_HSRR1 ], - ~((target_ulong )0xFFFF0000 ),0 ); + ~((target_ulong )0x0 ),0 ); }#endif #endif
Signature · 1 line
1.6.0.2
PATCH 9/11 PPC64: Fix NX bit
ctx->nx only got ORed, but never reset. So when one page in the lifetime of the VM was ever NX, all later pages were too.
--- target-ppc/helper.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
target-ppc/helper.c +1 -1
@@ -226,7 +226,7 @@ static always_inline int _pte_check (mmu_ctx_t *ctx, int is_64b, ptem = pte0 &PTE64_PTEM_MASK ; mmask =PTE64_CHECK_MASK ; pp = (pte1 &0x00000003 ) | ((pte1 >>61 ) &0x00000004 ); - ctx->nx |= (pte1 >>2 ) &1 ;/* No execute bit */ + ctx->nx = (pte1 >>2 ) &1 ;/* No execute bit */ ctx->nx |= (pte1 >>3 ) &1 ;/* Guarded bit */ } else#endif
Signature · 1 line
1.6.0.2
PATCH 10/11 PPC64: Keep SLB in-CPU
Real 970 CPUs have the SLB not memory backed, but inside the CPU. This breaks bridge mode for 970 for now, but at least keeps us from overwriting physical addresses 0x0 - 0x300, rendering our interrupt handlers useless.
I put in a stub for bridge mode operation that could be enabled easily, but for now it's safer to leave that off I guess (970fx doesn't have bridge mode AFAIK).
--- target-ppc/cpu.h | 7 ++ target-ppc/helper.c | 132 ++++++++++++++++++++++-------------------- target-ppc/translate_init.c | 2 +- 3 files changed, 77 insertions(+), 64 deletions(-)
target-ppc/cpu.h +7 -0
@@ -342,6 +342,12 @@ union ppc_tlb_t {ppcemb_tlb_t tlbe; }; +typedef struct ppc_slb_t ppc_slb_t ; +struct ppc_slb_t { +uint64_t tmp64; +uint32_t tmp; +}; +/*****************************************************************************/ /* Machine state register bits definition */ #define MSR_SF 63/* Sixty-four-bit mode hflags */
@@ -582,6 +588,7 @@ struct CPUPPCState {/* Address space register */ target_ulong asr;/* PowerPC 64 SLB area */ +ppc_slb_t slb[64 ];int slb_nr;#endif /* segment registers */
target-ppc/helper.c +69 -63
224 lines not on this page · raw message
target-ppc/translate_init.c +1 -1
@@ -6056,7 +6056,7 @@ static void init_proc_970FX (CPUPPCState *env) &spr_read_generic, &spr_write_generic, 0x00000000);#if !defined(CONFIG_USER_ONLY ) - env->slb_nr =32 ; + env->slb_nr =64 ;#endif init_excp_970 (env); env->dcache_line_size =128 ;
Signature · 1 line
1.6.0.2
PATCH 11/11 PPC64: Disable BAT for 970
The 970 doesn't know BAT, so let's not search BATs there. This was only in as a hack for OpenHackWare so it would work on PPC64.
--- target-ppc/helper.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
target-ppc/helper.c +3 -3
@@ -1357,13 +1357,13 @@ int get_physical_address (CPUState *env, mmu_ctx_t *ctx, target_ulong eaddr,case POWERPC_MMU_601 :case POWERPC_MMU_SOFT_6xx:case POWERPC_MMU_SOFT_74xx: +/* Try to find a BAT */ +if (env->nb_BATs !=0 ) + ret =get_bat (env, ctx, eaddr, rw, access_type);#if defined(TARGET_PPC64 )case POWERPC_MMU_620 :case POWERPC_MMU_64B :#endif -/* Try to find a BAT */ -if (env->nb_BATs !=0 ) - ret =get_bat (env, ctx, eaddr, rw, access_type);if (ret <0 ) {/* We didn't match any BAT entry or don't have BATs */ ret =get_segment (env, ctx, eaddr, rw, access_type);
Signature · 1 line
1.6.0.2
Quoted 2 lines · Alexander Graf
After spending even more time trying to get qemu-system-ppc64 to run Linux, I
get up to userspace now :-).
Great! I applied the whole series, thanks. The Uni-n patch left an unused variable, I deleted that. Patch 10 had a line with only white space but quilt caught that.
Quoted 3 lines
I also removed the lwsync patch from this patchset, as it only fixed symptoms and no causes. It would be great if anyone would step up to find out how to fix that, as it's not a ppc-only problem.
No, also Sparc translator eats nops without generating any output. Nops are also somewhat common because of the delay slots and mandatory delays between some instructions. Usually the compiler will put something useful to the delay slot, but not always.
Quoted 7 lines · Blue Swirl
Quoted 2 lines · Alexander Graf
After spending even more time trying to get qemu-system-ppc64 to run Linux, I get up to userspace now :-).
Great! I applied the whole series, thanks. The Uni-n patch left an unused variable, I deleted that. Patch 10 had a line with only white space but quilt caught that.
Ugh :-).
Keep in mind that this also requires someone to check on & in the patches for openbios, as with this patchset applied the 1.0 openbios release breaks on ppc64 due to invalid interrupt handling.
Alex
Quoted 7 lines · Alexander Graf
Quoted 4 lines · Blue Swirl
Quoted 2 lines · Alexander Graf
After spending even more time trying to get qemu-system-ppc64 to run Linux, I get up to userspace now :-).
Quoted 7 lines
Quoted 3 lines
Great! I applied the whole series, thanks. The Uni-n patch left an unused variable, I deleted that. Patch 10 had a line with only white space but quilt caught that.
Ugh :-).
Keep in mind that this also requires someone to check on & in the patches for openbios, as with this patchset applied the 1.0 openbios release breaks on ppc64 due to invalid interrupt handling.
openBIOS patches are now applied (r466)
Regards,
Laurent