summaryrefslogtreecommitdiff
path: root/device/lib/mcs51
diff options
context:
space:
mode:
authorXavier ASUS <xavi92psx@gmail.com>2019-10-18 00:31:54 +0200
committerXavier ASUS <xavi92psx@gmail.com>2019-10-18 00:31:54 +0200
commit268a53de823a6750d6256ee1fb1e7707b4b45740 (patch)
tree42c1799a9a82b2f7d9790ee9fe181d72a7274751 /device/lib/mcs51
downloadsdcc-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 'device/lib/mcs51')
-rw-r--r--device/lib/mcs51/Makefile62
-rw-r--r--device/lib/mcs51/Makefile.in62
-rw-r--r--device/lib/mcs51/README4
-rw-r--r--device/lib/mcs51/crtbank.asm75
-rw-r--r--device/lib/mcs51/crtcall.asm44
-rw-r--r--device/lib/mcs51/crtclear.asm46
-rw-r--r--device/lib/mcs51/crtpagesfr.asm29
-rw-r--r--device/lib/mcs51/crtstart.asm52
-rw-r--r--device/lib/mcs51/crtxclear.asm66
-rw-r--r--device/lib/mcs51/crtxinit.asm97
-rw-r--r--device/lib/mcs51/crtxpop.asm90
-rw-r--r--device/lib/mcs51/crtxpopr0.asm47
-rw-r--r--device/lib/mcs51/crtxpush.asm90
-rw-r--r--device/lib/mcs51/crtxpushr0.asm49
-rw-r--r--device/lib/mcs51/crtxstack.asm58
-rw-r--r--device/lib/mcs51/gptr_cmp.asm86
16 files changed, 957 insertions, 0 deletions
diff --git a/device/lib/mcs51/Makefile b/device/lib/mcs51/Makefile
new file mode 100644
index 0000000..cd35c94
--- /dev/null
+++ b/device/lib/mcs51/Makefile
@@ -0,0 +1,62 @@
+# libc/mcs51 Makefile
+
+
+srcdir = .
+
+top_srcdir = ../../..
+top_builddir = ../../..
+
+LIB_TYPE = RANLIB
+SAS = $(top_builddir)/bin/sdas8051
+SCC = $(top_builddir)/bin/sdcc
+
+# override PORTDIR defined by super (parent) makefile
+override PORTDIR = ../build/$(PORT)
+
+OBJ = crtstart.rel crtxinit.rel crtxclear.rel crtclear.rel \
+ crtpagesfr.rel crtbank.rel crtcall.rel \
+ crtxstack.rel crtxpush.rel crtxpushr0.rel crtxpop.rel crtxpopr0.rel \
+ gptr_cmp.rel
+
+LIB = mcs51.lib
+
+CC = $(SCC)
+AS = $(SAS)
+ASFLAGS = -plosgff
+
+CFLAGS = -I$(top_srcdir)/include --std-c11
+
+all: $(PORTDIR)/$(LIB)
+
+$(PORTDIR)/$(LIB): $(OBJ) Makefile
+ifeq ($(LIB_TYPE), SDCCLIB)
+ rm -f $@; \
+ $(top_builddir)/bin/sdcclib -a $@ $(OBJ)
+else
+ ifeq ($(LIB_TYPE), AR)
+ $(top_builddir)/bin/sdar -rcSD $@ $(OBJ)
+ else
+ ifeq ($(LIB_TYPE), RANLIB)
+ $(top_builddir)/bin/sdar -rcD $@ $(OBJ)
+ else
+ rm -f $@
+ for i in $(basename $(OBJ)); do echo $$i >>$@; done
+ cp $(OBJ) $(PORTDIR)
+ endif
+ endif
+endif
+
+%.rel: %.c
+ $(CC) $(CFLAGS) -c $<
+
+%.rel: %.asm
+ @# TODO: asx8051 should place it\'s output in the current dir
+ test $(srcdir) = . || cp $< .
+ -$(AS) $(ASFLAGS) $(notdir $<)
+ test $(srcdir) = . || rm $(notdir $<)
+
+clean:
+ rm -f *.rel *.sym *.lst *~ $(CLEANSPEC) *.dump* *.lib
+
+distclean: clean
+ rm -r Makefile
diff --git a/device/lib/mcs51/Makefile.in b/device/lib/mcs51/Makefile.in
new file mode 100644
index 0000000..99101ae
--- /dev/null
+++ b/device/lib/mcs51/Makefile.in
@@ -0,0 +1,62 @@
+# libc/mcs51 Makefile
+
+VPATH = @srcdir@
+srcdir = @srcdir@
+
+top_srcdir = @top_srcdir@
+top_builddir = @top_builddir@
+
+LIB_TYPE = @LIB_TYPE@
+SAS = $(top_builddir)/bin/sdas8051
+SCC = $(top_builddir)/bin/sdcc
+
+# override PORTDIR defined by super (parent) makefile
+override PORTDIR = ../build/$(PORT)
+
+OBJ = crtstart.rel crtxinit.rel crtxclear.rel crtclear.rel \
+ crtpagesfr.rel crtbank.rel crtcall.rel \
+ crtxstack.rel crtxpush.rel crtxpushr0.rel crtxpop.rel crtxpopr0.rel \
+ gptr_cmp.rel
+
+LIB = mcs51.lib
+
+CC = $(SCC)
+AS = $(SAS)
+ASFLAGS = -plosgff
+
+CFLAGS = -I$(top_srcdir)/include --std-c11
+
+all: $(PORTDIR)/$(LIB)
+
+$(PORTDIR)/$(LIB): $(OBJ) Makefile
+ifeq ($(LIB_TYPE), SDCCLIB)
+ rm -f $@; \
+ $(top_builddir)/bin/sdcclib -a $@ $(OBJ)
+else
+ ifeq ($(LIB_TYPE), AR)
+ $(top_builddir)/bin/sdar -rcSD $@ $(OBJ)
+ else
+ ifeq ($(LIB_TYPE), RANLIB)
+ $(top_builddir)/bin/sdar -rcD $@ $(OBJ)
+ else
+ rm -f $@
+ for i in $(basename $(OBJ)); do echo $$i >>$@; done
+ cp $(OBJ) $(PORTDIR)
+ endif
+ endif
+endif
+
+%.rel: %.c
+ $(CC) $(CFLAGS) -c $<
+
+%.rel: %.asm
+ @# TODO: asx8051 should place it\'s output in the current dir
+ test $(srcdir) = . || cp $< .
+ -$(AS) $(ASFLAGS) $(notdir $<)
+ test $(srcdir) = . || rm $(notdir $<)
+
+clean:
+ rm -f *.rel *.sym *.lst *~ $(CLEANSPEC) *.dump* *.lib
+
+distclean: clean
+ rm -r Makefile
diff --git a/device/lib/mcs51/README b/device/lib/mcs51/README
new file mode 100644
index 0000000..84adfe2
--- /dev/null
+++ b/device/lib/mcs51/README
@@ -0,0 +1,4 @@
+sdcc/device/lib/mcs51
+-------------------
+
+mcs51 specific routines.
diff --git a/device/lib/mcs51/crtbank.asm b/device/lib/mcs51/crtbank.asm
new file mode 100644
index 0000000..a6a03cb
--- /dev/null
+++ b/device/lib/mcs51/crtbank.asm
@@ -0,0 +1,75 @@
+;--------------------------------------------------------------------------
+; crtbank.asm - C run-time: bank switching
+;
+; Copyright (C) 2005, Maarten Brock
+;
+; This library 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 library 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 library; see the file COPYING. If not, write to the
+; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+; MA 02110-1301, USA.
+;
+; As a special exception, if you link this library with other files,
+; some of which are compiled with SDCC, to produce an executable,
+; this library does not by itself cause the resulting executable to
+; be covered by the GNU General Public License. This exception does
+; not however invalidate any other reasons why the executable file
+; might be covered by the GNU General Public License.
+;--------------------------------------------------------------------------
+
+
+ .area HOME (CODE)
+ .area GSINIT0 (CODE)
+ .area GSINIT1 (CODE)
+ .area GSINIT2 (CODE)
+ .area GSINIT3 (CODE)
+ .area GSINIT4 (CODE)
+ .area GSINIT5 (CODE)
+ .area GSINIT (CODE)
+ .area GSFINAL (CODE)
+ .area CSEG (CODE)
+
+; /*-------------------------------------------------------------------------
+; Example for SiLabs C8051F12x / C8051F13x with 128kB code memory
+; divided into 4 banks of 32kB
+; These devices have an sfr called PSBANK containing two parts:
+; COBANK (bit 5:4): Constant Operations Bank
+; IFBANK (bit 1:0): Instruction Fetch Bank
+; From 0x0000 to 0x7FFF bank 0 is always accessed
+; From 0x8000 to 0xFFFF bank COBANK is accessed for reading with movc
+; From 0x8000 to 0xFFFF bank IFBANK is accessed for executing instructions
+;
+; Make your own copy of this file,
+; adapt it to your situation,
+; and compile/link it in your project
+; -------------------------------------------------------------------------*/
+
+ .globl _PSBANK
+
+ .area HOME (CODE)
+
+__sdcc_banked_call::
+ 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
+
+__sdcc_banked_ret::
+ pop _PSBANK ;restore bank
+ ret ;return to caller
diff --git a/device/lib/mcs51/crtcall.asm b/device/lib/mcs51/crtcall.asm
new file mode 100644
index 0000000..3b298ab
--- /dev/null
+++ b/device/lib/mcs51/crtcall.asm
@@ -0,0 +1,44 @@
+;--------------------------------------------------------------------------
+; crtcall.asm - C run-time: indirect function call
+;
+; Copyright (C) 2007, Maarten Brock
+;
+; This library 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 library 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 library; see the file COPYING. If not, write to the
+; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+; MA 02110-1301, USA.
+;
+; As a special exception, if you link this library with other files,
+; some of which are compiled with SDCC, to produce an executable,
+; this library does not by itself cause the resulting executable to
+; be covered by the GNU General Public License. This exception does
+; not however invalidate any other reasons why the executable file
+; might be covered by the GNU General Public License.
+;--------------------------------------------------------------------------
+
+ .area HOME (CODE)
+ .area GSINIT0 (CODE)
+ .area GSINIT1 (CODE)
+ .area GSINIT2 (CODE)
+ .area GSINIT3 (CODE)
+ .area GSINIT4 (CODE)
+ .area GSINIT5 (CODE)
+ .area GSINIT (CODE)
+ .area GSFINAL (CODE)
+ .area CSEG (CODE)
+
+ .area HOME (CODE)
+
+__sdcc_call_dptr::
+ clr a
+ jmp @a+dptr
diff --git a/device/lib/mcs51/crtclear.asm b/device/lib/mcs51/crtclear.asm
new file mode 100644
index 0000000..afd18e0
--- /dev/null
+++ b/device/lib/mcs51/crtclear.asm
@@ -0,0 +1,46 @@
+;--------------------------------------------------------------------------
+; crtclear.asm - C run-time: clear DATA/IDATA
+;
+; Copyright (C) 2004, Erik Petrich
+;
+; This library 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 library 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 library; see the file COPYING. If not, write to the
+; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+; MA 02110-1301, USA.
+;
+; As a special exception, if you link this library with other files,
+; some of which are compiled with SDCC, to produce an executable,
+; this library does not by itself cause the resulting executable to
+; be covered by the GNU General Public License. This exception does
+; not however invalidate any other reasons why the executable file
+; might be covered by the GNU General Public License.
+;--------------------------------------------------------------------------
+
+ .area CSEG (CODE)
+ .area GSINIT0 (CODE)
+ .area GSINIT1 (CODE)
+ .area GSINIT2 (CODE)
+ .area GSINIT3 (CODE)
+ .area GSINIT4 (CODE)
+ .area GSINIT5 (CODE)
+ .area GSINIT (CODE)
+ .area GSFINAL (CODE)
+
+ .area GSINIT4 (CODE)
+
+__mcs51_genRAMCLEAR::
+ clr a
+ mov r0,#(l_IRAM-1) ; mov r0,a will do for most devices
+00004$: mov @r0,a
+ djnz r0,00004$
+; _mcs51_genRAMCLEAR() end
diff --git a/device/lib/mcs51/crtpagesfr.asm b/device/lib/mcs51/crtpagesfr.asm
new file mode 100644
index 0000000..72b64fa
--- /dev/null
+++ b/device/lib/mcs51/crtpagesfr.asm
@@ -0,0 +1,29 @@
+;--------------------------------------------------------------------------
+; crtpagesfr.asm - C run-time: define page sfr for movx @r0/r1 instructions
+;
+; Copyright (C) 2004, Erik Petrich
+;
+; This library 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 library 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 library; see the file COPYING. If not, write to the
+; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+; MA 02110-1301, USA.
+;
+; As a special exception, if you link this library with other files,
+; some of which are compiled with SDCC, to produce an executable,
+; this library does not by itself cause the resulting executable to
+; be covered by the GNU General Public License. This exception does
+; not however invalidate any other reasons why the executable file
+; might be covered by the GNU General Public License.
+;--------------------------------------------------------------------------
+
+__XPAGE == 0xa0 ; 0xa0 is P2 on the original 8051
diff --git a/device/lib/mcs51/crtstart.asm b/device/lib/mcs51/crtstart.asm
new file mode 100644
index 0000000..2d82fc6
--- /dev/null
+++ b/device/lib/mcs51/crtstart.asm
@@ -0,0 +1,52 @@
+;--------------------------------------------------------------------------
+; crtstart.asm - C run-time: startup
+;
+; Copyright (C) 2004, Erik Petrich
+;
+; This library 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 library 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 library; see the file COPYING. If not, write to the
+; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+; MA 02110-1301, USA.
+;
+; As a special exception, if you link this library with other files,
+; some of which are compiled with SDCC, to produce an executable,
+; this library does not by itself cause the resulting executable to
+; be covered by the GNU General Public License. This exception does
+; not however invalidate any other reasons why the executable file
+; might be covered by the GNU General Public License.
+;--------------------------------------------------------------------------
+
+ .area CSEG (CODE)
+ .area GSINIT0 (CODE)
+ .area GSINIT1 (CODE)
+ .area GSINIT2 (CODE)
+ .area GSINIT3 (CODE)
+ .area GSINIT4 (CODE)
+ .area GSINIT5 (CODE)
+ .area GSINIT (CODE)
+ .area GSFINAL (CODE)
+
+ .globl __start__stack
+
+ .area GSINIT0 (CODE)
+
+__sdcc_gsinit_startup::
+ mov sp,#__start__stack - 1
+
+ .area GSINIT2 (CODE)
+
+ lcall __sdcc_external_startup
+ mov a,dpl
+ jz __sdcc_init_data
+ ljmp __sdcc_program_startup
+__sdcc_init_data:
diff --git a/device/lib/mcs51/crtxclear.asm b/device/lib/mcs51/crtxclear.asm
new file mode 100644
index 0000000..93b95cf
--- /dev/null
+++ b/device/lib/mcs51/crtxclear.asm
@@ -0,0 +1,66 @@
+;--------------------------------------------------------------------------
+; crtxclear.asm - C run-time: clear XSEG
+;
+; Copyright (C) 2004, Erik Petrich
+;
+; This library 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 library 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 library; see the file COPYING. If not, write to the
+; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+; MA 02110-1301, USA.
+;
+; As a special exception, if you link this library with other files,
+; some of which are compiled with SDCC, to produce an executable,
+; this library does not by itself cause the resulting executable to
+; be covered by the GNU General Public License. This exception does
+; not however invalidate any other reasons why the executable file
+; might be covered by the GNU General Public License.
+;--------------------------------------------------------------------------
+
+ .area CSEG (CODE)
+ .area GSINIT0 (CODE)
+ .area GSINIT1 (CODE)
+ .area GSINIT2 (CODE)
+ .area GSINIT3 (CODE)
+ .area GSINIT4 (CODE)
+ .area GSINIT5 (CODE)
+ .area GSINIT (CODE)
+ .area GSFINAL (CODE)
+
+ .area GSINIT4 (CODE)
+
+__mcs51_genXRAMCLEAR::
+ mov r0,#l_PSEG
+ mov a,r0
+ orl a,#(l_PSEG >> 8)
+ jz 00006$
+ mov r1,#s_PSEG
+ mov __XPAGE,#(s_PSEG >> 8)
+ clr a
+00005$: movx @r1,a
+ inc r1
+ djnz r0,00005$
+
+00006$:
+ mov r0,#l_XSEG
+ mov a,r0
+ orl a,#(l_XSEG >> 8)
+ jz 00008$
+ mov r1,#((l_XSEG + 255) >> 8)
+ mov dptr,#s_XSEG
+ clr a
+00007$: movx @dptr,a
+ inc dptr
+ djnz r0,00007$
+ djnz r1,00007$
+00008$:
+
diff --git a/device/lib/mcs51/crtxinit.asm b/device/lib/mcs51/crtxinit.asm
new file mode 100644
index 0000000..057d91e
--- /dev/null
+++ b/device/lib/mcs51/crtxinit.asm
@@ -0,0 +1,97 @@
+;--------------------------------------------------------------------------
+; crtxinit.asm :- C run-time: copy XINIT to XISEG
+;
+; Copyright (C) 2004, Erik Petrich
+;
+; This library 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 library 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 library; see the file COPYING. If not, write to the
+; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+; MA 02110-1301, USA.
+;
+; As a special exception, if you link this library with other files,
+; some of which are compiled with SDCC, to produce an executable,
+; this library does not by itself cause the resulting executable to
+; be covered by the GNU General Public License. This exception does
+; not however invalidate any other reasons why the executable file
+; might be covered by the GNU General Public License.
+;--------------------------------------------------------------------------
+
+; Set DUAL_DPTR to 1 and reassemble if your derivative has dual data pointers
+; Especially useful if movx @Ri cannot go beyond the first 256 bytes of xdata
+; due to lack of P2 or _XPAGE
+; If the derivative has auto-toggle or auto-increment it can be further optimized
+ DUAL_DPTR = 0
+
+ .area CSEG (CODE)
+ .area GSINIT0 (CODE)
+ .area GSINIT1 (CODE)
+ .area GSINIT2 (CODE)
+ .area GSINIT3 (CODE)
+ .area GSINIT4 (CODE)
+ .area GSINIT5 (CODE)
+ .area GSINIT (CODE)
+ .area GSFINAL (CODE)
+
+ .area GSINIT3 (CODE)
+
+ .if DUAL_DPTR
+
+ .globl _DPS ; assume DPSEL is in DPS bit0
+
+__mcs51_genXINIT::
+ mov r1,#l_XINIT
+ mov a,r1
+ orl a,#(l_XINIT >> 8)
+ jz 00003$
+ mov r2,#((l_XINIT+255) >> 8)
+ orl _DPS,#0x01 ; set DPSEL, select DPTR1
+ mov dptr,#s_XINIT ; DPTR1 for code
+ dec _DPS ; clear DPSEL, select DPTR0
+ mov dptr,#s_XISEG ; DPTR0 for xdata
+00001$: clr a
+ inc _DPS ; set DPSEL, select DPTR1
+ movc a,@a+dptr
+ inc dptr
+ dec _DPS ; clear DPSEL, select DPTR0
+ movx @dptr,a
+ inc dptr
+ djnz r1,00001$
+ djnz r2,00001$
+00003$:
+
+ .else
+
+ .globl __XPAGE
+
+__mcs51_genXINIT::
+ mov r1,#l_XINIT
+ mov a,r1
+ orl a,#(l_XINIT >> 8)
+ jz 00003$
+ mov r2,#((l_XINIT+255) >> 8)
+ mov dptr,#s_XINIT
+ mov r0,#s_XISEG
+ mov __XPAGE,#(s_XISEG >> 8)
+00001$: clr a
+ movc a,@a+dptr
+ movx @r0,a
+ inc dptr
+ inc r0
+ cjne r0,#0,00002$
+ inc __XPAGE
+00002$: djnz r1,00001$
+ djnz r2,00001$
+ mov __XPAGE,#0xFF
+00003$:
+
+ .endif
diff --git a/device/lib/mcs51/crtxpop.asm b/device/lib/mcs51/crtxpop.asm
new file mode 100644
index 0000000..f0d3e24
--- /dev/null
+++ b/device/lib/mcs51/crtxpop.asm
@@ -0,0 +1,90 @@
+;--------------------------------------------------------------------------
+; crtxpop.asm - C run-time: pop registers (not bits) from xstack
+;
+; Copyright (C) 2009, Maarten Brock
+;
+; This library 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 library 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 library; see the file COPYING. If not, write to the
+; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+; MA 02110-1301, USA.
+;
+; As a special exception, if you link this library with other files,
+; some of which are compiled with SDCC, to produce an executable,
+; this library does not by itself cause the resulting executable to
+; be covered by the GNU General Public License. This exception does
+; not however invalidate any other reasons why the executable file
+; might be covered by the GNU General Public License.
+;--------------------------------------------------------------------------
+
+;--------------------------------------------------------
+; overlayable bit register bank
+;--------------------------------------------------------
+ .area BIT_BANK (REL,OVR,DATA)
+bits:
+ .ds 1
+
+ ar0 = 0x00
+ ar1 = 0x01
+
+ .area HOME (CODE)
+
+; Pop registers r1..r7 & bits from xstack
+; Expect mask in B
+___sdcc_xpop_regs::
+ mov a,r0
+ mov r0,_spx
+___sdcc_xpop::
+ push acc
+ jbc B.0,00100$ ;if B(0)=0 then
+ dec r0
+ movx a,@r0 ;pop bits
+ mov bits,a
+00100$:
+ jbc B.1,00101$ ;if B(1)=0 then
+ dec r0
+ movx a,@r0 ;pop R1
+ mov r1,a
+00101$:
+ jbc B.2,00102$ ;if B(2)=0 then
+ dec r0
+ movx a,@r0 ;pop R2
+ mov r2,a
+00102$:
+ jbc B.3,00103$ ;if B(3)=0 then
+ dec r0
+ movx a,@r0 ;pop R3
+ mov r3,a
+00103$:
+ jbc B.4,00104$ ;if B(4)=0 then
+ dec r0
+ movx a,@r0 ;pop R4
+ mov r4,a
+00104$:
+ jbc B.5,00105$ ;if B(5)=0 then
+ dec r0
+ movx a,@r0 ;pop R5
+ mov r5,a
+00105$:
+ jbc B.6,00106$ ;if B(6)=0 then
+ dec r0
+ movx a,@r0 ;pop R6
+ mov r6,a
+00106$:
+ jbc B.7,00107$ ;if B(7)=0 then
+ dec r0
+ movx a,@r0 ;pop R7
+ mov r7,a
+00107$:
+ mov _spx,r0
+ pop ar0
+ ret
diff --git a/device/lib/mcs51/crtxpopr0.asm b/device/lib/mcs51/crtxpopr0.asm
new file mode 100644
index 0000000..53019dd
--- /dev/null
+++ b/device/lib/mcs51/crtxpopr0.asm
@@ -0,0 +1,47 @@
+;--------------------------------------------------------------------------
+; crtxpopbits.asm - C run-time: pop bits and other registers from xstack
+;
+; Copyright (C) 2009, Maarten Brock
+;
+; This library 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 library 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 library; see the file COPYING. If not, write to the
+; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+; MA 02110-1301, USA.
+;
+; As a special exception, if you link this library with other files,
+; some of which are compiled with SDCC, to produce an executable,
+; this library does not by itself cause the resulting executable to
+; be covered by the GNU General Public License. This exception does
+; not however invalidate any other reasons why the executable file
+; might be covered by the GNU General Public License.
+;--------------------------------------------------------------------------
+
+;--------------------------------------------------------
+; overlayable bit register bank
+;--------------------------------------------------------
+ .area BIT_BANK (REL,OVR,DATA)
+bits:
+ .ds 1
+
+ ar0 = 0x00
+ ar1 = 0x01
+
+ .area HOME (CODE)
+
+; Pop registers r0..r7 & bits from xstack (r0 always)
+; Expect mask in B
+___sdcc_xpop_regs_r0::
+ mov r0,_spx
+ dec r0
+ movx a,@r0 ;pop R0
+ ljmp ___sdcc_xpop
diff --git a/device/lib/mcs51/crtxpush.asm b/device/lib/mcs51/crtxpush.asm
new file mode 100644
index 0000000..854f747
--- /dev/null
+++ b/device/lib/mcs51/crtxpush.asm
@@ -0,0 +1,90 @@
+;--------------------------------------------------------------------------
+; crtxpush.asm :- C run-time: push registers (not R0) to xstack
+;
+; Copyright (C) 2009, Maarten Brock
+;
+; This library 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 library 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 library; see the file COPYING. If not, write to the
+; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+; MA 02110-1301, USA.
+;
+; As a special exception, if you link this library with other files,
+; some of which are compiled with SDCC, to produce an executable,
+; this library does not by itself cause the resulting executable to
+; be covered by the GNU General Public License. This exception does
+; not however invalidate any other reasons why the executable file
+; might be covered by the GNU General Public License.
+;--------------------------------------------------------------------------
+
+;--------------------------------------------------------
+; overlayable bit register bank
+;--------------------------------------------------------
+ .area BIT_BANK (REL,OVR,DATA)
+bits:
+ .ds 1
+
+ ar0 = 0x00
+ ar1 = 0x01
+
+ .area HOME (CODE)
+
+; Push registers r1..r7 & bits on xstack
+; Expect allocation size in ACC and mask in B
+___sdcc_xpush_regs::
+ add a,_spx
+ mov _spx,a
+ xch a,r0
+___sdcc_xpush::
+ push acc
+ jbc B.0,00100$ ;if B(0)=0 then
+ mov a,bits ;push bits
+ dec r0
+ movx @r0,a
+00100$:
+ jbc B.1,00101$ ;if B(1)=0 then
+ mov a,r1 ;push R1
+ dec r0
+ movx @r0,a
+00101$:
+ jbc B.2,00102$ ;if B(2)=0 then
+ mov a,r2 ;push R2
+ dec r0
+ movx @r0,a
+00102$:
+ jbc B.3,00103$ ;if B(3)=0 then
+ mov a,r3 ;push R3
+ dec r0
+ movx @r0,a
+00103$:
+ jbc B.4,00104$ ;if B(4)=0 then
+ mov a,r4 ;push R4
+ dec r0
+ movx @r0,a
+00104$:
+ jbc B.5,00105$ ;if B(5)=0 then
+ mov a,r5 ;push R5
+ dec r0
+ movx @r0,a
+00105$:
+ jbc B.6,00106$ ;if B(6)=0 then
+ mov a,r6 ;push R6
+ dec r0
+ movx @r0,a
+00106$:
+ jbc B.7,00107$ ;if B(7)=0 then
+ mov a,r7 ;push R7
+ dec r0
+ movx @r0,a
+00107$:
+ pop ar0
+ ret
diff --git a/device/lib/mcs51/crtxpushr0.asm b/device/lib/mcs51/crtxpushr0.asm
new file mode 100644
index 0000000..3abc083
--- /dev/null
+++ b/device/lib/mcs51/crtxpushr0.asm
@@ -0,0 +1,49 @@
+;--------------------------------------------------------------------------
+; crtxpush0.asm - C run-time: push R0 and other registers to xstack
+;
+; Copyright (C) 2009, Maarten Brock
+;
+; This library 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 library 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 library; see the file COPYING. If not, write to the
+; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+; MA 02110-1301, USA.
+;
+; As a special exception, if you link this library with other files,
+; some of which are compiled with SDCC, to produce an executable,
+; this library does not by itself cause the resulting executable to
+; be covered by the GNU General Public License. This exception does
+; not however invalidate any other reasons why the executable file
+; might be covered by the GNU General Public License.
+;--------------------------------------------------------------------------
+
+;--------------------------------------------------------
+; overlayable bit register bank
+;--------------------------------------------------------
+ .area BIT_BANK (REL,OVR,DATA)
+bits:
+ .ds 1
+
+ ar0 = 0x00
+ ar1 = 0x01
+
+ .area HOME (CODE)
+
+; Push registers r0..r7 & bits on xstack (r0 always)
+; Expect allocation size in ACC and mask in B
+___sdcc_xpush_regs_r0::
+ add a,_spx
+ mov _spx,a
+ xch a,r0 ;push R0
+ dec r0
+ movx @r0,a
+ ljmp ___sdcc_xpush
diff --git a/device/lib/mcs51/crtxstack.asm b/device/lib/mcs51/crtxstack.asm
new file mode 100644
index 0000000..a74178e
--- /dev/null
+++ b/device/lib/mcs51/crtxstack.asm
@@ -0,0 +1,58 @@
+;--------------------------------------------------------------------------
+; crtxstack.asm - C run-time: setup xstack
+;
+; Copyright (C) 2004, Erik Petrich
+;
+; This library 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 library 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 library; see the file COPYING. If not, write to the
+; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+; MA 02110-1301, USA.
+;
+; As a special exception, if you link this library with other files,
+; some of which are compiled with SDCC, to produce an executable,
+; this library does not by itself cause the resulting executable to
+; be covered by the GNU General Public License. This exception does
+; not however invalidate any other reasons why the executable file
+; might be covered by the GNU General Public License.
+;--------------------------------------------------------------------------
+
+ .area CSEG (CODE)
+ .area GSINIT0 (CODE)
+ .area GSINIT1 (CODE)
+ .area GSINIT2 (CODE)
+ .area GSINIT3 (CODE)
+ .area GSINIT4 (CODE)
+ .area GSINIT5 (CODE)
+ .area GSINIT (CODE)
+ .area GSFINAL (CODE)
+
+ .globl __start__xstack
+ .globl __XPAGE
+
+ .area GSINIT1 (CODE)
+
+__sdcc_init_xstack::
+
+; Need to initialize in GSINIT1 in case the user's __sdcc_external_startup
+; uses the xstack.
+
+ mov __XPAGE,#(__start__xstack >> 8)
+ mov _spx,#__start__xstack
+
+ .area GSINIT5 (CODE)
+
+; Need to initialize in GSINIT5 because __mcs51_genXINIT modifies __XPAGE
+; and __mcs51_genRAMCLEAR modifies _spx.
+
+ mov __XPAGE,#(__start__xstack >> 8)
+ mov _spx,#__start__xstack
diff --git a/device/lib/mcs51/gptr_cmp.asm b/device/lib/mcs51/gptr_cmp.asm
new file mode 100644
index 0000000..90e621a
--- /dev/null
+++ b/device/lib/mcs51/gptr_cmp.asm
@@ -0,0 +1,86 @@
+;--------------------------------------------------------------------------
+; gptr_cmp.asm - C run-time: compare two generic pointers
+;
+; Copyright (C) 2011, Maarten Brock
+;
+; This library 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 library 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 library; see the file COPYING. If not, write to the
+; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+; MA 02110-1301, USA.
+;
+; As a special exception, if you link this library with other files,
+; some of which are compiled with SDCC, to produce an executable,
+; this library does not by itself cause the resulting executable to
+; be covered by the GNU General Public License. This exception does
+; not however invalidate any other reasons why the executable file
+; might be covered by the GNU General Public License.
+;--------------------------------------------------------------------------
+
+ .area HOME (CODE)
+ .area GSINIT0 (CODE)
+ .area GSINIT1 (CODE)
+ .area GSINIT2 (CODE)
+ .area GSINIT3 (CODE)
+ .area GSINIT4 (CODE)
+ .area GSINIT5 (CODE)
+ .area GSINIT (CODE)
+ .area GSFINAL (CODE)
+ .area CSEG (CODE)
+
+ .area HOME (CODE)
+
+; compares two generic pointers.
+; if p1 < p2 return NZ and C
+; if p1 == p2 return Z and NC
+; if p1 > p2 return NZ and NC
+; if both are a NULL pointer (yes, we have several) also return Z and NC
+; assumes that banks never map to address 0x0000
+; so it suffices to check dptr part only and ignore b
+
+___gptr_cmp::
+ mov a,sp
+ add a,#0xfc
+ clr c
+ xch a,r0
+ push acc
+ push dpl
+ mov a,@r0
+ inc r0
+ orl a,@r0
+ jnz 00001$
+ mov a,dpl
+ orl a,dph
+; if both are NULL, return Z and NC
+ jz 00002$
+00001$:
+ dec r0
+ mov a,dpl
+ subb a,@r0
+ mov dpl,a
+ inc r0
+ mov a,dph
+ subb a,@r0
+ orl dpl,a
+ inc r0
+ mov a,b
+ subb a,@r0
+ orl a,dpl
+; p2 < p1, return NZ and C
+; p2 = p1, return Z and NC
+; p2 > p1, return NZ and NC
+00002$:
+ pop dpl
+ xch a,r0
+ pop acc
+ xch a,r0
+ ret