00001 /* 00002 * Copyright (c) 2006, Swedish Institute of Computer Science 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. Neither the name of the Institute nor the names of its contributors 00014 * may be used to endorse or promote products derived from this software 00015 * without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00018 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 00021 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00023 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00024 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00025 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00027 * SUCH DAMAGE. 00028 * 00029 * @(#)$Id: cle.h,v 1.7 2007/06/04 17:47:56 bg- Exp $ 00030 */ 00031 00032 #ifndef CLE_H 00033 #define CLE_H 00034 00035 /* 00036 * The Contiki dynamic Link Editor (CLE) for small systems. 00037 */ 00038 00039 /* These typedefs limits object file size! */ 00040 typedef u16_t cle_off; /* Offset from start of file. */ 00041 typedef u16_t cle_word; 00042 typedef u16_t cle_half; 00043 00044 /* Also used for address arithmetic (can't be void *). */ 00045 #ifdef __AVR__ 00046 typedef uint32_t cle_addr; 00047 #else 00048 typedef uintptr_t cle_addr; 00049 #endif 00050 00051 typedef char cle_scratch[32]; 00052 00053 struct cle_info { 00054 cle_addr text; 00055 void *data, *bss; 00056 00057 cle_off textrelaoff, datarelaoff; 00058 cle_word textrelasize, datarelasize; 00059 00060 cle_off textoff, dataoff; 00061 cle_word textsize, datasize, bsssize; 00062 00063 cle_off symtaboff, strtaboff; 00064 cle_word symtabsize; 00065 00066 unsigned char text_shndx; 00067 unsigned char data_shndx; 00068 unsigned char bss_shndx; 00069 unsigned char unused_shndx; 00070 00071 cle_scratch name; /* Scratch and errmsg buffer. */ 00072 }; 00073 00074 int 00075 cle_read_info(struct cle_info *info, 00076 int (*read)(void *, int, off_t), 00077 off_t hdr); /* Offset to start of file. */ 00078 00079 int 00080 cle_relocate(struct cle_info *info, 00081 int (*read)(void *, int, off_t), 00082 off_t hdr, /* Offset to start of file. */ 00083 void *segmem, /* Where segment is stored in memory. */ 00084 cle_off reloff, /* .rela.<segment> start */ 00085 cle_word relsize); /* .rela.<segment> size */ 00086 00087 void * 00088 cle_lookup(struct cle_info *info, 00089 int (*read)(void *, int, off_t), 00090 off_t hdr, /* Offset to start of file. */ 00091 const char *symbol); 00092 00093 struct elf32_rela; /* Struct forward decl. */ 00094 00095 int cle_write_reloc(void *, 00096 const struct elf32_rela *, 00097 cle_addr, 00098 const struct cle_info *); 00099 00100 /* 00101 * Error codes that apply in general to linking and loading. 00102 */ 00103 #define CLE_OK 0 00104 #define CLE_BAD_HEADER 1 00105 #define CLE_NO_SYMTAB 2 00106 #define CLE_NO_STRTAB 3 00107 #define CLE_NO_TEXT 4 00108 #define CLE_UNDEFINED 5 00109 #define CLE_UNKNOWN_SEGMENT 6 00110 #define CLE_NO_STARTPOINT 7 00111 #define CLE_TEXT_TO_LARGE 8 00112 #define CLE_DATA_TO_LARGE 9 00113 #define CLE_UNKNOWN_RELOC 10 00114 #define CLE_MULTIPLY_DEFINED 11 00115 00116 #endif /* CLE_H */