c_gen.pl: Added sub-routine process_data_reg64 to handle 64bit register
[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 # # comment line
20 # Note: n can be 0 (for VU1), 1 (for VU2), or 2 (for GIF).
21 # H, High, or Low is hex data in the format of FFFFFFFF
22 #
23 #
24 # Result output:
25 # A c file, either with the name specified, or default.c
26 #
27 #***********************************************************/
28
29
30
31 ######################
32 # Main script:
33 ######################
34
35 $numargs = @ARGV;
36 if ( $numargs == 2 ) {
37 $infile_name = $ARGV[0];
38 $outfile_name = $ARGV[1];
39 }
40 elsif ( $numargs == 1)
41 {
42 $infile_name = $ARGV[0];
43 $outfile_name = "default.c"
44 }
45 else
46 {
47 die ("Usage: c_gen <input_data_file_name> <output_c_file_name>\n");
48 }
49
50 # Header containing SCEI system addresses
51 $date=`date`;
52 chop($date);
53
54 die ("Cannot open input file $infile_name.\n")
55 unless (open (INFILE, $infile_name));
56 die ("Cannot open output file $outfile_name.\n")
57 unless (open (OUTFILE, ">".$outfile_name));
58
59 print ("The input data file is: $infile_name \n");
60 print ("The output c file is: $outfile_name \n");
61
62 &print_header_part_of_c_code;
63
64 $current_line_number = 0;
65
66 #Now process the input and print the body_part_of_c_code:
67 while( $inputline = <INFILE> )
68 {
69 chop($inputline); # get rid of the new line char;
70 $current_line_number ++;
71
72 print OUTFILE ("/* #line \"$infile_name\" $current_line_number */\n");
73 if ($inputline =~ /^\#/ ) # A line starts with "#" is a comment
74 {
75 &process_comment;
76 }
77 elsif ( $inputline =~ /^\?/ ) # A line starts with "?" is a verification request
78 {
79 &perform_test;
80 }
81 elsif ( $inputline =~ /^[012]/ ) # This is a data line
82 {
83 &process_data;
84 }
85 elsif ( $inputline =~ /^\!/ ) # This is a 32-bit register write
86 {
87 &process_data_reg32;
88 }
89 elsif ( $inputline =~ /^\~/ ) # This is a 64-bit register write
90 {
91 &process_data_reg64;
92 }
93 else # ignore this input
94 {
95 print OUTFILE ("\n");
96 }
97 }
98
99 &print_foot_part_of_c_code;
100
101 close(INFILE);
102 close(OUTFILE);
103
104 print ("Done!\n");
105 exit(0);
106
107
108
109
110 ###################
111 # Subroutines:
112 ###################
113
114 sub process_comment {
115 $inputline =~ s/#//;
116 print OUTFILE ("/*".$inputline."*/\n");
117 }
118
119 sub perform_test {
120 print OUTFILE ("\n");
121 print OUTFILE ("/******************************************************************/\n");
122 print OUTFILE ("/*Verify the data in the specified address with the input value: */\n\n");
123
124 @columns = split ( /[\s]+/, $inputline );
125
126 #column[1] is the address;
127 #column[2] is the value, in the format of oxH;
128 #column[3] is the mask, in the format of oxH;
129
130 print OUTFILE ("\n{\n");
131 print OUTFILE (" volatile unsigned* test_ptr = \(unsigned *\)".$columns[1].";\n");
132 print OUTFILE (" unsigned test_data = *test_ptr;\n");
133 print OUTFILE (" if \( \( test_data & $columns[3] \) == $columns[2] \) {\n");
134 print OUTFILE (" num_passed ++;\n");
135 print OUTFILE (" } else {\n");
136 print OUTFILE (" printf \(\"Data Verification (line $current_line_number) failed!\\n\"\); \n" );
137 print OUTFILE (" printf \(\"Expecting \%08x mask \%08x in address \%08x but got \%08x !\\n\", $columns[2], $columns[3], $columns[1], test_data\); \n");
138 print OUTFILE (" num_failed++;\n");
139 print OUTFILE (" }\n}\n");
140
141 }
142
143 sub process_data {
144 print OUTFILE ("/*****************************************************************/\n");
145 print OUTFILE ("/* Assign a quadword: */\n");
146
147 @columns = split ( /[\s]+/, $inputline );
148 $data_count = @columns;
149
150 #column[0] tells to which unit (VU0, VU1, or GIF) these data should go to.
151 $src_addr_name = "SRC_ADDR_CONST_".$columns[0];
152 $data_addr_name = "DATA_ADDR_CONST_".$columns[0];
153 $flag_addr_name = "FLAG_ADDR_CONST_".$columns[0];
154
155 #column[1] is the qual_word in format of 0xH_H_H_H:
156 @quadword = split ("_", $columns[1]);
157 $quadword[0] =~ s/0x//i;
158
159 print OUTFILE ("\n{\n");
160
161 print OUTFILE (" volatile unsigned* flag_ptr = \(unsigned *\)$flag_addr_name;\n");
162 print OUTFILE (" volatile unsigned* src_ptr = \(unsigned *\)$src_addr_name;\n");
163 print OUTFILE (" volatile unsigned* data_ptr = \(unsigned *\)$data_addr_name;\n");
164
165 if ( $data_count > 3 )
166 { #column[3] is the DMA_tag flag, if exist
167 $flag = $columns[3];
168 if ( $flag =~ /d/i ) {
169 print OUTFILE (" *flag_ptr = 1;\n");
170 }
171 else {
172 print OUTFILE (" *flag_ptr = 0;\n");
173 }
174 }
175
176 if ( $data_count > 2 )
177 {
178 #column[2] is the src_address, if exist
179 $src_addr = $columns[2];
180 print OUTFILE (" *src_ptr = $src_addr; \n");
181 }
182
183 #Now write the quadword:
184 print OUTFILE ("\n");
185 print OUTFILE (" *data_ptr++ = 0x".$quadword[3].";\n");
186 print OUTFILE (" *data_ptr++ = 0x".$quadword[2].";\n");
187 print OUTFILE (" *data_ptr++ = 0x".$quadword[1].";\n");
188 print OUTFILE (" *data_ptr = 0x".$quadword[0].";\n");
189 print OUTFILE (" num_qw_written ++;\n");
190 print OUTFILE ("\n");
191
192 print OUTFILE (" *flag_ptr = 0;\n") unless ($data_count < 4);
193 print OUTFILE (" *src_ptr = 0;\n") unless ( $data_count < 3);
194 print OUTFILE ("}\n");
195 }
196
197
198 sub process_data_reg32 {
199 print OUTFILE ("\n");
200 print OUTFILE ("/******************************************************************/\n");
201 print OUTFILE ("/*Writing the specified data into the specified address: */\n\n");
202
203 @columns = split ( /[\s]+/, $inputline );
204
205 #column[1] is the address, column[2] is the value, both in the format of 0xH;
206
207 print OUTFILE ("\n{\n");
208 print OUTFILE (" volatile unsigned* addr_ptr = \(unsigned *\)".$columns[1].";\n");
209 print OUTFILE (" *addr_ptr = ".$columns[2].";\n");
210 print OUTFILE (" num_w_written ++;\n");
211 print OUTFILE ("}\n");
212
213 }
214
215 sub process_data_reg64 {
216 print OUTFILE ("\n");
217 print OUTFILE ("/******************************************************************/\n");
218 print OUTFILE ("/*Writing the specified 64-bit data into the specified address: */\n\n");
219
220 @columns = split ( /[\s]+/, $inputline );
221
222 #column[1] is the address, in the format of 0xH;
223 #column[2] is the value, in the format of 0xH_H;
224 @llword = split ("_", $columns[2]);
225
226 print OUTFILE ("\n{\n");
227 print OUTFILE (" volatile long long int* reg64_ptr = \(long long int *\)".$columns[1].";\n");
228 print OUTFILE (" *reg64_ptr = \(long long\)".$llword[0]." \<\< 32 \| \(long long\)0x".$llword[1].";\n");
229 print OUTFILE (" num_w_written ++;\n");
230 print OUTFILE ("}\n");
231
232 }
233
234
235
236
237 sub print_header_part_of_c_code {
238
239 print OUTFILE ("\n/*");
240 print OUTFILE ("\n * This file is automatically generated.");
241 $version='$Revision$ $Date$';
242 print OUTFILE ("\n * c_gen.pl $version");
243 print OUTFILE ("\n * Input file: $infile_name");
244 print OUTFILE ("\n * Date: $date");
245 print OUTFILE ("\n */");
246 print OUTFILE ("\n");
247 print OUTFILE ("\n#include <stdio.h>\n");
248 print OUTFILE ("\n");
249 print OUTFILE ("
250 /* Memory mapping constants: */
251
252 /* VIF0 */
253 #define SRC_ADDR_CONST_0 0x10008010
254 #define DATA_ADDR_CONST_0 0x10004000
255 #define FLAG_ADDR_CONST_0 0x10008060
256
257 /* VIF1 */
258 #define SRC_ADDR_CONST_1 0x10009010
259 #define DATA_ADDR_CONST_1 0x10005000
260 #define FLAG_ADDR_CONST_1 0x10009060
261
262 /* GIF */
263 #define SRC_ADDR_CONST_2 0x1000a010
264 #define DATA_ADDR_CONST_2 0x10006000
265 #define FLAG_ADDR_CONST_2 0x1000a060
266 ");
267 print OUTFILE ("\n\n");
268
269 print OUTFILE ("int main()\n");
270 print OUTFILE ("{\n");
271 print OUTFILE (" unsigned num_qw_written = 0;\n");
272 print OUTFILE (" unsigned num_w_written = 0;\n");
273 print OUTFILE (" unsigned num_passed = 0;\n");
274 print OUTFILE (" unsigned num_failed = 0;\n");
275 print OUTFILE (" printf \(\"Start of execution...\\n\"\); \n" );
276 print OUTFILE ("\n\n");
277 }
278
279 sub print_foot_part_of_c_code {
280
281 print OUTFILE ("\n");
282 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" );
283 print OUTFILE ("exit (num_failed);\n");
284 print OUTFILE ("}\n");
285 }