From 92a7e5853c6caeec09122c05ddbc19ae1498a0d8 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Tue, 10 Sep 2024 18:23:46 -0400 Subject: joe --- masm/asm.h | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 6 deletions(-) (limited to 'masm/asm.h') 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__ */ -- cgit v1.2.3-freya