Skip to content

Commit

Permalink
Add jal rd, symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
ekaitz-zarraga committed Aug 5, 2023
1 parent 1e597f3 commit 3b114c1
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions riscv64-asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ static void parse_operand(TCCState *s1, Operand *op)
op->type = OP_IM32;
return;
} else {
expect("operand");
/*TODO: Deal with offsets and stuff like that for the moment it's ok to
leave it like this as we are only taking the symbol case*/
}
}

Expand Down Expand Up @@ -304,6 +305,12 @@ static void gen_lla(int token, Operand* op1, Operand* op2) {
// If we do it as in the code above it works properly.
// I don't know why it should be like this, but it happens to work
}
static void gen_jal(int token, Operand* op1, Operand* op2) {
Sym *sym;
sym = op2->e.sym;
greloca(cur_text_section, sym, ind, R_RISCV_JAL, 0);
gen_le32( 0b1101111 | ENCODE_RD(op1->reg));
}

static void asm_binary_opcode(TCCState* s1, int token)
{
Expand Down Expand Up @@ -432,14 +439,15 @@ static void asm_jump_opcode(TCCState* s1, int token)
return;
case TOK_ASM_jal:
if(ops[1].e.sym){
// TODO: implement jal reg, symbol
tcc_error("(%s): to label not supported", get_tok_str(token, NULL));
}
// This is for offsets
// TODO: Make sure it works with positive and negative offsets
if(ops[1].type != OP_IM20S && ops[1].type != OP_IM12S)
// This handles `jal rd, symbol`
gen_jal(token, &ops[0], &ops[1]);
return;
} else if(ops[1].type != OP_IM20S && ops[1].type != OP_IM12S) {
tcc_error("jal jump too large");
else{
} else {
// This is for immediates like `jal rd, -1201`
// TODO: Make sure it works with positive and negative relative
// jumps
/* Weird encoding. It doesn't let us use `asm_emit_u` easily */
offset = 0;
offset = ((ops[1].e.v & 0x100000)>>20) <<19 |
Expand Down

0 comments on commit 3b114c1

Please sign in to comment.