Path: blob/main/crates/fiber/src/stackswitch/riscv64.rs
1692 views
// A WORD OF CAUTION1//2// This entire file basically needs to be kept in sync with itself. It's not3// really possible to modify just one bit of this file without understanding4// all the other bits. Documentation tries to reference various bits here and5// there but try to make sure to read over everything before tweaking things!67use wasmtime_asm_macros::asm_func;89// fn(top_of_stack(rdi): *mut u8)10asm_func!(11wasmtime_versioned_export_macros::versioned_stringify_ident!(wasmtime_fiber_switch),12"13// See https://github.com/rust-lang/rust/issues/80608.14.attribute arch, \"rv64gc\"1516// We're switching to arbitrary code somewhere else, so pessimistically17// assume that all callee-save register are clobbered. This means we need18// to save/restore all of them.19//20// Note that this order for saving is important since we use CFI directives21// below to point to where all the saved registers are.22sd ra,-0x8(sp)23sd fp,-0x10(sp)24sd s1,-0x18(sp)25sd s2,-0x20(sp)26sd s3,-0x28(sp)27sd s4,-0x30(sp)28sd s5,-0x38(sp)29sd s6,-0x40(sp)30sd s7,-0x48(sp)31sd s8,-0x50(sp)32sd s9,-0x58(sp)33sd s10,-0x60(sp)34sd s11,-0x68(sp)35fsd fs0,-0x70(sp)36fsd fs1,-0x78(sp)37fsd fs2,-0x80(sp)38fsd fs3,-0x88(sp)39fsd fs4,-0x90(sp)40fsd fs5,-0x98(sp)41fsd fs6,-0xa0(sp)42fsd fs7,-0xa8(sp)43fsd fs8,-0xb0(sp)44fsd fs9,-0xb8(sp)45fsd fs10,-0xc0(sp)46fsd fs11,-0xc8(sp)47addi sp , sp , -0xd04849ld t0 ,-0x10(a0)50sd sp ,-0x10(a0)5152// Swap stacks and restore all our callee-saved registers53mv sp,t05455fld fs11,0x8(sp)56fld fs10,0x10(sp)57fld fs9,0x18(sp)58fld fs8,0x20(sp)59fld fs7,0x28(sp)60fld fs6,0x30(sp)61fld fs5,0x38(sp)62fld fs4,0x40(sp)63fld fs3,0x48(sp)64fld fs2,0x50(sp)65fld fs1,0x58(sp)66fld fs0,0x60(sp)67ld s11,0x68(sp)68ld s10,0x70(sp)69ld s9,0x78(sp)70ld s8,0x80(sp)71ld s7,0x88(sp)72ld s6,0x90(sp)73ld s5,0x98(sp)74ld s4,0xa0(sp)75ld s3,0xa8(sp)76ld s2,0xb0(sp)77ld s1,0xb8(sp)78ld fp,0xc0(sp)79ld ra,0xc8(sp)80addi sp , sp , 0xd081jr ra82",83);8485// fn(86// top_of_stack(a0): *mut u8,87// entry_point(a1): extern fn(*mut u8, *mut u8),88// entry_arg0(a2): *mut u8,89// )90#[rustfmt::skip]91asm_func!(92wasmtime_versioned_export_macros::versioned_stringify_ident!(wasmtime_fiber_init),93"94lla t0,{}95sd t0,-0x18(a0) // ra,first should be wasmtime_fiber_start.96sd a0,-0x20(a0) // fp pointer.97sd a1,-0x28(a0) // entry_point will load to s1.98sd a2,-0x30(a0) // entry_arg0 will load to s2.99100//101addi t0,a0,-0xe0102sd t0,-0x10(a0)103ret104",105sym super::wasmtime_fiber_start,106);107108asm_func!(109wasmtime_versioned_export_macros::versioned_stringify_ident!(wasmtime_fiber_start),110"111.cfi_startproc simple112.cfi_def_cfa_offset 0113114115.cfi_escape 0x0f, /* DW_CFA_def_cfa_expression */ \1165, /* the byte length of this expression */ \1170x52, /* DW_OP_reg2 (sp) */ \1180x06, /* DW_OP_deref */ \1190x08, 0xd0 , /* DW_OP_const1u 0xc8 */ \1200x22 /* DW_OP_plus */121122123.cfi_rel_offset ra,-0x8124.cfi_rel_offset fp,-0x10125.cfi_rel_offset s1,-0x18126.cfi_rel_offset s2,-0x20127.cfi_rel_offset s3,-0x28128.cfi_rel_offset s4,-0x30129.cfi_rel_offset s5,-0x38130.cfi_rel_offset s6,-0x40131.cfi_rel_offset s7,-0x48132.cfi_rel_offset s8,-0x50133.cfi_rel_offset s9,-0x58134.cfi_rel_offset s10,-0x60135.cfi_rel_offset s11,-0x68136.cfi_rel_offset fs0,-0x70137.cfi_rel_offset fs1,-0x78138.cfi_rel_offset fs2,-0x80139.cfi_rel_offset fs3,-0x88140.cfi_rel_offset fs4,-0x90141.cfi_rel_offset fs5,-0x98142.cfi_rel_offset fs6,-0xa0143.cfi_rel_offset fs7,-0xa8144.cfi_rel_offset fs8,-0xb0145.cfi_rel_offset fs9,-0xb8146.cfi_rel_offset fs10,-0xc0147.cfi_rel_offset fs11,-0xc8148149mv a0,s2150mv a1,fp151jalr s1152// .4byte 0 will cause panic.153// for safety just like x86_64.rs.154.4byte 0155.cfi_endproc156",157);158159160