c_gen.pl: Change to use data type "int" instead of "long int" in
[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 &perform_test_read_only;
102 }
103 else # ignore this input
104 {
105 print OUTFILE ("\n");
106 }
107 }
108
109 &print_foot_part_of_c_code;
110
111 close(INFILE);
112 close(OUTFILE);
113
114 print ("Done!\n");
115 exit(0);
116
117
118
119
120 ###################
121 # Subroutines:
122 ###################
123
124 sub process_comment {
125 $inputline =~ s/#//;
126 print OUTFILE ("/*".$inputline."*/\n");
127 }
128
129 sub process_data {
130 print OUTFILE ("/*****************************************************************/\n");
131 print OUTFILE ("/* Assign a quadword: */\n");
132
133 @columns = split ( /[\s]+/, $inputline );
134 $data_count = @columns;
135
136 #column[0] tells to which unit (VU0, VU1, or GIF) these data should go to.
137 $src_addr_name = "SRC_ADDR_CONST_".$columns[0];
138 $data_addr_name = "DATA_ADDR_CONST_".$columns[0];
139 $flag_addr_name = "FLAG_ADDR_CONST_".$columns[0];
140
141 #column[1] is the qual_word in format of 0xH_H_H_H:
142 @quadword = split ("_", $columns[1]);
143 $quadword[0] =~ s/0x//i;
144
145 print OUTFILE ("\n{\n");
146
147 print OUTFILE (" volatile unsigned* flag_ptr = \(unsigned *\)$flag_addr_name;\n");
148 print OUTFILE (" volatile unsigned* src_ptr = \(unsigned *\)$src_addr_name;\n");
149 print OUTFILE (" volatile unsigned* data_ptr = \(unsigned *\)$data_addr_name;\n");
150
151 if ( $data_count > 3 )
152 { #column[3] is the DMA_tag flag, if exist
153 $flag = $columns[3];
154 if ( $flag =~ /d/i ) {
155 print OUTFILE (" *flag_ptr = 1;\n");
156 }
157 else {
158 print OUTFILE (" *flag_ptr = 0;\n");
159 }
160 }
161
162 if ( $data_count > 2 )
163 {
164 #column[2] is the src_address, if exist
165 $src_addr = $columns[2];
166 print OUTFILE (" *src_ptr = $src_addr; \n");
167 }
168
169 #Now write the quadword:
170 print OUTFILE ("\n");
171 print OUTFILE (" *data_ptr++ = 0x".$quadword[3].";\n");
172 print OUTFILE (" *data_ptr++ = 0x".$quadword[2].";\n");
173 print OUTFILE (" *data_ptr++ = 0x".$quadword[1].";\n");
174 print OUTFILE (" *data_ptr = 0x".$quadword[0].";\n");
175 print OUTFILE (" num_qw_written ++;\n");
176 print OUTFILE ("\n");
177
178 print OUTFILE (" *flag_ptr = 0;\n") unless ($data_count < 4);
179 print OUTFILE (" *src_ptr = 0;\n") unless ( $data_count < 3);
180 print OUTFILE ("}\n");
181 }
182
183
184 sub process_data_reg32 {
185 print OUTFILE ("\n");
186 print OUTFILE ("/******************************************************************/\n");
187 print OUTFILE ("/*Writing the specified data into the specified address: */\n\n");
188
189 @columns = split ( /[\s]+/, $inputline );
190
191 #column[1] is the address, column[2] is the value, both in the format of 0xH;
192
193 print OUTFILE ("\n{\n");
194 print OUTFILE (" volatile unsigned* addr_ptr = \(unsigned *\)".$columns[1].";\n");
195 print OUTFILE (" *addr_ptr = ".$columns[2].";\n");
196 print OUTFILE (" num_w_written ++;\n");
197 print OUTFILE ("}\n");
198
199 }
200
201 sub process_data_reg64 {
202 print OUTFILE ("\n");
203 print OUTFILE ("/******************************************************************/\n");
204 print OUTFILE ("/*Writing the specified 64-bit data into the specified address: */\n\n");
205
206 @columns = split ( /[\s]+/, $inputline );
207
208 #column[1] is the address, in the format of 0xH;
209 #column[2] is the value, in the format of 0xH_H;
210 @llword = split ("_", $columns[2]);
211
212 print OUTFILE ("\n{\n");
213 print OUTFILE (" volatile long long int* reg64_ptr = \(long long int *\)".$columns[1].";\n");
214 print OUTFILE (" *reg64_ptr = \(long long\)".$llword[0]." \<\< 32 \| \(long long\)0x".$llword[1].";\n");
215 print OUTFILE (" num_w_written ++;\n");
216 print OUTFILE ("}\n");
217
218 }
219
220 sub perform_test32 {
221 print OUTFILE ("\n");
222 print OUTFILE ("/******************************************************************/\n");
223 print OUTFILE ("/*Verify the data in the specified address with the input value: */\n\n");
224
225 @columns = split ( /[\s]+/, $inputline );
226
227 #column[1] is the address;
228 #column[2] is the value, in the format of oxH;
229 #column[3] is the mask, in the format of oxH;
230
231 print OUTFILE ("\n{\n");
232 print OUTFILE (" volatile unsigned* test_ptr = \(unsigned *\)".$columns[1].";\n");
233 print OUTFILE (" unsigned test_data = *test_ptr;\n");
234 print OUTFILE (" if \( \( test_data & $columns[3] \) == $columns[2] \) {\n");
235 print OUTFILE (" num_passed ++;\n");
236 print OUTFILE (" } else {\n");
237 print OUTFILE (" printf \(\"Data Verification (line $current_line_number) failed!\\n\"\); \n" );
238 print OUTFILE (" printf \(\"Expecting \%08x mask \%08x in address \%08x but got \%08x !\\n\", $columns[2], $columns[3], $columns[1], test_data\); \n");
239 print OUTFILE (" num_failed++;\n");
240 print OUTFILE (" }\n}\n");
241
242 }
243
244 sub perform_test64 {
245 print OUTFILE ("\n");
246 print OUTFILE ("/******************************************************************/\n");
247 print OUTFILE ("/*Verify the data in the specified address with the input value: */\n\n");
248
249 @columns = split ( /[\s]+/, $inputline );
250
251 #column[1] is the address;
252 #column[2] is the value, in the format of 0xH_H;
253 @llword = split ("_", $columns[2]);
254
255 print OUTFILE ("\n{\n");
256 print OUTFILE (" volatile long long int* test64_ptr = \(long long int *\)".$columns[1].";\n");
257 print OUTFILE (" long long int test64_data = \(long long\)".$llword[0]." \<\< 32 \| \(long long\)0x".$llword[1].";\n");
258 print OUTFILE (" if \( \( test64_data \) == *test64_ptr \) {\n");
259 print OUTFILE (" num_passed ++;\n");
260 print OUTFILE (" } else {\n");
261 print OUTFILE (" printf \(\"Data Verification (line $current_line_number) failed!\\n\"\); \n" );
262 print OUTFILE (" printf \(\"Expecting \%20s in address \%08x but got \%16x !\\n\", \"$columns[2]\", $columns[1], *test64_ptr\); \n");
263 print OUTFILE (" num_failed++;\n");
264 print OUTFILE (" }\n}\n");
265
266 }
267
268 sub perform_test_read_only {
269 print OUTFILE ("\n");
270 print OUTFILE ("/******************************************************************/\n");
271 print OUTFILE ("/*Just trying to read data from the specified address: */\n\n");
272
273 @columns = split ( /[\s]+/, $inputline );
274
275 #column[1] is the address;
276 #column[2] is the byte-indicator, which can be 4 or 8;
277
278 if ( $columns[2] =~ /^4/ ) # This is a 4-byte data address
279 { $d_type = " "; }
280 else {
281 $d_type = "long long "; # assuming the input is "8"
282 }
283
284 print OUTFILE ("\n{\n");
285 print OUTFILE (" volatile ".$d_type."int* test_add = \(".$d_type."int *\)".$columns[1].";\n");
286 print OUTFILE (" ".$d_type."int test_data = *test_add;\n");
287 print OUTFILE ("}\n");
288
289 }
290
291
292
293
294
295 sub print_header_part_of_c_code {
296
297 print OUTFILE ("\n/*");
298 print OUTFILE ("\n * This file is automatically generated.");
299 $version='$Revision$ $Date$';
300 print OUTFILE ("\n * c_gen.pl $version");
301 print OUTFILE ("\n * Input file: $infile_name");
302 print OUTFILE ("\n * Date: $date");
303 print OUTFILE ("\n */");
304 print OUTFILE ("\n");
305 print OUTFILE ("\n#include <stdio.h>\n");
306 print OUTFILE ("\n");
307 print OUTFILE ("
308 /* Memory mapping constants: */
309
310 /* VIF0 */
311 #define SRC_ADDR_CONST_0 0x10008010
312 #define DATA_ADDR_CONST_0 0x10004000
313 #define FLAG_ADDR_CONST_0 0x10008060
314
315 /* VIF1 */
316 #define SRC_ADDR_CONST_1 0x10009010
317 #define DATA_ADDR_CONST_1 0x10005000
318 #define FLAG_ADDR_CONST_1 0x10009060
319
320 /* GIF PATH1 */
321 #define SRC_ADDR_CONST_2 0x1000a010
322 #define DATA_ADDR_CONST_2 0x10006020
323 #define FLAG_ADDR_CONST_2 0x1000a060
324
325 /* GIF PATH2 */
326 #define SRC_ADDR_CONST_3 0x1000a010
327 #define DATA_ADDR_CONST_3 0x10006010
328 #define FLAG_ADDR_CONST_3 0x1000a060
329
330 /* GIF PATH3 */
331 #define SRC_ADDR_CONST_4 0x1000a010
332 #define DATA_ADDR_CONST_4 0x10006000
333 #define FLAG_ADDR_CONST_4 0x1000a060
334 ");
335 print OUTFILE ("\n\n");
336
337 print OUTFILE ("int main()\n");
338 print OUTFILE ("{\n");
339 print OUTFILE (" unsigned num_qw_written = 0;\n");
340 print OUTFILE (" unsigned num_w_written = 0;\n");
341 print OUTFILE (" unsigned num_passed = 0;\n");
342 print OUTFILE (" unsigned num_failed = 0;\n");
343 print OUTFILE (" printf \(\"Start of execution...\\n\"\); \n" );
344 print OUTFILE ("\n\n");
345 }
346
347 sub print_foot_part_of_c_code {
348
349 print OUTFILE ("\n");
350 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" );
351 print OUTFILE ("exit (num_failed);\n");
352 print OUTFILE ("}\n");
353 }
This page took 0.049033 seconds and 4 git commands to generate.