Contiki 2.5
elfloader-arch.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005, 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  * This file is part of the Contiki operating system.
30  *
31  * @(#)$Id: elfloader-arch.h,v 1.4 2007/03/24 15:21:34 oliverschmidt Exp $
32  */
33 /**
34  * \addtogroup elfloader
35  * @{
36  */
37 
38 /**
39  * \defgroup elfloaderarch Architecture specific functionality for the ELF loader.
40  *
41  * The architecture specific functionality for the Contiki ELF loader
42  * has to be implemented for each processor type Contiki runs on.
43  *
44  * Since the ELF format is slightly different for different processor
45  * types, the Contiki ELF loader is divided into two parts: the
46  * generic ELF loader module (\ref elfloader) and the architecture
47  * specific part (this module). The architecture specific part deals
48  * with memory allocation, code and data relocation, and writing the
49  * relocated ELF code into program memory.
50  *
51  * To port the Contiki ELF loader to a new processor type, this module
52  * has to be implemented for the new processor type.
53  *
54  * @{
55  */
56 
57 /**
58  * \file
59  * Header file for the architecture specific parts of the Contiki ELF loader.
60  *
61  * \author
62  * Adam Dunkels <adam@sics.se>
63  *
64  */
65 
66 #ifndef __ELFLOADER_ARCH_H__
67 #define __ELFLOADER_ARCH_H__
68 
69 #include "loader/elfloader.h"
70 
71 /**
72  * \brief Allocate RAM for a new module.
73  * \param size The size of the requested memory.
74  * \return A pointer to the allocated RAM
75  *
76  * This function is called from the Contiki ELF loader to
77  * allocate RAM for the module to be loaded into.
78  *
79  * \bug The Contiki ELF loader currently does not contain a
80  * mechanism for deallocating the memory allocated with
81  * this function.
82  */
83 void *elfloader_arch_allocate_ram(int size);
84 
85 /**
86  * \brief Allocate program memory for a new module.
87  * \param size The size of the requested memory.
88  * \return A pointer to the allocated program memory
89  *
90  * This function is called from the Contiki ELF loader to
91  * allocate program memory (typically ROM) for the module
92  * to be loaded into.
93  *
94  * \bug The Contiki ELF loader currently does not contain a
95  * mechanism for deallocating the memory allocated with
96  * this function.
97  */
98 void *elfloader_arch_allocate_rom(int size);
99 
100 /**
101  * \brief Perform a relocation.
102  * \param fd The file descriptor for the ELF file.
103  * \param sectionoffset The file offset at which the relocation can be found.
104  * \param sectionaddr The section start address (absolute runtime).
105  * \param rela A pointer to an ELF32 rela structure (struct elf32_rela).
106  * \param addr The relocated address.
107  *
108  * This function is called from the Contiki ELF loader to
109  * perform a relocation on a piece of code or data. The
110  * relocated address is calculated by the Contiki ELF
111  * loader, based on information in the ELF file, and it is
112  * the responsibility of this function to patch the
113  * executable code. The Contiki ELF loader passes a
114  * pointer to an ELF32 rela structure (struct elf32_rela)
115  * that contains information about how to patch the
116  * code. This information is different from processor to
117  * processor.
118  */
119 void elfloader_arch_relocate(int fd, unsigned int sectionoffset,
120  char *sectionaddr,
121  struct elf32_rela *rela, char *addr);
122 
123 /**
124  * \brief Write to read-only memory (for example the text segment).
125  * \param fd The file descriptor for the ELF file.
126  * \param textoff Offset of text segment relative start of file.
127  * \param size The size of the text segment.
128  * \param mem A pointer to the where the text segment should be flashed
129  *
130  * This function is called from the Contiki ELF loader to
131  * write the program code (text segment) of a loaded
132  * module into memory. The function is called when all
133  * relocations have been performed.
134  */
135 void elfloader_arch_write_rom(int fd, unsigned short textoff, unsigned int size, char *mem);
136 
137 #endif /* __ELFLOADER_ARCH_H__ */
138 
139 /** @} */
140 /** @} */