|
22 | 22 | \documentclass[a4paper,twoside]{tceusermanual} |
23 | 23 | \usepackage{pslatex,verbatim} |
24 | 24 | \usepackage{mathtools} |
25 | | -\usepackage[dvipdfm]{hyperref} |
| 25 | +\usepackage{hyperref} |
26 | 26 | \usepackage[font=footnotesize]{caption} |
27 | 27 | \usepackage[font=footnotesize]{subfig} |
28 | 28 | \usepackage{listings} |
@@ -4136,6 +4136,66 @@ \subsection{Defining a custom operation using an HDL snippet} |
4136 | 4136 | but same information should still be printed to stdout meaning that the algorithm |
4137 | 4137 | was executed correctly. |
4138 | 4138 |
|
| 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 | +
|
4139 | 4199 | \subsection{Final Words} |
4140 | 4200 |
|
4141 | 4201 | This tutorial is now finished. Now you should know how to customize |
|
0 commit comments