rtl/lm32_top.v

Sat, 06 Aug 2011 01:32:07 +0100

author
Philip Pemberton <philpem@philpem.me.uk>
date
Sat, 06 Aug 2011 01:32:07 +0100
changeset 28
da23ab8ef7b4
parent 26
lm32_top.v@73de224304c1
parent 24
lm32_top.v@c336e674a37e
permissions
-rw-r--r--

Merge LM32 v3.8 into local mainline

Changes in this release:
FEATURE: Support for dynamically switching EBA to DEBA via a GPIO
BUGFIX: EA now reports instruction which caused the data abort, rather than the instruction following it
STYLE: Update comments to refer to latest Lattice license

philpem@26 1 // ==================================================================
philpem@26 2 // >>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<<
philpem@26 3 // ------------------------------------------------------------------
philpem@26 4 // Copyright (c) 2006-2011 by Lattice Semiconductor Corporation
philpem@26 5 // ALL RIGHTS RESERVED
philpem@26 6 // ------------------------------------------------------------------
philpem@26 7 //
philpem@26 8 // IMPORTANT: THIS FILE IS AUTO-GENERATED BY THE LATTICEMICO SYSTEM.
philpem@26 9 //
philpem@26 10 // Permission:
philpem@26 11 //
philpem@26 12 // Lattice Semiconductor grants permission to use this code
philpem@26 13 // pursuant to the terms of the Lattice Semiconductor Corporation
philpem@26 14 // Open Source License Agreement.
philpem@26 15 //
philpem@26 16 // Disclaimer:
philpem@0 17 //
philpem@26 18 // Lattice Semiconductor provides no warranty regarding the use or
philpem@26 19 // functionality of this code. It is the user's responsibility to
philpem@26 20 // verify the user’s design for consistency and functionality through
philpem@26 21 // the use of formal verification methods.
philpem@26 22 //
philpem@26 23 // --------------------------------------------------------------------
philpem@26 24 //
philpem@26 25 // Lattice Semiconductor Corporation
philpem@26 26 // 5555 NE Moore Court
philpem@26 27 // Hillsboro, OR 97214
philpem@26 28 // U.S.A
philpem@26 29 //
philpem@26 30 // TEL: 1-800-Lattice (USA and Canada)
philpem@26 31 // 503-286-8001 (other locations)
philpem@26 32 //
philpem@26 33 // web: http://www.latticesemi.com/
philpem@26 34 // email: techsupport@latticesemi.com
philpem@26 35 //
philpem@26 36 // --------------------------------------------------------------------
philpem@0 37 // FILE DETAILS
philpem@0 38 // Project : LatticeMico32
philpem@0 39 // File : lm32_top.v
philpem@0 40 // Title : Top-level of CPU.
philpem@0 41 // Dependencies : lm32_include.v
philpem@0 42 // Version : 6.1.17
philpem@0 43 // : removed SPI - 04/12/07
philpem@0 44 // Version : 7.0SP2, 3.0
philpem@0 45 // : No Change
philpem@0 46 // Version : 3.1
philpem@0 47 // : No Change
philpem@0 48 // =============================================================================
philpem@0 49
philpem@0 50 `include "lm32_include.v"
philpem@0 51
philpem@0 52 /////////////////////////////////////////////////////
philpem@0 53 // Module interface
philpem@0 54 /////////////////////////////////////////////////////
philpem@0 55
philpem@0 56 module lm32_top (
philpem@0 57 // ----- Inputs -------
philpem@0 58 clk_i,
philpem@0 59 rst_i,
philpem@26 60 `ifdef CFG_DEBUG_ENABLED
philpem@26 61 `ifdef CFG_ALTERNATE_EBA
philpem@26 62 at_debug,
philpem@26 63 `endif
philpem@26 64 `endif
philpem@0 65 // From external devices
philpem@0 66 `ifdef CFG_INTERRUPTS_ENABLED
philpem@12 67 interrupt,
philpem@0 68 `endif
philpem@0 69 // From user logic
philpem@0 70 `ifdef CFG_USER_ENABLED
philpem@0 71 user_result,
philpem@0 72 user_complete,
philpem@0 73 `endif
philpem@0 74 `ifdef CFG_IWB_ENABLED
philpem@0 75 // Instruction Wishbone master
philpem@0 76 I_DAT_I,
philpem@0 77 I_ACK_I,
philpem@0 78 I_ERR_I,
philpem@0 79 I_RTY_I,
philpem@0 80 `endif
philpem@0 81 // Data Wishbone master
philpem@0 82 D_DAT_I,
philpem@0 83 D_ACK_I,
philpem@0 84 D_ERR_I,
philpem@0 85 D_RTY_I,
philpem@0 86 // ----- Outputs -------
philpem@0 87 `ifdef CFG_USER_ENABLED
philpem@0 88 user_valid,
philpem@0 89 user_opcode,
philpem@0 90 user_operand_0,
philpem@0 91 user_operand_1,
philpem@0 92 `endif
philpem@0 93 `ifdef CFG_IWB_ENABLED
philpem@0 94 // Instruction Wishbone master
philpem@0 95 I_DAT_O,
philpem@0 96 I_ADR_O,
philpem@0 97 I_CYC_O,
philpem@0 98 I_SEL_O,
philpem@0 99 I_STB_O,
philpem@0 100 I_WE_O,
philpem@0 101 I_CTI_O,
philpem@0 102 I_LOCK_O,
philpem@0 103 I_BTE_O,
philpem@0 104 `endif
philpem@0 105 // Data Wishbone master
philpem@0 106 D_DAT_O,
philpem@0 107 D_ADR_O,
philpem@0 108 D_CYC_O,
philpem@0 109 D_SEL_O,
philpem@0 110 D_STB_O,
philpem@0 111 D_WE_O,
philpem@0 112 D_CTI_O,
philpem@0 113 D_LOCK_O,
philpem@14 114 D_BTE_O
philpem@0 115 );
philpem@0 116
philpem@0 117 /////////////////////////////////////////////////////
philpem@0 118 // Inputs
philpem@0 119 /////////////////////////////////////////////////////
philpem@0 120
philpem@0 121 input clk_i; // Clock
philpem@0 122 input rst_i; // Reset
philpem@0 123
philpem@26 124 `ifdef CFG_DEBUG_ENABLED
philpem@26 125 `ifdef CFG_ALTERNATE_EBA
philpem@26 126 input at_debug; // GPIO input that maps EBA to DEBA
philpem@26 127 `endif
philpem@26 128 `endif
philpem@26 129
philpem@0 130 `ifdef CFG_INTERRUPTS_ENABLED
philpem@12 131 input [`LM32_INTERRUPT_RNG] interrupt; // Interrupt pins
philpem@0 132 `endif
philpem@0 133
philpem@0 134 `ifdef CFG_USER_ENABLED
philpem@0 135 input [`LM32_WORD_RNG] user_result; // User-defined instruction result
philpem@0 136 input user_complete; // Indicates the user-defined instruction result is valid
philpem@0 137 `endif
philpem@0 138
philpem@0 139 `ifdef CFG_IWB_ENABLED
philpem@0 140 input [`LM32_WORD_RNG] I_DAT_I; // Instruction Wishbone interface read data
philpem@0 141 input I_ACK_I; // Instruction Wishbone interface acknowledgement
philpem@0 142 input I_ERR_I; // Instruction Wishbone interface error
philpem@0 143 input I_RTY_I; // Instruction Wishbone interface retry
philpem@0 144 `endif
philpem@0 145
philpem@0 146 input [`LM32_WORD_RNG] D_DAT_I; // Data Wishbone interface read data
philpem@0 147 input D_ACK_I; // Data Wishbone interface acknowledgement
philpem@0 148 input D_ERR_I; // Data Wishbone interface error
philpem@0 149 input D_RTY_I; // Data Wishbone interface retry
philpem@0 150
philpem@0 151 /////////////////////////////////////////////////////
philpem@0 152 // Outputs
philpem@0 153 /////////////////////////////////////////////////////
philpem@0 154
philpem@0 155 `ifdef CFG_USER_ENABLED
philpem@0 156 output user_valid; // Indicates that user_opcode and user_operand_* are valid
philpem@0 157 wire user_valid;
philpem@0 158 output [`LM32_USER_OPCODE_RNG] user_opcode; // User-defined instruction opcode
philpem@0 159 reg [`LM32_USER_OPCODE_RNG] user_opcode;
philpem@0 160 output [`LM32_WORD_RNG] user_operand_0; // First operand for user-defined instruction
philpem@0 161 wire [`LM32_WORD_RNG] user_operand_0;
philpem@0 162 output [`LM32_WORD_RNG] user_operand_1; // Second operand for user-defined instruction
philpem@0 163 wire [`LM32_WORD_RNG] user_operand_1;
philpem@0 164 `endif
philpem@0 165
philpem@0 166 `ifdef CFG_IWB_ENABLED
philpem@0 167 output [`LM32_WORD_RNG] I_DAT_O; // Instruction Wishbone interface write data
philpem@0 168 wire [`LM32_WORD_RNG] I_DAT_O;
philpem@0 169 output [`LM32_WORD_RNG] I_ADR_O; // Instruction Wishbone interface address
philpem@0 170 wire [`LM32_WORD_RNG] I_ADR_O;
philpem@0 171 output I_CYC_O; // Instruction Wishbone interface cycle
philpem@0 172 wire I_CYC_O;
philpem@0 173 output [`LM32_BYTE_SELECT_RNG] I_SEL_O; // Instruction Wishbone interface byte select
philpem@0 174 wire [`LM32_BYTE_SELECT_RNG] I_SEL_O;
philpem@0 175 output I_STB_O; // Instruction Wishbone interface strobe
philpem@0 176 wire I_STB_O;
philpem@0 177 output I_WE_O; // Instruction Wishbone interface write enable
philpem@0 178 wire I_WE_O;
philpem@0 179 output [`LM32_CTYPE_RNG] I_CTI_O; // Instruction Wishbone interface cycle type
philpem@0 180 wire [`LM32_CTYPE_RNG] I_CTI_O;
philpem@0 181 output I_LOCK_O; // Instruction Wishbone interface lock bus
philpem@0 182 wire I_LOCK_O;
philpem@0 183 output [`LM32_BTYPE_RNG] I_BTE_O; // Instruction Wishbone interface burst type
philpem@0 184 wire [`LM32_BTYPE_RNG] I_BTE_O;
philpem@0 185 `endif
philpem@0 186
philpem@0 187 output [`LM32_WORD_RNG] D_DAT_O; // Data Wishbone interface write data
philpem@0 188 wire [`LM32_WORD_RNG] D_DAT_O;
philpem@0 189 output [`LM32_WORD_RNG] D_ADR_O; // Data Wishbone interface address
philpem@0 190 wire [`LM32_WORD_RNG] D_ADR_O;
philpem@0 191 output D_CYC_O; // Data Wishbone interface cycle
philpem@0 192 wire D_CYC_O;
philpem@0 193 output [`LM32_BYTE_SELECT_RNG] D_SEL_O; // Data Wishbone interface byte select
philpem@0 194 wire [`LM32_BYTE_SELECT_RNG] D_SEL_O;
philpem@0 195 output D_STB_O; // Data Wishbone interface strobe
philpem@0 196 wire D_STB_O;
philpem@0 197 output D_WE_O; // Data Wishbone interface write enable
philpem@0 198 wire D_WE_O;
philpem@0 199 output [`LM32_CTYPE_RNG] D_CTI_O; // Data Wishbone interface cycle type
philpem@0 200 wire [`LM32_CTYPE_RNG] D_CTI_O;
philpem@0 201 output D_LOCK_O; // Date Wishbone interface lock bus
philpem@0 202 wire D_LOCK_O;
philpem@0 203 output [`LM32_BTYPE_RNG] D_BTE_O; // Data Wishbone interface burst type
philpem@0 204 wire [`LM32_BTYPE_RNG] D_BTE_O;
philpem@0 205
philpem@0 206 /////////////////////////////////////////////////////
philpem@0 207 // Internal nets and registers
philpem@0 208 /////////////////////////////////////////////////////
philpem@0 209
philpem@0 210 `ifdef CFG_JTAG_ENABLED
philpem@0 211 // Signals between JTAG interface and CPU
philpem@0 212 wire [`LM32_BYTE_RNG] jtag_reg_d;
philpem@0 213 wire [`LM32_BYTE_RNG] jtag_reg_q;
philpem@0 214 wire jtag_update;
philpem@0 215 wire [2:0] jtag_reg_addr_d;
philpem@0 216 wire [2:0] jtag_reg_addr_q;
philpem@0 217 wire jtck;
philpem@0 218 wire jrstn;
philpem@0 219 `endif
philpem@0 220
philpem@14 221 // TODO: get the trace signals out
philpem@0 222 `ifdef CFG_TRACE_ENABLED
philpem@0 223 // PC trace signals
philpem@0 224 wire [`LM32_PC_RNG] trace_pc; // PC to trace (address of next non-sequential instruction)
philpem@0 225 wire trace_pc_valid; // Indicates that a new trace PC is valid
philpem@0 226 wire trace_exception; // Indicates an exception has occured
philpem@0 227 wire [`LM32_EID_RNG] trace_eid; // Indicates what type of exception has occured
philpem@0 228 wire trace_eret; // Indicates an eret instruction has been executed
philpem@0 229 `ifdef CFG_DEBUG_ENABLED
philpem@0 230 wire trace_bret; // Indicates a bret instruction has been executed
philpem@0 231 `endif
philpem@0 232 `endif
philpem@0 233
philpem@0 234 /////////////////////////////////////////////////////
philpem@0 235 // Functions
philpem@0 236 /////////////////////////////////////////////////////
philpem@0 237
philpem@0 238 `include "lm32_functions.v"
philpem@0 239 /////////////////////////////////////////////////////
philpem@0 240 // Instantiations
philpem@0 241 /////////////////////////////////////////////////////
philpem@12 242
philpem@12 243 // LM32 CPU
philpem@0 244 lm32_cpu cpu (
philpem@0 245 // ----- Inputs -------
philpem@0 246 .clk_i (clk_i),
philpem@0 247 `ifdef CFG_EBR_NEGEDGE_REGISTER_FILE
philpem@0 248 .clk_n_i (clk_n),
philpem@0 249 `endif
philpem@0 250 .rst_i (rst_i),
philpem@26 251 `ifdef CFG_DEBUG_ENABLED
philpem@26 252 `ifdef CFG_ALTERNATE_EBA
philpem@26 253 .at_debug (at_debug),
philpem@26 254 `endif
philpem@26 255 `endif
philpem@0 256 // From external devices
philpem@0 257 `ifdef CFG_INTERRUPTS_ENABLED
philpem@12 258 .interrupt (interrupt),
philpem@0 259 `endif
philpem@0 260 // From user logic
philpem@0 261 `ifdef CFG_USER_ENABLED
philpem@0 262 .user_result (user_result),
philpem@0 263 .user_complete (user_complete),
philpem@0 264 `endif
philpem@0 265 `ifdef CFG_JTAG_ENABLED
philpem@0 266 // From JTAG
philpem@0 267 .jtag_clk (jtck),
philpem@0 268 .jtag_update (jtag_update),
philpem@0 269 .jtag_reg_q (jtag_reg_q),
philpem@0 270 .jtag_reg_addr_q (jtag_reg_addr_q),
philpem@0 271 `endif
philpem@0 272 `ifdef CFG_IWB_ENABLED
philpem@0 273 // Instruction Wishbone master
philpem@0 274 .I_DAT_I (I_DAT_I),
philpem@0 275 .I_ACK_I (I_ACK_I),
philpem@0 276 .I_ERR_I (I_ERR_I),
philpem@0 277 .I_RTY_I (I_RTY_I),
philpem@0 278 `endif
philpem@0 279 // Data Wishbone master
philpem@0 280 .D_DAT_I (D_DAT_I),
philpem@0 281 .D_ACK_I (D_ACK_I),
philpem@0 282 .D_ERR_I (D_ERR_I),
philpem@0 283 .D_RTY_I (D_RTY_I),
philpem@0 284 // ----- Outputs -------
philpem@0 285 `ifdef CFG_TRACE_ENABLED
philpem@0 286 .trace_pc (trace_pc),
philpem@0 287 .trace_pc_valid (trace_pc_valid),
philpem@0 288 .trace_exception (trace_exception),
philpem@0 289 .trace_eid (trace_eid),
philpem@0 290 .trace_eret (trace_eret),
philpem@0 291 `ifdef CFG_DEBUG_ENABLED
philpem@0 292 .trace_bret (trace_bret),
philpem@0 293 `endif
philpem@0 294 `endif
philpem@0 295 `ifdef CFG_JTAG_ENABLED
philpem@0 296 .jtag_reg_d (jtag_reg_d),
philpem@0 297 .jtag_reg_addr_d (jtag_reg_addr_d),
philpem@0 298 `endif
philpem@0 299 `ifdef CFG_USER_ENABLED
philpem@0 300 .user_valid (user_valid),
philpem@0 301 .user_opcode (user_opcode),
philpem@0 302 .user_operand_0 (user_operand_0),
philpem@0 303 .user_operand_1 (user_operand_1),
philpem@0 304 `endif
philpem@0 305 `ifdef CFG_IWB_ENABLED
philpem@0 306 // Instruction Wishbone master
philpem@0 307 .I_DAT_O (I_DAT_O),
philpem@0 308 .I_ADR_O (I_ADR_O),
philpem@0 309 .I_CYC_O (I_CYC_O),
philpem@0 310 .I_SEL_O (I_SEL_O),
philpem@0 311 .I_STB_O (I_STB_O),
philpem@0 312 .I_WE_O (I_WE_O),
philpem@0 313 .I_CTI_O (I_CTI_O),
philpem@0 314 .I_LOCK_O (I_LOCK_O),
philpem@0 315 .I_BTE_O (I_BTE_O),
philpem@0 316 `endif
philpem@0 317 // Data Wishbone master
philpem@0 318 .D_DAT_O (D_DAT_O),
philpem@0 319 .D_ADR_O (D_ADR_O),
philpem@0 320 .D_CYC_O (D_CYC_O),
philpem@0 321 .D_SEL_O (D_SEL_O),
philpem@0 322 .D_STB_O (D_STB_O),
philpem@0 323 .D_WE_O (D_WE_O),
philpem@0 324 .D_CTI_O (D_CTI_O),
philpem@0 325 .D_LOCK_O (D_LOCK_O),
philpem@0 326 .D_BTE_O (D_BTE_O)
philpem@0 327 );
philpem@0 328
philpem@0 329 wire TRACE_ACK_O;
philpem@0 330 wire [`LM32_WORD_RNG] TRACE_DAT_O;
philpem@0 331 `ifdef CFG_TRACE_ENABLED
philpem@0 332 lm32_trace trace_module (.clk_i (clk_i),
philpem@0 333 .rst_i (rst_i),
philpem@0 334 .stb_i (DEBUG_STB_I & DEBUG_ADR_I[13]),
philpem@0 335 .we_i (DEBUG_WE_I),
philpem@0 336 .sel_i (DEBUG_SEL_I),
philpem@0 337 .dat_i (DEBUG_DAT_I),
philpem@0 338 .adr_i (DEBUG_ADR_I),
philpem@0 339 .trace_pc (trace_pc),
philpem@0 340 .trace_eid (trace_eid),
philpem@0 341 .trace_eret (trace_eret),
philpem@0 342 .trace_bret (trace_bret),
philpem@0 343 .trace_pc_valid (trace_pc_valid),
philpem@0 344 .trace_exception (trace_exception),
philpem@0 345 .ack_o (TRACE_ACK_O),
philpem@0 346 .dat_o (TRACE_DAT_O));
philpem@0 347 `else
philpem@0 348 assign TRACE_ACK_O = 0;
philpem@0 349 assign TRACE_DAT_O = 0;
philpem@0 350 `endif
philpem@0 351 `ifdef DEBUG_ROM
philpem@0 352 wire ROM_ACK_O;
philpem@0 353 wire [`LM32_WORD_RNG] ROM_DAT_O;
philpem@0 354
philpem@0 355 assign DEBUG_ACK_O = DEBUG_ADR_I[13] ? TRACE_ACK_O : ROM_ACK_O;
philpem@0 356 assign DEBUG_DAT_O = DEBUG_ADR_I[13] ? TRACE_DAT_O : ROM_DAT_O;
philpem@0 357
philpem@0 358 // ROM monitor
philpem@0 359 lm32_monitor debug_rom (
philpem@0 360 // ----- Inputs -------
philpem@0 361 .clk_i (clk_i),
philpem@0 362 .rst_i (rst_i),
philpem@8 363 .MON_ADR_I (DEBUG_ADR_I[10:2]),
philpem@0 364 .MON_STB_I (DEBUG_STB_I & ~DEBUG_ADR_I[13]),
philpem@0 365 .MON_CYC_I (DEBUG_CYC_I & ~DEBUG_ADR_I[13]),
philpem@0 366 .MON_WE_I (DEBUG_WE_I),
philpem@0 367 .MON_SEL_I (DEBUG_SEL_I),
philpem@0 368 .MON_DAT_I (DEBUG_DAT_I),
philpem@0 369 // ----- Outputs ------
philpem@0 370 .MON_RTY_O (DEBUG_RTY_O),
philpem@0 371 .MON_ERR_O (DEBUG_ERR_O),
philpem@0 372 .MON_ACK_O (ROM_ACK_O),
philpem@0 373 .MON_DAT_O (ROM_DAT_O)
philpem@0 374 );
philpem@0 375 `endif
philpem@0 376
philpem@0 377 `ifdef CFG_JTAG_ENABLED
philpem@0 378 // JTAG cores
philpem@0 379 jtag_cores jtag_cores (
philpem@0 380 // ----- Inputs -----
philpem@0 381 .reg_d (jtag_reg_d),
philpem@0 382 .reg_addr_d (jtag_reg_addr_d),
philpem@0 383 // ----- Outputs -----
philpem@0 384 .reg_update (jtag_update),
philpem@0 385 .reg_q (jtag_reg_q),
philpem@0 386 .reg_addr_q (jtag_reg_addr_q),
philpem@0 387 .jtck (jtck),
philpem@0 388 .jrstn (jrstn)
philpem@0 389 );
philpem@0 390 `endif
philpem@0 391
philpem@0 392 endmodule