github.com/f-secure-foundry/tamago@v0.0.0-20220307101044-d73fcdd7f11b/arm/features.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
    11  
    12  // ARM processor feature registers
    13  const (
    14  	ID_PFR0_ARM_MASK     = 0x000f
    15  	ID_PFR0_THUMB_MASK   = 0x00f0
    16  	ID_PFR0_THUMBEE_MASK = 0x0f00
    17  	ID_PFR0_JAZELLE_MASK = 0xf000
    18  
    19  	ID_PFR1_PROGRAMMERS_MODEL_MASK = 0x0000f
    20  	ID_PFR1_SECURITY_MASK          = 0x000f0
    21  	ID_PFR1_M_PROFILE_MODEL_MASK   = 0x00f00
    22  	ID_PFR1_VIRTUALIZATION_MASK    = 0x0f000
    23  	ID_PFR1_GENERIC_TIMER_MASK     = 0xf0000
    24  )
    25  
    26  // defined in features.s
    27  func read_idpfr0() uint32
    28  func read_idpfr1() uint32
    29  
    30  func (cpu *CPU) initFeatures() {
    31  	idpfr0 := read_idpfr0()
    32  	idpfr1 := read_idpfr1()
    33  
    34  	cpu.arm = (idpfr0 & ID_PFR0_ARM_MASK) != 0
    35  	cpu.thumb = (idpfr0 & ID_PFR0_THUMB_MASK) != 0
    36  	cpu.thumbee = (idpfr0 & ID_PFR0_THUMBEE_MASK) != 0
    37  	cpu.jazelle = (idpfr0 & ID_PFR0_JAZELLE_MASK) != 0
    38  
    39  	cpu.programmersModel = (idpfr1 & ID_PFR1_PROGRAMMERS_MODEL_MASK) != 0
    40  	cpu.security = (idpfr1 & ID_PFR1_SECURITY_MASK) != 0
    41  	cpu.mProfileModel = (idpfr1 & ID_PFR1_M_PROFILE_MODEL_MASK) != 0
    42  	cpu.virtualization = (idpfr1 & ID_PFR1_VIRTUALIZATION_MASK) != 0
    43  	cpu.genericTimer = (idpfr1 & ID_PFR1_GENERIC_TIMER_MASK) != 0
    44  }