Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* NLM (NetWare Loadable Module) swapping routines for BFD. |
dc810e39 | 2 | Copyright 1993, 2000, 2001 Free Software Foundation, Inc. |
252b5132 RH |
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 | static void nlm_swap_fixed_header_in PARAMS ((bfd *, PTR, | |
33 | Nlm_Internal_Fixed_Header *)); | |
34 | static void nlm_swap_fixed_header_out PARAMS ((bfd *, | |
35 | Nlm_Internal_Fixed_Header *, | |
36 | PTR)); | |
37 | ||
38 | /* Translate an NLM fixed length file header in external format into an NLM | |
1518639e | 39 | file header in internal format. */ |
252b5132 RH |
40 | |
41 | static void | |
42 | nlm_swap_fixed_header_in (abfd, realsrc, dst) | |
43 | bfd *abfd; | |
44 | PTR realsrc; | |
45 | Nlm_Internal_Fixed_Header *dst; | |
46 | { | |
47 | Nlm_External_Fixed_Header *src = (Nlm_External_Fixed_Header *) realsrc; | |
48 | memcpy (dst->signature, src->signature, NLM_SIGNATURE_SIZE); | |
49 | memcpy (dst->moduleName, src->moduleName, NLM_MODULE_NAME_SIZE); | |
50 | dst->version = | |
dc810e39 | 51 | H_GET_32 (abfd, src->version); |
252b5132 | 52 | dst->codeImageOffset = |
dc810e39 | 53 | H_GET_32 (abfd, src->codeImageOffset); |
252b5132 | 54 | dst->codeImageSize = |
dc810e39 | 55 | H_GET_32 (abfd, src->codeImageSize); |
252b5132 | 56 | dst->dataImageOffset = |
dc810e39 | 57 | H_GET_32 (abfd, src->dataImageOffset); |
252b5132 | 58 | dst->dataImageSize = |
dc810e39 | 59 | H_GET_32 (abfd, src->dataImageSize); |
252b5132 | 60 | dst->uninitializedDataSize = |
dc810e39 | 61 | H_GET_32 (abfd, src->uninitializedDataSize); |
252b5132 | 62 | dst->customDataOffset = |
dc810e39 | 63 | H_GET_32 (abfd, src->customDataOffset); |
252b5132 | 64 | dst->customDataSize = |
dc810e39 | 65 | H_GET_32 (abfd, src->customDataSize); |
252b5132 | 66 | dst->moduleDependencyOffset = |
dc810e39 | 67 | H_GET_32 (abfd, src->moduleDependencyOffset); |
252b5132 | 68 | dst->numberOfModuleDependencies = |
dc810e39 | 69 | H_GET_32 (abfd, src->numberOfModuleDependencies); |
252b5132 | 70 | dst->relocationFixupOffset = |
dc810e39 | 71 | H_GET_32 (abfd, src->relocationFixupOffset); |
252b5132 | 72 | dst->numberOfRelocationFixups = |
dc810e39 | 73 | H_GET_32 (abfd, src->numberOfRelocationFixups); |
252b5132 | 74 | dst->externalReferencesOffset = |
dc810e39 | 75 | H_GET_32 (abfd, src->externalReferencesOffset); |
252b5132 | 76 | dst->numberOfExternalReferences = |
dc810e39 | 77 | H_GET_32 (abfd, src->numberOfExternalReferences); |
252b5132 | 78 | dst->publicsOffset = |
dc810e39 | 79 | H_GET_32 (abfd, src->publicsOffset); |
252b5132 | 80 | dst->numberOfPublics = |
dc810e39 | 81 | H_GET_32 (abfd, src->numberOfPublics); |
252b5132 | 82 | dst->debugInfoOffset = |
dc810e39 | 83 | H_GET_32 (abfd, src->debugInfoOffset); |
252b5132 | 84 | dst->numberOfDebugRecords = |
dc810e39 | 85 | H_GET_32 (abfd, src->numberOfDebugRecords); |
252b5132 | 86 | dst->codeStartOffset = |
dc810e39 | 87 | H_GET_32 (abfd, src->codeStartOffset); |
252b5132 | 88 | dst->exitProcedureOffset = |
dc810e39 | 89 | H_GET_32 (abfd, src->exitProcedureOffset); |
252b5132 | 90 | dst->checkUnloadProcedureOffset = |
dc810e39 | 91 | H_GET_32 (abfd, src->checkUnloadProcedureOffset); |
252b5132 | 92 | dst->moduleType = |
dc810e39 | 93 | H_GET_32 (abfd, src->moduleType); |
252b5132 | 94 | dst->flags = |
dc810e39 | 95 | H_GET_32 (abfd, src->flags); |
252b5132 RH |
96 | } |
97 | ||
98 | /* Translate an NLM fixed length file header in internal format into | |
1518639e | 99 | an NLM file header in external format. */ |
252b5132 RH |
100 | |
101 | static void | |
102 | nlm_swap_fixed_header_out (abfd, src, realdst) | |
103 | bfd *abfd; | |
104 | Nlm_Internal_Fixed_Header *src; | |
105 | PTR realdst; | |
106 | { | |
107 | Nlm_External_Fixed_Header *dst = (Nlm_External_Fixed_Header *) realdst; | |
108 | memset (dst, 0, sizeof *dst); | |
109 | memcpy (dst->signature, src->signature, NLM_SIGNATURE_SIZE); | |
110 | memcpy (dst->moduleName, src->moduleName, NLM_MODULE_NAME_SIZE); | |
dc810e39 AM |
111 | H_PUT_32 (abfd, src->version, |
112 | dst->version); | |
113 | H_PUT_32 (abfd, src->codeImageOffset, | |
114 | dst->codeImageOffset); | |
115 | H_PUT_32 (abfd, src->codeImageSize, | |
116 | dst->codeImageSize); | |
117 | H_PUT_32 (abfd, src->dataImageOffset, | |
118 | dst->dataImageOffset); | |
119 | H_PUT_32 (abfd, src->dataImageSize, | |
120 | dst->dataImageSize); | |
121 | H_PUT_32 (abfd, src->uninitializedDataSize, | |
122 | dst->uninitializedDataSize); | |
123 | H_PUT_32 (abfd, src->customDataOffset, | |
124 | dst->customDataOffset); | |
125 | H_PUT_32 (abfd, src->customDataSize, | |
126 | dst->customDataSize); | |
127 | H_PUT_32 (abfd, src->moduleDependencyOffset, | |
128 | dst->moduleDependencyOffset); | |
129 | H_PUT_32 (abfd, src->numberOfModuleDependencies, | |
130 | dst->numberOfModuleDependencies); | |
131 | H_PUT_32 (abfd, src->relocationFixupOffset, | |
132 | dst->relocationFixupOffset); | |
133 | H_PUT_32 (abfd, src->numberOfRelocationFixups, | |
134 | dst->numberOfRelocationFixups); | |
135 | H_PUT_32 (abfd, src->externalReferencesOffset, | |
136 | dst->externalReferencesOffset); | |
137 | H_PUT_32 (abfd, src->numberOfExternalReferences, | |
138 | dst->numberOfExternalReferences); | |
139 | H_PUT_32 (abfd, src->publicsOffset, | |
140 | dst->publicsOffset); | |
141 | H_PUT_32 (abfd, src->numberOfPublics, | |
142 | dst->numberOfPublics); | |
143 | H_PUT_32 (abfd, src->debugInfoOffset, | |
144 | dst->debugInfoOffset); | |
145 | H_PUT_32 (abfd, src->numberOfDebugRecords, | |
146 | dst->numberOfDebugRecords); | |
147 | H_PUT_32 (abfd, src->codeStartOffset, | |
148 | dst->codeStartOffset); | |
149 | H_PUT_32 (abfd, src->exitProcedureOffset, | |
150 | dst->exitProcedureOffset); | |
151 | H_PUT_32 (abfd, src->checkUnloadProcedureOffset, | |
152 | dst->checkUnloadProcedureOffset); | |
153 | H_PUT_32 (abfd, src->moduleType, | |
154 | dst->moduleType); | |
155 | H_PUT_32 (abfd, src->flags, | |
156 | dst->flags); | |
252b5132 | 157 | } |