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>
33 #include "identify_intern.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 /*****************************************************************************
52 #include <proto/identify.h>
54 AROS_LH2(CONST_STRPTR
, IdHardware
,
57 AROS_LHA(ULONG
, type
, D0
),
58 AROS_LHA(struct TagItem
*, taglist
, A0
),
61 struct IdentifyBaseIntern
*, IdentifyBase
, 6, Identify
)
64 Gets information about the current system environment. The result
65 is returned as read only string. This function is fully DraCo
68 Once a information has been evaluated, it will be cached internally,
69 so changes will be ignored. Use IdHardwareUpdate() to clear the cache
73 Type -- (ULONG) Information type. These types are known:
75 IDHW_SYSTEM -- What system is used?
78 IDHW_CPU -- What kind of CPU is available?
81 IDHW_FPU -- What kind of FPU is available?
84 IDHW_MMU -- What kind of MMU is available?
87 IDHW_OSVER -- What OS version is used?
90 IDHW_EXECVER -- What exec version is used?
93 IDHW_WBVER -- What WorkBench version is used?
96 IDHW_ROMSIZE -- Size of AmigaOS ROM
99 IDHW_CHIPSET -- What Chipset is available?
102 IDHW_GFXSYS -- What Graphic OS is used?
105 IDHW_CHIPRAM -- Size of complete Chip RAM
108 IDHW_FASTRAM -- Size of complete Fast RAM
111 IDHW_RAM -- Size of complete System RAM
114 IDHW_SETPATCHVER -- [V4] Version of current SetPatch
117 IDHW_AUDIOSYS -- [V5] What Audio OS is used?
120 IDHW_OSNR -- [V5] What AmigaOS is used?
123 IDHW_VMMCHIPRAM -- [V5] Size of virtual Chip RAM
126 IDHW_VMMFASTRAM -- [V5] Size of virtual Fast RAM
129 IDHW_VMMRAM -- [V5] Size of total virtual RAM
132 IDHW_PLNCHIPRAM -- [V5] Size of non-virtual Chip RAM
135 IDHW_PLNFASTRAM -- [V5] Size of non-virtual Fast RAM
138 IDHW_PLNRAM -- [V5] Size of total non-virtual RAM
141 IDHW_VBR -- [V6] Vector Base Register contents
144 IDHW_LASTALERT -- [V6] Last Alert code
147 IDHW_VBLANKFREQ -- [V6] VBlank frequency (see execbase.h)
150 IDHW_POWERFREQ -- [V6] Power supply frequency (see execbase.h)
153 IDHW_ECLOCK -- [V6] System E clock frequency
156 IDHW_SLOWRAM -- [V6] A500/A2000 "Slow" RAM expansion
159 IDHW_GARY -- [V6] GARY revision
162 IDHW_RAMSEY -- [V6] RAMSEY revision
165 IDHW_BATTCLOCK -- [V6] Battery backed up clock present?
168 IDHW_CHUNKYPLANAR -- [V7] Chunky to planar hardware present?
171 IDHW_POWERPC -- [V7] PowerPC CPU present?
174 IDHW_PPCCLOCK -- [V7] PowerPC processor clock
177 IDHW_CPUREV -- [V8] Revision of the main processor, if
178 available (e.g. "Rev 1")
180 IDHW_CPUCLOCK -- [V8] CPU clock
183 IDHW_FPUCLOCK -- [V8] FPU clock, if available
186 IDHW_RAMACCESS -- [V8] Access time of the main board RAM
189 IDHW_RAMWIDTH -- [V8] Width of the main board RAM
192 IDHW_RAMCAS -- [V8] CAS mode of the main board RAM
195 IDHW_RAMBANDWIDTH -- [V8] Bandwidth of the main board RAM
198 IDHW_TCPIP -- [V9] Used TCP/IP stack
201 IDHW_PPCOS -- [V9] Used PowerPC OS
204 IDHW_AGNUS -- [V9] Agnus chip type and revision
205 (e.g. "Alice 8374 Rev. 3-4")
207 IDHW_AGNUSMODE -- [V9] Agnus chip mode
210 IDHW_DENISE -- [V10] Denise chip type
213 IDHW_DENISEREV -- [V10] Denise chip revision
216 TagList -- (struct TagItem *) tags that describe further
217 options. You may provide NULL.
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.
228 String -- (STRPTR) String containing the desired
229 information, or NULL if not available. Note that
230 all strings are READ ONLY!
233 Some results are nonsense on AROS.
240 IdHardwareNum(), IdHardwareUpdate()
247 *****************************************************************************/
252 struct TagItem
*tags
;
254 CONST_STRPTR result
= NULL
;
255 BOOL null4na
= FALSE
;
256 BOOL localize
= TRUE
;
258 for (tags
= taglist
; (tag
= NextTagItem(&tags
)); )
263 null4na
= tag
->ti_Data
? TRUE
: FALSE
;
267 localize
= tag
->ti_Data
? TRUE
: FALSE
;
273 /* FIXME: Do something here? */
276 ObtainSemaphore(&IdentifyBase
->sem
);
287 APTR ProcessorBase
= OpenResource(PROCESSORNAME
);
291 struct TagItem tags
[] =
293 { GCIT_Family
, (IPTR
)&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;
324 result
= handle_notavail(null4na
);
328 result
= handle_notavail(null4na
);
332 result
= handle_version(IdentifyBase
->hwb
.buf_OsVer
, IDHW_OSVER
);
336 result
= handle_version(IdentifyBase
->hwb
.buf_ExecVer
, IDHW_EXECVER
);
340 result
= handle_version(IdentifyBase
->hwb
.buf_WbVer
, IDHW_WBVER
);
344 result
= handle_size(IdentifyBase
->hwb
.buf_RomSize
, IDHW_ROMSIZE
);
348 result
= _(MSG_HW_OCS
);
352 result
= _(MSG_HW_CYBERGRAPHX
);
356 result
= handle_size(IdentifyBase
->hwb
.buf_ChipRAM
, IDHW_CHIPRAM
);
360 result
= handle_size(IdentifyBase
->hwb
.buf_FastRAM
, IDHW_FASTRAM
);
364 result
= handle_size(IdentifyBase
->hwb
.buf_RAM
, IDHW_RAM
);
367 case IDHW_SETPATCHVER
:
368 result
= handle_version(IdentifyBase
->hwb
.buf_SetPatchVer
, IDHW_SETPATCHVER
);
372 result
= _(MSG_HW_AHI
);
376 result
= _(MSG_HW_OS_40
);
379 case IDHW_VMMCHIPRAM
:
383 case IDHW_VMMFASTRAM
:
391 case IDHW_PLNCHIPRAM
:
392 result
= handle_size(IdentifyBase
->hwb
.buf_PlainChipRAM
, IDHW_PLNCHIPRAM
);
395 case IDHW_PLNFASTRAM
:
396 result
= handle_size(IdentifyBase
->hwb
.buf_PlainFastRAM
, IDHW_PLNFASTRAM
);
400 result
= handle_size(IdentifyBase
->hwb
.buf_PlainRAM
, IDHW_PLNRAM
);
404 IdentifyBase
->hwb
.buf_VBR
[0] = '\0'; // not buffered
405 result
= handle_address(IdentifyBase
->hwb
.buf_VBR
, IDHW_VBR
);
409 IdentifyBase
->hwb
.buf_LastAlert
[0] = '\0'; // not buffered
410 result
= handle_hex(IdentifyBase
->hwb
.buf_LastAlert
, IDHW_LASTALERT
);
413 case IDHW_VBLANKFREQ
:
414 result
= handle_freq(IdentifyBase
->hwb
.buf_VBlankFreq
, IDHW_VBLANKFREQ
);
418 result
= handle_freq(IdentifyBase
->hwb
.buf_PowerFreq
, IDHW_POWERFREQ
);
422 result
= handle_freq(IdentifyBase
->hwb
.buf_EClock
, IDHW_ECLOCK
);
426 result
= handle_size(IdentifyBase
->hwb
.buf_SlowRAM
, IDHW_SLOWRAM
);
430 result
= handle_notavail(null4na
);
434 result
= handle_notavail(null4na
);
438 result
= handle_avail(IDHW_BATTCLOCK
, null4na
);
441 case IDHW_CHUNKYPLANAR
:
442 result
= handle_avail(IDHW_CHUNKYPLANAR
, null4na
);
446 result
= handle_notavail(null4na
);
454 result
= handle_notavail(null4na
);
458 result
= handle_mhz(IdentifyBase
->hwb
.buf_CPUClock
, IDHW_CPUCLOCK
);
466 result
= handle_notavail(null4na
);
470 result
= handle_number(IdentifyBase
->hwb
.buf_RAMWidth
, IDHW_RAMWIDTH
);
475 ULONG num
= IdHardwareNum(IDHW_RAMCAS
, NULL
);
478 result
= _(MSG_HW_RAMCAS_DOUBLE
);
482 result
= _(MSG_HW_RAMCAS_NORMAL
);
487 case IDHW_RAMBANDWIDTH
:
488 result
= handle_notavail(null4na
);
492 result
= _(MSG_HW_TCPIP_AMITCP
);
496 result
= _(MSG_HW_PPCOS_NONE
);
500 result
= _(MSG_HW_AGNUS_NONE
);
504 result
= _(MSG_HW_AMODE_NONE
);
508 result
= _(MSG_HW_DENISE_NONE
);
512 result
= handle_notavail(null4na
);
516 result
= handle_notavail(null4na
);
520 ReleaseSemaphore(&IdentifyBase
->sem
);
528 static CONST_STRPTR
handle_version(TEXT
*buffer
, Tag tag
)
530 CONST_STRPTR result
= buffer
;
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
);
542 strlcpy(buffer
, _(MSG_HW_NOVERSION
), STRBUFSIZE
);
548 static CONST_STRPTR
handle_size(TEXT
*buffer
, Tag tag
)
550 CONST_STRPTR result
= buffer
;
556 UQUAD num
= IdHardwareNum(tag
, NULL
);
560 format
= _(MSG_BYTE
);
562 else if (num
< 1000 * 1000)
565 format
= _(MSG_KBYTE
);
567 else if (num
< 1000 * 1000 * 1000)
569 num
= num
/ 1024 / 102;
570 format
= _(MSG_MBYTE
);
574 num
= num
/ 1024 / 1024 / 102;
575 format
= _(MSG_GBYTE
);
580 snprintf(buffer
, STRBUFSIZE
, format
,
581 (long unsigned int)num
, '0' + fraction
);
586 static CONST_STRPTR
handle_freq(TEXT
*buffer
, Tag tag
)
588 CONST_STRPTR result
= buffer
;
591 ULONG num
= IdHardwareNum(tag
, NULL
);
593 snprintf(buffer
, STRBUFSIZE
, "%u Hz", (unsigned int)num
);
599 static CONST_STRPTR
handle_mhz(TEXT
*buffer
, Tag tag
)
601 CONST_STRPTR result
= buffer
;
604 ULONG num
= IdHardwareNum(tag
, NULL
);
606 snprintf(buffer
, STRBUFSIZE
, "%u MHz", (unsigned int)num
);
612 static CONST_STRPTR
handle_number(TEXT
*buffer
, Tag tag
)
614 CONST_STRPTR result
= buffer
;
617 ULONG num
= IdHardwareNum(tag
, NULL
);
619 snprintf(buffer
, STRBUFSIZE
, "%u", (unsigned int)num
);
625 static CONST_STRPTR
handle_address(TEXT
*buffer
, Tag tag
)
627 CONST_STRPTR result
= buffer
;
630 ULONG num
= IdHardwareNum(tag
, NULL
);
632 snprintf(buffer
, STRBUFSIZE
, "0x%08x", (unsigned int)num
);
638 static CONST_STRPTR
handle_hex(TEXT
*buffer
, Tag tag
)
640 CONST_STRPTR result
= buffer
;
643 ULONG num
= IdHardwareNum(tag
, NULL
);
645 snprintf(buffer
, STRBUFSIZE
, "%08x", (unsigned int)num
);
651 static CONST_STRPTR
handle_avail(Tag tag
, BOOL null4na
)
653 ULONG num
= IdHardwareNum(tag
, NULL
);
656 return _(MSG_HW_FOUND
);
660 return handle_notavail(null4na
);
664 static CONST_STRPTR
handle_notavail(BOOL null4na
)
666 if (null4na
== FALSE
)
667 return _(MSG_HW_NONE
);