File indexing completed on 2025-05-11 08:23:41
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 #include <rtems/asm.h>
0026 #include <rtems/score/registers.h>
0027
0028 BEGIN_CODE
0029 PUBLIC(checkCPUtypeSetCr0);
0030
0031
0032
0033
0034 SYM (checkCPUtypeSetCr0):
0035
0036
0037
0038 movl $3, SYM (x86)
0039
0040
0041
0042
0043
0044 pushfl
0045
0046 pushfl
0047 popl eax
0048
0049 movl eax,ecx
0050 xorl $EFLAGS_ALIGN_CHECK,eax
0051 pushl eax
0052 popfl
0053 pushfl
0054 popl eax
0055
0056 xorl ecx,eax
0057 andl $EFLAGS_ALIGN_CHECK,eax
0058 je is386
0059
0060
0061
0062 movl $4,SYM (x86)
0063 movl ecx,eax
0064 xorl $EFLAGS_ID,eax
0065 pushl eax
0066 popfl
0067 pushfl
0068 popl eax
0069
0070 xorl ecx,eax
0071 andl $EFLAGS_ID,eax
0072
0073
0074
0075
0076
0077
0078
0079 je is486x
0080
0081 isnew:
0082
0083
0084
0085 popfl
0086 incl SYM(have_cpuid)
0087
0088
0089
0090
0091
0092
0093 movl $4, eax
0094 movl $0, ecx
0095 cpuid
0096 movl eax,SYM(x86_capability_cores)
0097
0098
0099
0100
0101
0102
0103
0104 movl $1, eax
0105 cpuid
0106 movl ebx,SYM(x86_capability_ebx)
0107 movl ecx,SYM(x86_capability_x)
0108
0109 movb al, cl
0110
0111 andb $0x0f,ah
0112 movb ah,SYM (x86)
0113
0114 andb $0xf0, al
0115 shrb $4, al
0116 movb al,SYM (x86_model)
0117
0118 andb $0x0f, cl
0119 movb cl,SYM (x86_mask)
0120
0121 movl edx,SYM(x86_capability)
0122
0123
0124 xorl eax, eax
0125 cpuid
0126
0127
0128
0129
0130
0131 movl ebx,SYM(x86_vendor_id)
0132 movl edx,SYM(x86_vendor_id)+4
0133 movl ecx,SYM(x86_vendor_id)+8
0134
0135 movl cr0,eax
0136 andl $(CR0_PAGING | CR0_PROTECTION_ENABLE | CR0_EXTENSION_TYPE), eax
0137 orl $(CR0_ALIGMENT_MASK | CR0_WRITE_PROTECT | CR0_NUMERIC_ERROR | CR0_MONITOR_COPROC),eax
0138 jmp 2f
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153 is486x: xor ax,ax
0154 sahf
0155 movb $5,al
0156 movb $2,bl
0157 div bl
0158 lahf
0159 cmpb $2,ah
0160 jne ncyrix
0161
0162
0163
0164
0165
0166 #define setCx86(reg, val) \
0167 movb reg,al; \
0168 outb al,$0x22; \
0169 movb val,al; \
0170 outb al,$0x23
0171
0172 #define getCx86(reg) \
0173 movb reg,al; \
0174 outb al,$0x22; \
0175 inb $0x23,al
0176
0177 cli
0178 getCx86($0xc3)
0179 movb al,cl
0180 movb al,bl
0181 andb $0x0f,bl
0182 orb $0x10,bl
0183 setCx86($0xc3,bl)
0184
0185 getCx86($0xe8)
0186 orb $0x80,al
0187 movb al,bl
0188 setCx86($0xe8,bl)
0189
0190 getCx86($0xfe)
0191 andb $0xf0,al
0192 cmpb $0x30,al
0193 jne n6x86
0194 getCx86($0xe9)
0195 andb $0xfd,al
0196 movb al,bl
0197 setCx86($0xe9,bl)
0198 setCx86($0xc3,cl)
0199 sti
0200 jmp isnew
0201
0202 n6x86: setCx86($0xc3,cl)
0203 sti
0204 ncyrix:
0205 popfl
0206 movl cr0,eax
0207 andl $(CR0_PAGING | CR0_EXTENSION_TYPE | CR0_PROTECTION_ENABLE),eax
0208 orl $(CR0_ALIGMENT_MASK | CR0_WRITE_PROTECT | CR0_NUMERIC_ERROR | CR0_MONITOR_COPROC),eax
0209 jmp 2f
0210 is386:
0211 popfl
0212 movl cr0,eax
0213 andl $(CR0_PAGING | CR0_EXTENSION_TYPE | CR0_PROTECTION_ENABLE),eax
0214 orl $CR0_MONITOR_COPROC,eax
0215 2: movl eax,cr0
0216 call check_x87
0217 ret
0218
0219
0220
0221
0222
0223 check_x87:
0224 movb $0,SYM(hard_math)
0225 clts
0226 fninit
0227 fstsw ax
0228 cmpb $0,al
0229 je 1f
0230 movl cr0,eax
0231 xorl $4,eax
0232 movl eax,cr0
0233 ret
0234 .align 16
0235 1: movb $1,SYM(hard_math)
0236 .byte 0xDB,0xE4
0237 ret
0238
0239 END_CODE
0240
0241 BEGIN_DATA
0242 PUBLIC(x86)
0243 PUBLIC(have_cpuid)
0244 PUBLIC(x86_model)
0245 PUBLIC(x86_mask)
0246 PUBLIC(x86_capability)
0247 PUBLIC(x86_capability_ebx)
0248 PUBLIC(x86_capability_x)
0249 PUBLIC(x86_capability_cores)
0250 PUBLIC(x86_vendor_id)
0251 PUBLIC(hard_math)
0252
0253 SYM(x86):
0254 .byte 0
0255 SYM(have_cpuid):
0256 .long 0
0257 SYM(x86_model):
0258 .byte 0
0259 SYM(x86_mask):
0260 .byte 0
0261 SYM(x86_capability):
0262 .long 0
0263 SYM(x86_capability_ebx):
0264 .long 0
0265 SYM(x86_capability_x):
0266 .long 0
0267 SYM(x86_capability_cores):
0268 .long 0
0269 SYM(x86_vendor_id):
0270 .zero 13
0271 SYM(hard_math):
0272 .byte 0
0273 END_DATA