[8286] in Athena Bugs
[brendan@cs.widener.edu: Telling what kind of machine yer on [was Re: how to tell if sparc2?]]
daemon@ATHENA.MIT.EDU (John T Kohl)
Fri Sep 27 17:17:56 1991
Date: Fri, 27 Sep 91 14:20:04 PDT
From: jtkohl@antipodes.Berkeley.EDU (John T Kohl)
To: bugs@Athena.MIT.EDU
Reply-To: jtkohl@cs.berkeley.edu
Might be useful for machtype on suns.
From: brendan@cs.widener.edu (Brendan Kehoe)
Newsgroups: alt.sys.sun,comp.unix.questions,comp.unix.ultrix
Subject: Telling what kind of machine yer on [was Re: how to tell if sparc2?]
Date: 27 Sep 91 15:12:26 GMT
Followup-To: comp.unix.questions
Organization: Widener University Computer Science Dept, Chester PA
NNTP-Posting-Host: lisa.cs.widener.edu
gord@jericho.jericho.UUCP wrote:
>Is there a command I can run in csh (or sh for that matter) that will
>tell me if I am on a sparc1 sparc1+ or sparc2? The arch command only
>returns sun4, the mach command returns sparc. Any ideas?
I wrote this a few weeks ago (and during lunch today made it work for
Ultrix). Hope it's of some help. Any ports to other systems are more
than welcome!
Brendan
-- cut --
/*
* machine v1.1 - by Brendan Kehoe (brendan@cs.widener.edu)
*
* Find out what kinda Sun or ultrix system we're on. (Can't do Sun2s.)
* This was all gleaned from /usr/include/{sun3,sun3x,sun4,sun4c}/cpu.h on
* the Suns and /usr/include/machine/cpuconf.h under ultrix.
*
* Gotta run set-gid to whatever group's got read on /dev/kmem (e.g. kmem).
* Or set-uid root, but it's not necessary.
*
* 08/17/91 v1.0 - original
* 09/27/91 v1.1 - added Ultrix systems
*/
#include <stdio.h>
#include <nlist.h>
static char *machs[][26] = /* 26 == max #, in ultrix */
{
/* Sun 3 */ {"3/160", "3/50", "3/260", "3/110", "3/60", "3/E", NULL},
/* Sun3x */ {"3x/470", "3x/80", NULL},
/* Sun4 */ {"4/260", "4/110", "4/330", "4/470", NULL},
/* Sun4c */ {"Sparc 1 (4/60)", "IPC (4/40)", "Sparc 1+ (4/65)",
"Sparc SLC (4/20)", "Sparc 2 (4/75)", "4/30", "4/50", "4/70",
"4/80", "4/10", "4/45", "4/05", "4/85", "4/32", NULL},
/* ultrix*/ {"Vax 780", "Vax 750", "Vax 730", "Vax 8600", "Vax 8200",
"Vax 8800", "MicroVax I", "MicroVax II", "Virtual VAX",
"Vax 3600", "Vax 6200", "Vax 3400", "Vax 3100 (PVAX)",
"Vax 60 (Firefox)", "Vax 3900", "DECstation 3100 (PMAX)",
"Vax 8820", "DECstation 5400", "DECstation 5800",
"DECstation 5000", "DECstation CMAX", "Vax 6400", "VAXSTAR",
"DECstation 5500", "DECstation 5100", NULL, },
};
main ()
{
static struct nlist nl[2];
int fd, arch, m = 0;
enum archs
{
sun3, sun3x, sun4, sun4c,
ultrix_based,
};
nl[0].n_name = "_cpu";
nl[1].n_name = 0;
nlist ("/vmunix", nl);
if ((fd = open ("/dev/kmem", 0)) < 0)
{
perror ("open_krnl");
exit (1);
}
if (nl[0].n_value != 0)
{
/* Seek to the correct address */
lseek (fd, (long) nl[0].n_value, 0);
if (read (fd, &m, sizeof m) != sizeof (m))
{
close (fd);
perror ("read");
exit (1);
}
}
close (fd);
#ifdef sun
switch (m & 0xf0)
{
case 0x10: /* SUN3_ARCH */
arch = sun3;
m -= 0x10;
break;
case 0x40: /* SUN3X_ARCH */
arch = sun3x;
m -= 0x40;
break;
case 0x20: /* SUN4_ARCH */
arch = sun4;
m -= 0x20;
break;
case 0x50: /* SUN4C_ARCH */
arch = sun4c;
m -= 0x50;
break;
default:
printf ("Unknown architecture.\n");
exit (1);
}
#endif /* sun */
#ifdef ultrix
arch = ultrix_based;
#endif /* ultrix */
printf ("You're on a %s.\n", machs[arch][m - 1]);
exit (0);
}
-- cut --
--
Brendan Kehoe, Sun Network Manager brendan@cs.widener.edu
Widener University Chester, PA