《操作系统》的实验代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 regels
1.6 KiB

10 jaren geleden
  1. #ifndef __LIBS_ELF_H__
  2. #define __LIBS_ELF_H__
  3. #include <defs.h>
  4. #define ELF_MAGIC 0x464C457FU // "\x7FELF" in little endian
  5. /* file header */
  6. struct elfhdr {
  7. uint32_t e_magic; // must equal ELF_MAGIC
  8. uint8_t e_elf[12];
  9. uint16_t e_type; // 1=relocatable, 2=executable, 3=shared object, 4=core image
  10. uint16_t e_machine; // 3=x86, 4=68K, etc.
  11. uint32_t e_version; // file version, always 1
  12. uint32_t e_entry; // entry point if executable
  13. uint32_t e_phoff; // file position of program header or 0
  14. uint32_t e_shoff; // file position of section header or 0
  15. uint32_t e_flags; // architecture-specific flags, usually 0
  16. uint16_t e_ehsize; // size of this elf header
  17. uint16_t e_phentsize; // size of an entry in program header
  18. uint16_t e_phnum; // number of entries in program header or 0
  19. uint16_t e_shentsize; // size of an entry in section header
  20. uint16_t e_shnum; // number of entries in section header or 0
  21. uint16_t e_shstrndx; // section number that contains section name strings
  22. };
  23. /* program section header */
  24. struct proghdr {
  25. uint32_t p_type; // loadable code or data, dynamic linking info,etc.
  26. uint32_t p_offset; // file offset of segment
  27. uint32_t p_va; // virtual address to map segment
  28. uint32_t p_pa; // physical address, not used
  29. uint32_t p_filesz; // size of segment in file
  30. uint32_t p_memsz; // size of segment in memory (bigger if contains bss)
  31. uint32_t p_flags; // read/write/execute bits
  32. uint32_t p_align; // required alignment, invariably hardware page size
  33. };
  34. #endif /* !__LIBS_ELF_H__ */