Add RISC-V inline asm support
This commit is contained in:
parent
31e7fa54a0
commit
f9534a9bc9
@ -497,6 +497,18 @@ fn prologue(generated_asm: &mut String, arch: InlineAsmArch) {
|
||||
generated_asm.push_str(" push rbp\n");
|
||||
generated_asm.push_str(" mov rbp,rdi\n");
|
||||
}
|
||||
InlineAsmArch::RiscV32 => {
|
||||
generated_asm.push_str(" addi sp, sp, -8\n");
|
||||
generated_asm.push_str(" sw ra, 4(sp)\n");
|
||||
generated_asm.push_str(" sw s0, 0(sp)\n");
|
||||
generated_asm.push_str(" mv s0, a0\n");
|
||||
}
|
||||
InlineAsmArch::RiscV64 => {
|
||||
generated_asm.push_str(" addi sp, sp, -16\n");
|
||||
generated_asm.push_str(" sd ra, 8(sp)\n");
|
||||
generated_asm.push_str(" sd s0, 0(sp)\n");
|
||||
generated_asm.push_str(" mv s0, a0\n");
|
||||
}
|
||||
_ => unimplemented!("prologue for {:?}", arch),
|
||||
}
|
||||
}
|
||||
@ -511,6 +523,18 @@ fn epilogue(generated_asm: &mut String, arch: InlineAsmArch) {
|
||||
generated_asm.push_str(" pop rbp\n");
|
||||
generated_asm.push_str(" ret\n");
|
||||
}
|
||||
InlineAsmArch::RiscV32 => {
|
||||
generated_asm.push_str(" lw s0, 0(sp)\n");
|
||||
generated_asm.push_str(" lw ra, 4(sp)\n");
|
||||
generated_asm.push_str(" addi sp, sp, 8\n");
|
||||
generated_asm.push_str(" ret\n");
|
||||
}
|
||||
InlineAsmArch::RiscV64 => {
|
||||
generated_asm.push_str(" ld s0, 0(sp)\n");
|
||||
generated_asm.push_str(" ld ra, 8(sp)\n");
|
||||
generated_asm.push_str(" addi sp, sp, 16\n");
|
||||
generated_asm.push_str(" ret\n");
|
||||
}
|
||||
_ => unimplemented!("epilogue for {:?}", arch),
|
||||
}
|
||||
}
|
||||
@ -520,6 +544,9 @@ fn epilogue_noreturn(generated_asm: &mut String, arch: InlineAsmArch) {
|
||||
InlineAsmArch::X86 | InlineAsmArch::X86_64 => {
|
||||
generated_asm.push_str(" ud2\n");
|
||||
}
|
||||
InlineAsmArch::RiscV32 | InlineAsmArch::RiscV64 => {
|
||||
generated_asm.push_str(" ebreak\n");
|
||||
}
|
||||
_ => unimplemented!("epilogue_noreturn for {:?}", arch),
|
||||
}
|
||||
}
|
||||
@ -541,6 +568,16 @@ fn save_register(
|
||||
reg.emit(generated_asm, InlineAsmArch::X86_64, None).unwrap();
|
||||
generated_asm.push('\n');
|
||||
}
|
||||
InlineAsmArch::RiscV32 => {
|
||||
generated_asm.push_str(" sw ");
|
||||
reg.emit(generated_asm, InlineAsmArch::RiscV32, None).unwrap();
|
||||
writeln!(generated_asm, ", 0x{:x}(s0)", offset.bytes()).unwrap();
|
||||
}
|
||||
InlineAsmArch::RiscV64 => {
|
||||
generated_asm.push_str(" sd ");
|
||||
reg.emit(generated_asm, InlineAsmArch::RiscV64, None).unwrap();
|
||||
writeln!(generated_asm, ", 0x{:x}(s0)", offset.bytes()).unwrap();
|
||||
}
|
||||
_ => unimplemented!("save_register for {:?}", arch),
|
||||
}
|
||||
}
|
||||
@ -562,6 +599,16 @@ fn restore_register(
|
||||
reg.emit(generated_asm, InlineAsmArch::X86_64, None).unwrap();
|
||||
writeln!(generated_asm, ", [rbp+0x{:x}]", offset.bytes()).unwrap();
|
||||
}
|
||||
InlineAsmArch::RiscV32 => {
|
||||
generated_asm.push_str(" lw ");
|
||||
reg.emit(generated_asm, InlineAsmArch::RiscV32, None).unwrap();
|
||||
writeln!(generated_asm, ", 0x{:x}(s0)", offset.bytes()).unwrap();
|
||||
}
|
||||
InlineAsmArch::RiscV64 => {
|
||||
generated_asm.push_str(" ld ");
|
||||
reg.emit(generated_asm, InlineAsmArch::RiscV64, None).unwrap();
|
||||
writeln!(generated_asm, ", 0x{:x}(s0)", offset.bytes()).unwrap();
|
||||
}
|
||||
_ => unimplemented!("restore_register for {:?}", arch),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user