/* sbc_harness/ihex.h - Intel Hex decoder * * Copyright (C) 2025 Luke T. Shumaker * SPDX-License-Identifier: AGPL-3.0-or-later */ /* https://archive.org/details/IntelHEXStandard */ #ifndef _SBC_HARNESS_IHEX_H_ #define _SBC_HARNESS_IHEX_H_ #include /* for bool */ #include /* for size_t */ #include /* for uint{n}_t */ #include #include struct ihex_decoder { void *handle_arg; error (*handle_data)(void *arg, uint32_t off, uint8_t count, uint8_t *dat); error (*handle_set_exec_start_seg)(void *arg, uint16_t cs, uint16_t ip); error (*handle_set_exec_start_lin)(void *arg, uint32_t eip); error (*handle_eof)(void *arg); BEGIN_PRIVATE(IHEX_H); bool seen_eof; error sticky_err; /* ihex_decoder_write: deal with ASCII soup */ bool in_record; char buf_char; /* the first nibble of a byte (still in ASCII) */ /* ihex_decode_byte: build records from decoded bytes */ /* The currently-being-decoded record, after hex decoding. */ uint16_t buf_len; uint8_t buf[0xFF+5]; /* ihex_handle_record: handle record semantics */ enum { _IHEX_MODE_NONE, _IHEX_MODE_SEG, _IHEX_MODE_LIN } addr_mode; uint32_t addr_base; END_PRIVATE(IHEX_H); }; LO_IMPLEMENTATION_H(io_writer, struct ihex_decoder, ihex_decoder); LO_IMPLEMENTATION_H(io_closer, struct ihex_decoder, ihex_decoder); #endif /* _SBC_HARNESS_IHEX_H_ */