Rocket-chip-RoCC(4)--software

RISC-V RoCC软件:自定义指令底层汇编实现
本文介绍了如何在RISC-V架构下通过ROCC软件定制指令,涉及mstatus的XS位设置,以及旧版和新版汇编代码的区别。展示了如何在底层汇编*.S文件中使用XCUSTOM宏来创建定制指令,适用于不同指令类型和参数配置。

ROCC软件代码介绍

  • 前情提要:
    需要注意的是custom0~3均采用R类指令格式。RISC-V各指令类别如下图所示。
    在这里插入图片描述

  • mstatus的XS域
    需要打开mstatus的XS域。
    https://blog.youkuaiyun.com/a_weiming/article/details/111600428
    我是在底层汇编*.S文件中打开的,代码如下:
    其中MSTATUS_XS在encoding.h有定义。

 # enable accelerator if present
  li t0, MSTATUS_XS
  csrs mstatus, t0
  • ROCC的底层汇编
    我这里有两个版本,一个是很久的,另一个是较新的,较新的需要gcc支持某些特定的语法,例如.inst,我的gcc比较旧,所以使用旧的版本。新旧都是IBM开源在github上的。
    https://github.com/IBM/rocc-software
  • 旧版本代码:
// Copyright 2018 IBM
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef ROCC_SOFTWARE_SRC_XCUSTOM_H_
#define ROCC_SOFTWARE_SRC_XCUSTOM_H_

#define STR1(x) #x
#ifndef STR
#define STR(x) STR1(x)
#endif
#define EXTRACT(a, size, offset) (((~(~0 << size) << offset) & a) >> offset)

// rd = rs2[offset + size - 1 : offset]
// rs1 is clobbered
// rs2 is left intact
#define EXTRACT_RAW(rd, rs1, rs2, size, offset) \
  not x ## rs1, x0;                             \
  slli x ## rs1, x ## rs1, size;                \
  not x ## rs1, x ## rs1;                       \
  slli x ## rs1, x ## rs1, offset;              \
  and x ## rd, x ## rs1, x ## rs2;    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值