-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
unit1.pas
436 lines (371 loc) Β· 11.1 KB
/
unit1.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
Windows, CpuInterface, Clipbrd;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Image1: TImage;
Label1: TLabel;
LabelResult: TLabel;
LabelNX: TLabel;
LabelDISK: TLabel;
LabelCX16: TLabel;
LabelPDPE1GB: TLabel;
LabelSSE4_2: TLabel;
LabelSAHF: TLabel;
LabelPF: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
LabelAVX: TLabel;
LabelSSE3: TLabel;
LabelPOPCNT: TLabel;
LabelSSE4_1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Image1Click(Sender: TObject);
procedure Label6Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
uses cpu, LCLIntf;
{$R *.lfm}
{ TForm1 }
function IsWindows64: boolean;
{
Detect if we are running on 64 bit Windows or 32 bit Windows,
independently of bitness of this program.
Original source:
http://www.delphipraxis.net/118485-ermitteln-ob-32-bit-oder-64-bit-betriebssystem.html
modified for FreePascal in German Lazarus forum:
http://www.lazarusforum.de/viewtopic.php?f=55&t=5287
}
{$ifdef WIN32} //Modified KpjComp for 64bit compile mode
type
TIsWow64Process = function( // Type of IsWow64Process API fn
Handle: THandle; var Res: Windows.BOOL): Windows.BOOL; stdcall;
var
IsWow64Result: Windows.BOOL; // Result from IsWow64Process
IsWow64Process: TIsWow64Process; // IsWow64Process fn reference
begin
// Try to load required function from kernel32
IsWow64Process := TIsWow64Process(Windows.GetProcAddress(
Windows.GetModuleHandle('kernel32'), 'IsWow64Process'));
if Assigned(IsWow64Process) then
begin
// Function is implemented: call it
if not IsWow64Process(Windows.GetCurrentProcess, IsWow64Result) then
raise SysUtils.Exception.Create('IsWindows64: bad process handle');
// Return result of function
Result := IsWow64Result;
end
else
// Function not implemented: can't be running on Wow64
Result := False;
{$else} //if were running 64bit code, OS must be 64bit :)
begin
Result := True;
{$endif}
end;
type
MEMORYSTATUSEX = record
dwLength : DWORD;
dwMemoryLoad : DWORD;
ullTotalPhys : uint64;
ullAvailPhys : uint64;
ullTotalPageFile : uint64;
ullAvailPageFile : uint64;
ullTotalVirtual : uint64;
ullAvailVirtual : uint64;
ullAvailExtendedVirtual : uint64;
end;
function GlobalMemoryStatusEx(var Buffer: MEMORYSTATUSEX): BOOL; stdcall; external 'kernel32' name 'GlobalMemoryStatusEx';
function GetSystemMem: uint64;
var MS_Ex: MemoryStatusEx;
begin
result := 0;
FillChar(MS_Ex, SizeOf(MemoryStatusEx), 0);
MS_Ex.dwLength := SizeOf(MemoryStatusEx);
if GlobalMemoryStatusEx(MS_Ex) then
result := (MS_Ex.ullTotalPhys + 1024*1024*512) div (1024*1024*1024); // FormatFloat('###.##', MS_Ex.ullTotalPhys / (1024*1024*1024)) + ' GB';
// TODO round up
end;
function supportedFeature(const cpuIntf: ICpuIdentifier; const feature: string): string;
begin
result := '';
if (cpuIntf.hasFeature(feature)) then
begin
result := feature;
end;
end;
function reportAllSupportedFeatures(const cpuIntf: ICpuIdentifier): string;
const
startFeatureIndex = 0;
endFeatureIndex = 58;
var features : array [startFeatureIndex..endFeatureIndex] of string = (
'SSE3', 'PCLMULQDQ', 'DTES64', 'MONITOR', 'DS-CPL', 'VMX',
'SMX', 'EIST', 'TM2', 'SSSE3', 'CNXT-ID', 'SDBG', 'FMA',
'CMPXCHG16B', 'xTPR', 'PDCM', 'PCID', 'DCA', 'SSE4_1',
'SSE4_2', 'x2APIC', 'MOVBE', 'POPCNT', 'TSC-DEADLINE',
'AES', 'XSAVE', 'OSXSAVE', 'AVX', 'F16C',
'RDRAND', 'FPU', 'VME', 'DE', 'PSE', 'TSC', 'MSR',
'PAE', 'MCE', 'CX8', 'APIC', 'SEP', 'MTRR', 'PGE',
'MCA', 'CMOV', 'PAT', 'PSE-36', 'PSN', 'CLFSH', 'DS',
'ACPI', 'MMX', 'FXSR', 'SSE', 'SSE2', 'SS', 'HTT', 'TM', 'PBE'
);
i:integer;
tmp:string;
width:integer;
begin
result:='';
width:=0;
for i := startFeatureIndex to endFeatureIndex do
begin
tmp:= supportedFeature(cpuIntf, features[i]);
if (length(tmp) > 0) then
begin
//if i mod 10 = 0 then
// result:= result + tmp + ''#13#10''
//else
result:= result + tmp + ' ';
width := width + length(tmp) + 1;
if width > 40 then begin
width := 0;
result:= result + ''#13#10''
end;
end;
end;
end;
type
TDriveLayoutInformationMbr = record
Signature: DWORD;
end;
TDriveLayoutInformationGpt = record
DiskId: TGuid;
StartingUsableOffset: Int64;
UsableLength: Int64;
MaxPartitionCount: DWORD;
end;
TPartitionInformationMbr = record
PartitionType: Byte;
BootIndicator: Boolean;
RecognizedPartition: Boolean;
HiddenSectors: DWORD;
end;
TPartitionInformationGpt = record
PartitionType: TGuid;
PartitionId: TGuid;
Attributes: Int64;
Name: array [0..35] of WideChar;
end;
TPartitionInformationEx = record
PartitionStyle: Integer;
StartingOffset: Int64;
PartitionLength: Int64;
PartitionNumber: DWORD;
RewritePartition: Boolean;
case Integer of
0: (Mbr: TPartitionInformationMbr);
1: (Gpt: TPartitionInformationGpt);
end;
TDriveLayoutInformationEx = record
PartitionStyle: DWORD;
PartitionCount: DWORD;
DriveLayoutInformation: record
case Integer of
0: (Mbr: TDriveLayoutInformationMbr);
1: (Gpt: TDriveLayoutInformationGpt);
end;
PartitionEntry: array [0..15] of TPartitionInformationGpt;
//hard-coded maximum of 16 partitions
end;
const
PARTITION_STYLE_MBR = 0;
PARTITION_STYLE_GPT = 1;
PARTITION_STYLE_RAW = 2;
const
IOCTL_DISK_GET_DRIVE_LAYOUT_EX = $00070050;
function layout: string;
const
// Max number of drives assuming primary/secondary, master/slave topology
MAX_IDE_DRIVES = 16;
var
i: Integer;
Drive: string;
hDevice: THandle;
DriveLayoutInfo: TDriveLayoutInformationEx;
BytesReturned: DWORD;
begin
result := '{';
for i := 0 to MAX_IDE_DRIVES - 1 do
begin
Drive := '\\.\PHYSICALDRIVE' + IntToStr(i);
hDevice := CreateFile(PChar(Drive), 0, FILE_SHARE_READ or FILE_SHARE_WRITE,
nil, OPEN_EXISTING, 0, 0);
if hDevice <> INVALID_HANDLE_VALUE then
begin
if DeviceIoControl(hDevice, IOCTL_DISK_GET_DRIVE_LAYOUT_EX, nil, 0,
@DriveLayoutInfo, SizeOf(DriveLayoutInfo), BytesReturned, nil) then
begin
case DriveLayoutInfo.PartitionStyle of
PARTITION_STYLE_MBR:
result := result + '(MBR)';
//Writeln(Drive + ', MBR, ' +
// IntToHex(DriveLayoutInfo.DriveLayoutInformation.Mbr.Signature, 8));
PARTITION_STYLE_GPT:
result := result + '(GPT)';
//Writeln(Drive + ', GPT, ' +
// GUIDToString(DriveLayoutInfo.DriveLayoutInformation.Gpt.DiskId));
PARTITION_STYLE_RAW:
result := result + '(GPT)';
//Writeln(Drive + ', RAW');
end;
end;
CloseHandle(hDevice);
end;
end;
result := result + '}';
end;
procedure TForm1.Button1Click(Sender: TObject);
var
cpus: LongWord;
w64: boolean;
mem: uint64;
processor : ICpuIdentifier;
bad: boolean;
procedure red(text: TLabel);
begin
text.Color := clRed;
bad := true;
end;
begin
cpus := GetCPUCount();
w64 := IsWindows64;
mem := GetSystemMem;
processor := TCpuIdentifier.Create();
bad := false;
Label1.Caption :='CPU threads count is ' + IntToStr(cpus);
if cpus > 1 then
Label1.Color := clMoneyGreen
else red(Label1);
if w64 then begin
Label2.Color := clMoneyGreen;
// red(Label2); // Uncomment to simulate failure
Label2.Caption := 'CPU is 64-bit';
end else begin
red(Label2);
Label2.Caption := 'CPU is 32-bit';
end;
Button2.Enabled := true;
if mem > 1 then begin
Label4.Color := clMoneyGreen;
end else begin
red(Label4);
end;
Label4.Caption := 'RAM is ' + FormatFloat('###.##', mem) + ' GB';
Label7.Caption := Trim(processor.processorName());
if processor.hasFeature('x2APIC') then
Label7.Caption := Label7.Caption + ' (x2APIC)'
else Label7.Caption := Label7.Caption + ' (Legacy APIC)';
if processor.hasFeature('x2APIC') or processor.hasFeature('APIC') then
Label7.Color := clMoneyGreen
else red(Label7);
Label7.Hint := reportAllSupportedFeatures(processor);
// '-msse3 -mpopcnt -mcx16 -msahf -mprfchw ',
if processor.hasFeature('POPCNT') then
LabelPOPCNT.Color := clMoneyGreen
else red(LabelPOPCNT);
LabelPOPCNT.Caption := 'POPCNT';
if processor.hasFeature('SSE3') then
LabelSSE3.Color := clMoneyGreen
else red(LabelSSE3);
LabelSSE3.Caption := 'SSE3';
if processor.hasFeature('CMPXCHG16B') then
LabelCX16.Color := clMoneyGreen
else red(LabelCX16);
LabelCX16.Caption := 'CMPXCHG16B';
if processor.hasFeature('SAHF') then
LabelSAHF.Color := clMoneyGreen
else red(LabelSAHF);
LabelSAHF.Caption := 'SAHF';
if processor.hasFeature('PREFETCHW') then
LabelPF.Color := clMoneyGreen
else LabelPF.Color := clCream;
LabelPF.Caption := 'PREFETCHW';
// ---
if processor.hasFeature('SSE4_1') then
LabelSSE4_1.Color := clMoneyGreen
else red(LabelSSE4_1);
LabelSSE4_1.Caption := 'SSE4_1';
if processor.hasFeature('SSE4_2') then
LabelSSE4_2.Color := clMoneyGreen
else red(LabelSSE4_2);
LabelSSE4_2.Caption := 'SSE4_2';
if processor.hasFeature('NX') then
LabelNX.Color := clMoneyGreen
else LabelNX.Color := clCream;
LabelNX.Caption := 'NX';
if processor.hasFeature('AVX') then
LabelAVX.Color := clMoneyGreen
else LabelAVX.Color := clCream;
LabelAVX.Caption := 'AVX';
if processor.hasFeature('PDPE1GB') then
LabelPDPE1GB.Color := clMoneyGreen
else LabelPDPE1GB.Color := clCream;
LabelPDPE1GB.Caption := 'PDPE1GB';
// TODO UEFI/GPT
LabelDISK.Hint := layout;
if pos('(GPT)', LabelDISK.Hint) > 1 then begin
LabelDISK.Color := clMoneyGreen;
LabelDISK.Caption := 'GPT partition scheme';
end else begin
red(LabelDISK);
LabelDISK.Caption := 'MBR partition scheme';
end;
Button1.Visible := false;
LabelResult.Visible := true;
if bad then begin
LabelResult.Color := $009D9DFF;
LabelResult.Caption := 'Your device is too old to run Greentea OS';
end else begin
LabelResult.Color := $00DADAB6;
LabelResult.Caption := 'Your device is compatible with Greentea OS';
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Clipboard.AsText :=
Label7.Caption + ''#13#10'' +
Label1.Caption + ''#13#10'' +
Label2.Caption + ''#13#10'' +
Label4.Caption + ''#13#10'' +
LabelDISK.Caption + ''#13#10'' +
LabelPOPCNT.Caption + ''#13#10'' +
LabelSSE3.Caption + ''#13#10'' +
LabelCX16.Caption + ''#13#10'' +
LabelSAHF.Caption + ''#13#10'' +
LabelPF.Caption + ''#13#10'' +
Label7.Hint + ''#13#10''
;
end;
procedure TForm1.Image1Click(Sender: TObject);
var
found: boolean;
begin
found := OpenURL('https://greenteaos.github.io');
end;
procedure TForm1.Label6Click(Sender: TObject);
begin
end;
end.