Files
ftmemsim-valgrind/tests/cputest.c
Nicholas Nethercote 4399d9700f Added beginnings of an ARM port, to the point where it compiles. It does not
run, though.  There are lots of stubs to be filled in.  (The asm ones currently
just have "swi" in them, which seems to cause seg faults.) 

Also, some of the macros are decided dubious, especially:

  ARCH_* are bogus
  SYSCALL_RET is bogus
  PLATFORM_SET_SYSCALL_RESULT is bogus
  not sure about SET_SYSCALL_RETVAL
  FIRST_STACK_FRAME et al -- bogus?
  VG_MAX_JUMPS ?

And in stage2.lds, the 0x8048000 is almost certainly wrong


This required some tweakings of the core:
- some of the vki_*.h kernel types were fixed up

- had to disable the AM_PROG_CC_C_O macro in configure.in, because automake
  (autoconf?) didn't like it...

- some "#ifdef __x86__" guards were introduced, for nasty x86 things I don't
  yet know how to factor out (trampoline page muck, sysinfo page muck).

- fixed a minor stupidity in vg_proxylwp.c.

- moved the ptrace wrapper into the x86-linux part

- had to change the intercept mangling scheme, to use 'J' instead of '$' as the
  escape char because GCC didn't like '$'.  This is all very dubious, and only
  works because none of our intercepted symbols contains a 'J'.  To be fixed up
  ASAP.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3120
2004-11-26 19:34:36 +00:00

113 lines
2.3 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// We return:
// - 0 if the machine matches the asked-for cpu
// - 1 if it didn't match, but did match the name of another arch
// - 2 otherwise
// When updating this file for a new architecture, add the name to
// 'all_archs' as well as adding go().
#define False 0
#define True 1
typedef int Bool;
char* all_archs[] = {
"x86",
"arm",
"amd64",
"ppc",
NULL
};
#ifdef __x86__
static __inline__ void cpuid(unsigned int n,
unsigned int *a, unsigned int *b,
unsigned int *c, unsigned int *d)
{
__asm__ __volatile__ (
"cpuid"
: "=a" (*a), "=b" (*b), "=c" (*c), "=d" (*d) /* output */
: "0" (n) /* input */
);
}
static Bool go(char* cpu)
{
unsigned int level = 0, mask = 0, a, b, c, d;
if ( strcmp( cpu, "x86" ) == 0 ) {
return True;
} else if ( strcmp( cpu, "x86-fpu" ) == 0 ) {
level = 1;
mask = 1 << 0;
} else if ( strcmp( cpu, "x86-cmov" ) == 0 ) {
level = 1;
mask = 1 << 15;
} else if ( strcmp( cpu, "x86-mmx" ) == 0 ) {
level = 1;
mask = 1 << 23;
} else if ( strcmp( cpu, "x86-mmxext" ) == 0 ) {
level = 0x80000001;
mask = 1 << 22;
} else if ( strcmp( cpu, "x86-sse" ) == 0 ) {
level = 1;
mask = 1 << 25;
} else if ( strcmp( cpu, "x86-sse2" ) == 0 ) {
level = 1;
mask = 1 << 26;
} else {
return False;
}
cpuid( level & 0x80000000, &a, &b, &c, &d );
if ( a >= level ) {
cpuid( level, &a, &b, &c, &d );
if ( ( d & mask ) != 0 ) return True;
}
return False;
}
#endif // __x86__
#ifdef __arm__
static Bool go(char* cpu)
{
if ( strcmp( cpu, "arm" ) == 0 )
return True;
else
return False;
}
#endif // __arm__
#ifdef __ppc__
static Bool go(char* cpu)
{
if ( strcmp( cpu, "ppc" ) == 0 )
return True;
else
return False;
}
#endif // __ppc__
int main(int argc, char **argv)
{
int i;
if ( argc != 2 ) {
fprintf( stderr, "usage: cputest <cpu-type>\n" );
exit( 2 );
}
if (go( argv[1] )) {
return 0; // matched
}
for (i = 0; NULL != all_archs[i]; i++) {
if ( strcmp( argv[1], all_archs[i] ) == 0 )
return 1;
}
return 2;
}