OpenCores
URL https://opencores.org/ocsvn/amber/amber/trunk

Subversion Repositories amber

[/] [amber/] [trunk/] [hw/] [vlog/] [amber25/] [a25_decompile.v] - Blame information for rev 35

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

Line No. Rev Author Line
1 16 csantifort
//////////////////////////////////////////////////////////////////
2
//                                                              //
3 17 csantifort
//  Decompiler for Amber 25 Core                                //
4 16 csantifort
//                                                              //
5
//  This file is part of the Amber project                      //
6
//  http://www.opencores.org/project,amber                      //
7
//                                                              //
8
//  Description                                                 //
9
//  Decompiler for debugging core - not synthesizable           //
10
//  Shows instruction in Execute Stage at last clock of         //
11
//  the instruction                                             //
12
//                                                              //
13
//  Author(s):                                                  //
14
//      - Conor Santifort, csantifort.amber@gmail.com           //
15
//                                                              //
16
//////////////////////////////////////////////////////////////////
17
//                                                              //
18
// Copyright (C) 2011 Authors and OPENCORES.ORG                 //
19
//                                                              //
20
// This source file may be used and distributed without         //
21
// restriction provided that this copyright statement is not    //
22
// removed from the file and that any derivative work contains  //
23
// the original copyright notice and the associated disclaimer. //
24
//                                                              //
25
// This source file is free software; you can redistribute it   //
26
// and/or modify it under the terms of the GNU Lesser General   //
27
// Public License as published by the Free Software Foundation; //
28
// either version 2.1 of the License, or (at your option) any   //
29
// later version.                                               //
30
//                                                              //
31
// This source is distributed in the hope that it will be       //
32
// useful, but WITHOUT ANY WARRANTY; without even the implied   //
33
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
34
// PURPOSE.  See the GNU Lesser General Public License for more //
35
// details.                                                     //
36
//                                                              //
37
// You should have received a copy of the GNU Lesser General    //
38
// Public License along with this source; if not, download it   //
39
// from http://www.opencores.org/lgpl.shtml                     //
40
//                                                              //
41
//////////////////////////////////////////////////////////////////
42
 
43
`include "a25_config_defines.v"
44
 
45
module a25_decompile
46
(
47
input                       i_clk,
48 35 csantifort
input                       i_core_stall,
49 16 csantifort
input       [31:0]          i_instruction,
50
input                       i_instruction_valid,
51
input                       i_instruction_undefined,
52
input                       i_instruction_execute,
53
input       [2:0]           i_interrupt,            // non-zero value means interrupt triggered
54
input                       i_interrupt_state,
55
input       [31:0]          i_instruction_address,
56
input       [2:0]           i_pc_sel,
57
input                       i_pc_wen
58
 
59
);
60
 
61
`include "a25_localparams.v"
62
 
63
`ifdef A25_DECOMPILE
64
 
65
integer i;
66
 
67
wire    [31:0]         imm32;
68
wire    [7:0]          imm8;
69
wire    [11:0]         offset12;
70
wire    [7:0]          offset8;
71
wire    [3:0]          reg_n, reg_d, reg_m, reg_s;
72
wire    [4:0]          shift_imm;
73
wire    [3:0]          opcode;
74
wire    [3:0]          condition;
75
wire    [3:0]          type;
76
wire                   opcode_compare;
77
wire                   opcode_move;
78
wire                   no_shift;
79
wire                   shift_op_imm;
80
wire    [1:0]          mtrans_type;
81
wire                   s_bit;
82
 
83
reg     [(5*8)-1:0]    xINSTRUCTION_EXECUTE;
84
reg     [(5*8)-1:0]    xINSTRUCTION_EXECUTE_R = "---   ";
85
wire    [(8*8)-1:0]    TYPE_NAME;
86
reg     [3:0]          fchars;
87
reg     [31:0]         execute_address = 'd0;
88
reg     [2:0]          interrupt_d1;
89
reg     [31:0]         clk_count = 'd0;
90
reg     [31:0]         execute_instruction = 'd0;
91
reg                    execute_now = 'd0;
92
reg                    execute_valid = 'd0;
93
reg                    execute_undefined = 'd0;
94
 
95
 
96
// ========================================================
97
// Delay instruction to Execute stage
98
// ========================================================
99
always @( posedge i_clk )
100 35 csantifort
    if ( !i_core_stall && i_instruction_valid )
101 16 csantifort
        begin
102
        execute_instruction <= i_instruction;
103
        execute_address     <= i_instruction_address;
104
        execute_undefined   <= i_instruction_undefined;
105
        execute_now         <= 1'd1;
106
        end
107
    else
108
        execute_now         <= 1'd0;
109
 
110
 
111
always @ ( posedge i_clk )
112 35 csantifort
    if ( !i_core_stall )
113 16 csantifort
        execute_valid <= i_instruction_valid;
114
 
115
// ========================================================
116
// Open File
117
// ========================================================
118
integer decompile_file;
119
 
120
initial
121
    #1 decompile_file = $fopen(`A25_DECOMPILE_FILE, "w");
122
 
123
 
124
// ========================================================
125
// Fields within the instruction
126
// ========================================================
127
assign opcode      = execute_instruction[24:21];
128
assign condition   = execute_instruction[31:28];
129
assign s_bit       = execute_instruction[20];
130
assign reg_n       = execute_instruction[19:16];
131
assign reg_d       = execute_instruction[15:12];
132
assign reg_m       = execute_instruction[3:0];
133
assign reg_s       = execute_instruction[11:8];
134
assign shift_imm   = execute_instruction[11:7];
135
assign offset12    = execute_instruction[11:0];
136
assign offset8     = {execute_instruction[11:8], execute_instruction[3:0]};
137
assign imm8        = execute_instruction[7:0];
138
 
