Skip to contentSkip to conversation

target/rx/cpu: Use address_space_ldl() to read reset vector address

PATCH In review Philippe Mathieu-Daudé 4 participants 4 messages Mar 15, 2020 – Mar 16, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/rx/cpu: Use address_space_ldl() to read reset vector address

From: Philippe Mathieu-Daudé <[email protected]>

The RX code flash is not a Masked ROM but a EEPROM (electrically erasable programmable flash memory).
When implementing the flash hardware, the rom_ptr() returns NULL and the reset vector is not set.
Instead, use the address_space ld/st API to fetch the reset vector address from the code flash.

---
Based-on: <[email protected]>

Same issue might occurs in Cortex-M arm_cpu_reset()

---
 target/rx/cpu.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
target/rx/cpu.c +4 -6
index 9c224a273c..d3bd09e753 100644
@@ -26,6 +26,8 @@
 #include "hw/loader.h"
 #include "fpu/softfloat.h"
 
+#define CPU_RESET_VECTOR 0xfffffffc
+
 static void rx_cpu_set_pc(CPUState *cs, vaddr value)
 {
     RXCPU *cpu = RXCPU(cs);
@@ -51,17 +53,13 @@ static void rx_cpu_reset(CPUState *s)
     RXCPU *cpu = RXCPU(s);
     RXCPUClass *rcc = RXCPU_GET_CLASS(cpu);
     CPURXState *env = &cpu->env;
-    uint32_t *resetvec;
 
     rcc->parent_reset(s);
 
     memset(env, 0, offsetof(CPURXState, end_reset_fields));
 
-    resetvec = rom_ptr(0xfffffffc, 4);
-    if (resetvec) {
-        /* In the case of kernel, it is ignored because it is not set. */
-        env->pc = ldl_p(resetvec);
-    }
+    env->pc = address_space_ldl(cpu_get_address_space(s, 0),
+                                CPU_RESET_VECTOR, MEMTXATTRS_UNSPECIFIED, NULL);
     rx_cpu_unpack_psw(env, 0, 1);
     env->regs[0] = env->isp = env->usp = 0;
     env->fpsw = 0;
Signature · 1 line
2.21.1
#1 lore raw
Quoted 1 line · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Hmm author email should be <[email protected]>...

Quoted 51 lines

The RX code flash is not a Masked ROM but a EEPROM (electrically erasable programmable flash memory).
When implementing the flash hardware, the rom_ptr() returns NULL and the reset vector is not set.
Instead, use the address_space ld/st API to fetch the reset vector address from the code flash.

---
Based-on: <[email protected]>

Same issue might occurs in Cortex-M arm_cpu_reset()

---
  target/rx/cpu.c | 10 ++++------
  1 file changed, 4 insertions(+), 6 deletions(-)
target/rx/cpu.c +4 -6
index 9c224a273c..d3bd09e753 100644
@@ -26,6 +26,8 @@
  #include "hw/loader.h"
  #include "fpu/softfloat.h"
 
+#define CPU_RESET_VECTOR 0xfffffffc
+
  static void rx_cpu_set_pc(CPUState *cs, vaddr value)
  {
      RXCPU *cpu = RXCPU(cs);
@@ -51,17 +53,13 @@ static void rx_cpu_reset(CPUState *s)
      RXCPU *cpu = RXCPU(s);
      RXCPUClass *rcc = RXCPU_GET_CLASS(cpu);
      CPURXState *env = &cpu->env;
-    uint32_t *resetvec;
 
      rcc->parent_reset(s);
 
      memset(env, 0, offsetof(CPURXState, end_reset_fields));
 
-    resetvec = rom_ptr(0xfffffffc, 4);
-    if (resetvec) {
-        /* In the case of kernel, it is ignored because it is not set. */
-        env->pc = ldl_p(resetvec);
-    }
+    env->pc = address_space_ldl(cpu_get_address_space(s, 0),
+                                CPU_RESET_VECTOR, MEMTXATTRS_UNSPECIFIED, NULL);
      rx_cpu_unpack_psw(env, 0, 1);
      env->regs[0] = env->isp = env->usp = 0;
      env->fpsw = 0;
Reviewed-by on v1 1/1
#2 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

The RX code flash is not a Masked ROM but a EEPROM (electrically erasable programmable flash memory).
When implementing the flash hardware, the rom_ptr() returns NULL and the reset vector is not set.
Instead, use the address_space ld/st API to fetch the reset vector address from the code flash.

Quoted 8 lines

---
Based-on: <[email protected]>

Same issue might occurs in Cortex-M arm_cpu_reset()

---
 target/rx/cpu.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

r~

#3 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

The RX code flash is not a Masked ROM but a EEPROM (electrically erasable programmable flash memory).
When implementing the flash hardware, the rom_ptr() returns NULL and the reset vector is not set.
Instead, use the address_space ld/st API to fetch the reset vector address from the code flash.

Quoted 5 lines

---
Based-on: <[email protected]>

Same issue might occurs in Cortex-M arm_cpu_reset()

rom_ptr() does not mean "I'm trying to get this from ROM", it means "I'm trying to get this from a user-supplied ELF file or similar which hasn't been loaded into guest memory yet". (This is a workaround for a reset ordering issue where CPU reset happens before rom_reset() runs.)

Removing the usage of rom_ptr() altogether here doesn't look right -- have you tested the case where the initial reset vector contents are provided via -kernel or -device loader,... ?

thanks
-- PMM