码迷,mamicode.com
首页 > 其他好文 > 详细

Verilog MIPS32 CPU(五)-- CP0

时间:2017-10-01 11:26:29      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:cti   put   log   use   mips   ssi   homepage   lan   bsp   

 

 

module CP0(
        input clk,
        input rst,
        input teq_exc,
        input mtc0,            //CPU instruction is Mtc0
        input [31:0] pc,
        input [4:0] addr,        //Specifies CP0 register
        input [31:0] wdata,    //Data from GP register to replace CP0 register
        input eret,            //instruction is ERET(Exception Return)
        input [3:0] cause,
        output [31:0] rdata,    //Data from CP0 register for GP register,
        output [31:0] exc_addr    //Address for PC at the beginning of an exception
    );
    
    parameter    SYSCALL     =   4b1000,
                BREAK       =   4b1001,
                TEQ            =   4b1101,
                IE            =    0;
//                status    =    12,
//                cause        =    13,
//                epc        =    14,    
                
    reg [31:0] cop0 [0:31];
    wire [31:0] status    =    cop0[12];
    integer i;
    
    wire exception    =    status[0]&&    ((status[1]&&cause==SYSCALL)||
                                     (status[2]&&cause==BREAK)    ||
                                     (status[3]&&cause==TEQ&&teq_exc));
    
    always@(posedge clk or posedge rst) begin
        if(rst)begin
            for(i=0;i<32;i=i+1)
                cop0[i]<=0;
        end
        else begin
            if(mtc0)
                cop0[addr]    <=    wdata;
            else if(exception)begin
                cop0[14]    <=    pc;
                cop0[12]    <=    status<<5;
                cop0[13]    <=    {24b0,cause,2b0};
            end
            else if(eret) begin
                cop0[12]    <=    status>>5;
            end
        end 
    end
    assign exc_addr    =    eret?cop0[14]:32h4;
    assign rdata    =    cop0[addr];
    
endmodule

 

Verilog MIPS32 CPU(五)-- CP0

标签:cti   put   log   use   mips   ssi   homepage   lan   bsp   

原文地址:http://www.cnblogs.com/liutianchen/p/7616756.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!