Skip to contentSkip to conversation

Runtime Altivec detection

DISCUSSION Albert Cahalan 1 participant 1 message Mar 9, 2003

lore
Share & tools
lore
#0 lore raw

For those of you needing to get at ELF note info to determine CPU features and other things, here is the code procps-3.1.x has been using. You'll need the appropriate ID code; here I use AT_CLKTCK to determine USER_HZ. Pass the ID code into this function, and you get back the ELF note value.

////////////////////////////////////////////////////////////////////////// #ifndef AT_CLKTCK
#define AT_CLKTCK 17 // frequency of times()
#endif

#define ERROR_CODE 42 // choose something better!

extern char** environ;

// for ELF executables, notes are pushed before environment and args static unsigned long find_elf_note(unsigned long findme){
unsigned long *ep = (unsigned long *)environ; while(*ep++);

  while(*ep){
    if(ep[0]==findme) return ep[1];
    ep+=2;

}
return ERROR_CODE;
}

// Usage:
// Hertz = find_elf_note(AT_CLKTCK);

////////////////////////////////////////////////////////////////////////

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/