Skip to contentSkip to conversation

sim port for OpenRISC

PATCH Superseded Stafford Horne 2 participants 17 messages Oct 5, 2017 – Oct 9, 2017

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover sim port for OpenRISC

Hello,

(what I thought would be a few days turned into a month since the comments on v4)

Please find attached the sim patches that allow to get a basic OpenRISC system running. This was used to verify the OpenRISC gdb port.

The main author is Peter Gavin who should have his FSF copyright in place.

Request for comments on:
- The testcase has a few tests commented out. I do not plan to fix now, but hopefully be addressed after upstreaming.

# Guide to Code #

As Simon has requested I have tried to comment on the functions in the simulator implementation. But I want to provide some general architecture comments here for reference. Please let me know if there is a better place for these kind of docs.

The or1k sim uses the CGEN system to generate most of the simulator code. There is some documentation for CGEN on sourceware.org here:

https://sourceware.org/cgen/docs/cgen.html

In the binutils-gdb project there are several files which get combined to make up the CGEN simulator. The process for how those are built can be seen in or1k/Makefile.in. But the main files are:

MAIN
sim/common/nrun.c - the main() calls sim_open(), sim_resume() and others sim/or1k/sim-if.c - implements sim_open() and others used by nrun
when envoking sim in gdb, gdb uses sim_open() directly

CGEN input and generated files
cpu/or1k*.cpu - these define the hardware, model and semantics sim/or1k/arch.c - generated defines sim_machs array sim/or1k/cpu.c - *generated defines register setters and getters sim/or1k/decode.c - generated defines instruction decoder sim/or1k/model.c - generated defines instruction cycles sim/or1k/sem.c - *generated defines instruction operation semantics sim/or1k/sem-switch.c - *generated ditto but as a switch

ENGINE runs decode execute loop
sim/common/cgen-* - cgen implementation helpers sim/common/cgen-run.c - implements sim_resume() which runs the engine sim/common/genmloop.sh - helper script to generate mloop.c engine the
decode, execute loop
sim/or1k/mloop.in - openRISC implementation of mloop parts

EXTRAS callbacks from sem* to c code
sim/or1k/or1k.c - implements some instructions in c (not cgen schema) sim/or1k/traps.c - exception handler

For each sim architecture we have choices for how the mloop is implemented. The OpenRISC engine uses scache pbb (pseudo-basic-block) instruction extraction with both fast (sem-switch.c based) and full (sem.c based) implementations. The fast and full modes are switch via the command line options to the run command, i.e. --trace-insn will run in full mode.

# Building #

Simon asked for some details on how we build and test the openrisc sim. Here are some details:

                            ## TOOLCHAIN ##

This may not be needed as binutils contains most/all of the utilities required. But if needed, get this toolchain (this is the newlib binary, others also available)

https://github.com/openrisc/or1k-gcc/releases/download/or1k-5.4.0-20170218/or1k-elf-5.4.0-20170218.tar.xz

If you want to build that from scratch look to:

https://github.com/openrisc/newlib/blob/scripts/build.sh

                              ## GDB ##

In a directory along side binutils-gdb source

mkdir build-or1k-elf-gdb
cd build-or1k-elf-gdb

  ../binutils-gdb/configure --target=or1k-elf \
    --prefix=/opt/shorne/software/or1k \
    --disable-itcl \
    --disable-tk \
    --disable-tcl \
    --disable-winsup \
    --disable-gdbtk \
    --disable-libgui \
    --disable-rda \
    --disable-sid \
    --with-sysroot \
    --disable-newlib \
    --disable-libgloss \
    --disable-gas \
    --disable-ld \
    --disable-binutils \
    --disable-gprof \
    --with-system-zlib
  # make gdb, sim
  make
  # test sim
  cd sim
  make check

The sim creates a binary simulator too, you can run binaries such as hello world with:

  or1k-elf-gcc hello.c
  ./or1k/run --trace-insn ./a.out

# Test Results #

Sim dejagnu tests were added specifically for openrisc and used to test this. Please see the details of running the testsuite for sim below:

=== sim Summary ===

# of expected passes            18
/home/shorne/work/openrisc/build-gdb/sim/or1k/run 0.5

Thanks,
-Stafford

Changes since v4
* Added comments to most of the functions
* Implemented remainder fpu function
* Actually wire in fpu and error handling logic
* Added fpu test case

Changes since v3
* Cleaned up indentation and style of sim testsuite
* Cleaned up TODOs in testsuite
* Implemented range exception

Changes since v2
* Removed 64-bit implementation (reduced files)
* Removed cgen suffix patch
* Removed different builds for linux
* Removed unused macros
* Fixed gnu style issues pointed out by Mike
* Fixed copyrights (not Cygnus, added to each file)

Changes since v1
* Squashed sim patches into single sim patch
* Put Generated files in separate patch
* I have my sim/gdb copyright assignment complete

Peter Gavin (3):
sim: cgen: add remainder functions (needed for OR1K lf.rem.[sd])
sim: cgen: add MUL2OFSI and MUL1OFSI macros (needed for OR1K l.mul[u])
sim: testsuite: add testsuite for or1k sim

Stafford Horne (3):
sim: or1k: add or1k target to sim
sim: or1k: add cgen generated files
sim: or1k: add autoconf generated files

 sim/common/cgen-accfp.c                        |    40 +
 sim/common/cgen-fpu.h                          |     4 +
 sim/common/cgen-ops.h                          |    18 +
 sim/common/sim-fpu.c                           |    90 +-
 sim/common/sim-fpu.h                           |    13 +-
 sim/configure                                  |     9 +
 sim/configure.tgt                              |     4 +
 sim/or1k/Makefile.in                           |   147 +
 sim/or1k/aclocal.m4                            |   119 +
 sim/or1k/arch.c                                |    38 +
 sim/or1k/arch.h                                |    50 +
 sim/or1k/config.in                             |   248 +
 sim/or1k/configure                             | 16043 +++++++++++++++++++++++
 sim/or1k/configure.ac                          |    17 +
 sim/or1k/cpu.c                                 | 10181 ++++++++++++++
 sim/or1k/cpu.h                                 |  5024 +++++++
 sim/or1k/cpuall.h                              |    66 +
 sim/or1k/decode.c                              |  2559 ++++
 sim/or1k/decode.h                              |    94 +
 sim/or1k/mloop.in                              |   242 +
 sim/or1k/model.c                               |  3809 ++++++
 sim/or1k/or1k-sim.h                            |    95 +
 sim/or1k/or1k.c                                |   355 +
 sim/or1k/sem-switch.c                          |  2748 ++++
 sim/or1k/sem.c                                 |  2953 +++++
 sim/or1k/sim-if.c                              |   281 +
 sim/or1k/sim-main.h                            |    81 +
 sim/or1k/traps.c                               |   299 +
 sim/testsuite/configure                        |     4 +
 sim/testsuite/sim/or1k/add.S                   |   606 +
 sim/testsuite/sim/or1k/alltests.exp            |    34 +
 sim/testsuite/sim/or1k/and.S                   |   198 +
 sim/testsuite/sim/or1k/basic.S                 |   522 +
 sim/testsuite/sim/or1k/div.S                   |   290 +
 sim/testsuite/sim/or1k/ext.S                   |   236 +
 sim/testsuite/sim/or1k/find.S                  |   100 +
 sim/testsuite/sim/or1k/flag.S                  |   378 +
 sim/testsuite/sim/or1k/fpu.S                   |   128 +
 sim/testsuite/sim/or1k/jump.S                  |   104 +
 sim/testsuite/sim/or1k/load.S                  |   358 +
 sim/testsuite/sim/or1k/mac.S                   |   778 ++
 sim/testsuite/sim/or1k/mfspr.S                 |   171 +
 sim/testsuite/sim/or1k/mul.S                   |   573 +
 sim/testsuite/sim/or1k/or.S                    |   199 +
 sim/testsuite/sim/or1k/or1k-asm-test-env.h     |    59 +
 sim/testsuite/sim/or1k/or1k-asm-test-helpers.h |   121 +
 sim/testsuite/sim/or1k/or1k-asm-test.h         |   225 +
 sim/testsuite/sim/or1k/or1k-asm.h              |    37 +
 sim/testsuite/sim/or1k/or1k-test.ld            |    75 +
 sim/testsuite/sim/or1k/ror.S                   |   159 +
 sim/testsuite/sim/or1k/shift.S                 |   541 +
 sim/testsuite/sim/or1k/spr-defs.h              |   120 +
 sim/testsuite/sim/or1k/sub.S                   |   201 +
 sim/testsuite/sim/or1k/xor.S                   |   200 +
 54 files changed, 52037 insertions(+), 7 deletions(-)
 create mode 100644 sim/or1k/Makefile.in
 create mode 100644 sim/or1k/aclocal.m4
 create mode 100644 sim/or1k/arch.c
 create mode 100644 sim/or1k/arch.h
 create mode 100644 sim/or1k/config.in
 create mode 100755 sim/or1k/configure
 create mode 100644 sim/or1k/configure.ac
 create mode 100644 sim/or1k/cpu.c
 create mode 100644 sim/or1k/cpu.h
 create mode 100644 sim/or1k/cpuall.h
 create mode 100644 sim/or1k/decode.c
 create mode 100644 sim/or1k/decode.h
 create mode 100644 sim/or1k/mloop.in
 create mode 100644 sim/or1k/model.c
 create mode 100644 sim/or1k/or1k-sim.h
 create mode 100644 sim/or1k/or1k.c
 create mode 100644 sim/or1k/sem-switch.c
 create mode 100644 sim/or1k/sem.c
 create mode 100644 sim/or1k/sim-if.c
 create mode 100644 sim/or1k/sim-main.h
 create mode 100644 sim/or1k/traps.c
 create mode 100644 sim/testsuite/sim/or1k/add.S
 create mode 100644 sim/testsuite/sim/or1k/alltests.exp
 create mode 100644 sim/testsuite/sim/or1k/and.S
 create mode 100644 sim/testsuite/sim/or1k/basic.S
 create mode 100644 sim/testsuite/sim/or1k/div.S
 create mode 100644 sim/testsuite/sim/or1k/ext.S
 create mode 100644 sim/testsuite/sim/or1k/find.S
 create mode 100644 sim/testsuite/sim/or1k/flag.S
 create mode 100644 sim/testsuite/sim/or1k/fpu.S
 create mode 100644 sim/testsuite/sim/or1k/jump.S
 create mode 100644 sim/testsuite/sim/or1k/load.S
 create mode 100644 sim/testsuite/sim/or1k/mac.S
 create mode 100644 sim/testsuite/sim/or1k/mfspr.S
 create mode 100644 sim/testsuite/sim/or1k/mul.S
 create mode 100644 sim/testsuite/sim/or1k/or.S
 create mode 100644 sim/testsuite/sim/or1k/or1k-asm-test-env.h
 create mode 100644 sim/testsuite/sim/or1k/or1k-asm-test-helpers.h
 create mode 100644 sim/testsuite/sim/or1k/or1k-asm-test.h
 create mode 100644 sim/testsuite/sim/or1k/or1k-asm.h
 create mode 100644 sim/testsuite/sim/or1k/or1k-test.ld
 create mode 100644 sim/testsuite/sim/or1k/ror.S
 create mode 100644 sim/testsuite/sim/or1k/shift.S
 create mode 100644 sim/testsuite/sim/or1k/spr-defs.h
 create mode 100644 sim/testsuite/sim/or1k/sub.S
 create mode 100644 sim/testsuite/sim/or1k/xor.S
Signature · 1 line
2.13.5
#1 lore raw

PATCH v5 1/6 sim: cgen: add remainder functions (needed for OR1K lf.rem.[sd])

From: Peter Gavin <[email protected]>

* sim/common/ChangeLog:

2016-05-21 Peter Gavin <[email protected]>
Stafford Horne <[email protected]>

* cgen-accfp.c (remsf, remdf): New function. (cgen_init_accurate_fpu): Add remsf and remdf.
* cgen-fpu.h (cgen_fp_ops): Add remsf, remdf, remxf and remtf.
* sim-fpu.c (sim_fpu_rem): New function.
* sim-fpu.h (sim_fpu_status_invalid_irx): New enum. (sim_fpu_rem): New function.

---
 sim/common/cgen-accfp.c | 40 ++++++++++++++++++++++
 sim/common/cgen-fpu.h   |  4 +++
 sim/common/sim-fpu.c    | 90 +++++++++++++++++++++++++++++++++++++++++++++++--
 sim/common/sim-fpu.h    | 13 ++++---
 4 files changed, 140 insertions(+), 7 deletions(-)
sim/common/cgen-accfp.c +40 -0
index afbca6d582..5d600c6e41 100644
@@ -93,6 +93,25 @@ divsf (CGEN_FPU* fpu, SF x, SF y)
 }
 
 static SF
