Skip to content

Commit 546c01e

Browse files
authored
Merge pull request #283 from soronen/qemu_osal
C-callable functions for custom instruction evaluations
2 parents 5c65d18 + 4fc89d7 commit 546c01e

29 files changed

+4096
-16
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,15 @@ jobs:
6161
cmake \
6262
graphviz \
6363
bc \
64-
ghdl
64+
ghdl \
65+
python3 ninja-build pkg-config libglib2.0-dev \
66+
libpixman-1-dev libslirp-dev flex bison file device-tree-compiler \
67+
zlib1g-dev libfdt-dev python3-tomli \
68+
gcc-riscv64-unknown-elf
6569
66-
- name:
70+
sudo apt-get purge -y 'llvm-*' 'clang-*' 'libllvm-*' 'lld-*'
71+
72+
- name: Create workspace directory
6773
run: |
6874
mkdir -p ${{ github.workspace }}/local
6975
@@ -100,6 +106,11 @@ jobs:
100106
make -j$(nproc)
101107
make install
102108
109+
- name: install QEMU-OpenASIP
110+
run: |
111+
cd openasip
112+
python3 ./tools/scripts/install_qemu.py $HOME/qemu-openasip
113+
103114
- name: Run tests
104115
run: |
105116
cd openasip

openasip/doc/man/OpenASIP/OpenASIP.tex

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
\documentclass[a4paper,twoside]{tceusermanual}
2323
\usepackage{pslatex,verbatim}
2424
\usepackage{mathtools}
25-
\usepackage[dvipdfm]{hyperref}
25+
\usepackage{hyperref}
2626
\usepackage[font=footnotesize]{caption}
2727
\usepackage[font=footnotesize]{subfig}
2828
\usepackage{listings}
@@ -4136,6 +4136,66 @@ \subsection{Defining a custom operation using an HDL snippet}
41364136
but same information should still be printed to stdout meaning that the algorithm
41374137
was executed correctly.
41384138
4139+
\subsection{QEMU-OpenASIP}
4140+
4141+
Using RTL simulation for verifying and debugging software running in OpenASIP
4142+
designs with custom RISC-V instructions may be too slow, especially with
4143+
larger programs. To support faster early software development and debugging,
4144+
OpenASIP supports integration with QEMU: The base QEMU RISC-V model is used
4145+
for non-customized instructions and when the QEMU encounters an instruction it
4146+
doesn't recognize, OpenASIP emulates it using the OSAL definitions.
4147+
4148+
You can build the OpenASIP QEMU fork with:
4149+
4150+
\begin{verbatim}
4151+
$ git clone https://github.com/cpc/qemu-openasip.git
4152+
$ cd qemu-openasip
4153+
$ ./configure --target-list=riscv64-softmmu,riscv32-softmmu
4154+
$ make -j${nproc}
4155+
\end{verbatim}
4156+
4157+
And then you can run any program with custom OSAL instructions with the QEMU's
4158+
RISC-V 'virt' machine by specifying the new machine parameter \textbf{oasip\_machine}.
4159+
For example:
4160+
4161+
\begin{verbatim}
4162+
$ ./build/qemu-system-riscv32 \
4163+
-machine virt,oasip_machine=/path/to/machine.adf \
4164+
-bios none \
4165+
-nographic \
4166+
-no-reboot \
4167+
-kernel /path/to/program.elf
4168+
\end{verbatim}
4169+
4170+
The program (or "kernel") you want to execute should be a .elf file if you are targeting
4171+
baremetal, but for example RISC-V linux with a BusyBox works too. The process
4172+
for running a RISC-V program is not different from standard QEMU.
4173+
4174+
You can compile the program with custom instructions using oacc-riscv compiler
4175+
or standard riscv-unknown-elf-gcc, though in the latter case you must declare
4176+
your instructions in the insn-r bit format, for example:
4177+
4178+
\begin{verbatim}
4179+
# oacc-riscv can compile custom instructions written in the standard format:
4180+
_OA_RV_REFLECT32(remainder, output)
4181+
4182+
# with standard unknown-elf-gcc you have to write the custom instructions by hand:
4183+
asm volatile(".insn r 0x0B, 0x01, 0x00, %0, %1, x0"
4184+
: "=r"(output)
4185+
: "r"(remainder));
4186+
\end{verbatim}
4187+
4188+
You can find the bit format of an instruction with riscv-tdgen tool, also included
4189+
in OpenASIP if you have built it with the --enable-riscv flag.
4190+
\begin{verbatim}
4191+
$ riscv-tdgen -a /path/to/machine.adf -o out.txt
4192+
\end{verbatim}
4193+
4194+
Provided you have installed OpenASIP and the libopenasip.so is in your LD\_LIBRARY\_PATH,
4195+
QEMU will link to it and send all of the unknown instructions to OSAL for execution.
4196+
The instruction behaviors should be available in the standard paths,
4197+
see chapter~\ref{sec:osalpaths}.
4198+
41394199
\subsection{Final Words}
41404200
41414201
This tutorial is now finished. Now you should know how to customize
-1.56 MB
Binary file not shown.

openasip/src/base/osal/Makefile.am

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ libosal_la_SOURCES = OperationBehavior.cc OperationContext.cc \
88
OperationDAGEdge.cc OperationDAGBehavior.cc OperationDAGConverter.cc \
99
OperationDAGBuilder.cc OperationGlobals.cc OperationPoolPimpl.cc \
1010
OperationContextPimpl.cc OperationPimpl.cc ConstantNode.cc \
11-
OperationBuilder.cc
11+
OperationBuilder.cc RISCVInstructionExecutor.cc
1212

1313
PROJECT_ROOT = $(top_srcdir)
1414
DOXYGEN_CONFIG_FILE = ${PROJECT_ROOT}/tools/Doxygen/doxygen.config
1515
AM_CPPFLAGS = -I${PROJECT_ROOT}/src/tools \
1616
-I$(PROJECT_ROOT)/src/base/memory \
1717
-I../../applibs/Simulator \
18-
-I$(PROJECT_ROOT)/src/base/Graph ${LLVM_CPPFLAGS}
18+
-I$(PROJECT_ROOT)/src/base/Graph ${LLVM_CPPFLAGS} \
19+
-I$(PROJECT_ROOT)/src/applibs/bem \
20+
-I$(PROJECT_ROOT)/src/base/bem \
21+
-I$(PROJECT_ROOT)/src/base/mach
1922

2023
AM_CXXFLAGS = -UNDEBUG
2124

@@ -55,5 +58,6 @@ libosal_la_SOURCES += \
5558
OperationState.icc Operand.icc \
5659
Operation.icc OperationModule.icc \
5760
OperationBehavior.icc SimulateTriggerWrappers.icc \
58-
OperationPool.icc OperationIndex.icc
61+
OperationPool.icc OperationIndex.icc \
62+
RISCVInstructionExecutor.hh
5963
## headers end

openasip/src/base/osal/OperationBuilder.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ OperationBuilder::buildObject(
177177
specific functionality might not import all the symbols
178178
required by the .opb loaded by libopenasip later. */
179179
LDFLAGS += " -L" + Application::installationDir() + "/lib -lopenasip ";
180+
} else {
181+
LDFLAGS += " -L" + string(TCE_SRC_ROOT) + "/src/.libs -lopenasip ";
180182
}
181183

182184
// Add user defined CXXFLAGS + CPPFLAGS to the end because they

0 commit comments

Comments
 (0)