wok diff 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 (19 months ago) |
parents | |
children | e92394c9bae5 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/memtest/stuff/memtest86+-6-386.patch Mon Feb 13 17:17:56 2023 +0000 1.3 @@ -0,0 +1,149 @@ 1.4 +--- system/cpuinfo.c 1.5 ++++ system/cpuinfo.c 1.6 +@@ -848,6 +848,12 @@ 1.7 + default: 1.8 + // Unknown processor - make a guess at the family. 1.9 + switch (cpuid_info.version.family) { 1.10 ++ case 3: 1.11 ++ cpu_model = "386"; 1.12 ++ break; 1.13 ++ case 4: 1.14 ++ cpu_model = "486"; 1.15 ++ break; 1.16 + case 5: 1.17 + cpu_model = "586"; 1.18 + break; 1.19 +--- system/cpuid.c 1.20 ++++ system/cpuid.c 1.21 +@@ -8,6 +8,27 @@ 1.22 + #include <stdint.h> 1.23 + 1.24 + #include "cpuid.h" 1.25 ++#include "config.h" 1.26 ++ 1.27 ++#define AC_BIT (1<<18) 1.28 ++#define CPUID_BIT (1<<21) 1.29 ++static inline int has_cpuid(int bits) 1.30 ++{ 1.31 ++ int eax, edx; 1.32 ++ __asm__ __volatile__( 1.33 ++ "pushfl\n\t" 1.34 ++ "popl %0\n\t" 1.35 ++ "movl %0,%1\n\t" 1.36 ++ "xorl %2,%0\n\t" 1.37 ++ "pushl %0\n\t" 1.38 ++ "popfl\n\t" 1.39 ++ "pushfl\n\t" 1.40 ++ "popl %0\n\t" 1.41 ++ "pushl %1\n\t" 1.42 ++ "popfl\n\t" 1.43 ++ "xorl %1,%0":"=a" (eax),"=d" (edx):"c" (bits)); 1.44 ++ return eax; 1.45 ++} 1.46 + 1.47 + //------------------------------------------------------------------------------ 1.48 + // Public Variables 1.49 +@@ -24,6 +45,17 @@ 1.50 + uint32_t reg[4]; 1.51 + char *p, *q; 1.52 + 1.53 ++ switch (has_cpuid(AC_BIT|CPUID_BIT)) { 1.54 ++ case 0: 1.55 ++ cpuid_info.version.family = 3; 1.56 ++ pause_at_start = false; 1.57 ++ return; 1.58 ++ case AC_BIT: 1.59 ++ cpuid_info.version.family = 4; 1.60 ++ pause_at_start = false; 1.61 ++ return; 1.62 ++ } 1.63 ++ 1.64 + // Get the max standard cpuid & vendor ID. 1.65 + cpuid(0x0, 0, 1.66 + &cpuid_info.max_cpuid, 1.67 +--- boot/setup.S 1.68 ++++ boot/setup.S 1.69 +@@ -100,6 +100,29 @@ 1.70 + .long 0x10 1.71 + 1.72 + do_setup: 1.73 ++ 1.74 ++ # Check cpuid support 1.75 ++ 1.76 ++ pushfl 1.77 ++ popw %dx 1.78 ++ popw %ax 1.79 ++ xorb $0x20, %al # toggle CPUID feature bit (21) 1.80 ++ pushw %ax 1.81 ++ pushw %dx 1.82 ++ popfl 1.83 ++ pushfl 1.84 ++ popw %dx 1.85 ++ popw %ax 1.86 ++ xorb %dl, %al 1.87 ++ and $0x20, %al 1.88 ++ jz 1f 1.89 ++ movw $0x1000, %ax 1.90 ++ movw %ax, %ds 1.91 ++ movb $0xa8, %al # testb $imm %al opcode 1.92 ++ movw %ax, patch1 1.93 ++ movw %ax, patch2 1.94 ++1: 1.95 ++ 1.96 + # Reload the segment registers, except for the stack. 1.97 + 1.98 + movw %cs, %ax 1.99 +--- boot/startup32.S 1.100 ++++ boot/startup32.S 1.101 +@@ -105,6 +105,8 @@ 1.102 + 1.103 + # ...and check if the processor supports long mode. 1.104 + 1.105 ++patch1: 1.106 ++ jmp 1f 1.107 + movl $0x80000000, %eax # check if function 0x80000001 is available 1.108 + pushl %ebx # ebx is overwritten by cpuid 1.109 + cpuid 1.110 +@@ -198,6 +200,8 @@ 1.111 + 1.112 + # Enable PAE if supported. 1.113 + 1.114 ++patch2: 1.115 ++ jmp 1f 1.116 + pushl %ebx # ebx is overwritten by cpuid 1.117 + movl $0x00000001, %eax # test the PAE flag 1.118 + cpuid 1.119 +--- system/cache.h 1.120 ++++ system/cache.h 1.121 +@@ -1,6 +1,7 @@ 1.122 + // SPDX-License-Identifier: GPL-2.0 1.123 + #ifndef CACHE_H 1.124 + #define CACHE_H 1.125 ++#include "cpuid.h" 1.126 + /** 1.127 + * \file 1.128 + * 1.129 +@@ -26,6 +27,7 @@ 1.130 + : "rax", "memory" 1.131 + ); 1.132 + #else 1.133 ++ if (cpuid_info.version.family >= 4) 1.134 + __asm__ __volatile__ ("\t" 1.135 + "movl %%cr0, %%eax \n\t" 1.136 + "orl $0x40000000, %%eax \n\t" /* Set CD */ 1.137 +@@ -53,6 +55,7 @@ 1.138 + : "rax", "memory" 1.139 + ); 1.140 + #else 1.141 ++ // if (cpuid_info.version.family >= 4) 1.142 + __asm__ __volatile__ ("\t" 1.143 + "movl %%cr0, %%eax \n\t" 1.144 + "andl $0x9fffffff, %%eax \n\t" /* Clear CD and NW */ 1.145 +@@ -69,6 +72,7 @@ 1.146 + */ 1.147 + static inline void cache_flush(void) 1.148 + { 1.149 ++ if (cpuid_info.version.family >= 4) 1.150 + __asm__ __volatile__ ("\t" 1.151 + "wbinvd\n" 1.152 + : /* no outputs */