PPC64 Linux bringup patches
cover PPC64 Linux bringup patches
I spent my weekend on trying to get Linux running on qemu-system-ppc64 and partly succeeded :-).
This patchset extends MMU support far enough for Linux to be happy and works around one segmentation fault I encountered during the process.
Now the kernel panic()s on setting up nvram, which is a different field to look at next.
Alexander Graf (3):
PPC: Circumvent overflow in mtcrf
PPC64: Implement slbmte
PPC64: Implement large pages
target-ppc/cpu.h | 4 +- target-ppc/helper.c | 135 ++++++++++++++++++++++++++++++++---------------- target-ppc/op_helper.c | 6 ++- target-ppc/translate.c | 25 +++++++-- 4 files changed, 118 insertions(+), 52 deletions(-)
PATCH 1/3 PPC: Circumvent overflow in mtcrf
I had a segmentation fault in mtcrf, where ffs() returned 8 and the code then accessed cpu_crf[7 - 8].
In order to circumvent this, I just put in an & 7 to the ffs result, so we'll never run negative. This is probably not correct, but makes things work for me so far.
--- target-ppc/translate.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
target-ppc/translate.c +1 -1
@@ -3937,7 +3937,7 @@ GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC) crm =CRM (ctx->opcode);if (likely ((ctx->opcode &0x00100000 ) || (crm ^ (crm -1 )) ==0 )) {TCGv_i32 temp =tcg_temp_new_i32 (); - crn =ffs (crm); + crn =ffs (crm) &7 ;tcg_gen_trunc_tl_i32 (temp, cpu_gpr[rS (ctx->opcode)]);tcg_gen_shri_i32 (cpu_crf[7 - crn], temp, crn *4 );tcg_gen_andi_i32 (cpu_crf[7 - crn], cpu_crf[7 - crn],0xf );
Signature · 1 line
1.6.0.2
PATCH 2/3 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 | 57 ++++++++++++++++++++++++++++++++++++----------- target-ppc/op_helper.c | 6 +++- target-ppc/translate.c | 23 ++++++++++++++++--- 4 files changed, 68 insertions(+), 21 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 +43 -14
81 lines not on this page · raw message
target-ppc/op_helper.c +4 -2
@@ -3752,6 +3752,8 @@ 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 (env->mmu_model &POWERPC_MMU_64 ) +return ppc_load_sr (env, sr_num);return env->sr[sr_num]; }
@@ -3767,9 +3769,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
@@ -4291,7 +4291,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 }
@@ -4311,7 +4311,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 }
@@ -4328,7 +4328,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 }
@@ -4348,10 +4348,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 3/3 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
[Qemu-devel] Re: [PATCH 2/3] PPC64: Implement slbmte
In reply to Alexander GrafQuoted 18 lines · Alexander Graf
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.
Signed-off-by Alexander Graf <[email protected]>void
ppc_store_sr(CPUPPCState *env, int srnum,target_ulongvalue){ LOG_MMU("%s: reg=%d " ADDRX " " ADDRX "\n", __func__, srnum, value, env->sr[srnum]);- if (env->sr[srnum] != value) {
+ if (env->mmu_model&POWERPC_MMU_64) {
Quoted 6 lines
target_ulonghelper_load_sr(target_ulongsr_num) {
+ if (env->mmu_model&POWERPC_MMU_64)+ return ppc_load_sr(env, sr_num); return env->sr[sr_num];}
It would be faster to move the MMU model checks to translation time.
[Qemu-devel] Re: [PATCH 2/3] PPC64: Implement slbmte
Quoted 19 lines · Blue Swirl
Quoted 17 lines · Alexander Graf
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.
Signed-off-by Alexander Graf <[email protected]>void
ppc_store_sr(CPUPPCState *env, int srnum,target_ulongvalue){ LOG_MMU("%s: reg=%d " ADDRX " " ADDRX "\n", __func__, srnum, value, env->sr[srnum]);target-ppc/helper.c +1
-1-if (env->sr[srnum] != value) { +if (env->mmu_model &POWERPC_MMU_64 ) {
Quoted 8 lines
target-ppc/op_helper.c void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr) · line 3758
Quoted 6 lines
target_ulonghelper_load_sr(target_ulongsr_num) {target-ppc/op_helper.c +2
-0+if (env->mmu_model &POWERPC_MMU_64 ) +return ppc_load_sr (env, sr_num);return env->sr[sr_num]; }It would be faster to move the MMU model checks to translation time.
The problem is that we don't know which -cpu the user will give us when we run qemu-system-ppc64. Of course we could just make qemu-system-ppc64 not take any non-64 bit CPUs, if nobody totally disagrees.
Alex
Re: [Qemu-devel] Re: [PATCH 2/3] PPC64: Implement slbmte
Quoted 11 lines
Quoted 8 lines
target-ppc/op_helper.c void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr) · line 3758
Quoted 6 lines
target_ulonghelper_load_sr(target_ulongsr_num) {target-ppc/op_helper.c +2
-0+if (env->mmu_model &POWERPC_MMU_64 ) +return ppc_load_sr (env, sr_num);return env->sr[sr_num]; }It would be faster to move the MMU model checks to translation time.
The problem is that we don't know which -cpu the user will give us when we run qemu-system-ppc64.
You're confusing translation time with compile time.
Paul
[Qemu-devel] Re: [PATCH 2/3] PPC64: Implement slbmte
In reply to Alexander GrafQuoted 36 lines · Alexander Graf
Quoted 32 lines · Blue Swirl
Quoted 29 lines · Alexander Graf
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.
Signed-off-by Alexander Graf <[email protected]>void
ppc_store_sr(CPUPPCState *env, int srnum,target_ulongvalue){ LOG_MMU("%s: reg=%d " ADDRX " " ADDRX "\n", __func__, srnum, value, env->sr[srnum]);target-ppc/op_helper.c +3
-1-if (env->sr[srnum] != value) { +if (env->mmu_model &POWERPC_MMU_64 ) {target_ulong helper_load_sr (target_ulong sr_num) { +if (env->mmu_model &POWERPC_MMU_64 ) +return ppc_load_sr (env, sr_num);return env->sr[sr_num]; }
Quoted 7 lines
Quoted 2 lines
It would be faster to move the MMU model checks to translation time.
The problem is that we don't know which -cpu the user will give us when we
run qemu-system-ppc64.
Of course we could just make qemu-system-ppc64 not take any non-64 bit
CPUs, if nobody totally disagrees.
env could contain a pointer to (static const) structure describing the CPU features. This pointer would be copied to corresponding DisasContext feature pointer, to be used by the translation functions.
See for example target-sparc: translate.c (CHECK_IU_FEATURE macro) and helper.c for CPU definitions. IIRC MIPS or ARM have even nicer macros.
[Qemu-devel] Re: [PATCH 2/3] PPC64: Implement slbmte
Quoted 45 lines · Blue Swirl
Quoted 36 lines · Alexander Graf
Quoted 32 lines · Blue Swirl
Quoted 29 lines · Alexander Graf
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.
Signed-off-by Alexander Graf <[email protected]>void
ppc_store_sr(CPUPPCState *env, int srnum,target_ulongvalue) {
LOG_MMU("%s: reg=%d " ADDRX " " ADDRX "\n",__func__, srnum, value, env->sr[srnum]);target-ppc/helper.c +1
-1-if (env->sr[srnum] != value) { +if (env->mmu_model &POWERPC_MMU_64 ) {
target_ulonghelper_load_sr(target_ulongsr_num)
{target-ppc/op_helper.c +2
-0+if (env->mmu_model &POWERPC_MMU_64 ) +return ppc_load_sr (env, sr_num);return env->sr[sr_num];}
Quoted 7 lines
Quoted 2 lines
It would be faster to move the MMU model checks to translation time.
The problem is that we don't know which -cpu the user will give us when we run qemu-system-ppc64.
Of course we could just make qemu-system-ppc64 not take any non-64 bit CPUs, if nobody totally disagrees.
Quoted 6 lines
env could contain a pointer to (static const) structure describing the CPU features. This pointer would be copied to corresponding DisasContext feature pointer, to be used by the translation functions.
See for example target-sparc:
translate.c(CHECK_IU_FEATUREmacro) andhelper.cfor CPU definitions. IIRC MIPS or ARM have even nicer macros.
Right, as soon as I have Linux actually running and spare time to look at this, that's a pretty neat optimization :-). Honestly, for now speed isn't my main concern.
Alex
[Qemu-devel] Re: [PATCH 1/3] PPC: Circumvent overflow in mtcrf
In reply to Alexander GrafQuoted 6 lines · Alexander Graf
I had a segmentation fault in mtcrf, where
ffs()returned 8 and the
code then accessed cpu_crf[7 - 8].In order to circumvent this, I just put in an & 7 to the ffs result, so we'll never run negative. This is probably not correct, but makes things work for me so far.
ffs does not return bit number (in power of 2 numbering), but one if the zeroth bit is set, two if the first bit is set etc. So I'd try instead
crn = ffs(crm) - 1;
Re: [Qemu-devel] [PATCH 1/3] PPC: Circumvent overflow in mtcrf
In reply to Alexander GrafQuoted 17 lines · Alexander Graf
I had a segmentation fault in mtcrf, where
ffs()returned 8 and the code then accessed cpu_crf[7 - 8].In order to circumvent this, I just put in an & 7 to the ffs result, so we'll never run negative. This is probably not correct, but makes things work for me so far.
Signed-off-by Alexander Graf <[email protected]>--- target-ppc/translate.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)target-ppc/translate.c +0
-0
target-ppc/translate.c GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC) · line 3943
Quoted 8 lines
target-ppc/translate.c +1
-1@@ -3937,7 +3937,7 @@ GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC) crm =CRM (ctx->opcode);if (likely ((ctx->opcode &0x00100000 ) || (crm ^ (crm -1 )) ==0 )) {TCGv_i32 temp =tcg_temp_new_i32 (); - crn =ffs (crm); + crn =ffs (crm) &7 ;tcg_gen_trunc_tl_i32 (temp, cpu_gpr[rS (ctx->opcode)]);tcg_gen_shri_i32 (cpu_crf[7 - crn], temp, crn *4 );tcg_gen_andi_i32 (cpu_crf[7 - crn], cpu_crf[7 - crn],0xf );
I think the problem lies in the if; could you try this?
if (likely((ctx->opcode & 0x00100000))
if (crm ^ (crm - 1)) == 0) {
TCGv_i32 temp = tcg_temp_new_i32();
crn = ffs(crm);
tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4);
tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf);
tcg_temp_free_i32(temp);
}
} else {The Power spec says mtocrf is undefined if crm has not exactly one bit set. The patch above will just make it a nop (and will also generate code for mtcrf when it should instead of wrongly generating buggy code for mtocrf when crm is a power of 2 no matter what bit 20 [or bit 11 in dumb reversed bit numbering scheme of Power] is).
Laurent
Re: [Qemu-devel] [PATCH 1/3] PPC: Circumvent overflow in mtcrf
Quoted 42 lines · Laurent Desnogues
Quoted 25 lines · Alexander Graf
I had a segmentation fault in mtcrf, where
ffs()returned 8 and the code then accessed cpu_crf[7 - 8].In order to circumvent this, I just put in an & 7 to the ffs result, so we'll never run negative. This is probably not correct, but makes things work for me so far.
Signed-off-by Alexander Graf <[email protected]>---
target-ppc/translate.c| 2 +-1 files changed, 1 insertions(+), 1 deletions(-)target-ppc/translate.c +1
-1@@ -3937,7 +3937,7 @@ GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC) crm =CRM (ctx->opcode);if (likely ((ctx->opcode &0x00100000 ) || (crm ^ (crm -1 )) ==0 )) {TCGv_i32 temp =tcg_temp_new_i32 (); - crn =ffs (crm); + crn =ffs (crm) &7 ;tcg_gen_trunc_tl_i32 (temp, cpu_gpr[rS (ctx->opcode)]);Quoted 2 lines
tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4); tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf);I think the problem lies in the if; could you try this?
if (likely((ctx->opcode & 0x00100000)) if (crm ^ (crm - 1)) == 0) { TCGv_i32 temp = tcg_temp_new_i32(); crn = ffs(crm); tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]); tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4); tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf); tcg_temp_free_i32(temp); } } else {
Quoted 6 lines
The Power spec says mtocrf is undefined if crm has not exactly one bit set. The patch above will just make it a nop (and will also generate code for mtcrf when it should instead of wrongly generating buggy code for mtocrf when crm is a power of 2 no matter what bit 20 [or bit 11 in dumb reversed bit numbering scheme of Power] is).
I think malc fixed that one just before you hit the send button :-).
I've been running over other incorrectnesses while trying to get Linux working (now unpacks the initrd and panics in pmz init). Do you have a good link to the current isa so I can check which bits should be what?
Alex
Re: [Qemu-devel] [PATCH 1/3] PPC: Circumvent overflow in mtcrf
Quoted 1 line · Alexander Graf
I think malc fixed that one just before you hit the send button :-).
He did :-)
Quoted 3 lines
I've been running over other incorrectnesses while trying to get Linux working (now unpacks the initrd and panics in pmz init). Do you have a good link to the current isa so I can check which bits should be what?
Look here:
http://www.power.org/resources/downloads/
And remember the odd bit numbering scheme...
Laurent