github.com/jspc/eggos@v0.5.1-0.20221028160421-556c75c878a5/kernel/sys/sys.go (about) 1 package sys 2 3 import "unsafe" 4 5 const PtrSize = 4 << (^uintptr(0) >> 63) // unsafe.Sizeof(uintptr(0)) but an ideal const 6 7 const PageSize = 4 << 10 8 9 //go:nosplit 10 func Outb(port uint16, data byte) 11 12 //go:nosplit 13 func Inb(port uint16) byte 14 15 //go:nosplit 16 func Outl(port uint16, data uint32) 17 18 //go:nosplit 19 func Inl(port uint16) uint32 20 21 //go:nosplit 22 func Cli() 23 24 //go:nosplit 25 func Sti() 26 27 //go:nosplit 28 func Hlt() 29 30 //go:nosplit 31 func Cr2() uintptr 32 33 //go:nosplit 34 func Flags() uintptr 35 36 //go:nosplit 37 func UnsafeBuffer(p uintptr, n int) []byte { 38 return (*[1 << 30]byte)(unsafe.Pointer(p))[:n] 39 } 40 41 //go:nosplit 42 func Memclr(p uintptr, n int) { 43 s := (*(*[1 << 30]byte)(unsafe.Pointer(p)))[:n] 44 // the compiler will emit runtime.memclrNoHeapPointers 45 for i := range s { 46 s[i] = 0 47 } 48 } 49 50 // funcPC returns the entry PC of the function f. 51 // It assumes that f is a func value. Otherwise the behavior is undefined. 52 // CAREFUL: In programs with plugins, funcPC can return different values 53 // for the same function (because there are actually multiple copies of 54 // the same function in the address space). To be safe, don't use the 55 // results of this function in any == expression. It is only safe to 56 // use the result as an address at which to start executing code. 57 //go:nosplit 58 func FuncPC(f interface{}) uintptr { 59 return **(**uintptr)(unsafe.Pointer((uintptr(unsafe.Pointer(&f)) + PtrSize))) 60 } 61 62 //go:nosplit 63 func Fxsave(addr uintptr) 64 65 //go:nosplit 66 func SetAX(val uintptr) 67 68 //go:nosplit 69 func CS() uintptr