~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/xfree86/loader/coff.h

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86: xc/programs/Xserver/hw/xfree86/loader/coff.h,v 1.5 1998/07/25 16:56:12 dawes Exp $ */
 
2
 
 
3
/* This file was implemented from the information in the book
 
4
   Understanding and Using COFF
 
5
   Gintaras R. Gircys
 
6
   O'Reilly, 1988
 
7
   and by looking at the Linux kernel code.
 
8
 
 
9
   It is therefore most likely free to use...
 
10
 
 
11
   If the file format changes in the COFF object, this file should be
 
12
   subsequently updated to reflect the changes.
 
13
 
 
14
   The actual loader module only uses a few of the COFF structures. 
 
15
   Only those are included here.  If you wish more information about 
 
16
   COFF, thein check out the book mentioned above.
 
17
*/
 
18
 
 
19
#ifdef HAVE_XORG_CONFIG_H
 
20
#include <xorg-config.h>
 
21
#endif
 
22
 
 
23
#ifndef _COFF_H
 
24
#define _COFF_H
 
25
 
 
26
#define  E_SYMNMLEN  8          /* Number of characters in a symbol name         */
 
27
/*
 
28
 * Intel 386/486  
 
29
 */
 
30
 
 
31
/*
 
32
 * FILE HEADER 
 
33
 */
 
34
 
 
35
typedef struct COFF_filehdr {
 
36
    unsigned short f_magic;     /* magic number                 */
 
37
    unsigned short f_nscns;     /* number of sections           */
 
38
    long f_timdat;              /* time & date stamp            */
 
39
    long f_symptr;              /* file pointer to symtab       */
 
40
    long f_nsyms;               /* number of symtab entries     */
 
41
    unsigned short f_opthdr;    /* sizeof(optional hdr)         */
 
42
    unsigned short f_flags;     /* flags                        */
 
43
} FILHDR;
 
44
 
 
45
#define FILHSZ  sizeof(FILHDR)
 
46
 
 
47
/*
 
48
 * SECTION HEADER 
 
49
 */
 
50
 
 
51
typedef struct COFF_scnhdr {
 
52
    char s_name[8];             /* section name                 */
 
53
    long s_paddr;               /* physical address             */
 
54
    long s_vaddr;               /* virtual address              */
 
55
    long s_size;                /* section size                 */
 
56
    long s_scnptr;              /* raw data for section         */
 
57
    long s_relptr;              /* relocation                   */
 
58
    long s_lnnoptr;             /* line numbers                 */
 
59
    unsigned short s_nreloc;    /* number of relocation entries */
 
60
    unsigned short s_nlnno;     /* number of line number entries */
 
61
    long s_flags;               /* flags                        */
 
62
} SCNHDR;
 
63
 
 
64
#define COFF_SCNHDR     struct COFF_scnhdr
 
65
#define COFF_SCNHSZ     sizeof(COFF_SCNHDR)
 
66
#define SCNHSZ          COFF_SCNHSZ
 
67
 
 
68
/*
 
69
 * the optional COFF header as used by Linux COFF
 
70
 */
 
71
 
 
72
typedef struct {
 
73
    char magic[2];              /* type of file                  */
 
74
    char vstamp[2];             /* version stamp                 */
 
75
    char tsize[4];              /* text size in bytes            */
 
76
    char dsize[4];              /* initialized data              */
 
77
    char bsize[4];              /* uninitialized data            */
 
78
    char entry[4];              /* entry point                   */
 
79
    char text_start[4];         /* base of text                  */
 
80
    char data_start[4];         /* base of data                  */
 
81
} AOUTHDR;
 
82
 
 
83
/*
 
84
 * SYMBOLS 
 
85
 */
 
