1/* Alpha VMS external format of Libraries.
2
3   Copyright 2010 Free Software Foundation, Inc.
4   Written by Tristan Gingold <gingold@adacore.com>, AdaCore.
5
6   This file is part of BFD, the Binary File Descriptor library.
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 3 of the License, or
11   (at your option) any later version.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18   You should have received a copy of the GNU General Public License
19   along with this program; if not, write to the Free Software
20   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21   MA 02110-1301, USA.  */
22
23#ifndef _VMS_LBR_H
24#define _VMS_LBR_H
25
26/* Libray HeaDer.  */
27
28/* Magic numbers.  Should match the major version.  */
29
30#define LHD_SANEID_DCX 319232342
31#define LHD_SANEID3 233579905
32#define LHD_SANEID6 233579911
33
34/* Library type.  */
35#define LBR__C_TYP_UNK    0	/* Unknown / unspecified.  */
36#define LBR__C_TYP_OBJ    1	/* Vax object.  */
37#define LBR__C_TYP_MLB    2	/* Macro.  */
38#define LBR__C_TYP_HLP    3	/* Help.  */
39#define LBR__C_TYP_TXT    4	/* Text.  */
40#define LBR__C_TYP_SHSTB  5	/* Vax shareable image.  */
41#define LBR__C_TYP_NCS    6	/* NCS.  */
42#define LBR__C_TYP_EOBJ   7	/* Alpha object.  */
43#define LBR__C_TYP_ESHSTB 8	/* Alpha shareable image.  */
44#define LBR__C_TYP_IOBJ   9	/* IA-64 object.  */
45#define LBR__C_TYP_ISHSTB 10	/* IA-64 shareable image.  */
46
47struct vms_lhd
48{
49  /* Type of the library.  See above.  */
50  unsigned char type;
51
52  /* Number of indexes.  Generally 1, 2 for object libraries.  */
53  unsigned char nindex;
54
55  unsigned char fill_1[2];
56
57  /* Sanity Id.  */
58  unsigned char sanity[4];
59
60  /* Version.  */
61  unsigned char majorid[2];
62  unsigned char minorid[2];
63
64  /* Tool name.  */
65  unsigned char lbrver[32];
66
67  /* Create time.  */
68  unsigned char credat[8];
69
70  /* Update time.  */
71  unsigned char updtim[8];
72
73  /* Size of the MHD.  */
74  unsigned char mhdusz;
75
76  unsigned char idxblkf[2];	/* Unused.  */
77  unsigned char fill_2;
78  unsigned char closerror[2];
79
80  unsigned char spareword[2];
81
82  /* First free block, and number of free blocks.  */
83  unsigned char freevbn[4];
84  unsigned char freeblk[4];
85
86  unsigned char nextrfa[6];
87  unsigned char nextvbn[4];
88
89  /* Free pre-allocated index block.  */
90  unsigned char freidxblk[4];
91  unsigned char freeidx[4];
92
93  /* Highest pre-allocated index block and in use.  */
94  unsigned char hipreal[4];
95  unsigned char hiprusd[4];
96
97  /* Number of index blocks in use.  */
98  unsigned char idxblks[4];
99
100  /* Number of index entries.  */
101  unsigned char idxcnt[4];
102
103  /* Number of modules entries.  */
104  unsigned char modcnt[4];
105
106  unsigned char fill_3[2];
107
108  /* Number of module headers.  */
109  unsigned char modhdrs[4];
110
111  /* Overhead index pointers.  */
112  unsigned char idxovh[4];
113
114  /* Update history records.  */
115  unsigned char maxluhrec[2];
116  unsigned char numluhrec[2];
117  unsigned char begluhrfa[6];
118  unsigned char endluhrfa[6];
119
120  /* DCX map.  */
121  unsigned char dcxmapvbn[4];
122
123  unsigned char fill_4[4 * 13];
124};
125
126/* Known major ids.  */
127#define LBR_MAJORID 3		/* Alpha libraries.  */
128#define LBR_ELFMAJORID 6	/* Elf libraries (new index, new data).  */
129
130/* Offset of the first IDD.  */
131#define LHD_IDXDESC 196
132
133/* InDex Description.  */
134struct vms_idd
135{
136  unsigned char flags[2];
137
138  /* Max length of the key.  */
139  unsigned char keylen[2];
140
141  /* First index block.  */
142  unsigned char vbn[4];
143};
144
145/* IDD flags.  */
146#define IDD__FLAGS_ASCII 1
147#define IDD__FLAGS_LOCKED 2
148#define IDD__FLAGS_VARLENIDX 4
149#define IDD__FLAGS_NOCASECMP 8
150#define IDD__FLAGS_NOCASENTR 16
151#define IDD__FLAGS_UPCASNTRY 32
152
153#define IDD_LENGTH 8
154
155/* Index block.  */
156#define INDEXDEF__LENGTH 512
157#define INDEXDEF__BLKSIZ 500
158
159struct vms_indexdef
160{
161  /* Number of bytes used.  */
162  unsigned char used[2];
163
164  /* VBN of the parent.  */
165  unsigned char parent[4];
166
167  unsigned char fill_1[6];
168
169  /* The key field contains vms_idx/vms_elfidx structures, which are
170     simply a key (= a string) and a rfa.  */
171  unsigned char keys[INDEXDEF__BLKSIZ];
172};
173
174/* An offset in a file.  */
175
176struct vms_rfa
177{
178  /* Logical block number, 1 based.
179     0 means that the field is absent.  Block size is 512.  */
180  unsigned char vbn[4];
181
182  /* Offset within the block.  */
183  unsigned char offset[2];
184};
185
186/* Index keys.  For version 3.  */
187
188struct vms_idx
189{
190  /* Offset from the start of the vbn, so minimum should be
191     DATA__DATA (ie 6).  */
192  struct vms_rfa rfa;
193
194  unsigned char keylen;
195  /* The length of this field is in fact keylen.  */
196  unsigned char keyname[256];
197};
198
199/* Index keys, for version 4 and later.  */
200
201struct vms_elfidx
202{
203  struct vms_rfa rfa;
204
205  unsigned char keylen[2];
206  unsigned char flags;
207  unsigned char keyname[256];
208};
209
210/* Flags of elfidx.  */
211
212#define ELFIDX__WEAK 0x01	/* Weak symbol.  */
213#define ELFIDX__GROUP 0x02	/* Group symbol.  */
214#define ELFIDX__LISTRFA 0x04	/* RFA field points to an LHS.  */
215#define ELFIDX__SYMESC 0x08	/* Long symbol.  */
216
217#define RFADEF__C_INDEX 0xffff
218
219/* List head structure.  That's what is pointed by rfa when LISTRFA flag
220   is set in elfidx.  */
221
222struct vms_lhs
223{
224  struct vms_rfa ng_g_rfa;	/* Non-group global.  */
225  struct vms_rfa ng_wk_rfa;	/* Non-group weak.  */
226  struct vms_rfa g_g_rfa;	/* Group global.  */
227  struct vms_rfa g_wk_rfa;	/* Group weak.  */
228  unsigned char flags;
229};
230
231/* List node structure.  Fields of LHS point to this structure.  */
232
233struct vms_lns
234{
235  /* Next node in the list.  */
236  struct vms_rfa nxtrfa;
237
238  /* Module associated with the key.  */
239  struct vms_rfa modrfa;
240};
241
242struct vms_datadef
243{
244  /* Number of records in this block.  */
245  unsigned char recs;
246  unsigned char fill_1;
247
248  /* Next vbn.  */
249  unsigned char link[4];
250
251  /* Data.  The first word is the record length, followed by record
252     data and a possible pad byte so that record length is always aligned.  */
253  unsigned char data[506];
254};
255#define DATA__LENGTH 512
256#define DATA__DATA 6
257
258/* Key name block.  This is used for keys longer than 128 bytes.  */
259
260struct vms_kbn
261{
262  /* Length of the key chunk.  */
263  unsigned char keylen[2];
264
265  /* RFA of the next chunk.  */
266  struct vms_rfa rfa;
267
268  /* Followed by the key chunk.  */
269};
270
271/* Module header.  */
272struct vms_mhd
273{
274  /* Fixed part.  */
275  unsigned char lbrflag;
276  unsigned char id;
277  unsigned char fill_1[2];
278  unsigned char refcnt[4];
279  unsigned char datim[8];
280
281  unsigned char objstat;
282  /* Ident or GSMATCH.  */
283  unsigned char objidlng;
284  unsigned char objid[31];
285
286  unsigned char pad1[3];
287  unsigned char otherefcnt[4];
288  unsigned char modsize[4];
289  unsigned char pad2[4];
290};
291
292#define MHD__C_MHDID 0xad	/* Value for id.  */
293#define MHD__C_MHDLEN 16	/* Fixed part length.  */
294#define MHD__C_USRDAT 16
295
296/* Flags for objstat.  */
297#define MHD__M_SELSRC 0x1	/* Selective search.  */
298#define MHD__M_OBJTIR 0x2
299#define MHD__M_WKSYM  0x4
300
301struct vms_luh
302{
303  unsigned char nxtluhblk[4];
304  unsigned char spare[2];
305  unsigned char data[506];
306};
307
308struct vms_luhdef
309{
310  unsigned char rechdr[2];
311  unsigned char reclen[2];
312};
313#define LUH__RECHDRLEN 4
314#define LUH__RECHDRMRK 0xabba
315#define LUH__DATAFLDLEN 506
316
317/* Entry in the history.  */
318
319struct vms_leh
320{
321  unsigned char date[8];
322  unsigned char nbr_units[2];
323  unsigned char action[2]; /* 1: delete, 2: insert, 3: replaced.  */
324  unsigned char idlen;
325  /* username
326     modules... */
327};
328
329#endif /* _VMS_LBR_H */
330