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
25 #include <resources/processor.h>
27 #include <proto/utility.h>
28 #include <proto/processor.h>
29 #include <clib/alib_protos.h>
34 #include "identify_intern.h"
38 #include <aros/debug.h>
40 static CONST_STRPTR
handle_version(TEXT
*buffer
, Tag tag
);
41 static CONST_STRPTR
handle_size(TEXT
*buffer
, Tag tag
);
42 static CONST_STRPTR
handle_freq(TEXT
*buffer
, Tag tag
);
43 static CONST_STRPTR
handle_mhz(TEXT
*buffer
, Tag tag
);
44 static CONST_STRPTR
handle_number(TEXT
*buffer
, Tag tag
);
45 static CONST_STRPTR
handle_address(TEXT
*buffer
, Tag tag
);
46 static CONST_STRPTR
handle_hex(TEXT
*buffer
, Tag tag
);
47 static CONST_STRPTR
handle_avail(Tag tag
, BOOL null4na
);
48 static CONST_STRPTR
handle_notavail(BOOL null4na
);
50 /*****************************************************************************
53 #include <proto/identify.h>
55 AROS_LH2(CONST_STRPTR
, IdHardware
,
58 AROS_LHA(ULONG
, type
, D0
),
59 AROS_LHA(struct TagItem
*, taglist
, A0
),
62 struct IdentifyBaseIntern
*, IdentifyBase
, 6, Identify
)
65 Gets information about the current system environment. The result
66 is returned as read only string. This function is fully DraCo
69 Once a information has been evaluated, it will be cached internally,
70 so changes will be ignored. Use IdHardwareUpdate() to clear the cache
74 Type -- (ULONG) Information type. These types are known:
76 IDHW_SYSTEM -- What system is used?
79 IDHW_CPU -- What kind of CPU is available?
82 IDHW_FPU -- What kind of FPU is available?
85 IDHW_MMU -- What kind of MMU is available?
88 IDHW_OSVER -- What OS version is used?
91 IDHW_EXECVER -- What exec version is used?
94 IDHW_WBVER -- What WorkBench version is used?
97 IDHW_ROMSIZE -- Size of AmigaOS ROM
100 IDHW_CHIPSET -- What Chipset is available?
103 IDHW_GFXSYS -- What Graphic OS is used?
106 IDHW_CHIPRAM -- Size of complete Chip RAM
109 IDHW_FASTRAM -- Size of complete Fast RAM
112 IDHW_RAM -- Size of complete System RAM
115 IDHW_SETPATCHVER -- [V4] Version of current SetPatch
118 IDHW_AUDIOSYS -- [V5] What Audio OS is used?
121 IDHW_OSNR -- [V5] What AmigaOS is used?
124 IDHW_VMMCHIPRAM -- [V5] Size of virtual Chip RAM
127 IDHW_VMMFASTRAM -- [V5] Size of virtual Fast RAM
130 IDHW_VMMRAM -- [V5] Size of total virtual RAM
133 IDHW_PLNCHIPRAM -- [V5] Size of non-virtual Chip RAM
136 IDHW_PLNFASTRAM -- [V5] Size of non-virtual Fast RAM
139 IDHW_PLNRAM -- [V5] Size of total non-virtual RAM
142 IDHW_VBR -- [V6] Vector Base Register contents
145 IDHW_LASTALERT -- [V6] Last Alert code
148 IDHW_VBLANKFREQ -- [V6] VBlank frequency (see execbase.h)
151 IDHW_POWERFREQ -- [V6] Power supply frequency (see execbase.h)
154 IDHW_ECLOCK -- [V6] System E clock frequency
157 IDHW_SLOWRAM -- [V6] A500/A2000 "Slow" RAM expansion
160 IDHW_GARY -- [V6] GARY revision
163 IDHW_RAMSEY -- [V6] RAMSEY revision
166 IDHW_BATTCLOCK -- [V6] Battery backed up clock present?
169 IDHW_CHUNKYPLANAR -- [V7] Chunky to planar hardware present?
172 IDHW_POWERPC -- [V7] PowerPC CPU present?
175 IDHW_PPCCLOCK -- [V7] PowerPC processor clock
178 IDHW_CPUREV -- [V8] Revision of the main processor, if
179 available (e.g. "Rev 1")
181 IDHW_CPUCLOCK -- [V8] CPU clock
184 IDHW_FPUCLOCK -- [V8] FPU clock, if available
187 IDHW_RAMACCESS -- [V8] Access time of the main board RAM
190 IDHW_RAMWIDTH -- [V8] Width of the main board RAM
193 IDHW_RAMCAS -- [V8] CAS mode of the main board RAM
196 IDHW_RAMBANDWIDTH -- [V8] Bandwidth of the main board RAM
199 IDHW_TCPIP -- [V9] Used TCP/IP stack
202 IDHW_PPCOS -- [V9] Used PowerPC OS
205 IDHW_AGNUS -- [V9] Agnus chip type and revision
206 (e.g. "Alice 8374 Rev. 3-4")
208 IDHW_AGNUSMODE -- [V9] Agnus chip mode
211 IDHW_DENISE -- [V10] Denise chip type
214 IDHW_DENISEREV -- [V10] Denise chip revision
217 TagList -- (struct TagItem *) tags that describe further
218 options. You may provide NULL.
221 IDTAG_Localize -- [V8] (BOOL) FALSE to get English strings
222 only, TRUE for localized strings. This is useful for applications
223 with English as only language. Defaults to TRUE.
225 IDTAG_NULL4NA -- [V8] (BOOL) TRUE to get NULL pointer instead
226 of a 'not available' string. Defaults to FALSE.
229 String -- (STRPTR) String containing the desired
230 information, or NULL if not available. Note that
231 all strings are READ ONLY!
234 Some results are nonsense on AROS.
241 IdHardwareNum(), IdHardwareUpdate()
248 *****************************************************************************/
253 struct TagItem
*tags
;
255 CONST_STRPTR result
= NULL
;
256 BOOL null4na
= FALSE
;
257 BOOL localize
= TRUE
;
259 for (tags
= taglist
; (tag
= NextTagItem(&tags
)); )
264 null4na
= tag
->ti_Data
? TRUE
: FALSE
;
268 localize
= tag
->ti_Data
? TRUE
: FALSE
;
274 /* FIXME: Do something here? */
277 ObtainSemaphore(&IdentifyBase
->sem
);
288 APTR ProcessorBase
= OpenResource(PROCESSORNAME
);
292 struct TagItem tags
[] =
294 { GCIT_Family
, (IPTR
)&cpu
},
300 case CPUFAMILY_60X
: result
= "60X"; break;
301 case CPUFAMILY_7X0
: result
= "7X0"; break;
302 case CPUFAMILY_74XX
: result
= "74XX"; break;
303 case CPUFAMILY_4XX
: result
= "4XX"; break;
304 case CPUFAMILY_AMD_K5
: result
= "AMD_K5"; break;
305 case CPUFAMILY_AMD_K6
: result
= "AMD_K6"; break;
306 case CPUFAMILY_AMD_K7
: result
= "AMD_K7"; break;
307 case CPUFAMILY_AMD_K8
: result
= "AMD_K8"; break;
308 case CPUFAMILY_AMD_K9
: result
= "ADM_K9"; break;
309 case CPUFAMILY_AMD_K10
: result
= "AMD_K10"; break;
310 case CPUFAMILY_INTEL_486
: result
= "INTEL_486"; break;
311 case CPUFAMILY_INTEL_PENTIUM
: result
= "INTEL_PENTIUM"; break;
312 case CPUFAMILY_INTEL_PENTIUM_PRO
: result
= "INTEL_PENTIUM_PRO"; break;
313 case CPUFAMILY_INTEL_PENTIUM4
: result
= "INTEL_PENTIUM4"; break;
314 case CPUFAMILY_MOTOROLA_68000
: result
= "MOTOROLA_68000"; break;
315 default: result
= "unknown"; break;
325 result
= handle_notavail(null4na
);
329 result
= handle_notavail(null4na
);
333 result
= handle_version(IdentifyBase
->hwb
.buf_OsVer
, IDHW_OSVER
);
337 result
= handle_version(IdentifyBase
->hwb
.buf_ExecVer
, IDHW_EXECVER
);
341 result
= handle_version(IdentifyBase
->hwb
.buf_WbVer
, IDHW_WBVER
);
345 result
= handle_size(IdentifyBase
->hwb
.buf_RomSize
, IDHW_ROMSIZE
);
349 result
= _(MSG_HW_OCS
);
353 result
= _(MSG_HW_CYBERGRAPHX
);
357 result
= handle_size(IdentifyBase
->hwb
.buf_ChipRAM
, IDHW_CHIPRAM
);
361 result
= handle_size(IdentifyBase
->hwb
.buf_FastRAM
, IDHW_FASTRAM
);
365 result
= handle_size(IdentifyBase
->hwb
.buf_RAM
, IDHW_RAM
);
368 case IDHW_SETPATCHVER
:
369 result
= handle_version(IdentifyBase
->hwb
.buf_SetPatchVer
, IDHW_SETPATCHVER
);
373 result
= _(MSG_HW_AHI
);
377 result
= _(MSG_HW_OS_40
);
380 case IDHW_VMMCHIPRAM
:
384 case IDHW_VMMFASTRAM
:
392 case IDHW_PLNCHIPRAM
:
393 result
= handle_size(IdentifyBase
->hwb
.buf_PlainChipRAM
, IDHW_PLNCHIPRAM
);
396 case IDHW_PLNFASTRAM
:
397 result
= handle_size(IdentifyBase
->hwb
.buf_PlainFastRAM
, IDHW_PLNFASTRAM
);
401 result
= handle_size(IdentifyBase
->hwb
.buf_PlainRAM
, IDHW_PLNRAM
);
405 IdentifyBase
->hwb
.buf_VBR
[0] = '\0'; // not buffered
406 result
= handle_address(IdentifyBase
->hwb
.buf_VBR
, IDHW_VBR
);
410 IdentifyBase
->hwb
.buf_LastAlert
[0] = '\0'; // not buffered
411 result
= handle_hex(IdentifyBase
->hwb
.buf_LastAlert
, IDHW_LASTALERT
);
414 case IDHW_VBLANKFREQ
:
415 result
= handle_freq(IdentifyBase
->hwb
.buf_VBlankFreq
, IDHW_VBLANKFREQ
);
419 result
= handle_freq(IdentifyBase
->hwb
.buf_PowerFreq
, IDHW_POWERFREQ
);
423 result
= handle_freq(IdentifyBase
->hwb
.buf_EClock
, IDHW_ECLOCK
);
427 result
= handle_size(IdentifyBase
->hwb
.buf_SlowRAM
, IDHW_SLOWRAM
);
431 result
= handle_notavail(null4na
);
435 result
= handle_notavail(null4na
);
439 result
= handle_avail(IDHW_BATTCLOCK
, null4na
);
442 case IDHW_CHUNKYPLANAR
:
443 result
= handle_avail(IDHW_CHUNKYPLANAR
, null4na
);
447 result
= handle_notavail(null4na
);
455 result
= handle_notavail(null4na
);
459 result
= handle_mhz(IdentifyBase
->hwb
.buf_CPUClock
, IDHW_CPUCLOCK
);
467 result
= handle_notavail(null4na
);
471 result
= handle_number(IdentifyBase
->hwb
.buf_RAMWidth
, IDHW_RAMWIDTH
);
476 ULONG num
= IdHardwareNum(IDHW_RAMCAS
, NULL
);
479 result
= _(MSG_HW_RAMCAS_DOUBLE
);
483 result
= _(MSG_HW_RAMCAS_NORMAL
);
488 case IDHW_RAMBANDWIDTH
:
489 result
= handle_notavail(null4na
);
493 result
= _(MSG_HW_TCPIP_AMITCP
);
497 result
= _(MSG_HW_PPCOS_NONE
);
501 result
= _(MSG_HW_AGNUS_NONE
);
505 result
= _(MSG_HW_AMODE_NONE
);
509 result
= _(MSG_HW_DENISE_NONE
);
513 result
= handle_notavail(null4na
);
517 result
= handle_notavail(null4na
);
521 ReleaseSemaphore(&IdentifyBase
->sem
);
529 static CONST_STRPTR
handle_version(TEXT
*buffer
, Tag tag
)
531 CONST_STRPTR result
= buffer
;
534 ULONG num
= IdHardwareNum(tag
, NULL
);
535 if (num
!= 0 && num
!= -1)
537 ULONG version
= num
& 0xffff;
538 ULONG revision
= num
>> 16;
539 snprintf(buffer
, STRBUFSIZE
, _(MSG_HW_VERSION
), version
, revision
);
543 strlcpy(buffer
, _(MSG_HW_NOVERSION
), STRBUFSIZE
);
549 static CONST_STRPTR
handle_size(TEXT
*buffer
, Tag tag
)
551 CONST_STRPTR result
= buffer
;
557 UQUAD num
= IdHardwareNum(tag
, NULL
);
561 format
= _(MSG_BYTE
);
563 else if (num
< 1000 * 1000)
566 format
= _(MSG_KBYTE
);
568 else if (num
< 1000 * 1000 * 1000)
570 num
= num
/ 1024 / 102;
571 format
= _(MSG_MBYTE
);
575 num
= num
/ 1024 / 1024 / 102;
576 format
= _(MSG_GBYTE
);
581 snprintf(buffer
, STRBUFSIZE
, format
,
582 (long unsigned int)num
, '0' + fraction
);
587 static CONST_STRPTR
handle_freq(TEXT
*buffer
, Tag tag
)
589 CONST_STRPTR result
= buffer
;
592 ULONG num
= IdHardwareNum(tag
, NULL
);
594 snprintf(buffer
, STRBUFSIZE
, "%u Hz", (unsigned int)num
);
600 static CONST_STRPTR
handle_mhz(TEXT
*buffer
, Tag tag
)
602 CONST_STRPTR result
= buffer
;
605 ULONG num
= IdHardwareNum(tag
, NULL
);
607 snprintf(buffer
, STRBUFSIZE
, "%u MHz", (unsigned int)num
);
613 static CONST_STRPTR
handle_number(TEXT
*buffer
, Tag tag
)
615 CONST_STRPTR result
= buffer
;
618 ULONG num
= IdHardwareNum(tag
, NULL
);
620 snprintf(buffer
, STRBUFSIZE
, "%u", (unsigned int)num
);
626 static CONST_STRPTR
handle_address(TEXT
*buffer
, Tag tag
)
628 CONST_STRPTR result
= buffer
;
631 ULONG num
= IdHardwareNum(tag
, NULL
);
633 snprintf(buffer
, STRBUFSIZE
, "0x%08x", (unsigned int)num
);
639 static CONST_STRPTR
handle_hex(TEXT
*buffer
, Tag tag
)
641 CONST_STRPTR result
= buffer
;
644 ULONG num
= IdHardwareNum(tag
, NULL
);
646 snprintf(buffer
, STRBUFSIZE
, "%08x", (unsigned int)num
);
652 static CONST_STRPTR
handle_avail(Tag tag
, BOOL null4na
)
654 ULONG num
= IdHardwareNum(tag
, NULL
);
657 return _(MSG_HW_FOUND
);
661 return handle_notavail(null4na
);
665 static CONST_STRPTR
handle_notavail(BOOL null4na
)
667 if (null4na
== FALSE
)
668 return _(MSG_HW_NONE
);