86
 
 
87
typedef struct COFF_syment {
 
88
    union {
 
89
        char _n_name[E_SYMNMLEN];       /* Symbol name (first 8 chars)  */
 
90
        struct {
 
91
            long _n_zeroes;     /* Leading zeros               */
 
92
            long _n_offset;     /* Offset for a header section */
 
93
        } _n_n;
 
94
        char *_n_nptr[2];       /* allows for overlaying       */
 
95
    } _n;
 
96
 
 
97
    long n_value;               /* address of the segment       */
 
98
    short n_scnum;              /* Section number               */
 
99
    unsigned short n_type;      /* Type of section              */
 
100
    char n_sclass;              /* Loader class                 */
 
101
    char n_numaux;              /* Number of aux entries following */
 
102
} SYMENT;
 
103
 
 
104
#define n_name          _n._n_name
 
105
#define n_nptr          _n._n_nptr[1]
 
106
#define n_zeroes        _n._n_n._n_zeroes
 
107
#define n_offset        _n._n_n._n_offset
 
108
 
 
109
#define COFF_E_SYMNMLEN  8      /* characters in a short symbol name    */
 
110
#define COFF_E_FILNMLEN 14      /* characters in a file name            */
 
111
#define COFF_E_DIMNUM    4      /* array dimensions in aux entry        */
 
112
#define SYMNMLEN        COFF_E_SYMNMLEN
 
113
#define SYMESZ          18      /* not really sizeof(SYMENT) due to padding */
 
114
 
 
115
/* Special section number found in the symbol section */
 
116
#define N_UNDEF 0
 
117
#define N_ABS   -1
 
118
#define N_DEBUG -2
 
119
 
 
120
/* Symbol storage class values */
 
121
#define C_NULL          0
 
122
#define C_EXT           2
 
123
#define C_FILE          103
 
124
#define C_HIDEXT        107
 
125
 
 
126
/*
 
127
 * AUX Entries
 
128
 */
 
129
typedef struct COFF_auxent {
 
130
    long x_scnlen;
 
131
    long x_parmhash;
 
132
    unsigned short x_snhash;
 
133
    unsigned char x_smtyp;
 
134
    unsigned char x_smclas;
 
135
    long x_stab;
 
136
    unsigned short x_snstab;
 
137
} AUXENT;
 
138
 
 
139
/* Auxillary Symbol type values */
 
140
#define XTY_ER  0               /* Enternal Reference */
 
141
#define XTY_SD  1               /* csect section definition */
 
142
#define XTY_LD  2               /* Label definition */
 
143
#define XTY_CM  3               /* common csect definition */
 
144
 
 
145
/* Auxillary Symbol storage mapping class values */
 
146
#define XMC_PR  0               /* Program code */
 
147
#define XMC_RO  1               /* Read-only constant */
 
148
#define XMC_DB  2               /* Debug dictionary */
 
149
#define XMC_TC  3               /* TOC entry */
 
150
#define XMC_UA  4               /* Unclassified */
 
151
#define XMC_RW  5               /* Read/write data */
 
152
#define XMC_GL  6               /* Global linkage */
 
153
#define XMC_XO  7               /* Extended operation */
 
154
#define XMC_SV  8               /* Supervisor call descriptor */
 
155
#define XMC_BS  9               /* BSS class */
 
156
#define XMC_DS  10              /* Function descriptor csect */
 
157
#define XMC_UC  11              /* Unnamed FORTRAN comon */
 
158
#define XMC_TI  12              /* Reserved */
 
159
#define XMC_TB  13              /* Reserved */
 
160
#define XMC_TC0 15              /* TOC anchor */
 
161
#define XMC_TD  16              /* Scalar data entry in TOC */
 
162
 
 
163
/*
 
164
 * RELOCATION DIRECTIVES
 
165
 */
 
