15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2011 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef COURGETTE_ELF_TYPES_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define COURGETTE_ELF_TYPES_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This header defines various types from the ELF file spec, but no code
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// related to using them.
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)typedef uint32 Elf32_Addr;  // Unsigned program address
1468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)typedef uint16 Elf32_Half;  // Unsigned medium integer
1568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)typedef uint32 Elf32_Off;  // Unsigned file offset
1668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)typedef int32 Elf32_Sword;  // Signed large integer
1768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)typedef uint32 Elf32_Word;  // Unsigned large integer
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The header at the top of the file
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct Elf32_Ehdr {
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  unsigned char  e_ident[16];
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Half     e_type;
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Half     e_machine;
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Word     e_version;
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Addr     e_entry;
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Off      e_phoff;
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Off      e_shoff;
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Word     e_flags;
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Half     e_ehsize;
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Half     e_phentsize;
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Half     e_phnum;
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Half     e_shentsize;
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Half     e_shnum;
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Half     e_shstrndx;
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// values for header->e_type
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)enum e_type_values {
4068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  ET_NONE = 0,  // No file type
4168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  ET_REL = 1,  // Relocatable file
4268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  ET_EXEC = 2,  // Executable file
4368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  ET_DYN = 3,  // Shared object file
4468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  ET_CORE = 4,  // Core file
4568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  ET_LOPROC = 0xff00,  // Processor-specific
4668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  ET_HIPROC = 0xfff  // Processor-specific
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// values for header->e_machine
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)enum e_machine_values {
5168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  EM_NONE = 0,  // No machine
5268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  EM_386 = 3,  // Intel Architecture
5368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  EM_ARM = 40,  // ARM Architecture
5468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  EM_x86_64 = 62,  // Intel x86-64 Architecture
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Other values skipped
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A section header in the section header table
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct Elf32_Shdr {
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Word   sh_name;
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Word   sh_type;
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Word   sh_flags;
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Addr   sh_addr;
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Off    sh_offset;
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Word   sh_size;
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Word   sh_link;
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Word   sh_info;
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Word   sh_addralign;
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Word   sh_entsize;
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Values for the section type field in a section header
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)enum sh_type_values {
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SHT_NULL = 0,
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SHT_PROGBITS = 1,
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SHT_SYMTAB = 2,
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SHT_STRTAB = 3,
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SHT_RELA = 4,
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SHT_HASH = 5,
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SHT_DYNAMIC = 6,
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SHT_NOTE = 7,
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SHT_NOBITS = 8,
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SHT_REL = 9,
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SHT_SHLIB = 10,
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SHT_DYNSYM = 11,
867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  SHT_INIT_ARRAY = 14,
877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  SHT_FINI_ARRAY = 15,
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SHT_LOPROC = 0x70000000,
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SHT_HIPROC = 0x7fffffff,
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SHT_LOUSER = 0x80000000,
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SHT_HIUSER = 0xffffffff,
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct Elf32_Phdr {
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Word    p_type;
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Off     p_offset;
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Addr    p_vaddr;
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Addr    p_paddr;
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Word    p_filesz;
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Word    p_memsz;
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Word    p_flags;
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Word    p_align;
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Values for the segment type field in a program segment header
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)enum ph_type_values {
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PT_NULL = 0,
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PT_LOAD = 1,
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PT_DYNAMIC = 2,
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PT_INTERP = 3,
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PT_NOTE = 4,
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PT_SHLIB = 5,
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PT_PHDR = 6,
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PT_LOPROC = 0x70000000,
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PT_HIPROC = 0x7fffffff
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct Elf32_Rel {
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Addr    r_offset;
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Word    r_info;
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct Elf32_Rela {
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Addr    r_offset;
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Word    r_info;
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Elf32_Sword   r_addend;
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)enum elf32_rel_386_type_values {
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  R_386_NONE = 0,
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  R_386_32 = 1,
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  R_386_PC32 = 2,
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  R_386_GOT32 = 3,
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  R_386_PLT32 = 4,
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  R_386_COPY = 5,
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  R_386_GLOB_DAT = 6,
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  R_386_JMP_SLOT = 7,
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  R_386_RELATIVE = 8,
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  R_386_GOTOFF = 9,
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  R_386_GOTPC = 10,
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  R_386_TLS_TPOFF = 14,
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
144eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochenum elf32_rel_arm_type_values {
145eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  R_ARM_RELATIVE = 23,
146eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch};
147eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // COURGETTE_ELF_TYPES_H_
149