github.com/varialus/godfly@v0.0.0-20130904042352-1934f9f095ab/src/pkg/runtime/sys_x86.c (about) 1 // Copyright 2013 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build amd64 386 6 7 #include "runtime.h" 8 9 // adjust Gobuf as it if executed a call to fn with context ctxt 10 // and then did an immediate gosave. 11 void 12 runtime·gostartcall(Gobuf *gobuf, void (*fn)(void), void *ctxt) 13 { 14 uintptr *sp; 15 16 sp = (uintptr*)gobuf->sp; 17 *--sp = (uintptr)gobuf->pc; 18 gobuf->sp = (uintptr)sp; 19 gobuf->pc = (uintptr)fn; 20 gobuf->ctxt = ctxt; 21 } 22 23 // Called to rewind context saved during morestack back to beginning of function. 24 // To help us, the linker emits a jmp back to the beginning right after the 25 // call to morestack. We just have to decode and apply that jump. 26 void 27 runtime·rewindmorestack(Gobuf *gobuf) 28 { 29 byte *pc; 30 31 pc = (byte*)gobuf->pc; 32 if(pc[0] == 0xe9) { // jmp 4-byte offset 33 gobuf->pc = gobuf->pc + 5 + *(int32*)(pc+1); 34 return; 35 } 36 if(pc[0] == 0xeb) { // jmp 1-byte offset 37 gobuf->pc = gobuf->pc + 2 + *(int8*)(pc+1); 38 return; 39 } 40 runtime·printf("runtime: pc=%p %x %x %x %x %x\n", pc, pc[0], pc[1], pc[2], pc[3], pc[4]); 41 runtime·throw("runtime: misuse of rewindmorestack"); 42 }