1 /* NLM (NetWare Loadable Module) swapping routines for BFD.
2    Copyright 1993, 2000, 2001, 2005 Free Software Foundation, Inc.
3 
4    Written by Fred Fish @ Cygnus Support, using ELF support as the
5    template.
6 
7    This file is part of BFD, the Binary File Descriptor library.
8 
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
22 
23 /* Although this is a header file, it defines functions.  It is
24    included by NLM backends to define swapping functions that vary
25    from one NLM to another.  The backend code must arrange for
26    Nlm_External_xxxx to be defined appropriately, and can then include
27    this file to get the swapping routines.
28 
29    At the moment this is only needed for one structure, the fixed NLM
30    file header.  */
31 
32 /* Translate an NLM fixed length file header in external format into an NLM
33    file header in internal format.  */
34 
35 static void
36 nlm_swap_fixed_header_in (bfd *abfd,
37 			  void * realsrc,
38 			  Nlm_Internal_Fixed_Header *dst)
39 {
40   Nlm_External_Fixed_Header *src = (Nlm_External_Fixed_Header *) realsrc;
41 
42   memcpy (dst->signature, src->signature, NLM_SIGNATURE_SIZE);
43   memcpy (dst->moduleName, src->moduleName, NLM_MODULE_NAME_SIZE);
44   dst->version =
45     H_GET_32 (abfd, src->version);
46   dst->codeImageOffset =
47     H_GET_32 (abfd, src->codeImageOffset);
48   dst->codeImageSize =
49     H_GET_32 (abfd, src->codeImageSize);
50   dst->dataImageOffset =
51     H_GET_32 (abfd, src->dataImageOffset);
52   dst->dataImageSize =
53     H_GET_32 (abfd, src->dataImageSize);
54   dst->uninitializedDataSize =
55     H_GET_32 (abfd, src->uninitializedDataSize);
56   dst->customDataOffset =
57     H_GET_32 (abfd, src->customDataOffset);
58   dst->customDataSize =
59     H_GET_32 (abfd, src->customDataSize);
60   dst->moduleDependencyOffset =
61     H_GET_32 (abfd, src->moduleDependencyOffset);
62   dst->numberOfModuleDependencies =
63     H_GET_32 (abfd, src->numberOfModuleDependencies);
64   dst->relocationFixupOffset =
65     H_GET_32 (abfd, src->relocationFixupOffset);
66   dst->numberOfRelocationFixups =
67     H_GET_32 (abfd, src->numberOfRelocationFixups);
68   dst->externalReferencesOffset =
69     H_GET_32 (abfd, src->externalReferencesOffset);
70   dst->numberOfExternalReferences =
71     H_GET_32 (abfd, src->numberOfExternalReferences);
72   dst->publicsOffset =
73     H_GET_32 (abfd, src->publicsOffset);
74   dst->numberOfPublics =
75     H_GET_32 (abfd, src->numberOfPublics);
76   dst->debugInfoOffset =
77     H_GET_32 (abfd, src->debugInfoOffset);
78   dst->numberOfDebugRecords =
79     H_GET_32 (abfd, src->numberOfDebugRecords);
80   dst->codeStartOffset =
81     H_GET_32 (abfd, src->codeStartOffset);
82   dst->exitProcedureOffset =
83     H_GET_32 (abfd, src->exitProcedureOffset);
84   dst->checkUnloadProcedureOffset =
85     H_GET_32 (abfd, src->checkUnloadProcedureOffset);
86   dst->moduleType =
87     H_GET_32 (abfd, src->moduleType);
88   dst->flags =
89     H_GET_32 (abfd, src->flags);
90 }
91 
92 /* Translate an NLM fixed length file header in internal format into
93    an NLM file header in external format.  */
94 
95 static void
96 nlm_swap_fixed_header_out (bfd *abfd,
97 			   Nlm_Internal_Fixed_Header *src,
98 			   void * realdst)
99 {
100   Nlm_External_Fixed_Header *dst = (Nlm_External_Fixed_Header *) realdst;
101 
102   memset (dst, 0, sizeof *dst);
103   memcpy (dst->signature, src->signature, NLM_SIGNATURE_SIZE);
104   memcpy (dst->moduleName, src->moduleName, NLM_MODULE_NAME_SIZE);
105   H_PUT_32 (abfd, src->version,
106 	    dst->version);
107   H_PUT_32 (abfd, src->codeImageOffset,
108 	    dst->codeImageOffset);
109   H_PUT_32 (abfd, src->codeImageSize,
110 	    dst->codeImageSize);
111   H_PUT_32 (abfd, src->dataImageOffset,
112 	    dst->dataImageOffset);
113   H_PUT_32 (abfd, src->dataImageSize,
114 	    dst->dataImageSize);
115   H_PUT_32 (abfd, src->uninitializedDataSize,
116 	    dst->uninitializedDataSize);
117   H_PUT_32 (abfd, src->customDataOffset,
118 	    dst->customDataOffset);
119   H_PUT_32 (abfd, src->customDataSize,
120 	    dst->customDataSize);
121   H_PUT_32 (abfd, src->moduleDependencyOffset,
122 	    dst->moduleDependencyOffset);
123   H_PUT_32 (abfd, src->numberOfModuleDependencies,
124 	    dst->numberOfModuleDependencies);
125   H_PUT_32 (abfd, src->relocationFixupOffset,
126 	    dst->relocationFixupOffset);
127   H_PUT_32 (abfd, src->numberOfRelocationFixups,
128 	    dst->numberOfRelocationFixups);
129   H_PUT_32 (abfd, src->externalReferencesOffset,
130 	    dst->externalReferencesOffset);
131   H_PUT_32 (abfd, src->numberOfExternalReferences,
132 	    dst->numberOfExternalReferences);
133   H_PUT_32 (abfd, src->publicsOffset,
134 	    dst->publicsOffset);
135   H_PUT_32 (abfd, src->numberOfPublics,
136 	    dst->numberOfPublics);
137   H_PUT_32 (abfd, src->debugInfoOffset,
138 	    dst->debugInfoOffset);
139   H_PUT_32 (abfd, src->numberOfDebugRecords,
140 	    dst->numberOfDebugRecords);
141   H_PUT_32 (abfd, src->codeStartOffset,
142 	    dst->codeStartOffset);
143   H_PUT_32 (abfd, src->exitProcedureOffset,
144 	    dst->exitProcedureOffset);
145   H_PUT_32 (abfd, src->checkUnloadProcedureOffset,
146 	    dst->checkUnloadProcedureOffset);
147   H_PUT_32 (abfd, src->moduleType,
148 	    dst->moduleType);
149   H_PUT_32 (abfd, src->flags,
150 	    dst->flags);
151 }
152