ARM coprocessor register function introduction

Overview

In ARM-based embedded application systems, the operation of the storage system is usually completed by the coprocessor CP15 . CP15 contains 16 32-bit registers, which are numbered from 0 to 15. The instructions for accessing CP15 registers are mainly MCR and MRC instructions.

  • MRC : Data transfer instruction from coprocessor register to ARM processor register (read coprocessor register).
  • MCR : Data transfer instruction from ARM processor register to coprocessor register (write to coprocessor register).

1. Instruction format

MRC{cond} p15, <Opcode_1>, <Rd>, <CRn>, <CRm>, <Opcode_2>

MCR{cond} p15, <Opcode_1>, <Rd>, <CRn>, <CRm>, <Opcode_2>

cond : The condition code for the execution of the instruction. When cond is ignored, the instruction is executed unconditionally.
Opcode_1 : the specific opcode of the coprocessor. For CP15 registers, opcode1=0
Rd : the ARM register as the source register, its value will be transferred to the coprocessor register, or the value of the coprocessor register will be transferred to In this register, usually R0
CRn : the coprocessor register as the target register, its number is C~C15.
CRm : additional destination register or source operand register in the coprocessor. If you do not need to set additional information, set CRm to c0, otherwise the result is unknown.
Opcode_2 : optional coprocessor specific opcode. (Used to distinguish different physical registers of the same number, when no additional information is required, specify 0)

(1) Assembly syntax means:

mrc p15, 0, r0, c1, c0, 0             //将 CP15 的寄存器 C1 的值读到 r0 中 

mcr p15, 0, r0, c7, c7, 0             //关闭ICaches和DCaches 

mcr p15, 0, r0, c8, c7, 0             //使无效整个数据TLB和指令TLB

(2) C language syntax means:

__asm__("mrc p15, 0, r1, c1, c0, 0\n"      //使用__asm__  可以在C函数中执行汇编语句
        "orr r1, r1, #0xc0000000\n"                                         
        "mcr p15, 0, r1, c1, c0, 0\n"  
        :::"r1"                             //:::"r1" 向GCC声明:我对r1作了改动
);

2. Introduction to registers in CP15

Register number Basic role Role in MMU Role in PU
0 ID code (read only) ID encoding and cache type
1 Control bit (read and write) Various control bits
2 Storage protection and control Address translation table base address Cachability control bits
3 Storage protection and control Domain access control bit Bufferablity control bit
4 Storage protection and control Keep Keep
5 Storage protection and control Memory failure state Access control bit
6 Storage protection and control Memory failure address Protected area control
7 Cache and write cache Cache and write cache control
8 Storage protection and control TLB control Keep
9 Cache and write cache Cache lock
10 Storage protection and control TLB lock Keep
11 Keep
12 Keep
13 Process identifier Process identifier
14 Keep
15 Varies for different designs Varies for different designs Varies for different designs

(1) CP15 register C0

The register C0 in CP15 corresponds to two identifier registers. The register instruction to access CP15 specifies which specific physical register to access. The corresponding relationship with the two identifier registers is as follows:

opcode2 encoding Corresponding identification symbol register
0b000 Main identifier register
0b001 cache type identifier register
other Keep

A. Main identifier register

  • The encoding format of the main identifier is different for different ARM processor versions. For processors after AMR7, the main identifier encoding format is as follows:

    • Instruction format :, MRC P15,0,R0,C0,C0,0read the content of the main identifier register to the AMR register R0.
  • The detailed meaning of each part of the code is shown in the following table:
30**~24** 23**~20** 19**~16** 15**~4** 3**~0**
Determined by the manufacturer Product sub-number ARM system version number Product main number Processor version number

B , Cache type identifier register

  • The encoding format of the cache type identifier register in the ARM processor is as follows:
    • Instruction format:,MRC P15,0,R0,C0,C0,1 read the contents of the cache type identifier register into the AMR register R0
  • The meaning of each part of the field is as follows:
31~29 28~25 24 23~12 11~0
000 Attribute field S Data cache related attributes Instruction cache related attributes
  • The detailed meaning of each part of the code is shown in the following table:
Rank meaning
Place [28:25] Mainly used to define some attributes for write-back type cache
Rank [24] Define whether the data cache and instruction cache in the system are separate or unified: 0: The system data cache and instruction cache are unified 1: The system data cache and instruction cache are separate
Place [23:12] Define the relevant attributes of the data cache, if bit [24] is 0, this field defines the attributes of the entire cache
Place [31:24] Define the relevant attributes of the instruction cache, if bit [24] is 0, this field defines the attributes of the entire cache

The meaning of the control field bits [28: 25] : mainly used to define some attributes of the write-back type of cache,

​ The control field bits of the cache type identifier register [28: 25].

coding cache type Cache content removal method Cache content locking method
0b000 Write-through type No content removal required Content lock is not supported
0b0001 Write back type Data block read Content lock is not supported
0b0010 Write back type Defined by register C7 Content lock is not supported
0b0110 Write back type Defined by register C7 Support format A
0b0111 Write back type Defined by register C7 Support format B

