ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
emu_run.h File Reference

The chunked emulation run loop, report and exit-code mapping. More...

#include <stdint.h>
#include <unicorn/unicorn.h>
#include "board_view.h"
#include "emu_elf.h"
#include "emu_memmap.h"
#include "emu_presentation.h"
#include "ra8_attributes.h"
Include dependency graph for emu_run.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  emu_run_cfg_t
 Everything setup hands the run loop: engine, image, CLI products. More...
struct  run_guards_t
 The run-guard knobs (env-tunable budgets + stop conditions). More...

Enumerations

enum  emu_budget_t : uint32_t {
  k_run_chunk_insns = 500000U ,
  k_low_power_div = 4U ,
  k_run_max_chunks = 40000U ,
  k_idle_spin_insns = 2U ,
  k_op_branch_self = 0xE7FEU ,
  k_op_wfi = 0xBF30U ,
  k_op_cpsie_i = 0xB662U ,
  k_op_bn_mask = 0xF800U ,
  k_op_bn_base = 0xE000U ,
  k_op_bn_imm = 0x07FFU ,
  k_bn_imm_sext_shl = 21U ,
  k_bn_imm_sext_shr = 20U ,
  k_idle_scan_fwd = 8U ,
  k_idle_loop_max = 32U ,
  k_run_wall_s = 120U ,
  k_run_inner_max = 4096U ,
  k_env_strtol_base = 10U
}
enum  emu_exit_t : int {
  k_emu_exit_ok = 0 ,
  k_emu_exit_fault = 1 ,
  k_emu_exit_bkpt = 2 ,
  k_emu_exit_timeout = 3
}
 Process exit codes for the #67 run-every-example matrix. More...
enum  emu_misc_t : uint32_t {
  k_thumb_op5_shift = 11U ,
  k_thumb_op5_mask = 0x1FU ,
  k_thumb32_op5_min = 0x1DU ,
  k_cs_op_shift = 12U ,
  k_cs_op_mask = 0x3U ,
  k_max_panel_px = k_emu_presentation_max_panel_px ,
  k_record_dir_mode = 0755U ,
  k_dump_sym_max = 8U ,
  k_sectors_per_mib = 2048U
}
 Named constants for ELF parsing, Thumb decode, and assorted literals. More...
enum  emu_size_t : uint64_t {
  k_bytes_per_sector = 512ULL ,
  k_size_kib = 1024ULL ,
  k_sd_u32_max = 0xFFFFFFFFULL ,
  k_fat32_min_mib = 512ULL
}
 64-bit byte/size units used by –sd-new card sizing. More...

Functions

run_guards_t run_read_guards (const emu_run_cfg_t *cfg, const board_view_t *view)
 Read the run-guard environment knobs (see run_guards_t).
int emu_run_and_report (const emu_run_cfg_t *cfg)
 Run the firmware to a stop condition, print the report, map the exit code.

Detailed Description

The chunked emulation run loop, report and exit-code mapping.

Owns everything after setup: the streamed presentation surface, the run-guard environment knobs (RA8_EMU_WALL_S / MAX_CHUNKS / IDLE_STOP / USB_STOP / USBH_STOP / STOP_ON / STOP_PC / CLICK_SETTLE / the profiler idle-stop tunables), the chunked run loop with its inner exception-resolve loop and seven stop conditions, the run-end report, and the process exit-code mapping the #67 run-every-example matrix keys on. The shared run budgets and assorted sizing constants live here so both the setup banner and the loop read one definition.

Split out of the ra8_emulator main translation unit; behaviour unchanged.

Since
0.1.0

Definition in file emu_run.h.

Enumeration Type Documentation

◆ emu_budget_t

enum emu_budget_t : uint32_t
Enumerator
k_run_chunk_insns 

Instructions per emulation chunk.

k_low_power_div 

Low-power: shrink the chunk budget by.

this (the 4:1 M85:M33 clock ratio) so the modelled core advances ~1/4 as fast.

k_run_max_chunks 

Chunk budget.

Each chunk offers one SysTick, so RTOS apps whose threads sleep on hundreds/thousands of ticks (e.g. ThreadX tx_thread_sleep) need a far larger budget than bare-metal.

k_idle_spin_insns 

Budget when the core is parked on a wait-for-interrupt spin (a "b ." self-branch, wfi, or a cpsie i + back-branch poll): collapse the idle wait to the next SysTick instead of spinning a whole chunk.

k_op_branch_self 

Thumb "b ." (branch-to-self idle loop).

k_op_wfi 

Thumb wfi (wait-for-interrupt).

k_op_cpsie_i 

Thumb cpsie i (re-enable IRQ in a poll).

k_op_bn_mask 

Mask selecting a Thumb T2 b.n opcode.

k_op_bn_base 

Thumb T2 unconditional b.n base value.

k_op_bn_imm 

Thumb T2 b.n imm11 field mask.

k_bn_imm_sext_shl 

Shift imm11 bit10 up to bit31 (sign bit).

k_bn_imm_sext_shr 

Arith >> sign-extends and scales imm by 2.

k_idle_scan_fwd 

Halfwords scanned ahead for a loop edge.

