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