控制字段位 [23 12] 及控制字段位 [11 0] 含义 :[23:12]用于定义DCache的属性,[11: 0]用于定义ICache的属性。编码格式如下:

11~9 8~6 5~3 2 1~0
000 cache 容量 cache 相联特性 M 块大小

其中bits[1:0]含义如下:

编 码 cache 块大小
0b00 2 个 字( 8 字节)
0b01 4 个 字( 16 字节)
0b10 8 个 字( 32 字节)
0b11 16 个 字( 64 字节)

其中bits[5:3]含义如下:

编 码 M=0 时含义 M=1 时含义
0b000 1 路 相联(直接映射) 没有 cache
0b001 2 路 相联 3 路 相联
0b010 4 路 相联 6 路 相联
0b011 8 路 相联 12 路 相联
0b100 16 路 相联 24 路 相联
0b101 32 路 相联 48 路 相联
0b110 64 路 相联 96 路 相联
0b111 128 路相联 192 路相联

其中bits[8:6]含义如下:

编 码 M=0 时含义 M=1**时含义**
0b000 0.5KB 0.75 KB
0b001 1 KB 1.5 KB
0b010 2 KB 3 KB
0b011 4 KB 6 KB
0b100 8 KB 12 KB
0b101 16 KB 24 KB
0b110 32 KB 48 KB
0b111 64 KB 96 KB

(2) CP15 的寄存器 C1

CP15中的寄存器C1是一个控制寄存器,它包括以下控制功能:

  • 禁止或使能MMU以及其他与存储系统相关的功能
  • 配置存储系统以及ARM处理器中的相关部分的工作

指令如下:
mrc p15, 0, r0, c1, c0{, 0},将 CP15 的寄存器 C1 的值读到 r0 中
mcr p15, 0, r0, c1, c0{, 0},将 r0 的值写到 CP15 的寄存器 C1 中

CP15 中的寄存器 C1 的编码格式及含义说明如下:

C1中的控制位 含义
M(bit[0]) 0 :禁止 MMU 或者 PU <br />1 :使能 MMU 或者 PU 如果系统中没有MMU及PU,读取时该位返回0,写入时忽略该位。
A(bit[1]) 0 :禁止地址对齐检查<br />1 :使能地址对齐检查
C(bit[2]) 当数据cache和指令cache分开时,本控制位禁止/使能数据cache。当数据cache和指令cache统一时,该控制位禁止/使能整个cache。 <br />0 :禁止数据 / 整个 cache <br />1 :使能数据 / 整个 cache <br />如果系统中不含cache,读取时该位返回0.写入时忽略 当系统中不能禁止cache 时,读取时返回1.写入时忽略
W(bit[3]) 0 :禁止写缓冲 <br />1 :使能写缓冲 <br />如果系统中不含写缓冲时,读取时该位返回0.写入时忽略 当系统中不能禁止写缓冲时,读取时返回1.写入时忽略
P(bit[4]) 对于向前兼容26位地址的ARM处理器,本控制位控制PROG32控制信号 0 :异常中断处理程序进入 32 位地址模式 1 :异常中断处理程序进入26 位地址模式 如果本系统中不支持向前兼容26位地址,读取该位时返回1,写入时忽略
D(bit[5]) 对于向前兼容26位地址的ARM处理器,本控制位控制DATA32控制信号 <br />0 :禁止 26 位地址异常检查 <br />1 :使能 26 位地址异常检查 <br />如果本系统中不支持向前兼容26位地址,读取该位时返回1,写入时忽略
L(bit[6]) 对于ARMv3及以前的版本,本控制位可以控制处理器的中止模型 <br />0 :选择早期中止模型 <br />1 :选择后期中止模型
B(bit[7]) 对于存储系统同时支持big-endian和little-endian的ARM系统,本控制位配置系统的存储模式 <br />0 : little endian <br />1 : big endian <br />对于只支持little-endian的系统,读取时该位返回0,写入时忽略 <br />对于只支持big-endian的系统,读取时该位返回1,写入时忽略
S(bit[8]) 在基于 MMU 的存储系统中,本位用作系统保护
R(bit[9]) 在基于 MMU 的存储系统中,本位用作 ROM 保护
F(bit[10]) 由生产商定义
Z(bit[11]) 对于支持跳转预测的ARM系统,本控制位禁止/使能跳转预测功能 <br />0 :禁止跳转预测功能 <br />1 :使能跳转预测功能<br /> 对于不支持跳转预测的ARM系统,读取该位时返回0,写入时忽略
I(bit[12]) 当数据cache和指令cache是分开的,本控制位禁止/使能指令cache <br />0 :禁止指令 cache <br />1 :使能指令 cache <br />如果系统中使用统一的指令cache和数据cache或者系统中不含cache,读取该位时返回0,写入时忽略。当系统中的指令cache不能禁止时,读取时该位返回1,写入时忽略
V(bit[13]) 对于支持高端异常向量表的系统,本控制位控制向量表的位置 <br />0 :选择低端异常中断向量 0x0~0x1c <br />1 :选择高端异常中断向量0xffff0000~ 0xffff001c <br />对于不支持高端异常向量表的系统,读取时该位返回0,写入时忽略
PR(bit[14]) 如果系统中的cache的淘汰算法可以选择的话,本控制位选择淘汰算法 <br />0 :常规的 cache 淘汰算法,如随机淘汰 <br />1 :预测性淘汰算法,如round-robin 淘汰算法 <br />如果系统中cache的淘汰算法不可选择,写入该位时忽略。读取该位时,根据其淘汰算法是否可以比较简单地预测最坏情况返回0或者1
L4(bit[15]) 对于ARM版本5及以上的版本,本控制位可以提供兼容以前的ARM版本的功能 <br />0 :保持 ARMv5 以上版本的正常功能 <br />1 :将 ARMv5 以上版本与以前版本处理器 兼容,不根据跳转地址的 bit[0] 进行 ARM 指令和 Thumb 状态切换: bit[0] 等于 0 表示 ARM 指令,等于 1 表示 Thumb 指令
Bits[31:16]) 这些位保留将来使用,应为UNP/SBZP

