00001 /* 00002 * Copyright (c) 2007, Takahide Matsutsuka. 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 00011 * copyright notice, this list of conditions and the following 00012 * disclaimer in the documentation and/or other materials provided 00013 * with the distribution. 00014 * 3. The name of the author may not be used to endorse or promote 00015 * products derived from this software without specific prior 00016 * written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 00019 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00020 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00021 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 00022 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00023 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00024 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00026 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00027 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 * 00030 * $Id: mef.h,v 1.1 2007/11/28 06:13:24 matsutsuka Exp $ 00031 * 00032 */ 00033 00034 /* 00035 * \file 00036 * mef.h 00037 * The Micro Executable Format 00038 * \author 00039 * Takahide Matsutsuka <markn@markn.org> 00040 */ 00041 /* 00042 * MEF file format: 00043 * [AreaDecls] 00044 * BYTE nAreas (0-15) 00045 * struct AreaSize[nAreas] 00046 * [Data] 00047 * binary* 00048 * [Relocation] 00049 * WORD nRelocs 00050 * struct Relocation[nRelocs] 00051 */ 00052 00053 #ifndef __MEF_H__ 00054 #define __MEF_H__ 00055 00056 00057 /* 00058 * mode 00059 * bit 7: read/write (1) / read only (0) 00060 * bit 3-0: Area index 00061 * checksum 00062 * just a sum of all data of the area 00063 */ 00064 #define MEF_AREA_RW 0x80 00065 #define MEF_AREA_MAX 0x10 00066 00067 struct Area { 00068 unsigned char mode; 00069 u16_t size; 00070 u16_t checksum; 00071 }; 00072 00073 /* 00074 * mode 00075 * bit 7: Absolute (1) / Relative (0) 00076 * bit 6: MSB (1) / LSB (0) (in byte mode) 00077 * bit 5: Byte mode (1) / Word mode (0) 00078 */ 00079 #define MEF_RELOC_ABSOLUTE 0x80 00080 #define MEF_RELOC_MSB_BYTE 0x60 00081 #define MEF_RELOC_LSB_BYTE 0x20 00082 00083 struct Relocation { 00084 unsigned char mode; 00085 u16_t address; 00086 u16_t data; 00087 }; 00088 00089 unsigned char load_byte(); 00090 00091 void mef_load(unsigned char* offset); 00092 unsigned char load_byte(); 00093 void mef_reloc(unsigned char* offset, struct Relocation* reloc); 00094 00095 #endif /* __MEF_H__ */