Contiki 3.x
cle.h
1 /*
2  * Copyright (c) 2006, Swedish Institute of Computer Science
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  */
30 
31 #ifndef CLE_H
32 #define CLE_H
33 
34 /*
35  * The Contiki dynamic Link Editor (CLE) for small systems.
36  */
37 
38 /* These typedefs limits object file size! */
39 typedef uint16_t cle_off; /* Offset from start of file. */
40 typedef uint16_t cle_word;
41 typedef uint16_t cle_half;
42 
43 /* Also used for address arithmetic (can't be void *). */
44 #ifdef __AVR__
45 typedef uint32_t cle_addr;
46 #else
47 typedef uintptr_t cle_addr;
48 #endif
49 
50 typedef char cle_scratch[32];
51 
52 struct cle_info {
53  cle_addr text;
54  void *data, *bss;
55 
56  cle_off textrelaoff, datarelaoff;
57  cle_word textrelasize, datarelasize;
58 
59  cle_off textoff, dataoff;
60  cle_word textsize, datasize, bsssize;
61 
62  cle_off symtaboff, strtaboff;
63  cle_word symtabsize;
64 
65  unsigned char text_shndx;
66  unsigned char data_shndx;
67  unsigned char bss_shndx;
68  unsigned char unused_shndx;
69 
70  cle_scratch name; /* Scratch and errmsg buffer. */
71 };
72 
73 int
74 cle_read_info(struct cle_info *info,
75  int (*read)(void *, int, off_t),
76  off_t hdr); /* Offset to start of file. */
77 
78 int
79 cle_relocate(struct cle_info *info,
80  int (*read)(void *, int, off_t),
81  off_t hdr, /* Offset to start of file. */
82  void *segmem, /* Where segment is stored in memory. */
83  cle_off reloff, /* .rela.<segment> start */
84  cle_word relsize); /* .rela.<segment> size */
85 
86 void *
87 cle_lookup(struct cle_info *info,
88  int (*read)(void *, int, off_t),
89  off_t hdr, /* Offset to start of file. */
90  const char *symbol);
91 
92 struct elf32_rela; /* Struct forward decl. */
93 
94 int cle_write_reloc(void *,
95  const struct elf32_rela *,
96  cle_addr,
97  const struct cle_info *);
98 
99 /*
100  * Error codes that apply in general to linking and loading.
101  */
102 #define CLE_OK 0
103 #define CLE_BAD_HEADER 1
104 #define CLE_NO_SYMTAB 2
105 #define CLE_NO_STRTAB 3
106 #define CLE_NO_TEXT 4
107 #define CLE_UNDEFINED 5
108 #define CLE_UNKNOWN_SEGMENT 6
109 #define CLE_NO_STARTPOINT 7
110 #define CLE_TEXT_TO_LARGE 8
111 #define CLE_DATA_TO_LARGE 9
112 #define CLE_UNKNOWN_RELOC 10
113 #define CLE_MULTIPLY_DEFINED 11
114 
115 #endif /* CLE_H */