0001
0002 #include <stdio.h>
0003 #include <stdlib.h>
0004 #include <string.h>
0005 #include <elf.h>
0006
0007 int
0008 main(int argc, char **argv)
0009 {
0010 unsigned char ei[EI_NIDENT];
0011 union { short s; char c[2]; } endian_test;
0012
0013 if (fread(ei, 1, EI_NIDENT, stdin) != EI_NIDENT) {
0014 fprintf(stderr, "Error: input truncated\n");
0015 return 1;
0016 }
0017 if (memcmp(ei, ELFMAG, SELFMAG) != 0) {
0018 fprintf(stderr, "Error: not ELF\n");
0019 return 1;
0020 }
0021 switch (ei[EI_CLASS]) {
0022 case ELFCLASS32:
0023 printf("#define KERNEL_ELFCLASS ELFCLASS32\n");
0024 break;
0025 case ELFCLASS64:
0026 printf("#define KERNEL_ELFCLASS ELFCLASS64\n");
0027 break;
0028 default:
0029 exit(1);
0030 }
0031 switch (ei[EI_DATA]) {
0032 case ELFDATA2LSB:
0033 printf("#define KERNEL_ELFDATA ELFDATA2LSB\n");
0034 break;
0035 case ELFDATA2MSB:
0036 printf("#define KERNEL_ELFDATA ELFDATA2MSB\n");
0037 break;
0038 default:
0039 exit(1);
0040 }
0041
0042 if (sizeof(unsigned long) == 4) {
0043 printf("#define HOST_ELFCLASS ELFCLASS32\n");
0044 } else if (sizeof(unsigned long) == 8) {
0045 printf("#define HOST_ELFCLASS ELFCLASS64\n");
0046 }
0047
0048 endian_test.s = 0x0102;
0049 if (memcmp(endian_test.c, "\x01\x02", 2) == 0)
0050 printf("#define HOST_ELFDATA ELFDATA2MSB\n");
0051 else if (memcmp(endian_test.c, "\x02\x01", 2) == 0)
0052 printf("#define HOST_ELFDATA ELFDATA2LSB\n");
0053 else
0054 exit(1);
0055
0056 return 0;
0057 }