Skip to contentSkip to conversation

or1k: Add support for numcores and coreid sprs

PATCH New Stafford Horne 1 participant 1 message Jun 1, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 or1k: Add support for numcores and coreid sprs

These are needed when running GCC tests for newlib toolchains built with multicore support. Without these SPRs we get the following warnings when running tests.

    spawn or1k-elf-run ./20000112-1.exe^M
    WARNING: l.mfspr with invalid SPR address 0x80^M
    WARNING: l.mfspr with invalid SPR address 0x81^M
    WARNING: l.mfspr with invalid SPR address 0x81^M
    WARNING: l.mfspr with invalid SPR address 0x81^M

Support is added by defining the SPRs in the cgen machine definition and regenerating the machine code. In or1k/or1k.c we initialize NUMCORES to 1 and COREID to 0 as the sim has only one CPU. In or1k/traps.c we allow returning the NUMCORES and COREID spr values in the mfspr function.

---
 cpu/or1kcommon.cpu  |   2 +
 opcodes/or1k-desc.c |   2 +
 opcodes/or1k-desc.h | 547 ++++++++++++++++++++++----------------------
 sim/or1k/cpu.c      |  32 +++
 sim/or1k/cpu.h      |  14 ++
 sim/or1k/or1k.c     |   4 +
 sim/or1k/traps.c    |   2 +
 7 files changed, 330 insertions(+), 273 deletions(-)
