summaryrefslogtreecommitdiff
path: root/masm/asm.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--masm/asm.h62
1 files changed, 56 insertions, 6 deletions
diff --git a/masm/asm.h b/masm/asm.h
index b8e6214..86f6b9a 100644
--- a/masm/asm.h
+++ b/masm/asm.h
@@ -8,6 +8,34 @@
#include "lex.h"
#include "parse.h"
+enum symbol_flag {
+ SYM_LOCAL,
+ SYM_GLOBAL,
+ SYM_EXTERNAL,
+};
+
+struct symbol {
+ char name[MAX_LEX_LENGTH];
+ uint32_t index;
+ struct section *sec;
+ enum symbol_flag flag;
+
+};
+
+struct symbol_table {
+ uint32_t count;
+ uint32_t len;
+ struct symbol *symbols;
+};
+
+int symtbl_init(struct symbol_table *sym_tbl);
+void symtbl_free(struct symbol_table *sym_tbl);
+
+int symtbl_push(struct symbol_table *sym_tbl, struct symbol sym);
+int symtbl_find(struct symbol_table *sym_tbl, struct symbol **sym,
+ const char name[MAX_LEX_LENGTH]);
+
+
struct str_table {
char *ptr;
size_t size;
@@ -34,21 +62,43 @@ struct section_meta {
};
struct assembler {
+ // the token lexer
struct lexer lexer;
+ // the expression parser
struct parser parser;
- struct str_table shstr_tbl;
- struct str_table str_tbl;
+ // shdr indexes
struct section_meta *meta;
size_t shstrtbl_idx;
size_t strtbl_idx;
- size_t symtbl_idx;
+ size_t symtab_idx;
+
+ // symbols and strings
+ struct symbol_table sym_tbl;
+ struct str_table shstr_tbl;
+ struct str_table str_tbl;
+
+ // elf data
+ void *phdr; // void* since could be Elf32 or Elf64
+ void *shdr;
+ void *symtab;
+ uint32_t phdr_len;
+ uint32_t shdr_len;
+ uint32_t symtab_len;
+};
+
+struct assembler_arguments {
+ char *in_file;
+ char *out_file;
+ enum mips_isa isa;
};
-int assembler_init(struct assembler *asm, const char *path);
-void assembler_free(struct assembler *asm);
+int assembler_init(struct assembler *assembler, const char *path);
+void assembler_free(struct assembler *assembler);
+
+int assemble_file(struct assembler_arguments args);
/* assemble a mips32 file*/
-int assemble_file_mips32(char *path);
+int assemble_file_mips32(struct assembler_arguments args);
#endif /* __ASM_H__ */