+2004-11-24 Vangelis Rokas <vrokas AT otenet.gr>
+
+ Large cummulative patch for pic16 port.
+ * device/lib/pic16/gstack.h: NEW, user can specify its own handler
+ to call when a stack overflow occurs,
+ * (malloc.h): added CVS Id tag,
+ * (pic18f{242,252,442,452}.h): added T0CONbits structure and
+ variable,
+ * added libc directory. The current version of LibC contains string
+ functions, ctype functions and macros and some functions of the
+ stdlib set (like malloc/free/atof/atoi etc...). All functions are to
+ be extensively tested in the future. Standard disclaimer here.
+ Library is not automatically build yet. But one can build it by
+ invoking 'make' inside the libc directory.
+ * added ADC library under libio. Preliminary version yet.
+
+ * src/pic16/gen.h: added emitTOGC macro, to toggle Carry flag,
+ * src/pic16/gen.c (aopForRemat): asmop size is filled by
+ aopForRemat() now and not by pic16_aopOp(),
+ * (pic16_popGetTempReg): removed warning messgae when allocating
+ temporary registers, its a buggy feature and will be removed,
+ * (pic16_popGet): set register instance field in AOP_CRY,
+ * (pic16_outBitC): fixed for results in size greater than 1,
+ * (genUminusFloat): fixed for pic16, ported code from mcs51,
+ * (pic16_storeForReturn): optimized return of 0,
+ * (genCmp): experimental code for new genCmp which uses PIC18's
+ special compare&skip instructions. Initial tests fail some times
+ with variables grater than 1 byte in size, so new code is disabled,
+ * (genUnpackBits, genPackBits): more optimizations in reading/writing,
+ a single bit,
+ * (genCast): began a fix to optimize the casting of a bit to another
+ bit, now assigning a bitfield to another bitfield will fail, sorry,
+ * src/pic16/main.c: disabled the use of lr-support feature,
+ * src/pic16/pcode.h: renamed PCASMDIR to PCAD,
+ * added some function prototypes, added function _debugf prototype,
+ * src/pic16/pcode.c: (pic16_get_op): fixed emitting operands of register
+ bits with offset (case PO_GPR_BIT),
+ * (genericPrint): don't emit INFO pcode when --pcode-verbose not in
+ command line,
+ * (isBankInstruction): modified to return 0 for no banking instruction,
+ and 1 for banking instruction,
+ * (pic16_isPCinFlow): check for PCAD (assembler directives) too,
+ caused stop processing pCodes after a inline assembly block,
+ * (pic16_popCopyGPR2Bit): updated to match bitfields with offset,
+ * src/pic16/pcoderegs.c: fixed a bug with eliminating some temporary
+ registers when it shouldn't,
+ * src/pic16/ralloc.c (allocReg): add preliminary support for
+ supporting a limited set of temporary registers,
+
2004-11-23 Erik Petrich <epetrich AT ivorytower.norman.ok.us>
* src/hc08/gen.c (genAssign, genPointerGetSetOfs, genDataPointerGet,
--- /dev/null
+
+/*
+ * A/D conversion module library header
+ *
+ * Devices implemented:
+ * PIC18F[24][45][28]
+ *
+ */
+
+/*
+** $Id$
+*/
+
+#ifndef __ADC_H__
+#define __ADC_H__
+
+
+/* interrupt on/off flag */
+#define ADC_INT_OFF 0x00
+#define ADC_INT_ON 0x01
+
+
+/* output format */
+#define ADC_FRM_RJUST 0x80
+#define ADC_FRM_LJUST 0x00
+
+/* oscillator frequency */
+#define ADC_FOSC_2 0x00
+#define ADC_FOSC_4 0x10
+#define ADC_FOSC_16 0x11
+#define ADC_FOSC_32 0x02
+#define ADC_FOSC_64 0x12
+#define ADC_FOSC_RC 0x03
+
+
+/* channel selection */
+#define ADC_CHN_1 0x00
+#define ADC_CHN_2 0x01
+#define ADC_CHN_3 0x03
+#define ADC_CHN_4 0x04
+#define ADC_CHN_5 0x05
+#define ADC_CHN_6 0x06
+#define ADC_CHN_7 0x07
+
+
+/* reference and pin configuration */
+#define ADC_CFG_8A_0R 0x00
+#define ADC_CFG_7A_1R 0x01
+#define ADC_CFG_5A_0R 0x02
+#define ADC_CFG_4A_1R 0x03
+#define ADC_CFG_3A_0R 0x04
+#define ADC_CFG_2A_1R 0x05
+#define ADC_CFG_0A_0R 0x06
+#define ADC_CFG_6A_2R 0x08
+#define ADC_CFG_6A_0R 0x09
+#define ADC_CFG_5A_1R 0x0a
+#define ADC_CFG_4A_2R 0x0b
+#define ADC_CFG_3A_2R 0x0c
+#define ADC_CFG_2A_2R 0x0d
+#define ADC_CFG_1A_0R 0x0e
+#define ADC_CFG_1A_2R 0x0f
+
+
+void adc_open(unsigned char channel, unsigned char fosc, unsigned char pcfg, unsigned char config);
+
+void adc_close(void);
+
+void adc_conv(void);
+
+char adc_busy(void);
+
+int adc_read(void);
+
+void adc_setchannel(unsigned char channel);
+
+#endif
--- /dev/null
+/*-------------------------------------------------------------------------
+
+ gstack.h :- debug stack tracing header
+
+ Written for pic16 port by Vangelis Rokas, 2004 (vrokas@otenet.gr)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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!
+-------------------------------------------------------------------------*/
+/*
+** $Id$
+*/
+
+#ifndef __PIC16_GSTACK_H__
+#define __PIC16_GSTACK_H__
+
+extern void (* _gstack_overflow_handler)(void);
+
+#endif /* __PIC16_GSTACK_H__ */
/*
** $Id$
-*/
+ */
+
/*
* Structure of memory block header:
extern volatile __OSCCONbits_t at 0xfd3 OSCCONbits;
extern sfr at 0xfd5 T0CON;
+typedef union {
+ struct {
+ unsigned T0PS0:1;
+ unsigned T0PS1:1;
+ unsigned T0PS2:1;
+ unsigned PSA:1;
+ unsigned T0SE:1;
+ unsigned T0CS:1;
+ unsigned T08BIT:1;
+ unsigned TMR0ON:1;
+ };
+} __T0CONbits_t;
+
+extern volatile __T0CONbits_t at 0xfd5 T0CONbits;
+
extern sfr at 0xfd6 TMR0L;
extern sfr at 0xfd7 TMR0H;
extern sfr at 0xfd8 STATUS;
extern volatile __OSCCONbits_t at 0xfd3 OSCCONbits;
extern sfr at 0xfd5 T0CON;
+typedef union {
+ struct {
+ unsigned T0PS0:1;
+ unsigned T0PS1:1;
+ unsigned T0PS2:1;
+ unsigned PSA:1;
+ unsigned T0SE:1;
+ unsigned T0CS:1;
+ unsigned T08BIT:1;
+ unsigned TMR0ON:1;
+ };
+} __T0CONbits_t;
+
+extern volatile __T0CONbits_t at 0xfd5 T0CONbits;
+
extern sfr at 0xfd6 TMR0L;
extern sfr at 0xfd7 TMR0H;
extern sfr at 0xfd8 STATUS;
extern volatile __OSCCONbits_t at 0xfd3 OSCCONbits;
extern sfr at 0xfd5 T0CON;
+typedef union {
+ struct {
+ unsigned T0PS0:1;
+ unsigned T0PS1:1;
+ unsigned T0PS2:1;
+ unsigned PSA:1;
+ unsigned T0SE:1;
+ unsigned T0CS:1;
+ unsigned T08BIT:1;
+ unsigned TMR0ON:1;
+ };
+} __T0CONbits_t;
+
+extern volatile __T0CONbits_t at 0xfd5 T0CONbits;
+
extern sfr at 0xfd6 TMR0L;
extern sfr at 0xfd7 TMR0H;
extern sfr at 0xfd8 STATUS;
extern volatile __OSCCONbits_t at 0xfd3 OSCCONbits;
extern sfr at 0xfd5 T0CON;
+typedef union {
+ struct {
+ unsigned T0PS0:1;
+ unsigned T0PS1:1;
+ unsigned T0PS2:1;
+ unsigned PSA:1;
+ unsigned T0SE:1;
+ unsigned T0CS:1;
+ unsigned T08BIT:1;
+ unsigned TMR0ON:1;
+ };
+} __T0CONbits_t;
+
+extern volatile __T0CONbits_t at 0xfd5 T0CONbits;
+
extern sfr at 0xfd6 TMR0L;
extern sfr at 0xfd7 TMR0H;
extern sfr at 0xfd8 STATUS;
--- /dev/null
+#
+# Makefile - Makefile to build pic16 support libraries
+#
+# This file is part of the GNU PIC Library.
+#
+# January, 2004
+# The GNU PIC Library is maintained by,
+# Vangelis Rokas <vrokas@otenet.gr>
+#
+# $Id$
+#
+#
+
+
+DIRS = ctype \
+ stdlib \
+ string
+
+LIB = libp18c.lib
+
+all: build-libraries
+
+make-target: build-libraries
+
+build-libraries:
+ for dir in $(DIRS) ; do \
+ $(MAKE) -C $$dir ; \
+ done;
+ gplib -c $(LIB) string/*.o
+ mv -v $(LIB) ../bin
+
+
+clean-intermediate:
+ @for dir in $(DIRS) ; do \
+ $(MAKE) -C $$dir clean-intermediate ; \
+ done ;
+
+clean:
+ for dir in $(DIRS) ; do \
+ $(MAKE) -C $$dir clean; \
+ done ;
+ rm -fv $(LIB)
+
+
+real-clean: clean
+ find -name *.adb -print | xargs -- rm -fv ;
+ find -name *.p -print | xargs -- rm -fv ;
+ find -name *.d -print | xargs -- rm -fv ;
+ find -name *.dump* -print | xargs -- rm -fv ;
+
+
+dep:
+ for dir in $(DIRS) ; do \
+ $(MAKE) -C $$dir dep; \
+ done
--- /dev/null
+#
+# Makefile.rules - Common Makefile rules to build pic16 C Library
+#
+# This file is part of the GNU PIC Library.
+#
+# January, 2004
+# The GNU PIC Library is maintained by,
+# Vangelis Rokas <vrokas@otenet.gr>
+#
+# $Id$
+#
+#
+
+
+include ../../Makefile.common
+
+PRJDIR = ../../../../..
+
+LIBC_INC_DIR = $(PRJDIR)/device/include/pic16
+
+COMPILE_FLAGS += $(MODELFLAGS) --pomit-config-words --pomit-ivt --no-peep --i-code-in-asm
+CFLAGS = -I$(LIBC_INC_DIR)
+
+CFILES = $(patsubst %,%.c,$(SRCS))
+OFILES = $(patsubst %.c,%.o,$(CFILES))
+
+%.o: %.c
+ $(CC) $(CFLAGS) $(COMPILE_FLAGS) -c $<
+
+
+all: build-library
+
+clean-intermediate:
+ $(RM) -f *.lst *.asm *.dump* *.p *.d *.adb
+
+
+clean: clean-intermediate
+ $(RM) -f $(LIB) *.o
+
+dep .depend:
+ rm -f .depend
+ for temp in $(CFILES); do \
+ $(CPP) $(MM) $(CFLAGS) $$temp > .tmpdepend; \
+ $(SED) s/.rel/.o/g .tmpdepend >> .depend; \
+ $(RM) -f .tmpdepend; \
+ done;
+
+include .depend
--- /dev/null
+#
+# Makefile - Makefile to build pic16 C Library
+#
+# This file is part of the GNU PIC Library.
+#
+# January, 2004
+# The GNU PIC Library is maintained by,
+# Vangelis Rokas <vrokas@otenet.gr>
+#
+# $Id$
+#
+#
+
+include ../Makefile.rules
+
+SRCS = iscntrl \
+ isdigit \
+ isgraph \
+ islower \
+ isprint \
+ ispunct \
+ isspace \
+ isupper \
+ isxdigit
+
+
+CFILES = $(patsubst %,%.c,$(SRCS))
+OFILES = $(patsubst %.c,%.o,$(CFILES))
+
+
+DEBUG=
+#COMPILE_FLAGS += --pomit-config-words --pomit-ivt --no-peep
+COMPILE_FLAGS += $(DEBUG)
+
+CFILES = $(patsubst %,%.c,$(SRCS))
+OFILES = $(patsubst %.c,%.o,$(CFILES))
+
+%.o: %.c
+ $(CC) $(CFLAGS) $(COMPILE_FLAGS) -c $<
+
+build-library: $(OFILES)
+
--- /dev/null
+/*-------------------------------------------------------------------------
+ _iscntrl.c - part of ctype.h
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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!
+-------------------------------------------------------------------------*/
+
+char iscntrl(unsigned char c)
+{
+ if ( c <= '\x1F' || c == '\x7f')
+ return 1;
+
+ return 0;
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ _isdigit.c - part of ctype.h
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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!
+-------------------------------------------------------------------------*/
+
+char isdigit( unsigned char c)
+{
+ if ( c >= '0' && c <= '9' )
+ return 1;
+
+ return 0;
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ _isgraph.c - part of ctype.h
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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!
+-------------------------------------------------------------------------*/
+
+char isgraph( unsigned char c)
+{
+ if ( c >= '\x21' && c <= '\x7e' )
+ return 1;
+
+ return 0;
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ _islower.c - part of ctype.h
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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!
+-------------------------------------------------------------------------*/
+
+char islower(unsigned char c)
+{
+ if( c >= 'a' && c <= 'z' )
+ return 1;
+
+ return 0;
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ _isprint.c - part of ctype.h
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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!
+-------------------------------------------------------------------------*/
+char isprint (unsigned char c)
+{
+ if ( c >= '\x20' && c <= '\x7e')
+ return 1;
+
+ return 0;
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ _ispunct.c - part of ctype.h
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <ctype.h>
+
+char ispunct (unsigned char c)
+{
+ if (isprint (c)
+ && !islower(c)
+ && !isupper(c)
+ && c != ' '
+ && !isdigit(c))
+ return 1;
+
+ return 0;
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ _isppace.c - part of ctype.h
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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!
+-------------------------------------------------------------------------*/
+
+char isspace (unsigned char c)
+{
+ if ( c == ' '
+ || c == '\f'
+ || c == '\n'
+ || c == '\r'
+ || c == '\t'
+ || c == '\v' )
+ return 1;
+
+ return 0;
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ _isupper.c - part of ctype.h
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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!
+-------------------------------------------------------------------------*/
+
+char isupper (unsigned char c)
+{
+ if ( c >= 'A' && c <= 'Z')
+ return 1;
+
+ return 0;
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ _isxdigit.c - part of ctype.h
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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!
+-------------------------------------------------------------------------*/
+char isxdigit (unsigned char c)
+{
+ if (( c >= '0' && c <= '9')
+ || ( c >= 'a' && c <= 'f')
+ || ( c >= 'A' && c <= 'F'))
+ return 1;
+
+ return 0;
+}
+
--- /dev/null
+#
+# Makefile - Makefile to build pic16 C Library
+#
+# This file is part of the GNU PIC Library.
+#
+# January, 2004
+# The GNU PIC Library is maintained by,
+# Vangelis Rokas <vrokas@otenet.gr>
+#
+# $Id$
+#
+#
+
+include ../Makefile.rules
+
+SRCS = atof \
+ atoi \
+ atol \
+ calloc \
+ free \
+ ltoa \
+ malloc \
+ realloc
+
+
+CFILES = $(patsubst %,%.c,$(SRCS))
+OFILES = $(patsubst %.c,%.o,$(CFILES))
+
+
+DEBUG=
+#COMPILE_FLAGS += --pomit-config-words --pomit-ivt --no-peep
+COMPILE_FLAGS += $(DEBUG)
+
+CFILES = $(patsubst %,%.c,$(SRCS))
+OFILES = $(patsubst %.c,%.o,$(CFILES))
+
+%.o: %.c
+ $(CC) $(CFLAGS) $(COMPILE_FLAGS) -c $<
+
+build-library: $(OFILES)
+
--- /dev/null
+/* atof.c: converts an ASCII string to float
+
+ Copyright (C) 2003 Jesus Calvino-Fraga, jesusc@ieee.org
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#include <ctype.h>
+#include <stdlib.h>
+
+float atof(char * s)
+{
+ float value, fraction;
+ char iexp;
+ char sign;
+
+ //Skip leading blanks
+ while (isspace(*s)) s++;
+
+ //Get the sign
+ if (*s == '-')
+ {
+ sign=1;
+ s++;
+ }
+ else
+ {
+ sign=0;
+ if (*s == '+') s++;
+ }
+
+ //Get the integer part
+ for (value=0.0; isdigit(*s); s++)
+ {
+ value=10.0*value+(*s-'0');
+ }
+
+ //Get the fraction
+ if (*s == '.')
+ {
+ s++;
+ for (fraction=0.1; isdigit(*s); s++)
+ {
+ value+=(*s-'0')*fraction;
+ fraction*=0.1;
+ }
+ }
+
+ //Finally, the exponent (not very efficient, but enough for now*/
+ if (toupper(*s)=='E')
+ {
+ s++;
+ iexp=(char)atoi(s);
+ {
+ while(iexp!=0)
+ {
+ if(iexp<0)
+ {
+ value*=0.1;
+ iexp++;
+ }
+ else
+ {
+ value*=10.0;
+ iexp--;
+ }
+ }
+ }
+ }
+
+ if(sign) value*=-1.0;
+ return (value);
+}
--- /dev/null
+/*---------------------------------------------------------------------
+ atoi - convert a string to an integer and return it
+
+ written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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!
+-------------------------------------------------------------------------*/
+
+int atoi(char * s)
+{
+ register int rv=0;
+ register char sign = 0;
+
+ /* skip till we find either a digit or '+' or '-' */
+ while (*s) {
+ if (*s <= '9' && *s >= '0')
+ break;
+ if (*s == '-' || *s == '+')
+ break;
+ s++;
+ }
+
+ sign = (*s == '-');
+ if (*s == '-' || *s == '+') s++;
+
+ while (*s && *s >= '0' && *s <= '9') {
+ rv = (rv * 10) + (*s - '0');
+ s++;
+ }
+
+ return (sign ? -rv : rv);
+}
+
--- /dev/null
+/*---------------------------------------------------------------------
+ atol - convert a string to long integer and return it
+
+ written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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!
+-------------------------------------------------------------------------*/
+
+long atol(char * s)
+{
+ register long rv=0;
+ register char sign = 0;
+
+ /* skip till we find either a digit or '+' or '-' */
+ while (*s) {
+ if (*s <= '9' && *s >= '0')
+ break;
+ if (*s == '-' || *s == '+')
+ break;
+ s++;
+ }
+
+ sign = (*s == '-');
+ if (*s == '-' || *s == '+') s++;
+
+ while (*s && *s >= '0' && *s <= '9') {
+ rv = (rv * 10) + (*s - '0');
+ s++;
+ }
+
+ return (sign ? -rv : rv);
+}
+
--- /dev/null
+/*
+ * malloc.c - dynamic memory allocation
+ *
+ * written by Vangelis Rokas, 2004 (vrokas@otenet.gr)
+ *
+ */
+
+#include "malloc.h"
+
+extern unsigned char *_dynamicHeap; /* pointer to heap */
+
+unsigned char *calloc(unsigned char num) //, unsigned char len)
+{
+ unsigned char len=num;
+ unsigned char total;
+ unsigned char *result, *ch;
+
+ total = num * len;
+ if(total > MAX_BLOCK_SIZE)return ((unsigned char *)0);
+ result = ch = malloc( (char)(total) );
+
+ if(result != 0) {
+ while(total) {
+ total--;
+ *ch = 0;
+ ch++;
+ }
+ }
+
+ return (result);
+}
--- /dev/null
+/*
+ * malloc.c - dynamic memory allocation
+ *
+ * written by Vangelis Rokas, 2004 (vrokas@otenet.gr)
+ *
+ */
+
+#include "malloc.h"
+
+extern char *_dynamicHeap; /* pointer to heap */
+
+void free(unsigned char *buf)
+{
+ /* mark block as deallocated */
+ ((_malloc_rec *)(buf - 1))->bits.alloc = 0;
+}
+
--- /dev/null
+/*-------------------------------------------------------------------------
+ integer to string conversion
+
+ Written by: Bela Torok, 1999
+ bela.torok@kssg.ch
+ usage:
+
+ _ultoa(unsigned long value, char* string, int radix)
+ _ltoa(long value, char* string, int radix)
+
+ value -> Number to be converted
+ string -> Result
+ radix -> Base of value (e.g.: 2 for binary, 10 for decimal, 16 for hex)
+---------------------------------------------------------------------------*/
+
+#define NUMBER_OF_DIGITS 32
+
+void ultoa(unsigned long value, data char* string, unsigned char radix)
+{
+unsigned char index;
+char buffer[NUMBER_OF_DIGITS]; /* space for NUMBER_OF_DIGITS + '\0' */
+
+ index = NUMBER_OF_DIGITS;
+
+ do {
+ buffer[--index] = '0' + (value % radix);
+ if ( buffer[index] > '9') buffer[index] += 'A' - '9' - 1;
+ value /= radix;
+ } while (value != 0);
+
+ do {
+ *string++ = buffer[index++];
+ } while ( index < NUMBER_OF_DIGITS );
+
+ *string = 0; /* string terminator */
+}
+
+void ltoa(long value, data char* string, unsigned char radix)
+{
+ if (value < 0 && radix == 10) {
+ *string++ = '-';
+ ultoa(-value, string, radix);
+ }
+ else {
+ ultoa(value, string, radix);
+ }
+}
+
--- /dev/null
+/*
+ * malloc.c - dynamic memory allocation
+ *
+ * written by Vangelis Rokas, 2004 (vrokas@otenet.gr)
+ *
+ */
+
+#include "malloc.h"
+
+extern unsigned char *_dynamicHeap; /* pointer to heap */
+
+unsigned char *malloc(unsigned char len)
+{
+ _malloc_rec *pHeap; /* pointer to block header */
+ _malloc_rec *temp;
+ unsigned char bLen; /* size of block */
+ unsigned char eLen;
+
+ if(len > _MAX_HEAP_SIZE)
+ return ((unsigned char *)0);
+
+ pHeap = (_malloc_rec *)&_dynamicHeap;
+
+
+ while(1) {
+ bLen = pHeap->bits.count;
+
+ /* if datum is zero, then last block, return NULL */
+ if(pHeap->datum == 0)
+ return ((unsigned char *)0);
+
+ /* if current block is allocated then proceed to next */
+ if(pHeap->bits.alloc) {
+ pHeap += pHeap->bits.count;
+ continue;
+ }
+
+
+ /* current block is not allocated, try to allocate */
+
+ /* if current block is not enough for allocation, then proceed to next */
+ if(bLen <= len) {
+
+ /* current block is not enough see if we can merge some adjacent
+ * memory blocks to make it fit */
+ temp = pHeap + pHeap->bits.count;
+ eLen = bLen;
+ while((temp->datum) && (!temp->bits.alloc) && (eLen < len)) {
+ eLen += temp->bits.count;
+ temp += temp->bits.count;
+ }
+
+ if(eLen >= len) {
+ int i;
+ /* yes, there are some free blocks that can be merged, merge them... */
+
+ temp = pHeap;
+ while(eLen > 0) {
+ if(eLen > MAX_BLOCK_SIZE)i = MAX_BLOCK_SIZE;
+ else i = eLen;
+
+ temp->bits.count = i;
+ temp->bits.alloc = 0;
+
+ temp += i;
+ eLen -= i;
+ }
+
+ bLen = pHeap->bits.count;
+ } else {
+ /* otherwise proceed with next block */
+ pHeap += pHeap->bits.count;
+ continue;
+ }
+ }
+
+
+ /* current block is enough to hold the new block */
+
+ /* allocate by filling the fields */
+ pHeap->bits.count = len+1;
+ pHeap->bits.alloc = 1;
+
+ if(bLen > len+1) {
+ /* if current block size is greater than the requested one,
+ * create a new empty block at the end of the newly allocated */
+ temp = pHeap + len+1;
+ temp->bits.count = bLen - len - 1;
+ temp->bits.alloc = 0;
+ }
+
+ return ((unsigned char *)pHeap + 1);
+ }
+}
--- /dev/null
+/*
+ * malloc.c - dynamic memory allocation
+ *
+ * written by Vangelis Rokas, 2004 (vrokas@otenet.gr)
+ *
+ */
+
+#include "malloc.h"
+
+extern unsigned char *_dynamicHeap; /* pointer to heap */
+
+unsigned char *realloc(unsigned char *mblock, unsigned char len)
+{
+ _malloc_rec *pHeap; /* pointer to block header */
+ _malloc_rec *temp;
+ unsigned char bLen; /* size of block */
+ unsigned char eLen;
+
+ if(len > MAX_BLOCK_SIZE)
+ return ((unsigned char *)0);
+
+ len++; /* increase to count header too */
+
+ pHeap = (_malloc_rec *)(mblock-1);
+ bLen = pHeap->bits.count;
+
+ /* new size is same as old, return pointer */
+ if(bLen == len)return (mblock);
+
+ if(bLen > len) {
+ /* new segment is smaller than the old one, that's easy! */
+ pHeap->bits.count = len;
+ temp = pHeap + len;
+ temp->bits.alloc = 0;
+ temp->bits.count = bLen - len;
+
+ return (((unsigned char *)pHeap) + 1);
+ }
+
+ /* so, new segment has size bigger than the old one
+ * we can only return a valid pointer only when after
+ * the block there is an empty block that can be merged
+ * to produce a new block of the requested size, otherwise
+ * we return NULL */
+
+ temp = pHeap + pHeap->bits.count;
+ eLen = bLen;
+ while((temp->datum) && (!temp->bits.alloc) && (eLen < len)) {
+ eLen += temp->bits.count;
+ temp += temp->bits.count;
+ }
+
+ if(eLen >= len) {
+ int i;
+ /* so we found one, adjust memory blocks */
+ temp = pHeap;
+
+ temp->bits.count = len;
+ eLen -= len;
+ temp += len;
+
+ while(eLen>0) {
+ if(eLen > MAX_BLOCK_SIZE)i = MAX_BLOCK_SIZE;
+ else i = eLen;
+
+ temp->bits.count = i;
+ temp->bits.alloc = 0;
+ temp += i;
+ eLen -= i;
+ }
+
+ return (((unsigned char *)pHeap) + 1);
+ }
+
+
+ /* no could not find a valid block, return NULL */
+
+ return ((unsigned char *)0);
+}
--- /dev/null
+#
+# Makefile - Makefile to build pic16 C Library
+#
+# This file is part of the GNU PIC Library.
+#
+# January, 2004
+# The GNU PIC Library is maintained by,
+# Vangelis Rokas <vrokas@otenet.gr>
+#
+# $Id$
+#
+#
+
+include ../Makefile.rules
+
+SRCS = memchr \
+ memcmp \
+ memcpy \
+ memccpy \
+ memmove \
+ memrchr \
+ memset \
+ strcat \
+ strchr \
+ strcmp \
+ strcpy \
+ strcspn \
+ strlen \
+ strlwr \
+ strncat \
+ strncmp \
+ strncpy \
+ strpbrk \
+ strrchr \
+ strspn \
+ strstr \
+ strtok \
+ strupr \
+ memchrpgm \
+ memchrram \
+ memcpypgm2ram \
+ memcpyram2ram \
+
+
+CFILES = $(patsubst %,%.c,$(SRCS))
+OFILES = $(patsubst %.c,%.o,$(CFILES))
+
+
+DEBUG=
+#COMPILE_FLAGS += --pomit-config-words --pomit-ivt --no-peep
+COMPILE_FLAGS += $(DEBUG)
+
+CFILES = $(patsubst %,%.c,$(SRCS))
+OFILES = $(patsubst %.c,%.o,$(CFILES))
+
+%.o: %.c
+ $(CC) $(CFLAGS) $(COMPILE_FLAGS) -c $<
+
+build-library: $(OFILES)
+
--- /dev/null
+/*-------------------------------------------------------------------------
+ memccpy.c - part of string library functions
+
+ Written by Vangelis Rokas, 2004 <vrokas AT otenet.gr>
+
+ Based on source
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+void *memccpy (void *dst, void *src, int c, size_t acount)
+{
+ void *ret = dst;
+ char *d = dst;
+ char *s = src;
+
+ /*
+ * copy from lower addresses to higher addresses
+ */
+ while (acount--) {
+ if( *s == c)
+ return (++s);
+
+ *d++ = *s++;
+ }
+
+ return((void *)0x00);
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ memchr.c - part of string library functions
+
+ Written by Vangelis Rokas 2004 <vrokas AT otenet.gr>
+
+ Based on source
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+void *memchr(void *s, char c, size_t count)
+{
+ if(!count)return (void *)0x00;
+
+ while((*(char *)s != c) && (count)) {
+ s = (char *)s + sizeof(char *);
+ count--;
+ }
+
+ if(count)return s;
+ else return (void *)0x00;
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ memchrpgm.c - part of string library functions
+
+ Written by Vangelis Rokas 2004 <vrokas AT otenet.gr>
+
+ Based on source
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+code void *memchrpgm(code void *s, char c, size_t count)
+{
+ if(!count)return (void *)0x00;
+
+ while((*(code char *)s != c) && (count)) {
+ s = (code char *)s + sizeof(code char *);
+ count--;
+ }
+
+ if(count)return s;
+ else return (void *)0x00;
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ memchrram.c - part of string library functions
+
+ Written by Vangelis Rokas 2004 <vrokas AT otenet.gr>
+
+ Based on source
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+data void *memchrram(data void *s, char c, size_t count)
+{
+ if(!count)return (void *)0x00;
+
+ while((*(data char *)s != c) && (count)) {
+ s = (data char *)s + sizeof(data char *);
+ count--;
+ }
+
+ if(count)return s;
+ else return (void *)0x00;
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ memcmp.c - part of string library functions
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+int memcmp (void * buf1, void * buf2, size_t count)
+{
+ if(!count)return(0);
+
+ while (--count && *((char *)buf1) == *((char *)buf2) ) {
+ buf1 = (char *)buf1 + 1;
+ buf2 = (char *)buf2 + 1;
+ }
+
+ return( *((unsigned char *)buf1) - *((unsigned char *)buf2) );
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ memcpy.c - part of string library functions
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+void *memcpy (void *dst, void *src, size_t acount)
+{
+ void *ret = dst; /* perhaps ret should be removed, use dst instead */
+ char *d = dst;
+ char *s = src;
+
+ /*
+ * copy from lower addresses to higher addresses
+ */
+ while (acount--) {
+ *d++ = *s++;
+ }
+
+ return(ret);
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ memcpypgm2ram.c - part of string library functions
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+void *memcpypgm2ram (data void *dst, void code *src, size_t acount)
+{
+ void *ret = dst; /* perhaps ret should be removed, use dst instead */
+ char data *d = dst;
+ char *s = src;
+
+ /*
+ * copy from lower addresses to higher addresses
+ */
+ while (acount--) {
+ *d++ = *s++;
+ }
+
+ return(ret);
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ memcpypgm2ram.c - part of string library functions
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+data void *memcpyram2ram (data void *dst, data void *src, size_t acount)
+{
+ void data *ret = dst; /* perhaps ret should be removed, use dst instead */
+ char data *d = dst;
+ char data *s = src;
+
+ /*
+ * copy from lower addresses to higher addresses
+ */
+ while (acount--) {
+ *d++ = *s++;
+ }
+
+ return(ret);
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ _memmove.c - part of string library functions
+
+ Adapted By - Erik Petrich . epetrich@users.sourceforge.net
+ from _memcpy.c which was originally
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+void *memmove (void *dst, void *src, size_t acount)
+{
+ void *ret = dst;
+ char *d;
+ char *s;
+
+ if(((int)src < (int)dst) && ((((int)src)+acount) > (int)dst)) {
+ /*
+ * copy from higher addresses to lower addresses
+ */
+ d = ((char *)dst)+acount-1;
+ s = ((char *)src)+acount-1;
+ while (acount--) {
+ *d-- = *s--;
+ }
+ } else {
+ /*
+ * copy from lower addresses to higher addresses
+ */
+ d = dst;
+ s = src;
+ while (acount--) {
+ *d++ = *s++;
+ }
+ }
+
+ return(ret);
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ memrchr.c - part of string library functions
+
+ Written by Vangelis Rokas 2004 <vrokas AT otenet.gr>
+
+ Based on source
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+void *memrchr(void *s, char c, size_t count)
+{
+ if(!count)return (void *)0x00;
+
+ s = (char *)s + sizeof(char *) * count;
+
+ while((*(char *)s != c) && (count)) {
+ s = (char *)s - sizeof(char *);
+ count--;
+ }
+
+ if(count)return s;
+ else return (void *)0x00;
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ memset.c - part of string library functions
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+void *memset (void *buf, unsigned char ch, size_t count)
+{
+ register unsigned char *ret = buf;
+
+ while (count--) {
+ *(unsigned char *) ret = ch;
+ ret++;
+ }
+
+ return buf ;
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ strncat.c - part of string library functions
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+char *strcat(char *dst, char *src)
+{
+ char *cp = dst;
+
+ while( *cp )cp++; /* find end of dst */
+
+ while( *cp++ = *src++ ) ; /* Copy src to end of dst */
+
+ return( dst ); /* return dst */
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ strchr.c - part of string library functions
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+char *strchr(char *string, char ch)
+{
+ while(*string && *string != ch)string++;
+
+ if (*string == ch)return(string);
+
+ return ( NULL );
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ strcmp.c - part of string library functions
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+int strcmp(char * asrc, char * adst)
+{
+ register int ret = 0 ;
+
+ while( ! (ret = *asrc - *adst) && *adst)++asrc, ++adst;
+
+ if ( ret < 0 )ret = -1 ;
+ else if ( ret > 0 )ret = 1 ;
+
+ return( ret );
+}
+
--- /dev/null
+/*-------------------------------------------------------------------------
+ strcpy.c - part of string library functions
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+char *strcpy(char *d, char *s)
+{
+ register char * d1 = d;
+
+ while (*d1++ = *s++) ;
+
+ return d;
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ strcspn.c - part of string library functions
+
+ Bug fixed by Vangelis Rokas . vrokas AT otenet.gr (2004)
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+int strcspn (char *string, char *control)
+{
+ register int count = 0 ;
+ register char ch ;
+
+ while (ch = *string) {
+ if (strchr(control,ch))break;
+ else count++ ;
+ string++;
+ }
+
+ return count ;
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ strcpy.c - part of string library functions
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+int strlen (char * str)
+{
+ register int i = 0 ;
+
+ while (*str++)i++;
+
+ return i;
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ strlwr.c - part of string library functions
+
+ Written by Vangelis Rokas, 2004 <vrokas AT otenet.gr>
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <ctype.h>
+#include <string.h>
+
+char *strlwr(char *str)
+{
+ char *ret = str;
+
+ while(*str) {
+ *str = tolower( *str );
+ str++;
+ }
+
+ return (ret);
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ strncat.c - part of string library functions
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+char *strncat(char *front, char * back, size_t count)
+{
+ char *start = front;
+
+ while (*front++);
+
+ front--;
+ while (count--)
+ if (!(*front++ = *back++))return(start);
+
+ *front = '\0';
+
+ return(start);
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ _strncmp.c - part of string library functions
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+int strncmp(char *first, char *last, size_t count)
+{
+ if (!count)return(0);
+
+ while (--count && *first && *first == *last) {
+ first++;
+ last++;
+ }
+
+ return( *first - *last );
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ strncpy.c - part of string library functions
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+char *strncpy (char *d, char *s, size_t n)
+{
+ register char *d1 = d;
+
+ while ( n-- )*d++ = *s++ ;
+
+ return d1;
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ strpbrk.c - part of string library functions
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+char *strpbrk (char * string, char *control)
+{
+ register char ch ;
+
+ while(ch = *string) {
+ if(strchr(control, ch ))return string ;
+ }
+
+ return (NULL);
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ strrchr.c - part of string library functions
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+char *strrchr(char *string, char ch)
+{
+ char *start = string;
+
+ while (*string++) /* find end of string */
+ ;
+
+ /* search towards front */
+ while (--string != start && *string != ch)
+ ;
+
+ if (*string == ch) /* char found ? */
+ return( (char *)string );
+
+ return (NULL) ;
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ strspn.c - part of string library functions
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+int strspn(char *string, char *control)
+{
+ register int count = 0;
+ register char ch ;
+
+ while (ch = *string) {
+ if ( strchr(control,ch) )
+ count++ ;
+ else break ;
+
+ string++ ;
+ }
+
+ return count ;
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ _strstr.c - part of string library functions
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+char *strstr(char *str1, char *str2)
+{
+ char *cp = str1;
+ char *s1;
+ char *s2;
+
+
+ if( !*str2 )
+ return str1;
+
+ while (*cp) {
+ s1 = cp;
+ s2 = str2;
+
+ while ( *s1 && *s2 && !(*s1-*s2) )
+ s1++, s2++;
+
+ if (!*s2)return(cp);
+
+ cp++;
+ }
+
+ return (NULL) ;
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ strtok.c - part of string library functions
+
+ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <string.h>
+
+char *strtok(char *str, char *control)
+{
+ static char * s;
+ register char * s1;
+
+ if (str)s = str ;
+
+ if (!s)return NULL;
+
+ while (*s) {
+ if (strchr(control,*s))s++;
+ else break;
+ }
+
+ s1 = s ;
+
+ while (*s) {
+ if (strchr(control,*s)) {
+ *s++ = '\0';
+ return s1 ;
+ }
+ s++ ;
+ }
+
+ s = NULL;
+
+ if (*s1)return s1;
+ else return NULL;
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ strupr.c - part of string library functions
+
+ Written by Vangelis Rokas, 2004 <vrokas AT otenet.gr>
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Library 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library 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 <ctype.h>
+#include <string.h>
+
+char *strupr(char *str)
+{
+ char *ret = str;
+
+ while(*str) {
+ *str = toupper( *str );
+ str++;
+ }
+
+ return (ret);
+}
volatile __OSCCONbits_t at 0xfd3 OSCCONbits;
sfr at 0xfd5 T0CON;
+volatile __T0CONbits_t at 0xfd5 T0CONbits;
+
sfr at 0xfd6 TMR0L;
sfr at 0xfd7 TMR0H;
sfr at 0xfd8 STATUS;
volatile __OSCCONbits_t at 0xfd3 OSCCONbits;
sfr at 0xfd5 T0CON;
+volatile __T0CONbits_t at 0xfd5 T0CONbits;
+
sfr at 0xfd6 TMR0L;
sfr at 0xfd7 TMR0H;
sfr at 0xfd8 STATUS;
volatile __OSCCONbits_t at 0xfd3 OSCCONbits;
sfr at 0xfd5 T0CON;
+volatile __T0CONbits_t at 0xfd5 T0CONbits;
+
sfr at 0xfd6 TMR0L;
sfr at 0xfd7 TMR0H;
sfr at 0xfd8 STATUS;
volatile __OSCCONbits_t at 0xfd3 OSCCONbits;
sfr at 0xfd5 T0CON;
+volatile __T0CONbits_t at 0xfd5 T0CONbits;
+
sfr at 0xfd6 TMR0L;
sfr at 0xfd7 TMR0H;
sfr at 0xfd8 STATUS;
--- /dev/null
+#
+# Makefile - Makefile to build pic16 support libraries
+#
+# This file is part of the GNU PIC Library.
+#
+# January, 2004
+# The GNU PIC Library is maintained by,
+# Vangelis Rokas <vrokas@otenet.gr>
+#
+# $Id$
+#
+#
+
+
+DIRS = adc
+
+
+LIB = libio.lib
+
+all: build-libraries
+
+make-target: build-libraries
+
+build-libraries:
+ for dir in $(DIRS) ; do \
+ $(MAKE) -C $$dir ; \
+ done;
+ gplib -c $(LIB) adc/*.o
+ mv -v $(LIB) ../bin
+
+
+clean-intermediate:
+ @for dir in $(DIRS) ; do \
+ $(MAKE) -C $$dir clean-intermediate ; \
+ done ;
+
+clean:
+ for dir in $(DIRS) ; do \
+ $(MAKE) -C $$dir clean; \
+ done ;
+ rm -fv $(LIB)
+
+
+real-clean: clean
+ find -name *.adb -print | xargs -- rm -fv ;
+ find -name *.p -print | xargs -- rm -fv ;
+ find -name *.d -print | xargs -- rm -fv ;
+ find -name *.dump* -print | xargs -- rm -fv ;
+
+
+dep:
+ for dir in $(DIRS) ; do \
+ $(MAKE) -C $$dir dep; \
+ done
--- /dev/null
+#
+# Makefile.rules - Common Makefile rules to build pic16 C Library
+#
+# This file is part of the GNU PIC Library.
+#
+# January, 2004
+# The GNU PIC Library is maintained by,
+# Vangelis Rokas <vrokas@otenet.gr>
+#
+# $Id$
+#
+#
+
+
+include ../../Makefile.common
+
+PRJDIR = ../../../../..
+
+LIBC_INC_DIR = $(PRJDIR)/device/include/pic16
+
+COMPILE_FLAGS += $(MODELFLAGS) --pomit-config-words --pomit-ivt --no-peep --i-code-in-asm
+CFLAGS = -I$(LIBC_INC_DIR)
+
+CFILES = $(patsubst %,%.c,$(SRCS))
+OFILES = $(patsubst %.c,%.o,$(CFILES))
+
+%.o: %.c
+ $(CC) $(CFLAGS) $(COMPILE_FLAGS) -c $<
+
+
+all: build-library
+
+clean-intermediate:
+ $(RM) -f *.lst *.asm *.dump* *.p *.d *.adb
+
+
+clean: clean-intermediate
+ $(RM) -f $(LIB) *.o
+
+dep .depend:
+ rm -f .depend
+ for temp in $(CFILES); do \
+ $(CPP) $(MM) $(CFLAGS) $$temp > .tmpdepend; \
+ $(SED) s/.rel/.o/g .tmpdepend >> .depend; \
+ $(RM) -f .tmpdepend; \
+ done;
+
+include .depend
--- /dev/null
+#
+# Makefile - Makefile to build pic16 C Library
+#
+# This file is part of the GNU PIC Library.
+#
+# January, 2004
+# The GNU PIC Library is maintained by,
+# Vangelis Rokas <vrokas@otenet.gr>
+#
+# $Id$
+#
+#
+
+include ../Makefile.rules
+
+SRCS = adcbusy \
+ adcclose \
+ adcconv \
+ adcopen \
+ adcread \
+ adcsetch
+
+
+CFILES = $(patsubst %,%.c,$(SRCS))
+OFILES = $(patsubst %.c,%.o,$(CFILES))
+
+
+DEBUG=
+#COMPILE_FLAGS += --pomit-config-words --pomit-ivt --no-peep
+COMPILE_FLAGS += $(DEBUG)
+
+CFILES = $(patsubst %,%.c,$(SRCS))
+OFILES = $(patsubst %.c,%.o,$(CFILES))
+
+%.o: %.c
+ $(CC) $(CFLAGS) $(COMPILE_FLAGS) -c $<
+
+build-library: $(OFILES)
+
--- /dev/null
+
+#include <pic18fregs.h>
+
+#include <adc.h>
+
+
+char adc_busy(void)
+{
+ return (ADCON0bits.GO == 1);
+}
--- /dev/null
+
+#include <pic18fregs.h>
+
+#include <adc.h>
+
+
+void adc_close(void)
+{
+ ADCON0bits.ADON = 0;
+ PIE1bits.ADIE = 0;
+}
--- /dev/null
+
+#include <pic18fregs.h>
+
+#include <adc.h>
+
+
+void adc_conv(void)
+{
+ ADCON0bits.GO = 1;
+}
--- /dev/null
+
+#include <pic18fregs.h>
+
+#include <adc.h>
+
+
+/* parameters are:
+ * channel: one of ADC_CHN_*
+ * fosc: one of ADC_FOSC_*
+ * pcfg: one of ADC_CFG_*
+ * config: ADC_FRM_* | ADC_INT_*
+ */
+
+void adc_open(unsigned char channel, unsigned char fosc, unsigned char pcfg, unsigned char config)
+{
+ ADCON0 = 0;
+ ADCON1 = 0;
+
+ /* setup channel */
+ ADCON0 |= (channel & 0x07) << 3;
+
+ /* setup fosc */
+ ADCON0 |= (fosc & 0x03) << 6;
+ ADCON1 |= (fosc & 0x04) << 4;
+
+ /* setup reference and pins */
+ ADCON1 |= pcfg & 0x0f;
+
+ ADCON0 |= (config & ADC_FRM_RJUST);
+
+ if(config & ADC_INT_ON) {
+ PIR1bits.ADIF = 0;
+ PIE1bits.ADIE = 1;
+ INTCONbits.PEIE = 1;
+ }
+
+ /* enable the A/D module */
+ ADCON0bits.ADON = 1;
+}
--- /dev/null
+
+#include <pic18fregs.h>
+
+#include <adc.h>
+
+
+int adc_read(void)
+{
+ union {
+ int ri;
+ char rb[2];
+ } result;
+
+ result.rb[0] = ADRESL;
+ result.rb[1] = ADRESH;
+
+ return (result.ri);
+}
--- /dev/null
+
+#include <pic18fregs.h>
+
+#include <adc.h>
+
+
+void adc_setchannel(unsigned char channel)
+{
+ ADCON0 &= ~(0x7 << 3);
+ ADCON0 |= channel << 3;
+}
for dir in $(DIRS) ; do \
$(MAKE) -C $$dir ; \
done;
- gplib -c $(LIB) char/*.o int/*.o long/*.o float/*.o gptr/*.o
+ gplib -c $(LIB) char/*.o int/*.o long/*.o float/*.o gptr/*.o lregs/*.o
mv -v $(LIB) ../bin
what you give them. Help stamp out software-hoarding!
-------------------------------------------------------------------------*/
+/*
+** $Id$
+*/
+
#include <sdcc-lib.h>
unsigned char _divuchar (unsigned char a, unsigned char b);
what you give them. Help stamp out software-hoarding!
-------------------------------------------------------------------------*/
+/*
+** $Id$
+*/
+
#include <sdcc-lib.h>
#define MSB_SET(x) ((x >> (8*sizeof(x)-1)) & 1)
what you give them. Help stamp out software-hoarding!
-------------------------------------------------------------------------*/
+/*
+** $Id$
+*/
+
+
#include <sdcc-lib.h>
unsigned char _moduchar (unsigned char a, unsigned char b);
char _modschar (char a, char b) _IL_REENTRANT
{
register char r;
- register char ta, tb;
+ char ta, tb;
if(a<0)ta = -a; else ta = a;
if(b<0)tb = -b; else tb = b;
uint2fs \
ulong2fs
+COMPILE_FLAGS += --obanksel=9
include ../Makefile.rules
#if 1
if(IC_TRUE(ifx))
- DEBUGpic16_emitcode("; ***","ifx true is non-null");
+ DEBUGpic16_emitcode("; +++","ifx true is non-null");
+ else
+ DEBUGpic16_emitcode("; +++","ifx true is null");
if(IC_FALSE(ifx))
- DEBUGpic16_emitcode("; ***","ifx false is non-null");
+ DEBUGpic16_emitcode("; +++","ifx false is non-null");
+ else
+ DEBUGpic16_emitcode("; +++","ifx false is null");
#endif
}
if(IN_CODESPACE( SPEC_OCLS( OP_SYM_ETYPE(refop)))
|| viaimmd) {
- DEBUGpic16_emitcode(";", "%s:%d immediate", __FILE__, __LINE__);
+ DEBUGpic16_emitcode(";", "%s:%d immediate, size: %d", __FILE__, __LINE__, getSize( sym->type ));
aop->aopu.pcop = pic16_popGetImmd(OP_SYMBOL(IC_LEFT(ic))->rname, 0, val);
#endif
PCOI(aop->aopu.pcop)->index = val;
+
+ aop->size = getSize( sym->type );
} else {
- DEBUGpic16_emitcode(";", "%s:%d dir", __FILE__, __LINE__);
+ DEBUGpic16_emitcode(";", "%s:%d dir size: %d", __FILE__, __LINE__, getSize( OP_SYMBOL( IC_LEFT(ic))->type));
aop->aopu.pcop = pic16_popRegFromString(OP_SYMBOL(IC_LEFT(ic))->rname,
getSize( OP_SYMBOL( IC_LEFT(ic))->type), val, op);
-// aop->size = AOP_SIZE( IC_LEFT(ic) );
+
+ aop->size = getSize( OP_SYMBOL( IC_LEFT(ic))->type );
}
if (!op)
return ;
-// DEBUGpic16_emitcode(";","%s %d",__FUNCTION__, __LINE__);
+ DEBUGpic16_emitcode(";","%s %d",__FUNCTION__, __LINE__);
/* if this a literal */
if (IS_OP_LITERAL(op)) {
sym = OP_SYMBOL(op);
- DEBUGpic16_emitcode("; ***", "%d: symbol name = %s", __LINE__, sym->name);
+ DEBUGpic16_emitcode("; ***", "%d: symbol name = %s, regType = %d", __LINE__, sym->name, sym->regType);
/* if the type is a conditional */
if (sym->regType == REG_CND) {
aop = op->aop = sym->aop = newAsmop(AOP_CRY);
if (sym->remat) {
sym->aop = op->aop = aop = aopForRemat (op);
- aop->size = getSize(sym->type);
- //DEBUGpic16_emitcode(";"," %d: size %d, %s\n",__LINE__,aop->size,aop->aopu.aop_immd);
+// aop->size = getSize(sym->type);
+// DEBUGpic16_emitcode(";"," %d: size %d, %s\n",__LINE__,aop->size,aop->aopu.aop_immd);
return;
}
// DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if(_TempReg_lock) {
- werror(W_POSSBUG2, __FILE__, __LINE__);
+// werror(W_POSSBUG2, __FILE__, __LINE__);
}
_TempReg_lock += lock;
// DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
if(_TempReg_lock) {
- werror(W_POSSBUG2, __FILE__, __LINE__);
+// werror(W_POSSBUG2, __FILE__, __LINE__);
}
_TempReg_lock += lock;
PCOR(pcop)->instance = offset;
pcop->type = PCOR(pcop)->r->pc_type;
+
+ DEBUGpic16_emitcode(";*+*", "%d\tAOP_REG type = %s\n", __LINE__, dumpPicOptype(pcop->type));
rs = aop->aopu.aop_reg[offset]->name;
DEBUGpic16_emitcode(";","%d regiser idx = %d name = %s",__LINE__,rIdx,rs);
return pcop;
DEBUGpic16_emitcode(";","%d\tAOP_CRY", __LINE__);
pcop = pic16_newpCodeOpBit(aop->aopu.aop_dir,-1,1, PO_GPR_REGISTER);
+ PCOR(pcop)->instance = offset;
PCOR(pcop)->r = pic16_dirregWithName(aop->aopu.aop_dir);
//if(PCOR(pcop)->r == NULL)
//fprintf(stderr,"%d - couldn't find %s in allocated registers\n",__LINE__,aop->aopu.aop_dir);
int i;
DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+
/* if the result is bit */
if (AOP_TYPE(result) == AOP_CRY) {
fprintf(stderr, "%s:%d: pic16 port warning: unsupported case\n", __FILE__, __LINE__);
pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(result), i));
}
pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result), 0));
-
-/*
- pic16_emitcode("clr","a ; %d", __LINE__);
- pic16_emitcode("rlc","a");
- pic16_outAcc(result);
-*/
+ }
+}
+
+/*-----------------------------------------------------------------*/
+/* pic16_outBitOp - output a bit from Op */
+/* Move to result the value of set/clr op -- VR */
+/*-----------------------------------------------------------------*/
+void pic16_outBitOp(operand *result, pCodeOp *pcop)
+{
+ int i;
+
+ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+
+ /* if the result is bit */
+ if (AOP_TYPE(result) == AOP_CRY) {
+ fprintf(stderr, "%s:%d: pic16 port warning: unsupported case\n", __FILE__, __LINE__);
+ pic16_aopPut(AOP(result),"c",0);
+ } else {
+
+ i = AOP_SIZE(result);
+ while(i--) {
+ pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(result), i));
+ }
+ pic16_emitpcode(POC_RRCF, pcop);
+ pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(result), 0));
}
}
static void genUminusFloat(operand *op,operand *result)
{
int size ,offset =0 ;
- char *l;
DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
/* for this we just need to flip the
first it then copy the rest in place */
- size = AOP_SIZE(op) - 1;
- l = pic16_aopGet(AOP(op),3,FALSE,FALSE);
-
- MOVA(l);
-
- pic16_emitcode("cpl","acc.7");
- pic16_aopPut(AOP(result),"a",3);
+ size = AOP_SIZE(op);
while(size--) {
- pic16_aopPut(AOP(result),
- pic16_aopGet(AOP(op),offset,FALSE,FALSE),
- offset);
- offset++;
- }
+ mov2f(AOP(result), AOP(op), offset);
+ offset++;
+ }
+
+ /* toggle the MSB's highest bit */
+ pic16_emitpcode(POC_BTG, pic16_popCopyGPR2Bit(pic16_popGet(AOP(result), offset-1), 7));
}
/*-----------------------------------------------------------------*/
pic16_emitpcode(POC_INCF, pic16_popCopyReg(&pic16_pc_fsr1h));
}
+// sym->regsUsed = _G.fregsUsed;
+
/* now we need to restore the registers */
/* if any registers used */
if (sym->regsUsed) {
void pic16_storeForReturn(operand *op, int offset, pCodeOp *dest)
{
if(is_LitOp(op)) {
- pic16_emitpcode(POC_MOVLW, pic16_popGet(AOP(op), offset));
- if(dest->type != PO_WREG)pic16_emitpcode(POC_MOVWF, dest);
+ unsigned long lit = (unsigned long)floatFromVal(AOP(op)->aopu.aop_lit);
+ if(lit == 0) {
+ pic16_emitpcode(POC_CLRF, dest);
+ } else {
+ pic16_emitpcode(POC_MOVLW, pic16_popGet(AOP(op), offset));
+ if(dest->type != PO_WREG)pic16_emitpcode(POC_MOVWF, dest);
+ }
} else {
if(dest->type == PO_WREG && (offset == 0)) {
pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(op), offset));
/* genCmp :- greater or less than comparison */
/*-----------------------------------------------------------------*/
#if 1
+ /* { */
+ /* original code */
static void genCmp (operand *left,operand *right,
operand *result, iCode *ifx, int sign)
{
}
-
pic16_emitpcode(POC_MOVLW, pic16_popGetLit((lp1 >> (size*8)) & 0xff));
pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(right),size));
}
-#else /* old version of genCmp() */
+#else /* old version of genCmp() */ /* } else { */
+
+/* check all condition and return appropriate instruction, POC_CPFSGT or POC_CPFFSLT */
+static int selectCompareOp(resolvedIfx *rIfx, iCode *ifx,
+ operand *result, int offset, int invert_op)
+{
+ /* add code here */
+
+ /* check condition, > or < ?? */
+ if(rIfx->condition != 0)invert_op ^= 1;
+
+ if(ifx && IC_FALSE(ifx))invert_op ^= 1;
+
+ if(!ifx)invert_op ^= 1;
+
+ DEBUGpic16_emitcode("; +++", "%s:%d %s] rIfx->condition= %d, ifx&&IC_FALSE(ifx)= %d, invert_op = %d",
+ __FILE__, __LINE__, __FUNCTION__, rIfx->condition, (ifx && IC_FALSE(ifx)), invert_op);
+
+ /* do selection */
+ if(!invert_op)return POC_CPFSGT;
+ else return POC_CPFSLT;
+}
+
+static int compareAopfirstpass=1;
+
+static void compareAop(resolvedIfx *resIfx, iCode *ifx, symbol *falselbl,
+ operand *oper, int offset, operand *result,
+ int sign, int invert_op, pCodeOp *pcop, pCodeOp *pcop2,
+ symbol *tlbl)
+{
+ int op;
+ symbol *truelbl;
+
+ /* invert if there is a result to be loaded, in order to fit,
+ * SETC/CLRC sequence */
+ if(AOP_SIZE(result))invert_op ^= 1;
+
+// if(sign && !offset)invert_op ^= 1;
+
+// if(sign)invert_op ^= 1;
+
+ op = selectCompareOp(resIfx, ifx, result, offset, invert_op);
+
+ if(AOP_SIZE(result) && compareAopfirstpass) {
+ if(!ifx) {
+ if(pcop2)
+ pic16_emitpcode(POC_SETF, pcop2);
+ else
+ emitSETC;
+ } else {
+ if(pcop2)
+ pic16_emitpcode(POC_CLRF, pcop2);
+ else
+ emitCLRC;
+ }
+ }
+
+ compareAopfirstpass = 0;
+
+ /* there is a bug when comparing operands with size > 1,
+ * because higher bytes can be equal and test should be performed
+ * to the next lower byte, current algorithm, considers operands
+ * inequal in these cases! -- VR 20041107 */
+
+
+ if(pcop)
+ pic16_emitpcode(op, pcop);
+ else
+ pic16_emitpcode(op, pic16_popGet(AOP(oper), offset));
+
+
+ if((!sign || !offset) && AOP_SIZE(result)) {
+ if(!ifx) {
+ if(pcop2)
+ pic16_emitpcode(POC_CLRF, pcop2);
+ else
+ emitCLRC;
+ } else {
+ if(pcop2)
+ pic16_emitpcode(POC_SETF, pcop2);
+ else
+ emitSETC;
+ }
+
+ /* don't emit final branch (offset == 0) */
+ if(offset) {
+
+ if(pcop2)
+ pic16_emitpcode(POC_RRCF, pcop2);
+
+ pic16_emitpcode(POC_BNC, pic16_popGetLabel(falselbl->key));
+ }
+ } else {
+ if((ifx && (IC_TRUE(ifx)!=NULL)) || (sign && !offset)) {
+ DEBUGpic16_emitcode ("; +++","%s: %d: ifx = %p, IC_TRUE(ifx) = %d, sign = %d, offset = %d",
+ __FUNCTION__, __LINE__, ifx, (ifx&&IC_TRUE(ifx)), sign, offset);
+
+ truelbl = newiTempLabel( NULL );
+ pic16_emitpcode(POC_BRA, pic16_popGetLabel(truelbl->key));
+ if((!ifx || !IC_TRUE(ifx)) && (sign && !offset))
+ pic16_emitpcode(POC_GOTO, pic16_popGetLabel(tlbl->key));
+ else
+ pic16_emitpcode(POC_GOTO, pic16_popGetLabel(resIfx->lbl->key));
+ pic16_emitpLabel(truelbl->key);
+ } else {
+ pic16_emitpcode(POC_GOTO, pic16_popGetLabel(resIfx->lbl->key));
+ }
+ }
+}
+
+
+
+
+#if 1 /* { */
+static void genCmp (operand *left, operand *right,
+ operand *result, iCode *ifx, int sign)
+{
+ int size, cmpop=1;
+ long lit = 0L;
+ resolvedIfx rFalseIfx;
+ symbol *falselbl, *tlbl;
+
+ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ DEBUGpic16_pic16_AopType(__LINE__,left,right,result);
+
+ resolveIfx(&rFalseIfx, ifx);
+ size = max(AOP_SIZE(left), AOP_SIZE(right));
+
+ /* if left & right are bit variables */
+ if(AOP_TYPE(left) == AOP_CRY
+ && AOP_TYPE(right) == AOP_CRY ) {
+
+ pic16_emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
+ pic16_emitcode("anl","c,/%s",AOP(left)->aopu.aop_dir);
+
+ werror(W_POSSBUG2, __FILE__, __LINE__);
+ exit(-1);
+ }
+
+ /* if literal is on the right then swap with left */
+ if((AOP_TYPE(right) == AOP_LIT)) {
+ operand *tmp = right ;
+// unsigned long mask = (0x100 << (8*(size-1))) - 1;
+
+ lit = /*(unsigned long)*/floatFromVal(AOP(right)->aopu.aop_lit);
+
+// lit = (lit - 1) & mask;
+ right = left;
+ left = tmp;
+ rFalseIfx.condition ^= 1; /* reverse compare */
+ } else
+ if ((AOP_TYPE(left) == AOP_LIT)) {
+ /* float compares are handled by support functions */
+ lit = /*(unsigned long)*/floatFromVal(AOP(left)->aopu.aop_lit);
+ }
+
+ /* actual comparing algorithm */
+// size = AOP_SIZE( right );
+
+ falselbl = newiTempLabel( NULL );
+ if(AOP_TYPE(left) == AOP_LIT) {
+ /* compare to literal */
+ DEBUGpic16_emitcode ("; ***","%s: %d: compare to literal", __FUNCTION__, __LINE__);
+
+ if(sign) {
+ pCodeOp *pct, *pct2;
+ symbol *tlbl1;
+
+ /* signed compare */
+ DEBUGpic16_emitcode ("; ***","%s: %d: signed compare", __FUNCTION__, __LINE__);
+
+ pct = pic16_popCopyReg(&pic16_pc_prodl);
+ pct2 = pic16_popCopyReg(&pic16_pc_prodh);
+ tlbl = newiTempLabel( NULL );
+
+ /* first compare signs:
+ * a. if both are positive, compare just like unsigned
+ * b. if both are negative, invert cmpop, compare just like unsigned
+ * c. if different signs, determine the result directly */
+
+ size--;
+
+#if 1
+ /* { */
+ tlbl1 = newiTempLabel( NULL );
+// pic16_emitpcode(POC_RLCFW, pic16_popGet( AOP(right), size)); /* move sign to carry */
+
+ if(lit > 0) {
+
+ /* literal is zero or positive:
+ * a. if carry is zero, too, continue compare,
+ * b. if carry is set, then continue depending on cmpop ^ condition:
+ * 1. '<' return false (literal < variable),
+ * 2. '>' return true (literal > variable) */
+// pic16_emitpcode(POC_BNC, pic16_popGetLabel( tlbl1->key ));
+ pic16_emitpcode(POC_BTFSC, pic16_popCopyGPR2Bit(pic16_popGet(AOP(right), size), 7));
+
+
+ if(cmpop ^ rFalseIfx.condition)pic16_emitpcode(POC_GOTO, pic16_popGetLabel( tlbl->key ));
+ else pic16_emitpcode(POC_GOTO, pic16_popGetLabel( rFalseIfx.lbl->key ));
+ } else
+ if(lit < 0) {
+
+ /* literal is negative:
+ * a. if carry is set, too, continue compare,
+ * b. if carry is zero, then continue depending on cmpop ^ condition:
+ * 1. '<' return true (literal < variable),
+ * 2. '>' return false (literal > variable) */
+// pic16_emitpcode(POC_BC, pic16_popGetLabel( tlbl1->key ));
+ pic16_emitpcode(POC_BTFSS, pic16_popCopyGPR2Bit(pic16_popGet(AOP(right), size), 7));
+
+ if(!(cmpop ^ rFalseIfx.condition))pic16_emitpcode(POC_GOTO, pic16_popGetLabel( tlbl->key ));
+ else pic16_emitpcode(POC_GOTO, pic16_popGetLabel( rFalseIfx.lbl->key));
+ }
+#if 1
+ else {
+ /* lit == 0 */
+ pic16_emitpcode(POC_BTFSC, pic16_popCopyGPR2Bit(pic16_popGet(AOP(right), size), 7));
+
+ if(!(cmpop ^ rFalseIfx.condition))pic16_emitpcode(POC_GOTO, pic16_popGetLabel( tlbl->key ));
+ else pic16_emitpcode(POC_GOTO, pic16_popGetLabel( rFalseIfx.lbl->key));
+ }
+#endif
+
+
+ pic16_emitpLabel( tlbl1->key );
+#endif /* } */
+
+ compareAopfirstpass=1;
+// pic16_emitpcode(POC_MOVLW, pic16_popGetLit(0x80));
+// pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(right), size));
+// pic16_emitpcode(POC_MOVWF, pct);
+
+// pic16_emitpcode(POC_MOVLW, pic16_popGetLit(BYTEofLONG(lit, size) + 0x80));
+ pic16_emitpcode(POC_MOVLW, pic16_popGetLit(BYTEofLONG(lit, size)));
+// compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, pct, pct2, tlbl);
+ compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, NULL, pct2, tlbl);
+
+ /* generic case */
+ while( size-- ) {
+// pic16_emitpcode(POC_MOVLW, pic16_popGetLit(0x80));
+// pic16_emitpcode(POC_MOVLW, pic16_popGetLit(0x0));
+// pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(right), size));
+// pic16_emitpcode(POC_MOVWF, pct);
+
+// pic16_emitpcode(POC_MOVLW, pic16_popGetLit(BYTEofLONG(lit, size) + 0x80));
+ pic16_emitpcode(POC_MOVLW, pic16_popGetLit(BYTEofLONG(lit, size) + 0x0));
+ compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, NULL, pct2, tlbl);
+// compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, pct, pct2, tlbl);
+// compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 0, pct, pct2, tlbl);
+ }
+// }
+
+ if(ifx)ifx->generated = 1;
+
+ if(AOP_SIZE(result)) {
+ pic16_emitpLabel(tlbl->key);
+ pic16_emitpLabel(falselbl->key);
+ pic16_outBitOp( result, pct2 );
+ } else {
+ pic16_emitpLabel(tlbl->key);
+ }
+ } else {
+
+
+ /* unsigned compare */
+ DEBUGpic16_emitcode ("; ***","%s: %d: unsigned compare", __FUNCTION__, __LINE__);
+
+ compareAopfirstpass=1;
+ while(size--) {
+
+ pic16_emitpcode(POC_MOVLW, pic16_popGetLit(BYTEofLONG(lit, size)));
+ compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, NULL, NULL, NULL);
+
+ }
+
+ if(ifx)ifx->generated = 1;
+
+
+ if(AOP_SIZE(result)) {
+ pic16_emitpLabel(falselbl->key);
+ pic16_outBitC( result );
+ }
+
+ }
+ } else {
+ /* compare registers */
+ DEBUGpic16_emitcode ("; ***","%s: %d: compare registers", __FUNCTION__, __LINE__);
+
+
+ if(sign) {
+ pCodeOp *pct, *pct2;
+
+ /* signed compare */
+ DEBUGpic16_emitcode ("; ***","%s: %d: signed compare", __FUNCTION__, __LINE__);
+
+ pct = pic16_popCopyReg(&pic16_pc_prodl); /* first temporary register */
+ pct2 = pic16_popCopyReg(&pic16_pc_prodh); /* second temporary register */
+ tlbl = newiTempLabel( NULL );
+
+ compareAopfirstpass=1;
+
+ size--;
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right), size));
+// pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x80));
+ pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x0));
+ pic16_emitpcode(POC_MOVWF, pct);
+
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left), size));
+// pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x80));
+ pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x0));
+
+ /* WREG already holds left + 0x80 */
+ compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, pct, pct2, tlbl);
+
+ while( size-- ) {
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right), size));
+// pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x80));
+ pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x0));
+ pic16_emitpcode(POC_MOVWF, pct);
+
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left), size));
+// pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x80));
+ pic16_emitpcode(POC_ADDLW, pic16_popGetLit(0x0));
+
+ /* WREG already holds left + 0x80 */
+ compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, pct, pct2, tlbl);
+// compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 0, pct, pct2, tlbl);
+ }
+
+ if(ifx)ifx->generated = 1;
+
+ if(AOP_SIZE(result)) {
+ pic16_emitpLabel(tlbl->key);
+ pic16_emitpLabel(falselbl->key);
+ pic16_outBitOp( result, pct2 );
+ } else {
+ pic16_emitpLabel(tlbl->key);
+ }
+
+ } else {
+ /* unsigned compare */
+ DEBUGpic16_emitcode ("; ***","%s: %d: unsigned compare", __FUNCTION__, __LINE__);
+
+ compareAopfirstpass=1;
+ while(size--) {
+
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left), size));
+ compareAop(&rFalseIfx, ifx, falselbl, right, size, result, sign, 1, NULL, NULL, NULL);
+
+ }
+
+ if(ifx)ifx->generated = 1;
+ if(AOP_SIZE(result)) {
+
+ pic16_emitpLabel(falselbl->key);
+ pic16_outBitC( result );
+ }
+
+ }
+ }
+}
+
+#else /* } else { */
/* new version of genCmp -- VR 20041012 */
static void genCmp (operand *left,operand *right,
// lit = (lit - 1) & mask;
right = left;
left = tmp;
- rFalseIfx.condition ^= 1;
+ rFalseIfx.condition ^= 1; /* reverse compare */
} else
if ((AOP_TYPE(left) == AOP_LIT)) {
/* float compares are handled by support functions */
/* if left & right are bit variables */
if (AOP_TYPE(left) == AOP_CRY &&
AOP_TYPE(right) == AOP_CRY ) {
+
pic16_emitcode("mov","c,%s",AOP(right)->aopu.aop_dir);
pic16_emitcode("anl","c,/%s",AOP(left)->aopu.aop_dir);
else willCheckCarry = 0;
/* Special cases */
- if((lit == 0) && (sign == 0)){
-
+ if((lit == 0) && (sign == 0)) {
+ /* unsigned compare to 0 */
+ DEBUGpic16_emitcode("; unsigned compare to 0","lit = 0x%x, sign=%d",lit,sign);
+
size--;
pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),size));
while(size)
pic16_emitpcode(POC_IORFW, pic16_popGet(AOP(right),--size));
genSkipz2(&rFalseIfx,0);
- if(ifx) ifx->generated = 1;
+ if(ifx)ifx->generated = 1;
return;
}
if(sign) {
/* signed comparisons to a literal byte */
+ DEBUGpic16_emitcode(";signed compare to literal","%d: lit = 0x%x, sign=%d",__LINE__, lit,sign);
int lp1 = (lit+1) & 0xff;
- DEBUGpic16_emitcode(";left lit","line = %d lit = 0x%x condition = %d",__LINE__,lit, rFalseIfx.condition);
+ DEBUGpic16_emitcode(";left lit","line = %d lit = 0x%x condition = %d lp1 = %i",__LINE__,lit, rFalseIfx.condition, lp1);
switch (lp1) {
case 0:
rFalseIfx.condition ^= 1;
}
} else {
/* unsigned comparisons to a literal byte */
+ DEBUGpic16_emitcode("; unsigned compare to literal","%d: lit = 0x%x, sign=%d",__LINE__, lit,sign);
switch(lit & 0xff ) {
+ /* special cases */
case 0:
pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right),0));
genSkipz2(&rFalseIfx,0);
rFalseIfx.condition ^= 1;
genSkipCond(&rFalseIfx,right,0,7);
break;
-
default:
pic16_emitpcode(POC_MOVLW, pic16_popGetLit((lit+1) & 0xff));
pic16_emitpcode(POC_SUBFW, pic16_popGet(AOP(right),0));
}
}
-#endif
+#endif /* } */
+
+
+#endif /* } */
/*-----------------------------------------------------------------*/
static bool is_LitOp(operand *op)
{
- return (AOP_TYPE(op) == AOP_LIT)
+ return ((AOP_TYPE(op) == AOP_LIT)
|| ( (AOP_TYPE(op) == AOP_PCODE)
&& ( (AOP(op)->aopu.pcop->type == PO_LITERAL)
- || (AOP(op)->aopu.pcop->type == PO_IMMEDIATE) ));
+ || (AOP(op)->aopu.pcop->type == PO_IMMEDIATE) )));
}
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
static bool is_LitAOp(asmop *aop)
{
- return (aop->type == AOP_LIT)
+ return ((aop->type == AOP_LIT)
|| ( (aop->type == AOP_PCODE)
&& ( (aop->aopu.pcop->type == PO_LITERAL)
- || (aop->aopu.pcop->type == PO_IMMEDIATE) ));
+ || (aop->aopu.pcop->type == PO_IMMEDIATE) )));
}
/*-----------------------------------------------------------------*/
static void genUnpackBits (operand *result, operand *left, char *rname, int ptype)
{
- int shCnt ;
- int rlen = 0 ;
- sym_link *etype;
- int offset = 0 ;
+ int shCnt ;
+ int rlen = 0 ;
+ sym_link *etype, *letype;
+ int blen=0, bstr=0;
+ int lbstr;
+ int offset = 0 ;
- DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- etype = getSpec(operandType(result));
+ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+ etype = getSpec(operandType(result));
+ letype = getSpec(operandType(left));
+
+// if(IS_BITFIELD(etype)) {
+ blen = SPEC_BLEN(etype);
+ bstr = SPEC_BSTR(etype);
+// }
+
+ lbstr = SPEC_BSTR( letype );
+
+#if 1
+ if((blen == 1) && (bstr < 8)) {
+ /* it is a single bit, so use the appropriate bit instructions */
+ DEBUGpic16_emitcode (";","%s %d optimize bit read",__FUNCTION__,__LINE__);
+
+ if(IS_BITFIELD(etype)/* && !IS_ITEMP(left)*/) {
+ pic16_emitpcode(POC_MOVFW, pic16_popGet( AOP(result), 0 ));
+ pic16_emitpcode(POC_BCF, pic16_popCopyGPR2Bit(pic16_popCopyReg(&pic16_pc_wreg), bstr));
+ } else {
+ pic16_emitpcode(POC_CLRF, pic16_popCopyReg(&pic16_pc_wreg));
+ }
+
+ if((ptype == POINTER) && (result)) {
+ /* workaround to reduce the extra lfsr instruction */
+ pic16_emitpcode(POC_BTFSC,
+ pic16_popCopyGPR2Bit(pic16_popGet(AOP(left), 0), bstr));
+ } else {
+ pic16_emitpcode(POC_BTFSC,
+ pic16_popCopyGPR2Bit(pic16_popCopyReg(&pic16_pc_indf0), bstr));
+ }
+
+
+ if(IS_BITFIELD(etype)) {
+ pic16_emitpcode(POC_BSF, pic16_popCopyGPR2Bit(pic16_popCopyReg(&pic16_pc_wreg), bstr));
+ } else {
+ pic16_emitpcode(POC_INCF, pic16_popCopyReg(&pic16_pc_wreg));
+ }
+
+ pic16_emitpcode(POC_MOVWF, pic16_popGet( AOP(result), 0 ));
+ return;
+ }
+
+#endif
/* the following call to pic16_loadFSR0 is temporary until
* optimization to handle single bit assignments is added
if(!IS_BITFIELD(retype))
pic16_loadFSR0( left ); // patch 10
} else {
- // set up FSR0 with address from left
- pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),0), pic16_popCopyReg(&pic16_pc_fsr0l))); // patch 10
- pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),1), pic16_popCopyReg(&pic16_pc_fsr0h))); // patch 10
+ if(!IS_BITFIELD(retype)) {
+ // set up FSR0 with address from left
+ pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),0), pic16_popCopyReg(&pic16_pc_fsr0l))); // patch 10
+ pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),1), pic16_popCopyReg(&pic16_pc_fsr0h))); // patch 10
+ }
}
}
// else
// rname = pic16_aopGet(AOP(left),0,FALSE,FALSE);
- pic16_aopOp (result,ic,FALSE);
+ pic16_aopOp (result,ic,FALSE);
+ DEBUGpic16_pic16_AopType(__LINE__, left, NULL, result);
+
/* if bitfield then unpack the bits */
if (IS_BITFIELD(retype))
genUnpackBits (result, left, NULL, POINTER);
int offset = 0 ;
int rLen = 0 ;
int blen, bstr ;
+ sym_link *retype;
char *l ;
DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
blen = SPEC_BLEN(etype);
bstr = SPEC_BSTR(etype);
+ retype = getSpec(operandType(right));
+
if(AOP_TYPE(right) == AOP_LIT) {
if((blen == 1) && (bstr < 8)) {
unsigned long lit;
pic16_emitpcode(POC_MOVLW, pic16_popGet(AOP(right), 0));
offset++;
} else
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right), offset++));
+ if(IS_BITFIELD(retype)
+ && (AOP_TYPE(right) == AOP_REG || AOP_TYPE(right) == AOP_DIR)
+ && (blen == 1)) {
+ int rblen, rbstr;
+
+ rblen = SPEC_BLEN( retype );
+ rbstr = SPEC_BSTR( retype );
+
+
+ if(IS_BITFIELD(etype)) {
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(result), 0));
+ pic16_emitpcode(POC_BCF, pic16_popCopyGPR2Bit(pic16_popCopyReg(&pic16_pc_wreg), bstr));
+ } else {
+ pic16_emitpcode(POC_CLRF, pic16_popCopyReg(&pic16_pc_wreg));
+ }
+
+ pic16_emitpcode(POC_BTFSC, pic16_popCopyGPR2Bit(pic16_popGet(AOP(right), 0), rbstr));
+
+ if(IS_BITFIELD(etype)) {
+ pic16_emitpcode(POC_BSF, pic16_popCopyGPR2Bit(pic16_popCopyReg(&pic16_pc_wreg), bstr));
+ } else {
+ pic16_emitpcode(POC_INCF, pic16_popCopyReg(&pic16_pc_wreg));
+ }
+
+ pic16_emitpcode(POC_MOVWF, pic16_popGet( AOP(result), 0));
+
+ return;
+ } else
+ pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(right), offset++));
/* if the bit lenth is less than or */
/* it exactly fits a byte then */
switch (p_type) {
case FPOINTER:
case POINTER:
- case GPOINTER:
pic16_emitpcode(POC_MOVFW, pic16_popCopyReg(&pic16_pc_indf0));
// pic16_emitcode ("mov","b,a");
// pic16_emitcode("mov","a,@%s",rname);
break;
+
+ case GPOINTER:
+ werror(W_POSSBUG2, __FILE__, __LINE__);
+ break;
+
}
#if 1
pic16_emitpcode(POC_ANDLW, pic16_popGetLit(
/* otherwise get a free pointer register */
DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
- if( (AOP_TYPE(result) == AOP_PCODE)
- && ((AOP(result)->aopu.pcop->type == PO_IMMEDIATE)
- || (AOP(result)->aopu.pcop->type == PO_DIR))) // patch 10
+// if( (AOP_TYPE(result) == AOP_PCODE)
+// && ((AOP(result)->aopu.pcop->type == PO_IMMEDIATE)
+// || (AOP(result)->aopu.pcop->type == PO_DIR))) // patch 10
+ if(is_LitAOp( AOP(result) ))
{
if(!IS_BITFIELD(resetype))
pic16_loadFSR0( result ); // patch 10
} else {
+ if(!IS_BITFIELD(resetype)) {
// set up FSR0 with address of result
pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(result),0), pic16_popCopyReg(&pic16_pc_fsr0l))); // patch 10
pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(result),1), pic16_popCopyReg(&pic16_pc_fsr0h))); // patch 10
+ }
}
}
DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__);
+// pic16_loadFSR0( result );
+
/* if bitfield then unpack the bits */
if (IS_BITFIELD(resetype)) {
genPackBits (resetype, result, right, NULL, POINTER);
// jump into the table
pic16_emitpcode(POC_MOVWF , pic16_popCopyReg(&pic16_pc_pcl));
- // this goto prevents the next label from being removed...
- pic16_emitpcode(POC_GOTO, jt_label);
- pic16_emitpLabel(jtab->key);
+ pic16_emitpLabelFORCE(jtab->key);
#endif
pic16_freeAsmop(IC_JTCOND(ic),NULL,ic,TRUE);
/* now generate the jump labels */
for (jtab = setFirstItem(IC_JTLABELS(ic)) ; jtab;
jtab = setNextItem(IC_JTLABELS(ic))) {
- pic16_emitcode("ljmp","%05d_DS_",jtab->key+100);
+// pic16_emitcode("ljmp","%05d_DS_",jtab->key+100);
pic16_emitpcode(POC_GOTO,pic16_popGetLabel(jtab->key));
}
operand *result = IC_RESULT(ic);
sym_link *ctype = operandType(IC_LEFT(ic));
sym_link *rtype = operandType(IC_RIGHT(ic));
+ sym_link *restype = operandType(IC_RESULT(ic));
operand *right = IC_RIGHT(ic);
int size, offset ;
DEBUGpic16_emitcode("; ***","%s %d",__FUNCTION__,__LINE__);
+
+
/* if they are equivalent then do nothing */
- if (operandsEqu(IC_RESULT(ic),IC_RIGHT(ic)))
- return ;
+// if (operandsEqu(IC_RESULT(ic),IC_RIGHT(ic)))
+// return ;
pic16_aopOp(right,ic,FALSE) ;
pic16_aopOp(result,ic,FALSE);
DEBUGpic16_pic16_AopType(__LINE__,NULL,right,result);
+
/* if the result is a bit */
if (AOP_TYPE(result) == AOP_CRY) {
goto release;
}
+ if(IS_BITFIELD(getSpec(restype))
+ && IS_BITFIELD(getSpec(rtype))) {
+ DEBUGpic16_emitcode("***", "%d casting a bit to another bit", __LINE__);
+ }
+
/* if they are the same size : or less */
if (AOP_SIZE(result) <= AOP_SIZE(right)) {
#define emitSETC pic16_emitpcode(POC_BSF, pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_C_BIT))
#define emitSETDC pic16_emitpcode(POC_BSF, pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_DC_BIT))
+#define emitTOGC pic16_emitpcode(POC_BTG, pic16_popCopyGPR2Bit(PCOP(&pic16_pc_status),PIC_C_BIT))
+
int pic16_getDataSize(operand *op);
void pic16_emitpcode(PIC_OPCODE poc, pCodeOp *pcop);
void pic16_emitpLabel(int key);
void dumpiCode(iCode *lic);
+int inWparamList(char *s);
+
+
#endif
if(carry_info) {
switch(lo) {
case 0:
- D_POS(">>> IMPROVED and compacted");
+ D_POS(">>> IMPROVED and compacted 0");
emitSKPNC;
pic16_emitpcode(POC_INCF, pic16_popGet(AOP(result),offset));
D_POS("<<< IMPROVED and compacted");
pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(result),offset));
break;
default:
- D_POS(">>> IMPROVED and compacted");
+ D_POS(">>> IMPROVED and compacted - default");
pic16_emitpcode(POC_MOVLW,pic16_popGetLit(lo));
pic16_emitpcode(POC_ADDWFC, pic16_popGet(AOP(result),offset));
D_POS("<<< IMPROVED and compacted");
pic16_emitDS(buf, ptype, p);
break;
default:
-// debugf("itype = %d\n", itype );
+ debugf("itype = %d\n", itype );
assert( 0 );
}
{ 0, USE_CRT, NULL, "use <crt-o> run-time initialization module"},
{ 0, "--no-crt", &pic16_options.no_crt, "do not link any default run-time initialization module"},
{ 0, "--gstack", &pic16_options.gstack, "trace stack pointer push/pop to overflow"},
- { 0, OFMSG_LRSUPPORT, NULL, "use support functions for local register store/restore"},
+// { 0, OFMSG_LRSUPPORT, NULL, "use support functions for local register store/restore"},
{ 0, NULL, NULL, NULL}
};
return TRUE;
}
+#if 0
if(ISOPT(OFMSG_LRSUPPORT)) {
pic16_options.opt_flags |= OF_LR_SUPPORT;
return TRUE;
}
+#endif
return FALSE;
}
pCodeOp *pic16_popCopyGPR2Bit(pCodeOp *pc, int bitval);
void pic16_pCodeRegMapLiveRanges(pBlock *pb);
void OptimizeLocalRegs(void);
+pCodeOp *pic16_popGet2p(pCodeOp *src, pCodeOp *dst);
char *dumpPicOptype(PIC_OPTYPE type);
pCodeOp *pic16_popGetLit2(int, pCodeOp *);
pCodeOp *pic16_popGetLit(int);
pCodeOp *pic16_popGetWithString(char *);
+extern int inWparamList(char *s);
/****************************************************************/
0, // second literal operand
POC_NOP,
PCC_NONE, // inCond
- PCC_NONE , // outCond
+ PCC_NONE, // outCond
PCI_MAGIC
};
for(pb = the_pFile->pbHead; pb; pb = pb->next) {
for(pc = pb->pcHead; pc; pc = pc->next) {
- if(isPCI(pc) || isASMDIR(pc))isize += PCI(pc)->isize;
+ if(isPCI(pc) || isPCAD(pc))isize += PCI(pc)->isize;
}
}
return (isize);
if(!pcop)
return 0;
+ if(!pcop->name)return 0;
+
if(pcop->type == PO_GPR_BIT && !strcmp(pcop->name, pic16_pc_status.pcop.name)) {
switch(PCORB(pcop)->bit) {
case PIC_C_BIT:
SAFE_snprintf(&s,&size,"%s",pcop->name);
}
return buffer;
+ case PO_GPR_BIT:
+ s = buffer;
+ if(PCORB(pcop)->subtype == PO_GPR_TEMP) {
+ SAFE_snprintf(&s, &size, "%s", pcop->name);
+ } else {
+ if(PCORB(pcop)->pcor.instance)
+ SAFE_snprintf(&s, &size, "(%s + %d)", pcop->name, PCORB(pcop)->pcor.instance);
+ else
+ SAFE_snprintf(&s, &size, "%s", pcop->name);
+ }
+ return (buffer);
default:
if(pcop->name) {
if(use_buffer) {
}
if(PCI(pc)->isBitInst) {
- if(PCI(pc)->pcop->type == PO_GPR_BIT) {
+ if(PCI(pc)->pcop->type != PO_GPR_BIT) {
if( (((pCodeOpRegBit *)(PCI(pc)->pcop))->inBitSpace) )
SAFE_snprintf(&s,&size,"(%s >> 3), (%s & 7)",
PCI(pc)->pcop->name ,
PCI(pc)->pcop->name );
else
- SAFE_snprintf(&s,&size,"%s,%d", pic16_get_op_from_instruction(PCI(pc)),
+ SAFE_snprintf(&s,&size,"%s,%d", pic16_get_op_from_instruction(PCI(pc)),
+// (((pCodeOpRegBit *)(PCI(pc)->pcop))->pcor.instance),
(((pCodeOpRegBit *)(PCI(pc)->pcop))->bit ));
+
} else if(PCI(pc)->pcop->type == PO_GPR_BIT) {
SAFE_snprintf(&s,&size,"%s,%d", pic16_get_op_from_instruction(PCI(pc)),PCORB(PCI(pc)->pcop)->bit);
}else
}
}
- fprintf(of, "; info ==>");
- switch(((pCodeInfo *)pc)->type) {
- case INF_OPTIMIZATION:
- fprintf(of, " [optimization] %s\n", OPT_TYPE_STR[ PCOO(PCINF(pc)->oper1)->type ]);
- break;
- case INF_LOCALREGS:
- fprintf(of, " [localregs] %s\n", LR_TYPE_STR[ PCOLR(PCINF(pc)->oper1)->type ]);
- break;
- }; break;
+ if(pic16_pcode_verbose) {
+ fprintf(of, "; info ==>");
+ switch(((pCodeInfo *)pc)->type) {
+ case INF_OPTIMIZATION:
+ fprintf(of, " [optimization] %s\n", OPT_TYPE_STR[ PCOO(PCINF(pc)->oper1)->type ]);
+ break;
+ case INF_LOCALREGS:
+ fprintf(of, " [localregs] %s\n", LR_TYPE_STR[ PCOLR(PCINF(pc)->oper1)->type ]);
+ break;
+ }
+ };
+
+ break;
case PC_INLINE:
fprintf(of,"%s\n", ((pCodeComment *)pc)->comment);
int bank = -1;
if(!isPCI(pc))
- return -1;
+ return 0;
if( PCI(pc)->op == POC_MOVLB ||
(( (reg = pic16_getRegFromInstruction(pc)) != NULL) && isBSR_REG(reg))) {
bank = PCOL(pc)->lit;
}
- return bank;
+ return 1;
}
if(!pc || !pcflow)
return 0;
- if(!isPCI(pc) || !PCI(pc)->pcflow || !isPCFL(pcflow) )
+ if((!isPCI(pc) && !isPCAD(pc)) || !PCI(pc)->pcflow || !isPCFL(pcflow) )
return 0;
if( PCI(pc)->pcflow->pc.seq == pcflow->seq)
pCodeOp *pic16_popCopyGPR2Bit(pCodeOp *pc, int bitval)
{
- pCodeOp *pcop;
+ pCodeOp *pcop=NULL;
+
+// fprintf(stderr, "%s:%d pc type: %s\tname: %s\n", __FILE__, __LINE__, pic16_pCodeOpType(pc), pc->name);
-// fprintf(stderr, "%s:%d pc type: %s\n", __FILE__, __LINE__, pic16_pCodeOpType(pc));
- pcop = pic16_newpCodeOpBit(pc->name, bitval, 0, pc->type);
+ if(pc->name) {
+ pcop = pic16_newpCodeOpBit(pc->name, bitval, 0, pc->type);
+ } else {
+ if(PCOR(pc)->r)pcop = pic16_newpCodeOpBit(PCOR(pc)->r->name, bitval, 0, pc->type);
+ }
+
+ assert(pcop != NULL);
if( !( (pcop->type == PO_LABEL) ||
(pcop->type == PO_LITERAL) ||
(pcop->type == PO_STR) ))
PCOR(pcop)->r = PCOR(pc)->r; /* This is dangerous... */
PCOR(pcop)->r->wasUsed = 1;
+ PCOR(pcop)->instance = PCOR(pc)->instance;
return pcop;
}
pcstart->next = pcend;
pcend->prev = pcstart;
- pic16_pCodeInsertAfter(pcstart, (pct=pic16_newpCode(POC_LFSR, pic16_popGetLit2(0, pic16_popGetWithString(r->name))))); pc = pct;
+ pc = pcstart;
+// if(!entry) {
+// pic16_pCodeInsertAfter(pc, pct = pic16_newpCode(POC_MOVFF, pic16_popGet2p(
+// pic16_popCopyReg(&pic16_pc_fsr0l), pic16_popCopyReg(&pic16_pc_fsr2l)))); pc = pct;
+// }
+
+ pic16_pCodeInsertAfter(pc, pct=pic16_newpCode(POC_LFSR, pic16_popGetLit2(0, pic16_popGetWithString(r->name)))); pc = pct;
pic16_pCodeInsertAfter(pc, pct=pic16_newpCode(POC_MOVLW, pic16_popGetLit( count ))); pc = pct;
- pic16_pCodeInsertAfter(pc, pct=pic16_newpCode(POC_CALL, pic16_popGetWithString( fname[ (entry==1?0:1) ] )));
+ pic16_pCodeInsertAfter(pc, pct=pic16_newpCode(POC_CALL, pic16_popGetWithString( fname[ (entry==1?0:1) ] ))); pc = pct;
+
+// if(!entry) {
+// pic16_pCodeInsertAfter(pc, pct = pic16_newpCode(POC_MOVFF, pic16_popGet2p(
+// pic16_popCopyReg(&pic16_pc_fsr2l), pic16_popCopyReg(&pic16_pc_fsr0l)))); pc = pct;
+// }
+
{
symbol *sym;
}
-
/*-----------------------------------------------------------------*/
/* OptimizeLocalRegs - turn sequence of MOVFF instructions for */
/* local registers to a support function call */
regs *r, *lastr=NULL, *firstr=NULL;
pCode *pcstart=NULL, *pcend=NULL;
int inEntry=0;
+ char *curFunc=NULL;
/* Overview:
* local_regs begin mark
inRegCount = regCount = 0;
firstr = lastr = NULL;
for(pc = pb->pcHead; pc; pc = pc->next) {
+
+ /* hold current function name */
+ if(pc && isPCF(pc))curFunc = PCF(pc)->fname;
+
if(pc && (pc->type == PC_INFO)) {
pci = PCINF(pc);
pcend = pc; //pic16_findPrevInstruction(pc->prev);
#if 1
- if(regCount>2) {
- pic16_convertLocalRegs2Support(pcstart, pcend, regCount,
- firstr, inEntry);
+ if(curFunc && inWparamList(curFunc+1)) {
+ fprintf(stderr, "sdcc: %s: warning: disabling lr-support for functionn %s\n",
+ filename, curFunc);
+ } else {
+ if(regCount>2) {
+ pic16_convertLocalRegs2Support(pcstart, pcend, regCount,
+ firstr, inEntry);
+ }
}
#endif
firstr = lastr = NULL;
#define isPCL(x) ((PCODE(x)->type == PC_LABEL))
#define isPCW(x) ((PCODE(x)->type == PC_WILD))
#define isPCCS(x) ((PCODE(x)->type == PC_CSOURCE))
-#define isASMDIR(x) ((PCODE(x)->type == PC_ASMDIR))
+#define isPCAD(x) ((PCODE(x)->type == PC_ASMDIR))
#define isCALL(x) ((isPCI(x)) && (PCI(x)->op == POC_CALL))
#define isSTATUS_REG(r) ((r)->pc_type == PO_STATUS)
int pic16_isPCinFlow(pCode *pc, pCode *pcflow);
struct regs * pic16_getRegFromInstruction(pCode *pc);
struct regs * pic16_getRegFromInstruction2(pCode *pc);
+char *pic16_get_op(pCodeOp *pcop,char *buffer, size_t size);
+char *pic16_get_op2(pCodeOp *pcop,char *buffer, size_t size);
+char *dumpPicOptype(PIC_OPTYPE type);
extern void pic16_pcode_test(void);
extern int pic16_debug_verbose;
#ifndef debugf
//#define debugf(frm, rest...) _debugf(__FILE__, __LINE__, frm, rest)
-#define debugf(frm, rest) _debug(__FILE__, __LINE__, frm, rest)
+#define debugf(frm, rest) _debugf(__FILE__, __LINE__, frm, rest)
#endif
extern void _debugf(char *f, int l, char *frm, ...);
int pic16_getpCodePeepCommand(char *cmd);
void pic16_pBlockMergeLabels(pBlock *pb);
char *pic16_pCode2str(char *str, int size, pCode *pc);
-char *pic16_get_op( pCodeOp *pcop,char *buf,int buf_size);
+//char *pic16_get_op(pCodeOp *pcop,char *buf, size_t buf_size);
pCodeOp *pic16_popCombine2(pCodeOp *, pCodeOp *, int);
extern pCodeInstruction *pic16Mnemonics[];
#endif
-// fprintf(stderr, "trying to get first operand from pCode reg= %s\n", reg->name);
+// fprintf(stderr, "%s:%d: trying to get first operand from pCode reg= %s\n", __FILE__, __LINE__, reg->name);
addSetIfnotP(& (PCFL(pcfl)->registers), reg);
if((PCC_REGISTER | PCC_LITERAL) & PCI(pc)->inCond)
if(PCI(pc)->is2MemOp) {
reg = pic16_getRegFromInstruction2(pc);
if(reg) {
-// fprintf(stderr, "trying to get second operand from pCode reg= %s\n", reg->name);
+// fprintf(stderr, "%s:%d: trying to get second operand from pCode reg= %s\n", __FILE__, __LINE__, reg->name);
addSetIfnotP(& (PCFL(pcfl)->registers), reg);
if((PCC_REGISTER | PCC_LITERAL) & PCI(pc)->inCond)
movf %1,w
}
-replace restart {
- movff %1,%1
-} by {
- ; peep 12 - Removed redundant move
-}
-
#define STRCASECMP strcasecmp
#endif
+#ifndef debugf
+#define debugf(frm, rest) _debugf(__FILE__, __LINE__, frm, rest)
+#endif
+void _debugf(char *f, int l, char *frm, ...);
+
+
//#define USE_ONSTACK
* are used to pass and return parameters */
-
+int _inRegAllocator=0; /* flag that marks whther allocReg happens while
+ * inside the register allocator function */
+
static void spillThis (symbol *);
int pic16_ralloc_debug = 0;
return NULL;
}
+
+
/*-----------------------------------------------------------------*/
/* allocReg - allocates register of given type */
/*-----------------------------------------------------------------*/
{
regs * reg=NULL;
+#define MAX_P16_NREGS 6
+
+
#if 0
if(dynrIdx > pic16_nRegs)
return NULL;
reg = regFindFree( pic16_dynAllocRegs );
if(reg) {
-// fprintf(stderr, "%s: found FREE register %s\n", __FILE__, reg->name);
+// fprintf(stderr, "%s: [%s] found FREE register %s, rIdx: %d\n", __FILE__, (_inRegAllocator)?"ralloc":"", reg->name, reg->rIdx);
}
if(!reg) {
reg = newReg(REG_GPR, PO_GPR_TEMP, dynrIdx++, NULL, 1, 0, NULL);
+// fprintf(stderr, "%s: [%s] allocating NEW register %s, rIdx: %d\n", __FILE__, (_inRegAllocator)?"ralloc":"", reg->name, reg->rIdx);
+
+#if 1
+ if(_inRegAllocator && (dynrIdx > MAX_P16_NREGS)) {
+// debugf("allocating more registers than available\n", 0);
+// return (NULL);
+ }
+#endif
+
// addSet(&pic16_dynAllocRegs, reg);
}
/* else we assign registers to it */
_G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
- debugLog (" %d - nRegs: %d\n", __LINE__, sym->nRegs);
if(debugF)
bitVectDebugOn(_G.regAssigned, debugF);
if (IS_AGGREGATE (sym->type) || sym->isptr)
sym->type = aggrToPtr (sym->type, FALSE);
debugLog (" %d - no reg needed - used as a return\n", __LINE__);
-
continue;
}
/* registers for true symbols we will */
/* see how things go */
sym->nRegs = 0;
+
}
}
debugLog ("\nebbs before optimizing:\n");
dumpEbbsToDebug (ebbs, count);
+ _inRegAllocator = 1;
+
setToNull ((void *) &_G.funcrUsed);
pic16_ptrRegReq = _G.stackExtend = _G.dataExtend = 0;
debugLog ("ebbs after optimizing:\n");
dumpEbbsToDebug (ebbs, count);
+ _inRegAllocator = 0;
genpic16Code (ic);
/* mark all registers as free */
pic16_freeAllRegs ();
+
debugLog ("leaving\n<><><><><><><><><><><><><><><><><>\n");
debugLogClose ();
return;