139
assign no_shift    = execute_instruction[11:4] == 8'h0;
140
assign mtrans_type = execute_instruction[24:23];
141
 
142
 
143
assign opcode_compare =
144
            opcode == CMP ||
145
            opcode == CMN ||
146
            opcode == TEQ ||
147
            opcode == TST ;
148
 
149
assign opcode_move =
150
            opcode == MOV ||
151
            opcode == MVN ;
152
 
153
assign shift_op_imm = type == REGOP && execute_instruction[25] == 1'd1;
154
 
155
assign imm32 =  execute_instruction[11:8] == 4'h0 ? {            24'h0, imm8[7:0] } :
156
                execute_instruction[11:8] == 4'h1 ? { imm8[1:0], 24'h0, imm8[7:2] } :
157
                execute_instruction[11:8] == 4'h2 ? { imm8[3:0], 24'h0, imm8[7:4] } :
158
                execute_instruction[11:8] == 4'h3 ? { imm8[5:0], 24'h0, imm8[7:6] } :
159
                execute_instruction[11:8] == 4'h4 ? { imm8[7:0], 24'h0            } :
160
                execute_instruction[11:8] == 4'h5 ? { 2'h0,  imm8[7:0], 22'h0 }     :
161
                execute_instruction[11:8] == 4'h6 ? { 4'h0,  imm8[7:0], 20'h0 }     :
162
                execute_instruction[11:8] == 4'h7 ? { 6'h0,  imm8[7:0], 18'h0 }     :
163
                execute_instruction[11:8] == 4'h8 ? { 8'h0,  imm8[7:0], 16'h0 }     :
164
                execute_instruction[11:8] == 4'h9 ? { 10'h0, imm8[7:0], 14'h0 }     :
165
                execute_instruction[11:8] == 4'ha ? { 12'h0, imm8[7:0], 12'h0 }     :
166
                execute_instruction[11:8] == 4'hb ? { 14'h0, imm8[7:0], 10'h0 }     :
167
                execute_instruction[11:8] == 4'hc ? { 16'h0, imm8[7:0], 8'h0  }     :
168
                execute_instruction[11:8] == 4'hd ? { 18'h0, imm8[7:0], 6'h0  }     :
169
                execute_instruction[11:8] == 4'he ? { 20'h0, imm8[7:0], 4'h0  }     :
170
                                                    { 22'h0, imm8[7:0], 2'h0  }     ;
171
 
172
 
