⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loader.hxx

📁 eCos/RedBoot for勤研ARM AnywhereII(4510) 含全部源代码
💻 HXX
📖 第 1 页 / 共 2 页
字号:
#ifndef CYGONCE_LOADER_LOADER_HXX
#define CYGONCE_LOADER_LOADER_HXX

//==========================================================================
//
//      loader.hxx
//
//      ELF dynamic loader definitions
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s):           nickg
// Contributors:        nickg
// Date:                2000-11-15
// Purpose:             Define ELF dynamic loader
// Description: The classes defined here collectively implement the
//              internal API of the ELF dynamic loader.
// Usage:       #include <cyg/loader/loader.hxx>
//
//####DESCRIPTIONEND####
//
//==========================================================================

#include <pkgconf/system.h>

#ifndef CYG_LOADER_DYNAMIC_LD

#include <cyg/loader/elf.h>           // ELF data structures

#ifdef __cplusplus

#include <cyg/kernel/ktypes.h>
#include <cyg/infra/cyg_ass.h>         // assertion macros

#include <cyg/infra/clist.hxx>

// -------------------------------------------------------------------------
// Forward definitions

class Cyg_LoaderStream;
class Cyg_LoaderMemBlock;
class Cyg_LoaderMemAlloc;
class Cyg_LoadObject_Base;
class Cyg_LoadObject_Proc;
class Cyg_LoadObject;
class Cyg_Loader;

// -------------------------------------------------------------------------
// Error codes

#define CYG_LOADERR_NOERROR             0       // No error
#define CYG_LOADERR_NOT_ELF             1       // Not ELF format file
#define CYG_LOADERR_INVALID_CLASS       2       // Not expected file class
#define CYG_LOADERR_INVALID_BYTEORDER   3       // Not expected byte order
#define CYG_LOADERR_INVALID_VERSION     4       // Not expected ELF version
#define CYG_LOADERR_INVALID_MACHINE     5       // Not expected machine type
#define CYG_LOADERR_NO_MEMORY           6       // No memory
#define CYG_LOADERR_EOF                 7       // End of input stream
#define CYG_LOADERR_SEEK                8       // Cannot seek to stream position
#define CYG_LOADERR_INVALID_RELOC       9       // Invalid or unexpected relocation
#define CYG_LOADERR_NO_HASHTABLE        10      // No hash table in ELF file
#define CYG_LOADERR_NO_SYMTAB           11      // No symbol table in ELF file
#define CYG_LOADERR_NO_STRTAB           12      // No srting table in ELF file
#define CYG_LOADERR_NO_SYMBOL           13      // Symbol not found

// -------------------------------------------------------------------------
// Value for undefined or otherwise invalid symbol addresses.

#define CYG_LOADER_NULLSYMADDR          0

// -------------------------------------------------------------------------
// Loader Stream base class.
// This defines the interface to data streams that are ELF dynamic executable
// files.

class Cyg_LoaderStream
{
public:

    Cyg_LoaderStream();                         // Constructor

    virtual ~Cyg_LoaderStream();                // Destructor


    // The following functions are virtual and are supplied by a
    // derived class to access to data stream.
    
    virtual cyg_code get_byte(CYG_BYTE *val); // Get a byte from the stream

    virtual cyg_code get_data(CYG_BYTE *addr, CYG_ADDRWORD size);

    virtual cyg_code seek(CYG_ADDRWORD pos);  // seek to given position

    // The following functions all make use of the virtual functions
    // to access the data stream.
    
    cyg_code get_word16(CYG_WORD16 *val);       // get a 16 bit value

    cyg_code get_word32(CYG_WORD32 *val);       // get a 32 bit value

    cyg_code get_word64(CYG_WORD64 *val);       // get a 64 bit value
};

// -------------------------------------------------------------------------
// Memory allocation object. All memory allocated by the Loader is described
// by one of these. 

struct Cyg_LoaderMemBlock
    : public Cyg_DNode_T<Cyg_LoaderMemBlock>
{
    void                *address;       // data address
    cyg_int32           size;           // block size
    cyg_int32           alignment;      // block alignment
    Cyg_LoaderMemAlloc  *mem;           // allocator used
    CYG_ADDRESS         actual_address; // allocator specific actual address for block
    CYG_WORD32          actual_size;    // allocator specific actual size for block

    // Convenience free() function
    void free();
};

// -------------------------------------------------------------------------
// Memory allocator base class
// This defines the interface to a memory allocator used by the loader.

class Cyg_LoaderMemAlloc
{

public:

    Cyg_LoaderMemAlloc();

    virtual ~Cyg_LoaderMemAlloc();

    // The following functions are virtual so that alternative memory
    // allocators may be implemented. The default behaviour of this
    // class is to use malloc/realloc/free to support these functions.

    // Allocate memory of the supplied size and alignment.
    // size      - size in bytes
    // alignment - alignment expressed as a power of 2
    //             defaults to 8 byte alignment
    virtual Cyg_LoaderMemBlock *alloc( cyg_int32 size,
                                       cyg_int32 alignment = 8);

    // Reallocate block
    // block    - block to reallocate
    // size     - new size in bytes
    // alignment - new alignment, -1 if old alignment is to be used.
    virtual Cyg_LoaderMemBlock *realloc( Cyg_LoaderMemBlock *block,
                                         cyg_int32 size,
                                         cyg_int32 alignment = -1);
    
    // Free a previously allocated memory segment.
    virtual void free( Cyg_LoaderMemBlock *block );

};

// -------------------------------------------------------------------------
// Cyg_LoaderMemBlock convenience free() function implementation.

inline void Cyg_LoaderMemBlock::free() { mem->free(this); };

// -------------------------------------------------------------------------
// A loaded object

class Cyg_LoadObject_Base
    : public Cyg_DNode_T<Cyg_LoadObject>
{
    friend class Cyg_Loader;
    
protected:    
    // The following fields come from the constructor arguments

    cyg_uint32          mode;           // mode flags
    
    Cyg_LoaderMemAlloc  *memalloc;      // Memory allocator

    
    // The following fields are derived from the ELF header

    Elf32_Word          e_type;         // File type

    Elf32_Addr          e_entry;        // Executable entry point


    
    // The following fields are derived from the PT_DYNAMIC segment in
    // the program header. These fields are named after the DT_ tags
    // that their values are derived from.
    
    Elf32_Word          flags;          // flags from DT_FLAGS

    Elf32_Word          soname;         // name of module, if defined
    
    Elf_Hash            *hash;          // address of hash table
    Elf32_Word          *bucket;        // derived bucket array address
    Elf32_Word          *chain;         // derived chain array address
    
    // String table
    unsigned char       *strtab;        // address of table
    Elf32_Word          strsize;        // size of table in bytes

    // Symbol table
    Elf32_Sym           *symtab;        // address of table
    Elf32_Word          syment;         // size of entry
    
    // PTL and GOT
    Elf32_Addr          pltgot;         // address of PLT and/or GOT

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -