#include <sgs.h>
#include <_debug.h>
#include <conv.h>
#include <msg.h>
void
Elf_ehdr(Lm_list *lml, Ehdr *ehdr, Shdr *shdr0)
{
Conv_inv_buf_t inv_buf1, inv_buf2;
Conv_ehdr_flags_buf_t flags_buf;
Conv_sec_flags_buf_t sec_flags_buf;
Byte *byte = &(ehdr->e_ident[0]);
const char *flgs;
int xshdr = 0;
uchar_t osabi = ehdr->e_ident[EI_OSABI];
Half mach = ehdr->e_machine;
dbg_print(lml, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(lml, MSG_INTL(MSG_ELF_HEADER));
dbg_print(lml, MSG_ORIG(MSG_ELF_MAGIC), byte[EI_MAG0],
(byte[EI_MAG1] ? byte[EI_MAG1] : '0'),
(byte[EI_MAG2] ? byte[EI_MAG2] : '0'),
(byte[EI_MAG3] ? byte[EI_MAG3] : '0'));
dbg_print(lml, MSG_ORIG(MSG_ELF_CLASS),
conv_ehdr_class(ehdr->e_ident[EI_CLASS], 0, &inv_buf1),
conv_ehdr_data(ehdr->e_ident[EI_DATA], 0, &inv_buf2));
dbg_print(lml, MSG_ORIG(MSG_ELF_OSABI),
conv_ehdr_osabi(ehdr->e_ident[EI_OSABI], 0, &inv_buf1),
conv_ehdr_abivers(ehdr->e_ident[EI_OSABI],
ehdr->e_ident[EI_ABIVERSION], CONV_FMT_DECIMAL, &inv_buf2));
dbg_print(lml, MSG_ORIG(MSG_ELF_MACHINE),
conv_ehdr_mach(mach, 0, &inv_buf1),
conv_ehdr_vers(ehdr->e_version, 0, &inv_buf2));
dbg_print(lml, MSG_ORIG(MSG_ELF_TYPE),
conv_ehdr_type(osabi, ehdr->e_type, 0, &inv_buf1));
flgs = conv_ehdr_flags(mach, ehdr->e_flags, 0, &flags_buf);
if (flgs[0] == '[')
dbg_print(lml, MSG_ORIG(MSG_ELF_FLAGS_FMT), flgs);
else
dbg_print(lml, MSG_ORIG(MSG_ELF_FLAGS), flgs);
if (ehdr->e_shstrndx == SHN_XINDEX) {
dbg_print(lml, MSG_ORIG(MSG_ELFX_ESIZE),
EC_ADDR(ehdr->e_entry), ehdr->e_ehsize);
xshdr++;
} else
dbg_print(lml, MSG_ORIG(MSG_ELF_ESIZE), EC_ADDR(ehdr->e_entry),
ehdr->e_ehsize, ehdr->e_shstrndx);
if (ehdr->e_shnum == 0) {
dbg_print(lml, MSG_ORIG(MSG_ELFX_SHOFF), EC_OFF(ehdr->e_shoff),
ehdr->e_shentsize);
xshdr++;
} else
dbg_print(lml, MSG_ORIG(MSG_ELF_SHOFF), EC_OFF(ehdr->e_shoff),
ehdr->e_shentsize, ehdr->e_shnum);
if (ehdr->e_phnum == PN_XNUM) {
dbg_print(lml, MSG_ORIG(MSG_ELFX_PHOFF), EC_OFF(ehdr->e_phoff),
ehdr->e_phentsize);
xshdr++;
} else
dbg_print(lml, MSG_ORIG(MSG_ELF_PHOFF), EC_OFF(ehdr->e_phoff),
ehdr->e_phentsize, ehdr->e_phnum);
if ((xshdr == 0) || (shdr0 == NULL))
return;
dbg_print(lml, MSG_ORIG(MSG_STR_EMPTY));
dbg_print(lml, MSG_ORIG(MSG_SHD0_TITLE));
dbg_print(lml, MSG_ORIG(MSG_SHD0_ADDR), EC_ADDR(shdr0->sh_addr),
conv_sec_flags(osabi, mach, shdr0->sh_flags, 0, &sec_flags_buf));
dbg_print(lml, MSG_ORIG(MSG_SHD0_SIZE), EC_XWORD(shdr0->sh_size),
conv_sec_type(osabi, mach, shdr0->sh_type, 0, &inv_buf1));
dbg_print(lml, MSG_ORIG(MSG_SHD0_OFFSET), EC_OFF(shdr0->sh_offset),
EC_XWORD(shdr0->sh_entsize));
dbg_print(lml, MSG_ORIG(MSG_SHD0_LINK), EC_WORD(shdr0->sh_link),
EC_WORD(shdr0->sh_info));
dbg_print(lml, MSG_ORIG(MSG_SHD0_ALIGN), EC_XWORD(shdr0->sh_addralign));
}