// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build amd64 && (darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris)

package runtime

import (
	
	
	
)

func ( *sigctxt) {
	print("rax    ", hex(.rax()), "\n")
	print("rbx    ", hex(.rbx()), "\n")
	print("rcx    ", hex(.rcx()), "\n")
	print("rdx    ", hex(.rdx()), "\n")
	print("rdi    ", hex(.rdi()), "\n")
	print("rsi    ", hex(.rsi()), "\n")
	print("rbp    ", hex(.rbp()), "\n")
	print("rsp    ", hex(.rsp()), "\n")
	print("r8     ", hex(.r8()), "\n")
	print("r9     ", hex(.r9()), "\n")
	print("r10    ", hex(.r10()), "\n")
	print("r11    ", hex(.r11()), "\n")
	print("r12    ", hex(.r12()), "\n")
	print("r13    ", hex(.r13()), "\n")
	print("r14    ", hex(.r14()), "\n")
	print("r15    ", hex(.r15()), "\n")
	print("rip    ", hex(.rip()), "\n")
	print("rflags ", hex(.rflags()), "\n")
	print("cs     ", hex(.cs()), "\n")
	print("fs     ", hex(.fs()), "\n")
	print("gs     ", hex(.gs()), "\n")
}

//go:nosplit
//go:nowritebarrierrec
func ( *sigctxt) () uintptr { return uintptr(.rip()) }

func ( *sigctxt) ( uint64) { .set_rip() }
func ( *sigctxt) () uintptr    { return uintptr(.rsp()) }
func ( *sigctxt) () uintptr    { return 0 }
func ( *sigctxt) () uintptr    { return uintptr(.sigaddr()) }

// preparePanic sets up the stack to look like a call to sigpanic.
func ( *sigctxt) ( uint32,  *g) {
	// Work around Leopard bug that doesn't set FPE_INTDIV.
	// Look at instruction to see if it is a divide.
	// Not necessary in Snow Leopard (si_code will be != 0).
	if GOOS == "darwin" &&  == _SIGFPE && .sigcode0 == 0 {
		 := (*[4]byte)(unsafe.Pointer(.sigpc))
		 := 0
		if []&0xF0 == 0x40 { // 64-bit REX prefix
			++
		} else if [] == 0x66 { // 16-bit instruction prefix
			++
		}
		if [] == 0xF6 || [] == 0xF7 {
			.sigcode0 = _FPE_INTDIV
		}
	}

	 := uintptr(.rip())
	 := uintptr(.rsp())

	// In case we are panicking from external code, we need to initialize
	// Go special registers. We inject sigpanic0 (instead of sigpanic),
	// which takes care of that.
	if shouldPushSigpanic(, , *(*uintptr)(unsafe.Pointer())) {
		.pushCall(abi.FuncPCABI0(sigpanic0), )
	} else {
		// Not safe to push the call. Just clobber the frame.
		.set_rip(uint64(abi.FuncPCABI0(sigpanic0)))
	}
}

func ( *sigctxt) (,  uintptr) {
	// Make it look like we called target at resumePC.
	 := uintptr(.rsp())
	 -= goarch.PtrSize
	*(*uintptr)(unsafe.Pointer()) = 
	.set_rsp(uint64())
	.set_rip(uint64())
}