From: bernhardheld Date: Wed, 7 Nov 2001 20:28:07 +0000 (+0000) Subject: * sdcc/sim/ucsim/s51.src/glob.cc: Minor fix. X-Git-Url: https://git.gag.com/?a=commitdiff_plain;ds=sidebyside;h=1bb04369c1ceddeeace0ecd3a8bd05f0877ba4e3;p=fw%2Fsdcc * sdcc/sim/ucsim/s51.src/glob.cc: Minor fix. * sdcc/sim/ucsim/s51.src/regs51.h: Minor fix. * sdcc/support/regression/Makefile: Add port ds390. * sdcc/support/regression/ports/mcs51/spec.mk: Minor change. * sdcc/support/regression/ports/ds390/spec.mk: Added. * sdcc/support/regression/ports/ds390/support.c: Added. * sdcc/support/regression/ports/ds390/uCsim.cmd: Added. * sdcc/support/regression/ports/mcs51/timeout.c: Cut. * sdcc/support/regression/fwk/lib/timeout.c: Paste. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1523 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 3921f27e..a5c420c2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2001-11-07 Bernhard Held + + * sdcc/sim/ucsim/s51.src/glob.cc: Minor fix. + + * sdcc/sim/ucsim/s51.src/regs51.h: Minor fix. + + * sdcc/support/regression/Makefile: Add port ds390. + + * sdcc/support/regression/ports/mcs51/spec.mk: Minor change. + + * sdcc/support/regression/ports/z80/spec.mk: Minor change. + + * sdcc/support/regression/ports/ds390/spec.mk: Added. + + * sdcc/support/regression/ports/ds390/support.c: Added. + + * sdcc/support/regression/ports/ds390/uCsim.cmd: Added. + + * sdcc/support/regression/ports/mcs51/timeout.c: Cut. + + * sdcc/support/regression/fwk/lib/timeout.c: Paste. + 2001-11-04 Michael Hope * device/include/malloc.h: Added z80 and gbz80 support. diff --git a/sim/ucsim/s51.src/glob.cc b/sim/ucsim/s51.src/glob.cc index cd3f47a8..2f2e88ba 100644 --- a/sim/ucsim/s51.src/glob.cc +++ b/sim/ucsim/s51.src/glob.cc @@ -322,9 +322,9 @@ struct name_entry sfr_tab51[]= {CPU_ALL_51|CPU_ALL_52|CPU_251, 0x8d, "TH1"}, {CPU_ALL_51|CPU_ALL_52|CPU_251, 0x8b, "TL1"}, {CPU_ALL_51|CPU_ALL_52|CPU_251, 0x98, "SCON"}, - {CPU_ALL_51|CPU_ALL_52, 0x99, "SBUF"}, - {CPU_251, 0x99, "SBUF0"}, - {CPU_251, 0xC1, "SBUF1"}, + {CPU_DS390|CPU_DS390F, 0x99, "SBUF0"}, + {CPU_DS390|CPU_DS390F, 0xC1, "SBUF1"}, + {CPU_ALL_51|CPU_ALL_52|CPU_251, 0x99, "SBUF"}, {CPU_ALL_51|CPU_ALL_52|CPU_251, 0x87, "PCON"}, {CPU_ALL_52|CPU_251, 0xc8, "T2CON"}, {CPU_ALL_52|CPU_251, 0xcd, "TH2"}, diff --git a/sim/ucsim/s51.src/regs51.h b/sim/ucsim/s51.src/regs51.h index 4155c1a0..b9f55a5c 100644 --- a/sim/ucsim/s51.src/regs51.h +++ b/sim/ucsim/s51.src/regs51.h @@ -82,8 +82,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #define MCNT0 0xd1 #define MCNT1 0xd2 #define MA 0xd3 /* MA register from math accelerator */ -#define MB 0xd4 /* MA register from math accelerator */ -#define MC 0xd5 /* MA register from math accelerator */ +#define MB 0xd4 /* MB register from math accelerator */ +#define MC 0xd5 /* MC register from math accelerator */ #define CCON 0xd8 /* */ #define CMOD 0xd9 /* */ #define CCAPM0 0xda /* */ diff --git a/support/regression/Makefile b/support/regression/Makefile index 92057a7e..5d9e50eb 100644 --- a/support/regression/Makefile +++ b/support/regression/Makefile @@ -61,10 +61,10 @@ GENERATE_CASES = generate-cases.py # The port name must be the same as the one used in the SDCC '-mxxx' argument. # 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 mcs51 gbz80,$(notdir $(wildcard $(PORTS_DIR)/*))) +ALL_PORTS = $(filter-out CVS mcs51 ds390 gbz80,$(notdir $(wildcard $(PORTS_DIR)/*))) # These ports will be cleaned with 'make clean' -CLEAN_PORTS = $(filter-out CVS,$(notdir $(wildcard $(PORTS_DIR)/*))) +CLEAN_PORTS = $(filter-out CVS,$(notdir $(wildcard $(PORTS_DIR)/*))) all: test-ports @@ -84,7 +84,11 @@ test-gbz80: test-mcs51: $(MAKE) inter-port-clean test-port PORT=mcs51 -# Helper rule for testing the host cc only + # Helper rule for testing the ds390 port only +test-ds390: + $(MAKE) inter-port-clean test-port PORT=ds390 + +### Helper rule for testing the host cc only test-host: $(MAKE) inter-port-clean test-port PORT=host @@ -115,7 +119,7 @@ OBJEXT = .o # Extension of files that can be run in the emulator EXEEXT = .bin # Currently unused. Extension to append to intermediate directories. -DIREXT = +DIREXT = # Only include if we're in a per-port call. ifdef PORT @@ -183,9 +187,9 @@ $(RESULTS): $(SUB_RESULTS) # BeginGeneric rules clean: inter-port-clean - rm -rf $(CASES_DIR) $(RESULTS_DIR) *.pyc + rm -rf $(CASES_DIR) $(RESULTS_DIR) *.pyc fwk/lib/timeout fwk/lib/timeout.exe for i in $(CLEAN_PORTS); do $(MAKE) -f $(PORTS_DIR)/$$i/spec.mk _clean PORT=$$i; done inter-port-clean: rm -f fwk/lib/*.o fwk/lib/*.asm fwk/lib/*.rst fwk/lib/*.lst fwk/lib/*.rel \ - fwk/lib/*.ihx fwk/lib/*.map fwk/lib/*.sym + fwk/lib/*.ihx fwk/lib/*.map fwk/lib/*.sym diff --git a/support/regression/fwk/lib/timeout.c b/support/regression/fwk/lib/timeout.c new file mode 100644 index 00000000..a768ffe5 --- /dev/null +++ b/support/regression/fwk/lib/timeout.c @@ -0,0 +1,163 @@ +/*------------------------------------------------------------------------- + timeout.c - source file for running ucSim within the regression tests + + Written By - Bernhard Held . bernhard@bernhardheld.de (2001) + + 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! +-------------------------------------------------------------------------*/ + +#define PROGNAME "timeout" + +#define USAGE PROGNAME " : 1.00\n" \ + "Usage : " PROGNAME " timeout_in_seconds filename [arguments]\n" \ + " ´filename´ is executed, the arguments are passed to ´filename´.\n" \ + " When ´filename´exits before the timeout expires, the\n" \ + " exit-status of ´filename´ is returned.\n" \ + " When the timeout expires before ´filename´ exits, ´filename´\n" \ + " will be killed and an exit-status of 1 is returned.\n" + +/* First the program tries to limit the maximum CPU-time to the timeout-value. + Then the child is run with execvp(). + + It's not possible to limit the CPU-time under Cygwin (V1.3.3). If setrlimit (RLIMIT_CPU, rlp) + fails, the program will fork() and run the child with execvp(). The fork/exec pair is slow on + Cygwin, but what else can we do? The parent sleeps until: + - a signal shows the child´s exitus + The exit status of the child is returned. + - the timeout elapses + The child will be killed. +*/ + +#include +#include +#include +#include +#include + +/* Get the status from all child processes that have terminated, without ever waiting. + This function is designed to be a handler for SIGCHLD, the signal that indicates + that at least one child process has terminated. + http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_23.html#SEC401 +*/ + +#ifndef WAIT_ANY + #define WAIT_ANY -1 +#endif + +void +sigchld_handler (int signum) +{ + int pid; + int status; + int exit_status = 0; + + while (1) + { + pid = waitpid (WAIT_ANY, &status, WNOHANG); + if (WEXITSTATUS (status)) + exit_status = 1; // WEXITSTATUS(status); + /* pid == -1: no children */ + /* pid == 0: no children to be noticed */ + if (pid <= 0) + break; + } + exit (exit_status); +} + +int +main (int argc, char * const *argv) +{ + /* if getrlimit() / setrlimit() succeed, then no fork is neeeded */ + int flagNoFork = 0; + int old_stderr; + long timeout; + pid_t pid_child; + struct rlimit rl; + + if (argc < 3) + { + fprintf (stderr, USAGE); + return 1; + } + timeout = atol (argv[1]); + if (timeout == 0) + { + fprintf (stderr, "Error parameter " PROGNAME ": must be a non-zero dezimal value\n"); + return 1; + } + + /* try to use getrlimit() / setrlimit() for RLIMIT_CPU */ + /* to limit the CPU-time */ + if (getrlimit (RLIMIT_CPU, &rl) == 0) + { + rl.rlim_cur = timeout; + if (setrlimit (RLIMIT_CPU, &rl) == 0) + flagNoFork = 1; + } + + if (flagNoFork) + { /* the CPU-time is limited: simple execvp */ + + /* s51 prints warnings on stderr: */ + /* serial input/output interface connected to a non-terminal file. */ + /* We'll redirect here stderr to stdout, which will be redirected */ + /* to /dev/null by the shell. The shell could also redirect stderr */ + /* to /dev/null, but then this program doesn't have the chance to */ + /* output any real error. */ + old_stderr = dup (STDERR_FILENO); + dup2 (STDOUT_FILENO, STDERR_FILENO); + /* shouldn't return */ + execvp (argv[2], argv + 2); + /* restore stderr */ + dup2 (old_stderr, STDERR_FILENO); + perror (argv[2]); + return 1; /* Error */ + } + else + { + /* do it the hard way: fork/exec */ + signal (SIGCHLD, sigchld_handler); + pid_child = fork(); + if (pid_child == 0) + { + /* s51 prints warnings on stderr: */ + /* serial input/output interface connected to a non-terminal file. */ + /* We'll redirect here stderr to stdout, which will be redirected */ + /* to /dev/null by the shell. The shell could also redirect stderr */ + /* to /dev/null, but then this program doesn't have the chance to */ + /* output any real error. */ + old_stderr = dup (STDERR_FILENO); + dup2 (STDOUT_FILENO, STDERR_FILENO); + /* shouldn't return */ + execvp (argv[2], argv + 2); + /* restore stderr */ + dup2 (old_stderr, STDERR_FILENO); + perror (argv[2]); + return 1; /* Error */ + } + else + { + /* this timeout is hopefully aborted by a SIGCHLD */ + sleep (timeout); + fprintf (stderr, PROGNAME ": timeout, killing child %s\n", argv[2]); + kill (pid_child, SIGTERM); + return 1; /* Error */ + } + } +} diff --git a/support/regression/ports/ds390/spec.mk b/support/regression/ports/ds390/spec.mk new file mode 100644 index 00000000..ff6a68e3 --- /dev/null +++ b/support/regression/ports/ds390/spec.mk @@ -0,0 +1,35 @@ +# Port specification for the ds390 port running with uCsim + +# path to uCsim +S51 = ../../sim/ucsim/s51.src/s51 + +SDCCFLAGS +=-mds390 --lesspedantic -DREENTRANT=reentrant --stack-after-data + +OBJEXT = .rel +EXEEXT = .ihx + +EXTRAS = fwk/lib/testfwk$(OBJEXT) $(PORTS_DIR)/$(PORT)/support$(OBJEXT) + +# Rule to link into .ihx +%$(EXEEXT): %$(OBJEXT) $(EXTRAS) + $(SDCC) $(SDCCFLAGS) $(EXTRAS) $< + mv fwk/lib/testfwk.ihx $@ + mv fwk/lib/testfwk.map $(@:.ihx=.map) + +%$(OBJEXT): %.c + $(SDCC) $(SDCCFLAGS) -c $< + +# run simulator with 5 seconds timeout +%.out: %$(EXEEXT) fwk/lib/timeout + mkdir -p `dirname $@` + -fwk/lib/timeout 5 $(S51) -tds390f -S in=/dev/null,out=$@ $< < $(PORTS_DIR)/ds390/uCsim.cmd >/dev/null || \ + echo -e --- FAIL: \"timeout, simulation killed\" in $(<:.ihx=.c)"\n"--- Summary: 1/1/1: timeout >> $@ + -grep -n FAIL $@ /dev/null || true + +fwk/lib/timeout: fwk/lib/timeout.c + gcc -o $@ $< + +_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 temp.lnk + diff --git a/support/regression/ports/ds390/support.c b/support/regression/ports/ds390/support.c new file mode 100644 index 00000000..d91f1880 --- /dev/null +++ b/support/regression/ports/ds390/support.c @@ -0,0 +1,108 @@ +/*------------------------------------------------------------------------- + support.c - startup for regression tests with uCsim + + Copied from tinibios.c, which was written By - Johan Knol, johan.knol@iduna.nl + + 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! +-------------------------------------------------------------------------*/ + +#include + +#define TIMED_ACCESS(sfr,value) { TA=0xaa; TA=0x55; sfr=value; } + +signed char _sdcc_external_startup(void) +{ + TI_0 = 1; // init transmitter + +/* copied from tinibios.h */ + + IE=0; // disable ALL interrupts + + // use A19..16 and !CE3..0, no CAN + TIMED_ACCESS(P4CNT,0x3f); + + // use !PCE3..0, serial 1 at P5.2/3 + TIMED_ACCESS(P5CNT,0x27); + + // disable watchdog + EWT=0; + + // watchdog set to 9.1 seconds + // CKCON|=0xc0; + + // default stretch cycles for MOVX + //CKCON = (CKCON&0xf8)|(CPU_MOVX_STRETCH&0x07); + CKCON=0xf9; + + // use internal 4k RAM as data(stack) memory at 0x400000 and + // move CANx memory access to 0x401000 and upwards + // use !CE* for program and/or data memory access + TIMED_ACCESS(MCON,0xaf); + + // select default cpu speed + //CpuSpeed(CPU_SPEED); will hang on s51 + + _asm + ; save the 24-bit return address + pop ar2; msb + pop ar1 + pop ar0; lsb + + + mov _TA,#0xaa; timed access + mov _TA,#0x55 + mov _ACON,#0x06; 24 bit addresses, 10 bit stack at 0x400000 + + mov _ESP,#0x00; reinitialize the stack + mov _SP,#0x00 + + ; restore the 24-bit return address + push ar0; lsb + push ar1 + push ar2; msb + _endasm; + + // global interrupt enable, all masks cleared + // let the Gods be with us :) + // IE = 0x80; + + //Serial0Init(SERIAL_0_BAUD,1); + //Serial1Init(SERIAL_1_BAUD,1); + //ClockInit(); + //RtcInit(); + //WatchDogInit(); + + // signal _sdcc_gsinit_startup to initialize data (call _sdcc_init_data) + return 0; +} + +void +_putchar (char c) +{ + while (!TI_0) + ; + TI_0 = 0; + SBUF0 = c; +} + +void +_exitEmu (void) +{ + * (char idata *) 0 = * (char xdata *) 0x7654; +} diff --git a/support/regression/ports/ds390/uCsim.cmd b/support/regression/ports/ds390/uCsim.cmd new file mode 100644 index 00000000..3ba07510 --- /dev/null +++ b/support/regression/ports/ds390/uCsim.cmd @@ -0,0 +1,3 @@ +break xram r 0x7654 +run +quit diff --git a/support/regression/ports/mcs51/spec.mk b/support/regression/ports/mcs51/spec.mk index 0bed1171..91eb9461 100644 --- a/support/regression/ports/mcs51/spec.mk +++ b/support/regression/ports/mcs51/spec.mk @@ -1,14 +1,16 @@ # Port specification for the mcs51 port running with uCsim +# +# model small # path to uCsim S51 = ../../sim/ucsim/s51.src/s51 -SDCCFLAGS += --lesspedantic -DREENTRANT=reentrant --stack-after-data +SDCCFLAGS +=--lesspedantic -DREENTRANT=reentrant --stack-after-data OBJEXT = .rel EXEEXT = .ihx -EXTRAS = fwk/lib/testfwk$(OBJEXT) ports/$(PORT)/support$(OBJEXT) +EXTRAS = fwk/lib/testfwk$(OBJEXT) $(PORTS_DIR)/$(PORT)/support$(OBJEXT) # Rule to link into .ihx %$(EXEEXT): %$(OBJEXT) $(EXTRAS) @@ -20,16 +22,16 @@ EXTRAS = fwk/lib/testfwk$(OBJEXT) ports/$(PORT)/support$(OBJEXT) $(SDCC) $(SDCCFLAGS) -c $< # run simulator with 5 seconds timeout -%.out: %$(EXEEXT) ports/$(PORT)/timeout +%.out: %$(EXEEXT) fwk/lib/timeout mkdir -p `dirname $@` - -ports/$(PORT)/timeout 5 $(S51) -t32 -S in=/dev/null,out=$@ $< < ports/mcs51/uCsim.cmd >/dev/null || \ - echo -e --- FAIL: \"timeout, simulation killed\" in $(<:.ihx=.c)"\n"--- Summary: 1/1/1: timeout >> $@ + -fwk/lib/timeout 6 $(S51) -t32 -S in=/dev/null,out=$@ $< < $(PORTS_DIR)/mcs51/uCsim.cmd >/dev/null \ + || echo -e --- FAIL: \"timeout, simulation killed\" in $(<:.ihx=.c)"\n"--- Summary: 1/1/1: timeout >> $@ -grep -n FAIL $@ /dev/null || true -ports/$(PORT)/timeout: ports/$(PORT)/timeout.c +fwk/lib/timeout: fwk/lib/timeout.c gcc -o $@ $< _clean: - rm -f ports/$(PORT)/timeout ports/$(PORT)/timeout.exe ports/$(PORT)/*.rel ports/$(PORT)/*.rst \ - ports/$(PORT)/*.lst ports/$(PORT)/*.sym ports/$(PORT)/*.asm temp.lnk + 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 temp.lnk diff --git a/support/regression/ports/z80/spec.mk b/support/regression/ports/z80/spec.mk index b14249d4..312af767 100644 --- a/support/regression/ports/z80/spec.mk +++ b/support/regression/ports/z80/spec.mk @@ -3,7 +3,7 @@ RRZ80 = $(SDCC_EXTRA_DIR)/emu/rrz80/rrz80 -SDCCFLAGS += --lesspedantic --profile -DREENTRANT= +SDCCFLAGS +=-mz80 --lesspedantic --profile -DREENTRANT= EXEEXT = .bin