1 | /* |
---|
2 | * Copyright (c) 1992-1998 Michael A. Cooper. |
---|
3 | * This software may be freely used and distributed provided it is not |
---|
4 | * sold for profit or used in part or in whole for commercial gain |
---|
5 | * without prior written agreement, and the author is credited |
---|
6 | * appropriately. |
---|
7 | */ |
---|
8 | |
---|
9 | #ifndef lint |
---|
10 | static char *RCSid = "$Revision: 1.1.1.3 $"; |
---|
11 | #endif |
---|
12 | |
---|
13 | /* |
---|
14 | * Convex SPP-UX specific functions |
---|
15 | */ |
---|
16 | |
---|
17 | #include "defs.h" |
---|
18 | #include <utmp.h> |
---|
19 | #include <sys/cnx_sysinfo.h> |
---|
20 | #include <sys/libio.h> |
---|
21 | #include <sys/conf.h> |
---|
22 | |
---|
23 | /* |
---|
24 | * Platform Specific Interfaces |
---|
25 | */ |
---|
26 | extern char *GetModelCnxUname(); |
---|
27 | PSI_t GetModelPSI[] = { /* Get system Model */ |
---|
28 | { GetModelCnxUname }, |
---|
29 | { GetModelFile }, |
---|
30 | { GetModelDef }, |
---|
31 | { NULL }, |
---|
32 | }; |
---|
33 | extern char *GetSerialUname(); |
---|
34 | PSI_t GetSerialPSI[] = { /* Get Serial Number */ |
---|
35 | { GetSerialUname }, |
---|
36 | { NULL }, |
---|
37 | }; |
---|
38 | PSI_t GetRomVerPSI[] = { /* Get ROM Version */ |
---|
39 | { NULL }, |
---|
40 | }; |
---|
41 | PSI_t GetKernArchPSI[] = { /* Get Kernel Architecture */ |
---|
42 | { GetKernArchDef }, |
---|
43 | { NULL }, |
---|
44 | }; |
---|
45 | extern char *GetAppArchHPUX(); |
---|
46 | PSI_t GetAppArchPSI[] = { /* Get Application Architecture */ |
---|
47 | { GetAppArchHPUX }, |
---|
48 | { GetAppArchTest }, |
---|
49 | { NULL }, |
---|
50 | }; |
---|
51 | extern char *GetCpuTypeHPUX(); |
---|
52 | PSI_t GetCpuTypePSI[] = { /* Get CPU Type */ |
---|
53 | { GetCpuTypeHPUX }, |
---|
54 | { NULL }, |
---|
55 | }; |
---|
56 | extern char *GetNumCpuCnxSysinfo(); |
---|
57 | PSI_t GetNumCpuPSI[] = { /* Get Number of CPU's */ |
---|
58 | { GetNumCpuCnxSysinfo }, |
---|
59 | { NULL }, |
---|
60 | }; |
---|
61 | extern char *GetKernVerCnxSysinfo(); |
---|
62 | PSI_t GetKernVerPSI[] = { /* Get Kernel Version */ |
---|
63 | { GetKernVerCnxSysinfo }, |
---|
64 | { NULL }, |
---|
65 | }; |
---|
66 | extern char *GetOSNameCnxUname(); |
---|
67 | extern char *GetOSNameCnxSysinfo(); |
---|
68 | PSI_t GetOSNamePSI[] = { /* Get OS Name */ |
---|
69 | { GetOSNameCnxUname }, |
---|
70 | { GetOSNameCnxSysinfo }, |
---|
71 | { NULL }, |
---|
72 | }; |
---|
73 | extern char *GetOSVerCnxSysinfo(); |
---|
74 | PSI_t GetOSVerPSI[] = { /* Get OS Version */ |
---|
75 | { GetOSVerCnxSysinfo }, |
---|
76 | { NULL }, |
---|
77 | }; |
---|
78 | PSI_t GetManShortPSI[] = { /* Get Short Man Name */ |
---|
79 | { GetManShortSysinfo }, |
---|
80 | { GetManShortDef }, |
---|
81 | { NULL }, |
---|
82 | }; |
---|
83 | PSI_t GetManLongPSI[] = { /* Get Long Man Name */ |
---|
84 | { GetManLongSysinfo }, |
---|
85 | { GetManLongDef }, |
---|
86 | { NULL }, |
---|
87 | }; |
---|
88 | extern char *GetMemoryCnxSysinfo(); |
---|
89 | PSI_t GetMemoryPSI[] = { /* Get amount of memory */ |
---|
90 | { GetMemoryCnxSysinfo }, |
---|
91 | { GetMemoryPhysmemSym }, |
---|
92 | { NULL }, |
---|
93 | }; |
---|
94 | PSI_t GetVirtMemPSI[] = { /* Get amount of virtual memory */ |
---|
95 | { NULL }, |
---|
96 | }; |
---|
97 | PSI_t GetBootTimePSI[] = { /* Get System Boot Time */ |
---|
98 | #if defined(BOOT_TIME) |
---|
99 | { GetBootTimeUtmp }, |
---|
100 | #endif /* BOOT_TIME */ |
---|
101 | { NULL }, |
---|
102 | }; |
---|
103 | |
---|
104 | /* |
---|
105 | * Get system Model type using cnx_uname() |
---|
106 | */ |
---|
107 | extern char *GetModelCnxUname() |
---|
108 | { |
---|
109 | static struct utsname un; |
---|
110 | static char Buff[BUFSIZ]; |
---|
111 | |
---|
112 | if (cnx_uname(&un) != 0) |
---|
113 | return((char *) NULL); |
---|
114 | |
---|
115 | #if defined(MODEL_NAME) |
---|
116 | (void) snprintf(Buff, sizeof(Buff), "%s ", MODEL_NAME); |
---|
117 | #else |
---|
118 | Buff[0] = CNULL; |
---|
119 | #endif |
---|
120 | (void) strcat(Buff, un.machine); |
---|
121 | |
---|
122 | return(Buff); |
---|
123 | } |
---|
124 | |
---|
125 | /* |
---|
126 | * Get Serial Number |
---|
127 | */ |
---|
128 | extern char *GetSerialUname() |
---|
129 | { |
---|
130 | static struct utsname un; |
---|
131 | |
---|
132 | if (cnx_uname(&un) != 0) |
---|
133 | return((char *) NULL); |
---|
134 | |
---|
135 | return( (un.idnumber[0]) ? un.idnumber : (char *)NULL ); |
---|
136 | } |
---|
137 | |
---|
138 | /* |
---|
139 | * Determine system application architecture using sysconf(). |
---|
140 | */ |
---|
141 | extern char *GetAppArchHPUX() |
---|
142 | { |
---|
143 | long CpuVersion; |
---|
144 | |
---|
145 | CpuVersion = sysconf(_SC_CPU_VERSION); |
---|
146 | if (CpuVersion < 0) { |
---|
147 | SImsg(SIM_GERR, "sysconf(_SC_CPU_VERSION) failed: %s.", SYSERR); |
---|
148 | return((char *) NULL); |
---|
149 | } |
---|
150 | |
---|
151 | if (CPU_IS_PA_RISC(CpuVersion)) |
---|
152 | return(HP_AA_PARISC); |
---|
153 | else if (CPU_IS_HP_MC68K(CpuVersion)) |
---|
154 | return(HP_AA_MC68K); |
---|
155 | |
---|
156 | return((char *) NULL); |
---|
157 | } |
---|
158 | |
---|
159 | /* |
---|
160 | * Determine CPU type using sysconf(). |
---|
161 | */ |
---|
162 | extern char *GetCpuTypeHPUX() |
---|
163 | { |
---|
164 | long CpuVersion; |
---|
165 | register int i; |
---|
166 | Define_t *Def; |
---|
167 | |
---|
168 | CpuVersion = sysconf(_SC_CPU_VERSION); |
---|
169 | if (CpuVersion < 0) { |
---|
170 | SImsg(SIM_GERR, "sysconf(_SC_CPU_VERSION) failed: %s.", SYSERR); |
---|
171 | return((char *) NULL); |
---|
172 | } |
---|
173 | |
---|
174 | Def = DefGet(DL_CPU, NULL, CpuVersion, 0); |
---|
175 | if (Def && Def->ValStr1) |
---|
176 | return(Def->ValStr1); |
---|
177 | |
---|
178 | return((char *) NULL); |
---|
179 | } |
---|
180 | |
---|
181 | /* |
---|
182 | * Get Number of CPU's using cnx_sysinfo() |
---|
183 | */ |
---|
184 | extern char *GetNumCpuCnxSysinfo() |
---|
185 | { |
---|
186 | cnx_is_complex_basic_info_data_t |
---|
187 | Basic; |
---|
188 | cnx_is_target_data_t Target; |
---|
189 | int Status; |
---|
190 | static char Buff[10]; |
---|
191 | unsigned long Num; |
---|
192 | |
---|
193 | cnx_sysinfo_target_complex(&Target); |
---|
194 | Status = cnx_sysinfo(CNX_IS_COMPLEX_BASIC_INFO, &Target, &Basic, |
---|
195 | 1, CNX_IS_COMPLEX_BASIC_INFO_COUNT, NULL); |
---|
196 | if (Status != 1) { |
---|
197 | SImsg(SIM_GERR, "cnx_sysinfo(CNX_IS_COMPLEX_BASIC_INFO) failed: %s", SYSERR); |
---|
198 | return((char *) NULL); |
---|
199 | } |
---|
200 | |
---|
201 | Num = Basic.cpu_cnt; |
---|
202 | if (Num < 1) { |
---|
203 | if (Debug) |
---|
204 | SImsg(SIM_GERR, "cnx_sysinfo(CNX_IS_COMPLEX_BASIC_INFO): Bad cpu count (%d)", |
---|
205 | Num); |
---|
206 | return((char *) NULL); |
---|
207 | } |
---|
208 | (void) snprintf(Buff, sizeof(Buff), "%d", Num); |
---|
209 | |
---|
210 | return(Buff); |
---|
211 | } |
---|
212 | |
---|
213 | /* |
---|
214 | * Get kernel version string using cnx_sysinfo() |
---|
215 | */ |
---|
216 | extern char *GetKernVerCnxSysinfo() |
---|
217 | { |
---|
218 | cnx_is_complex_vers_info_data_t |
---|
219 | Version; |
---|
220 | cnx_is_target_data_t Target; |
---|
221 | int Status; |
---|
222 | static char *VerString = NULL; |
---|
223 | char *cp; |
---|
224 | |
---|
225 | if (VerString) |
---|
226 | return(VerString); |
---|
227 | |
---|
228 | cnx_sysinfo_target_complex(&Target); |
---|
229 | Status = cnx_sysinfo(CNX_IS_COMPLEX_VERS_INFO, &Target, &Version, |
---|
230 | 1, CNX_IS_COMPLEX_VERS_INFO_COUNT, NULL); |
---|
231 | if (Status != 1) { |
---|
232 | SImsg(SIM_GERR, "cnx_sysinfo(CNX_IS_COMPLEX_VERS_INFO) failed: %s", SYSERR); |
---|
233 | return((char *) NULL); |
---|
234 | } |
---|
235 | |
---|
236 | cp = Version.server_version; |
---|
237 | if (cp && *cp) |
---|
238 | VerString = strdup(cp); |
---|
239 | else { |
---|
240 | if (Debug) |
---|
241 | SImsg(SIM_GERR, "cnx_sysinfo(CNX_IS_COMPLEX_VERS_INFO): No version string."); |
---|
242 | return((char *) NULL); |
---|
243 | } |
---|
244 | |
---|
245 | return(VerString); |
---|
246 | } |
---|
247 | |
---|
248 | /* |
---|
249 | * Get OS name using cnx_uname() |
---|
250 | */ |
---|
251 | extern char *GetOSNameCnxUname() |
---|
252 | { |
---|
253 | static struct utsname un; |
---|
254 | |
---|
255 | if (cnx_uname(&un) != 0) |
---|
256 | return((char *) NULL); |
---|
257 | |
---|
258 | return((un.sysname[0]) ? un.sysname : (char *) NULL); |
---|
259 | } |
---|
260 | |
---|
261 | /* |
---|
262 | * Get our OS name using cnx_sysinfo() |
---|
263 | */ |
---|
264 | extern char *GetOSNameCnxSysinfo() |
---|
265 | { |
---|
266 | static char OSName[100]; |
---|
267 | char *KernStr; |
---|
268 | register char *cp; |
---|
269 | |
---|
270 | if (OSName[0]) |
---|
271 | return(OSName); |
---|
272 | |
---|
273 | KernStr = GetKernVerCnxSysinfo(); |
---|
274 | if (!KernStr) |
---|
275 | return((char *) NULL); |
---|
276 | /* |
---|
277 | * Find the end of the first argument which should |
---|
278 | * be the OS name. |
---|
279 | */ |
---|
280 | cp = strchr(KernStr, '_'); |
---|
281 | if (!cp) { |
---|
282 | cp = strchr(KernStr, ' '); |
---|
283 | if (!cp) |
---|
284 | return((char *) NULL); |
---|
285 | } |
---|
286 | |
---|
287 | if (cp - KernStr > sizeof(OSName)) { |
---|
288 | SImsg(SIM_DBG, "GetOSNameCnx(): OSName buffer too small."); |
---|
289 | return((char *) NULL); |
---|
290 | } |
---|
291 | |
---|
292 | (void) strncpy(OSName, KernStr, cp - KernStr); |
---|
293 | OSName[cp - KernStr] = CNULL; |
---|
294 | |
---|
295 | return(OSName); |
---|
296 | } |
---|
297 | |
---|
298 | /* |
---|
299 | * Get our OS version using cnx_sysinfo() |
---|
300 | */ |
---|
301 | extern char *GetOSVerCnxSysinfo() |
---|
302 | { |
---|
303 | static char OSVer[100]; |
---|
304 | char *KernStr; |
---|
305 | register char *cp; |
---|
306 | |
---|
307 | if (OSVer[0]) |
---|
308 | return(OSVer); |
---|
309 | |
---|
310 | KernStr = GetKernVerCnxSysinfo(); |
---|
311 | if (!KernStr) |
---|
312 | return((char *) NULL); |
---|
313 | |
---|
314 | /* |
---|
315 | * Find the start of the version number |
---|
316 | */ |
---|
317 | while (KernStr && *KernStr && !isdigit(*KernStr)) |
---|
318 | ++KernStr; |
---|
319 | |
---|
320 | /* |
---|
321 | * Find the end of the first argument which should |
---|
322 | * be the OS name. |
---|
323 | */ |
---|
324 | cp = strchr(KernStr, ' '); |
---|
325 | if (!cp) |
---|
326 | return((char *) NULL); |
---|
327 | |
---|
328 | if (cp - KernStr > sizeof(OSVer)) { |
---|
329 | SImsg(SIM_DBG, "GetOSVerCnxSysinfo(): OSVer buffer too small."); |
---|
330 | return((char *) NULL); |
---|
331 | } |
---|
332 | |
---|
333 | (void) strncpy(OSVer, KernStr, cp - KernStr); |
---|
334 | OSVer[cp - KernStr] = CNULL; |
---|
335 | |
---|
336 | return(OSVer); |
---|
337 | } |
---|
338 | |
---|
339 | /* |
---|
340 | * Get amount of physical memory using cnx_sysinfo() |
---|
341 | */ |
---|
342 | extern char *GetMemoryCnxSysinfo() |
---|
343 | { |
---|
344 | cnx_is_complex_mem_info_data_t |
---|
345 | Mem; |
---|
346 | cnx_is_target_data_t Target; |
---|
347 | SYSINFO_LARGE_T Num; |
---|
348 | int Status; |
---|
349 | static char Buff[100]; |
---|
350 | |
---|
351 | cnx_sysinfo_target_complex(&Target); |
---|
352 | Status = cnx_sysinfo(CNX_IS_COMPLEX_MEM_INFO, &Target, &Mem, |
---|
353 | 1, CNX_IS_COMPLEX_MEM_INFO_COUNT, NULL); |
---|
354 | if (Status != 1) { |
---|
355 | SImsg(SIM_GERR, "cnx_sysinfo(CNX_IS_COMPLEX_MEM_INFO) failed: %s", SYSERR); |
---|
356 | return((char *) NULL); |
---|
357 | } |
---|
358 | |
---|
359 | Num = (SYSINFO_LARGE_T)Mem.total_memory; |
---|
360 | |
---|
361 | return(GetSizeStr(Num, BYTES)); |
---|
362 | } |
---|
363 | |
---|
364 | /* |
---|
365 | * Initialize the OS specific parts of the Device Types table |
---|
366 | */ |
---|
367 | void DevTypesInit() |
---|
368 | { |
---|
369 | #ifdef notdef |
---|
370 | register int i; |
---|
371 | |
---|
372 | for (i = 0; DevTypes[i].Name; ++i) |
---|
373 | switch (DevTypes[i].Type) { |
---|
374 | case DT_DISKDRIVE: DevTypes[i].Probe = ProbeDiskDrive; break; |
---|
375 | case DT_FRAMEBUFFER: DevTypes[i].Probe = ProbeFrameBuffer; break; |
---|
376 | case DT_KEYBOARD: DevTypes[i].Probe = ProbeKbd; break; |
---|
377 | case DT_NETIF: DevTypes[i].Probe = ProbeNetif; break; |
---|
378 | case DT_TAPEDRIVE: DevTypes[i].Probe = ProbeTapeDrive; break; |
---|
379 | #if defined(HAVE_OPENPROM) |
---|
380 | case DT_CPU: DevTypes[i].Probe = OBPprobeCPU; break; |
---|
381 | #endif /* HAVE_OPENPROM */ |
---|
382 | } |
---|
383 | #endif |
---|
384 | } |
---|