37#define MAP_ANONYMOUS MAP_ANON
42 {
"ITCM", 0x00000000UL, 0x00010000UL},
43 {
"MRAM", 0x02000000UL, 0x00100000UL},
44 {
"TRIM", 0x02C1E000UL, 0x00001000UL},
52 {
"OFS_CFG", 0x02C9F000UL, 0x00001000UL},
57 {
"OFS_OTP", 0x02E07000UL, 0x00011000UL},
65 {
"DTCM", 0x20000000UL, 0x00010000UL},
66 {
"SRAM", 0x22000000UL, 0x001D4000UL},
88 {
"NS_SRAM2", 0x32100000UL, 0x00080000UL},
102 {
"SDRAM", 0x68000000UL, 0x04000000UL},
108 {
"NS_SDRAM", 0x78000000UL, 0x04000000UL},
116 {
"OSPI", 0x80000000UL, 0x04000000UL},
122 {
"NS_OSPI", 0x90000000UL, 0x04000000UL},
128 {
"PPB", 0xE0000000UL, 0x00100000UL},
140typedef enum : uint64_t {
155typedef enum : uint32_t {
162typedef enum :
size_t {
169typedef enum : uint64_t {
186 "the SRAM2 Non-secure alias must lie inside the on-chip SRAM aperture");
188 "the reported logical geometry must be the sum of the three apertures");
222 .os_error = os_error};
255 for (
size_t index = 0U; index < (
sizeof(k_aliased_windows) /
sizeof(k_aliased_windows[0]));
258 if (window->
base != base) {
262 if ((backing->
host ==
nullptr) || (size > backing->
size) ||
291 void*
const host = mmap(
nullptr,
293 PROT_READ | PROT_WRITE,
297 if (host == MAP_FAILED) {
320 if (backing->
host !=
nullptr) {
321 (void)munmap(backing->
host, (
size_t)backing->
size);
371 nullptr) != UC_ERR_OK) {
389 nullptr) != UC_ERR_OK) {
418 for (
size_t index = 0U; index < (
sizeof(
s_regions) /
sizeof(
s_regions[0])); index++) {
421 const uc_err mapped =
422 (host !=
nullptr) ? uc_mem_map_ptr(uc, region->
base, (
size_t)region->
size, UC_PROT_ALL, host)
423 : uc_mem_map(uc, region->
base, (
size_t)region->
size, UC_PROT_ALL);
424 if (mapped != UC_ERR_OK) {
427 (
unsigned long long)region->
base);
441 if ((workspace ==
nullptr) || workspace->
open) {
453 const int failure = errno;
458 candidate.
open =
true;
459 *workspace = candidate;
465 if ((workspace ==
nullptr) || !workspace->
open || (uc ==
nullptr)) {
471 binding = &workspace->
bindings[index];
475 if (binding ==
nullptr) {
488 if ((workspace ==
nullptr) || (uc ==
nullptr)) {
502 if ((workspace ==
nullptr) || !workspace->
open) {
Emulator text-console surfaces: UART echo, ITM/SWO echo, escapes.
@ k_ns_sram2_base
SRAM2 Non-secure alias (bit[28]=1).
@ k_ns_alias_bit
IDAU bit[28]: NS alias of a Secure addr.
Bounded raw-descriptor I/O seam for the RA8 emulator.
emu_io_result_t priv_emu_io_errf(const char *format,...)
Format bounded text and write it to the injected error descriptor.
emu_memmap_result_t emu_memmap_open(emu_memmap_workspace_t *workspace)
Create three independent, lazily-committed host aperture mappings.
static RA8_INTERNAL emu_memmap_result_t internal_result(emu_memmap_status_t status, int os_error)
Construct one exact lifecycle result.
emu_memmap_result_t emu_memmap_requirements(void)
Report the immutable aliased-aperture backing geometry.
static RA8_INTERNAL void internal_seed_tsn(uc_engine *uc)
Seed deterministic factory TSN calibration words.
static RA8_INTERNAL uint8_t * internal_window_host(const emu_memmap_workspace_t *workspace, uint64_t base, uint64_t size)
Resolve a guest region base to its shared host aperture address.
@ k_tsn_cal_addr
TSCDR (+0x00), TSCDR2 (+0x04).
@ k_tsn_cal_tscdr2
12-bit calibration code at -40 degC.
@ k_tsn_cal_tscdr
12-bit calibration code at +125 degC.
static RA8_INTERNAL void internal_backings_close(emu_memmap_workspace_t *workspace)
Release every acquired aperture mapping in a workspace.
mmap_argument_t
Fixed arguments for an anonymous host aperture mapping.
@ k_mmap_no_fd
Anonymous mappings are backed by no descriptor.
@ k_mmap_no_offset
Anonymous mappings start at offset zero.
emu_memmap_result_t emu_memmap_attach(emu_memmap_workspace_t *workspace, uc_engine *uc)
Map one Unicorn engine onto the shared aperture backing.
static RA8_INTERNAL bool internal_map_periph_mmio(uc_engine *uc)
Map the Secure peripheral window and its IDAU bit[28] NS alias.
@ k_ospi_ns_base
OSPI XIP window: NS alias (IDAU bit[28]=1).
@ k_ospi_xip_base
OSPI XIP window: Secure physical base.
backing_index_t
Identity of each shared aperture within a workspace.
@ k_backing_sdram
External SDRAM aperture index.
@ k_backing_sram
On-chip SRAM aperture index.
@ k_backing_ospi
OSPI XIP aperture index.
bool emu_memmap_detach(emu_memmap_workspace_t *workspace, uc_engine *uc)
Remove one engine binding before closing that Unicorn engine.
static RA8_INTERNAL bool internal_map_regions(const emu_memmap_workspace_t *workspace, uc_engine *uc)
Map every guest region into one engine, sharing the apertures.
bool emu_memmap_close(emu_memmap_workspace_t *workspace)
Release every host aperture mapping after all engines detached.
uint64_t emu_memmap_mram_base(void)
Implementation of emu_memmap_mram_base() – named MRAM lookup.
static RA8_INTERNAL bool internal_backing_open(uint64_t size, emu_memmap_backing_t *backing)
Acquire one zero-filled, lazily-committed host aperture mapping.
const mem_region_t * emu_memmap_regions(uint32_t *count)
Implementation of emu_memmap_regions() – static table access.
backing_geometry_t
Exact logical extents of the three shared apertures.
@ k_sram_size
Exact on-chip SRAM extent.
@ k_logical_bytes
Total logical bytes the three shared apertures span.
@ k_ospi_size
Exact OSPI XIP extent.
@ k_ns_sram2_size
SRAM2 alias extent.
@ k_sdram_size
Exact external SDRAM extent.
@ k_ns_sram2_offset
SRAM offset the SRAM2 alias starts at.
#define MAP_ANONYMOUS
Portable spelling of the anonymous-mapping flag.
Shared aliased-memory backing and Unicorn memory-map bindings.
struct emu_memmap_workspace emu_memmap_workspace_t
Independent aperture backing with at most two engine bindings.
emu_memmap_status_t
Semantic result for backing lifecycle operations.
@ k_emu_memmap_ok
Operation completed exactly.
@ k_emu_memmap_backing
A host aperture mapping could not be made.
@ k_emu_memmap_invalid
Pointer, state, or engine was invalid.
@ k_emu_memmap_unicorn
Unicorn map or window install failed.
@ k_emu_memmap_binding_count
CPU0 and optional CPU1 engines.
@ k_emu_memmap_backing_count
SRAM, SDRAM, and OSPI host mappings.
@ k_sdram_base
External SDRAM start.
@ k_sram_base
On-chip SRAM start.
@ k_ns_sdram_base
Non-secure SDRAM alias.
uc_err emu_mem_write(uc_engine *uc, uint64_t address, const void *bytes, size_t count)
Write guest memory through the central access seam.
Sparse MMIO model of the Renesas peripheral space.
void mmio_write(uc_engine *uc, uint64_t offset, unsigned size, uint64_t value, void *user)
UC_MMIO write callback for the peripheral window.
@ k_periph_size
0x40000000-0x4FFFFFFF: all Renesas peripherals.
@ k_periph_base
Peripheral window base.
uint64_t mmio_read(uc_engine *uc, uint64_t offset, unsigned size, void *user)
UC_MMIO read callback for the peripheral window.
static const ra8_mpu_region_t s_regions[]
One-region RO descriptor covering s_ro_buffer.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
One guest window that resolves onto a shared host aperture.
size_t backing
Aperture the window resolves onto.
uint64_t base
Guest base address of this window.
uint64_t offset
Byte offset of the window in the aperture.
One owned host aperture mapping.
uint8_t * host
Page-aligned host mapping, or nullptr.
uint64_t size
Exact logical byte length.
One caller-owned association between a Unicorn engine and backing.
bool active
Binding occupies this slot and must be undone.
uc_engine * uc
Bound Unicorn engine.
Exact requirements and operation outcome.
emu_memmap_binding_t bindings[k_emu_memmap_binding_count]
Active Unicorn engine views.
bool open
Whether the host mappings are owned.
emu_memmap_backing_t backings[k_emu_memmap_backing_count]
Owned host aperture mappings.
One emulated memory-region table row.
const char * name
Human-readable region name.
uint64_t size
Region byte length.
uint64_t base
Guest base address.