summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2024-09-20 20:46:37 -0400
committerFreya Murphy <freya@freyacat.org>2024-09-20 21:02:38 -0400
commit3b0a87254f8a1e48a155f5571c274297353a0106 (patch)
tree8aab94632c01c50e4adafc8a4d062902d5cdfe4e /include
parentremove test file (diff)
downloadmips-3b0a87254f8a1e48a155f5571c274297353a0106.tar.gz
mips-3b0a87254f8a1e48a155f5571c274297353a0106.tar.bz2
mips-3b0a87254f8a1e48a155f5571c274297353a0106.zip
start mld, add loading of object files, add fuzzing support
Diffstat (limited to '')
-rw-r--r--include/melf.h41
-rw-r--r--include/merror.h5
2 files changed, 46 insertions, 0 deletions
diff --git a/include/melf.h b/include/melf.h
new file mode 100644
index 0000000..095518b
--- /dev/null
+++ b/include/melf.h
@@ -0,0 +1,41 @@
+/* Copyright (c) 2024 Freya Murphy */
+
+#ifndef __MELF_H__
+#define __MELF_H__
+
+#include <elf.h>
+#include <arpa/inet.h>
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define B32(n) (__bswap_constant_32(n))
+#define B16(n) (__bswap_constant_16(n))
+#else
+#define B32(n) (n)
+#define B16(n) (n)
+#endif
+
+static const Elf32_Ehdr MIPS_ELF_EHDR =
+{
+ .e_ident = {
+ [EI_MAG0] = ELFMAG0,
+ [EI_MAG1] = ELFMAG1,
+ [EI_MAG2] = ELFMAG2,
+ [EI_MAG3] = ELFMAG3,
+ [EI_CLASS] = ELFCLASS32,
+ [EI_DATA] = ELFDATA2MSB,
+ [EI_VERSION] = EV_CURRENT,
+ [EI_OSABI] = ELFOSABI_NONE,
+ [EI_ABIVERSION] = 0x00,
+ [EI_PAD] = 0x00,
+ },
+ .e_type = B16(ET_REL),
+ .e_machine = B16(EM_MIPS),
+ .e_version = B32(EV_CURRENT),
+ .e_entry = 0x00,
+ .e_flags = B32(EF_MIPS_ARCH_32R6),
+ .e_ehsize = B16(sizeof(Elf32_Ehdr)),
+ .e_phentsize = B16(sizeof(Elf32_Phdr)),
+ .e_shentsize = B16(sizeof(Elf32_Shdr)),
+};
+
+#endif /* __MELF_H__ */
diff --git a/include/merror.h b/include/merror.h
index 727111d..7be6fc7 100644
--- a/include/merror.h
+++ b/include/merror.h
@@ -2,6 +2,8 @@
#ifndef __MERROR_H__
#define __MERROR_H__
+#include <errno.h>
+
/* Error codes
*/
#define M_SUCCESS 0
@@ -34,4 +36,7 @@ void __log_impl(int type, const char *format, ...);
#define ERROR_POS(pos, format, ...) \
__log_impl_pos(pos.y, pos.x, __ERROR, format, ##__VA_ARGS__)
+#define PERROR(format, ...) \
+ __log_impl(__ERROR, format ": %s", ##__VA_ARGS__, (strerror(errno)))
+
#endif /* __MERROR_H__ */