Subversion Repositories shark

Rev

Rev 3 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/* Project:     OSLib
2
 * Description: The OS Construction Kit
3
 * Date:                1.6.2000
4
 * Idea by:             Luca Abeni & Gerardo Lamastra
5
 *
6
 * OSLib is an SO project aimed at developing a common, easy-to-use
7
 * low-level infrastructure for developing OS kernels and Embedded
8
 * Applications; it partially derives from the HARTIK project but it
9
 * currently is independently developed.
10
 *
11
 * OSLib is distributed under GPL License, and some of its code has
12
 * been derived from the Linux kernel source; also some important
13
 * ideas come from studying the DJGPP go32 extender.
14
 *
15
 * We acknowledge the Linux Community, Free Software Foundation,
16
 * D.J. Delorie and all the other developers who believe in the
17
 * freedom of software and ideas.
18
 *
19
 * For legalese, check out the included GPL license.
20
 */
21
 
22
/*	CPU detection code	*/
23
 
24
.title	"CPU2.S"
25
 
26
#include <ll/i386/linkage.h>
27
#include <ll/i386/defs.h>
28
 
29
/*
30
 * The following code has been extracted by Intel AP-485
31
 * Application Note: Intel Processor Identification with CPUID instruction
32
 */
33
 
34
.data
35
 
36
ASMFILE(CPU2)
37
 
38
.globl	SYMBOL_NAME(X86_fpu)
39
 
40
SYMBOL_NAME_LABEL(X86_fpu)		.byte	0
41
SYMBOL_NAME_LABEL(X86_cpu)		.byte	0
42
fpu_status:	.word	0
43
 
44
/*
45
	struct CPU {
46
		DWORD X86_cpu;			0
47
		DWORD X86_cpuIdFlag;		4
48
		DWORD X86_vendor_1;		8
49
		DWORD X86_vendor_2;		12
50
		DWORD X86_vendor_3;		16
51
		DWORD X86_signature;		20
52
		DWORD X86_IntelFeature_1;	24
53
		DWORD X86_IntelFeature_2;	28
54
		DWORD X86_StandardFeature;	32
55
	}
56
*/
57
 
58
.text
59
 
60
.globl SYMBOL_NAME(X86_get_CPU)
61
.globl SYMBOL_NAME(X86_get_FPU)
62
.globl SYMBOL_NAME(X86_is386)
63
.globl SYMBOL_NAME(X86_isCyrix)
64
.globl SYMBOL_NAME(X86_hasCPUID)
787 giacomo 65
.globl SYMBOL_NAME(X86_enable_cyrix_cpuid)
2 pj 66
 
67
SYMBOL_NAME_LABEL(X86_is386)
68
		pushfl
69
		popl	%eax
70
		movl	%eax, %ecx
71
		xorl	$0x40000, %eax
72
		pushl	%eax
73
		popfl
74
		pushfl
75
		popl	%eax
76
		cmp	%ecx, %eax
77
		jz	is386
78
 
79
		pushl	%ecx
80
		popfl
81
		movl	$0, %eax
82
		ret
83
is386:
84
		movl	$1, %eax
85
		ret
86
 
787 giacomo 87
SYMBOL_NAME_LABEL(X86_enable_cyrix_cpuid)
88
 
89
		pushfl
90
		cli
91
   		/* Get Cyrix reg c3h */
92
		movb   $0xc3,%al
93
   		outb   %al,$0x22
94
   		inb    $0x23,%al
95
   		/* Enable config access */
96
   		movb   %al,%cl
97
   		movb   %al,%bl
98
   		andb   $0xf,%bl
99
   		orb    $0x10,%bl
100
   		/* Set Cyrix reg c3h */
101
   		movb   $0xc3,%al
102
   		outb   %al,$0x22
103
		movb   %bl,%al
104
		outb   %al,$0x23
105
   		/* Get Cyrix reg e8 */
106
		movb   $0xe8,%al
107
		outb   %al,$0x22
108
		inb    $0x23,%al
109
		/* Set "CPUID" bit */
110
   		orb    $0x80,%al
111
		movb   %al,%bl
112
		/* Set Cyrix reg e8 */
113
		movb   $0xe8,%al
114
		outb   %al,$0x22
115
		movb   %bl,%al
116
		outb   %al,$0x23
117
		/* Get Cyrix reg fe */
