add place-holder directory for the a3000 wd533c93 scsi controller implementation.
[AROS.git] / workbench / tools / SysExplorer / computer_page_cl.c
blob1c7348f80fbf973b8bc672e713185b34db459f72
1 /*
2 Copyright (C) 2013-2019, The AROS Development Team.
3 $Id$
4 */
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>
30 #include <ctype.h>
31 #include <stdio.h>
32 #include <stdlib.h>
34 #include "classes.h"
35 #include "cpuspecific.h"
36 #include "locale.h"
38 #include <zune/customclasses.h>
40 APTR ProcessorBase = NULL;
43 /*** Instance Data **********************************************************/
44 struct ComputerWindow_DATA
46 /* Nothing to add */
50 ULONG ExtUDivMod32(ULONG a, ULONG b, ULONG *mod)
52 *mod = a % b;
54 return a/b;
58 void PrintNum(char *buffer, LONG bufsize, ULONG num)
60 /* MBytes ? */
61 if(num > 1023)
63 ULONG x, xx;
64 char* fmt = "meg";
66 /* GBytes ? */
67 if(num > 0xfffff)
69 num >>= 10;
70 fmt = "gig";
73 num = ExtUDivMod32(UMult32(num, 100) >> 10, 100, &x);
75 /* round */
76 x = ExtUDivMod32(x, 10, &xx);
78 if(xx > 4)
80 if(++x > 9)
82 x = 0;
83 num++;
87 snprintf(buffer, bufsize, "%d.%d %s", (int)num, (int)x, fmt);
89 else
91 snprintf(buffer, bufsize, "%d K", (int)num);
95 ULONG ComputeKBytes(APTR a, APTR b)
97 IPTR result = b - a;
99 return (ULONG)(result >> 10);
102 static ULONG GetProcessorsCount()
104 ULONG count = 0;
105 struct TagItem tags [] =
107 {GCIT_NumberOfProcessors, (IPTR)&count},
108 {TAG_DONE, TAG_DONE}
111 GetCPUInfo(tags);
113 return count;
116 struct
118 ULONG Architecture;
119 STRPTR Description;
120 } ProcessorArchitecture [] =
122 { PROCESSORARCH_UNKNOWN, "Unknown" },
123 { PROCESSORARCH_M68K, "Motorola 68K" },
124 { PROCESSORARCH_PPC, "PowerPC" },
125 { PROCESSORARCH_X86, "X86" },
126 { PROCESSORARCH_ARM, "ARM" },
127 { 0, NULL }
130 struct
132 ULONG Endianness;
133 STRPTR Description;
134 } CurrentEndianness [] =
136 { ENDIANNESS_UNKNOWN, "Unknown" },
137 { ENDIANNESS_LE, "LE" },
138 { ENDIANNESS_BE, "BE" },
139 { 0, NULL}
142 static VOID ParseProcessorInformation(Object *GrpProcessors)
144 ULONG count = GetProcessorsCount();
145 ULONG i, j;
146 CONST_STRPTR modelstring;
147 ULONG architecture, endianness;
148 CONST_STRPTR architecturestring = "", endiannessstring = "";
149 UQUAD cpuspeed;
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},
168 {TAG_DONE, TAG_DONE}
171 GetCPUInfo(tags);
172 D(bug("[SysExplorer] %s: CPU #%d\n", __func__, i));
174 j = 0;
175 while(ProcessorArchitecture[j].Description != NULL)
177 if (ProcessorArchitecture[j].Architecture == architecture)
179 architecturestring = ProcessorArchitecture[j].Description;
180 break;
182 j++;
185 j = 0;
186 while(CurrentEndianness[j].Description != NULL)
188 if (CurrentEndianness[j].Endianness == endianness)
190 endiannessstring = CurrentEndianness[j].Description;
191 break;
193 j++;
196 if (!modelstring)
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);
204 snprintf(CoreIDStr,
205 strlen(architecturestring) + strlen(endiannessstring) + strlen(modelstring) + 4,
206 "%s/%s %s",
207 architecturestring, endiannessstring, modelstring);
208 CoreIDStrObj = TextObject,
209 TextFrame,
210 MUIA_Background, MUII_TextBack,
211 MUIA_CycleChain, 1,
212 MUIA_Text_Contents, (IPTR)CoreIDStr,
213 End;
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);
222 if (cpuspeed)
224 char *CoreSpdStr;
225 CoreSpdLabelObj = Label("Speed");
226 CoreSpdStr = AllocVec(20, MEMF_PUBLIC);
227 snprintf(CoreSpdStr, 20, "%llu MHz", (unsigned long long)(cpuspeed / 1000000));
228 CoreSpdStrObj = TextObject,
229 TextFrame,
230 MUIA_Background, MUII_TextBack,
231 MUIA_CycleChain, 1,
232 MUIA_Text_Contents, (IPTR)CoreSpdStr,
233 End;
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,
247 TextFrame,
248 MUIA_Background, MUII_TextBack,
249 MUIA_Scrollgroup_Contents, (IPTR)(NFloattextObject,
250 NoFrame,
251 MUIA_Background, MUII_TextBack,
252 MUIA_CycleChain, 1,
253 MUIA_Floattext_Text, (IPTR)CPUFeatureStr,
254 End),
255 End;
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);
273 int i, count;
275 D(bug("[SysExplorer] %s()\n", __func__));
277 if (rawargs)
279 D(bug("[SysExplorer] %s: splitting '%s'\n", __func__, rawargs));
280 count = strlen(rawargs);
281 if (count > bufsize)
282 count = bufsize;
283 for (i = 0; i < count ; i++)
285 if (rawargs[i] == ' ')
286 buffer[i] = '\n';
287 else
288 buffer[i] = rawargs[i];
291 return buffer;
294 static Object *ComputerWindow__OM_NEW(Class *cl, Object *self, struct opSet *msg)
296 Object *GrpProcessors;
297 Object *hpet_flt;
298 Object *ram_flt;
299 char aros_ver[12], exec_ver[12];
300 char buffer[2000];
301 IPTR bootldr = 0;
302 IPTR args = 0;
303 APTR KernelBase;
304 APTR HPETBase;
306 STRPTR pagetitles[5];
307 int pagecnt = 0;
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");
315 if (KernelBase)
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
341 cl, self, NULL,
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,
346 MUIA_CycleChain, 1,
347 Child, (IPTR)(VGroup,
348 Child, (IPTR)(ColGroup(2),
349 MUIA_FrameTitle, __(MSG_VERSION),
350 GroupFrame,
351 MUIA_Background, MUII_GroupBack,
352 Child, (IPTR)Label("AROS"),
353 Child, (IPTR)(TextObject,
354 TextFrame,
355 MUIA_Background, MUII_TextBack,
356 MUIA_CycleChain, 1,
357 MUIA_Text_Contents, (IPTR)aros_ver,
358 End),
359 Child, (IPTR)Label("Exec Library"),
360 Child, (IPTR)(TextObject,
361 TextFrame,
362 MUIA_Background, MUII_TextBack,
363 MUIA_CycleChain, 1,
364 MUIA_Text_Contents, (IPTR)exec_ver,
365 End),
366 End),
367 Child, (IPTR)(ColGroup(2),
368 GroupFrame,
369 MUIA_FrameTitle, (IPTR)"Boot Config",
370 Child, (IPTR)Label("Loader"),
371 Child, (IPTR)(TextObject,
372 TextFrame,
373 MUIA_Background, MUII_TextBack,
374 MUIA_CycleChain, 1,
375 MUIA_Text_Contents, bootldr,
376 End),
377 Child, (IPTR)Label(__(MSG_ARGUMENTS)),
378 Child, (IPTR)(ScrollgroupObject,
379 TextFrame,
380 MUIA_Background, MUII_TextBack,
381 MUIA_Scrollgroup_Contents, (IPTR)(NFloattextObject,
382 NoFrame,
383 MUIA_Background, MUII_TextBack,
384 MUIA_CycleChain, 1,
385 MUIA_Floattext_Text, args,
386 End),
387 End),
388 End),
389 End),
390 ProcessorBase ? Child : TAG_IGNORE, (IPTR)(HGroup,
391 Child, (IPTR)(GrpProcessors = ColGroup(2),
392 End),
393 End),
394 Child, (IPTR)(VGroup,
395 Child, (IPTR)(NListviewObject,
396 TextFrame,
397 MUIA_Background, MUII_TextBack,
398 MUIA_NListview_NList, (IPTR)(ram_flt = NFloattextObject,
399 NoFrame,
400 MUIA_Background, MUII_TextBack,
401 End),
402 End),
403 End),
404 HPETBase ? Child : TAG_IGNORE, (IPTR)(VGroup,
405 Child, (IPTR)(NListviewObject,
406 TextFrame,
407 MUIA_Background, MUII_TextBack,
408 MUIA_NListview_NList, (IPTR)(hpet_flt = NFloattextObject,
409 NoFrame,
410 MUIA_Background, MUII_TextBack,
411 End),
412 End),
413 End),
414 End),
415 TAG_DONE
418 if (self)
420 struct MemHeader *mh;
421 char *bufptr;
422 LONG slen;
423 LONG bufsize;
425 D(bug("[SysExplorer] %s: self @ %p\n", __func__, self));
427 // processors
428 *buffer = '\0';
429 if (ProcessorBase)
430 ParseProcessorInformation(GrpProcessors);
432 D(bug("[SysExplorer] %s: Processor Information read\n", __func__));
434 // high precision timers
435 *buffer = '\0';
436 bufptr = buffer;
437 bufsize = sizeof(buffer);
439 if (HPETBase)
441 const char *owner;
442 ULONG i = 0;
444 while (bufsize > 5 && GetUnitAttrs(i, HPET_UNIT_OWNER, &owner, TAG_DONE))
446 if (!owner)
447 owner = _(MSG_AVAILABLE);
449 snprintf(bufptr, bufsize, "HPET %u:\t\t%s\n", (unsigned)(++i), owner);
451 slen = strlen(bufptr);
452 bufptr += slen;
453 bufsize -= slen;
456 // we intentionally use MUIA_Floattext_Text because it copies the text
457 SET(hpet_flt, MUIA_Floattext_Text, buffer);
459 // RAM
460 *buffer = '\0';
461 bufptr = 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)
474 memtype = "CHIP";
475 if (mh->mh_Attributes & MEMF_FAST)
476 memtype = "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);
482 bufptr += slen;
483 bufsize -= slen;
485 if (bufsize < 30)
486 break;
488 PrintNum(bufptr, bufsize, ComputeKBytes(mh->mh_Lower, mh->mh_Upper));
489 slen = strlen(bufptr);
490 bufptr += slen;
491 bufsize -= slen;
493 snprintf(bufptr, bufsize, ")\n");
494 slen = strlen(bufptr);
495 bufptr += slen;
496 bufsize -= slen;
498 // we intentionally use MUIA_Floattext_Text because it copies the text
499 SET(ram_flt, MUIA_Floattext_Text, buffer);
502 return self;
505 /*** Setup ******************************************************************/
506 ZUNE_CUSTOMCLASS_1
508 ComputerWindow, NULL, MUIC_Window, NULL,
509 OM_NEW, struct opSet *