c_gen.pl : Added handling for data from GIF path1/2/3 FIFO.
[deliverable/binutils-gdb.git] / sim / testsuite / sky / c_gen.pl
1 #!/usr/local/bin/perl
2 #
3 #***********************************************************
4 #
5 # A tool to read quad-data input and generate a
6 # c test-program to help testing PKE/GIF, etc.
7 #
8 # To Invoke:
9 # c_gen <input_data_file> <output_c_file>
10 #
11 # Expected input format:
12 # <first column> <second_column> <third column> <forth column>
13 # (indicator ) ( quad_word ) ( source_addr) (flag)
14 # ------------- --------------- -------------- -------------
15 # n (for data) 0xH_H_H_H 0xH 4-CHARs
16 # ? (for test) 0xH (addr) 0xH (value) 0xH (mask)
17 # ! (reg wrt 32) 0xH (addr) 0xH (data)
18 # ~ (reg wrt 64) 0xH (addr) 0xHigh_Low (data)
19 # % (reg read 64) 0xH (addr) 0xHigh_Low (data)
20 # @ (read only) 0xH (addr) 4/8
21 # # comment line
22 # Note: n can be 0 (for VU1), 1 (for VU2), or 2 (for GIF).
23 # H, High, or Low is hex data in the format of FFFFFFFF
24 #
25 #
26 # Result output:
27 # A c file, either with the name specified, or default.c
28 #
29 #***********************************************************/
30
31
32
33 ######################
34 # Main script:
35 ######################
36
37 $numargs = @ARGV;
38 if ( $numargs == 2 ) {
39 $infile_name = $ARGV[0];
40 $outfile_name = $ARGV[1];
41 }
42 elsif ( $numargs == 1)
43 {
44 $infile_name = $ARGV[0];
45 $outfile_name = "default.c"
46 }
47 else
48 {
49 die ("Usage: c_gen <input_data_file_name> <output_c_file_name>\n");
50 }
51
52 # Header containing SCEI system addresses
53 $date=`date`;
54 chop($date);
55
56 die ("Cannot open input file $infile_name.\n")
57 unless (open (INFILE, $infile_name));
58 die ("Cannot open output file $outfile_name.\n")
59 unless (open (OUTFILE, ">".$outfile_name));
60
61 print ("The input data file is: $infile_name \n");
62 print ("The output c file is: $outfile_name \n");
63
64 &print_header_part_of_c_code;
65
66 $current_line_number = 0;
67
68 #Now process the input and print the body_part_of_c_code:
69 while( $inputline = <INFILE> )
70 {
71 chop($inputline); # get rid of the new line char;
72 $current_line_number ++;
73
74 print OUTFILE ("/* #line \"$infile_name\" $current_line_number */\n");
75 if ($inputline =~ /^\#/ ) # A line starts with "#" is a comment
76 {
77 &process_comment;
78 }
79 elsif ( $inputline =~ /^[01234]/ ) # This is a data line
80 {
81 &process_data;
82 }
83 elsif ( $inputline =~ /^\!/ ) # This is a 32-bit register write
84 {
85 &process_data_reg32;
86 }
87 elsif ( $inputline =~ /^\~/ ) # This is a 64-bit register write
88 {
89 &process_data_reg64;
90 }
91 elsif ( $inputline =~ /^\?/ ) # A line starts with "?" is a 32bit read/verification request
92 {
93 &perform_test32;
94 }
95 elsif ( $inputline =~ /^\%/ ) # A line starts with "%" is a 64bit read/verification request
96 {
97 &perform_test64;
98 }
99 elsif ( $inputline =~ /^\@/ ) # A line starts with "@" is a read only test request
100 {
101 print ("glorp\n");
102 &perform_test_read_only;
103 }
104 else # ignore this input
105 {
106 print OUTFILE ("\n");
107 }
108 }
109
110 &print_foot_part_of_c_code;
111
112 close(INFILE);
113 close(OUTFILE);
114
115 print ("Done!\n");
116 exit(0);
117
118
119
120
121 ###################
122 # Subroutines:
123 ###################
124
125 sub process_comment {
126 $inputline =~ s/#//;
127 print OUTFILE ("/*".$inputline."*/\n");
128 }
129
130 sub process_data {
131 print OUTFILE ("/*****************************************************************/\n");
132 print OUTFILE ("/* Assign a quadword: */\n");
133
134 @columns = split ( /[\s]+/, $inputline );
135 $data_count = @columns;
136
137 #column[0] tells to which unit (VU0, VU1, or GIF) these data should go to.
138 $src_addr_name = "SRC_ADDR_CONST_".$columns[0];
139 $data_addr_name = "DATA_ADDR_CONST_".$columns[0];
140 $flag_addr_name = "FLAG_ADDR_CONST_".$columns[0];
141
142 #column[1] is the qual_word in format of 0xH_H_H_H:
143 @quadword = split ("_", $columns[1]);
144 $quadword[0] =~ s/0x//i;
145
146 print OUTFILE ("\n{\n");
147
148 print OUTFILE (" volatile unsigned* flag_ptr = \(unsigned *\)$flag_addr_name;\n");
149 print OUTFILE (" volatile unsigned* src_ptr = \(unsigned *\)$src_addr_name;\n");
150 print OUTFILE (" volatile unsigned* data_ptr = \(unsigned *\)$data_addr_name;\n");
151
152 if ( $data_count > 3 )
153 { #column[3] is the DMA_tag flag, if exist
154 $flag = $columns[3];
155 if ( $flag =~ /d/i ) {
156 print OUTFILE (" *flag_ptr = 1;\n");
157 }
158 else {
159 print OUTFILE (" *flag_ptr = 0;\n");
160 }
161 }
162
163 if ( $data_count > 2 )
164 {
165 #column[2] is the src_address, if exist
166 $src_addr = $columns[2];
167 print OUTFILE (" *src_ptr = $src_addr; \n");
168 }
169
170 #Now write the quadword:
171 print OUTFILE ("\n");
172 print OUTFILE (" *data_ptr++ = 0x".$quadword[3].";\n");
173 print OUTFILE (" *data_ptr++ = 0x".$quadword[2].";\n");
174 print OUTFILE (" *data_ptr++ = 0x".$quadword[1].";\n");
175 print OUTFILE (" *data_ptr = 0x".$quadword[0].";\n");
176 print OUTFILE (" num_qw_written ++;\n");
177 print OUTFILE ("\n");
178
179 print OUTFILE (" *flag_ptr = 0;\n") unless ($data_count < 4);
180 print OUTFILE (" *src_ptr = 0;\n") unless ( $data_count < 3);
181 print OUTFILE ("}\n");
182 }
183
184
185 sub process_data_reg32 {
186 print OUTFILE ("\n");
187 print OUTFILE ("/******************************************************************/\n");
188 print OUTFILE ("/*Writing the specified data into the specified address: */\n\n");
189
190 @columns = split ( /[\s]+/, $inputline );
191
192 #column[1] is the address, column[2] is the value, both in the format of 0xH;
193
194 print OUTFILE ("\n{\n");
195 print OUTFILE (" volatile unsigned* addr_ptr = \(unsigned *\)".$columns[1].";\n");
196 print OUTFILE (" *addr_ptr = ".$columns[2].";\n");
197 print OUTFILE (" num_w_written ++;\n");
198 print OUTFILE ("}\n");
199
200 }
201
202 sub process_data_reg64 {
203 print OUTFILE ("\n");
204 print OUTFILE ("/******************************************************************/\n");
205 print OUTFILE ("/*Writing the specified 64-bit data into the specified address: */\n\n");
206
207 @columns = split ( /[\s]+/, $inputline );
208
209 #column[1] is the address, in the format of 0xH;
210 #column[2] is the value, in the format of 0xH_H;
211 @llword = split ("_", $columns[2]);
212
213 print OUTFILE ("\n{\n");
214 print OUTFILE (" volatile long long int* reg64_ptr = \(long long int *\)".$columns[1].";\n");
215 print OUTFILE (" *reg64_ptr = \(long long\)".$llword[0]." \<\< 32 \| \(long long\)0x".$llword[1].";\n");
216 print OUTFILE (" num_w_written ++;\n");
217 print OUTFILE ("}\n");
218
219 }
220
221 sub perform_test32 {
222 print OUTFILE ("\n");
223 print OUTFILE ("/******************************************************************/\n");
224 print OUTFILE ("/*Verify the data in the specified address with the input value: */\n\n");
225
226 @columns = split ( /[\s]+/, $inputline );
227
228 #column[1] is the address;
229 #column[2] is the value, in the format of oxH;
230 #column[3] is the mask, in the format of oxH;
231
232 print OUTFILE ("\n{\n");
233 print OUTFILE (" volatile unsigned* test_ptr = \(unsigned *\)".$columns[1].";\n");
234 print OUTFILE (" unsigned test_data = *test_ptr;\n");
235 print OUTFILE (" if \( \( test_data & $columns[3] \) == $columns[2] \) {\n");
236 print OUTFILE (" num_passed ++;\n");
237 print OUTFILE (" } else {\n");
238 print OUTFILE (" printf \(\"Data Verification (line $current_line_number) failed!\\n\"\); \n" );
239 print OUTFILE (" printf \(\"Expecting \%08x mask \%08x in address \%08x but got \%08x !\\n\", $columns[2], $columns[3], $columns[1], test_data\); \n");
240 print OUTFILE (" num_failed++;\n");
241 print OUTFILE (" }\n}\n");
242
243 }
244
245 sub perform_test64 {
246 print OUTFILE ("\n");
247 print OUTFILE ("/******************************************************************/\n");
248 print OUTFILE ("/*Verify the data in the specified address with the input value: */\n\n");
249
250 @columns = split ( /[\s]+/, $inputline );
251
252 #column[1] is the address;
253 #column[2] is the value, in the format of 0xH_H;
254 @llword = split ("_", $columns[2]);
255
256 print OUTFILE ("\n{\n");
257 print OUTFILE (" volatile long long int* test64_ptr = \(long long int *\)".$columns[1].";\n");
258 print OUTFILE (" long long int test64_data = \(long long\)".$llword[0]." \<\< 32 \| \(long long\)0x".$llword[1].";\n");
259 print OUTFILE (" if \( \( test64_data \) == *test64_ptr \) {\n");
260 print OUTFILE (" num_passed ++;\n");
261 print OUTFILE (" } else {\n");
262 print OUTFILE (" printf \(\"Data Verification (line $current_line_number) failed!\\n\"\); \n" );
263 print OUTFILE (" printf \(\"Expecting \%20s in address \%08x but got \%16x !\\n\", \"$columns[2]\", $columns[1], *test64_ptr\); \n");
264 print OUTFILE (" num_failed++;\n");
265 print OUTFILE (" }\n}\n");
266
267 }
268
269 sub perform_test_read_only {
270 print OUTFILE ("\n");
271 print OUTFILE ("/******************************************************************/\n");
272 print OUTFILE ("/*Just trying to read data from the specified address: */\n\n");
273
274 @columns = split ( /[\s]+/, $inputline );
275
276 #column[1] is the address;
277 #column[2] is the byte-indicator, which can be 4 or 8;
278
279 if ( $column[2] =~ /^4/ ) # This is a 4-byte data address
280 { $d_type = "long "; }
281 else {
282 $d_type = "long long "; # assuming the input is "8"
283 }
284
285 print OUTFILE ("\n{\n");
286 print OUTFILE (" volatile ".$d_type."int* test_add = \(".$d_type."int *\)".$columns[1].";\n");
287 print OUTFILE (" long long int test64_data = \(long long\) \( *test_add \);\n");
288 print OUTFILE ("}\n");
289
290 }
291
292
293
294
295
296 sub print_header_part_of_c_code {
297
298 print OUTFILE ("\n/*");
299 print OUTFILE ("\n * This file is automatically generated.");
300 $version='$Revision$ $Date$';
301 print OUTFILE ("\n * c_gen.pl $version");
302 print OUTFILE ("\n * Input file: $infile_name");
303 print OUTFILE ("\n * Date: $date");
304 print OUTFILE ("\n */");
305 print OUTFILE ("\n");
306 print OUTFILE ("\n#include <stdio.h>\n");
307 print OUTFILE ("\n");
308 print OUTFILE ("
309 /* Memory mapping constants: */
310
311 /* VIF0 */
312 #define SRC_ADDR_CONST_0 0x10008010
313 #define DATA_ADDR_CONST_0 0x10004000
314 #define FLAG_ADDR_CONST_0 0x10008060
315
316 /* VIF1 */
317 #define SRC_ADDR_CONST_1 0x10009010
318 #define DATA_ADDR_CONST_1 0x10005000
319 #define FLAG_ADDR_CONST_1 0x10009060
320
321 /* GIF PATH1 */
322 #define SRC_ADDR_CONST_2 0x1000a010
323 #define DATA_ADDR_CONST_2 0x10006020
324 #define FLAG_ADDR_CONST_2 0x1000a060
325
326 /* GIF PATH2 */
327 #define SRC_ADDR_CONST_3 0x1000a010
328 #define DATA_ADDR_CONST_3 0x10006010
329 #define FLAG_ADDR_CONST_3 0x1000a060
330
331 /* GIF PATH3 */
332 #define SRC_ADDR_CONST_4 0x1000a010
333 #define DATA_ADDR_CONST_4 0x10006000
334 #define FLAG_ADDR_CONST_4 0x1000a060
335 ");
336 print OUTFILE ("\n\n");
337
338 print OUTFILE ("int main()\n");
339 print OUTFILE ("{\n");
340 print OUTFILE (" unsigned num_qw_written = 0;\n");
341 print OUTFILE (" unsigned num_w_written = 0;\n");
342 print OUTFILE (" unsigned num_passed = 0;\n");
343 print OUTFILE (" unsigned num_failed = 0;\n");
344 print OUTFILE (" printf \(\"Start of execution...\\n\"\); \n" );
345 print OUTFILE ("\n\n");
346 }
347
348 sub print_foot_part_of_c_code {
349
350 print OUTFILE ("\n");
351 print OUTFILE (" printf \(\"End of execution. %d FIFO quadwords, %d pokes, %d checks ok, %d failed.\\n\", num_qw_written, num_w_written, num_passed, num_failed\); \n\n" );
352 print OUTFILE ("exit (num_failed);\n");
353 print OUTFILE ("}\n");
354 }
This page took 0.044571 seconds and 4 git commands to generate.