github.com/letsencrypt/go@v0.0.0-20160714163537-4054769a31f6/src/runtime/sys_s390x.go (about) 1 // Copyright 2016 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 uint64 25 if buf.pc&1 == 0 && buf.pc != 0 { 26 inst = *(*uint64)(unsafe.Pointer(buf.pc)) 27 switch inst >> 48 { 28 case 0xa7f4: // BRC (branch relative on condition) instruction. 29 inst >>= 32 30 inst &= 0xFFFF 31 offset := int64(int16(inst)) 32 offset <<= 1 33 buf.pc += uintptr(offset) 34 return 35 case 0xc0f4: // BRCL (branch relative on condition long) instruction. 36 inst >>= 16 37 inst = inst & 0xFFFFFFFF 38 inst = (inst << 1) & 0xFFFFFFFF 39 buf.pc += uintptr(int32(inst)) 40 return 41 } 42 } 43 print("runtime: pc=", hex(buf.pc), " ", hex(inst), "\n") 44 throw("runtime: misuse of rewindmorestack") 45 }