118
		movb   $0xfe,%al
119
		outb   %al,$0x22
120
		inb    $0x23,%al
121
		/* Is CPU a 6x86(L)? */
122
		andb   $0xf0,%al
123
		cmpb   $0x30,%al
124
		jne   not6x86
125
		/* Get Cyrix reg e9 */
126
		movb   $0xe9,%al
127
		outb   %al,$0x22
128
		inb    $0x23,%al
129
		/* Fix 6x86 SLOP bug */
130
		andb   $0xfd,%al
131
		movb   %al,%bl
132
		/* Set Cyrix reg e9 */
133
		movb   $0xe9,%al
134
		outb   %al,$0x22
135
		movb   %bl,%al
136
		outb   %al,$0x23
137
not6x86:
138
		/* Set Cyrix reg c3 */
139
		movb   $0xc3,%al
140
		outb   %al,$0x22
141
		movb   %cl,%al
142
		outb   %al,$0x23
143
		popfl
144
		ret
145
 
2 pj 146
SYMBOL_NAME_LABEL(X86_hasCPUID)
147
		pushfl
148
		popl	%eax
149
		movl	%eax, %ecx
150
		xorl	$0x200000, %eax
151
		pushl	%eax
152
		popfl
153
		pushfl
154
		popl	%eax
155
		xorl	%ecx, %eax
156
		je	noCPUID
157
 
158
		pushl	%ecx	/* Restore the old EFLAG value... */
159
		popfl
160
		movl	$1, %eax
161
		ret
162
noCPUID:
163
		movl	$0, %eax
164
		ret
165
 
166
SYMBOL_NAME_LABEL(X86_isCyrix)
167
		xorw	%ax, %ax
168
		sahf
169
		mov	$5, %ax
170
		mov	$2, %bx
171
		divb	%bl
172
		lahf
173
		cmpb	$2, %ah
174
		jne	noCyrix
175
		movl	$1, %eax
176
		ret
177
noCyrix:
178
		movl	$0, %eax
179
		ret
180
 
181
SYMBOL_NAME_LABEL(X86_get_FPU)
182
	/* First of all, set the FPU type to 0... */
183
		movb	$0, SYMBOL_NAME(X86_fpu)
184
		fninit
185
	/* Let's give some time to the FPU...
186
	 * We cannot use WAIT 'cause we don't know if an FPU is present...
187
	 */
188
		movl	$2, %ecx
189
here:
190
		loop	here
191
		movw	$0x5a5a, fpu_status
192
		fnstsw	fpu_status
193
	/* Guys, I really don't know when to wai and when not...
194
	 */
195
		movl	$2, %ecx
196
here1:
197
		loop	here1
198
		movw	fpu_status, %ax
199
 
200
		cmpb	$0, %al
201
		jne	endFPUProc
202
 
203
chkCW:
204
	/* OK, if we are here, we have some kind of FPU... */
205
		fnstcw 	fpu_status
206
 
207
	/* Guys, I really don't know when to wai and when not...
208
	 */
209
		movl	$2, %ecx
210
here2:
211
		loop	here2
212
 
213
		movw	fpu_status, %ax
214
		andw	$0x103f, %ax
215
		cmpw	$0x03F, %ax
216
		jne	endFPUProc
217
	/* ... Err... I was wrong :(. Here we are sure to have an FPU */
218
		movb	$1, SYMBOL_NAME(X86_fpu)
219
 
220
chkInf:
221
/* Well... I assume that if we arrive to X86_get_FPU, we are running on a
222
 * 386+ processor... Hence, the following is a complete nonsense!!!
223
 * I'm commenting it out, we will see...
224
 */
225
#if 0
226
	/* Um... If we have a -386, end of the story! */
227
		cmpb	$3, SYMBOL_NAME(X86_cpu)
228
		jle	endFPUProc
229
		movb	$2, SYMBOL_NAME(X86_fpu)
230
		fld1
231
		fldz
232
		fdivp
233
		fld	%st
234
		fchs
235
		fcompp
236
		fstsw	fpu_status
237
		wait
238
		sahf
239
		jz	endFPUProc
240
		movb	$3, SYMBOL_NAME(X86_fpu)
241
#else
242
		movb	$3, SYMBOL_NAME(X86_fpu)
243
#endif
244
endFPUProc:
245
		ret