github.com/f-secure-foundry/tamago@v0.0.0-20220307101044-d73fcdd7f11b/soc/bcm2835/bcm2835.go (about) 1 // BCM2835 SoC support 2 // https://github.com/f-secure-foundry/tamago 3 // 4 // Copyright (c) the bcm2835 package authors 5 // 6 // Use of this source code is governed by the license 7 // that can be found in the LICENSE file. 8 9 // Package bcm2835 provides support to Go bare metal unikernels written using 10 // the TamaGo framework on BCM2835/BCM2836 SoCs. 11 // 12 // This package is only meant to be used with `GOOS=tamago GOARCH=arm` as 13 // supported by the TamaGo framework for bare metal Go on ARM SoCs, see 14 // https://github.com/f-secure-foundry/tamago. 15 package bcm2835 16 17 import ( 18 _ "unsafe" 19 20 "github.com/f-secure-foundry/tamago/arm" 21 ) 22 23 // nanos - should be same value as arm/timer.go refFreq 24 const refFreq int64 = 1000000000 25 26 // DRAM_FLAG_NOCACHE disables caching by setting to high bits 27 const DRAM_FLAG_NOCACHE = 0xC0000000 28 29 // peripheralBase represents the (remapped) peripheral base address, it varies 30 // by model and it is therefore initialized (see Init) by individual board 31 // packages. 32 var peripheralBase uint32 33 34 // ARM processor instance 35 var ARM = &arm.CPU{} 36 37 //go:linkname ramStackOffset runtime.ramStackOffset 38 var ramStackOffset uint32 = 0x100000 // 1 MB 39 40 //go:linkname nanotime1 runtime.nanotime1 41 func nanotime1() int64 { 42 return read_systimer() * ARM.TimerMultiplier + ARM.TimerOffset 43 } 44 45 // Init takes care of the lower level SoC initialization triggered early in 46 // runtime setup. 47 func Init(base uint32) { 48 peripheralBase = base 49 50 ARM.Init() 51 ARM.EnableVFP() 52 53 // required when booting in SDP mode 54 ARM.EnableSMP() 55 56 // MMU initialization is required to take advantage of data cache 57 ARM.InitMMU() 58 ARM.EnableCache() 59 60 ARM.TimerMultiplier = refFreq / SysTimerFreq 61 ARM.TimerFn = read_systimer 62 63 // initialize serial console 64 MiniUART.Init() 65 } 66 67 // PeripheralAddress returns the absolute address for a peripheral. The Pi 68 // boards map 'bus addresses' to board specific base addresses but with 69 // consistent layout otherwise. 70 func PeripheralAddress(offset uint32) uint32 { 71 return peripheralBase + offset 72 }