Back to index

cell-binutils  2.17cvs20070401
nlmswap.h
Go to the documentation of this file.
00001 /* NLM (NetWare Loadable Module) swapping routines for BFD.
00002    Copyright 1993, 2000, 2001, 2005 Free Software Foundation, Inc.
00003 
00004    Written by Fred Fish @ Cygnus Support, using ELF support as the
00005    template.
00006 
00007    This file is part of BFD, the Binary File Descriptor library.
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; either version 2 of the License, or
00012    (at your option) any later version.
00013 
00014    This program is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017    GNU General Public License for more details.
00018 
00019    You should have received a copy of the GNU General Public License
00020    along with this program; if not, write to the Free Software
00021    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00022 
00023 /* Although this is a header file, it defines functions.  It is
00024    included by NLM backends to define swapping functions that vary
00025    from one NLM to another.  The backend code must arrange for
00026    Nlm_External_xxxx to be defined appropriately, and can then include
00027    this file to get the swapping routines.
00028 
00029    At the moment this is only needed for one structure, the fixed NLM
00030    file header.  */
00031 
00032 /* Translate an NLM fixed length file header in external format into an NLM
00033    file header in internal format.  */
00034 
00035 static void
00036 nlm_swap_fixed_header_in (bfd *abfd,
00037                        void * realsrc,
00038                        Nlm_Internal_Fixed_Header *dst)
00039 {
00040   Nlm_External_Fixed_Header *src = (Nlm_External_Fixed_Header *) realsrc;
00041 
00042   memcpy (dst->signature, src->signature, NLM_SIGNATURE_SIZE);
00043   memcpy (dst->moduleName, src->moduleName, NLM_MODULE_NAME_SIZE);
00044   dst->version =
00045     H_GET_32 (abfd, src->version);
00046   dst->codeImageOffset =
00047     H_GET_32 (abfd, src->codeImageOffset);
00048   dst->codeImageSize =
00049     H_GET_32 (abfd, src->codeImageSize);
00050   dst->dataImageOffset =
00051     H_GET_32 (abfd, src->dataImageOffset);
00052   dst->dataImageSize =
00053     H_GET_32 (abfd, src->dataImageSize);
00054   dst->uninitializedDataSize =
00055     H_GET_32 (abfd, src->uninitializedDataSize);
00056   dst->customDataOffset =
00057     H_GET_32 (abfd, src->customDataOffset);
00058   dst->customDataSize =
00059     H_GET_32 (abfd, src->customDataSize);
00060   dst->moduleDependencyOffset =
00061     H_GET_32 (abfd, src->moduleDependencyOffset);
00062   dst->numberOfModuleDependencies =
00063     H_GET_32 (abfd, src->numberOfModuleDependencies);
00064   dst->relocationFixupOffset =
00065     H_GET_32 (abfd, src->relocationFixupOffset);
00066   dst->numberOfRelocationFixups =
00067     H_GET_32 (abfd, src->numberOfRelocationFixups);
00068   dst->externalReferencesOffset =
00069     H_GET_32 (abfd, src->externalReferencesOffset);
00070   dst->numberOfExternalReferences =
00071     H_GET_32 (abfd, src->numberOfExternalReferences);
00072   dst->publicsOffset =
00073     H_GET_32 (abfd, src->publicsOffset);
00074   dst->numberOfPublics =
00075     H_GET_32 (abfd, src->numberOfPublics);
00076   dst->debugInfoOffset =
00077     H_GET_32 (abfd, src->debugInfoOffset);
00078   dst->numberOfDebugRecords =
00079     H_GET_32 (abfd, src->numberOfDebugRecords);
00080   dst->codeStartOffset =
00081     H_GET_32 (abfd, src->codeStartOffset);
00082   dst->exitProcedureOffset =
00083     H_GET_32 (abfd, src->exitProcedureOffset);
00084   dst->checkUnloadProcedureOffset =
00085     H_GET_32 (abfd, src->checkUnloadProcedureOffset);
00086   dst->moduleType =
00087     H_GET_32 (abfd, src->moduleType);
00088   dst->flags =
00089     H_GET_32 (abfd, src->flags);
00090 }
00091 
00092 /* Translate an NLM fixed length file header in internal format into
00093    an NLM file header in external format.  */
00094 
00095 static void
00096 nlm_swap_fixed_header_out (bfd *abfd,
00097                         Nlm_Internal_Fixed_Header *src,
00098                         void * realdst)
00099 {
00100   Nlm_External_Fixed_Header *dst = (Nlm_External_Fixed_Header *) realdst;
00101 
00102   memset (dst, 0, sizeof *dst);
00103   memcpy (dst->signature, src->signature, NLM_SIGNATURE_SIZE);
00104   memcpy (dst->moduleName, src->moduleName, NLM_MODULE_NAME_SIZE);
00105   H_PUT_32 (abfd, src->version,
00106            dst->version);
00107   H_PUT_32 (abfd, src->codeImageOffset,
00108            dst->codeImageOffset);
00109   H_PUT_32 (abfd, src->codeImageSize,
00110            dst->codeImageSize);
00111   H_PUT_32 (abfd, src->dataImageOffset,
00112            dst->dataImageOffset);
00113   H_PUT_32 (abfd, src->dataImageSize,
00114            dst->dataImageSize);
00115   H_PUT_32 (abfd, src->uninitializedDataSize,
00116            dst->uninitializedDataSize);
00117   H_PUT_32 (abfd, src->customDataOffset,
00118            dst->customDataOffset);
00119   H_PUT_32 (abfd, src->customDataSize,
00120            dst->customDataSize);
00121   H_PUT_32 (abfd, src->moduleDependencyOffset,
00122            dst->moduleDependencyOffset);
00123   H_PUT_32 (abfd, src->numberOfModuleDependencies,
00124            dst->numberOfModuleDependencies);
00125   H_PUT_32 (abfd, src->relocationFixupOffset,
00126            dst->relocationFixupOffset);
00127   H_PUT_32 (abfd, src->numberOfRelocationFixups,
00128            dst->numberOfRelocationFixups);
00129   H_PUT_32 (abfd, src->externalReferencesOffset,
00130            dst->externalReferencesOffset);
00131   H_PUT_32 (abfd, src->numberOfExternalReferences,
00132            dst->numberOfExternalReferences);
00133   H_PUT_32 (abfd, src->publicsOffset,
00134            dst->publicsOffset);
00135   H_PUT_32 (abfd, src->numberOfPublics,
00136            dst->numberOfPublics);
00137   H_PUT_32 (abfd, src->debugInfoOffset,
00138            dst->debugInfoOffset);
00139   H_PUT_32 (abfd, src->numberOfDebugRecords,
00140            dst->numberOfDebugRecords);
00141   H_PUT_32 (abfd, src->codeStartOffset,
00142            dst->codeStartOffset);
00143   H_PUT_32 (abfd, src->exitProcedureOffset,
00144            dst->exitProcedureOffset);
00145   H_PUT_32 (abfd, src->checkUnloadProcedureOffset,
00146            dst->checkUnloadProcedureOffset);
00147   H_PUT_32 (abfd, src->moduleType,
00148            dst->moduleType);
00149   H_PUT_32 (abfd, src->flags,
00150            dst->flags);
00151 }