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 |
82 |
csantifort |
`include "global_timescale.vh"
|
43 |
|
|
`include "global_defines.vh"
|
44 |
|
|
`include "a25_config_defines.vh"
|
45 |
16 |
csantifort |
|
46 |
|
|
module a25_decompile
|
47 |
|
|
(
|
48 |
|
|
input i_clk,
|
49 |
35 |
csantifort |
input i_core_stall,
|
50 |
16 |
csantifort |
input [31:0] i_instruction,
|
51 |
|
|
input i_instruction_valid,
|
52 |
|
|
input i_instruction_undefined,
|
53 |
|
|
input i_instruction_execute,
|
54 |
|
|
input [2:0] i_interrupt, // non-zero value means interrupt triggered
|
55 |
|
|
input i_interrupt_state,
|
56 |
|
|
input [31:0] i_instruction_address,
|
57 |
|
|
input [2:0] i_pc_sel,
|
58 |
|
|
input i_pc_wen
|
59 |
|
|
|
60 |
|
|
);
|
61 |
|
|
|
62 |
82 |
csantifort |
`include "a25_localparams.vh"
|
63 |
16 |
csantifort |
|
64 |
|
|
`ifdef A25_DECOMPILE
|
65 |
|
|
|
66 |
|
|
integer i;
|
67 |
|
|
|
68 |
|
|
wire [31:0] imm32;
|
69 |
|
|
wire [7:0] imm8;
|
70 |
|
|
wire [11:0] offset12;
|
71 |
|
|
wire [7:0] offset8;
|
72 |
|
|
wire [3:0] reg_n, reg_d, reg_m, reg_s;
|
73 |
|
|
wire [4:0] shift_imm;
|
74 |
|
|
wire [3:0] opcode;
|
75 |
|
|
wire [3:0] condition;
|
76 |
|
|
wire [3:0] type;
|
77 |
|
|
wire opcode_compare;
|
78 |
|
|
wire opcode_move;
|
79 |
|
|
wire no_shift;
|
80 |
|
|
wire shift_op_imm;
|
81 |
|
|
wire [1:0] mtrans_type;
|
82 |
|
|
wire s_bit;
|
83 |
|
|
|
84 |
|
|
reg [(5*8)-1:0] xINSTRUCTION_EXECUTE;
|
85 |
|
|
reg [(5*8)-1:0] xINSTRUCTION_EXECUTE_R = "--- ";
|
86 |
|
|
wire [(8*8)-1:0] TYPE_NAME;
|
87 |
|
|
reg [3:0] fchars;
|
88 |
|
|
reg [31:0] execute_address = 'd0;
|
89 |
|
|
reg [2:0] interrupt_d1;
|
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 |
35 |
csantifort |
// =================================================================================
|
256 |
|
|
// Memory Reads and Writes
|
257 |
|
|
// =================================================================================
|
258 |
|
|
|
259 |
|
|
reg [31:0] tmp_address;
|
260 |
|
|
|
261 |
|
|
|
262 |
16 |
csantifort |
always @( posedge i_clk )
|
263 |
35 |
csantifort |
begin
|
264 |
|
|
// Data Write
|
265 |
|
|
if ( get_1bit_signal(0) && !get_1bit_signal(3) )
|
266 |
|
|
begin
|
267 |
|
|
|
268 |
58 |
csantifort |
$fwrite(decompile_file, "%09d write addr ", `U_TB.clk_count);
|
269 |
35 |
csantifort |
tmp_address = get_32bit_signal(2);
|
270 |
|
|
fwrite_hex_drop_zeros(decompile_file, {tmp_address [31:2], 2'd0} );
|
271 |
|
|
|
272 |
|
|
$fwrite(decompile_file, ", data %08h, be %h",
|
273 |
|
|
get_32bit_signal(3), // u_cache.i_write_data
|
274 |
|
|
get_4bit_signal (0)); // u_cache.i_byte_enable
|
275 |
|
|
|
276 |
|
|
$fwrite(decompile_file, "\n");
|
277 |
|
|
end
|
278 |
|
|
|
279 |
|
|
// Data Read
|
280 |
|
|
if ( get_1bit_signal(4) && !get_1bit_signal(1) )
|
281 |
|
|
begin
|
282 |
58 |
csantifort |
$fwrite(decompile_file, "%09d read addr ", `U_TB.clk_count);
|
283 |
35 |
csantifort |
tmp_address = get_32bit_signal(5);
|
284 |
|
|
fwrite_hex_drop_zeros(decompile_file, {tmp_address[31:2], 2'd0} );
|
285 |
|
|
|
286 |
|
|
$fwrite(decompile_file, ", data %08h to ", get_32bit_signal(4));
|
287 |
|
|
warmreg(get_4bit_signal(1));
|
288 |
|
|
|
289 |
|
|
$fwrite(decompile_file, "\n");
|
290 |
|
|
end
|
291 |
|
|
|
292 |
|
|
// instruction
|
293 |
16 |
csantifort |
if ( execute_now )
|
294 |
|
|
begin
|
295 |
|
|
|
296 |
|
|
// Interrupts override instructions that are just starting
|
297 |
|
|
if ( interrupt_d1 == 3'd0 || interrupt_d1 == 3'd7 )
|
298 |
|
|
begin
|
299 |
58 |
csantifort |
$fwrite(decompile_file,"%09d ", `U_TB.clk_count);
|
300 |
16 |
csantifort |
|
301 |
|
|
// Right justify the address
|
302 |
|
|
if ( execute_address < 32'h10) $fwrite(decompile_file," %01x: ", {execute_address[ 3:1], 1'd0});
|
303 |
|
|
else if ( execute_address < 32'h100) $fwrite(decompile_file," %02x: ", {execute_address[ 7:1], 1'd0});
|
304 |
|
|
else if ( execute_address < 32'h1000) $fwrite(decompile_file," %03x: ", {execute_address[11:1], 1'd0});
|
305 |
|
|
else if ( execute_address < 32'h10000) $fwrite(decompile_file," %04x: ", {execute_address[15:1], 1'd0});
|
306 |
|
|
else if ( execute_address < 32'h100000) $fwrite(decompile_file," %05x: ", {execute_address[19:1], 1'd0});
|
307 |
|
|
else if ( execute_address < 32'h1000000) $fwrite(decompile_file," %06x: ", {execute_address[23:1], 1'd0});
|
308 |
|
|
else if ( execute_address < 32'h10000000) $fwrite(decompile_file," %07x: ", {execute_address[27:1], 1'd0});
|
309 |
|
|
else $fwrite(decompile_file,"%8x: ", {execute_address[31:1], 1'd0});
|
310 |
|
|
|
311 |
|
|
// Mark that the instruction is not being executed
|
312 |
|
|
// condition field in execute stage allows instruction to execute ?
|
313 |
|
|
if (!i_instruction_execute)
|
314 |
|
|
begin
|
315 |
|
|
$fwrite(decompile_file,"-");
|
316 |
|
|
if ( type == SWI )
|
317 |
58 |
csantifort |
$display ("Cycle %09d SWI not taken *************", `U_TB.clk_count);
|
318 |
16 |
csantifort |
end
|
319 |
|
|
else
|
320 |
|
|
$fwrite(decompile_file," ");
|
321 |
|
|
|
322 |
|
|
// ========================================
|
323 |
|
|
// print the instruction name
|
324 |
|
|
// ========================================
|
325 |
|
|
case (numchars( xINSTRUCTION_EXECUTE ))
|
326 |
|
|
4'd1: $fwrite(decompile_file,"%s", xINSTRUCTION_EXECUTE[39:32] );
|
327 |
|
|
4'd2: $fwrite(decompile_file,"%s", xINSTRUCTION_EXECUTE[39:24] );
|
328 |
|
|
4'd3: $fwrite(decompile_file,"%s", xINSTRUCTION_EXECUTE[39:16] );
|
329 |
|
|
4'd4: $fwrite(decompile_file,"%s", xINSTRUCTION_EXECUTE[39: 8] );
|
330 |
|
|
default: $fwrite(decompile_file,"%s", xINSTRUCTION_EXECUTE[39: 0] );
|
331 |
|
|
endcase
|
332 |
|
|
|
333 |
|
|
fchars = 8 - numchars(xINSTRUCTION_EXECUTE);
|
334 |
|
|
|
335 |
|
|
// Print the Multiple transfer type
|
336 |
|
|
if (type == MTRANS )
|
337 |
|
|
begin
|
338 |
|
|
w_mtrans_type;
|
339 |
|
|
fchars = fchars - 2;
|
340 |
|
|
end
|
341 |
|
|
|
342 |
|
|
// Print the s bit
|
343 |
|
|
if ( ((type == REGOP && !opcode_compare) || type == MULT ) && s_bit == 1'b1 )
|
344 |
|
|
begin
|
345 |
|
|
$fwrite(decompile_file,"s");
|
346 |
|
|
fchars = fchars - 1;
|
347 |
|
|
end
|
348 |
|
|
|
349 |
|
|
// Print the p bit
|
350 |
|
|
if ( type == REGOP && opcode_compare && s_bit == 1'b1 && reg_d == 4'd15 )
|
351 |
|
|
begin
|
352 |
|
|
$fwrite(decompile_file,"p");
|
353 |
|
|
fchars = fchars - 1;
|
354 |
|
|
end
|
355 |
|
|
|
356 |
|
|
// Print the condition code
|
357 |
|
|
if ( condition != AL )
|
358 |
|
|
begin
|
359 |
|
|
wcond;
|
360 |
|
|
fchars = fchars - 2;
|
361 |
|
|
end
|
362 |
|
|
|
363 |
|
|
// Align spaces after instruction
|
364 |
|
|
case ( fchars )
|
365 |
|
|
4'd0: $fwrite(decompile_file,"");
|
366 |
|
|
4'd1: $fwrite(decompile_file," ");
|
367 |
|
|
4'd2: $fwrite(decompile_file," ");
|
368 |
|
|
4'd3: $fwrite(decompile_file," ");
|
369 |
|
|
4'd4: $fwrite(decompile_file," ");
|
370 |
|
|
4'd5: $fwrite(decompile_file," ");
|
371 |
|
|
4'd6: $fwrite(decompile_file," ");
|
372 |
|
|
4'd7: $fwrite(decompile_file," ");
|
373 |
|
|
4'd8: $fwrite(decompile_file," ");
|
374 |
|
|
default: $fwrite(decompile_file," ");
|
375 |
|
|
endcase
|
376 |
|
|
|
377 |
|
|
// ========================================
|
378 |
|
|
// print the arguments for the instruction
|
379 |
|
|
// ========================================
|
380 |
|
|
case ( type )
|
381 |
|
|
REGOP: regop_args;
|
382 |
|
|
TRANS: trans_args;
|
383 |
|
|
MTRANS: mtrans_args;
|
384 |
|
|
BRANCH: branch_args;
|
385 |
|
|
MULT: mult_args;
|
386 |
|
|
SWAP: swap_args;
|
387 |
|
|
CODTRANS: codtrans_args;
|
388 |
|
|
COREGOP: begin
|
389 |
|
|
// `TB_ERROR_MESSAGE
|
390 |
|
|
$write("Coregop not implemented in decompiler yet\n");
|
391 |
|
|
end
|
392 |
|
|
CORTRANS: cortrans_args;
|
393 |
|
|
SWI: $fwrite(decompile_file,"#0x%06h", execute_instruction[23:0]);
|
394 |
|
|
default: begin
|
395 |
|
|
`TB_ERROR_MESSAGE
|
396 |
|
|
$write("Unknown Instruction Type ERROR\n");
|
397 |
|
|
end
|
398 |
|
|
endcase
|
399 |
|
|
|
400 |
|
|
$fwrite( decompile_file,"\n" );
|
401 |
|
|
end
|
402 |
|
|
|
403 |
|
|
// Undefined Instruction Interrupts
|
404 |
|
|
if ( i_instruction_execute && execute_undefined )
|
405 |
|
|
begin
|
406 |
58 |
csantifort |
$fwrite( decompile_file,"%09d interrupt undefined instruction", `U_TB.clk_count );
|
407 |
16 |
csantifort |
$fwrite( decompile_file,", return addr " );
|
408 |
|
|
$fwrite( decompile_file,"%08x\n", pcf(get_reg_val(5'd21)-4'd4) );
|
409 |
|
|
end
|
410 |
|
|
|
411 |
|
|
// Software Interrupt
|
412 |
|
|
if ( i_instruction_execute && type == SWI )
|
413 |
|
|
begin
|
414 |
58 |
csantifort |
$fwrite( decompile_file,"%09d interrupt swi", `U_TB.clk_count );
|
415 |
16 |
csantifort |
$fwrite( decompile_file,", return addr " );
|
416 |
|
|
$fwrite( decompile_file,"%08x\n", pcf(get_reg_val(5'd21)-4'd4) );
|
417 |
|
|
end
|
418 |
|
|
end
|
419 |
35 |
csantifort |
end
|
420 |
|
|
|
421 |
|
|
|
422 |
16 |
csantifort |
|
423 |
|
|
always @( posedge i_clk )
|
424 |
35 |
csantifort |
if ( !i_core_stall )
|
425 |
16 |
csantifort |
begin
|
426 |
|
|
interrupt_d1 <= i_interrupt;
|
427 |
|
|
|
428 |
|
|
// Asynchronous Interrupts
|
429 |
|
|
if ( interrupt_d1 != 3'd0 && i_interrupt_state )
|
430 |
|
|
begin
|
431 |
58 |
csantifort |
$fwrite( decompile_file,"%09d interrupt ", `U_TB.clk_count );
|
432 |
16 |
csantifort |
case ( interrupt_d1 )
|
433 |
|
|
3'd1: $fwrite( decompile_file,"data abort" );
|
434 |
|
|
3'd2: $fwrite( decompile_file,"firq" );
|
435 |
|
|
3'd3: $fwrite( decompile_file,"irq" );
|
436 |
|
|
3'd4: $fwrite( decompile_file,"address exception" );
|
437 |
|
|
3'd5: $fwrite( decompile_file,"instruction abort" );
|
438 |
|
|
default: $fwrite( decompile_file,"unknown type" );
|
439 |
|
|
endcase
|
440 |
|
|
$fwrite( decompile_file,", return addr " );
|
441 |
|
|
|
442 |
|
|
case ( interrupt_d1 )
|
443 |
|
|
3'd1: $fwrite(decompile_file,"%08h\n", pcf(get_reg_val(5'd16)));
|
444 |
|
|
3'd2: $fwrite(decompile_file,"%08h\n", pcf(get_reg_val(5'd17)));
|
445 |
|
|
3'd3: $fwrite(decompile_file,"%08h\n", pcf(get_reg_val(5'd18)));
|
446 |
|
|
3'd4: $fwrite(decompile_file,"%08h\n", pcf(get_reg_val(5'd19)));
|
447 |
|
|
3'd5: $fwrite(decompile_file,"%08h\n", pcf(get_reg_val(5'd19)));
|
448 |
|
|
3'd7: $fwrite(decompile_file,"%08h\n", pcf(get_reg_val(5'd20)));
|
449 |
|
|
default: ;
|
450 |
|
|
endcase
|
451 |
|
|
end
|
452 |
|
|
end
|
453 |
|
|
|
454 |
|
|
|
455 |
|
|
// jump
|
456 |
|
|
// Dont print a jump message for interrupts
|
457 |
|
|
always @( posedge i_clk )
|
458 |
|
|
if (
|
459 |
|
|
i_pc_sel != 3'd0 &&
|
460 |
|
|
i_pc_wen &&
|
461 |
35 |
csantifort |
!i_core_stall &&
|
462 |
16 |
csantifort |
i_instruction_execute &&
|
463 |
|
|
i_interrupt == 3'd0 &&
|
464 |
|
|
!execute_undefined &&
|
465 |
|
|
type != SWI &&
|
466 |
|
|
execute_address != get_32bit_signal(0) // Don't print jump to same address
|
467 |
|
|
)
|
468 |
|
|
begin
|
469 |
58 |
csantifort |
$fwrite(decompile_file,"%09d jump from ", `U_TB.clk_count);
|
470 |
16 |
csantifort |
fwrite_hex_drop_zeros(decompile_file, pcf(execute_address));
|
471 |
|
|
$fwrite(decompile_file," to ");
|
472 |
|
|
fwrite_hex_drop_zeros(decompile_file, pcf(get_32bit_signal(0)) ); // u_execute.pc_nxt
|
473 |
|
|
$fwrite(decompile_file,", r0 %08h, ", get_reg_val ( 5'd0 ));
|
474 |
|
|
$fwrite(decompile_file,"r1 %08h\n", get_reg_val ( 5'd1 ));
|
475 |
|
|
end
|
476 |
|
|
|
477 |
|
|
|
478 |
|
|
// =================================================================================
|
479 |
|
|
// Tasks
|
480 |
|
|
// =================================================================================
|
481 |
|
|
|
482 |
|
|
// Write Condition field
|
483 |
|
|
task wcond;
|
484 |
|
|
begin
|
485 |
|
|
case( condition)
|
486 |
|
|
4'h0: $fwrite(decompile_file,"eq");
|
487 |
|
|
4'h1: $fwrite(decompile_file,"ne");
|
488 |
|
|
4'h2: $fwrite(decompile_file,"cs");
|
489 |
|
|
4'h3: $fwrite(decompile_file,"cc");
|
490 |
|
|
4'h4: $fwrite(decompile_file,"mi");
|
491 |
|
|
4'h5: $fwrite(decompile_file,"pl");
|
492 |
|
|
4'h6: $fwrite(decompile_file,"vs");
|
493 |
|
|
4'h7: $fwrite(decompile_file,"vc");
|
494 |
|
|
4'h8: $fwrite(decompile_file,"hi");
|
495 |
|
|
4'h9: $fwrite(decompile_file,"ls");
|
496 |
|
|
4'ha: $fwrite(decompile_file,"ge");
|
497 |
|
|
4'hb: $fwrite(decompile_file,"lt");
|
498 |
|
|
4'hc: $fwrite(decompile_file,"gt");
|
499 |
|
|
4'hd: $fwrite(decompile_file,"le");
|
500 |
|
|
4'he: $fwrite(decompile_file," "); // Always
|
501 |
|
|
default: $fwrite(decompile_file,"nv"); // Never
|
502 |
|
|
endcase
|
503 |
|
|
end
|
504 |
|
|
endtask
|
505 |
|
|
|
506 |
|
|
// ldm and stm types
|
507 |
|
|
task w_mtrans_type;
|
508 |
|
|
begin
|
509 |
|
|
case( mtrans_type )
|
510 |
|
|
4'h0: $fwrite(decompile_file,"da");
|
511 |
|
|
4'h1: $fwrite(decompile_file,"ia");
|
512 |
|
|
4'h2: $fwrite(decompile_file,"db");
|
513 |
|
|
4'h3: $fwrite(decompile_file,"ib");
|
514 |
|
|
default: $fwrite(decompile_file,"xx");
|
515 |
|
|
endcase
|
516 |
|
|
end
|
517 |
|
|
endtask
|
518 |
|
|
|
519 |
|
|
// e.g. mrc 15, 0, r9, cr0, cr0, {0}
|
520 |
|
|
task cortrans_args;
|
521 |
|
|
begin
|
522 |
|
|
// Co-Processor Number
|
523 |
|
|
$fwrite(decompile_file,"%1d, ", execute_instruction[11:8]);
|
524 |
|
|
// opcode1
|
525 |
|
|
$fwrite(decompile_file,"%1d, ", execute_instruction[23:21]);
|
526 |
|
|
// Rd [15:12]
|
527 |
|
|
warmreg(reg_d);
|
528 |
|
|
// CRn [19:16]
|
529 |
|
|
$fwrite(decompile_file,", cr%1d", execute_instruction[19:16]);
|
530 |
|
|
// CRm [3:0]
|
531 |
|
|
$fwrite(decompile_file,", cr%1d", execute_instruction[3:0]);
|
532 |
|
|
// Opcode2 [7:5]
|
533 |
|
|
$fwrite(decompile_file,", {%1d}", execute_instruction[7:5]);
|
534 |
|
|
end
|
535 |
|
|
endtask
|
536 |
|
|
|
537 |
|
|
|
538 |
|
|
// ldc 15, 0, r9, cr0, cr0, {0}
|
539 |
|
|
task codtrans_args;
|
540 |
|
|
begin
|
541 |
|
|
// Co-Processor Number
|
542 |
|
|
$fwrite(decompile_file,"%1d, ", execute_instruction[11:8]);
|
543 |
|
|
// CRd [15:12]
|
544 |
|
|
$fwrite(decompile_file,"cr%1d, ", execute_instruction[15:12]);
|
545 |
|
|
// Rd [19:16]
|
546 |
|
|
warmreg(reg_n);
|
547 |
|
|
end
|
548 |
|
|
endtask
|
549 |
|
|
|
550 |
|
|
|
551 |
|
|
task branch_args;
|
552 |
|
|
reg [31:0] shift_amount;
|
553 |
|
|
begin
|
554 |
|
|
if (execute_instruction[23]) // negative
|
555 |
|
|
shift_amount = {~execute_instruction[23:0] + 24'd1, 2'd0};
|
556 |
|
|
else
|
557 |
|
|
shift_amount = {execute_instruction[23:0], 2'd0};
|
558 |
|
|
|
559 |
|
|
if (execute_instruction[23]) // negative
|
560 |
|
|
fwrite_hex_drop_zeros ( decompile_file, get_reg_val( 5'd21 ) - shift_amount );
|
561 |
|
|
else
|
562 |
|
|
fwrite_hex_drop_zeros ( decompile_file, get_reg_val( 5'd21 ) + shift_amount );
|
563 |
|
|
end
|
564 |
|
|
endtask
|
565 |
|
|
|
566 |
|
|
|
567 |
|
|
task mult_args;
|
568 |
|
|
begin
|
569 |
|
|
warmreg(reg_n); // Rd is in the Rn position for MULT instructions
|
570 |
|
|
$fwrite(decompile_file,", ");
|
571 |
|
|
warmreg(reg_m);
|
572 |
|
|
$fwrite(decompile_file,", ");
|
573 |
|
|
warmreg(reg_s);
|
574 |
|
|
|
575 |
|
|
if (execute_instruction[21]) // MLA
|
576 |
|
|
begin
|
577 |
|
|
$fwrite(decompile_file,", ");
|
578 |
|
|
warmreg(reg_d);
|
579 |
|
|
end
|
580 |
|
|
end
|
581 |
|
|
endtask
|
582 |
|
|
|
583 |
|
|
|
584 |
|
|
task swap_args;
|
585 |
|
|
begin
|
586 |
|
|
warmreg(reg_d);
|
587 |
|
|
$fwrite(decompile_file,", ");
|
588 |
|
|
warmreg(reg_m);
|
589 |
|
|
$fwrite(decompile_file,", [");
|
590 |
|
|
warmreg(reg_n);
|
591 |
|
|
$fwrite(decompile_file,"]");
|
592 |
|
|
end
|
593 |
|
|
endtask
|
594 |
|
|
|
595 |
|
|
|
596 |
|
|
task regop_args;
|
597 |
|
|
begin
|
598 |
|
|
if (!opcode_compare)
|
599 |
|
|
warmreg(reg_d);
|
600 |
|
|
|
601 |
|
|
if (!opcode_move )
|
602 |
|
|
begin
|
603 |
|
|
if (!opcode_compare)
|
604 |
|
|
begin
|
605 |
|
|
$fwrite(decompile_file,", ");
|
606 |
|
|
if (reg_d < 4'd10 || reg_d > 4'd12)
|
607 |
|
|
$fwrite(decompile_file," ");
|
608 |
|
|
end
|
609 |
|
|
warmreg(reg_n);
|
610 |
|
|
$fwrite(decompile_file,", ");
|
611 |
|
|
if (reg_n < 4'd10 || reg_n > 4'd12)
|
612 |
|
|
$fwrite(decompile_file," ");
|
613 |
|
|
end
|
614 |
|
|
else
|
615 |
|
|
begin
|
616 |
|
|
$fwrite(decompile_file,", ");
|
617 |
|
|
if (reg_d < 4'd10 || reg_d > 4'd12)
|
618 |
|
|
$fwrite(decompile_file," ");
|
619 |
|
|
end
|
620 |
|
|
|
621 |
|
|
if (shift_op_imm)
|
622 |
|
|
begin
|
623 |
|
|
if (|imm32[31:15])
|
624 |
|
|
$fwrite(decompile_file,"#0x%08h", imm32);
|
625 |
|
|
else
|
626 |
|
|
$fwrite(decompile_file,"#%1d", imm32);
|
627 |
|
|
end
|
628 |
|
|
else // Rm
|
629 |
|
|
begin
|
630 |
|
|
warmreg(reg_m);
|
631 |
|
|
if (execute_instruction[4])
|
632 |
|
|
// Register Shifts
|
633 |
|
|
wshiftreg;
|
634 |
|
|
else
|
635 |
|
|
// Immediate shifts
|
636 |
|
|
wshift;
|
637 |
|
|
end
|
638 |
|
|
end
|
639 |
|
|
endtask
|
640 |
|
|
|
641 |
|
|
|
642 |
|
|
task trans_args;
|
643 |
|
|
begin
|
644 |
|
|
warmreg(reg_d); // Destination register
|
645 |
|
|
|
646 |
|
|
casez ({execute_instruction[25:23], execute_instruction[21], no_shift, offset12==12'd0})
|
647 |
|
|
6'b0100?0 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", #-%1d]" , offset12); end
|
648 |
|
|
6'b0110?0 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", #%1d]" , offset12); end
|
649 |
|
|
6'b0100?1 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"]"); end
|
650 |
|
|
6'b0110?1 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"]"); end
|
651 |
|
|
6'b0101?? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", #-%1d]!", offset12); end
|
652 |
|
|
6'b0111?? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", #%1d]!" , offset12); end
|
653 |
|
|
|
654 |
|
|
6'b0000?0 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], #-%1d", offset12); end
|
655 |
|
|
6'b0010?0 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], #%1d" , offset12); end
|
656 |
|
|
6'b0001?0 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], #-%1d", offset12); end
|
657 |
|
|
6'b0011?0 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], #%1d" , offset12); end
|
658 |
|
|
|
659 |
|
|
6'b0000?1 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"]"); end
|
660 |
|
|
6'b0010?1 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"]"); end
|
661 |
|
|
6'b0001?1 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"]"); end
|
662 |
|
|
6'b0011?1 : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"]"); end
|
663 |
|
|
|
664 |
|
|
6'b11001? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", -"); warmreg(reg_m); $fwrite(decompile_file,"]"); end
|
665 |
|
|
6'b11101? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", "); warmreg(reg_m); $fwrite(decompile_file,"]"); end
|
666 |
|
|
6'b11011? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", -"); warmreg(reg_m); $fwrite(decompile_file,"]!"); end
|
667 |
|
|
6'b11111? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", "); warmreg(reg_m); $fwrite(decompile_file,"]!"); end
|
668 |
|
|
|
669 |
|
|
6'b10001? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], -"); warmreg(reg_m); end
|
670 |
|
|
6'b10101? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], "); warmreg(reg_m); end
|
671 |
|
|
6'b10011? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], -"); warmreg(reg_m); end
|
672 |
|
|
6'b10111? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], "); warmreg(reg_m); end
|
673 |
|
|
|
674 |
|
|
6'b11000? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", -"); warmreg(reg_m); wshift; $fwrite(decompile_file,"]"); end
|
675 |
|
|
6'b11100? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", "); warmreg(reg_m); wshift; $fwrite(decompile_file,"]"); end
|
676 |
|
|
6'b11010? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", -"); warmreg(reg_m); wshift; $fwrite(decompile_file,"]!");end
|
677 |
|
|
6'b11110? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,", "); warmreg(reg_m); wshift; $fwrite(decompile_file,"]!");end
|
678 |
|
|
|
679 |
|
|
6'b10000? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], -"); warmreg(reg_m); wshift; end
|
680 |
|
|
6'b10100? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], "); warmreg(reg_m); wshift; end
|
681 |
|
|
6'b10010? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], -"); warmreg(reg_m); wshift; end
|
682 |
|
|
6'b10110? : begin $fwrite(decompile_file,", ["); warmreg(reg_n); $fwrite(decompile_file,"], "); warmreg(reg_m); wshift; end
|
683 |
|
|
|
684 |
|
|
endcase
|
685 |
|
|
end
|
686 |
|
|
endtask
|
687 |
|
|
|
688 |
|
|
|
689 |
|
|
task mtrans_args;
|
690 |
|
|
begin
|
691 |
|
|
warmreg(reg_n);
|
692 |
|
|
if (execute_instruction[21]) $fwrite(decompile_file,"!");
|
693 |
|
|
$fwrite(decompile_file,", {");
|
694 |
|
|
for (i=0;i<16;i=i+1)
|
695 |
|
|
if (execute_instruction[i])
|
696 |
|
|
begin
|
697 |
|
|
warmreg(i);
|
698 |
|
|
if (more_to_come(execute_instruction[15:0], i))
|
699 |
|
|
$fwrite(decompile_file,", ");
|
700 |
|
|
end
|
701 |
|
|
$fwrite(decompile_file,"}");
|
702 |
|
|
// SDM: store the user mode registers, when in priviledged mode
|
703 |
|
|
if (execute_instruction[22:20] == 3'b100)
|
704 |
|
|
$fwrite(decompile_file,"^");
|
705 |
|
|
end
|
706 |
|
|
endtask
|
707 |
|
|
|
708 |
|
|
|
709 |
|
|
task wshift;
|
710 |
|
|
begin
|
711 |
|
|
// Check that its a valid shift operation. LSL by #0 is the null operator
|
712 |
|
|
if (execute_instruction[6:5] != LSL || shift_imm != 5'd0)
|
713 |
|
|
begin
|
714 |
|
|
case(execute_instruction[6:5])
|
715 |
|
|
2'd0: $fwrite(decompile_file,", lsl");
|
716 |
|
|
2'd1: $fwrite(decompile_file,", lsr");
|
717 |
|
|
2'd2: $fwrite(decompile_file,", asr");
|
718 |
|
|
2'd3: if (shift_imm == 5'd0) $fwrite(decompile_file,", rrx"); else $fwrite(decompile_file,", ror");
|
719 |
|
|
endcase
|
720 |
|
|
|
721 |
|
|
if (execute_instruction[6:5] != 2'd3 || shift_imm != 5'd0)
|
722 |
|
|
$fwrite(decompile_file," #%1d", shift_imm);
|
723 |
|
|
end
|
724 |
|
|
end
|
725 |
|
|
endtask
|
726 |
|
|
|
727 |
|
|
|
728 |
|
|
task wshiftreg;
|
729 |
|
|
begin
|
730 |
|
|
case(execute_instruction[6:5])
|
731 |
|
|
2'd0: $fwrite(decompile_file,", lsl ");
|
732 |
|
|
2'd1: $fwrite(decompile_file,", lsr ");
|
733 |
|
|
2'd2: $fwrite(decompile_file,", asr ");
|
734 |
|
|
2'd3: $fwrite(decompile_file,", ror ");
|
735 |
|
|
endcase
|
736 |
|
|
|
737 |
|
|
warmreg(reg_s);
|
738 |
|
|
end
|
739 |
|
|
endtask
|
740 |
|
|
|
741 |
|
|
|
742 |
|
|
task warmreg;
|
743 |
|
|
input [3:0] regnum;
|
744 |
|
|
begin
|
745 |
|
|
if (regnum < 4'd12)
|
746 |
|
|
$fwrite(decompile_file,"r%1d", regnum);
|
747 |
|
|
else
|
748 |
|
|
case (regnum)
|
749 |
|
|
4'd12 : $fwrite(decompile_file,"ip");
|
750 |
|
|
4'd13 : $fwrite(decompile_file,"sp");
|
751 |
|
|
4'd14 : $fwrite(decompile_file,"lr");
|
752 |
|
|
4'd15 : $fwrite(decompile_file,"pc");
|
753 |
|
|
endcase
|
754 |
|
|
end
|
755 |
|
|
endtask
|
756 |
|
|
|
757 |
|
|
|
758 |
|
|
task fwrite_hex_drop_zeros;
|
759 |
|
|
input [31:0] file;
|
760 |
|
|
input [31:0] num;
|
761 |
|
|
begin
|
762 |
|
|
if (num[31:28] != 4'd0)
|
763 |
|
|
$fwrite(file, "%x", num);
|
764 |
|
|
else if (num[27:24] != 4'd0)
|
765 |
|
|
$fwrite(file, "%x", num[27:0]);
|
766 |
|
|
else if (num[23:20] != 4'd0)
|
767 |
|
|
$fwrite(file, "%x", num[23:0]);
|
768 |
|
|
else if (num[19:16] != 4'd0)
|
769 |
|
|
$fwrite(file, "%x", num[19:0]);
|
770 |
|
|
else if (num[15:12] != 4'd0)
|
771 |
|
|
$fwrite(file, "%x", num[15:0]);
|
772 |
|
|
else if (num[11:8] != 4'd0)
|
773 |
|
|
$fwrite(file, "%x", num[11:0]);
|
774 |
|
|
else if (num[7:4] != 4'd0)
|
775 |
|
|
$fwrite(file, "%x", num[7:0]);
|
776 |
|
|
else
|
777 |
|
|
$fwrite(file, "%x", num[3:0]);
|
778 |
|
|
|
779 |
|
|
end
|
780 |
|
|
endtask
|
781 |
|
|
|
782 |
|
|
|
783 |
|
|
|
784 |
|
|
// =================================================================================
|
785 |
|
|
// Functions
|
786 |
|
|
// =================================================================================
|
787 |
|
|
|
788 |
|
|
// Get current value of register
|
789 |
|
|
function [31:0] get_reg_val;
|
790 |
|
|
input [4:0] regnum;
|
791 |
|
|
begin
|
792 |
|
|
case (regnum)
|
793 |
|
|
5'd0 : get_reg_val = `U_REGISTER_BANK.r0_out;
|
794 |
|
|
5'd1 : get_reg_val = `U_REGISTER_BANK.r1_out;
|
795 |
|
|
5'd2 : get_reg_val = `U_REGISTER_BANK.r2_out;
|
796 |
|
|
5'd3 : get_reg_val = `U_REGISTER_BANK.r3_out;
|
797 |
|
|
5'd4 : get_reg_val = `U_REGISTER_BANK.r4_out;
|
798 |
|
|
5'd5 : get_reg_val = `U_REGISTER_BANK.r5_out;
|
799 |
|
|
5'd6 : get_reg_val = `U_REGISTER_BANK.r6_out;
|
800 |
|
|
5'd7 : get_reg_val = `U_REGISTER_BANK.r7_out;
|
801 |
|
|
5'd8 : get_reg_val = `U_REGISTER_BANK.r8_out;
|
802 |
|
|
5'd9 : get_reg_val = `U_REGISTER_BANK.r9_out;
|
803 |
|
|
5'd10 : get_reg_val = `U_REGISTER_BANK.r10_out;
|
804 |
|
|
5'd11 : get_reg_val = `U_REGISTER_BANK.r11_out;
|
805 |
|
|
5'd12 : get_reg_val = `U_REGISTER_BANK.r12_out;
|
806 |
|
|
5'd13 : get_reg_val = `U_REGISTER_BANK.r13_out;
|
807 |
|
|
5'd14 : get_reg_val = `U_REGISTER_BANK.r14_out;
|
808 |
|
|
5'd15 : get_reg_val = `U_REGISTER_BANK.r15_out_rm; // the version of pc with status bits
|
809 |
|
|
|
810 |
|
|
5'd16 : get_reg_val = `U_REGISTER_BANK.r14_svc;
|
811 |
|
|
5'd17 : get_reg_val = `U_REGISTER_BANK.r14_firq;
|
812 |
|
|
5'd18 : get_reg_val = `U_REGISTER_BANK.r14_irq;
|
813 |
|
|
5'd19 : get_reg_val = `U_REGISTER_BANK.r14_svc;
|
814 |
|
|
5'd20 : get_reg_val = `U_REGISTER_BANK.r14_svc;
|
815 |
|
|
5'd21 : get_reg_val = `U_REGISTER_BANK.r15_out_rn; // the version of pc without status bits
|
816 |
|
|
endcase
|
817 |
|
|
end
|
818 |
|
|
endfunction
|
819 |
|
|
|
820 |
|
|
|
821 |
|
|
function [31:0] get_32bit_signal;
|
822 |
|
|
input [2:0] num;
|
823 |
|
|
begin
|
824 |
|
|
case (num)
|
825 |
|
|
3'd0: get_32bit_signal = `U_EXECUTE.pc_nxt;
|
826 |
|
|
3'd1: get_32bit_signal = `U_EXECUTE.o_iaddress;
|
827 |
|
|
3'd2: get_32bit_signal = `U_EXECUTE.o_daddress;
|
828 |
|
|
3'd3: get_32bit_signal = `U_EXECUTE.o_write_data;
|
829 |
|
|
// 3'd4: get_32bit_signal = `U_EXECUTE.read_data_filtered;
|
830 |
|
|
3'd4: get_32bit_signal = `U_EXECUTE.i_wb_read_data;
|
831 |
|
|
3'd5: get_32bit_signal = `U_WB.daddress_r;
|
832 |
|
|
endcase
|
833 |
|
|
end
|
834 |
|
|
endfunction
|
835 |
|
|
|
836 |
|
|
|
837 |
|
|
function get_1bit_signal;
|
838 |
|
|
input [2:0] num;
|
839 |
|
|
begin
|
840 |
|
|
case (num)
|
841 |
|
|
3'd0: get_1bit_signal = `U_EXECUTE.o_write_enable;
|
842 |
|
|
3'd1: get_1bit_signal = `U_AMBER.mem_stall;
|
843 |
|
|
3'd2: get_1bit_signal = `U_EXECUTE.o_daddress_valid;
|
844 |
35 |
csantifort |
3'd3: get_1bit_signal = `U_AMBER.core_stall;
|
845 |
16 |
csantifort |
3'd4: get_1bit_signal = `U_WB.mem_read_data_valid_r;
|
846 |
|
|
endcase
|
847 |
|
|
end
|
848 |
|
|
endfunction
|
849 |
|
|
|
850 |
|
|
|
851 |
|
|
function [3:0] get_4bit_signal;
|
852 |
|
|
input [2:0] num;
|
853 |
|
|
begin
|
854 |
|
|
case (num)
|
855 |
|
|
3'd0: get_4bit_signal = `U_EXECUTE.o_byte_enable;
|
856 |
|
|
3'd1: get_4bit_signal = `U_WB.mem_load_rd_r;
|
857 |
|
|
endcase
|
858 |
|
|
end
|
859 |
|
|
endfunction
|
860 |
|
|
|
861 |
|
|
|
862 |
|
|
function [3:0] numchars;
|
863 |
|
|
input [(5*8)-1:0] xINSTRUCTION_EXECUTE;
|
864 |
|
|
begin
|
865 |
|
|
if (xINSTRUCTION_EXECUTE[31:0] == " ")
|
866 |
|
|
numchars = 4'd1;
|
867 |
|
|
else if (xINSTRUCTION_EXECUTE[23:0] == " ")
|
868 |
|
|
numchars = 4'd2;
|
869 |
|
|
else if (xINSTRUCTION_EXECUTE[15:0] == " ")
|
870 |
|
|
numchars = 4'd3;
|
871 |
|
|
else if (xINSTRUCTION_EXECUTE[7:0] == " ")
|
872 |
|
|
numchars = 4'd4;
|
873 |
|
|
else
|
874 |
|
|
numchars = 4'd5;
|
875 |
|
|
end
|
876 |
|
|
endfunction
|
877 |
|
|
|
878 |
|
|
|
879 |
|
|
function more_to_come;
|
880 |
|
|
input [15:0] regs;
|
881 |
|
|
input [31:0] i;
|
882 |
|
|
begin
|
883 |
|
|
case (i)
|
884 |
|
|
15 : more_to_come = 1'd0;
|
885 |
|
|
14 : more_to_come = regs[15] ? 1'd1 : 1'd0;
|
886 |
|
|
13 : more_to_come = |regs[15:14] ? 1'd1 : 1'd0;
|
887 |
|
|
12 : more_to_come = |regs[15:13] ? 1'd1 : 1'd0;
|
888 |
|
|
11 : more_to_come = |regs[15:12] ? 1'd1 : 1'd0;
|
889 |
|
|
10 : more_to_come = |regs[15:11] ? 1'd1 : 1'd0;
|
890 |
|
|
9 : more_to_come = |regs[15:10] ? 1'd1 : 1'd0;
|
891 |
|
|
8 : more_to_come = |regs[15: 9] ? 1'd1 : 1'd0;
|
892 |
|
|
7 : more_to_come = |regs[15: 8] ? 1'd1 : 1'd0;
|
893 |
|
|
6 : more_to_come = |regs[15: 7] ? 1'd1 : 1'd0;
|
894 |
|
|
5 : more_to_come = |regs[15: 6] ? 1'd1 : 1'd0;
|
895 |
|
|
4 : more_to_come = |regs[15: 5] ? 1'd1 : 1'd0;
|
896 |
|
|
3 : more_to_come = |regs[15: 4] ? 1'd1 : 1'd0;
|
897 |
|
|
2 : more_to_come = |regs[15: 3] ? 1'd1 : 1'd0;
|
898 |
|
|
1 : more_to_come = |regs[15: 2] ? 1'd1 : 1'd0;
|
899 |
|
|
|
900 |
|
|
endcase
|
901 |
|
|
end
|
902 |
|
|
endfunction
|
903 |
|
|
|
904 |
|
|
`endif
|
905 |
|
|
|
906 |
|
|
endmodule
|
907 |
|
|
|