more toolchain + stage 1 updates
[hdw-linux/hdw-linux.git] / packages / base / coreutils / coreutils_uname.patch
1 --- coreutils-5.92.orig/src/uname.c     2005-09-15 20:34:42.000000000 +0000
2 +++ coreutils-5.92/src/uname.c  2005-10-23 10:14:06.000000000 +0000
3 @@ -29,6 +29,12 @@
4  # include <sys/systeminfo.h>
5  #endif
6  
7 +#ifdef linux
8 +#define cpuid(in,a,b,c,d)\
9 +  asm("cpuid": "=a" (a), "=b" (b), "=c" (c), "=d" (d) : "a" (in));
10 +int has_sse( void );
11 +#endif
12 +
13  #if HAVE_SYS_SYSCTL_H
14  # if HAVE_SYS_PARAM_H
15  #  include <sys/param.h> /* needed for OpenBSD 3.0 */
16 @@ -256,6 +262,96 @@
17         if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor))
18           element = processor;
19        }
20 +#else
21 +      {
22 +       struct utsname u;
23 +       uname (&u);
24 +       element = u.machine;
25 +#ifdef linux
26 +/******************************************************************************
27 + *
28 + * Hello, major hack.  I shouldn't have to do this.  struct utsname should
29 + * have another element with this info in it.  There's probably a struct
30 + * somewhere that has this info, I just don't know where it is.
31 + *
32 + *****************************************************************************/
33 +
34 +       if( !strcmp( element, "i586" ) || !strcmp( element, "i686" ) ) {
35 +         int eax, ebx, ecx, edx, unused;
36 +         int model, family, sse;
37 +     
38 +         cpuid(0,unused,ebx,ecx,edx);
39 +         cpuid(1,eax,unused,unused,unused);
40 +         model = (eax >> 4) & 0xf;
41 +         family = (eax >> 8) & 0xf;
42 +
43 +         switch(ebx) {
44 +         case 0x756e6547: // Intel
45 +           switch( family ) {
46 +           case 5: // Pentium
47 +             if( model <= 3 )
48 +               element="pentium";
49 +             if( model > 3 )
50 +               element="pentium-mmx";
51 +             break;
52 +           case 6: // PentiumPro - Pentium III
53 +             if( model == 1 ) // Pentium Pro
54 +               element="pentiumpro";
55 +             if( ( model == 3 ) || ( model == 5 ) ||
56 +                 ( model == 6 ) ) // Pentium II
57 +               element="pentium2";
58 +             if( ( model == 7 ) || ( model == 8 ) ||
59 +                 ( model == 10 ) || ( model == 11 ) ) // These are all Pentium III
60 +               element="pentium3";
61 +             break;
62 +           case 15: // Pentium4
63 +             element="pentium4";
64 +             break;
65 +           default:
66 +             break;
67 +           } // end switch( family )
68 +           break;
69 +         case 0x68747541: // AMD
70 +           switch(family) {
71 +           case 5:
72 +             if( ( model == 0 ) || ( model == 1 ) || 
73 +                 ( model == 2 ) || ( model == 3 ) ) // K5
74 +               element="i586";
75 +             if( ( model == 6 ) || ( model == 7 ) ) // K6
76 +               element="k6";
77 +             if( model == 8 ) // K6-2
78 +               element="k6-2";
79 +             if( model == 9 ) // K6-3
80 +               element="k6-3";
81 +             break;
82 +           case 6:
83 +             if( model <= 4 )
84 +               element="athlon";
85 +             if( model > 4 ) {
86 +               sse = has_sse();
87 +               if( sse == 0 )
88 +                 element="athlon";
89 +               if( sse == 1 )
90 +                 element="athlon-4";
91 +             }
92 +             break;
93 +           case 15:
94 +             element="athlon-4";
95 +             break;
96 +           default:
97 +             break;
98 +           } // end switch( family )
99 +           break;
100 +         case 0x69727943: // Cyrix
101 +           element="i386"; // who knows what cyrix supports, lets be safe
102 +           break;
103 +         default:
104 +           break;
105 +         } // end switch(ebx)
106 +       }
107 +
108 +#endif
109 +      }
110  #endif
111  #ifdef UNAME_PROCESSOR
112        if (element == unknown)
113 @@ -293,7 +389,7 @@
114  
115    if (toprint & PRINT_HARDWARE_PLATFORM)
116      {
117 -      char const *element = unknown;
118 +      char *element = unknown;
119  #if HAVE_SYSINFO && defined SI_PLATFORM
120        {
121         static char hardware_platform[257];
122 @@ -301,6 +397,15 @@
123                           hardware_platform, sizeof hardware_platform))
124           element = hardware_platform;
125        }
126 +#else
127 +      {
128 +       struct utsname u;
129 +       uname (&u);
130 +       element = u.machine;
131 +       if (strlen (element) == 4 && element[0] == 'i' && element[2] == '8'
132 +           && element[3] == '6')
133 +         element[1] = '3';
134 +      }
135  #endif
136  #ifdef UNAME_HARDWARE_PLATFORM
137        if (element == unknown)
138 @@ -323,3 +428,29 @@
139  
140    exit (EXIT_SUCCESS);
141  }
142 +
143 +#ifdef linux
144 +
145 +/******************************************************************************
146 + *
147 + * int has_sse( void )
148 + * Checks Athlon CPU's to see if they support SSE.
149 + *
150 + *****************************************************************************/
151 +
152 +int has_sse( void )
153 +{
154 +  unsigned long edx, unused;
155 +  int sse;
156 +  cpuid(1,unused,unused,unused,edx);
157 +  // I think, I need this tested on a Duron with SSE
158 +  // and one without it.
159 +  sse = edx & 0x2000000;
160 +  if( sse == 0 ) {
161 +    return 0;
162 +  } else {
163 +    return 1;
164 +  }
165 +
166 +}
167 +#endif