wok view memtest/stuff/memtest86+-6-386.patch @ rev 25511

memtest: 386 support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Feb 13 17:17:56 2023 +0000 (15 months ago)
parents
children e92394c9bae5
line source
1 --- system/cpuinfo.c
2 +++ system/cpuinfo.c
3 @@ -848,6 +848,12 @@
4 default:
5 // Unknown processor - make a guess at the family.
6 switch (cpuid_info.version.family) {
7 + case 3:
8 + cpu_model = "386";
9 + break;
10 + case 4:
11 + cpu_model = "486";
12 + break;
13 case 5:
14 cpu_model = "586";
15 break;
16 --- system/cpuid.c
17 +++ system/cpuid.c
18 @@ -8,6 +8,27 @@
19 #include <stdint.h>
21 #include "cpuid.h"
22 +#include "config.h"
23 +
24 +#define AC_BIT (1<<18)
25 +#define CPUID_BIT (1<<21)
26 +static inline int has_cpuid(int bits)
27 +{
28 + int eax, edx;
29 + __asm__ __volatile__(
30 + "pushfl\n\t"
31 + "popl %0\n\t"
32 + "movl %0,%1\n\t"
33 + "xorl %2,%0\n\t"
34 + "pushl %0\n\t"
35 + "popfl\n\t"
36 + "pushfl\n\t"
37 + "popl %0\n\t"
38 + "pushl %1\n\t"
39 + "popfl\n\t"
40 + "xorl %1,%0":"=a" (eax),"=d" (edx):"c" (bits));
41 + return eax;
42 +}
44 //------------------------------------------------------------------------------
45 // Public Variables
46 @@ -24,6 +45,17 @@
47 uint32_t reg[4];
48 char *p, *q;
50 + switch (has_cpuid(AC_BIT|CPUID_BIT)) {
51 + case 0:
52 + cpuid_info.version.family = 3;
53 + pause_at_start = false;
54 + return;
55 + case AC_BIT:
56 + cpuid_info.version.family = 4;
57 + pause_at_start = false;
58 + return;
59 + }
60 +
61 // Get the max standard cpuid & vendor ID.
62 cpuid(0x0, 0,
63 &cpuid_info.max_cpuid,
64 --- boot/setup.S
65 +++ boot/setup.S
66 @@ -100,6 +100,29 @@
67 .long 0x10
69 do_setup:
70 +
71 + # Check cpuid support
72 +
73 + pushfl
74 + popw %dx
75 + popw %ax
76 + xorb $0x20, %al # toggle CPUID feature bit (21)
77 + pushw %ax
78 + pushw %dx
79 + popfl
80 + pushfl
81 + popw %dx
82 + popw %ax
83 + xorb %dl, %al
84 + and $0x20, %al
85 + jz 1f
86 + movw $0x1000, %ax
87 + movw %ax, %ds
88 + movb $0xa8, %al # testb $imm %al opcode
89 + movw %ax, patch1
90 + movw %ax, patch2
91 +1:
92 +
93 # Reload the segment registers, except for the stack.
95 movw %cs, %ax
96 --- boot/startup32.S
97 +++ boot/startup32.S
98 @@ -105,6 +105,8 @@
100 # ...and check if the processor supports long mode.
102 +patch1:
103 + jmp 1f
104 movl $0x80000000, %eax # check if function 0x80000001 is available
105 pushl %ebx # ebx is overwritten by cpuid
106 cpuid
107 @@ -198,6 +200,8 @@
109 # Enable PAE if supported.
111 +patch2:
112 + jmp 1f
113 pushl %ebx # ebx is overwritten by cpuid
114 movl $0x00000001, %eax # test the PAE flag
115 cpuid
116 --- system/cache.h
117 +++ system/cache.h
118 @@ -1,6 +1,7 @@
119 // SPDX-License-Identifier: GPL-2.0
120 #ifndef CACHE_H
121 #define CACHE_H
122 +#include "cpuid.h"
123 /**
124 * \file
125 *
126 @@ -26,6 +27,7 @@
127 : "rax", "memory"
128 );
129 #else
130 + if (cpuid_info.version.family >= 4)
131 __asm__ __volatile__ ("\t"
132 "movl %%cr0, %%eax \n\t"
133 "orl $0x40000000, %%eax \n\t" /* Set CD */
134 @@ -53,6 +55,7 @@
135 : "rax", "memory"
136 );
137 #else
138 + // if (cpuid_info.version.family >= 4)
139 __asm__ __volatile__ ("\t"
140 "movl %%cr0, %%eax \n\t"
141 "andl $0x9fffffff, %%eax \n\t" /* Clear CD and NW */
142 @@ -69,6 +72,7 @@
143 */
144 static inline void cache_flush(void)
145 {
146 + if (cpuid_info.version.family >= 4)
147 __asm__ __volatile__ ("\t"
148 "wbinvd\n"
149 : /* no outputs */