Path: blob/main/crates/fiber/src/stackswitch/x86.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!6//7// This file is modeled after x86_64.rs and comments are not copied over. For8// reference be sure to review the other file. Note that the pointer size is9// different so the reserved space at the top of the stack is 8 bytes, not 1610// bytes. Still two pointers though.1112use wasmtime_asm_macros::asm_func;1314// fn(top_of_stack: *mut u8)15asm_func!(16wasmtime_versioned_export_macros::versioned_stringify_ident!(wasmtime_fiber_switch),17"18// Load our stack-to-use19mov eax, 0x4[esp]20mov ecx, -0x8[eax]2122// Save callee-saved registers23push ebp24push ebx25push esi26push edi2728// Save our current stack and jump to the stack-to-use29mov -0x8[eax], esp30mov esp, ecx3132// Restore callee-saved registers33pop edi34pop esi35pop ebx36pop ebp37ret38",39);4041// fn(42// top_of_stack: *mut u8,43// entry_point: extern fn(*mut u8, *mut u8),44// entry_arg0: *mut u8,45// )46asm_func!(47wasmtime_versioned_export_macros::versioned_stringify_ident!(wasmtime_fiber_init),48"49mov eax, 4[esp]5051// move top_of_stack to the 2nd argument52mov -0x0c[eax], eax5354// move entry_arg0 to the 1st argument55mov ecx, 12[esp]56mov -0x10[eax], ecx5758// Move our start function to the return address which the `ret` in59// `wasmtime_fiber_start` will return to.60lea ecx, {start}61mov -0x14[eax], ecx6263// And move `entry_point` to get loaded into `%ebp` through the context64// switch. This'll get jumped to in `wasmtime_fiber_start`.65mov ecx, 8[esp]66mov -0x18[eax], ecx6768// Our stack from top-to-bottom looks like:69//70// * 8 bytes of reserved space per unix.rs (two-pointers space)71// * 8 bytes of arguments (two arguments wasmtime_fiber_start forwards)72// * 4 bytes of return address73// * 16 bytes of saved registers74//75// Note that after the return address the stack is conveniently 16-byte76// aligned as required, so we just leave the arguments on the stack in77// `wasmtime_fiber_start` and immediately do the call.78lea ecx, -0x24[eax]79mov -0x08[eax], ecx80ret81",82start = sym super::wasmtime_fiber_start,83);8485asm_func!(86wasmtime_versioned_export_macros::versioned_stringify_ident!(wasmtime_fiber_start),87"88.cfi_startproc simple89.cfi_def_cfa_offset 090.cfi_escape 0x0f, /* DW_CFA_def_cfa_expression */ \915, /* the byte length of this expression */ \920x74, 0x08, /* DW_OP_breg4 (%esp) + 8 */ \930x06, /* DW_OP_deref */ \940x23, 0x14 /* DW_OP_plus_uconst 0x14 */9596.cfi_rel_offset eip, -497.cfi_rel_offset ebp, -898.cfi_rel_offset ebx, -1299.cfi_rel_offset esi, -16100.cfi_rel_offset edi, -20101102// Our arguments and stack alignment are all prepped by103// `wasmtime_fiber_init`.104call ebp105ud2106.cfi_endproc107",108);109110111