|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Bounded raw-descriptor host-I/O implementation. More...
#include <errno.h>#include <fcntl.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/stat.h>#include <unistd.h>#include "emu_host_io_internal.h"Go to the source code of this file.
Typedefs | |
| typedef ssize_t(* | internal_transfer_fn_t) (int fd, void *buf, size_t count, off_t offset) |
Enumerations | |
| enum | : size_t { k_emu_io_format_cap = 1024U , k_emu_io_eintr_max = 8U } |
Functions | |
| static RA8_INTERNAL ssize_t | internal_read (int fd, void *buf, size_t count) |
| Call the default sequential input primitive. | |
| static RA8_INTERNAL ssize_t | internal_write (int fd, const void *buf, size_t count) |
| Call the default sequential output primitive. | |
| static RA8_INTERNAL ssize_t | internal_pread (int fd, void *buf, size_t count, off_t offset) |
| Call the default positioned input primitive. | |
| static RA8_INTERNAL ssize_t | internal_pwrite (int fd, const void *buf, size_t count, off_t offset) |
| Call the default positioned output primitive. | |
| static RA8_INTERNAL emu_io_result_t | internal_result (emu_io_status_t status, size_t transferred, int os_error) |
| Construct one complete public operation result. | |
| void | priv_emu_io_configure (int out_fd, int err_fd, const emu_io_ops_t *ops) |
| Inject process output descriptors and optional raw transfer hooks. | |
| static RA8_INTERNAL emu_io_result_t | internal_transfer (int fd, void *buf, size_t count, off_t offset, internal_transfer_fn_t fn, bool input) |
| Complete one exact raw transfer with bounded EINTR retries. | |
| static RA8_INTERNAL ssize_t | internal_read_adapter (int fd, void *buf, size_t count, off_t offset) |
| Adapt sequential input to the common positioned callback shape. | |
| static RA8_INTERNAL ssize_t | internal_write_adapter (int fd, void *buf, size_t count, off_t offset) |
| Adapt sequential output to the common positioned callback shape. | |
| static RA8_INTERNAL ssize_t | internal_pread_adapter (int fd, void *buf, size_t count, off_t offset) |
| Dispatch positioned input through the configured operation table. | |
| static RA8_INTERNAL ssize_t | internal_pwrite_adapter (int fd, void *buf, size_t count, off_t offset) |
| Dispatch positioned output through the configured operation table. | |
| emu_io_result_t | priv_emu_io_read_exact (int fd, void *buf, size_t count) |
Read exactly count sequential bytes or report EOF/fault progress. | |
| emu_io_result_t | priv_emu_io_write_exact (int fd, const void *buf, size_t count) |
Write exactly count sequential bytes or report fault progress. | |
| emu_io_result_t | priv_emu_io_pread_exact (int fd, void *buf, size_t count, off_t offset) |
Read exactly count bytes at offset without changing the cursor. | |
| emu_io_result_t | priv_emu_io_pwrite_exact (int fd, const void *buf, size_t count, off_t offset) |
Write exactly count bytes at offset without changing the cursor. | |
| static RA8_INTERNAL emu_io_result_t | internal_vformat (int fd, const char *format, va_list args) |
| Render one bounded format operation and write it exactly. | |
| emu_io_result_t | priv_emu_io_out_text (const char *text) |
| Write a NUL-terminated literal to the injected output descriptor. | |
| emu_io_result_t | priv_emu_io_err_text (const char *text) |
| Write a NUL-terminated literal to the injected error descriptor. | |
| emu_io_result_t | priv_emu_io_err_bytes (const void *bytes, size_t length) |
| Write an exact non-NUL-terminated byte fragment to the error sink. | |
| emu_io_result_t | priv_emu_io_outf (const char *format,...) |
| Format bounded text and write it to the injected output descriptor. | |
| emu_io_result_t | priv_emu_io_errf (const char *format,...) |
| Format bounded text and write it to the injected error descriptor. | |
| emu_io_result_t | priv_emu_io_file_text (int fd, const char *text) |
| Write a NUL-terminated literal to an explicit raw descriptor. | |
| emu_io_result_t | priv_emu_io_file_char (int fd, char value) |
| Write one byte to an explicit raw descriptor. | |
| emu_io_result_t | priv_emu_io_filef (int fd, const char *format,...) |
| Format bounded text and write it to an explicit raw descriptor. | |
| emu_io_result_t | priv_emu_io_open_read (const char *path, emu_io_file_t *file) |
| Open and stat a regular file for bounded raw reading. | |
| emu_io_result_t | priv_emu_io_close (emu_io_file_t *file) |
| Close and invalidate an owned raw file descriptor. | |
| emu_io_result_t | priv_emu_io_txn_begin (const char *path, emu_io_txn_t *txn) |
| Create a sibling temporary output for failure-atomic publication. | |
| emu_io_result_t | priv_emu_io_txn_commit (emu_io_txn_t *txn) |
| Sync, close, and atomically rename an active sibling transaction. | |
| void | priv_emu_io_txn_abort (emu_io_txn_t *txn) |
| Close and unlink an active sibling transaction without publication. | |
Variables | |
| static const emu_io_ops_t | s_k_default_ops |
| static const emu_io_ops_t * | s_ops = &s_k_default_ops |
| static int | s_out_fd = STDOUT_FILENO |
| static int | s_err_fd = STDERR_FILENO |
Bounded raw-descriptor host-I/O implementation.
Implements bounded EINTR/short-I/O loops, memory-only formatting, descriptor-selected process sinks, regular-file reads, and atomic publication.
Definition in file emu_host_io.c.
| typedef ssize_t(* internal_transfer_fn_t) (int fd, void *buf, size_t count, off_t offset) |
Definition at line 147 of file emu_host_io.c.
| anonymous enum : size_t |
| Enumerator | |
|---|---|
| k_emu_io_format_cap | Per-call stack formatting capacity. |
| k_emu_io_eintr_max | Consecutive EINTR retry bound. |
Definition at line 22 of file emu_host_io.c.
|
static |
Call the default positioned input primitive.
Reads without changing the descriptor cursor.
| [in] | fd | Raw descriptor. |
| [out] | buf | Destination bytes. |
| [in] | count | Requested byte count. |
| [in] | offset | Starting byte offset. |
| -1 | The host primitive failed. |
fd identifies an open seekable descriptor. buf spans count writable bytes when count is nonzero. Definition at line 83 of file emu_host_io.c.
References RA8_INTERNAL.
Referenced by priv_fmt_host_source_open().
|
static |
Dispatch positioned input through the configured operation table.
Preserves the exact offset passed by the transfer loop.
| [in] | fd | Raw descriptor. |
| [out] | buf | Destination bytes. |
| [in] | count | Requested byte count. |
| [in] | offset | Starting byte offset. |
| -1 | The configured primitive failed. |
buf spans count writable bytes when nonzero. Definition at line 258 of file emu_host_io.c.
References RA8_INTERNAL, and s_ops.
Referenced by priv_emu_io_pread_exact().
|
static |
Call the default positioned output primitive.
Writes without changing the descriptor cursor.
| [in] | fd | Raw descriptor. |
| [in] | buf | Source bytes. |
| [in] | count | Requested byte count. |
| [in] | offset | Starting byte offset. |
| -1 | The host primitive failed. |
fd identifies an open seekable descriptor. buf spans count readable bytes when count is nonzero. Definition at line 104 of file emu_host_io.c.
References RA8_INTERNAL.
|
static |
Dispatch positioned output through the configured operation table.
Preserves the exact offset passed by the transfer loop.
| [in] | fd | Raw descriptor. |
| [in,out] | buf | Source bytes carried in the common mutable callback shape. |
| [in] | count | Requested byte count. |
| [in] | offset | Starting byte offset. |
| -1 | The configured primitive failed. |
buf spans count readable bytes when nonzero. Definition at line 279 of file emu_host_io.c.
References RA8_INTERNAL, and s_ops.
Referenced by priv_emu_io_pwrite_exact().
|
static |
Call the default sequential input primitive.
Thin hook target keeping production and injected operations shape-compatible.
| [in] | fd | Raw descriptor. |
| [out] | buf | Destination bytes. |
| [in] | count | Requested byte count. |
| -1 | The host primitive failed. |
fd identifies an open descriptor. buf spans count writable bytes when count is nonzero. Definition at line 42 of file emu_host_io.c.
References RA8_INTERNAL.
|
static |
Adapt sequential input to the common positioned callback shape.
Ignores offset and dispatches through the configured operation table.
| [in] | fd | Raw descriptor. |
| [out] | buf | Destination bytes. |
| [in] | count | Requested byte count. |
| [in] | offset | Ignored compatibility offset. |
| -1 | The configured primitive failed. |
buf spans count writable bytes when nonzero. Definition at line 214 of file emu_host_io.c.
References RA8_INTERNAL, and s_ops.
Referenced by priv_emu_io_read_exact().
|
static |
Construct one complete public operation result.
Centralises field initialisation for every result path.
| [in] | status | Semantic operation status. |
| [in] | transferred | Completed byte count. |
| [in] | os_error | Captured host error. |
| emu_io_result_t | The supplied fields in their corresponding members. |
status is a valid emu_io_status_t value. transferred reflects only completed bytes. Definition at line 135 of file emu_host_io.c.
Referenced by internal_transfer(), internal_vformat(), priv_emu_io_close(), priv_emu_io_err_text(), priv_emu_io_file_text(), priv_emu_io_open_read(), priv_emu_io_out_text(), priv_emu_io_txn_begin(), and priv_emu_io_txn_commit().
|
static |
Complete one exact raw transfer with bounded EINTR retries.
Repeats partial operations, resets the retry budget after progress, and reports EOF.
| [in] | fd | Raw descriptor. |
| [in,out] | buf | Transfer buffer. |
| [in] | count | Exact requested byte count. |
| [in] | offset | Initial positioned-I/O offset. |
| [in] | fn | Injected transfer primitive. |
| [in] | input | True for EOF semantics, false for zero-write error semantics. |
| emu_io_result_t | The exact transfer outcome. |
fn is non-null for a valid request. buf spans count bytes when count is nonzero. count transferred bytes. Definition at line 167 of file emu_host_io.c.
References internal_result(), k_emu_io_eintr_max, k_emu_io_eof, k_emu_io_error, k_emu_io_invalid, k_emu_io_ok, and RA8_INTERNAL.
Referenced by priv_emu_io_pread_exact(), priv_emu_io_pwrite_exact(), priv_emu_io_read_exact(), and priv_emu_io_write_exact().
|
static |
Render one bounded format operation and write it exactly.
Uses memory-only formatting and emits no partial text when truncation is detected.
| [in] | fd | Destination raw descriptor. |
| [in] | format | Format string. |
| [in] | args | Format arguments. |
| emu_io_result_t | Success, truncation, invalid input, or host failure. |
fd is non-negative. format is non-null and matches args. Definition at line 319 of file emu_host_io.c.
References internal_result(), k_emu_io_error, k_emu_io_format_cap, k_emu_io_invalid, k_emu_io_truncated, priv_emu_io_write_exact(), and RA8_INTERNAL.
Referenced by priv_emu_io_errf(), priv_emu_io_filef(), and priv_emu_io_outf().
|
static |
Call the default sequential output primitive.
Thin hook target keeping production and injected operations shape-compatible.
| [in] | fd | Raw descriptor. |
| [in] | buf | Source bytes. |
| [in] | count | Requested byte count. |
| -1 | The host primitive failed. |
fd identifies an open descriptor. buf spans count readable bytes when count is nonzero. Definition at line 62 of file emu_host_io.c.
References RA8_INTERNAL.
|
static |
Adapt sequential output to the common positioned callback shape.
Ignores offset and dispatches through the configured operation table.
| [in] | fd | Raw descriptor. |
| [in,out] | buf | Source bytes carried in the common mutable callback shape. |
| [in] | count | Requested byte count. |
| [in] | offset | Ignored compatibility offset. |
| -1 | The configured primitive failed. |
buf spans count readable bytes when nonzero. Definition at line 236 of file emu_host_io.c.
References RA8_INTERNAL, and s_ops.
Referenced by priv_emu_io_write_exact().
|
nodiscard |
Close and invalidate an owned raw file descriptor.
Definition at line 415 of file emu_host_io.c.
References internal_result(), k_emu_io_error, k_emu_io_invalid, and k_emu_io_ok.
Referenced by board_sd_attach(), load_panel(), and priv_emu_elf_source_close().
| void priv_emu_io_configure | ( | int | out_fd, |
| int | err_fd, | ||
| const emu_io_ops_t * | ops ) |
Inject process output descriptors and optional raw transfer hooks.
Selects composition-owned destinations and production or test raw operations.
| [in] | out_fd | Descriptor used by output-sink calls. |
| [in] | err_fd | Descriptor used by error-sink calls. |
| [in] | ops | Complete operation table, or nullptr for production syscalls. |
out_fd and err_fd are valid for their intended calls. ops supplies all four callbacks. ops or the production table. Definition at line 140 of file emu_host_io.c.
References s_err_fd, s_k_default_ops, s_ops, and s_out_fd.
Referenced by main().
|
nodiscard |
Write an exact non-NUL-terminated byte fragment to the error sink.
Definition at line 350 of file emu_host_io.c.
References priv_emu_io_write_exact(), and s_err_fd.
Referenced by internal_prof_name_chunk().
|
nodiscard |
Write a NUL-terminated literal to the injected error descriptor.
Definition at line 344 of file emu_host_io.c.
References internal_result(), k_emu_io_invalid, priv_emu_io_write_exact(), s_err_fd, and strlen().
Referenced by internal_args_print_usage(), internal_prof_print_incl_self_table(), internal_prof_print_phase(), and prof_report().
|
nodiscard |
Format bounded text and write it to the injected error descriptor.
Definition at line 364 of file emu_host_io.c.
References internal_vformat(), and s_err_fd.
Referenced by board_eink_report(), board_modem_report(), board_net_on_tx(), board_net_report(), board_periph_icu_raise_event(), board_periph_note_irq_taken(), board_periph_register_block(), board_periph_sci_feed_rx(), board_sd_attach(), board_sd_attach_blank(), board_sd_save(), board_usb_bridge_dcp_in_take(), board_usb_host_report(), board_usb_host_write(), board_usb_report(), div0_patch_sites(), div0_seam_install(), emu_mmio_print_bgc_and_table(), emu_mmio_print_counts(), emu_tz_install(), fast_sd_seam_install(), internal_adc_report(), internal_adc_write(), internal_args_attach_blank_sd(), internal_bkup_report(), internal_cac_report(), internal_canfd_loopback_deliver(), internal_canfd_report(), internal_ceu_do_capture(), internal_ceu_report(), internal_cpu1_engine_init(), internal_crc_report(), internal_dac_report(), internal_dac_write(), internal_div0_scan_segment(), internal_dmac_report(), internal_dmac_run_transfer(), internal_doc_report(), internal_drw_report(), internal_dtc_report(), internal_eth_report(), internal_glcdc_report(), internal_gptp_report(), internal_guard_setup_record(), internal_i3c_report(), internal_install_seg_hooks(), internal_ipc_report(), internal_ipc_write(), internal_lvd_report(), internal_main_apply_button_battery(), internal_main_arm_touch_seq(), internal_main_feed_inputs(), internal_main_load_ns(), internal_main_load_primary(), internal_main_open_engine(), internal_main_open_memory(), internal_main_open_presentation(), internal_main_reset_vector(), internal_main_resolve_symbols(), internal_map_periph_mmio(), internal_map_regions(), internal_mram_report(), internal_mstp_report(), internal_net_rx_icmp(), internal_net_rx_tcp(), internal_net_tcp_on_estab(), internal_npu_report(), internal_on_sym_trace(), internal_on_unmapped(), internal_pdctr_report(), internal_pdm_report(), internal_poeg_report(), internal_port_report(), internal_port_trace_leds(), internal_prcr_report(), internal_prof_print_boot_timeline(), internal_prof_print_incl_self_table(), internal_prof_print_phase(), internal_report_created(), internal_report_irqs(), internal_report_unhandled_insn(), internal_reset_report(), internal_riic_report(), internal_rtc_raise_events(), internal_rtc_report(), internal_rtt_report(), internal_run_classify_click(), internal_run_open_view(), internal_run_print_dump_syms(), internal_run_print_sd_summary(), internal_run_print_stop_summary(), internal_run_print_verdict(), internal_sci_report(), internal_sdhi_report(), internal_spi_report(), internal_sram_report(), internal_ssie_report(), internal_stream_segment(), internal_timer_report(), internal_ulpt_report(), internal_ulpt_tick_channel(), internal_usb_hid_decode_report(), internal_usbhs_do_setup(), internal_usbhs_report(), internal_wdt_report(), internal_xspi_report(), load_elf(), load_panel(), long_shift_seam_install(), priv_riic_devices_report(), priv_run_hold_view(), priv_run_write_outputs(), priv_usb_log_line(), prof_load(), prof_report(), sym_trace_install(), usbh_seam_install(), and warm_reboot().
|
nodiscard |
Write one byte to an explicit raw descriptor.
Definition at line 379 of file emu_host_io.c.
References priv_emu_io_write_exact().
Referenced by internal_prof_js_frames(), internal_prof_json_samples(), and internal_prof_name_chunk().
|
nodiscard |
Write a NUL-terminated literal to an explicit raw descriptor.
Definition at line 373 of file emu_host_io.c.
References internal_result(), k_emu_io_invalid, priv_emu_io_write_exact(), and strlen().
Referenced by internal_prof_js_frames(), internal_prof_json_frames(), internal_prof_write_html(), and internal_prof_write_speedscope().
|
nodiscard |
Format bounded text and write it to an explicit raw descriptor.
Definition at line 384 of file emu_host_io.c.
References internal_vformat().
Referenced by internal_prof_json_samples(), internal_prof_json_weights(), internal_prof_write_html(), internal_prof_write_speedscope(), and write_ppm().
|
nodiscard |
Open and stat a regular file for bounded raw reading.
Definition at line 393 of file emu_host_io.c.
References internal_result(), k_emu_io_error, k_emu_io_invalid, k_emu_io_ok, and O_CLOEXEC.
Referenced by board_sd_attach(), load_panel(), and priv_emu_elf_source_open().
|
nodiscard |
Write a NUL-terminated literal to the injected output descriptor.
Definition at line 338 of file emu_host_io.c.
References internal_result(), k_emu_io_invalid, priv_emu_io_write_exact(), s_out_fd, and strlen().
|
nodiscard |
Format bounded text and write it to the injected output descriptor.
Definition at line 355 of file emu_host_io.c.
References internal_vformat(), and s_out_fd.
Referenced by console_flush_line(), internal_on_itm_stim_write(), and internal_rtt_line_feed().
|
nodiscard |
Read exactly count bytes at offset without changing the cursor.
Definition at line 294 of file emu_host_io.c.
References internal_pread_adapter(), and internal_transfer().
Referenced by board_view_read_rgb888_fd(), emu_presentation_read(), internal_copy_bytes(), priv_board_sd_storage_read(), and priv_emu_elf_read().
|
nodiscard |
Write exactly count bytes at offset without changing the cursor.
Definition at line 299 of file emu_host_io.c.
References internal_pwrite_adapter(), and internal_transfer().
Referenced by emu_presentation_snapshot(), emu_presentation_write(), internal_copy_bytes(), internal_write_sector(), and priv_board_sd_storage_write().
|
nodiscard |
Read exactly count sequential bytes or report EOF/fault progress.
Definition at line 284 of file emu_host_io.c.
References internal_read_adapter(), and internal_transfer().
Referenced by load_panel().
| void priv_emu_io_txn_abort | ( | emu_io_txn_t * | txn | ) |
Close and unlink an active sibling transaction without publication.
Releases any temporary descriptor/path while preserving the final target.
| [in,out] | txn | Transaction to abandon; nullptr is accepted. |
txn was zero-initialised or passed to priv_emu_io_txn_begin(). txn. Definition at line 467 of file emu_host_io.c.
References emu_io_txn_t::fd, and emu_io_txn_t::temp.
Referenced by board_sd_save(), internal_prof_write_html(), internal_prof_write_speedscope(), and write_ppm().
|
nodiscard |
Create a sibling temporary output for failure-atomic publication.
Definition at line 427 of file emu_host_io.c.
References emu_io_txn_t::fd, emu_io_txn_t::final, internal_result(), k_emu_io_error, k_emu_io_invalid, k_emu_io_ok, k_emu_io_truncated, and emu_io_txn_t::temp.
Referenced by board_sd_save(), internal_prof_write_html(), internal_prof_write_speedscope(), and write_ppm().
|
nodiscard |
Sync, close, and atomically rename an active sibling transaction.
Definition at line 447 of file emu_host_io.c.
References emu_io_txn_t::fd, emu_io_txn_t::final, internal_result(), k_emu_io_error, k_emu_io_invalid, k_emu_io_ok, and emu_io_txn_t::temp.
Referenced by board_sd_save(), internal_prof_write_html(), internal_prof_write_speedscope(), and write_ppm().
|
nodiscard |
Write exactly count sequential bytes or report fault progress.
Definition at line 289 of file emu_host_io.c.
References internal_transfer(), and internal_write_adapter().
Referenced by internal_vformat(), internal_write_ppm_pixels(), priv_emu_io_err_bytes(), priv_emu_io_err_text(), priv_emu_io_file_char(), priv_emu_io_file_text(), and priv_emu_io_out_text().
|
static |
Definition at line 117 of file emu_host_io.c.
Referenced by priv_emu_io_configure(), priv_emu_io_err_bytes(), priv_emu_io_err_text(), and priv_emu_io_errf().
|
static |
Definition at line 109 of file emu_host_io.c.
Referenced by priv_emu_io_configure().
|
static |
Definition at line 115 of file emu_host_io.c.
Referenced by internal_pread_adapter(), internal_pwrite_adapter(), internal_read_adapter(), internal_write_adapter(), and priv_emu_io_configure().
|
static |
Definition at line 116 of file emu_host_io.c.
Referenced by priv_emu_io_configure(), priv_emu_io_out_text(), and priv_emu_io_outf().