/**************************************************************************************
 Copyright (c) 2002 The UbixOS Project
 All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 $Id: elf.h,v 1.4 2003/05/07 05:03:37 reddawg Exp $

**************************************************************************************/

#ifndef _ELF_H
#define _ELF_H

#include <ubixos/types.h>

#define elfExecutable 0x002
#define elfLibrary    0x003


/* Elf Types */
#define ET_NONE         0  // No file type
#define ET_REL          1  // Relocatable file
#define ET_EXEC         2  // Executable file
#define ET_DYN          3  // Shared object file
#define ET_CORE         4  // Core file
#define ET_LOPROC  0xff00  // Processor-specific
#define ET_HIPROC  0xffff
/* End Elf Types */

/* Elf Machine Types */
#define EM_NONE       0  // No machine
#define EM_M32        1  // AT&T WE 32100
#define EM_SPARC      2  // SPARC
#define EM_386        3  // Intel 80386
#define EM_68K        4  // Motorola 68000
#define EM_88K        5  // Motorola 88000
#define EM_860        7  // Intel 80860
#define EM_MIPS       8  // MIPS RS3000
/* End Elf Machines Types */

/* Elf Version */
#define EV_NONE          0  // Invalid version
#define EV_CURRENT       1  // Current version
/* End Elf Version */

/* Elf Program Header Types */
#define PT_NULL          0
#define PT_LOAD          1
#define PT_DYNAMIC       2
/* End Elf Program Header Types */

typedef struct {
  uChar  eIdent[16]; /* File identification. */
  uShort eType;      /* File type. */
  uShort eMachine;   /* Machine architecture. */
  uLong  eVersion;   /* ELF format version. */
  uLong  eEntry;     /* Entry point. */
  uLong  ePhoff;     /* Program header file offset. */
  uLong  eShoff;     /* Section header file offset. */
  uLong  eFlags;     /* Architecture-specific flags. */
  uShort eEhsize;    /* Size of ELF header in bytes. */
  uShort ePhentsize; /* Size of program header entry. */
  uShort ePhnum;     /* Number of program header entries. */
  uShort eShentsize; /* Size of section header entry. */
  uShort eShnum;     /* Number of section header entries. */
  uShort eShstrndx;  /* Section name strings section. */
  } elfHeader;

typedef struct {
  uLong phType;         /* Entry type. */
  uLong phOffset;       /* File offset of contents. */
  uLong phVaddr;        /* Virtual address in memory image. */
  uLong phPaddr;        /* Physical address (not used). */
  uLong phFilesz;       /* Size of contents in file. */
  uLong phMemsz;        /* Size of contents in memory. */
  uLong phFlags;        /* Access permission flags. */
  uLong phAlign;        /* Alignment in memory and file. */
  } elfProgramheader;

typedef struct {
  uLong shName;        /* Section name (index into the section header string table). */
  uLong shType;        /* Section type. */
  uLong shFlags;       /* Section flags. */
  uLong shAddr;        /* Address in memory image. */
  uLong shOffset;      /* Offset in file. */
  uLong shSize;        /* Size in bytes. */
  uLong shLink;        /* Index of a related section. */
  uLong shInfo;        /* Depends on section type. */
  uLong shAddralign;   /* Alignment in bytes. */
  uLong shEntsize;     /* Size of each entry in section. */
  } elfSectionheader;

typedef struct {
  uLong pltOffset;
  uLong pltInfo;
  } elfPltInfo;

typedef struct {
  uLong dynName;
  uLong dynValue;
  uLong dynSize;
  uLong dynInfo;
  } elfDynsym;

typedef struct {
  uLong a;
  uLong b;
  } elfDynamic;

char *elfGetShType(int);
char *elfGetPhType(int);

#endif

