MicroBlaze queue
cover MicroBlaze queue
From: "Edgar E. Iglesias" <[email protected]>
Hi,
These are various MicroBlaze patches sitting in my queue.
A few optimizations, sysemu initrd boot loading support and improvement to the exclusive load/store for system emulation.
Cheers,
Edgar
Edgar E. Iglesias (10):
microblaze: Clarify expected input of write_carry
microblaze: Make write_carryi input a boolean
microblaze: Simplify andn by using tcg_gen_andc
microblaze: Improve srl
microblaze: Improve src
microblaze: Move the saving of the reservation addr into gen_load
microblaze: Turn res_addr into a tcg global
microblaze: At swx, check that the reserved word is unmodified hw/microblaze: Indentation cleanups
hw/microblaze: Add support for loading initrd images
hw/microblaze/boot.c | 50 +++++++++++++++++--- hw/microblaze/boot.h | 4 +- hw/microblaze/petalogix_ml605_mmu.c | 6 ++- hw/microblaze/petalogix_s3adsp1800_mmu.c | 4 +- target-microblaze/cpu.h | 1 + target-microblaze/translate.c | 75 +++++++++++++++++------------- 6 files changed, 98 insertions(+), 42 deletions(-)
Signature · 1 line
1.7.10.4
PATCH 1/10 microblaze: Clarify expected input of write_carry
From: "Edgar E. Iglesias" <[email protected]>
--- target-microblaze/translate.c | 4 ++++ 1 file changed, 4 insertions(+)
target-microblaze/translate.c +4 -0
@@ -150,6 +150,10 @@ static void read_carry(DisasContext *dc, TCGv d)tcg_gen_shri_tl (d, cpu_SR[SR_MSR ],31 ); } +/* +* write_carry sets the carry bits in MSR based on bit 0 of v. +* v[31:1] are ignored. +*/ static void write_carry (DisasContext *dc,TCGv v) {TCGv t0 =tcg_temp_new ();
Signature · 1 line
1.7.10.4
PATCH 2/10 microblaze: Make write_carryi input a boolean
In reply to [email protected]From: "Edgar E. Iglesias" <[email protected]>
--- target-microblaze/translate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target-microblaze/translate.c +2 -2
@@ -166,10 +166,10 @@ static void write_carry(DisasContext *dc, TCGv v)tcg_temp_free (t0); } -static void write_carryi (DisasContext *dc,int carry) +static void write_carryi (DisasContext *dc,bool carry) {TCGv t0 =tcg_temp_new (); -tcg_gen_movi_tl (t0, carry ?1 :0 ); +tcg_gen_movi_tl (t0, carry);write_carry (dc, t0);tcg_temp_free (t0); }
Signature · 1 line
1.7.10.4
PATCH 3/10 microblaze: Simplify andn by using tcg_gen_andc
In reply to [email protected]From: "Edgar E. Iglesias" <[email protected]>
--- target-microblaze/translate.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
target-microblaze/translate.c +1 -4
@@ -390,10 +390,7 @@ static void dec_and(DisasContext *dc)return ;if (not) { -TCGv t =tcg_temp_new (); -tcg_gen_not_tl (t, *(dec_alu_op_b (dc))); -tcg_gen_and_tl (cpu_R[dc->rd], cpu_R[dc->ra], t); -tcg_temp_free (t); +tcg_gen_andc_tl (cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b (dc))); }else tcg_gen_and_tl (cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b (dc))); }
Signature · 1 line
1.7.10.4
PATCH 4/10 microblaze: Improve srl
In reply to [email protected]From: "Edgar E. Iglesias" <[email protected]>
write_carry only looks at bit zero, no need to mask out the others.
Meassured a 12% speed improvement in linux-user srl loops.
--- target-microblaze/translate.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
target-microblaze/translate.c +2 -5
@@ -780,13 +780,10 @@ static void dec_bit(DisasContext *dc)case 0x1 :case 0x41 :/* srl. */ - t0 =tcg_temp_new ();LOG_DIS ("srl r%d r%d\n" , dc->rd, dc->ra); -/* Update carry. */ -tcg_gen_andi_tl (t0, cpu_R[dc->ra],1 ); -write_carry (dc, t0); -tcg_temp_free (t0); +/* Update carry. Note that write carry only looks at the LSB. */ +write_carry (dc, cpu_R[dc->ra]);if (dc->rd) {if (op ==0x41 )tcg_gen_shri_tl (cpu_R[dc->rd], cpu_R[dc->ra],1 );
Signature · 1 line
1.7.10.4
PATCH 5/10 microblaze: Improve src
In reply to [email protected]From: "Edgar E. Iglesias" <[email protected]>
Microblaze carry is mirrored in MSR[31], pick it directly from there. Also, no need to mask cpu_R[dc->ra] when calling write_carry.
15% improvement in linux-user src loops.
--- target-microblaze/translate.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
target-microblaze/translate.c +4 -11
@@ -750,7 +750,7 @@ static void dec_barrel(DisasContext *dc)static void dec_bit (DisasContext *dc) { -TCGv t0, t1; +TCGv t0;unsigned int op;int mem_index =cpu_mmu_index (dc->env);
@@ -761,19 +761,12 @@ static void dec_bit(DisasContext *dc) t0 =tcg_temp_new ();LOG_DIS ("src r%d r%d\n" , dc->rd, dc->ra); -tcg_gen_andi_tl (t0, cpu_R[dc->ra],1 ); +tcg_gen_andi_tl (t0, cpu_SR[SR_MSR ],MSR_CC ); +write_carry (dc, cpu_R[dc->ra]);if (dc->rd) { - t1 =tcg_temp_new (); -read_carry (dc, t1); -tcg_gen_shli_tl (t1, t1,31 ); -tcg_gen_shri_tl (cpu_R[dc->rd], cpu_R[dc->ra],1 ); -tcg_gen_or_tl (cpu_R[dc->rd], cpu_R[dc->rd], t1); -tcg_temp_free (t1); +tcg_gen_or_tl (cpu_R[dc->rd], cpu_R[dc->rd], t0); } - -/* Update carry. */ -write_carry (dc, t0);tcg_temp_free (t0);break ;
Signature · 1 line
1.7.10.4
PATCH 6/10 microblaze: Move the saving of the reservation addr into gen_load
In reply to [email protected]From: "Edgar E. Iglesias" <[email protected]>
No functional change.
--- target-microblaze/translate.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
target-microblaze/translate.c +8 -5
@@ -863,7 +863,7 @@ static void dec_imm(DisasContext *dc) }static inline void gen_load (DisasContext *dc,TCGv dst,TCGv addr, -unsigned int size) +unsigned int size,bool exclusive) {int mem_index =cpu_mmu_index (dc->env);
@@ -875,6 +875,10 @@ static inline void gen_load(DisasContext *dc, TCGv dst, TCGv addr,tcg_gen_qemu_ld32u (dst, addr, mem_index); }else cpu_abort (dc->env,"Incorrect load size %d\n" , size); + +if (exclusive) { +tcg_gen_st_tl (addr, cpu_env, offsetof(CPUMBState , res_addr)); + } }static inline TCGv *compute_ldst_addr (DisasContext *dc,TCGv *t)
@@ -1046,7 +1050,7 @@ static void dec_load(DisasContext *dc)* into v. If the load succeeds, we verify alignment of the * address and if that succeeds we write into the destination reg. */ -gen_load (dc, v, *addr, size); +gen_load (dc, v, *addr, size, ex);tcg_gen_movi_tl (cpu_SR[SR_PC ], dc->pc); gen_helper_memalign(cpu_env, *addr, tcg_const_tl(dc->rd),
@@ -1061,20 +1065,19 @@ static void dec_load(DisasContext *dc)tcg_temp_free (v); }else {if (dc->rd) { -gen_load (dc, cpu_R[dc->rd], *addr, size); +gen_load (dc, cpu_R[dc->rd], *addr, size, ex);if (rev) {dec_byteswap (dc, cpu_R[dc->rd], cpu_R[dc->rd], size); } }else {/* We are loading into r0, no need to reverse. */ -gen_load (dc, env_imm, *addr, size); +gen_load (dc, env_imm, *addr, size, ex); } }if (ex) {/* lwx */ /* no support for for AXI exclusive so always clear C */ write_carryi (dc,0 ); -tcg_gen_st_tl (*addr, cpu_env, offsetof(CPUMBState , res_addr)); }if (addr == &t)
Signature · 1 line
1.7.10.4
PATCH 7/10 microblaze: Turn res_addr into a tcg global
In reply to [email protected]From: "Edgar E. Iglesias" <[email protected]>
--- target-microblaze/translate.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
target-microblaze/translate.c +7 -6
@@ -49,6 +49,7 @@ static TCGv env_imm;static TCGv env_btaken;static TCGv env_btarget;static TCGv env_iflags; +static TCGv env_res_addr;#include "exec/gen-icount.h"
@@ -877,7 +878,7 @@ static inline void gen_load(DisasContext *dc, TCGv dst, TCGv addr,cpu_abort (dc->env,"Incorrect load size %d\n" , size);if (exclusive) { -tcg_gen_st_tl (addr, cpu_env, offsetof(CPUMBState , res_addr)); +tcg_gen_mov_tl (env_res_addr, addr); } }
@@ -1101,7 +1102,7 @@ static void gen_store(DisasContext *dc, TCGv addr, TCGv val,static void dec_store (DisasContext *dc) { -TCGv t, *addr, swx_addr, r_check; +TCGv t, *addr, swx_addr;int swx_skip =0 ;unsigned int size, rev =0 , ex =0 ;
@@ -1125,7 +1126,6 @@ static void dec_store(DisasContext *dc)sync_jmpstate (dc); addr =compute_ldst_addr (dc, &t); - r_check =tcg_temp_new (); swx_addr =tcg_temp_local_new ();if (ex) {/* swx */
@@ -1135,10 +1135,9 @@ static void dec_store(DisasContext *dc)/* swx does not throw unaligned access errors, so force alignment */ tcg_gen_andi_tl (swx_addr, swx_addr, ~3 ); -tcg_gen_ld_tl (r_check, cpu_env, offsetof(CPUMBState , res_addr));write_carryi (dc,1 ); swx_skip =gen_new_label (); -tcg_gen_brcond_tl (TCG_COND_NE , r_check, swx_addr, swx_skip); +tcg_gen_brcond_tl (TCG_COND_NE , env_res_addr, swx_addr, swx_skip);write_carryi (dc,0 ); }
@@ -1221,7 +1220,6 @@ static void dec_store(DisasContext *dc)if (ex) {gen_set_label (swx_skip); } -tcg_temp_free (r_check);tcg_temp_free (swx_addr);if (addr == &t)
@@ -2008,6 +2006,9 @@ void mb_tcg_init(void) env_btaken =tcg_global_mem_new (TCG_AREG0 , offsetof(CPUMBState , btaken),"btaken" ); + env_res_addr =tcg_global_mem_new (TCG_AREG0 , + offsetof(CPUMBState , res_addr), +"res_addr" );for (i =0 ; i <ARRAY_SIZE (cpu_R); i++) { cpu_R[i] =tcg_global_mem_new (TCG_AREG0 , offsetof(CPUMBState, regs[i]),
Signature · 1 line
1.7.10.4
PATCH 8/10 microblaze: At swx, check that the reserved word is unmodified
In reply to [email protected]From: "Edgar E. Iglesias" <[email protected]>
This improves the reservation check for system emulation, making it possible to catch stores that modify reserved word.
--- target-microblaze/cpu.h | 1 + target-microblaze/translate.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+)
target-microblaze/cpu.h +1 -0
@@ -246,6 +246,7 @@ struct CPUMBState {/* lwx/swx reserved address */ #define RES_ADDR_NONE 0xffffffff/* Use 0xffffffff to indicate no reservation */ uint32_t res_addr; +uint32_t res_val;/* Internal flags. */ #define IMM_FLAG 4
target-microblaze/translate.c +16 -0
@@ -50,6 +50,7 @@ static TCGv env_btaken;static TCGv env_btarget;static TCGv env_iflags;static TCGv env_res_addr; +static TCGv env_res_val;#include "exec/gen-icount.h"
@@ -879,6 +880,7 @@ static inline void gen_load(DisasContext *dc, TCGv dst, TCGv addr,if (exclusive) {tcg_gen_mov_tl (env_res_addr, addr); +tcg_gen_mov_tl (env_res_val, dst); } }
@@ -1128,6 +1130,7 @@ static void dec_store(DisasContext *dc) swx_addr =tcg_temp_local_new ();if (ex) {/* swx */ +TCGv tval;/* Force addr into the swx_addr. */ tcg_gen_mov_tl (swx_addr, *addr);
@@ -1138,7 +1141,17 @@ static void dec_store(DisasContext *dc)write_carryi (dc,1 ); swx_skip =gen_new_label ();tcg_gen_brcond_tl (TCG_COND_NE , env_res_addr, swx_addr, swx_skip); + +/* Compare the value loaded at lwx with current contents of +the reserved location. +FIXME: This only works for system emulation where we can expect +this compare and the following write to be atomic. For user +emulation we need to add atomicity between threads. */ + tval =tcg_temp_new (); +gen_load (dc, tval, swx_addr,4 , false); +tcg_gen_brcond_tl (TCG_COND_NE , env_res_val, tval, swx_skip);write_carryi (dc,0 ); +tcg_temp_free (tval); }if (rev && size !=4 ) {
@@ -2009,6 +2022,9 @@ void mb_tcg_init(void) env_res_addr =tcg_global_mem_new (TCG_AREG0 , offsetof(CPUMBState , res_addr),"res_addr" ); + env_res_val =tcg_global_mem_new (TCG_AREG0 , + offsetof(CPUMBState , res_val), +"res_val" );for (i =0 ; i <ARRAY_SIZE (cpu_R); i++) { cpu_R[i] =tcg_global_mem_new (TCG_AREG0 , offsetof(CPUMBState, regs[i]),
Signature · 1 line
1.7.10.4
PATCH 9/10 hw/microblaze: Indentation cleanups
In reply to [email protected]From: "Edgar E. Iglesias" <[email protected]>
--- hw/microblaze/boot.c | 11 ++++++----- hw/microblaze/petalogix_ml605_mmu.c | 5 +++-- hw/microblaze/petalogix_s3adsp1800_mmu.c | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-)
hw/microblaze/boot.c +6 -5
@@ -57,9 +57,9 @@ static void main_cpu_reset(void *opaque) }static int microblaze_load_dtb (hwaddr addr, -uint32_t ramsize, -const char *kernel_cmdline, -const char *dtb_filename) +uint32_t ramsize, +const char *kernel_cmdline, +const char *dtb_filename) {int fdt_size;void *fdt =NULL ;
@@ -157,8 +157,9 @@ void microblaze_load_kernel(MicroBlazeCPU *cpu, hwaddr ddr_base, }/* Provide a device-tree. */ boot_info.fdt = boot_info.cmdline +4096 ; -microblaze_load_dtb (boot_info.fdt, ram_size, kernel_cmdline, - dtb_filename); +microblaze_load_dtb (boot_info.fdt, ram_size, + kernel_cmdline, + dtb_filename); } }
hw/microblaze/petalogix_ml605_mmu.c +3 -2
@@ -176,8 +176,9 @@ petalogix_ml605_init(QEMUMachineInitArgs *args) } } -microblaze_load_kernel (cpu, ddr_base, ram_size,BINARY_DEVICE_TREE_FILE , - machine_cpu_reset); +microblaze_load_kernel (cpu, ddr_base, ram_size, +BINARY_DEVICE_TREE_FILE , + machine_cpu_reset); }
hw/microblaze/petalogix_s3adsp1800_mmu.c +1 -1
@@ -108,7 +108,7 @@ petalogix_s3adsp1800_init(QEMUMachineInitArgs *args)xilinx_ethlite_create (&nd_table[0 ],ETHLITE_BASEADDR , irq[1 ],0 ,0 );microblaze_load_kernel (cpu, ddr_base, ram_size, -BINARY_DEVICE_TREE_FILE , machine_cpu_reset); +BINARY_DEVICE_TREE_FILE , machine_cpu_reset); }static QEMUMachine petalogix_s3adsp1800_machine = {
Signature · 1 line
1.7.10.4
PATCH 10/10 hw/microblaze: Add support for loading initrd images
In reply to [email protected]From: "Edgar E. Iglesias" <[email protected]>
--- hw/microblaze/boot.c | 39 +++++++++++++++++++++++++++++- hw/microblaze/boot.h | 4 ++- hw/microblaze/petalogix_ml605_mmu.c | 1 + hw/microblaze/petalogix_s3adsp1800_mmu.c | 4 ++- 4 files changed, 45 insertions(+), 3 deletions(-)
hw/microblaze/boot.c +38 -1
@@ -26,6 +26,7 @@#include "qemu/option.h" #include "qemu/config-file.h" +#include "qemu/error-report.h" #include "qemu-common.h" #include "sysemu/device_tree.h" #include "sysemu/sysemu.h"
@@ -39,6 +40,8 @@ static structvoid (*machine_cpu_reset)(MicroBlazeCPU *);uint32_t bootstrap_pc;uint32_t cmdline; +uint32_t initrd_start; +uint32_t initrd_end;uint32_t fdt; } boot_info;
@@ -49,6 +52,7 @@ static void main_cpu_reset(void *opaque)cpu_reset (CPU (cpu)); env->regs[5 ] = boot_info.cmdline; + env->regs[6 ] = boot_info.initrd_start; env->regs[7 ] = boot_info.fdt; env->sregs[SR_PC ] = boot_info.bootstrap_pc;if (boot_info.machine_cpu_reset) {
@@ -58,6 +62,8 @@ static void main_cpu_reset(void *opaque)static int microblaze_load_dtb (hwaddr addr,uint32_t ramsize, +uint32_t initrd_start, +uint32_t initrd_end,const char *kernel_cmdline,const char *dtb_filename) {
@@ -80,6 +86,14 @@ static int microblaze_load_dtb(hwaddr addr, } } +if (initrd_start) { +qemu_devtree_setprop_cell (fdt,"/chosen" ,"linux,initrd-start" , + initrd_start); + +qemu_devtree_setprop_cell (fdt,"/chosen" ,"linux,initrd-end" , + initrd_end); + } +cpu_physical_memory_write (addr, fdt, fdt_size);return fdt_size; }
@@ -90,7 +104,9 @@ static uint64_t translate_kernel_address(void *opaque, uint64_t addr) }void microblaze_load_kernel (MicroBlazeCPU *cpu,hwaddr ddr_base, -uint32_t ramsize,const char *dtb_filename, +uint32_t ramsize, +const char *initrd_filename, +const char *dtb_filename,void (*machine_cpu_reset)(MicroBlazeCPU *)) {QemuOpts *machine_opts;
@@ -151,6 +167,25 @@ void microblaze_load_kernel(MicroBlazeCPU *cpu, hwaddr ddr_base, high = (ddr_base + kernel_size +3 ) & ~3 ; } +if (initrd_filename) { +int initrd_size; +uint32_t initrd_offset; + + high =ROUND_UP (high + kernel_size,4 ); + boot_info.initrd_start = high; + initrd_offset = boot_info.initrd_start - ddr_base; + initrd_size =load_image_targphys (initrd_filename, + boot_info.initrd_start, + ram_size - initrd_offset); +if (initrd_size <0 ) { +error_report ("qemu: could not load initrd '%s'\n" , + initrd_filename); +exit (EXIT_FAILURE ); + } + boot_info.initrd_end = boot_info.initrd_start + initrd_size; + high =ROUND_UP (high + initrd_size,4 ); + } + boot_info.cmdline = high +4096 ;if (kernel_cmdline &&strlen (kernel_cmdline)) {pstrcpy_targphys ("cmdline" , boot_info.cmdline,256 , kernel_cmdline);
@@ -158,6 +193,8 @@ void microblaze_load_kernel(MicroBlazeCPU *cpu, hwaddr ddr_base,/* Provide a device-tree. */ boot_info.fdt = boot_info.cmdline +4096 ;microblaze_load_dtb (boot_info.fdt, ram_size, + boot_info.initrd_start, + boot_info.initrd_end, kernel_cmdline, dtb_filename); }
hw/microblaze/boot.h +3 -1
@@ -4,7 +4,9 @@#include "hw/hw.h" void microblaze_load_kernel (MicroBlazeCPU *cpu,hwaddr ddr_base, -uint32_t ramsize,const char *dtb_filename, +uint32_t ramsize, +const char *initrd_filename, +const char *dtb_filename,void (*machine_cpu_reset)(MicroBlazeCPU *));#endif /* __MICROBLAZE_BOOT __ */
hw/microblaze/petalogix_ml605_mmu.c +1 -0
@@ -177,6 +177,7 @@ petalogix_ml605_init(QEMUMachineInitArgs *args) }microblaze_load_kernel (cpu, ddr_base, ram_size, + args->initrd_filename,BINARY_DEVICE_TREE_FILE , machine_cpu_reset);
hw/microblaze/petalogix_s3adsp1800_mmu.c +3 -1
@@ -108,7 +108,9 @@ petalogix_s3adsp1800_init(QEMUMachineInitArgs *args)xilinx_ethlite_create (&nd_table[0 ],ETHLITE_BASEADDR , irq[1 ],0 ,0 );microblaze_load_kernel (cpu, ddr_base, ram_size, -BINARY_DEVICE_TREE_FILE , machine_cpu_reset); + args->initrd_filename, +BINARY_DEVICE_TREE_FILE , + machine_cpu_reset); }static QEMUMachine petalogix_s3adsp1800_machine = {
Signature · 1 line
1.7.10.4