source: patches/coreutils-5.94-uname-1.patch @ f99d122

clfs-1.2clfs-2.1clfs-3.0.0-systemdclfs-3.0.0-sysvinitsystemdsysvinit
Last change on this file since f99d122 was 69cde8d, checked in by Jim Gifford <clfs@…>, 18 years ago

Added: All patches needed for the book.

  • Property mode set to 100644
File size: 4.5 KB
  • coreutils-5.92

    Submitted By: Matthew Burgess <matthew at linuxfromscratch dot org>
    Date: 2005-10-23
    Initial Package Version: 5.92
    Upstream Status: pending
    Origin: Scot McPherson
    Description: Fix the output of uname once and for all.
    
    	$ uname -m	# This always worked.
    	i686
    	$ uname -i	# Used to report 'unknown'.
    	i386
    	$ uname -p	# Likewise.
    	athlon-4
    
    diff -Naur coreutils-5.92.orig/src/uname.c coreutils-5.92/src/uname.c
    old new  
    2929# include <sys/systeminfo.h>
    3030#endif
    3131
     32#ifdef linux
     33#define cpuid(in,a,b,c,d)\
     34  asm("cpuid": "=a" (a), "=b" (b), "=c" (c), "=d" (d) : "a" (in));
     35int has_sse( void );
     36#endif
     37
    3238#if HAVE_SYS_SYSCTL_H
    3339# if HAVE_SYS_PARAM_H
    3440#  include <sys/param.h> /* needed for OpenBSD 3.0 */
     
    256262        if (0 <= sysinfo (SI_ARCHITECTURE, processor, sizeof processor))
    257263          element = processor;
    258264      }
     265#else
     266      {
     267        struct utsname u;
     268        uname (&u);
     269        element = u.machine;
     270#ifdef linux
     271/******************************************************************************
     272 *
     273 * Hello, major hack.  I shouldn't have to do this.  struct utsname should
     274 * have another element with this info in it.  There's probably a struct
     275 * somewhere that has this info, I just don't know where it is.
     276 *
     277 *****************************************************************************/
     278
     279        if( !strcmp( element, "i586" ) || !strcmp( element, "i686" ) ) {
     280          int eax, ebx, ecx, edx, unused;
     281          int model, family, sse;
     282     
     283          cpuid(0,unused,ebx,ecx,edx);
     284          cpuid(1,eax,unused,unused,unused);
     285          model = (eax >> 4) & 0xf;
     286          family = (eax >> 8) & 0xf;
     287
     288          switch(ebx) {
     289          case 0x756e6547: // Intel
     290            switch( family ) {
     291            case 5: // Pentium
     292              if( model <= 3 )
     293                element="pentium";
     294              if( model > 3 )
     295                element="pentium-mmx";
     296              break;
     297            case 6: // PentiumPro - Pentium III
     298              if( model == 1 ) // Pentium Pro
     299                element="pentiumpro";
     300              if( ( model == 3 ) || ( model == 5 ) ||
     301                  ( model == 6 ) ) // Pentium II
     302                element="pentium2";
     303              if( ( model == 7 ) || ( model == 8 ) ||
     304                  ( model == 10 ) || ( model == 11 ) ) // These are all Pentium III
     305                element="pentium3";
     306              break;
     307            case 15: // Pentium4
     308              element="pentium4";
     309              break;
     310            default:
     311              break;
     312            } // end switch( family )
     313            break;
     314          case 0x68747541: // AMD
     315            switch(family) {
     316            case 5:
     317              if( ( model == 0 ) || ( model == 1 ) ||
     318                  ( model == 2 ) || ( model == 3 ) ) // K5
     319                element="i586";
     320              if( ( model == 6 ) || ( model == 7 ) ) // K6
     321                element="k6";
     322              if( model == 8 ) // K6-2
     323                element="k6-2";
     324              if( model == 9 ) // K6-3
     325                element="k6-3";
     326              break;
     327            case 6:
     328              if( model <= 4 )
     329                element="athlon";
     330              if( model > 4 ) {
     331                sse = has_sse();
     332                if( sse == 0 )
     333                  element="athlon";
     334                if( sse == 1 )
     335                  element="athlon-4";
     336              }
     337              break;
     338            case 15:
     339              element="athlon-4";
     340              break;
     341            default:
     342              break;
     343            } // end switch( family )
     344            break;
     345          case 0x69727943: // Cyrix
     346            element="i386"; // who knows what cyrix supports, lets be safe
     347            break;
     348          default:
     349            break;
     350          } // end switch(ebx)
     351        }
     352
     353#endif
     354      }
    259355#endif
    260356#ifdef UNAME_PROCESSOR
    261357      if (element == unknown)
     
    293389
    294390  if (toprint & PRINT_HARDWARE_PLATFORM)
    295391    {
    296       char const *element = unknown;
     392      char *element = unknown;
    297393#if HAVE_SYSINFO && defined SI_PLATFORM
    298394      {
    299395        static char hardware_platform[257];
     
    301397                          hardware_platform, sizeof hardware_platform))
    302398          element = hardware_platform;
    303399      }
     400#else
     401      {
     402        struct utsname u;
     403        uname (&u);
     404        element = u.machine;
     405        if (strlen (element) == 4 && element[0] == 'i' && element[2] == '8'
     406            && element[3] == '6')
     407          element[1] = '3';
     408      }
    304409#endif
    305410#ifdef UNAME_HARDWARE_PLATFORM
    306411      if (element == unknown)
     
    323428
    324429  exit (EXIT_SUCCESS);
    325430}
     431
     432#ifdef linux
     433
     434/******************************************************************************
     435 *
     436 * int has_sse( void )
     437 * Checks Athlon CPU's to see if they support SSE.
     438 *
     439 *****************************************************************************/
     440
     441int has_sse( void )
     442{
     443  unsigned long edx, unused;
     444  int sse;
     445  cpuid(1,unused,unused,unused,edx);
     446  // I think, I need this tested on a Duron with SSE
     447  // and one without it.
     448  sse = edx & 0x2000000;
     449  if( sse == 0 ) {
     450    return 0;
     451  } else {
     452    return 1;
     453  }
     454
     455}
     456#endif
Note: See TracBrowser for help on using the repository browser.