����14-1 linux/include/a.out.h


  1 #ifndef _A_OUT_H

  2 #define _A_OUT_H

  3

  4 #define __GNU_EXEC_MACROS__

  5

    // ��6--108���Ǹ��ļ���1���֡�����Ŀ���ļ�ִ�нṹ�Լ���ز����ĺ궨�塣

    // Ŀ���ļ�ͷ�ṹ���μ���������ϸ˵����

    // =============================

    // unsigned long a_magic        // ִ���ļ�ħ����ʹ��N_MAGIC�Ⱥ���ʡ�

    // unsigned a_text              // ���볤�ȣ��ֽ�����

    // unsigned a_data              // ���ݳ��ȣ��ֽ�����

    // unsigned a_bss               // �ļ��е�δ��ʼ�����������ȣ��ֽ�����

    // unsigned a_syms              // �ļ��еķ��ű����ȣ��ֽ�����

    // unsigned a_entry             // ִ�п�ʼ��ַ��

    // unsigned a_trsize            // �����ض�λ��Ϣ���ȣ��ֽ�����

    // unsigned a_drsize            // �����ض�λ��Ϣ���ȣ��ֽ�����

    // -----------------------------

  6 struct exec {

  7   unsigned long a_magic;        /* Use macros N_MAGIC, etc for access */

  8   unsigned a_text;              /* length of text, in bytes */

  9   unsigned a_data;              /* length of data, in bytes */

 10   unsigned a_bss;               /* length of uninitialized data area for file, in bytes */

 11   unsigned a_syms;              /* length of symbol table data in file, in bytes */

 12   unsigned a_entry;             /* start address */

 13   unsigned a_trsize;            /* length of relocation info for text, in bytes */

 14   unsigned a_drsize;            /* length of relocation info for data, in bytes */

 15 };

 16

    // ����ȡ����exec�ṹ�е�ħ����

 17 #ifndef N_MAGIC

 18 #define N_MAGIC(exec) ((exec).a_magic)

 19 #endif

 20

 21 #ifndef OMAGIC

 22 /* Code indicating object file or impure executable.  */

    /* ָ��ΪĿ���ļ����߲����Ŀ�ִ���ļ��Ĵ��� */

    // ��ʷ��������PDP-11������ϣ�ħ�����������ǰ˽�����0407��0x107������λ��ִ�г���

    // ͷ�ṹ�Ŀ�ʼ����ԭ����PDP-11��һ����תָ���ʾ��ת�����7���ֺ�Ĵ��뿪ʼ����

    // �������س���loader���Ϳ����ڰ�ִ���ļ������ڴ��ֱ����ת��ָ�ʼ�����С� ����

    // ��û�г���ʹ�����ַ�����������˽�����ȴ��Ϊʶ���ļ����͵ı�־��ħ����������������

    // OMAGIC������Ϊ��Old Magic ����˼��

 23 #define OMAGIC 0407

 24 /* Code indicating pure executable.  */

    /* ָ��Ϊ����ִ���ļ��Ĵ��� */       // New Magic��1975���Ժ�ʼʹ�á��漰�����ơ�

 25 #define NMAGIC 0410                  // 0410 == 0x108

 26 /* Code indicating demand-paged executable.  */

    /* ָ��Ϊ�����ҳ�����Ŀ�ִ���ļ� */ // ��ͷ�ṹռ���ļ���ʼ��1K�ռ䡣

 27 #define ZMAGIC 0413                  // 0413 == 0x10b

 28 #endif /* not OMAGIC */

 29 // ���⻹��һ��QMAGIC����Ϊ�˽�Լ����������������ִ���ļ���ͷ�ṹ�������մ�š�

    // ����������ж�ħ���ֶε���ȷ�ԡ����ħ�����ܱ�ʶ���򷵻��档

 30 #ifndef N_BADMAG

 31 #define N_BADMAG(x)                                     \

 32  (N_MAGIC(x) != OMAGIC && N_MAGIC(x) != NMAGIC          \

 33   && N_MAGIC(x) != ZMAGIC)

 34 #endif

 35

 36 #define _N_BADMAG(x)                                    \

 37  (N_MAGIC(x) != OMAGIC && N_MAGIC(x) != NMAGIC          \

 38   && N_MAGIC(x) != ZMAGIC)

 39

    // Ŀ���ļ�ͷ�ṹĩ�˵�1024�ֽ�֮��ij��ȡ�

 40 #define _N_HDROFF(x) (SEGMENT_SIZE - sizeof (struct exec))

 41

    // ��������ڲ���Ŀ���ļ������ݣ�����.oģ���ļ��Ϳ�ִ���ļ���

 

    // ���벿����ʼƫ��ֵ��

    // ����ļ��� ZMAGIC���͵ģ�����ִ���ļ�����ô���벿���Ǵ�ִ���ļ���1024�ֽ�ƫ�ƴ�

    // ��ʼ������ִ�д��벿�ֽ���ִ��ͷ�ṹĩ�ˣ�32�ֽڣ���ʼ�����ļ���ģ���ļ���OMAGIC

    // ���ͣ���

 42 #ifndef N_TXTOFF

 43 #define N_TXTOFF(x) \

 44  (N_MAGIC(x) == ZMAGIC ? _N_HDROFF((x)) + sizeof (struct exec) : sizeof (struct exec))

 45 #endif

 46

    // ���ݲ�����ʼƫ��ֵ���Ӵ��벿��ĩ�˿�ʼ��

 47 #ifndef N_DATOFF

 48 #define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text)

 49 #endif

 50

    // �����ض�λ��Ϣƫ��ֵ�������ݲ���ĩ�˿�ʼ��

 51 #ifndef N_TRELOFF

 52 #define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data)

 53 #endif

 54

    // �����ض�λ��Ϣƫ��ֵ���Ӵ����ض�λ��Ϣĩ�˿�ʼ��

 55 #ifndef N_DRELOFF

 56 #define N_DRELOFF(x) (N_TRELOFF(x) + (x).a_trsize)

 57 #endif

 58

    // ���ű�ƫ��ֵ�����������ݶ��ض�λ��ĩ�˿�ʼ��

 59 #ifndef N_SYMOFF

 60 #define N_SYMOFF(x) (N_DRELOFF(x) + (x).a_drsize)

 61 #endif

 62

    // �ַ�����Ϣƫ��ֵ���ڷ��ű�֮��

 63 #ifndef N_STROFF

 64 #define N_STROFF(x) (N_SYMOFF(x) + (x).a_syms)

 65 #endif

 66

    // ����Կ�ִ���ļ������ص��ڴ棨�߼��ռ䣩�е�λ��������в�����

 67 /* Address of text segment in memory after it is loaded.  */

    /* ����μ��غ����ڴ��еĵ�ַ */

 68 #ifndef N_TXTADDR

 69 #define N_TXTADDR(x) 0                            // �ɼ�������δӵ�ַ0��ʼִ�С�

 70 #endif

 71

 72 /* Address of data segment in memory after it is loaded.

 73    Note that it is up to you to define SEGMENT_SIZE

 74    on machines not listed here.  */

    /* ���ݶμ��غ����ڴ��еĵ�ַ��

       ע�⣬��������û���г����ƵĻ�������Ҫ���Լ�������

       ��Ӧ��SEGMENT_SIZE */

 75 #if defined(vax) || defined(hp300) || defined(pyr)

 76 #define SEGMENT_SIZE PAGE_SIZE

 77 #endif

 78 #ifdef  hp300

 79 #define PAGE_SIZE       4096

 80 #endif

 81 #ifdef  sony

 82 #define SEGMENT_SIZE    0x2000

 83 #endif  /* Sony.  */

 84 #ifdef is68k

 85 #define SEGMENT_SIZE 0x20000

 86 #endif

 87 #if defined(m68k) && defined(PORTAR)

 88 #define PAGE_SIZE 0x400

 89 #define SEGMENT_SIZE PAGE_SIZE

 90 #endif

 91

    // ���Linux 0.12�ں˰��ڴ�ҳ����Ϊ4KB���δ�С����Ϊ1KB�����û��ʹ������Ķ��塣

 92 #define PAGE_SIZE 4096

 93 #define SEGMENT_SIZE 1024

 94

    // �Զ�Ϊ��Ĵ�С����λ��ʽ����

 95 #define _N_SEGMENT_ROUND(x) (((x) + SEGMENT_SIZE - 1) & ~(SEGMENT_SIZE - 1))

 96

    // �����β��ַ��

 97 #define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text)

 98

    // ���ݶο�ʼ��ַ��

    // ����ļ���OMAGIC���͵ģ���ô���ݶξ�ֱ�ӽ������κ��档����Ļ����ݶε�ַ�Ӵ���

    // �κ���α߽翪ʼ��1KB�߽���룩������ZMAGIC���͵��ļ���

 99 #ifndef N_DATADDR