k_idle_loop_max 

Largest idle loop (bytes) that may hold PC.

k_run_wall_s 

Wall-clock safety bound (seconds).

k_run_inner_max 

Per-chunk exception-resolve relaunch cap.

k_env_strtol_base 

Decimal base for env-var integer parse.

Definition at line 37 of file emu_run.h.

◆ emu_exit_t

enum emu_exit_t : int

Process exit codes for the #67 run-every-example matrix.

The matrix keys off the process exit code (not the injected error sink banner): a clean run-to-budget returns success; a firmware BKPT, an emulation fault, or the wall-clock timeout each return a distinct non-zero code so a wedged or trapped run is distinguishable from a healthy one.

Enumerator
k_emu_exit_ok 

Clean run-to-budget (no fault/BKPT/timeout).

k_emu_exit_fault 

Emulation fault / invalid access ended it.

k_emu_exit_bkpt 

Firmware executed a BKPT (assert/give-up).

k_emu_exit_timeout 

Wall-clock budget reached before a clean stop.

Definition at line 76 of file emu_run.h.

◆ emu_misc_t

enum emu_misc_t : uint32_t

Named constants for ELF parsing, Thumb decode, and assorted literals.

Enumerator
k_thumb_op5_shift 

op5 = hw0[15:11].

k_thumb_op5_mask 

5-bit op5 field.

k_thumb32_op5_min 

op5 >= this -> 32-bit instruction.

k_cs_op_shift 

CSEL-family op = hw2[13:12].

k_cs_op_mask 

2-bit op field.

k_max_panel_px 

Largest –size dimension.

k_record_dir_mode 

mkdir mode for the –record dir.

k_dump_sym_max 

Max –dump-sym globals per run.

k_sectors_per_mib 

512-byte sectors per MiB (–sd-new).

Definition at line 87 of file emu_run.h.

◆ emu_size_t

enum emu_size_t : uint64_t

64-bit byte/size units used by –sd-new card sizing.

Enumerator
k_bytes_per_sector 

SD logical sector size in bytes.

k_size_kib 

One kibibyte (k suffix multiplier).

k_sd_u32_max 

32-bit sector-count ceiling.

k_fat32_min_mib 

FAT32 default threshold, in MiB.

Definition at line 102 of file emu_run.h.

Function Documentation

◆ emu_run_and_report()

int emu_run_and_report ( const emu_run_cfg_t * cfg)

Run the firmware to a stop condition, print the report, map the exit code.

Uses the caller-prepared raw-fd presentation surface (window / –ppm / –record / –click), reads the run-guard environment knobs, executes the chunked run loop – one SysTick period per outer chunk, exceptions resolved to a steady state by the inner loop, cpu1 interleaved, seven stop conditions – then prints the run-end report (stop cause, telemetry, peripheral summaries, MMIO table, –dump-sym probes), writes the –ppm / –record outputs, holds the live window until closed, saves the SD image, closes owned descriptors and the engine, and returns the #67 matrix exit code.

Parameters
[in]cfgThe setup products (see emu_run_cfg_t).
Returns
Process exit status.
Return values
0Clean run-to-budget (no fault / BKPT / timeout).
1Emulation fault / invalid access ended the run.
2Firmware executed a BKPT (assert / give-up).
3Wall-clock budget reached before a clean stop.
Precondition
cfg is fully populated and its engine is ready to run.
The seams / hooks are installed.
Postcondition
The engine and caller-owned ELF source are closed.
Note
Not thread-safe; this IS the single-threaded run.
Since
0.1.0
Postcondition
Ownership of caller-supplied storage is unchanged.

Definition at line 852 of file emu_run.c.

References internal_run_loop(), internal_run_loop_setup(), priv_run_cleanup(), priv_run_hold_view(), priv_run_report(), and priv_run_write_outputs().

Referenced by internal_main_run_loaded().

◆ run_read_guards()

run_guards_t run_read_guards ( const emu_run_cfg_t * cfg,
const board_view_t * view )

Read the run-guard environment knobs (see run_guards_t).

Moved verbatim from the run preamble: every default, override precedence and –view/–record interaction is unchanged, including the –record-secs chunk bound and the RA8_EMU_STOP_PC hand-off to the profiler.

Parameters
[in]cfgThe run configuration (record/click fields).
[in]viewThe live window handle (NULL when headless).
Returns
The populated guard set.
Return values
(byvalue) Every field holds its default or env override.
Precondition
The environment is stable for the run.
cfg outlives the call.
Postcondition
RA8_EMU_STOP_PC (if set) has been handed to the profiler.
With –record active, the frame directory exists (mkdir) and the recording banner has been printed to injected error sink.
Note
Not thread-safe; call once during setup.
Since
0.1.0

Definition at line 255 of file emu_run_guards.c.

References internal_guard_apply_stop_pc(), internal_guard_env_u32(), internal_guard_env_u32_headless(), internal_guard_read_prof_idle(), internal_guard_read_stop_on(), internal_guard_read_wall(), internal_guard_setup_record(), k_click_settle_chunks, k_run_max_chunks, k_run_wall_s, and k_view_max_chunks.

Referenced by internal_run_loop_setup().