]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/common/gentmap.c
sim: switch config.h usage to defs.h
[thirdparty/binutils-gdb.git] / sim / common / gentmap.c
CommitLineData
c906108c
SS
1/* Generate targ-vals.h and targ-map.c. */
2
3#include <stdio.h>
09d96939 4#include <stdlib.h>
dc1d9d1f 5#include <string.h>
c906108c
SS
6
7struct tdefs {
8 char *symbol;
9 int value;
10};
11
12static struct tdefs sys_tdefs[] = {
13#define sys_defs
99d8e879 14#include "nltvals.def"
c906108c
SS
15#undef sys_defs
16 { 0, 0 }
17};
18
19static struct tdefs errno_tdefs[] = {
20#define errno_defs
99d8e879 21#include "nltvals.def"
c906108c
SS
22#undef errno_defs
23 { 0, 0 }
24};
25
26static struct tdefs open_tdefs[] = {
27#define open_defs
99d8e879 28#include "nltvals.def"
c906108c
SS
29#undef open_defs
30 { 0, 0 }
31};
32
33static void
6cd5ace4 34gen_targ_vals_h (void)
c906108c
SS
35{
36 struct tdefs *t;
37
38 printf ("/* Target header values needed by the simulator and gdb. */\n");
39 printf ("/* This file is machine generated by gentmap.c. */\n\n");
40
41 printf ("#ifndef TARG_VALS_H\n");
42 printf ("#define TARG_VALS_H\n\n");
43
44 printf ("/* syscall values */\n");
45 for (t = &sys_tdefs[0]; t->symbol; ++t)
46 printf ("#define TARGET_%s %d\n", t->symbol, t->value);
47 printf ("\n");
48
49 printf ("/* errno values */\n");
50 for (t = &errno_tdefs[0]; t->symbol; ++t)
51 printf ("#define TARGET_%s %d\n", t->symbol, t->value);
52 printf ("\n");
53
54 printf ("/* open flag values */\n");
55 for (t = &open_tdefs[0]; t->symbol; ++t)
56 printf ("#define TARGET_%s 0x%x\n", t->symbol, t->value);
57 printf ("\n");
58
59 printf ("#endif /* TARG_VALS_H */\n");
60}
61
62static void
6cd5ace4 63gen_targ_map_c (void)
c906108c
SS
64{
65 struct tdefs *t;
66
67 printf ("/* Target value mapping utilities needed by the simulator and gdb. */\n");
68 printf ("/* This file is machine generated by gentmap.c. */\n\n");
69
6df01ab8 70 printf ("#include \"defs.h\"\n");
c906108c
SS
71 printf ("#include <errno.h>\n");
72 printf ("#include <fcntl.h>\n");
73 printf ("#include \"ansidecl.h\"\n");
df68e12b 74 printf ("#include \"sim/callback.h\"\n");
c906108c
SS
75 printf ("#include \"targ-vals.h\"\n");
76 printf ("\n");
77
78 printf ("/* syscall mapping table */\n");
79 printf ("CB_TARGET_DEFS_MAP cb_init_syscall_map[] = {\n");
80 for (t = &sys_tdefs[0]; t->symbol; ++t)
81 {
82 printf ("#ifdef CB_%s\n", t->symbol);
6362a3f8
MF
83 /* Skip the "SYS_" prefix for the name. */
84 printf (" { \"%s\", CB_%s, TARGET_%s },\n", t->symbol + 4, t->symbol, t->symbol);
c906108c
SS
85 printf ("#endif\n");
86 }
6362a3f8 87 printf (" { 0, -1, -1 }\n");
c906108c
SS
88 printf ("};\n\n");
89
90 printf ("/* errno mapping table */\n");
91 printf ("CB_TARGET_DEFS_MAP cb_init_errno_map[] = {\n");
92 for (t = &errno_tdefs[0]; t->symbol; ++t)
93 {
94 printf ("#ifdef %s\n", t->symbol);
6362a3f8 95 printf (" { \"%s\", %s, TARGET_%s },\n", t->symbol, t->symbol, t->symbol);
c906108c
SS
96 printf ("#endif\n");
97 }
6362a3f8 98 printf (" { 0, 0, 0 }\n");
c906108c
SS
99 printf ("};\n\n");
100
101 printf ("/* open flags mapping table */\n");
102 printf ("CB_TARGET_DEFS_MAP cb_init_open_map[] = {\n");
103 for (t = &open_tdefs[0]; t->symbol; ++t)
104 {
105 printf ("#ifdef %s\n", t->symbol);
6362a3f8 106 printf (" { \"%s\", %s, TARGET_%s },\n", t->symbol, t->symbol, t->symbol);
c906108c
SS
107 printf ("#endif\n");
108 }
6362a3f8 109 printf (" { 0, -1, -1 }\n");
c906108c
SS
110 printf ("};\n\n");
111}
112
113int
6cd5ace4 114main (int argc, char *argv[])
c906108c
SS
115{
116 if (argc != 2)
117 abort ();
118
119 if (strcmp (argv[1], "-h") == 0)
120 gen_targ_vals_h ();
121 else if (strcmp (argv[1], "-c") == 0)
122 gen_targ_map_c ();
123 else
124 abort ();
125
126 exit (0);
127}