1 | /* |
---|
2 | * Machtype: determine machine type & display type |
---|
3 | * |
---|
4 | * RCS Info |
---|
5 | * $Id: machtype_sun4.c,v 1.17 1996-12-11 21:24:45 ghudson Exp $ |
---|
6 | * $Locker: $ |
---|
7 | */ |
---|
8 | |
---|
9 | #define volatile |
---|
10 | #include <stdio.h> |
---|
11 | #include <string.h> |
---|
12 | #include <kvm.h> |
---|
13 | #include <nlist.h> |
---|
14 | #include <fcntl.h> |
---|
15 | #undef NBPP |
---|
16 | #define NBPP 4 |
---|
17 | #include <sys/types.h> |
---|
18 | #include <sys/file.h> |
---|
19 | #include <sys/cpu.h> |
---|
20 | #include <ctype.h> |
---|
21 | /* OpenPROM stuff */ |
---|
22 | #include <sys/promif.h> |
---|
23 | #include <sys/ddi.h> |
---|
24 | #include <sys/sunddi.h> |
---|
25 | #include <sys/ddi_impldefs.h> |
---|
26 | |
---|
27 | int verbose =0; |
---|
28 | char mydisk[128]; |
---|
29 | |
---|
30 | struct nlist nl[] = { |
---|
31 | #define X_cpu 0 |
---|
32 | { "cputype" }, |
---|
33 | #define X_maxmem 1 |
---|
34 | { "maxmem" }, |
---|
35 | #define X_physmem 2 |
---|
36 | { "physmem" }, |
---|
37 | #define X_topnode 3 |
---|
38 | { "top_devinfo" }, |
---|
39 | { "" } |
---|
40 | }; |
---|
41 | |
---|
42 | main(argc, argv) |
---|
43 | int argc; |
---|
44 | char **argv; |
---|
45 | { |
---|
46 | kvm_t *kv; |
---|
47 | int i; |
---|
48 | int cpuflg = 0, dpyflg = 0, raflg = 0, memflg = 0; |
---|
49 | int doathenaV = 0; |
---|
50 | int dosyspV = 0; |
---|
51 | int dolocalV = 0; |
---|
52 | int dobosN = 0; |
---|
53 | int dobosV = 0; |
---|
54 | int dosysnam = 0; |
---|
55 | char *kernel = "/dev/ksyms", *memory = "/dev/mem"; |
---|
56 | FILE *f; |
---|
57 | |
---|
58 | for (i = 1; i < argc; i++) { |
---|
59 | if (argv[i][0] != '-') |
---|
60 | usage(argv[0]); |
---|
61 | |
---|
62 | switch (argv[i][1]) { |
---|
63 | case 'c': |
---|
64 | cpuflg++; |
---|
65 | break; |
---|
66 | case 'd': |
---|
67 | dpyflg++; |
---|
68 | break; |
---|
69 | case 'r': |
---|
70 | raflg++; |
---|
71 | break; |
---|
72 | case 'M': |
---|
73 | memflg++; |
---|
74 | break; |
---|
75 | case 'k': |
---|
76 | kernel = argv[i+1]; |
---|
77 | i++; |
---|
78 | break; |
---|
79 | case 'm': |
---|
80 | memory = argv[i+1]; |
---|
81 | i++; |
---|
82 | break; |
---|
83 | case 'A': |
---|
84 | doathenaV = 1; |
---|
85 | break; |
---|
86 | case 'L': |
---|
87 | dolocalV = 1; |
---|
88 | break; |
---|
89 | case 'P': |
---|
90 | dosyspV = 1; |
---|
91 | break; |
---|
92 | case 'N': |
---|
93 | dobosN = 1; |
---|
94 | break; |
---|
95 | case 'E': |
---|
96 | dobosV = 1; |
---|
97 | break; |
---|
98 | case 'S': |
---|
99 | dosysnam = 1; |
---|
100 | break; |
---|
101 | case 'v': |
---|
102 | verbose++; |
---|
103 | break; |
---|
104 | default: |
---|
105 | usage(argv[0]); |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | if ((argc == 1) || ((argc == 2) && verbose)) { |
---|
110 | puts("sun4"); |
---|
111 | exit(0); |
---|
112 | } |
---|
113 | |
---|
114 | /* Print out version of Athena machtype compiled against */ |
---|
115 | if (doathenaV) { |
---|
116 | if (verbose) |
---|
117 | printf("Machtype version: %s.%s\n",ATHMAJV,ATHMINV); |
---|
118 | else |
---|
119 | printf("%s.%s\n",ATHMAJV,ATHMINV); |
---|
120 | } |
---|
121 | |
---|
122 | /* Print out version of attached packs */ |
---|
123 | if (dosyspV) { |
---|
124 | char buf[256],rvd_version[256], *p; |
---|
125 | if ((f = fopen("/srvd/.rvdinfo","r")) == NULL) { |
---|
126 | printf("Syspack information unavailable\n"); |
---|
127 | } else { |
---|
128 | fgets(buf,256,f); |
---|
129 | fclose(f); |
---|
130 | /* If it is verbose, give the whole line, else just the vers # */ |
---|
131 | if (verbose) { |
---|
132 | printf(buf); |
---|
133 | } else { |
---|
134 | p = strchr(buf,' '); /* skip "Athena" */ |
---|
135 | p = strchr(p+1,' '); /* skip "RVD" */ |
---|
136 | p = strchr(p+1,' '); /* Skip "RSAIX" */ |
---|
137 | p = strchr(p+1,' '); /* skip "version" */ |
---|
138 | strncpy(rvd_version,p+1,256); |
---|
139 | p = strchr(rvd_version,' '); |
---|
140 | *p = '\0'; |
---|
141 | printf("%s\n",rvd_version); |
---|
142 | } |
---|
143 | } |
---|
144 | } |
---|
145 | |
---|
146 | /* Print out local version from /etc/athena/version */ |
---|
147 | if (dolocalV) { |
---|
148 | char buf[256],loc_version[256], *p; |
---|
149 | if ((f = fopen("/etc/athena/version","r")) == NULL) { |
---|
150 | printf("Local version information unavailable\n"); |
---|
151 | } else { |
---|
152 | fseek(f,-100,2); |
---|
153 | while (fgets(buf,256,f) != NULL) |
---|
154 | ; |
---|
155 | fclose(f); |
---|
156 | |
---|
157 | if (verbose) { |
---|
158 | printf(buf); |
---|
159 | } else { |
---|
160 | p = strchr(buf,' '); /* skip "Athena" */ |
---|
161 | p = strchr(p+1,' '); /* skip "Workstation/Server" */ |
---|
162 | p = strchr(p+1,' '); /* Skip "RSAIX" */ |
---|
163 | p = strchr(p+1,' '); /* skip "version" */ |
---|
164 | strncpy(loc_version,p+1,256); |
---|
165 | p = strchr(loc_version,' '); |
---|
166 | *p = '\0'; |
---|
167 | printf("%s\n",loc_version); |
---|
168 | } |
---|
169 | } |
---|
170 | } |
---|
171 | |
---|
172 | /* Print out vendor OS name */ |
---|
173 | if (dobosN) { |
---|
174 | if (verbose) { |
---|
175 | printf(OSNAME " " OSVERS "\n"); |
---|
176 | } else { |
---|
177 | printf(OSNAME "\n"); |
---|
178 | } |
---|
179 | } |
---|
180 | |
---|
181 | /* Print out vendor OS version */ |
---|
182 | if (dobosV) { |
---|
183 | printf(OSVERS "\n"); |
---|
184 | } |
---|
185 | |
---|
186 | /* Print out Athena System name */ |
---|
187 | if (dosysnam) { |
---|
188 | printf("%s\n", ATHSYS); |
---|
189 | } |
---|
190 | |
---|
191 | if (cpuflg || dpyflg || raflg || memflg) |
---|
192 | { |
---|
193 | int memfd; |
---|
194 | kv = kvm_open(NULL,NULL,NULL,O_RDONLY,NULL); |
---|
195 | if (!kv) { |
---|
196 | fprintf(stderr,"%s: unable to examine the kernel\n", argv[0]); |
---|
197 | exit(2); |
---|
198 | } |
---|
199 | if (kvm_nlist(kv, &nl) < 0) { |
---|
200 | fprintf(stderr,"%s: can't get namelist\n", argv[0]); |
---|
201 | exit(2); |
---|
202 | } |
---|
203 | if (cpuflg) |
---|
204 | do_cpu(kv, memfd); |
---|
205 | if (dpyflg) |
---|
206 | do_dpy(kernel, memfd); |
---|
207 | if (raflg) |
---|
208 | do_disk(kernel, memfd); |
---|
209 | if (memflg) |
---|
210 | do_memory(kv, memfd); |
---|
211 | } |
---|
212 | if (cpuflg || dpyflg || raflg || memflg) |
---|
213 | kvm_close(kv); |
---|
214 | exit(0); |
---|
215 | } |
---|
216 | |
---|
217 | usage(name) |
---|
218 | char *name; |
---|
219 | { |
---|
220 | fprintf(stderr, "usage: %s [-v] [-c] [-d] [-r] [-E] [-N] [-M]\n",name); |
---|
221 | fprintf(stderr, " [-k kernel] [-m memory] [-A] [-L] [-P] [-S]\n"); |
---|
222 | exit(1); |
---|
223 | } |
---|
224 | |
---|
225 | void do_cpu_prom(kvm_t *kernel) |
---|
226 | { |
---|
227 | unsigned long ptop; |
---|
228 | struct dev_info top; |
---|
229 | char buf[BUFSIZ]; |
---|
230 | |
---|
231 | char* cpustr; |
---|
232 | |
---|
233 | /* read device name of the top node of the OpenPROM */ |
---|
234 | |
---|
235 | if ( (! nl[X_topnode].n_value) |
---|
236 | || (kvm_read(kernel, (unsigned long) nl[X_topnode].n_value, |
---|
237 | (char*) &ptop, sizeof(ptop)) != sizeof(ptop)) |
---|
238 | || (! ptop) |
---|
239 | || (kvm_read(kernel, (unsigned long) ptop, |
---|
240 | (char*) &top, sizeof(top)) != sizeof(top)) |
---|
241 | || (! top.devi_name) |
---|
242 | || (kvm_read(kernel, (unsigned long) top.devi_name, |
---|
243 | (char*) &buf, sizeof(buf)) != sizeof(buf)) |
---|
244 | || (! buf[0]) ) { |
---|
245 | fprintf(stderr, "Can't get CPU information from the kernel\n"); |
---|
246 | exit(2); |
---|
247 | } |
---|
248 | buf[BUFSIZ-1] = '\0'; |
---|
249 | |
---|
250 | /* now, return a string identifying the CPU */ |
---|
251 | |
---|
252 | if (verbose) { |
---|
253 | /* "verbose" returns the kernel information directly */ |
---|
254 | puts(buf); |
---|
255 | |
---|
256 | } else { |
---|
257 | |
---|
258 | /* skip the initial "SUNW," */ |
---|
259 | if (cpustr = strchr(buf, ',')) |
---|
260 | cpustr++; |
---|
261 | else |
---|
262 | cpustr = buf; |
---|
263 | |
---|
264 | /* reformat the result to look like "SPARC/Classic" or "SPARC/5" */ |
---|
265 | if (! strncmp(cpustr, "SPARC", sizeof("SPARC")-1)) { |
---|
266 | cpustr += sizeof("SPARC")-1; |
---|
267 | |
---|
268 | if (! strncmp(cpustr, "station-", sizeof("station-")-1)) |
---|
269 | cpustr += sizeof("station-")-1; |
---|
270 | else |
---|
271 | if (! strcmp(cpustr, "classic")) /* backwards compat - cap classic */ |
---|
272 | (*cpustr) = toupper(*cpustr); |
---|
273 | |
---|
274 | printf("SPARC/%s\n", cpustr); |
---|
275 | |
---|
276 | } else { |
---|
277 | /* if it didn't start with "SPARC", just leave it be... */ |
---|
278 | puts(cpustr); |
---|
279 | } |
---|
280 | } |
---|
281 | |
---|
282 | return; |
---|
283 | } |
---|
284 | |
---|
285 | do_cpu(kernel, mf) |
---|
286 | kvm_t *kernel; |
---|
287 | int mf; |
---|
288 | { |
---|
289 | short cpu; |
---|
290 | short cpu_type; |
---|
291 | |
---|
292 | cpu_type = kvm_read(kernel,nl[X_cpu].n_value,&cpu, sizeof(cpu)); |
---|
293 | { |
---|
294 | switch(cpu) { |
---|
295 | case CPU_SUN4C_60: |
---|
296 | puts(verbose ? "SPARCstation 1": "SPARC/1"); |
---|
297 | break; |
---|
298 | case CPU_SUN4C_40: |
---|
299 | puts(verbose ? "SPARCstation IPC" : "SPARC/IPC"); |
---|
300 | break; |
---|
301 | case CPU_SUN4C_65: |
---|
302 | puts(verbose ? "SPARCstation 1+" : "SPARC/1+"); |
---|
303 | break; |
---|
304 | case CPU_SUN4C_20: |
---|
305 | puts(verbose ? "SPARCstation SLC" : "SPARC/SLC"); |
---|
306 | break; |
---|
307 | case CPU_SUN4C_75: |
---|
308 | puts(verbose ? "SPARCstation 2" : "SPARC/2"); |
---|
309 | break; |
---|
310 | case CPU_SUN4C_25: |
---|
311 | puts(verbose ? "SPARCstation ELC" : "SPARC/ELC"); |
---|
312 | break; |
---|
313 | case CPU_SUN4C_50: |
---|
314 | puts(verbose ? "SPARCstation IPX" : "SPARC/IPX"); |
---|
315 | break; |
---|
316 | case CPU_SUN4M_50: /* 114... Sparc20 */ |
---|
317 | case OBP_ARCH: /* 128 */ |
---|
318 | do_cpu_prom(kernel); |
---|
319 | break; |
---|
320 | |
---|
321 | default: |
---|
322 | if(verbose) |
---|
323 | printf("Unknown SUN type %d\n", cpu); |
---|
324 | else |
---|
325 | puts("SUN???"); |
---|
326 | } |
---|
327 | } |
---|
328 | return; |
---|
329 | } |
---|
330 | |
---|
331 | do_dpy(kernel, mf) |
---|
332 | char *kernel; |
---|
333 | int mf; |
---|
334 | { |
---|
335 | puts(verbose? "cgthree frame buffer" : "cgthree"); |
---|
336 | return; |
---|
337 | } |
---|
338 | |
---|
339 | do_disk(kernel, mf) |
---|
340 | char *kernel; |
---|
341 | int mf; |
---|
342 | { |
---|
343 | int len; |
---|
344 | |
---|
345 | mf = open ("/dev/dsk/c0t3d0s0", O_RDONLY); |
---|
346 | len = read (mf, mydisk, sizeof(mydisk)-1); |
---|
347 | if (len != -1) |
---|
348 | mydisk[len] = '\0'; |
---|
349 | |
---|
350 | if (verbose) |
---|
351 | printf("c0t3d0s0 : "); |
---|
352 | if (mydisk[1] == 'U') |
---|
353 | printf("%.7s\n", mydisk); |
---|
354 | else |
---|
355 | printf("%.15s\n", mydisk); |
---|
356 | |
---|
357 | return; |
---|
358 | } |
---|
359 | |
---|
360 | #define MEG (1024*1024) |
---|
361 | |
---|
362 | do_memory (kernel, mf) |
---|
363 | kvm_t *kernel; |
---|
364 | int mf; |
---|
365 | { |
---|
366 | int pos, mem; |
---|
367 | |
---|
368 | kvm_read(kernel,nl[X_maxmem].n_value,&mem, sizeof(mem)); |
---|
369 | if(verbose) |
---|
370 | printf("%d user, ",mem * NBPP); |
---|
371 | kvm_read(kernel,nl[X_physmem].n_value,&mem, sizeof(mem)); |
---|
372 | if(verbose) |
---|
373 | printf("%d (%d M) total\n",mem * NBPP ,(mem * NBPP + 916)/1024 ); |
---|
374 | else |
---|
375 | printf("%d\n", mem * NBPP + 916); |
---|
376 | return; |
---|
377 | } |
---|
378 | |
---|