|
| 1 | +/* Modified by Nober <s0913768710@gmail.com> |
| 2 | + 13-DEC-2019 - Define all CSR macro |
| 3 | +*/ |
| 4 | + |
| 5 | +/* |
| 6 | +RISCV emulator for the RV32I architecture |
| 7 | +based on TinyEMU by Fabrice Bellard, see https://bellard.org/tinyemu/ |
| 8 | +stripped down for RV32I only, all "gotos" removed, and fixed some bugs for the compliance test |
| 9 | +by Frank Buss, 2018 |
| 10 | +
|
| 11 | +Requires libelf-dev: |
| 12 | +
|
| 13 | +sudo apt-get install libelf-dev |
| 14 | +
|
| 15 | +
|
| 16 | +Compile it like this: |
| 17 | +
|
| 18 | +gcc -O3 -Wall -lelf emu-rv32i.c -o emu-rv32i |
| 19 | +
|
| 20 | +
|
| 21 | +It is compatible to Spike for the command line arguments, which means you can run |
| 22 | +the compliance test from https://github.com/riscv/riscv-compliance like this: |
| 23 | +
|
| 24 | +make RISCV_TARGET=spike RISCV_DEVICE=rv32i TARGET_SIM=/full/path/emulator variant |
| 25 | +
|
| 26 | +It is also compatible with qemu32, as it is used for Zephyr. You can compile the |
| 27 | +Zephyr examples for qemu like this: |
| 28 | +
|
| 29 | +cd zephyr |
| 30 | +source zephyr-env.sh |
| 31 | +cd samples/synchronization |
| 32 | +mkdir build && cd build |
| 33 | +cmake -GNinja -DBOARD=qemu_riscv32 .. |
| 34 | +ninja |
| 35 | +
|
| 36 | +After this you can run it with the emulator like this: |
| 37 | +
|
| 38 | +emu-rv32i zephyr/zephyr.elf |
| 39 | +
|
| 40 | +
|
| 41 | +original copyright: |
| 42 | +*/ |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +/* |
| 47 | + * RISCV emulator |
| 48 | + * |
| 49 | + * Copyright (c) 2016 Fabrice Bellard |
| 50 | + * |
| 51 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 52 | + * of this software and associated documentation files (the "Software"), to deal |
| 53 | + * in the Software without restriction, including without limitation the rights |
| 54 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 55 | + * copies of the Software, and to permit persons to whom the Software is |
| 56 | + * furnished to do so, subject to the following conditions: |
| 57 | + * |
| 58 | + * The above copyright notice and this permission notice shall be included in |
| 59 | + * all copies or substantial portions of the Software. |
| 60 | + * |
| 61 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 62 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 63 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 64 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 65 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 66 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 67 | + * THE SOFTWARE. |
| 68 | + */ |
| 69 | + |
| 70 | +#include <stdint.h> |
| 71 | + |
| 72 | + |
| 73 | +// ====================================================== // |
| 74 | +// =================== User Trap Setup ================== // |
| 75 | +// ====================================================== // |
| 76 | +uint32_t ustatus; /* User status register */ |
| 77 | +uint32_t uie; /* User interrupt-enable register */ |
| 78 | +uint32_t utvec; /* User trap handler base address */ |
| 79 | +// ====================================================== // |
| 80 | +// ================= User Trap Handling ================= // |
| 81 | +// ====================================================== // |
| 82 | +uint32_t uscratch; /* Scratch register for user trap handlers*/ |
| 83 | +uint32_t uepc; /* User exception program counter */ |
| 84 | +uint32_t ucause; /* User trap cause*/ |
| 85 | +uint32_t ubadaddr; /* User bad address */ |
| 86 | +uint32_t uip; /* User interrupt pending */ |
| 87 | +// ====================================================== // |
| 88 | +// ============== User Floating-Point CSRs ============== // |
| 89 | +// ====================================================== // |
| 90 | +uint32_t fflags; /* Floating-Point Accrued Exceptions*/ |
| 91 | +uint32_t frm; /* Floating-Point Dynamic Rounding Mode*/ |
0 commit comments