revert between 56095 -> 55830 in arch
[AROS.git] / workbench / tools / ShowConfig / ShowConfig.c
blob0714fabf42fce674df85cb433fa243bf4d07a154
1 #include <aros/kernel.h>
2 #include <exec/execbase.h>
3 #include <exec/memory.h>
4 #include <resources/hpet.h>
5 #include <resources/processor.h>
7 #include <proto/aros.h>
8 #include <proto/hpet.h>
9 #include <proto/kernel.h>
10 #include <proto/exec.h>
11 #include <proto/utility.h>
12 #include <proto/processor.h>
14 #include <stdio.h>
16 #include "cpuspecific.h"
18 APTR ProcessorBase = NULL;
19 char execextra[100];
21 ULONG ExtUDivMod32(ULONG a, ULONG b, ULONG *mod)
23 *mod = a % b;
25 return a/b;
28 void PrintNum(ULONG num)
30 /* MBytes ? */
31 if(num > 1023)
33 ULONG x, xx;
34 char* fmt = "meg";
36 /* GBytes ? */
37 if(num > 0xfffff)
39 num >>= 10;
40 fmt = "gig";
43 num = ExtUDivMod32(UMult32(num, 100) >> 10, 100, &x);
45 /* round */
46 x = ExtUDivMod32(x, 10, &xx);
48 if(xx > 4)
50 if(++x > 9)
52 x = 0;
53 num++;
57 printf("%d.%d %s", (int)num, (int)x, fmt);
59 else
61 printf("%d K", (int)num);
65 ULONG ComputeKBytes(APTR a, APTR b)
67 IPTR result = b - a;
69 return (ULONG)(result >> 10);
72 static ULONG GetProcessorsCount()
74 ULONG count = 0;
75 struct TagItem tags [] =
77 {GCIT_NumberOfProcessors, (IPTR)&count},
78 {TAG_DONE, TAG_DONE}
81 GetCPUInfo(tags);
83 return count;
86 struct
88 ULONG Architecture;
89 STRPTR Description;
90 } ProcessorArchitecture [] =
92 { PROCESSORARCH_UNKNOWN, "Unknown" },
93 { PROCESSORARCH_M68K, "M68K" },
94 { PROCESSORARCH_PPC, "PowerPC" },
95 { PROCESSORARCH_X86, "X86" },
96 { PROCESSORARCH_ARM, "ARM" },
97 { 0, NULL }
100 struct
102 ULONG Endianness;
103 STRPTR Description;
104 } CurrentEndianness [] =
106 { ENDIANNESS_UNKNOWN, "Unknown" },
107 { ENDIANNESS_LE, "LE" },
108 { ENDIANNESS_BE, "BE" },
109 { 0, NULL}
112 static VOID PrintProcessorInformation()
114 ULONG count = GetProcessorsCount();
115 ULONG i, j;
116 CONST_STRPTR modelstring;
117 ULONG architecture, endianness;
118 CONST_STRPTR architecturestring = "", endiannessstring = "";
119 UQUAD cpuspeed;
121 for (i = 0; i < count; i++)
123 struct TagItem tags [] =
125 {GCIT_SelectedProcessor, i},
126 {GCIT_ModelString, (IPTR)&modelstring},
127 {GCIT_Architecture, (IPTR)&architecture},
128 {GCIT_Endianness, (IPTR)&endianness},
129 {GCIT_ProcessorSpeed, (IPTR)&cpuspeed},
130 {TAG_DONE, TAG_DONE}
133 GetCPUInfo(tags);
135 j = 0;
136 while(ProcessorArchitecture[j].Description != NULL)
138 if (ProcessorArchitecture[j].Architecture == architecture)
140 architecturestring = ProcessorArchitecture[j].Description;
141 break;
143 j++;
146 j = 0;
147 while(CurrentEndianness[j].Description != NULL)
149 if (CurrentEndianness[j].Endianness == endianness)
151 endiannessstring = CurrentEndianness[j].Description;
152 break;
154 j++;
157 if (!modelstring)
158 modelstring = "Unknown";
160 printf("PROCESSOR %d:\t[%s/%s] %s", (int)(i + 1), architecturestring, endiannessstring, modelstring);
161 if (cpuspeed)
162 printf(" (%llu MHz)", (unsigned long long)(cpuspeed / 1000000));
163 printf("\n");
165 PrintCPUSpecificInfo(i, ProcessorBase);
169 int __nocommandline;
170 char __stdiowin[]="CON://800/400/ShowConfig/AUTO/CLOSE/WAIT";
172 int main()
174 struct MemHeader *mh;
175 APTR KernelBase;
176 APTR HPETBase;
177 int offset = 0;
179 #if (__WORDSIZE==64)
180 sprintf(&execextra[1], "64bit/");
181 offset = 6;
182 #endif
183 if (OpenResource("execlock.resource"))
185 sprintf(&execextra[1 + offset], "SMP Enabled ");
186 offset += 12;
189 if (offset == 0)
190 execextra[0] = '\0';
191 else
193 execextra[0] = '[';
194 execextra[offset] = ']';
197 printf("VERS:\t\tAROS version %d.%d, Exec version %d.%d %s\n", ArosBase->lib_Version, ArosBase->lib_Revision,
198 SysBase->LibNode.lib_Version, SysBase->LibNode.lib_Revision, execextra);
200 ProcessorBase = OpenResource(PROCESSORNAME);
201 if (ProcessorBase)
202 PrintProcessorInformation();
204 HPETBase = OpenResource("hpet.resource");
205 if (HPETBase)
207 const char *owner;
208 ULONG i = 0;
210 while (GetUnitAttrs(i, HPET_UNIT_OWNER, &owner, TAG_DONE))
212 if (!owner)
213 owner = "Available for use";
215 printf("HPET %u:\t\t%s\n", (unsigned)(++i), owner);
219 printf("RAM:");
220 for (mh = (struct MemHeader *)SysBase->MemList.lh_Head; mh->mh_Node.ln_Succ; mh = (struct MemHeader *)mh->mh_Node.ln_Succ) {
221 char *memtype = "ROM";
223 if (mh->mh_Attributes & MEMF_CHIP)
224 memtype = "CHIP";
225 if (mh->mh_Attributes & MEMF_FAST)
226 memtype = "FAST";
227 printf("\t\tNode Type 0x%X, Attributes 0x%X (%s), at $%p-$%p (", mh->mh_Node.ln_Type, mh->mh_Attributes, memtype, mh->mh_Lower, mh->mh_Upper - 1);
228 PrintNum(ComputeKBytes(mh->mh_Lower, mh->mh_Upper));
229 printf(")\n");
232 KernelBase = OpenResource("kernel.resource");
233 if (KernelBase)
235 struct TagItem *bootinfo = KrnGetBootInfo();
236 struct TagItem *tag;
238 tag = FindTagItem(KRN_BootLoader, bootinfo);
239 if (tag)
240 printf("BOOTLDR:\t%s\n", (char *)tag->ti_Data);
242 tag = FindTagItem(KRN_CmdLine, bootinfo);
243 if (tag)
244 printf("ARGS:\t\t%s\n", (char *)tag->ti_Data);
247 return 0;