+remsf (CGEN_FPU* fpu, SF x, SF y)
+{
+  sim_fpu op1;
+  sim_fpu op2;
+  sim_fpu ans;
+  unsigned32 res;
+  sim_fpu_status status;
+
+  sim_fpu_32to (&op1, x);
+  sim_fpu_32to (&op2, y);
+  status = sim_fpu_rem (&ans, &op1, &op2);
+  if (status != 0)
+    (*fpu->ops->error) (fpu, status);
+  sim_fpu_to32 (&res, &ans);
+
+  return res;
+}
+
+static SF
 negsf (CGEN_FPU* fpu, SF x)
 {
   sim_fpu op1;
@@ -453,6 +472,25 @@ divdf (CGEN_FPU* fpu, DF x, DF y)
 }
 
 static DF
+remdf (CGEN_FPU* fpu, DF x, DF y)
+{
+  sim_fpu op1;
+  sim_fpu op2;
+  sim_fpu ans;
+  unsigned64 res;
+  sim_fpu_status status;
+
+  sim_fpu_64to (&op1, x);
+  sim_fpu_64to (&op2, y);
+  status = sim_fpu_rem (&ans, &op1, &op2);
+  if (status != 0)
+    (*fpu->ops->error) (fpu, status);
+  sim_fpu_to64(&res, &ans);
+
+  return res;
+}
+
+static DF
 negdf (CGEN_FPU* fpu, DF x)
 {
   sim_fpu op1;
@@ -664,6 +702,7 @@ cgen_init_accurate_fpu (SIM_CPU* cpu, CGEN_FPU* fpu, CGEN_FPU_ERROR_FN* error)
   o->subsf = subsf;
   o->mulsf = mulsf;
   o->divsf = divsf;
+  o->remsf = remsf;
   o->negsf = negsf;
   o->abssf = abssf;
   o->sqrtsf = sqrtsf;
@@ -682,6 +721,7 @@ cgen_init_accurate_fpu (SIM_CPU* cpu, CGEN_FPU* fpu, CGEN_FPU_ERROR_FN* error)
   o->subdf = subdf;
   o->muldf = muldf;
   o->divdf = divdf;
+  o->remdf = remdf;
   o->negdf = negdf;
   o->absdf = absdf;
   o->sqrtdf = sqrtdf;
sim/common/cgen-fpu.h +4 -0
index 134b4d031c..5f9b55d32e 100644
@@ -69,6 +69,7 @@ struct cgen_fp_ops {
   SF (*subsf) (CGEN_FPU*, SF, SF);
   SF (*mulsf) (CGEN_FPU*, SF, SF);
   SF (*divsf) (CGEN_FPU*, SF, SF);
+  SF (*remsf) (CGEN_FPU*, SF, SF);
   SF (*negsf) (CGEN_FPU*, SF);
   SF (*abssf) (CGEN_FPU*, SF);
   SF (*sqrtsf) (CGEN_FPU*, SF);
@@ -93,6 +94,7 @@ struct cgen_fp_ops {
   DF (*subdf) (CGEN_FPU*, DF, DF);
   DF (*muldf) (CGEN_FPU*, DF, DF);
   DF (*divdf) (CGEN_FPU*, DF, DF);
+  DF (*remdf) (CGEN_FPU*, DF, DF);
   DF (*negdf) (CGEN_FPU*, DF);
   DF (*absdf) (CGEN_FPU*, DF);
   DF (*sqrtdf) (CGEN_FPU*, DF);
@@ -142,6 +144,7 @@ struct cgen_fp_ops {
   XF (*subxf) (CGEN_FPU*, XF, XF);
   XF (*mulxf) (CGEN_FPU*, XF, XF);
   XF (*divxf) (CGEN_FPU*, XF, XF);
+  XF (*remxf) (CGEN_FPU*, XF, XF);
   XF (*negxf) (CGEN_FPU*, XF);
   XF (*absxf) (CGEN_FPU*, XF);
   XF (*sqrtxf) (CGEN_FPU*, XF);
@@ -180,6 +183,7 @@ struct cgen_fp_ops {
   TF (*subtf) (CGEN_FPU*, TF, TF);
   TF (*multf) (CGEN_FPU*, TF, TF);
   TF (*divtf) (CGEN_FPU*, TF, TF);
+  TF (*remtf) (CGEN_FPU*, TF, TF);
   TF (*negtf) (CGEN_FPU*, TF);
   TF (*abstf) (CGEN_FPU*, TF);
   TF (*sqrttf) (CGEN_FPU*, TF);
sim/common/sim-fpu.c +88 -2

126 lines not on this page · raw message

sim/common/sim-fpu.h +8 -5
index d27d80a513..adf3b1904a 100644
@@ -146,11 +146,12 @@ typedef enum
   sim_fpu_status_invalid_div0 = 128, /* (X / 0) */
   sim_fpu_status_invalid_cmp = 256, /* compare */
   sim_fpu_status_invalid_sqrt = 512,
-  sim_fpu_status_rounded = 1024,
-  sim_fpu_status_inexact = 2048,
-  sim_fpu_status_overflow = 4096,
-  sim_fpu_status_underflow = 8192,
-  sim_fpu_status_denorm = 16384,
+  sim_fpu_status_invalid_irx = 1024, /* (inf % X) */
+  sim_fpu_status_rounded = 2048,
+  sim_fpu_status_inexact = 4096,
+  sim_fpu_status_overflow = 8192,
+  sim_fpu_status_underflow = 16384,
+  sim_fpu_status_denorm = 32768,
 } sim_fpu_status;
 
 
@@ -230,6 +231,8 @@ INLINE_SIM_FPU (int) sim_fpu_mul (sim_fpu *f,
 				  const sim_fpu *l, const sim_fpu *r);
 INLINE_SIM_FPU (int) sim_fpu_div (sim_fpu *f,
 				  const sim_fpu *l, const sim_fpu *r);
+INLINE_SIM_FPU (int) sim_fpu_rem (sim_fpu *f,
+				  const sim_fpu *l, const sim_fpu *r);
 INLINE_SIM_FPU (int) sim_fpu_max (sim_fpu *f,
 				  const sim_fpu *l, const sim_fpu *r);
 INLINE_SIM_FPU (int) sim_fpu_min (sim_fpu *f,
Signature · 1 line
2.13.5
#5 lore raw

PATCH v5 2/6 sim: cgen: add MUL2OFSI and MUL1OFSI macros (needed for OR1K l.mul[u])

In reply to Stafford Horne

From: Peter Gavin <[email protected]>

sim/common/ChangeLog:

2012-03-14 Peter Gavin <[email protected]>

* cgen-ops.h (MUL2OFSI): New macro, 1's complement overflow. (MUL1OFSI): New macro, 2's complement overflow.

---
 sim/common/cgen-ops.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
sim/common/cgen-ops.h +18 -0
index 97585d7943..ffbdf3fd6e 100644
@@ -631,6 +631,22 @@ SUBOFQI (QI a, QI b, BI c)
   return res;
 }
 
+SEMOPS_INLINE BI
+MUL2OFSI (SI a, SI b)
+{
+  DI tmp = MULDI (EXTSIDI(a), EXTSIDI(b));
+  BI res = tmp < -0x80000000LL || tmp > 0x7fffffffLL;
+  return res;
+}
+
+SEMOPS_INLINE BI
+MUL1OFSI (USI a, USI b)
+{
+  UDI tmp = MULDI (ZEXTSIDI(a), ZEXTSIDI(b));
+  BI res = (tmp > 0xFFFFFFFFULL);
+  return res;
+}
+
 #else
 
 SI ADDCSI (SI, SI, BI);
@@ -651,6 +667,8 @@ UBI ADDOFQI (QI, QI, BI);
 QI SUBCQI (QI, QI, BI);
 UBI SUBCFQI (QI, QI, BI);
 UBI SUBOFQI (QI, QI, BI);
+BI MUL1OFSI (SI a, SI b);
+BI MUL2OFSI (SI a, SI b);
 
 #endif
 
Signature · 1 line
2.13.5
#8 lore raw

PATCH v5 3/6 sim: or1k: add or1k target to sim

In reply to Stafford Horne

This adds the OpenRISC 32-bit sim target. The OpenRISC sim is a CGEN based sim so the bulk of the code is generated from the .cpu files by CGEN. The engine decode and execute logic in mloop uses scache with pseudo-basic-block extraction and supports both full and fast (switch) modes.

The sim does not implement an mmu at the moment. The sim does implement fpu instructions via the common sim-fpu implementation.

sim/ChangeLog:

2017-09-13 Stafford Horne <[email protected]>
Peter Gavin <[email protected]>

* configure.tgt: Add or1k sim.
* or1k/Makefile.in: New file.
* or1k/configure.ac: New file.
* or1k/mloop.in: New file.
* or1k/or1k-sim.h: New file.
* or1k/or1k.c: New file.
* or1k/sim-if.c: New file.
* or1k/sim-main.h: New file.
* or1k/traps.c: New file.

---
 sim/configure.tgt     |   4 +
 sim/or1k/Makefile.in  | 147 +++++++++++++++++++++
 sim/or1k/configure.ac |  17 +++
 sim/or1k/mloop.in     | 242 ++++++++++++++++++++++++++++++++++
 sim/or1k/or1k-sim.h   |  95 ++++++++++++++
 sim/or1k/or1k.c       | 355 ++++++++++++++++++++++++++++++++++++++++++++++++++
 sim/or1k/sim-if.c     | 281 +++++++++++++++++++++++++++++++++++++++
 sim/or1k/sim-main.h   |  81 ++++++++++++
 sim/or1k/traps.c      | 299 ++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 1521 insertions(+)
 create mode 100644 sim/or1k/Makefile.in
 create mode 100644 sim/or1k/configure.ac
 create mode 100644 sim/or1k/mloop.in
 create mode 100644 sim/or1k/or1k-sim.h
 create mode 100644 sim/or1k/or1k.c
 create mode 100644 sim/or1k/sim-if.c
 create mode 100644 sim/or1k/sim-main.h
 create mode 100644 sim/or1k/traps.c
sim/configure.tgt +4 -0
index c958fb3174..82b0e89240 100644
@@ -76,6 +76,10 @@ case "${target}" in
    msp430*-*-*)
        SIM_ARCH(msp430)
        ;;
+   or1k-*-* | or1knd-*-*)
+       SIM_ARCH(or1k)
+       sim_testsuite=yes
+       ;;
    rl78-*-*)
        SIM_ARCH(rl78)
        ;;
sim/or1k/Makefile.in new file +147 -0

147 lines not on this page · raw message

sim/or1k/configure.ac new file +17 -0
new file mode 100644
index 0000000000..8873a1d2de
@@ -0,0 +1,17 @@
+dnl Process this file with autoconf to produce a configure script.
+AC_PREREQ(2.64)dnl
+AC_INIT(Makefile.in)
+sinclude(../common/acinclude.m4)
+
+SIM_AC_COMMON
+
+SIM_AC_OPTION_ENDIAN(BIG)
+SIM_AC_OPTION_ALIGNMENT(STRICT_ALIGNMENT)
+SIM_AC_OPTION_BITSIZE([32], [31], [32])
+SIM_AC_OPTION_SCACHE(16384)
+SIM_AC_OPTION_DEFAULT_MODEL([or1200])
+SIM_AC_OPTION_ENVIRONMENT
+SIM_AC_OPTION_INLINE()
+SIM_AC_OPTION_CGEN_MAINT
+
+SIM_AC_OUTPUT
sim/or1k/mloop.in new file +242 -0

242 lines not on this page · raw message

sim/or1k/or1k-sim.h new file +95 -0

95 lines not on this page · raw message

sim/or1k/or1k.c new file +355 -0

355 lines not on this page · raw message

sim/or1k/sim-if.c new file +281 -0

281 lines not on this page · raw message

sim/or1k/sim-main.h new file +81 -0

81 lines not on this page · raw message

sim/or1k/traps.c new file +299 -0

299 lines not on this page · raw message

Signature · 1 line
2.13.5
#12 lore raw

PATCH v5 4/6 sim: or1k: add cgen generated files

In reply to Stafford Horne

These are the simulator files generated by cgen. These are split out from the main sim patch to make the patch easier to review and smaller.

sim/ChangeLog:

yyyy-mm-dd Stafford Horne <[email protected]>
Peter Gavin <[email protected]>

* or1k/arch.c: Generated.
* or1k/arch.h: Generated.
* or1k/cpu.c: Generated.
* or1k/cpu.h: Generated.
* or1k/cpuall.h: Generated.
* or1k/decode.c: Generated.
* or1k/decode.h: Generated.
* or1k/model.c: Generated.
* or1k/sem-switch.c: Generated.
* or1k/sem.c: Generated.

---
 sim/or1k/arch.c       |    38 +
 sim/or1k/arch.h       |    50 +
 sim/or1k/cpu.c        | 10181 ++++++++++++++++++++++++++++++++++++++++++++++++
 sim/or1k/cpu.h        |  5024 ++++++++++++++++++++++++
 sim/or1k/cpuall.h     |    66 +
 sim/or1k/decode.c     |  2559 ++++++++++++
 sim/or1k/decode.h     |    94 +
 sim/or1k/model.c      |  3809 ++++++++++++++++++
 sim/or1k/sem-switch.c |  2748 +++++++++++++
 sim/or1k/sem.c        |  2953 ++++++++++++++
 10 files changed, 27522 insertions(+)
 create mode 100644 sim/or1k/arch.c
 create mode 100644 sim/or1k/arch.h
 create mode 100644 sim/or1k/cpu.c
 create mode 100644 sim/or1k/cpu.h
 create mode 100644 sim/or1k/cpuall.h
 create mode 100644 sim/or1k/decode.c
 create mode 100644 sim/or1k/decode.h
 create mode 100644 sim/or1k/model.c
 create mode 100644 sim/or1k/sem-switch.c
 create mode 100644 sim/or1k/sem.c
sim/or1k/arch.c new file +38 -0
new file mode 100644
index 0000000000..83a9815284
@@ -0,0 +1,38 @@
+/* Simulator support for or1k.
+
+THIS FILE IS MACHINE GENERATED WITH CGEN.
+
+Copyright 1996-2010 Free Software Foundation, Inc.
+
+This file is part of the GNU simulators.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   It is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this program; if not, write to the Free Software Foundation, Inc.,
+   51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+
+*/
+
+#include "sim-main.h"
+#include "bfd.h"
+
+const SIM_MACH *sim_machs[] =
+{
+#ifdef HAVE_CPU_OR1K32BF
+  & or32_mach,
+#endif
+#ifdef HAVE_CPU_OR1K32BF
+  & or32nd_mach,
+#endif
+  0
+};
+
sim/or1k/arch.h new file +50 -0

50 lines not on this page · raw message

sim/or1k/cpu.c new file +10181 -0

2,912 lines not on this page · raw message

sim/or1k/cpu.h new file +5024 -0

5,024 lines not on this page · raw message

sim/or1k/cpuall.h new file +66 -0

66 lines not on this page · raw message

sim/or1k/decode.c new file +2559 -0

2,559 lines not on this page · raw message

sim/or1k/decode.h new file +94 -0

94 lines not on this page · raw message

sim/or1k/model.c new file +3809 -0

3,809 lines not on this page · raw message

sim/or1k/sem-switch.c new file +2748 -0

2,748 lines not on this page · raw message

sim/or1k/sem.c new file +2953 -0

2,953 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.13.5

Part of the diff is not shown here. View the raw message.

#13 lore raw

PATCH v5 5/6 sim: or1k: add autoconf generated files

In reply to Stafford Horne

These are separted out to make the patch easier to read and smaller.

sim/ChangeLog:

yyyy-mm-dd Stafford Horne <[email protected]>
Peter Gavin <[email protected]>

* configure: Regenerated.
* or1k/aclocal.m4: Generated.
* or1k/config.in: Generated.
* or1k/configure: Generated.

---
 sim/configure       |     9 +
 sim/or1k/aclocal.m4 |   119 +
 sim/or1k/config.in  |   248 +
 sim/or1k/configure  | 16043 ++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 16419 insertions(+)
 create mode 100644 sim/or1k/aclocal.m4
 create mode 100644 sim/or1k/config.in
 create mode 100755 sim/or1k/configure
sim/configure +9 -0
index 243ecc90e3..b90152e7fb 100755
@@ -653,6 +653,7 @@ microblaze
 mips
 mn10300
 moxie
+or1k
 msp430
 rl78
 rx
@@ -3770,6 +3771,14 @@ subdirs="$subdirs aarch64"
 
 
        ;;
+   or1k-*-* | or1knd-*-*)
+
+  sim_arch=or1k
+  subdirs="$subdirs or1k"
+
+
+       sim_testsuite=yes
+       ;;
    rl78-*-*)
 
   sim_arch=rl78
