Contiki 2.5
mef.h
1 /*
2  * Copyright (c) 2007, Takahide Matsutsuka.
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
11  * copyright notice, this list of conditions and the following
12  * disclaimer in the documentation and/or other materials provided
13  * with the distribution.
14  * 3. The name of the author may not be used to endorse or promote
15  * products derived from this software without specific prior
16  * written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * $Id: mef.h,v 1.1 2007/11/28 06:13:24 matsutsuka Exp $
31  *
32  */
33 
34 /*
35  * \file
36  * mef.h
37  * The Micro Executable Format
38  * \author
39  * Takahide Matsutsuka <markn@markn.org>
40  */
41 /*
42  * MEF file format:
43  * [AreaDecls]
44  * BYTE nAreas (0-15)
45  * struct AreaSize[nAreas]
46  * [Data]
47  * binary*
48  * [Relocation]
49  * WORD nRelocs
50  * struct Relocation[nRelocs]
51  */
52 
53 #ifndef __MEF_H__
54 #define __MEF_H__
55 
56 
57 /*
58  * mode
59  * bit 7: read/write (1) / read only (0)
60  * bit 3-0: Area index
61  * checksum
62  * just a sum of all data of the area
63  */
64 #define MEF_AREA_RW 0x80
65 #define MEF_AREA_MAX 0x10
66 
67 struct Area {
68  unsigned char mode;
69  u16_t size;
70  u16_t checksum;
71 };
72 
73 /*
74  * mode
75  * bit 7: Absolute (1) / Relative (0)
76  * bit 6: MSB (1) / LSB (0) (in byte mode)
77  * bit 5: Byte mode (1) / Word mode (0)
78  */
79 #define MEF_RELOC_ABSOLUTE 0x80
80 #define MEF_RELOC_MSB_BYTE 0x60
81 #define MEF_RELOC_LSB_BYTE 0x20
82 
83 struct Relocation {
84  unsigned char mode;
85  u16_t address;
86  u16_t data;
87 };
88 
89 unsigned char load_byte();
90 
91 void mef_load(unsigned char* offset);
92 unsigned char load_byte();
93 void mef_reloc(unsigned char* offset, struct Relocation* reloc);
94 
95 #endif /* __MEF_H__ */