# HG changeset patch # User Pascal Bellard # Date 1676308676 0 # Node ID be6d30fe521d0dc14ebfc7a09e5561b278b1798b # Parent 69e1e705f038a9baeab136d08e2aa0b1449517c8 memtest: 386 support diff -r 69e1e705f038 -r be6d30fe521d memtest/receipt --- a/memtest/receipt Sun Feb 12 20:36:56 2023 +0000 +++ b/memtest/receipt Mon Feb 13 17:17:56 2023 +0000 @@ -67,11 +67,15 @@ compile_rules() { # Need CPUID instruction (586+ cpu) - sed -i 's|64, MT_VERSION "." GIT_HASH|65, MT_VERSION ".SliTaz"|;s|"\.x32"|".586"|' app/display.c - sed 's|gcc|gcc-83|' -i build32/Makefile + sed -i 's|64, MT_VERSION "." GIT_HASH|65, MT_VERSION ".SliTaz"|;s|"\.x32"|".386"|' app/display.c + sed 's|gcc|gcc-83|;s|march=i586|march=i486|' -i build32/Makefile + patch -p0 < $stuff/memtest86\+-6-386.patch cd build32 + make boot/startup.o + objdump -t boot/startup.o | \ + awk '/patch/ { print "sed -i \"s|" $5 "|0x" $1 "|\" ../boot/setup.S" }' | sh make memtest.bin - tune_lzma memtest.bin 122,mf=bt4 LC 3 PB 2 + tune_lzma memtest.bin 161,mf=bt2 LC 3 PB 2 } diff -r 69e1e705f038 -r be6d30fe521d memtest/stuff/memtest86+-6-386.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/memtest/stuff/memtest86+-6-386.patch Mon Feb 13 17:17:56 2023 +0000 @@ -0,0 +1,149 @@ +--- system/cpuinfo.c ++++ system/cpuinfo.c +@@ -848,6 +848,12 @@ + default: + // Unknown processor - make a guess at the family. + switch (cpuid_info.version.family) { ++ case 3: ++ cpu_model = "386"; ++ break; ++ case 4: ++ cpu_model = "486"; ++ break; + case 5: + cpu_model = "586"; + break; +--- system/cpuid.c ++++ system/cpuid.c +@@ -8,6 +8,27 @@ + #include + + #include "cpuid.h" ++#include "config.h" ++ ++#define AC_BIT (1<<18) ++#define CPUID_BIT (1<<21) ++static inline int has_cpuid(int bits) ++{ ++ int eax, edx; ++ __asm__ __volatile__( ++ "pushfl\n\t" ++ "popl %0\n\t" ++ "movl %0,%1\n\t" ++ "xorl %2,%0\n\t" ++ "pushl %0\n\t" ++ "popfl\n\t" ++ "pushfl\n\t" ++ "popl %0\n\t" ++ "pushl %1\n\t" ++ "popfl\n\t" ++ "xorl %1,%0":"=a" (eax),"=d" (edx):"c" (bits)); ++ return eax; ++} + + //------------------------------------------------------------------------------ + // Public Variables +@@ -24,6 +45,17 @@ + uint32_t reg[4]; + char *p, *q; + ++ switch (has_cpuid(AC_BIT|CPUID_BIT)) { ++ case 0: ++ cpuid_info.version.family = 3; ++ pause_at_start = false; ++ return; ++ case AC_BIT: ++ cpuid_info.version.family = 4; ++ pause_at_start = false; ++ return; ++ } ++ + // Get the max standard cpuid & vendor ID. + cpuid(0x0, 0, + &cpuid_info.max_cpuid, +--- boot/setup.S ++++ boot/setup.S +@@ -100,6 +100,29 @@ + .long 0x10 + + do_setup: ++ ++ # Check cpuid support ++ ++ pushfl ++ popw %dx ++ popw %ax ++ xorb $0x20, %al # toggle CPUID feature bit (21) ++ pushw %ax ++ pushw %dx ++ popfl ++ pushfl ++ popw %dx ++ popw %ax ++ xorb %dl, %al ++ and $0x20, %al ++ jz 1f ++ movw $0x1000, %ax ++ movw %ax, %ds ++ movb $0xa8, %al # testb $imm %al opcode ++ movw %ax, patch1 ++ movw %ax, patch2 ++1: ++ + # Reload the segment registers, except for the stack. + + movw %cs, %ax +--- boot/startup32.S ++++ boot/startup32.S +@@ -105,6 +105,8 @@ + + # ...and check if the processor supports long mode. + ++patch1: ++ jmp 1f + movl $0x80000000, %eax # check if function 0x80000001 is available + pushl %ebx # ebx is overwritten by cpuid + cpuid +@@ -198,6 +200,8 @@ + + # Enable PAE if supported. + ++patch2: ++ jmp 1f + pushl %ebx # ebx is overwritten by cpuid + movl $0x00000001, %eax # test the PAE flag + cpuid +--- system/cache.h ++++ system/cache.h +@@ -1,6 +1,7 @@ + // SPDX-License-Identifier: GPL-2.0 + #ifndef CACHE_H + #define CACHE_H ++#include "cpuid.h" + /** + * \file + * +@@ -26,6 +27,7 @@ + : "rax", "memory" + ); + #else ++ if (cpuid_info.version.family >= 4) + __asm__ __volatile__ ("\t" + "movl %%cr0, %%eax \n\t" + "orl $0x40000000, %%eax \n\t" /* Set CD */ +@@ -53,6 +55,7 @@ + : "rax", "memory" + ); + #else ++ // if (cpuid_info.version.family >= 4) + __asm__ __volatile__ ("\t" + "movl %%cr0, %%eax \n\t" + "andl $0x9fffffff, %%eax \n\t" /* Clear CD and NW */ +@@ -69,6 +72,7 @@ + */ + static inline void cache_flush(void) + { ++ if (cpuid_info.version.family >= 4) + __asm__ __volatile__ ("\t" + "wbinvd\n" + : /* no outputs */