From 77b62b49054cb150e7d621515b920081ec6f0598 Mon Sep 17 00:00:00 2001 From: borutr Date: Fri, 3 Mar 2006 19:32:46 +0000 Subject: [PATCH] * support/regression/fwk/lib/testfwk.c, support/regression/fwk/include/testfwk.h: introduced function _prints(), nonrecursive _printn(), call _initEmu() from main() * support/regression/ports/gbz80/support.asm, support/regression/ports/ucz80/support.asm, support/regression/ports/z80/support.asm, support/regression/ports/ds390/support.c, support/regression/ports/hc08/support.c, support/regression/ports/host/support.c, support/regression/ports/mcs51/support.c, support/regression/ports/xa51/support.c: added empty _initEmu() function * support/regression/ports/pic16/gpsim.cmd, support/regression/ports/pic16/spec.mk, support/regression/ports/pic16/support.c, support/regression/Makefile.in: added pic16 regression test git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4049 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 19 +++ support/regression/Makefile.in | 2 +- support/regression/fwk/include/testfwk.h | 22 ++- support/regression/fwk/lib/testfwk.c | 174 +++++++++++---------- support/regression/ports/ds390/support.c | 5 + support/regression/ports/gbz80/support.asm | 3 + support/regression/ports/hc08/support.c | 5 + support/regression/ports/host/support.c | 11 +- support/regression/ports/mcs51/support.c | 5 + support/regression/ports/pic16/gpsim.cmd | 2 + support/regression/ports/pic16/spec.mk | 43 +++++ support/regression/ports/pic16/support.c | 102 ++++++++++++ support/regression/ports/ucz80/support.asm | 3 + support/regression/ports/xa51/support.c | 5 + support/regression/ports/z80/support.asm | 3 + 15 files changed, 310 insertions(+), 94 deletions(-) create mode 100755 support/regression/ports/pic16/gpsim.cmd create mode 100644 support/regression/ports/pic16/spec.mk create mode 100644 support/regression/ports/pic16/support.c diff --git a/ChangeLog b/ChangeLog index 65c7c3ea..e70abe4d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2006-03-02 Borut Razem + + * support/regression/fwk/lib/testfwk.c, + support/regression/fwk/include/testfwk.h: introduced function + _prints(), nonrecursive _printn(), call _initEmu() from main() + * support/regression/ports/gbz80/support.asm, + support/regression/ports/ucz80/support.asm, + support/regression/ports/z80/support.asm, + support/regression/ports/ds390/support.c, + support/regression/ports/hc08/support.c, + support/regression/ports/host/support.c, + support/regression/ports/mcs51/support.c, + support/regression/ports/xa51/support.c: added empty _initEmu() + function + * support/regression/ports/pic16/gpsim.cmd, + support/regression/ports/pic16/spec.mk, + support/regression/ports/pic16/support.c, + support/regression/Makefile.in: added pic16 regression test + 2006-03-01 Raphael Neider * src/pic16/gen.c (genPcall,pic16_derefPtr,genGenPointerGet, diff --git a/support/regression/Makefile.in b/support/regression/Makefile.in index 6450e85b..0c5e55dc 100644 --- a/support/regression/Makefile.in +++ b/support/regression/Makefile.in @@ -62,7 +62,7 @@ GENERATE_CASES = generate-cases.py # Each directory under ports/ is used as a port name. Each port is tested. # Each port must have a spec.mk which describes how to build the object # files and how to run the emulator. -ALL_PORTS = $(filter-out CVS xa51 ucz80 gbz80,$(notdir $(wildcard $(PORTS_DIR)/*))) +ALL_PORTS = $(filter-out CVS xa51 ucz80 gbz80 pic16,$(notdir $(wildcard $(PORTS_DIR)/*))) # These ports will be cleaned with 'make clean' CLEAN_PORTS = $(filter-out CVS,$(notdir $(wildcard $(PORTS_DIR)/*))) diff --git a/support/regression/fwk/include/testfwk.h b/support/regression/fwk/include/testfwk.h index 07cfa31f..2f8c3225 100644 --- a/support/regression/fwk/include/testfwk.h +++ b/support/regression/fwk/include/testfwk.h @@ -1,27 +1,25 @@ #ifndef __TESTFWK_H -#define __TESTFWK_H 1 +#define __TESTFWK_H 1 extern int __numTests; void __fail(const char *szMsg, const char *szCond, const char *szFile, int line); -void __printf(const char *szFormat, ...) REENTRANT; +void __printf(const char *szFormat, ...); -#define ASSERT(_a) (__numTests++, (_a) ? (void)0 : __fail("Assertion failed", #_a, __FILE__, __LINE__)) -#define LOG(_a) __printf _a -#define FAIL() FAILM("Failure") -#define FAILM(_a) __fail(_a, #_a, __FILE__, __LINE__) +#define ASSERT(_a) (__numTests++, (_a) ? (void)0 : __fail("Assertion failed", #_a, __FILE__, __LINE__)) +#define LOG(_a) __printf _a +#define FAIL() FAILM("Failure") +#define FAILM(_a) __fail(_a, #_a, __FILE__, __LINE__) typedef void (*TESTFUNP)(void); // Provided by the suite -TESTFUNP * -suite(void); +TESTFUNP *suite(void); -const char * -getSuiteName(void); +const char *getSuiteName(void); -#define NULL 0 +#define NULL 0 -#define UNUSED(_a) if (_a) { } +#define UNUSED(_a) if (_a) { } #endif diff --git a/support/regression/fwk/lib/testfwk.c b/support/regression/fwk/lib/testfwk.c index 4753dea3..7bad2a3e 100644 --- a/support/regression/fwk/lib/testfwk.c +++ b/support/regression/fwk/lib/testfwk.c @@ -7,12 +7,6 @@ #include /* main() must see the ISR declarations */ #endif -#if defined(PORT_HOST) || defined(SDCC_z80) || defined(SDCC_gbz80) -#define _REENTRANT -#else -#define _REENTRANT reentrant -#endif - #if defined(SDCC_mcs51) /* until changed, isr's must have a prototype in the module containing main */ void T2_isr (void) interrupt 5; @@ -23,11 +17,13 @@ void T2_isr (void) interrupt 5; */ //#define BROKEN_DIV_MOD 1 -void _putchar(char c); -void _exitEmu(void); +extern void _putchar(char c); +extern void _initEmu(void); +extern void _exitEmu(void); #if BROKEN_DIV_MOD -int __div(int num, int denom) +static int +__div(int num, int denom) { int q = 0; while (num >= denom) { @@ -37,7 +33,8 @@ int __div(int num, int denom) return q; } -int __mod(int num, int denom) +static int +__mod(int num, int denom) { while (num >= denom) { num -= denom; @@ -45,101 +42,120 @@ int __mod(int num, int denom) return num; } #else -int __div(int num, int denom) -{ - return num/denom; -} +#define __div(num, denom) ((num) / (denom)) +#define __mod(num, denom) ((num) % (denom)) +#endif -int __mod(int num, int denom) +static void +_prints(const char *s) { - return num%denom; + char c; + + while ('\0' != (c = *s)) { + _putchar(c); + ++s; + } } -#endif -static void _printn(int n) _REENTRANT +static void +_printn(int n) { - int rem; - - if (n < 0) { - _putchar('-'); - n = -n; + if (0 == n) { + _putchar('0'); + } + else { + char buf[6]; + char *p = &buf[sizeof(buf) - 1]; + char neg = 0; + + buf[sizeof(buf) - 1] = '\0'; + + if (0 > n) { + n = -n; + neg = 1; } - - rem = __mod(n, 10); - if (rem != n) { - _printn(__div(n, 10)); + + while (0 != n) { + *--p = '0' + __mod(n, 10); + n = __div(n, 10); } - _putchar('0' + rem); + + if (neg) + _putchar('-'); + + _prints(p); + } } -void __printf(const char *szFormat, ...) REENTRANT +void +__printf(const char *szFormat, ...) { - va_list ap; - va_start(ap, szFormat); - - while (*szFormat) { - if (*szFormat == '%') { - switch (*++szFormat) { - case 's': { - char *sz = va_arg(ap, char *); - while (*sz) { - _putchar(*sz++); - } - break; - } - case 'u': { - int i = va_arg(ap, int); - _printn(i); - break; - } - case '%': - _putchar('%'); - break; - default: - break; - } - } - else { - _putchar(*szFormat); - } - szFormat++; + va_list ap; + va_start(ap, szFormat); + + while (*szFormat) { + if (*szFormat == '%') { + switch (*++szFormat) { + case 's': { + char *sz = va_arg(ap, char *); + _prints(sz); + break; + } + case 'u': { + int i = va_arg(ap, int); + _printn(i); + break; + } + case '%': + _putchar('%'); + break; + default: + break; + } + } + else { + _putchar(*szFormat); } - va_end(ap); + szFormat++; + } + va_end(ap); } -int __numTests; -int __numFailures; +int __numTests = 0; +static int __numFailures = 0; void __fail(const char *szMsg, const char *szCond, const char *szFile, int line) { - __printf("--- FAIL: \"%s\" on %s at %s:%u\n", szMsg, szCond, szFile, line); - __numFailures++; + __printf("--- FAIL: \"%s\" on %s at %s:%u\n", szMsg, szCond, szFile, line); + __numFailures++; } int main(void) { - TESTFUNP *cases; - int numCases = 0; + TESTFUNP *cases; + int numCases = 0; - __printf("--- Running: %s\n", getSuiteName()); + _initEmu(); - cases = suite(); + __printf("--- Running: %s\n", getSuiteName()); - while (*cases) { - __printf("Running %u\n", numCases); - (*cases)(); - cases++; - numCases++; - } + cases = suite(); + + while (*cases) { + __printf("Running %u\n", numCases); + (*cases)(); + cases++; + numCases++; + } - __printf("--- Summary: %u/%u/%u: %u failed of %u tests in %u cases.\n", - __numFailures, __numTests, numCases, - __numFailures, __numTests, numCases - ); + __printf("--- Summary: %u/%u/%u: %u failed of %u tests in %u cases.\n", + __numFailures, __numTests, numCases, + __numFailures, __numTests, numCases + ); - _exitEmu(); + _exitEmu(); - return 0; + return 0; } diff --git a/support/regression/ports/ds390/support.c b/support/regression/ports/ds390/support.c index 7ced42f7..f582f22f 100644 --- a/support/regression/ports/ds390/support.c +++ b/support/regression/ports/ds390/support.c @@ -30,6 +30,11 @@ _putchar (char c) Serial0PutChar (c); } +void +_initEmu (void) +{ +} + void _exitEmu (void) { diff --git a/support/regression/ports/gbz80/support.asm b/support/regression/ports/gbz80/support.asm index 01e0ef8b..c16fa2ab 100644 --- a/support/regression/ports/gbz80/support.asm +++ b/support/regression/ports/gbz80/support.asm @@ -5,5 +5,8 @@ __putchar:: jp _putchar +__initEmu:: + ret + __exitEmu:: jp _exit diff --git a/support/regression/ports/hc08/support.c b/support/regression/ports/hc08/support.c index efb77ca6..69705c2a 100644 --- a/support/regression/ports/hc08/support.c +++ b/support/regression/ports/hc08/support.c @@ -8,6 +8,11 @@ _putchar(unsigned char c) _endasm; } +void +_initEmu(void) +{ +} + void _exitEmu(void) { diff --git a/support/regression/ports/host/support.c b/support/regression/ports/host/support.c index 1077fb5b..3921b47c 100644 --- a/support/regression/ports/host/support.c +++ b/support/regression/ports/host/support.c @@ -3,12 +3,19 @@ #include #include -void _putchar(char c) +void +_putchar(char c) { putchar(c); } -void _exitEmu(void) +void +_initEmu(void) +{ +} + +void +_exitEmu(void) { exit(0); } diff --git a/support/regression/ports/mcs51/support.c b/support/regression/ports/mcs51/support.c index ddb75582..47ddf35b 100644 --- a/support/regression/ports/mcs51/support.c +++ b/support/regression/ports/mcs51/support.c @@ -27,6 +27,11 @@ _putchar (char c) TI = 0; } +void +_initEmu (void) +{ +} + void _exitEmu (void) { diff --git a/support/regression/ports/pic16/gpsim.cmd b/support/regression/ports/pic16/gpsim.cmd new file mode 100755 index 00000000..58afc787 --- /dev/null +++ b/support/regression/ports/pic16/gpsim.cmd @@ -0,0 +1,2 @@ +run +quit diff --git a/support/regression/ports/pic16/spec.mk b/support/regression/ports/pic16/spec.mk new file mode 100644 index 00000000..27167811 --- /dev/null +++ b/support/regression/ports/pic16/spec.mk @@ -0,0 +1,43 @@ +# Port specification for the pic16 port running with uCsim + +# path to gpsim +ifdef GPSIM_PATH + GPSIM := $(GPSIM_PATH)/gpsim +else + GPSIM := gpsim +endif + +SDCCFLAGS += -mpic16 -I$(SDCC_DIR)/device/include/pic16 --nostdinc --less-pedantic -Wl,-t255 -DREENTRANT=reentrant +LINKFLAGS = --nostdlib +LINKFLAGS += libsdcc.lib libc18f.lib +LIBDIR = $(SDCC_DIR)/device/lib/build/pic16 + +OBJEXT = .o +EXEEXT = .cod + +EXTRAS = $(PORTS_DIR)/$(PORT)/testfwk$(OBJEXT) $(PORTS_DIR)/$(PORT)/support$(OBJEXT) + +# Rule to link into .ihx +%$(EXEEXT): %$(OBJEXT) $(EXTRAS) + $(SDCC) $(SDCCFLAGS) $(LINKFLAGS) -L $(LIBDIR) $(EXTRAS) $< -o $@ + +%$(OBJEXT): %.c + $(SDCC) $(SDCCFLAGS) -c $< -o $@ + +$(PORTS_DIR)/$(PORT)/testfwk$(OBJEXT): fwk/lib/testfwk.c + $(SDCC) $(SDCCFLAGS) -c $< -o $@ + +# run simulator with 25 seconds timeout +%.out: %$(EXEEXT) fwk/lib/timeout + mkdir -p `dirname $@` + -fwk/lib/timeout 25 $(GPSIM) -i -s $< -c $(PORTS_DIR)/pic16/gpsim.cmd > $@ || \ + echo -e --- FAIL: \"timeout, simulation killed\" in $(<:$(EXEEXT)=.c)"\n"--- Summary: 1/1/1: timeout >> $@ + python get_ticks.py < $@ >> $@ + -grep -n FAIL $@ /dev/null || true + +fwk/lib/timeout: fwk/lib/timeout.c + +_clean: + rm -f fwk/lib/timeout fwk/lib/timeout.exe $(PORTS_DIR)/$(PORT)/*.rel $(PORTS_DIR)/$(PORT)/*.rst \ + $(PORTS_DIR)/$(PORT)/*.lst $(PORTS_DIR)/$(PORT)/*.sym $(PORTS_DIR)/$(PORT)/*.asm \ + $(PORTS_DIR)/$(PORT)/*.lnk $(PORTS_DIR)/$(PORT)/*.map $(PORTS_DIR)/$(PORT)/*.mem diff --git a/support/regression/ports/pic16/support.c b/support/regression/ports/pic16/support.c new file mode 100644 index 00000000..281ebb17 --- /dev/null +++ b/support/regression/ports/pic16/support.c @@ -0,0 +1,102 @@ +/*------------------------------------------------------------------------- + support.c - startup for PIC16 regression tests with gpsim + + Copyright (c) 2006 Borut Razem + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! +-------------------------------------------------------------------------*/ + +#pragma preproc_asm - +#include + + +void +_putchar(char c) +{ + while (!PIR1bits.TXIF) + ; + TXREG = c; +} + + +void +_initEmu(void) +{ + /* load and configure the libgpsim_usart_con module */ + _asm + ;; Set frequency to 20MHz + .direct "e", ".frequency=20e6" + + ;; Load the USART library and module + .direct "e", "module library libgpsim_usart_con" + .direct "e", "module load usart_con U1" + + ;; Define a node + .direct "e", "node PIC_tx" + + ;; Tie the USART module to the PIC + .direct "e", "attach PIC_tx portc6 U1.RXPIN" + + ;; Set the USART module's Baud Rate + .direct "e", "U1.rxbaud = 9600" + _endasm; + + /* USART initialization */ + PORTCbits.TX = 1; // Set TX pin to 1 + TRISCbits.TRISC6 = 0; // TX pin is output + + TXSTA = 0; // Reset USART registers to POR state + RCSTA = 0; + + //1. Initialize the SPBRG register for the appropriate + // baud rate. If a high speed baud rate is desired, + // set bit BRGH (Section 16.1). + TXSTAbits.BRGH = 1; + SPBRG = 129; + + //2. Enable the asynchronous serial port by clearing + // bit SYNC and setting bit SPEN. + RCSTAbits.SPEN = 1; + + //3. If interrupts are desired, set enable bit TXIE. + //4. If 9-bit transmission is desired, set transmit bit + // TX9. Can be used as address/data bit. + //5. Enable the transmission by setting bit TXEN, + // which will also set bit TXIF. + TXSTAbits.TXEN = 1; + + //6. If 9-bit transmission is selected, the ninth bit + // should be loaded in bit TX9D. + //7. Load data to the TXREG register (starts + // transmission). +} + + +void +_exitEmu(void) +{ + /* wait until the transmit buffer is empty */ + while (!TXSTAbits.TRMT) + ; + + /* set the breakpoint */ + _asm + .direct "a", "\"\"" + _endasm; +} diff --git a/support/regression/ports/ucz80/support.asm b/support/regression/ports/ucz80/support.asm index 01e0ef8b..c16fa2ab 100644 --- a/support/regression/ports/ucz80/support.asm +++ b/support/regression/ports/ucz80/support.asm @@ -5,5 +5,8 @@ __putchar:: jp _putchar +__initEmu:: + ret + __exitEmu:: jp _exit diff --git a/support/regression/ports/xa51/support.c b/support/regression/ports/xa51/support.c index 8b091917..85c98676 100755 --- a/support/regression/ports/xa51/support.c +++ b/support/regression/ports/xa51/support.c @@ -36,6 +36,11 @@ _putchar (char c) _endasm; } +void +_initEmu (void) +{ +} + void _exitEmu (void) { diff --git a/support/regression/ports/z80/support.asm b/support/regression/ports/z80/support.asm index 01e0ef8b..c16fa2ab 100644 --- a/support/regression/ports/z80/support.asm +++ b/support/regression/ports/z80/support.asm @@ -5,5 +5,8 @@ __putchar:: jp _putchar +__initEmu:: + ret + __exitEmu:: jp _exit -- 2.47.2