The Micro-Executable Format (MEF) support (experimental).
This commit is contained in:
parent
bcfc99fa5b
commit
fbb8fb409a
|
@ -2,7 +2,7 @@
|
|||
# Makefile for z80/SDCC
|
||||
# @author Takahide Matsutsuka <markn@markn.org>
|
||||
#
|
||||
# $Id: Makefile.z80,v 1.9 2007/10/01 23:04:02 matsutsuka Exp $
|
||||
# $Id: Makefile.z80,v 1.10 2007/11/28 06:13:24 matsutsuka Exp $
|
||||
#
|
||||
|
||||
### Compiler definitions
|
||||
|
@ -29,12 +29,14 @@ AROPTS = -a
|
|||
CLEAN += *.lnk *.sym *.lib contiki.ihx
|
||||
|
||||
### CPU-dependent directories
|
||||
CONTIKI_CPU_DIRS = . dev lib
|
||||
CONTIKI_CPU_DIRS = . dev lib loader
|
||||
|
||||
### CPU-dependent source files
|
||||
CONTIKI_SOURCEFILES += strcasecmp.c mtarch.c uip_arch.c \
|
||||
libconio_z80.c log-conio.c rs232.c
|
||||
libconio_z80.c log-conio.c rs232.c \
|
||||
mef.c
|
||||
CONTIKI_ASMFILES += uip_arch-asm.S crt0.S
|
||||
#crt-prg.S
|
||||
|
||||
|
||||
CONTIKI_CASMOBJECTFILES = ${addprefix $(OBJECTDIR)/,$(CONTIKI_CASMFILES:.cS=.o)}
|
||||
|
@ -66,3 +68,13 @@ contiki-$(TARGET).lib: $(CONTIKI_OBJECTFILES) $(PROJECT_OBJECTFILES) $(CONTIKI_A
|
|||
contiki.ihx: contiki-$(TARGET).lib $(OBJECTDIR)/crt0.o
|
||||
$(CC) $(LDFLAGS) -o $@ $(OBJECTDIR)/crt0.o -lcontiki-$(TARGET).lib
|
||||
$(LD) -nf contiki
|
||||
|
||||
LDPFLAGS = -mz80 --out-fmt-ihx --no-std-crt0 --code-loc 0 --data-loc 0
|
||||
|
||||
test.ihx: contiki-$(TARGET).lib $(OBJECTDIR)/crt-prg.o
|
||||
$(CC) $(LDPFLAGS) -o $@ $(OBJECTDIR)/crt-prg.o -lcontiki-$(TARGET).lib
|
||||
$(LD) -nf test
|
||||
|
||||
%.ihx: contiki-$(TARGET).lib $(OBJECTDIR)/%*.o
|
||||
$(CC) $(LDPFLAGS) -o $@ $(OBJECTDIR)/$*.o -lcontiki-$(TARGET).lib
|
||||
$(LD) -nf $*
|
||||
|
|
|
@ -1,4 +1,13 @@
|
|||
;; crt0.S for Contiki
|
||||
;;;
|
||||
;;;
|
||||
;;; ctt0.S
|
||||
;;;
|
||||
;;; \file
|
||||
;;; C runtime startup routine
|
||||
;;;
|
||||
;;; \author
|
||||
;;; Takahide Matsutsuka <markn@markn.org>
|
||||
;;;
|
||||
.module crt0
|
||||
.globl _main
|
||||
|
||||
|
|
107
cpu/z80/loader/mef.c
Normal file
107
cpu/z80/loader/mef.c
Normal file
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Takahide Matsutsuka.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $Id: mef.c,v 1.1 2007/11/28 06:13:24 matsutsuka Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* \file
|
||||
* mef.c
|
||||
* The Micro Executable Format
|
||||
* \author
|
||||
* Takahide Matsutsuka <markn@markn.org>
|
||||
*/
|
||||
|
||||
#ifdef WITH_LOADER_ARCH
|
||||
#include "contiki.h"
|
||||
#include "loader/mef.h"
|
||||
|
||||
struct Area areas[MEF_AREA_MAX];
|
||||
|
||||
void
|
||||
mef_load(unsigned char* offset)
|
||||
{
|
||||
unsigned char* start = offset;
|
||||
unsigned char areasize = load_byte();
|
||||
u16_t relocsize;
|
||||
unsigned int i, j;
|
||||
u16_t checksum = 0;
|
||||
unsigned char* buf;
|
||||
struct Relocation reloc;
|
||||
|
||||
for (i = 0; i < areasize; i++) {
|
||||
buf = (unsigned char *) &areas[i];
|
||||
for (j = 0; j < sizeof(struct Area); j++) {
|
||||
*buf++ = load_byte();
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < areasize; i++) {
|
||||
for (j = 0; j < areas[i].size; j++) {
|
||||
*offset = load_byte();
|
||||
checksum += *offset;
|
||||
offset++;
|
||||
}
|
||||
if (areas[i].checksum != checksum) {
|
||||
// Checksum error!
|
||||
}
|
||||
}
|
||||
|
||||
// relocation information
|
||||
relocsize = load_byte();
|
||||
relocsize = (load_byte() << 8) + relocsize;
|
||||
for (i = 0; i < relocsize; i++) {
|
||||
buf = (unsigned char *) &reloc;
|
||||
for (j = 0; j < sizeof(struct Relocation); j++) {
|
||||
*buf++ = load_byte();
|
||||
}
|
||||
mef_reloc(start, &reloc);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
mef_reloc(unsigned char* offset, struct Relocation *reloc)
|
||||
{
|
||||
if (reloc->mode & MEF_RELOC_ABSOLUTE) {
|
||||
return;
|
||||
}
|
||||
offset += reloc->address;
|
||||
if (reloc->mode & MEF_RELOC_MSB_BYTE) {
|
||||
*offset = (unsigned char) ((reloc->data + (u16_t) offset) >> 8);
|
||||
} else if (reloc->mode & MEF_RELOC_LSB_BYTE) {
|
||||
*offset = (unsigned char) ((reloc->data + (u16_t) offset) & 0xff);
|
||||
} else { /* word */
|
||||
*offset++ = (unsigned char) ((reloc->data + (u16_t) offset) & 0xff);
|
||||
*offset = (unsigned char) ((reloc->data + (u16_t) offset) >> 8);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* WITH_LOADER_ARCH */
|
95
cpu/z80/loader/mef.h
Normal file
95
cpu/z80/loader/mef.h
Normal file
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Takahide Matsutsuka.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $Id: mef.h,v 1.1 2007/11/28 06:13:24 matsutsuka Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* \file
|
||||
* mef.h
|
||||
* The Micro Executable Format
|
||||
* \author
|
||||
* Takahide Matsutsuka <markn@markn.org>
|
||||
*/
|
||||
/*
|
||||
* MEF file format:
|
||||
* [AreaDecls]
|
||||
* BYTE nAreas (0-15)
|
||||
* struct AreaSize[nAreas]
|
||||
* [Data]
|
||||
* binary*
|
||||
* [Relocation]
|
||||
* WORD nRelocs
|
||||
* struct Relocation[nRelocs]
|
||||
*/
|
||||
|
||||
#ifndef __MEF_H__
|
||||
#define __MEF_H__
|
||||
|
||||
|
||||
/*
|
||||
* mode
|
||||
* bit 7: read/write (1) / read only (0)
|
||||
* bit 3-0: Area index
|
||||
* checksum
|
||||
* just a sum of all data of the area
|
||||
*/
|
||||
#define MEF_AREA_RW 0x80
|
||||
#define MEF_AREA_MAX 0x10
|
||||
|
||||
struct Area {
|
||||
unsigned char mode;
|
||||
u16_t size;
|
||||
u16_t checksum;
|
||||
};
|
||||
|
||||
/*
|
||||
* mode
|
||||
* bit 7: Absolute (1) / Relative (0)
|
||||
* bit 6: MSB (1) / LSB (0) (in byte mode)
|
||||
* bit 5: Byte mode (1) / Word mode (0)
|
||||
*/
|
||||
#define MEF_RELOC_ABSOLUTE 0x80
|
||||
#define MEF_RELOC_MSB_BYTE 0x60
|
||||
#define MEF_RELOC_LSB_BYTE 0x20
|
||||
|
||||
struct Relocation {
|
||||
unsigned char mode;
|
||||
u16_t address;
|
||||
u16_t data;
|
||||
};
|
||||
|
||||
unsigned char load_byte();
|
||||
|
||||
void mef_load(unsigned char* offset);
|
||||
unsigned char load_byte();
|
||||
void mef_reloc(unsigned char* offset, struct Relocation* reloc);
|
||||
|
||||
#endif /* __MEF_H__ */
|
Loading…
Reference in a new issue