# HG changeset patch # User Pascal Bellard # Date 1625497516 0 # Node ID 06547d8cf2415af0c7b6f5b54fcb0b68fa555271 # Parent 68cf96abc146bcfca4f68d5cebf102f6babe2404 linld: add cpu detection diff -r 68cf96abc146 -r 06547d8cf241 linld/stuff/src/COMMON.H --- a/linld/stuff/src/COMMON.H Mon Jul 05 15:00:07 2021 +0000 +++ b/linld/stuff/src/COMMON.H Mon Jul 05 15:05:16 2021 +0000 @@ -16,6 +16,7 @@ #define LINUX001 linux 0.01 support #define ELKS elks support #define IPXE ipxe support +#define CPUTYPE detect cpu family and model /* End of the optional features */ #ifdef ISOHOOK @@ -108,12 +109,21 @@ #define vid_mode (cmdnum[1]) // -3 = ask, -2 = Extended VGA, -1 = Normal VGA, n = as "n" was pressed #define topmem (cmdnum[2]) #define base_himem (cmdnum[3]) +#ifdef CPUTYPE +#define skip_alloc (* (char *) &cmdnum[5]) +#define mincpu (* (short *) &cmdnum[6]) +extern unsigned cputype; +#else #define skip_alloc (* (char *) &cmdnum[4]) +#endif +extern u32 cmdnum[5 +#ifdef CPUTYPE + +1 +#endif #ifdef QUICK_BOOT -extern u32 cmdnum[7]; -#else -extern u32 cmdnum[5]; + +2 #endif + ]; extern _fastcall void memcpy_image_kernel(); extern _fastcall void memcpy_image_initrd(); diff -r 68cf96abc146 -r 06547d8cf241 linld/stuff/src/CRTL.ASM --- a/linld/stuff/src/CRTL.ASM Mon Jul 05 15:00:07 2021 +0000 +++ b/linld/stuff/src/CRTL.ASM Mon Jul 05 15:05:16 2021 +0000 @@ -952,8 +952,8 @@ dec bx sub di,dx @@loop: + add di,dx mov si,cx ; s - add di,dx @@match: lodsb ; *s++ or al,20h ; locase @@ -969,12 +969,13 @@ cmp [byte bx],'|' je @@testal jl @@notsw ; } ~ + ;mov dl,1 cmp al,20h ; EOS or 20h jne @@loop ; assume [bx] = '|' @@notsw: mov al,-1 jne @@notopt - jmp @@setnum + jmp @@setnum2 @@testal: cmp al,-1 jz @@loop @@ -1044,10 +1045,11 @@ endif @@end: @@setnum: + mov [di+2],dx +@@setnum2: xchg ax,si - mov [di+2],dx @@done: - mov [di],si + or [di],si xchg ax,di @@nokeyword: pop di si bx diff -r 68cf96abc146 -r 06547d8cf241 linld/stuff/src/JUMP.ASM --- a/linld/stuff/src/JUMP.ASM Mon Jul 05 15:00:07 2021 +0000 +++ b/linld/stuff/src/JUMP.ASM Mon Jul 05 15:05:16 2021 +0000 @@ -25,36 +25,40 @@ ;*************************************************************** macro dos_shutdown - xor si,si + xor bx,bx ifdef QUICK_BOOT extrn _cmdnum:dword -quickboot = (word _cmdnum+20) - cmp si,[quickboot] - mov ds,si + ifdef CPUTYPE +quickboot = (byte _cmdnum+24) + else +quickboot = (byte _cmdnum+20) + endif + cmp bl,[quickboot] + mov ds,bx jne skip_shutdown else - mov ds,si + mov ds,bx endif ifndef NO386 - push [dword si+4] ; save step - mov [word si+4],offset step19 + push [dword bx+4] ; save step + mov [word bx+4],offset step19 else mov ax,offset step19 - xchg ax,[word si+4] - push [word si+6] + xchg ax,[word bx+4] + push [word bx+6] push ax ; save step endif mov [word cs:sssp],sp - ;cmp [byte si+7],0F0h + ;cmp [byte bx+7],0F0h ;jnc notdos - mov [si+6],cs + mov [bx+6],cs pushf pushf pop ax inc ah ; set TF push ax popf - call [dword si+4*19h] + call [dword bx+4*19h] notdos: ifndef NO386 lss sp,[dword cs:sssp] diff -r 68cf96abc146 -r 06547d8cf241 linld/stuff/src/LINLD.CPP --- a/linld/stuff/src/LINLD.CPP Mon Jul 05 15:00:07 2021 +0000 +++ b/linld/stuff/src/LINLD.CPP Mon Jul 05 15:05:16 2021 +0000 @@ -8,11 +8,6 @@ extern char bzimagestr[]; const char* cmdstr[4] = {"auto",bzimagestr,NULL,NULL}; -#ifdef QUICK_BOOT -extern u32 cmdnum[7]; -#else -extern u32 cmdnum[5]; -#endif inline void syntax() { die("Syntax:" NL @@ -22,8 +17,8 @@ #endif "..." NL "vga mode: ask,extended,normal or dec/oct/hex number" NL -#ifdef CPU32 - "-32 for 386+" NL +#ifdef CPUTYPE + "-m mincpu family*256+model" NL #endif #ifdef CPU64 "-64 for cpu64 only" NL @@ -40,6 +35,9 @@ NL NL "Examples:" NL "\tLINLD " "-b 64m " +#ifdef CPUTYPE + "-m 0x600 " +#endif "initrd=rootfs4.gz,rootfs3.gz,rootfs2.gz,rootfs1.gz " "\"cl=root=/dev/null video=-32\"" NL "\tLINLD memtest" @@ -58,12 +56,6 @@ if (!*++argv) syntax(); const char **clp = &cmdline; do { -#ifdef CPU32 - if ((*(u16 *)*argv|2) == 0x332F) { // -32 /32 - extrn char cpu386; - if (cpu386 == 0) exit(); - } -#endif #ifdef CPU64 if ((*(u16 *)*argv|2) == 0x362F) { // -64 /64 if (cpuhaslm() == 0) exit(); @@ -74,11 +66,15 @@ #else if (argstr(*argv,"cl|image|initrd",clp) == (int) clp) continue; #endif + if (argnum(*argv,"root|vga|mem|-b|" +#ifdef CPUTYPE + "-m|" +#endif + "-f~" #ifdef QUICK_BOOT - if (argnum(*argv,"root|vga|mem|-b|-f~-q~-v~",&root_dev) >= (int) &base_himem) continue; -#else - if (argnum(*argv,"root|vga|mem|-b|-f~",&root_dev) >= (int) &base_himem) continue; + "-q~-v~" #endif + ,&root_dev) >= (int) &base_himem) continue; if (fileexist(*argv) != -1) { kernel_name=*argv; continue; @@ -86,6 +82,9 @@ *clp = (const char *) heap_top +1; strcatb((const char *) heap_top,*argv); } while (*++argv); +#ifdef CPUTYPE + if (mincpu > cputype) exit(); +#endif puts(*clp); asm{ xchg ax,bx diff -r 68cf96abc146 -r 06547d8cf241 linld/stuff/src/VCPI.ASM --- a/linld/stuff/src/VCPI.ASM Mon Jul 05 15:00:07 2021 +0000 +++ b/linld/stuff/src/VCPI.ASM Mon Jul 05 15:05:16 2021 +0000 @@ -351,7 +351,11 @@ ;mov [bx+2],ss ifdef QUICK_BOOT extrn _cmdnum:dword + ifdef CPUTYPE +v86boot = (byte _cmdnum+28) + else v86boot = (byte _cmdnum+24) + endif test [v86boot],bh jnz @vm2rm_ret endif diff -r 68cf96abc146 -r 06547d8cf241 linld/stuff/src/_BEG.ASM --- a/linld/stuff/src/_BEG.ASM Mon Jul 05 15:00:07 2021 +0000 +++ b/linld/stuff/src/_BEG.ASM Mon Jul 05 15:05:16 2021 +0000 @@ -11,10 +11,12 @@ include "himem.inc" include "isostate.inc" +CMDNUMCNT = 5 + ifdef CPUTYPE +CMDNUMCNT = CMDNUMCNT+1 + endif ifdef QUICK_BOOT -CMDNUMCNT = 7 - else -CMDNUMCNT = 5 +CMDNUMCNT = CMDNUMCNT+2 endif macro alloc_isostate @@ -78,6 +80,10 @@ ;global _bss_start:byte label _bss_start byte global stktop:byte + ifdef CPUTYPE + global _cputype:word +_cputype dw ? + endif global _cpu386:byte _cpu386 db ? ifdef CPU64 @@ -133,6 +139,13 @@ ;*************************************************************** ; Check for oldies + ifndef NO386 + ifdef CPUTYPE + mov ax,100h + mov cl,32 ; 186+ masks with 31 + shr ax,cl + endif + endif push bx ; < 286 : flags[12..15] are forced 1 popf ; = 286 : flags[12..15] are forced 0, cld, cli pushf ; > 286 : only flags[15] is forced 0 @@ -142,8 +155,15 @@ mov bx,offset msg_badcpu js godie ;it is not a 386+, die else + ifdef CPUTYPE + jc not286 + mov ah,2 +not286: + js jmp_endcpu86 ;it is not a 386+, try ELKS & co + else js endcpu86 ;it is not a 386+, try ELKS & co endif + endif p386 ifdef VCPI mov edx,cs @@ -176,6 +196,7 @@ godie: call near die else +jmp_endcpu86: jmp endcpu86 endif @@ -219,7 +240,11 @@ pushfd pop dx pop ax + ifdef CPUTYPE + xor al,24h ; toggle CPUID feature bit & AC bit + else xor al,20h ; toggle CPUID feature bit 21 (=> pentium+) + endif push ax ; (toggle AC: bit 18 => 486+) push dx popfd @@ -227,9 +252,47 @@ pop dx pop dx xor al,dl ; clear C + ifdef CPUTYPE + cmp al,20h + mov ax,0400h + je is486 + mov ah,3 +is486: + jae set_cputype + xor eax,eax + inc ax + cpuid ; Basic cpuid (late 486 or Pentium) + xor eax,eax + inc ax + cpuid ; again cause of Nasty EMM386s + push eax + bt edx,26 ; sse2 bit + jnc baseInfo + else jne @@no_cpuid ; CPUID feature bit changed ? - mov eax,80000001h ; Extended Processor Info and Feature Bits - cpuid + endif + mov eax,80000001h ; Extended Processor Info and Feature Bits (Pentium 4 or newer) + cpuid ; Extended cpuid (Pentium 4) + ifdef CPUTYPE +baseInfo: + pop ax ; base IDs + and ax,0FF0h ; keep FamilyID & ModelID + pop cx ; extended IDs + mov bx,cx + shr bx,4 ; extended FamilyID in bl + shr al,4 ; set base ModelID + cmp ah,0Fh + jz SetModelID + cmp ah,06h + jnz ModelIDset + db 3Dh ; cmp ax,0DC00h +SetModelID: + add ah,bl ; use extended FamilyID + shl cl,4 + or al,cl ; use extended ModelID +ModelIDset: +set_cputype: + endif mov dl,-1 ; set 386 flag ifdef NO386 db 66h ; mov [_cpu_features],edx @@ -243,6 +306,9 @@ dec [_cpu386] endif endcpu86: + ifdef CPUTYPE + mov [_cputype],ax ; _cputype: FFMM or 0[1-4]00=80[1-4]86 or 0000=8086/8088 + endif p8086 ;*************************************************************** diff -r 68cf96abc146 -r 06547d8cf241 linld/stuff/src/pipehole.awk --- a/linld/stuff/src/pipehole.awk Mon Jul 05 15:00:07 2021 +0000 +++ b/linld/stuff/src/pipehole.awk Mon Jul 05 15:05:16 2021 +0000 @@ -17,6 +17,12 @@ if (/add di,2/) $0=" scasw ; " $0 if (/bx,di/ || /\[bp-2\]/) next sub(/\[bx\],0/,"[di],0") + if (/ptr @exit\$qv/) { + if (gotexit) next + print "call_exit:" + gotexit=1 + } + if (/short @1@422/ && gotexit) $0=" ja call_exit" if (islinld==1) { if (/,word.*/) islinld=0 print "; " $0 @@ -33,7 +39,7 @@ print " mov ax,word ptr [di]" next } - if (/ax,word ptr/) next + if (/ax,word ptr \[/) next } if (/buf_cmdline\+1/) { islinld=5