173
// ========================================================
174
// Instruction decode
175
// ========================================================
176
// the order of these matters
177
assign type =
178
    {execute_instruction[27:23], execute_instruction[21:20], execute_instruction[11:4] } == { 5'b00010, 2'b00, 8'b00001001 } ? SWAP     :  // Before REGOP
179
    {execute_instruction[27:22], execute_instruction[7:4]                              } == { 6'b000000, 4'b1001           } ? MULT     :  // Before REGOP
180
    {execute_instruction[27:26]                                                        } == { 2'b00                        } ? REGOP    :
181
    {execute_instruction[27:26]                                                        } == { 2'b01                        } ? TRANS    :
182
    {execute_instruction[27:25]                                                        } == { 3'b100                       } ? MTRANS   :
183
    {execute_instruction[27:25]                                                        } == { 3'b101                       } ? BRANCH   :
184
    {execute_instruction[27:25]                                                        } == { 3'b110                       } ? CODTRANS :
185
    {execute_instruction[27:24], execute_instruction[4]                                } == { 4'b1110, 1'b0                } ? COREGOP  :
186
    {execute_instruction[27:24], execute_instruction[4]                                } == { 4'b1110, 1'b1                } ? CORTRANS :
187
                                                                                                                               SWI      ;
188
 
189
 
190
//
191
// Convert some important signals to ASCII
192
// so their values can easily be displayed on a waveform viewer
193
//
194
assign TYPE_NAME    = type == REGOP    ? "REGOP   " :
195
                      type == MULT     ? "MULT    " :
196
                      type == SWAP     ? "SWAP    " :
197
                      type == TRANS    ? "TRANS   " :
198
                      type == MTRANS   ? "MTRANS  " :
199
                      type == BRANCH   ? "BRANCH  " :
200
                      type == CODTRANS ? "CODTRANS" :
201
                      type == COREGOP  ? "COREGOP " :
202
                      type == CORTRANS ? "CORTRANS" :
203
                      type == SWI      ? "SWI     " :
204
                                         "UNKNOWN " ;
205
 
206
 
207
always @*
208
    begin
209
 
210
    if ( !execute_now )
211
        begin
212
        xINSTRUCTION_EXECUTE =  xINSTRUCTION_EXECUTE_R;
213
        end // stalled
214
 
215
    else if ( type == REGOP    && opcode == ADC                                                          ) xINSTRUCTION_EXECUTE = "adc  ";
216
    else if ( type == REGOP    && opcode == ADD                                                          ) xINSTRUCTION_EXECUTE = "add  ";
217
    else if ( type == REGOP    && opcode == AND                                                          ) xINSTRUCTION_EXECUTE = "and  ";
218
    else if ( type == BRANCH   && execute_instruction[24] == 1'b0                                        ) xINSTRUCTION_EXECUTE = "b    ";
219
    else if ( type == REGOP    && opcode == BIC                                                          ) xINSTRUCTION_EXECUTE = "bic  ";
220
    else if ( type == BRANCH   && execute_instruction[24] == 1'b1                                        ) xINSTRUCTION_EXECUTE = "bl   ";
221
    else if ( type == COREGOP                                                                            ) xINSTRUCTION_EXECUTE = "cdp  ";
222
    else if ( type == REGOP    && opcode == CMN                                                          ) xINSTRUCTION_EXECUTE = "cmn  ";
223
    else if ( type == REGOP    && opcode == CMP                                                          ) xINSTRUCTION_EXECUTE = "cmp  ";
224
    else if ( type == REGOP    && opcode == EOR                                                          ) xINSTRUCTION_EXECUTE = "eor  ";
225
    else if ( type == CODTRANS && execute_instruction[20] == 1'b1                                        ) xINSTRUCTION_EXECUTE = "ldc  ";
226
    else if ( type == MTRANS   && execute_instruction[20] == 1'b1                                        ) xINSTRUCTION_EXECUTE = "ldm  ";
227
    else if ( type == TRANS    && {execute_instruction[22],execute_instruction[20]}    == {1'b0, 1'b1}   ) xINSTRUCTION_EXECUTE = "ldr  ";
228
    else if ( type == TRANS    && {execute_instruction[22],execute_instruction[20]}    == {1'b1, 1'b1}   ) xINSTRUCTION_EXECUTE = "ldrb ";
229
    else if ( type == CORTRANS && execute_instruction[20] == 1'b0                                        ) xINSTRUCTION_EXECUTE = "mcr  ";
230
    else if ( type == MULT     && execute_instruction[21] == 1'b1                                        ) xINSTRUCTION_EXECUTE = "mla  ";
231
    else if ( type == REGOP    && opcode == MOV                                                          ) xINSTRUCTION_EXECUTE = "mov  ";
232
    else if ( type == CORTRANS && execute_instruction[20] == 1'b1                                        ) xINSTRUCTION_EXECUTE = "mrc  ";
233
    else if ( type == MULT     && execute_instruction[21] == 1'b0                                        ) xINSTRUCTION_EXECUTE = "mul  ";
234
    else if ( type == REGOP    && opcode == MVN                                                          ) xINSTRUCTION_EXECUTE = "mvn  ";
235
    else if ( type == REGOP    && opcode == ORR                                                          ) xINSTRUCTION_EXECUTE = "orr  ";
236
    else if ( type == REGOP    && opcode == RSB                                                          ) xINSTRUCTION_EXECUTE = "rsb  ";
237
    else if ( type == REGOP    && opcode == RSC                                                          ) xINSTRUCTION_EXECUTE = "rsc  ";
238
    else if ( type == REGOP    && opcode == SBC                                                          ) xINSTRUCTION_EXECUTE = "sbc  ";
239
    else if ( type == CODTRANS && execute_instruction[20] == 1'b0                                        ) xINSTRUCTION_EXECUTE = "stc  ";
240
    else if ( type == MTRANS   && execute_instruction[20] == 1'b0                                        ) xINSTRUCTION_EXECUTE = "stm  ";
241
    else if ( type == TRANS    && {execute_instruction[22],execute_instruction[20]}    == {1'b0, 1'b0}   ) xINSTRUCTION_EXECUTE = "str  ";
242
    else if ( type == TRANS    && {execute_instruction[22],execute_instruction[20]}    == {1'b1, 1'b0}   ) xINSTRUCTION_EXECUTE = "strb ";
243
    else if ( type == REGOP    && opcode == SUB                                                          ) xINSTRUCTION_EXECUTE = "sub  ";
244
    else if ( type == SWI                                                                                ) xINSTRUCTION_EXECUTE = "swi  ";
245
    else if ( type == SWAP     && execute_instruction[22] == 1'b0                                        ) xINSTRUCTION_EXECUTE = "swp  ";
246
    else if ( type == SWAP     && execute_instruction[22] == 1'b1                                        ) xINSTRUCTION_EXECUTE = "swpb ";
247
    else if ( type == REGOP    && opcode == TEQ                                                          ) xINSTRUCTION_EXECUTE = "teq  ";
248
    else if ( type == REGOP    && opcode == TST                                                          ) xINSTRUCTION_EXECUTE = "tst  ";
249
    else                                                                                                   xINSTRUCTION_EXECUTE = "unkow";
250
    end
251
 
252
always @ ( posedge i_clk )
253
    xINSTRUCTION_EXECUTE_R <= xINSTRUCTION_EXECUTE;
254
 
255
always @( posedge i_clk )
256
    clk_count <= clk_count + 1'd1;
257
 
258 35 csantifort
// =================================================================================
259
// Memory Reads and Writes
260
// =================================================================================
261
 
262
reg [31:0] tmp_address;
263
 
264
 
265 16 csantifort
always @( posedge i_clk )
266 35 csantifort
    begin
267
    // Data Write    
268
    if ( get_1bit_signal(0) && !get_1bit_signal(3) )
269
        begin
270
 
271
        $fwrite(decompile_file, "%09d              write   addr ", clk_count);
272
        tmp_address = get_32bit_signal(2);
273
        fwrite_hex_drop_zeros(decompile_file, {tmp_address [31:2], 2'd0} );
274
 
275
        $fwrite(decompile_file, ", data %08h, be %h",
276
                get_32bit_signal(3),    // u_cache.i_write_data
277
                get_4bit_signal (0));   // u_cache.i_byte_enable
278
 
279
        $fwrite(decompile_file, "\n");
280
        end
281
 
282
    // Data Read    
283
    if ( get_1bit_signal(4) && !get_1bit_signal(1) )
284
        begin
285
        $fwrite(decompile_file, "%09d              read    addr ", clk_count);
286
        tmp_address = get_32bit_signal(5);
287
        fwrite_hex_drop_zeros(decompile_file, {tmp_address[31:2], 2'd0} );
288
 
289
        $fwrite(decompile_file, ", data %08h to ", get_32bit_signal(4));
290
        warmreg(get_4bit_signal(1));
291
 
292
        $fwrite(decompile_file, "\n");
293
        end
294
 
295
    // instruction
296 16 csantifort
    if ( execute_now )
297
        begin
298
 
299
            // Interrupts override instructions that are just starting
300
        if ( interrupt_d1 == 3'd0 || interrupt_d1 == 3'd7 )
301
            begin
302
            $fwrite(decompile_file,"%09d  ", clk_count);
303
 
304
            // Right justify the address
305
            if      ( execute_address < 32'h10)        $fwrite(decompile_file,"       %01x:  ", {execute_address[ 3:1], 1'd0});
306
            else if ( execute_address < 32'h100)       $fwrite(decompile_file,"      %02x:  ",  {execute_address[ 7:1], 1'd0});
307
            else if ( execute_address < 32'h1000)      $fwrite(decompile_file,"     %03x:  ",   {execute_address[11:1], 1'd0});
308
            else if ( execute_address < 32'h10000)     $fwrite(decompile_file,"    %04x:  ",    {execute_address[15:1], 1'd0});
309
            else if ( execute_address < 32'h100000)    $fwrite(decompile_file,"   %05x:  ",     {execute_address[19:1], 1'd0});
310
            else if ( execute_address < 32'h1000000)   $fwrite(decompile_file,"  %06x:  ",      {execute_address[23:1], 1'd0});
311
            else if ( execute_address < 32'h10000000)  $fwrite(decompile_file," %07x:  ",       {execute_address[27:1], 1'd0});
312
            else                                       $fwrite(decompile_file,"%8x:  ",         {execute_address[31:1], 1'd0});
313
 
314
            // Mark that the instruction is not being executed 
315
            // condition field in execute stage allows instruction to execute ?
316
            if (!i_instruction_execute)
317
                begin
318
                $fwrite(decompile_file,"-");
319
                if ( type == SWI )
320
                    $display ("Cycle %09d  SWI not taken *************", clk_count);
321
                end
322
            else
323
                $fwrite(decompile_file," ");
324
 
325
            // ========================================
326
            // print the instruction name
327
            // ========================================
328
            case (numchars( xINSTRUCTION_EXECUTE ))
329
                4'd1: $fwrite(decompile_file,"%s", xINSTRUCTION_EXECUTE[39:32] );
330
                4'd2: $fwrite(decompile_file,"%s", xINSTRUCTION_EXECUTE[39:24] );
331
                4'd3: $fwrite(decompile_file,"%s", xINSTRUCTION_EXECUTE[39:16] );
332
                4'd4: $fwrite(decompile_file,"%s", xINSTRUCTION_EXECUTE[39: 8] );
333
            default:  $fwrite(decompile_file,"%s", xINSTRUCTION_EXECUTE[39: 0] );
334
            endcase
335
 
336
            fchars = 8 - numchars(xINSTRUCTION_EXECUTE);
337
 
338
            // Print the Multiple transfer type
339
            if (type   == MTRANS )
340
                begin
341
                w_mtrans_type;
342
                fchars = fchars - 2;
343
                end
344
 
345
            // Print the s bit
346
           if ( ((type == REGOP && !opcode_compare) || type == MULT ) && s_bit == 1'b1 )
347
                begin
348
                $fwrite(decompile_file,"s");
349
                fchars = fchars - 1;
350
                end
351
 
352
            // Print the p bit
353
           if ( type == REGOP && opcode_compare && s_bit == 1'b1 && reg_d == 4'd15 )
354
                begin
355
                $fwrite(decompile_file,"p");
356
                fchars = fchars - 1;
357
                end
358
 
359
            // Print the condition code
360
            if ( condition != AL )
361
                begin
362
                wcond;
363
                fchars = fchars - 2;
364
                end
365
 
366
            // Align spaces after instruction    
367
            case ( fchars )
368
                4'd0: $fwrite(decompile_file,"");
369
                4'd1: $fwrite(decompile_file," ");
370
                4'd2: $fwrite(decompile_file,"  ");
371
                4'd3: $fwrite(decompile_file,"   ");
372
                4'd4: $fwrite(decompile_file,"    ");
373
                4'd5: $fwrite(decompile_file,"     ");
374
                4'd6: $fwrite(decompile_file,"      ");
375
                4'd7: $fwrite(decompile_file,"       ");
376
                4'd8: $fwrite(decompile_file,"        ");
377
            default:  $fwrite(decompile_file,"         ");
378
            endcase
379
 
380
            // ========================================
381
            // print the arguments for the instruction
382
            // ========================================
383
            case ( type )
384
                REGOP:     regop_args;
385
                TRANS:     trans_args;
386
                MTRANS:    mtrans_args;
387
                BRANCH:    branch_args;
388
                MULT:      mult_args;
389
                SWAP:      swap_args;
390
                CODTRANS:  codtrans_args;
391
                COREGOP:   begin
392
                           // `TB_ERROR_MESSAGE
393
                           $write("Coregop not implemented in decompiler yet\n");
394
                           end
395
                CORTRANS:  cortrans_args;
396
                SWI:       $fwrite(decompile_file,"#0x%06h", execute_instruction[23:0]);
397
                default: begin
398
                         `TB_ERROR_MESSAGE
399
                         $write("Unknown Instruction Type ERROR\n");
400
                         end
401
            endcase
402
 
403
            $fwrite( decompile_file,"\n" );
404
            end
405
 
406
        // Undefined Instruction Interrupts    
407
        if ( i_instruction_execute && execute_undefined )
408
            begin
409
            $fwrite( decompile_file,"%09d              interrupt undefined instruction", clk_count );
410
            $fwrite( decompile_file,", return addr " );
411
            $fwrite( decompile_file,"%08x\n",  pcf(get_reg_val(5'd21)-4'd4) );
412
            end
413
 
414
        // Software Interrupt  
415
        if ( i_instruction_execute && type == SWI )
416
            begin
417
            $fwrite( decompile_file,"%09d              interrupt swi", clk_count );
418
            $fwrite( decompile_file,", return addr " );
419
            $fwrite( decompile_file,"%08x\n",  pcf(get_reg_val(5'd21)-4'd4) );
420
            end
421
        end
422 35 csantifort
    end
423
 
424
 
425 16 csantifort
 
426
always @( posedge i_clk )
427 35 csantifort
    if ( !i_core_stall )
428 16 csantifort
        begin
429
        interrupt_d1 <= i_interrupt;
430
 
431
        // Asynchronous Interrupts    
432
        if ( interrupt_d1 != 3'd0 && i_interrupt_state )
433
            begin
434
            $fwrite( decompile_file,"%09d              interrupt ", clk_count );
435
            case ( interrupt_d1 )
436
                3'd1:    $fwrite( decompile_file,"data abort" );
437
                3'd2:    $fwrite( decompile_file,"firq" );
438
                3'd3:    $fwrite( decompile_file,"irq" );
439
                3'd4:    $fwrite( decompile_file,"address exception" );
440
                3'd5:    $fwrite( decompile_file,"instruction abort" );
441
                default: $fwrite( decompile_file,"unknown type" );
442
            endcase
443
            $fwrite( decompile_file,", return addr " );
444
 
445
            case ( interrupt_d1 )
446
                3'd1:    $fwrite(decompile_file,"%08h\n",  pcf(get_reg_val(5'd16)));
447
                3'd2:    $fwrite(decompile_file,"%08h\n",  pcf(get_reg_val(5'd17)));
448
                3'd3:    $fwrite(decompile_file,"%08h\n",  pcf(get_reg_val(5'd18)));
449
                3'd4:    $fwrite(decompile_file,"%08h\n",  pcf(get_reg_val(5'd19)));
450
                3'd5:    $fwrite(decompile_file,"%08h\n",  pcf(get_reg_val(5'd19)));
451
                3'd7:    $fwrite(decompile_file,"%08h\n",  pcf(get_reg_val(5'd20)));
452
                default: ;
453
            endcase
454
            end
455
        end
456
 
457
 
458
// jump
459
// Dont print a jump message for interrupts
460
always @( posedge i_clk )
461
        if (
462
             i_pc_sel != 3'd0 &&
463
             i_pc_wen &&
464 35 csantifort
             !i_core_stall &&
465 16 csantifort
             i_instruction_execute &&
466
             i_interrupt == 3'd0 &&
467
             !execute_undefined &&
468
             type != SWI &&
469
             execute_address != get_32bit_signal(0)  // Don't print jump to same address
470
             )
471
            begin
472
            $fwrite(decompile_file,"%09d              jump    from ", clk_count);
473
            fwrite_hex_drop_zeros(decompile_file,  pcf(execute_address));
474
            $fwrite(decompile_file," to ");
475
            fwrite_hex_drop_zeros(decompile_file,  pcf(get_32bit_signal(0)) ); // u_execute.pc_nxt
476
            $fwrite(decompile_file,", r0 %08h, ",  get_reg_val ( 5'd0 ));
477
            $fwrite(decompile_file,"r1 %08h\n",    get_reg_val ( 5'd1 ));
478
            end
479
 
480
 
481
// =================================================================================
482
// Tasks
483
// =================================================================================
484
 
485
// Write Condition field
486
task wcond;
487
    begin
488
    case( condition)
489
        4'h0:    $fwrite(decompile_file,"eq");
490
        4'h1:    $fwrite(decompile_file,"ne");
491
        4'h2:    $fwrite(decompile_file,"cs");
492
        4'h3:    $fwrite(decompile_file,"cc");
493
        4'h4:    $fwrite(decompile_file,"mi");
494
        4'h5:    $fwrite(decompile_file,"pl");
495
        4'h6:    $fwrite(decompile_file,"vs");
496
        4'h7:    $fwrite(decompile_file,"vc");
497
        4'h8:    $fwrite(decompile_file,"hi");
498
        4'h9:    $fwrite(decompile_file,"ls");
499
        4'ha:    $fwrite(decompile_file,"ge");
500
        4'hb:    $fwrite(decompile_file,"lt");
501
        4'hc:    $fwrite(decompile_file,"gt");
502
        4'hd:    $fwrite(decompile_file,"le");
503
        4'he:    $fwrite(decompile_file,"  ");  // Always
504
        default: $fwrite(decompile_file,"nv");  // Never
505
    endcase
506
    end
507
endtask
508
 
509
// ldm and stm types
510
task w_mtrans_type;
511
    begin
512
    case( mtrans_type )
513
        4'h0:    $fwrite(decompile_file,"da");
514
        4'h1:    $fwrite(decompile_file,"ia");
515
        4'h2:    $fwrite(decompile_file,"db");
516
        4'h3:    $fwrite(decompile_file,"ib");
517
        default: $fwrite(decompile_file,"xx");
518
    endcase
519
    end
520
endtask
521
 
522
// e.g. mrc     15, 0, r9, cr0, cr0, {0}
523
task cortrans_args;
524
    begin
525
    // Co-Processor Number
526
    $fwrite(decompile_file,"%1d, ", execute_instruction[11:8]);
527
    // opcode1
528
    $fwrite(decompile_file,"%1d, ", execute_instruction[23:21]);
529
    // Rd [15:12]
530
    warmreg(reg_d);
531
    // CRn [19:16]
532
    $fwrite(decompile_file,", cr%1d", execute_instruction[19:16]);
533
    // CRm [3:0]
534
    $fwrite(decompile_file,", cr%1d", execute_instruction[3:0]);
535
    // Opcode2 [7:5]
536
    $fwrite(decompile_file,", {%1d}",   execute_instruction[7:5]);
537
    end
538
endtask
539
 
540
 
541
// ldc  15, 0, r9, cr0, cr0, {0}
542
task codtrans_args;
543
    begin
544
    // Co-Processor Number
545
    $fwrite(decompile_file,"%1d, ", execute_instruction[11:8]);
546
    // CRd [15:12]
547
    $fwrite(decompile_file,"cr%1d, ", execute_instruction[15:12]);
548
    // Rd [19:16]
549
    warmreg(reg_n);
550
    end
551
endtask
552
 
553
 
554
task branch_args;
555
reg [31:0] shift_amount;
556
    begin
557
    if (execute_instruction[23]) // negative
558
        shift_amount = {~execute_instruction[23:0] + 24'd1, 2'd0};
559
    else
560
        shift_amount = {execute_instruction[23:0], 2'd0};
561
 
562
    if (execute_instruction[23]) // negative
563
        fwrite_hex_drop_zeros ( decompile_file, get_reg_val( 5'd21 ) - shift_amount );
564
    else
565
        fwrite_hex_drop_zeros ( decompile_file, get_reg_val( 5'd21 ) + shift_amount );
566
    end
567
endtask
568
 
569
 
570
task mult_args;
571
    begin
572
    warmreg(reg_n);  // Rd is in the Rn position for MULT instructions
573
    $fwrite(decompile_file,", ");
574
    warmreg(reg_m);
575
    $fwrite(decompile_file,", ");
576
    warmreg(reg_s);
577
 
578
    if (execute_instruction[21]) // MLA
579
        begin
580
        $fwrite(decompile_file,", ");
581
        warmreg(reg_d);
582
        end
583
    end
584
endtask
585
 
586
 
587
task swap_args;
588
    begin
589
    warmreg(reg_d);
590
    $fwrite(decompile_file,", ");
591
    warmreg(reg_m);
592
    $fwrite(decompile_file,", [");
593
    warmreg(reg_n);
594
    $fwrite(decompile_file,"]");
595
    end
596
endtask
597
 
598
 
599
task regop_args;
600
    begin
601
    if (!opcode_compare)
602
        warmreg(reg_d);
603
 
604
    if (!opcode_move )
605
        begin
606
        if (!opcode_compare)
607
            begin
608
            $fwrite(decompile_file,", ");
609
            if (reg_d < 4'd10 || reg_d > 4'd12)
610
                $fwrite(decompile_file," ");
611
            end
612
        warmreg(reg_n);
613
        $fwrite(decompile_file,", ");
614
        if (reg_n < 4'd10 || reg_n > 4'd12)
615
            $fwrite(decompile_file," ");
616
        end
617
    else
618
        begin
619
        $fwrite(decompile_file,", ");
620
        if (reg_d < 4'd10 || reg_d > 4'd12)
621
            $fwrite(decompile_file," ");
622
        end
623
 
624
    if (shift_op_imm)
625
        begin
626
        if (|imm32[31:15])
627
            $fwrite(decompile_file,"#0x%08h", imm32);
628
        else
629
            $fwrite(decompile_file,"#%1d", imm32);
630
        end
631
    else // Rm
632
        begin
633
        warmreg(reg_m);
634
        if (execute_instruction[4])
635
            // Register Shifts
636
            wshiftreg;
637
        else
638
            // Immediate shifts
639
            wshift;
640
        end
641
    end
642
endtask
643
 
644
 
645
task trans_args;
646
    begin
647
    warmreg(reg_d);   // Destination register
648
 
649
    casez ({execute_instruction[25:23], execute_instruction[21], no_shift, offset12==12'd0})
650
           6'b0100?0 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", #-%1d]" , offset12); end
651
           6'b0110?0 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", #%1d]"  , offset12); end
652
           6'b0100?1 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"]"); end
653
           6'b0110?1 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"]"); end
654
           6'b0101?? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", #-%1d]!", offset12); end
655
           6'b0111?? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", #%1d]!" , offset12); end
656
 
657
           6'b0000?0 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], #-%1d", offset12); end
658
           6'b0010?0 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], #%1d" , offset12); end
659
           6'b0001?0 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], #-%1d", offset12); end
660
           6'b0011?0 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], #%1d" , offset12); end
661
 
662
           6'b0000?1 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"]"); end
663
           6'b0010?1 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"]"); end
664
           6'b0001?1 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"]"); end
665
           6'b0011?1 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"]"); end
666
 
667
           6'b11001? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", -");  warmreg(reg_m); $fwrite(decompile_file,"]");  end
668
           6'b11101? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", ");   warmreg(reg_m); $fwrite(decompile_file,"]");  end
669
           6'b11011? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", -");  warmreg(reg_m); $fwrite(decompile_file,"]!"); end
670
           6'b11111? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", ");   warmreg(reg_m); $fwrite(decompile_file,"]!"); end
671
 
672
           6'b10001? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], -"); warmreg(reg_m);  end
673
           6'b10101? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], ");  warmreg(reg_m);  end
674
           6'b10011? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], -"); warmreg(reg_m);  end
675
           6'b10111? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], ");  warmreg(reg_m);  end
676
 
677
           6'b11000? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", -");  warmreg(reg_m); wshift; $fwrite(decompile_file,"]"); end
678
           6'b11100? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", ");   warmreg(reg_m); wshift; $fwrite(decompile_file,"]"); end
679
           6'b11010? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", -");  warmreg(reg_m); wshift; $fwrite(decompile_file,"]!");end
680
           6'b11110? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", ");   warmreg(reg_m); wshift; $fwrite(decompile_file,"]!");end
681
 
682
           6'b10000? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], -"); warmreg(reg_m); wshift; end
683
           6'b10100? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], ");  warmreg(reg_m); wshift; end
684
           6'b10010? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], -"); warmreg(reg_m); wshift; end
685
           6'b10110? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], ");  warmreg(reg_m); wshift; end
686
 
687
    endcase
688
    end
689
endtask
690
 
691
 
692
task mtrans_args;
693
    begin
694
    warmreg(reg_n);
695
    if (execute_instruction[21]) $fwrite(decompile_file,"!");
696
    $fwrite(decompile_file,", {");
697
    for (i=0;i<16;i=i+1)
698
        if (execute_instruction[i])
699
            begin
700
            warmreg(i);
701
            if (more_to_come(execute_instruction[15:0], i))
702
                $fwrite(decompile_file,", ");
703
            end
704
    $fwrite(decompile_file,"}");
705
    // SDM: store the user mode registers, when in priviledged mode     
706
    if (execute_instruction[22:20] == 3'b100)
707
        $fwrite(decompile_file,"^");
708
    end
709
endtask
710
 
711
 
712
task wshift;
713
    begin
714
    // Check that its a valid shift operation. LSL by #0 is the null operator                                    
715
    if (execute_instruction[6:5] != LSL || shift_imm != 5'd0)
716
        begin
717
        case(execute_instruction[6:5])
718
            2'd0: $fwrite(decompile_file,", lsl");
719
            2'd1: $fwrite(decompile_file,", lsr");
720
            2'd2: $fwrite(decompile_file,", asr");
721
            2'd3: if (shift_imm == 5'd0) $fwrite(decompile_file,", rrx"); else $fwrite(decompile_file,", ror");
722
        endcase
723
 
724
       if (execute_instruction[6:5] != 2'd3 || shift_imm != 5'd0)
725
           $fwrite(decompile_file," #%1d", shift_imm);
726
       end
727
    end
728
endtask
729
 
730
 
731
task wshiftreg;
732
    begin
733
    case(execute_instruction[6:5])
734
        2'd0: $fwrite(decompile_file,", lsl ");
735
        2'd1: $fwrite(decompile_file,", lsr ");
736
        2'd2: $fwrite(decompile_file,", asr ");
737
        2'd3: $fwrite(decompile_file,", ror ");
738
    endcase
739
 
740
    warmreg(reg_s);
741
    end
742
endtask
743
 
744
 
745
task warmreg;
746
input [3:0] regnum;
747
    begin
748
    if (regnum < 4'd12)
749
        $fwrite(decompile_file,"r%1d", regnum);
750
    else
751
    case (regnum)
752
        4'd12   : $fwrite(decompile_file,"ip");
753
        4'd13   : $fwrite(decompile_file,"sp");
754
        4'd14   : $fwrite(decompile_file,"lr");
755
        4'd15   : $fwrite(decompile_file,"pc");
756
    endcase
757
    end
758
endtask
759
 
760
 
761
task fwrite_hex_drop_zeros;
762
input [31:0] file;
763
input [31:0] num;
764
    begin
765
    if (num[31:28] != 4'd0)
766
        $fwrite(file, "%x", num);
767
    else if (num[27:24] != 4'd0)
768
        $fwrite(file, "%x", num[27:0]);
769
    else if (num[23:20] != 4'd0)
770
        $fwrite(file, "%x", num[23:0]);
771
    else if (num[19:16] != 4'd0)
772
        $fwrite(file, "%x", num[19:0]);
773
    else if (num[15:12] != 4'd0)
774
        $fwrite(file, "%x", num[15:0]);
775
    else if (num[11:8] != 4'd0)
776
        $fwrite(file, "%x", num[11:0]);
777
    else if (num[7:4] != 4'd0)
778
        $fwrite(file, "%x", num[7:0]);
779
    else
780
        $fwrite(file, "%x", num[3:0]);
781
 
782
    end
783
endtask
784
 
785
 
786
 
787
// =================================================================================
788
// Functions
789
// =================================================================================
790
 
791
// Get current value of register
792
function [31:0] get_reg_val;
793
input [4:0] regnum;
794
begin
795
    case (regnum)
796
        5'd0   : get_reg_val = `U_REGISTER_BANK.r0_out;
797
        5'd1   : get_reg_val = `U_REGISTER_BANK.r1_out;
798
        5'd2   : get_reg_val = `U_REGISTER_BANK.r2_out;
799
        5'd3   : get_reg_val = `U_REGISTER_BANK.r3_out;
800
        5'd4   : get_reg_val = `U_REGISTER_BANK.r4_out;
801
        5'd5   : get_reg_val = `U_REGISTER_BANK.r5_out;
802
        5'd6   : get_reg_val = `U_REGISTER_BANK.r6_out;
803
        5'd7   : get_reg_val = `U_REGISTER_BANK.r7_out;
804
        5'd8   : get_reg_val = `U_REGISTER_BANK.r8_out;
805
        5'd9   : get_reg_val = `U_REGISTER_BANK.r9_out;
806
        5'd10  : get_reg_val = `U_REGISTER_BANK.r10_out;
807
        5'd11  : get_reg_val = `U_REGISTER_BANK.r11_out;
808
        5'd12  : get_reg_val = `U_REGISTER_BANK.r12_out;
809
        5'd13  : get_reg_val = `U_REGISTER_BANK.r13_out;
810
        5'd14  : get_reg_val = `U_REGISTER_BANK.r14_out;
811
        5'd15  : get_reg_val = `U_REGISTER_BANK.r15_out_rm; // the version of pc with status bits 
812
 
813
        5'd16  : get_reg_val = `U_REGISTER_BANK.r14_svc;
814
        5'd17  : get_reg_val = `U_REGISTER_BANK.r14_firq;
815
        5'd18  : get_reg_val = `U_REGISTER_BANK.r14_irq;
816
        5'd19  : get_reg_val = `U_REGISTER_BANK.r14_svc;
817
        5'd20  : get_reg_val = `U_REGISTER_BANK.r14_svc;
818
        5'd21  : get_reg_val = `U_REGISTER_BANK.r15_out_rn; // the version of pc without status bits 
819
    endcase
820
end
821
endfunction
822
 
823
 
824
function [31:0] get_32bit_signal;
825
input [2:0] num;
826
begin
827
    case (num)
828
        3'd0: get_32bit_signal = `U_EXECUTE.pc_nxt;
829
        3'd1: get_32bit_signal = `U_EXECUTE.o_iaddress;
830
        3'd2: get_32bit_signal = `U_EXECUTE.o_daddress;
831
        3'd3: get_32bit_signal = `U_EXECUTE.o_write_data;
832
//         3'd4: get_32bit_signal = `U_EXECUTE.read_data_filtered;
833
        3'd4: get_32bit_signal = `U_EXECUTE.i_wb_read_data;
834
        3'd5: get_32bit_signal = `U_WB.daddress_r;
835
    endcase
836
end
837
endfunction
838
 
839
 
840
function get_1bit_signal;
841
input [2:0] num;
842
begin
843
    case (num)
844
        3'd0: get_1bit_signal = `U_EXECUTE.o_write_enable;
845
        3'd1: get_1bit_signal = `U_AMBER.mem_stall;
846
        3'd2: get_1bit_signal = `U_EXECUTE.o_daddress_valid;
847 35 csantifort
        3'd3: get_1bit_signal = `U_AMBER.core_stall;
848 16 csantifort
        3'd4: get_1bit_signal = `U_WB.mem_read_data_valid_r;
849
    endcase
850
end
851
endfunction
852
 
853
 
854
function [3:0] get_4bit_signal;
855
input [2:0] num;
856
begin
857
    case (num)
858
        3'd0: get_4bit_signal = `U_EXECUTE.o_byte_enable;
859
        3'd1: get_4bit_signal = `U_WB.mem_load_rd_r;
860
    endcase
861
end
862
endfunction
863
 
864
 
865
function [3:0] numchars;
866
input [(5*8)-1:0] xINSTRUCTION_EXECUTE;
867
begin
868
     if (xINSTRUCTION_EXECUTE[31:0] == "    ")
869
    numchars = 4'd1;
870
else if (xINSTRUCTION_EXECUTE[23:0] == "   ")
871
    numchars = 4'd2;
872
else if (xINSTRUCTION_EXECUTE[15:0] == "  ")
873
    numchars = 4'd3;
874
else if (xINSTRUCTION_EXECUTE[7:0]  == " ")
875
    numchars = 4'd4;
876
else
877
    numchars = 4'd5;
878
end
879
endfunction
880
 
881
 
882
function more_to_come;
883
input [15:0] regs;
884
input [31:0] i;
885
begin
886
case (i)
887
    15 : more_to_come = 1'd0;
888
    14 : more_to_come =  regs[15]    ? 1'd1 : 1'd0;
889
    13 : more_to_come = |regs[15:14] ? 1'd1 : 1'd0;
890
    12 : more_to_come = |regs[15:13] ? 1'd1 : 1'd0;
891
    11 : more_to_come = |regs[15:12] ? 1'd1 : 1'd0;
892
    10 : more_to_come = |regs[15:11] ? 1'd1 : 1'd0;
893
     9 : more_to_come = |regs[15:10] ? 1'd1 : 1'd0;
894
     8 : more_to_come = |regs[15: 9] ? 1'd1 : 1'd0;
895
     7 : more_to_come = |regs[15: 8] ? 1'd1 : 1'd0;
896
     6 : more_to_come = |regs[15: 7] ? 1'd1 : 1'd0;
897
     5 : more_to_come = |regs[15: 6] ? 1'd1 : 1'd0;
898
     4 : more_to_come = |regs[15: 5] ? 1'd1 : 1'd0;
899
     3 : more_to_come = |regs[15: 4] ? 1'd1 : 1'd0;
900
     2 : more_to_come = |regs[15: 3] ? 1'd1 : 1'd0;
901
     1 : more_to_come = |regs[15: 2] ? 1'd1 : 1'd0;
902
 
903
endcase
904
end
905
endfunction
906
 
907
`endif
908
 
909
endmodule
910
 

powered by: WebSVN 2.1.0

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