100 #define N_DATADDR(x) \

101     (N_MAGIC(x)==OMAGIC? (_N_TXTENDADDR(x)) \

102      : (_N_SEGMENT_ROUND (_N_TXTENDADDR(x))))

103 #endif

104

105 /* Address of bss segment in memory after it is loaded.  */

    /* bss�μ��ص��ڴ��Ժ�ĵ�ַ */

    // δ��ʼ�����ݶ�bbsλ�����ݶκ��棬�������ݶΡ�

106 #ifndef N_BSSADDR

107 #define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)

108 #endif

109

    // ��110��185���ǵ�2���֡���Ŀ���ļ��еķ��ű������ز�������ж����˵����

    // a.outĿ���ļ��з��ű���ṹ�����ű���¼�ṹ�����μ���������ϸ˵����

110 #ifndef N_NLIST_DECLARED

111 struct nlist {

112   union {

113     char *n_name;

114     struct nlist *n_next;

115     long n_strx;

116   } n_un;

117   unsigned char n_type;        // ���ֽڷֳ�3���ֶΣ�146--154������Ӧ�ֶε������롣

118   char n_other;

119   short n_desc;

120   unsigned long n_value;

121 };

122 #endif

123

    // ���涨��nlist�ṹ��n_type�ֶ�ֵ�ij������š�

124 #ifndef N_UNDF

125 #define N_UNDF 0

126 #endif

127 #ifndef N_ABS

128 #define N_ABS 2

129 #endif

130 #ifndef N_TEXT

131 #define N_TEXT 4

132 #endif

133 #ifndef N_DATA

134 #define N_DATA 6

135 #endif

136 #ifndef N_BSS

137 #define N_BSS 8

138 #endif

139 #ifndef N_COMM

140 #define N_COMM 18

141 #endif

142 #ifndef N_FN

143 #define N_FN 15

144 #endif

145

    // ����3������������nlist�ṹ��n_type�ֶε������루�˽��̱�ʾ����

146 #ifndef N_EXT

147 #define N_EXT 1                  // 0x01��0b0000,0001�������Ƿ����ⲿ�ģ�ȫ�ֵģ���

148 #endif

149 #ifndef N_TYPE

150 #define N_TYPE 036               // 0x1e��0b0001,1110�����ŵ�����λ��

151 #endif

152 #ifndef N_STAB                   // STAB -- ���ű����ͣ�Symbol table types����

153 #define N_STAB 0340              // 0xe0��0b1110,0000���⼸���������ڷ��ŵ�������

154 #endif

155

156 /* The following type indicates the definition of a symbol as being

157    an indirect reference to another symbol.  The other symbol

158    appears as an undefined reference, immediately following this symbol.

159

160    Indirection is asymmetrical.  The other symbol's value will be used

161    to satisfy requests for the indirect symbol, but not vice versa.

162    If the other symbol does not have a definition, libraries will

163    be searched to find a definition.  */

    /* ���������ָ����һ�����ŵĶ�������Ϊ����һ�����ŵļ�����á����Ӹ�

     * ���ŵ������ķ��ų���Ϊδ��������á�

     *

     * ���ּ�������Dz��ԳƵġ���һ�����ŵ�ֵ�������������ӷ��ŵ�Ҫ��

     * ����֮��Ȼ�������һ������û�ж��壬����������Ѱ��һ������ */

164 #define N_INDR 0xa

165

