Subversion Repositories HelenOS

Rev

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

Rev Author Line No. Line
1 jermar 1
/*
2071 jermar 2
 * Copyright (c) 2001-2004 Jakub Jermar
1 jermar 3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
1731 jermar 29
/** @addtogroup ia32
1702 cejka 30
 * @{
31
 */
32
/** @file
33
 */
34
 
1888 jermar 35
#ifndef KERN_ia32_CPUID_H_
36
#define KERN_ia32_CPUID_H_
1 jermar 37
 
38
#include <arch/types.h>
39
 
2079 decky 40
typedef struct {
1780 jermar 41
    uint32_t cpuid_eax;
42
    uint32_t cpuid_ebx;
43
    uint32_t cpuid_ecx;
44
    uint32_t cpuid_edx;
2079 decky 45
} __attribute__ ((packed)) cpu_info_t;
1 jermar 46
 
1019 vana 47
struct __cpuid_extended_feature_info {
48
    unsigned sse3 :  1;
49
    unsigned      : 31;
50
} __attribute__ ((packed));
51
 
52
typedef union cpuid_extended_feature_info
53
{
54
    struct __cpuid_extended_feature_info bits;
1780 jermar 55
    uint32_t                                word;
1019 vana 56
}cpuid_extended_feature_info;
57
 
58
 
59
struct __cpuid_feature_info {
60
    unsigned            : 23;
61
    unsigned mmx  :  1;
62
    unsigned fxsr :  1;
63
    unsigned sse  :  1;
64
    unsigned sse2 :  1;
65
    unsigned      :  5;
66
} __attribute__ ((packed));
67
 
68
typedef union cpuid_feature_info
69
{
70
    struct __cpuid_feature_info bits;
1780 jermar 71
    uint32_t                word       ;
1019 vana 72
}cpuid_feature_info;
73
 
74
 
1780 jermar 75
static inline uint32_t has_cpuid(void)
408 decky 76
{
1780 jermar 77
    uint32_t val, ret;
408 decky 78
 
2082 decky 79
    asm volatile (
408 decky 80
        "pushf\n"               /* read flags */
81
        "popl %0\n"
82
        "movl %0, %1\n"
83
 
84
        "btcl $21, %1\n"        /* swap the ID bit */
85
 
86
        "pushl %1\n"            /* propagate the change into flags */
87
        "popf\n"
88
        "pushf\n"
89
        "popl %1\n"
90
 
91
        "andl $(1 << 21), %0\n" /* interrested only in ID bit */
92
        "andl $(1 << 21), %1\n"
93
        "xorl %1, %0\n"
94
        : "=r" (ret), "=r" (val)
95
    );
96
 
97
    return ret;
98
}
1 jermar 99
 
2079 decky 100
static inline void cpuid(uint32_t cmd, cpu_info_t *info)
348 jermar 101
{
2315 hudecek 102
    register int eax asm("eax")=cmd;
103
    register int ebx asm("ebx");
104
    register int ecx asm("ecx");
105
    register int edx asm("edx");
2082 decky 106
    asm volatile (
408 decky 107
        "cpuid\n"
108
 
2315 hudecek 109
        : "=r" (eax), "=r" (ebx), "=r" (ecx), "=r" (edx)
110
        : "r" (eax)
408 decky 111
    );
2315 hudecek 112
    info->cpuid_eax=eax;
113
    info->cpuid_ebx=ebx;
114
    info->cpuid_ecx=ecx;
115
    info->cpuid_edx=edx;
348 jermar 116
}
1 jermar 117
 
118
#endif
1702 cejka 119
 
1731 jermar 120
/** @}
1702 cejka 121
 */