The pc-6001 platform was the last z80 platform in the tree, so we'll remove the cpu/z80 directory too

This commit is contained in:
Adam Dunkels 2013-11-19 12:14:48 +01:00
parent 52a0b4594f
commit 27433244a9
17 changed files with 0 additions and 1799 deletions

View File

@ -1,83 +0,0 @@
#
# Makefile for z80/SDCC
# @author Takahide Matsutsuka <markn@markn.org>
#
# $Id: Makefile.z80,v 1.15 2009/12/16 06:47:17 matsutsuka Exp $
#
### Compiler definitions
CC = sdcc
LD = link-z80
AS = as-z80
AR = sdcclib
OBJCOPY = objcopy
STRIP = strip
### Custom rules
CUSTOM_RULE_C_TO_OBJECTDIR_O=1
CUSTOM_RULE_ALLOBJS_TO_TARGETLIB=1
CUSTOM_RULE_LINK=1
### Default flags
CFLAGS += --std-c99 -mz80 --opt-code-size
CFLAGS += --peep-file $(CONTIKI_CPU)/z80peephole.def --fverbose-asm
ASFLAGS +=
LDFLAGS += -mz80 --out-fmt-ihx --no-std-crt0
AROPTS = -a
ifdef CONTIKI_PROJECT
CFLAGS += -DAUTOSTART_ENABLE=1
CONTIKI_SOURCEFILES += $(CONTIKI_PROJECT).c
endif
### CPU-dependent cleanup files
CLEAN += *.ihx *.lnk *.sym contiki-$(TARGET).lib *.$(TARGET)
### CPU-dependent directories
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
CONTIKI_ASMFILES += uip_arch-asm.S crt0.S
CONTIKI_ASMOBJECTFILES = ${addprefix $(OBJECTDIR)/,$(CONTIKI_ASMFILES:.S=.o)}
CONTIKI_CASMOBJECTFILES = ${addprefix $(OBJECTDIR)/,$(CONTIKI_CASMFILES:.cS=.o)}
CONTIKI_PLATFORM_DIRS = $(PLATFORM_APPDIRS) \
${addprefix $(CONTIKI)/platform/$(TARGET)/, $(CONTIKI_TARGET_DIRS)}
#".cS" suffix means assembler file with #include directive
#so that a developer can use definitions of C-style include file
#in assembler file. Make sure the header file contains only compiler
#directives. (i.e. #define, etc.)
vpath %.cS $(CONTIKI_PLATFORM_DIRS)
#option -MMD doesn't work well on SDCC as of 2.9.0
$(OBJECTDIR)/%.o: %.c | $(OBJECTDIR)
$(CC) $(CFLAGS) -c $< -o $@
ifndef CUSTOM_RULE_CS_TO_OBJECTDIR_O
$(OBJECTDIR)/%.o: %.cS | $(OBJECTDIR)
cp $< $(OBJECTDIR)/$*.c
$(CC) $(CFLAGS) -E $(OBJECTDIR)/$*.c > $(OBJECTDIR)/tmp
perl -pe "s/^#(.*)/;$$1/" $(OBJECTDIR)/tmp > $(OBJECTDIR)/$*.S
$(AS) $(ASFLAGS) -o $@ $(OBJECTDIR)/$*.S
rm -f $(OBJECTDIR)/tmp
endif
#CUSTOM_RULE_ALLOBJS_TO_TARGETLIB
contiki-$(TARGET).lib: $(CONTIKI_OBJECTFILES) $(PROJECT_OBJECTFILES) $(CONTIKI_ASMOBJECTFILES) $(CONTIKI_CASMOBJECTFILES)
rm -f $@
for target in $^; do echo $$target >> $@; done
#CUSTOM_RULE_LINK (workaround for compiling examples)
$(CONTIKI_PROJECT): $(CONTIKI_PROJECT).ihx
mv $(CONTIKI_PROJECT).ihx $(CONTIKI_PROJECT).$(TARGET)
#CUSTOM_RULE_LINK
%.ihx: contiki-$(TARGET).lib
$(CC) $(LDFLAGS) -o $@ $(OBJECTDIR)/crt0.o -lcontiki-$(TARGET).lib
$(LD) -nf $*

View File

