Subversion Repositories shark

Rev

Rev 705 | 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
#include <ll/i386/hw-data.h>
25
#include <ll/i386/hw-arch.h>
26
#include <ll/i386/mem.h>
705 giacomo 27
#include <ll/i386/advtimer.h>
28
#include <ll/i386/apic.h>
2 pj 29
 
40 pj 30
FILE(Cpu-C);
2 pj 31
 
40 pj 32
INLINE_OP void cpuid(DWORD a, DWORD *outa, DWORD *outb, DWORD *outc, DWORD *outd)
2 pj 33
{
34
#ifdef __OLD_GNU__
40 pj 35
    __asm__ __volatile__ (".byte 0x0F,0xA2"
2 pj 36
#else
40 pj 37
    __asm__ __volatile__ ("cpuid"
2 pj 38
#endif
40 pj 39
    : "=a" (*outa),
40
      "=b" (*outb),
41
      "=c" (*outc),
42
      "=d" (*outd)
43
    : "a"  (a));
2 pj 44
}
45
 
46
void X86_get_CPU(struct ll_cpuInfo *p)
47
{
40 pj 48
        DWORD tmp;
2 pj 49
 
40 pj 50
        memset(p, 0, sizeof(struct ll_cpuInfo));
51
        if (X86_is386()) {
52
                p->X86_cpu = 3;
53
 
54
                return;
2 pj 55
        }
40 pj 56
        if (X86_hasCPUID()) {
57
                p->X86_cpuIdFlag = 1;
58
                p->X86_cpu = 5;
59
                cpuid(0, &tmp, &(p->X86_vendor_1),
60
                                &(p->X86_vendor_3),
61
                                &(p->X86_vendor_2));
62
                if (tmp >= 1) {
705 giacomo 63
 
40 pj 64
                        cpuid(1, &(p->X86_signature),
65
                                &(p->X86_IntelFeature_1),
66
                                &(p->X86_IntelFeature_2),
67
                                &(p->X86_StandardFeature));
756 giacomo 68
                #ifdef __APIC__
705 giacomo 69
                        if ((p->X86_StandardFeature >> 5) & 1) {
70
 
71
                                unsigned long msr_original_low, msr_original_high;
72
 
73
                                rdmsr(APIC_BASE_MSR, msr_original_low, msr_original_high);
74
                                wrmsr(APIC_BASE_MSR, msr_original_low|(1<<11), 0);
75
 
76
                                cpuid(1, &(p->X86_signature),
77
                                        &(p->X86_IntelFeature_1),
78
                                        &(p->X86_IntelFeature_2),
79
                                        &(p->X86_StandardFeature));
80
 
81
                                wrmsr(APIC_BASE_MSR, msr_original_low, msr_original_high);
82
 
83
                        }      
756 giacomo 84
                #endif
40 pj 85
                }
86
        } else {
87
                p->X86_cpu = 4;
88
                if (X86_isCyrix()) {
89
                        /* Err... Adjust IT!!!! */
90
                        p->X86_cpu = 11;
91
                }
92
                /* Need tests for AMD and others... */
2 pj 93
        }
94
}