关于ARM9协处理器CP15及MCR和MRC指令
(2011-03-26 08:53:47)转载
标签: 杂谈 |
关于ARM9协处理器CP15及MCR和MRC指令
http://6xudonghai.blog.163.com/blog/static/336406292008724103317304
在基于ARM的嵌入式应用系统中,存储系统通常是通过系统控制协处理器CP15完成的。CP15包含16个32位的寄存器,其编号为0~15。
访问CP15寄存器的指令
MCR
MRC
MCR指令和MRC指令只能在处理器模式为系统模式时执行,在用户模式下执行MCR指令和MRC指令将会触发未定义指令的异常中断。
MCR指令
MCR指令将ARM处理器的寄存器中的数据传送到协处理器寄存器中。如果协处理器不能成功地执行该操作,将产生未定义的指令异常中断。
指令语法格式
MCR{<cond>} <p>,< opcode_1>,<Rd>,<CRn>,<CRm>{,<opcode_2>}
MCR{<cond>} p15,0,<Rd>,<CRn>,<CRm>{,<opcode_2>}
其中,<cond>为指令执行的条件码。当<cond>忽略时指令为无条件执行。
< opcode_1>为协处理器将执行的操作的操作码。对于CP15协处理器来说,< opcode_1>永远为0b000,当< opcode_1>不为0b000时,该指令操作结果不可预知。
<Rd>作为源寄存器的ARM寄存器,其值将被传送到协处理器寄存器中。
<CRn>作为目标寄存器的协处理器寄存器,其编号可能是C0,C1,…,C15。
<CRm>和<opcode_2>两者组合决定对协处理器寄存器进行所需要的操作,如果没有指定,则将为<CRm>为C0,opcode_2为0,否则可能导致不可预知的结果。
The CRm field and opcode_2 field are used to specify a particular action when addressing registers.The opcode_1, opcode_2 and CRm fields should be zero, except when the values specified are used to select the desired operations, in all instructions which access CP15. Using other values will result in unpredictable behavior. Attempting to read from a non-readable register, or writing to a non-writable register will cause unpredictable results.
使用示例
下面的指令从ARM寄存器R4中中将数据传送到协处理器CP15的寄存器C1中。其中R4为ARM寄存器,存放源操作数,C1、C0为协处理器寄存器,为目标寄存器,opcode_1为0,opcode_2为0。
MCR
MRC指令
MRC指令将协处理器的寄存器中的数值传送到ARM处理器的寄存器中、如果协处理器不能成功地执行该操作,将产生未定义的指令异常中断。
指令语法格式
MRC{<cond>} <p>,< opcode_1>,<Rd>,<CRn>,<CRm>{,<opcode_2>}
MRC{<cond>} p15,0,<Rd>,<CRn>,<CRm>{,<opcode_2>}
参数用法同MCR指令
CP15中的寄存器介绍
Register(寄存器) |
Read |
Write |
|
C0 |
ID Code (1) |
Unpredictable |
|
C0 |
Catch type(1) |
Unpredictable |
|
C1 |
Control |
Control |
|
C2 |
Translation table base |
Translation table base |
|
C3 |
Domain access control |
Domain access control |
|
C4 |
Unpredictable |
Unpredictable |
|
C5 |
Fault status(2) |
Fault status (2) |
|
C6 |
Fault address |
Fault address |
|
C7 |
Unpredictable |
Cache operations |
|
C8 |
Unpredictable |
TLB operations |
|
C9 |
Cache lockdown(2) |
Cache lockdown (2) |
|
C10 |
TLB lock down(2) |
TLB lock down(2) |
|
C11 |
Unpredictable |
Unpredictable |
|
C12 |
Unpredictable |
Unpredictable |
|
C13 |
Process ID |
Process ID |
|
C14 |
Unpredictable |
Unpredictable |
|
C15 |
Test configuration |
Test configuration |
|
Notes:
1.
2.
寄存器0:ID Code Register
The ID code register is accessed by reading CP15 register 0 with the opcode_2 field set to any value other than 1(the CRm field should be zero when reading). For example:
MRC
ID Code内容如下:
Register bits |
Function |
Value |
[31:24] |
Implementor |
0x41(‘A’,表示Arm公司) |
[23:20] |
Specification revision |
0x1 |
[19:16] |
Architecture version(4T) |
0x2(ARM体系版本4T) |
[15:4] |
Part number |
0x920 |
[3:0] |
Layout revision |
0x0 |
寄存器0:Cache type register
This is a read-only register which contains information about the size and architecture of the caches, allowing operating systems to establish how to perform such operations as cache cleaning and lockdown.
这个只读寄存器包含了高速缓存的大小和类型。
The cache type register is accessed by reading CP15 register 0 with the opcode_2 field set to 1.for example:
MRC
The format of cache type register (寄存器的数据格式如下)
Register bits |
Function |
Value |
[31:29] |
Reserved |
000 |
[28:25] |
Cache type (缓存类型) |
0110 |
[24] |
Harvard/Unified |
1(defines Harvard cache) |
[23:21] |
Reserved |
000 |
[20:18] |
Data Cache size(数据缓存大小) |
101(defines 16KB) |
[17:15] |
Data Cache associativity |
110(defines 64 way) |
[14] |
Reserved |
0 |
[13:12] |
Data Cache words per line |
10(defines 8 words per line) |
[11:9] |
Reserved |
000 |
[ 8:6] |
Instruction Cache size(指令缓存大小) |
101(defines 16KB) |
[5:3] |
Instruction Cache Associativity |
110(defines 64 way) |
[2] |
Reserved |
0 |
[1:0] |
Instruction Cache per line |
10(defines 8 words per line) |
寄存器1:Control register
对该寄存器读写指令如下:
MRC
MCR
该寄存器功能如下表
Registe bits |
Name |
Function |
Value |
31 |
iA bit |
Asynchronous clock select |