cpu/or1kcommon.cpu +2 -0
index 9f102c93a18..7f91954e570 100644
@@ -243,6 +243,8 @@
    (.unsplice
     (.map (.pmacro (n) (.splice SYS (.sym "ESR" n) (.add n #x40) (.str "Exception supervision register " n)))
           (.iota #x10)))
+   (SYS COREID   #x080 "Core identifier register")
+   (SYS NUMCORES #x081 "Number of cores register")
    (.unsplice
     (.map (.pmacro (n) (.splice SYS (.sym "GPR" n) (.add n #x400) (.str "General purpose register " n)))
           (.iota #x200)))
opcodes/or1k-desc.c +2 -0
index 9b8aa08699f..90db200fc6c 100644
@@ -302,6 +302,8 @@ const CGEN_HW_ENTRY or1k_cgen_hw_table[] =
   { "h-sys-esr13", HW_H_SYS_ESR13, CGEN_ASM_NONE, 0, { 0|A(VIRTUAL), { { { (1<<MACH_OR32)|(1<<MACH_OR32ND), 0 } } } } },
   { "h-sys-esr14", HW_H_SYS_ESR14, CGEN_ASM_NONE, 0, { 0|A(VIRTUAL), { { { (1<<MACH_OR32)|(1<<MACH_OR32ND), 0 } } } } },
   { "h-sys-esr15", HW_H_SYS_ESR15, CGEN_ASM_NONE, 0, { 0|A(VIRTUAL), { { { (1<<MACH_OR32)|(1<<MACH_OR32ND), 0 } } } } },
+  { "h-sys-coreid", HW_H_SYS_COREID, CGEN_ASM_NONE, 0, { 0|A(VIRTUAL), { { { (1<<MACH_OR32)|(1<<MACH_OR32ND), 0 } } } } },
+  { "h-sys-numcores", HW_H_SYS_NUMCORES, CGEN_ASM_NONE, 0, { 0|A(VIRTUAL), { { { (1<<MACH_OR32)|(1<<MACH_OR32ND), 0 } } } } },
   { "h-sys-gpr0", HW_H_SYS_GPR0, CGEN_ASM_NONE, 0, { 0|A(VIRTUAL), { { { (1<<MACH_OR32)|(1<<MACH_OR32ND), 0 } } } } },
   { "h-sys-gpr1", HW_H_SYS_GPR1, CGEN_ASM_NONE, 0, { 0|A(VIRTUAL), { { { (1<<MACH_OR32)|(1<<MACH_OR32ND), 0 } } } } },
   { "h-sys-gpr2", HW_H_SYS_GPR2, CGEN_ASM_NONE, 0, { 0|A(VIRTUAL), { { { (1<<MACH_OR32)|(1<<MACH_OR32ND), 0 } } } } },
opcodes/or1k-desc.h +274 -273

559 lines not on this page · raw message

sim/or1k/cpu.c +32 -0
index c75e2a0ba25..14e43ccf5c8 100644
@@ -1100,6 +1100,38 @@ or1k32bf_h_sys_esr15_set (SIM_CPU *current_cpu, USI newval)
   SET_H_SYS_ESR15 (newval);
 }
 
+/* Get the value of h-sys-coreid.  */
+
+USI
+or1k32bf_h_sys_coreid_get (SIM_CPU *current_cpu)
+{
+  return GET_H_SYS_COREID ();
+}
+
+/* Set a value for h-sys-coreid.  */
+
+void
+or1k32bf_h_sys_coreid_set (SIM_CPU *current_cpu, USI newval)
+{
+  SET_H_SYS_COREID (newval);
+}
+
+/* Get the value of h-sys-numcores.  */
+
+USI
+or1k32bf_h_sys_numcores_get (SIM_CPU *current_cpu)
+{
+  return GET_H_SYS_NUMCORES ();
+}
+
+/* Set a value for h-sys-numcores.  */
+
+void
+or1k32bf_h_sys_numcores_set (SIM_CPU *current_cpu, USI newval)
+{
+  SET_H_SYS_NUMCORES (newval);
+}
+
 /* Get the value of h-sys-gpr0.  */
 
 USI
sim/or1k/cpu.h +14 -0
index 7f8a340efdb..ab2c0621d15 100644
@@ -408,6 +408,16 @@ SET_H_SPR (ORSI (SLLSI (SPR_GROUP_SYS, 11), SPR_INDEX_SYS_ESR14), (x));\
 do { \
 SET_H_SPR (ORSI (SLLSI (SPR_GROUP_SYS, 11), SPR_INDEX_SYS_ESR15), (x));\
 ;} while (0)
+#define GET_H_SYS_COREID() GET_H_SPR (ORSI (SLLSI (SPR_GROUP_SYS, 11), SPR_INDEX_SYS_COREID))
+#define SET_H_SYS_COREID(x) \
+do { \
+SET_H_SPR (ORSI (SLLSI (SPR_GROUP_SYS, 11), SPR_INDEX_SYS_COREID), (x));\
+;} while (0)
+#define GET_H_SYS_NUMCORES() GET_H_SPR (ORSI (SLLSI (SPR_GROUP_SYS, 11), SPR_INDEX_SYS_NUMCORES))
+#define SET_H_SYS_NUMCORES(x) \
+do { \
+SET_H_SPR (ORSI (SLLSI (SPR_GROUP_SYS, 11), SPR_INDEX_SYS_NUMCORES), (x));\
+;} while (0)
 #define GET_H_SYS_GPR0() GET_H_SPR (ORSI (SLLSI (SPR_GROUP_SYS, 11), SPR_INDEX_SYS_GPR0))
 #define SET_H_SYS_GPR0(x) \
 do { \
@@ -3379,6 +3389,10 @@ USI or1k32bf_h_sys_esr14_get (SIM_CPU *);
 void or1k32bf_h_sys_esr14_set (SIM_CPU *, USI);
 USI or1k32bf_h_sys_esr15_get (SIM_CPU *);
 void or1k32bf_h_sys_esr15_set (SIM_CPU *, USI);
+USI or1k32bf_h_sys_coreid_get (SIM_CPU *);
+void or1k32bf_h_sys_coreid_set (SIM_CPU *, USI);
+USI or1k32bf_h_sys_numcores_get (SIM_CPU *);
+void or1k32bf_h_sys_numcores_set (SIM_CPU *, USI);
 USI or1k32bf_h_sys_gpr0_get (SIM_CPU *);
 void or1k32bf_h_sys_gpr0_set (SIM_CPU *, USI);
 USI or1k32bf_h_sys_gpr1_get (SIM_CPU *);
sim/or1k/or1k.c +4 -0
index 2d1f7f88a3e..73ab6f0db22 100644
@@ -206,6 +206,10 @@ or1k_cpu_init (SIM_DESC sd, sim_cpu *current_cpu, const USI or1k_vr,
 
   /* Clear the floating point control status register.  */
   SET_H_SYS_FPCSR (0);
+
+  /* Set this as the one and only core.  */
+  SET_H_SYS_NUMCORES (1);
+  SET_H_SYS_COREID (0);
 }
 
 void
sim/or1k/traps.c +2 -0
index 753bffff424..d1113ac4941 100644
@@ -224,6 +224,8 @@ or1k32bf_mfspr (sim_cpu *current_cpu, USI addr)
     case SPR_ADDR (SYS, PPC):
     case SPR_ADDR (SYS, FPCSR):
     case SPR_ADDR (SYS, EPCR0):
+    case SPR_ADDR (SYS, COREID):
+    case SPR_ADDR (SYS, NUMCORES):
     case SPR_ADDR (MAC, MACLO):
     case SPR_ADDR (MAC, MACHI):
       break;
Signature · 1 line
2.49.0