feat: implement llgo.stackSave
This commit is contained in:
26
_demo/c/stacksave/stacksave_amd64.go
Normal file
26
_demo/c/stacksave/stacksave_amd64.go
Normal file
@@ -0,0 +1,26 @@
|
||||
//go:build amd64
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
_ "unsafe"
|
||||
)
|
||||
|
||||
//go:linkname getsp llgo.stackSave
|
||||
func getsp() unsafe.Pointer
|
||||
|
||||
//go:linkname asmFull llgo.asm
|
||||
func asmFull(instruction string, regs map[string]any) uintptr { return 0 }
|
||||
|
||||
func main() {
|
||||
var spPtr uintptr
|
||||
|
||||
asmFull("movq sp, {{addr}}", map[string]any{
|
||||
"addr": unsafe.Pointer(&spPtr),
|
||||
})
|
||||
|
||||
if spPtr != uintptr(getsp()) {
|
||||
panic("invalid stack pointer")
|
||||
}
|
||||
}
|
||||
22
_demo/c/stacksave/stacksave_arm64.go
Normal file
22
_demo/c/stacksave/stacksave_arm64.go
Normal file
@@ -0,0 +1,22 @@
|
||||
//go:build arm64
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
_ "unsafe"
|
||||
)
|
||||
|
||||
//go:linkname getsp llgo.stackSave
|
||||
func getsp() unsafe.Pointer
|
||||
|
||||
//go:linkname asmFull llgo.asm
|
||||
func asmFull(instruction string, regs map[string]any) uintptr { return 0 }
|
||||
|
||||
func main() {
|
||||
sp := asmFull("mov {}, sp", nil)
|
||||
|
||||
if sp != uintptr(getsp()) {
|
||||
panic("invalid stack pointer")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user