Files
unicorn/bindings/dotnet
Martin Atkins 7d8fe2ab11 riscv: Expose privilege level as pseudo-register PRIV (#1989)
Unlike some other architectures, RISC-V does not expose the current
privilege mode in any architecturally-defined register. That is intentional
to make it easier to implement virtualization in software, but a Unicorn
caller operates outside of the emulated hart and so it can and should be
able to observe and change the current privilege mode in order to properly
emulate certain behaviors of a real CPU.

The current privilege level is therefore now exposed as a new
pseudo-register using the name "priv", which matches the name of the
virtual register used by RISC-V's debug extension to allow the debugger
to read and change the privilege mode while the hart is halted. Unicorn's
use of it is conceptually similar to a debugger.

The bit encoding of this register is the same as specified in RISC-V Debug
Specification v1.0-rc3 Section 4.10.1. It's defined as a "virtual"
register exposing a subset of fields from the dcsr register, although here
it's implemented directly inside the Unicorn code because QEMU doesn't
currently have explicit support for the CSRs from the debug specification.
If it supports "dcsr" in a future release then this implementation could
change to wrap reading and writing that CSR and then projecting the "prv"
and "v" bitfields into the correct locations for the virtual register.
2024-11-11 21:09:45 +08:00
..
2024-09-26 18:44:51 +08:00

This documentation explains how to use the .NET binding for Unicorn from source.

  1. Install the core engine as a dependency

    Follow README in the root directory to compile & install the core.

  2. Compile the code

    You need to have at least version 5.0 of .NET installed.

    1. Windows

      To compile the code open the UnicornSln.sln with Microsoft Visual Studio 12 or with a newer version and just press Ctrl+Shift+B to build the solution.

    2. Linux

      To compile the code open a terminal in this directory and enter the following command to build the solution: dotnet build

  3. Usage

    The solution includes the testing project UnicornTests with examples of usage.

    In order to use the library in your project just add a reference to the .NET library and be sure to copy the unmanaged unicorn.dll library in the output directory.

    The naming convention used is the Upper Camel Case, this mean that to invoke the uc_mem_read method you have to search for the MemRead method.