Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / libs / identify / idhardware.c
blob86d1824f83e866b5b6bf082748d52fcd8c1e951d
1 /*
2 * Copyright (c) 2010-2011 Matthias Rustler
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 * IN THE SOFTWARE.
22 * $Id$
25 #include <resources/processor.h>
27 #include <proto/utility.h>
28 #include <proto/processor.h>
30 #include <stdio.h>
31 #include <string.h>
33 #include "identify_intern.h"
34 #include "identify.h"
35 #include "locale.h"
37 #include <aros/debug.h>
39 static CONST_STRPTR handle_version(TEXT *buffer, Tag tag);
40 static CONST_STRPTR handle_size(TEXT *buffer, Tag tag);
41 static CONST_STRPTR handle_freq(TEXT *buffer, Tag tag);
42 static CONST_STRPTR handle_mhz(TEXT *buffer, Tag tag);
43 static CONST_STRPTR handle_number(TEXT *buffer, Tag tag);
44 static CONST_STRPTR handle_address(TEXT *buffer, Tag tag);
45 static CONST_STRPTR handle_hex(TEXT *buffer, Tag tag);
46 static CONST_STRPTR handle_avail(Tag tag, BOOL null4na);
47 static CONST_STRPTR handle_notavail(BOOL null4na);
49 /*****************************************************************************
51 NAME */
52 #include <proto/identify.h>
54 AROS_LH2(CONST_STRPTR, IdHardware,
56 /* SYNOPSIS */
57 AROS_LHA(ULONG , type , D0),
58 AROS_LHA(struct TagItem *, taglist, A0),
60 /* LOCATION */
61 struct IdentifyBaseIntern *, IdentifyBase, 6, Identify)
63 /* FUNCTION
64 Gets information about the current system environment. The result
65 is returned as read only string. This function is fully DraCo
66 compatible!
68 Once a information has been evaluated, it will be cached internally,
69 so changes will be ignored. Use IdHardwareUpdate() to clear the cache
70 contents.
72 INPUTS
73 Type -- (ULONG) Information type. These types are known:
75 IDHW_SYSTEM -- What system is used?
76 (e. g. "Amiga 4000")
78 IDHW_CPU -- What kind of CPU is available?
79 (e. g. "68060")
81 IDHW_FPU -- What kind of FPU is available?
82 (e. g. "68060")
84 IDHW_MMU -- What kind of MMU is available?
85 (e. g. "68060")
87 IDHW_OSVER -- What OS version is used?
88 (e.g. "V39.106")
90 IDHW_EXECVER -- What exec version is used?
91 (e.g. "V39.47")
93 IDHW_WBVER -- What WorkBench version is used?
94 (e.g. "V39.29")
96 IDHW_ROMSIZE -- Size of AmigaOS ROM
97 (e.g. "512KB")
99 IDHW_CHIPSET -- What Chipset is available?
100 (e.g. "AGA")
102 IDHW_GFXSYS -- What Graphic OS is used?
103 (e.g. "CyberGraphX")
105 IDHW_CHIPRAM -- Size of complete Chip RAM
106 (e.g. "~2.0MB")
108 IDHW_FASTRAM -- Size of complete Fast RAM
109 (e.g. "12.0MB")
111 IDHW_RAM -- Size of complete System RAM
112 (e.g. "~14.0MB")
114 IDHW_SETPATCHVER -- [V4] Version of current SetPatch
115 (e.g. "V40.14")
117 IDHW_AUDIOSYS -- [V5] What Audio OS is used?
118 (e.g. "AHI")
120 IDHW_OSNR -- [V5] What AmigaOS is used?
121 (e.g. "3.1")
123 IDHW_VMMCHIPRAM -- [V5] Size of virtual Chip RAM
124 (e.g. "0")
126 IDHW_VMMFASTRAM -- [V5] Size of virtual Fast RAM
127 (e.g. "40.0MB")
129 IDHW_VMMRAM -- [V5] Size of total virtual RAM
130 (e.g. "40.0MB")
132 IDHW_PLNCHIPRAM -- [V5] Size of non-virtual Chip RAM
133 (e.g. "2.0MB")
135 IDHW_PLNFASTRAM -- [V5] Size of non-virtual Fast RAM
136 (e.g. "12.0MB")
138 IDHW_PLNRAM -- [V5] Size of total non-virtual RAM
139 (e.g. "14.0MB")
141 IDHW_VBR -- [V6] Vector Base Register contents
142 (e.g. "0x0806C848")
144 IDHW_LASTALERT -- [V6] Last Alert code
145 (e.g. "80000003")
147 IDHW_VBLANKFREQ -- [V6] VBlank frequency (see execbase.h)
148 (e.g. "50 Hz")
150 IDHW_POWERFREQ -- [V6] Power supply frequency (see execbase.h)
151 (e.g. "50 Hz")
153 IDHW_ECLOCK -- [V6] System E clock frequency
154 (e.g. "709379 Hz")
156 IDHW_SLOWRAM -- [V6] A500/A2000 "Slow" RAM expansion
157 (e.g. "512.0KB")
159 IDHW_GARY -- [V6] GARY revision
160 (e.g. "Normal")
162 IDHW_RAMSEY -- [V6] RAMSEY revision
163 (e.g. "F")
165 IDHW_BATTCLOCK -- [V6] Battery backed up clock present?
166 (e.g. "Found")
168 IDHW_CHUNKYPLANAR -- [V7] Chunky to planar hardware present?
169 (e.g. "Found")
171 IDHW_POWERPC -- [V7] PowerPC CPU present?
172 (e.g. "603e")
174 IDHW_PPCCLOCK -- [V7] PowerPC processor clock
175 (e.g. "200 MHz")
177 IDHW_CPUREV -- [V8] Revision of the main processor, if
178 available (e.g. "Rev 1")
180 IDHW_CPUCLOCK -- [V8] CPU clock
181 (e.g. "50 MHz")
183 IDHW_FPUCLOCK -- [V8] FPU clock, if available
184 (e.g. "50 MHz")
186 IDHW_RAMACCESS -- [V8] Access time of the main board RAM
187 (e.g. "80 ns")
189 IDHW_RAMWIDTH -- [V8] Width of the main board RAM
190 (e.g. "16 bit")
192 IDHW_RAMCAS -- [V8] CAS mode of the main board RAM
193 (e.g. "Double")
195 IDHW_RAMBANDWIDTH -- [V8] Bandwidth of the main board RAM
196 (e.g. "2")
198 IDHW_TCPIP -- [V9] Used TCP/IP stack
199 (e.g. "AmiTCP/IP")
201 IDHW_PPCOS -- [V9] Used PowerPC OS
202 (e.g. "PowerUp")
204 IDHW_AGNUS -- [V9] Agnus chip type and revision
205 (e.g. "Alice 8374 Rev. 3-4")
207 IDHW_AGNUSMODE -- [V9] Agnus chip mode
208 (e.g. "PAL")
210 IDHW_DENISE -- [V10] Denise chip type
211 (e.g. "Lisa 8364")
213 IDHW_DENISEREV -- [V10] Denise chip revision
214 (e.g. "0")
216 TagList -- (struct TagItem *) tags that describe further
217 options. You may provide NULL.
219 TAGS
220 IDTAG_Localize -- [V8] (BOOL) FALSE to get English strings
221 only, TRUE for localized strings. This is useful for applications
222 with English as only language. Defaults to TRUE.
224 IDTAG_NULL4NA -- [V8] (BOOL) TRUE to get NULL pointer instead
225 of a 'not available' string. Defaults to FALSE.
227 RESULT
228 String -- (STRPTR) String containing the desired
229 information, or NULL if not available. Note that
230 all strings are READ ONLY!
232 NOTES
233 Some results are nonsense on AROS.
235 EXAMPLE
237 BUGS
239 SEE ALSO
240 IdHardwareNum(), IdHardwareUpdate()
242 INTERNALS
244 HISTORY
247 *****************************************************************************/
249 AROS_LIBFUNC_INIT
251 struct TagItem *tag;
252 struct TagItem *tags;
254 CONST_STRPTR result = NULL;
255 BOOL null4na = FALSE;
256 BOOL localize = TRUE;
258 for (tags = taglist; (tag = NextTagItem(&tags)); )
260 switch (tag->ti_Tag)
262 case IDTAG_NULL4NA:
263 null4na = tag->ti_Data ? TRUE : FALSE;
264 break;
266 case IDTAG_Localize:
267 localize = tag->ti_Data ? TRUE : FALSE;
268 break;
272 if (localize) {
273 /* FIXME: Do something here? */
276 ObtainSemaphore(&IdentifyBase->sem);
278 switch(type)
280 case IDHW_SYSTEM:
281 result = "AROS";
282 break;
284 case IDHW_CPU:
286 IPTR cpu = 0;
287 APTR ProcessorBase = OpenResource(PROCESSORNAME);
289 if (ProcessorBase)
291 struct TagItem tags [] =
293 { GCIT_Family, (IPTR)&cpu },
294 { TAG_DONE }
296 GetCPUInfo(tags);
297 switch(cpu)
299 case CPUFAMILY_60X: result = "60X"; break;
300 case CPUFAMILY_7X0: result = "7X0"; break;
301 case CPUFAMILY_74XX: result = "74XX"; break;
302 case CPUFAMILY_4XX: result = "4XX"; break;
303 case CPUFAMILY_AMD_K5: result = "AMD_K5"; break;
304 case CPUFAMILY_AMD_K6: result = "AMD_K6"; break;
305 case CPUFAMILY_AMD_K7: result = "AMD_K7"; break;
306 case CPUFAMILY_AMD_K8: result = "AMD_K8"; break;
307 case CPUFAMILY_AMD_K9: result = "ADM_K9"; break;
308 case CPUFAMILY_AMD_K10: result = "AMD_K10"; break;
309 case CPUFAMILY_INTEL_486: result = "INTEL_486"; break;
310 case CPUFAMILY_INTEL_PENTIUM: result = "INTEL_PENTIUM"; break;
311 case CPUFAMILY_INTEL_PENTIUM_PRO: result = "INTEL_PENTIUM_PRO"; break;
312 case CPUFAMILY_INTEL_PENTIUM4: result = "INTEL_PENTIUM4"; break;
313 case CPUFAMILY_MOTOROLA_68000: result = "MOTOROLA_68000"; break;
314 default: result = "unknown"; break;
317 else
319 result = "unknown";
321 break;
323 case IDHW_FPU:
324 result = handle_notavail(null4na);
325 break;
327 case IDHW_MMU:
328 result = handle_notavail(null4na);
329 break;
331 case IDHW_OSVER:
332 result = handle_version(IdentifyBase->hwb.buf_OsVer, IDHW_OSVER);
333 break;
335 case IDHW_EXECVER:
336 result = handle_version(IdentifyBase->hwb.buf_ExecVer, IDHW_EXECVER);
337 break;
339 case IDHW_WBVER:
340 result = handle_version(IdentifyBase->hwb.buf_WbVer, IDHW_WBVER);
341 break;
343 case IDHW_ROMSIZE:
344 result = handle_size(IdentifyBase->hwb.buf_RomSize, IDHW_ROMSIZE);
345 break;
347 case IDHW_CHIPSET:
348 result = _(MSG_HW_OCS);
349 break;
351 case IDHW_GFXSYS:
352 result = _(MSG_HW_CYBERGRAPHX);
353 break;
355 case IDHW_CHIPRAM:
356 result = handle_size(IdentifyBase->hwb.buf_ChipRAM, IDHW_CHIPRAM);
357 break;
359 case IDHW_FASTRAM:
360 result = handle_size(IdentifyBase->hwb.buf_FastRAM, IDHW_FASTRAM);
361 break;
363 case IDHW_RAM:
364 result = handle_size(IdentifyBase->hwb.buf_RAM, IDHW_RAM);
365 break;
367 case IDHW_SETPATCHVER:
368 result = handle_version(IdentifyBase->hwb.buf_SetPatchVer, IDHW_SETPATCHVER);
369 break;
371 case IDHW_AUDIOSYS:
372 result = _(MSG_HW_AHI);
373 break;
375 case IDHW_OSNR:
376 result = _(MSG_HW_OS_40);
377 break;
379 case IDHW_VMMCHIPRAM:
380 result = "0";
381 break;
383 case IDHW_VMMFASTRAM:
384 result = "0";
385 break;
387 case IDHW_VMMRAM:
388 result = "0";
389 break;
391 case IDHW_PLNCHIPRAM:
392 result = handle_size(IdentifyBase->hwb.buf_PlainChipRAM, IDHW_PLNCHIPRAM);
393 break;
395 case IDHW_PLNFASTRAM:
396 result = handle_size(IdentifyBase->hwb.buf_PlainFastRAM, IDHW_PLNFASTRAM);
397 break;
399 case IDHW_PLNRAM:
400 result = handle_size(IdentifyBase->hwb.buf_PlainRAM, IDHW_PLNRAM);
401 break;
403 case IDHW_VBR:
404 IdentifyBase->hwb.buf_VBR[0] = '\0'; // not buffered
405 result = handle_address(IdentifyBase->hwb.buf_VBR, IDHW_VBR);
406 break;
408 case IDHW_LASTALERT:
409 IdentifyBase->hwb.buf_LastAlert[0] = '\0'; // not buffered
410 result = handle_hex(IdentifyBase->hwb.buf_LastAlert, IDHW_LASTALERT);
411 break;
413 case IDHW_VBLANKFREQ:
414 result = handle_freq(IdentifyBase->hwb.buf_VBlankFreq, IDHW_VBLANKFREQ);
415 break;
417 case IDHW_POWERFREQ:
418 result = handle_freq(IdentifyBase->hwb.buf_PowerFreq, IDHW_POWERFREQ);
419 break;
421 case IDHW_ECLOCK:
422 result = handle_freq(IdentifyBase->hwb.buf_EClock, IDHW_ECLOCK);
423 break;
425 case IDHW_SLOWRAM:
426 result = handle_size(IdentifyBase->hwb.buf_SlowRAM, IDHW_SLOWRAM);
427 break;
429 case IDHW_GARY:
430 result = handle_notavail(null4na);
431 break;
433 case IDHW_RAMSEY:
434 result = handle_notavail(null4na);
435 break;
437 case IDHW_BATTCLOCK:
438 result = handle_avail(IDHW_BATTCLOCK, null4na);
439 break;
441 case IDHW_CHUNKYPLANAR:
442 result = handle_avail(IDHW_CHUNKYPLANAR, null4na);
443 break;
445 case IDHW_POWERPC:
446 result = handle_notavail(null4na);
447 break;
449 case IDHW_PPCCLOCK:
450 result = "0 MHz";
451 break;
453 case IDHW_CPUREV:
454 result = handle_notavail(null4na);
455 break;
457 case IDHW_CPUCLOCK:
458 result = handle_mhz(IdentifyBase->hwb.buf_CPUClock, IDHW_CPUCLOCK);
459 break;
461 case IDHW_FPUCLOCK:
462 result = "0 MHz";
463 break;
465 case IDHW_RAMACCESS:
466 result = handle_notavail(null4na);
467 break;
469 case IDHW_RAMWIDTH:
470 result = handle_number(IdentifyBase->hwb.buf_RAMWidth, IDHW_RAMWIDTH);
471 break;
473 case IDHW_RAMCAS:
475 ULONG num = IdHardwareNum(IDHW_RAMCAS, NULL);
476 if (num == 2)
478 result = _(MSG_HW_RAMCAS_DOUBLE);
480 else
482 result = _(MSG_HW_RAMCAS_NORMAL);
484 break;
487 case IDHW_RAMBANDWIDTH:
488 result = handle_notavail(null4na);
489 break;
491 case IDHW_TCPIP:
492 result = _(MSG_HW_TCPIP_AMITCP);
493 break;
495 case IDHW_PPCOS:
496 result = _(MSG_HW_PPCOS_NONE);
497 break;
499 case IDHW_AGNUS:
500 result = _(MSG_HW_AGNUS_NONE);
501 break;
503 case IDHW_AGNUSMODE:
504 result = _(MSG_HW_AMODE_NONE);
505 break;
507 case IDHW_DENISE:
508 result = _(MSG_HW_DENISE_NONE);
509 break;
511 case IDHW_DENISEREV:
512 result = handle_notavail(null4na);
513 break;
515 default:
516 result = handle_notavail(null4na);
517 break;
520 ReleaseSemaphore(&IdentifyBase->sem);
522 return result;
524 AROS_LIBFUNC_EXIT
525 } /* IdHardware */
528 static CONST_STRPTR handle_version(TEXT *buffer, Tag tag)
530 CONST_STRPTR result = buffer;
531 if (*buffer == '\0')
533 ULONG num = IdHardwareNum(tag, NULL);
534 if (num != 0 && num != -1)
536 ULONG version = num & 0xffff;
537 ULONG revision = num >> 16;
538 snprintf(buffer, STRBUFSIZE, _(MSG_HW_VERSION), version, revision);
540 else
542 strlcpy(buffer, _(MSG_HW_NOVERSION), STRBUFSIZE);
545 return result;
548 static CONST_STRPTR handle_size(TEXT *buffer, Tag tag)
550 CONST_STRPTR result = buffer;
551 CONST_STRPTR format;
552 UBYTE fraction = 0;
554 if (*buffer == '\0')
556 UQUAD num = IdHardwareNum(tag, NULL);
557 if (num < 1000)
559 num *= 10;
560 format = _(MSG_BYTE);
562 else if (num < 1000 * 1000)
564 num /= 102;
565 format = _(MSG_KBYTE);
567 else if (num < 1000 * 1000 * 1000)
569 num = num / 1024 / 102;
570 format = _(MSG_MBYTE);
572 else
574 num = num / 1024 / 1024 / 102;
575 format = _(MSG_GBYTE);
577 fraction = num % 10;
578 num /= 10;
580 snprintf(buffer, STRBUFSIZE, format,
581 (long unsigned int)num, '0' + fraction);
583 return result;
586 static CONST_STRPTR handle_freq(TEXT *buffer, Tag tag)
588 CONST_STRPTR result = buffer;
589 if (*buffer == '\0')
591 ULONG num = IdHardwareNum(tag, NULL);
593 snprintf(buffer, STRBUFSIZE, "%u Hz", (unsigned int)num);
596 return result;
599 static CONST_STRPTR handle_mhz(TEXT *buffer, Tag tag)
601 CONST_STRPTR result = buffer;
602 if (*buffer == '\0')
604 ULONG num = IdHardwareNum(tag, NULL);
606 snprintf(buffer, STRBUFSIZE, "%u MHz", (unsigned int)num);
609 return result;
612 static CONST_STRPTR handle_number(TEXT *buffer, Tag tag)
614 CONST_STRPTR result = buffer;
615 if (*buffer == '\0')
617 ULONG num = IdHardwareNum(tag, NULL);
619 snprintf(buffer, STRBUFSIZE, "%u", (unsigned int)num);
622 return result;
625 static CONST_STRPTR handle_address(TEXT *buffer, Tag tag)
627 CONST_STRPTR result = buffer;
628 if (*buffer == '\0')
630 ULONG num = IdHardwareNum(tag, NULL);
632 snprintf(buffer, STRBUFSIZE, "0x%08x", (unsigned int)num);
635 return result;
638 static CONST_STRPTR handle_hex(TEXT *buffer, Tag tag)
640 CONST_STRPTR result = buffer;
641 if (*buffer == '\0')
643 ULONG num = IdHardwareNum(tag, NULL);
645 snprintf(buffer, STRBUFSIZE, "%08x", (unsigned int)num);
648 return result;
651 static CONST_STRPTR handle_avail(Tag tag, BOOL null4na)
653 ULONG num = IdHardwareNum(tag, NULL);
654 if (num)
656 return _(MSG_HW_FOUND);
658 else
660 return handle_notavail(null4na);
664 static CONST_STRPTR handle_notavail(BOOL null4na)
666 if (null4na == FALSE)
667 return _(MSG_HW_NONE);
668 else
669 return NULL;