]> 4ch.mooo.com Git - 16.git/blob - src/lib/doslib/hw/cpu/cpuidext.c
added a bunch of things~ and midi stuff~
[16.git] / src / lib / doslib / hw / cpu / cpuidext.c
1
2 #if defined(TARGET_WINDOWS) && TARGET_MSDOS == 16
3 /* Win16: We're probably on a 386, but we could be on a 286 if Windows 3.1 is in standard mode.
4  *        If the user manages to run us under Windows 3.0, we could also run in 8086 real mode.
5  *        We still do the tests so the Windows API cannot deceive us, but we still need GetWinFlags
6  *        to tell between 8086 real mode + virtual8086 mode and protected mode. */
7 # include <windows.h>
8 # include <toolhelp.h>
9 #endif
10
11 #include <stdio.h>
12 #include <conio.h> /* this is where Open Watcom hides the outp() etc. functions */
13 #include <stdlib.h>
14 #include <string.h>
15 #include <unistd.h>
16 #include <assert.h>
17 #include <fcntl.h>
18 #include <dos.h>
19
20 #include <hw/cpu/cpu.h>
21 #include <hw/dos/dos.h>
22 #include <hw/cpu/cpuidext.h>
23
24 /* DEBUG: Flush out calls that aren't there */
25 #ifdef TARGET_OS2
26 # define int86 ___EVIL___
27 # define ntvdm_RegisterModule ___EVIL___
28 # define ntvdm_UnregisterModule ___EVIL___
29 # define _dos_getvect ___EVIL___
30 # define _dos_setvect ___EVIL___
31 #endif
32
33 #if defined(TARGET_WINDOWS) && TARGET_MSDOS == 16
34 # include <hw/dos/winfcon.h>
35 #endif
36
37 struct cpu_cpuid_ext_info*      cpu_cpuid_ext_info = NULL;
38
39 void cpu_extended_cpuid_info_free() {
40         if (cpu_cpuid_ext_info) free(cpu_cpuid_ext_info);
41         cpu_cpuid_ext_info = NULL;
42 }
43
44 int cpu_extended_cpuid_probe() {
45         struct cpuid_result r={0};
46
47         cpu_extended_cpuid_info_free();
48
49         cpu_cpuid_ext_info = malloc(sizeof(struct cpu_cpuid_ext_info));
50         if (cpu_cpuid_ext_info == NULL) return 0;
51         memset(cpu_cpuid_ext_info,0,sizeof(struct cpu_cpuid_ext_info));
52
53         if (cpu_flags & CPU_FLAG_CPUID) {
54                 /* probe for extended CPUID */
55                 cpu_cpuid(0x80000000UL,&r);
56                 if (r.eax >= 0x80000001UL) {
57                         cpu_cpuid_ext_info->cpuid_max = r.eax;
58                         cpu_flags |= CPU_FLAG_CPUID_EXT;
59
60                         cpu_cpuid(0x80000001UL,&r);
61                         cpu_cpuid_ext_info->features.a.raw[0] = r.eax;
62                         cpu_cpuid_ext_info->features.a.raw[1] = r.ebx;
63                         cpu_cpuid_ext_info->features.a.raw[2] = r.ecx;
64                         cpu_cpuid_ext_info->features.a.raw[3] = r.edx;
65
66                         if (cpu_cpuid_ext_info->cpuid_max >= 0x80000004UL) {
67                                 cpu_cpuid(0x80000002UL,&r);
68                                 ((uint32_t*)cpu_cpuid_ext_info->brand)[0] = r.eax;
69                                 ((uint32_t*)cpu_cpuid_ext_info->brand)[1] = r.ebx;
70                                 ((uint32_t*)cpu_cpuid_ext_info->brand)[2] = r.ecx;
71                                 ((uint32_t*)cpu_cpuid_ext_info->brand)[3] = r.edx;
72
73                                 cpu_cpuid(0x80000003UL,&r);
74                                 ((uint32_t*)cpu_cpuid_ext_info->brand)[4] = r.eax;
75                                 ((uint32_t*)cpu_cpuid_ext_info->brand)[5] = r.ebx;
76                                 ((uint32_t*)cpu_cpuid_ext_info->brand)[6] = r.ecx;
77                                 ((uint32_t*)cpu_cpuid_ext_info->brand)[7] = r.edx;
78
79                                 cpu_cpuid(0x80000004UL,&r);
80                                 ((uint32_t*)cpu_cpuid_ext_info->brand)[8] = r.eax;
81                                 ((uint32_t*)cpu_cpuid_ext_info->brand)[9] = r.ebx;
82                                 ((uint32_t*)cpu_cpuid_ext_info->brand)[10] = r.ecx;
83                                 ((uint32_t*)cpu_cpuid_ext_info->brand)[11] = r.edx;
84
85                                 cpu_cpuid_ext_info->brand[48] = 0;
86                         }
87
88                         if (cpu_cpuid_ext_info->cpuid_max >= 0x80000005UL) {
89                                 cpu_cpuid(0x80000005UL,&r);
90                                 cpu_cpuid_ext_info->cache_tlb.a.raw[0] = r.eax;
91                                 cpu_cpuid_ext_info->cache_tlb.a.raw[1] = r.ebx;
92                                 cpu_cpuid_ext_info->cache_tlb.a.raw[2] = r.ecx;
93                                 cpu_cpuid_ext_info->cache_tlb.a.raw[3] = r.edx;
94                         }
95
96                         if (cpu_cpuid_ext_info->cpuid_max >= 0x80000006UL) {
97                                 cpu_cpuid(0x80000006UL,&r);
98                                 cpu_cpuid_ext_info->cache_tlb_l2.a.raw[0] = r.eax;
99                                 cpu_cpuid_ext_info->cache_tlb_l2.a.raw[1] = r.ebx;
100                                 cpu_cpuid_ext_info->cache_tlb_l2.a.raw[2] = r.ecx;
101                                 cpu_cpuid_ext_info->cache_tlb_l2.a.raw[3] = r.edx;
102                         }
103
104                         if (cpu_cpuid_ext_info->cpuid_max >= 0x80000007UL) {
105                                 cpu_cpuid(0x80000007UL,&r);
106                                 cpu_cpuid_ext_info->apm.a.raw[0] = r.eax;
107                         }
108
109                         if (cpu_cpuid_ext_info->cpuid_max >= 0x80000008UL) {
110                                 cpu_cpuid(0x80000008UL,&r);
111                                 cpu_cpuid_ext_info->longmode.a.raw[0] = r.eax;
112                                 cpu_cpuid_ext_info->longmode.a.raw[1] = r.ebx;
113                                 cpu_cpuid_ext_info->longmode.a.raw[2] = r.ecx;
114                                 cpu_cpuid_ext_info->longmode.a.raw[3] = r.edx;
115                         }
116                 }
117         }
118
119         return (cpu_flags & CPU_FLAG_CPUID_EXT)?1:0;
120 }
121