2 Copyright (C) 2013-2019, The AROS Development Team.
6 #include <aros/debug.h>
8 #define MUIMASTER_YES_INLINE_STDARG
10 #include <exec/memory.h>
11 #include <hidd/hidd.h>
12 #include <resources/hpet.h>
13 #include <libraries/mui.h>
14 #include <mui/NFloattext_mcc.h>
15 #include <resources/processor.h>
16 #include <utility/tagitem.h>
17 #include <utility/hooks.h>
19 #include <proto/alib.h>
20 #include <proto/aros.h>
21 #include <proto/dos.h>
22 #include <proto/exec.h>
23 #include <proto/hpet.h>
24 #include <proto/kernel.h>
25 #include <proto/muimaster.h>
26 #include <proto/utility.h>
27 #include <proto/intuition.h>
28 #include <proto/processor.h>
35 #include "cpuspecific.h"
38 #include <zune/customclasses.h>
40 APTR ProcessorBase
= NULL
;
43 /*** Instance Data **********************************************************/
44 struct ComputerWindow_DATA
50 ULONG
ExtUDivMod32(ULONG a
, ULONG b
, ULONG
*mod
)
58 void PrintNum(char *buffer
, LONG bufsize
, ULONG num
)
73 num
= ExtUDivMod32(UMult32(num
, 100) >> 10, 100, &x
);
76 x
= ExtUDivMod32(x
, 10, &xx
);
87 snprintf(buffer
, bufsize
, "%d.%d %s", (int)num
, (int)x
, fmt
);
91 snprintf(buffer
, bufsize
, "%d K", (int)num
);
95 ULONG
ComputeKBytes(APTR a
, APTR b
)
99 return (ULONG
)(result
>> 10);
102 static ULONG
GetProcessorsCount()
105 struct TagItem tags
[] =
107 {GCIT_NumberOfProcessors
, (IPTR
)&count
},
120 } ProcessorArchitecture
[] =
122 { PROCESSORARCH_UNKNOWN
, "Unknown" },
123 { PROCESSORARCH_M68K
, "Motorola 68K" },
124 { PROCESSORARCH_PPC
, "PowerPC" },
125 { PROCESSORARCH_X86
, "X86" },
126 { PROCESSORARCH_ARM
, "ARM" },
134 } CurrentEndianness
[] =
136 { ENDIANNESS_UNKNOWN
, "Unknown" },
137 { ENDIANNESS_LE
, "LE" },
138 { ENDIANNESS_BE
, "BE" },
142 static VOID
ParseProcessorInformation(Object
*GrpProcessors
)
144 ULONG count
= GetProcessorsCount();
146 CONST_STRPTR modelstring
;
147 ULONG architecture
, endianness
;
148 CONST_STRPTR architecturestring
= "", endiannessstring
= "";
151 D(bug("[SysExplorer] %s()\n", __func__
));
153 for (i
= 0; i
< count
; i
++)
155 Object
*CoreIDLabelObj
, *CoreIDStrObj
,
156 *CoreSpdLabelObj
, *CoreSpdStrObj
,
157 *CoreFeatLabelObj
, *CoreFeatStrObj
;
159 char *CoreIDLabelStr
, *CoreIDStr
;
161 struct TagItem tags
[] =
163 {GCIT_SelectedProcessor
, i
},
164 {GCIT_ModelString
, (IPTR
)&modelstring
},
165 {GCIT_Architecture
, (IPTR
)&architecture
},
166 {GCIT_Endianness
, (IPTR
)&endianness
},
167 {GCIT_ProcessorSpeed
, (IPTR
)&cpuspeed
},
172 D(bug("[SysExplorer] %s: CPU #%d\n", __func__
, i
));
175 while(ProcessorArchitecture
[j
].Description
!= NULL
)
177 if (ProcessorArchitecture
[j
].Architecture
== architecture
)
179 architecturestring
= ProcessorArchitecture
[j
].Description
;
186 while(CurrentEndianness
[j
].Description
!= NULL
)
188 if (CurrentEndianness
[j
].Endianness
== endianness
)
190 endiannessstring
= CurrentEndianness
[j
].Description
;
197 modelstring
= "Unknown";
199 CoreIDLabelStr
= AllocVec(14, MEMF_PUBLIC
);
200 snprintf(CoreIDLabelStr
, 14, "CPU Core #%u", (int)(i
+ 1));
201 CoreIDLabelObj
= Label(CoreIDLabelStr
);
203 CoreIDStr
= AllocVec(strlen(architecturestring
) + strlen(endiannessstring
) + strlen(modelstring
) + 4, MEMF_PUBLIC
);
205 strlen(architecturestring
) + strlen(endiannessstring
) + strlen(modelstring
) + 4,
207 architecturestring
, endiannessstring
, modelstring
);
208 CoreIDStrObj
= TextObject
,
210 MUIA_Background
, MUII_TextBack
,
212 MUIA_Text_Contents
, (IPTR
)CoreIDStr
,
215 if (DoMethod(GrpProcessors
, MUIM_Group_InitChange
))
217 DoMethod(GrpProcessors
, OM_ADDMEMBER
, CoreIDLabelObj
);
218 DoMethod(GrpProcessors
, OM_ADDMEMBER
, CoreIDStrObj
);
219 DoMethod(GrpProcessors
, MUIM_Group_ExitChange
);
225 CoreSpdLabelObj
= Label("Speed");
226 CoreSpdStr
= AllocVec(20, MEMF_PUBLIC
);
227 snprintf(CoreSpdStr
, 20, "%llu MHz", (unsigned long long)(cpuspeed
/ 1000000));
228 CoreSpdStrObj
= TextObject
,
230 MUIA_Background
, MUII_TextBack
,
232 MUIA_Text_Contents
, (IPTR
)CoreSpdStr
,
235 if (DoMethod(GrpProcessors
, MUIM_Group_InitChange
))
237 DoMethod(GrpProcessors
, OM_ADDMEMBER
, CoreSpdLabelObj
);
238 DoMethod(GrpProcessors
, OM_ADDMEMBER
, CoreSpdStrObj
);
239 DoMethod(GrpProcessors
, MUIM_Group_ExitChange
);
243 char *CPUFeatureStr
= AllocVec(1024, MEMF_PUBLIC
);
244 PrintCPUSpecificInfo(CPUFeatureStr
, 1024, i
, ProcessorBase
);
245 CoreFeatLabelObj
= Label("Features");
246 CoreFeatStrObj
= ScrollgroupObject
,
248 MUIA_Background
, MUII_TextBack
,
249 MUIA_Scrollgroup_Contents
, (IPTR
)(NFloattextObject
,
251 MUIA_Background
, MUII_TextBack
,
253 MUIA_Floattext_Text
, (IPTR
)CPUFeatureStr
,
256 if (DoMethod(GrpProcessors
, MUIM_Group_InitChange
))
258 DoMethod(GrpProcessors
, OM_ADDMEMBER
, CoreFeatLabelObj
);
259 DoMethod(GrpProcessors
, OM_ADDMEMBER
, CoreFeatStrObj
);
260 DoMethod(GrpProcessors
, MUIM_Group_ExitChange
);
265 static inline void VersionStr(char *ptr
, int len
, struct Library
*base
)
267 snprintf(ptr
, len
, "%d.%d", base
->lib_Version
, base
->lib_Revision
);
270 char *SplitBootArgs(struct TagItem
*bootinfo
, char *buffer
, LONG bufsize
)
272 char *rawargs
= (char *)GetTagData(KRN_CmdLine
, 0, bootinfo
);
275 D(bug("[SysExplorer] %s()\n", __func__
));
279 D(bug("[SysExplorer] %s: splitting '%s'\n", __func__
, rawargs
));
280 count
= strlen(rawargs
);
283 for (i
= 0; i
< count
; i
++)
285 if (rawargs
[i
] == ' ')
288 buffer
[i
] = rawargs
[i
];
294 static Object
*ComputerWindow__OM_NEW(Class
*cl
, Object
*self
, struct opSet
*msg
)
296 Object
*GrpProcessors
;
299 char aros_ver
[12], exec_ver
[12];
306 STRPTR pagetitles
[5];
309 D(bug("[SysExplorer] %s()\n", __func__
));
311 VersionStr(aros_ver
, sizeof(aros_ver
), ArosBase
);
312 VersionStr(exec_ver
, sizeof(exec_ver
), &SysBase
->LibNode
);
314 KernelBase
= OpenResource("kernel.resource");
317 struct TagItem
*bootinfo
= KrnGetBootInfo();
319 bootldr
= GetTagData(KRN_BootLoader
, 0, bootinfo
);
320 args
= (IPTR
)SplitBootArgs(bootinfo
, buffer
, sizeof(buffer
));
323 D(bug("[SysExplorer] %s: prepairing pages ..\n", __func__
));
325 pagetitles
[pagecnt
++] = (STRPTR
)_(MSG_GENERAL
);
326 if ((ProcessorBase
= OpenResource(PROCESSORNAME
)) != NULL
)
328 pagetitles
[pagecnt
++] = (STRPTR
)_(MSG_PROCESSORS
);
330 pagetitles
[pagecnt
++] = (STRPTR
)_(MSG_RAM
);
331 if ((HPETBase
= OpenResource("hpet.resource")) != NULL
)
333 pagetitles
[pagecnt
++] = (STRPTR
)_(MSG_HPET
);
335 pagetitles
[pagecnt
] = NULL
;
337 D(bug("[SysExplorer] %s: %d pages\n", __func__
, pagecnt
));
339 self
= (Object
*) DoSuperNewTags
342 MUIA_Window_Title
, __(MSG_SYSTEM_PROPERTIES
),
343 MUIA_Window_ID
, MAKE_ID('S', 'Y', 'P', 'R'),
344 WindowContents
, (IPTR
)(RegisterObject
,
345 MUIA_Register_Titles
, (IPTR
) pagetitles
,
347 Child
, (IPTR
)(VGroup
,
348 Child
, (IPTR
)(ColGroup(2),
349 MUIA_FrameTitle
, __(MSG_VERSION
),
351 MUIA_Background
, MUII_GroupBack
,
352 Child
, (IPTR
)Label("AROS"),
353 Child
, (IPTR
)(TextObject
,
355 MUIA_Background
, MUII_TextBack
,
357 MUIA_Text_Contents
, (IPTR
)aros_ver
,
359 Child
, (IPTR
)Label("Exec Library"),
360 Child
, (IPTR
)(TextObject
,
362 MUIA_Background
, MUII_TextBack
,
364 MUIA_Text_Contents
, (IPTR
)exec_ver
,
367 Child
, (IPTR
)(ColGroup(2),
369 MUIA_FrameTitle
, (IPTR
)"Boot Config",
370 Child
, (IPTR
)Label("Loader"),
371 Child
, (IPTR
)(TextObject
,
373 MUIA_Background
, MUII_TextBack
,
375 MUIA_Text_Contents
, bootldr
,
377 Child
, (IPTR
)Label(__(MSG_ARGUMENTS
)),
378 Child
, (IPTR
)(ScrollgroupObject
,
380 MUIA_Background
, MUII_TextBack
,
381 MUIA_Scrollgroup_Contents
, (IPTR
)(NFloattextObject
,
383 MUIA_Background
, MUII_TextBack
,
385 MUIA_Floattext_Text
, args
,
390 ProcessorBase
? Child
: TAG_IGNORE
, (IPTR
)(HGroup
,
391 Child
, (IPTR
)(GrpProcessors
= ColGroup(2),
394 Child
, (IPTR
)(VGroup
,
395 Child
, (IPTR
)(NListviewObject
,
397 MUIA_Background
, MUII_TextBack
,
398 MUIA_NListview_NList
, (IPTR
)(ram_flt
= NFloattextObject
,
400 MUIA_Background
, MUII_TextBack
,
404 HPETBase
? Child
: TAG_IGNORE
, (IPTR
)(VGroup
,
405 Child
, (IPTR
)(NListviewObject
,
407 MUIA_Background
, MUII_TextBack
,
408 MUIA_NListview_NList
, (IPTR
)(hpet_flt
= NFloattextObject
,
410 MUIA_Background
, MUII_TextBack
,
420 struct MemHeader
*mh
;
425 D(bug("[SysExplorer] %s: self @ %p\n", __func__
, self
));
430 ParseProcessorInformation(GrpProcessors
);
432 D(bug("[SysExplorer] %s: Processor Information read\n", __func__
));
434 // high precision timers
437 bufsize
= sizeof(buffer
);
444 while (bufsize
> 5 && GetUnitAttrs(i
, HPET_UNIT_OWNER
, &owner
, TAG_DONE
))
447 owner
= _(MSG_AVAILABLE
);
449 snprintf(bufptr
, bufsize
, "HPET %u:\t\t%s\n", (unsigned)(++i
), owner
);
451 slen
= strlen(bufptr
);
456 // we intentionally use MUIA_Floattext_Text because it copies the text
457 SET(hpet_flt
, MUIA_Floattext_Text
, buffer
);
462 bufsize
= sizeof(buffer
);
466 mh
= (struct MemHeader
*)SysBase
->MemList
.lh_Head
;
467 bufsize
> 5 && mh
->mh_Node
.ln_Succ
;
468 mh
= (struct MemHeader
*)mh
->mh_Node
.ln_Succ
471 char *memtype
= "ROM";
473 if (mh
->mh_Attributes
& MEMF_CHIP
)
475 if (mh
->mh_Attributes
& MEMF_FAST
)
478 snprintf(bufptr
, bufsize
, "Node Type 0x%X, Attributes 0x%X (%s), at $%p-$%p (",
479 mh
->mh_Node
.ln_Type
, mh
->mh_Attributes
, memtype
, mh
->mh_Lower
, mh
->mh_Upper
- 1);
481 slen
= strlen(bufptr
);
488 PrintNum(bufptr
, bufsize
, ComputeKBytes(mh
->mh_Lower
, mh
->mh_Upper
));
489 slen
= strlen(bufptr
);
493 snprintf(bufptr
, bufsize
, ")\n");
494 slen
= strlen(bufptr
);
498 // we intentionally use MUIA_Floattext_Text because it copies the text
499 SET(ram_flt
, MUIA_Floattext_Text
, buffer
);
505 /*** Setup ******************************************************************/
508 ComputerWindow
, NULL
, MUIC_Window
, NULL
,
509 OM_NEW
, struct opSet
*