[BACK]Return to procfs_machdep.c CVS log [TXT][DIR] Up to [local] / sys / arch / i386 / i386

Annotation of sys/arch/i386/i386/procfs_machdep.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: procfs_machdep.c,v 1.6 2006/12/20 17:50:40 gwk Exp $  */
                      2: /*     $NetBSD: procfs_machdep.c,v 1.6 2001/02/21 21:39:59 jdolecek Exp $      */
                      3:
                      4: /*
                      5:  * Copyright (c) 2001 Wasabi Systems, Inc.
                      6:  * All rights reserved.
                      7:  *
                      8:  * Written by Frank van der Linden for Wasabi Systems, Inc.
                      9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. Redistributions in binary form must reproduce the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer in the
                     17:  *    documentation and/or other materials provided with the distribution.
                     18:  * 3. All advertising materials mentioning features or use of this software
                     19:  *    must display the following acknowledgement:
                     20:  *      This product includes software developed for the NetBSD Project by
                     21:  *      Wasabi Systems, Inc.
                     22:  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
                     23:  *    or promote products derived from this software without specific prior
                     24:  *    written permission.
                     25:  *
                     26:  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
                     27:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     28:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     29:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
                     30:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     31:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     32:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     33:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     34:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     35:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     36:  * POSSIBILITY OF SUCH DAMAGE.
                     37:  */
                     38:
                     39:
                     40: #include <sys/param.h>
                     41: #include <sys/systm.h>
                     42: #include <sys/mount.h>
                     43: #include <sys/vnode.h>
                     44: #include <miscfs/procfs/procfs.h>
                     45: #include <machine/cpu.h>
                     46: #include <machine/cpufunc.h>
                     47: #include <machine/specialreg.h>
                     48:
                     49: extern int i386_fpu_present, i386_fpu_exception, i386_fpu_fdivbug;
                     50:
                     51: static const char * const i386_features[] = {
                     52:        "fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
                     53:        "cx8", "apic", NULL, "sep", "mtrr", "pge", "mca", "cmov",
                     54:        "pat", "pse36", "pn", "clflush", NULL, "dts", "acpi", "mmx",
                     55:        "fxsr", "sse", "sse2", "ss", "ht", "tm", "ia64", "pbe"
                     56: };
                     57:
                     58:
                     59: /*
                     60:  * Linux-style /proc/cpuinfo.
                     61:  * Only used when procfs is mounted with -o linux.
                     62:  *
                     63:  * In the multiprocessor case, this should be a loop over all CPUs.
                     64:  */
                     65: int
                     66: procfs_getcpuinfstr(char *buf, int *len)
                     67: {
                     68:        int left, l, i;
                     69:        char featurebuf[256], *p;
                     70:
                     71:        p = featurebuf;
                     72:        left = sizeof featurebuf;
                     73:        for (i = 0; i < 32; i++) {
                     74:                if ((cpu_feature & (1 << i)) && i386_features[i]) {
                     75:                        l = snprintf(p, left, "%s ", i386_features[i]);
                     76:                        if (l == -1)
                     77:                                l = 0;
                     78:                        else if (l >= left)
                     79:                                l = left - 1;
                     80:                        left -= l;
                     81:                        p += l;
                     82:                        if (left <= 0)
                     83:                                break;
                     84:                }
                     85:        }
                     86:
                     87:        p = buf;
                     88:        left = *len;
                     89:        l = snprintf(p, left,
                     90:                "processor\t: %d\n"
                     91:                "vendor_id\t: %s\n"
                     92:                "cpu family\t: %d\n"
                     93:                "model\t\t: %d\n"
                     94:                "model name\t: %s\n"
                     95:                "stepping\t: ",
                     96:                0,
                     97:                cpu_vendor,
                     98:                cpuid_level >= 0 ? ((cpu_id >> 8) & 15) : cpu_class + 3,
                     99:                cpuid_level >= 0 ? ((cpu_id >> 4) & 15) : 0,
                    100:                cpu_model
                    101:            );
                    102:        if (l == -1)
                    103:                l = 0;
                    104:        else if (l >= left)
                    105:                l = left - 1;
                    106:
                    107:        left -= l;
                    108:        p += l;
                    109:        if (left <= 0)
                    110:                return 0;
                    111:
                    112:        if (cpuid_level >= 0)
                    113:                l = snprintf(p, left, "%d\n", cpu_id & 15);
                    114:        else
                    115:                l = snprintf(p, left, "unknown\n");
                    116:
                    117:        if (l == -1)
                    118:                l = 0;
                    119:        else if (l >= left)
                    120:                l = left - 1;
                    121:        left -= l;
                    122:        p += l;
                    123:        if (left <= 0)
                    124:                return 0;
                    125:
                    126: #if defined(I586_CPU) || defined(I686_CPU)
                    127:        if (cpuspeed != 0)
                    128:                l = snprintf(p, left, "cpu MHz\t\t: %d\n",
                    129:                    cpuspeed);
                    130:        else
                    131: #endif
                    132:                l = snprintf(p, left, "cpu MHz\t\t: unknown\n");
                    133:
                    134:        if (l == -1)
                    135:                l = 0;
                    136:        else if (l >= left)
                    137:                l = left - 1;
                    138:        left -= l;
                    139:        p += l;
                    140:        if (left <= 0)
                    141:                return 0;
                    142:
                    143:        l = snprintf(p, left,
                    144:                "fdiv_bug\t: %s\n"
                    145:                "fpu\t\t: %s\n"
                    146:                "fpu_exception:\t: %s\n"
                    147:                "cpuid level\t: %d\n"
                    148:                "wp\t\t: %s\n"
                    149:                "flags\t\t: %s\n",
                    150:                i386_fpu_fdivbug ? "yes" : "no",
                    151:                i386_fpu_present ? "yes" : "no",
                    152:                i386_fpu_exception ? "yes" : "no",
                    153:                cpuid_level,
                    154:                (rcr0() & CR0_WP) ? "yes" : "no",
                    155:                featurebuf);
                    156:        if (l == -1)
                    157:                l = 0;
                    158:        else if (l >= left)
                    159:                l = left - 1;
                    160:
                    161:        *len = (p + l) - buf;
                    162:
                    163:        return 0;
                    164: }

CVSweb