github.com/f-secure-foundry/tamago@v0.0.0-20220307101044-d73fcdd7f11b/arm/arm.go (about) 1 // ARM processor support 2 // https://github.com/f-secure-foundry/tamago 3 // 4 // Copyright (c) F-Secure Corporation 5 // https://foundry.f-secure.com 6 // 7 // Use of this source code is governed by the license 8 // that can be found in the LICENSE file. 9 10 // Package arm provides support for ARM architecture specific operations. 11 // 12 // The following architectures/cores are supported/tested: 13 // * ARMv7-A / Cortex-A7 (single-core) 14 // 15 // This package is only meant to be used with `GOOS=tamago GOARCH=arm` as 16 // supported by the TamaGo framework for bare metal Go on ARM SoCs, see 17 // https://github.com/f-secure-foundry/tamago. 18 package arm 19 20 // ARM processor modes 21 // (Table B1-1, ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition). 22 const ( 23 USR_MODE = 0b10000 24 FIQ_MODE = 0b10001 25 IRQ_MODE = 0b10010 26 SVC_MODE = 0b10011 27 MON_MODE = 0b10110 28 ABT_MODE = 0b10111 29 HYP_MODE = 0b11010 30 UND_MODE = 0b11011 31 SYS_MODE = 0b11111 32 ) 33 34 // CPU instance 35 type CPU struct { 36 // instruction sets 37 arm bool 38 thumb bool 39 jazelle bool 40 thumbee bool 41 42 // extensions 43 programmersModel bool 44 security bool 45 mProfileModel bool 46 virtualization bool 47 genericTimer bool 48 49 // timer multiplier 50 TimerMultiplier int64 51 // timer offset in nanoseconds 52 TimerOffset int64 53 // timer function 54 TimerFn func() int64 55 } 56 57 // defined in arm.s 58 func read_cpsr() uint32 59 60 // Init performs initialization of an ARM core instance. 61 func (cpu *CPU) Init() { 62 cpu.initFeatures() 63 cpu.initVectorTable() 64 } 65 66 // Mode returns the processor mode. 67 func (cpu *CPU) Mode() int { 68 return int(read_cpsr() & 0x1f) 69 } 70 71 // ModeName returns the processor mode name. 72 func ModeName(mode int) string { 73 switch mode { 74 case USR_MODE: 75 return "USR" 76 case FIQ_MODE: 77 return "FIQ" 78 case IRQ_MODE: 79 return "IRQ" 80 case SVC_MODE: 81 return "SVC" 82 case MON_MODE: 83 return "MON" 84 case ABT_MODE: 85 return "ABT" 86 case HYP_MODE: 87 return "HYP" 88 case UND_MODE: 89 return "UND" 90 case SYS_MODE: 91 return "SYS" 92 } 93 94 return "Unknown" 95 }