From 43cacf95462588de0ab3125bdea7a37f10ebf8fc Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sat, 19 Apr 2025 20:10:05 -0600 Subject: /harness/flash.bin: Accept ihex files instead of verbatim data --- cmd/sbc_harness/ihex.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 cmd/sbc_harness/ihex.h (limited to 'cmd/sbc_harness/ihex.h') diff --git a/cmd/sbc_harness/ihex.h b/cmd/sbc_harness/ihex.h new file mode 100644 index 0000000..d5ac70c --- /dev/null +++ b/cmd/sbc_harness/ihex.h @@ -0,0 +1,48 @@ +/* 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); + +#endif /* _SBC_HARNESS_IHEX_H_ */ -- cgit v1.2.3-2-g168b