Rocket - debug - Example: Accessing Registers Using Abstract Command

https://mp.weixin.qq.com/s/RdJzE06mMkh2x__vVj_fEA

 

介绍riscv debug接口的使用实例:使用抽象命令读取寄存器。

 

 

1. Read s0 using abstract command

 

 

1) abstract command

 

抽象命令,Debug模块支持一些可选的抽象命令。一般情况下,debugger执行命令时,CPU核心是被暂停的:

 

命令是否支持只能通过执行之后判断返回的错误码来确定:

 

debugger通过写command寄存器来执行命令:

使用data寄存器进行传参和接收返回值:

 

目前支持的抽象命令有三种:

 

2) command寄存器

 

 

 

3) Access Register Command

 

如果抽象命令是访问寄存器,那么command寄存器的格式如下:

 

在当前这个实例中:

a. aarsize=2:表示Access the lowest 32 bits of the register;

b. transfer=1:表示Do the operation specied by write;

c. write=0:表示Copy data from the specified register into arg0 portion of data,即把目标寄存器的数据拷贝到data0;

d. regno=0x1008:这应该是寄存器s0的编号;

 

4) s0

 

s0在riscv-spec中定义:

 

s0是ABI中使用的助记词,原名是x8:

x8是一个GPR,即General Purpose Register,通用寄存器的意思:

 

根据regno的描述,寄存器的编号在Table 3.3中定义:

 

GPRs的范围是0x1000-0x101f,刚好32个。可以推知,x8的编号是0x1008。

 

5) 实例

 

这里实例的用意就很好理解了:

a. 写command寄存器,表明把regno=0x1008也就是寄存器s0的值传输到data0寄存器中;

b. 然后读取data0,获取s0的值;

 

当然这里面省略了一些步骤,比如读取cmderr判断命令执行结果等等。

 

2. Write mstatus using abstract command

 

 

1) Access Register command

 

在这个实例的命令中:

a. aarsize=2:表示Access the lowest 32 bits of the register;

b. transfer=1:表示Do the operation specied by write;

c. write=1:表示Copy data from arg0 portion of data into the specified register.,即把data0的数据拷贝到目标寄存器;

d. regno=0x300:这应该是寄存器mstatus的编号;

 

2) mstatus

 

根据regno使用的表格即Table 3.3,CSR的范围在0x0000-0x0fff。

 

mstatus在riscv-priviledged规范中定义,即Machine Status Register。其格式如下:

 

其编号为0x300:

 

所以这里使用的mstatus的regno=0x0000+0x300=0x300.

 

3) 实例

 

a. 首先把要写到mstatus的数据写入到寄存器data0;

b. 然后写command寄存器,执行写寄存器命令,把data0中的数据写入到mstatus寄存器中;

 

当然,这里面也省略了一些步骤。

 

posted @ 2019-11-09 21:41  wjcdx  阅读(583)  评论(0编辑  收藏  举报