查看: 1126|回复: 1
收起左侧

RISC-V处理器 蜂鸟e203 core_exu_alu_rglr 源码添加注释

[复制链接]

  离线 

  • TA的每日心情
    奋斗
    2021-3-3 12:32
  • 签到天数: 10 天

    [LV.3]

    发表于 2020-8-24 12:12:08 | 显示全部楼层 |阅读模式

    有人预言,RISC-V或将是继Intel和Arm之后的第三大主流处理器体系。欢迎访问全球首家只专注于RISC-V单片机行业应用的中文网站

    您需要 登录 才可以下载或查看,没有帐号?立即注册

    x
    本帖最后由 皋陶 于 2020-8-27 15:19 编辑

    2019.4.30添加


    粗略通读了整个蜂鸟e203的ALU模块的代码,其基本工作流程为:


    在译码阶段,已经读取了对源操作数寄存器索引,源操作数的读取,需要写回的结果操作数,存在InfoBUS中的信息等


    下面是在e203_exu_decode.v文件中对相关信息的提取,顺带一提,在RISC-V架构中,x0寄存器是一个相对特殊的寄存器,


    在v2.2版本的用户文档中是这样描述的:


    Register x0 is hardwired to the constant 0.


    博主英文水平与基础的电路知识不佳,大致意思是这个寄存器是通过硬件手段强行置0的,


    也就是说这个寄存器无法写入值,其内存存放的永远都是0;


    1. //e203_exu_decode.v
    2. module e203_exu_decode(
    3.     ....
    4. )
    5.     ....

    6. //以下为对指令译码得到的信息
    7.     output dec_rs1x0,//源操作数1寄存器索引为x0
    8.     output dec_rs2x0,//源操作数2寄存器索引为x0
    9.     output dec_rs1en,//该指令需要读取源操作数1
    10.     output dec_rs2en,//该指令需要读取源操作数2
    11.     output dec_rdwen,//该指令需要写回结果操作数
    12.     output ['E203_RGIDX_WIDTH-1:0] dec_rs1idx,//源操作数1寄存器索引
    13.     output ['E203_RGIDX_WIDTH-1:0] dec_rs2idx,//源操作数2寄存器索引
    14.     output ['E203_RGIDX_WIDTH-1:0] dec_rdidx,//结果操作数寄存器索引
    15.     output ['E203_DECINFO_WIDTH-1:0] dec_info,//其余信息统一存在INFOBUS中

    16.     output ['E203_XLEN-1:0] dec_imm,//该指令使用立即数
    17. ...
    18.     output dec_ilegl,//该指令非法
    19. ...


    20. endmodule
    复制代码


    通过上面的代码片段可以看出译码完成后被传入ALU中的信号已经很规整了,ALU当中的子模块通过判断info bus中的信号来确定接下来需要复用运算数据通路子模块的具体部分,且可以认为此时两个源操作数和需要用来存放结果的寄存器都已经取到了。


    再结合下面的部分看相信就对这部分的工作流程有个框架已经在大家的脑海中成型了。


    **************************************分割线**************************************************


    首次添加2019.3.28,计划继续补充修改


    1. //  This module to implement the regular ALU instructions
    2. //
    3. //
    4. // ====================================================================
    5. `include "e203_defines.v"

    6. module e203_exu_alu_rglr(

    7.   //
    8.   //
    9.   // The Handshake Interface
    10.   //
    11.   input  alu_i_valid, // Handshake valid写入使能
    12.   output alu_i_ready, // Handshake ready写入准备就绪
    13.   //E203_XLEN32bit
    14.   input  [`E203_XLEN-1:0] alu_i_rs1,
    15.   input  [`E203_XLEN-1:0] alu_i_rs2,
    16.   input  [`E203_XLEN-1:0] alu_i_imm,
    17.   input  [`E203_PC_SIZE-1:0] alu_i_pc,
    18.   //当前E203_DECINFO_ALU_WIDTH为21[20:0],此项为从info总线取到的数据
    19.   input  [`E203_DECINFO_ALU_WIDTH-1:0] alu_i_info,

    20.   //
    21.   //
    22.   // The ALU Write-back/Commit Interface
    23.   output alu_o_valid, // Handshake valid输出使能
    24.   input  alu_o_ready, // Handshake ready输出就绪或完成
    25.   // The Write-Back Interface for Special (unaligned ldst and AMO instructions)
    26.   output [`E203_XLEN-1:0] alu_o_wbck_wdat,//连接至数据通路返回的结果,即写回的数据
    27.   output alu_o_wbck_err,   
    28.   output alu_o_cmt_ecall,   
    29.   output alu_o_cmt_ebreak,   
    30.   output alu_o_cmt_wfi,   


    31.   //
    32.   //
    33.   // To share the ALU datapath将发送至数据通路的数据
    34.   //
    35.   // The operands and info to ALU
    36.   output alu_req_alu_add ,
    37.   output alu_req_alu_sub ,
    38.   output alu_req_alu_xor ,
    39.   output alu_req_alu_sll ,
    40.   output alu_req_alu_srl ,
    41.   output alu_req_alu_sra ,
    42.   output alu_req_alu_or  ,
    43.   output alu_req_alu_and ,
    44.   output alu_req_alu_slt ,
    45.   output alu_req_alu_sltu,
    46.   output alu_req_alu_lui ,
    47.   output [`E203_XLEN-1:0] alu_req_alu_op1,//两个源操作数
    48.   output [`E203_XLEN-1:0] alu_req_alu_op2,


    49.   input  [`E203_XLEN-1:0] alu_req_alu_res,//从数据通路模块取回的结果

    50.   input  clk,
    51.   input  rst_n
    52.   );

    53.   wire op1pc   = alu_i_info [`E203_DECINFO_ALU_OP1PC  ];//判定第一个源操作数是否使用PC 16:16
    54.   wire op2imm  = alu_i_info [`E203_DECINFO_ALU_OP2IMM ];//判定第二个源操作数是否为立即数 15:15
    55.   
    56.   assign alu_req_alu_op1  = op1pc  ? alu_i_pc  : alu_i_rs1;//两个源操作数
    57.   assign alu_req_alu_op2  = op2imm ? alu_i_imm : alu_i_rs2;

    58.   wire nop    = alu_i_info [`E203_DECINFO_ALU_NOP ] ;//17:17
    59.   wire ecall  = alu_i_info [`E203_DECINFO_ALU_ECAL ];//18:18
    60.   wire ebreak = alu_i_info [`E203_DECINFO_ALU_EBRK ];//19:19
    61.   wire wfi    = alu_i_info [`E203_DECINFO_ALU_WFI ];//20:20

    62.      // The NOP is encoded as ADDI, so need to uncheck it
    63.   assign alu_req_alu_add  = alu_i_info [`E203_DECINFO_ALU_ADD ] & (~nop);//4:4
    64.   assign alu_req_alu_sub  = alu_i_info [`E203_DECINFO_ALU_SUB ];//5:5
    65.   assign alu_req_alu_xor  = alu_i_info [`E203_DECINFO_ALU_XOR ];//6:6
    66.   assign alu_req_alu_sll  = alu_i_info [`E203_DECINFO_ALU_SLL ];//7
    67.   assign alu_req_alu_srl  = alu_i_info [`E203_DECINFO_ALU_SRL ];//8
    68.   assign alu_req_alu_sra  = alu_i_info [`E203_DECINFO_ALU_SRA ];//9
    69.   assign alu_req_alu_or   = alu_i_info [`E203_DECINFO_ALU_OR  ];//10
    70.   assign alu_req_alu_and  = alu_i_info [`E203_DECINFO_ALU_AND ];//11
    71.   assign alu_req_alu_slt  = alu_i_info [`E203_DECINFO_ALU_SLT ];//12
    72.   assign alu_req_alu_sltu = alu_i_info [`E203_DECINFO_ALU_SLTU];//13
    73.   assign alu_req_alu_lui  = alu_i_info [`E203_DECINFO_ALU_LUI ];//14:14

    74.   assign alu_o_valid = alu_i_valid;//根据输入使能得到输出使能                             
    75.   assign alu_i_ready = alu_o_ready;//
    76.   assign alu_o_wbck_wdat = alu_req_alu_res;//将从数据通路取回的数据输出

    77.   assign alu_o_cmt_ecall  = ecall;   
    78.   assign alu_o_cmt_ebreak = ebreak;   
    79.   assign alu_o_cmt_wfi = wfi;   
    80.   
    81.   // The exception or error result cannot write-back
    82.   assign alu_o_wbck_err = alu_o_cmt_ecall | alu_o_cmt_ebreak | alu_o_cmt_wfi;

    83. endmodule
    复制代码

    本篇完,感谢关注:RISC-V单片机中文网




    上一篇:AdaCore 加入 RISC-V 基金会,带来 C 与 Ada 编译支持
    下一篇:Running 64-bit RISC-V Linux on QEMU
    RISCV作者优文
    全球首家只专注于RISC-V单片机行业应用的中文网站
    回复

    使用道具 举报

    RISC-V隐身侠  发表于 2022-7-5 07:21:17
    It is actually a nice and helpful piece of info. I am glad that
    you simply shared this useful info with
    us. Please keep us informed like this. Thank you for sharing.
    dark web market https://mydarkmarket.com
    全球首家只专注于RISC-V单片机行业应用的中文网站
    回复 支持 反对

    使用道具

    高级模式
    B Color Image Link Quote Code Smilies

    本版积分规则

    关闭

    RISC-V单片机中文网上一条 /2 下一条



    版权及免责声明|RISC-V单片机中文网 |网站地图

    GMT+8, 2024-3-29 01:38 , Processed in 0.472302 second(s), 47 queries .

    快速回复 返回顶部 返回列表