166 /* The following symbols refer to set elements.

167    All the N_SET[ATDB] symbols with the same name form one set.

168    Space is allocated for the set in the text section, and each set

169    element's value is stored into one word of the space.

170    The first word of the space is the length of the set (number of elements).

171

172    The address of the set is made into an N_SETV symbol

173    whose name is the same as the name of the set.

174    This symbol acts like a N_DATA global symbol

175    in that it can satisfy undefined external references.  */

    /* ����ķ����뼯��Ԫ���йء����о�����ͬ����N_SET[ATDB]�ķ���

       �γ�һ�����ϡ��ڴ��벿������Ϊ���Ϸ����˿ռ䣬����ÿ������Ԫ��

       ��ֵ�����һ���֣�word���Ŀռ��С��ռ�ĵ�һ���ִ��м��ϵij��ȣ�����Ԫ����Ŀ����

     

       ���ϵĵ�ַ������һ��N_SETV�����У����������뼯��ͬ����

       ������δ������ⲿ���÷��棬�÷��ŵ���Ϊ��һ��N_DATAȫ�ַ��š�*/

176

177 /* These appear as input to LD, in a .o file.  */

    /* ������Щ������ .o �ļ�������Ϊ���ӳ���LD�����롣*/

178 #define N_SETA  0x14        /* Absolute set element symbol */  /* ���Լ���Ԫ�ط��� */

179 #define N_SETT  0x16        /* Text set element symbol */      /* ���뼯��Ԫ�ط��� */

180 #define N_SETD  0x18        /* Data set element symbol */      /* ���ݼ���Ԫ�ط��� */

181 #define N_SETB  0x1A        /* Bss set element symbol */       /* Bss����Ԫ�ط��� */

182

183 /* This is output from LD.  */

    /* ������LD�������*/

184 #define N_SETV  0x1C        /* Pointer to set vector in data area.  */

                                /* ָ���������м���������*/

185

186 #ifndef N_RELOCATION_INFO_DECLARED

187

188 /* This structure describes a single relocation to be performed.

189    The text-relocation section of the file is a vector of these structures,

190    all of which apply to the text section.

191    Likewise, the data-relocation section applies to the data section.  */

    /* ����ṹ���������ض�λ������ִ�С�

       �ļ��Ĵ����ض�λ��������Щ�ṹ��һ�����飬������Щ�����ڴ��벿�֡�

       ���Ƶأ������ض�λ�����������ݲ��֡�*/

192

    // a.outĿ���ļ��д���������ض�λ��Ϣ�ṹ��

193 struct relocation_info

194 {

195   /* Address (within segment) to be relocated.  */

      /* ������Ҫ�ض�λ�ĵ�ַ��*/

196   int r_address;

197   /* The meaning of r_symbolnum depends on r_extern.  */

      /* r_symbolnum�ĺ�����r_extern�йء�*/

198   unsigned int r_symbolnum:24;

199   /* Nonzero means value is a pc-relative offset

200      and it should be relocated for changes in its own address

201      as well as for changes in the symbol or section specified.  */

      /* ������ζ��ֵ��һ��pc��ص�ƫ��ֵ����������Լ���ַ�ռ�

         �Լ����Ż�ָ���Ľڸı�ʱ����Ҫ���ض�λ */

202   unsigned int r_pcrel:1;

203   /* Length (as exponent of 2) of the field to be relocated.

204      Thus, a value of 2 indicates 1<<2 bytes.  */

      /* ��Ҫ���ض�λ���ֶγ��ȣ���2�Ĵη�����

         ��ˣ���ֵ��2���ʾ1<<2�ֽ�����*/

205   unsigned int r_length:2;

206   /* 1 => relocate with value of symbol.

207           r_symbolnum is the index of the symbol

208           in file's the symbol table.

209      0 => relocate with the address of a segment.

210           r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS

211           (the N_EXT bit may be set also, but signifies nothing).  */

      /* 1 => �Է��ŵ�ֵ�ض�λ��

              r_symbolnum���ļ����ű��з��ŵ�������

         0 => �Զεĵ�ַ�����ض�λ��

              r_symbolnum��N_TEXT��N_DATA��N_BSS��N_ABS

              (N_EXT����λҲ���Ա����ã����Ǻ�������)��*/

212   unsigned int r_extern:1;

213   /* Four bits that aren't used, but when writing an object file

214      it is desirable to clear them.  */

      /* û��ʹ�õ�4������λ�����ǵ�����дһ��Ŀ���ļ�ʱ

         ��ý����Ǹ�λ����*/

215   unsigned int r_pad:4;

216 };

217 #endif /* no N_RELOCATION_INFO_DECLARED.  */

218

219

220 #endif /* __A_OUT_GNU_H__ */

221