Skip to content

Commit 495134b

Browse files
lbmengalistair23
authored andcommitted
hw/riscv: sifive: Change SiFive E/U CPU reset vector to 0x1004
Per the SiFive manual, all E/U series CPU cores' reset vector is at 0x1004. Update our codes to match the hardware. Signed-off-by: Bin Meng <[email protected]> Reviewed-by: Alistair Francis <[email protected]> Message-id: [email protected] Message-Id: <[email protected]> Signed-off-by: Alistair Francis <[email protected]>
1 parent e8905c6 commit 495134b

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

hw/riscv/sifive_e.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,16 @@ static void sifive_e_machine_init(MachineState *machine)
9595
memmap[SIFIVE_E_DTIM].base, main_mem);
9696

9797
/* Mask ROM reset vector */
98-
uint32_t reset_vec[2];
98+
uint32_t reset_vec[4];
9999

100100
if (s->revb) {
101-
reset_vec[0] = 0x200102b7; /* 0x1000: lui t0,0x20010 */
101+
reset_vec[1] = 0x200102b7; /* 0x1004: lui t0,0x20010 */
102102
} else {
103-
reset_vec[0] = 0x204002b7; /* 0x1000: lui t0,0x20400 */
103+
reset_vec[1] = 0x204002b7; /* 0x1004: lui t0,0x20400 */
104104
}
105-
reset_vec[1] = 0x00028067; /* 0x1004: jr t0 */
105+
reset_vec[2] = 0x00028067; /* 0x1008: jr t0 */
106+
107+
reset_vec[0] = reset_vec[3] = 0;
106108

107109
/* copy in the reset vector in little_endian byte order */
108110
for (i = 0; i < sizeof(reset_vec) >> 2; i++) {

hw/riscv/sifive_u.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,18 +430,18 @@ static void sifive_u_machine_init(MachineState *machine)
430430

431431
/* reset vector */
432432
uint32_t reset_vec[8] = {
433+
0x00000000,
433434
0x00000297, /* 1: auipc t0, %pcrel_hi(dtb) */
434-
0x02028593, /* addi a1, t0, %pcrel_lo(1b) */
435+
0x01c28593, /* addi a1, t0, %pcrel_lo(1b) */
435436
0xf1402573, /* csrr a0, mhartid */
436437
#if defined(TARGET_RISCV32)
437438
0x0182a283, /* lw t0, 24(t0) */
438439
#elif defined(TARGET_RISCV64)
439-
0x0182b283, /* ld t0, 24(t0) */
440+
0x0182e283, /* lwu t0, 24(t0) */
440441
#endif
441442
0x00028067, /* jr t0 */
442443
0x00000000,
443444
start_addr, /* start: .dword */
444-
0x00000000,
445445
/* dtb: */
446446
};
447447

target/riscv/cpu.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,20 @@ static void riscv_base_cpu_init(Object *obj)
134134
set_resetvec(env, DEFAULT_RSTVEC);
135135
}
136136

137-
static void rvxx_gcsu_priv1_10_0_cpu_init(Object *obj)
137+
static void rvxx_sifive_u_cpu_init(Object *obj)
138138
{
139139
CPURISCVState *env = &RISCV_CPU(obj)->env;
140140
set_misa(env, RVXLEN | RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU);
141141
set_priv_version(env, PRIV_VERSION_1_10_0);
142-
set_resetvec(env, DEFAULT_RSTVEC);
142+
set_resetvec(env, 0x1004);
143143
}
144144

145-
static void rvxx_imacu_nommu_cpu_init(Object *obj)
145+
static void rvxx_sifive_e_cpu_init(Object *obj)
146146
{
147147
CPURISCVState *env = &RISCV_CPU(obj)->env;
148148
set_misa(env, RVXLEN | RVI | RVM | RVA | RVC | RVU);
149149
set_priv_version(env, PRIV_VERSION_1_10_0);
150-
set_resetvec(env, DEFAULT_RSTVEC);
150+
set_resetvec(env, 0x1004);
151151
qdev_prop_set_bit(DEVICE(obj), "mmu", false);
152152
}
153153

@@ -578,13 +578,13 @@ static const TypeInfo riscv_cpu_type_infos[] = {
578578
#if defined(TARGET_RISCV32)
579579
DEFINE_CPU(TYPE_RISCV_CPU_BASE32, riscv_base_cpu_init),
580580
DEFINE_CPU(TYPE_RISCV_CPU_IBEX, rv32_ibex_cpu_init),
581-
DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E31, rvxx_imacu_nommu_cpu_init),
581+
DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E31, rvxx_sifive_e_cpu_init),
582582
DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E34, rv32_imafcu_nommu_cpu_init),
583-
DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U34, rvxx_gcsu_priv1_10_0_cpu_init),
583+
DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U34, rvxx_sifive_u_cpu_init),
584584
#elif defined(TARGET_RISCV64)
585585
DEFINE_CPU(TYPE_RISCV_CPU_BASE64, riscv_base_cpu_init),
586-
DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E51, rvxx_imacu_nommu_cpu_init),
587-
DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U54, rvxx_gcsu_priv1_10_0_cpu_init),
586+
DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E51, rvxx_sifive_e_cpu_init),
587+
DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U54, rvxx_sifive_u_cpu_init),
588588
#endif
589589
};
590590

0 commit comments

Comments
 (0)