1 /* Miscellaneous simulator utilities.
2 Copyright (C) 1997 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This file is part of GDB, the GNU debugger.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
29 printf ("typedef struct _test_tuples {\n");
30 printf (" int line;\n");
31 printf (" int row;\n");
32 printf (" int col;\n");
33 printf (" long long val;\n");
34 printf (" long long check;\n");
35 printf ("} test_tuples;\n");
37 printf ("typedef struct _test_spec {\n");
38 printf (" const char *file;\n");
39 printf (" const char *macro;\n");
40 printf (" int nr_rows;\n");
41 printf (" int nr_cols;\n");
42 printf (" test_tuples *tuples;\n");
43 printf ("} test_spec;\n");
55 printf ("\n/* Test the BIT%s macro */\n", macro);
56 printf ("test_tuples bit%s_tuples[%d] = {\n", macro, nr_bits);
57 for (i = 0; i < nr_bits; i++)
59 /* compute what we think the value is */
62 bit <<= nr_bits - i - 1;
68 printf (" { __LINE__, ");
69 printf ("%d, %d, ", -1, i);
70 printf ("BIT%s (%2d), ", macro, i);
71 printf ("0x%08lx%08lxLL, ", (long) (bit >> 32), (long) bit);
76 printf ("test_spec bit%s_test = { __FILE__, \"BIT%s\", 1, %d, bit%s_tuples, };\n",
77 macro, macro, nr_bits, macro);
83 gen_mask (int bitsize,
90 printf ("\n/* Test the %sMASK%s macro */\n", msb, macro);
91 printf ("test_tuples mask%s_tuples[%d][%d] = {\n", macro, nr_bits, nr_bits);
92 for (l = 0; l < nr_bits; l++)
95 for (h = 0; h < nr_bits; h++)
97 printf (" { __LINE__, ");
98 if ((strcmp (msb, "MS") == 0 && l <= h)
99 || (strcmp (msb, "MS") != 0 && l >= h)
100 || (strcmp (macro, "") == 0))
102 /* compute the mask */
105 for (b = 0; b < nr_bits; b++)
108 if (strcmp (msb, "MS") == 0)
110 if ((l <= b && b <= h)
111 || (h < l && (b <= h || b >= l)))
112 bit <<= (nr_bits - b - 1);
118 if ((l >= b && b >= h)
119 || (h > l && (b >= h || b <= l)))
127 mask = (unsigned long) mask;
128 printf ("%d, %d, ", l, h);
129 printf ("%sMASK%s (%2d, %2d), ", msb, macro, l, h);
130 printf ("0x%08lx%08lxLL, ", (long) (mask >> 32), (long) mask);
140 printf ("test_spec mask%s_test = { __FILE__, \"%sMASK%s\", %d, %d, &mask%s_tuples[0][0], };\n",
141 macro, msb, macro, nr_bits, nr_bits, macro);
149 fprintf (stderr, "Usage:\n");
150 fprintf (stderr, " bits-gen <nr-bits> <msb>\n");
151 fprintf (stderr, "Generate a test case for the simulator bit manipulation code\n");
152 fprintf (stderr, " <nr-bits> = { 32 | 64 }\n");
153 fprintf (stderr, " <msb> = { 0 | { 31 | 63 } }\n");
157 case 1: fprintf (stderr, "Wrong number of arguments\n");
160 fprintf (stderr, "Invalid <nr-bits> argument\n");
163 fprintf (stderr, "Invalid <msb> argument\n");
182 /* parse the only argument */
185 if (strcmp (argv [1], "32") == 0)
187 else if (strcmp (argv [1], "64") == 0)
191 if (strcmp (argv [2], "0") == 0)
193 else if (strcmp (argv [2], "31") == 0 && bitsize == 32)
195 else if (strcmp (argv [2], "63") == 0 && bitsize == 64)
204 printf ("#define WITH_TARGET_WORD_BITSIZE %d\n", bitsize);
205 printf ("#define WITH_TARGET_WORD_MSB %d\n", msb);
206 printf ("#define WITH_HOST_WORD_BITSIZE %d\n", sizeof (int) * 8);
208 printf ("#define SIM_BITS_INLINE (INCLUDE_MODULE | INCLUDED_BY_MODULE)\n");
210 printf ("#define ASSERT(X) do { if (!(X)) abort(); } while (0)\n");
212 printf ("#include \"sim-basics.h\"\n");
213 printf ("#include \"sim-types.h\"\n");
214 printf ("#include \"sim-bits.h\"\n");
220 printf ("#define DO_BIT_TESTS\n");
221 gen_bit ( 4, msb, "4", 4);
222 gen_bit ( 5, msb, "5", 5);
223 gen_bit ( 8, msb, "8", 8);
224 gen_bit (10, msb, "10", 10);
225 gen_bit (16, msb, "16", 16);
226 gen_bit (32, msb, "32", 32);
227 gen_bit (64, msb, "64", 64);
228 gen_bit (bitsize, msb, "", 64);
230 printf ("test_spec *(bit_tests[]) = {\n");
231 printf (" &bit4_test,\n");
232 printf (" &bit5_test,\n");
233 printf (" &bit8_test,\n");
234 printf (" &bit10_test,\n");
235 printf (" &bit16_test,\n");
236 printf (" &bit32_test,\n");
237 printf (" &bit64_test,\n");
238 printf (" &bit_test,\n");
244 printf ("#define DO_MASK_TESTS\n");
245 gen_mask (16, ms, "16", 16);
246 gen_mask (32, ms, "32", 32);
247 gen_mask (64, ms, "64", 64);
248 gen_mask (bitsize, ms, "", 64);
250 printf ("test_spec *(mask_tests[]) = {\n");
251 printf (" &mask16_test,\n");
252 printf (" &mask32_test,\n");
253 printf (" &mask64_test,\n");
254 printf (" &mask_test,\n");