]> 4ch.mooo.com Git - 16.git/blob - src/lib/doslib/hw/llmem/test.c
added a bunch of things~ and midi stuff~
[16.git] / src / lib / doslib / hw / llmem / test.c
1 /* NOTES:
2  *    This code works perfectly on most test systems I have.
3  *    Some systems do provide interesting insight though when they do fail.
4  *
5  *    Test: Oracle VirtualBox 4.1.8 with 64-bit guest and AMD VT-X acceleration:
6  *    Result: VirtualBox reports PAE and PSE, and 32-bit test program works perfectly.
7  *            The 16-bit real mode builds however, cause the virtual machine to hang
8  *            when attempting to use the PSE method. This hang does not occur when
9  *            AMD VT-x is disabled.
10  *
11  *    Test: Dell netbook with Intel Atom processor
12  *    Result: Processor reports via CPUID that it has 32-bit linear and 32-bit physical
13  *            address space. And it means it. The minute this program steps beyond 4GB,
14  *            the CPU faults and the system resets. This is true regardless of whether
15  *            the 16-bit real mode or the 32-bit protected mode version is used. This is
16  *            true whether you use PSE-36 or PAE.
17  *
18  *            So apparently, they don't do what 386/486/pentium systems USED to do and just
19  *            silently wrap the addresses, eh?
20  *
21  *            That means this code should make use of the "extended CPUID" to read those
22  *            limits and then llmemcpy() should enforce them. */
23
24 #include <stdio.h>
25 #include <conio.h> /* this is where Open Watcom hides the outp() etc. functions */
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <string.h>
29 #include <malloc.h>
30 #include <assert.h>
31 #include <fcntl.h>
32 #include <dos.h>
33
34 #include <hw/cpu/cpu.h>
35 #include <hw/dos/dos.h>
36 #include <hw/llmem/llmem.h>
37 #include <hw/cpu/cpuidext.h>
38
39 static unsigned char temp1[256],temp2[256];
40
41 static void print_contents(unsigned char *t,unsigned int len) {
42         unsigned int x;
43
44         len = (len + 15U) >> 4U;
45         while (len-- > 0) {
46                 printf("    ");
47                 for (x=0;x < 16;x++) printf("%02X ",t[x]);
48                 t += 16;
49                 printf("\n");
50         }
51 }
52
53 static void help() {
54         fprintf(stderr,"Long-Long memory copy test program\n");
55         fprintf(stderr,"llmem [options]\n");
56         fprintf(stderr,"  /PAE        Prefer PAE if both are available\n");
57         fprintf(stderr,"  /PSE        Prefer PSE if both are available\n");
58 }
59
60 int main(int argc,char **argv) {
61         int i,pref_pse=0,pref_pae=0;
62         char *a;
63
64         for (i=1;i < argc;) {
65                 a = argv[i++];
66
67                 if (*a == '/' || *a == '-') {
68                         do { a++; } while (*a == '/' || *a == '-');
69
70                         if (!strcmp(a,"h") || !strcmp(a,"help")) {
71                                 help();
72                                 return 1;
73                         }
74                         else if (!strcmp(a,"pse")) {
75                                 pref_pse=1;
76                         }
77                         else if (!strcmp(a,"pae")) {
78                                 pref_pae=1;
79                         }
80                         else {
81                                 help();
82                                 return 1;
83                         }
84                 }
85                 else {
86                         fprintf(stderr,"Unknown arg '%s'\n",a);
87                         return 1;
88                 }
89         }
90
91         if (!llmem_init()) {
92                 printf("Your system is not suitable to use with the Long-Long memory access library\n");
93                 printf("Reason: %s\n",llmem_reason);
94                 return 1;
95         }
96
97         if (pref_pse && llmem_meth_pse)
98                 llmem_meth_pae = 0;
99         if (pref_pae && llmem_meth_pae)
100                 llmem_meth_pse = 0;
101
102         printf("Long-Long memory access is usable on this machine.\n");
103         printf("  - PSE method: %d\n",llmem_meth_pse);
104         printf("  - PAE method: %d\n",llmem_meth_pae);
105
106         memset(temp1,0xAA,sizeof(temp1));
107         if (llmemcpy(llmem_ptr2ofs(temp1),0x000000000UL,256UL)) { /* At lowest address */
108                 printf("Memory @ 0MB:\n");
109                 print_contents(temp1,256);
110         }
111         else {
112                 printf("! Cannot read memory @ 0MB: '%s'\n",llmem_reason);
113         }
114         while (getch() != 13);
115
116         memset(temp1,0xAA,sizeof(temp1));
117         if (llmemcpy(llmem_ptr2ofs(temp1),0xFFFFFF00UL,256UL)) { /* Just below the 4GB boundary */
118                 printf("Memory @ 4096MB-256b:\n");
119                 print_contents(temp1,256);
120         }
121         else {
122                 printf("! Cannot read memory @ 4096MB-256B: '%s'\n",llmem_reason);
123         }
124         while (getch() != 13);
125
126         memset(temp2,0xAA,sizeof(temp2));
127         if (llmemcpy(llmem_ptr2ofs(temp2),0x100000000UL,256UL)) { /* At the 4GB boundary */
128                 printf("Memory @ 4096MB:\n");
129                 print_contents(temp2,256);
130         }
131         else {
132                 printf("! Cannot read memory @ 4096MB: '%s'\n",llmem_reason);
133         }
134         while (getch() != 13);
135
136         memset(temp2,0xAA,sizeof(temp2));
137         if (llmemcpy(llmem_ptr2ofs(temp2),0x200000000UL,256UL)) { /* At the 8GB boundary */
138                 printf("Memory @ 8192MB:\n");
139                 print_contents(temp2,256);
140         }
141         else {
142                 printf("! Cannot read memory @ 8192MB: '%s'\n",llmem_reason);
143         }
144         while (getch() != 13);
145
146         llmemcpy_free();
147         cpu_extended_cpuid_info_free();
148         return 0;
149 }
150