Skip to content

Commit

Permalink
Merge branch 'feature/riscv-asm'
Browse files Browse the repository at this point in the history
  • Loading branch information
tyfkda committed Apr 27, 2024
2 parents e66db13 + af48a4d commit e33d435
Show file tree
Hide file tree
Showing 26 changed files with 1,423 additions and 365 deletions.
11 changes: 9 additions & 2 deletions include/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,15 @@ typedef struct {
#define R_X86_64_PC32 (2) /* PC relative 32 bit signed */
#define R_X86_64_PLT32 (4) /* 32 bit PLT address */

#define R_RISCV_CALL (18)
#define R_RISCV_RELAX (51)
#define R_RISCV_64 (2)
#define R_RISCV_BRANCH (16)
#define R_RISCV_JAL (17)
#define R_RISCV_CALL (18)
#define R_RISCV_PCREL_HI20 (23)
#define R_RISCV_PCREL_LO12_I (24)
#define R_RISCV_RVC_BRANCH (44)
#define R_RISCV_RVC_JUMP (45)
#define R_RISCV_RELAX (51)

#define ELF64_R_SYM(info) ((info) >> 32)
#define ELF64_R_TYPE(info) ((Elf64_Word)(info))
Expand Down
8 changes: 0 additions & 8 deletions src/as/arch/aarch64/asm_code.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@
#include "parse_asm.h"
#include "util.h"

#ifndef MAKE_CODE16
#define MAKE_CODE16(inst, code, ...) do { unsigned short buf[] = {__VA_ARGS__}; make_code16(inst, code, buf, sizeof(buf)); } while (0)
#endif

#ifndef MAKE_CODE32
#define MAKE_CODE32(inst, code, ...) do { unsigned int buf[] = {__VA_ARGS__}; make_code32(inst, code, buf, sizeof(buf)); } while (0)
#endif

void make_code16(Inst *inst, Code *code, unsigned short *buf, int len) {
assert(code->len + len <= (int)sizeof(code->buf));
code->inst = inst;
Expand Down
2 changes: 1 addition & 1 deletion src/as/arch/aarch64/inst.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ enum Opcode {
};

enum RegType {
NOREG,
NOREG = -1,

// 32bit
W0, W1, W2, W3, W4, W5, W6, W7, W8, W9, W10, W11, W12, W13, W14, W15,
Expand Down
38 changes: 0 additions & 38 deletions src/as/arch/aarch64/ir_asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,6 @@
#define LONG_SIZE (4)
#define QUAD_SIZE (8)

static LabelInfo *new_label(int section, uintptr_t address) {
LabelInfo *info = malloc_or_die(sizeof(*info));
info->section = section;
info->flag = 0;
info->address = address;
info->kind = LK_NONE;
return info;
}

LabelInfo *add_label_table(Table *label_table, const Name *label, int section, bool define, bool global) {
LabelInfo *info = table_get(label_table, label);
if (info != NULL) {
if (define) {
if ((info->flag & LF_DEFINED) != 0) {
fprintf(stderr, "`%.*s' already defined\n", NAMES(label));
return NULL;
}
info->address = 1;
info->section = section;
}
} else {
info = new_label(section, 0);
table_put(label_table, label, info);
}
if (define)
info->flag |= LF_DEFINED;
if (global)
info->flag |= LF_GLOBAL;
return info;
}

IR *new_ir_label(const Name *label) {
IR *ir = malloc_or_die(sizeof(*ir));
ir->kind = IR_LABEL;
Expand Down Expand Up @@ -86,13 +55,6 @@ IR *new_ir_expr(enum IrKind kind, const Expr *expr) {
return ir;
}

static uintptr_t align_next_section(enum SectionType sec, uintptr_t address) {
size_t align = section_aligns[sec];
if (align > 1)
address = ALIGN(address, align);
return address;
}

bool calc_label_address(uintptr_t start_address, Vector **section_irs, Table *label_table) {
bool settle = true;
uintptr_t address = start_address;
Expand Down
5 changes: 3 additions & 2 deletions src/as/arch/aarch64/parse_aarch64.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static enum RegType find_register(const char **pp) {
for (int i = 0; i < (int)ARRAY_SIZE(kRegisters); ++i) {
const char *name = kRegisters[i].name;
size_t n = strlen(name);
if (strncmp(p, name, n) == 0 && !isdigit(p[n])) {
if (strncmp(p, name, n) == 0 && !is_label_chr(p[n])) {
*pp = p + n;
return kRegisters[i].reg;
}
Expand Down Expand Up @@ -167,7 +167,8 @@ static bool parse_operand(ParseInfo *info, Operand *operand) {
return false;
}

void parse_inst(ParseInfo *info, Inst *inst) {
void parse_inst(ParseInfo *info, Line *line) {
Inst *inst = &line->inst;
Operand *opr_table[] = {&inst->opr1, &inst->opr2, &inst->opr3};
for (int i = 0; i < (int)ARRAY_SIZE(opr_table); ++i)
opr_table[i]->type = NOOPERAND;
Expand Down
Loading

0 comments on commit e33d435

Please sign in to comment.