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