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