rtl/lm32_include.v

Sat, 06 Aug 2011 01:34:41 +0100

author
Philip Pemberton <philpem@philpem.me.uk>
date
Sat, 06 Aug 2011 01:34:41 +0100
changeset 30
614f58128bcc
parent 28
da23ab8ef7b4
permissions
-rw-r--r--

Merge LM32 v3.8 docs in

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_include.v
philpem@0 40 // Title : CPU global macros
philpem@0 41 // Version : 6.1.17
philpem@0 42 // : Initial Release
philpem@0 43 // Version : 7.0SP2, 3.0
philpem@0 44 // : No Change
philpem@0 45 // Version : 3.1
philpem@0 46 // : No Change
philpem@0 47 // Version : 3.2
philpem@0 48 // : No Change
philpem@0 49 // Version : 3.3
philpem@0 50 // : Support for extended configuration register
philpem@0 51 // =============================================================================
philpem@0 52
philpem@0 53 `ifdef LM32_INCLUDE_V
philpem@0 54 `else
philpem@0 55 `define LM32_INCLUDE_V
philpem@0 56
philpem@1 57 //
philpem@1 58 // Common configuration options
philpem@1 59 //
philpem@1 60
philpem@21 61 `define CFG_EBA_RESET 32'h00000000
philpem@21 62 `define CFG_DEBA_RESET 32'h10000000
philpem@1 63
philpem@1 64 `define CFG_PL_MULTIPLY_ENABLED
philpem@1 65 `define CFG_PL_BARREL_SHIFT_ENABLED
philpem@1 66 `define CFG_SIGN_EXTEND_ENABLED
philpem@1 67 `define CFG_MC_DIVIDE_ENABLED
philpem@21 68 `define CFG_EBR_POSEDGE_REGISTER_FILE
philpem@1 69
philpem@4 70 // [found by Milkymist dev'rs]
philpem@4 71 // Bug in Xst:
philpem@4 72 // CFG_ICACHE_ASSOCIATIVITY=2 => works in most cases (random crash on complex software)
philpem@4 73 // CFG_ICACHE_ASSOCIATIVITY=1 => disaster, CPU will not work at all
philpem@4 74 // Works 100% OK with expensive synthesizers.
philpem@6 75 `define CFG_ICACHE_ENABLED
philpem@21 76 `define CFG_ICACHE_ASSOCIATIVITY 1
philpem@21 77 `define CFG_ICACHE_SETS 256
philpem@21 78 `define CFG_ICACHE_BYTES_PER_LINE 16
philpem@1 79 `define CFG_ICACHE_BASE_ADDRESS 32'h0
philpem@6 80 `define CFG_ICACHE_LIMIT 32'h7FFF_FFFF
philpem@1 81
philpem@1 82 `define CFG_DCACHE_ENABLED
philpem@21 83 `define CFG_DCACHE_ASSOCIATIVITY 1
philpem@21 84 `define CFG_DCACHE_SETS 256
philpem@21 85 `define CFG_DCACHE_BYTES_PER_LINE 16
philpem@1 86 `define CFG_DCACHE_BASE_ADDRESS 32'h0
philpem@6 87 `define CFG_DCACHE_LIMIT 32'h0FFF_FFFF
philpem@6 88
philpem@21 89 // Enable Debugging
philpem@21 90 //`define CFG_JTAG_ENABLED
philpem@21 91 //`define CFG_JTAG_UART_ENABLED
philpem@21 92 //`define CFG_DEBUG_ENABLED
philpem@21 93 //`define CFG_HW_DEBUG_ENABLED
philpem@21 94 //`define CFG_ROM_DEBUG_ENABLED
philpem@21 95 //`define CFG_BREAKPOINTS 32'h0
philpem@21 96 //`define CFG_WATCHPOINTS 32'h0
philpem@21 97
philpem@1 98 //
philpem@1 99 // End of common configuration options
philpem@1 100 //
philpem@0 101
philpem@0 102 `ifdef TRUE
philpem@0 103 `else
philpem@0 104 `define TRUE 1'b1
philpem@0 105 `define FALSE 1'b0
philpem@0 106 `define TRUE_N 1'b0
philpem@0 107 `define FALSE_N 1'b1
philpem@0 108 `endif
philpem@0 109
philpem@0 110 // Wishbone configuration
philpem@0 111 `define CFG_IWB_ENABLED
philpem@0 112 `define CFG_DWB_ENABLED
philpem@0 113
philpem@0 114 // Data-path width
philpem@0 115 `define LM32_WORD_WIDTH 32
philpem@0 116 `define LM32_WORD_RNG (`LM32_WORD_WIDTH-1):0
philpem@0 117 `define LM32_SHIFT_WIDTH 5
philpem@0 118 `define LM32_SHIFT_RNG (`LM32_SHIFT_WIDTH-1):0
philpem@0 119 `define LM32_BYTE_SELECT_WIDTH 4
philpem@0 120 `define LM32_BYTE_SELECT_RNG (`LM32_BYTE_SELECT_WIDTH-1):0
philpem@0 121
philpem@0 122 // Register file size
philpem@0 123 `define LM32_REGISTERS 32
philpem@0 124 `define LM32_REG_IDX_WIDTH 5
philpem@0 125 `define LM32_REG_IDX_RNG (`LM32_REG_IDX_WIDTH-1):0
philpem@0 126
philpem@0 127 // Standard register numbers
philpem@0 128 `define LM32_RA_REG `LM32_REG_IDX_WIDTH'd29
philpem@0 129 `define LM32_EA_REG `LM32_REG_IDX_WIDTH'd30
philpem@0 130 `define LM32_BA_REG `LM32_REG_IDX_WIDTH'd31
philpem@0 131
philpem@0 132 // Range of Program Counter. Two LSBs are always 0.
philpem@0 133 // `ifdef CFG_ICACHE_ENABLED
philpem@0 134 // `define LM32_PC_WIDTH (clogb2(`CFG_ICACHE_LIMIT-`CFG_ICACHE_BASE_ADDRESS)-2)
philpem@0 135 // `else
philpem@0 136 // `ifdef CFG_IWB_ENABLED
philpem@0 137 `define LM32_PC_WIDTH (`LM32_WORD_WIDTH-2)
philpem@0 138 // `else
philpem@0 139 // `define LM32_PC_WIDTH `LM32_IROM_ADDRESS_WIDTH
philpem@0 140 // `endif
philpem@0 141 // `endif
philpem@0 142 `define LM32_PC_RNG (`LM32_PC_WIDTH+2-1):2
philpem@0 143
philpem@0 144 // Range of an instruction
philpem@0 145 `define LM32_INSTRUCTION_WIDTH 32
philpem@0 146 `define LM32_INSTRUCTION_RNG (`LM32_INSTRUCTION_WIDTH-1):0
philpem@0 147
philpem@0 148 // Adder operation
philpem@0 149 `define LM32_ADDER_OP_ADD 1'b0
philpem@0 150 `define LM32_ADDER_OP_SUBTRACT 1'b1
philpem@0 151
philpem@0 152 // Shift direction
philpem@0 153 `define LM32_SHIFT_OP_RIGHT 1'b0
philpem@0 154 `define LM32_SHIFT_OP_LEFT 1'b1
philpem@0 155
philpem@21 156 // Bus errors
philpem@21 157 //`define CFG_BUS_ERRORS_ENABLED
philpem@0 158
philpem@0 159 // Derive macro that indicates whether we have single-stepping or not
philpem@0 160 `ifdef CFG_ROM_DEBUG_ENABLED
philpem@0 161 `define LM32_SINGLE_STEP_ENABLED
philpem@0 162 `else
philpem@0 163 `ifdef CFG_HW_DEBUG_ENABLED
philpem@0 164 `define LM32_SINGLE_STEP_ENABLED
philpem@0 165 `endif
philpem@0 166 `endif
philpem@0 167
philpem@0 168 // Derive macro that indicates whether JTAG interface is required
philpem@0 169 `ifdef CFG_JTAG_UART_ENABLED
philpem@0 170 `define LM32_JTAG_ENABLED
philpem@0 171 `else
philpem@0 172 `ifdef CFG_DEBUG_ENABLED
philpem@0 173 `define LM32_JTAG_ENABLED
philpem@0 174 `else
philpem@0 175 `endif
philpem@0 176 `endif
philpem@0 177
philpem@0 178 // Derive macro that indicates whether we have a barrel-shifter or not
philpem@0 179 `ifdef CFG_PL_BARREL_SHIFT_ENABLED
philpem@0 180 `define LM32_BARREL_SHIFT_ENABLED
philpem@0 181 `else // CFG_PL_BARREL_SHIFT_ENABLED
philpem@0 182 `ifdef CFG_MC_BARREL_SHIFT_ENABLED
philpem@0 183 `define LM32_BARREL_SHIFT_ENABLED
philpem@0 184 `else
philpem@0 185 `define LM32_NO_BARREL_SHIFT
philpem@0 186 `endif
philpem@0 187 `endif // CFG_PL_BARREL_SHIFT_ENABLED
philpem@0 188
philpem@0 189 // Derive macro that indicates whether we have a multiplier or not
philpem@0 190 `ifdef CFG_PL_MULTIPLY_ENABLED
philpem@0 191 `define LM32_MULTIPLY_ENABLED
philpem@0 192 `else
philpem@0 193 `ifdef CFG_MC_MULTIPLY_ENABLED
philpem@0 194 `define LM32_MULTIPLY_ENABLED
philpem@0 195 `endif
philpem@0 196 `endif
philpem@0 197
philpem@0 198 // Derive a macro that indicates whether or not the multi-cycle arithmetic unit is required
philpem@0 199 `ifdef CFG_MC_DIVIDE_ENABLED
philpem@0 200 `define LM32_MC_ARITHMETIC_ENABLED
philpem@0 201 `endif
philpem@0 202 `ifdef CFG_MC_MULTIPLY_ENABLED
philpem@0 203 `define LM32_MC_ARITHMETIC_ENABLED
philpem@0 204 `endif
philpem@0 205 `ifdef CFG_MC_BARREL_SHIFT_ENABLED
philpem@0 206 `define LM32_MC_ARITHMETIC_ENABLED
philpem@0 207 `endif
philpem@0 208
philpem@0 209 // Derive macro that indicates if we are using an EBR register file
philpem@0 210 `ifdef CFG_EBR_POSEDGE_REGISTER_FILE
philpem@0 211 `define LM32_EBR_REGISTER_FILE
philpem@0 212 `endif
philpem@0 213 `ifdef CFG_EBR_NEGEDGE_REGISTER_FILE
philpem@0 214 `define LM32_EBR_REGISTER_FILE
philpem@0 215 `endif
philpem@0 216
philpem@0 217 // Revision number
philpem@0 218 `define LM32_REVISION 6'h02
philpem@0 219
philpem@0 220 // Logical operations - Function encoded directly in instruction
philpem@0 221 `define LM32_LOGIC_OP_RNG 3:0
philpem@0 222
philpem@0 223 // Conditions for conditional branches
philpem@0 224 `define LM32_CONDITION_WIDTH 3
philpem@0 225 `define LM32_CONDITION_RNG (`LM32_CONDITION_WIDTH-1):0
philpem@0 226 `define LM32_CONDITION_E 3'b001
philpem@0 227 `define LM32_CONDITION_G 3'b010
philpem@0 228 `define LM32_CONDITION_GE 3'b011
philpem@0 229 `define LM32_CONDITION_GEU 3'b100
philpem@0 230 `define LM32_CONDITION_GU 3'b101
philpem@0 231 `define LM32_CONDITION_NE 3'b111
philpem@0 232 `define LM32_CONDITION_U1 3'b000
philpem@0 233 `define LM32_CONDITION_U2 3'b110
philpem@0 234
philpem@0 235 // Size of load or store instruction - Encoding corresponds to opcode
philpem@0 236 `define LM32_SIZE_WIDTH 2
philpem@0 237 `define LM32_SIZE_RNG 1:0
philpem@0 238 `define LM32_SIZE_BYTE 2'b00
philpem@0 239 `define LM32_SIZE_HWORD 2'b11
philpem@0 240 `define LM32_SIZE_WORD 2'b10
philpem@0 241 `define LM32_ADDRESS_LSBS_WIDTH 2
philpem@0 242
philpem@0 243 // Width and range of a CSR index
philpem@0 244 `ifdef CFG_DEBUG_ENABLED
philpem@0 245 `define LM32_CSR_WIDTH 5
philpem@0 246 `define LM32_CSR_RNG (`LM32_CSR_WIDTH-1):0
philpem@0 247 `else
philpem@0 248 `ifdef CFG_JTAG_ENABLED
philpem@0 249 `define LM32_CSR_WIDTH 4
philpem@0 250 `define LM32_CSR_RNG (`LM32_CSR_WIDTH-1):0
philpem@0 251 `else
philpem@0 252 `define LM32_CSR_WIDTH 3
philpem@0 253 `define LM32_CSR_RNG (`LM32_CSR_WIDTH-1):0
philpem@0 254 `endif
philpem@0 255 `endif
philpem@0 256
philpem@0 257 // CSR indices
philpem@0 258 `define LM32_CSR_IE `LM32_CSR_WIDTH'h0
philpem@0 259 `define LM32_CSR_IM `LM32_CSR_WIDTH'h1
philpem@0 260 `define LM32_CSR_IP `LM32_CSR_WIDTH'h2
philpem@0 261 `define LM32_CSR_ICC `LM32_CSR_WIDTH'h3
philpem@0 262 `define LM32_CSR_DCC `LM32_CSR_WIDTH'h4
philpem@0 263 `define LM32_CSR_CC `LM32_CSR_WIDTH'h5
philpem@0 264 `define LM32_CSR_CFG `LM32_CSR_WIDTH'h6
philpem@0 265 `define LM32_CSR_EBA `LM32_CSR_WIDTH'h7
philpem@0 266 `ifdef CFG_DEBUG_ENABLED
philpem@0 267 `define LM32_CSR_DC `LM32_CSR_WIDTH'h8
philpem@0 268 `define LM32_CSR_DEBA `LM32_CSR_WIDTH'h9
philpem@0 269 `endif
philpem@0 270 `define LM32_CSR_CFG2 `LM32_CSR_WIDTH'ha
philpem@0 271 `ifdef CFG_JTAG_ENABLED
philpem@0 272 `define LM32_CSR_JTX `LM32_CSR_WIDTH'he
philpem@0 273 `define LM32_CSR_JRX `LM32_CSR_WIDTH'hf
philpem@0 274 `endif
philpem@0 275 `ifdef CFG_DEBUG_ENABLED
philpem@0 276 `define LM32_CSR_BP0 `LM32_CSR_WIDTH'h10
philpem@0 277 `define LM32_CSR_BP1 `LM32_CSR_WIDTH'h11
philpem@0 278 `define LM32_CSR_BP2 `LM32_CSR_WIDTH'h12
philpem@0 279 `define LM32_CSR_BP3 `LM32_CSR_WIDTH'h13
philpem@0 280 `define LM32_CSR_WP0 `LM32_CSR_WIDTH'h18
philpem@0 281 `define LM32_CSR_WP1 `LM32_CSR_WIDTH'h19
philpem@0 282 `define LM32_CSR_WP2 `LM32_CSR_WIDTH'h1a
philpem@0 283 `define LM32_CSR_WP3 `LM32_CSR_WIDTH'h1b
philpem@0 284 `endif
philpem@0 285
philpem@0 286 // Values for WPC CSR
philpem@0 287 `define LM32_WPC_C_RNG 1:0
philpem@0 288 `define LM32_WPC_C_DISABLED 2'b00
philpem@0 289 `define LM32_WPC_C_READ 2'b01
philpem@0 290 `define LM32_WPC_C_WRITE 2'b10
philpem@0 291 `define LM32_WPC_C_READ_WRITE 2'b11
philpem@0 292
philpem@0 293 // Exception IDs
philpem@0 294 `define LM32_EID_WIDTH 3
philpem@0 295 `define LM32_EID_RNG (`LM32_EID_WIDTH-1):0
philpem@0 296 `define LM32_EID_RESET 3'h0
philpem@0 297 `define LM32_EID_BREAKPOINT 3'd1
philpem@0 298 `define LM32_EID_INST_BUS_ERROR 3'h2
philpem@0 299 `define LM32_EID_WATCHPOINT 3'd3
philpem@0 300 `define LM32_EID_DATA_BUS_ERROR 3'h4
philpem@0 301 `define LM32_EID_DIVIDE_BY_ZERO 3'h5
philpem@0 302 `define LM32_EID_INTERRUPT 3'h6
philpem@0 303 `define LM32_EID_SCALL 3'h7
philpem@0 304
philpem@0 305 // Pipeline result selection mux controls
philpem@0 306
philpem@0 307 `define LM32_D_RESULT_SEL_0_RNG 0:0
philpem@0 308 `define LM32_D_RESULT_SEL_0_REG_0 1'b0
philpem@0 309 `define LM32_D_RESULT_SEL_0_NEXT_PC 1'b1
philpem@0 310
philpem@0 311 `define LM32_D_RESULT_SEL_1_RNG 1:0
philpem@0 312 `define LM32_D_RESULT_SEL_1_ZERO 2'b00
philpem@0 313 `define LM32_D_RESULT_SEL_1_REG_1 2'b01
philpem@0 314 `define LM32_D_RESULT_SEL_1_IMMEDIATE 2'b10
philpem@0 315
philpem@0 316 `define LM32_USER_OPCODE_WIDTH 11
philpem@0 317 `define LM32_USER_OPCODE_RNG (`LM32_USER_OPCODE_WIDTH-1):0
philpem@0 318
philpem@0 319 // Derive a macro to indicate if either of the caches are implemented
philpem@0 320 `ifdef CFG_ICACHE_ENABLED
philpem@0 321 `define LM32_CACHE_ENABLED
philpem@0 322 `else
philpem@0 323 `ifdef CFG_DCACHE_ENABLED
philpem@0 324 `define LM32_CACHE_ENABLED
philpem@0 325 `endif
philpem@0 326 `endif
philpem@0 327
philpem@0 328 /////////////////////////////////////////////////////
philpem@0 329 // Interrupts
philpem@0 330 /////////////////////////////////////////////////////
philpem@0 331
philpem@0 332 // Always enable interrupts
philpem@0 333 `define CFG_INTERRUPTS_ENABLED
philpem@0 334
philpem@0 335 // Currently this is fixed to 32 and should not be changed
philpem@0 336 `define CFG_INTERRUPTS 32
philpem@0 337 `define LM32_INTERRUPT_WIDTH `CFG_INTERRUPTS
philpem@0 338 `define LM32_INTERRUPT_RNG (`LM32_INTERRUPT_WIDTH-1):0
philpem@0 339
philpem@0 340 /////////////////////////////////////////////////////
philpem@0 341 // General
philpem@0 342 /////////////////////////////////////////////////////
philpem@0 343
philpem@0 344 // Sub-word range types
philpem@0 345 `define LM32_BYTE_WIDTH 8
philpem@0 346 `define LM32_BYTE_RNG 7:0
philpem@0 347 `define LM32_HWORD_WIDTH 16
philpem@0 348 `define LM32_HWORD_RNG 15:0
philpem@0 349
philpem@0 350 // Word sub-byte indicies
philpem@0 351 `define LM32_BYTE_0_RNG 7:0
philpem@0 352 `define LM32_BYTE_1_RNG 15:8
philpem@0 353 `define LM32_BYTE_2_RNG 23:16
philpem@0 354 `define LM32_BYTE_3_RNG 31:24
philpem@0 355
philpem@0 356 // Word sub-halfword indices
philpem@0 357 `define LM32_HWORD_0_RNG 15:0
philpem@0 358 `define LM32_HWORD_1_RNG 31:16
philpem@0 359
philpem@0 360 // Use an asynchronous reset
philpem@0 361 // To use a synchronous reset, define this macro as nothing
philpem@23 362 //`define CFG_RESET_SENSITIVITY or posedge rst_i
philpem@23 363 `define CFG_RESET_SENSITIVITY
philpem@0 364
philpem@0 365 // Whether to include context registers for debug exceptions
philpem@0 366 // in addition to standard exception handling registers
philpem@0 367 `define CFG_DEBUG_EXCEPTIONS_ENABLED
philpem@0 368
philpem@12 369 // Wishbone defines
philpem@0 370 // Refer to Wishbone System-on-Chip Interconnection Architecture
philpem@0 371 // These should probably be moved to a Wishbone common file
philpem@0 372
philpem@0 373 // Wishbone cycle types
philpem@0 374 `define LM32_CTYPE_WIDTH 3
philpem@0 375 `define LM32_CTYPE_RNG (`LM32_CTYPE_WIDTH-1):0
philpem@0 376 `define LM32_CTYPE_CLASSIC 3'b000
philpem@0 377 `define LM32_CTYPE_CONSTANT 3'b001
philpem@0 378 `define LM32_CTYPE_INCREMENTING 3'b010
philpem@0 379 `define LM32_CTYPE_END 3'b111
philpem@0 380
philpem@0 381 // Wishbone burst types
philpem@0 382 `define LM32_BTYPE_WIDTH 2
philpem@0 383 `define LM32_BTYPE_RNG (`LM32_BTYPE_WIDTH-1):0
philpem@0 384 `define LM32_BTYPE_LINEAR 2'b00
philpem@0 385 `define LM32_BTYPE_4_BEAT 2'b01
philpem@0 386 `define LM32_BTYPE_8_BEAT 2'b10
philpem@0 387 `define LM32_BTYPE_16_BEAT 2'b11
philpem@0 388
philpem@0 389 `endif