Commit | Line | Data |
---|---|---|
074c4a12 ILT |
1 | /* NLM (NetWare Loadable Module) swapping routines for BFD. |
2 | Copyright (C) 1993 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., 675 Mass Ave, Cambridge, MA 02139, 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 | ||
f7912fb4 ILT |
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 | ||
074c4a12 ILT |
38 | /* Translate an NLM fixed length file header in external format into an NLM |
39 | file header in internal format. */ | |
40 | ||
41 | static void | |
42 | DEFUN (nlm_swap_fixed_header_in, (abfd, realsrc, dst), | |
43 | bfd * abfd AND | |
44 | PTR realsrc AND | |
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 = | |
51 | bfd_h_get_32 (abfd, (bfd_byte *) src -> version); | |
52 | dst -> codeImageOffset = | |
53 | bfd_h_get_32 (abfd, (bfd_byte *) src -> codeImageOffset); | |
54 | dst -> codeImageSize = | |
55 | bfd_h_get_32 (abfd, (bfd_byte *) src -> codeImageSize); | |
56 | dst -> dataImageOffset = | |
57 | bfd_h_get_32 (abfd, (bfd_byte *) src -> dataImageOffset); | |
58 | dst -> dataImageSize = | |
59 | bfd_h_get_32 (abfd, (bfd_byte *) src -> dataImageSize); | |
60 | dst -> uninitializedDataSize = | |
61 | bfd_h_get_32 (abfd, (bfd_byte *) src -> uninitializedDataSize); | |
62 | dst -> customDataOffset = | |
63 | bfd_h_get_32 (abfd, (bfd_byte *) src -> customDataOffset); | |
64 | dst -> customDataSize = | |
65 | bfd_h_get_32 (abfd, (bfd_byte *) src -> customDataSize); | |
66 | dst -> moduleDependencyOffset = | |
67 | bfd_h_get_32 (abfd, (bfd_byte *) src -> moduleDependencyOffset); | |
68 | dst -> numberOfModuleDependencies = | |
69 | bfd_h_get_32 (abfd, (bfd_byte *) src -> numberOfModuleDependencies); | |
70 | dst -> relocationFixupOffset = | |
71 | bfd_h_get_32 (abfd, (bfd_byte *) src -> relocationFixupOffset); | |
72 | dst -> numberOfRelocationFixups = | |
73 | bfd_h_get_32 (abfd, (bfd_byte *) src -> numberOfRelocationFixups); | |
74 | dst -> externalReferencesOffset = | |
75 | bfd_h_get_32 (abfd, (bfd_byte *) src -> externalReferencesOffset); | |
76 | dst -> numberOfExternalReferences = | |
77 | bfd_h_get_32 (abfd, (bfd_byte *) src -> numberOfExternalReferences); | |
78 | dst -> publicsOffset = | |
79 | bfd_h_get_32 (abfd, (bfd_byte *) src -> publicsOffset); | |
80 | dst -> numberOfPublics = | |
81 | bfd_h_get_32 (abfd, (bfd_byte *) src -> numberOfPublics); | |
82 | dst -> debugInfoOffset = | |
83 | bfd_h_get_32 (abfd, (bfd_byte *) src -> debugInfoOffset); | |
84 | dst -> numberOfDebugRecords = | |
85 | bfd_h_get_32 (abfd, (bfd_byte *) src -> numberOfDebugRecords); | |
86 | dst -> codeStartOffset = | |
87 | bfd_h_get_32 (abfd, (bfd_byte *) src -> codeStartOffset); | |
88 | dst -> exitProcedureOffset = | |
89 | bfd_h_get_32 (abfd, (bfd_byte *) src -> exitProcedureOffset); | |
90 | dst -> checkUnloadProcedureOffset = | |
91 | bfd_h_get_32 (abfd, (bfd_byte *) src -> checkUnloadProcedureOffset); | |
92 | dst -> moduleType = | |
93 | bfd_h_get_32 (abfd, (bfd_byte *) src -> moduleType); | |
94 | dst -> flags = | |
95 | bfd_h_get_32 (abfd, (bfd_byte *) src -> flags); | |
96 | } | |
97 | ||
98 | /* Translate an NLM fixed length file header in internal format into | |
99 | an NLM file header in external format. */ | |
100 | ||
101 | static void | |
102 | DEFUN (nlm_swap_fixed_header_out, (abfd, src, realdst), | |
103 | bfd * abfd AND | |
104 | Nlm_Internal_Fixed_Header * src AND | |
105 | PTR realdst) | |
106 | { | |
107 | Nlm_External_Fixed_Header * dst = (Nlm_External_Fixed_Header*)realdst; | |
108 | memcpy (dst -> signature, src -> signature, NLM_SIGNATURE_SIZE); | |
109 | memcpy (dst -> moduleName, src -> moduleName, NLM_MODULE_NAME_SIZE); | |
110 | bfd_h_put_32 (abfd, (bfd_vma) src -> version, | |
111 | (bfd_byte *) dst -> version); | |
112 | bfd_h_put_32 (abfd, (bfd_vma) src -> codeImageOffset, | |
113 | (bfd_byte *) dst -> codeImageOffset); | |
114 | bfd_h_put_32 (abfd, (bfd_vma) src -> codeImageSize, | |
115 | (bfd_byte *) dst -> codeImageSize); | |
116 | bfd_h_put_32 (abfd, (bfd_vma) src -> dataImageOffset, | |
117 | (bfd_byte *) dst -> dataImageOffset); | |
118 | bfd_h_put_32 (abfd, (bfd_vma) src -> dataImageSize, | |
119 | (bfd_byte *) dst -> dataImageSize); | |
120 | bfd_h_put_32 (abfd, (bfd_vma) src -> uninitializedDataSize, | |
121 | (bfd_byte *) dst -> uninitializedDataSize); | |
122 | bfd_h_put_32 (abfd, (bfd_vma) src -> customDataOffset, | |
123 | (bfd_byte *) dst -> customDataOffset); | |
124 | bfd_h_put_32 (abfd, (bfd_vma) src -> customDataSize, | |
125 | (bfd_byte *) dst -> customDataSize); | |
126 | bfd_h_put_32 (abfd, (bfd_vma) src -> moduleDependencyOffset, | |
127 | (bfd_byte *) dst -> moduleDependencyOffset); | |
128 | bfd_h_put_32 (abfd, (bfd_vma) src -> numberOfModuleDependencies, | |
129 | (bfd_byte *) dst -> numberOfModuleDependencies); | |
130 | bfd_h_put_32 (abfd, (bfd_vma) src -> relocationFixupOffset, | |
131 | (bfd_byte *) dst -> relocationFixupOffset); | |
132 | bfd_h_put_32 (abfd, (bfd_vma) src -> numberOfRelocationFixups, | |
133 | (bfd_byte *) dst -> numberOfRelocationFixups); | |
134 | bfd_h_put_32 (abfd, (bfd_vma) src -> externalReferencesOffset, | |
135 | (bfd_byte *) dst -> externalReferencesOffset); | |
136 | bfd_h_put_32 (abfd, (bfd_vma) src -> numberOfExternalReferences, | |
137 | (bfd_byte *) dst -> numberOfExternalReferences); | |
138 | bfd_h_put_32 (abfd, (bfd_vma) src -> publicsOffset, | |
139 | (bfd_byte *) dst -> publicsOffset); | |
140 | bfd_h_put_32 (abfd, (bfd_vma) src -> numberOfPublics, | |
141 | (bfd_byte *) dst -> numberOfPublics); | |
142 | bfd_h_put_32 (abfd, (bfd_vma) src -> debugInfoOffset, | |
143 | (bfd_byte *) dst -> debugInfoOffset); | |
144 | bfd_h_put_32 (abfd, (bfd_vma) src -> numberOfDebugRecords, | |
145 | (bfd_byte *) dst -> numberOfDebugRecords); | |
146 | bfd_h_put_32 (abfd, (bfd_vma) src -> codeStartOffset, | |
147 | (bfd_byte *) dst -> codeStartOffset); | |
148 | bfd_h_put_32 (abfd, (bfd_vma) src -> exitProcedureOffset, | |
149 | (bfd_byte *) dst -> exitProcedureOffset); | |
150 | bfd_h_put_32 (abfd, (bfd_vma) src -> checkUnloadProcedureOffset, | |
151 | (bfd_byte *) dst -> checkUnloadProcedureOffset); | |
152 | bfd_h_put_32 (abfd, (bfd_vma) src -> moduleType, | |
153 | (bfd_byte *) dst -> moduleType); | |
154 | bfd_h_put_32 (abfd, (bfd_vma) src -> flags, | |
155 | (bfd_byte *) dst -> flags); | |
156 | } |