在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 9585|回复: 6

[求助] 大神们进来瞧一瞧

[复制链接]
发表于 2012-7-11 11:19:36 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

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

x
请问这些写的是什么东西?有什么作用?有什么错误(主要的错误和次要的错误)?然后更正~请各位大神帮帮忙。。。



  1. module dcpu16_alu (/*AUTOARG*/
  2.    // Outputs
  3.    f_dto, g_dto, rwd, regR, regO, CC,
  4.    // Inputs
  5.    regA, regB, opc, clk, rst, ena, pha
  6.    );

  7.    output [15:0] f_dto,
  8.                  g_dto,
  9.                  rwd;
  10.    
  11.    output [15:0] regR,
  12.                  regO;
  13.    output          CC;   
  14.    
  15.    input [15:0]  regA,
  16.                  regB;   
  17.    
  18.    input [3:0]          opc;
  19.    
  20.    input          clk,
  21.                  rst,
  22.                  ena;

  23.    input [1:0]          pha;   

  24.    wire [15:0]          src, // a
  25.                  tgt; // b
  26.    
  27.    /*AUTOREG*/
  28.    // Beginning of automatic regs (for this module's undeclared outputs)
  29.    reg                        CC;
  30.    reg [15:0]                regO;
  31.    reg [15:0]                regR;
  32.    // End of automatics

  33.    reg                 c;
  34.    reg [15:0]         add;
  35.    reg [33:0]         mul;       
  36.    reg [31:0]         shl,
  37.                 shr;   
  38.    
  39.    assign f_dto = regR;
  40.    assign g_dto = regR;   
  41.    assign rwd = regR;   
  42.    
  43.    assign src = regA;
  44.    assign tgt = regB;   

  45.    // adder
  46.    always @(/*AUTOSENSE*/opc or src or tgt) begin
  47.       {c,add} <= (~opc[0]) ? (src + tgt) : (src - tgt);
  48.       mul <= {1'b0,src} * {1'b0,tgt};
  49.       shl <= src << tgt;
  50.       shr <= src >> tgt;      
  51.    end

  52.    
  53.    always @(posedge clk)
  54.      if (rst) begin
  55.         /*AUTORESET*/
  56.         // Beginning of autoreset for uninitialized flops
  57.         CC <= 1'h0;
  58.         regO <= 16'h0;
  59.         regR <= 16'h0;
  60.         // End of automatics
  61.      end else if (ena) begin

  62.         // 0x1: SET a, b - sets a to b
  63.         // 0x2: ADD a, b - sets a to a+b, sets O to 0x0001 if there's an overflow, 0x0 otherwise
  64.         // 0x3: SUB a, b - sets a to a-b, sets O to 0xffff if there's an underflow, 0x0 otherwise
  65.         // 0x4: MUL a, b - sets a to a*b, sets O to ((a*b)>>16)&0xffff
  66.         // 0x5: DIV a, b - sets a to a/b, sets O to ((a<<16)/b)&0xffff. if b==0, sets a and O to 0 instead.
  67.         // 0x6: MOD a, b - sets a to a%b. if b==0, sets a to 0 instead.
  68.         // 0x7: SHL a, b - sets a to a<<b, sets O to ((a<<b)>>16)&0xffff
  69.         // 0x8: SHR a, b - sets a to a>>b, sets O to ((a<<16)>>b)&0xffff         
  70.         // 0x9: AND a, b - sets a to a&b
  71.         // 0xa: BOR a, b - sets a to a|b
  72.         // 0xb: XOR a, b - sets a to a^b

  73.         if (pha == 2'o0)
  74.           case (opc)
  75.             4'h2: regO <= {15'd0,c};
  76.             4'h3: regO <= {(16){c}};
  77.             4'h4: regO <= mul[31:16];
  78.             4'h7: regO <= shl[31:16];
  79.             4'h8: regO <= shr[15:0];
  80.             default: regO <= regO;            
  81.           endcase // case (opc)

  82.         if (pha == 2'o0)
  83.           case (opc)
  84.             4'h0: regR <= src;
  85.             4'h1: regR <= tgt;
  86.             4'h2: regR <= add;
  87.             4'h3: regR <= add;
  88.             4'h4: regR <= mul[15:0];
  89.             4'h7: regR <= shl[15:0];
  90.             4'h8: regR <= shr[31:16];
  91.             4'h9: regR <= src & tgt;
  92.             4'hA: regR <= src | tgt;
  93.             4'hB: regR <= src ^ tgt;
  94.             default: regR <= 16'hX;            
  95.           endcase // case (opc)       
  96.        
  97.         /*
  98.         if (pha == 2'o0)
  99.         case (opc)

  100.           4'h0: {regO, regR} <= {regO, src};          

  101.           // 0x1: SET a, b - sets a to b
  102.           4'h1: {regO, regR} <= {regO, tgt};

  103.           // 0x2: ADD a, b - sets a to a+b, sets O to 0x0001 if there's an overflow, 0x0 otherwise
  104.           // 0x3: SUB a, b - sets a to a-b, sets O to 0xffff if there's an underflow, 0x0 otherwise
  105.           // 0x4: MUL a, b - sets a to a*b, sets O to ((a*b)>>16)&0xffff
  106.           // 0x5: DIV a, b - sets a to a/b, sets O to ((a<<16)/b)&0xffff. if b==0, sets a and O to 0 instead.
  107.           // 0x6: MOD a, b - sets a to a%b. if b==0, sets a to 0 instead.
  108.           4'h2, 4'h3: {regO, regR} <= (opc[0]) ?
  109.                                       {{(16){c}},as} :
  110.                                       {15'd0,c,as};          
  111.           4'h4: {regO, regR} <= {1'b0,src} * {1'b0,tgt}; // force 17x17 unsigned

  112.           // 0x7: SHL a, b - sets a to a<<b, sets O to ((a<<b)>>16)&0xffff
  113.           // 0x8: SHR a, b - sets a to a>>b, sets O to ((a<<16)>>b)&0xffff         
  114.           4'h7: {regO, regR} <= src << tgt;
  115.           4'h8: {regR, regO} <= {src,16'h0} >> tgt;
  116.           
  117.           // 0x9: AND a, b - sets a to a&b
  118.           // 0xa: BOR a, b - sets a to a|b
  119.           // 0xb: XOR a, b - sets a to a^b
  120.           4'h9: {regO, regR} <= {regO, src & tgt};
  121.           4'hA: {regO, regR} <= {regO, src | tgt};
  122.           4'hB: {regO, regR} <= {regO, src ^ tgt};          

  123.           default: {regO, regR} <= {regO, 16'hX};          
  124.         endcase // case (opc)
  125.          */
  126.        
  127.         // 0xc: IFE a, b - performs next instruction only if a==b
  128.         // 0xd: IFN a, b - performs next instruction only if a!=b
  129.         // 0xe: IFG a, b - performs next instruction only if a>b
  130.         // 0xf: IFB a, b - performs next instruction only if (a&b)!=0                    
  131.           
  132.         if (pha == 2'o0)
  133.           case (opc)
  134.             4'hC: CC <= (src == tgt);
  135.             4'hD: CC <= (src != tgt);
  136.             4'hE: CC <= (src > tgt);
  137.             4'hF: CC <= |(src & tgt);
  138.             default: CC <= 1'b1;          
  139.           endcase // case (opc)
  140.        
  141.      end
  142.    
  143. endmodule // dcpu16_alu



复制代码








复制代码




  1. /*

  2. DCPU16 PIPELINE
  3. ===============

  4. Consists of the following stages:

  5. - Fetch (FE): fetches instructions from the FBUS.
  6. - Decode (DE): decodes instructions.
  7. - EA A (EA) : calculates EA for A
  8. - EA B (EB) : calculates EA for B
  9. - Load A (LA): loads operand A from ABUS.
  10. - Load B (LB): loads operand B from ABUS.
  11. - Execute (EX): performs the ALU operation.
  12. - Save A (SA): saves operand A to the FBUS.

  13. 0| 1| 2| 3| 0| 1| 2| 3| 0| 1| 2| 3
  14.       FE|DE|EA|EB|LA|LB|EX|SA
  15.                   FE|DE|EA|EB|LA|LB|EX|SA
  16.                                FE|DE|EA|EB|LA|LB|EX|SA
  17. */

  18. // 775@155
  19. // 692@159
  20. // 685@160
  21. // 603@138
  22. // 573@138
  23. // 508@141
  24. // 502@149
  25. // 712@153
  26. // 679@162

  27. module dcpu16_cpu (/*AUTOARG*/
  28.    // Outputs
  29.    g_wre, g_stb, g_dto, g_adr, f_wre, f_stb, f_dto, f_adr,
  30.    // Inputs
  31.    rst, g_dti, g_ack, f_dti, f_ack, clk
  32.    );

  33.    /*AUTOOUTPUT*/
  34.    // Beginning of automatic outputs (from unused autoinst outputs)
  35.    output [15:0]        f_adr;                        // From m0 of dcpu16_mbus.v
  36.    output [15:0]        f_dto;                        // From x0 of dcpu16_alu.v
  37.    output                f_stb;                        // From m0 of dcpu16_mbus.v
  38.    output                f_wre;                        // From m0 of dcpu16_mbus.v
  39.    output [15:0]        g_adr;                        // From m0 of dcpu16_mbus.v
  40.    output [15:0]        g_dto;                        // From x0 of dcpu16_alu.v
  41.    output                g_stb;                        // From m0 of dcpu16_mbus.v
  42.    output                g_wre;                        // From m0 of dcpu16_mbus.v
  43.    // End of automatics
  44.    /*AUTOINPUT*/
  45.    // Beginning of automatic inputs (from unused autoinst inputs)
  46.    input                clk;                        // To c0 of dcpu16_ctl.v, ...
  47.    input                f_ack;                        // To c0 of dcpu16_ctl.v, ...
  48.    input [15:0]                f_dti;                        // To c0 of dcpu16_ctl.v, ...
  49.    input                g_ack;                        // To m0 of dcpu16_mbus.v
  50.    input [15:0]                g_dti;                        // To m0 of dcpu16_mbus.v
  51.    input                rst;                        // To c0 of dcpu16_ctl.v, ...
  52.    // End of automatics
  53.    /*AUTOWIRE*/
  54.    // Beginning of automatic wires (for undeclared instantiated-module outputs)
  55.    wire                        CC;                        // From x0 of dcpu16_alu.v
  56.    wire                        bra;                        // From c0 of dcpu16_ctl.v
  57.    wire                        ena;                        // From m0 of dcpu16_mbus.v
  58.    wire [15:0]                ireg;                        // From c0 of dcpu16_ctl.v
  59.    wire [3:0]                opc;                        // From c0 of dcpu16_ctl.v
  60.    wire [1:0]                pha;                        // From c0 of dcpu16_ctl.v
  61.    wire [15:0]                regA;                        // From m0 of dcpu16_mbus.v
  62.    wire [15:0]                regB;                        // From m0 of dcpu16_mbus.v
  63.    wire [15:0]                regO;                        // From x0 of dcpu16_alu.v
  64.    wire [15:0]                regR;                        // From x0 of dcpu16_alu.v
  65.    wire [2:0]                rra;                        // From c0 of dcpu16_ctl.v
  66.    wire [15:0]                rrd;                        // From r0 of dcpu16_regs.v
  67.    wire [2:0]                rwa;                        // From c0 of dcpu16_ctl.v
  68.    wire [15:0]                rwd;                        // From x0 of dcpu16_alu.v
  69.    wire                        rwe;                        // From c0 of dcpu16_ctl.v
  70.    wire                        wpc;                        // From m0 of dcpu16_mbus.v
  71.    // End of automatics
  72.    /*AUTOREG*/

  73.    dcpu16_ctl
  74.      c0 (/*AUTOINST*/
  75.          // Outputs
  76.          .ireg                                (ireg[15:0]),
  77.          .pha                                (pha[1:0]),
  78.          .opc                                (opc[3:0]),
  79.          .rra                                (rra[2:0]),
  80.          .rwa                                (rwa[2:0]),
  81.          .rwe                                (rwe),
  82.          .bra                                (bra),
  83.          // Inputs
  84.          .CC                                (CC),
  85.          .wpc                                (wpc),
  86.          .f_dti                                (f_dti[15:0]),
  87.          .f_ack                                (f_ack),
  88.          .clk                                (clk),
  89.          .ena                                (ena),
  90.          .rst                                (rst));   

  91.    dcpu16_mbus
  92.      m0 (/*AUTOINST*/
  93.          // Outputs
  94.          .g_adr                                (g_adr[15:0]),
  95.          .g_stb                                (g_stb),
  96.          .g_wre                                (g_wre),
  97.          .f_adr                                (f_adr[15:0]),
  98.          .f_stb                                (f_stb),
  99.          .f_wre                                (f_wre),
  100.          .ena                                (ena),
  101.          .wpc                                (wpc),
  102.          .regA                                (regA[15:0]),
  103.          .regB                                (regB[15:0]),
  104.          // Inputs
  105.          .g_dti                                (g_dti[15:0]),
  106.          .g_ack                                (g_ack),
  107.          .f_dti                                (f_dti[15:0]),
  108.          .f_ack                                (f_ack),
  109.          .bra                                (bra),
  110.          .CC                                (CC),
  111.          .regR                                (regR[15:0]),
  112.          .rrd                                (rrd[15:0]),
  113.          .ireg                                (ireg[15:0]),
  114.          .regO                                (regO[15:0]),
  115.          .pha                                (pha[1:0]),
  116.          .clk                                (clk),
  117.          .rst                                (rst));
  118.    
  119.    dcpu16_alu
  120.      x0 (/*AUTOINST*/
  121.          // Outputs
  122.          .f_dto                                (f_dto[15:0]),
  123.          .g_dto                                (g_dto[15:0]),
  124.          .rwd                                (rwd[15:0]),
  125.          .regR                                (regR[15:0]),
  126.          .regO                                (regO[15:0]),
  127.          .CC                                (CC),
  128.          // Inputs
  129.          .regA                                (regA[15:0]),
  130.          .regB                                (regB[15:0]),
  131.          .opc                                (opc[3:0]),
  132.          .clk                                (clk),
  133.          .rst                                (rst),
  134.          .ena                                (ena),
  135.          .pha                                (pha[1:0]));
  136.    
  137.    
  138.    dcpu16_regs
  139.      r0 (/*AUTOINST*/
  140.          // Outputs
  141.          .rrd                                (rrd[15:0]),
  142.          // Inputs
  143.          .rwd                                (rwd[15:0]),
  144.          .rra                                (rra[2:0]),
  145.          .rwa                                (rwa[2:0]),
  146.          .rwe                                (rwe),
  147.          .rst                                (rst),
  148.          .ena                                (ena),
  149.          .clk                                (clk));
  150.    
  151. endmodule // dcpu16



复制代码
 楼主| 发表于 2012-7-11 11:22:53 | 显示全部楼层
回复 1# leo23h
下面继续发~






  1. /*
  2. DCPU16 Verilog Implementation
  3. Copyright (C) 2012 Shawn Tan <shawn.tan@sybreon.com>

  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as
  6. published by the Free Software Foundation, either version 3 of the
  7. License, or (at your option) any later version.  This program is
  8. distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11. for more details.

  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this program.  If not, see
  14. <http://www.gnu.org/licenses/>.  */

  15. // TODO: JSR
  16. // FIXME: Reg-Reg forwarding

  17. module dcpu16_ctl (/*AUTOARG*/
  18.    // Outputs
  19.    ireg, pha, opc, rra, rwa, rwe, bra,
  20.    // Inputs
  21.    CC, wpc, f_dti, f_ack, clk, ena, rst
  22.    );

  23.    output [15:0] ireg;   
  24.    output [1:0]  pha;

  25.    // shared
  26.    output [3:0]  opc;
  27.    output [2:0]  rra,
  28.                  rwa;
  29.    output          rwe;
  30.    output          bra;

  31.    input          CC;   
  32.    input          wpc;
  33.    
  34.    input [15:0]  f_dti;   
  35.    input          f_ack;   
  36.   
  37.    // system
  38.    input          clk,
  39.                  ena,
  40.                  rst;

  41.    /*AUTOREG*/
  42.    // Beginning of automatic regs (for this module's undeclared outputs)
  43.    reg                        bra;
  44.    reg [15:0]                ireg;
  45.    reg [3:0]                opc;
  46.    reg [1:0]                pha;
  47.    reg [2:0]                rra;
  48.    reg [2:0]                rwa;
  49.    reg                        rwe;
  50.    // End of automatics

  51.    // repeated decoder
  52.    wire [5:0]                 decA, decB;
  53.    wire [3:0]                 decO;   
  54.    assign {decB, decA, decO} = ireg;   

  55.    wire                 nop = 16'd1; // NOP = SET A, A   
  56.    wire                 _skp = (decO == 4'h0);

  57.    wire                 Fbra = (ireg[4:0] == 5'h10);   
  58.    
  59.    // PHASE CALCULATOR
  60.    always @(posedge clk)
  61.      if (rst) begin
  62.         /*AUTORESET*/
  63.         // Beginning of autoreset for uninitialized flops
  64.         pha <= 2'h0;
  65.         // End of automatics
  66.      end else if (ena) begin
  67.         pha <= pha + 1;               
  68.      end

  69.    // IREG LATCH
  70.    always @(posedge clk)
  71.      if (rst) begin
  72.         /*AUTORESET*/
  73.         // Beginning of autoreset for uninitialized flops
  74.         ireg <= 16'h0;
  75.         opc <= 4'h0;
  76.         // End of automatics
  77.      end else if (ena) begin
  78.         case (pha)
  79.           2'o2: ireg <= (wpc | Fbra) ? nop : f_dti; // latch instruction only on PHA2
  80.           default: ireg <= ireg;          
  81.         endcase // case (pha)

  82.         case (pha)
  83.           2'o2: opc <= ireg[3:0];          
  84.           default: opc <= opc;
  85.         endcase // case (pha)
  86.        
  87.      end

  88.    // BRANCH CONTROL
  89.    reg _bra;   
  90.    always @(posedge clk)
  91.      if (rst) begin
  92.         /*AUTORESET*/
  93.         // Beginning of autoreset for uninitialized flops
  94.         _bra <= 1'h0;
  95.         bra <= 1'h0;
  96.         // End of automatics
  97.      end else if (ena) begin
  98.         case (pha)
  99.           2'o0: {bra, _bra} <= {_bra & CC, (ireg[5:0] == 5'h10)};          
  100.           default: {bra, _bra} <= {1'b0, _bra};          
  101.         endcase // case (pha)
  102.      end
  103.    
  104.    // REGISTER FILE
  105.    reg [2:0] _rwa;
  106.    reg              _rwe;   
  107.    always @(posedge clk)
  108.      if (rst) begin
  109.         /*AUTORESET*/
  110.         // Beginning of autoreset for uninitialized flops
  111.         _rwa <= 3'h0;
  112.         _rwe <= 1'h0;
  113.         rra <= 3'h0;
  114.         rwa <= 3'h0;
  115.         rwe <= 1'h0;
  116.         // End of automatics
  117.      end else if (ena) begin
  118.         case (pha)
  119.           2'o3: rra <= decA[2:0];
  120.           2'o1: rra <= decA[2:0];
  121.           2'o2: rra <= decB[2:0];
  122.           2'o0: rra <= decB[2:0];          
  123.           //default: rra <= 3'oX;          
  124.         endcase // case (pha)

  125.         case (pha)
  126.           2'o0: {rwe} <= _rwe & CC & (opc[3:2] != 2'o3);          
  127.           default: {rwe} <= {1'b0};          
  128.         endcase // case (pha)
  129.        
  130.         case (pha)
  131.           2'o1: {rwa} <= {_rwa};          
  132.           default: {rwa} <= {rwa};          
  133.         endcase // case (pha)
  134.        
  135.         case (pha)
  136.           2'o0: begin
  137.              _rwa <= decA[2:0];
  138.              _rwe <= (decA[5:3] == 3'o0) & !_skp;             
  139.           end
  140.           default: {_rwa, _rwe} <= {_rwa, _rwe};          
  141.         endcase // case (pha)
  142.        
  143.      end
  144.    
  145. endmodule // dcpu16_ctl



复制代码
   




  1. /*
  2. DCPU16 Verilog Implementation
  3. Copyright (C) 2012 Shawn Tan <shawn.tan@sybreon.com>

  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as
  6. published by the Free Software Foundation, either version 3 of the
  7. License, or (at your option) any later version.  This program is
  8. distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11. for more details.

  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this program.  If not, see
  14. <http://www.gnu.org/licenses/>.  */

  15. /*
  16. MEMORY BUS

  17. Handles *all* the memory control signals for both F-BUS and A-BUS.
  18. */

  19. module dcpu16_mbus (/*AUTOARG*/
  20.    // Outputs
  21.    g_adr, g_stb, g_wre, f_adr, f_stb, f_wre, ena, wpc, regA, regB,
  22.    // Inputs
  23.    g_dti, g_ack, f_dti, f_ack, bra, CC, regR, rrd, ireg, regO, pha,
  24.    clk, rst
  25.    );

  26.    // Simplified Wishbone
  27.    output [15:0] g_adr;
  28.    output          g_stb,
  29.                  g_wre;
  30.    input [15:0]  g_dti;
  31.    input          g_ack;   

  32.    // Simplified Wishbone
  33.    output [15:0] f_adr;
  34.    output          f_stb,
  35.                  f_wre;
  36.    input [15:0]  f_dti;
  37.    input          f_ack;   
  38.    
  39.    // internal
  40.    output          ena;
  41.    output          wpc;   
  42.    output [15:0] regA,
  43.                  regB;

  44.    input          bra;
  45.    input          CC;   
  46.    input [15:0]  regR;   
  47.    input [15:0]  rrd;
  48.    input [15:0]  ireg;   
  49.    input [15:0]  regO;   

  50.    input [1:0]          pha;   
  51.    input          clk,
  52.                  rst;

  53.    /*AUTOREG*/
  54.    // Beginning of automatic regs (for this module's undeclared outputs)
  55.    reg [15:0]                f_adr;
  56.    reg                        f_stb;
  57.    reg                        f_wre;
  58.    reg [15:0]                g_adr;
  59.    reg                        g_stb;
  60.    reg [15:0]                regA;
  61.    reg [15:0]                regB;
  62.    reg                        wpc;
  63.    // End of automatics

  64.    reg                         wsp;   
  65.    reg [15:0]                 regSP,
  66.                         regPC;
  67.    
  68.    assign ena = (f_stb ~^ f_ack) & (g_stb ~^ g_ack); // pipe stall
  69.    
  70.    // repeated decoder
  71.    wire [5:0]                 decA, decB;
  72.    wire [3:0]                 decO;   
  73.    assign {decB, decA, decO} = ireg;   
  74.   
  75.    /*
  76.     0x00-0x07: register (A, B, C, X, Y, Z, I or J, in that order)
  77.     0x08-0x0f: [register]
  78. `    0x10-0x17: [next word + register]
  79.          0x18: POP / [SP++]
  80.          0x19: PEEK / [SP]
  81.          0x1a: PUSH / [--SP]
  82.          0x1b: SP
  83.          0x1c: PC
  84.          0x1d: O
  85.          0x1e: [next word]
  86.          0x1f: next word (literal)
  87.     0x20-0x3f: literal value 0x00-0x1f (literal)
  88.     */

  89.    // decode EA     
  90.    wire                 Fjsr = (ireg [4:0] == 5'h10);   

  91.    wire [5:0]                 ed = (pha[0]) ? decB : decA;   

  92.    wire                 Eind = (ed[5:3] == 3'o1); // [R]
  93.    wire                 Enwr = (ed[5:3] == 3'o2); // [[PC++] + R]
  94.    wire                 Epop = (ed[5:0] == 6'h18); // [SP++]
  95.    wire                 Epek = (ed[5:0] == 6'h19); // [SP]
  96.    wire                 Epsh = (ed[5:0] == 6'h1A); // [--SP]
  97.    wire                 Ersp = (ed[5:0] == 6'h1B); // SP
  98.    wire                 Erpc = (ed[5:0] == 6'h1C); // PC
  99.    wire                 Erro = (ed[5:0] == 6'h1D); // O
  100.    wire                 Enwi = (ed[5:0] == 6'h1E); // [PC++]
  101.    wire                 Esht = ed[5]; // xXX

  102.    wire [5:0]                 fg = (pha[0]) ? decA : decB;   

  103.    wire                 Fdir = (fg[5:3] == 3'o0); // R
  104.    wire                 Find = (fg[5:3] == 3'o1); // [R]
  105.    wire                 Fnwr = (fg[5:3] == 3'o2); // [[PC++] + R]
  106.    wire                 Fspi = (fg[5:0] == 6'h18); // [SP++]
  107.    wire                 Fspr = (fg[5:0] == 6'h19); // [SP]
  108.    wire                 Fspd = (fg[5:0] == 6'h1A); // [--SP]  
  109.    wire                 Frsp = (fg[5:0] == 6'h1B); // SP
  110.    wire                 Frpc = (fg[5:0] == 6'h1C); // PC
  111.    wire                 Fnwi = (fg[5:0] == 6'h1E); // [PC++]
  112.    wire                 Fnwl = (fg[5:0] == 6'h1F); // PC++   
  113.    
  114.    // PROGRAMME COUNTER - loadable binary up counter
  115.    reg [15:0]                 rpc;
  116.    reg                         lpc;  
  117.    
  118.    always @(posedge clk)
  119.      if (rst) begin
  120.         /*AUTORESET*/
  121.         // Beginning of autoreset for uninitialized flops
  122.         regPC <= 16'h0;
  123.         wpc <= 1'h0;
  124.         // End of automatics
  125.      end else if (ena) begin
  126.         if (lpc)
  127.           regPC <= rpc;
  128.         else
  129.           regPC <= regPC + 1;

  130.                case (pha)
  131.           2'o1: wpc <= Frpc & CC;
  132.           default: wpc <= wpc;          
  133.         endcase // case (pha)
  134.      end // if (ena)

  135.    always @(/*AUTOSENSE*/Fnwi or Fnwl or Fnwr or bra or pha or regB
  136.             or regPC or regR or wpc) begin      
  137.       case (pha)
  138.         2'o1: rpc <= (wpc) ? regR :
  139.                      (bra) ? regB :
  140.                      regPC;
  141.         default: rpc <= regPC;       
  142.       endcase // case (pha)
  143.       case (pha)
  144.         2'o3: lpc <= ~(Fnwr | Fnwi | Fnwl);
  145.         2'o0: lpc <= ~(Fnwr | Fnwi | Fnwl);
  146.         2'o1: lpc <= 1'b1;       
  147.         default: lpc <= 1'b0;       
  148.       endcase // case (pha)
  149.    end // always @ (...
  150.    
  151.    // STACK POINTER - loadable binary up/down counter   
  152.    reg [15:0] _rSP;
  153.    reg               lsp;
  154.    reg [15:0] rsp;
  155.    
  156.    always @(posedge clk)
  157.      if (rst) begin
  158.         regSP <= 16'hFFFF;
  159.         /*AUTORESET*/
  160.         // Beginning of autoreset for uninitialized flops
  161.         _rSP <= 16'h0;
  162.         wsp <= 1'h0;
  163.         // End of automatics
  164.      end else if (ena) begin
  165.         _rSP <= regSP; // backup SP

  166.         if (lsp) // manipulate SP
  167.           regSP <= rsp;
  168.         else if (fg[1] | Fjsr)
  169.           regSP <= regSP - 1;
  170.         else
  171.           regSP <= regSP + 1;

  172.         case (pha) // write to SP
  173.           2'o1: wsp <= Frsp & CC;          
  174.           default: wsp <= wsp;          
  175.         endcase // case (pha)
  176.      end // if (ena)

  177.    always @(/*AUTOSENSE*/Fjsr or Fspd or Fspi or pha or regR or regSP
  178.             or wsp) begin
  179.       case (pha)
  180.         2'o3: lsp <= ~(Fspi | Fspd | Fjsr);       
  181.         2'o0: lsp <= ~(Fspi | Fspd);
  182.         default: lsp <= 1'b1;       
  183.       endcase // case (pha)
  184.       
  185.       case (pha)
  186.         2'o1: rsp <= (wsp) ? regR :
  187.                      regSP;       
  188.         default: rsp <= regSP;       
  189.       endcase // case (pha)
  190.    end // always @ (...

  191.    // EA CALCULATOR
  192.    wire [15:0]                 nwr = rrd + g_dti;   // FIXME: Reduce this and combine with other ALU
  193.    reg [15:0]                 ea,
  194.                         eb;
  195.    reg [15:0]                 ec; // Calculated EA

  196.    always @(posedge clk)
  197.      if (rst) begin
  198.         /*AUTORESET*/
  199.         // Beginning of autoreset for uninitialized flops
  200.         ea <= 16'h0;
  201.         eb <= 16'h0;
  202.         // End of automatics
  203.      end else if (ena) begin
  204.         case (pha)
  205.           2'o0: ea <= (Fjsr) ? regSP : ec;          
  206.           default: ea <= ea;          
  207.         endcase // case (pha)

  208.         case (pha)
  209.           2'o1: eb <= ec;          
  210.           default: eb <= eb;          
  211.         endcase // case (pha)
  212.      end // if (ena)
  213.   
  214.    always @(/*AUTOSENSE*/Eind or Enwi or Enwr or Epek or Epop or Epsh
  215.             or _rSP or g_dti or nwr or regSP or rrd) begin
  216.       ec <= (Eind) ? rrd :
  217.             (Enwr) ? nwr :
  218.             //(Fjsr) ? decSP :
  219.             (Epsh) ? regSP :
  220.             (Epop | Epek) ? _rSP :
  221.             (Enwi) ? g_dti :
  222.             16'hX;      
  223.    end
  224.    
  225.    // G-BUS
  226.    assign g_wre = 1'b0;
  227.    
  228.    always @(posedge clk)
  229.      if (rst) begin
  230.         /*AUTORESET*/
  231.         // Beginning of autoreset for uninitialized flops
  232.         g_adr <= 16'h0;
  233.         g_stb <= 1'h0;
  234.         // End of automatics
  235.      end else if (ena) begin
  236.         case (pha)
  237.           2'o1: g_adr <= ea;
  238.           2'o2: g_adr <= eb;          
  239.           default: g_adr <= regPC;          
  240.         endcase // case (pha)

  241.         case (pha)
  242.           2'o3: g_stb <= Fnwr | Fnwi | Fnwl;
  243.           2'o0: g_stb <= Fnwr | Fnwi | Fnwl;
  244.           2'o1: g_stb <= Find | Fnwr | Fspr | Fspi | Fspd | Fnwi;
  245.           2'o2: g_stb <= Find | Fnwr | Fspr | Fspi | Fspd | Fnwi;          
  246.         endcase // case (pha)
  247.      end // if (ena)
  248.    

  249.    // F-BUS
  250.    reg [15:0] _adr;
  251.    reg               _stb, _wre;   
  252.    always @(posedge clk)
  253.      if (rst) begin
  254.         /*AUTORESET*/
  255.         // Beginning of autoreset for uninitialized flops
  256.         _adr <= 16'h0;
  257.         _stb <= 1'h0;
  258.         _wre <= 1'h0;
  259.         // End of automatics
  260.      end else if (ena) begin
  261.         case (pha)
  262.           2'o2: begin
  263.              _adr <= g_adr;
  264.              _stb <= g_stb | Fjsr;
  265.           end
  266.           default:begin
  267.              _adr <= _adr;
  268.              _stb <= _stb;             
  269.           end
  270.         endcase // case (pha)

  271.         case (pha)
  272.           2'o1: _wre <= Find | Fnwr | Fspr | Fspi | Fspd | Fnwi | Fjsr;             
  273.           default: _wre <= _wre;          
  274.         endcase // case (pha)
  275.        
  276.      end // if (ena)

  277.    always @(posedge clk)
  278.      if (rst) begin
  279.         /*AUTORESET*/
  280.         // Beginning of autoreset for uninitialized flops
  281.         f_adr <= 16'h0;
  282.         f_stb <= 1'h0;
  283.         f_wre <= 1'h0;
  284.         // End of automatics
  285.      end else if (ena) begin

  286.         case (pha)
  287.           2'o1: f_adr <= (wpc) ? regR :
  288.                          (bra) ? regB :
  289.                          regPC;
  290.           2'o0: f_adr <= _adr;          
  291.           default: f_adr <= 16'hX;          
  292.         endcase // case (pha)

  293.         case (pha)
  294.           2'o1: {f_stb,f_wre} <= (Fjsr) ? 2'o0 : 2'o2;
  295.           2'o0: {f_stb,f_wre} <= {_stb, _wre & CC};          
  296.           default: {f_stb,f_wre} <= 2'o0;          
  297.         endcase // case (pha)

  298.      end // if (ena)
  299.    
  300.    // REG-A/REG-B
  301.    reg                         _rd;
  302.    reg [15:0]                 opr;
  303.    
  304.    always @(posedge clk)
  305.      if (rst) begin
  306.         /*AUTORESET*/
  307.         // Beginning of autoreset for uninitialized flops
  308.         _rd <= 1'h0;
  309.         // End of automatics
  310.      end else if (ena)
  311.                case (pha)
  312.           2'o1: _rd <= Fdir;
  313.           2'o2: _rd <= Fdir;          
  314.           default: _rd <= 1'b0;          
  315.         endcase // case (pha)

  316.    always @(posedge clk)
  317.      if (rst) begin
  318.         /*AUTORESET*/
  319.         // Beginning of autoreset for uninitialized flops
  320.         regA <= 16'h0;
  321.         regB <= 16'h0;
  322.         // End of automatics
  323.      end else if (ena) begin
  324.         case (pha)
  325.           2'o0: regA <= opr;          
  326.           2'o2: regA <= (g_stb) ? g_dti :
  327.                         (Fjsr) ? regPC :
  328.                         (_rd) ? rrd :
  329.                         regA;             
  330.           default: regA <= regA;
  331.         endcase // case (pha)
  332.        
  333.         case (pha)
  334.           2'o1: regB <= opr;          
  335.           2'o3: regB <= (g_stb) ? g_dti :
  336.                         (_rd) ? rrd :
  337.                         regB;
  338.           default: regB <= regB;          
  339.         endcase // case (pha)
  340.      end // if (ena)

  341.    always @(/*AUTOSENSE*/Erpc or Erro or Ersp or Esht or ed or g_dti
  342.             or g_stb or regO or regPC or regSP) begin
  343.       opr <= (g_stb) ? g_dti :
  344.              (Ersp) ? regSP :
  345.              (Erpc) ? regPC :
  346.              (Erro) ? regO :
  347.              (Esht) ? {11'd0,ed[4:0]} :
  348.              16'hX;
  349.    end
  350.    
  351. endmodule // dcpu16_mbus

  352.   


复制代码
 楼主| 发表于 2012-7-11 11:25:54 | 显示全部楼层
本帖最后由 leo23h 于 2012-7-11 11:27 编辑

回复 2# leo23h
继续~




  1. /*
  2. DCPU16 Verilog Implementation
  3. Copyright (C) 2012 Shawn Tan <shawn.tan@sybreon.com>

  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as
  6. published by the Free Software Foundation, either version 3 of the
  7. License, or (at your option) any later version.  This program is
  8. distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11. for more details.

  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this program.  If not, see
  14. <http://www.gnu.org/licenses/>.  */

  15. module dcpu16_regs (/*AUTOARG*/
  16.    // Outputs
  17.    rrd,
  18.    // Inputs
  19.    rwd, rra, rwa, rwe, rst, ena, clk
  20.    );

  21.    output [15:0] rrd; // read data
  22.    input [15:0]  rwd; // write data
  23.    input [2:0]          rra, // read address
  24.                  rwa; // write address   
  25.    input          rwe; // write-enable
  26.    
  27.    input          rst,
  28.                  ena,
  29.                  clk;      
  30.    
  31.    reg [15:0]          file [0:7]; // A, B, C, X, Y, Z, I, J

  32.    reg [2:0]          r;

  33.    assign rrd = file[rra];   
  34.    
  35.    always @(posedge clk)
  36.      if (ena) begin
  37.         r <= rra;        
  38.         
  39.         if (rwe) begin
  40.            file[rwa] <= rwd;        
  41.         end
  42.      end
  43.         
  44. endmodule // dcpu16_regs



复制代码

[/code]
/*
DCPU16 Verilog Implementation
Copyright (C) 2012 Shawn Tan <shawn.tan@sybreon.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.  This program is
distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU Lesser General Public
License along with this program.  If not, see
<http://www.gnu.org/licenses/>;.  */
module dcpu16sim (/*AUTOARG*/);
   /*AUTOOUTPUT*/
   /*AUTOINPUT*/
   /*AUTOWIRE*/
   // Beginning of automatic wires (for undeclared instantiated-module outputs)
   wire [15:0]  f_adr;   // From ut0 of dcpu16_cpu.v
   wire [15:0]  f_dti;   // From ur0 of fasm_dpsram_wbr.v
   wire [15:0]  f_dto;   // From ut0 of dcpu16_cpu.v
   wire   f_stb;   // From ut0 of dcpu16_cpu.v
   wire   f_wre;   // From ut0 of dcpu16_cpu.v
   wire [15:0]  g_adr;   // From ut0 of dcpu16_cpu.v
   wire [15:0]  g_dti;   // From ur0 of fasm_dpsram_wbr.v
   wire [15:0]  g_dto;   // From ut0 of dcpu16_cpu.v
   wire   g_stb;   // From ut0 of dcpu16_cpu.v
   wire   g_wre;   // From ut0 of dcpu16_cpu.v
   // End of automatics
   /*AUTOREG*/
   reg    rst,
   clk;
   reg    f_ack, g_ack;
   
   
   initial begin
      $dumpfile ("dump.vcd");
      $dumpvars (2,ut0);
      
      clk = $random;
      rst = 1;
      #50 rst = 0;
      $readmemh ("dump.vmem", ur0.bram);      
      #5000 $displayh("\n*** TIMEOUT ", $stime, " ***");
      $finish;
   end // initial begin
   always #5 clk <= !clk;
   always @(negedge clk) begin
      f_ack <= f_stb;
      //& !f_ack;
      g_ack <= g_stb;
      //& !g_ack;      
   end

   /* fasm_dpsram_wbr AUTO_TEMPLATE (
    .AW(16),
    .DW(16),
   
    .xclk_i(~clk),
    .clk_i(~clk),
   
    .xwre_i(g_wre),
    .xstb_i(g_stb),
    .xadr_i(g_adr),
    .xdat_o(g_dti[15:0]),
    .xdat_i(g_dto[15:0]),
   
    .wre_i(f_wre),
    .stb_i(f_stb),
    .adr_i(f_adr),
    .dat_o(f_dti[15:0]),
    .dat_i(f_dto[15:0]),
   
    .rst_i(rst),
    .xrst_i(rst),
    ) */
   
   fasm_dpsram_wbr
     #(/*AUTOINSTPARAM*/
       // Parameters
       .AW    (16),    // Templated
       .DW    (16))    // Templated
     ur0 (/*AUTOINST*/
   // Outputs
   .dat_o   (f_dti[15:0]),   // Templated
   .xdat_o   (g_dti[15:0]),   // Templated
   // Inputs
   .dat_i   (f_dto[15:0]),   // Templated
   .adr_i   (f_adr),   // Templated
   .wre_i   (f_wre),   // Templated
   .stb_i   (f_stb),   // Templated
   .rst_i   (rst),    // Templated
   .clk_i   (~clk),    // Templated
   .xdat_i   (g_dto[15:0]),   // Templated
   .xadr_i   (g_adr),   // Templated
   .xwre_i   (g_wre),   // Templated
   .xstb_i   (g_stb),   // Templated
   .xrst_i   (rst),    // Templated
   .xclk_i   (~clk));    // Templated
   
   dcpu16_cpu
     ut0 (/*AUTOINST*/
   // Outputs
   .f_adr   (f_adr[15:0]),
   .f_dto   (f_dto[15:0]),
   .f_stb   (f_stb),
   .f_wre   (f_wre),
   .g_adr   (g_adr[15:0]),
   .g_dto   (g_dto[15:0]),
   .g_stb   (g_stb),
   .g_wre   (g_wre),
   // Inputs
   .clk    (clk),
   .f_ack   (f_ack),
   .f_dti   (f_dti[15:0]),
   .g_ack   (g_ack),
   .g_dti   (g_dti[15:0]),
   .rst    (rst));   
   integer i;
   initial begin
      for (i=0; i<8; i=i+1) begin
  ut0.r0.file <= $random;  
      end
   end
   
endmodule // dcpu16sim
// Local Variables:
// verilog-library-directories"." "../../rtl/verilog/")
// verilog-library-files"")
// End:


[/code]
 楼主| 发表于 2012-7-11 11:33:57 | 显示全部楼层
回复 2# leo23h
继续~






  1. /* $Id: fasm_dpsram.v,v 1.3 2008/06/05 20:51:56 sybreon Exp $
  2. **
  3. ** FASM MEMORY LIBRARY
  4. ** Copyright (C) 2004-2009 Shawn Tan <shawn.tan@aeste.net>
  5. ** All rights reserved.
  6. **
  7. ** FASM is free software: you can redistribute it and/or modify it
  8. ** under the terms of the GNU Lesser General Public License as
  9. ** published by the Free Software Foundation, either version 3 of the
  10. ** License, or (at your option) any later version.
  11. **
  12. ** FASM is distributed in the hope that it will be useful, but WITHOUT
  13. ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  14. ** or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
  15. ** Public License for more details.
  16. **
  17. ** You should have received a copy of the GNU Lesser General Public
  18. ** License along with FASM. If not, see <http:**www.gnu.org/licenses/>.
  19. */
  20. /*
  21. * DUAL PORT SYNCHRONOUS RAM - WRITE-BEFORE-READ
  22. * Synthesis proven on:
  23. * - Xilinx ISE
  24. * - Altera Quartus (>=8.0)
  25. */

  26. module fasm_dpsram_wbr (/*AUTOARG*/
  27.    // Outputs
  28.    dat_o, xdat_o,
  29.    // Inputs
  30.    dat_i, adr_i, wre_i, stb_i, rst_i, clk_i, xdat_i, xadr_i, xwre_i,
  31.    xstb_i, xrst_i, xclk_i
  32.    );

  33.    parameter AW = 8;  ///< address space (2^AW) words
  34.    parameter DW = 32; ///< data word width bits

  35.    // wishbone port a
  36.    output [DW-1:0] dat_o; // DO
  37.    input [DW-1:0]  dat_i; // DI
  38.    input [AW-1:0]  adr_i; // A
  39.    input            wre_i; // WE
  40.    input            stb_i; // CS
  41.    
  42.    input            rst_i,
  43.                    clk_i;

  44.    // wishbone port x
  45.    output [DW-1:0] xdat_o; // DO
  46.    input [DW-1:0]  xdat_i; // DI
  47.    input [AW-1:0]  xadr_i; // A
  48.    input            xwre_i; // WE
  49.    input            xstb_i; // CS
  50.    
  51.    input            xrst_i,
  52.                    xclk_i;
  53.    
  54.    // address latch
  55.    reg [AW-1:0]    rA, rX;   
  56.    
  57.    // memory block
  58.    reg [DW-1:0]    bram [(1<<AW)-1:0];
  59.    
  60.    always @(posedge xclk_i)
  61.      if (xstb_i)
  62.        begin
  63.           rX <= xadr_i;          
  64.           if (xwre_i) // strobe and write-enable
  65.             bram[xadr_i] <= xdat_i;          
  66.        end
  67.    always @(posedge clk_i)
  68.      if (stb_i)
  69.        begin
  70.           rA <= adr_i;          
  71.           if (wre_i) // strobe and write-enable
  72.             bram[adr_i] <= dat_i;          
  73.        end

  74.    assign            xdat_o = bram[rX]; // write-thru
  75.    assign            dat_o = bram[rA]; // write-thru
  76.    
  77.    // ### SIMULATION ONLY ###
  78.    // synopsys translate_off
  79.    integer i;
  80.    initial begin
  81.       for (i=0; i<(1<<AW); i=i+1) begin
  82.          bram[i] <= $random;         
  83.       end
  84.    end
  85.    // synopsys translate_on
  86.    
  87. endmodule // fasm_dpsram_wbr



复制代码
发表于 2012-7-11 14:03:09 | 显示全部楼层
你太牛了,这是你们的设计代码么,我觉得这个得慢慢看,或者用rtl viewer看看结构!
太长了
 楼主| 发表于 2012-7-11 16:10:24 | 显示全部楼层
回复 5# SKILLER

这是一个微处理器的code~目前就知道这些
发表于 2012-7-11 23:17:28 | 显示全部楼层
编译和代码检查工具的使用是王道。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条

X

小黑屋| 手机版| 关于我们| 联系我们| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2025-6-7 02:31 , Processed in 0.428364 second(s), 11 queries , Gzip On, MemCached On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表