(3)CP15的寄存器C2

C2寄存器的别名:Translation table base (TTB) register
C2寄存器用来保存页表的基地址,即一级映射描述符表的基地址。其编码格如下所示:

[31:0]
一级映射描述符表的基地址(物理地址)

(4) CP15 的寄存器 C3

CP15 中的寄存器 C3 定义了 ARM 处理器的 16 个域的访问权限。

在 CP15的C3寄存器中,划分了 16个域,每个区域由两位构成,这两位说明了当前内存的检查权限:

00:当前级别下,该内存区域不允许被访问,任何的访问都会引起一个domain fault,这时 AP位无效 ;

01:当前级别下,该内存区域的访问必须配合该内存区域的段描述符中AP位进行权检查 ;

10:保留状态(我们最好不要填写该值,以免引起不能确定的问题) ;

11:当前级别下,对该内存区域的访问都不进行权限检查, 这时 AP位无效 。

所以只有当相应域的编码为 01 时,才会根据 AP位 和协处理器CP15中的C1寄存器的R,S位进行权限检查。

(5) CP15 的寄存器 C5

CP15 中的寄存器 C5 是失效状态寄存器,分为指令状态失效和数据状态失效。

MRC p15, 0, , c5, c0, 0 :访问数据失效状态寄存器

MRC p15, 0, , c5, c0, 1 :访问指令状态失效寄存器
编码格式如下所示:

[31:9] 8 [7:4] [3:0]
UNP/SBZP 0 域标识 状态标识

其中,域标识bit[7:4]表示存放引起存储访问失效的存储访问所属的域。状态标识 bit[3:0] 表示放引起存储访问失效的存储访问类型,该字段含义如下表所示(优先级由上到下递减)。

(6) CP15的寄存器C6

CP15 中的寄存器 C6 是失效地址寄存器,其中保存了引起存储访问失效的地址,分为数据失效地址寄存器和指令失效地址寄存器。

MRC p15, 0, , c6, c0, 0 :访问数据失效地址寄存器

MRC p15, 0, , c6, c0, 2 :访问指令失效地址寄存器
编码格式如下所示:

[31:0]
失效地址(虚拟地址)

(7) CP15的寄存器C7

CP15 的 C7 寄存器用来控制 cache 和写缓存,它是一个只写寄存器,读操作将产生不可预知的后果。

访问 CP15 的 C7 寄存器的指令格式为:mcr p15, 0, Rd, CRn, CRm, opcode_2 。具体含义如下表所示(表中的数据是指Rd中的数据)

(8) CP15的寄存器C8

系统协处理器CP15的寄存器C8就是清除TLB内容的相关操作。它是一个只写的寄存器。

MCR p15,0,Rd,c8,CRm,opcode_2

Rd中为要写入C8寄存器的内容,CRm和opcode_2的不同组合决定指令执行的不同操作。

(9) CP15的寄存器C12

CP15寄存器C12用来设置异常向量基地址,其编码格式如下所示: MCR p15, 0, , c12, c0, 0,Rd中存放要修改的异常向量基地址

[31:5] [4:0]
异常向量基地址 Reserve

注:只有ARM11和cortex-a 可以任意修改异常向量基地址。arm7,ARM9,ARM10只可以在0地址或0xffff0000中

(10) CP15的寄存器C13

CP15中的寄存器C13用于快速上下文切换。其编码格式如下所示

[31:25] [24:0]
PID

其中, 在读操作时,结果中位[31::25]返回PID,其他位 的数值是不可以预知的。写操作将设置PID的值。当PID的值为0时,MVA = VA | (0(PID)<<25),MVA=VA,相当于禁止了FCSE。系统复位后PID即为0。当PID的值不为0时,相当于使能了FCSE。

参考链接:

协处理器CP15介绍—MCR/MRC指令(6)

Guess you like

Origin blog.51cto.com/14592069/2591169