sim/or1k/aclocal.m4 new file +119 -0

119 lines not on this page · raw message

sim/or1k/config.in new file +248 -0

248 lines not on this page · raw message

sim/or1k/configure new file +16043 -0

2,612 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.13.5

Part of the diff is not shown here. View the raw message.

#14 lore raw

PATCH v5 6/6 sim: testsuite: add testsuite for or1k sim

In reply to Stafford Horne

From: Peter Gavin <[email protected]>

This is the testsuite for the or1k sim, it tests running many of the basic architecture instructions on the openrisc sim.

sim/testsuite/sim/or1k/ChangeLog:

2017-10-04 Peter Gavin <[email protected]>
Stafford Horne <[email protected]>

* add.S: New file.
* alltests.exp: New file.
* and.S: New file.
* basic.S: New file.
* div.S: New file.
* ext.S: New file.
* find.S: New file.
* flag.S: New file.
* fpu.S: New file.
* jump.S: New file.
* load.S: New file.
* mac.S: New file.
* mfspr.S: New file.
* mul.S: New file.
* or.S: New file.
* or1k-asm-test-env.h: New file.
* or1k-asm-test-helpers.h: New file.
* or1k-asm-test.h: New file.
* or1k-asm.h: New file.
* or1k-test.ld: New file.
* ror.S: New file.
* shift.S: New file.
* spr-defs.h: New file.
* sub.S: New file.
* xor.S: New file.

sim/testsuite/ChangeLog:

2017-01-20 Stafford Horne <[email protected]>
Peter Gavin <[email protected]>

* testsuite/configure: Regenerated.

---
 sim/testsuite/configure                        |   4 +
 sim/testsuite/sim/or1k/add.S                   | 606 +++++++++++++++++++
 sim/testsuite/sim/or1k/alltests.exp            |  34 ++
 sim/testsuite/sim/or1k/and.S                   | 198 +++++++
 sim/testsuite/sim/or1k/basic.S                 | 522 +++++++++++++++++
 sim/testsuite/sim/or1k/div.S                   | 290 +++++++++
 sim/testsuite/sim/or1k/ext.S                   | 236 ++++++++
 sim/testsuite/sim/or1k/find.S                  | 100 ++++
 sim/testsuite/sim/or1k/flag.S                  | 378 ++++++++++++
 sim/testsuite/sim/or1k/fpu.S                   | 128 ++++
 sim/testsuite/sim/or1k/jump.S                  | 104 ++++
 sim/testsuite/sim/or1k/load.S                  | 358 ++++++++++++
 sim/testsuite/sim/or1k/mac.S                   | 778 +++++++++++++++++++++++++
 sim/testsuite/sim/or1k/mfspr.S                 | 171 ++++++
 sim/testsuite/sim/or1k/mul.S                   | 573 ++++++++++++++++++
 sim/testsuite/sim/or1k/or.S                    | 199 +++++++
 sim/testsuite/sim/or1k/or1k-asm-test-env.h     |  59 ++
 sim/testsuite/sim/or1k/or1k-asm-test-helpers.h | 121 ++++
 sim/testsuite/sim/or1k/or1k-asm-test.h         | 225 +++++++
 sim/testsuite/sim/or1k/or1k-asm.h              |  37 ++
 sim/testsuite/sim/or1k/or1k-test.ld            |  75 +++
 sim/testsuite/sim/or1k/ror.S                   | 159 +++++
 sim/testsuite/sim/or1k/shift.S                 | 541 +++++++++++++++++
 sim/testsuite/sim/or1k/spr-defs.h              | 120 ++++
 sim/testsuite/sim/or1k/sub.S                   | 201 +++++++
 sim/testsuite/sim/or1k/xor.S                   | 200 +++++++
 26 files changed, 6417 insertions(+)
 create mode 100644 sim/testsuite/sim/or1k/add.S
 create mode 100644 sim/testsuite/sim/or1k/alltests.exp
 create mode 100644 sim/testsuite/sim/or1k/and.S
 create mode 100644 sim/testsuite/sim/or1k/basic.S
 create mode 100644 sim/testsuite/sim/or1k/div.S
 create mode 100644 sim/testsuite/sim/or1k/ext.S
 create mode 100644 sim/testsuite/sim/or1k/find.S
 create mode 100644 sim/testsuite/sim/or1k/flag.S
 create mode 100644 sim/testsuite/sim/or1k/fpu.S
 create mode 100644 sim/testsuite/sim/or1k/jump.S
 create mode 100644 sim/testsuite/sim/or1k/load.S
 create mode 100644 sim/testsuite/sim/or1k/mac.S
 create mode 100644 sim/testsuite/sim/or1k/mfspr.S
 create mode 100644 sim/testsuite/sim/or1k/mul.S
 create mode 100644 sim/testsuite/sim/or1k/or.S
 create mode 100644 sim/testsuite/sim/or1k/or1k-asm-test-env.h
 create mode 100644 sim/testsuite/sim/or1k/or1k-asm-test-helpers.h
 create mode 100644 sim/testsuite/sim/or1k/or1k-asm-test.h
 create mode 100644 sim/testsuite/sim/or1k/or1k-asm.h
 create mode 100644 sim/testsuite/sim/or1k/or1k-test.ld
 create mode 100644 sim/testsuite/sim/or1k/ror.S
 create mode 100644 sim/testsuite/sim/or1k/shift.S
 create mode 100644 sim/testsuite/sim/or1k/spr-defs.h
 create mode 100644 sim/testsuite/sim/or1k/sub.S
 create mode 100644 sim/testsuite/sim/or1k/xor.S
sim/testsuite/configure +4 -0
index bbc3bea48d..e37bdbd8d8 100755
@@ -1888,6 +1888,10 @@ case "${target}" in
    msp430*-*-*)
        sim_arch=msp430
        ;;
+   or1k-*-* | or1knd-*-*)
+       sim_arch=or1k
+       sim_testsuite=yes
+       ;;
    rl78-*-*)
        sim_arch=rl78
        ;;
sim/testsuite/sim/or1k/add.S new file +606 -0

606 lines not on this page · raw message

sim/testsuite/sim/or1k/alltests.exp new file +34 -0
new file mode 100644
index 0000000000..4480590050
@@ -0,0 +1,34 @@
+# OR1K simulator testsuite.
+#
+# Copyright 2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+if [istarget or1k*-*-*] {
+
+    set all_machs "or1k"
+
+    global global_ld_options
+    set global_ld_options "-T $srcdir/$subdir/or1k-test.ld"
+
+    foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.S]] {
+
+	if ![runtest_file_p $runtests $src] {
+	    continue
+	}
+
+	run_sim_test $src $all_machs
+    }
+
+}
sim/testsuite/sim/or1k/and.S new file +198 -0

198 lines not on this page · raw message

sim/testsuite/sim/or1k/basic.S new file +522 -0

522 lines not on this page · raw message

sim/testsuite/sim/or1k/div.S new file +290 -0

290 lines not on this page · raw message

sim/testsuite/sim/or1k/ext.S new file +236 -0

236 lines not on this page · raw message

sim/testsuite/sim/or1k/find.S new file +100 -0

100 lines not on this page · raw message

sim/testsuite/sim/or1k/flag.S new file +378 -0

378 lines not on this page · raw message

sim/testsuite/sim/or1k/fpu.S new file +128 -0

128 lines not on this page · raw message

sim/testsuite/sim/or1k/jump.S new file +104 -0

104 lines not on this page · raw message

sim/testsuite/sim/or1k/load.S new file +358 -0

358 lines not on this page · raw message

sim/testsuite/sim/or1k/mac.S new file +778 -0

36 lines not on this page · raw message

sim/testsuite/sim/or1k/mfspr.S new file +171 -0

171 lines not on this page · raw message

sim/testsuite/sim/or1k/mul.S new file +573 -0

573 lines not on this page · raw message

sim/testsuite/sim/or1k/or.S new file +199 -0

199 lines not on this page · raw message

sim/testsuite/sim/or1k/or1k-asm-test-env.h new file +59 -0

59 lines not on this page · raw message

sim/testsuite/sim/or1k/or1k-asm-test-helpers.h new file +121 -0

121 lines not on this page · raw message

sim/testsuite/sim/or1k/or1k-asm-test.h new file +225 -0

225 lines not on this page · raw message

sim/testsuite/sim/or1k/or1k-asm.h new file +37 -0
new file mode 100644
index 0000000000..a4f05d8439

Lines of this file are not shown. View the raw message.

sim/testsuite/sim/or1k/or1k-test.ld new file +75 -0

75 lines not on this page · raw message

sim/testsuite/sim/or1k/ror.S new file +159 -0

159 lines not on this page · raw message

sim/testsuite/sim/or1k/shift.S new file +541 -0

541 lines not on this page · raw message

sim/testsuite/sim/or1k/spr-defs.h new file +120 -0

120 lines not on this page · raw message

sim/testsuite/sim/or1k/sub.S new file +201 -0

201 lines not on this page · raw message

sim/testsuite/sim/or1k/xor.S new file +200 -0

200 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.13.5

Part of the diff is not shown here. View the raw message.

#15 lore raw

v5 cover sim port for OpenRISC

