wok diff linld/stuff/src/_BEG.ASM @ rev 24067
linld: add cpu detection
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Mon Jul 05 15:05:16 2021 +0000 (2021-07-05) |
parents | 324b3fa82b76 |
children | 3e2a0347b2f1 |
line diff
1.1 --- a/linld/stuff/src/_BEG.ASM Mon May 24 11:24:29 2021 +0000 1.2 +++ b/linld/stuff/src/_BEG.ASM Mon Jul 05 15:05:16 2021 +0000 1.3 @@ -11,10 +11,12 @@ 1.4 include "himem.inc" 1.5 include "isostate.inc" 1.6 1.7 +CMDNUMCNT = 5 1.8 + ifdef CPUTYPE 1.9 +CMDNUMCNT = CMDNUMCNT+1 1.10 + endif 1.11 ifdef QUICK_BOOT 1.12 -CMDNUMCNT = 7 1.13 - else 1.14 -CMDNUMCNT = 5 1.15 +CMDNUMCNT = CMDNUMCNT+2 1.16 endif 1.17 1.18 macro alloc_isostate 1.19 @@ -78,6 +80,10 @@ 1.20 ;global _bss_start:byte 1.21 label _bss_start byte 1.22 global stktop:byte 1.23 + ifdef CPUTYPE 1.24 + global _cputype:word 1.25 +_cputype dw ? 1.26 + endif 1.27 global _cpu386:byte 1.28 _cpu386 db ? 1.29 ifdef CPU64 1.30 @@ -133,6 +139,13 @@ 1.31 ;*************************************************************** 1.32 1.33 ; Check for oldies 1.34 + ifndef NO386 1.35 + ifdef CPUTYPE 1.36 + mov ax,100h 1.37 + mov cl,32 ; 186+ masks with 31 1.38 + shr ax,cl 1.39 + endif 1.40 + endif 1.41 push bx ; < 286 : flags[12..15] are forced 1 1.42 popf ; = 286 : flags[12..15] are forced 0, cld, cli 1.43 pushf ; > 286 : only flags[15] is forced 0 1.44 @@ -142,8 +155,15 @@ 1.45 mov bx,offset msg_badcpu 1.46 js godie ;it is not a 386+, die 1.47 else 1.48 + ifdef CPUTYPE 1.49 + jc not286 1.50 + mov ah,2 1.51 +not286: 1.52 + js jmp_endcpu86 ;it is not a 386+, try ELKS & co 1.53 + else 1.54 js endcpu86 ;it is not a 386+, try ELKS & co 1.55 endif 1.56 + endif 1.57 p386 1.58 ifdef VCPI 1.59 mov edx,cs 1.60 @@ -176,6 +196,7 @@ 1.61 godie: 1.62 call near die 1.63 else 1.64 +jmp_endcpu86: 1.65 jmp endcpu86 1.66 endif 1.67 1.68 @@ -219,7 +240,11 @@ 1.69 pushfd 1.70 pop dx 1.71 pop ax 1.72 + ifdef CPUTYPE 1.73 + xor al,24h ; toggle CPUID feature bit & AC bit 1.74 + else 1.75 xor al,20h ; toggle CPUID feature bit 21 (=> pentium+) 1.76 + endif 1.77 push ax ; (toggle AC: bit 18 => 486+) 1.78 push dx 1.79 popfd 1.80 @@ -227,9 +252,47 @@ 1.81 pop dx 1.82 pop dx 1.83 xor al,dl ; clear C 1.84 + ifdef CPUTYPE 1.85 + cmp al,20h 1.86 + mov ax,0400h 1.87 + je is486 1.88 + mov ah,3 1.89 +is486: 1.90 + jae set_cputype 1.91 + xor eax,eax 1.92 + inc ax 1.93 + cpuid ; Basic cpuid (late 486 or Pentium) 1.94 + xor eax,eax 1.95 + inc ax 1.96 + cpuid ; again cause of Nasty EMM386s 1.97 + push eax 1.98 + bt edx,26 ; sse2 bit 1.99 + jnc baseInfo 1.100 + else 1.101 jne @@no_cpuid ; CPUID feature bit changed ? 1.102 - mov eax,80000001h ; Extended Processor Info and Feature Bits 1.103 - cpuid 1.104 + endif 1.105 + mov eax,80000001h ; Extended Processor Info and Feature Bits (Pentium 4 or newer) 1.106 + cpuid ; Extended cpuid (Pentium 4) 1.107 + ifdef CPUTYPE 1.108 +baseInfo: 1.109 + pop ax ; base IDs 1.110 + and ax,0FF0h ; keep FamilyID & ModelID 1.111 + pop cx ; extended IDs 1.112 + mov bx,cx 1.113 + shr bx,4 ; extended FamilyID in bl 1.114 + shr al,4 ; set base ModelID 1.115 + cmp ah,0Fh 1.116 + jz SetModelID 1.117 + cmp ah,06h 1.118 + jnz ModelIDset 1.119 + db 3Dh ; cmp ax,0DC00h 1.120 +SetModelID: 1.121 + add ah,bl ; use extended FamilyID 1.122 + shl cl,4 1.123 + or al,cl ; use extended ModelID 1.124 +ModelIDset: 1.125 +set_cputype: 1.126 + endif 1.127 mov dl,-1 ; set 386 flag 1.128 ifdef NO386 1.129 db 66h ; mov [_cpu_features],edx 1.130 @@ -243,6 +306,9 @@ 1.131 dec [_cpu386] 1.132 endif 1.133 endcpu86: 1.134 + ifdef CPUTYPE 1.135 + mov [_cputype],ax ; _cputype: FFMM or 0[1-4]00=80[1-4]86 or 0000=8086/8088 1.136 + endif 1.137 p8086 1.138 1.139 ;***************************************************************