diff options
author | Freya Murphy <freya@freyacat.org> | 2024-09-10 18:23:46 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-09-10 18:23:46 -0400 |
commit | 92a7e5853c6caeec09122c05ddbc19ae1498a0d8 (patch) | |
tree | d14a6a1c091df35c06ffb735ce3f6c72b1f37b42 /masm/asm.h | |
parent | relocation table hell (diff) | |
download | mips-92a7e5853c6caeec09122c05ddbc19ae1498a0d8.tar.gz mips-92a7e5853c6caeec09122c05ddbc19ae1498a0d8.tar.bz2 mips-92a7e5853c6caeec09122c05ddbc19ae1498a0d8.zip |
joe
Diffstat (limited to '')
-rw-r--r-- | masm/asm.h | 62 |
1 files changed, 56 insertions, 6 deletions
@@ -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__ */ |