ARM926EJ-S/ARM920T 协处理器 CP14, CP15详解

http://simengru.blog.163.com/blog/static/54386860201010301111898/

在基于ARM的嵌入式应用系统中,存储系统通常是通过系统控制协处理器CP15完成的。CP15包含1632位的寄存器,其编号为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>} p150<Rd>,<CRn>,<CRm>{,<opcode_2>}

其中,<cond>为指令执行的条件码。当<cond>忽略时指令为无条件执行。

< opcode_1>为协处理器将执行的操作的操作码。对于CP15协处理器来说,< opcode_1>永远为0b000,当< opcode_1>不为0b000时,该指令操作结果不可预知。

<Rd>作为源寄存器的ARM寄存器,其值将被传送到协处理器寄存器中。

<CRn>作为目标寄存器的协处理器寄存器,其编号可能是C0C1C15

<CRm><opcode_2>两者组合决定对协处理器寄存器进行所需要的操作,如果没有指定,则将为<CRm>C0opcode_20,否则可能导致不可预知的结果。

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中。其中R4ARM寄存器,存放源操作数,C1C0为协处理器寄存器,为目标寄存器,opcode_10opcode_20

MCR  p15,  0,  R4,  C1,  C0,  0

 

MRC指令

MRC指令将协处理器的寄存器中的数值传送到ARM处理器的寄存器中、如果协处理器不能成功地执行该操作,将产生未定义的指令异常中断。

指令语法格式

MRC{<cond>} <p>< opcode_1><Rd>,<CRn>,<CRm>{,<opcode_2>}

MRC{<cond>} p150<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.

 

寄存器0ID 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

 

 

寄存器0Cache 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

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)

 

 

寄存器1Control 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 = 使能地址对齐检查功能

0

M bit

MMU enable

0 = MMU disable

1 = MMU enable

 

 

 时钟模式表

 

Clocking mode(时钟模式)

iA

      nF

Fastbus mode (快速总线模式)

      0

      0

Reserved

      1

      0

Synchronous (同步模式)

      0

      1

Asynchronous (异步模式)

      1

      1

 

 引用 关于ARM9协处理器CP15及MCR和MRC指令 - Galaxy - Galaxy的博客

                                                         图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个位

引用 关于ARM9协处理器CP15及MCR和MRC指令 - Galaxy - Galaxy的博客

访问该寄存器的指令如下:

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

引用 关于ARM9协处理器CP15及MCR和MRC指令 - Galaxy - Galaxy的博客

 

 

寄存器4:保留

对该寄存器的读写会产生不可预料的结果。

 

寄存器5Fault Status Register

寄存器6Fault Address Register

寄存器7Cache Operations

该寄存器是只写寄存器,用于管理指令缓存和数据缓存。

对该寄存器的写操作所实现的功能,是通过MCR指令中的opcode_2CRm两者的组合来选择的,具体组合如下。

 

 

 

寄存器8TLB 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
 

引用 关于ARM9协处理器CP15及MCR和MRC指令 - Galaxy - Galaxy的博客

 

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

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值