ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
emu_elf.h
Go to the documentation of this file.
1
21
22#pragma once
23
24#include <stddef.h>
25#include <stdint.h>
26#include <unicorn/unicorn.h>
27
28#include "ra8_attributes.h"
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
72
81
89
91typedef struct {
92 int fd;
93 uint64_t length;
95
97typedef struct {
98 const uint8_t* bytes;
99 size_t length;
100 uint64_t offset;
102
131int load_elf(uc_engine* uc, const emu_elf_source_t* elf);
132
162uint32_t elf_vector_base(const emu_elf_source_t* elf);
163
191uint32_t elf_sym_addr(const emu_elf_source_t* elf, const char* name, uint32_t* size_out);
192
221uint32_t warm_reboot(uc_engine* uc, const emu_elf_source_t* elf, bool trace);
222
238typedef struct {
240 uint32_t offset;
241 uint32_t vaddr;
242 uint32_t paddr;
243 uint32_t filesz;
244 uint32_t flags;
246
255typedef bool (*elf_exec_segment_fn)(const elf_exec_segment_t* seg, void* ctx);
256
272uint32_t elf_foreach_load_segment(const emu_elf_source_t* elf, elf_exec_segment_fn fn, void* ctx);
273
304uint32_t elf_foreach_exec_segment(const emu_elf_source_t* elf, elf_exec_segment_fn fn, void* ctx);
305
307typedef struct {
308 uint64_t name_offset;
309 uint32_t value;
310 uint32_t size;
311 uint8_t info;
313
315typedef bool (*emu_elf_symbol_fn)(const emu_elf_symbol_t* symbol, void* ctx);
316
332uint32_t elf_foreach_symbol(const emu_elf_source_t* elf, emu_elf_symbol_fn fn, void* ctx);
333
335typedef bool (*emu_elf_string_fn)(const char* bytes, size_t length, void* ctx);
336
355 uint64_t offset,
357 void* ctx);
358
359#ifdef __cplusplus
360}
361#endif
bool elf_string_foreach(const emu_elf_source_t *elf, uint64_t offset, emu_elf_string_fn fn, void *ctx)
Stream one NUL-terminated ELF string through bounded stack chunks.
bool(* elf_exec_segment_fn)(const elf_exec_segment_t *seg, void *ctx)
Per-segment callback for elf_foreach_exec_segment.
Definition emu_elf.h:255
uint32_t elf_foreach_load_segment(const emu_elf_source_t *elf, elf_exec_segment_fn fn, void *ctx)
Walk every non-empty, bounds-checked PT_LOAD segment.
Definition emu_elf.c:172
bool(* emu_elf_string_fn)(const char *bytes, size_t length, void *ctx)
Callback receiving one non-empty chunk of an ELF string.
Definition emu_elf.h:335
uint32_t elf_sym_addr(const emu_elf_source_t *elf, const char *name, uint32_t *size_out)
Resolve a function symbol's entry address from the ELF .symtab.
uint32_t elf_foreach_symbol(const emu_elf_source_t *elf, emu_elf_symbol_fn fn, void *ctx)
Walk every symbol in every usable SHT_SYMTAB section.
emu_elf_layout_t
ELF32 file-layout constants (header sizes and field byte offsets).
Definition emu_elf.h:51
@ k_elf_pf_x
PF_X: segment is executable.
Definition emu_elf.h:63
@ k_elf_st_type_mask
Low nibble of st_info is the type.
Definition emu_elf.h:70
@ k_elf_em_arm
e_machine == EM_ARM.
Definition emu_elf.h:53
@ k_elf_ph_paddr_off
p_paddr in a program header.
Definition emu_elf.h:60
@ k_elf_shentsize_min
ELF32 section-header entry size.
Definition emu_elf.h:65
@ k_elf_ph_flags_off
p_flags in a program header.
Definition emu_elf.h:62
@ k_elf_e_machine_off
e_machine in the file header.
Definition emu_elf.h:54
@ k_elf_ph_vaddr_off
p_vaddr (VMA) in a program header.
Definition emu_elf.h:59
@ k_elf_sh_entsize_off
sh_entsize in a section header.
Definition emu_elf.h:68
@ k_elf_sym_info_off
st_info in a symbol-table entry.
Definition emu_elf.h:69
@ k_elf_e_phentsize_off
e_phentsize in the file header.
Definition emu_elf.h:56
@ k_elf_sh_link_off
sh_link in a section header.
Definition emu_elf.h:67
@ k_elf_e_phoff_off
e_phoff in the file header.
Definition emu_elf.h:55
@ k_elf_e_phnum_off
e_phnum in the file header.
Definition emu_elf.h:57
@ k_elf_ph_filesz_off
p_filesz in a program header.
Definition emu_elf.h:61
@ k_elf_ehdr_size
ELF32 file-header size.
Definition emu_elf.h:52
@ k_elf_ph_offset_off
p_offset in a program header.
Definition emu_elf.h:58
@ k_elf_sh_size_off
sh_size in a section header.
Definition emu_elf.h:66
@ k_elf_pt_load
p_type == PT_LOAD.
Definition emu_elf.h:64
uint32_t elf_foreach_exec_segment(const emu_elf_source_t *elf, elf_exec_segment_fn fn, void *ctx)
Walk every executable PT_LOAD segment of an ELF32 image.
Definition emu_elf.c:265
int load_elf(uc_engine *uc, const emu_elf_source_t *elf)
Load ELF32 PT_LOAD segments into emulated memory at their LMA.
Definition emu_elf.c:248
uint32_t warm_reboot(uc_engine *uc, const emu_elf_source_t *elf, bool trace)
Warm-reboot the firmware: re-run from the reset vector in place.
uint32_t elf_vector_base(const emu_elf_source_t *elf)
Vector-table base of an ELF: lowest executable PT_LOAD VMA.
Definition emu_elf.c:320
bool(* emu_elf_symbol_fn)(const emu_elf_symbol_t *symbol, void *ctx)
Callback invoked for each bounds-checked ELF symbol entry.
Definition emu_elf.h:315
emu_elf_io_status_t
Status for bounded raw-descriptor ELF source operations.
Definition emu_elf.h:74
@ k_emu_elf_io_eof
The source ended during an exact read.
Definition emu_elf.h:78
@ k_emu_elf_io_error
A host operation failed.
Definition emu_elf.h:79
@ k_emu_elf_io_capacity
Caller scratch is smaller than required.
Definition emu_elf.h:77
@ k_emu_elf_io_ok
The complete operation succeeded.
Definition emu_elf.h:75
@ k_emu_elf_io_invalid
A pointer, descriptor, range, or path was bad.
Definition emu_elf.h:76
Annotation-attribute framework macros for ra8-firmware.
One executable PT_LOAD segment, already bounds-checked against the image.
Definition emu_elf.h:238
uint32_t offset
Segment file offset.
Definition emu_elf.h:240
uint32_t filesz
Segment file byte count.
Definition emu_elf.h:243
const emu_elf_source_t * source
Open source owning segment bytes.
Definition emu_elf.h:239
uint32_t paddr
Segment physical load address.
Definition emu_elf.h:242
uint32_t vaddr
Segment virtual address.
Definition emu_elf.h:241
uint32_t flags
ELF program-header flags.
Definition emu_elf.h:244
Exact result for source open and bounded view acquisition.
Definition emu_elf.h:83
emu_elf_io_status_t status
Semantic completion status.
Definition emu_elf.h:84
uint64_t supplied_bytes
Caller-provided scratch byte count.
Definition emu_elf.h:86
int os_error
Captured host error, or zero.
Definition emu_elf.h:87
uint64_t required_bytes
Source or requested range byte count.
Definition emu_elf.h:85
One independently owned immutable raw-descriptor ELF source.
Definition emu_elf.h:91
int fd
Owned regular-file descriptor, or -1 when closed.
Definition emu_elf.h:92
uint64_t length
Stat-derived parsing bound.
Definition emu_elf.h:93
One bounds-checked symbol-table entry plus its string offset.
Definition emu_elf.h:307
uint64_t name_offset
Absolute source offset of the NUL-terminated name.
Definition emu_elf.h:308
uint32_t size
Symbol byte extent.
Definition emu_elf.h:310
uint32_t value
Symbol value.
Definition emu_elf.h:309
uint8_t info
ELF st_info byte.
Definition emu_elf.h:311
Transient view into caller-owned bounded scratch.
Definition emu_elf.h:97
uint64_t offset
Starting source offset.
Definition emu_elf.h:100
const uint8_t * bytes
Scratch containing the exact source bytes.
Definition emu_elf.h:98
size_t length
Published exact byte count.
Definition emu_elf.h:99