1/* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */ 2.global _longjmp 3.global longjmp 4.type _longjmp,@function 5.type longjmp,@function 6_longjmp: 7longjmp: 8 mov rax,rsi /* val will be longjmp return */ 9 test rax,rax 10 jnz 1f 11 inc rax /* if val==0, val=1 per longjmp semantics */ 121: 13 mov rbx, [rdi] /* rdi is the jmp_buf, restore regs from it */ 14 mov rbp, [rdi + 8] 15 mov r12, [rdi + 16] 16 mov r13, [rdi + 24] 17 mov r14, [rdi + 32] 18 mov r15, [rdi + 40] 19 mov rdx, [rdi + 48] /* this ends up being the stack pointer */ 20 mov rsp, rdx 21 mov rdx, [rdi + 56] /* this is the instruction pointer */ 22 jmp rdx /* goto saved address without altering rsp */ 23