166
 
 
167
typedef struct COFF_reloc {
 
168
    long r_vaddr;               /* Virtual address of item    */
 
169
    long r_symndx;              /* Symbol index in the symtab */
 
170
#if defined(__powerpc__)
 
171
    union {
 
172
        unsigned short _r_type; /* old style coff relocation type */
 
173
        struct {
 
174
            char _r_rsize;      /* sign and reloc bit len */
 
175
            char _r_rtype;      /* toc relocation type */
 
176
        } _r_r;
 
177
    } _r;
 
178
#define r_otype  _r._r_type     /* old style reloc - original name */
 
179
#define r_rsize _r._r_r._r_rsize        /* extract sign and bit len    */
 
180
#define r_type _r._r_r._r_rtype /* extract toc relocation type */
 
181
#else
 
182
    unsigned short r_type;      /* Relocation type             */
 
183
#endif
 
184
} RELOC;
 
185
 
 
186
#define COFF_RELOC      struct COFF_reloc
 
187
#define COFF_RELSZ      10
 
188
#define RELSZ           COFF_RELSZ
 
189
 
 
190
/*
 
191
 * x86 Relocation types 
 
192
 */
 
193
#define R_ABS           000
 
194
#define R_DIR32         006
 
195
#define R_PCRLONG       024
 
196
 
 
197
#if defined(__powerpc__)
 
198
/*
 
199
 * Power PC
 
200
 */
 
201
#define R_LEN   0x1F            /* extract bit-length field */
 
202
#define R_SIGN  0x80            /* extract sign of relocation */
 
203
#define R_FIXUP 0x40            /* extract code-fixup bit */
 
204
 
 
205
#define RELOC_RLEN(x)   ((x)._r._r_r._r_rsize & R_LEN)
 
206
#define RELOC_RSIGN(x)  ((x)._r._r_r._r_rsize & R_SIGN)
 
207
#define RELOC_RFIXUP(x) ((x)._r._r_r._r_rsize & R_FIXUP)
 
208
#define RELOC_RTYPE(x)  ((x)._r._r_r._r_rtype)
 
209
 
 
210
/*
 
211
 * POWER and PowerPC - relocation types
 
212
 */
 
213
#define R_POS   0x00    /* A(sym) Positive Relocation */
 
214
#define R_NEG   0x01    /* -A(sym) Negative Relocation */
 
215
#define R_REL   0x02    /* A(sym-*) Relative to self */
 
216
#define R_TOC   0x03    /* A(sym-TOC) Relative to TOC */
 
217
#define R_TRL   0x12    /* A(sym-TOC) TOC Relative indirect load. */
 
218
                                        /* modifiable instruction */
 
219
#define R_TRLA  0x13    /* A(sym-TOC) TOC Rel load address. modifiable inst */
 
220
#define R_GL    0x05    /* A(external TOC of sym) Global Linkage */
 
221
#define R_TCL   0x06    /* A(local TOC of sym) Local object TOC address */
 
222
#define R_RL    0x0C    /* A(sym) Pos indirect load. modifiable instruction */
 
223
#define R_RLA   0x0D    /* A(sym) Pos Load Address. modifiable instruction */
 
224
#define R_REF   0x0F    /* AL0(sym) Non relocating ref. No garbage collect */
 
225
#define R_BA    0x08    /* A(sym) Branch absolute. Cannot modify instruction */
 
226
#define R_RBA   0x18    /* A(sym) Branch absolute. modifiable instruction */
 
227
#define R_RBAC  0x19    /* A(sym) Branch absolute constant. modifiable instr */
 
228
#define R_BR    0x0A    /* A(sym-*) Branch rel to self. non modifiable */
 
229
#define R_RBR   0x1A    /* A(sym-*) Branch rel to self. modifiable instr */
 
230
#define R_RBRC  0x1B    /* A(sym-*) Branch absolute const. */
 
231
                                                /* modifiable to R_RBR */
 
232
#define R_RTB   0x04    /* A((sym-*)/2) RT IAR Rel Branch. non modifiable */
 
233
#define R_RRTBI 0x14    /* A((sym-*)/2) RT IAR Rel Br. modifiable to R_RRTBA */
 
234
#define R_RRTBA 0x15    /* A((sym-*)/2) RT absolute br. modifiable to R_RRTBI */
 
235
#endif /* __powerpc */
 
236
 
 
237
#endif /* _COFF_H */