Home | History | Annotate | Download | only in runtime
      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 package runtime
      6 
      7 import "unsafe"
      8 
      9 // adjust Gobuf as if it executed a call to fn with context ctxt
     10 // and then did an immediate Gosave.
     11 func gostartcall(buf *gobuf, fn, ctxt unsafe.Pointer) {
     12 	if buf.lr != 0 {
     13 		throw("invalid use of gostartcall")
     14 	}
     15 	buf.lr = buf.pc
     16 	buf.pc = uintptr(fn)
     17 	buf.ctxt = ctxt
     18 }
     19 
     20 // Called to rewind context saved during morestack back to beginning of function.
     21 // To help us, the linker emits a jmp back to the beginning right after the
     22 // call to morestack. We just have to decode and apply that jump.
     23 func rewindmorestack(buf *gobuf) {
     24 	var inst uint32
     25 	if buf.pc&3 == 0 && buf.pc != 0 {
     26 		inst = *(*uint32)(unsafe.Pointer(buf.pc))
     27 		// section C3.2.6 Unconditional branch (immediate)
     28 		if inst>>26 == 0x05 {
     29 			buf.pc += uintptr(int32(inst<<6) >> 4)
     30 			return
     31 		}
     32 	}
     33 
     34 	print("runtime: pc=", hex(buf.pc), " ", hex(inst), "\n")
     35 	throw("runtime: misuse of rewindmorestack")
     36 }
     37