Advertisement
Guest User

Untitled

a guest
Oct 28th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `define STATUS_REGISTER 5'd12
  2. `define CAUSE_REGISTER  5'd13
  3. `define EPC_REGISTER    5'd14
  4.  
  5. module cp0(rd_data, EPC, TakenInterrupt,
  6.           wr_data, regnum, next_pc,
  7.           MTC0, ERET, TimerInterrupt, clock, reset);
  8.    output [31:0] rd_data;
  9.    output [29:0] EPC;
  10.    output        TakenInterrupt;
  11.    input  [31:0] wr_data;
  12.    input   [4:0] regnum;
  13.    input  [29:0] next_pc;
  14.    input         MTC0, ERET, TimerInterrupt, clock, reset;
  15.  
  16.    wire and1_out, not1_out, and2_out, and3_out, reset_or_out, or1_out, exception_level;
  17.    wire [31:0] cause_register, user_status,decoder_out, ext_epc_out, status_register;
  18.    wire [29:0] epcReg_out, epc_in;
  19.  
  20.    // your Verilog for coprocessor 0 goes here
  21.  
  22. register userStatusReg(user_status, wr_data, clock, decoder_out[12], reset);
  23.  
  24. assign reset_or_out = (ERET | reset);
  25. dffe exceptionStatusReg(exception_level,1'b1,clock,and3_out,reset_or_out);
  26. decoder32 mtcDecoder(decoder_out,regnum,MTC0);
  27.  
  28. mux2v #(30) pcOrWriteData(epc_in, wr_data[31:2], next_pc,and3_out);
  29.  
  30. assign ext_epc_out = {epcReg_out,2'b00};
  31. mux3v #(32) finalData(rd_data,status_register,cause_register,ext_epc_out,regnum);
  32.  
  33. assign EPC = epcReg_out;
  34.  
  35. // module register(q, d, clk, enable, reset);
  36. or or1(or1_out, decoder_out[14], and3_out);
  37.  
  38. register #(30) epcReg(epcReg_out, epc_in, clock, or1_out, reset);
  39.  
  40. and and1(and1_out, cause_register[15], user_status[15]);
  41. not not1(not1_out, exception_level);
  42. and and2(and2_out, not1_out, user_status[0]);
  43. and and3(and3_out, and1_out, and2_out);
  44.  
  45. assign status_register[15:8] = user_status[15:8];
  46. assign status_register[1] = exception_level;
  47. assign status_register[0] = user_status[0];
  48. assign status_register[7:2] = 6'b0;
  49. assign status_register[31:16] = 16'b0;
  50.  
  51. assign cause_register[15] = TimerInterrupt;
  52. assign cause_register[14:0] = 15'b0;
  53. assign cause_register[31:16] = 16'b0;
  54.  
  55.  
  56. // and3_out == TakenInterrupt
  57. assign TakenInterrupt = and3_out;
  58.  
  59. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement