http://simengru.blog.163.com/blog/static/54386860201010301111898/
在基于ARM的嵌入式應用系統中,存儲系統通常是通過系統控制協處理器CP15完成的。CP15包含16個32位的寄存器,其編号為0~15。
通路CP15寄存器的指令
MCR ARM寄存器到協處理器寄存器的資料傳送
MRC 協處理器寄存器到ARM寄存器的資料傳送
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 p15, 0, R4, C1, C0, 0
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. Register location 0 provides access to more than one register. The register accessed depends upon values of the opcode_2 field. See the register description for details.
2. Separate register for instruction and data .See the register description for details.
寄存器0:ID Code Register
This is a read-only register which returns a 32-bit device ID code
這是一個隻讀寄存器,它存放微處理器的辨別碼。
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 p15, 0, Rd, C0, C0, 0
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 p15, 0, Rd, C0, C0, 1; returns cache details
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 | |
[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 | |
[1:0] | Instruction Cache per line | 10(defines 8 words per line) |
寄存器1:Control register
對該寄存器讀寫指令如下:
MRC p15, 0, Rd, c1, c0, 0 ; read control register
MCR p15, 0, Rd, c1, c0, 0 ; write control register
該寄存器功能如下表
Registe bits | Name | Function | Value |
31 | iA bit | Asynchronous clock select | 見時鐘模式表 |
30 | nF bit | notFastBus select | 見 時鐘模式表 |
29:15 | - | Reserved | Read = Unpredictable Write = should be zero |
14 | RR bit | Round robin replacement | 0 = Random replacement 1 = Round robin replacement |
13 | V bit | Base location of exception register(異常寄存器基位址) | 0 = Low address = 0x0000 0000 1 = High address = 0xFFFF 0000 |
12 | I bit | Instruction cache enable | 0 = Instruction cache disable 1 = Instruction cache enable |
11:10 | - | Reserved | Read = 00 Write = 00 |
9 | R bit | ROM protection | 見圖1 |
8 | S bit | System protection | 見圖1 |
7 | B bit | Big-endian/little-endian | 0 = Little-endian operation 1 = Big-endian operation |
6:3 | - | Reserved | Read = 1111 Write = 1111 |
2 | C bit | Data cache enable | 0 = data cache disable 1 = data cache enable |
1 | A bit | Alignment fault enable | Data address alignment fault checking (位址對齊檢查) 0 = 禁用位址對齊檢查功能 1 = 使能位址對齊檢查功能 |
M bit | MMU enable | 0 = MMU disable 1 = MMU enable |
時鐘模式表
Clocking mode(時鐘模式) | iA | nF |
Fastbus mode (快速總線模式) | ||
Reserved | 1 | |
Synchronous (同步模式) | 1 | |
Asynchronous (異步模式) | 1 | 1 |

圖1
寄存器2:Translation Table Base(TTB) Register
Register bits | Function |
31:14 | Pointer to first level translation table base . Read /write |
13:0 | Reserved Read = Unpredictable Write = Should be zero |
通路C2寄存器指令如下:
MRC p15, 0, Rd, C2, C0, 0 ; Read TTB register
MCR p15, 0, Rd, C2, C0, 0 ; Write TTB register
該寄存器存放第一級轉換表基位址。寫入時,位[13:0]必須為0,讀出時,位[13:0]的值不可預知。
寄存器3:Domain Access Control Register
寄存器3是可讀寫的域通路控制寄存器,分為16組,每組占用2個位
通路該寄存器的指令如下:
MRC p15, 0, Rd, C3, C0, 0 ; Read domain 15:0 access permissions
MCR p15, 0, Rd, C3, C0, 0 ; Read domain 15:0 access permissions
Interpreting Access Control Bits in Domain Access Control Register
寄存器4:保留
對該寄存器的讀寫會産生不可預料的結果。
寄存器5:Fault Status Register
寄存器6:Fault Address Register
寄存器7:Cache Operations
該寄存器是隻寫寄存器,用于管理指令緩存和資料緩存。
對該寄存器的寫操作所實作的功能,是通過MCR指令中的opcode_2和CRm兩者的組合來選擇的,具體組合如下。
寄存器8:TLB Operations
Register 8 is a write-only register used to manage the translation lookaside buffer(TLBs),the instruction TLB and the data TLB.
Five TLB operations are defined and the function to be performed is selected by the opcode_2 and CRm fields in the MCR instruction used to write CP15 register 8.Writing other opcode_2 or CRm values id unpredictable. Reading from CP15 register 8 is unpredictable.
Function | Data | instruction |
Invalidate TLB(s) | SBZ | MCR p15,0,Rd,c8,c7,0 |
Invalidate I TLB | SBZ | MCR p15,0,Rd,c8,c5,0 |
Invalidate I TLB single entry (using MVA) | MVA format | MCR p15,0,Rd,c8,c5,1 |
Invalidate D TLB | SBZ | MCR p15,0,Rd,c8,c6,0 |
Invalidate D TLB single entry (using MVA) | MVA format | MCR p15,0,Rd,c8,c6,1 |
The ARM920T 有兩個具體協處理器
CP14調試通信通道協處理器
調試通信通道協處理器DCC(the Debug Communications Channel)提供了兩個32bits寄存器用于傳送資料,還提供了6bits通信資料控制寄存器控制寄存器中的兩個位提供目标和主機調試器之間的同步握手。
通信資料控制寄存器
以下指令在 Rd 中傳回控制寄存器的值:
MRC p14, 0, Rd, c0, c0
此控制寄存器中的兩個位提供目标和主機調試器之間的同步握手:
位 1(W 位) 從目标的角度表示通信資料寫入寄存器是否空閑:
W = 0 目标應用程式可以寫入新資料。
W = 1 主機調試器可以從寫入寄存器中掃描出新資料。
位 0(R 位) 從目标的角度表示通信資料讀取寄存器中是否有新資料:
R = 1 有新資料,目标應用程式可以讀取。
R = 0 主機調試器可以将新資料掃描到讀取寄存器中。
注意
調試器不能利用協處理器 14 直接通路調試通信通道,因為這對調試器無意義。 但調試器可使用掃描鍊讀寫 DCC 寄存器。 DCC 資料和控制寄存器可映射到 EmbeddedICE 邏輯單元中的位址。 若要檢視 EmbeddedICE 邏輯寄存器,請參閱您的調試器和調試目标的相關文檔。
通信資料讀取寄存器
用于接收來自調試器的資料的 32 位寬寄存器。 以下指令在 Rd 中返
回讀取寄存器的值:
MRC p14, 0, Rd, c1, c0
通信資料寫入寄存器
用于向調試器發送資料的 32 位寬寄存器。 以下指令将 Rn 中的值寫
到寫入寄存器中:
MCR p14, 0, Rn, c1, c0
注意
有關通路 ARM10 和 ARM11 核心 DCC 寄存器的資訊,請參閱相應的技術參考手冊。 ARM9 之後的各處理器中,所用指令、狀态位位置以及對狀态位的解釋都有所不同。
目标到調試器的通信
這是運作于 ARM 核心上的應用程式與運作于主機上的調試器之間的通信事件
順序:
1. 目标應用程式檢查 DCC 寫入寄存器是否空閑可用。 為此,目标應用程式使
用 MRC 指令讀取調試通信通道控制寄存器,以檢查 W 位是否已清除。
2. 如果 W 位已清除,則通信資料寫入寄存器已清空,應用程式對協處理器 14
使用 MCR 指令将字寫入通信資料寫入寄存器。 寫入寄存器操作會自動設定
W 位。如果 W 位已設定,則表明調試器尚未清空通信資料寫入寄存器。此
時,如果應用程式需要發送另一個字,它必須輪詢 W 位,直到它已清除。
3. 調試器通過掃描鍊 2 輪詢通信資料控制寄存器。 如果調試器發現 W 位已設
置,則它可以讀 DCC 資料寄存器,以讀取應用程式發送的資訊。 讀取資料
的程序會自動清除通信資料控制寄存器中的 W 位。
以下代碼顯示了這一過程
AREA OutChannel, CODE, READONLY
ENTRY
MOV r1,#3 ; Number of words to send
ADR r2, outdata ; Address of data to send
pollout
MRC p14,0,r0,c0,c0 ; Read control register
TST r0, #2
BNE pollout ; if W set, register still full
write
LDR r3,[r2],#4 ; Read word from outdata
; into r3 and update the pointer
MCR p14,0,r3,c1,c0 ; Write word from r3
SUBS r1,r1,#1 ; Update counter
BNE pollout ; Loop if more words to be written
MOV r0, #0x18 ; Angel_SWIreason_ReportException
LDR r1, =0x20026 ; ADP_Stopped_ApplicationExit
SVC 0x123456 ; ARM semihosting (formerly SWI)
outdata
DCB "Hello there!"
END
調試器到目标的通信
這是運作于主機上的調試器向運作于核心上的應用程式傳輸消息的事件順序:
1. 調試器輪詢通信資料控制寄存器的 R 位。 如果 R 位已清除,則通信資料讀
取寄存器已清空,可将資料寫入此寄存器,以供目标應用程式讀取。
2. 調試器通過掃描鍊 2 将資料掃描到通信資料讀取寄存器中。 此操作會自動
設定通信資料控制寄存器中的 R 位。
3. 目标應用程式輪詢通信資料控制寄存器中的 R 位。 如果該位已經設定,則
通信資料讀取寄存器中已經有資料,應用程式可使用 MRC 指令從協處理器
14 讀取該資料。 同時,讀取指令還會清除 R 位。
以下顯示的目标應用程式代碼示範了這一過程
AREA InChannel, CODE, READONLY
ENTRY
MOV r1,#3 ; Number of words to read
LDR r2, =indata ; Address to store data read
pollin
MRC p14,0,r0,c0,c0 ; Read control register
TST r0, #1
BEQ pollin ; If R bit clear then loop
read
MRC p14,0,r3,c1,c0 ; read word into r3
STR r3,[r2],#4 ; Store to memory and
; update pointer
SUBS r1,r1,#1 ; Update counter
BNE pollin ; Loop if more words to read
MOV r0, #0x18 ; Angel_SWIreason_ReportException
LDR r1, =0x20026 ; ADP_Stopped_ApplicationExit
SVC 0x123456 ; ARM semihosting (formerly SWI)
AREA Storage, DATA, READWRITE
indata
DCB "Duffmessage#"
END
CP15系統控制協處理器
CP15 —系統控制協處理器 (the system control coprocessor)他通過協處理器指令MCR和MRC提供具體的寄存器來配置和控制caches、MMU、保護系統、配置時鐘模式(在bootloader時鐘初始化用到)
CP15的寄存器隻能被MRC和MCR(Move to Coprocessor from ARM Register )指令通路
MCR{cond} p15,<Opcode_1>,<Rd>,<CRn>,<CRm>,<Opcode_2>
MRC{cond} p15,<Opcode_1>,<Rd>,<CRn>,<CRm>,<Opcode_2>
其中L位用來區分MCR(L=1)和MRC(L=0)操作. CP15包括15個具體的寄存器如下:
-R0:ID号寄存器
-R0:緩存類型寄存器
-R1:控制寄存器
-R2:轉換表基址寄存器(Translation Table Base --TTB)
-R3:域通路控制寄存器(Domain access control )
-R4:保留
-R5:異常狀态寄存器(fault status -FSR)
-R6:異常位址寄存器(fault address -FAR)
-R7:緩存操作寄存器
-R8:TLB操作寄存器
-R9:緩存鎖定寄存器
-R10:TLB 鎖定寄存器
-R11-12&14:保留
-R13:處理器ID
-R15:測試配置寄存器 2-24
要注意有2個R0,根據MCR操作數的不同傳送不同的值,這也一個隻讀寄存器
-R0:ID号寄存器 這是一個隻讀寄存器,傳回一個32位的裝置ID号,具體功能參考ARM各個系列型号的的CP15 Register 0說明.
MRC p15, 0, <Rd>, c0, c0, {0, 3-7} ;returns ID
以下為ID Code詳細描叙(ARM926EJ-S); ARM920T Part Number為0x920,Architecture (ARMv4T) 為0x2具體可參照ARM各型号.
-R0:緩存類型寄存器(CACHE TYPE REGISTER),包含了caches的資訊。讀這個寄存器的方式是通過設定協處理操作碼為1.
MRC p15, 0, <Rd>, c0, c0, 1; returns cache details
以下為CP15的一些應用示例
U32 ARM_CP15_DeviceIDRead(void)
{
U32 id;
__asm { MRC P15, 0, id, c0, c0; }
return id;
}
void ARM_CP15_SetPageTableBase(P_U32 TableAddress)
{
__asm { MCR P15, 0, TableAddress, c2, c0, 0; }
}
void ARM_CP15_SetDomainAccessControl(U32 flags)
{
__asm { MCR P15, 0, flags, c3, c0, 0; }
}
void ARM_CP15_ICacheFlush()
{
unsigned long dummy;
__asm { MCR p15, 0, dummy, c7, c5, 0; }
}
void ARM_CP15_DCacheFlush()
{
unsigned long dummy;
__asm { MCR p15, 0, dummy, c7, c6, 0; }
}
void ARM_CP15_CacheFlush()
{
unsigned long dummy;
__asm { MCR p15, 0, dummy, c7, c7, 0; }
}
void ARM_CP15_TLBFlush(void)
{
unsigned long dummy;
__asm { MCR P15, 0, dummy, c8, c7, 0; }
}
void ARM_CP15_ControlRegisterWrite(U32 flags)
{
__asm { MCR P15, 0, flags, c1, c0; }
}
void ARM_CP15_ControlRegisterOR(U32 flag)
{
__asm {
mrc p15,0,r0,c1,c0,0
mov r2,flag
orr r0,r2,r0
mcr p15,0,r0,c1,c0,0
}
}
void ARM_CP15_ControlRegisterAND(U32 flag)
{
__asm {
mrc p15,0,r0,c1,c0,0
mov r2,flag
and r0,r2,r0
mcr p15,0,r0,c1,c0,0
}
}
void ARM_MMU_Init(P_U32 TableAddress)
{
ARM_CP15_TLBFlush();
ARM_CP15_CacheFlush();
ARM_CP15_SetDomainAccessControl(0xFFFFFFFF);
ARM_CP15_SetPageTableBase(TableAddress);
}
void Enable_MMU (void)
{
__asm {
mrc p15,0,r0,c1,c0,0
mov r2, #0x00000001
orr r0,r2,r0
mcr p15,0,r0,c1,c0,0
}
printf("MMU enabled/n");
}
void Disable_MMU (void)
{
__asm {
mrc p15,0,r0,c1,c0,0
mov r2, #0xFFFFFFFE
and r0,r2,r0
mcr p15,0,r0,c1,c0,0
}
printf("MMU disabled/n");
}
本文來自CSDN部落格,轉載請标明出處:http://blog.csdn.net/tzwhzf/archive/2010/08/24/5833579.aspx