summaryrefslogtreecommitdiff
path: root/cmd/sbc_harness/ihex.h
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-06-12 02:32:54 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-06-12 02:32:54 -0600
commit0474953ab2600ee3b6bc17ba605b8e7877e181fe (patch)
tree5d3d4499d81d6a9f5422caf0694051272a1f6335 /cmd/sbc_harness/ihex.h
parent8ce568bae1cc9a77996f16b859482992d27e0b37 (diff)
parent43cacf95462588de0ab3125bdea7a37f10ebf8fc (diff)
Merge branch 'lukeshu/better-net-flash'
Diffstat (limited to 'cmd/sbc_harness/ihex.h')
-rw-r--r--cmd/sbc_harness/ihex.h48
1 files changed, 48 insertions, 0 deletions
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 <lukeshu@lukeshu.com>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+/* https://archive.org/details/IntelHEXStandard */
+
+#ifndef _SBC_HARNESS_IHEX_H_
+#define _SBC_HARNESS_IHEX_H_
+
+#include <stdbool.h> /* for bool */
+#include <stddef.h> /* for size_t */
+#include <stdint.h> /* for uint{n}_t */
+
+#include <libhw/generic/io.h>
+#include <libmisc/private.h>
+
+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_ */