README 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. SIM port for the OpenRISC architecture
  2. Authors: Stafford Horne <shorne@gmail.com>
  3. Peter Gavin
  4. # Guide to Code #
  5. We have tried to comment on the functions in the simulator implementation as
  6. best as we can. Here we provide some general architecture comments for
  7. reference. Please let me know if there is a better place for these kind of
  8. docs.
  9. The or1k sim uses the CGEN system to generate most of the simulator code. There
  10. is some documentation for CGEN on sourceware.org here:
  11. https://sourceware.org/cgen/docs/cgen.html
  12. In the binutils-gdb project there are several files which get combined to make
  13. up the CGEN simulator. The process for how those are built can be seen in
  14. `or1k/Makefile.in`. But the main files are:
  15. MAIN
  16. sim/common/nrun.c - the main() calls sim_open(), sim_resume() and others
  17. sim/or1k/sim-if.c - implements sim_open() and others used by nrun
  18. when envoking sim in gdb, gdb uses sim_open() directly
  19. CGEN input and generated files
  20. cpu/or1k*.cpu - these define the hardware, model and semantics
  21. sim/or1k/arch.c - generated defines sim_machs array
  22. sim/or1k/cpu.c - *generated defines register setters and getters
  23. sim/or1k/decode.c - generated defines instruction decoder
  24. sim/or1k/model.c - generated defines instruction cycles
  25. sim/or1k/sem.c - *generated defines instruction operation semantics
  26. sim/or1k/sem-switch.c - *generated ditto but as a switch
  27. ENGINE runs decode execute loop
  28. sim/common/cgen-* - cgen implementation helpers
  29. sim/common/cgen-run.c - implements sim_resume() which runs the engine
  30. sim/common/genmloop.sh - helper script to generate mloop.c engine the
  31. decode, execute loop
  32. sim/or1k/mloop.in - openRISC implementation of mloop parts
  33. EXTRAS callbacks from sem* to c code
  34. sim/or1k/or1k.c - implements some instructions in c (not cgen schema)
  35. sim/or1k/traps.c - exception handler
  36. For each sim architecture we have choices for how the mloop is implemented. The
  37. OpenRISC engine uses scache pbb (pseudo-basic-block) instruction extraction with
  38. both fast (sem-switch.c based) and full (sem.c based) implementations. The fast
  39. and full modes are switch via the command line options to the `run` command,
  40. i.e. --trace-insn will run in full mode.
  41. # Building #
  42. Below are some details on how we build and test the openrisc sim.
  43. ## TOOLCHAIN ##
  44. This may not be needed as binutils contains most/all of the utilities required.
  45. But if needed, get this toolchain (this is the newlib binary, others also
  46. available)
  47. https://github.com/openrisc/or1k-gcc/releases/download/or1k-5.4.0-20170218/or1k-elf-5.4.0-20170218.tar.xz
  48. If you want to build that from scratch look to:
  49. https://github.com/openrisc/newlib/blob/scripts/build.sh
  50. ## GDB ##
  51. In a directory along side binutils-gdb source
  52. mkdir build-or1k-elf-gdb
  53. cd build-or1k-elf-gdb
  54. ../binutils-gdb/configure --target=or1k-elf \
  55. --prefix=/opt/shorne/software/or1k \
  56. --disable-itcl \
  57. --disable-tk \
  58. --disable-tcl \
  59. --disable-winsup \
  60. --disable-gdbtk \
  61. --disable-libgui \
  62. --disable-rda \
  63. --disable-sid \
  64. --with-sysroot \
  65. --disable-newlib \
  66. --disable-libgloss \
  67. --disable-gas \
  68. --disable-ld \
  69. --disable-binutils \
  70. --disable-gprof \
  71. --with-system-zlib
  72. # make gdb, sim
  73. make
  74. # test sim
  75. cd sim
  76. make check
  77. The sim creates a binary simulator too, you can run binaries such as hello
  78. world with:
  79. or1k-elf-gcc hello.c
  80. ./or1k/run --trace-insn ./a.out