3 #***********************************************************
5 # A tool to read quad-data input and generate a
6 # c test-program to help testing PKE/GIF, etc.
9 # c_gen <input_data_file> <output_c_file>
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
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
27 # A c file, either with the name specified, or default.c
29 #***********************************************************/
33 ######################
35 ######################
38 if ( $numargs == 2 ) {
39 $infile_name = $ARGV[0];
40 $outfile_name = $ARGV[1];
42 elsif ( $numargs == 1)
44 $infile_name = $ARGV[0];
45 $outfile_name = "default.c"
49 die ("Usage: c_gen <input_data_file_name> <output_c_file_name>\n");
52 # Header containing SCEI system addresses
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));
61 print ("The input data file is: $infile_name \n");
62 print ("The output c file is: $outfile_name \n");
64 &print_header_part_of_c_code
;
66 $current_line_number = 0;
68 #Now process the input and print the body_part_of_c_code:
69 while( $inputline = <INFILE
> )
71 chop($inputline); # get rid of the new line char;
72 $current_line_number ++;
74 print OUTFILE
("/* #line \"$infile_name\" $current_line_number */\n");
75 if ($inputline =~ /^\#/ ) # A line starts with "#" is a comment
79 elsif ( $inputline =~ /^[01234]/ ) # This is a data line
83 elsif ( $inputline =~ /^\!/ ) # This is a 32-bit register write
87 elsif ( $inputline =~ /^\~/ ) # This is a 64-bit register write
91 elsif ( $inputline =~ /^\?/ ) # A line starts with "?" is a 32bit read/verification request
95 elsif ( $inputline =~ /^\%/ ) # A line starts with "%" is a 64bit read/verification request
99 elsif ( $inputline =~ /^\@/ ) # A line starts with "@" is a read only test request
102 &perform_test_read_only
;
104 else # ignore this input
106 print OUTFILE
("\n");
110 &print_foot_part_of_c_code
;
125 sub process_comment
{
127 print OUTFILE
("/*".$inputline."*/\n");
131 print OUTFILE
("/*****************************************************************/\n");
132 print OUTFILE
("/* Assign a quadword: */\n");
134 @columns = split ( /[\s]+/, $inputline );
135 $data_count = @columns;
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];
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;
146 print OUTFILE
("\n{\n");
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");
152 if ( $data_count > 3 )
153 { #column[3] is the DMA_tag flag, if exist
155 if ( $flag =~ /d/i ) {
156 print OUTFILE
(" *flag_ptr = 1;\n");
159 print OUTFILE
(" *flag_ptr = 0;\n");
163 if ( $data_count > 2 )
165 #column[2] is the src_address, if exist
166 $src_addr = $columns[2];
167 print OUTFILE
(" *src_ptr = $src_addr; \n");
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");
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");
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");
190 @columns = split ( /[\s]+/, $inputline );
192 #column[1] is the address, column[2] is the value, both in the format of 0xH;
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");
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");
207 @columns = split ( /[\s]+/, $inputline );
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]);
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");
222 print OUTFILE
("\n");
223 print OUTFILE
("/******************************************************************/\n");
224 print OUTFILE
("/*Verify the data in the specified address with the input value: */\n\n");
226 @columns = split ( /[\s]+/, $inputline );
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;
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");
246 print OUTFILE
("\n");
247 print OUTFILE
("/******************************************************************/\n");
248 print OUTFILE
("/*Verify the data in the specified address with the input value: */\n\n");
250 @columns = split ( /[\s]+/, $inputline );
252 #column[1] is the address;
253 #column[2] is the value, in the format of 0xH_H;
254 @llword = split ("_", $columns[2]);
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");
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");
274 @columns = split ( /[\s]+/, $inputline );
276 #column[1] is the address;
277 #column[2] is the byte-indicator, which can be 4 or 8;
279 if ( $column[2] =~ /^4/ ) # This is a 4-byte data address
280 { $d_type = "long "; }
282 $d_type = "long long "; # assuming the input is "8"
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");
296 sub print_header_part_of_c_code
{
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");
309 /* Memory mapping constants: */
312 #define SRC_ADDR_CONST_0 0x10008010
313 #define DATA_ADDR_CONST_0 0x10004000
314 #define FLAG_ADDR_CONST_0 0x10008060
317 #define SRC_ADDR_CONST_1 0x10009010
318 #define DATA_ADDR_CONST_1 0x10005000
319 #define FLAG_ADDR_CONST_1 0x10009060
322 #define SRC_ADDR_CONST_2 0x1000a010
323 #define DATA_ADDR_CONST_2 0x10006020
324 #define FLAG_ADDR_CONST_2 0x1000a060
327 #define SRC_ADDR_CONST_3 0x1000a010
328 #define DATA_ADDR_CONST_3 0x10006010
329 #define FLAG_ADDR_CONST_3 0x1000a060
332 #define SRC_ADDR_CONST_4 0x1000a010
333 #define DATA_ADDR_CONST_4 0x10006000
334 #define FLAG_ADDR_CONST_4 0x1000a060
336 print OUTFILE
("\n\n");
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");
348 sub print_foot_part_of_c_code
{
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");