elfloader.h

Go to the documentation of this file.
00001 /**
00002  * \addtogroup loader
00003  * @{
00004  */
00005 
00006 /**
00007  * \defgroup elfloader The Contiki ELF loader
00008  *
00009  * The Contiki ELF loader links, relocates, and loads ELF
00010  * (Executable Linkable Format) object files into a running Contiki
00011  * system.
00012  *
00013  * ELF is a standard format for relocatable object code and executable
00014  * files. ELF is the standard program format for Linux, Solaris, and
00015  * other operating systems.
00016  *
00017  * An ELF file contains either a standalone executable program or a
00018  * program module. The file contains both the program code, the
00019  * program data, as well as information about how to link, relocate,
00020  * and load the program into a running system.
00021  *
00022  * The ELF file is composed of a set of sections. The sections contain
00023  * program code, data, or relocation information, but can also contain
00024  * debugging information.
00025  *
00026  * To link and relocate an ELF file, the Contiki ELF loader first
00027  * parses the ELF file structure to find the appropriate ELF
00028  * sections. It then allocates memory for the program code and data in
00029  * ROM and RAM, respectively. After allocating memory, the Contiki ELF
00030  * loader starts relocating the code found in the ELF file.
00031  *
00032  * @{
00033  */
00034 
00035 /**
00036  * \file
00037  *         Header file for the Contiki ELF loader.
00038  * \author
00039  *         Adam Dunkels <adam@sics.se>
00040  *
00041  */
00042 
00043 /*
00044  * Copyright (c) 2005, Swedish Institute of Computer Science
00045  * All rights reserved.
00046  *
00047  * Redistribution and use in source and binary forms, with or without
00048  * modification, are permitted provided that the following conditions
00049  * are met:
00050  * 1. Redistributions of source code must retain the above copyright
00051  *    notice, this list of conditions and the following disclaimer.
00052  * 2. Redistributions in binary form must reproduce the above copyright
00053  *    notice, this list of conditions and the following disclaimer in the
00054  *    documentation and/or other materials provided with the distribution.
00055  * 3. Neither the name of the Institute nor the names of its contributors
00056  *    may be used to endorse or promote products derived from this software
00057  *    without specific prior written permission.
00058  *
00059  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
00060  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00061  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00062  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
00063  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00064  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00065  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00066  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00067  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00068  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00069  * SUCH DAMAGE.
00070  *
00071  * This file is part of the Contiki operating system.
00072  *
00073  * @(#)$Id: elfloader.h,v 1.4 2010/04/26 14:02:07 fros4943 Exp $
00074  */
00075 #ifndef __ELFLOADER_H__
00076 #define __ELFLOADER_H__
00077 
00078 #include "cfs/cfs.h"
00079 
00080 /**
00081  * Return value from elfloader_load() indicating that loading worked.
00082  */
00083 #define ELFLOADER_OK                  0
00084 /**
00085  * Return value from elfloader_load() indicating that the ELF file had
00086  * a bad header.
00087  */
00088 #define ELFLOADER_BAD_ELF_HEADER      1
00089 /**
00090  * Return value from elfloader_load() indicating that no symbol table
00091  * could be found in the ELF file.
00092  */
00093 #define ELFLOADER_NO_SYMTAB           2
00094 /**
00095  * Return value from elfloader_load() indicating that no string table
00096  * could be found in the ELF file.
00097  */
00098 #define ELFLOADER_NO_STRTAB           3
00099 /**
00100  * Return value from elfloader_load() indicating that the size of the
00101  * .text segment was zero.
00102  */
00103 #define ELFLOADER_NO_TEXT             4
00104 /**
00105  * Return value from elfloader_load() indicating that a symbol
00106  * specific symbol could not be found.
00107  *
00108  * If this value is returned from elfloader_load(), the symbol has
00109  * been copied into the elfloader_unknown[] array.
00110  */
00111 #define ELFLOADER_SYMBOL_NOT_FOUND    5
00112 /**
00113  * Return value from elfloader_load() indicating that one of the
00114  * required segments (.data, .bss, or .text) could not be found.
00115  */
00116 #define ELFLOADER_SEGMENT_NOT_FOUND   6
00117 /**
00118  * Return value from elfloader_load() indicating that no starting
00119  * point could be found in the loaded module.
00120  */
00121 #define ELFLOADER_NO_STARTPOINT       7
00122 
00123 /**
00124  * elfloader initialization function.
00125  *
00126  * This function should be called at boot up to initialize the elfloader.
00127  */
00128 void elfloader_init(void);
00129 
00130 /**
00131  * \brief      Load and relocate an ELF file.
00132  * \param fd   An open CFS file descriptor.
00133  * \return     ELFLOADER_OK if loading and relocation worked.
00134  *             Otherwise an error value.
00135  *
00136  *             This function loads and relocates an ELF file. The ELF
00137  *             file must have been opened with cfs_open() prior to
00138  *             calling this function.
00139  *
00140  *             If the function is able to load the ELF file, a pointer
00141  *             to the process structure in the model is stored in the
00142  *             elfloader_loaded_process variable.
00143  *
00144  * \note       This function modifies the ELF file opened with cfs_open()!
00145  *             If the contents of the file is required to be intact,
00146  *             the file must be backed up first.
00147  *
00148  */
00149 int elfloader_load(int fd);
00150 
00151 /**
00152  * A pointer to the processes loaded with elfloader_load().
00153  */
00154 extern struct process * const * elfloader_autostart_processes;
00155 
00156 /**
00157  * If elfloader_load() could not find a specific symbol, it is copied
00158  * into this array.
00159  */
00160 extern char elfloader_unknown[30];
00161 
00162 #ifndef ELFLOADER_DATAMEMORY_SIZE
00163 #ifdef ELFLOADER_CONF_DATAMEMORY_SIZE
00164 #define ELFLOADER_DATAMEMORY_SIZE ELFLOADER_CONF_DATAMEMORY_SIZE
00165 #else
00166 #define ELFLOADER_DATAMEMORY_SIZE 0x100
00167 #endif
00168 #endif /* ELFLOADER_DATAMEMORY_SIZE */
00169 
00170 #ifndef ELFLOADER_TEXTMEMORY_SIZE
00171 #ifdef ELFLOADER_CONF_TEXTMEMORY_SIZE
00172 #define ELFLOADER_TEXTMEMORY_SIZE ELFLOADER_CONF_TEXTMEMORY_SIZE
00173 #else
00174 #define ELFLOADER_TEXTMEMORY_SIZE 0x100
00175 #endif
00176 #endif /* ELFLOADER_TEXTMEMORY_SIZE */
00177 
00178 typedef unsigned long  elf32_word;
00179 typedef   signed long  elf32_sword;
00180 typedef unsigned short elf32_half;
00181 typedef unsigned long  elf32_off;
00182 typedef unsigned long  elf32_addr;
00183 
00184 struct elf32_rela {
00185   elf32_addr      r_offset;       /* Location to be relocated. */
00186   elf32_word      r_info;         /* Relocation type and symbol index. */
00187   elf32_sword     r_addend;       /* Addend. */
00188 };
00189 
00190 
00191 #endif /* __ELFLOADER_H__ */
00192 
00193 /** @} */
00194 /** @} */

Generated on Mon Apr 11 14:23:28 2011 for Contiki 2.5 by  doxygen 1.6.1