Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * OpenSPARC T2 Processor File: dumpconfig.c | |
5 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. | |
7 | * | |
8 | * The above named program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public | |
10 | * License version 2 as published by the Free Software Foundation. | |
11 | * | |
12 | * The above named program is distributed in the hope that it will be | |
13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public | |
18 | * License along with this work; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | * | |
21 | * ========== Copyright Header End ============================================ | |
22 | */ | |
23 | #include <sys/types.h> | |
24 | #include <errno.h> | |
25 | #include <stdlib.h> | |
26 | #include <unistd.h> | |
27 | #include <stdio.h> | |
28 | #include <stdarg.h> | |
29 | #include <time.h> | |
30 | ||
31 | #include "basics.h" | |
32 | #include "allocate.h" | |
33 | #include "simcore.h" | |
34 | #include "config.h" | |
35 | #include "options.h" | |
36 | #include "fileutil.h" | |
37 | #include "lexer.h" | |
38 | #include "dumpinfo.h" | |
39 | ||
40 | ||
41 | dumpinfo_t dumpinfo; | |
42 | ||
43 | static void dump_system(system_t * sp); | |
44 | static void dump_domain(domain_t * dp); | |
45 | ||
46 | /* | |
47 | * Dump the current config and state of the simulator system | |
48 | */ | |
49 | ||
50 | void dump_config(FILE * outp) | |
51 | { | |
52 | system_t * systemp; | |
53 | int i; | |
54 | time_t ti; | |
55 | struct tm tms; | |
56 | char buf[1024]; | |
57 | ||
58 | ti = time((void*)0); | |
59 | localtime_r(&ti, &tms); | |
60 | ||
61 | sprintf(buf, "%04d-%02d-%02d %02d:%02d:%02d", | |
62 | tms.tm_year+1900, tms.tm_mon+1, tms.tm_mday, | |
63 | tms.tm_hour, tms.tm_min, tms.tm_sec); | |
64 | ||
65 | /* Wander the systems and dump each one */ | |
66 | ||
67 | dumpinfo.indent = 0; | |
68 | dumpinfo.outp = outp; | |
69 | ||
70 | pi("\n\ | |
71 | //\n\ | |
72 | // Simulator config/dump file auto-created %s\n\ | |
73 | //\n\n", buf); | |
74 | ||
75 | for (i=0; i<target_config.systems.count; i++) | |
76 | dump_system(LIST_ENTRY(target_config.systems, i)); | |
77 | } | |
78 | ||
79 | ||
80 | ||
81 | ||
82 | void dump_system(system_t * sysp) | |
83 | { | |
84 | int i; | |
85 | ||
86 | pi("\t// system %d\n", sysp->idx); | |
87 | pi("system \"%s\" {\n", sysp->namep); | |
88 | dumpinfo.indent ++; | |
89 | ||
90 | for (i=0; i<sysp->domains.count; i++) | |
91 | dump_domain(LIST_ENTRY(sysp->domains,i)); | |
92 | ||
93 | dumpinfo.indent --; | |
94 | pi("}\n"); | |
95 | } | |
96 | ||
97 | ||
98 | ||
99 | ||
100 | ||
101 | void dump_domain(domain_t * dp) | |
102 | { | |
103 | int i; | |
104 | config_proc_t * procp; | |
105 | config_dev_t * devp; | |
106 | ||
107 | pi("\t// domain %d\n", dp->idx); | |
108 | pi("domain {\n"); | |
109 | dumpinfo.indent ++; | |
110 | ||
111 | pi("sysclkfreq = 0x%llx ;\n", dp->sysclkfreq); | |
112 | ||
113 | for (i=0; i<dp->procs.count; i ++) { | |
114 | procp = LIST_ENTRY( dp->procs, i ); | |
115 | ||
116 | procp->proc_typep->dump_proc(dp, procp); | |
117 | } | |
118 | ||
119 | devp = dp->device.listp; | |
120 | if (devp!=(config_dev_t*)0) { | |
121 | pi("addressmap {\n"); | |
122 | dumpinfo.indent++; | |
123 | ||
124 | for (i=0; i<dp->device.count; i++) { | |
125 | /* leave defn dangling for dump routine */ | |
126 | pi("\t// device id %d\n", devp->device_id); | |
127 | ||
128 | /* FIXME: for the moment implied devices get a commented output ... */ | |
129 | /* eventually all output must be squashed of these devices */ | |
130 | if (devp->is_implied) { | |
131 | pi("// "); | |
132 | ASSERT(devp->dev_typep->dump_dev == NULL); | |
133 | } | |
134 | pi("device \"%s\" 0x%llx + 0x%llx %s\n", | |
135 | devp->dev_typep->dev_type_namep, | |
136 | devp->addrp->baseaddr, | |
137 | devp->addrp->topaddr - devp->addrp->baseaddr, | |
138 | devp->dev_typep->dump_dev ? "{" : ";" ); | |
139 | if (devp->dev_typep->dump_dev) { | |
140 | devp->dev_typep->dump_dev(devp); | |
141 | pi("}\n"); | |
142 | } | |
143 | devp = devp->nextp; | |
144 | } | |
145 | ||
146 | dumpinfo.indent --; | |
147 | pi("}\n"); | |
148 | } | |
149 | ||
150 | ||
151 | dumpinfo.indent --; | |
152 | pi("}\n"); | |
153 | } | |
154 | ||
155 | ||
156 | ||
157 | ||
158 | ||
159 | ||
160 | ||
161 | ||
162 | ||
163 | ||
164 | ||
165 | void pi(char * fmt, ...) | |
166 | { | |
167 | int i; | |
168 | va_list args; | |
169 | ||
170 | va_start(args, fmt); | |
171 | ||
172 | for (i=0; i<dumpinfo.indent; i++) | |
173 | fputc('\t', dumpinfo.outp); | |
174 | ||
175 | ||
176 | vfprintf(dumpinfo.outp, fmt, args); | |
177 | ||
178 | va_end(args); | |
179 | } | |
180 |