github.com/usbarmory/GoTEE@v0.0.0-20240405084336-c52770d9fcdb/applet/init_riscv64.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 supervised 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=riscv64` as 14 // supported by the TamaGo framework for bare metal Go on RISC-V SoCs, see 15 // https://github.com/usbarmory/tamago. 16 package applet 17 18 import ( 19 _ "unsafe" 20 21 "github.com/usbarmory/tamago/soc/sifive/clint" 22 ) 23 24 var CLINT = &clint.CLINT{ 25 Base: 0x2000000, 26 RTCCLK: 1000000, 27 } 28 29 //go:linkname nanotime1 runtime.nanotime1 30 func nanotime1() int64 { 31 // Direct access to timers is allowed under supervised mode, so an 32 // efficient implementation of nanotime1 in supervised mode simply 33 // mirrors what TamaGo does natively: 34 return CLINT.Nanotime() 35 36 // A less efficient version, in case tiemrs are not accessible, is to 37 // make a supervisor request: 38 // return syscall.Nanotime() 39 } 40 41 //go:linkname hwinit runtime.hwinit 42 func hwinit() { 43 // no initialization required in supervised mode 44 }