RISC-V: QEMU 2.13 Privileged ISA emulation updates
Subsystems (2)
The following changes since commit c8b7e627b4269a3bc3ae41d9f420547a47e6d9b9:
Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2018-05-04' into staging (2018-05-04 14:42:46 +0100)
are available in the git repository at:
https://github.com/riscv/riscv-qemu.git tags/riscv-qemu-2.13-pull-20180506
for you to fetch changes up to 5aec3247c190f10654250203a1742490ae7343a2:
RISC-V: Mark ROM read-only after copying in code (2018-05-06 10:54:21 +1200)
----------------------------------------------------------------
RISC-V: QEMU 2.13 Privileged ISA emulation updates
Several code cleanups, minor specification conformance changes, fixes to make ROM read-only and add device-tree size checks.
* Honour privileged ISA v1.10 counter enable CSRs.
* Implements WARL behavior for CSRs that don't support writes
* Past behavior of raising traps was non-conformant with the RISC-V Privileged ISA Specification v1.10.
* Allow S-mode access to sstatus.MXR when priv ISA >= v1.10
* Sets mtval/stval to zero on exceptions without addresses
* Past behavior of leaving the last value was non-conformant with the RISC-V Privileged ISA Specition v1.10. mtval/stval must be set on all exceptions; to zero if not supported.
* Make ROMs read-only and implement device-tree size checks
* Uses memory_region_init_rom and rom_add_blob_fixed_as
* Adds hexidecimal instruction bytes to disassembly output.
* Fixes missing break statement for rv128 disassembly.
* Several code cleanups
* Replacing hard-coded constants with enums
* Dead-code elimination
This is an incremental pull that contains 20 reviewed changes out of 38 changes currently queued in the qemu-2.13-for-upstream branch.
----------------------------------------------------------------
Michael Clark (20):
RISC-V: Replace hardcoded constants with enum values
RISC-V: Make virt board description match spike
RISC-V: Use ROM base address and size from memmap
RISC-V: Remove identity_translate from load_elf
RISC-V: Remove unused class definitions
RISC-V: Include instruction hex in disassembly
RISC-V: Fix missing break statement in disassembler
RISC-V: Make some header guards more specific
RISC-V: Make virt header comment title consistent
RISC-V: Remove EM_RISCV ELF_MACHINE indirection
RISC-V: Remove erroneous comment from translate.c
RISC-V: Update E and I extension order
RISC-V: Hardwire satp to 0 for no-mmu case
RISC-V: Clear mtval/stval on exceptions without info
RISC-V: Allow S-mode mxr access when priv ISA >= v1.10
RISC-V: Use [ms]counteren CSRs when priv ISA >= v1.10
RISC-V: Add mcycle/minstret support for -icount auto
RISC-V: Make mtvec/stvec ignore vectored traps
RISC-V: No traps on writes to misa,minstret,mcycle
RISC-V: Mark ROM read-only after copying in code
disas/riscv.c | 42 ++++++------ hw/riscv/riscv_hart.c | 6 -- hw/riscv/sifive_clint.c | 9 +-- hw/riscv/sifive_e.c | 54 +++------------ hw/riscv/sifive_u.c | 91 ++++++++++--------------- hw/riscv/spike.c | 104 +++++++++++++---------------- hw/riscv/virt.c | 85 +++++++++--------------- include/hw/riscv/sifive_clint.h | 4 ++ include/hw/riscv/sifive_e.h | 5 -- include/hw/riscv/sifive_u.h | 9 ++- include/hw/riscv/spike.h | 15 ++--- include/hw/riscv/virt.h | 17 ++--- target/riscv/cpu.c | 2 +- target/riscv/cpu.h | 8 +-- target/riscv/helper.c | 8 +++ target/riscv/op_helper.c | 143 +++++++++++++++++++++++++++++----------- target/riscv/translate.c | 3 +- 17 files changed, 287 insertions(+), 318 deletions(-)
Signature · 1 line
2.7.0
[Qemu-devel] [PULL 01/20] RISC-V: Replace hardcoded constants with enum values
The RISC-V device-tree code has a number of hard-coded constants and this change moves them into header enums.
--- hw/riscv/sifive_clint.c | 9 +++------ hw/riscv/sifive_u.c | 6 ++++-- hw/riscv/spike.c | 6 ++++-- hw/riscv/virt.c | 6 ++++-- include/hw/riscv/sifive_clint.h | 4 ++++ include/hw/riscv/sifive_u.h | 4 ++++ include/hw/riscv/spike.h | 4 ++++ include/hw/riscv/virt.h | 4 ++++ 8 files changed, 31 insertions(+), 12 deletions(-)
hw/riscv/sifive_clint.c +3 -6
@@ -26,13 +26,10 @@#include "hw/riscv/sifive_clint.h" #include "qemu/timer.h" -/* See: riscv-pk/machine/sbi_entry.S and arch/riscv/kernel/time.c */ -#define TIMER_FREQ (10 * 1000 * 1000) -static uint64_t cpu_riscv_read_rtc (void ) { -return muldiv64 (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ),TIMER_FREQ , -NANOSECONDS_PER_SECOND ); +return muldiv64 (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ), +SIFIVE_CLINT_TIMEBASE_FREQ ,NANOSECONDS_PER_SECOND ); }/*
@@ -59,7 +56,7 @@ static void sifive_clint_write_timecmp(RISCVCPU *cpu, uint64_t value) diff = cpu->env.timecmp - rtc_r;/* back to ns (note args switched in muldiv64) */ next =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + -muldiv64 (diff,NANOSECONDS_PER_SECOND ,TIMER_FREQ ); +muldiv64 (diff,NANOSECONDS_PER_SECOND ,SIFIVE_CLINT_TIMEBASE_FREQ );timer_mod (cpu->env.timer, next); }
hw/riscv/sifive_u.c +4 -2
@@ -122,7 +122,8 @@ static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap,g_free (nodename);qemu_fdt_add_subnode (fdt,"/cpus" ); -qemu_fdt_setprop_cell (fdt,"/cpus" ,"timebase-frequency" ,10000000 ); +qemu_fdt_setprop_cell (fdt,"/cpus" ,"timebase-frequency" , +SIFIVE_CLINT_TIMEBASE_FREQ );qemu_fdt_setprop_cell (fdt,"/cpus" ,"#size-cells" ,0x0 );qemu_fdt_setprop_cell (fdt,"/cpus" ,"#address-cells" ,0x1 );
@@ -131,7 +132,8 @@ static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap,char *intc =g_strdup_printf ("/cpus/cpu@%d/interrupt-controller" , cpu);char *isa =riscv_isa_string (&s->soc.harts[cpu]);qemu_fdt_add_subnode (fdt, nodename); -qemu_fdt_setprop_cell (fdt, nodename,"clock-frequency" ,1000000000 ); +qemu_fdt_setprop_cell (fdt, nodename,"clock-frequency" , +SIFIVE_U_CLOCK_FREQ );qemu_fdt_setprop_string (fdt, nodename,"mmu-type" ,"riscv,sv48" );qemu_fdt_setprop_string (fdt, nodename,"riscv,isa" , isa);qemu_fdt_setprop_string (fdt, nodename,"compatible" ,"riscv" );
hw/riscv/spike.c +4 -2
@@ -115,7 +115,8 @@ static void create_fdt(SpikeState *s, const struct MemmapEntry *memmap,g_free (nodename);qemu_fdt_add_subnode (fdt,"/cpus" ); -qemu_fdt_setprop_cell (fdt,"/cpus" ,"timebase-frequency" ,10000000 ); +qemu_fdt_setprop_cell (fdt,"/cpus" ,"timebase-frequency" , +SIFIVE_CLINT_TIMEBASE_FREQ );qemu_fdt_setprop_cell (fdt,"/cpus" ,"#size-cells" ,0x0 );qemu_fdt_setprop_cell (fdt,"/cpus" ,"#address-cells" ,0x1 );
@@ -124,7 +125,8 @@ static void create_fdt(SpikeState *s, const struct MemmapEntry *memmap,char *intc =g_strdup_printf ("/cpus/cpu@%d/interrupt-controller" , cpu);char *isa =riscv_isa_string (&s->soc.harts[cpu]);qemu_fdt_add_subnode (fdt, nodename); -qemu_fdt_setprop_cell (fdt, nodename,"clock-frequency" ,1000000000 ); +qemu_fdt_setprop_cell (fdt, nodename,"clock-frequency" , +SPIKE_CLOCK_FREQ );qemu_fdt_setprop_string (fdt, nodename,"mmu-type" ,"riscv,sv48" );qemu_fdt_setprop_string (fdt, nodename,"riscv,isa" , isa);qemu_fdt_setprop_string (fdt, nodename,"compatible" ,"riscv" );
hw/riscv/virt.c +4 -2
@@ -145,7 +145,8 @@ static void *create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,g_free (nodename);qemu_fdt_add_subnode (fdt,"/cpus" ); -qemu_fdt_setprop_cell (fdt,"/cpus" ,"timebase-frequency" ,10000000 ); +qemu_fdt_setprop_cell (fdt,"/cpus" ,"timebase-frequency" , +SIFIVE_CLINT_TIMEBASE_FREQ );qemu_fdt_setprop_cell (fdt,"/cpus" ,"#size-cells" ,0x0 );qemu_fdt_setprop_cell (fdt,"/cpus" ,"#address-cells" ,0x1 );
@@ -155,7 +156,8 @@ static void *create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap,char *intc =g_strdup_printf ("/cpus/cpu@%d/interrupt-controller" , cpu);char *isa =riscv_isa_string (&s->soc.harts[cpu]);qemu_fdt_add_subnode (fdt, nodename); -qemu_fdt_setprop_cell (fdt, nodename,"clock-frequency" ,1000000000 ); +qemu_fdt_setprop_cell (fdt, nodename,"clock-frequency" , +VIRT_CLOCK_FREQ );qemu_fdt_setprop_string (fdt, nodename,"mmu-type" ,"riscv,sv48" );qemu_fdt_setprop_string (fdt, nodename,"riscv,isa" , isa);qemu_fdt_setprop_string (fdt, nodename,"compatible" ,"riscv" );
include/hw/riscv/sifive_clint.h +4 -0
@@ -47,4 +47,8 @@ enum {SIFIVE_TIME_BASE =0xBFF8 }; +enum { +SIFIVE_CLINT_TIMEBASE_FREQ =10000000 +}; +#endif
include/hw/riscv/sifive_u.h +4 -0
@@ -50,6 +50,10 @@ enum { SIFIVE_U_UART1_IRQ = 4 }; +enum { +SIFIVE_U_CLOCK_FREQ =1000000000 +}; +#define SIFIVE_U_PLIC_HART_CONFIG "MS"#define SIFIVE_U_PLIC_NUM_SOURCES 127#define SIFIVE_U_PLIC_NUM_PRIORITIES 7
include/hw/riscv/spike.h +4 -0
@@ -42,6 +42,10 @@ enum { SPIKE_DRAM }; +enum { +SPIKE_CLOCK_FREQ =1000000000 +}; +#if defined(TARGET_RISCV32 )#define SPIKE_V1_09_1_CPU TYPE_RISCV_CPU_RV32GCSU_V1_09_1#define SPIKE_V1_10_0_CPU TYPE_RISCV_CPU_RV32GCSU_V1_10_0
include/hw/riscv/virt.h +4 -0
@@ -55,6 +55,10 @@ enum { VIRTIO_NDEV = 10 }; +enum { +VIRT_CLOCK_FREQ =1000000000 +}; +#define VIRT_PLIC_HART_CONFIG "MS"#define VIRT_PLIC_NUM_SOURCES 127#define VIRT_PLIC_NUM_PRIORITIES 7
Signature · 1 line
2.7.0
[Qemu-devel] [PULL 02/20] RISC-V: Make virt board description match spike
In reply to Michael ClarkThis makes 'qemu-system-riscv64 -machine help' output more tidy and consistent.
--- hw/riscv/virt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/riscv/virt.c +1 -1
@@ -407,7 +407,7 @@ static const TypeInfo riscv_virt_board_device = {static void riscv_virt_board_machine_init (MachineClass *mc) { - mc->desc ="RISC-V VirtIO Board (Privileged spec v1.10)" ; + mc->desc ="RISC-V VirtIO Board (Privileged ISA v1.10)" ; mc->init = riscv_virt_board_init; mc->max_cpus =8 ;/* hardcoded limit in BBL */ }
Signature · 1 line
2.7.0
[Qemu-devel] [PULL 03/20] RISC-V: Use ROM base address and size from memmap
In reply to Michael ClarkAnother case of replacing hard coded constants, this time referring to the definition in the virt machine's memmap.
--- hw/riscv/virt.c | 4 ++-- include/hw/riscv/virt.h | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-)
hw/riscv/virt.c +2 -2
@@ -341,11 +341,11 @@ static void riscv_virt_board_init(MachineState *machine) };/* copy in the reset vector */ -copy_le32_to_phys (ROM_BASE , reset_vec,sizeof (reset_vec)); +copy_le32_to_phys (memmap[VIRT_MROM ].base, reset_vec,sizeof (reset_vec));/* copy in the device tree */ qemu_fdt_dumpdtb (s->fdt, s->fdt_size); -cpu_physical_memory_write (ROM_BASE +sizeof (reset_vec), +cpu_physical_memory_write (memmap[VIRT_MROM ].base +sizeof (reset_vec), s->fdt, s->fdt_size);/* create PLIC hart topology configuration string */
include/hw/riscv/virt.h +0 -2
@@ -23,8 +23,6 @@#define VIRT (obj) \ OBJECT_CHECK(RISCVVirtState, (obj), TYPE_RISCV_VIRT_BOARD) -enum {ROM_BASE =0x1000 }; - typedef struct { /*< private >*/ SysBusDevice parent_obj;
Signature · 1 line
2.7.0
[Qemu-devel] [PULL 04/20] RISC-V: Remove identity_translate from load_elf
In reply to Michael ClarkWhen load_elf is called with NULL as an argument to the address translate callback, it does an identity translation. This commit removes the redundant identity_translate callback.
--- hw/riscv/sifive_e.c | 7 +------ hw/riscv/sifive_u.c | 7 +------ hw/riscv/spike.c | 7 +------ hw/riscv/virt.c | 7 +------ 4 files changed, 4 insertions(+), 24 deletions(-)
hw/riscv/sifive_e.c +1 -6
@@ -82,16 +82,11 @@ static void copy_le32_to_phys(hwaddr pa, uint32_t *rom, size_t len) } } -static uint64_t identity_translate (void *opaque,uint64_t addr) -{ -return addr; -} -static uint64_t load_kernel (const char *kernel_filename) {uint64_t kernel_entry, kernel_high; -if (load_elf (kernel_filename, identity_translate,NULL , +if (load_elf (kernel_filename,NULL ,NULL , &kernel_entry,NULL , &kernel_high,0 ,ELF_MACHINE ,1 ,0 ) <0 ) {error_report ("qemu: could not load kernel '%s'" , kernel_filename);
hw/riscv/sifive_u.c +1 -6
@@ -68,16 +68,11 @@ static void copy_le32_to_phys(hwaddr pa, uint32_t *rom, size_t len) } } -static uint64_t identity_translate (void *opaque,uint64_t addr) -{ -return addr; -} -static uint64_t load_kernel (const char *kernel_filename) {uint64_t kernel_entry, kernel_high; -if (load_elf (kernel_filename, identity_translate,NULL , +if (load_elf (kernel_filename,NULL ,NULL , &kernel_entry,NULL , &kernel_high,0 ,ELF_MACHINE ,1 ,0 ) <0 ) {error_report ("qemu: could not load kernel '%s'" , kernel_filename);
hw/riscv/spike.c +1 -6
@@ -59,16 +59,11 @@ static void copy_le32_to_phys(hwaddr pa, uint32_t *rom, size_t len) } } -static uint64_t identity_translate (void *opaque,uint64_t addr) -{ -return addr; -} -static uint64_t load_kernel (const char *kernel_filename) {uint64_t kernel_entry, kernel_high; -if (load_elf_ram_sym (kernel_filename, identity_translate,NULL , +if (load_elf_ram_sym (kernel_filename,NULL ,NULL , &kernel_entry,NULL , &kernel_high,0 ,ELF_MACHINE ,1 ,0 ,NULL , true, htif_symbol_callback) <0 ) {error_report ("qemu: could not load kernel '%s'" , kernel_filename);
hw/riscv/virt.c +1 -6
@@ -62,16 +62,11 @@ static void copy_le32_to_phys(hwaddr pa, uint32_t *rom, size_t len) } } -static uint64_t identity_translate (void *opaque,uint64_t addr) -{ -return addr; -} -static uint64_t load_kernel (const char *kernel_filename) {uint64_t kernel_entry, kernel_high; -if (load_elf (kernel_filename, identity_translate,NULL , +if (load_elf (kernel_filename,NULL ,NULL , &kernel_entry,NULL , &kernel_high,0 ,ELF_MACHINE ,1 ,0 ) <0 ) {error_report ("qemu: could not load kernel '%s'" , kernel_filename);
Signature · 1 line
2.7.0
[Qemu-devel] [PULL 05/20] RISC-V: Remove unused class definitions
In reply to Michael ClarkRemoves a whole lot of unnecessary boilerplate code. Machines don't need to be objects. The expansion of the SOC object model for the RISC-V machines will happen in the future as SiFive plans to add their FE310 and FU540 SOCs to QEMU. However, it seems that this present boilerplate is complete unnecessary.
--- hw/riscv/riscv_hart.c | 6 ------ hw/riscv/sifive_e.c | 25 ------------------------- hw/riscv/sifive_u.c | 25 ------------------------- hw/riscv/spike.c | 20 -------------------- hw/riscv/virt.c | 25 ------------------------- include/hw/riscv/sifive_e.h | 5 ----- include/hw/riscv/sifive_u.h | 5 ----- include/hw/riscv/spike.h | 7 ------- include/hw/riscv/virt.h | 5 ----- 9 files changed, 123 deletions(-)
hw/riscv/riscv_hart.c +0 -6
@@ -68,16 +68,10 @@ static void riscv_harts_class_init(ObjectClass *klass, void *data) dc->realize = riscv_harts_realize; } -static void riscv_harts_init (Object *obj) -{ -/* RISCVHartArrayState *s = SIFIVE_COREPLEX(obj); */ -} -static const TypeInfo riscv_harts_info = { .name =TYPE_RISCV_HART_ARRAY , .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (RISCVHartArrayState), - .instance_init = riscv_harts_init, .class_init = riscv_harts_class_init, };
hw/riscv/sifive_e.c +0 -25
@@ -194,24 +194,6 @@ static void riscv_sifive_e_init(MachineState *machine) } } -static int riscv_sifive_e_sysbus_device_init (SysBusDevice *sysbusdev) -{ -return 0 ; -} - -static void riscv_sifive_e_class_init (ObjectClass *klass,void *data) -{ -SysBusDeviceClass *k =SYS_BUS_DEVICE_CLASS (klass); - k->init = riscv_sifive_e_sysbus_device_init; -} - -static const TypeInfo riscv_sifive_e_device = { - .name =TYPE_SIFIVE_E , - .parent =TYPE_SYS_BUS_DEVICE , - .instance_size =sizeof (SiFiveEState), - .class_init = riscv_sifive_e_class_init, -}; -static void riscv_sifive_e_machine_init (MachineClass *mc) { mc->desc ="RISC-V Board compatible with SiFive E SDK" ;
@@ -220,10 +202,3 @@ static void riscv_sifive_e_machine_init(MachineClass *mc) }DEFINE_MACHINE ("sifive_e" , riscv_sifive_e_machine_init) - -static void riscv_sifive_e_register_types (void ) -{ -type_register_static (&riscv_sifive_e_device); -} - -type_init (riscv_sifive_e_register_types);
hw/riscv/sifive_u.c +0 -25
@@ -301,31 +301,6 @@ static void riscv_sifive_u_init(MachineState *machine) SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE); } -static int riscv_sifive_u_sysbus_device_init (SysBusDevice *sysbusdev) -{ -return 0 ; -} - -static void riscv_sifive_u_class_init (ObjectClass *klass,void *data) -{ -SysBusDeviceClass *k =SYS_BUS_DEVICE_CLASS (klass); - k->init = riscv_sifive_u_sysbus_device_init; -} - -static const TypeInfo riscv_sifive_u_device = { - .name =TYPE_SIFIVE_U , - .parent =TYPE_SYS_BUS_DEVICE , - .instance_size =sizeof (SiFiveUState), - .class_init = riscv_sifive_u_class_init, -}; - -static void riscv_sifive_u_register_types (void ) -{ -type_register_static (&riscv_sifive_u_device); -} - -type_init (riscv_sifive_u_register_types); -static void riscv_sifive_u_machine_init (MachineClass *mc) { mc->desc ="RISC-V Board compatible with SiFive U SDK" ;
hw/riscv/spike.c +0 -20
@@ -334,18 +334,6 @@ static void spike_v1_09_1_board_init(MachineState *machine) smp_cpus, SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE); } -static const TypeInfo spike_v_1_09_1_device = { - .name =TYPE_RISCV_SPIKE_V1_09_1_BOARD , - .parent =TYPE_SYS_BUS_DEVICE , - .instance_size =sizeof (SpikeState), -}; - -static const TypeInfo spike_v_1_10_0_device = { - .name =TYPE_RISCV_SPIKE_V1_10_0_BOARD , - .parent =TYPE_SYS_BUS_DEVICE , - .instance_size =sizeof (SpikeState), -}; -static void spike_v1_09_1_machine_init (MachineClass *mc) { mc->desc ="RISC-V Spike Board (Privileged ISA v1.9.1)" ;
@@ -363,11 +351,3 @@ static void spike_v1_10_0_machine_init(MachineClass *mc) DEFINE_MACHINE("spike_v1.9.1", spike_v1_09_1_machine_init)DEFINE_MACHINE ("spike_v1.10" , spike_v1_10_0_machine_init) - -static void riscv_spike_board_register_types (void ) -{ -type_register_static (&spike_v_1_09_1_device); -type_register_static (&spike_v_1_10_0_device); -} - -type_init (riscv_spike_board_register_types);
hw/riscv/virt.c +0 -25
@@ -382,24 +382,6 @@ static void riscv_virt_board_init(MachineState *machine) serial_hd(0), DEVICE_LITTLE_ENDIAN); } -static int riscv_virt_board_sysbus_device_init (SysBusDevice *sysbusdev) -{ -return 0 ; -} - -static void riscv_virt_board_class_init (ObjectClass *klass,void *data) -{ -SysBusDeviceClass *k =SYS_BUS_DEVICE_CLASS (klass); - k->init = riscv_virt_board_sysbus_device_init; -} - -static const TypeInfo riscv_virt_board_device = { - .name =TYPE_RISCV_VIRT_BOARD , - .parent =TYPE_SYS_BUS_DEVICE , - .instance_size =sizeof (RISCVVirtState), - .class_init = riscv_virt_board_class_init, -}; -static void riscv_virt_board_machine_init (MachineClass *mc) { mc->desc ="RISC-V VirtIO Board (Privileged ISA v1.10)" ;
@@ -408,10 +390,3 @@ static void riscv_virt_board_machine_init(MachineClass *mc) }DEFINE_MACHINE ("virt" , riscv_virt_board_machine_init) - -static void riscv_virt_board_register_types (void ) -{ -type_register_static (&riscv_virt_board_device); -} - -type_init (riscv_virt_board_register_types);
include/hw/riscv/sifive_e.h +0 -5
@@ -19,11 +19,6 @@ #ifndef HW_SIFIVE_E_H #define HW_SIFIVE_E_H -#define TYPE_SIFIVE_E "riscv.sifive_e" - -#define SIFIVE_E(obj) \ - OBJECT_CHECK(SiFiveEState, (obj), TYPE_SIFIVE_E) - typedef struct SiFiveEState { /*< private >*/ SysBusDevice parent_obj;
include/hw/riscv/sifive_u.h +0 -5
@@ -19,11 +19,6 @@ #ifndef HW_SIFIVE_U_H #define HW_SIFIVE_U_H -#define TYPE_SIFIVE_U "riscv.sifive_u" - -#define SIFIVE_U(obj) \ - OBJECT_CHECK(SiFiveUState, (obj), TYPE_SIFIVE_U) - typedef struct SiFiveUState { /*< private >*/ SysBusDevice parent_obj;
include/hw/riscv/spike.h +0 -7
@@ -19,12 +19,6 @@ #ifndef HW_SPIKE_H #define HW_SPIKE_H -#define TYPE_RISCV_SPIKE_V1_09_1_BOARD "riscv.spike_v1_9_1" -#define TYPE_RISCV_SPIKE_V1_10_0_BOARD "riscv.spike_v1_10" - -#define SPIKE(obj) \ - OBJECT_CHECK(SpikeState, (obj), TYPE_RISCV_SPIKE_BOARD) - typedef struct { /*< private >*/ SysBusDevice parent_obj;
@@ -35,7 +29,6 @@ typedef struct {int fdt_size; } SpikeState; -enum {SPIKE_MROM ,SPIKE_CLINT ,
include/hw/riscv/virt.h +0 -5
@@ -19,10 +19,6 @@ #ifndef HW_VIRT_H #define HW_VIRT_H -#define TYPE_RISCV_VIRT_BOARD "riscv.virt" -#define VIRT(obj) \ - OBJECT_CHECK(RISCVVirtState, (obj), TYPE_RISCV_VIRT_BOARD) - typedef struct { /*< private >*/ SysBusDevice parent_obj;
@@ -45,7 +41,6 @@ enum {VIRT_DRAM }; -enum {UART0_IRQ =10 ,VIRTIO_IRQ =1 ,/* 1 to 8 */
Signature · 1 line
2.7.0
[Qemu-devel] [PULL 06/20] RISC-V: Include instruction hex in disassembly
In reply to Michael ClarkThis was added to help debug issues using -d in_asm. It is useful to see the instruction bytes, as one can detect if one is trying to execute ASCII or device-tree magic.
--- disas/riscv.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-)
disas/riscv.c +20 -19
@@ -2769,25 +2769,6 @@ static void format_inst(char *buf, size_t buflen, size_t tab, rv_decode *dec)char tmp[64 ];const char *fmt; -if (dec->op == rv_op_illegal) { -size_t len =inst_length (dec->inst); -switch (len) { -case 2 : -snprintf (buf, buflen,"(0x%04" PRIx64")" , dec->inst); -break ; -case 4 : -snprintf (buf, buflen,"(0x%08" PRIx64")" , dec->inst); -break ; -case 6 : -snprintf (buf, buflen,"(0x%012" PRIx64")" , dec->inst); -break ; -default : -snprintf (buf, buflen,"(0x%016" PRIx64")" , dec->inst); -break ; - } -return ; - } - fmt = opcode_data[dec->op].format;while (*fmt) {switch (*fmt) {
@@ -3004,6 +2985,11 @@ disasm_inst(char *buf, size_t buflen, rv_isa isa, uint64_t pc, rv_inst inst)format_inst (buf, buflen,16 , &dec); } +#define INST_FMT_2 "%04" PRIx64 " " +#define INST_FMT_4 "%08" PRIx64 " " +#define INST_FMT_6 "%012" PRIx64 " " +#define INST_FMT_8 "%016" PRIx64 " " +static int print_insn_riscv (bfd_vma memaddr,struct disassemble_info *info,rv_isa isa) {
@@ -3031,6 +3017,21 @@ print_insn_riscv(bfd_vma memaddr, struct disassemble_info *info, rv_isa isa) } } +switch (len) { +case 2 : + (*info->fprintf_func)(info->stream,INST_FMT_2 , inst); +break ; +case 4 : + (*info->fprintf_func)(info->stream,INST_FMT_4 , inst); +break ; +case 6 : + (*info->fprintf_func)(info->stream,INST_FMT_6 , inst); +break ; +default : + (*info->fprintf_func)(info->stream,INST_FMT_8 , inst); +break ; + } +disasm_inst (buf,sizeof (buf), isa, memaddr, inst); (*info->fprintf_func)(info->stream,"%s" , buf);
Signature · 1 line
2.7.0
[Qemu-devel] [PULL 07/20] RISC-V: Fix missing break statement in disassembler
In reply to Michael ClarkThis fixes an issue when disassembling rv128 c.sqsp, where the code erroneously fell through to c.swsp.
--- disas/riscv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
disas/riscv.c +2 -1
@@ -1470,8 +1470,9 @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)if (isa == rv128) { op = rv_op_c_sqsp; }else { - op = rv_op_c_fsdsp;break ; + op = rv_op_c_fsdsp; } +break ;case 6 : op = rv_op_c_swsp;break ;case 7 :if (isa == rv32) {
Signature · 1 line
2.7.0
[Qemu-devel] [PULL 08/20] RISC-V: Make some header guards more specific
In reply to Michael Clark--- include/hw/riscv/spike.h | 4 ++-- include/hw/riscv/virt.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
include/hw/riscv/spike.h +2 -2
@@ -16,8 +16,8 @@* this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef HW_SPIKE_H -#define HW_SPIKE_H +#ifndef HW_RISCV_SPIKE_H +#define HW_RISCV_SPIKE_H typedef struct { /*< private >*/
include/hw/riscv/virt.h +2 -2
@@ -16,8 +16,8 @@* this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef HW_VIRT_H -#define HW_VIRT_H +#ifndef HW_RISCV_VIRT_H +#define HW_RISCV_VIRT_H typedef struct { /*< private >*/
Signature · 1 line
2.7.0
[Qemu-devel] [PULL 09/20] RISC-V: Make virt header comment title consistent
In reply to Michael Clark--- include/hw/riscv/virt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/hw/riscv/virt.h +1 -1
@@ -1,5 +1,5 @@/* -* SiFive VirtIO Board +* QEMU RISC-V VirtIO machine interface * * Copyright (c) 2017 SiFive, Inc. *
Signature · 1 line
2.7.0
[Qemu-devel] [PULL 10/20] RISC-V: Remove EM_RISCV ELF_MACHINE indirection
In reply to Michael ClarkPointless indirection. Other ports use EM_ constants directly.
--- hw/riscv/sifive_e.c | 2 +- hw/riscv/sifive_u.c | 2 +- hw/riscv/spike.c | 2 +- hw/riscv/virt.c | 2 +- target/riscv/cpu.h | 1 - 5 files changed, 4 insertions(+), 5 deletions(-)
hw/riscv/sifive_e.c +1 -1
@@ -88,7 +88,7 @@ static uint64_t load_kernel(const char *kernel_filename)if (load_elf (kernel_filename,NULL ,NULL , &kernel_entry,NULL , &kernel_high, -0 ,ELF_MACHINE ,1 ,0 ) <0 ) { +0 ,EM_RISCV ,1 ,0 ) <0 ) {error_report ("qemu: could not load kernel '%s'" , kernel_filename);exit (1 ); }
hw/riscv/sifive_u.c +1 -1
@@ -74,7 +74,7 @@ static uint64_t load_kernel(const char *kernel_filename)if (load_elf (kernel_filename,NULL ,NULL , &kernel_entry,NULL , &kernel_high, -0 ,ELF_MACHINE ,1 ,0 ) <0 ) { +0 ,EM_RISCV ,1 ,0 ) <0 ) {error_report ("qemu: could not load kernel '%s'" , kernel_filename);exit (1 ); }
hw/riscv/spike.c +1 -1
@@ -64,7 +64,7 @@ static uint64_t load_kernel(const char *kernel_filename)uint64_t kernel_entry, kernel_high;if (load_elf_ram_sym (kernel_filename,NULL ,NULL , - &kernel_entry,NULL , &kernel_high,0 ,ELF_MACHINE ,1 ,0 , + &kernel_entry,NULL , &kernel_high,0 ,EM_RISCV ,1 ,0 ,NULL , true, htif_symbol_callback) <0 ) {error_report ("qemu: could not load kernel '%s'" , kernel_filename);exit (1 );
hw/riscv/virt.c +1 -1
@@ -68,7 +68,7 @@ static uint64_t load_kernel(const char *kernel_filename)if (load_elf (kernel_filename,NULL ,NULL , &kernel_entry,NULL , &kernel_high, -0 ,ELF_MACHINE ,1 ,0 ) <0 ) { +0 ,EM_RISCV ,1 ,0 ) <0 ) {error_report ("qemu: could not load kernel '%s'" , kernel_filename);exit (1 ); }
target/riscv/cpu.h +0 -1
@@ -34,7 +34,6 @@#define TCG_GUEST_DEFAULT_MO 0 -#define ELF_MACHINE EM_RISCV#define CPUArchState struct CPURISCVState#include "qemu-common.h"
Signature · 1 line
2.7.0
[Qemu-devel] [PULL 11/20] RISC-V: Remove erroneous comment from translate.c
In reply to Michael Clark--- target/riscv/translate.c | 1 - 1 file changed, 1 deletion(-)
target/riscv/translate.c +0 -1
@@ -280,7 +280,6 @@ static void gen_arith(DisasContext *ctx, uint32_t opc, int rd, int rs1,tcg_gen_andi_tl (source2, source2,0x1F );tcg_gen_sar_tl (source1, source1, source2);break ; -/* fall through to SRA */ #endif case OPC_RISC_SRA :tcg_gen_andi_tl (source2, source2,TARGET_LONG_BITS -1 );
Signature · 1 line
2.7.0
[Qemu-devel] [PULL 12/20] RISC-V: Update E and I extension order
In reply to Michael ClarkSection 22.8 Subset Naming Convention of the RISC-V ISA Specification defines the canonical order for extensions in the ISA string. It is silent on the position of the E extension however E is a substitute for I so it must come early in the extension list order. A comment is added to state E and I are mutually exclusive, as the E extension will be added to the RISC-V port in the future.
--- target/riscv/cpu.c | 2 +- target/riscv/cpu.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
target/riscv/cpu.c +1 -1
@@ -26,7 +26,7 @@/* RISC-V CPU definitions */ -static const char riscv_exts[26 ] ="IMAFDQECLBJTPVNSUHKORWXYZG" ; +static const char riscv_exts[26 ] ="IEMAFDQCLBJTPVNSUHKORWXYZG" ;const char *const riscv_int_regnames[] = {"zero" ,"ra " ,"sp " ,"gp " ,"tp " ,"t0 " ,"t1 " ,"t2 " ,
target/riscv/cpu.h +1 -0
@@ -71,6 +71,7 @@#define RV (x) ((target_ulong)1 << (x - 'A'))#define RVI RV('I') +#define RVE RV('E')/* E and I are mutually exclusive */ #define RVM RV('M')#define RVA RV('A')#define RVF RV('F')
Signature · 1 line
2.7.0
[Qemu-devel] [PULL 13/20] RISC-V: Hardwire satp to 0 for no-mmu case
In reply to Michael Clarksatp is WARL so it should not trap on illegal writes, rather it can be hardwired to zero and silently ignore illegal writes.
It seems the RISC-V WARL behaviour is preferred to having to trap overhead versus simply reading back the value and checking if the write took (saves hundreds of cycles and more complex trap handling code).
--- target/riscv/op_helper.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
target/riscv/op_helper.c +5 -2
@@ -255,7 +255,7 @@ void csr_write_helper(CPURISCVState *env, target_ulong val_to_write, }case CSR_SATP :/* CSR_SPTBR */ {if (!riscv_feature (env,RISCV_FEATURE_MMU )) { - goto do_illegal; +break ; }if (env->priv_ver <=PRIV_VERSION_1_09_1 && (val_to_write ^ env->sptbr)) {
@@ -465,7 +465,10 @@ target_ulong csr_read_helper(CPURISCVState *env, target_ulong csrno)return env->scounteren;case CSR_SCAUSE :return env->scause; -case CSR_SPTBR : +case CSR_SATP :/* CSR_SPTBR */ +if (!riscv_feature (env,RISCV_FEATURE_MMU )) { +return 0 ; + }if (env->priv_ver >=PRIV_VERSION_1_10_0 ) {return env->satp; }else {
Signature · 1 line
2.7.0
[Qemu-devel] [PULL 14/20] RISC-V: Clear mtval/stval on exceptions without info
In reply to Michael Clarkmtval/stval must be set on all exceptions but zero is a legal value if there is no exception specific info. Placing the instruction bytes for illegal instruction exceptions in mtval/stval is an optional feature and is currently not supported by QEMU RISC-V.
--- target/riscv/helper.c | 8 ++++++++ 1 file changed, 8 insertions(+)
target/riscv/helper.c +8 -0
@@ -466,6 +466,10 @@ void riscv_cpu_do_interrupt(CPUState *cs) ": badaddr 0x" TARGET_FMT_lx, env->mhartid, env->badaddr); } env->sbadaddr = env->badaddr; + }else { +/* otherwise we must clear sbadaddr/stval +* todo: support populating stval on illegal instructions */ + env->sbadaddr =0 ; }target_ulong s = env->mstatus;
@@ -487,6 +491,10 @@ void riscv_cpu_do_interrupt(CPUState *cs) ": badaddr 0x" TARGET_FMT_lx, env->mhartid, env->badaddr); } env->mbadaddr = env->badaddr; + }else { +/* otherwise we must clear mbadaddr/mtval +* todo: support populating mtval on illegal instructions */ + env->mbadaddr =0 ; }target_ulong s = env->mstatus;
Signature · 1 line
2.7.0
[Qemu-devel] [PULL 15/20] RISC-V: Allow S-mode mxr access when priv ISA >= v1.10
In reply to Michael ClarkThe mstatus.MXR alias in sstatus should only be writable by S-mode if the privileged ISA version >= v1.10. Also MXR was masked in sstatus CSR read but not sstatus CSR writes. Now we correctly mask sstatus.mxr in both read and write.
--- target/riscv/op_helper.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
target/riscv/op_helper.c +5 -2
@@ -234,7 +234,10 @@ void csr_write_helper(CPURISCVState *env, target_ulong val_to_write,target_ulong ms = env->mstatus;target_ulong mask =SSTATUS_SIE |SSTATUS_SPIE |SSTATUS_UIE |SSTATUS_UPIE |SSTATUS_SPP |SSTATUS_FS |SSTATUS_XS - |SSTATUS_SUM |SSTATUS_MXR |SSTATUS_SD ; + |SSTATUS_SUM |SSTATUS_SD ; +if (env->priv_ver >=PRIV_VERSION_1_10_0 ) { + mask |=SSTATUS_MXR ; + } ms = (ms & ~mask) | (val_to_write & mask);csr_write_helper (env, ms,CSR_MSTATUS );break ;
@@ -441,7 +444,7 @@ target_ulong csr_read_helper(CPURISCVState *env, target_ulong csrno)case CSR_SSTATUS : {target_ulong mask =SSTATUS_SIE |SSTATUS_SPIE |SSTATUS_UIE |SSTATUS_UPIE |SSTATUS_SPP |SSTATUS_FS |SSTATUS_XS - |SSTATUS_SUM |SSTATUS_SD ; + |SSTATUS_SUM |SSTATUS_SD ;if (env->priv_ver >=PRIV_VERSION_1_10_0 ) { mask |=SSTATUS_MXR ; }
Signature · 1 line
2.7.0
[Qemu-devel] [PULL 16/20] RISC-V: Use [ms]counteren CSRs when priv ISA >= v1.10
In reply to Michael ClarkPrivileged ISA v1.9.1 defines mscounteren and mucounteren:
* mscounteren contains a mask of counters available to S-mode
* mucounteren contains a mask of counters available to U-mode
Privileged ISA v1.10 defines mcounteren and scounteren:
* mcounteren contains a mask of counters available to S-mode
* scounteren contains a mask of counters available to U-mode
mcounteren and scounteren CSR registers were implemented however they were not honoured for counter accesses when the privilege ISA was >= v1.10. This fix solves the issue by coalescing the counter enable registers. In addition the code now generates illegal instruction exceptions for accesses to the counter enabled registers depending on the privileged ISA version.
- Coalesce mscounteren and mcounteren into one variable
- Coalesce mucounteren and scounteren into one variable
- Makes mcounteren and scounteren CSR accesses generate illegal instructions when the privileged ISA <= v1.9.1
- Makes mscounteren and mucounteren CSR accesses generate illegal instructions when the privileged ISA >= v1.10
--- target/riscv/cpu.h | 6 ++--- target/riscv/op_helper.c | 62 +++++++++++++++++++++++++++++++++++++----------- 2 files changed, 50 insertions(+), 18 deletions(-)
target/riscv/cpu.h +2 -4
@@ -151,10 +151,8 @@ struct CPURISCVState {target_ulong mcause;target_ulong mtval;/* since: priv-1.10.0 */ -uint32_t mucounteren; -uint32_t mscounteren; -target_ulong scounteren;/* since: priv-1.10.0 */ -target_ulong mcounteren;/* since: priv-1.10.0 */ +target_ulong scounteren; +target_ulong mcounteren;target_ulong sscratch;target_ulong mscratch;
target/riscv/op_helper.c +48 -14
112 lines not on this page · raw message
Signature · 1 line
2.7.0
[Qemu-devel] [PULL 17/20] RISC-V: Add mcycle/minstret support for -icount auto
In reply to Michael ClarkPreviously the mycycle/minstret CSRs and rdcycle/rdinstret psuedo instructions would return the time as a proxy for an increasing instruction counter in the absence of having a precise instruction count. If QEMU is invoked with -icount, the mcycle/minstret CSRs and rdcycle/rdinstret psuedo instructions will return the instruction count.
--- target/riscv/op_helper.c | 28 ++++++++++++++++++++++++++-- target/riscv/translate.c | 2 ++ 2 files changed, 28 insertions(+), 2 deletions(-)
target/riscv/op_helper.c +26 -2
@@ -434,25 +434,49 @@ target_ulong csr_read_helper(CPURISCVState *env, target_ulong csrno)case CSR_INSTRET :case CSR_CYCLE :if (ctr_ok) { +#if !defined(CONFIG_USER_ONLY ) +if (use_icount) { +return cpu_get_icount (); + }else { +return cpu_get_host_ticks (); + } +#else return cpu_get_host_ticks (); +#endif }break ;#if defined(TARGET_RISCV32 )case CSR_INSTRETH :case CSR_CYCLEH :if (ctr_ok) { +#if !defined(CONFIG_USER_ONLY ) +if (use_icount) { +return cpu_get_icount () >>32 ; + }else { +return cpu_get_host_ticks () >>32 ; + } +#else return cpu_get_host_ticks () >>32 ; +#endif }break ;#endif #ifndef CONFIG_USER_ONLY case CSR_MINSTRET :case CSR_MCYCLE : -return cpu_get_host_ticks (); +if (use_icount) { +return cpu_get_icount (); + }else { +return cpu_get_host_ticks (); + }case CSR_MINSTRETH :case CSR_MCYCLEH :#if defined(TARGET_RISCV32 ) -return cpu_get_host_ticks () >>32 ; +if (use_icount) { +return cpu_get_icount () >>32 ; + }else { +return cpu_get_host_ticks () >>32 ; + }#endif break ;case CSR_MUCOUNTEREN :
target/riscv/translate.c +2 -0
@@ -1390,6 +1390,7 @@ static void gen_system(CPURISCVState *env, DisasContext *ctx, uint32_t opc,break ;default :tcg_gen_movi_tl (imm_rs1, rs1); +gen_io_start ();switch (opc) {case OPC_RISC_CSRRW :gen_helper_csrrw (dest, cpu_env, source1, csr_store);
@@ -1413,6 +1414,7 @@ static void gen_system(CPURISCVState *env, DisasContext *ctx, uint32_t opc,gen_exception_illegal (ctx);return ; } +gen_io_end ();gen_set_gpr (rd, dest);/* end tb since we may be changing priv modes, to get mmu_index right */ tcg_gen_movi_tl (cpu_pc, ctx->next_pc);
Signature · 1 line
2.7.0
[Qemu-devel] [PULL 18/20] RISC-V: Make mtvec/stvec ignore vectored traps
In reply to Michael ClarkVectored traps for asynchrounous interrupts are optional. The mtvec/stvec mode field is WARL and hence does not trap if an illegal value is written. Illegal values are ignored.
Later we can add RISCV_FEATURE_VECTORED_TRAPS however until then the correct behavior for WARL (Write Any, Read Legal) fields is to drop writes to unsupported bits.
--- target/riscv/op_helper.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
target/riscv/op_helper.c +8 -6
@@ -287,11 +287,12 @@ void csr_write_helper(CPURISCVState *env, target_ulong val_to_write, env->sepc = val_to_write;break ;case CSR_STVEC : -if (val_to_write &1 ) { +/* bits [1:0] encode mode; 0 = direct, 1 = vectored, 2 >= reserved */ +if ((val_to_write &3 ) ==0 ) { + env->stvec = val_to_write >>2 <<2 ; + }else {qemu_log_mask (LOG_UNIMP ,"CSR_STVEC: vectored traps not supported" ); - goto do_illegal; } - env->stvec = val_to_write >>2 <<2 ;break ;case CSR_SCOUNTEREN :if (env->priv_ver >=PRIV_VERSION_1_10_0 ) {
@@ -313,11 +314,12 @@ void csr_write_helper(CPURISCVState *env, target_ulong val_to_write, env->mepc = val_to_write;break ;case CSR_MTVEC : -if (val_to_write &1 ) { +/* bits [1:0] indicate mode; 0 = direct, 1 = vectored, 2 >= reserved */ +if ((val_to_write &3 ) ==0 ) { + env->mtvec = val_to_write >>2 <<2 ; + }else {qemu_log_mask (LOG_UNIMP ,"CSR_MTVEC: vectored traps not supported" ); - goto do_illegal; } - env->mtvec = val_to_write >>2 <<2 ;break ;case CSR_MCOUNTEREN :if (env->priv_ver >=PRIV_VERSION_1_10_0 ) {
Signature · 1 line
2.7.0
[Qemu-devel] [PULL 19/20] RISC-V: No traps on writes to misa, minstret, mcycle
In reply to Michael ClarkThese fields are marked WARL (Write Any Values, Reads Legal Values) in the RISC-V Privileged Architecture Specification so instead of raising exceptions, illegal writes are silently dropped.
--- target/riscv/op_helper.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
target/riscv/op_helper.c +13 -12
@@ -213,17 +213,19 @@ void csr_write_helper(CPURISCVState *env, target_ulong val_to_write,break ; }case CSR_MINSTRET : -qemu_log_mask (LOG_UNIMP ,"CSR_MINSTRET: write not implemented" ); - goto do_illegal; +/* minstret is WARL so unsupported writes are ignored */ +break ;case CSR_MCYCLE : -qemu_log_mask (LOG_UNIMP ,"CSR_MCYCLE: write not implemented" ); - goto do_illegal; +/* mcycle is WARL so unsupported writes are ignored */ +break ; +#if defined(TARGET_RISCV32 )case CSR_MINSTRETH : -qemu_log_mask (LOG_UNIMP ,"CSR_MINSTRETH: write not implemented" ); - goto do_illegal; +/* minstreth is WARL so unsupported writes are ignored */ +break ;case CSR_MCYCLEH : -qemu_log_mask (LOG_UNIMP ,"CSR_MCYCLEH: write not implemented" ); - goto do_illegal; +/* mcycleh is WARL so unsupported writes are ignored */ +break ; +#endif case CSR_MUCOUNTEREN :if (env->priv_ver <=PRIV_VERSION_1_09_1 ) { env->scounteren = val_to_write;
@@ -337,10 +339,9 @@ void csr_write_helper(CPURISCVState *env, target_ulong val_to_write,case CSR_MBADADDR : env->mbadaddr = val_to_write;break ; -case CSR_MISA : { -qemu_log_mask (LOG_UNIMP ,"CSR_MISA: misa writes not supported" ); - goto do_illegal; - } +case CSR_MISA : +/* misa is WARL so unsupported writes are ignored */ +break ;case CSR_PMPCFG0 :case CSR_PMPCFG1 :case CSR_PMPCFG2 :
Signature · 1 line
2.7.0
[Qemu-devel] [PULL 20/20] RISC-V: Mark ROM read-only after copying in code
In reply to Michael ClarkThe sifive_u machine already marks its ROM readonly however it has the wrong base address for its mask ROM. This patch fixes the sifive_u mask ROM base address.
This commit makes all other boards consistently use mask_rom as the variable name for their ROMs. Boards that use device tree now check that that the device tree fits in the assigned ROM space using the new qemu_fdt_totalsize(void *fdt) interface, adding a bounds check and error message. This can detect truncation.
--- hw/riscv/sifive_e.c | 20 +++++++--------- hw/riscv/sifive_u.c | 51 +++++++++++++++++++++------------------ hw/riscv/spike.c | 69 +++++++++++++++++++++++++++++++---------------------- hw/riscv/virt.c | 43 ++++++++++++++++++--------------- 4 files changed, 101 insertions(+), 82 deletions(-)
hw/riscv/sifive_e.c +8 -12
@@ -74,14 +74,6 @@ static const struct MemmapEntry { [SIFIVE_E_DTIM] = { 0x80000000, 0x4000 } }; -static void copy_le32_to_phys (hwaddr pa,uint32_t *rom,size_t len) -{ -int i; -for (i =0 ; i < (len >>2 ); i++) { -stl_phys (&address_space_memory, pa + (i <<2 ), rom[i]); - } -} -static uint64_t load_kernel (const char *kernel_filename) {uint64_t kernel_entry, kernel_high;
@@ -112,6 +104,7 @@ static void riscv_sifive_e_init(MachineState *machine)MemoryRegion *main_mem =g_new (MemoryRegion,1 );MemoryRegion *mask_rom =g_new (MemoryRegion,1 );MemoryRegion *xip_mem =g_new (MemoryRegion,1 ); +int i;/* Initialize SOC */ object_initialize (&s->soc,sizeof (s->soc),TYPE_RISCV_HART_ARRAY );
@@ -131,7 +124,7 @@ static void riscv_sifive_e_init(MachineState *machine) memmap[SIFIVE_E_DTIM].base, main_mem);/* Mask ROM */ -memory_region_init_ram (mask_rom,NULL ,"riscv.sifive.e.mrom" , +memory_region_init_rom (mask_rom,NULL ,"riscv.sifive.e.mrom" , memmap[SIFIVE_E_MROM ].size, &error_fatal);memory_region_add_subregion (sys_mem, memmap[SIFIVE_E_MROM ].base, mask_rom);
@@ -185,9 +178,12 @@ static void riscv_sifive_e_init(MachineState *machine) 0x00028067, /* 0x1004: jr t0 */ }; -/* copy in the reset vector */ -copy_le32_to_phys (memmap[SIFIVE_E_MROM ].base, reset_vec,sizeof (reset_vec)); -memory_region_set_readonly (mask_rom, true); +/* copy in the reset vector in little_endian byte order */ +for (i =0 ; i <sizeof (reset_vec) >>2 ; i++) { + reset_vec[i] =cpu_to_le32 (reset_vec[i]); + } +rom_add_blob_fixed_as ("mrom.reset" , reset_vec,sizeof (reset_vec), + memmap[SIFIVE_E_MROM ].base, &address_space_memory);if (machine->kernel_filename) {load_kernel (machine->kernel_filename);
hw/riscv/sifive_u.c +28 -23
102 lines not on this page · raw message
hw/riscv/spike.c +41 -28
127 lines not on this page · raw message
hw/riscv/virt.c +24 -19
80 lines not on this page · raw message
Signature · 1 line
2.7.0
Peter Maydell
AppliedQuoted 35 lines · Michael Clark
The following changes since commit
c8b7e627b4269a3bc3ae41d9f420547a47e6d9b9:Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2018-05-04' into staging (2018-05-04 14:42:46 +0100)
are available in the git repository at:
https://github.com/riscv/riscv-qemu.git tags/riscv-qemu-2.13-pull-20180506
for you to fetch changes up to
5aec3247c190f10654250203a1742490ae7343a2:RISC-V: Mark ROM read-only after copying in code (2018-05-06 10:54:21 +1200)
----------------------------------------------------------------
RISC-V: QEMU 2.13 Privileged ISA emulation updatesSeveral code cleanups, minor specification conformance changes, fixes to make ROM read-only and add device-tree size checks.
* Honour privileged ISA v1.10 counter enable CSRs.
* Implements WARL behavior for CSRs that don't support writes
* Past behavior of raising traps was non-conformant with the RISC-V Privileged ISA Specification v1.10.
* Allow S-mode access to sstatus.MXR when priv ISA >= v1.10
* Sets mtval/stval to zero on exceptions without addresses
* Past behavior of leaving the last value was non-conformant with the RISC-V Privileged ISA Specition v1.10. mtval/stval must be set on all exceptions; to zero if not supported.
* Make ROMs read-only and implement device-tree size checks
* Usesmemory_region_init_romandrom_add_blob_fixed_as
* Adds hexidecimal instruction bytes to disassembly output.
* Fixes missing break statement for rv128 disassembly.
* Several code cleanups
* Replacing hard-coded constants with enums
* Dead-code elimination
Quoted 3 lines
This is an incremental pull that contains 20 reviewed changes out of 38 changes currently queued in the qemu-2.13-for-upstream branch.
Applied, thanks.
-- PMM
Quoted 40 lines · Peter Maydell
Quoted 1 line · Michael Clark
The following changes since commit
c8b7e627b4269a3bc3ae41d9f42054
7a47e6d9b9:Quoted 2 lines
Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2018-05-04'
into staging (2018-05-04 14:42:46 +0100)
Quoted 4 lines
are available in the git repository at:
https://github.com/riscv/riscv-qemu.git tags/riscv-qemu-2.13-pull-
20180506
Quoted 4 lines
for you to fetch changes up to
5aec3247c190f10654250203a1742490ae7343a2:RISC-V: Mark ROM read-only after copying in code (2018-05-06 10:54:21
+1200)
Quoted 24 lines
----------------------------------------------------------------
RISC-V: QEMU 2.13 Privileged ISA emulation updatesSeveral code cleanups, minor specification conformance changes, fixes to make ROM read-only and add device-tree size checks.
* Honour privileged ISA v1.10 counter enable CSRs.
* Implements WARL behavior for CSRs that don't support writes
* Past behavior of raising traps was non-conformant with the RISC-V Privileged ISA Specification v1.10.
* Allow S-mode access to sstatus.MXR when priv ISA >= v1.10
* Sets mtval/stval to zero on exceptions without addresses
* Past behavior of leaving the last value was non-conformant with the RISC-V Privileged ISA Specition v1.10. mtval/stval must be set on all exceptions; to zero if not supported.
* Make ROMs read-only and implement device-tree size checks
* Usesmemory_region_init_romandrom_add_blob_fixed_as
* Adds hexidecimal instruction bytes to disassembly output.
* Fixes missing break statement for rv128 disassembly.
* Several code cleanups
* Replacing hard-coded constants with enums
* Dead-code elimination
Quoted 6 lines
Quoted 3 lines
This is an incremental pull that contains 20 reviewed changes out of 38 changes currently queued in the qemu-2.13-for-upstream branch.
Applied, thanks.
Thanks!
I didn't include qemu-stable on this series as I simply hadn't spent the time to locally test the issue with 'sifive_u' that Alastair mentioned. I've now locally reproduced Alastair's results confirming that the last commit in this series, namely "RISC-V: Mark ROM read-only after copying in code", fixes the 'sifive_u' board.
-
https://git.qemu.org/?p=qemu.git;a=commit;h=5aec3247c190f10654250203a1742490ae7343a2
There are however several other usability issues and bugs fixess in this series that could be considered for 'qemu-stable'.
- "RISC-V: Mark ROM read-only after copying in code" fixes the 'sifive_u' board issue (bug fix)
- "RISC-V: No traps on writes to misa,minstret,mcycle" fixes a case where an illegal instruction should not be generated (bug fix - misa write bug was hit by Andes Technology)
- "RISC-V: Make mtvec/stvec ignore vectored traps" fixes a case where an illegal instruction should not be generated (bug fix - not hit yet, but nevertheless is a fix)
- "RISC-V: Use [ms]counteren CSRs when priv ISA >= v1.10" fixes the counter enable CSRs, so they actually work (bug fix - hit by someone working on 'perf' for riscv-linux)
- "RISC-V: Include instruction hex in disassembly" adds instruction bytes to disassembly to improbe usability, and was on the list before soft-freeze (small usability issue)
- "RISC-V: Make virt board description match spike" makes the -help listing use consistent naming for privileged ISA version (small usability issue)
The rest of the series are the innocuous fixes and code cleanups (replacing constants with enums, etc) that had been on the list mid-March, with the exception of "RISC-V: Fix missing break statement in disassembler" which fixes the rv128 disassembly issue picked up recently by coverity and the "RISC-V: Add mcycle/minstret support for -icount auto" is a small new feature.
It would be safe to import the tag as the cleanup commits or I can selectively backport changes. The issue is the fixes depending on context of the cleanup commits early in the series. The sifive_u fix: "RISC-V: Mark ROM read-only after copying in code" depends on diff context from "RISC-V:
Remove identity_translate from load_elf" and "RISC-V: Use ROM base address and size from memmap" which were both code cleanups.
The question is whether code cleanups can come into qemu-stable (i.e. merge this tag to stable) or whether we should cherry-pick and solve merge conflicts to get the minimal set of commits with what we classify as important fixes or usability issue into qemu-stable. The most essential would be to just backport "RISC-V: Mark ROM read-only after copying in code" as it makes the 'sifive_u' board usable. The others are nice-to-have.
This first 20 patch series deliberately include low risk changes focused on spec conformance issues, minor usabiliy issues, some code cleanups, with the exception of the ROM bug actually fixing the 'sifive_u' board. I have been using git rebase to move the smaller fixes earlier in the series.
Richard, what changes to you think you would classify as being suitable for qemu-stable? These changes have also been quite extensively tested with SMP Linux running Fedora. I'm building GCC and QEMU in an MTTCG multi-core RISC-V QEMU 'virt' instance, along with testing the 'spike' and 'sifive_e' and now 'sifive_u' boards with Linux boots.
Thanks,
Michael.