#ifndef __A_OUT_GNU_H__
#define __A_OUT_GNU_H__#define __GNU_EXEC_MACROS__#ifndef __STRUCT_EXEC_OVERRIDE__//定义执行文件结构
struct exec
{unsigned long a_info; /* Use macros N_MAGIC, etc for access */unsigned a_text; /* length of text, in bytes */unsigned a_data; /* length of data, in bytes */unsigned a_bss; /* length of uninitialized data area for file, in bytes */unsigned a_syms; /* length of symbol table data in file, in bytes */unsigned a_entry; /* start address */unsigned a_trsize; /* length of relocation info for text, in bytes */unsigned a_drsize; /* length of relocation info for data, in bytes */
};#endif /* __STRUCT_EXEC_OVERRIDE__ *///机器类型设定
/* these go in the N_MACHTYPE field */
enum machine_type {
#if defined (M_OLDSUN2)M__OLDSUN2 = M_OLDSUN2,
#elseM_OLDSUN2 = 0,
#endif
#if defined (M_68010)M__68010 = M_68010,
#elseM_68010 = 1,
#endif
#if defined (M_68020)M__68020 = M_68020,
#elseM_68020 = 2,
#endif
#if defined (M_SPARC)M__SPARC = M_SPARC,
#elseM_SPARC = 3,
#endif/* skip a bunch so we don't run into any of sun's numbers */M_386 = 100,
};//定义MAGIC地址为32位的有效值。0-16位
#if !defined (N_MAGIC)
#define N_MAGIC(exec) ((exec).a_info & 0xffff)
#endif//获取机器类型 16-23位
#define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff))//标记 24-31位
#define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff)//设定Magic,机器类型,标记
#define N_SET_INFO(exec, magic, type, flags) \((exec).a_info = ((magic) & 0xffff) \| (((int)(type) & 0xff) << 16) \| (((flags) & 0xff) << 24))//单独设定Magic值
#define N_SET_MAGIC(exec, magic) \((exec).a_info = (((exec).a_info & 0xffff0000) | ((magic) & 0xffff)))//设定机器类型
#define N_SET_MACHTYPE(exec, machtype) \((exec).a_info = \((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16))//设定机器标记
#define N_SET_FLAGS(exec, flags) \((exec).a_info = \((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24))//不纯净的执行方式
/* Code indicating object file or impure executable. */
#define OMAGIC 0407//纯净的执行方式
/* Code indicating pure executable. */
#define NMAGIC 0410//需求页执行方式
/* Code indicating demand-paged executable. */
#define ZMAGIC 0413//带有头文件的需求页执行方式
/* This indicates a demand-paged executable with the header in the text. The first page is unmapped to help trap NULL pointer references */
#define QMAGIC 0314//核心文件执行方式
/* Code indicating core file. */
#define CMAGIC 0421//判断是不是没有定义的执行方式 1为该执行方式没有定义 0为已经定义的执行方式
#if !defined (N_BADMAG)
#define N_BADMAG(x) (N_MAGIC(x) != OMAGIC \&& N_MAGIC(x) != NMAGIC \&& N_MAGIC(x) != ZMAGIC \&& N_MAGIC(x) != QMAGIC)
#endif//获取1024空间存放程序信息后的剩余的大小。
#define _N_HDROFF(x) (1024 - sizeof (struct exec))//获取TEXT文本的偏移地址
//如果为按需求页执行方式(ZMAGIC); 剩余文本空间为1024;
//如果为带有头文件的需求页执行方式(QMAGIC); 剩余文本空间为0;
//如果2者都不是 剩余文本空间为执行程序空间的大小;
#if !defined (N_TXTOFF)
#define N_TXTOFF(x) \(N_MAGIC(x) == ZMAGIC ? _N_HDROFF((x)) + sizeof (struct exec) : \(N_MAGIC(x) == QMAGIC ? 0 : sizeof (struct exec)))
#endif//获取DATA数据的偏移地址
#if !defined (N_DATOFF)
#define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text)
#endif//获取重新配置Text数据的偏移地址
#if !defined (N_TRELOFF)
#define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data)
#endif//获取重新配置dat啊数据的偏移地址
#if !defined (N_DRELOFF)
#define N_DRELOFF(x) (N_TRELOFF(x) + (x).a_trsize)
#endif//获取标志表数据的偏移地址
#if !defined (N_SYMOFF)
#define N_SYMOFF(x) (N_DRELOFF(x) + (x).a_drsize)
#endif//获取BSS数据的偏移地址
#if !defined (N_STROFF)
#define N_STROFF(x) (N_SYMOFF(x) + (x).a_syms)
#endif//TEXT地址 如果为 带有头文件的需求页执行方式 地址为4096 不是为0
/* Address of text segment in memory after it is loaded. */
#if !defined (N_TXTADDR)
#define N_TXTADDR(x) (N_MAGIC(x) == QMAGIC ? PAGE_SIZE : 0)
#endif//段的大小设定
/* Address of data segment in memory after it is loaded.Note that it is up to you to define SEGMENT_SIZEon machines not listed here. */
#if defined(vax) || defined(hp300) || defined(pyr)
#define SEGMENT_SIZE page_size
#endif
#ifdef sony
#define SEGMENT_SIZE 0x2000 //8192
#endif /* Sony. */
#ifdef is68k
#define SEGMENT_SIZE 0x20000 //131072
#endif
#if defined(m68k) && defined(PORTAR)
#define PAGE_SIZE 0x400 //1024
#define SEGMENT_SIZE PAGE_SIZE //4096
#endif//linux段的大小设定 1024
#ifdef linux
#include <linux/page.h>
#define SEGMENT_SIZE 1024
#endif//段的大小。需要段X×每个段的大小
#define _N_SEGMENT_ROUND(x) (((x) + SEGMENT_SIZE - 1) & ~(SEGMENT_SIZE - 1))//执行程序Text文件的结束点。
#define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text)//获取执行程序DATA数据的地址
//如果为不纯净的执行方式 在TEXT文件结束点;
//如果为非 地址为X的TEXT位置×每个段的大小
#ifndef N_DATADDR
#define N_DATADDR(x) \(N_MAGIC(x)==OMAGIC? (_N_TXTENDADDR(x)) \: (_N_SEGMENT_ROUND (_N_TXTENDADDR(x))))
#endif/* Address of bss segment in memory after it is loaded. */
//获取执行程序BSS数据的地址
#if !defined (N_BSSADDR)
#define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)
#endif//定义nList列表结构
#if !defined (N_NLIST_DECLARED)
struct nlist {union {char *n_name;struct nlist *n_next;long n_strx;} n_un; //统一4位的unionunsigned char n_type; //列表类型char n_other; //列表它项short n_desc; //减少值unsigned long n_value; //列表值
};
#endif /* no N_NLIST_DECLARED. *///定义必要的宏!
#if !defined (N_UNDF)
#define N_UNDF 0
#endif
#if !defined (N_ABS)
#define N_ABS 2
#endif
#if !defined (N_TEXT)
#define N_TEXT 4
#endif
#if !defined (N_DATA)
#define N_DATA 6
#endif
#if !defined (N_BSS)
#define N_BSS 8
#endif
#if !defined (N_FN)
#define N_FN 15
#endif#if !defined (N_EXT)
#define N_EXT 1
#endif
#if !defined (N_TYPE)
#define N_TYPE 036
#endif
#if !defined (N_STAB)
#define N_STAB 0340
#endif/* The following type indicates the definition of a symbol as beingan indirect reference to another symbol. The other symbolappears as an undefined reference, immediately following this symbol.Indirection is asymmetrical. The other symbol's value will be usedto satisfy requests for the indirect symbol, but not vice versa.If the other symbol does not have a definition, libraries willbe searched to find a definition. */
#define N_INDR 0xa/* The following symbols refer to set elements.All the N_SET[ATDB] symbols with the same name form one set.Space is allocated for the set in the text section, and each setelement's value is stored into one word of the space.The first word of the space is the length of the set (number of elements).The address of the set is made into an N_SETV symbolwhose name is the same as the name of the set.This symbol acts like a N_DATA global symbolin that it can satisfy undefined external references. *///元素标记
/* These appear as input to LD, in a .o file. */
#define N_SETA 0x14 /* Absolute set element symbol */
#define N_SETT 0x16 /* Text set element symbol */
#define N_SETD 0x18 /* Data set element symbol */
#define N_SETB 0x1A /* Bss set element symbol *//* This is output from LD. */
#define N_SETV 0x1C /* Pointer to set vector in data area. */#if !defined (N_RELOCATION_INFO_DECLARED)
/* This structure describes a single relocation to be performed.The text-relocation section of the file is a vector of these structures,all of which apply to the text section.Likewise, the data-relocation section applies to the data section. *///重新分配信息结构8位,2整数大小
struct relocation_info
{//重新分配地址/* Address (within segment) to be relocated. */int r_address;//标号数/* The meaning of r_symbolnum depends on r_extern. */unsigned int r_symbolnum:24;//pcrel偏移位/* Nonzero means value is a pc-relative offsetand it should be relocated for changes in its own addressas well as for changes in the symbol or section specified. */unsigned int r_pcrel:1;//分配域的长度/* Length (as exponent of 2) of the field to be relocated.Thus, a value of 2 indicates 1<<2 bytes. */unsigned int r_length:2;//扩展位/* 1 => relocate with value of symbol.r_symbolnum is the index of the symbolin file's the symbol table.0 => relocate with the address of a segment.r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS(the N_EXT bit may be set also, but signifies nothing). */ unsigned int r_extern:1;//pad值/* Four bits that aren't used, but when writing an object fileit is desirable to clear them. */
#ifdef NS32Kunsigned r_bsr:1;unsigned r_disp:1;unsigned r_pad:2;
#elseunsigned int r_pad:4;
#endif
};
#endif /* no N_RELOCATION_INFO_DECLARED. */#endif /* __A_OUT_GNU_H__ */