Skip to content

Commit 399e79d

Browse files
Corey Whartongalak
authored andcommitted
qemu: Add support for changing CPU type in sifive_e machine.
This change allows the sifive_e machine to run with different CPU targets to enable different ISA entensions. To that end it also introduces a new sifive-e34 CPU type which provides the same ISA as sifive-e31, with the addition of the single precision floating-point extension (f). The default CPU for the sifive_e machine is unchanged. Signed-off-by: Corey Wharton <[email protected]>
1 parent dd250f2 commit 399e79d

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
From 6bee5cdeb7ae297a997e23ab671beaaf3b3ebf58 Mon Sep 17 00:00:00 2001
2+
From: Corey Wharton <[email protected]>
3+
Date: Thu, 12 Mar 2020 15:38:16 -0700
4+
Subject: [PATCH v2 1/2] riscv: sifive_e: Support changing CPU type
5+
6+
Allows the CPU to be changed from the default via the -cpu command
7+
line option.
8+
9+
Signed-off-by: Corey Wharton <[email protected]>
10+
Reviewed-by: Bin Meng <[email protected]>
11+
Reviewed-by: Alistair Francis <[email protected]>
12+
---
13+
hw/riscv/sifive_e.c | 3 ++-
14+
1 file changed, 2 insertions(+), 1 deletion(-)
15+
16+
diff --git a/hw/riscv/sifive_e.c b/hw/riscv/sifive_e.c
17+
index a254cad489..b0a611adb9 100644
18+
--- a/hw/riscv/sifive_e.c
19+
+++ b/hw/riscv/sifive_e.c
20+
@@ -123,7 +123,7 @@ static void riscv_sifive_e_soc_init(Object *obj)
21+
object_initialize_child(obj, "cpus", &s->cpus,
22+
sizeof(s->cpus), TYPE_RISCV_HART_ARRAY,
23+
&error_abort, NULL);
24+
- object_property_set_str(OBJECT(&s->cpus), SIFIVE_E_CPU, "cpu-type",
25+
+ object_property_set_str(OBJECT(&s->cpus), ms->cpu_type, "cpu-type",
26+
&error_abort);
27+
object_property_set_int(OBJECT(&s->cpus), ms->smp.cpus, "num-harts",
28+
&error_abort);
29+
@@ -220,6 +220,7 @@ static void riscv_sifive_e_machine_init(MachineClass *mc)
30+
mc->desc = "RISC-V Board compatible with SiFive E SDK";
31+
mc->init = riscv_sifive_e_init;
32+
mc->max_cpus = 1;
33+
+ mc->default_cpu_type = SIFIVE_E_CPU;
34+
}
35+
36+
DEFINE_MACHINE("sifive_e", riscv_sifive_e_machine_init)
37+
--
38+
2.21.1
39+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
From c9481f6ba0050a53411193b5a49bde6f2c4158b3 Mon Sep 17 00:00:00 2001
2+
From: Corey Wharton <[email protected]>
3+
Date: Thu, 12 Mar 2020 16:43:02 -0700
4+
Subject: [PATCH v2 2/2] target/riscv: Add a sifive-e34 cpu type
5+
6+
The sifive-e34 cpu type is the same as the sifive-e31 with the
7+
single precision floating-point extension enabled.
8+
9+
Signed-off-by: Corey Wharton <[email protected]>
10+
---
11+
v2: Added missing RVU flag
12+
13+
target/riscv/cpu.c | 10 ++++++++++
14+
target/riscv/cpu.h | 1 +
15+
2 files changed, 11 insertions(+)
16+
17+
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
18+
index c0b7023100..1ae9d085b8 100644
19+
--- a/target/riscv/cpu.c
20+
+++ b/target/riscv/cpu.c
21+
@@ -164,6 +164,15 @@ static void rv32imacu_nommu_cpu_init(Object *obj)
22+
set_feature(env, RISCV_FEATURE_PMP);
23+
}
24+
25+
+static void rv32imafcu_nommu_cpu_init(Object *obj)
26+
+{
27+
+ CPURISCVState *env = &RISCV_CPU(obj)->env;
28+
+ set_misa(env, RV32 | RVI | RVM | RVA | RVF | RVC | RVU);
29+
+ set_priv_version(env, PRIV_VERSION_1_10_0);
30+
+ set_resetvec(env, DEFAULT_RSTVEC);
31+
+ set_feature(env, RISCV_FEATURE_PMP);
32+
+}
33+
+
34+
#elif defined(TARGET_RISCV64)
35+
36+
static void riscv_base64_cpu_init(Object *obj)
37+
@@ -609,6 +618,7 @@ static const TypeInfo riscv_cpu_type_infos[] = {
38+
#if defined(TARGET_RISCV32)
39+
DEFINE_CPU(TYPE_RISCV_CPU_BASE32, riscv_base32_cpu_init),
40+
DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E31, rv32imacu_nommu_cpu_init),
41+
+ DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E34, rv32imafcu_nommu_cpu_init),
42+
DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U34, rv32gcsu_priv1_10_0_cpu_init),
43+
/* Depreacted */
44+
DEFINE_CPU(TYPE_RISCV_CPU_RV32IMACU_NOMMU, rv32imacu_nommu_cpu_init),
45+
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
46+
index 3dcdf92227..ae5a1d9dce 100644
47+
--- a/target/riscv/cpu.h
48+
+++ b/target/riscv/cpu.h
49+
@@ -36,6 +36,7 @@
50+
#define TYPE_RISCV_CPU_BASE32 RISCV_CPU_TYPE_NAME("rv32")
51+
#define TYPE_RISCV_CPU_BASE64 RISCV_CPU_TYPE_NAME("rv64")
52+
#define TYPE_RISCV_CPU_SIFIVE_E31 RISCV_CPU_TYPE_NAME("sifive-e31")
53+
+#define TYPE_RISCV_CPU_SIFIVE_E34 RISCV_CPU_TYPE_NAME("sifive-e34")
54+
#define TYPE_RISCV_CPU_SIFIVE_E51 RISCV_CPU_TYPE_NAME("sifive-e51")
55+
#define TYPE_RISCV_CPU_SIFIVE_U34 RISCV_CPU_TYPE_NAME("sifive-u34")
56+
#define TYPE_RISCV_CPU_SIFIVE_U54 RISCV_CPU_TYPE_NAME("sifive-u54")
57+
--
58+
2.21.1
59+

meta-zephyr-sdk/recipes-devtools/qemu/zephyr-qemu_git.bb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ SRC_URI = "git://github.com/qemu/qemu.git;protocol=https \
1313
file://0002-hw-sparc-leon-Fix-compilation-errors.patch \
1414
file://0003-hw-sparc-leon-timer-Call-leon_timer_io_read-for-TIME.patch \
1515
file://0004-hw-sparc-leon-Switch-to-transaction-based-ptimer-API.patch \
16+
file://0005-riscv-sifive_e-Support-changing-CPU-type.patch \
17+
file://0006-target-riscv-Add-a-sifive-e34-cpu-type.patch \
1618
"
1719

1820
BBCLASSEXTEND = "native nativesdk"

0 commit comments

Comments
 (0)