In reply to Stafford Horne

Hi All,

In case people are looking for it the patch [5/6] containing a 16k line generated configure script was dropped my the mta.

Please let me know if you need it and I can send a .gz, the shortlog is:

sim/ChangeLog:

yyyy-mm-dd Stafford Horne <[email protected]>
Peter Gavin <[email protected]>

* configure: Regenerated.
* or1k/aclocal.m4: Generated.
* or1k/config.in: Generated.
* or1k/configure: Generated.

-Stafford

Quoted 271 lines · Stafford Horne

Hello,

(what I thought would be a few days turned into a month since the comments on v4)

Please find attached the sim patches that allow to get a basic OpenRISC system running. This was used to verify the OpenRISC gdb port.

The main author is Peter Gavin who should have his FSF copyright in place.

Request for comments on:
- The testcase has a few tests commented out. I do not plan to fix now, but hopefully be addressed after upstreaming.

# Guide to Code #

As Simon has requested I have tried to comment on the functions in the simulator implementation. But I want to provide some general architecture comments here for reference. Please let me know if there is a better place for these kind of docs.

The or1k sim uses the CGEN system to generate most of the simulator code. There is some documentation for CGEN on sourceware.org here:

https://sourceware.org/cgen/docs/cgen.html

In the binutils-gdb project there are several files which get combined to make up the CGEN simulator. The process for how those are built can be seen in or1k/Makefile.in. But the main files are:

MAIN
sim/common/nrun.c - the main() calls sim_open(), sim_resume() and others sim/or1k/sim-if.c - implements sim_open() and others used by nrun
when envoking sim in gdb, gdb uses sim_open() directly

CGEN input and generated files
cpu/or1k*.cpu - these define the hardware, model and semantics sim/or1k/arch.c - generated defines sim_machs array sim/or1k/cpu.c - *generated defines register setters and getters sim/or1k/decode.c - generated defines instruction decoder sim/or1k/model.c - generated defines instruction cycles sim/or1k/sem.c - *generated defines instruction operation semantics sim/or1k/sem-switch.c - *generated ditto but as a switch

ENGINE runs decode execute loop
sim/common/cgen-* - cgen implementation helpers sim/common/cgen-run.c - implements sim_resume() which runs the engine sim/common/genmloop.sh - helper script to generate mloop.c engine the
decode, execute loop
sim/or1k/mloop.in - openRISC implementation of mloop parts

EXTRAS callbacks from sem* to c code
sim/or1k/or1k.c - implements some instructions in c (not cgen schema) sim/or1k/traps.c - exception handler

For each sim architecture we have choices for how the mloop is implemented. The OpenRISC engine uses scache pbb (pseudo-basic-block) instruction extraction with both fast (sem-switch.c based) and full (sem.c based) implementations. The fast and full modes are switch via the command line options to the run command, i.e. --trace-insn will run in full mode.

# Building #

Simon asked for some details on how we build and test the openrisc sim. Here are some details:

                            ## TOOLCHAIN ##

This may not be needed as binutils contains most/all of the utilities required. But if needed, get this toolchain (this is the newlib binary, others also available)

https://github.com/openrisc/or1k-gcc/releases/download/or1k-5.4.0-20170218/or1k-elf-5.4.0-20170218.tar.xz

If you want to build that from scratch look to:

https://github.com/openrisc/newlib/blob/scripts/build.sh

                              ## GDB ##

In a directory along side binutils-gdb source

mkdir build-or1k-elf-gdb
cd build-or1k-elf-gdb

  ../binutils-gdb/configure --target=or1k-elf \
    --prefix=/opt/shorne/software/or1k \
    --disable-itcl \
    --disable-tk \
    --disable-tcl \
    --disable-winsup \
    --disable-gdbtk \
    --disable-libgui \
    --disable-rda \
    --disable-sid \
    --with-sysroot \
    --disable-newlib \
    --disable-libgloss \
    --disable-gas \
    --disable-ld \
    --disable-binutils \
    --disable-gprof \
    --with-system-zlib
  # make gdb, sim
  make
  # test sim
  cd sim
  make check

The sim creates a binary simulator too, you can run binaries such as hello world with:

  or1k-elf-gcc hello.c
  ./or1k/run --trace-insn ./a.out

# Test Results #

Sim dejagnu tests were added specifically for openrisc and used to test this. Please see the details of running the testsuite for sim below:

=== sim Summary ===

# of expected passes            18
/home/shorne/work/openrisc/build-gdb/sim/or1k/run 0.5

Thanks,
-Stafford

Changes since v4
* Added comments to most of the functions
* Implemented remainder fpu function
* Actually wire in fpu and error handling logic
* Added fpu test case

Changes since v3
* Cleaned up indentation and style of sim testsuite
* Cleaned up TODOs in testsuite
* Implemented range exception

Changes since v2
* Removed 64-bit implementation (reduced files)
* Removed cgen suffix patch
* Removed different builds for linux
* Removed unused macros
* Fixed gnu style issues pointed out by Mike
* Fixed copyrights (not Cygnus, added to each file)

Changes since v1
* Squashed sim patches into single sim patch
* Put Generated files in separate patch
* I have my sim/gdb copyright assignment complete

Peter Gavin (3):
sim: cgen: add remainder functions (needed for OR1K lf.rem.[sd])
sim: cgen: add MUL2OFSI and MUL1OFSI macros (needed for OR1K l.mul[u])
sim: testsuite: add testsuite for or1k sim

Stafford Horne (3):
sim: or1k: add or1k target to sim
sim: or1k: add cgen generated files
sim: or1k: add autoconf generated files

 sim/common/cgen-accfp.c                        |    40 +
 sim/common/cgen-fpu.h                          |     4 +
 sim/common/cgen-ops.h                          |    18 +
 sim/common/sim-fpu.c                           |    90 +-
 sim/common/sim-fpu.h                           |    13 +-
 sim/configure                                  |     9 +
 sim/configure.tgt                              |     4 +
 sim/or1k/Makefile.in                           |   147 +
 sim/or1k/aclocal.m4                            |   119 +
 sim/or1k/arch.c                                |    38 +
 sim/or1k/arch.h                                |    50 +
 sim/or1k/config.in                             |   248 +
 sim/or1k/configure                             | 16043 +++++++++++++++++++++++
 sim/or1k/configure.ac                          |    17 +
 sim/or1k/cpu.c                                 | 10181 ++++++++++++++
 sim/or1k/cpu.h                                 |  5024 +++++++
 sim/or1k/cpuall.h                              |    66 +
 sim/or1k/decode.c                              |  2559 ++++
 sim/or1k/decode.h                              |    94 +
 sim/or1k/mloop.in                              |   242 +
 sim/or1k/model.c                               |  3809 ++++++
 sim/or1k/or1k-sim.h                            |    95 +
 sim/or1k/or1k.c                                |   355 +
 sim/or1k/sem-switch.c                          |  2748 ++++
 sim/or1k/sem.c                                 |  2953 +++++
 sim/or1k/sim-if.c                              |   281 +
 sim/or1k/sim-main.h                            |    81 +
 sim/or1k/traps.c                               |   299 +
 sim/testsuite/configure                        |     4 +
 sim/testsuite/sim/or1k/add.S                   |   606 +
 sim/testsuite/sim/or1k/alltests.exp            |    34 +
 sim/testsuite/sim/or1k/and.S                   |   198 +
 sim/testsuite/sim/or1k/basic.S                 |   522 +
 sim/testsuite/sim/or1k/div.S                   |   290 +
 sim/testsuite/sim/or1k/ext.S                   |   236 +
 sim/testsuite/sim/or1k/find.S                  |   100 +
 sim/testsuite/sim/or1k/flag.S                  |   378 +
 sim/testsuite/sim/or1k/fpu.S                   |   128 +
 sim/testsuite/sim/or1k/jump.S                  |   104 +
 sim/testsuite/sim/or1k/load.S                  |   358 +
 sim/testsuite/sim/or1k/mac.S                   |   778 ++
 sim/testsuite/sim/or1k/mfspr.S                 |   171 +
 sim/testsuite/sim/or1k/mul.S                   |   573 +
 sim/testsuite/sim/or1k/or.S                    |   199 +
 sim/testsuite/sim/or1k/or1k-asm-test-env.h     |    59 +
 sim/testsuite/sim/or1k/or1k-asm-test-helpers.h |   121 +
 sim/testsuite/sim/or1k/or1k-asm-test.h         |   225 +
 sim/testsuite/sim/or1k/or1k-asm.h              |    37 +
 sim/testsuite/sim/or1k/or1k-test.ld            |    75 +
 sim/testsuite/sim/or1k/ror.S                   |   159 +
 sim/testsuite/sim/or1k/shift.S                 |   541 +
 sim/testsuite/sim/or1k/spr-defs.h              |   120 +
 sim/testsuite/sim/or1k/sub.S                   |   201 +
 sim/testsuite/sim/or1k/xor.S                   |   200 +
 54 files changed, 52037 insertions(+), 7 deletions(-)
 create mode 100644 sim/or1k/Makefile.in
 create mode 100644 sim/or1k/aclocal.m4
 create mode 100644 sim/or1k/arch.c
 create mode 100644 sim/or1k/arch.h
 create mode 100644 sim/or1k/config.in
 create mode 100755 sim/or1k/configure
 create mode 100644 sim/or1k/configure.ac
 create mode 100644 sim/or1k/cpu.c
 create mode 100644 sim/or1k/cpu.h
 create mode 100644 sim/or1k/cpuall.h
 create mode 100644 sim/or1k/decode.c
 create mode 100644 sim/or1k/decode.h
 create mode 100644 sim/or1k/mloop.in
 create mode 100644 sim/or1k/model.c
 create mode 100644 sim/or1k/or1k-sim.h
 create mode 100644 sim/or1k/or1k.c
 create mode 100644 sim/or1k/sem-switch.c
 create mode 100644 sim/or1k/sem.c
 create mode 100644 sim/or1k/sim-if.c
 create mode 100644 sim/or1k/sim-main.h
 create mode 100644 sim/or1k/traps.c
 create mode 100644 sim/testsuite/sim/or1k/add.S
 create mode 100644 sim/testsuite/sim/or1k/alltests.exp
 create mode 100644 sim/testsuite/sim/or1k/and.S
 create mode 100644 sim/testsuite/sim/or1k/basic.S
 create mode 100644 sim/testsuite/sim/or1k/div.S
 create mode 100644 sim/testsuite/sim/or1k/ext.S
 create mode 100644 sim/testsuite/sim/or1k/find.S
 create mode 100644 sim/testsuite/sim/or1k/flag.S
 create mode 100644 sim/testsuite/sim/or1k/fpu.S
 create mode 100644 sim/testsuite/sim/or1k/jump.S
 create mode 100644 sim/testsuite/sim/or1k/load.S
 create mode 100644 sim/testsuite/sim/or1k/mac.S
 create mode 100644 sim/testsuite/sim/or1k/mfspr.S
 create mode 100644 sim/testsuite/sim/or1k/mul.S
 create mode 100644 sim/testsuite/sim/or1k/or.S
 create mode 100644 sim/testsuite/sim/or1k/or1k-asm-test-env.h
 create mode 100644 sim/testsuite/sim/or1k/or1k-asm-test-helpers.h
 create mode 100644 sim/testsuite/sim/or1k/or1k-asm-test.h
 create mode 100644 sim/testsuite/sim/or1k/or1k-asm.h
 create mode 100644 sim/testsuite/sim/or1k/or1k-test.ld
 create mode 100644 sim/testsuite/sim/or1k/ror.S
 create mode 100644 sim/testsuite/sim/or1k/shift.S
 create mode 100644 sim/testsuite/sim/or1k/spr-defs.h
 create mode 100644 sim/testsuite/sim/or1k/sub.S
 create mode 100644 sim/testsuite/sim/or1k/xor.S
Signature · 1 line
2.13.5
#16 lore raw

v5 cover sim port for OpenRISC

In reply to Stafford Horne

Hello,

Sorry about that, also, the CGEN generated files did not make it through.

If you would like to retrieve them please ask me for them and ill send you a .gz. Or you can pull from my branch:

https://github.com/stffrdhrn/binutils-gdb.git or1k-upstream-v8

This is the commit:

https://github.com/stffrdhrn/binutils-gdb/commit/29922870480ae4fdfb37ad115db29b79f2eb47c9

-Stafford

Quoted 271 lines · Stafford Horne

Hello,

(what I thought would be a few days turned into a month since the comments on v4)

Please find attached the sim patches that allow to get a basic OpenRISC system running. This was used to verify the OpenRISC gdb port.

The main author is Peter Gavin who should have his FSF copyright in place.

Request for comments on:
- The testcase has a few tests commented out. I do not plan to fix now, but hopefully be addressed after upstreaming.

# Guide to Code #

As Simon has requested I have tried to comment on the functions in the simulator implementation. But I want to provide some general architecture comments here for reference. Please let me know if there is a better place for these kind of docs.

