diff options
| author | Xavier ASUS <xavi92psx@gmail.com> | 2019-10-18 00:31:54 +0200 |
|---|---|---|
| committer | Xavier ASUS <xavi92psx@gmail.com> | 2019-10-18 00:31:54 +0200 |
| commit | 268a53de823a6750d6256ee1fb1e7707b4b45740 (patch) | |
| tree | 42c1799a9a82b2f7d9790ee9fe181d72a7274751 /sim/ucsim/example | |
| download | sdcc-gas-268a53de823a6750d6256ee1fb1e7707b4b45740.tar.gz | |
sdcc-3.9.0 fork implementing GNU assembler syntax
This fork aims to provide better support for stm8-binutils
Diffstat (limited to 'sim/ucsim/example')
| -rw-r--r-- | sim/ucsim/example/Makefile | 21 | ||||
| -rw-r--r-- | sim/ucsim/example/bank0.c | 7 | ||||
| -rw-r--r-- | sim/ucsim/example/bank0.h | 6 | ||||
| -rw-r--r-- | sim/ucsim/example/bank1.c | 7 | ||||
| -rw-r--r-- | sim/ucsim/example/bank1.h | 6 | ||||
| -rw-r--r-- | sim/ucsim/example/banking.c | 87 | ||||
| -rw-r--r-- | sim/ucsim/example/banking.mk | 10 | ||||
| -rw-r--r-- | sim/ucsim/example/banking_conf.cmd | 17 | ||||
| -rw-r--r-- | sim/ucsim/example/conf.cmd | 5 | ||||
| -rw-r--r-- | sim/ucsim/example/run.cmd | 3 | ||||
| -rwxr-xr-x | sim/ucsim/example/run.sh | 25 | ||||
| -rw-r--r-- | sim/ucsim/example/sdcc.mk | 49 | ||||
| -rw-r--r-- | sim/ucsim/example/simif.c | 256 | ||||
| -rw-r--r-- | sim/ucsim/example/simif.mk | 7 | ||||
| -rwxr-xr-x | sim/ucsim/example/simif.sh | 3 | ||||
| -rw-r--r-- | sim/ucsim/example/simif_fin.txt | 2 |
16 files changed, 511 insertions, 0 deletions
diff --git a/sim/ucsim/example/Makefile b/sim/ucsim/example/Makefile new file mode 100644 index 0000000..65019d7 --- /dev/null +++ b/sim/ucsim/example/Makefile @@ -0,0 +1,21 @@ +PRJ = simif banking + +all: + for p in $(PRJ); do \ + $(MAKE) -f $$p.mk; \ + done + +clean: + for p in $(PRJ); do \ + $(MAKE) -f $$p.mk clean; \ + done + +#all: simif.ihx +# +#simif.ihx: simif.c +# sdcc --model-large --debug simif.c +# +#clean: +# rm -f *.asm *.ihx *.lk *.lst *.map *.mem *.rel *.rst *.sym +# rm -f *.adb *.cdb *.omf +# rm -f simif.out simif_fout.txt diff --git a/sim/ucsim/example/bank0.c b/sim/ucsim/example/bank0.c new file mode 100644 index 0000000..ed5af8c --- /dev/null +++ b/sim/ucsim/example/bank0.c @@ -0,0 +1,7 @@ +#pragma codeseg BANK0 + +int +bank0_fn(int x) __banked +{ + return x+2; +} diff --git a/sim/ucsim/example/bank0.h b/sim/ucsim/example/bank0.h new file mode 100644 index 0000000..74c9d5b --- /dev/null +++ b/sim/ucsim/example/bank0.h @@ -0,0 +1,6 @@ +#ifndef BANK0_HEADER +#define BANK0_HEADER + +extern int bank0_fn(int x) __banked; + +#endif diff --git a/sim/ucsim/example/bank1.c b/sim/ucsim/example/bank1.c new file mode 100644 index 0000000..3b21228 --- /dev/null +++ b/sim/ucsim/example/bank1.c @@ -0,0 +1,7 @@ +#pragma codeseg BANK1 + +int +bank1_fn(int x) __banked +{ + return x+3; +} diff --git a/sim/ucsim/example/bank1.h b/sim/ucsim/example/bank1.h new file mode 100644 index 0000000..1296def --- /dev/null +++ b/sim/ucsim/example/bank1.h @@ -0,0 +1,6 @@ +#ifndef BANK1_HEADER +#define BANK1_HEADER + +extern int bank1_fn(int x) __banked; + +#endif diff --git a/sim/ucsim/example/banking.c b/sim/ucsim/example/banking.c new file mode 100644 index 0000000..3ae6264 --- /dev/null +++ b/sim/ucsim/example/banking.c @@ -0,0 +1,87 @@ +#include <mcs51reg.h> +#include <stdio.h> + +#include "bank0.h" +#include "bank1.h" + +__sfr __at(0xB1) PSBANK; // like Silabs F120 + +unsigned char __xdata * volatile sif; + +unsigned char +_sdcc_external_startup (void) +{ + /* copied from device/examples/mcs51/simple2/hi.c */ + PCON = 0x80; /* power control byte, set SMOD bit for serial port */ + SCON = 0x40; /* serial control byte, mode 1, RI _NOT_ active */ + TMOD = 0x21; /* timer control mode, byte operation */ + TCON = 0; /* timer control register, byte operation */ + + TH1 = 0xFA; /* serial reload value, 9,600 baud at 11.0952Mhz */ + TR1 = 1; /* start serial timer */ + + TI = 1; /* enable transmission of first byte */ + return 0; +} + +int +putchar (int c) +{ + while (!TI) + ; + SBUF = c; + TI = 0; + return c; +} + +int +non_banked(int x) +{ + return x+1; +} + +void +main(void) +{ + int i; + + sif= (unsigned char __xdata *)0xffff; + i= 0; + + i= non_banked(i); + printf("i must be 1: %d\n", i); + i= bank0_fn(i); + printf("i must be 3: %d\n", i); + i= bank1_fn(i); + printf("i must be 6: %d\n", i); + + *sif= 's'; + while (1) ; +} + +void +_sdcc_banked_call(void) __naked +{ + __asm + push _PSBANK ;save return bank + xch a,r0 ;save Acc in r0, do not assume any register bank + push acc ;push LSB address + mov a,r1 + push acc ;push MSB address + mov a,r2 ;get new bank + anl a,#0x0F ;remove storage class indicator + anl _PSBANK,#0xF0 + orl _PSBANK,a ;select bank + xch a,r0 ;restore Acc + ret ;make the call + __endasm; +} + +void +_sdcc_banked_ret(void) __naked +{ + __asm + pop _PSBANK ;restore bank + ret ;return to caller + __endasm; +} diff --git a/sim/ucsim/example/banking.mk b/sim/ucsim/example/banking.mk new file mode 100644 index 0000000..3a66cba --- /dev/null +++ b/sim/ucsim/example/banking.mk @@ -0,0 +1,10 @@ + +MAIN = banking + +OTHERS = bank0 bank1 + +include sdcc.mk + +TARGET = -mmcs51 + +LDFLAGS = -Wl-bBANK0=0x18000 -Wl-bBANK1=0x28000 --code-size 0x1000000 -Wl-r diff --git a/sim/ucsim/example/banking_conf.cmd b/sim/ucsim/example/banking_conf.cmd new file mode 100644 index 0000000..9119684 --- /dev/null +++ b/sim/ucsim/example/banking_conf.cmd @@ -0,0 +1,17 @@ +memory create chip bank1_chip 0x8000 8 +memory create chip bank2_chip 0x8000 8 +memory create chip bank3_chip 0x8000 8 + +memory create banker sfr 0xb1 0x03 rom 0x8000 0xffff + +memory create bank rom 0x8000 0 rom_chip 0x8000 +memory create bank rom 0x8000 1 bank1_chip 0 +memory create bank rom 0x8000 2 bank2_chip 0 +memory create bank rom 0x8000 3 bank3_chip 0 + +fill rom_chip 0x8000 0xffff 0 +fill bank1_chip 0 0x7fff 0 +fill bank2_chip 0 0x7fff 0 +fill bank3_chip 0 0x7fff 0 + +set hardware simif xram 0xffff diff --git a/sim/ucsim/example/conf.cmd b/sim/ucsim/example/conf.cmd new file mode 100644 index 0000000..f0c5d3f --- /dev/null +++ b/sim/ucsim/example/conf.cmd @@ -0,0 +1,5 @@ +file "simif.ihx" +set error memory off +set hardware simif xram 0xffff +set hardware simif fout "simif_fout.txt" +set hardware simif fin "simif_fin.txt" diff --git a/sim/ucsim/example/run.cmd b/sim/ucsim/example/run.cmd new file mode 100644 index 0000000..ae16e83 --- /dev/null +++ b/sim/ucsim/example/run.cmd @@ -0,0 +1,3 @@ +run +state +quit diff --git a/sim/ucsim/example/run.sh b/sim/ucsim/example/run.sh new file mode 100755 index 0000000..0e06cc5 --- /dev/null +++ b/sim/ucsim/example/run.sh @@ -0,0 +1,25 @@ +PRJ=$1 + +if [ -z "$PRJ" ]; then + PRJ=simif +fi + +if [ -f ${PRJ}.ihx ]; then + if [ -f ${PRJ}_conf.cmd ]; then + CONF="-C ${PRJ}_conf.cmd" + elif [ -f conf.cmd ]; then + CONF="-C conf.cmd" + else + CONF="" + fi + if [ -f ${PRJ}.type ]; then + TYPE="-t $(cat ${PRJ}.type)" + else + TYPE="-t 52" + fi + CMD="../s51.src/s51 ${TYPE} ${CONF} -Z6666 -S in=/dev/null,out=${PRJ}.out -G ${PRJ}.ihx" + echo $CMD + $CMD + cat ${PRJ}.out + echo +fi diff --git a/sim/ucsim/example/sdcc.mk b/sim/ucsim/example/sdcc.mk new file mode 100644 index 0000000..5df497c --- /dev/null +++ b/sim/ucsim/example/sdcc.mk @@ -0,0 +1,49 @@ +TARGET = -mmcs51 + +MODEL = + +CC = sdcc $(TARGET) $(MODEL) + +CPPFLAGS = +CFLAGS = --debug +LDFLAGS = +LIBS = + +ALL = $(MAIN) $(OTHERS) +OBJECTS = $(MAIN).rel $(OTHERS:=.rel) + +all: $(MAIN).hex + +dep: $(MAIN).dep + +$(MAIN).dep: $(OBJECTS:.rel=.c) *.h + @>$(MAIN).dep + @for c in $(OBJECTS:.rel=.c); do \ + $(CC) -MM $(CPPFALGS) $$c >>$(MAIN).dep ;\ + done + +include $(MAIN).dep + +$(MAIN).ihx: $(OBJECTS) + $(CC) $(CFLAGS) $(LDFLAGS) $(OBJECTS) -o $@ + +.SUFFIXES: .rel .ihx .hex + +.c.rel: + $(CC) -c $(CPPFLAGS) $(CFLAGS) $< + +.asm.rel: + $(CC) -c $(CPPFLAGS) $(CFLAGS) $< + +.ihx.hex: + packihx $< >$@ + +clean: + rm -f $(ALL:=.rel) $(ALL:=.lst) $(ALL:=.asm) $(ALL:=.rst) $(ALL:=.sym) $(ALL:=.adb) + rm -f $(MAIN).ihx $(MAIN).hex $(MAIN).lk $(MAIN).map $(MAIN).mem $(MAIN).cdb $(MAIN).omf $(MAIN).noi + rm -f *~ + rm -f $(MAIN).dep + rm -f $(MAIN).sim $(MAIN).out + + +# End of sdcc.mk diff --git a/sim/ucsim/example/simif.c b/sim/ucsim/example/simif.c new file mode 100644 index 0000000..66d9ebd --- /dev/null +++ b/sim/ucsim/example/simif.c @@ -0,0 +1,256 @@ +#include <mcs51reg.h> +#include <stdio.h> + + +enum sif_command { + DETECT_SIGN = '!', // answer to detect command + SIFCM_DETECT = '_', // command used to detect the interface + SIFCM_COMMANDS = 'i', // get info about commands + SIFCM_IFVER = 'v', // interface version + SIFCM_SIMVER = 'V', // simulator version + SIFCM_IFRESET = '@', // reset the interface + SIFCM_CMDINFO = 'I', // info about a command + SIFCM_CMDHELP = 'h', // help about a command + SIFCM_STOP = 's', // stop simulation + SIFCM_PRINT = 'p', // print character + SIFCM_FIN_CHECK = 'f', // check input file for input + SIFCM_READ = 'r', // read from input file + SIFCM_WRITE = 'w', // write to output file +}; + +enum sif_answer_type { + SIFAT_UNKNOWN = 0x00, // we don't know... + SIFAT_BYTE = 0x01, // just a byte + SIFAT_ARRAY = 0x02, // array of some bytes + SIFAT_STRING = 0x03, // a string + SIFAT_NONE = 0x04 // no answer at all +}; + +unsigned char +_sdcc_external_startup (void) +{ + /* copied from device/examples/mcs51/simple2/hi.c */ + PCON = 0x80; /* power control byte, set SMOD bit for serial port */ + SCON = 0x40; /* serial control byte, mode 1, RI _NOT_ active */ + TMOD = 0x21; /* timer control mode, byte operation */ + TCON = 0; /* timer control register, byte operation */ + + TH1 = 0xFA; /* serial reload value, 9,600 baud at 11.0952Mhz */ + TR1 = 1; /* start serial timer */ + + TI = 1; /* enable transmission of first byte */ + return 0; +} + +int +putchar (int c) +{ + while (!TI) + ; + SBUF = c; + TI = 0; + return c; +} + +#define SIF_ADDRESS_SPACE_NAME "xram" +#define SIF_ADDRESS_SPACE __xdata +#define SIF_ADDRESS 0xffff + +unsigned char SIF_ADDRESS_SPACE * volatile sif; + +char +sif_get(char cmd) +{ + *sif= cmd; + return *sif; +} + +char +simulated(void) +{ + unsigned char c; + *sif= 0x55; + c= *sif; + if (c != (unsigned char)~0x55) + return(0); + *sif= 0xaa; + if (*sif != (unsigned char)~0xaa) + return(0); + return(1); +} + +char +detect(void) +{ + *sif= SIFCM_DETECT; + return *sif == DETECT_SIGN; +} + +int nuof_commands; +unsigned char commands[100]; + +void +get_commands(void) +{ + int i; + *sif= SIFCM_COMMANDS; + nuof_commands= *sif; + for (i= 0; i < nuof_commands; i++) + commands[i]= *sif; +} + +int +get_ifversion(void) +{ + *sif= SIFCM_IFVER; + return(*sif); +} + +unsigned char sim_version[15]; + +void +get_sim_version() +{ + unsigned char c, i, n; + + *sif= SIFCM_SIMVER; + sim_version[0]= 0; + n= *sif; + if (n) + { + i= 0; + c= *sif; + while (c && (i<14)) + { + sim_version[i++]= c; + c= *sif; + } + while (c) + c= *sif; + sim_version[i]= 0; + } +} + +void +print_cmd_infos(void) +{ + int i, j; + unsigned char inf[5]; + for (i= 0; i < nuof_commands; i++) + { + printf("Command '%c' info:\n", commands[i]); + *sif= SIFCM_CMDINFO; + *sif= commands[i]; + inf[0]= *sif; + for (j= 0; j < inf[0]; j++) + { + inf[j+1]= *sif; + //printf(" 0x%02x", inf[j+1]); + } + printf(" need %d params, answers as ", inf[1]); + switch (inf[2]) + { + case SIFAT_UNKNOWN : printf("unknown"); break; + case SIFAT_BYTE : printf("byte"); break; + case SIFAT_ARRAY : printf("array"); break; + case SIFAT_STRING : printf("string"); break; + case SIFAT_NONE : printf("none"); break; + } + printf(": "); + *sif= SIFCM_CMDHELP; + *sif= commands[i]; + if (*sif) + { + j= *sif; + while (j) + { + putchar(j); + j= *sif; + } + } + printf("\n"); + } + +} + +void +sif_putchar(char c) +{ + *sif= SIFCM_PRINT; + *sif= c; +} + +void +sif_print(char *s) +{ + while (*s) + sif_putchar(*s++); +} + +void +fout_demo(char *s) +{ + while (*s) + { + *sif= SIFCM_WRITE; + *sif= *s++; + } +} + +char +sif_fin_avail() +{ + return sif_get(SIFCM_FIN_CHECK); +} + +char +sif_read() +{ + return sif_get(SIFCM_READ); +} + +void +fin_demo() +{ + char i, c; + printf("Reading input from SIMIF input file:\n"); + while (i= sif_fin_avail()) + { + c= sif_read(); + if (c > 31) + putchar(c); + } + printf("\nRead demo finished\n"); +} + +void +main(void) +{ + sif= (unsigned char SIF_ADDRESS_SPACE *) SIF_ADDRESS; + printf("Testing simulator interface at %s[0x%x]\n", + SIF_ADDRESS_SPACE_NAME, SIF_ADDRESS); + printf("%s", detect()?"Interface found.":"Interface not found"); + if (detect()) + { + int i; + i= get_ifversion(); + get_sim_version(); + printf(" Version %d (of simulator %s)\n", i, sim_version); + get_commands(); + printf("Interface knows about %d commands:\n", nuof_commands); + for (i= 0; i < nuof_commands; i++) + printf("%c", commands[i]); + printf("\n"); + print_cmd_infos(); + sif_print("Message from simulated program: Hello World!\n"); + fout_demo("Write this message\n" + "to simif output file.\n" + "\n" + "Done.\n"); + fin_demo(); + } + else + printf("\n"); + //* (char __idata *) 0 = * (char __xdata *) 0x7654; + *sif= SIFCM_STOP; +} diff --git a/sim/ucsim/example/simif.mk b/sim/ucsim/example/simif.mk new file mode 100644 index 0000000..689aae1 --- /dev/null +++ b/sim/ucsim/example/simif.mk @@ -0,0 +1,7 @@ +MAIN = simif + +OTHERS = + +include sdcc.mk + +MODEL = --model-large diff --git a/sim/ucsim/example/simif.sh b/sim/ucsim/example/simif.sh new file mode 100755 index 0000000..0780c6e --- /dev/null +++ b/sim/ucsim/example/simif.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +s516 -S in=/dev/null,out=simif.out -C config.cmd <run.cmd diff --git a/sim/ucsim/example/simif_fin.txt b/sim/ucsim/example/simif_fin.txt new file mode 100644 index 0000000..a00ad3c --- /dev/null +++ b/sim/ucsim/example/simif_fin.txt @@ -0,0 +1,2 @@ +This message comes from +simif input file. |
