RISC-V: Start to remove xlen preprocess
Subsystems (2)
v4 cover RISC-V: Start to remove xlen preprocess
The RISC-V QEMU port currently has lot of preprocessor directives that check if we are targetting a 32-bit or 64-bit CPU. This means that the 64-bit RISC-V target can not run 32-bit CPUs. This is different to most other QEMU architectures and doesn't allow us to mix xlens (such as when running Hypervisors with different xlen guests).
This series is a step toward removing some of those to allow us to use 32-bit CPUs on 64-bit RISC-V targets.
v4:
- Add a commit that converts the machine 32-bit check to use the CPU
v3:
- Address Richard's comments
v2:
- Rebase on the latest RISC-V tree
Alistair Francis (16):
hw/riscv: Expand the is 32-bit check to support more CPUs target/riscv: Add a TYPE_RISCV_CPU_BASE CPU
riscv: spike: Remove target macro conditionals
riscv: virt: Remove target macro conditionals hw/riscv: boot: Remove compile time XLEN checks hw/riscv: virt: Remove compile time XLEN checks hw/riscv: spike: Remove compile time XLEN checks hw/riscv: sifive_u: Remove compile time XLEN checks target/riscv: fpu_helper: Match function defs in HELPER macros target/riscv: Add a riscv_cpu_is_32bit() helper function target/riscv: Specify the XLEN for CPUs target/riscv: cpu: Remove compile time XLEN checks target/riscv: cpu_helper: Remove compile time XLEN checks target/riscv: csr: Remove compile time XLEN checks target/riscv: cpu: Set XLEN independently from target hw/riscv: Use the CPU to determine if 32-bit
include/hw/riscv/boot.h | 14 +-- include/hw/riscv/spike.h | 6 -- include/hw/riscv/virt.h | 6 -- target/riscv/cpu.h | 8 ++ target/riscv/cpu_bits.h | 4 +- target/riscv/helper.h | 24 ++---- hw/riscv/boot.c | 70 ++++++++------- hw/riscv/sifive_u.c | 59 +++++++------ hw/riscv/spike.c | 52 +++++------ hw/riscv/virt.c | 39 +++++---- target/riscv/cpu.c | 84 ++++++++++++------ target/riscv/cpu_helper.c | 12 +-- target/riscv/csr.c | 176 ++++++++++++++++++++------------------ target/riscv/fpu_helper.c | 8 -- 14 files changed, 299 insertions(+), 263 deletions(-)
Signature · 1 line
2.29.2
PATCH v4 1/16 hw/riscv: Expand the is 32-bit check to support more CPUs
Currently the riscv_is_32_bit() function only supports the generic rv32 CPUs. Extend the function to support the SiFive and LowRISC CPUs as well.
--- hw/riscv/boot.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
hw/riscv/boot.c +11 -1
@@ -41,7 +41,17 @@bool riscv_is_32_bit (MachineState *machine) { -if (!strncmp (machine->cpu_type,"rv32" ,4 )) { +/* +* To determine if the CPU is 32-bit we need to check a few different CPUs. +* +* If the CPU starts with rv32 +* If the CPU is a sifive 3 seriries CPU (E31, U34) +* If it's the Ibex CPU +*/ +if (!strncmp (machine->cpu_type,"rv32" ,4 ) || + (!strncmp (machine->cpu_type,"sifive" ,6 ) && + machine->cpu_type[8 ] =='3' ) || + !strncmp (machine->cpu_type,"lowrisc-ibex" ,12 )) {return true; }else {return false;
Signature · 1 line
2.29.2
PATCH v4 2/16 target/riscv: Add a TYPE_RISCV_CPU_BASE CPU
In reply to Alistair Francis--- target/riscv/cpu.h | 6 ++++++ 1 file changed, 6 insertions(+)
target/riscv/cpu.h +6 -0
@@ -44,6 +44,12 @@#define TYPE_RISCV_CPU_SIFIVE_U34 RISCV_CPU_TYPE_NAME("sifive-u34")#define TYPE_RISCV_CPU_SIFIVE_U54 RISCV_CPU_TYPE_NAME("sifive-u54") +#if defined(TARGET_RISCV32 ) +# define TYPE_RISCV_CPU_BASE TYPE_RISCV_CPU_BASE32 +#elif defined(TARGET_RISCV64 ) +# define TYPE_RISCV_CPU_BASE TYPE_RISCV_CPU_BASE64 +#endif +#define RV32 ((target_ulong)1 << (TARGET_LONG_BITS - 2))#define RV64 ((target_ulong)2 << (TARGET_LONG_BITS - 2))
Signature · 1 line
2.29.2
PATCH v4 3/16 riscv: spike: Remove target macro conditionals
In reply to Alistair Francis--- include/hw/riscv/spike.h | 6 ------ hw/riscv/spike.c | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-)
include/hw/riscv/spike.h +0 -6
@@ -47,10 +47,4 @@ enum {SPIKE_DRAM }; -#if defined(TARGET_RISCV32 ) -#define SPIKE_V1_10_0_CPU TYPE_RISCV_CPU_BASE32 -#elif defined(TARGET_RISCV64 ) -#define SPIKE_V1_10_0_CPU TYPE_RISCV_CPU_BASE64 -#endif -#endif
hw/riscv/spike.c +1 -1
@@ -317,7 +317,7 @@ static void spike_machine_class_init(ObjectClass *oc, void *data) mc->init = spike_board_init; mc->max_cpus =SPIKE_CPUS_MAX ; mc->is_default = true; - mc->default_cpu_type =SPIKE_V1_10_0_CPU ; + mc->default_cpu_type =TYPE_RISCV_CPU_BASE ; mc->possible_cpu_arch_ids = riscv_numa_possible_cpu_arch_ids; mc->cpu_index_to_instance_props = riscv_numa_cpu_index_to_props; mc->get_default_cpu_node_id = riscv_numa_get_default_cpu_node_id;
Signature · 1 line
2.29.2
PATCH v4 4/16 riscv: virt: Remove target macro conditionals
In reply to Alistair Francis--- include/hw/riscv/virt.h | 6 ------ hw/riscv/virt.c | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-)
include/hw/riscv/virt.h +0 -6
@@ -89,10 +89,4 @@ enum {#define FDT_INT_MAP_WIDTH (FDT_PCI_ADDR_CELLS + FDT_PCI_INT_CELLS + 1 + \ FDT_PLIC_ADDR_CELLS + FDT_PLIC_INT_CELLS) -#if defined(TARGET_RISCV32 ) -#define VIRT_CPU TYPE_RISCV_CPU_BASE32 -#elif defined(TARGET_RISCV64 ) -#define VIRT_CPU TYPE_RISCV_CPU_BASE64 -#endif -#endif
hw/riscv/virt.c +1 -1
@@ -706,7 +706,7 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) mc->desc ="RISC-V VirtIO board" ; mc->init = virt_machine_init; mc->max_cpus =VIRT_CPUS_MAX ; - mc->default_cpu_type =VIRT_CPU ; + mc->default_cpu_type =TYPE_RISCV_CPU_BASE ; mc->pci_allow_0_address = true; mc->possible_cpu_arch_ids = riscv_numa_possible_cpu_arch_ids; mc->cpu_index_to_instance_props = riscv_numa_cpu_index_to_props;
Signature · 1 line
2.29.2
PATCH v4 5/16 hw/riscv: boot: Remove compile time XLEN checks
In reply to Alistair Francis--- include/hw/riscv/boot.h | 8 +++--- hw/riscv/boot.c | 55 ++++++++++++++++++++++------------------- hw/riscv/sifive_u.c | 2 +- hw/riscv/spike.c | 3 ++- hw/riscv/virt.c | 2 +- 5 files changed, 39 insertions(+), 31 deletions(-)
include/hw/riscv/boot.h +5 -3
@@ -41,10 +41,12 @@ target_ulong riscv_load_kernel(const char *kernel_filename,hwaddr riscv_load_initrd (const char *filename,uint64_t mem_size,uint64_t kernel_entry,hwaddr *start);uint32_t riscv_load_fdt (hwaddr dram_start,uint64_t dram_size,void *fdt); -void riscv_setup_rom_reset_vec (hwaddr saddr,hwaddr rom_base, -hwaddr rom_size,uint64_t kernel_entry, +void riscv_setup_rom_reset_vec (MachineState *machine,hwaddr saddr, +hwaddr rom_base,hwaddr rom_size, +uint64_t kernel_entry,uint32_t fdt_load_addr,void *fdt); -void riscv_rom_copy_firmware_info (hwaddr rom_base,hwaddr rom_size, +void riscv_rom_copy_firmware_info (MachineState *machine,hwaddr rom_base, +hwaddr rom_size,uint32_t reset_vec_size,uint64_t kernel_entry);
hw/riscv/boot.c +30 -25
99 lines not on this page · raw message
hw/riscv/sifive_u.c +1 -1
@@ -550,7 +550,7 @@ static void sifive_u_machine_init(MachineState *machine)rom_add_blob_fixed_as ("mrom.reset" , reset_vec,sizeof (reset_vec), memmap[SIFIVE_U_DEV_MROM ].base, &address_space_memory); -riscv_rom_copy_firmware_info (memmap[SIFIVE_U_DEV_MROM ].base, +riscv_rom_copy_firmware_info (machine, memmap[SIFIVE_U_DEV_MROM ].base, memmap[SIFIVE_U_DEV_MROM ].size,sizeof (reset_vec), kernel_entry); }
hw/riscv/spike.c +2 -1
@@ -296,7 +296,8 @@ static void spike_board_init(MachineState *machine) fdt_load_addr =riscv_load_fdt (memmap[SPIKE_DRAM ].base, machine->ram_size, s->fdt);/* load the reset vector */ -riscv_setup_rom_reset_vec (memmap[SPIKE_DRAM ].base, memmap[SPIKE_MROM ].base, +riscv_setup_rom_reset_vec (machine, memmap[SPIKE_DRAM ].base, + memmap[SPIKE_MROM ].base, memmap[SPIKE_MROM ].size, kernel_entry, fdt_load_addr, s->fdt);
hw/riscv/virt.c +1 -1
@@ -656,7 +656,7 @@ static void virt_machine_init(MachineState *machine) fdt_load_addr =riscv_load_fdt (memmap[VIRT_DRAM ].base, machine->ram_size, s->fdt);/* load the reset vector */ -riscv_setup_rom_reset_vec (start_addr, virt_memmap[VIRT_MROM ].base, +riscv_setup_rom_reset_vec (machine, start_addr, virt_memmap[VIRT_MROM ].base, virt_memmap[VIRT_MROM ].size, kernel_entry, fdt_load_addr, s->fdt);
Signature · 1 line
2.29.2
PATCH v4 6/16 hw/riscv: virt: Remove compile time XLEN checks
In reply to Alistair Francis--- hw/riscv/virt.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-)
hw/riscv/virt.c +17 -15
@@ -43,12 +43,6 @@#include "hw/pci/pci.h" #include "hw/pci-host/gpex.h" -#if defined(TARGET_RISCV32 ) -# define BIOS_FILENAME "opensbi-riscv32-generic-fw_dynamic.bin" -#else -# define BIOS_FILENAME "opensbi-riscv64-generic-fw_dynamic.bin" -#endif - static const struct MemmapEntry { hwaddr base; hwaddr size;
@@ -177,7 +171,7 @@ static void create_pcie_irq_map(void *fdt, char *nodename, }static void create_fdt (RISCVVirtState *s,const struct MemmapEntry *memmap, -uint64_t mem_size,const char *cmdline) +uint64_t mem_size,const char *cmdline,bool is_32_bit) {void *fdt;int i, cpu, socket;
@@ -242,11 +236,11 @@ static void create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap, cpu_name =g_strdup_printf ("/cpus/cpu@%d" , s->soc[socket].hartid_base + cpu);qemu_fdt_add_subnode (fdt, cpu_name); -#if defined(TARGET_RISCV32 ) -qemu_fdt_setprop_string (fdt, cpu_name,"mmu-type" ,"riscv,sv32" ); -#else -qemu_fdt_setprop_string (fdt, cpu_name,"mmu-type" ,"riscv,sv48" ); -#endif +if (is_32_bit) { +qemu_fdt_setprop_string (fdt, cpu_name,"mmu-type" ,"riscv,sv32" ); + }else { +qemu_fdt_setprop_string (fdt, cpu_name,"mmu-type" ,"riscv,sv48" ); + } name =riscv_isa_string (&s->soc[socket].harts[cpu]);qemu_fdt_setprop_string (fdt, cpu_name,"riscv,isa" , name);g_free (name);
@@ -608,7 +602,8 @@ static void virt_machine_init(MachineState *machine) main_mem);/* create device tree */ -create_fdt (s, memmap, machine->ram_size, machine->kernel_cmdline); +create_fdt (s, memmap, machine->ram_size, machine->kernel_cmdline, +riscv_is_32_bit (machine));/* boot rom */ memory_region_init_rom(mask_rom, NULL, "riscv_virt_board.mrom",
@@ -616,8 +611,15 @@ static void virt_machine_init(MachineState *machine)memory_region_add_subregion (system_memory, memmap[VIRT_MROM ].base, mask_rom); - firmware_end_addr =riscv_find_and_load_firmware (machine,BIOS_FILENAME , - start_addr,NULL ); +if (riscv_is_32_bit (machine)) { + firmware_end_addr =riscv_find_and_load_firmware (machine, +"opensbi-riscv32-generic-fw_dynamic.bin" , + start_addr,NULL ); + }else { + firmware_end_addr =riscv_find_and_load_firmware (machine, +"opensbi-riscv64-generic-fw_dynamic.bin" , + start_addr,NULL ); + }if (machine->kernel_filename) { kernel_start_addr = riscv_calc_kernel_start_addr(machine,
Signature · 1 line
2.29.2
PATCH v4 7/16 hw/riscv: spike: Remove compile time XLEN checks
In reply to Alistair Francis--- hw/riscv/spike.c | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-)
hw/riscv/spike.c +24 -21
@@ -43,17 +43,6 @@#include "sysemu/qtest.h" #include "sysemu/sysemu.h" -/* -* Not like other RISC-V machines that use plain binary bios images, -* keeping ELF files here was intentional because BIN files don't work -* for the Spike machine as HTIF emulation depends on ELF parsing. -*/ -#if defined(TARGET_RISCV32 ) -# define BIOS_FILENAME "opensbi-riscv32-generic-fw_dynamic.elf" -#else -# define BIOS_FILENAME "opensbi-riscv64-generic-fw_dynamic.elf" -#endif - static const struct MemmapEntry { hwaddr base; hwaddr size;
@@ -64,7 +53,7 @@ static const struct MemmapEntry { };static void create_fdt (SpikeState *s,const struct MemmapEntry *memmap, -uint64_t mem_size,const char *cmdline) +uint64_t mem_size,const char *cmdline,bool is_32_bit) {void *fdt;uint64_t addr, size;
@@ -115,11 +104,11 @@ static void create_fdt(SpikeState *s, const struct MemmapEntry *memmap, cpu_name =g_strdup_printf ("/cpus/cpu@%d" , s->soc[socket].hartid_base + cpu);qemu_fdt_add_subnode (fdt, cpu_name); -#if defined(TARGET_RISCV32 ) -qemu_fdt_setprop_string (fdt, cpu_name,"mmu-type" ,"riscv,sv32" ); -#else -qemu_fdt_setprop_string (fdt, cpu_name,"mmu-type" ,"riscv,sv48" ); -#endif +if (is_32_bit) { +qemu_fdt_setprop_string (fdt, cpu_name,"mmu-type" ,"riscv,sv32" ); + }else { +qemu_fdt_setprop_string (fdt, cpu_name,"mmu-type" ,"riscv,sv48" ); + } name =riscv_isa_string (&s->soc[socket].harts[cpu]);qemu_fdt_setprop_string (fdt, cpu_name,"riscv,isa" , name);g_free (name);
@@ -254,7 +243,8 @@ static void spike_board_init(MachineState *machine) main_mem);/* create device tree */ -create_fdt (s, memmap, machine->ram_size, machine->kernel_cmdline); +create_fdt (s, memmap, machine->ram_size, machine->kernel_cmdline, +riscv_is_32_bit (machine));/* boot rom */ memory_region_init_rom(mask_rom, NULL, "riscv.spike.mrom",
@@ -262,9 +252,22 @@ static void spike_board_init(MachineState *machine)memory_region_add_subregion (system_memory, memmap[SPIKE_MROM ].base, mask_rom); - firmware_end_addr =riscv_find_and_load_firmware (machine,BIOS_FILENAME , - memmap[SPIKE_DRAM ].base, - htif_symbol_callback); +/* +* Not like other RISC-V machines that use plain binary bios images, +* keeping ELF files here was intentional because BIN files don't work +* for the Spike machine as HTIF emulation depends on ELF parsing. +*/ +if (riscv_is_32_bit (machine)) { + firmware_end_addr =riscv_find_and_load_firmware (machine, +"opensbi-riscv32-generic-fw_dynamic.elf" , + memmap[SPIKE_DRAM ].base, + htif_symbol_callback); + }else { + firmware_end_addr =riscv_find_and_load_firmware (machine, +"opensbi-riscv64-generic-fw_dynamic.elf" , + memmap[SPIKE_DRAM ].base, + htif_symbol_callback); + }if (machine->kernel_filename) { kernel_start_addr = riscv_calc_kernel_start_addr(machine,
Signature · 1 line
2.29.2
PATCH v4 8/16 hw/riscv: sifive_u: Remove compile time XLEN checks
In reply to Alistair Francis--- hw/riscv/sifive_u.c | 55 ++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 25 deletions(-)
hw/riscv/sifive_u.c +30 -25
@@ -60,12 +60,6 @@#include <libfdt.h> -#if defined(TARGET_RISCV32 ) -# define BIOS_FILENAME "opensbi-riscv32-generic-fw_dynamic.bin" -#else -# define BIOS_FILENAME "opensbi-riscv64-generic-fw_dynamic.bin" -#endif - static const struct MemmapEntry { hwaddr base; hwaddr size;
@@ -93,7 +87,7 @@ static const struct MemmapEntry {#define GEM_REVISION 0x10070109static void create_fdt (SiFiveUState *s,const struct MemmapEntry *memmap, -uint64_t mem_size,const char *cmdline) +uint64_t mem_size,const char *cmdline,bool is_32_bit) {MachineState *ms =MACHINE (qdev_get_machine ());void *fdt;
@@ -178,11 +172,11 @@ static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap,qemu_fdt_add_subnode (fdt, nodename);/* cpu 0 is the management hart that does not have mmu */ if (cpu !=0 ) { -#if defined(TARGET_RISCV32 ) -qemu_fdt_setprop_string (fdt, nodename,"mmu-type" ,"riscv,sv32" ); -#else -qemu_fdt_setprop_string (fdt, nodename,"mmu-type" ,"riscv,sv48" ); -#endif +if (is_32_bit) { +qemu_fdt_setprop_string (fdt, nodename,"mmu-type" ,"riscv,sv32" ); + }else { +qemu_fdt_setprop_string (fdt, nodename,"mmu-type" ,"riscv,sv48" ); + } isa =riscv_isa_string (&s->soc.u_cpus.harts[cpu -1 ]); }else { isa =riscv_isa_string (&s->soc.e_cpus.harts[0 ]);
@@ -458,7 +452,8 @@ static void sifive_u_machine_init(MachineState *machine) qemu_allocate_irq(sifive_u_machine_reset, NULL, 0));/* create device tree */ -create_fdt (s, memmap, machine->ram_size, machine->kernel_cmdline); +create_fdt (s, memmap, machine->ram_size, machine->kernel_cmdline, +riscv_is_32_bit (machine));if (s->start_in_flash) {/*
@@ -487,8 +482,15 @@ static void sifive_u_machine_init(MachineState *machine)break ; } - firmware_end_addr =riscv_find_and_load_firmware (machine,BIOS_FILENAME , - start_addr,NULL ); +if (riscv_is_32_bit (machine)) { + firmware_end_addr =riscv_find_and_load_firmware (machine, +"opensbi-riscv32-generic-fw_dynamic.bin" , + start_addr,NULL ); + }else { + firmware_end_addr =riscv_find_and_load_firmware (machine, +"opensbi-riscv64-generic-fw_dynamic.bin" , + start_addr,NULL ); + }if (machine->kernel_filename) { kernel_start_addr = riscv_calc_kernel_start_addr(machine,
@@ -518,9 +520,9 @@ static void sifive_u_machine_init(MachineState *machine)/* Compute the fdt load address in dram */ fdt_load_addr =riscv_load_fdt (memmap[SIFIVE_U_DEV_DRAM ].base, machine->ram_size, s->fdt); -#if defined(TARGET_RISCV64 ) - start_addr_hi32 = start_addr >>32 ; -#endif +if (!riscv_is_32_bit (machine)) { + start_addr_hi32 = (uint64_t )start_addr >>32 ; + }/* reset vector */ uint32_t reset_vec[11 ] = {
@@ -528,13 +530,8 @@ static void sifive_u_machine_init(MachineState *machine)0x00000297 ,/* 1: auipc t0, %pcrel_hi(fw_dyn) */ 0x02828613 ,/* addi a2, t0, %pcrel_lo(1b) */ 0xf1402573 ,/* csrr a0, mhartid */ -#if defined(TARGET_RISCV32 ) - 0x0202a583, /* lw a1, 32(t0) */ - 0x0182a283, /* lw t0, 24(t0) */ -#elif defined(TARGET_RISCV64 ) -0x0202b583 ,/* ld a1, 32(t0) */ -0x0182b283 ,/* ld t0, 24(t0) */ -#endif +0 , +0 ,0x00028067 ,/* jr t0 */ start_addr,/* start: .dword */ start_addr_hi32,
@@ -542,6 +539,14 @@ static void sifive_u_machine_init(MachineState *machine) 0x00000000,/* fw_dyn: */ }; +if (riscv_is_32_bit (machine)) { + reset_vec[4 ] =0x0202a583 ;/* lw a1, 32(t0) */ + reset_vec[5 ] =0x0182a283 ;/* lw t0, 24(t0) */ + }else { + reset_vec[4 ] =0x0202b583 ;/* ld a1, 32(t0) */ + reset_vec[5 ] =0x0182b283 ;/* ld t0, 24(t0) */ + } +/* copy in the reset vector in little_endian byte order */ for (i =0 ; i <ARRAY_SIZE (reset_vec); i++) {
Signature · 1 line
2.29.2
Re: [PATCH v4 08/16] hw/riscv: sifive_u: Remove compile time XLEN checks
Quoted 8 lines · Alistair Francis
Signed-off-by Alistair Francis <[email protected]>Reviewed-by Palmer Dabbelt <[email protected]>Acked-by Palmer Dabbelt <[email protected]>--- hw/riscv/sifive_u.c | 55 ++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 25 deletions(-)
Tested with 64-bit sifive_u
32-bit is blocked by:
http://lists.infradead.org/pipermail/linux-riscv/2020-December/003927.html
Regards,
Bin
PATCH v4 9/16 target/riscv: fpu_helper: Match function defs in HELPER macros
In reply to Alistair FrancisUpdate the function definitions generated in helper.h to match the actual function implementations.
Also remove all compile time XLEN checks when building.
--- target/riscv/helper.h | 24 ++++++++---------------- target/riscv/fpu_helper.c | 8 -------- 2 files changed, 8 insertions(+), 24 deletions(-)
target/riscv/helper.h +8 -16
@@ -27,16 +27,12 @@ DEF_HELPER_FLAGS_3(flt_s, TCG_CALL_NO_RWG, tl, env, i64, i64) DEF_HELPER_FLAGS_3(feq_s, TCG_CALL_NO_RWG, tl, env, i64, i64) DEF_HELPER_FLAGS_2(fcvt_w_s, TCG_CALL_NO_RWG, tl, env, i64) DEF_HELPER_FLAGS_2(fcvt_wu_s, TCG_CALL_NO_RWG, tl, env, i64) -#if defined(TARGET_RISCV64 ) -DEF_HELPER_FLAGS_2(fcvt_l_s, TCG_CALL_NO_RWG, tl, env, i64) -DEF_HELPER_FLAGS_2(fcvt_lu_s, TCG_CALL_NO_RWG, tl, env, i64) -#endif +DEF_HELPER_FLAGS_2(fcvt_l_s, TCG_CALL_NO_RWG, i64, env, i64) +DEF_HELPER_FLAGS_2(fcvt_lu_s, TCG_CALL_NO_RWG, i64, env, i64) DEF_HELPER_FLAGS_2(fcvt_s_w, TCG_CALL_NO_RWG, i64, env, tl) DEF_HELPER_FLAGS_2(fcvt_s_wu, TCG_CALL_NO_RWG, i64, env, tl) -#if defined(TARGET_RISCV64 ) -DEF_HELPER_FLAGS_2(fcvt_s_l, TCG_CALL_NO_RWG, i64, env, tl) -DEF_HELPER_FLAGS_2(fcvt_s_lu, TCG_CALL_NO_RWG, i64, env, tl) -#endif +DEF_HELPER_FLAGS_2(fcvt_s_l, TCG_CALL_NO_RWG, i64, env, i64) +DEF_HELPER_FLAGS_2(fcvt_s_lu, TCG_CALL_NO_RWG, i64, env, i64)DEF_HELPER_FLAGS_1 (fclass_s,TCG_CALL_NO_RWG_SE , tl, i64)/* Floating Point - Double Precision */
@@ -54,16 +50,12 @@ DEF_HELPER_FLAGS_3(flt_d, TCG_CALL_NO_RWG, tl, env, i64, i64) DEF_HELPER_FLAGS_3(feq_d, TCG_CALL_NO_RWG, tl, env, i64, i64) DEF_HELPER_FLAGS_2(fcvt_w_d, TCG_CALL_NO_RWG, tl, env, i64) DEF_HELPER_FLAGS_2(fcvt_wu_d, TCG_CALL_NO_RWG, tl, env, i64) -#if defined(TARGET_RISCV64 ) -DEF_HELPER_FLAGS_2(fcvt_l_d, TCG_CALL_NO_RWG, tl, env, i64) -DEF_HELPER_FLAGS_2(fcvt_lu_d, TCG_CALL_NO_RWG, tl, env, i64) -#endif +DEF_HELPER_FLAGS_2(fcvt_l_d, TCG_CALL_NO_RWG, i64, env, i64) +DEF_HELPER_FLAGS_2(fcvt_lu_d, TCG_CALL_NO_RWG, i64, env, i64) DEF_HELPER_FLAGS_2(fcvt_d_w, TCG_CALL_NO_RWG, i64, env, tl) DEF_HELPER_FLAGS_2(fcvt_d_wu, TCG_CALL_NO_RWG, i64, env, tl) -#if defined(TARGET_RISCV64 ) -DEF_HELPER_FLAGS_2(fcvt_d_l, TCG_CALL_NO_RWG, i64, env, tl) -DEF_HELPER_FLAGS_2(fcvt_d_lu, TCG_CALL_NO_RWG, i64, env, tl) -#endif +DEF_HELPER_FLAGS_2(fcvt_d_l, TCG_CALL_NO_RWG, i64, env, i64) +DEF_HELPER_FLAGS_2(fcvt_d_lu, TCG_CALL_NO_RWG, i64, env, i64)DEF_HELPER_FLAGS_1 (fclass_d,TCG_CALL_NO_RWG_SE , tl, i64)/* Special functions */
target/riscv/fpu_helper.c +0 -8
@@ -223,7 +223,6 @@ target_ulong helper_fcvt_wu_s(CPURISCVState *env, uint64_t rs1)return (int32_t )float32_to_uint32 (frs1, &env->fp_status); } -#if defined(TARGET_RISCV64 )uint64_t helper_fcvt_l_s (CPURISCVState *env,uint64_t rs1) {float32 frs1 =check_nanbox_s (rs1);
@@ -235,7 +234,6 @@ uint64_t helper_fcvt_lu_s(CPURISCVState *env, uint64_t rs1)float32 frs1 =check_nanbox_s (rs1);return float32_to_uint64 (frs1, &env->fp_status); } -#endif uint64_t helper_fcvt_s_w (CPURISCVState *env,target_ulong rs1) {
@@ -247,7 +245,6 @@ uint64_t helper_fcvt_s_wu(CPURISCVState *env, target_ulong rs1)return nanbox_s (uint32_to_float32 ((uint32_t )rs1, &env->fp_status)); } -#if defined(TARGET_RISCV64 )uint64_t helper_fcvt_s_l (CPURISCVState *env,uint64_t rs1) {return nanbox_s (int64_to_float32 (rs1, &env->fp_status));
@@ -257,7 +254,6 @@ uint64_t helper_fcvt_s_lu(CPURISCVState *env, uint64_t rs1) {return nanbox_s (uint64_to_float32 (rs1, &env->fp_status)); } -#endif target_ulong helper_fclass_s (uint64_t rs1) {
@@ -336,7 +332,6 @@ target_ulong helper_fcvt_wu_d(CPURISCVState *env, uint64_t frs1)return (int32_t )float64_to_uint32 (frs1, &env->fp_status); } -#if defined(TARGET_RISCV64 )uint64_t helper_fcvt_l_d (CPURISCVState *env,uint64_t frs1) {return float64_to_int64 (frs1, &env->fp_status);
@@ -346,7 +341,6 @@ uint64_t helper_fcvt_lu_d(CPURISCVState *env, uint64_t frs1) {return float64_to_uint64 (frs1, &env->fp_status); } -#endif uint64_t helper_fcvt_d_w (CPURISCVState *env,target_ulong rs1) {
@@ -358,7 +352,6 @@ uint64_t helper_fcvt_d_wu(CPURISCVState *env, target_ulong rs1)return uint32_to_float64 ((uint32_t )rs1, &env->fp_status); } -#if defined(TARGET_RISCV64 )uint64_t helper_fcvt_d_l (CPURISCVState *env,uint64_t rs1) {return int64_to_float64 (rs1, &env->fp_status);
@@ -368,7 +361,6 @@ uint64_t helper_fcvt_d_lu(CPURISCVState *env, uint64_t rs1) {return uint64_to_float64 (rs1, &env->fp_status); } -#endif target_ulong helper_fclass_d (uint64_t frs1) {
Signature · 1 line
2.29.2
PATCH v4 10/16 target/riscv: Add a riscv_cpu_is_32bit() helper function
In reply to Alistair Francis--- target/riscv/cpu.h | 2 ++ target/riscv/cpu.c | 9 +++++++++ 2 files changed, 11 insertions(+)
target/riscv/cpu.h +2 -0
@@ -384,6 +384,8 @@ FIELD(TB_FLAGS, VILL, 8, 1)/* Is a Hypervisor instruction load/store allowed? */ FIELD(TB_FLAGS, HLSX, 9, 1) +bool riscv_cpu_is_32bit (CPURISCVState *env); +/* * A simplification for VLMAX * = (1 << LMUL) * VLEN / (8 * (1 << SEW))
target/riscv/cpu.c +9 -0
@@ -108,6 +108,15 @@ const char *riscv_cpu_get_trap_name(target_ulong cause, bool async) } } +bool riscv_cpu_is_32bit (CPURISCVState *env) +{ +if (env->misa &RV64 ) { +return false; + } + +return true; +} +static void set_misa (CPURISCVState *env,target_ulong misa) { env->misa_mask = env->misa = misa;
Signature · 1 line
2.29.2
PATCH v4 11/16 target/riscv: Specify the XLEN for CPUs
In reply to Alistair Francis--- target/riscv/cpu.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-)
target/riscv/cpu.c +23 -10
@@ -158,22 +158,36 @@ static void riscv_base_cpu_init(Object *obj)set_misa (env,0 ); } -static void rvxx_sifive_u_cpu_init (Object *obj) +#ifdef TARGET_RISCV64 +static void rv64_sifive_u_cpu_init (Object *obj) {CPURISCVState *env = &RISCV_CPU (obj)->env; -set_misa (env,RVXLEN |RVI |RVM |RVA |RVF |RVD |RVC |RVS |RVU ); +set_misa (env,RV64 |RVI |RVM |RVA |RVF |RVD |RVC |RVS |RVU );set_priv_version (env,PRIV_VERSION_1_10_0 ); } -static void rvxx_sifive_e_cpu_init (Object *obj) +static void rv64_sifive_e_cpu_init (Object *obj) {CPURISCVState *env = &RISCV_CPU (obj)->env; -set_misa (env,RVXLEN |RVI |RVM |RVA |RVC |RVU ); +set_misa (env,RV64 |RVI |RVM |RVA |RVC |RVU );set_priv_version (env,PRIV_VERSION_1_10_0 );qdev_prop_set_bit (DEVICE (obj),"mmu" , false); } +#else +static void rv32_sifive_u_cpu_init (Object *obj) +{ +CPURISCVState *env = &RISCV_CPU (obj)->env; +set_misa (env,RV32 |RVI |RVM |RVA |RVF |RVD |RVC |RVS |RVU ); +set_priv_version (env,PRIV_VERSION_1_10_0 ); +} -#if defined(TARGET_RISCV32 ) +static void rv32_sifive_e_cpu_init (Object *obj) +{ +CPURISCVState *env = &RISCV_CPU (obj)->env; +set_misa (env,RV32 |RVI |RVM |RVA |RVC |RVU ); +set_priv_version (env,PRIV_VERSION_1_10_0 ); +qdev_prop_set_bit (DEVICE (obj),"mmu" , false); +}static void rv32_ibex_cpu_init (Object *obj) {
@@ -191,7 +205,6 @@ static void rv32_imafcu_nommu_cpu_init(Object *obj)set_resetvec (env,DEFAULT_RSTVEC ); qdev_prop_set_bit(DEVICE(obj), "mmu", false); } -#endif static ObjectClass *riscv_cpu_class_by_name (const char *cpu_model)
@@ -643,13 +656,13 @@ static const TypeInfo riscv_cpu_type_infos[] = {#if defined(TARGET_RISCV32 ) DEFINE_CPU(TYPE_RISCV_CPU_BASE32, riscv_base_cpu_init), DEFINE_CPU(TYPE_RISCV_CPU_IBEX, rv32_ibex_cpu_init), - DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E31, rvxx_sifive_e_cpu_init), + DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E31, rv32_sifive_e_cpu_init), DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E34, rv32_imafcu_nommu_cpu_init), - DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U34, rvxx_sifive_u_cpu_init), + DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U34, rv32_sifive_u_cpu_init), #elif defined(TARGET_RISCV64) DEFINE_CPU(TYPE_RISCV_CPU_BASE64, riscv_base_cpu_init), - DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E51, rvxx_sifive_e_cpu_init), - DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U54, rvxx_sifive_u_cpu_init), + DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E51, rv64_sifive_e_cpu_init), + DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U54, rv64_sifive_u_cpu_init),#endif };
Signature · 1 line
2.29.2
PATCH v4 12/16 target/riscv: cpu: Remove compile time XLEN checks
In reply to Alistair Francis--- target/riscv/cpu.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
target/riscv/cpu.c +10 -9
@@ -240,10 +240,10 @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags)#ifndef CONFIG_USER_ONLY qemu_fprintf (f," %s " TARGET_FMT_lx"\n" ,"mhartid " , env->mhartid);qemu_fprintf (f," %s " TARGET_FMT_lx"\n" ,"mstatus " , (target_ulong )env->mstatus); -#ifdef TARGET_RISCV32 -qemu_fprintf (f," %s " TARGET_FMT_lx"\n" ,"mstatush " , - (target_ulong)(env->mstatus >>32 )); -#endif +if (riscv_cpu_is_32bit (env)) { +qemu_fprintf (f," %s " TARGET_FMT_lx"\n" ,"mstatush " , + (target_ulong)(env->mstatus >>32 )); + }if (riscv_has_ext (env,RVH )) {qemu_fprintf (f," %s " TARGET_FMT_lx"\n" ,"hstatus " , env->hstatus); qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "vsstatus ",
@@ -356,11 +356,12 @@ static void riscv_cpu_reset(DeviceState *dev)static void riscv_cpu_disas_set_info (CPUState *s,disassemble_info *info) { -#if defined(TARGET_RISCV32 ) - info->print_insn = print_insn_riscv32; -#elif defined(TARGET_RISCV64 ) - info->print_insn = print_insn_riscv64; -#endif +RISCVCPU *cpu =RISCV_CPU (s); +if (riscv_cpu_is_32bit (&cpu->env)) { + info->print_insn = print_insn_riscv32; + }else { + info->print_insn = print_insn_riscv64; + } }static void riscv_cpu_realize (DeviceState *dev,Error **errp)
Signature · 1 line
2.29.2
Re: [PATCH v4 12/16] target/riscv: cpu: Remove compile time XLEN checks
Quoted 10 lines · Alistair Francis
Signed-off-by Alistair Francis <[email protected]>Reviewed-by Bin Meng <[email protected]>Reviewed-by Richard Henderson <[email protected]>Reviewed-by Palmer Dabbelt <[email protected]>Acked-by Palmer Dabbelt <[email protected]>--- target/riscv/cpu.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
PATCH v4 13/16 target/riscv: cpu_helper: Remove compile time XLEN checks
In reply to Alistair Francis--- target/riscv/cpu_helper.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
target/riscv/cpu_helper.c +7 -5
@@ -446,11 +446,13 @@ restart:return TRANSLATE_PMP_FAIL ; } -#if defined(TARGET_RISCV32 ) -target_ulong pte =address_space_ldl (cs->as, pte_addr, attrs, &res); -#elif defined(TARGET_RISCV64 ) -target_ulong pte =address_space_ldq (cs->as, pte_addr, attrs, &res); -#endif +target_ulong pte; +if (riscv_cpu_is_32bit (env)) { + pte =address_space_ldl (cs->as, pte_addr, attrs, &res); + }else { + pte =address_space_ldq (cs->as, pte_addr, attrs, &res); + } +if (res !=MEMTX_OK ) {return TRANSLATE_FAIL ; }
Signature · 1 line
2.29.2
Re: [PATCH v4 13/16] target/riscv: cpu_helper: Remove compile time XLEN checks
Quoted 9 lines · Alistair Francis
Signed-off-by Alistair Francis <[email protected]>Reviewed-by Richard Henderson <[email protected]>Reviewed-by Palmer Dabbelt <[email protected]>Acked-by Palmer Dabbelt <[email protected]>--- target/riscv/cpu_helper.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
PATCH v4 14/16 target/riscv: csr: Remove compile time XLEN checks
In reply to Alistair Francis--- target/riscv/cpu_bits.h | 4 +- target/riscv/csr.c | 176 +++++++++++++++++++++------------------- 2 files changed, 92 insertions(+), 88 deletions(-)
target/riscv/cpu_bits.h +1 -3
@@ -437,9 +437,7 @@#define HSTATUS_VGEIN 0x0003F000#define HSTATUS_VTVM 0x00100000#define HSTATUS_VTSR 0x00400000 -#if defined(TARGET_RISCV64 ) -#define HSTATUS_VSXL 0x300000000 -#endif +#define HSTATUS_VSXL 0x300000000#define HSTATUS32_WPRI 0xFF8FF87E#define HSTATUS64_WPRI 0xFFFFFFFFFF8FF87EULL
target/riscv/csr.c +91 -85
342 lines not on this page · raw message
Signature · 1 line
2.29.2
Re: [PATCH v4 14/16] target/riscv: csr: Remove compile time XLEN checks
Quoted 10 lines · Alistair Francis
Signed-off-by Alistair Francis <[email protected]>Reviewed-by Bin Meng <[email protected]>Reviewed-by Palmer Dabbelt <[email protected]>Acked-by Palmer Dabbelt <[email protected]>--- target/riscv/cpu_bits.h | 4 +- target/riscv/csr.c | 176 +++++++++++++++++++++------------------- 2 files changed, 92 insertions(+), 88 deletions(-)
PATCH v4 15/16 target/riscv: cpu: Set XLEN independently from target
In reply to Alistair Francis--- target/riscv/cpu.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)
target/riscv/cpu.c +16 -9
@@ -151,14 +151,14 @@ static void riscv_any_cpu_init(Object *obj)set_priv_version (env,PRIV_VERSION_1_11_0 ); } -static void riscv_base_cpu_init (Object *obj) +#if defined(TARGET_RISCV64 ) +static void rv64_base_cpu_init (Object *obj) {CPURISCVState *env = &RISCV_CPU (obj)->env;/* We set this in the realise function */ -set_misa (env,0 ); +set_misa (env,RV64 ); } -#ifdef TARGET_RISCV64 static void rv64_sifive_u_cpu_init (Object *obj) {CPURISCVState *env = &RISCV_CPU (obj)->env;
@@ -174,6 +174,13 @@ static void rv64_sifive_e_cpu_init(Object *obj) qdev_prop_set_bit(DEVICE(obj), "mmu", false); }#else +static void rv32_base_cpu_init (Object *obj) +{ +CPURISCVState *env = &RISCV_CPU (obj)->env; +/* We set this in the realise function */ +set_misa (env,RV32 ); +} +static void rv32_sifive_u_cpu_init (Object *obj) {CPURISCVState *env = &RISCV_CPU (obj)->env;
@@ -372,7 +379,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)RISCVCPUClass *mcc =RISCV_CPU_GET_CLASS (dev);int priv_version =PRIV_VERSION_1_11_0 ;int vext_version =VEXT_VERSION_0_07_1 ; -target_ulong target_misa =0 ; +target_ulong target_misa = env->misa;Error *local_err =NULL ;cpu_exec_realizefn (cs, &local_err);
@@ -407,8 +414,8 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)set_resetvec (env, cpu->cfg.resetvec); -/* If misa isn't set (rv32 and rv64 machines) set it here */ -if (!env->misa) { +/* If only XLEN is set for misa, then set misa from properties */ +if (env->misa ==RV32 || env->misa ==RV64 ) {/* Do some ISA extension error checking */ if (cpu->cfg.ext_i && cpu->cfg.ext_e) { error_setg(errp,
@@ -504,7 +511,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)set_vext_version (env, vext_version); } -set_misa (env,RVXLEN | target_misa); +set_misa (env, target_misa); }riscv_cpu_register_gdb_regs_for_features (cs);
@@ -655,13 +662,13 @@ static const TypeInfo riscv_cpu_type_infos[] = { }, DEFINE_CPU(TYPE_RISCV_CPU_ANY, riscv_any_cpu_init),#if defined(TARGET_RISCV32 ) - DEFINE_CPU(TYPE_RISCV_CPU_BASE32, riscv_base_cpu_init), + DEFINE_CPU(TYPE_RISCV_CPU_BASE32, rv32_base_cpu_init), DEFINE_CPU(TYPE_RISCV_CPU_IBEX, rv32_ibex_cpu_init), DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E31, rv32_sifive_e_cpu_init), DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E34, rv32_imafcu_nommu_cpu_init), DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U34, rv32_sifive_u_cpu_init), #elif defined(TARGET_RISCV64) - DEFINE_CPU(TYPE_RISCV_CPU_BASE64, riscv_base_cpu_init), + DEFINE_CPU(TYPE_RISCV_CPU_BASE64, rv64_base_cpu_init), DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E51, rv64_sifive_e_cpu_init), DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U54, rv64_sifive_u_cpu_init),#endif
Signature · 1 line
2.29.2
PATCH v4 16/16 hw/riscv: Use the CPU to determine if 32-bit
In reply to Alistair FrancisInstead of using string compares to determine if a RISC-V machine is using 32-bit or 64-bit CPUs we can use the initalised CPUs. This avoids us having to maintain a list of CPU names to compare against.
This commit also fixes the name of the function to match the riscv_cpu_is_32bit() function.
--- include/hw/riscv/boot.h | 8 +++++--- hw/riscv/boot.c | 31 ++++++++++--------------------- hw/riscv/sifive_u.c | 10 +++++----- hw/riscv/spike.c | 8 ++++---- hw/riscv/virt.c | 9 +++++---- 5 files changed, 29 insertions(+), 37 deletions(-)
include/hw/riscv/boot.h +5 -3
@@ -22,10 +22,11 @@#include "exec/cpu-defs.h" #include "hw/loader.h" +#include "hw/riscv/riscv_hart.h" -bool riscv_is_32_bit (MachineState *machine); +bool riscv_is_32bit (RISCVHartArrayState harts); -target_ulong riscv_calc_kernel_start_addr (MachineState *machine, +target_ulong riscv_calc_kernel_start_addr (RISCVHartArrayState harts,target_ulong firmware_end_addr); target_ulong riscv_find_and_load_firmware(MachineState *machine, const char *default_machine_firmware,
@@ -41,7 +42,8 @@ target_ulong riscv_load_kernel(const char *kernel_filename,hwaddr riscv_load_initrd (const char *filename,uint64_t mem_size,uint64_t kernel_entry,hwaddr *start);uint32_t riscv_load_fdt (hwaddr dram_start,uint64_t dram_size,void *fdt); -void riscv_setup_rom_reset_vec (MachineState *machine,hwaddr saddr, +void riscv_setup_rom_reset_vec (MachineState *machine,RISCVHartArrayState harts, +hwaddr saddr,hwaddr rom_base,hwaddr rom_size,uint64_t kernel_entry,uint32_t fdt_load_addr,void *fdt);
hw/riscv/boot.c +10 -21
@@ -33,28 +33,16 @@#include <libfdt.h> -bool riscv_is_32_bit (MachineState *machine) +bool riscv_is_32bit (RISCVHartArrayState harts) { -/* -* To determine if the CPU is 32-bit we need to check a few different CPUs. -* -* If the CPU starts with rv32 -* If the CPU is a sifive 3 seriries CPU (E31, U34) -* If it's the Ibex CPU -*/ -if (!strncmp (machine->cpu_type,"rv32" ,4 ) || - (!strncmp (machine->cpu_type,"sifive" ,6 ) && - machine->cpu_type[8 ] =='3' ) || - !strncmp (machine->cpu_type,"lowrisc-ibex" ,12 )) { -return true; - }else { -return false; - } +RISCVCPU hart = harts.harts[0 ]; + +return riscv_cpu_is_32bit (&hart.env); } -target_ulong riscv_calc_kernel_start_addr (MachineState *machine, +target_ulong riscv_calc_kernel_start_addr (RISCVHartArrayState harts,target_ulong firmware_end_addr) { -if (riscv_is_32_bit (machine)) { +if (riscv_is_32bit (harts)) {return QEMU_ALIGN_UP (firmware_end_addr,4 * MiB); }else {return QEMU_ALIGN_UP (firmware_end_addr,2 * MiB);
@@ -259,7 +247,8 @@ void riscv_rom_copy_firmware_info(MachineState *machine, hwaddr rom_base, &address_space_memory); } -void riscv_setup_rom_reset_vec (MachineState *machine,hwaddr start_addr, +void riscv_setup_rom_reset_vec (MachineState *machine,RISCVHartArrayState harts, +hwaddr start_addr,hwaddr rom_base,hwaddr rom_size,uint64_t kernel_entry,uint32_t fdt_load_addr,void *fdt)
@@ -267,7 +256,7 @@ void riscv_setup_rom_reset_vec(MachineState *machine, hwaddr start_addr,int i;uint32_t start_addr_hi32 =0x00000000 ; -if (!riscv_is_32_bit (machine)) { +if (!riscv_is_32bit (harts)) { start_addr_hi32 = start_addr >>32 ; }/* reset vector */
@@ -284,7 +273,7 @@ void riscv_setup_rom_reset_vec(MachineState *machine, hwaddr start_addr, 0x00000000,/* fw_dyn: */ }; -if (riscv_is_32_bit (machine)) { +if (riscv_is_32bit (harts)) { reset_vec[3 ] =0x0202a583 ;/* lw a1, 32(t0) */ reset_vec[4 ] =0x0182a283 ;/* lw t0, 24(t0) */ }else {
hw/riscv/sifive_u.c +5 -5
@@ -453,7 +453,7 @@ static void sifive_u_machine_init(MachineState *machine)/* create device tree */ create_fdt (s, memmap, machine->ram_size, machine->kernel_cmdline, -riscv_is_32_bit (machine)); +riscv_is_32bit (s->soc.u_cpus));if (s->start_in_flash) {/*
@@ -482,7 +482,7 @@ static void sifive_u_machine_init(MachineState *machine)break ; } -if (riscv_is_32_bit (machine)) { +if (riscv_is_32bit (s->soc.u_cpus)) { firmware_end_addr =riscv_find_and_load_firmware (machine,"opensbi-riscv32-generic-fw_dynamic.bin" , start_addr,NULL );
@@ -493,7 +493,7 @@ static void sifive_u_machine_init(MachineState *machine) }if (machine->kernel_filename) { - kernel_start_addr =riscv_calc_kernel_start_addr (machine, + kernel_start_addr =riscv_calc_kernel_start_addr (s->soc.u_cpus, firmware_end_addr); kernel_entry = riscv_load_kernel(machine->kernel_filename,
@@ -520,7 +520,7 @@ static void sifive_u_machine_init(MachineState *machine)/* Compute the fdt load address in dram */ fdt_load_addr =riscv_load_fdt (memmap[SIFIVE_U_DEV_DRAM ].base, machine->ram_size, s->fdt); -if (!riscv_is_32_bit (machine)) { +if (!riscv_is_32bit (s->soc.u_cpus)) { start_addr_hi32 = (uint64_t )start_addr >>32 ; }
@@ -539,7 +539,7 @@ static void sifive_u_machine_init(MachineState *machine) 0x00000000,/* fw_dyn: */ }; -if (riscv_is_32_bit (machine)) { +if (riscv_is_32bit (s->soc.u_cpus)) { reset_vec[4 ] =0x0202a583 ;/* lw a1, 32(t0) */ reset_vec[5 ] =0x0182a283 ;/* lw t0, 24(t0) */ }else {
hw/riscv/spike.c +4 -4
@@ -244,7 +244,7 @@ static void spike_board_init(MachineState *machine)/* create device tree */ create_fdt (s, memmap, machine->ram_size, machine->kernel_cmdline, -riscv_is_32_bit (machine)); +riscv_is_32bit (s->soc[0 ]));/* boot rom */ memory_region_init_rom(mask_rom, NULL, "riscv.spike.mrom",
@@ -257,7 +257,7 @@ static void spike_board_init(MachineState *machine)* keeping ELF files here was intentional because BIN files don't work * for the Spike machine as HTIF emulation depends on ELF parsing. */ -if (riscv_is_32_bit (machine)) { +if (riscv_is_32bit (s->soc[0 ])) { firmware_end_addr = riscv_find_and_load_firmware(machine, "opensbi-riscv32-generic-fw_dynamic.elf", memmap[SPIKE_DRAM].base,
@@ -270,7 +270,7 @@ static void spike_board_init(MachineState *machine) }if (machine->kernel_filename) { - kernel_start_addr =riscv_calc_kernel_start_addr (machine, + kernel_start_addr =riscv_calc_kernel_start_addr (s->soc[0 ], firmware_end_addr); kernel_entry = riscv_load_kernel(machine->kernel_filename,
@@ -299,7 +299,7 @@ static void spike_board_init(MachineState *machine) fdt_load_addr =riscv_load_fdt (memmap[SPIKE_DRAM ].base, machine->ram_size, s->fdt);/* load the reset vector */ -riscv_setup_rom_reset_vec (machine, memmap[SPIKE_DRAM ].base, +riscv_setup_rom_reset_vec (machine, s->soc[0 ], memmap[SPIKE_DRAM ].base, memmap[SPIKE_MROM ].base, memmap[SPIKE_MROM ].size, kernel_entry, fdt_load_addr, s->fdt);
hw/riscv/virt.c +5 -4
@@ -603,7 +603,7 @@ static void virt_machine_init(MachineState *machine)/* create device tree */ create_fdt (s, memmap, machine->ram_size, machine->kernel_cmdline, -riscv_is_32_bit (machine)); +riscv_is_32bit (s->soc[0 ]));/* boot rom */ memory_region_init_rom(mask_rom, NULL, "riscv_virt_board.mrom",
@@ -611,7 +611,7 @@ static void virt_machine_init(MachineState *machine)memory_region_add_subregion (system_memory, memmap[VIRT_MROM ].base, mask_rom); -if (riscv_is_32_bit (machine)) { +if (riscv_is_32bit (s->soc[0 ])) { firmware_end_addr =riscv_find_and_load_firmware (machine,"opensbi-riscv32-generic-fw_dynamic.bin" , start_addr,NULL );
@@ -622,7 +622,7 @@ static void virt_machine_init(MachineState *machine) }if (machine->kernel_filename) { - kernel_start_addr =riscv_calc_kernel_start_addr (machine, + kernel_start_addr =riscv_calc_kernel_start_addr (s->soc[0 ], firmware_end_addr); kernel_entry = riscv_load_kernel(machine->kernel_filename,
@@ -658,7 +658,8 @@ static void virt_machine_init(MachineState *machine) fdt_load_addr =riscv_load_fdt (memmap[VIRT_DRAM ].base, machine->ram_size, s->fdt);/* load the reset vector */ -riscv_setup_rom_reset_vec (machine, start_addr, virt_memmap[VIRT_MROM ].base, +riscv_setup_rom_reset_vec (machine, s->soc[0 ], start_addr, + virt_memmap[VIRT_MROM ].base, virt_memmap[VIRT_MROM ].size, kernel_entry, fdt_load_addr, s->fdt);
Signature · 1 line
2.29.2
Re: [PATCH v4 16/16] hw/riscv: Use the CPU to determine if 32-bit
Quoted 7 lines · Alistair Francis
Instead of using string compares to determine if a RISC-V machine is using 32-bit or 64-bit CPUs we can use the initalised CPUs. This avoids us having to maintain a list of CPU names to compare against.
This commit also fixes the name of the function to match the
riscv_cpu_is_32bit()function.
Quoted 8 lines
Signed-off-by Alistair Francis <[email protected]>--- include/hw/riscv/boot.h | 8 +++++--- hw/riscv/boot.c | 31 ++++++++++--------------------- hw/riscv/sifive_u.c | 10 +++++----- hw/riscv/spike.c | 8 ++++---- hw/riscv/virt.c | 9 +++++---- 5 files changed, 29 insertions(+), 37 deletions(-)
r~
Re: [PATCH v4 16/16] hw/riscv: Use the CPU to determine if 32-bit
In reply to Alistair FrancisQuoted 62 lines · Alistair Francis
Instead of using string compares to determine if a RISC-V machine is using 32-bit or 64-bit CPUs we can use the initalised CPUs. This avoids us having to maintain a list of CPU names to compare against.
This commit also fixes the name of the function to match the
riscv_cpu_is_32bit()function.Signed-off-by Alistair Francis <[email protected]>--- include/hw/riscv/boot.h | 8 +++++--- hw/riscv/boot.c | 31 ++++++++++--------------------- hw/riscv/sifive_u.c | 10 +++++----- hw/riscv/spike.c | 8 ++++---- hw/riscv/virt.c | 9 +++++---- 5 files changed, 29 insertions(+), 37 deletions(-)include/hw/riscv/boot.h +5
-3@@ -22,10 +22,11 @@#include "exec/cpu-defs.h" #include "hw/loader.h" +#include "hw/riscv/riscv_hart.h" -bool riscv_is_32_bit (MachineState *machine); +bool riscv_is_32bit (RISCVHartArrayState harts); -target_ulong riscv_calc_kernel_start_addr (MachineState *machine, +target_ulong riscv_calc_kernel_start_addr (RISCVHartArrayState harts,target_ulong firmware_end_addr); target_ulong riscv_find_and_load_firmware(MachineState *machine, const char *default_machine_firmware,@@ -41,7 +42,8 @@ target_ulong riscv_load_kernel(const char *kernel_filename,hwaddr riscv_load_initrd (const char *filename,uint64_t mem_size,uint64_t kernel_entry,hwaddr *start);uint32_t riscv_load_fdt (hwaddr dram_start,uint64_t dram_size,void *fdt); -void riscv_setup_rom_reset_vec (MachineState *machine,hwaddr saddr, +void riscv_setup_rom_reset_vec (MachineState *machine,RISCVHartArrayState harts, +hwaddr saddr,hwaddr rom_base,hwaddr rom_size,uint64_t kernel_entry,uint32_t fdt_load_addr,void *fdt);hw/riscv/boot.c +1
-7@@ -33,28 +33,16 @@#include <libfdt.h> -bool riscv_is_32_bit (MachineState *machine) +bool riscv_is_32bit (RISCVHartArrayState harts) { -/* -* To determine if the CPU is 32-bit we need to check a few different CPUs. -* -* If the CPU starts with rv32 -* If the CPU is a sifive 3 seriries CPU (E31, U34) -* If it's the Ibex CPU
hw/riscv/boot.c line 38
Quoted 10 lines
hw/riscv/boot.c +1
-9-*/ -if (!strncmp (machine->cpu_type,"rv32" ,4 ) || - (!strncmp (machine->cpu_type,"sifive" ,6 ) && - machine->cpu_type[8 ] =='3' ) || - !strncmp (machine->cpu_type,"lowrisc-ibex" ,12 )) { -return true; - }else { -return false; - } +RISCVCPU hart = harts.harts[0 ];
What happens if something like ARM big.LITTLE needs to be supported on RISC-V?
hw/riscv/boot.c line 42
Quoted 4 lines
hw/riscv/boot.c +2
-0+ +return riscv_cpu_is_32bit (&hart.env); }
[snip]
Regards,
Bin
Re: [PATCH v4 16/16] hw/riscv: Use the CPU to determine if 32-bit
Quoted 1 line · Bin Meng
What happens if something like ARM big.LITTLE needs to be supported on RISC-V?
I'd say it's the board's job to pass the boot heart. (Though even big.LITTLE doesn't mix 64 and 32-bit cores.)
r~
Palmer Dabbelt
maintainerRe: [PATCH v4 16/16] hw/riscv: Use the CPU to determine if 32-bit
Quoted 5 lines · On Thu, 17 Dec 2020 05:58:11 PST (-0800), [email protected] wrote:
Quoted 1 line · Bin Meng
What happens if something like ARM big.LITTLE needs to be supported on RISC-V?
I'd say it's the board's job to pass the boot heart. (Though even big.LITTLE doesn't mix 64 and 32-bit cores.)
I guess we can't stop people from building crazy things, but it does seem like building a system that mixes up base ISAs is unlikely. IDK if 32-bit compatibility on 64-bit systems is ever going to be important enough to show up on RISC-V, as 32-bit might be defunct in portable systems by the point real RISC-V systems are availiable, but one could imagine systems where only a subset of cores have 32-bit compatibility. My guess is that they'd all boot into 64-bit mode, though, so that sort of stuff won't be relevant until one tries to get to 32-bit code.
Regardless of where that sort of thing goes, it seems reasonable to just ban people from spinning up mixed machine XLEN systems in QEMU for the time being. IIUC that's always been impossible (as it was a #define before), so it's not like we're regressing on any functionality with that constraint.
Other hetergenous ISA/microarctucture stuff seems reasonable to support in QEMU, but also not a high priority. It doesn't seem that hard to write the early boot stuff in a way such that it only depends on the base ISA -- that's essentially how we're handling stuff like F/D in Linux, you just either probe or handle the traps. There's already some simple hetergenous stuff floating around (like the non-MMU cores in the SiFive designs) and that all seems to work fine so my guess is we have enough stuff there, but I'm sure there'll be more work do to as more complicated designs start to show up (doubly so as there's no specs for any of this).
Re: [PATCH v4 16/16] hw/riscv: Use the CPU to determine if 32-bit
Quoted 17 lines · Palmer Dabbelt
Quoted 5 lines · On Thu, 17 Dec 2020 05:58:11 PST (-0800), [email protected] wrote:
Quoted 1 line · Bin Meng
What happens if something like ARM big.LITTLE needs to be supported on RISC-V?
I'd say it's the board's job to pass the boot heart. (Though even big.LITTLE doesn't mix 64 and 32-bit cores.)
I guess we can't stop people from building crazy things, but it does seem like building a system that mixes up base ISAs is unlikely. IDK if 32-bit compatibility on 64-bit systems is ever going to be important enough to show up on RISC-V, as 32-bit might be defunct in portable systems by the point real RISC-V systems are availiable, but one could imagine systems where only a subset of cores have 32-bit compatibility. My guess is that they'd all boot into 64-bit mode, though, so that sort of stuff won't be relevant until one tries to get to 32-bit code.
Quoted 4 lines
Regardless of where that sort of thing goes, it seems reasonable to just ban people from spinning up mixed machine XLEN systems in QEMU for the time being. IIUC that's always been impossible (as it was a #define before), so it's not like we're regressing on any functionality with that constraint.
I agree. Currently we don't get anywhere close to allowing mixed XLEN systems.
Allowing 32-bit and 64-bit CPUs on a system is a useful goal, as for example that is what the HiFive 1 has. As richard said though the main interest at this point is the boot CPU, which the board can specify different harts depending on what it is doing.
This is just the first step to making RISC-V more flexible with XLEN, there will be more patches in the future to continue improving this.
I'm going to apply this series today.
Alistair
Quoted 10 lines
Other hetergenous ISA/microarctucture stuff seems reasonable to support in QEMU, but also not a high priority. It doesn't seem that hard to write the early boot stuff in a way such that it only depends on the base ISA -- that's essentially how we're handling stuff like F/D in Linux, you just either probe or handle the traps. There's already some simple hetergenous stuff floating around (like the non-MMU cores in the SiFive designs) and that all seems to work fine so my guess is we have enough stuff there, but I'm sure there'll be more work do to as more complicated designs start to show up (doubly so as there's no specs for any of this).