The or1k sim uses the CGEN system to generate most of the simulator code. There is some documentation for CGEN on sourceware.org here:

https://sourceware.org/cgen/docs/cgen.html

In the binutils-gdb project there are several files which get combined to make up the CGEN simulator. The process for how those are built can be seen in or1k/Makefile.in. But the main files are:

MAIN
sim/common/nrun.c - the main() calls sim_open(), sim_resume() and others sim/or1k/sim-if.c - implements sim_open() and others used by nrun
when envoking sim in gdb, gdb uses sim_open() directly

CGEN input and generated files
cpu/or1k*.cpu - these define the hardware, model and semantics sim/or1k/arch.c - generated defines sim_machs array sim/or1k/cpu.c - *generated defines register setters and getters sim/or1k/decode.c - generated defines instruction decoder sim/or1k/model.c - generated defines instruction cycles sim/or1k/sem.c - *generated defines instruction operation semantics sim/or1k/sem-switch.c - *generated ditto but as a switch

ENGINE runs decode execute loop
sim/common/cgen-* - cgen implementation helpers sim/common/cgen-run.c - implements sim_resume() which runs the engine sim/common/genmloop.sh - helper script to generate mloop.c engine the
decode, execute loop
sim/or1k/mloop.in - openRISC implementation of mloop parts

EXTRAS callbacks from sem* to c code
sim/or1k/or1k.c - implements some instructions in c (not cgen schema) sim/or1k/traps.c - exception handler

For each sim architecture we have choices for how the mloop is implemented. The OpenRISC engine uses scache pbb (pseudo-basic-block) instruction extraction with both fast (sem-switch.c based) and full (sem.c based) implementations. The fast and full modes are switch via the command line options to the run command, i.e. --trace-insn will run in full mode.

# Building #

Simon asked for some details on how we build and test the openrisc sim. Here are some details:

                            ## TOOLCHAIN ##

This may not be needed as binutils contains most/all of the utilities required. But if needed, get this toolchain (this is the newlib binary, others also available)

https://github.com/openrisc/or1k-gcc/releases/download/or1k-5.4.0-20170218/or1k-elf-5.4.0-20170218.tar.xz

If you want to build that from scratch look to:

https://github.com/openrisc/newlib/blob/scripts/build.sh

                              ## GDB ##

In a directory along side binutils-gdb source

mkdir build-or1k-elf-gdb
cd build-or1k-elf-gdb

  ../binutils-gdb/configure --target=or1k-elf \
    --prefix=/opt/shorne/software/or1k \
    --disable-itcl \
    --disable-tk \
    --disable-tcl \
    --disable-winsup \
    --disable-gdbtk \
    --disable-libgui \
    --disable-rda \
    --disable-sid \
    --with-sysroot \
    --disable-newlib \
    --disable-libgloss \
    --disable-gas \
    --disable-ld \
    --disable-binutils \
    --disable-gprof \
    --with-system-zlib
  # make gdb, sim
  make
  # test sim
  cd sim
  make check

The sim creates a binary simulator too, you can run binaries such as hello world with:

  or1k-elf-gcc hello.c
  ./or1k/run --trace-insn ./a.out

# Test Results #

Sim dejagnu tests were added specifically for openrisc and used to test this. Please see the details of running the testsuite for sim below:

=== sim Summary ===

# of expected passes            18
/home/shorne/work/openrisc/build-gdb/sim/or1k/run 0.5

Thanks,
-Stafford

Changes since v4
* Added comments to most of the functions
* Implemented remainder fpu function
* Actually wire in fpu and error handling logic
* Added fpu test case

Changes since v3
* Cleaned up indentation and style of sim testsuite
* Cleaned up TODOs in testsuite
* Implemented range exception

Changes since v2
* Removed 64-bit implementation (reduced files)
* Removed cgen suffix patch
* Removed different builds for linux
* Removed unused macros
* Fixed gnu style issues pointed out by Mike
* Fixed copyrights (not Cygnus, added to each file)

Changes since v1
* Squashed sim patches into single sim patch
* Put Generated files in separate patch
* I have my sim/gdb copyright assignment complete

Peter Gavin (3):
sim: cgen: add remainder functions (needed for OR1K lf.rem.[sd])
sim: cgen: add MUL2OFSI and MUL1OFSI macros (needed for OR1K l.mul[u])
sim: testsuite: add testsuite for or1k sim

Stafford Horne (3):
sim: or1k: add or1k target to sim
sim: or1k: add cgen generated files
sim: or1k: add autoconf generated files

 sim/common/cgen-accfp.c                        |    40 +
 sim/common/cgen-fpu.h                          |     4 +
 sim/common/cgen-ops.h                          |    18 +
 sim/common/sim-fpu.c                           |    90 +-
 sim/common/sim-fpu.h                           |    13 +-
 sim/configure                                  |     9 +
 sim/configure.tgt                              |     4 +
 sim/or1k/Makefile.in                           |   147 +
 sim/or1k/aclocal.m4                            |   119 +
 sim/or1k/arch.c                                |    38 +
 sim/or1k/arch.h                                |    50 +
 sim/or1k/config.in                             |   248 +
 sim/or1k/configure                             | 16043 +++++++++++++++++++++++
 sim/or1k/configure.ac                          |    17 +
 sim/or1k/cpu.c                                 | 10181 ++++++++++++++
 sim/or1k/cpu.h                                 |  5024 +++++++
 sim/or1k/cpuall.h                              |    66 +
 sim/or1k/decode.c                              |  2559 ++++
 sim/or1k/decode.h                              |    94 +
 sim/or1k/mloop.in                              |   242 +
 sim/or1k/model.c                               |  3809 ++++++
 sim/or1k/or1k-sim.h                            |    95 +
 sim/or1k/or1k.c                                |   355 +
 sim/or1k/sem-switch.c                          |  2748 ++++
 sim/or1k/sem.c                                 |  2953 +++++
 sim/or1k/sim-if.c                              |   281 +
 sim/or1k/sim-main.h                            |    81 +
 sim/or1k/traps.c                               |   299 +
 sim/testsuite/configure                        |     4 +
 sim/testsuite/sim/or1k/add.S                   |   606 +
 sim/testsuite/sim/or1k/alltests.exp            |    34 +
 sim/testsuite/sim/or1k/and.S                   |   198 +
 sim/testsuite/sim/or1k/basic.S                 |   522 +
 sim/testsuite/sim/or1k/div.S                   |   290 +
 sim/testsuite/sim/or1k/ext.S                   |   236 +
 sim/testsuite/sim/or1k/find.S                  |   100 +
 sim/testsuite/sim/or1k/flag.S                  |   378 +
 sim/testsuite/sim/or1k/fpu.S                   |   128 +
 sim/testsuite/sim/or1k/jump.S                  |   104 +
 sim/testsuite/sim/or1k/load.S                  |   358 +
 sim/testsuite/sim/or1k/mac.S                   |   778 ++
 sim/testsuite/sim/or1k/mfspr.S                 |   171 +
 sim/testsuite/sim/or1k/mul.S                   |   573 +
 sim/testsuite/sim/or1k/or.S                    |   199 +
 sim/testsuite/sim/or1k/or1k-asm-test-env.h     |    59 +
 sim/testsuite/sim/or1k/or1k-asm-test-helpers.h |   121 +
 sim/testsuite/sim/or1k/or1k-asm-test.h         |   225 +
 sim/testsuite/sim/or1k/or1k-asm.h              |    37 +
 sim/testsuite/sim/or1k/or1k-test.ld            |    75 +
 sim/testsuite/sim/or1k/ror.S                   |   159 +
 sim/testsuite/sim/or1k/shift.S                 |   541 +
 sim/testsuite/sim/or1k/spr-defs.h              |   120 +
 sim/testsuite/sim/or1k/sub.S                   |   201 +
 sim/testsuite/sim/or1k/xor.S                   |   200 +
 54 files changed, 52037 insertions(+), 7 deletions(-)
 create mode 100644 sim/or1k/Makefile.in
 create mode 100644 sim/or1k/aclocal.m4
 create mode 100644 sim/or1k/arch.c
 create mode 100644 sim/or1k/arch.h
 create mode 100644 sim/or1k/config.in
 create mode 100755 sim/or1k/configure
 create mode 100644 sim/or1k/configure.ac
 create mode 100644 sim/or1k/cpu.c
 create mode 100644 sim/or1k/cpu.h
 create mode 100644 sim/or1k/cpuall.h
 create mode 100644 sim/or1k/decode.c
 create mode 100644 sim/or1k/decode.h
 create mode 100644 sim/or1k/mloop.in
 create mode 100644 sim/or1k/model.c
 create mode 100644 sim/or1k/or1k-sim.h
 create mode 100644 sim/or1k/or1k.c
 create mode 100644 sim/or1k/sem-switch.c
 create mode 100644 sim/or1k/sem.c
 create mode 100644 sim/or1k/sim-if.c
 create mode 100644 sim/or1k/sim-main.h
 create mode 100644 sim/or1k/traps.c
 create mode 100644 sim/testsuite/sim/or1k/add.S
 create mode 100644 sim/testsuite/sim/or1k/alltests.exp
 create mode 100644 sim/testsuite/sim/or1k/and.S
 create mode 100644 sim/testsuite/sim/or1k/basic.S
 create mode 100644 sim/testsuite/sim/or1k/div.S
 create mode 100644 sim/testsuite/sim/or1k/ext.S
 create mode 100644 sim/testsuite/sim/or1k/find.S
 create mode 100644 sim/testsuite/sim/or1k/flag.S
 create mode 100644 sim/testsuite/sim/or1k/fpu.S
 create mode 100644 sim/testsuite/sim/or1k/jump.S
 create mode 100644 sim/testsuite/sim/or1k/load.S
 create mode 100644 sim/testsuite/sim/or1k/mac.S
 create mode 100644 sim/testsuite/sim/or1k/mfspr.S
 create mode 100644 sim/testsuite/sim/or1k/mul.S
 create mode 100644 sim/testsuite/sim/or1k/or.S
 create mode 100644 sim/testsuite/sim/or1k/or1k-asm-test-env.h
 create mode 100644 sim/testsuite/sim/or1k/or1k-asm-test-helpers.h
 create mode 100644 sim/testsuite/sim/or1k/or1k-asm-test.h
 create mode 100644 sim/testsuite/sim/or1k/or1k-asm.h
 create mode 100644 sim/testsuite/sim/or1k/or1k-test.ld
 create mode 100644 sim/testsuite/sim/or1k/ror.S
 create mode 100644 sim/testsuite/sim/or1k/shift.S
 create mode 100644 sim/testsuite/sim/or1k/spr-defs.h
 create mode 100644 sim/testsuite/sim/or1k/sub.S
 create mode 100644 sim/testsuite/sim/or1k/xor.S
Signature · 1 line
2.13.5
#2 lore raw

PATCH v5 1/6 sim: cgen: add remainder functions (needed for OR1K lf.rem.[sd])

In reply to Stafford Horne

As far as I can tell, this patch looks good, but I'm more or less clueless about floating point stuff...

I just pointed out nits:

Quoted 11 lines · Stafford Horne

From: Peter Gavin <[email protected]>

* sim/common/ChangeLog:

2016-05-21 Peter Gavin <[email protected]>
Stafford Horne <[email protected]>

* cgen-accfp.c (remsf, remdf): New function. (cgen_init_accurate_fpu): Add remsf and remdf.
* cgen-fpu.h (cgen_fp_ops): Add remsf, remdf, remxf and remtf.
* sim-fpu.c (sim_fpu_rem): New function.

Mention the change to sim_fpu_print_status.

sim-fpu.c contains other changes (comments added, lines removed). If you think the changes belong with this patch, mention them here, otherwise submit them as a separate patch.

