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.
unicorn-engine-pascal
Pascal/Delphi language binding for the Unicorn emulator (GitHub).
Unicorn is a lightweight multi-platform, multi-architecture CPU emulator framework based on QEMU.
License
GPLv2
Compilers Compatibility
Free Pascal >= v3
Mac OSWindowsLinux
Delphi
Windows
Features
-
Same API as the C core
-
with some workarounds for Pascals case insensitivity:
uc_mem_write()->uc_mem_write_(),uc_mem_read()->uc_mem_read_() -
and the missing feature passing variable number of arguments to functions (
...):i solve it by using ->
args : Array of Const;you can pass args inside [] like :uc_hook_add(uc, trace, UC_HOOK_INSN, @HookIn, nil, 1,0,[UC_X86_INS_IN];the main loader in
Unicorn_dyn.pas, check X86 example for more info .
-
-
Multiplatform (Mac OS , Windows and Linux are tested)
Examples
X86Emulate 16, 32, 64 Bit x86
Version History
1.1- Add Delphi Compatibility [ Windows ]
1.0- this is the first version it has all APIs of UNICORN v1.0.1
TODO
- Add more Examples
- Add Mac , Linux Support for Delphi