/* Deterministic RV64IMA machine with CLINT, PLIC, UART and finish devices. */ #ifndef MACHINE_H #define MACHINE_H #include "types.h" /* Platform limits and the physical base of RAM, also published in the FDT. */ #define MACHINE_MAX_HARTS 8U #define MACHINE_RAM_BASE 0x80000000ULL #define MACHINE_UART_IRQ 10U #define MACHINE_IRQ_COUNT 31U /* A loaded physical section. Empty sections need not reserve any memory. */ struct machine_section { u64 base; /* Inclusive physical start address. */ u32 size; /* Total reserved bytes, including the zero-filled tail. */ }; /* Immutable run configuration. The caller owns RAM. */ struct machine_config { u8 *ram; /* Loaded RAM at MACHINE_RAM_BASE. */ u32 memory_size; /* RAM byte count. */ u64 entry; /* Initial PC for every hart. */ struct machine_section text; /* Loaded executable section. */ struct machine_section rodata; /* Loaded immutable data section. */ struct machine_section rwdata; /* Loaded initialized writable section. */ u32 stack_size; /* Bytes reserved per hart; multiple of 16. */ u32 hart_count; /* Number of enabled harts, 1 through 8. */ u64 max_steps; /* Virtual ticks, including skipped idle time. */ u32 irq_source; /* One-shot PLIC edge source, 0 disables. */ u64 irq_at; /* Virtual tick of the one-shot edge. */ bool trace; /* Print hart-tagged instructions and traps. */ bool count_instructions; /* Report actual retired instructions. */ bool *timed_out; /* Optional out: set when the tick limit ended the run. */ }; /* Run the machine until a finish write or the tick limit. Returns 0 when the * guest writes the success value to the finish register, 1 when it writes a * failure value, and 2 for an invalid layout, UART output failure or timeout. * A timeout is also reported through `timed_out`, when it is not NULL. * Machine execution never enters the hosted JIT, debugger, or syscall * runtime. */ int machine_run(const struct machine_config *config); #endif /* MACHINE_H */