Quoted 58 lines
sim/common/sim-fpu.c +54 -0
@@ -1551,6 +1551,89 @@ sim_fpu_div (sim_fpu *f,
 
 
 INLINE_SIM_FPU (int)
+sim_fpu_rem (sim_fpu *f,
+	     const sim_fpu *l,
+	     const sim_fpu *r)
+{
+  if (sim_fpu_is_snan (l))
+    {
+      *f = *l;
+      f->class = sim_fpu_class_qnan;
+      return sim_fpu_status_invalid_snan;
+    }
+  if (sim_fpu_is_snan (r))
+    {
+      *f = *r;
+      f->class = sim_fpu_class_qnan;
+      return sim_fpu_status_invalid_snan;
+    }
+  if (sim_fpu_is_qnan (l))
+    {
+      *f = *l;
+      f->class = sim_fpu_class_qnan;
+      return 0;
+    }
+  if (sim_fpu_is_qnan (r))
+    {
+      *f = *r;
+      f->class = sim_fpu_class_qnan;
+      return 0;
+    }
+  if (sim_fpu_is_infinity (l))
+    {
+      *f = sim_fpu_qnan;
+      return sim_fpu_status_invalid_irx;
+    }
+  if (sim_fpu_is_zero (r))
+    {
+      *f = sim_fpu_qnan;
+      return sim_fpu_status_invalid_div0;
+    }
+  if (sim_fpu_is_zero (l))
+    {
+      *f = *l;
+      return 0;
+    }
+  if (sim_fpu_is_infinity (r))
+    {
+      *f = *l;
+      return 0;
+    }
+  {
+    sim_fpu n, tmp;
+
+    /* Remainder is calculated as l-n*r, where n is l/r rounded to the
+       nearest integer.  The variable n is rounded half even.  */
+

sim/common/sim-fpu.c sim_fpu_div (sim_fpu *f, · line 1617

Quoted 10 lines
sim/common/sim-fpu.c +10 -0
+    sim_fpu_div (&n, l, r);
+    sim_fpu_round_64 (&n, 0, 0);
+
+    if (n.normal_exp < -1) /* If n looks like zero just return l.  */
+      {
+	*f = *l;
+	return 0;
+      }
+    else if (n.class == sim_fpu_class_number
+	&& n.normal_exp <= (NR_FRAC_GUARD)) /* If not too large round.  */

This line should be aligned with the opening parenthesis (well, one char to the right).

Quoted 6 lines
sim/common/sim-fpu.c +6 -0
+      do_normal_round (&n, (NR_FRAC_GUARD) - n.normal_exp, sim_fpu_round_near);
+
+    /* Mark 0's as zero so multiply can detect zero.  */
+    if (n.fraction == 0)
+      n.class = sim_fpu_class_zero;
+

sim/common/sim-fpu.c sim_fpu_div (sim_fpu *f, · line 1633

Quoted 10 lines
sim/common/sim-fpu.c +10 -0
+    /* Calculate n*r.  */
+    sim_fpu_mul (&tmp, &n, r);
+    sim_fpu_round_64 (&tmp, 0, 0);
+
+    /* Finally calculate l-n*r.  */
+    sim_fpu_sub (f, l, &tmp);
+
+    return 0;
+  }
+}

Thanks,

Simon

#6 lore raw

PATCH v5 2/6 sim: cgen: add MUL2OFSI and MUL1OFSI macros (needed for OR1K l.mul[u])

In reply to Stafford Horne
Quoted 8 lines · Stafford Horne

From: Peter Gavin <[email protected]>

sim/common/ChangeLog:

2012-03-14 Peter Gavin <[email protected]>

* cgen-ops.h (MUL2OFSI): New macro, 1's complement overflow. (MUL1OFSI): New macro, 2's complement overflow.

Macro? Aren't they functions?

Quoted 9 lines
---
 sim/common/cgen-ops.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
sim/common/cgen-ops.h +0 -0
index 97585d7943..ffbdf3fd6e 100644

sim/common/cgen-ops.h SUBOFQI (QI a, QI b, BI c) · line 637

Quoted 7 lines
sim/common/cgen-ops.h +4 -0
@@ -631,6 +631,22 @@ SUBOFQI (QI a, QI b, BI c)
   return res;
 }
 
+SEMOPS_INLINE BI
+MUL2OFSI (SI a, SI b)
+{
+  DI tmp = MULDI (EXTSIDI(a), EXTSIDI(b));

Add spaces before the parentheses.

sim/common/cgen-ops.h SUBOFQI (QI a, QI b, BI c) · line 645

Quoted 8 lines
sim/common/cgen-ops.h +8 -0
+  BI res = tmp < -0x80000000LL || tmp > 0x7fffffffLL;
+  return res;
+}
+
+SEMOPS_INLINE BI
+MUL1OFSI (USI a, USI b)
+{
+  UDI tmp = MULDI (ZEXTSIDI(a), ZEXTSIDI(b));

Here too.

Otherwise, this patch makes sense to me.

Simon

#9 lore raw

PATCH v5 3/6 sim: or1k: add or1k target to sim

In reply to Stafford Horne
Quoted 47 lines · Stafford Horne

This adds the OpenRISC 32-bit sim target. The OpenRISC sim is a CGEN based sim so the bulk of the code is generated from the .cpu files by CGEN. The engine decode and execute logic in mloop uses scache with pseudo-basic-block extraction and supports both full and fast (switch) modes.

The sim does not implement an mmu at the moment. The sim does implement fpu instructions via the common sim-fpu implementation.

sim/ChangeLog:

2017-09-13 Stafford Horne <[email protected]>
Peter Gavin <[email protected]>

* configure.tgt: Add or1k sim.
* or1k/Makefile.in: New file.
* or1k/configure.ac: New file.> * or1k/mloop.in: New file.
* or1k/or1k-sim.h: New file.
* or1k/or1k.c: New file.
* or1k/sim-if.c: New file.
* or1k/sim-main.h: New file.
* or1k/traps.c: New file.

---
 sim/configure.tgt     |   4 +
 sim/or1k/Makefile.in  | 147 +++++++++++++++++++++
 sim/or1k/configure.ac |  17 +++
 sim/or1k/mloop.in     | 242 ++++++++++++++++++++++++++++++++++
 sim/or1k/or1k-sim.h   |  95 ++++++++++++++
 sim/or1k/or1k.c       | 355 ++++++++++++++++++++++++++++++++++++++++++++++++++
 sim/or1k/sim-if.c     | 281 +++++++++++++++++++++++++++++++++++++++
 sim/or1k/sim-main.h   |  81 ++++++++++++
 sim/or1k/traps.c      | 299 ++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 1521 insertions(+)
 create mode 100644 sim/or1k/Makefile.in
 create mode 100644 sim/or1k/configure.ac
 create mode 100644 sim/or1k/mloop.in
 create mode 100644 sim/or1k/or1k-sim.h
 create mode 100644 sim/or1k/or1k.c
 create mode 100644 sim/or1k/sim-if.c
 create mode 100644 sim/or1k/sim-main.h
 create mode 100644 sim/or1k/traps.c
sim/configure.tgt +0 -0
index c958fb3174..82b0e89240 100644

sim/configure.tgt case "${target}" in · line 81

Quoted 6 lines
sim/configure.tgt +3 -0
@@ -76,6 +76,10 @@ case "${target}" in
    msp430*-*-*)
        SIM_ARCH(msp430)
        ;;
+   or1k-*-* | or1knd-*-*)
+       SIM_ARCH(or1k)
+       sim_testsuite=yes

sim_testsuite seems like it has been removed some time ago.

sim/or1k/Makefile.in line 2

Quoted 12 lines
sim/configure.tgt +1 -0
+       ;;
    rl78-*-*)
        SIM_ARCH(rl78)
        ;;
sim/or1k/Makefile.in new file +2 -0
new file mode 100644
index 0000000000..fdc0f01ae1
@@ -0,0 +1,147 @@
+# Makefile template for configure for the or1k simulator
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.

You used 1996 as the starting date for the copyright for all the files, is it right? If your code was originally copied from existing code with that date, or if the code really dates from 1996, that's fine. Otherwise, it should probably be 2017 or the year the work started.

Quoted 47 lines
sim/or1k/or1k-sim.h new file +41 -0
new file mode 100644
index 0000000000..4cb6dd8b4c
@@ -0,0 +1,95 @@
+/* OpenRISC simulator support code header
+   Copyright (C) 1996-2017 Free Software Foundation, Inc.
+
+   This file is part of GDB, the GNU debugger.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef OR1K_SIM_H
+#define OR1K_SIM_H
+
+#include "symcat.h"
+
+/* GDB register numbers.  */
+#define PPC_REGNUM	32
+#define PC_REGNUM	33
+#define SR_REGNUM	34
+
+/* Misc. profile data.  */
+typedef struct
+{
+} OR1K_MISC_PROFILE;
+
+/* Nop codes used in nop simulation.  */
+#define NOP_NOP         0x0
+#define NOP_EXIT        0x1
+#define NOP_REPORT      0x2
+#define NOP_PUTC        0x4
+#define NOP_CNT_RESET   0x5
+#define NOP_GET_TICKS   0x6
+#define NOP_GET_PS      0x7

sim/or1k/or1k-sim.h line 51

Quoted 10 lines
sim/or1k/or1k-sim.h new file +10 -0
+#define NOP_TRACE_ON    0x8
+#define NOP_TRACE_OFF   0x9
+#define NOP_RANDOM      0xa
+#define NOP_OR1KSIM     0xb
+#define NOP_EXIT_SILENT 0xc
+
+#define NUM_SPR 0x20000
+#define SPR_GROUP_SHIFT 11
+#define SPR_GROUP_FIRST(group) (((UWI) SPR_GROUP_##group) << SPR_GROUP_SHIFT)
+#define SPR_ADDR(group,index) (SPR_GROUP_FIRST(group) | ((UWI) SPR_INDEX_##group##_##index))

Unless sim/ has some special rule allowing things to overflow 80 columns, these lines will have to be wrapped.

sim/or1k/or1k-sim.h line 57

