Parolin 0.7.9 6796
Console (soon DLLs) to do a tar like job
Loading...
Searching...
No Matches
cpu_fixed_z.c
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
3 #2023 X March 21 19:50 PM Brasília Time
4
5* *
6* Licensa de Copia (C) <2024> <Aurora Boreal> *
7* *
8* Este programa e software livre: voce pode redistribuir isto e/ou *
9* modificar isto sobre os termos do GNU Licensa Geral Pública como 25
10* publicado pela Fundacao de Software Livre, tanto a versão 3 da *
11* Licensa, ou (dependendo da sua opcao) qualquer versao posterior. *
12* *
13* Este programa e distribuido na esperanca que isto vai ser util, *
14* mas SEM QUALQUER GARANTIA; sem ate mesmo a implicada garantia de *
15* COMERCIALIZAcaO ou CABIMENTO PARA UM FIM PARTICULAR. Veja a *
16* Licensa Geral Publica para mais detalhes. *
17* *
18* Você deve ter recebido uma cópia da LICENSA GERAL PUBLICA e a GNU *
19* Licensa Publica Menor junto com este programa *
20* Se não, veja <http://www.gnu.org/licenses/>. *
21* *
22* Suporte: sourceforge.net github.com *
23* *
24* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
25
26* Pereira: arsoftware25@gmail.com ricardo@arsoftware.net.br *
27* xcx: arsoftware10@gmail.com charli@arsoftware.net.br *
28 Yasmin: yasmin@arsoftware.net.br *
29 pereira1001@users.sourceforge.net
30 */
31
32
33#ifndef INCLUDEUCHAR
34#ifndef uchar
35#define uchar unsigned char
36#define uint unsigned int
37#define ulong unsigned long
38#define ushort unsigned short
39#endif
40#endif
41
42#include <windows.h>
43#include <stdint.h>
44#include <stdio.h>
45#include <stdlib.h>
46#include <string.h>
47#include <time.h>
48#include <errno.h>
49#include <fcntl.h>
50#include <ctype.h>
51#include <math.h>
52#include <wctype.h>
53#include <wchar.h>
54#include <stdarg.h>
55#include <stddef.h>
56#include <setjmp.h>
57#include <locale.h>
58#include <signal.h>
59#include <limits.h>
60#include <float.h>
61#include <iso646.h>
62
63#undef NDEBUG
64#include <assert.h>
65
66#include <cpuid.h>
67
68int __stdcall hasSSE2 (void);
69int __stdcall hasSSE (void);
70
72
73
79int getcpuinfo (int aeax, int *oEAX, int *oEBX, int *oECX, int *oEDX)
80{
81 int iebx = 0;
82 int iecx = 0;
83 int iedx = 0;
84 int ieax = 0;
85
86/*
87
88 //for historical reasons
89 __try
90 {
91
92
93 __asm
94 {
95
96 mov eax, aeax;
97 cpuid;
98 mov ieax, eax;
99 mov iebx, ebx;
100 mov iedx, edx;
101 mov iecx, ecx;
102
103 }
104
105 }
106 __except (1)
107 {
108 // dprintf ("Invalid CPU code \n");
109
110 retvalue = 1;
111 }
112 */
113
114 __cpuid(aeax, ieax, iebx, iecx, iedx);
115
116 *oECX = iecx;
117 *oEDX = iedx;
118 *oEBX = iebx;
119 *oEAX = ieax;
120
121 return 0;
122
123}
124
126{
127
128 int iebx = 0;
129 int iecx = 0;
130 int iedx = 0;
131 int ieax = 0;
132 static char fixo[255];
133
134 memset (fixo, 0, 254);
135
136 if (getcpuinfo (0x80000000, &ieax, &iebx, &iecx, &iedx))
137 {
138 strcpy (fixo, "Unavailable");
139 goto final;
140 }
141
142 if ((int)ieax < (int)0x80000004)
143 {
144 strcpy (fixo, "Unavailable");
145 goto final;
146 }
147
148 if (getcpuinfo (0x80000002, &ieax, &iebx, &iecx, &iedx))
149 {
150 strcpy (fixo, "Unavailable");
151 goto final;
152 }
153 else
154 {
155 memcpy (&fixo[0], &ieax, 4);
156 memcpy (&fixo[4], &iebx, 4);
157 memcpy (&fixo[8], &iecx, 4);
158 memcpy (&fixo[12], &iedx, 4);
159 }
160
161 if (getcpuinfo (0x80000003, &ieax, &iebx, &iecx, &iedx))
162 {
163 strcpy (fixo, "Unavailable");
164 goto final;
165 }
166 else
167 {
168 memcpy (&fixo[16], &ieax, 4);
169 memcpy (&fixo[20], &iebx, 4);
170 memcpy (&fixo[24], &iecx, 4);
171 memcpy (&fixo[28], &iedx, 4);
172 }
173
174 if (getcpuinfo (0x80000004, &ieax, &iebx, &iecx, &iedx))
175 {
176 strcpy (fixo, "Unavailable");
177 goto final;
178 }
179 else
180 {
181 memcpy (&fixo[32], &ieax, 4);
182 memcpy (&fixo[36], &iebx, 4);
183 memcpy (&fixo[40], &iecx, 4);
184 memcpy (&fixo[44], &iedx, 4);
185 }
186
187 if(hasSSE ())
188 {
189 strcat(fixo, ", SSE");
190 }
191 if(hasSSE2())
192 {
193 strcat(fixo, ", SSE2");
194 }
195
196final:
197 return fixo;
198
199}
200
201int __stdcall getcputype (int *family, int *model, int *stepping)
202{
203
204
205 int iebx = 0;
206 int iecx = 0;
207 int iedx = 0;
208 int ieax = 0;
209
210 if (getcpuinfo (1, &ieax, &iebx, &iecx, &iedx))
211 {
212
213 *family = 0;
214 *model = 0;
215 *stepping = 0;
216 return 1;
217
218 }
219
220 *stepping = (ieax & 15);
221
222 *model = ieax >> 4;
223 *model = (*model & 15);
224
225
226 *family = ieax >> 8;
227 *family = (*family & 15);
228
229 return 0;
230
231}
232
233char *getcpuname_k (void)
234{
235
236 int iebx = 0;
237 int iecx = 0;
238 int iedx = 0;
239 int ieax = 0;
240 static char fixo[255];
241
242 memset (fixo, 0, 254);
243
244 if (getcpuinfo (0, &ieax, &iebx, &iecx, &iedx))
245 {
246 strcpy (fixo, "Unavailable");
247 }
248 else
249 {
250 memcpy (&fixo[0], &iebx, 4);
251 memcpy (&fixo[4], &iedx, 4);
252 memcpy (&fixo[8], &iecx, 4);
253 }
254
255
256 return fixo;
257
258}
259
260int __stdcall hasMMX ()
261{
262
263 int iebx = 0;
264 int iecx = 0;
265 int iedx = 0;
266 int ieax = 0;
267
268 if (getcpuinfo (1, &ieax, &iebx, &iecx, &iedx))
269 {
270 return 0;
271 }
272
273
274
275 if (iedx & (1 << 23))
276 {
277 return 1;
278 }
279 return 0;
280
281}
282
283int __stdcall hasSSE ()
284{
285
286 int iebx = 0;
287 int iecx = 0;
288 int iedx = 0;
289 int ieax = 0;
290
291 if (getcpuinfo (1, &ieax, &iebx, &iecx, &iedx))
292 {
293 return 0;
294 }
295
296 if (iedx & (1 << 25))
297 {
298 return 1;
299 }
300 return 0;
301
302}
303
304int __stdcall hasSSE2 ()
305{
306
307 int iebx = 0;
308 int iecx = 0;
309 int iedx = 0;
310 int ieax = 0;
311
312 if (getcpuinfo (1, &ieax, &iebx, &iecx, &iedx))
313 {
314 return 0;
315 }
316
317 if (iedx & (1 << 26))
318 {
319 return 1;
320 }
321 return 0;
322
323}
324
325int __stdcall has3DNOW ()
326{
327
328 int iebx = 0;
329 int iecx = 0;
330 int iedx = 0;
331 int ieax = 0;
332
333 if (getcpuinfo (0x80000001, &ieax, &iebx, &iecx, &iedx))
334 {
335 return 0;
336 }
337
338 if (iedx & (1 << 31))
339 {
340 return 1;
341 }
342 return 0;
343
344}
345
346int __stdcall has3DNOWExtensions ()
347{
348
349 int iebx = 0;
350 int iecx = 0;
351 int iedx = 0;
352 int ieax = 0;
353
354 if (getcpuinfo (0x80000001, &ieax, &iebx, &iecx, &iedx))
355 {
356 return 0;
357 }
358
359 if (iedx & (1 << 30))
360 {
361 return 1;
362 }
363 return 0;
364
365}
366
367int __stdcall IsAMD64 ()
368{
369
370 int iebx = 0;
371 int iecx = 0;
372 int iedx = 0;
373 int ieax = 0;
374
375 if (getcpuinfo (0x80000001, &ieax, &iebx, &iecx, &iedx))
376 {
377 return 0;
378 }
379
380 if (iedx & (1 << 29))
381 {
382 return 1;
383 }
384 return 0;
385
386}
387
388int __stdcall hasCMOV ()
389{
390
391 int iebx = 0;
392 int iecx = 0;
393 int iedx = 0;
394 int ieax = 0;
395
396 if (getcpuinfo (1, &ieax, &iebx, &iecx, &iedx))
397 {
398 return 0;
399 }
400
401 if (iedx & (1 << 15))
402 {
403 return 1;
404 }
405 return 0;
406
407}
408
409int __stdcall hasHyperThreading ()
410{
411
412 int iebx = 0;
413 int iecx = 0;
414 int iedx = 0;
415 int ieax = 0;
416
417 if (getcpuinfo (1, &ieax, &iebx, &iecx, &iedx))
418 {
419 return 0;
420 }
421
422 if (iedx & (1 << 28))
423 {
424 return 1;
425 }
426 return 0;
427
428}
429
430int __stdcall hasFPU ()
431{
432
433 int iebx = 0;
434 int iecx = 0;
435 int iedx = 0;
436 int ieax = 0;
437
438 if (getcpuinfo (1, &ieax, &iebx, &iecx, &iedx))
439 {
440 return 0;
441 }
442
443 if (iedx & (1))
444 {
445 return 1;
446 }
447 return 0;
448
449}
450
451int __stdcall getcpuextendedfeature (int *eisst, int *tm2, int *ci)
452{
453
454 int iebx = 0;
455 int iecx = 0;
456 int iedx = 0;
457 int ieax = 0;
458
459 if (getcpuinfo (1, &ieax, &iebx, &iecx, &iedx))
460 {
461 return 1;
462 }
463
464 *eisst = 0;
465
466 if (iecx & (1 << 7))
467 {
468 *eisst = 1;
469 }
470
471 *tm2 = 0;
472
473 if (iecx & (1 << 8))
474 {
475 *tm2 = 1;
476 }
477
478 *ci = 0;
479
480 if (iecx & (1 << 10))
481 {
482 *ci = 1;
483 }
484
485 return 0;
486
487}
488
489#if 0
490int main ()
491{
492
493 int iebx = 0;
494 int iecx = 0;
495 int iedx = 0;
496 int ieax = 0;
497
498 getcpuinfo (0, &ieax, &iebx, &iecx, &iedx);
499#ifdef NPRINTF
500 dprintf ("Valores eax , ebx , ecx ,edx %x %x %x %x \n", ieax, iebx, iecx, iedx);
501#endif
502
503 getcpuinfo (1, &ieax, &iebx, &iecx, &iedx);
504#ifdef NPRINTF
505 dprintf ("01 eax , ebx , ecx ,edx %x %x %x %x \n", ieax, iebx, iecx, iedx);
506#endif
507 getcpuinfo (2, &ieax, &iebx, &iecx, &iedx);
508#ifdef NPRINTF
509 dprintf ("02 eax , ebx , ecx ,edx %x %x %x %x \n", ieax, iebx, iecx, iedx);
510#endif
511 getcpuinfo (3, &ieax, &iebx, &iecx, &iedx);
512#ifdef NPRINTF
513 dprintf ("03 eax , ebx , ecx ,edx %x %x %x %x \n", ieax, iebx, iecx, iedx);
514#endif
515 getcpuinfo (0x80000000, &ieax, &iebx, &iecx, &iedx);
516#ifdef NPRINTF
517 dprintf ("0x80000000 eax , ebx , ecx ,edx %x %x %x %x \n", ieax, iebx, iecx, iedx);
518#endif
519
520 getcpuinfo (0x80000001, &ieax, &iebx, &iecx, &iedx);
521#ifdef NPRINTF
522 dprintf ("81 eax , ebx , ecx ,edx %x %x %x %x \n", ieax, iebx, iecx, iedx);
523#endif
524
525 getcpuinfo (0x80000002, &ieax, &iebx, &iecx, &iedx);
526#ifdef NPRINTF
527 dprintf ("82 eax , ebx , ecx ,edx %x %x %x %x \n", ieax, iebx, iecx, iedx);
528#endif
529
530 getcpuinfo (0x80000003, &ieax, &iebx, &iecx, &iedx);
531#ifdef NPRINTF
532 dprintf ("83 eax , ebx , ecx ,edx %x %x %x %x \n", ieax, iebx, iecx, iedx);
533#endif
534 getcpuinfo (0x80000004, &ieax, &iebx, &iecx, &iedx);
535#ifdef NPRINTF
536 dprintf ("84 eax , ebx , ecx ,edx %x %x %x %x \n", ieax, iebx, iecx, iedx);
537#endif
538 getcpuinfo (0x80000005, &ieax, &iebx, &iecx, &iedx);
539#ifdef NPRINTF
540 dprintf ("85 eax , ebx , ecx ,edx %x %x %x %x \n", ieax, iebx, iecx, iedx);
541#endif
542
543 getcpuinfo (0x80000006, &ieax, &iebx, &iecx, &iedx);
544#ifdef NPRINTF
545 dprintf ("86 eax , ebx , ecx ,edx %x %x %x %x \n", ieax, iebx, iecx, iedx);
546#endif
547 getcpuinfo (0x80000007, &ieax, &iebx, &iecx, &iedx);
548#ifdef NPRINTF
549 dprintf ("87 eax , ebx , ecx ,edx %x %x %x %x \n", ieax, iebx, iecx, iedx);
550#endif
551 getcpuinfo (0x80000008, &ieax, &iebx, &iecx, &iedx);
552#ifdef NPRINTF
553 dprintf ("88 eax , ebx , ecx ,edx %x %x %x %x \n", ieax, iebx, iecx, iedx);
554
555 dprintf ("Namoe do processador -%s- \n", getprocessorbrandstring ());
556
557 dprintf ("Namoe do processador -%s- \n", getcpuname ());
558#endif
559 {
560 int model;
561 int family;
562 int stepping;
563 int ret;
564
565 ret = getcputype (&family, &model, &stepping);
566
567 if (ret)
568 {
569#ifdef NPRINTF
570 dprintf ("Error getting type of processor \n");
571#endif
572 }
573 else
574 {
575#ifdef NPRINTF
576 dprintf ("Family %d \n", family);
577 dprintf ("Model %d \n", model);
578 dprintf ("Stepping %d \n", stepping);
579#endif
580 }
581
582 }
583
584#ifdef NPRINTF
585 dprintf ("Valor binarion %s \n", decimalparabinarioprintf (1 << 10));
586#endif
587
588 {
589
590 int ss;
591 int ci;
592 int mt2;
593
594 getcpuextendedfeature (&ss, &mt2, &ci);
595 }
596#ifdef NPRINTF
597 dprintf ("Has MMX %d \n", hasMMX ());
598 dprintf ("Has SSE %d \n", hasSSE ());
599 dprintf ("Has SSE2 %d \n", hasSSE2 ());
600 dprintf ("Has CMOV %d \n", hasCMOV ());
601 dprintf ("Has FPU %d \n", hasFPU ());
602 dprintf ("Has 3DNOW! %d \n", has3DNOW ());
603 dprintf ("Has 3DNOW! extensions %d \n", has3DNOWExtensions ());
604 dprintf ("Has IsAMD64 %d \n", IsAMD64 ());
605 dprintf ("Has OShasSSEsupport %d \n", OShasSSEsupport ());
606#endif
607 return 0;
608}
609#endif
610
621int __amandacall get_cpu_data_z(char * the_data_z)
622{
623 static char out_z[300] = {0, };
624
625 if(0 == strlen(out_z))
626 {
627 strcpy(out_z, getprocessorbrandstring_k());
628 strcat(out_z, ", " );
629 strcat(out_z, getcpuname_k() );
630 strcat(out_z, ", " );
631 strcat(out_z, cpu_speed_z() );
632 }
633
634 strcpy(the_data_z, out_z );
635 return 0;
636}
void dprintf(char *format,...)
Definition dprintf.c:96
int __stdcall hasSSE2(void)
Definition cpu_fixed_z.c:304
int __amandacall get_cpu_data_z(char *the_data_z)
Definition cpu_fixed_z.c:621
int __stdcall has3DNOWExtensions()
Definition cpu_fixed_z.c:346
int __stdcall hasMMX()
Definition cpu_fixed_z.c:260
int __stdcall getcpuextendedfeature(int *eisst, int *tm2, int *ci)
Definition cpu_fixed_z.c:451
char * getcpuname_k(void)
Definition cpu_fixed_z.c:233
char * getprocessorbrandstring_k(void)
Definition cpu_fixed_z.c:125
int getcpuinfo(int aeax, int *oEAX, int *oEBX, int *oECX, int *oEDX)
Definition cpu_fixed_z.c:79
int __stdcall hasCMOV()
Definition cpu_fixed_z.c:388
int __stdcall hasHyperThreading()
Definition cpu_fixed_z.c:409
int __stdcall hasFPU()
Definition cpu_fixed_z.c:430
int __stdcall IsAMD64()
Definition cpu_fixed_z.c:367
#define uint
Definition cpu_fixed_z.c:36
int __stdcall hasSSE(void)
Definition cpu_fixed_z.c:283
int __stdcall has3DNOW()
Definition cpu_fixed_z.c:325
char * decimalparabinarioprintf(uint value)
int __stdcall getcputype(int *family, int *model, int *stepping)
Definition cpu_fixed_z.c:201
int main()
Definition dirent_ronkko.h:938
#define __amandacall
Definition tar_1_33.c:79
char *__amandacall cpu_speed_z(void)
Definition tar_1_33.c:7979
ret
Definition zlib_interface.c:30