github.com/aloncn/graphics-go@v0.0.1/src/runtime/sys_mips64x.go (about)

     1  // Copyright 2015 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 mips64 mips64le
     6  
     7  package runtime
     8  
     9  import "unsafe"
    10  
    11  // adjust Gobuf as if it executed a call to fn with context ctxt
    12  // and then did an immediate Gosave.
    13  func gostartcall(buf *gobuf, fn, ctxt unsafe.Pointer) {
    14  	if buf.lr != 0 {
    15  		throw("invalid use of gostartcall")
    16  	}
    17  	buf.lr = buf.pc
    18  	buf.pc = uintptr(fn)
    19  	buf.ctxt = ctxt
    20  }
    21  
    22  // Called to rewind context saved during morestack back to beginning of function.
    23  // To help us, the linker emits a jmp back to the beginning right after the
    24  // call to morestack. We just have to decode and apply that jump.
    25  func rewindmorestack(buf *gobuf) {
    26  	var inst uint32
    27  	if buf.pc&3 == 0 && buf.pc != 0 {
    28  		inst = *(*uint32)(unsafe.Pointer(buf.pc))
    29  		if inst>>26 == 2 { // JMP addr
    30  			//print("runtime: rewind pc=", hex(buf.pc), " to pc=", hex(buf.pc &^ uintptr(1<<28-1) | uintptr((inst&^0xfc000000)<<2)), "\n");
    31  			buf.pc &^= 1<<28 - 1
    32  			buf.pc |= uintptr((inst &^ 0xfc000000) << 2)
    33  			return
    34  		}
    35  		if inst>>16 == 0x1000 { // BEQ	R0, R0, offset
    36  			//print("runtime: rewind pc=", hex(buf.pc), " to pc=", hex(buf.pc + uintptr(int32(int16(inst&0xffff))<<2 + 4)), "\n");
    37  			buf.pc += uintptr(int32(int16(inst&0xffff))<<2 + 4)
    38  			return
    39  		}
    40  	}
    41  	print("runtime: pc=", hex(buf.pc), " ", hex(inst), "\n")
    42  	throw("runtime: misuse of rewindmorestack")
    43  }