github.com/usbarmory/GoTEE@v0.0.0-20240405084336-c52770d9fcdb/applet/init_arm.go (about) 1 // Copyright (c) WithSecure Corporation 2 // https://foundry.withsecure.com 3 // 4 // Use of this source code is governed by the license 5 // that can be found in the LICENSE file. 6 7 // Package applet provides user mode initialization for bare metal Go 8 // unikernels written using the TamaGo framework. 9 // 10 // The package supports trusted applet execution under a GoTEE compatible 11 // supervisor, linking essential runtime functions with required system calls. 12 // 13 // This package is only meant to be used with `GOOS=tamago GOARCH=arm` as 14 // supported by the TamaGo framework for bare metal Go on ARM SoCs, see 15 // https://github.com/usbarmory/tamago. 16 package applet 17 18 import ( 19 _ "unsafe" 20 21 "github.com/usbarmory/tamago/arm" 22 ) 23 24 var ARM = &arm.CPU{} 25 26 func init() { 27 if ARM.Mode() != arm.USR_MODE { 28 panic("unexpected processor mode") 29 } 30 } 31 32 //go:linkname nanotime1 runtime.nanotime1 33 func nanotime1() int64 { 34 // TamaGo allows PL0 access to generic counters, so an efficient 35 // implementation of nanotime1 in user mode simply mirrors what TamaGo 36 // does natively: 37 return int64(ARM.TimerFn()*ARM.TimerMultiplier + ARM.TimerOffset) 38 39 // A less efficient version, in case counters are not accessible, is to 40 // make a supervisor request: 41 // return syscall.Nanotime() 42 } 43 44 //go:linkname hwinit runtime.hwinit 45 func hwinit() { 46 ARM.InitGenericTimers(0, 0) 47 }