OpenCores
URL https://opencores.org/ocsvn/6809_6309_compatible_core/6809_6309_compatible_core/trunk

Subversion Repositories 6809_6309_compatible_core

[/] [6809_6309_compatible_core/] [trunk/] [rtl/] [verilog/] [decoders.v] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ale500
 
2
/*
3
 * Signals which registers have to be read/written for the current opcode
4
 *
5
 *
6
 *
7
 */
8
`include "defs.v"
9
module decode_regs(
10
        input wire [7:0] opcode,
11
        input wire [7:0] postbyte0,
12
        input wire page2_valid, // is 1 when the postbyte0 is a valid opcode (after it was loaded)
13
        input wire page3_valid, // is 1 when the postbyte0 is a valid opcode (after it was loaded)
14
        output reg [3:0] path_left_addr,
15
        output reg [3:0] path_right_addr,
16
        output reg [3:0] dest_reg,
17
        output wire write_dest_8,
18
        output wire write_dest_16,
19
        output wire result_size
20
        );
21
// for registers, memory writes are handled differently
22
assign write_dest_8 = ((dest_reg >= `RN_ACCA) && (dest_reg <= `RN_DP)) ? 1:0;
23
assign write_dest_16 = (dest_reg < `RN_IMM16) ? 1:0;
24
assign result_size = (dest_reg < `RN_IMM16) ? 1:0;
25
always @(opcode, postbyte0, page2_valid, page3_valid)
26
        begin
27
                path_left_addr = `RN_INV;
28
                path_right_addr = `RN_INV;
29
                dest_reg = `RN_INV;
30
 
31
                if (page2_valid | page3_valid)
32
                        begin
33
                                casex(postbyte0)
34
                                        8'h83, 8'h93, 8'ha3, 8'hb3: path_left_addr = `RN_ACCD;
35
                                        8'h8c, 8'h9c, 8'hac, 8'hbc: path_left_addr = `RN_IY;
36
                                        8'h8e, 8'h9e, 8'hae, 8'hbe: path_left_addr = `RN_IY;
37
                                        8'h8f, 8'h9f, 8'haf, 8'hbf: path_left_addr = `RN_IY;
38
                                endcase
39
                                casex (postbyte0) // right arm
40
                                        8'h83, 8'h8c, 8'h8e, 8'h8f: path_right_addr = `RN_IMM16;
41
                                        8'h93, 8'ha3, 8'hb3: path_right_addr = `RN_MEM16;
42
                                        8'h9c, 8'hac, 8'hbc: path_right_addr = `RN_MEM16;
43
                                        8'h9e, 8'hae, 8'hbe: path_right_addr = `RN_MEM16;
44
                                        8'h9f, 8'haf, 8'hbf: path_right_addr = `RN_MEM16;
45
                                endcase
46
                                casex(postbyte0) // dest
47
                                        8'h83, 8'h93, 8'ha3, 8'hb3: begin end // only flags
48
                                        8'h8c, 8'h9c, 8'hac, 8'hbc: begin end // only flags 
49
                                        8'h8e, 8'h9e, 8'hae, 8'hbe: dest_reg = `RN_IY;
50
                                        8'h8f, 8'h9f, 8'haf, 8'hbf: dest_reg = `RN_MEM16;
51
                                endcase
52
                        end
53
                // destination
54
                casex(opcode)
55
                        8'h30: dest_reg = `RN_IX;
56
                        8'h31: dest_reg = `RN_IY;
57
                        8'h32: dest_reg = `RN_S;
58
                        8'h33: dest_reg = `RN_U;
59
                        8'h39: dest_reg = `RN_PC; // rts
60
                        8'h3d: begin path_left_addr = `RN_ACCA; path_right_addr = `RN_ACCB; dest_reg = `RN_ACCD; end // mul
61
                        8'h4x: begin path_left_addr = `RN_ACCA; dest_reg = `RN_ACCA; end
62
                        8'h5x: begin path_left_addr = `RN_ACCB; dest_reg = `RN_ACCB; end
63
                        8'h0x, 8'h7x: begin path_left_addr = `RN_MEM8; dest_reg = `RN_MEM8; end
64
                        8'h6x:
65
                                case (opcode[3:0])
66
                                        4'hf: begin dest_reg = `RN_MEM8; end // CLR, only dest
67
                                        default: begin path_left_addr = `RN_MEM8; dest_reg = `RN_MEM8; end
68
                                endcase
69
                        8'h4x, 8'h8x, 8'h9x, 8'hax, 8'hbx:
70
                                case (opcode[3:0])
71
                                        4'h3: begin path_left_addr = `RN_ACCD; dest_reg = `RN_ACCD; end
72
                                        4'h7: begin path_left_addr = `RN_ACCA; dest_reg = `RN_MEM8; end
73
                                        4'hc, 4'he, 4'hf: begin path_left_addr = `RN_IX; dest_reg = `RN_IX; end
74
                                        4'hd: begin end // nothing active, jsr
75
                                        default: begin path_left_addr = `RN_ACCA; dest_reg = `RN_ACCA; end
76
                                endcase
77
                        8'h5x, 8'hcx, 8'hdx, 8'hex, 8'hfx:
78
                                case (opcode[3:0])
79
                                        4'h3, 4'hc: begin path_left_addr = `RN_ACCD; dest_reg = `RN_ACCD; end
80
                                        4'h7: begin path_left_addr = `RN_ACCB; dest_reg = `RN_MEM8; end // store to mem
81
                                        4'he: begin path_left_addr = `RN_U; dest_reg = `RN_IX; end
82
                                        4'hf: begin path_left_addr = `RN_IX; dest_reg = `RN_IX; end
83
                                        4'hd: begin path_left_addr = `RN_ACCD; end
84
                                        default: begin path_left_addr = `RN_ACCB; dest_reg = `RN_ACCB; end
85
                                endcase
86
                endcase
87
                casex (opcode) // right arm
88
                        // 8x and Cx
89
                        8'b1x00_000x, 8'b1x00_0010: path_right_addr = `RN_IMM8;
90
                        8'b1x00_0011, 8'b1x00_11x0, 8'b1x00_1111: path_right_addr = `RN_IMM16;
91
                        8'b1x00_010x, 8'b1x00_0110,
92
                        8'b1x00_10xx: path_right_addr = `RN_IMM8;
93
                        // 9, A, B, D, E, F
94
                        8'b1x01_000x, 8'b1x01_0010: path_right_addr = `RN_MEM8;
95
                        8'b1x01_0011, 8'b1x01_11x0, 8'b1x01_1111: path_right_addr = `RN_MEM16;
96
                        8'b1x01_010x, 8'b1x01_0110,
97
                        8'b1x01_10xx: path_right_addr = `RN_MEM8;
98
                        8'b1x1x_000x, 8'b1x1x_0010: path_right_addr = `RN_MEM8;
99
                        8'b1x1x_0011, 8'b1x1x_11x0, 8'b1x1x_1111: path_right_addr = `RN_MEM16;
100
                        8'b1x1x_010x, 8'b1x1x_0110,
101
                        8'b1x1x_10xx: path_right_addr = `RN_MEM8;
102
                endcase
103
        end
104
 
105
endmodule
106
 
107
/* Decodes module and addressing mode for page 1 opcodes */
108
module decode_op(
109
        input wire [7:0] opcode,
110
        input wire [7:0] postbyte0,
111
        input wire page2_valid, // is 1 when the postbyte0 is a valid opcode (after it was loaded)
112
        input wire page3_valid, // is 1 when the postbyte0 is a valid opcode (after it was loaded)
113
        output reg [2:0] mode,
114
        output reg [2:0] optype,
115
        output reg use_s
116
        );
117
 
118
wire [3:0] oplo;
119
reg size;
120
assign oplo = opcode[3:0];
121
 
122
always @(opcode, postbyte0, page2_valid, page3_valid, oplo)
123
        begin
124
                //dsize = `DSZ_8; // data operand size
125
                //msize = `MSZ_8; // memory operand size
126
                optype = `OP_NONE;
127
                use_s = 1;
128
                mode = `NONE;
129
                size = 0;
130
                // Addressing mode
131
                casex(opcode)
132
                        8'h0x: begin mode = `DIRECT; end
133
                        8'h12, 8'h13, 8'h19: mode = `INHERENT;
134
                        8'h14, 8'h15, 8'h18, 8'h1b: mode = `NONE; // undefined opcodes
135
                        8'h16: mode = `REL16;
136
                        8'h17: begin mode = `REL16; optype = `OP_JSR; end
137
                        8'h1a, 8'h1c, 8'h1d, 8'h1e, 8'h1f: mode = `IMMEDIATE; // handled in ALU ORCC, ANDCC, SEX, EXG, TFR
138
 
139
                        8'h2x: mode = `REL8;
140
                        8'h30, 8'h31, 8'h32, 8'h33: begin mode = `INDEXED;  optype = `OP_LEA; end
141
                        8'h34: begin optype = `OP_PUSH; mode = `NONE; end
142
                        8'h35: begin optype = `OP_PULL; mode = `NONE; end
143
                        8'h36: begin optype = `OP_PUSH; mode = `NONE; use_s = 0; end
144
                        8'h37: begin optype = `OP_PULL; mode = `NONE; use_s = 0; end
145
                        8'h38, 8'h3e: mode = `NONE;
146
                        // don't change to inh because SEQ_MEM_READ_x would not use register S as address
147
                        8'h39, 8'h3b: begin  mode = `NONE; optype = `OP_RTS; end
148
                        8'h3a, 8'h3c, 8'h3d, 8'h3f: mode = `INHERENT;
149
 
150
                        8'h4x: begin mode = `INHERENT; end
151
                        8'h5x: begin mode = `INHERENT; end
152
                        8'h6x: begin mode = `INDEXED; end
153
                        8'h7x: begin mode = `EXTENDED; end
154
                        8'h8x:
155
                                begin
156
                                        case (oplo)
157
                                                4'h3, 4'hc, 4'he: begin mode = `IMMEDIATE; size = 1; end
158
                                                4'hd: mode = `REL8; // bsr
159
                                                default: mode = `IMMEDIATE;
160
                                        endcase
161
                                end
162
                        8'hcx:
163
                                begin
164
                                        case (oplo)
165
                                                4'h3, 4'hc, 4'he: begin mode = `IMMEDIATE; size = 1; end
166
                                                default: mode = `IMMEDIATE;
167
                                        endcase
168
                                end
169
                        8'h9x, 8'hdx: begin mode = `DIRECT; end
170
                        8'hax, 8'hex: begin mode = `INDEXED; end
171
                        8'hbx, 8'hfx: begin mode = `EXTENDED; end
172
                endcase
173
                // Opcode type
174
                casex(opcode)
175
                        8'b1xxx0110: optype = `OP_LD;
176
                        8'b1xxx0111: optype = `OP_ST;
177
                        8'b11xx1100: optype = `OP_LD; // LDD
178
                        8'b10xx1101: begin optype = `OP_JSR; end// bsr & jsr
179
                        8'b1xxx1110: optype = `OP_LD; // LDX, LDU
180
                        8'b1xxx1111, 8'b1xxx1101: optype = `OP_ST;
181
                endcase
182
                if (page2_valid == 1'b1)
183
                        begin
184
                                casex(postbyte0)
185
                                        8'h1x: mode = `REL16;
186
                                        8'h2f: mode = `INHERENT;
187
                                        8'h83: begin  mode = `IMMEDIATE; size = 1; end
188
                                        //8'h93, 8'ha3, 8'hb3: begin mem16 = 1; size = 1; end
189
                                        8'h8c: begin  mode = `IMMEDIATE; size = 1; end
190
                                        //8'h9c, 8'hac, 8'hbc: begin mem16 = 1; size = 1; end
191
                                        8'h8e: begin mode = `IMMEDIATE; size = 1; end
192
                                        //8'h9e, 8'hae, 8'hbe: begin mem16 = 1; size = 1; end
193
                                        //8'h9f, 8'haf, 8'hbf: begin  mem16 = 1; size = 1; end
194
                                        8'hce: begin  mode = `IMMEDIATE; size = 1; end
195
                                        //8'hde, 8'hee, 8'hfe: begin mem16 = 1; size = 1; end
196
                                        //8'hdf, 8'hef, 8'hff: begin mem16 = 1; size = 1; end
197
                                endcase
198
                                casex( postbyte0)
199
                                        8'h9x, 8'hdx: mode = `DIRECT;
200
                                        8'hax, 8'hex: mode = `INDEXED;
201
                                        8'hbx, 8'hfx: mode = `EXTENDED;
202
                                endcase
203
                                casex( postbyte0)
204
                                        8'b1xxx1110: optype = `OP_LD; // LDY, LDS
205
                                        8'b1xxx1111, 8'b1xxx1101: optype = `OP_ST; // STY, STS
206
                                endcase
207
                        end
208
                if (page3_valid == 1'b1)
209
                        begin
210
                                casex(postbyte0)
211
                                        8'h2f: mode = `INHERENT;
212
                                        8'h83: begin mode = `IMMEDIATE; size = 1; end // CMPD
213
                                        //8'h93, 8'ha3, 8'hb3: begin mem16 = 1; size = 1; end // CMPD
214
                                        8'h8c: begin mode = `IMMEDIATE; size = 1; end
215
                                        //8'h9c, 8'hac, 8'hbc: begin mem16 = 1; size = 1; end
216
                                        8'h8e: begin mode = `IMMEDIATE; size = 1; end
217
                                        //8'h9e, 8'hae, 8'hbe: begin mem16 = 1; size = 1; end
218
                                        //8'h9f, 8'haf, 8'hbf: begin mem16 = 1; size = 1; end
219
                                        8'hce: begin mode = `IMMEDIATE; size = 1; end
220
                                        //8'hde, 8'hee, 8'hfe: begin mem16 = 1; size = 1; end
221
                                        //8'hdf, 8'hef, 8'hff: begin mem16 = 1; size = 1; end
222
                                endcase
223
                                casex( postbyte0)
224
                                        8'h9x, 8'hdx: mode = `DIRECT;
225
                                        8'hax, 8'hex: mode = `INDEXED;
226
                                        8'hbx, 8'hfx: mode = `EXTENDED;
227
                                endcase
228
                        end
229
        end
230
 
231
endmodule
232
 
233
/* Decodes the Effective Address postbyte
234
   to recover size of offset to load and post-incr/pre-decr info
235
 */
236
module decode_ea(
237
        input wire [7:0] eapostbyte,
238
        output reg noofs,
239
        output reg ofs8, // needs an 8 bit offset
240
        output reg ofs16, // needs an 16 bit offset
241
        output reg write_post, // needs to write back a predecr or post incr
242
        output wire isind // signals when the mode is indirect, the memory at the address is read to load the real address
243
        );
244
 
245
assign isind = (eapostbyte[7] & eapostbyte[4]) ? 1'b1:1'b0;
246
always @(*)
247
        begin
248
                noofs = 0;
249
                ofs8 = 0;
250
                ofs16 = 0;
251
                write_post = 0;
252
                casex (eapostbyte)
253
                        8'b0xxxxxxx, 8'b1xx00100: noofs = 1;
254
                        8'b1xxx1000, 8'b1xxx1100: ofs8 = 1;
255
                        8'b1xxx1001, 8'b1xxx1101: ofs16 = 1;
256
                        8'b1xx11111: ofs16 = 1; // extended indirect
257
                        8'b1xxx00xx: write_post = 1;
258
                endcase
259
        end
260
endmodule
261
 
262
module decode_alu(
263
        input wire [7:0] opcode,
264
        input wire [7:0] postbyte0,
265
        input wire page2_valid, // is 1 when the postbyte0 was loaded and is page2 opcode
266
        input wire page3_valid, // is 1 when the postbyte0 was loaded and is page3 opcode
267
        output reg [4:0] alu_opcode,
268
        output reg [1:0] dec_alu_right_path_mod,
269
        output wire dest_flags
270
        );
271
 
272
assign dest_flags = alu_opcode != `NOP;
273
always @(*)
274
        begin
275
                alu_opcode = `NOP;
276
                dec_alu_right_path_mod = `MOD_DEFAULT;
277
                casex (opcode)
278
                        8'b1xxx_0000: alu_opcode = `SUB;
279
                        8'b1xxx_0001: alu_opcode = `CMP;
280
                        8'b1xxx_0010: alu_opcode = `SBC;
281
                        8'b10xx_0011: alu_opcode = `SUB;
282
                        8'b11xx_0011: alu_opcode = `ADD;
283
                        8'b1xxx_0100: alu_opcode = `AND;
284
                        8'b1xxx_0101: alu_opcode = `BIT;
285
                        8'b1xxx_0110: alu_opcode = `LD;
286
                        8'b1xxx_0111: alu_opcode = `ST;
287
                        8'b1xxx_1000: alu_opcode = `EOR;
288
                        8'b1xxx_1001: alu_opcode = `ADC;
289
                        8'b1xxx_1010: alu_opcode = `OR;
290
                        8'b1xxx_1011: alu_opcode = `ADD;
291
                        8'b10xx_1100: alu_opcode = `CMP;
292
                        8'b11xx_1100: alu_opcode = `LD;
293
                        8'b11xx_1101: alu_opcode = `LD;
294
                        8'b1xxx_1110: alu_opcode = `LD;
295
                        8'b1xxx_1111: alu_opcode = `ST;
296
 
297
                        8'h00, 8'b01xx_0000: alu_opcode = `NEG;
298
                        8'h03, 8'b01xx_0011: alu_opcode = `COM;
299
                        8'h04, 8'b01xx_0100: alu_opcode = `LSR;
300
                        8'h06, 8'b01xx_0110: alu_opcode = `ROR;
301
                        8'h07, 8'b01xx_0111: alu_opcode = `ASR;
302
                        8'h08, 8'b01xx_1000: alu_opcode = `LSL;
303
                        8'h09, 8'b01xx_1001: alu_opcode = `ROL;
304
                        8'h0a, 8'b01xx_1010: begin alu_opcode = `SUB; dec_alu_right_path_mod = `MOD_MINUS1; end // dec
305
                        8'h0c, 8'b01xx_1100: begin alu_opcode = `ADD; dec_alu_right_path_mod = `MOD_ONE; end // inc
306
                        8'h0d, 8'b01xx_1101: alu_opcode = `AND;
307
                        8'h0f, 8'b01xx_1111: begin alu_opcode = `LD; dec_alu_right_path_mod = `MOD_ZERO; end // CLR
308
 
309
                        8'h19: alu_opcode = `DAA;
310
                        8'h1a: alu_opcode = `ORCC;
311
                        8'h1c: alu_opcode = `ANDCC;
312
                        8'h1d: alu_opcode = `SEXT;
313
                        8'h1e: alu_opcode = `EXG;
314
                        8'h3d: alu_opcode = `MUL;
315
                endcase
316
                if (page2_valid)
317
                        casex (postbyte0)
318
                                8'b10xx_0011,
319
                                8'b10xx_1010: alu_opcode = `CMP;
320
                                8'b1xxx_1110: alu_opcode = `LD;
321
                                8'b1xxx_1111: alu_opcode = `ST;
322
                        endcase
323
                if (page3_valid)
324
                        casex (postbyte0)
325
                                8'b10xx_0011,
326
                                8'b10xx_1010: alu_opcode = `CMP;
327
                                8'b1xxx_1110: alu_opcode = `LD;
328
                                8'b1xxx_1111: alu_opcode = `ST;
329
                        endcase
330
        end
331
 
332
endmodule
333
/* decodes the condition and checks the flags to see if it is met */
334
module test_condition(
335
        input wire [7:0] opcode,
336
        input wire [7:0] postbyte0,
337
        input wire page2_valid,
338
        input wire [7:0] CCR,
339
        output reg cond_taken
340
        );
341
 
342
wire [7:0] op = page2_valid ? postbyte0:opcode;
343
 
344
always @(*)
345
        begin
346
                cond_taken = 1'b0;
347
                if ((op == 8'h16) || (op == 8'h17) || (op == 8'h8D))
348
                        cond_taken = 1'b1; // LBRA/LBSR, BSR
349
                if (op[7:4] == 4'h2)
350
                        case (op[3:0])
351
                                4'h0: cond_taken = 1'b1; // BRA
352
                                4'h1: cond_taken = 0; // BRN
353
                                4'h2: cond_taken = !(`DFLAGC & `DFLAGZ); // BHI
354
                                4'h3: cond_taken = `DFLAGC | `DFLAGZ; // BLS
355
                                4'h4: cond_taken = !`DFLAGC; // BCC, BHS
356
                                4'h5: cond_taken = `DFLAGC; // BCS, BLO
357
                                4'h6: cond_taken = !`DFLAGZ; // BNE
358
                                4'h7: cond_taken = `DFLAGZ; // BEQ
359
                                4'h8: cond_taken = !`DFLAGV; // BVC
360
                                4'h9: cond_taken = `DFLAGV; // BVS
361
                                4'ha: cond_taken = !`DFLAGN; // BPL
362
                                4'hb: cond_taken = `DFLAGN; // BMI
363
                                4'hc: cond_taken = `DFLAGN == `DFLAGV; // BGE
364
                                4'hd: cond_taken = `DFLAGN != `DFLAGV; // BLT
365
                                4'he: cond_taken = (`DFLAGN == `DFLAGV) & (!`DFLAGZ); // BGT
366
                                4'hf: cond_taken = (`DFLAGN != `DFLAGV) | (`DFLAGZ); // BLE
367
                endcase
368
        end
369
 
370
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.