diff options
Diffstat (limited to 'masm')
-rw-r--r-- | masm/asm.c | 9 | ||||
-rw-r--r-- | masm/lex.c | 2 | ||||
-rw-r--r-- | masm/parse.c | 24 | ||||
-rw-r--r-- | masm/reltab.c | 4 | ||||
-rw-r--r-- | masm/sectab.c | 8 | ||||
-rw-r--r-- | masm/strtab.c | 2 | ||||
-rw-r--r-- | masm/symtab.c | 4 |
7 files changed, 30 insertions, 23 deletions
@@ -315,7 +315,7 @@ static int assemble_phdr(struct assembler *assembler, Elf32_Phdr **res, Elf32_Phdr *phdr = malloc(sizeof(Elf32_Phdr) * assembler->sectab.len); if (phdr == NULL) { - ERROR("cannot alloc"); + PERROR("cannot alloc"); return M_ERROR;; } @@ -354,6 +354,11 @@ static int assemble_shdr(struct assembler *assembler, Elf32_Shdr **res, Elf32_Shdr *shdr = malloc(sizeof(Elf32_Shdr) * max_entries); + if (shdr == NULL) { + PERROR("cannot alloc"); + return M_ERROR; + } + size_t str_off; uint32_t count = 0; @@ -593,7 +598,7 @@ static int write_file(struct assembler *assembler, Elf32_Ehdr *ehdr, if (out == NULL) { - ERROR("cannot write '%s'", path); + PERROR("cannot write '%s'", path); return M_ERROR; } @@ -309,7 +309,7 @@ int lexer_init(const char *path, struct lexer *lexer) { FILE *file = fopen(path, "r"); if (file == NULL) { - ERROR("cannot read '%s'", path); + PERROR("cannot read '%s'", path); return M_ERROR; } lexer->file = file; diff --git a/masm/parse.c b/masm/parse.c index 6c817d4..2e404ad 100644 --- a/masm/parse.c +++ b/masm/parse.c @@ -1,6 +1,5 @@ #include <mlimits.h> #include <merror.h> -#include <netinet/in.h> #include <stdint.h> #include <stdio.h> #include <string.h> @@ -10,6 +9,9 @@ #include "lex.h" #include "mips.h" +#define B16(x) (x) +#define B32(x) (x) + static int next_token(struct parser *parser, struct token *tok) { if (parser->peek.type != TOK_EOF) { @@ -475,7 +477,7 @@ off: if (assert_token(parser, TOK_NUMBER, &token)) return M_ERROR; - fi->data.offset = htons(token.number); + fi->data.immd = B16(token.number); if (peek_token(parser, &token)) return M_ERROR; @@ -618,7 +620,7 @@ static int parse_instruction_i(struct parser *parser, if (token.number >= MAX16) return M_ERROR; - ins->data.immd = htons(token.number); + ins->data.immd = B16(token.number); return M_SUCCESS; } @@ -634,12 +636,12 @@ static int parse_instruction_offset(struct parser *parser, case MAX26: if (get_offset_26(parser, &n, ref)) return M_ERROR; - ins->data.offs26 = htonl(n); + ins->data.offs26 = B32(n); break; case MAX16: if (get_offset(parser, &n, ref)) return M_ERROR; - ins->data.offset = htons(n); + ins->data.offset = B16(n); break; default: return M_ERROR; @@ -682,7 +684,7 @@ static int parse_instruction_branch_equal(struct parser *parser, int32_t off; if (get_offset(parser, &off, ref)) return M_ERROR; - ins->data.offset = htons(off); + ins->data.offset = B16(off); return M_SUCCESS; } @@ -703,7 +705,7 @@ static int parse_instruction_branch(struct parser *parser, if (get_offset(parser, &n, ref)) return M_ERROR; - ins->data.offset = htons(n); + ins->data.offset = B16(n); return M_SUCCESS; } @@ -742,7 +744,7 @@ static int parse_instruction_sli(struct parser *parser, if (assert_token(parser, TOK_NUMBER, &token) || token.number > MAX16) return M_ERROR; - ins->data.immd = htons(token.number); + ins->data.immd = B16(token.number); return M_SUCCESS; } @@ -818,7 +820,7 @@ static int parse_pseudo_li(struct parser *parser, struct ins_expr *expr) expr->ins[0] = mips_instructions[MIPS_INS_ORI]; expr->ins[0].data.rt = reg; expr->ins[0].data.rs = MIPS_REG_ZERO; - expr->ins[0].data.immd = htons(immd); + expr->ins[0].data.immd = B16(immd); expr->ref[0].type = R_MIPS_NONE; return M_SUCCESS; @@ -859,11 +861,11 @@ static int parse_pseudo_la(struct parser *parser, struct ins_expr *expr) expr->ins_len = 2; expr->ins[0] = mips_instructions[MIPS_INS_LUI]; expr->ins[0].data.rt = reg; - expr->ins[0].data.immd = htons(hi); + expr->ins[0].data.immd = B16(hi); expr->ins[1] = mips_instructions[MIPS_INS_ORI]; expr->ins[1].data.rt = reg; expr->ins[1].data.rs = MIPS_REG_ZERO; - expr->ins[1].data.immd = htons(lo); + expr->ins[1].data.immd = B16(lo); return M_SUCCESS; } diff --git a/masm/reltab.c b/masm/reltab.c index 482ed44..afbd5e7 100644 --- a/masm/reltab.c +++ b/masm/reltab.c @@ -13,7 +13,7 @@ int reltab_init(struct relocation_table *reltab) reltab->data = malloc(sizeof(Elf32_Rela) * RELTAB_INIT_LEN); if (reltab->data == NULL) { - ERROR("cannot alloc"); + PERROR("cannot alloc"); return M_ERROR; } @@ -33,7 +33,7 @@ int reltab_push(struct relocation_table *reltab, const Elf32_Rela rel) * reltab->size); if (reltab->data == NULL) { - ERROR("cannot realloc"); + PERROR("cannot realloc"); return M_ERROR; } } diff --git a/masm/sectab.c b/masm/sectab.c index d07399f..caf34dd 100644 --- a/masm/sectab.c +++ b/masm/sectab.c @@ -16,7 +16,7 @@ int sectab_init(struct section_table *sectab) sectab->sections = malloc(sizeof(struct section) * SECTBL_INIT_LEN); if (sectab->sections == NULL) { - ERROR("cannot alloc"); + PERROR("cannot alloc"); return M_ERROR; } @@ -59,7 +59,7 @@ int sectab_alloc(struct section_table *sectab, struct section **res, sizeof(struct section) * sectab->size); if (sectab->sections == NULL) { - ERROR("cannot realloc"); + PERROR("cannot realloc"); return M_ERROR; } } @@ -94,7 +94,7 @@ int sectab_alloc(struct section_table *sectab, struct section **res, } if (sec->entries == NULL) { - ERROR("cannot alloc"); + PERROR("cannot alloc"); return M_ERROR; } @@ -127,7 +127,7 @@ int sec_push(struct section *section, struct section_entry entry) sizeof(struct section_entry) * section->size); if (new == NULL) { - ERROR("cannot realloc"); + PERROR("cannot realloc"); return M_ERROR; } diff --git a/masm/strtab.c b/masm/strtab.c index 57d3d0e..404ea73 100644 --- a/masm/strtab.c +++ b/masm/strtab.c @@ -41,7 +41,7 @@ int strtab_init(struct str_table *strtab) strtab->size = 1; strtab->ptr = malloc(1); if (strtab->ptr == NULL) { - ERROR("cannot alloc"); + PERROR("cannot alloc"); return M_ERROR; } *strtab->ptr = '\0'; diff --git a/masm/symtab.c b/masm/symtab.c index c6f9aac..652bd42 100644 --- a/masm/symtab.c +++ b/masm/symtab.c @@ -18,7 +18,7 @@ int symtab_init(struct symbol_table *symtab) symtab->sections = malloc(sizeof(ssize_t) * SYMTBL_INIT_LEN); if (symtab->symbols == NULL || symtab->sections == NULL) { - ERROR("cannot alloc"); + PERROR("cannot alloc"); return M_ERROR; } @@ -44,7 +44,7 @@ int symtab_push(struct symbol_table *symtab, Elf32_Sym sym, ssize_t sec_idx) symtab->sections = realloc(symtab->sections, sizeof(ssize_t) * symtab->size); if (symtab->symbols == NULL || symtab->sections == NULL) { - ERROR("cannot realloc"); + PERROR("cannot realloc"); return M_ERROR; } } |