@ -1,55 +0,0 @@
;;;
;;;
;;; ctt0.S
;;;
;;; \file
;;; C runtime startup routine
;;;
;;; \author
;;; Takahide Matsutsuka <markn@markn.org>
;;;
;;; $Id: crt0.S,v 1.3 2008/07/02 07:13:22 matsutsuka Exp $
;;;
.module crt0
.globl _main
;; Ordering of segments for the linker.
.area _HOME
.area _CODE
.area _GSINIT
.area _GSFINAL
.area _DATA
.area _DATAFINAL
.area _BSS
.area _HEAP
.area _CODE
init::
;; Clear global variables
ld hl, #_datastart
ld bc, #_dataend
_clear_loop:
ld a, h
sub b
jr nz, _clear_next
ld a, l
sub c
jr z, _clear_exit
_clear_next:
ld (hl), #0
inc hl
jr _clear_loop
_clear_exit:
;; Initialize global variables
call gsinit
jp _main
.area _GSINIT
gsinit::
.area _GSFINAL
ret
.area _DATA
_datastart::
.area _DATAFINAL
_dataend::

View File

@ -1,75 +0,0 @@
/*
* 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.
*
*
*/
/*
* \file
* This is RS-232C process based on polling.
* Note that rs232.c and rs232-slip.c cannot be used at the same time.
* \author
* Takahide Matsutsuka <markn@markn.org>
*/
#include "contiki.h"
#include "dev/slip.h"
#include "dev/serial-line.h"
#include "dev/rs232.h"
PROCESS(rs232_process, "RS-232C polling process");
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(rs232_process, ev, data)
{
static struct etimer timer;
char ch;
unsigned char i, stat;
PROCESS_BEGIN();
rs232_arch_init(RS232_BAUD_RATE);
etimer_set(&timer, CLOCK_SECOND / 16);
while(1) {
PROCESS_WAIT_EVENT();
if (etimer_expired(&timer)) {
for (i = 0; i < RS232_BUFSIZE; i++) {
ch = rs232_arch_poll(&stat);
if (stat == 0) {
break;
}
/* We have an input data */
RS232_CALLBACK(ch);
}
etimer_reset(&timer);
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View File

@ -1,87 +0,0 @@
/*
* 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.
*
*
*/
/*
* \file
* This is RS-232C process based on polling.
* \author
* Takahide Matsutsuka <markn@markn.org>
*/
#ifndef __RS232_H__
#define __RS232_H__
/*
* Implement the following methods for each platform.
*/
/*
* An architecture-depend implementation of RS-232C initialization.
*/
void rs232_arch_init(unsigned long ubr);
/*
* An architecture-depend implementation of RS-232C polling.
* @return character, stat == zero if no input.
*/
unsigned char rs232_arch_poll(unsigned char* stat);
/*
* An architecture-depend implementation of RS-232C writing a byte.
*/
void rs232_arch_writeb(unsigned char ch);
PROCESS_NAME(rs232_process);
/*
* if you want to use simple serial communication,
* define RS232_CONF_CALLBACK as serial_input_byte.
* The default is SLIP.
*/
#ifdef RS232_CONF_CALLBACK
#define RS232_CALLBACK RS232_CONF_CALLBACK
#else /* RS232_CONF_CALLBACK */
#define RS232_CALLBACK slip_input_byte
#endif /* RS232_CONF_CALLBACK */
#ifdef RS232_CONF_BUFISZE
#define RS232_BUFSIZE RS232_CONF_BUFISZE
#else /* RS232_CONF_BUFISZE */
#define RS232_BUFSIZE 64
#endif /* RS232_CONF_BUFISZE */
#ifdef RS232_CONF_BAUD_RATE
#define RS232_BAUD_RATE RS232_CONF_BAUD_RATE
#else /* RS232_CONF_BAUD_RATE */
#define RS232_BAUD_RATE 9600
#endif /* RS232_CONF_BAUD_RATE */
#endif /* __RS232_H__ */

View File

@ -1,101 +0,0 @@
/*
* 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.
*
*
*/
/*
* \file
* Arcitecture-depend libconio module, which supposes
* the machine has character VRAM and optional attribute VRAM
* on the main memory.
* \author
* Takahide Matsutsuka <markn@markn.org>
*/
#include "contiki.h"
#include "sys/log.h"
#include "libconio.h"
#include "libconio_z80.h"
/*---------------------------------------------------------------------------*/
static void scroll() {
unsigned char y;
uint16_t src, dst;
for (y = 0; y < LIBCONIO_CONF_SCREEN_HEIGHT - 1; y++) {
dst = LIBCONIO_VRAM_OFFSET(0, y);
src = LIBCONIO_VRAM_OFFSET(0, y + 1);
memcpy(LIBCONIO_VRAM_CHAR + dst,
LIBCONIO_VRAM_CHAR + src,
LIBCONIO_CONF_SCREEN_WIDTH);
#ifdef LIBCONIO_CONF_ATTRIBUTES_ENABLED
memcpy(LIBCONIO_VRAM_ATTR + dst,
LIBCONIO_VRAM_ATTR + src,
LIBCONIO_CONF_SCREEN_WIDTH);
#endif /* LIBCONIO_CONF_ATTRIBUTES_ENABLED */
}
dst = LIBCONIO_VRAM_OFFSET(0, LIBCONIO_CONF_SCREEN_HEIGHT - 1);
memset(LIBCONIO_VRAM_CHAR + dst, ' ',
LIBCONIO_CONF_SCREEN_WIDTH);
#ifdef LIBCONIO_CONF_ATTRIBUTES_ENABLED
memset(LIBCONIO_VRAM_ATTR + dst, LIBCONIO_COLOR_NORMAL,
LIBCONIO_CONF_SCREEN_WIDTH);
#endif /* LIBCONIO_CONF_ATTRIBUTES_ENABLED */
gotoxy(0, LIBCONIO_CONF_SCREEN_HEIGHT - 1);
}
/*---------------------------------------------------------------------------*/
/* make sure that the position is inside screen */
static void adjust(unsigned char *x, unsigned char *y) {
if (*x > LIBCONIO_CONF_SCREEN_WIDTH) {
*y += *x / LIBCONIO_CONF_SCREEN_WIDTH;
*x = *x % LIBCONIO_CONF_SCREEN_WIDTH;
gotoxy(*x, *y);
}
}
/*---------------------------------------------------------------------------*/
void ctk_arch_draw_char(char c,
unsigned char xpos,
unsigned char ypos,
unsigned char reversed,
unsigned char color) {
uint16_t off;
adjust(&xpos, &ypos);
off = LIBCONIO_VRAM_OFFSET(xpos, ypos);
if (off >= LIBCONIO_VRAM_OFFSET_MAX) {
scroll();
off = LIBCONIO_VRAM_OFFSET(0, LIBCONIO_CONF_SCREEN_HEIGHT - 1);
}
*(char *)(LIBCONIO_VRAM_CHAR + off) = c;
#ifdef LIBCONIO_CONF_ATTRIBUTES_ENABLED
*(char *)(LIBCONIO_VRAM_ATTR + off) = reversed ?
LIBCONIO_COLOR_REVERSED : LIBCONIO_COLOR_NORMAL;
#endif /* LIBCONIO_CONF_ATTRIBUTES_ENABLED */
}
/*---------------------------------------------------------------------------*/

View File

@ -1,87 +0,0 @@
/*
* 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.
*
*
*/
/*
* \file
* Arcitecture-depend libconio module, which supposes
* the machine has character VRAM and optional attribute VRAM
* on the main memory.
* \author
* Takahide Matsutsuka <markn@markn.org>
*/
#ifndef __LIBCONIO_ARCH_H__
#define __LIBCONIO_ARCH_H__
#ifndef LIBCONIO_VRAM_CHAR
#error "must specify vram address for characters!"
#endif /* LIBCONIO_VRAM_CHAR */
#ifdef LIBCONIO_CONF_ATTRIBUTES_ENABLED
#ifndef LIBCONIO_VRAM_ATTR
#error "must specify vram address for attributes!"
#endif /* LIBCONIO_VRAM_ATTR */
#endif /* LIBCONIO_CONF_ATTRIBUTES_ENABLED */
#ifndef LIBCONIO_CONF_SCREEN_WIDTH
#define LIBCONIO_CONF_SCREEN_WIDTH 32
#endif /* LIBCONIO_CONF_SCREEN_WIDTH */
#ifndef LIBCONIO_CONF_SCREEN_HEIGHT
#define LIBCONIO_CONF_SCREEN_HEIGHT 16
#endif /* LIBCONIO_CONF_SCREEN_HEIGHT */
#ifndef LIBCONIO_COLOR_REVERSED
#define LIBCONIO_COLOR_REVERSED 0x21
#endif /* LIBCONIO_COLOR_REVERSED */
#ifndef LIBCONIO_COLOR_NORMAL
#define LIBCONIO_COLOR_NORMAL 0x20
#endif /* LIBCONIO_COLOR_NORMAL */
/*
* An offset caluclation logic.
* The default supposes the VRAM is sequential
*/
#ifndef LIBCONIO_VRAM_OFFSET
#define LIBCONIO_VRAM_OFFSET(x, y) (y) * LIBCONIO_CONF_SCREEN_WIDTH + (x)
#endif /* VRAM_OFFSET */
/*
* A maximum offset + 1.
* If offset is equal or more than this maximum, the screen will scroll.
*/
#ifndef LIBCONIO_VRAM_OFFSET_MAX
#define LIBCONIO_VRAM_OFFSET_MAX \
(LIBCONIO_CONF_SCREEN_HEIGHT * LIBCONIO_CONF_SCREEN_WIDTH)
#endif /* VRAM_MAX */
#endif /* __LIBCONIO_ARCH_H__ */

View File

@ -1,51 +0,0 @@
/*
* 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.
*
*
*/
/*
* \file
* A default implmentation of logging for conio
* \author
* Takahide Matsutsuka <markn@markn.org>
*/
#include "contiki.h"
#include "libconio.h"
#include "log.h"
#if LOG_CONF_ENABLED
void
log_message(const char *part1, const char *part2)
{
cputs(part1);
/* line feed */
gotoxy(0, wherey() + 1);
}
#endif /* LOG_CONF_ENABLED */

View File

@ -1,49 +0,0 @@
/*
* 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.
*
*
*/
/*
* \file
* This complements standard C library of sdcc.
* \author
* Takahide Matsutsuka <markn@markn.org>
*/
#include <ctype.h>
#include "strcasecmp.h"
int strcasecmp(const char *str1, const char *str2)
{
while (*str1 != '\0' && tolower(*str1) == tolower(*str2)) {
str1++;
str2++;
}
return tolower(*(unsigned char *)str1) - tolower(*(unsigned char *)str2);
}

View File

@ -1,44 +0,0 @@
/*
* 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.
*
*
*/
/*
* \file
* This complements standard C library of sdcc.
* \author
* Takahide Matsutsuka <markn@markn.org>
*/
#ifndef __STRCASECMP_H__
#define __STRCASECMP_H__
int strcasecmp(const char *str1, const char *str2);
#endif /*__STRCASECMP_H__*/

View File

@ -1,106 +0,0 @@
/*
* 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.
*
*
*/
/*
* \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();
uint16_t relocsize;
unsigned int i, j;
uint16_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 + (uint16_t) offset) >> 8);
} else if (reloc->mode & MEF_RELOC_LSB_BYTE) {
*offset = (unsigned char) ((reloc->data + (uint16_t) offset) & 0xff);
} else { /* word */
*offset++ = (unsigned char) ((reloc->data + (uint16_t) offset) & 0xff);
*offset = (unsigned char) ((reloc->data + (uint16_t) offset) >> 8);
}
}
#endif /* WITH_LOADER_ARCH */

View File

@ -1,94 +0,0 @@
/*
* 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.
*
*
*/
/*
* \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;
uint16_t size;
uint16_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;
uint16_t address;
uint16_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__ */

View File

@ -1,192 +0,0 @@
/*
* 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.
*
*/
/*
* \file
* Z80 machine-specific implementation for supporting multithread.
* \author
* Takahide Matsutsuka <markn@markn.org>
*/
#include "sys/mt.h"
#include "mtarch.h"
/*--------------------------------------------------------------------------*/
void
mtarch_init(void)
{
}
/*--------------------------------------------------------------------------*/
void
mtarch_start(struct mtarch_thread *t,
void (*function)(void *), void *data)
{
uint16_t i;
for(i = 0; i < MTARCH_STACKSIZE; i++) {
t->stack[i] = i;
}
t->sp = &t->stack[MTARCH_STACKSIZE - 1];
/* A parameter for method for thread function. */
*t->sp = (uint16_t)data;
--t->sp;
/* This will be a return address of thread function. */
*t->sp = (uint16_t)mt_exit;
--t->sp;
/* The thread function, is used as a return address of mtarch_switch. */
*t->sp = (uint16_t)function;
--t->sp;
/*
* Space for registers.
* af, bc, de, hl, ix, iy, af', bc', de', hl'
*/
/*
* Z80 stack basis:
* push stores the data AFTER decrementing sp.
* pop reads the data BEFORE incrementing sp.
*/
t->sp = t->sp - 9;
}
/*--------------------------------------------------------------------------*/
static struct mtarch_thread *running_thread;
static uint16_t *sptmp;
static void
mtarch_switch()
{
__asm
di ; disable interrupt
; normal registers
push af
push bc
push de
push hl
push ix
push iy
; back registers
ex af,af'
push af
exx
push bc
push de
push hl
; swap between running_thread->sp and SP reg
; _running_thread in asembler below points running_thread->sp
; sptmp = sp;
ld (_sptmp),sp
; sp = *(running_thread->sp);
ld ix,(_running_thread)
ld l,0(ix)
ld h,1(ix)
ld sp,hl
; running_thread->sp = sptmp;
ld hl,(_sptmp)
ld 0(ix),l
ld 1(ix),h
; back registers
pop hl
pop de
pop bc
exx
pop af
ex af,af'
; normal registers
pop iy
pop ix
pop hl
pop de
pop bc
pop af
ei ; enable interrupt
__endasm;
// here sp indicates the address that point the function
}
/*--------------------------------------------------------------------------*/
void
mtarch_exec(struct mtarch_thread *t)
{
running_thread = t;
mtarch_switch();
running_thread = NULL;
}
/*--------------------------------------------------------------------------*/
void
mtarch_remove()
{
}
/*--------------------------------------------------------------------------*/
void
mtarch_yield()
{
if (running_thread == NULL) {
/* ERROR! we have no runnning thread. */
return;
}
mtarch_switch();
}
/*--------------------------------------------------------------------------*/
void mtarch_stop(struct mtarch_thread *thread)
{
}
/*--------------------------------------------------------------------------*/
void
mtarch_pstop()
{
}
/*--------------------------------------------------------------------------*/
void
mtarch_pstart()
{
}
/*--------------------------------------------------------------------------*/
int
mtarch_stack_usage(struct mtarch_thread *t)
{
uint16_t i;
for (i = 0; i < MTARCH_STACKSIZE; i++) {
if (t->stack[i] != i) {
return MTARCH_STACKSIZE - i;
}
}
return 0;
}
/*--------------------------------------------------------------------------*/

View File

@ -1,65 +0,0 @@
/*
* 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.
*
*/
/*
* \file
* Z80 machine-specific difinitions for supporting multithread.
*
* \author
* Takahide Matsutsuka <markn@markn.org>
*/
#ifndef __MTARCH_H__
#define __MTARCH_H__
/* Unit of the stack is 2byte wide. */
#ifndef MTARCH_STACKSIZE
#define MTARCH_STACKSIZE 128
#endif /* MTARCH_STACKSIZE */
struct mtarch_thread {
/*
* On top of the mtarch_thread must be the address for the stack pointer.
* See details at mtarch_switch in mtarch.c
*/
uint16_t *sp;
/*
* Stack is 2-byte wide, so please note that you need 2 * MTARCH_STACKSIZE
* bytes for the stack area for each thread.
*/
uint16_t stack[MTARCH_STACKSIZE];
};
/*
* A function for debugging purpose, placed here by following other implementations.
*/
int mtarch_stack_usage(struct mtarch_thread *t);
#endif /* __MTARCH_H__ */

View File

@ -1,221 +0,0 @@
;;;
;;;
;;; uip_arch-asm.S
;;;
;;; \file
;;; Z80 architecture-depend uip module
;;; for calculating checksums
;;;
;;; \author
;;; Takahide Matsutsuka <markn@markn.org>
;;;
.module uip_arch-asm
;; export symbols
.globl _uip_add32
.globl _uip_arch_chksum
.globl _uip_chksum
;; import symbols
.globl _uip_acc32
.globl _uip_buf
.area _DATA
.area _GSINIT
.area _CODE
;; ---------------------------------
;; void uip_add32(uint8_t *op32, uint16_t op16);
;; Stack; retl reth op32l op32h op16l op16h
;; ABCDEHL____
;; return void
;; _uip_acc32 = op32 + op16
;; ---------------------------------
_uip_add32_start::
_uip_add32:
;; HL = #_op32l
ld hl, #2
add hl, sp
;; DE = #(_op32)
ld e, (hl)
inc hl
ld d, (hl)
inc hl
;; BC = op16
ld c, (hl)
inc hl
ld b, (hl)
;; HL = #(_op32) + 3
ld hl, #3
add hl, de
;; DE = #_uip_acc32 + 3
ld de, #_uip_acc32 + 3
;; uip_acc32[3] = op32[3] + op16l;
ld a, (hl)
add a, c
ld (de), a
;; uip_acc32[2] = op32[2] + op16h + carry;
dec hl
dec de
ld a, (hl)
adc a, b
ld (de), a
jr nc, _uip_add32_nocarry1
;; uip_acc32[1]
dec hl
dec de
ld a, (hl)
inc a
ld (de), a
jr nz, _uip_add32_nocarry0
;; uip_acc32[0]
dec hl
dec de
ld a, (hl)
inc a
ld (de), a
ret
_uip_add32_nocarry1:
;; uip_acc32[1]
dec hl
dec de
ld a, (hl)
ld (de), a
_uip_add32_nocarry0:
;; uip_acc32[0]
dec hl
dec de
ld a, (hl)
ld (de), a
ret
_uip_add32_end::
;; ---------------------------------
;; static uint16_t chksum(uint16_t sum, const uint8_t *data, uint16_t len)
;; Stack; retl reth suml sumh datal datah lenl lenh
;; ABCDEHL____
;; return HL
;; ---------------------------------
_uip_arch_chksum_start::
_uip_arch_chksum:
push ix
;; IX = #_suml
ld ix, #4
add ix, sp
;; BC = sum
ld c, 0(ix)
ld b, 1(ix)
;; DE = #data
ld e, 2(ix)
ld d, 3(ix)
;; (lenl, lenh) <- dataptr + len - 1 (last address)
;; (len) + DE - 1 -> (len)
ld l, 4(ix)
ld h, 5(ix)
add hl, de
dec hl
ld 4(ix), l
ld 5(ix), h
_uip_arch_chksum_loop:
;; compare HL(last address) and DE(dataptr)
;; HL - DE
;; if (HL < DE) C,NZ else if (HL = DE) NC,Z=1 otherwise NC,NZ
;; HL = last address, DE = current pointer
ld l, 4(ix)
ld h, 5(ix)
ld a, h
sub d
jr nz, _uip_arch_chksum_compared
ld a, l
sub e
;; if (last address == dataptr) _uip_arch_chksum_loop_exit_add_trailing
jr z, _uip_arch_chksum_loop_exit_add_trailing
_uip_arch_chksum_compared:
;; if (last address > dataptr) _uip_arch_chksum_loop_exit
jr c, _uip_arch_chksum_loop_exit
;; bc = dataptr[0],dataptr[1] + bc
ld a, (de)
ld h, a
inc de
ld a, (de)
ld l, a
push hl
add hl, bc
inc de
ld b, h
ld c, l
;; HL = t
pop hl
;; BC - HL
;; if (sumBC < tHL) sum++
ld a, b
sub h
jr nz, _uip_arch_chksum_compared_t
ld a, c
sub l
_uip_arch_chksum_compared_t:
jr nc, _uip_arch_chksum_nocarry_t
inc bc
_uip_arch_chksum_nocarry_t:
jr _uip_arch_chksum_loop
_uip_arch_chksum_loop_exit_add_trailing:
;; HL = last address
;; bc = bc + (last address)<<8
ld a, b
add a, (hl)
ld b, a
jr nc, _uip_arch_chksum_loop_exit
inc bc
_uip_arch_chksum_loop_exit:
ld l, c
ld h, b
pop ix
ret
_uip_arch_chksum_end::
;; ---------------------------------
;; uint16_t uip_chksum(void);
;; Stack; retl reth datal datah lenl lenh
;; ABCDEHL____
;; return HL
;; return htons(chksum(0, (uint8_t *)data, len));
;; ---------------------------------
_uip_chksum_start::
_uip_chksum:
ld hl, #5
add hl, sp
;; HL indicates #_lenh
ld b, #2
_uip_chksum_loop:
ld d, (hl)
dec hl
ld e, (hl)
dec hl
push de
djnz _uip_chksum_loop
ld bc, #0
push bc
call _uip_arch_chksum
pop af
pop af
pop af
;; convert to BIG ENDIAN (htons)
ld a, l
ld l, h
ld h, a
ret
_uip_chksum_end::

View File

@ -1,215 +0,0 @@
/*
* 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.
*
*
*/
/*
* \file
* Z80 architecture-depend uip module
* for calculating checksums
* \author
* Takahide Matsutsuka <markn@markn.org>
*/
#include <stddef.h>
#include "uip_arch.h"
static const uint16_t sizeof_uip_ipaddr_t = sizeof(uip_ipaddr_t);
static const uint16_t offset_tcpip_hdr_len = offsetof(struct uip_tcpip_hdr, len);
static const uint16_t offset_tcpip_hdr_srcipaddr = offsetof(struct uip_tcpip_hdr, srcipaddr);
/*--------------------------------------------------------------------------*/
static void upper_layer_chksum() {
__asm
;; ---------------------------------
;; static uint16_t upper_layer_chksum(uint8_t proto);
;; Stack; retl reth
;; @param C proto
;; ABCDEHL____
;; ---------------------------------
;; HL = BUF = &uip_buf[UIP_LLH_LEN]
ld hl, #_uip_buf
ld de, #UIP_LLH_LEN
add hl, de
push hl
;; HL = BUF->len[0]
push ix
ld ix, #_offset_tcpip_hdr_len
ld e, 0(ix)
ld d, 1(ix)
add hl, de
pop ix
;; DE = upper layer length
ld d, (hl)
inc hl
ld e, (hl)
#if UIP_CONF_IPV6
#else
ld a, e
sub a, #UIP_IPH_LEN
ld e, a
jr nc, _upper_layer_chksum_setlen2
dec d
_upper_layer_chksum_setlen2:
#endif
;; bc = upper_leyer_len + proto
ld b, d
ld a, e
add a, c
ld c, a
jr nc, _upper_layer_chksum_setlen3
inc b
_upper_layer_chksum_setlen3:
pop hl ; BUF
push de
push ix
ld ix, #_offset_tcpip_hdr_srcipaddr
ld e, 0(ix)
ld d, 1(ix)
add hl, de
ld e, l
ld d, h
ld ix, #_sizeof_uip_ipaddr_t
ld l, 0(ix)
ld h, 1(ix)
pop ix
sla l
rl h
push hl
push de
push bc
call _uip_arch_chksum ; hl = sum
pop af
pop af
pop af
;; de is still stacked
ld b, h
ld c, l
ld hl, #_uip_buf
ld de, #UIP_IPH_LEN
add hl, de
_upper_layer_chksum_call:
ld de, #UIP_LLH_LEN
add hl, de
push hl
push bc
call _uip_arch_chksum
pop af
pop af
pop af
ld a, h
or a, l
jr nz, _upper_layer_uip_htons
ld hl, #0xffff
jr _upper_layer_ret
_upper_layer_uip_htons:
ld a, l
ld l, h
ld h, a
_upper_layer_ret:
__endasm;
}
/*--------------------------------------------------------------------------*/
uint16_t
uip_ipchksum(void)
{
__asm
;; ---------------------------------
;; uint16_t uip_ipchksum(void);
;; Stack; retl reth
;; ABCDEHL____
;; return HL
;; ---------------------------------
ld hl, #UIP_IPH_LEN
push hl
;; HL = BUF = &uip_buf[UIP_LLH_LEN]
ld hl, #_uip_buf
;; BC = sum = 0
ld bc, #0
jp _upper_layer_chksum_call
__endasm;
}
/*--------------------------------------------------------------------------*/
#if UIP_CONF_IPV6
uint16_t
uip_icmp6chksum(void)
{
__asm
;; ---------------------------------
;; uint16_t uip_icmp6chksum(void);
;; Stack; retl reth
;; ABCDEHL____
;; return HL
;; ---------------------------------
ld c, #UIP_PROTO_ICMP6
jp _upper_layer_chksum
__endasm;
}
#endif /* UIP_CONF_IPV6 */
/*--------------------------------------------------------------------------*/
uint16_t
uip_tcpchksum(void)
{
__asm
;; ---------------------------------
;; uint16_t uip_tcpchksum(void);
;; Stack; retl reth
;; ABCDEHL____
;; return HL
;; ---------------------------------
ld c, #UIP_PROTO_TCP
jp _upper_layer_chksum
__endasm;
}
/*--------------------------------------------------------------------------*/
#if UIP_UDP_CHKSUMS
uint16_t
uip_udpchksum(void)
{
__asm
;; ---------------------------------
;; uint16_t uip_udpchksum(void);
;; Stack; retl reth
;; ABCDEHL____
;; return HL
;; ---------------------------------
ld c, #UIP_PROTO_UDP
jp _upper_layer_chksum
__endasm;
}
#endif /* UIP_UDP_CHKSUMS */
/*--------------------------------------------------------------------------*/

View File

@ -1,91 +0,0 @@
/*
* 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.
*
*
*/
/*
* \file
* This file contains a set of configuration for using SDCC as a compiler.
*
* \author
* Takahide Matsutsuka <markn@markn.org>
*/
#ifndef __Z80_DEF_H__
#define __Z80_DEF_H__
#define CC_CONF_FUNCTION_POINTER_ARGS 1
#define CC_CONF_FASTCALL
#define CC_CONF_VA_ARGS 0
#define CC_CONF_UNSIGNED_CHAR_BUGS 0
#define CC_CONF_REGISTER_ARGS 0
/* Generic types. */
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;
typedef unsigned char u8_t; /* 8 bit type */
typedef unsigned short u16_t; /* 16 bit type */
typedef unsigned long u32_t; /* 32 bit type */
typedef signed long s32_t; /* 32 bit type */
typedef unsigned short uip_stats_t;
typedef signed long int32_t; /* 32 bit type */
#ifndef _SIZE_T_DEFINED
#define _SIZE_T_DEFINED
typedef unsigned int size_t;
#endif
/* Compiler configurations */
#define CCIF
#define CLIF
#define CC_CONF_CONST_FUNCTION_BUG
/*
* Enable architecture-depend checksum calculation
* for uIP configuration.
* @see uip_arch.h
* @see uip_arch-asm.S
*/
#define UIP_ARCH_ADD32 1
#define UIP_ARCH_CHKSUM 1
#define UIP_ARCH_IPCHKSUM
#define CC_CONF_ASSIGN_AGGREGATE(dest, src) \
memcpy(dest, src, sizeof(*dest))
#define uip_ipaddr_copy(dest, src) \
memcpy(dest, src, sizeof(*dest))
#define snprintf(a...)
#endif /* __Z80_DEF_H__ */

View File

@ -1,183 +0,0 @@
#
# Customized peep-hole optimizer for z80/SDCC
# @author Takahide Matsutsuka <markn@markn.org>
#
# $Id: z80peephole.def,v 1.1 2009/12/11 14:59:32 matsutsuka Exp $
#
replace {
ld hl, %1
ld (hl), #0x%2
inc hl
ld (hl), #0x%3
} by {
;; (peep) 1 short store
ld hl, #0x%3%2
ld (%1), hl
}
replace {
ld hl, %1 + 0
ld (hl), %2
ld hl, %1 + 1
ld (hl), %3
} by {
;; (peep) 2 short store
ld hl, %1
ld (hl), %2
inc hl
ld (hl), %3
}
replace {
sub a, #0x01
jr Z, %1
} by {
;; (peep) 3 decrement optimization
dec a
jr z, %1
}
replace {
sub a, #0x01
jr NZ, %1
} by {
;; (peep) 4 decrement optimization
dec a
jr nz, %1
}
replace {
sub a, #0x01
jp Z, %1
} by {
;; (peep) 5 decrement optimization
dec a
jp z, %1
}
replace {
sub a, #0x01
jp NZ, %1
} by {
;; (peep) 6 decrement optimization
dec a
jp nz, %1
}
replace {
push %1
pop iy
ld a, (iy)
or a, a
} by {
;; (peep) 7 or optimization
ld a, (%1)
or a, a
}
replace {
ld iy, %1
ld a, 0 (iy)
} by {
;; (peep) 8 iy optimization
ld a, (%1)
}
replace {
ld iy, %1
ld 0 (iy), a
} by {
;; (peep) 9 iy optimization
ld (%1), a
}
replace {
push %1
pop iy
ld (iy), %2
} by {
;; (peep) 10 iy optimization
ld a, %2
ld (%1), a
}
replace {
ld iy, %1
ld %2,0 (iy)
ld iy, %1
ld %3,1 (iy)
ld iy, %1
ld %4,2 (iy)
ld iy, %1
ld %5,3 (iy)
} by {
;; (peep) 11 iy optimization
ld iy, %1
ld %2,0 (iy)
ld %3,1 (iy)
ld %4,2 (iy)
ld %5,3 (iy)
}
replace {
ld iy, %1
ld %2,0 (iy)
ld iy, %1
ld %3,1 (iy)
} by {
;; (peep) 12 iy optimization
ld iy, %1
ld %2,0 (iy)
ld %3,1 (iy)
}
replace {
ld iy, %1
ld 0 (iy), %2
ld iy, %1
ld 1 (iy), %3
ld iy, %1
ld 2 (iy), %4
ld iy, %1
ld 3 (iy), %5
} by {
;; (peep) 13 iy optimization
ld iy, %1
ld 0 (iy), %2
ld 1 (iy), %3
ld 2 (iy), %4
ld 3 (iy), %5
}
replace {
ld iy, %1
ld 0 (iy), %2
ld iy, %1
ld 1 (iy), %3
} by {
;; (peep) 14 iy optimization
ld iy, %1
ld 0 (iy), %2
ld 1 (iy), %3
}
replace {
jp %1
%2:
} by {
;; (peep) 15 short jump optimization
jr %1
%2:
} if labelInRange
replace {
ld c,%3 (ix)
ld b,%4 (ix)
push bc
pop iy
ld 0 (iy), #0x%6
ld 1 (iy), #0x%5
} by {
;; (peep) 16 store value
ld l, %3 (ix)
ld h, %4 (ix)
ld (hl), #0x%5%6
}