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
101 &perform_test_read_only
;
103 else # ignore this input
105 print OUTFILE
("\n");
109 &print_foot_part_of_c_code
;
124 sub process_comment
{
126 print OUTFILE
("/*".$inputline."*/\n");
130 print OUTFILE
("/*****************************************************************/\n");
131 print OUTFILE
("/* Assign a quadword: */\n");
133 @columns = split ( /[\s]+/, $inputline );
134 $data_count = @columns;
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];
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;
145 print OUTFILE
("\n{\n");
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");
151 if ( $data_count > 3 )
152 { #column[3] is the DMA_tag flag, if exist
154 if ( $flag =~ /d/i ) {
155 print OUTFILE
(" *flag_ptr = 1;\n");
158 print OUTFILE
(" *flag_ptr = 0;\n");
162 if ( $data_count > 2 )
164 #column[2] is the src_address, if exist
165 $src_addr = $columns[2];
166 print OUTFILE
(" *src_ptr = $src_addr; \n");
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");
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");
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");
189 @columns = split ( /[\s]+/, $inputline );
191 #column[1] is the address, column[2] is the value, both in the format of 0xH;
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");
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");
206 @columns = split ( /[\s]+/, $inputline );
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]);
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");
221 print OUTFILE
("\n");
222 print OUTFILE
("/******************************************************************/\n");
223 print OUTFILE
("/*Verify the data in the specified address with the input value: */\n\n");
225 @columns = split ( /[\s]+/, $inputline );
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;
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");
245 print OUTFILE
("\n");
246 print OUTFILE
("/******************************************************************/\n");
247 print OUTFILE
("/*Verify the data in the specified address with the input value: */\n\n");
249 @columns = split ( /[\s]+/, $inputline );
251 #column[1] is the address;
252 #column[2] is the value, in the format of 0xH_H;
253 @llword = split ("_", $columns[2]);
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");
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");
273 @columns = split ( /[\s]+/, $inputline );
275 #column[1] is the address;
276 #column[2] is the byte-indicator, which can be 4 or 8;
278 if ( $columns[2] =~ /^4/ ) # This is a 4-byte data address
281 $d_type = "long long "; # assuming the input is "8"
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");
295 sub print_header_part_of_c_code
{
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");
308 /* Memory mapping constants: */
311 #define SRC_ADDR_CONST_0 0x10008010
312 #define DATA_ADDR_CONST_0 0x10004000
313 #define FLAG_ADDR_CONST_0 0x10008060
316 #define SRC_ADDR_CONST_1 0x10009010
317 #define DATA_ADDR_CONST_1 0x10005000
318 #define FLAG_ADDR_CONST_1 0x10009060
321 #define SRC_ADDR_CONST_2 0x1000a010
322 #define DATA_ADDR_CONST_2 0x10006020
323 #define FLAG_ADDR_CONST_2 0x1000a060
326 #define SRC_ADDR_CONST_3 0x1000a010
327 #define DATA_ADDR_CONST_3 0x10006010
328 #define FLAG_ADDR_CONST_3 0x1000a060
331 #define SRC_ADDR_CONST_4 0x1000a010
332 #define DATA_ADDR_CONST_4 0x10006000
333 #define FLAG_ADDR_CONST_4 0x1000a060
335 print OUTFILE
("\n\n");
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");
347 sub print_foot_part_of_c_code
{
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");