Quoted 6 lines
sim/or1k/or1k-sim.h new file +6 -0
+
+/* Define word getters and setter helpers based on those from sim/common/cgen-mem.h.  */
+#define GETTWI GETTSI
+#define SETTWI SETTSI
+
+void or1k_cpu_init (SIM_DESC sd, sim_cpu * current_cpu, const USI or1k_vr,

Throughout, there are spurious after * in types.

sim/or1k/or1k-sim.h line 62

Quoted 5 lines
sim/or1k/or1k-sim.h new file +5 -0
+#define CHECK_SPR_FIELD(GROUP, INDEX, FIELD, test)                      \
+  do {                                                                  \
+    USI field = GET_H_##SYS##_##INDEX##_##FIELD ();                     \
+    if (!(test)) {                                                      \
+      sim_io_eprintf(sd, "WARNING: unsupported %s field in %s register: 0x%x\n", \

80 columns.

Quoted 33 lines
sim/or1k/or1k-sim.h new file +33 -0
+                     #FIELD, #INDEX, field);                            \
+    }                                                                   \
+  } while (0)
+
+  /* Set flags indicating if we are in a delay slot or not.  */
+  current_cpu->next_delay_slot = 0;
+  current_cpu->delay_slot = 0;
+
+  /* Verify any user passed fields and warn on configurations we don't
+     support.  */
+  CHECK_SPR_FIELD (SYS, UPR, UP, field == 1);
+  CHECK_SPR_FIELD (SYS, UPR, DCP, field == 0);
+  CHECK_SPR_FIELD (SYS, UPR, ICP, field == 0);
+  CHECK_SPR_FIELD (SYS, UPR, DMP, field == 0);
+  CHECK_SPR_FIELD (SYS, UPR, MP, field == 0);
+  CHECK_SPR_FIELD (SYS, UPR, IMP, field == 0);
+  CHECK_SPR_FIELD (SYS, UPR, DUP, field == 0);
+  CHECK_SPR_FIELD (SYS, UPR, PCUP, field == 0);
+  CHECK_SPR_FIELD (SYS, UPR, PICP, field == 0);
+  CHECK_SPR_FIELD (SYS, UPR, PMP, field == 0);
+  CHECK_SPR_FIELD (SYS, UPR, TTP, field == 0);
+  CHECK_SPR_FIELD (SYS, UPR, CUP, field == 0);
+
+  CHECK_SPR_FIELD (SYS, CPUCFGR, NSGR, field == 0);
+  CHECK_SPR_FIELD (SYS, CPUCFGR, CGF, field == 0);
+  CHECK_SPR_FIELD (SYS, CPUCFGR, OB32S, field == 1);
+  CHECK_SPR_FIELD (SYS, CPUCFGR, OF32S, field == 1);
+  CHECK_SPR_FIELD (SYS, CPUCFGR, OB64S, field == 0);
+  CHECK_SPR_FIELD (SYS, CPUCFGR, OF64S, field == 0);
+  CHECK_SPR_FIELD (SYS, CPUCFGR, OV64S, field == 0);
+
+#undef CHECK_SPR_FIELD
+

sim/or1k/or1k-sim.h

Quoted 10 lines
sim/or1k/or1k-sim.h new file +10 -0
+  /* Configure the fpu operations and mark fpu available.  */
+  cgen_init_accurate_fpu (current_cpu, CGEN_CPU_FPU (current_cpu),
+			  or1k32bf_fpu_error);
+  SET_H_SYS_CPUCFGR_OF32S (1);
+
+  /* Set the UPR[UP] flag, even if the user tried to unset it, as we always
+     support the Unit Present Register.  */
+  SET_H_SYS_UPR_UP (1);
+
+  /* Set the supervisor register to indicate we are in suprevisor mode and

"suprevisor"

Quoted 24 lines
sim/or1k/or1k-sim.h new file +24 -0
+/* Build an address value used for load and store instructions.  For
+   example, the instruction 'l.lws rD, I(rA)' will require to load data
+   from the 4 byte address represented by rA + I.  Here the argument base
+   is rA, offset is I and the size is the address size in bytes.  */
+
+USI
+or1k32bf_make_load_store_addr (sim_cpu * current_cpu, USI base, SI offset,
+			       int size)
+{
+  SIM_DESC sd = CPU_STATE (current_cpu);
+
+  USI addr = base + offset;
+
+  if (GET_H_SYS_SR_LEE ())
+    {
+      switch (size)
+	{
+
+	case 4:
+	  break;
+
+	case 2:
+	  addr ^= 0x2;
+	  break;

sim/or1k/or1k-sim.h

Quoted 10 lines
sim/or1k/or1k-sim.h new file +10 -0
+
+	case 1:
+	  addr ^= 0x3;
+	  break;
+
+	default:
+	  SIM_ASSERT (0);
+	  return 0;
+	}
+    }

That code looks strange to me. Enabling byte reordering (SR[LEE]) makes it so that each group of 4 bytes appears swapped in memory? Is this something a program can turn on/off at any time? There isn't much detail about that in the spec it seems.

Quoted 33 lines
sim/or1k/or1k-sim.h new file +33 -0
+/* Implement the OpenRISC exception function.  This is mostly used by the
+   CGEN generated files.  For example, this is used when handling a
+   overflow exception during a multiplication instruction. */
+
+void
+or1k32bf_exception (sim_cpu * current_cpu, USI pc, USI exnum)
+{
+  SIM_DESC sd = CPU_STATE (current_cpu);
+
+  if (exnum == EXCEPT_TRAP)
+    {
+      /* Trap, used for breakpoints, sends control back to gdb breakpoint
+	 handling.  */
+      sim_engine_halt (sd, current_cpu, NULL, pc, sim_stopped, SIM_SIGTRAP);
+    }
+  else
+    {
+
+      /* Calculate the exception program counter.  */
+      switch (exnum)
+	{
+	case EXCEPT_RESET:
+	  break;
+
+	case EXCEPT_FPE:
+	case EXCEPT_SYSCALL:
+	  SET_H_SYS_EPCR0 (pc + 4 - (current_cpu->delay_slot ? 4 : 0));
+	  break;
+
+	case EXCEPT_BUSERR:
+	case EXCEPT_ALIGN:
+	case EXCEPT_ILLEGAL:
+	case EXCEPT_RANGE:

sim/or1k/or1k-sim.h

Quoted 10 lines
sim/or1k/or1k-sim.h new file +10 -0
+	  SET_H_SYS_EPCR0 (pc - (current_cpu->delay_slot ? 4 : 0));
+	  break;
+
+	default:
+	  sim_io_error (sd, "unexpected exception 0x%x raised at PC 0x%08x",
+			exnum, pc);
+	  break;
+	}
+
+      /* Store the curent SR into ESR0.  */

"curent"

Thanks,

Simon

#3 lore raw

PATCH v5 1/6 sim: cgen: add remainder functions (needed for OR1K lf.rem.[sd])

In reply to Simon Marchi
Quoted 12 lines · Simon Marchi

As far as I can tell, this patch looks good, but I'm more or less clueless about floating point stuff...

I just pointed out nits:

Quoted 7 lines · Stafford Horne

From: Peter Gavin <[email protected]>

* sim/common/ChangeLog:

2016-05-21 Peter Gavin <[email protected]>
Stafford Horne <[email protected]>

Quoted 6 lines
Quoted 4 lines

* cgen-accfp.c (remsf, remdf): New function. (cgen_init_accurate_fpu): Add remsf and remdf.
* cgen-fpu.h (cgen_fp_ops): Add remsf, remdf, remxf and remtf.
* sim-fpu.c (sim_fpu_rem): New function.

Mention the change to sim_fpu_print_status.

Right, Thank you.

Quoted 1 line

sim-fpu.c contains other changes (comments added, lines removed). If you think the changes belong with this patch, mention them here, otherwise submit them as a separate patch.

I just removed them, they are noise. I saw them when I reviewed the patch but was not sure if it would be an issue to keep them.

Quoted 62 lines
Quoted 62 lines
sim/common/sim-fpu.c +58 -0
@@ -1551,6 +1551,89 @@ sim_fpu_div (sim_fpu *f,
 
 
 INLINE_SIM_FPU (int)
+sim_fpu_rem (sim_fpu *f,
+	     const sim_fpu *l,
+	     const sim_fpu *r)
+{
+  if (sim_fpu_is_snan (l))
+    {
+      *f = *l;
+      f->class = sim_fpu_class_qnan;
+      return sim_fpu_status_invalid_snan;
+    }
+  if (sim_fpu_is_snan (r))
+    {
+      *f = *r;
+      f->class = sim_fpu_class_qnan;
+      return sim_fpu_status_invalid_snan;
+    }
+  if (sim_fpu_is_qnan (l))
+    {
+      *f = *l;
+      f->class = sim_fpu_class_qnan;
+      return 0;
+    }
+  if (sim_fpu_is_qnan (r))
+    {
+      *f = *r;
+      f->class = sim_fpu_class_qnan;
+      return 0;
+    }
+  if (sim_fpu_is_infinity (l))
+    {
+      *f = sim_fpu_qnan;
+      return sim_fpu_status_invalid_irx;
+    }
+  if (sim_fpu_is_zero (r))
+    {
+      *f = sim_fpu_qnan;
+      return sim_fpu_status_invalid_div0;
+    }
+  if (sim_fpu_is_zero (l))
+    {
+      *f = *l;
+      return 0;
+    }
+  if (sim_fpu_is_infinity (r))
+    {
+      *f = *l;
+      return 0;
+    }
+  {
+    sim_fpu n, tmp;
+
+    /* Remainder is calculated as l-n*r, where n is l/r rounded to the
+       nearest integer.  The variable n is rounded half even.  */
+
+    sim_fpu_div (&n, l, r);
+    sim_fpu_round_64 (&n, 0, 0);
+
+    if (n.normal_exp < -1) /* If n looks like zero just return l.  */
Quoted 8 lines

sim/common/sim-fpu.c sim_fpu_div (sim_fpu *f, · line 1617

Quoted 6 lines
sim/common/sim-fpu.c +6 -0
+      {
+	*f = *l;
+	return 0;
+      }
+    else if (n.class == sim_fpu_class_number
+	&& n.normal_exp <= (NR_FRAC_GUARD)) /* If not too large round.  */

This line should be aligned with the opening parenthesis (well, one char to the right).

Right, that does move the comment out of the 80 char range, but just the ending '*/'. I hope thats ok.

Quoted 19 lines
Quoted 6 lines
sim/common/sim-fpu.c +6 -0
+      do_normal_round (&n, (NR_FRAC_GUARD) - n.normal_exp, sim_fpu_round_near);
+
+    /* Mark 0's as zero so multiply can detect zero.  */
+    if (n.fraction == 0)
+      n.class = sim_fpu_class_zero;
+

sim/common/sim-fpu.c sim_fpu_div (sim_fpu *f, · line 1633

Quoted 10 lines
sim/common/sim-fpu.c +10 -0
+    /* Calculate n*r.  */
+    sim_fpu_mul (&tmp, &n, r);
+    sim_fpu_round_64 (&tmp, 0, 0);
+
+    /* Finally calculate l-n*r.  */
+    sim_fpu_sub (f, l, &tmp);
+
+    return 0;
+  }
+}

Thanks,

Quoted 1 line

Simon

Thank you,
-Stafford

#7 lore raw

PATCH v5 2/6 sim: cgen: add MUL2OFSI and MUL1OFSI macros (needed for OR1K l.mul[u])

In reply to Simon Marchi
Quoted 11 lines · Simon Marchi
Quoted 8 lines · Stafford Horne

From: Peter Gavin <[email protected]>

sim/common/ChangeLog:

2012-03-14 Peter Gavin <[email protected]>

* cgen-ops.h (MUL2OFSI): New macro, 1's complement overflow. (MUL1OFSI): New macro, 2's complement overflow.

Macro? Aren't they functions?

Yes, I am not sure where macro came from. Maybe I added that, maybe it was there before.

Quoted 12 lines
Quoted 12 lines
---
 sim/common/cgen-ops.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
sim/common/cgen-ops.h +0 -0
index 97585d7943..ffbdf3fd6e 100644
@@ -631,6 +631,22 @@ SUBOFQI (QI a, QI b, BI c)
   return res;
 }
 
Quoted 6 lines

sim/common/cgen-ops.h SUBOFQI (QI a, QI b, BI c) · line 637

Quoted 4 lines
sim/common/cgen-ops.h +4 -0
+SEMOPS_INLINE BI
+MUL2OFSI (SI a, SI b)
+{
+  DI tmp = MULDI (EXTSIDI(a), EXTSIDI(b));

Add spaces before the parentheses.

Right, fixed.

Quoted 11 lines

sim/common/cgen-ops.h SUBOFQI (QI a, QI b, BI c) · line 645

Quoted 8 lines
sim/common/cgen-ops.h +8 -0
+  BI res = tmp < -0x80000000LL || tmp > 0x7fffffffLL;
+  return res;
+}
+
+SEMOPS_INLINE BI
+MUL1OFSI (USI a, USI b)
+{
+  UDI tmp = MULDI (ZEXTSIDI(a), ZEXTSIDI(b));

Here too.

Quoted 3 lines

Otherwise, this patch makes sense to me.

Simon

Thank You
-Stafford

#4 lore raw

PATCH v5 1/6 sim: cgen: add remainder functions (needed for OR1K lf.rem.[sd])

In reply to Stafford Horne
Quoted 11 lines · Stafford Horne
Quoted 10 lines

sim/common/sim-fpu.c sim_fpu_div (sim_fpu *f, · line 1617

Quoted 7 lines
sim/common/sim-fpu.c +7 -0
+    if (n.normal_exp < -1) /* If n looks like zero just return l.  */
+      {
+	*f = *l;
+	return 0;
+      }
+    else if (n.class == sim_fpu_class_number
+	&& n.normal_exp <= (NR_FRAC_GUARD)) /* If not too large round.  */

This line should be aligned with the opening parenthesis (well, one char to the right).

Quoted 3 lines

Right, that does move the comment out of the 80 char range, but just the
ending '*/'. I hope thats ok.

Hmm, when I try it the trailing */ arrives right before the 80th column.

Simon

#10 lore raw

PATCH v5 3/6 sim: or1k: add or1k target to sim

In reply to Simon Marchi
Quoted 43 lines · Simon Marchi
Quoted 42 lines · Stafford Horne

This adds the OpenRISC 32-bit sim target. The OpenRISC sim is a CGEN based sim so the bulk of the code is generated from the .cpu files by CGEN. The engine decode and execute logic in mloop uses scache with pseudo-basic-block extraction and supports both full and fast (switch) modes.

The sim does not implement an mmu at the moment. The sim does implement fpu instructions via the common sim-fpu implementation.

sim/ChangeLog:

2017-09-13 Stafford Horne <[email protected]>
Peter Gavin <[email protected]>

* configure.tgt: Add or1k sim.
* or1k/Makefile.in: New file.
* or1k/configure.ac: New file.> * or1k/mloop.in: New file.
* or1k/or1k-sim.h: New file.
* or1k/or1k.c: New file.
* or1k/sim-if.c: New file.
* or1k/sim-main.h: New file.
* or1k/traps.c: New file.

---
 sim/configure.tgt     |   4 +
 sim/or1k/Makefile.in  | 147 +++++++++++++++++++++
 sim/or1k/configure.ac |  17 +++
 sim/or1k/mloop.in     | 242 ++++++++++++++++++++++++++++++++++
 sim/or1k/or1k-sim.h   |  95 ++++++++++++++
 sim/or1k/or1k.c       | 355 ++++++++++++++++++++++++++++++++++++++++++++++++++
 sim/or1k/sim-if.c     | 281 +++++++++++++++++++++++++++++++++++++++
 sim/or1k/sim-main.h   |  81 ++++++++++++
 sim/or1k/traps.c      | 299 ++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 1521 insertions(+)
 create mode 100644 sim/or1k/Makefile.in
 create mode 100644 sim/or1k/configure.ac
 create mode 100644 sim/or1k/mloop.in
 create mode 100644 sim/or1k/or1k-sim.h
 create mode 100644 sim/or1k/or1k.c
 create mode 100644 sim/or1k/sim-if.c
 create mode 100644 sim/or1k/sim-main.h
 create mode 100644 sim/or1k/traps.c
Quoted 13 lines

sim/configure.tgt case "${target}" in · line 81

Quoted 11 lines
sim/configure.tgt +3 -0
index c958fb3174..82b0e89240 100644
@@ -76,6 +76,10 @@ case "${target}" in
    msp430*-*-*)
        SIM_ARCH(msp430)
        ;;
+   or1k-*-* | or1knd-*-*)
+       SIM_ARCH(or1k)
+       sim_testsuite=yes

sim_testsuite seems like it has been removed some time ago.

Right, removed.

Quoted 9 lines
Quoted 9 lines
sim/configure.tgt +1 -0
+       ;;
    rl78-*-*)
        SIM_ARCH(rl78)
        ;;
sim/or1k/Makefile.in new file +0 -0
new file mode 100644
index 0000000000..fdc0f01ae1
Quoted 8 lines

sim/or1k/Makefile.in line 2

Quoted 3 lines
sim/or1k/Makefile.in new file +2 -0
@@ -0,0 +1,147 @@
+# Makefile template for configure for the or1k simulator
+# Copyright (C) 1996-2017 Free Software Foundation, Inc.

You used 1996 as the starting date for the copyright for all the files, is it right? If your code was originally copied from existing code with that date, or if the code really dates from 1996, that's fine. Otherwise, it should probably be 2017 or the year the work started.

It was started in the last few years, not 1996. But I will put 2017 as the year it finally gets commited (hopefully).

Quoted 52 lines
Quoted 52 lines
sim/or1k/or1k-sim.h new file +46 -0
new file mode 100644
index 0000000000..4cb6dd8b4c
@@ -0,0 +1,95 @@
+/* OpenRISC simulator support code header
+   Copyright (C) 1996-2017 Free Software Foundation, Inc.
+
+   This file is part of GDB, the GNU debugger.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef OR1K_SIM_H
+#define OR1K_SIM_H
+
+#include "symcat.h"
+
+/* GDB register numbers.  */
+#define PPC_REGNUM	32
+#define PC_REGNUM	33
+#define SR_REGNUM	34
+
+/* Misc. profile data.  */
+typedef struct
+{
+} OR1K_MISC_PROFILE;
+
+/* Nop codes used in nop simulation.  */
+#define NOP_NOP         0x0
+#define NOP_EXIT        0x1
+#define NOP_REPORT      0x2
+#define NOP_PUTC        0x4
+#define NOP_CNT_RESET   0x5
+#define NOP_GET_TICKS   0x6
+#define NOP_GET_PS      0x7
+#define NOP_TRACE_ON    0x8
+#define NOP_TRACE_OFF   0x9
+#define NOP_RANDOM      0xa
+#define NOP_OR1KSIM     0xb
+#define NOP_EXIT_SILENT 0xc
Quoted 8 lines

sim/or1k/or1k-sim.h line 51

Quoted 5 lines
sim/or1k/or1k-sim.h new file +5 -0
+
+#define NUM_SPR 0x20000
+#define SPR_GROUP_SHIFT 11
+#define SPR_GROUP_FIRST(group) (((UWI) SPR_GROUP_##group) << SPR_GROUP_SHIFT)
+#define SPR_ADDR(group,index) (SPR_GROUP_FIRST(group) | ((UWI) SPR_INDEX_##group##_##index))

Unless sim/ has some special rule allowing things to overflow 80 columns, these lines will have to be wrapped.

OK

Quoted 8 lines

sim/or1k/or1k-sim.h line 57

Quoted 6 lines
sim/or1k/or1k-sim.h new file +6 -0
+
+/* Define word getters and setter helpers based on those from sim/common/cgen-mem.h.  */
+#define GETTWI GETTSI
+#define SETTWI SETTSI
+
+void or1k_cpu_init (SIM_DESC sd, sim_cpu * current_cpu, const USI or1k_vr,

Throughout, there are spurious after * in types.

OK, there are a few cases char * const *argv, char * const *envp) which look strange, but I see other examples with similar format. I would usually do 'const char **argv` but is the before-mentioned ok?

Quoted 7 lines

sim/or1k/or1k-sim.h line 62

Quoted 5 lines
sim/or1k/or1k-sim.h new file +5 -0
+#define CHECK_SPR_FIELD(GROUP, INDEX, FIELD, test)                      \
+  do {                                                                  \
+    USI field = GET_H_##SYS##_##INDEX##_##FIELD ();                     \
+    if (!(test)) {                                                      \
+      sim_io_eprintf(sd, "WARNING: unsupported %s field in %s register: 0x%x\n", \

80 columns.

OK, also noted the other issues like 'do {' should have '{' on the next line.

Quoted 36 lines
Quoted 36 lines
sim/or1k/or1k-sim.h new file +36 -0
+                     #FIELD, #INDEX, field);                            \
+    }                                                                   \
+  } while (0)
+
+  /* Set flags indicating if we are in a delay slot or not.  */
+  current_cpu->next_delay_slot = 0;
+  current_cpu->delay_slot = 0;> > +
+  /* Verify any user passed fields and warn on configurations we don't
+     support.  */
+  CHECK_SPR_FIELD (SYS, UPR, UP, field == 1);
+  CHECK_SPR_FIELD (SYS, UPR, DCP, field == 0);
+  CHECK_SPR_FIELD (SYS, UPR, ICP, field == 0);
+  CHECK_SPR_FIELD (SYS, UPR, DMP, field == 0);
+  CHECK_SPR_FIELD (SYS, UPR, MP, field == 0);
+  CHECK_SPR_FIELD (SYS, UPR, IMP, field == 0);
+  CHECK_SPR_FIELD (SYS, UPR, DUP, field == 0);
+  CHECK_SPR_FIELD (SYS, UPR, PCUP, field == 0);
+  CHECK_SPR_FIELD (SYS, UPR, PICP, field == 0);
+  CHECK_SPR_FIELD (SYS, UPR, PMP, field == 0);
+  CHECK_SPR_FIELD (SYS, UPR, TTP, field == 0);
+  CHECK_SPR_FIELD (SYS, UPR, CUP, field == 0);
+
+  CHECK_SPR_FIELD (SYS, CPUCFGR, NSGR, field == 0);
+  CHECK_SPR_FIELD (SYS, CPUCFGR, CGF, field == 0);
+  CHECK_SPR_FIELD (SYS, CPUCFGR, OB32S, field == 1);
+  CHECK_SPR_FIELD (SYS, CPUCFGR, OF32S, field == 1);
+  CHECK_SPR_FIELD (SYS, CPUCFGR, OB64S, field == 0);
+  CHECK_SPR_FIELD (SYS, CPUCFGR, OF64S, field == 0);
+  CHECK_SPR_FIELD (SYS, CPUCFGR, OV64S, field == 0);
+
+#undef CHECK_SPR_FIELD
+
+  /* Configure the fpu operations and mark fpu available.  */
+  cgen_init_accurate_fpu (current_cpu, CGEN_CPU_FPU (current_cpu),
+			  or1k32bf_fpu_error);
+  SET_H_SYS_CPUCFGR_OF32S (1);
Quoted 8 lines

sim/or1k/or1k-sim.h

Quoted 6 lines
sim/or1k/or1k-sim.h new file +6 -0
+
+  /* Set the UPR[UP] flag, even if the user tried to unset it, as we always
+     support the Unit Present Register.  */
+  SET_H_SYS_UPR_UP (1);
+
+  /* Set the supervisor register to indicate we are in suprevisor mode and

"suprevisor"

OK.

Quoted 30 lines
Quoted 30 lines
sim/or1k/or1k-sim.h new file +30 -0
+/* Build an address value used for load and store instructions.  For
+   example, the instruction 'l.lws rD, I(rA)' will require to load data
+   from the 4 byte address represented by rA + I.  Here the argument base
+   is rA, offset is I and the size is the address size in bytes.  */
+
+USI
+or1k32bf_make_load_store_addr (sim_cpu * current_cpu, USI base, SI offset,
+			       int size)
+{
+  SIM_DESC sd = CPU_STATE (current_cpu);
+
+  USI addr = base + offset;
+
+  if (GET_H_SYS_SR_LEE ())
+    {
+      switch (size)
+	{
+
+	case 4:
+	  break;
+
+	case 2:
+	  addr ^= 0x2;
+	  break;
+
+	case 1:
+	  addr ^= 0x3;
+	  break;
+
+	default:
Quoted 8 lines

sim/or1k/or1k-sim.h

Quoted 4 lines
sim/or1k/or1k-sim.h new file +4 -0
+	  SIM_ASSERT (0);
+	  return 0;
+	}
+    }

That code looks strange to me. Enabling byte reordering (SR[LEE]) makes it so that each group of 4 bytes appears swapped in memory? Is this something a program can turn on/off at any time? There isn't much detail about that in the spec it seems.

I have added some more comments to this in the next patch series. I am not to sure as to the 'why' for this functionality. But I assume its probably to interact with hardware like graphics cards which only support little-endian addressing. The SR[LEE] would only be available to change in supervisor mode, so not just any program could change it.

The above code only handles the address translation (note for half-word access openrisc requires the address to be half-word aligned).

Quoted 37 lines
Quoted 37 lines
sim/or1k/or1k-sim.h new file +37 -0
+/* Implement the OpenRISC exception function.  This is mostly used by the
+   CGEN generated files.  For example, this is used when handling a
+   overflow exception during a multiplication instruction. */
+
+void
+or1k32bf_exception (sim_cpu * current_cpu, USI pc, USI exnum)
+{
+  SIM_DESC sd = CPU_STATE (current_cpu);
+
+  if (exnum == EXCEPT_TRAP)
+    {
+      /* Trap, used for breakpoints, sends control back to gdb breakpoint
+	 handling.  */
+      sim_engine_halt (sd, current_cpu, NULL, pc, sim_stopped, SIM_SIGTRAP);
+    }
+  else
+    {
+
+      /* Calculate the exception program counter.  */
+      switch (exnum)
+	{
+	case EXCEPT_RESET:
+	  break;
+
+	case EXCEPT_FPE:
+	case EXCEPT_SYSCALL:
+	  SET_H_SYS_EPCR0 (pc + 4 - (current_cpu->delay_slot ? 4 : 0));
+	  break;
+
+	case EXCEPT_BUSERR:
+	case EXCEPT_ALIGN:
+	case EXCEPT_ILLEGAL:
+	case EXCEPT_RANGE:
+	  SET_H_SYS_EPCR0 (pc - (current_cpu->delay_slot ? 4 : 0));
+	  break;
+
+	default:
Quoted 9 lines

sim/or1k/or1k-sim.h

Quoted 6 lines
sim/or1k/or1k-sim.h new file +6 -0
+	  sim_io_error (sd, "unexpected exception 0x%x raised at PC 0x%08x",
+			exnum, pc);
+	  break;
+	}
+
+      /* Store the curent SR into ESR0.  */

"curent"

OK.

FYI, also the testsuite patch aas a few long lines like:

	/* The sign extension produces unexpected results here.  */
	SHOULD_BE_LESS_THAN_UNSIGNED_I 0xFFFFFFFF - 1, 0xFFFF  /* 0xFFFF gets sign-extended to 0xFFFFFFFF.  */
	SHOULD_BE_LESS_THAN_UNSIGNED_I 0xFFFF7FFF, 0x8000  /* 0x8000 gets sign-extended to 0xFFFF8000.  */

I guess it should be like this? I don't mind the inline comments, but I guess convention is convention?

	/* 0xFFFF gets sign-extended to 0xFFFFFFFF.  */
	SHOULD_BE_LESS_THAN_UNSIGNED_I 0xFFFFFFFF - 1, 0xFFFF
	/* 0x8000 gets sign-extended to 0xFFFF8000.  */
	SHOULD_BE_LESS_THAN_UNSIGNED_I 0xFFFF7FFF, 0x8000

Thank you,

Stafford

#11 lore raw

PATCH v5 3/6 sim: or1k: add or1k target to sim

Quoted 4 lines · Stafford Horne
Quoted 3 lines

That code looks strange to me. Enabling byte reordering (SR[LEE]) makes it so that each group of 4 bytes appears swapped in memory? Is this something a program can turn on/off at any time? There isn't much detail about that in the spec it seems.

Quoted 8 lines

I have added some more comments to this in the next patch series. I am not to sure as to the 'why' for this functionality. But I assume its probably to interact with hardware like graphics cards which only support little-endian addressing. The SR[LEE] would only be available to change in supervisor mode, so not just any program could change it.

The above code only handles the address translation (note for half-word access openrisc requires the address to be half-word aligned).

Ok, thanks for the explanation.

Quoted 6 lines

FYI, also the testsuite patch aas a few long lines like:

	/* The sign extension produces unexpected results here.  */
	SHOULD_BE_LESS_THAN_UNSIGNED_I 0xFFFFFFFF - 1, 0xFFFF  /* 0xFFFF gets sign-extended to 0xFFFFFFFF.  */
	SHOULD_BE_LESS_THAN_UNSIGNED_I 0xFFFF7FFF, 0x8000  /* 0x8000 gets sign-extended to 0xFFFF8000.  */
Quoted 7 lines

I guess it should be like this? I don't mind the inline comments, but I guess convention is convention?

	/* 0xFFFF gets sign-extended to 0xFFFFFFFF.  */
	SHOULD_BE_LESS_THAN_UNSIGNED_I 0xFFFFFFFF - 1, 0xFFFF
	/* 0x8000 gets sign-extended to 0xFFFF8000.  */
	SHOULD_BE_LESS_THAN_UNSIGNED_I 0xFFFF7FFF, 0x8000

Personally I prefer with the comment above.

Simon