diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e7683df --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*~ +*.bak diff --git a/README.md b/README.md new file mode 100644 index 0000000..ce3c3a8 --- /dev/null +++ b/README.md @@ -0,0 +1,132 @@ +# Windows tools for using sduino + +This collection of files helps to use the +[sdunio](https://github.com/tenbaht/sduino) environment on Windows systems. + +Windows is lacking all the needed tools, a package system to +install them and even a file system concept where to store them. For +convinience, I collected the bare minimum of needed tools here. + +I didn't write any of the tools contained in this repository. The only +purpose of this compilation is to save you some work downloading them +separately (which I still recommand over using these older versions). + + +## Usage + +Download the repostory and copy the directory tree into your sduino +directory. Add the sduino/tools/bin directory to your path or move the files +in there to a directory that is already in your path. + + + +## The individual pieces + +All the tools in the convinience package are 32 bit. If you need the 64 bit +versions you might have to collect them yourself. + +You need SDCC, `make` with some basic tools and maybe `stm8flash`. Get SDCC +from the project website. `make` is a standard tool included in either +MinGW/Msys or cygwin. Both are fine, MinGW/Msys is smaller. `stm8flash` from +the [stm8flash repository](https://github.com/vdudouyt/stm8flash). + + + +#### SDCC + +1. Download the lastest snapshot build from http://sdcc.sourceforge.net/snap.php +2. unzip into c:\sdcc (use a path name without whitespace) + +You only need support for the stm8. You can safely delete all the files +related to the pic1x CPUs (that safes more than 90% of the used disk space +and leaves only 20MB out of 240MB) + + +#### MinGW + +[MinGW/MSys](http://www.mingw.org/wiki/MSYS) and +[cygwin](https://www.cygwin.com/) are both fine. cygwin aims to be an almost +complete POSIX environment (which is nice, but we don't need it here). MinGW +wants to be more compact and works with the native Windows API. That is good +enough for this purpose. + +1. Check the + [MinGW Installation Notes](http://www.mingw.org/wiki/Getting_Started) +2. Download + [mingw-get-setup.exe](https://sourceforge.net/projects/mingw/files/Installer/) + from https://sourceforge.net/projects/mingw/files/Installer/ +3. Start it. You can safely deactivate the graphical option. +4. Add this at the end to your path: `;c:\mingw\bin;c:\mingw\msys\1.0\bin` + (follow the instructions in "Environment Setting" on the [Installation + Notes page[(http://www.mingw.org/wiki/Getting_Started)) +5. Open a command line and install the package msys-base by issuing this + command: `mingw-get install msys-base` +6. Now `ls` or `make` should work. + +For efficiency, the Makefile is configured to use dash instead of bash as a +shell. `egrep` is replaced by `grep -E`. The bare minimum of tools you will +need to run the Arduino.mk makefile: + + dash make + awk cat cut expr grep head ls mkdir sed tr uname which + + + + +#### stm8flash + +A precompiled windows binary was in the stm8flash repository for a while but +got removed at one point. I used an +[old version](https://github.com/vdudouyt/stm8flash/raw/39b1a9ec1dd26030065c3e476fc3b7b89626e21d/stm8flash.exe) +of the file. You might prefer to compile your own version from the +[stm8flash repository](https://github.com/vdudouyt/stm8flash) using either +MinGW or cygwin. For compiling, you will need the libusb windows binary: +http://libusb.info/ (I used the MinGW32 dll) + + + + +## General problems using Windows + +It works, but using the Arduino.mk makefile with Windows is slow. **Very** +slow. Painfully slow. Compiling-the-Blink-example-takes-about-40-seconds +kind of slow. Yes, seriously. No kidding. 40 seconds. Measured on a 3GHz +machine with 4GB RAM. + +There is no easy fix, the underlying problem is a fundamental one. It is not +about the compilation itself, it is the way Makefiles are written and +executed. The whole concept relies on forking subprocesses for all the shell +calls. Unfortunately, there is nothing like a fork in Windows and to work +around that is painfully slow. + +It would be great if somebody could manage to modify the original Arduino +build system to support non-C++-builds. Or to integrate it somehow into the +STVD IDE. Or replace the painfully slow parameter checking part of the +makefile (that causes the majority of forking) by a single shell script that +gets called by the makefile and delivers the results in no time. Or use +[cmake](www.cmake.org). Or whatever. + +Until than the least annoying way out might be using a virtual machine +running a simple Linux system. Ubuntu Mate or a basic Debian install for +example. Virtual Box is great for this purpose and freely available. + + + +## Possible improvements + +### All-inclusive packages + +One of the big convinience points of the Arduino project are the +easy-to-install all-inclusive packages without any external dependencies. +They don't require any prior knowledge to set up a full cross-compiler tool +chain. + +Something like that would be very nice for the STM8 as well, but I didn't go +that far. You still have to do some work yourself. You definitly need the +compiler SDCC. `stm8flash` is a simple tool to transfer the compiled program +to the CPU, but any other flash tool supporting the SWIM protocol will do. +The build process is controlled by `make`. It is a standard tool with any +UNIX system but available for windows as well. + +Alternative ways of controlling the build process exist, but then you are +on your own to set it up. diff --git a/hardware/tools/stm8/bin/as2gbmap.cmd b/hardware/tools/stm8/bin/as2gbmap.cmd new file mode 100644 index 0000000..3b5fdf8 --- /dev/null +++ b/hardware/tools/stm8/bin/as2gbmap.cmd @@ -0,0 +1,178 @@ +@setlocal enabledelayedexpansion && python -x "%~f0" %* & exit /b !ERRORLEVEL! +#!/usr/bin/env python + +# as2gbmap - asxxxx to gb map file converter +# +# Copyright (c) 2010 Borut Razem +# +# This file is part of sdcc. +# +# This software is provided 'as-is', without any express or implied +# warranty. In no event will the authors be held liable for any damages +# arising from the use of this software. +# +# Permission is granted to anyone to use this software for any purpose, +# including commercial applications, and to alter it and redistribute it +# freely, subject to the following restrictions: +# +# 1. The origin of this software must not be misrepresented; you must not +# claim that you wrote the original software. If you use this software +# in a product, an acknowledgment in the product documentation would be +# appreciated but is not required. +# 2. Altered source versions must be plainly marked as such, and must not be +# misrepresented as being the original software. +# 3. This notice may not be removed or altered from any source distribution. +# +# Borut Razem +# borut.razem@siol.net + +import sys +import os +import re +from optparse import OptionParser +import operator + +def main(): + '''asxxxx to gb map file converter''' + usage = "usage: %prog [options] [ []]" + parser = OptionParser(usage = usage, version = "1.0") + parser.set_defaults(no_gmb = False) + parser.add_option("-j", "--no$gmb", action = "store_true", dest = "no_gmb", help = "generate no$gmb symbol file (default: rrgb)") + (options, args) = parser.parse_args() + + if len(args) > 0 and args[0] != "-": + try: + fin = open(args[0], "r") + except IOError, (errno, strerror): + print >> sys.stderr, "%s: can't open %s: %s" % (os.path.basename(sys.argv[0]), args[0], strerror) + return 1 + else: + fin = sys.stdin + + if len(args) > 1 and args[1] != "-": + try: + fout = open(args[1], "w") + except IOError, (errno, strerror): + print >> sys.stderr, "%s: can't create %s: %s" % (os.path.basename(sys.argv[1]), args[1], strerror) + return 1 + else: + fout = sys.stdout; + + areas = [] + modules = [] + libraries = [] + ubads = [] + + radix = 'HEX' + state = None + area = None + + # process asxxxx map file + for line in fin: + if re.match(r"^Hexadecimal$", line): + radix = 'HEX'; + continue + + if re.match(r"^Area +Addr +Size +Decimal +Bytes +\(Attributes\)$", line): + line = fin.next() + if re.match(r"^[- ]+$", line): + line = fin.next() + m = re.match(r"^([^ ]+) +([0-9A-Fa-f]{4}) +([0-9A-Fa-f]{4}) += +\d+\. +\w+ +\(([^\)]+)\)$", line) + if m: + if area: + if m.group(1) != area['area']: + areas.append(area) + area = {'area': m.group(1), 'radix': radix, 'base': int(m.group(2), 16), 'size': int(m.group(3), 16), 'attrib': m.group(4).replace(',', ' '), 'globals': []} + else: + area = {'area': m.group(1), 'radix': radix, 'base': int(m.group(2), 16), 'size': int(m.group(3), 16), 'attrib': m.group(4).replace(',', ' '), 'globals': []} + state = 'IN_AREA' + continue + + m = re.match(r"^ +([0-9A-Fa-f]{4}) +([^ ]+) +$", line) + if state == 'IN_AREA' and m: + area['globals'].append({'value': int(m.group(1), 16), 'global': m.group(2)}) + continue + + m = re.match(r"Files Linked +\[ module\(s\) \]$", line) + if m: + state = 'IN_MODULES' + continue + + m = re.match(r"Libraries Linked +\[ object file \]$", line) + if m: + state = 'IN_LIBRARIES' + continue + + m = re.match(r"User Base Address Definitions$", line) + if m: + state = 'IN_UBAD' + continue + + m = re.match(r"^([^ ]+) +\[ ([^ ]*) \]$", line) + if m: + if state == 'IN_MODULES': + modules.append({'file': m.group(1), 'name': m.group(2)}) + continue + + if state == 'IN_LIBRARIES': + libraries.append({'library': m.group(1), 'module': m.group(2)}) + continue + + m = re.match(r"^([^ ]+) += +0x([0-9A-Fa-f]{4})$", line) + if state == 'IN_UBAD' and m: + ubads.append({'symbol': m.group(1), 'value': m.group(2)}) + continue + + if area: + areas.append(area) + + + if options.no_gmb: + # generate no$gmp map file + print >> fout, '; no$gmb format .sym file' + print >> fout, '; Generated automagically by %s' % os.path.basename(sys.argv[0]) + for e in areas: + print >> fout, '; Area: %s' % e['area'] + if e['globals']: + e['globals'].sort(key = operator.itemgetter('value')) + for g in e['globals']: + if g['global'][0:3] != 'l__': + if g['value'] > 0x7FFF: + print >> fout, '00:%04X %s' % (g['value'], g['global']) + else: + print >> fout, '%02X:%04X %s' % (g['value'] // 16384, g['value'], g['global']) + else: + # generate rrgb map file + for e in areas: + print >> fout, 'AREA %s' % e['area'] + print >> fout, '\tRADIX %s' % e['radix'] + print >> fout, '\tBASE %04X' % e['base'] + print >> fout, '\tSIZE %04X' % e['size'] + print >> fout, '\tATTRIB %s' % e['attrib'] + if e['globals']: + e['globals'].sort(key = operator.itemgetter('value')) + print >> fout, '\tGLOBALS' + for g in e['globals']: + print >> fout, '\t\t%s\t%04X' % (g['global'], g['value']) + + if modules: + print >> fout, 'MODULES' + for m in modules: + print >> fout, '\tFILE %s' % m['file'] + if m['name']: + print >> fout, '\t\tNAME %s' % m['name'] + + if libraries: + print >> fout, 'LIBRARIES' + for m in libraries: + print >> fout, '\tLIBRARY %s' % m['library'] + print >> fout, '\t\tMODULE %s' % m['module'] + + if ubads: + print >> fout, 'USERBASEDEF' + for m in ubads: + print >> fout, '\t%s = 0x%04X' % (m['symbol'], int(m['value'], 16)) + return 0 + +if __name__ == '__main__': + sys.exit(main()) diff --git a/hardware/tools/stm8/bin/libusb-1.0.dll b/hardware/tools/stm8/bin/libusb-1.0.dll new file mode 100644 index 0000000..a2e99dd Binary files /dev/null and b/hardware/tools/stm8/bin/libusb-1.0.dll differ diff --git a/hardware/tools/stm8/bin/makebin.exe b/hardware/tools/stm8/bin/makebin.exe new file mode 100644 index 0000000..082a14b Binary files /dev/null and b/hardware/tools/stm8/bin/makebin.exe differ diff --git a/hardware/tools/stm8/bin/packihx.exe b/hardware/tools/stm8/bin/packihx.exe new file mode 100644 index 0000000..d14e885 Binary files /dev/null and b/hardware/tools/stm8/bin/packihx.exe differ diff --git a/hardware/tools/stm8/bin/sdar.exe b/hardware/tools/stm8/bin/sdar.exe new file mode 100644 index 0000000..9cf2406 Binary files /dev/null and b/hardware/tools/stm8/bin/sdar.exe differ diff --git a/hardware/tools/stm8/bin/sdas390.exe b/hardware/tools/stm8/bin/sdas390.exe new file mode 100644 index 0000000..fb0a2c7 Binary files /dev/null and b/hardware/tools/stm8/bin/sdas390.exe differ diff --git a/hardware/tools/stm8/bin/sdas6808.exe b/hardware/tools/stm8/bin/sdas6808.exe new file mode 100644 index 0000000..866ad76 Binary files /dev/null and b/hardware/tools/stm8/bin/sdas6808.exe differ diff --git a/hardware/tools/stm8/bin/sdas8051.exe b/hardware/tools/stm8/bin/sdas8051.exe new file mode 100644 index 0000000..e710112 Binary files /dev/null and b/hardware/tools/stm8/bin/sdas8051.exe differ diff --git a/hardware/tools/stm8/bin/sdasgb.exe b/hardware/tools/stm8/bin/sdasgb.exe new file mode 100644 index 0000000..217aeb7 Binary files /dev/null and b/hardware/tools/stm8/bin/sdasgb.exe differ diff --git a/hardware/tools/stm8/bin/sdasrab.exe b/hardware/tools/stm8/bin/sdasrab.exe new file mode 100644 index 0000000..76ea102 Binary files /dev/null and b/hardware/tools/stm8/bin/sdasrab.exe differ diff --git a/hardware/tools/stm8/bin/sdasstm8.exe b/hardware/tools/stm8/bin/sdasstm8.exe new file mode 100644 index 0000000..df0d37d Binary files /dev/null and b/hardware/tools/stm8/bin/sdasstm8.exe differ diff --git a/hardware/tools/stm8/bin/sdasz80.exe b/hardware/tools/stm8/bin/sdasz80.exe new file mode 100644 index 0000000..470f892 Binary files /dev/null and b/hardware/tools/stm8/bin/sdasz80.exe differ diff --git a/hardware/tools/stm8/bin/sdcc.exe b/hardware/tools/stm8/bin/sdcc.exe new file mode 100644 index 0000000..55f4463 Binary files /dev/null and b/hardware/tools/stm8/bin/sdcc.exe differ diff --git a/hardware/tools/stm8/bin/sdcclib.exe b/hardware/tools/stm8/bin/sdcclib.exe new file mode 100644 index 0000000..3102c37 Binary files /dev/null and b/hardware/tools/stm8/bin/sdcclib.exe differ diff --git a/hardware/tools/stm8/bin/sdcpp.exe b/hardware/tools/stm8/bin/sdcpp.exe new file mode 100644 index 0000000..c674f6d Binary files /dev/null and b/hardware/tools/stm8/bin/sdcpp.exe differ diff --git a/hardware/tools/stm8/bin/sdld.exe b/hardware/tools/stm8/bin/sdld.exe new file mode 100644 index 0000000..7042c75 Binary files /dev/null and b/hardware/tools/stm8/bin/sdld.exe differ diff --git a/hardware/tools/stm8/bin/sdld6808.exe b/hardware/tools/stm8/bin/sdld6808.exe new file mode 100644 index 0000000..2f8b1fb Binary files /dev/null and b/hardware/tools/stm8/bin/sdld6808.exe differ diff --git a/hardware/tools/stm8/bin/sdldgb.exe b/hardware/tools/stm8/bin/sdldgb.exe new file mode 100644 index 0000000..2f8b1fb Binary files /dev/null and b/hardware/tools/stm8/bin/sdldgb.exe differ diff --git a/hardware/tools/stm8/bin/sdldstm8.exe b/hardware/tools/stm8/bin/sdldstm8.exe new file mode 100644 index 0000000..2f8b1fb Binary files /dev/null and b/hardware/tools/stm8/bin/sdldstm8.exe differ diff --git a/hardware/tools/stm8/bin/sdldz80.exe b/hardware/tools/stm8/bin/sdldz80.exe new file mode 100644 index 0000000..2f8b1fb Binary files /dev/null and b/hardware/tools/stm8/bin/sdldz80.exe differ diff --git a/hardware/tools/stm8/bin/sdnm.exe b/hardware/tools/stm8/bin/sdnm.exe new file mode 100644 index 0000000..0f18c7e Binary files /dev/null and b/hardware/tools/stm8/bin/sdnm.exe differ diff --git a/hardware/tools/stm8/bin/sdobjcopy.exe b/hardware/tools/stm8/bin/sdobjcopy.exe new file mode 100644 index 0000000..bb6055e Binary files /dev/null and b/hardware/tools/stm8/bin/sdobjcopy.exe differ diff --git a/hardware/tools/stm8/bin/sdranlib.exe b/hardware/tools/stm8/bin/sdranlib.exe new file mode 100644 index 0000000..119385b Binary files /dev/null and b/hardware/tools/stm8/bin/sdranlib.exe differ diff --git a/hardware/tools/stm8/bin/stm8flash.exe b/hardware/tools/stm8/bin/stm8flash.exe new file mode 100644 index 0000000..3996700 Binary files /dev/null and b/hardware/tools/stm8/bin/stm8flash.exe differ diff --git a/hardware/tools/stm8/bin64/libusb-1.0.dll b/hardware/tools/stm8/bin64/libusb-1.0.dll new file mode 100644 index 0000000..1330ae4 Binary files /dev/null and b/hardware/tools/stm8/bin64/libusb-1.0.dll differ diff --git a/hardware/tools/stm8/include/asm/stm8/features.h b/hardware/tools/stm8/include/asm/stm8/features.h new file mode 100644 index 0000000..b701e15 --- /dev/null +++ b/hardware/tools/stm8/include/asm/stm8/features.h @@ -0,0 +1,45 @@ +/*------------------------------------------------------------------------- + features.h - STM8 specific features. + + Copyright (C) 2001, Michael Hope, 2013, Philipp Klaus Krause + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#ifndef __SDCC_ASM_STM8_FEATURES_H +#define __SDCC_ASM_STM8_FEATURES_H 1 + +#define _REENTRANT +#define _CODE +#define _AUTOMEM +#define _STATMEM + +#define _SDCC_MANGLES_SUPPORT_FUNS 1 +#define _SDCC_Z80_STYLE_LIB_OPT 1 + +#define _SDCC_PORT_PROVIDES_MEMCPY 0 +#define _SDCC_PORT_PROVIDES_STRCMP 0 +#define _SDCC_PORT_PROVIDES_STRCPY 0 + +#endif + diff --git a/hardware/tools/stm8/include/assert.h b/hardware/tools/stm8/include/assert.h new file mode 100644 index 0000000..6c612c4 --- /dev/null +++ b/hardware/tools/stm8/include/assert.h @@ -0,0 +1,46 @@ +/*------------------------------------------------------------------------- + assert.h - header file for assert ANSI routine + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#undef assert + +#ifdef NDEBUG + +/* Debugging disabled -- do not evaluate assertions. */ +#define assert(x) ((void)0) + +#else + +/* Debugging enabled -- verify assertions at run time. */ +void _assert(char *, const char *, unsigned int); +#define assert(x) ((x) == 0 ? _assert(#x, __FILE__, __LINE__):(void)0) + +#if __STDC_VERSION__ >= 201112L +#define static_assert _Static_assert +#endif + +#endif diff --git a/hardware/tools/stm8/include/ctype.h b/hardware/tools/stm8/include/ctype.h new file mode 100644 index 0000000..236f3ad --- /dev/null +++ b/hardware/tools/stm8/include/ctype.h @@ -0,0 +1,96 @@ +/*------------------------------------------------------------------------- + ctype.h + + Philipp Klaus Krause, philipp@informatik.uni-frankfurt.de 2013 + + (c) 2013 Goethe-Universität Frankfurt + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#ifndef __SDCC_CTYPE_H +#define __SDCC_CTYPE_H 1 + +extern int isalnum (int c); +extern int isalpha (int c); +extern int iscntrl (int c); +extern int isgraph (int c); +extern int isprint (int c); +extern int ispunct (int c); +extern int isspace (int c); +extern int isalnum (int c); +extern int isalnum (int c); +extern int isxdigit (int c); + +extern int tolower (int c); +extern int toupper (int c); + +/* Provide inline versions for the most used functions for efficiency */ +#if __STDC_VERSION__ >= 199901L + +inline int isblank (int c) +{ + return ((unsigned char)c == ' ' || (unsigned char)c == '\t'); +} + +#ifdef EOF +_Static_assert(!((unsigned char)EOF == ' ' || (unsigned char)EOF == '\t'), "EOF out of range - "); +#endif + +inline int isdigit (int c) +{ + return ((unsigned char)c >= '0' && (unsigned char)c <= '9'); +} + +#ifdef EOF +_Static_assert(!((unsigned char)EOF >= '0' && (unsigned char)EOF <= '9'), "EOF out of range - "); +#endif + +inline int islower (int c) +{ + return ((unsigned char)c >= 'a' && (unsigned char)c <= 'z'); +} + +#ifdef EOF +_Static_assert(!((unsigned char)EOF >= 'a' && (unsigned char)EOF <= 'z'), "EOF out of range - "); +#endif + +inline int isupper (int c) +{ + return ((unsigned char)c >= 'A' && (unsigned char)c <= 'Z'); +} + +#ifdef EOF +_Static_assert(!((unsigned char)EOF >= 'A' && (unsigned char)EOF <= 'Z'), "EOF out of range - "); +#endif + +#else + +extern int isblank (int c); +extern int isdigit (int c); +extern int islower (int c); +extern int isupper (int c); + +#endif + +#endif diff --git a/hardware/tools/stm8/include/errno.h b/hardware/tools/stm8/include/errno.h new file mode 100644 index 0000000..f1437d8 --- /dev/null +++ b/hardware/tools/stm8/include/errno.h @@ -0,0 +1,53 @@ +/*------------------------------------------------------------------------- + errno.h: Error codes used in the math functions + + Copyright (C) 2001, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* Version 1.0 - Initial release */ + +#ifndef _INC_ERRNO +#define _INC_ERRNO + +extern int errno; + +/* Error Codes: */ + +#define EDOM 33 /* Math argument out of domain of functions */ +#define ERANGE 34 /* Math result not representable */ +#define EILSEQ 84 /* Illegal byte sequence */ + +/* Bounds-checking interfaces from annex K of the C11 standard. */ +#if defined (__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ + +#ifndef __ERRNO_T_DEFINED +#define __ERRNO_T_DEFINED +typedef int errno_t; +#endif + +#endif + +#endif /* _INC_ERRNO */ + diff --git a/hardware/tools/stm8/include/float.h b/hardware/tools/stm8/include/float.h new file mode 100644 index 0000000..ddc028c --- /dev/null +++ b/hardware/tools/stm8/include/float.h @@ -0,0 +1,104 @@ +/*------------------------------------------------------------------------- + float.h - ANSI functions forward declarations + + Copyright (C) 1998, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#ifndef __SDC51_FLOAT_H +#define __SDC51_FLOAT_H 1 + +#include + +#define FLT_RADIX 2 +#define FLT_MANT_DIG 24 +#define FLT_EPSILON 1.192092896E-07F +#define FLT_DIG 6 +#define FLT_MIN_EXP (-125) +#define FLT_MIN 1.175494351E-38F +#define FLT_MIN_10_EXP (-37) +#define FLT_MAX_EXP (+128) +#define FLT_MAX 3.402823466E+38F +#define FLT_MAX_10_EXP (+38) + +/* the following deal with IEEE single-precision numbers */ +#if defined(__SDCC_FLOAT_LIB) +#define EXCESS 126 +#define SIGNBIT ((unsigned long)0x80000000) +#define __INFINITY ((unsigned long)0x7F800000) +#define HIDDEN (unsigned long)(1ul << 23) +#define SIGN(fp) (((unsigned long)(fp) >> (8*sizeof(fp)-1)) & 1) +#define EXP(fp) (((unsigned long)(fp) >> 23) & (unsigned int) 0x00FF) +#define MANT(fp) (((fp) & (unsigned long)0x007FFFFF) | HIDDEN) +#define NORM 0xff000000 +#define PACK(s,e,m) ((s) | ((unsigned long)(e) << 23) | (m)) +#endif + +float __uchar2fs (unsigned char); +float __schar2fs (signed char); +float __uint2fs (unsigned int); +float __sint2fs (signed int); +float __ulong2fs (unsigned long); +float __slong2fs (signed long); +unsigned char __fs2uchar (float); +signed char __fs2schar (float); +unsigned int __fs2uint (float); +signed int __fs2sint (float); +unsigned long __fs2ulong (float); +signed long __fs2slong (float); + +float __fsadd (float, float); +float __fssub (float, float); +float __fsmul (float, float); +float __fsdiv (float, float); + +char __fslt (float, float); +char __fseq (float, float); +char __fsgt (float, float); + + +#if defined(__SDCC_FLOAT_LIB) && defined(__SDCC_mcs51) && !defined(__SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS) + +#define FLOAT_ASM_MCS51 + +/* This adds extra code for proper round-off, in + an attempt to match the results from gcc. */ +#define FLOAT_FULL_ACCURACY + +/* This adds about 66 bytes to the code size and + significantly speeds up shift operations more + than 8 bits (common when subtracting numbers + of significantly different magnitude and scaling + to fixed point) */ +#define FLOAT_SHIFT_SPEEDUP + +#define sign_a psw.1 +#define sign_b psw.5 +#define exp_a dpl +#define exp_b dph +#endif /* using mcs51 assembly */ + + +#endif /* __SDC51_FLOAT_H */ + diff --git a/hardware/tools/stm8/include/iso646.h b/hardware/tools/stm8/include/iso646.h new file mode 100644 index 0000000..ff3cd16 --- /dev/null +++ b/hardware/tools/stm8/include/iso646.h @@ -0,0 +1,45 @@ +/*------------------------------------------------------------------------- + iso646.h + + Copyright (C) 2011, Philipp Klaus Krause . pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#ifndef __SDCC_ISO646_H +#define __SDCC_ISO646_H + +#define and && +#define and_eq &= +#define bitand & +#define bitor | +#define complement ~ +#define not ! +#define not_eq != +#define or || +#define or_eq |= +#define xor ^ +#define xor_eq ^= + +#endif + diff --git a/hardware/tools/stm8/include/limits.h b/hardware/tools/stm8/include/limits.h new file mode 100644 index 0000000..8c49dc8 --- /dev/null +++ b/hardware/tools/stm8/include/limits.h @@ -0,0 +1,69 @@ +/*------------------------------------------------------------------------- + limits.h - ANSI defines constants for sizes of integral types + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#ifndef __SDC51_LIMITS_H +#define __SDC51_LIMITS_H 1 + +#define CHAR_BIT 8 /* bits in a char */ +#define SCHAR_MAX 127 +#define SCHAR_MIN -128 +#define UCHAR_MAX 0xff + +#ifdef __SDCC_CHAR_UNSIGNED +#define CHAR_MAX UCHAR_MAX +#define CHAR_MIN 0 +#else +#define CHAR_MAX SCHAR_MAX +#define CHAR_MIN SCHAR_MIN +#endif + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199409L +#define MB_LEN_MAX 4 +#endif + +#define INT_MIN -32768 +#define INT_MAX 32767 +#define SHRT_MAX INT_MAX +#define SHRT_MIN INT_MIN +#define UINT_MAX 0xffff +#define UINT_MIN 0 +#define USHRT_MAX UINT_MAX +#define USHRT_MIN UINT_MIN +#define LONG_MIN (-2147483647L-1) +#define LONG_MAX 2147483647L +#define ULONG_MAX 0xffffffff +#define ULONG_MIN 0 + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L +#define LLONG_MIN (-9223372036854775807LL-1) +#define LLONG_MAX 9223372036854775807LL +#define ULLONG_MAX 18446744073709551615ULL +#endif + +#endif + diff --git a/hardware/tools/stm8/include/math.h b/hardware/tools/stm8/include/math.h new file mode 100644 index 0000000..ecbad40 --- /dev/null +++ b/hardware/tools/stm8/include/math.h @@ -0,0 +1,108 @@ +/*------------------------------------------------------------------------- + math.h: Floating point math function declarations + + Copyright (C) 2001, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* Version 1.0 - Initial release */ + +#ifndef _INC_MATH +#define _INC_MATH + +#define HUGE_VALF 3.402823466e+38 + +#define PI 3.1415926536 +#define TWO_PI 6.2831853071 +#define HALF_PI 1.5707963268 +#define QUART_PI 0.7853981634 +#define iPI 0.3183098862 +#define iTWO_PI 0.1591549431 +#define TWO_O_PI 0.6366197724 + +/* EPS=B**(-t/2), where B is the radix of the floating-point representation + and there are t base-B digits in the significand. Therefore, for floats + EPS=2**(-12). Also define EPS2=EPS*EPS. */ +#define EPS 244.14062E-6 +#define EPS2 59.6046E-9 + +union float_long +{ + float f; + long l; +}; + +#if defined(__SDCC_MATH_LIB) && defined(__SDCC_mcs51) && !defined(__SDCC_USE_XSTACK) && !defined(__SDCC_STACK_AUTO) && !defined(_SDCC_NO_ASM_LIB_FUNCS) +/* Compile the mcs51 assembly version only when all these + conditions are met. Since not all the functions are + reentrant, do not compile with --stack-auto is used. */ +#define MATH_ASM_MCS51 +#endif + + +/* Functions on the z80 & gbz80 are always reentrant and so the "reentrant" */ +/* keyword is not defined. */ +#if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_r2k) || defined(__SDCC_r3ka) || defined(__SDCC_tlcs90) || defined(__SDCC_gbz80) || defined(__SDCC_stm8) +#define _FLOAT_FUNC_REENTRANT +#else +#define _FLOAT_FUNC_REENTRANT __reentrant +#endif + +/********************************************** + * Prototypes for float ANSI C math functions * + **********************************************/ + +/* Trigonometric functions */ +float sinf(float x) _FLOAT_FUNC_REENTRANT; +float cosf(float x) _FLOAT_FUNC_REENTRANT; +float tanf(float x) _FLOAT_FUNC_REENTRANT; +float cotf(float x) _FLOAT_FUNC_REENTRANT; +float asinf(float x) _FLOAT_FUNC_REENTRANT; +float acosf(float x) _FLOAT_FUNC_REENTRANT; +float atanf(float x) _FLOAT_FUNC_REENTRANT; +float atan2f(float x, float y); + +/* Hyperbolic functions */ +float sinhf(float x) _FLOAT_FUNC_REENTRANT; +float coshf(float x) _FLOAT_FUNC_REENTRANT; +float tanhf(float x) _FLOAT_FUNC_REENTRANT; + +/* Exponential, logarithmic and power functions */ +float expf(float x) _FLOAT_FUNC_REENTRANT; +float logf(float x) _FLOAT_FUNC_REENTRANT; +float log10f(float x) _FLOAT_FUNC_REENTRANT; +float powf(float x, float y); +float sqrtf(float a) _FLOAT_FUNC_REENTRANT; + +/* Nearest integer, absolute value, and remainder functions */ +float fabsf(float x) _FLOAT_FUNC_REENTRANT; +float frexpf(float x, int *pw2); +float ldexpf(float x, int pw2); +float ceilf(float x) _FLOAT_FUNC_REENTRANT; +float floorf(float x) _FLOAT_FUNC_REENTRANT; +float modff(float x, float * y); + +int isnan(float f); +int isinf(float f); +#endif /* _INC_MATH */ diff --git a/hardware/tools/stm8/include/sdcc-lib.h b/hardware/tools/stm8/include/sdcc-lib.h new file mode 100644 index 0000000..26fe8c4 --- /dev/null +++ b/hardware/tools/stm8/include/sdcc-lib.h @@ -0,0 +1,67 @@ +/*------------------------------------------------------------------------- + sdcc-lib.h - Top level header file for the sdcc libraries that enables + target specific features. + + Copyright (C) 2004, Maarten Brock, sourceforge.brock@dse.nl + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#ifndef __SDC51_SDCC_LIB_H +#define __SDC51_SDCC_LIB_H 1 + +#if defined(__SDCC_z80) +#include + +#elif defined(__SDCC_z180) +#include + +#elif defined(__SDCC_r2k) +#include + +#elif defined(__SDCC_r3ka) +#include + +#elif defined(__SDCC_tlcs90) +#include + +#elif defined(__SDCC_gbz80) +#include + +#elif defined(__SDCC_mcs51) +#include + +#elif defined(__SDCC_ds390) +#include + +#elif defined(__SDCC_stm8) +#include + +#else +/* PENDING */ +#include + +#endif + +#endif + diff --git a/hardware/tools/stm8/include/setjmp.h b/hardware/tools/stm8/include/setjmp.h new file mode 100644 index 0000000..3f3cf4d --- /dev/null +++ b/hardware/tools/stm8/include/setjmp.h @@ -0,0 +1,81 @@ +/*------------------------------------------------------------------------- + setjmp.h - header file for setjmp & longjmp ANSI routines + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#ifndef __SDCC_SETJMP_H +#define __SDCC_SETJMP_H + +#define SP_SIZE 1 + +#ifdef __SDCC_STACK_AUTO +#define BP_SIZE SP_SIZE +#else +#define BP_SIZE 0 +#endif + +#ifdef __SDCC_USE_XSTACK +#define SPX_SIZE 1 +#else +#define SPX_SIZE 0 +#endif + +#define BPX_SIZE SPX_SIZE + +#ifdef __SDCC_MODEL_HUGE +#define RET_SIZE 3 +#else +#define RET_SIZE 2 +#endif + +#if defined (__SDCC_z80) || defined (__SDCC_z180) || defined (__SDCC_r2k) || defined (__SDCC_r3ka) +typedef unsigned char jmp_buf[6]; /* 2 for the stack pointer, 2 for the return address, 2 for the frame pointer. */ +#elif defined (__SDCC_stm8) || defined (__SDCC_gbz80) || defined (__SDCC_hc08) || defined (__SDCC_s08) +typedef unsigned char jmp_buf[4]; /* 2 for the stack pointer, 2 for the return address. */ +#elif defined (__SDCC_ds390) +typedef unsigned char jmp_buf[5]; /* 2 for the stack pointer, 3 for the return address. */ +#else +typedef unsigned char jmp_buf[RET_SIZE + SP_SIZE + BP_SIZE + SPX_SIZE + BPX_SIZE]; +#endif + +int __setjmp (jmp_buf); + +/* C99 might require setjmp to be a macro. The standard seems self-contradicting on this issue. */ +/* However, it is clear that the standards allow setjmp to be a macro. */ +#define setjmp(jump_buf) __setjmp(jump_buf) + +#ifndef __SDCC_HIDE_LONGJMP +_Noreturn void longjmp(jmp_buf, int); +#endif + +#undef RET_SIZE +#undef SP_SIZE +#undef BP_SIZE +#undef SPX_SIZE +#undef BPX_SIZE + +#endif + diff --git a/hardware/tools/stm8/include/stdalign.h b/hardware/tools/stm8/include/stdalign.h new file mode 100644 index 0000000..335ca53 --- /dev/null +++ b/hardware/tools/stm8/include/stdalign.h @@ -0,0 +1,20 @@ +#ifndef __SDCC_STDALIGN_H +#define __SDCC_STDALIGN_H 1 + +#ifndef __alignas_is_defined +#define __alignas_is_defined 1 + +#define alignas _Alignas + +#endif + + +#ifndef __alignof_is_defined +#define __alignof_is_defined 1 + +#define alignof _Alignof + +#endif + +#endif + diff --git a/hardware/tools/stm8/include/stdarg.h b/hardware/tools/stm8/include/stdarg.h new file mode 100644 index 0000000..8282c44 --- /dev/null +++ b/hardware/tools/stm8/include/stdarg.h @@ -0,0 +1,63 @@ +/*------------------------------------------------------------------------- + stdarg.h - ANSI macros for variable parameter list + + Copyright (C) 2000, Michael Hope + Copyright (C) 2011, Philipp Klaus Krause pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#ifndef __SDC51_STDARG_H +#define __SDC51_STDARG_H 1 + +#if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_r2k) || defined(__SDCC_r3ka) || defined(__SDCC_tlcs90) || defined(__SDCC_gbz80) || defined(__SDCC_hc08) || defined(__SDCC_s08) || defined(__SDCC_stm8) + +typedef unsigned char * va_list; +#define va_start(marker, last) { marker = (va_list)&last + sizeof(last); } +#define va_arg(marker, type) *((type *)((marker += sizeof(type)) - sizeof(type))) + +#elif defined(__SDCC_ds390) || defined(__SDCC_ds400) + +typedef unsigned char * va_list; +#define va_start(marker, first) { marker = (va_list)&first; } +#define va_arg(marker, type) *((type *)(marker -= sizeof(type))) + +#elif defined(__SDCC_USE_XSTACK) + +typedef unsigned char __pdata * va_list; +#define va_start(marker, first) { marker = (va_list)&first; } +#define va_arg(marker, type) *((type __pdata *)(marker -= sizeof(type))) + +#else + +typedef unsigned char __data * va_list; +#define va_start(marker, first) { marker = (va_list)&first; } +#define va_arg(marker, type) *((type __data * )(marker -= sizeof(type))) + +#endif + +#define va_copy(dest, src) { dest = src; } +#define va_end(marker) { marker = (va_list) 0; }; + +#endif + diff --git a/hardware/tools/stm8/include/stdbool.h b/hardware/tools/stm8/include/stdbool.h new file mode 100644 index 0000000..3ad3b65 --- /dev/null +++ b/hardware/tools/stm8/include/stdbool.h @@ -0,0 +1,39 @@ +/*------------------------------------------------------------------------- + stdbool.h - ANSI functions forward declarations + + Copyright (C) 2004, Maarten Brock, sourceforge.brock@dse.nl + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#ifndef __SDC51_STDBOOL_H +#define __SDC51_STDBOOL_H 1 + +#define true 1 +#define false 0 + +#define bool _Bool +#define __bool_true_false_are_defined 1 + +#endif + diff --git a/hardware/tools/stm8/include/stddef.h b/hardware/tools/stm8/include/stddef.h new file mode 100644 index 0000000..fa03894 --- /dev/null +++ b/hardware/tools/stm8/include/stddef.h @@ -0,0 +1,78 @@ +/*------------------------------------------------------------------------- + stddef.h - ANSI functions forward declarations + + Copyright (C) 2004, Maarten Brock / sourceforge.brock@dse.nl + Copyright (C) 2011, Philipp Klaus Krause / pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#ifndef __SDCC_STDDEF_H +#define __SDCC_STDDEF_H 1 + +#ifndef NULL + #define NULL (void *)0 +#endif + +#ifndef __PTRDIFF_T_DEFINED +#define __PTRDIFF_T_DEFINED +#if defined (__SDCC_mcs51) || defined (__SDCC_ds390) + typedef long int ptrdiff_t; +#else + typedef int ptrdiff_t; +#endif +#endif + +#ifndef __SIZE_T_DEFINED +#define __SIZE_T_DEFINED + typedef unsigned int size_t; +#endif + +#if __STDC_VERSION__ >= 201112L + typedef unsigned char max_align_t; +#endif + +#ifndef __WCHAR_T_DEFINED +#define __WCHAR_T_DEFINED + typedef unsigned long int wchar_t; +#endif + +/* Bounds-checking interfaces from annex K of the C11 standard. */ +#if defined (__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ + +#ifndef __RSIZE_T_DEFINED +#define __RSIZE_T_DEFINED +typedef size_t rsize_t; +#endif + +#ifndef __ERRNO_T_DEFINED +#define __ERRNO_T_DEFINED +typedef int errno_t; +#endif + +#endif + +#define offsetof(s, m) __builtin_offsetof (s, m) + +#endif + diff --git a/hardware/tools/stm8/include/stdint.h b/hardware/tools/stm8/include/stdint.h new file mode 100644 index 0000000..71f846d --- /dev/null +++ b/hardware/tools/stm8/include/stdint.h @@ -0,0 +1,258 @@ +/*------------------------------------------------------------------------- + stdint.h - ISO C99 7.18 Integer types + + Copyright (C) 2005, Maarten Brock, sourceforge.brock@dse.nl + Copyright (C) 2011, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#ifndef _STDINT_H +#define _STDINT_H 1 + +/* Exact integral types. */ + +#if !defined(__SDCC_ds390) && !defined(__SDCC_ds400) && !defined(__SDCC_pic14) && !defined(__SDCC_pic16) +#if __STDC_VERSION__ >= 199901L +#define __SDCC_LONGLONG +#endif +#endif + +/* Signed. */ + +typedef signed char int8_t; +typedef short int int16_t; +typedef long int int32_t; +#ifdef __SDCC_LONGLONG +typedef long long int int64_t; +#endif + +/* Unsigned. */ +typedef unsigned char uint8_t; +typedef unsigned short int uint16_t; +typedef unsigned long int uint32_t; +#ifdef __SDCC_LONGLONG +typedef unsigned long long int uint64_t; +#endif + +/* Small types. */ + +/* Signed. */ +typedef signed char int_least8_t; +typedef short int int_least16_t; +typedef long int int_least32_t; +#ifdef __SDCC_LONGLONG +typedef long long int int_least64_t; +#endif + +/* Unsigned. */ +typedef unsigned char uint_least8_t; +typedef unsigned short int uint_least16_t; +typedef unsigned long int uint_least32_t; +#ifdef __SDCC_LONGLONG +typedef unsigned long long int uint_least64_t; +#endif + +/* Fast types. */ + +/* Signed. */ +typedef signed char int_fast8_t; +typedef int int_fast16_t; +typedef long int int_fast32_t; +#ifdef __SDCC_LONGLONG +typedef long long int int_fast64_t; +#endif + +/* Unsigned. */ +typedef unsigned char uint_fast8_t; +typedef unsigned int uint_fast16_t; +typedef unsigned long int uint_fast32_t; +#ifdef __SDCC_LONGLONG +typedef unsigned long long int uint_fast64_t; +#endif + +/* Types for `void *' pointers. */ +#if defined (__SDCC_mcs51) || defined (__SDCC_ds390) + typedef long int intptr_t; + typedef unsigned long int uintptr_t; +#else + typedef int intptr_t; + typedef unsigned int uintptr_t; +#endif + + +/* Largest integral types. */ +#ifndef __SDCC_LONGLONG +typedef long int intmax_t; +typedef unsigned long int uintmax_t; +#else +typedef long long int intmax_t; +typedef unsigned long long int uintmax_t; +#endif + +/* Limits of integral types. */ + +/* Minimum of signed integral types. */ +#define INT8_MIN (-128) +#define INT16_MIN (-32767-1) +#define INT32_MIN (-2147483647L-1) +#ifdef __SDCC_LONGLONG +#define INT64_MIN (-9223372036854775807LL-1) +#endif + +/* Maximum of signed integral types. */ +#define INT8_MAX (127) +#define INT16_MAX (32767) +#define INT32_MAX (2147483647L) +#ifdef __SDCC_LONGLONG +#define INT64_MAX (9223372036854775807LL) +#endif + +/* Maximum of unsigned integral types. */ +#define UINT8_MAX (255) +#define UINT16_MAX (65535) +#define UINT32_MAX (4294967295UL) +#ifdef __SDCC_LONGLONG +#define UINT64_MAX (18446744073709551615ULL) +#endif + +/* Minimum of signed integral types having a minimum size. */ +#define INT_LEAST8_MIN INT8_MIN +#define INT_LEAST16_MIN INT16_MIN +#define INT_LEAST32_MIN INT32_MIN +#ifdef __SDCC_LONGLONG +#define INT_LEAST64_MIN INT64_MIN +#endif + +/* Maximum of signed integral types having a minimum size. */ +#define INT_LEAST8_MAX INT8_MAX +#define INT_LEAST16_MAX INT16_MAX +#define INT_LEAST32_MAX INT32_MAX +#ifdef __SDCC_LONGLONG +#define INT_LEAST64_MAX INT64_MAX +#endif + +/* Maximum of unsigned integral types having a minimum size. */ +#define UINT_LEAST8_MAX UINT8_MAX +#define UINT_LEAST16_MAX UINT16_MAX +#define UINT_LEAST32_MAX UINT32_MAX +#ifdef __SDCC_LONGLONG +#define UINT_LEAST64_MAX UINT64_MAX +#endif + +/* Minimum of fast signed integral types having a minimum size. */ +#define INT_FAST8_MIN INT8_MIN +#define INT_FAST16_MIN INT16_MIN +#define INT_FAST32_MIN INT32_MIN +#ifdef __SDCC_LONGLONG +#define INT_FAST64_MIN INT64_MIN +#endif + +/* Maximum of fast signed integral types having a minimum size. */ +#define INT_FAST8_MAX INT8_MAX +#define INT_FAST16_MAX INT16_MAX +#define INT_FAST32_MAX INT32_MAX +#ifdef __SDCC_LONGLONG +#define INT_FAST64_MAX INT64_MAX +#endif + +/* Maximum of fast unsigned integral types having a minimum size. */ +#define UINT_FAST8_MAX UINT8_MAX +#define UINT_FAST16_MAX UINT16_MAX +#define UINT_FAST32_MAX UINT32_MAX +#ifdef __SDCC_LONGLONG +#define UINT_FAST64_MAX UINT64_MAX +#endif + +/* Values to test for integral types holding `void *' pointer. */ +#if defined (__SDCC_mcs51) || defined (__SDCC_ds390) +#define INTPTR_MIN (-2147483647L-1) +#define INTPTR_MAX (2147483647L) +#define UINTPTR_MAX (4294967295UL) +#else +#define INTPTR_MIN (-32767-1) +#define INTPTR_MAX (32767) +#define UINTPTR_MAX (65535) +#endif + +/* Minimum for largest signed integral type. */ +#define INTMAX_MIN (-__INT32_C(-2147483647L)-1) +/* Maximum for largest signed integral type. */ +#define INTMAX_MAX (__INT32_C(2147483647L)) + +/* Maximum for largest unsigned integral type. */ +#define UINTMAX_MAX (__UINT32_C(4294967295UL)) + + +/* Limits of other integer types. */ + +/* Limits of `ptrdiff_t' type. */ +#if defined (__SDCC_mcs51) || defined (__SDCC_ds390) +#define PTRDIFF_MIN (-2147483647L-1) +#define PTRDIFF_MAX (2147483647L) +#else +#define PTRDIFF_MIN (-32767-1) +#define PTRDIFF_MAX (32767) +#endif + +/* Limit of `size_t' type. */ +#define SIZE_MAX (65535u) + +/* Signed. */ +#define INT8_C(c) c +#define INT16_C(c) c +#define INT32_C(c) c ## L +#ifdef __SDCC_LONGLONG +#define INT64_C(c) c ## LL +#endif + +/* Unsigned. */ +#define UINT8_C(c) c ## U +#define UINT16_C(c) c ## U +#define UINT32_C(c) c ## UL +#ifdef __SDCC_LONGLONG +#define UINT64_C(c) c ## ULL +#endif + +#define WCHAR_MIN CHAR_MIN +#define WCHAR_MAX CHAR_MAX + +#define WINT_MIN INT_MIN +#define WINT_MAX INT_MAX + +/* Maximal type. */ +#ifdef __SDCC_LONGLONG +#define INTMAX_C(c) c ## LL +#define UINTMAX_C(c) c ## ULL +#else +#define INTMAX_C(c) c ## L +#define UINTMAX_C(c) c ## UL +#endif + +/* Bounds-checking interfaces from annex K of the C11 standard. */ +#if defined (__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ +#define RSIZE_MAX SIZE_MAX +#endif + +#endif /* stdint.h */ + diff --git a/hardware/tools/stm8/include/stdio.h b/hardware/tools/stm8/include/stdio.h new file mode 100644 index 0000000..afde94a --- /dev/null +++ b/hardware/tools/stm8/include/stdio.h @@ -0,0 +1,94 @@ +/*------------------------------------------------------------------------- + stdio.h - ANSI functions forward declarations + + Copyright (C) 1998, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#ifndef __SDC51_STDIO_H +#define __SDC51_STDIO_H 1 + +#include + +#ifdef __ds390 +#include +#endif + +#include + +#ifndef EOF + #define EOF (-1) +#endif + +#ifndef NULL + #define NULL (void *)0 +#endif + +#ifndef __SIZE_T_DEFINED +#define __SIZE_T_DEFINED + typedef unsigned int size_t; +#endif + +/* Bounds-checking interfaces from annex K of the C11 standard. */ +#if defined (__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ + +#ifndef __RSIZE_T_DEFINED +#define __RSIZE_T_DEFINED +typedef size_t rsize_t; +#endif + +#ifndef __ERRNO_T_DEFINED +#define __ERRNO_T_DEFINED +typedef int errno_t; +#endif + +#endif + +typedef void (*pfn_outputchar)(char c, void* p) _REENTRANT; + +extern int _print_format (pfn_outputchar pfn, void* pvoid, const char *format, va_list ap); + +/*-----------------------------------------------------------------------*/ + +extern void printf_small (char *,...) _REENTRANT; +extern int printf (const char *,...); +extern int vprintf (const char *, va_list); +extern int sprintf (char *, const char *, ...); +extern int vsprintf (char *, const char *, va_list); +extern int puts(const char *); + +#if __STDC_VERSION__ < 201112L +extern char *gets(char *); +#endif + +extern char getchar(void); +extern int putchar(int); + +#if defined(__SDCC_mcs51) && !defined(__SDCC_USE_XSTACK) +extern void printf_fast(__code const char *fmt, ...) _REENTRANT; +extern void printf_fast_f(__code const char *fmt, ...) _REENTRANT; +extern void printf_tiny(__code const char *fmt, ...) _REENTRANT; +#endif + +#endif /* __SDC51_STDIO_H */ diff --git a/hardware/tools/stm8/include/stdlib.h b/hardware/tools/stm8/include/stdlib.h new file mode 100644 index 0000000..3f3ace4 --- /dev/null +++ b/hardware/tools/stm8/include/stdlib.h @@ -0,0 +1,125 @@ +/*------------------------------------------------------------------------- + stdlib.h - General utilities (ISO C 11 7.22) + + Copyright (C) 1998, Sandeep Dutta . sandeep.dutta@usa.net + Copyright (c) 2016, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#ifndef __SDCC_STDLIB_H +#define __SDCC_STDLIB_H 1 + +#ifndef __SIZE_T_DEFINED +#define __SIZE_T_DEFINED + typedef unsigned int size_t; +#endif + +#ifndef __WCHAR_T_DEFINED +#define __WCHAR_T_DEFINED + typedef unsigned long int wchar_t; +#endif + +#ifndef NULL +#define NULL (void *)0 +#endif + +#define RAND_MAX 32767 + +#define MB_CUR_MAX 4 + +extern float atof (const char *nptr); +extern int atoi (const char *nptr); +extern long int atol (const char *nptr); +#ifdef __SDCC_LONGLONG +extern long long int atoll (const char *nptr); +#endif + +extern void _uitoa(unsigned int, char*, unsigned char); +extern void _itoa(int, char*, unsigned char); + +extern void _ultoa(unsigned long, char*, unsigned char); +extern void _ltoa(long, char*, unsigned char); + +int rand(void); +void srand(unsigned int seed); + +#if defined(__SDCC_mcs51) || defined(__SDCC_ds390) || defined(__SDCC_ds400) +void __xdata *calloc (size_t nmemb, size_t size); +void __xdata *malloc (size_t size); +void __xdata *realloc (void *ptr, size_t size); +#else +void *calloc (size_t nmemb, size_t size); +void *malloc (size_t size); +void *realloc (void *ptr, size_t size); +#endif + +#if __STDC_VERSION__ >= 201112L +inline void *aligned_alloc(size_t alignment, size_t size) +{ + (void)alignment; + return malloc(size); +} +#endif + +extern void free (void * ptr); + +#if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_r2k) || defined(__SDCC_r3ka) || defined(__SDCC_tlcs90) +int abs(int j) __preserves_regs(b, c, iyl, iyh); +#else +int abs(int j); +#endif +long int labs(long int j); + +/* C99 Multibyte/wide character conversion functions (ISO C 11 7.22.7) */ +#if __STDC_VERSION__ >= 199901L +int mblen(const char *s, size_t n); +int mbtowc(wchar_t *restrict pwc, const char *restrict s, size_t n); +int wctomb(char *s, wchar_t wc); +#endif + +/* C99 Multibyte/wide string conversion functions (ISO C 11 7.22.8) */ +#if __STDC_VERSION__ >= 199901L +size_t mbstowcs(wchar_t *restrict pwcs, const char *restrict s, size_t n); +size_t wcstombs(char *restrict s, const wchar_t *restrict pwcs, size_t n); +#endif + +/* Bounds-checking interfaces from annex K of the C11 standard. */ +#if defined (__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ + +#ifndef __RSIZE_T_DEFINED +#define __RSIZE_T_DEFINED +typedef size_t rsize_t; +#endif + +#ifndef __ERRNO_T_DEFINED +#define __ERRNO_T_DEFINED +typedef int errno_t; +#endif + +typedef void (*constraint_handler_t)(const char *restrict msg, void *restrict ptr, errno_t error); + +#endif + +#endif + diff --git a/hardware/tools/stm8/include/stdnoreturn.h b/hardware/tools/stm8/include/stdnoreturn.h new file mode 100644 index 0000000..992f9b9 --- /dev/null +++ b/hardware/tools/stm8/include/stdnoreturn.h @@ -0,0 +1,7 @@ +#ifndef __SDCC_STDNORETURN_H +#define __SDCC_STDNORETURN_H 1 + +#define noreturn _Noreturn + +#endif + diff --git a/hardware/tools/stm8/include/string.h b/hardware/tools/stm8/include/string.h new file mode 100644 index 0000000..7e678c7 --- /dev/null +++ b/hardware/tools/stm8/include/string.h @@ -0,0 +1,136 @@ +/*------------------------------------------------------------------------- + string.h - ISO header for string library functions + + Copyright (C) 1998, Sandeep Dutta + Copyright (C) 2009-2011, Philipp Klaus Krause pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#ifndef __SDCC_STRING_H +#define __SDCC_STRING_H 1 + +#ifndef NULL +# define NULL (void *)0 +#endif + +#ifndef __SIZE_T_DEFINED +# define __SIZE_T_DEFINED + typedef unsigned int size_t; +#endif + +/* Bounds-checking interfaces from annex K of the C11 standard. */ +#if defined (__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ + +#ifndef __RSIZE_T_DEFINED +#define __RSIZE_T_DEFINED +typedef size_t rsize_t; +#endif + +#ifndef __ERRNO_T_DEFINED +#define __ERRNO_T_DEFINED +typedef int errno_t; +#endif + +#endif + +#if defined(__SDCC_mcs51) || defined(__SDCC_hc08) || defined(__SDCC_ds390) || defined(__SDCC_pic14) || defined(__SDCC_pic16) +#define __SDCC_BROKEN_STRING_FUNCTIONS +#endif + +/* The function prototypes are ordered as in the ISO C99 standard. */ + +/* Todo: fix the "restrict" stuff for C99 compliance. */ + +/* Copying functions: */ +extern void *memcpy (void * /*restrict */ dest, const void * /*restrict*/ src, size_t n); +#if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_r2k) || defined(__SDCC_r3ka) +extern void *memmove (void *dest, const void *src, size_t n) __preserves_regs(iyl, iyh); +#else +extern void *memmove (void *dest, const void *src, size_t n); +#endif +#if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_r2k) || defined(__SDCC_r3ka) || defined(__SDCC_tlcs90) +extern char *strcpy (char * /*restrict*/ dest, const char * /*restrict*/ src) __preserves_regs(iyl, iyh); +#else +extern char *strcpy (char * /*restrict*/ dest, const char * /*restrict*/ src); +#endif +extern char *strncpy(char * /*restrict*/ dest, const char * /*restrict*/ src, size_t n); + +/* Concatenation functions: */ +extern char *strcat (char * /*restrict*/ dest, const char * /*restrict*/ src); +extern char *strncat(char * /*restrict*/ dest, const char * /*restrict*/ src, size_t n); + +/* Comparison functions: */ +extern int memcmp (const void *s1, const void *s2, size_t n); +extern int strcmp (const char *s1, const char *s2); +#define strcoll(s1, s2) strcmp(s1, s2) +/*int strcoll(const char *s1, const char *s2) {return strcmp(s1, s2);}*/ +extern int strncmp(const char *s1, const char *s2, size_t n); +extern size_t strxfrm(char *dest, const char *src, size_t n); + +/* Search functions: */ +extern void *memchr (const void *s, int c, size_t n); +#ifdef __SDCC_BROKEN_STRING_FUNCTIONS +extern char *strchr (const char *s, char c); /* c should be int according to standard. */ +#else +extern char *strchr (const char *s, int c); +#endif +extern size_t strcspn(const char *s, const char *reject); +extern char *strpbrk(const char *s, const char *accept); +#ifdef __SDCC_BROKEN_STRING_FUNCTIONS +extern char *strrchr(const char *s, char c); /* c should be int according to standard. */ +#else +extern char *strrchr(const char *s, int c); +#endif +extern size_t strspn (const char *s, const char *accept); +extern char *strstr (const char *haystack, const char *needle); +extern char *strtok (char * /* restrict*/ str, const char * /*restrict*/ delim); + +/* Miscanelleous functions: */ +#ifdef __SDCC_BROKEN_STRING_FUNCTIONS +extern void *memset (void *s, unsigned char c, size_t n); /* c should be int according to standard. */ +#else +extern void *memset (void *s, int c, size_t n); +#endif + +/* extern char *strerror(int errnum); */ +#if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_tlcs90) +extern size_t strlen (const char *s) __preserves_regs(d, e, iyl, iyh); +#else +extern size_t strlen (const char *s); +#endif + +#ifdef __SDCC_ds390 +extern void __xdata * memcpyx(void __xdata *, void __xdata *, int) __naked; +#endif + +#if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_r2k) || defined(__SDCC_r3ka) +#define memcpy(dst, src, n) __builtin_memcpy(dst, src, n) +#define strcpy(dst, src) __builtin_strcpy(dst, src) +#define strncpy(dst, src, n) __builtin_strncpy(dst, src, n) +#define strchr(s, c) __builtin_strchr(s, c) +#define memset(dst, c, n) __builtin_memset(dst, c, n) +#endif + +#endif + diff --git a/hardware/tools/stm8/include/time.h b/hardware/tools/stm8/include/time.h new file mode 100644 index 0000000..267f942 --- /dev/null +++ b/hardware/tools/stm8/include/time.h @@ -0,0 +1,90 @@ +/*------------------------------------------------------------------------- + time.h + + Copyright (C) 2001, Johan Knol + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#ifndef TIME_H +#define TIME_H + +#ifndef __TIME_UNSIGNED +#define __TIME_UNSIGNED 1 +#endif + +/* Bounds-checking interfaces from annex K of the C11 standard. */ +#if defined (__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ + +#ifndef __RSIZE_T_DEFINED +#define __RSIZE_T_DEFINED +typedef size_t rsize_t; +#endif + +#ifndef __ERRNO_T_DEFINED +#define __ERRNO_T_DEFINED +typedef int errno_t; +#endif + +#endif + +#if __TIME_UNSIGNED +struct tm +{ + unsigned char tm_sec; /* Seconds. [0-60] */ + unsigned char tm_min; /* Minutes. [0-59] */ + unsigned char tm_hour; /* Hours. [0-23] */ + unsigned char tm_mday; /* Day. [1-31] */ + unsigned char tm_mon; /* Month. [0-11] */ + int tm_year; /* Year since 1900 */ + unsigned char tm_wday; /* Day of week. [0-6] */ + int tm_yday; /* Days in year.[0-365] */ + unsigned char tm_isdst; /* Daylight saving time */ + unsigned char tm_hundredth; /* not standard 1/100th sec */ +}; +#else +struct tm +{ + int tm_sec; /* Seconds. [0-60] */ + int tm_min; /* Minutes. [0-59] */ + int tm_hour; /* Hours. [0-23] */ + int tm_mday; /* Day. [1-31] */ + int tm_mon; /* Month. [0-11] */ + int tm_year; /* Year since 1900 */ + int tm_wday; /* Day of week. [0-6] */ + int tm_yday; /* Days in year.[0-365] */ + int tm_isdst; /* Daylight saving time */ + char *tm_zone; /* Abbreviated timezone */ +}; +#endif + +typedef unsigned long time_t; + +time_t time(time_t *t); +struct tm *gmtime(time_t *timep); +struct tm *localtime(time_t *timep); +time_t mktime(struct tm *timeptr); +char *asctime(struct tm *timeptr); +char *ctime(time_t *timep); + +#endif /* TIME_H */ diff --git a/hardware/tools/stm8/include/tinibios.h b/hardware/tools/stm8/include/tinibios.h new file mode 100644 index 0000000..67e9a87 --- /dev/null +++ b/hardware/tools/stm8/include/tinibios.h @@ -0,0 +1,153 @@ +/*------------------------------------------------------------------------- + time.h + + Copyright (C) 2001, Johan Knol + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#ifndef TINIBIOS_H + +#define TINIBIOS_H + +#include +#include + +void Serial0Init (unsigned long baud, unsigned char buffered); +char Serial0GetChar(void); +void Serial0PutChar(char); +char Serial0CharArrived(void); +void Serial0Baud(unsigned long baud); +void Serial0SendBreak(void); +void Serial0Flush(void); + +void Serial0SwitchToBuffered(void); /* ds400 only. */ + +void Serial1Init (unsigned long baud, unsigned char buffered); +char Serial1GetChar(void); +void Serial1PutChar(char); +char Serial1CharArrived(void); +void Serial1Baud(unsigned long baud); +void Serial1SendBreak(void); +void Serial1Flush(void); + +unsigned long ClockTicks(); +void ClockMilliSecondsDelay(unsigned long ms); +void ClockMicroSecondsDelay(unsigned int us); + +#define SERIAL_0_BAUD 115200L +#define SERIAL_1_BAUD 9600L + +/* these need to be binary numbers */ +#define SERIAL_0_RECEIVE_BUFFER_SIZE 1024 +#define SERIAL_1_RECEIVE_BUFFER_SIZE 64 + +/* I know someone is fooling with the crystals */ +#if defined(__SDCC_ds400) +# define OSCILLATOR 14745600L +#else +# define OSCILLATOR 18432000L +#endif + +/* Set the cpu speed in clocks per machine cycle, valid values are: + 1024: Divide-by-1024 (power management) mode (screws ALL timers and serial) + 4: Standard 8051 divide-by-4 mode + 2: Use 2x xtal multiplier + 1: Use 4x xtal multiplier (Don't do this with a TINI at 18.432MHz) +*/ +#define CPU_SPEED 2 +void CpuSpeed(unsigned int speed); + +/* The MOVX stretch cycles, see datasheet */ +#define CPU_MOVX_STRETCH 0x01 + +/* from rtc390.c */ +#define HAVE_RTC +unsigned char RtcRead(struct tm *rtcDate); +void RtcWrite(struct tm *rtcDate); + +/* from lcd390.c */ +extern void LcdInit(void); +extern void LcdOn(void); +extern void LcdOff(void); +extern void LcdClear(void); +extern void LcdHome(void); +extern void LcdGoto(unsigned int collumnRow); +extern void LcdPutChar(char c); +extern void LcdPutString(char *string); +extern void LcdLPutString(unsigned int collumnRow, char *string); +extern void LcdPrintf(const char *format, ...) __reentrant; +extern void LcdLPrintf(unsigned int collumnRow, const char *format, ...) __reentrant; + +/* from i2c390.c */ +#define I2C_BUFSIZE 128 +extern char I2CReset(void); +extern char I2CStart(void); +extern char I2CStop(void); +extern char I2CSendStop(char addr, char count, + char send_stop); +extern char I2CReceive(char addr, char count); +extern char I2CSendReceive(char addr, char tx_count, + char rx_count); +/*extern char I2CByteOut(char);*/ +/*extern void I2CDumpError(char);*/ + +/* global transfer buffers */ +extern char i2cTransmitBuffer[I2C_BUFSIZE]; +extern char i2cReceiveBuffer[I2C_BUFSIZE]; + +/* Macro for normal send transfer ending with a stop condition */ +#define I2CSend(addr, count) I2CSendStop(addr, count, 1) + + +/* internal functions used by tinibios.c */ +unsigned char _sdcc_external_startup(void); +void Serial0IrqHandler (void) __interrupt 4; +void Serial1IrqHandler (void) __interrupt 7; + +#if !defined(__SDCC_ds400) +void ClockInit(); +void ClockIrqHandler (void) __interrupt 1 __naked; +#endif + +#if defined(__SDCC_ds400) +/* functions for dealing with the ds400 ROM firmware. */ + +/* A wrapper which calls rom_init allocating all available RAM in CE0 + to the heap, sets the serial port to SERIAL_0_BAUD, sets up the + millisecond timer, and diddles the clock multiplier. */ + +/* Values for the romInit "speed" parameter. */ +#define SPEED_1X 0 /* no clock multiplier, normal speed. */ +#define SPEED_2X 1 /* 2x clock multiplier. */ +#define SPEED_4X 2 /* 4x clock, DOESN'T WORK ON TINIm400! */ + +unsigned char romInit(unsigned char noisy, + char speed); + +/* Install an interrupt handler. */ +void installInterrupt(void (*isrPtr)(void), unsigned char offset); +#endif + + +#endif /* TINIBIOS_H */ diff --git a/hardware/tools/stm8/include/typeof.h b/hardware/tools/stm8/include/typeof.h new file mode 100644 index 0000000..e1f6f97 --- /dev/null +++ b/hardware/tools/stm8/include/typeof.h @@ -0,0 +1,54 @@ +/*------------------------------------------------------------------------- + typeof.h - Contains enumerations of values returned by __typeof + + Copyright (C) 2001, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#ifndef __SDC51_TYPEOF_H +#define __SDC51_TYPEOF_H 1 + +#define TYPEOF_INT 1 +#define TYPEOF_SHORT 2 +#define TYPEOF_CHAR 3 +#define TYPEOF_LONG 4 +#define TYPEOF_FLOAT 5 +#define TYPEOF_FIXED16X16 6 +#define TYPEOF_BIT 7 +#define TYPEOF_BITFIELD 8 +#define TYPEOF_SBIT 9 +#define TYPEOF_SFR 10 +#define TYPEOF_VOID 11 +#define TYPEOF_STRUCT 12 +#define TYPEOF_ARRAY 13 +#define TYPEOF_FUNCTION 14 +#define TYPEOF_POINTER 15 +#define TYPEOF_FPOINTER 16 +#define TYPEOF_CPOINTER 17 +#define TYPEOF_GPOINTER 18 +#define TYPEOF_PPOINTER 19 +#define TYPEOF_IPOINTER 20 +#define TYPEOF_EEPPOINTER 21 + +#endif diff --git a/hardware/tools/stm8/include/uchar.h b/hardware/tools/stm8/include/uchar.h new file mode 100644 index 0000000..8e53230 --- /dev/null +++ b/hardware/tools/stm8/include/uchar.h @@ -0,0 +1,58 @@ +/*------------------------------------------------------------------------- + uchar.h: Unicode utilities (ISO C 11 7.28) + + Copyright (C) 2015-2016, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#ifndef __SDCC_UCHAR_H +#define __SDCC_UCHAR_H 1 + +#ifndef __MBSTATE_T_DEFINED +#define __MBSTATE_T_DEFINED + typedef struct {unsigned char c[3];} mbstate_t; +#endif + +#ifndef __SIZE_T_DEFINED +#define __SIZE_T_DEFINED + typedef unsigned int size_t; +#endif + +#ifndef __CHAR16_T_DEFINED +#define __CHAR16_T_DEFINED + typedef unsigned int char16_t; +#endif + +#ifndef __CHAR32_T_DEFINED +#define __CHAR32_T_DEFINED + typedef unsigned long int char32_t; +#endif + +size_t mbrtoc16(char16_t *restrict pc16, const char *restrict s, size_t n, mbstate_t *restrict ps); +size_t c16rtomb(char *restrict s, char16_t c16, mbstate_t *restrict ps); +size_t mbrtoc32(char32_t *restrict pc32, const char *restrict s, size_t n, mbstate_t *restrict ps); +size_t c32rtomb(char *restrict s, char32_t c32, mbstate_t *restrict ps); + +#endif + diff --git a/hardware/tools/stm8/include/wchar.h b/hardware/tools/stm8/include/wchar.h new file mode 100644 index 0000000..3dd00ce --- /dev/null +++ b/hardware/tools/stm8/include/wchar.h @@ -0,0 +1,72 @@ +/*------------------------------------------------------------------------- + wchar.h - Extended and multibyte wide character utilitites (ISO C 11 7.29) + + Copyright (c) 2015-2016, Philipp Klaus Krause / pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#ifndef __WCHAR_T_DEFINED +#define __WCHAR_T_DEFINED + typedef unsigned long int wchar_t; +#endif + +#ifndef __SIZE_T_DEFINED +#define __SIZE_T_DEFINED + typedef unsigned int size_t; +#endif + +#ifndef __MBSTATE_T_DEFINED +#define __MBSTATE_T_DEFINED + typedef struct {unsigned char c[3];} mbstate_t; +#endif + +#ifndef __WINT_T_DEFINED +#define __WINT_T_DEFINED + typedef unsigned long int wint_t; +#endif + +struct tm; + +#ifndef WEOF + #define WEOF 0xfffffffful +#endif + +/* C99 Wide string comparison functions (ISO C11 7.29.4.4) */ +int wcscmp(const wchar_t *s1, const wchar_t *s2); + +/* C99 Miscellaneous functions (ISO C11 7.29.4.6) */ +size_t wcslen(const wchar_t *s); + +/* C99 Single-byte/wide character conversion functions (ISO C 11 7.29.6.1) */ +wint_t btowc(int c); +int wctob(wint_t c); + +/* C99 Conversion state functions (ISO C 11 7.29.6.2) */ +int mbsinit(const mbstate_t *ps); + +/* C99 Restartable multibyte/wide character conversion functions (ISO C 11 7.29.6.3) */ +size_t mbrlen(const char *restrict s, size_t n, mbstate_t *restrict ps); +size_t mbrtowc(wchar_t *restrict pwc, const char *restrict s, size_t n, mbstate_t *restrict ps); +size_t wcrtomb(char *restrict s, wchar_t wc, mbstate_t *restrict ps); + diff --git a/hardware/tools/stm8/lib/src/_atof.c b/hardware/tools/stm8/lib/src/_atof.c new file mode 100644 index 0000000..fe952f5 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_atof.c @@ -0,0 +1,96 @@ +/*------------------------------------------------------------------------- + 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include +#include +#include + +float atof(const char * s) +{ + float value, fraction; + signed char iexp; + bool 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=(signed 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); +} + diff --git a/hardware/tools/stm8/lib/src/_autobaud.c b/hardware/tools/stm8/lib/src/_autobaud.c new file mode 100644 index 0000000..73a4379 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_autobaud.c @@ -0,0 +1,101 @@ +/*------------------------------------------------------------------------- + + _autobaud.c - automatic baud rate detection routine. Adapted for + sdcc compiler from Paul Stoffregen's autobaud.asm + the original assembly code can be found at + http://www.ece.orst.edu/~paul/8051-goodies/autobaud.html + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include <8051.h> +/* +; To set the baud rate, use this formula or use autobaud() +; baud_const = 256 - (crystal / (12 * 16 * baud)) */ + +/* +;to do automatic baud rate detection, we assume the user will +;press the carriage return, which will cause this bit pattern +;to appear on port 3 pin 0 (CR = ascii code 13, assume 8N1 format) +; +; 0 1 0 1 1 0 0 0 0 1 +; | | | | +; start bit----+ +--lsb msb--+ +----stop bit +; +;we'll start timer #1 in 16 bit mode at the transition between the +;start bit and the LSB and stop it between the MBS and stop bit. +;That will give approx the number of cpu cycles for 8 bits. Divide +;by 8 for one bit and by 16 since the built-in UART takes 16 timer +;overflows for each bit. We need to be careful about roundoff during +;division and the result has to be inverted since timer #1 counts up. Of +;course, timer #1 gets used in 8-bit auto reload mode for generating the +;built-in UART's baud rate once we know what the reload value should be. +*/ + +void autobaud () +{ + + /* get timer #1 ready for action (16 bit mode) */ + TMOD=0x11; + TCON = 0; + TH1 = TL1 = 0; + + /* wait for start bit */ +autobaud2: + while(RXD) ; + + /* check it a few more times to make + sure we don't trigger on some noise*/ + if (RXD) goto autobaud2; + if (RXD) goto autobaud2; + if (RXD) goto autobaud2; + if (RXD) goto autobaud2; + + /* wait for bit #0 to begin */ + while (!RXD); + TR1 = 1; /* start the timer */ + while (RXD); // wait for bit #1 to begin + while(!RXD); // wait for bit #2 to begin + while(RXD); // wait for bit #4 to begin + while (!RXD); // wait for stop bit to begin + TR1 = 0; // stop timing + + /* ;grab bit 7... it's the lsb we want */ + TH1 = (TH1 << 1) | (TL1 >> 7); + + /* round off if necessary */ + TH1 = (TH1 << 1) | ((TL1 >> 6) & 0x01); + + /* invert since timer #1 will count up */ + TH1 = ~TH1; + + /* now TH1 has the correct reload value (I hope) */ + TH1++ ; + + TL1 = TH1; + TMOD = 0x21 ; // set timer #1 for 8 bit auto-reload + PCON = 0x80 ; // configure built-in uart + SCON = 0x52 ; +} diff --git a/hardware/tools/stm8/lib/src/_bp.c b/hardware/tools/stm8/lib/src/_bp.c new file mode 100644 index 0000000..21f346a --- /dev/null +++ b/hardware/tools/stm8/lib/src/_bp.c @@ -0,0 +1,29 @@ +/*------------------------------------------------------------------------- + _bp.c - just declares bp as a variable + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +__data unsigned char bp ; diff --git a/hardware/tools/stm8/lib/src/_decdptr.c b/hardware/tools/stm8/lib/src/_decdptr.c new file mode 100644 index 0000000..222846b --- /dev/null +++ b/hardware/tools/stm8/lib/src/_decdptr.c @@ -0,0 +1,52 @@ +/*------------------------------------------------------------------------- + _decdptr.c - decrement dptr by 1 + + Copyright (C) 1999, Jean-Louis Vern + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +static void +dummy (void) __naked +{ +// void _decdptr (char *gptr) +/* the return value is already in dph/dpl */ + __asm + .globl __decdptr +__decdptr: + +#ifdef __SDCC_ds390 + orl dps, #0xc0 + inc dptr + anl dps, #0x3f +#else + xch a,dpl + jnz 00001$ + dec dph +00001$: + dec a + xch a,dpl +#endif + ret + __endasm; +} diff --git a/hardware/tools/stm8/lib/src/_divschar.c b/hardware/tools/stm8/lib/src/_divschar.c new file mode 100644 index 0000000..29fb0c9 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_divschar.c @@ -0,0 +1,47 @@ +/*------------------------------------------------------------------------- + _divschar.c :- routine for signed char (8 bit) division. just calls + routine for signed int division after sign extension + + Copyright (C) 2013, Philipp Klaus Krause . pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +signed int +_divschar (signed char x, signed char y) +{ + return ((int)x / (int)y); +} + +signed int +_divuschar (unsigned char x, unsigned char y) +{ + return ((int)((signed char)x) / (int)y); +} + +unsigned int +_divsuchar (signed char x, signed char y) +{ + return ((int)((unsigned char)x) / (int)y); +} + diff --git a/hardware/tools/stm8/lib/src/_divsint.c b/hardware/tools/stm8/lib/src/_divsint.c new file mode 100644 index 0000000..cacfe93 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_divsint.c @@ -0,0 +1,218 @@ +/*------------------------------------------------------------------------- + _divsint.c :- routine for signed int (16 bit) division. just calls + routine for unsigned division after sign adjustment + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + +#include + +#if _SDCC_MANGLES_SUPPORT_FUNS +unsigned unsigned _divuint (unsigned x, unsigned y); +#endif + +/* Assembler-functions are provided for: + mcs51 small + mcs51 small stack-auto +*/ + +#if !defined(__SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS) +# if defined(__SDCC_mcs51) +# if defined(__SDCC_MODEL_SMALL) +# if defined(__SDCC_STACK_AUTO) && !defined(__SDCC_PARMS_IN_BANK1) +# define _DIVSINT_ASM_SMALL_AUTO +# else +# define _DIVSINT_ASM_SMALL +# endif +# endif +# endif +#endif + +#if defined _DIVSINT_ASM_SMALL + +static void +_divsint_dummy (void) __naked +{ + __asm + + #define xl dpl + #define xh dph + + .globl __divsint + + // _divsint_PARM_2 shares the same memory with _divuint_PARM_2 + // and is defined in _divuint.c +#if defined(__SDCC_PARMS_IN_BANK1) + #define yl (b1_0) + #define yh (b1_1) +#else + #define yl (__divsint_PARM_2) + #define yh (__divsint_PARM_2 + 1) +#endif +__divsint: + ; xh in dph + ; yh in (__divsint_PARM_2 + 1) + + clr F0 ; Flag 0 in PSW + ; available to user for general purpose + mov a,xh + jnb acc.7,a_not_negative + + setb F0 + + clr a + clr c + subb a,xl + mov xl,a + clr a + subb a,xh + mov xh,a + +a_not_negative: + + mov a,yh + jnb acc.7,b_not_negative + + cpl F0 + + clr a + clr c + subb a,yl + mov yl,a + clr a + subb a,yh + mov yh,a + +b_not_negative: + + lcall __divuint + + jnb F0,not_negative + + clr a + clr c + subb a,xl + mov xl,a + clr a + subb a,xh + mov xh,a + +not_negative: + ret + + __endasm; +} + +#elif defined _DIVSINT_ASM_SMALL_AUTO + +static void +_divsint_dummy (void) __naked +{ + __asm + + #define xl dpl + #define xh dph + + .globl __divsint + +__divsint: + + clr F0 ; Flag 0 in PSW + ; available to user for general purpose + mov a,xh + jnb acc.7,a_not_negative + + setb F0 + + clr a + clr c + subb a,xl + mov xl,a + clr a + subb a,xh + mov xh,a + +a_not_negative: + + mov a,sp + add a,#-2 ; 2 bytes return address + mov r0,a ; r0 points to yh + mov a,@r0 ; a = yh + + jnb acc.7,b_not_negative + + cpl F0 + + dec r0 + + clr a + clr c + subb a,@r0 ; yl + mov @r0,a + clr a + inc r0 + subb a,@r0 ; a = yh + +b_not_negative: + + mov r1,a ; yh + dec r0 + mov a,@r0 ; yl + mov r0,a + + lcall __divint + + jnb F0,not_negative + + clr a + clr c + subb a,xl + mov xl,a + clr a + subb a,xh + mov xh,a + +not_negative: + ret + + __endasm; +} + +#else // _DIVSINT_ASM_ + +int +_divsint (int x, int y) +{ + register int r; + + r = (unsigned int)(x < 0 ? -x : x) / (unsigned int)(y < 0 ? -y : y); + if ((x < 0) ^ (y < 0)) + return -r; + else + return r; +} + +#endif // _DIVSINT_ASM_ diff --git a/hardware/tools/stm8/lib/src/_divslong.c b/hardware/tools/stm8/lib/src/_divslong.c new file mode 100644 index 0000000..c82329c --- /dev/null +++ b/hardware/tools/stm8/lib/src/_divslong.c @@ -0,0 +1,270 @@ +/*------------------------------------------------------------------------- + _divslong.c - routine for division of 32 bit long + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + +#include + +#if _SDCC_MANGLES_SUPPORT_FUNS +unsigned long _divulong (unsigned long x, unsigned long y); +#endif + +/* Assembler-functions are provided for: + mcs51 small + mcs51 small stack-auto +*/ + +#if !defined(__SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS) +# if defined(__SDCC_mcs51) +# if defined(__SDCC_MODEL_SMALL) +# if defined(__SDCC_STACK_AUTO) && !defined(__SDCC_PARMS_IN_BANK1) +# define _DIVSLONG_ASM_SMALL_AUTO +# else +# define _DIVSLONG_ASM_SMALL +# endif +# endif +# endif +#endif + +#if defined _DIVSLONG_ASM_SMALL + +static void +_divslong_dummy (void) __naked +{ + __asm + + #define x0 dpl + #define x1 dph + #define x2 b + #define x3 r3 + + .globl __divslong + + // _divslong_PARM_2 shares the same memory with _divulong_PARM_2 + // and is defined in _divulong.c +#if defined(__SDCC_PARMS_IN_BANK1) + #define y0 (b1_0) + #define y1 (b1_1) + #define y2 (b1_2) + #define y3 (b1_3) +#else + #define y0 (__divslong_PARM_2) + #define y1 (__divslong_PARM_2 + 1) + #define y2 (__divslong_PARM_2 + 2) + #define y3 (__divslong_PARM_2 + 3) +#endif +__divslong: + ; x3 in acc + ; y3 in (__divslong_PARM_2 + 3) + mov x3,a ; save x3 + + clr F0 ; Flag 0 in PSW + ; available to user for general purpose + jnb acc.7,a_not_negative + + setb F0 + + clr a + clr c + subb a,x0 + mov x0,a + clr a + subb a,x1 + mov x1,a + clr a + subb a,x2 + mov x2,a + clr a + subb a,x3 + mov x3,a + +a_not_negative: + + mov a,y3 + jnb acc.7,b_not_negative + + cpl F0 + + clr a + clr c + subb a,y0 + mov y0,a + clr a + subb a,y1 + mov y1,a + clr a + subb a,y2 + mov y2,a + clr a + subb a,y3 + mov y3,a + +b_not_negative: + + mov a,x3 ; restore x3 in acc + + lcall __divulong + + jnb F0,not_negative + + mov x3,a ; save x3 + + clr a + clr c + subb a,x0 + mov x0,a + clr a + subb a,x1 + mov x1,a + clr a + subb a,x2 + mov x2,a + clr a + subb a,x3 ; x3 ends in acc + +not_negative: + ret + + __endasm; +} + +#elif defined _DIVSLONG_ASM_SMALL_AUTO + +static void +_divslong_dummy (void) __naked +{ + __asm + + #define x0 dpl + #define x1 dph + #define x2 b + #define x3 r3 + + .globl __divslong + +__divslong: + + ; x3 in acc + mov x3,a ; save x3 + + clr F0 ; Flag 0 in PSW + ; available to user for general purpose + jnb acc.7,a_not_negative + + setb F0 + + clr a + clr c + subb a,x0 + mov x0,a + clr a + subb a,x1 + mov x1,a + clr a + subb a,x2 + mov x2,a + clr a + subb a,x3 + mov x3,a + +a_not_negative: + + mov a,sp + add a,#-2 ; 2 bytes return address + mov r0,a ; r0 points to y3 + mov a,@r0 ; y3 + + jnb acc.7,b_not_negative + + cpl F0 + + dec r0 + dec r0 + dec r0 + + clr a + clr c + subb a,@r0 ; y0 + mov @r0,a + clr a + inc r0 + subb a,@r0 ; y1 + mov @r0,a + clr a + inc r0 + subb a,@r0 ; y2 + mov @r0,a + clr a + inc r0 + subb a,@r0 ; y3 + mov @r0,a + +b_not_negative: + dec r0 + dec r0 + dec r0 ; r0 points to y0 + + lcall __divlong + + jnb F0,not_negative + + mov x3,a ; save x3 + + clr a + clr c + subb a,x0 + mov x0,a + clr a + subb a,x1 + mov x1,a + clr a + subb a,x2 + mov x2,a + clr a + subb a,x3 ; x3 ends in acc + +not_negative: + ret + + __endasm; +} + +#else // _DIVSLONG_ASM + +long +_divslong (long x, long y) +{ + long r; + + r = (unsigned long)(x < 0 ? -x : x) / (unsigned long)(y < 0 ? -y : y); + if ((x < 0) ^ (y < 0)) + return -r; + else + return r; +} + +#endif // _DIVSLONG_ASM diff --git a/hardware/tools/stm8/lib/src/_divslonglong.c b/hardware/tools/stm8/lib/src/_divslonglong.c new file mode 100644 index 0000000..bdc6a37 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_divslonglong.c @@ -0,0 +1,52 @@ +/*------------------------------------------------------------------------- + _divslonglong.c - routine for divsion of 64 bit unsigned long long + + Copyright (C) 2012, Philipp Klaus Krause . pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#pragma std_c99 + +#include +#include + +#ifdef __SDCC_LONGLONG +long long +_divslonglong (long long numerator, long long denominator) +{ + bool numeratorneg = (numerator < 0); + bool denominatorneg = (denominator < 0); + long long d; + + if (numeratorneg) + numerator = -numerator; + if (denominatorneg) + denominator = -denominator; + + d = (unsigned long long)numerator / (unsigned long long)denominator; + + return ((numeratorneg ^ denominatorneg) ? -d : d); +} +#endif + diff --git a/hardware/tools/stm8/lib/src/_divuint.c b/hardware/tools/stm8/lib/src/_divuint.c new file mode 100644 index 0000000..71d9557 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_divuint.c @@ -0,0 +1,181 @@ +/*------------------------------------------------------------------------- + _divuint.c - routine for unsigned int (16 bit) division + + Copyright (C) 1999, Jean-Louis Vern + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* Assembler-functions are provided for: + mcs51 small + mcs51 small stack-auto +*/ + +#include + +#if !defined(__SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS) +# if defined(__SDCC_mcs51) +# if defined(__SDCC_MODEL_SMALL) +# if defined(__SDCC_STACK_AUTO) +# define _DIVUINT_ASM_SMALL_AUTO +# else +# define _DIVUINT_ASM_SMALL +# endif +# endif +# endif +#endif + +#if defined _DIVUINT_ASM_SMALL || defined _DIVUINT_ASM_SMALL_AUTO + +static void +_divuint_dummy (void) __naked +{ + __asm + + .globl __divuint + +__divuint: + + #define count r2 + #define reste_l r3 + #define reste_h r4 + #define xl dpl + #define xh dph + +#if defined(__SDCC_PARMS_IN_BANK1) + #define yl (b1_0) + #define yh (b1_1) +#else // __SDCC_PARMS_IN_BANK1 + #if defined(__SDCC_STACK_AUTO) + + .globl __divint + + mov a,sp + add a,#-2 ; 2 bytes return address + mov r0,a ; r0 points to yh + mov a,@r0 ; load yh + mov r1,a + dec r0 + mov a,@r0 ; load yl + mov r0,a + + #define yl r0 + #define yh r1 + +__divint: ; entry point for __divsint + + + #else // __SDCC_STACK_AUTO + + #if defined(__SDCC_NOOVERLAY) + .area DSEG (DATA) + #else + .area OSEG (OVR,DATA) + #endif + + .globl __divuint_PARM_2 + .globl __divsint_PARM_2 + +__divuint_PARM_2: +__divsint_PARM_2: + .ds 2 + + .area CSEG (CODE) + + #define yl (__divuint_PARM_2) + #define yh (__divuint_PARM_2 + 1) + + #endif // __SDCC_STACK_AUTO +#endif // __SDCC_PARMS_IN_BANK1 + + mov count,#16 + clr a + mov reste_l,a + mov reste_h,a + +loop: + mov a,xl ; x <<= 1 + add a,acc + mov xl,a + mov a,xh + rlc a + mov xh,a + + mov a,reste_l ; reste <<= 1 + rlc a ; feed in carry + mov reste_l,a + mov a,reste_h + rlc a + mov reste_h,a + + mov a,reste_l ; reste - y + subb a,yl ; here carry is always clear, because + ; reste <<= 1 never overflows + mov b,a + mov a,reste_h + subb a,yh + + jc smaller ; reste >= y? + + mov reste_h,a ; -> yes; reste = reste - y; + mov reste_l,b + orl xl,#1 +smaller: ; -> no + djnz count,loop + ret + + __endasm; +} + +#else // defined _DIVUINT_ASM_SMALL || defined _DIVUINT_ASM_SMALL_AUTO + +#define MSB_SET(x) ((x >> (8*sizeof(x)-1)) & 1) + +unsigned int +_divuint (unsigned int x, unsigned int y) +{ + unsigned int reste = 0; + unsigned char count = 16; + bool c; + + do + { + // reste: x <- 0; + c = MSB_SET(x); + x <<= 1; + reste <<= 1; + if (c) + reste |= 1; + + if (reste >= y) + { + reste -= y; + // x <- (result = 1) + x |= 1; + } + } + while (--count); + return x; +} + +#endif // defined _DIVUINT_ASM_SMALL || defined _DIVUINT_ASM_SMALL_AUTO diff --git a/hardware/tools/stm8/lib/src/_divulong.c b/hardware/tools/stm8/lib/src/_divulong.c new file mode 100644 index 0000000..d339391 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_divulong.c @@ -0,0 +1,357 @@ +/*------------------------------------------------------------------------- + _divulong.c - routine for division of 32 bit unsigned long + + Copyright (C) 1999, Jean-Louis Vern + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* Assembler-functions are provided for: + mcs51 small + mcs51 small stack-auto +*/ + +#include + +#if !defined(__SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS) +# if defined(__SDCC_mcs51) +# if defined(__SDCC_MODEL_SMALL) +# if defined(__SDCC_STACK_AUTO) && !defined(__SDCC_PARMS_IN_BANK1) +# define _DIVULONG_ASM_SMALL_AUTO +# else +# define _DIVULONG_ASM_SMALL +# endif +# endif +# endif +#endif + +#if defined _DIVULONG_ASM_SMALL + +static void +_divlong_dummy (void) __naked +{ + __asm + + .globl __divulong + +__divulong: + + #define count r2 + + #define x0 dpl + #define x1 dph + #define x2 b + #define x3 r3 + + #define reste0 r4 + #define reste1 r5 + #define reste2 r6 + #define reste3 r7 +#if !defined(__SDCC_PARMS_IN_BANK1) + +#if defined(__SDCC_NOOVERLAY) + .area DSEG (DATA) +#else + .area OSEG (OVR,DATA) +#endif + + .globl __divulong_PARM_2 + .globl __divslong_PARM_2 + +__divulong_PARM_2: +__divslong_PARM_2: + .ds 4 + + .area CSEG (CODE) + + #define y0 (__divulong_PARM_2) + #define y1 (__divulong_PARM_2 + 1) + #define y2 (__divulong_PARM_2 + 2) + #define y3 (__divulong_PARM_2 + 3) +#else + #define y0 (b1_0) + #define y1 (b1_1) + #define y2 (b1_2) + #define y3 (b1_3) +#endif // !__SDCC_PARMS_IN_BANK1 + ; parameter x comes in a, b, dph, dpl + mov x3,a ; save parameter x3 + + mov count,#32 + clr a + mov reste0,a + mov reste1,a + mov reste2,a + mov reste3,a + + ; optimization loop in lp0 until the first bit is shifted into rest + +lp0: mov a,x0 ; x <<= 1 + add a,x0 + mov x0,a + mov a,x1 + rlc a + mov x1,a + mov a,x2 + rlc a + mov x2,a + mov a,x3 + rlc a + mov x3,a + + jc in_lp + djnz count,lp0 + + sjmp exit + +loop: mov a,x0 ; x <<= 1 + add a,x0 + mov x0,a + mov a,x1 + rlc a + mov x1,a + mov a,x2 + rlc a + mov x2,a + mov a,x3 + rlc a + mov x3,a + +in_lp: mov a,reste0 ; reste <<= 1 + rlc a ; feed in carry + mov reste0,a + mov a,reste1 + rlc a + mov reste1,a + mov a,reste2 + rlc a + mov reste2,a + mov a,reste3 + rlc a + mov reste3,a + + mov a,reste0 ; reste - y + subb a,y0 ; carry is always clear here, because + ; reste <<= 1 never overflows + mov a,reste1 + subb a,y1 + mov a,reste2 + subb a,y2 + mov a,reste3 + subb a,y3 + + jc minus ; reste >= y? + + ; -> yes; reste -= y; + mov a,reste0 + subb a,y0 ; carry is always clear here (jc) + mov reste0,a + mov a,reste1 + subb a,y1 + mov reste1,a + mov a,reste2 + subb a,y2 + mov reste2,a + mov a,reste3 + subb a,y3 + mov reste3,a + + orl x0,#1 + +minus: djnz count,loop ; -> no + +exit: mov a,x3 ; prepare the return value + ret + + __endasm; +} + +#elif defined _DIVULONG_ASM_SMALL_AUTO + +static void +_divlong_dummy (void) __naked +{ + __asm + + .globl __divulong + +__divulong: + + #define count r2 + + #define x0 dpl + #define x1 dph + #define x2 b + #define x3 r3 + + #define reste0 r4 + #define reste1 r5 + #define reste2 r6 + #define reste3 r7 + + .globl __divlong ; entry point for __divslong + + #define y0 r1 + + ; parameter x comes in a, b, dph, dpl + mov x3,a ; save parameter x3 + + mov a,sp + add a,#-2-3 ; 2 bytes return address, 3 bytes param y + mov r0,a ; r0 points to y0 + +__divlong: ; entry point for __divslong + + mov a,@r0 ; load y0 + mov y0,a + inc r0 ; r0 points to y1 + + mov count,#32 + clr a + mov reste0,a + mov reste1,a + mov reste2,a + mov reste3,a + + ; optimization loop in lp0 until the first bit is shifted into rest + +lp0: mov a,x0 ; x <<= 1 + add a,x0 + mov x0,a + mov a,x1 + rlc a + mov x1,a + mov a,x2 + rlc a + mov x2,a + mov a,x3 + rlc a + mov x3,a + + jc in_lp + djnz count,lp0 + + sjmp exit + +loop: mov a,x0 ; x <<= 1 + add a,x0 + mov x0,a + mov a,x1 + rlc a + mov x1,a + mov a,x2 + rlc a + mov x2,a + mov a,x3 + rlc a + mov x3,a + +in_lp: mov a,reste0 ; reste <<= 1 + rlc a ; feed in carry + mov reste0,a + mov a,reste1 + rlc a + mov reste1,a + mov a,reste2 + rlc a + mov reste2,a + mov a,reste3 + rlc a + mov reste3,a + + mov a,reste0 ; reste - y + subb a,y0 ; carry is always clear here, because + ; reste <<= 1 never overflows + mov a,reste1 + subb a,@r0 ; y1 + mov a,reste2 + inc r0 + subb a,@r0 ; y2 + mov a,reste3 + inc r0 + subb a,@r0 ; y3 + dec r0 + dec r0 + + jc minus ; reste >= y? + + ; -> yes; reste -= y; + mov a,reste0 + subb a,y0 ; carry is always clear here (jc) + mov reste0,a + mov a,reste1 + subb a,@r0 ; y1 + mov reste1,a + mov a,reste2 + inc r0 + subb a,@r0 ; y2 + mov reste2,a + mov a,reste3 + inc r0 + subb a,@r0 ; y3 + mov reste3,a + dec r0 + dec r0 + + orl x0,#1 + +minus: djnz count,loop ; -> no + +exit: mov a,x3 ; prepare the return value + ret + + __endasm; +} + +#else // _DIVULONG_ASM + +#define MSB_SET(x) ((x >> (8*sizeof(x)-1)) & 1) + +unsigned long +_divulong (unsigned long x, unsigned long y) +{ + unsigned long reste = 0L; + unsigned char count = 32; + bool c; + + do + { + // reste: x <- 0; + c = MSB_SET(x); + x <<= 1; + reste <<= 1; + if (c) + reste |= 1L; + + if (reste >= y) + { + reste -= y; + // x <- (result = 1) + x |= 1L; + } + } + while (--count); + return x; +} + +#endif // _DIVULONG_ASM diff --git a/hardware/tools/stm8/lib/src/_divulonglong.c b/hardware/tools/stm8/lib/src/_divulonglong.c new file mode 100644 index 0000000..6bcc32e --- /dev/null +++ b/hardware/tools/stm8/lib/src/_divulonglong.c @@ -0,0 +1,65 @@ +/*------------------------------------------------------------------------- + _divslonglong.c - routine for divsion of 64 bit unsigned long long + + Copyright (C) 1999, Jean-Louis Vern + Copyright (C) 2012, Philipp Klaus Krause . pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#pragma std_c99 + +#include +#include + +#ifdef __SDCC_LONGLONG +#define MSB_SET(x) ((x >> (8*sizeof(x)-1)) & 1) + +unsigned long long +_divulonglong (unsigned long long x, unsigned long long y) +{ + unsigned long long reste = 0L; + unsigned char count = 64; + bool c; + + do + { + // reste: x <- 0; + c = MSB_SET(x); + x <<= 1; + reste <<= 1; + if (c) + reste |= 1L; + + if (reste >= y) + { + reste -= y; + // x <- (result = 1) + x |= 1L; + } + } + while (--count); + return x; +} +#endif + diff --git a/hardware/tools/stm8/lib/src/_fs2schar.c b/hardware/tools/stm8/lib/src/_fs2schar.c new file mode 100644 index 0000000..3d990d3 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_fs2schar.c @@ -0,0 +1,97 @@ +/*------------------------------------------------------------------------- + _fs2schar.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + +#define __SDCC_FLOAT_LIB +#include + + + +#ifdef FLOAT_ASM_MCS51 + +// char __fs2schar (float x) +static void dummy(void) __naked +{ + __asm + .globl ___fs2schar +___fs2schar: + lcall ___fs2slong + jnz fs2schar_not_zero + mov a, dpl + orl a, dph + orl a, b + jnz fs2schar_clr_a + ret +fs2schar_clr_a: + clr a +fs2schar_not_zero: + jnb sign_a, fs2schar_pos +fs2schar_neg: + cpl a + jnz fs2schar_maxval_neg + mov a, b + cpl a + jnz fs2schar_maxval_neg + mov a, dph + cpl a + jnz fs2schar_maxval_neg + mov a, dpl + jnb acc.7, fs2schar_maxval_neg + ret +fs2schar_maxval_neg: + mov dpl, #0x80 + ret +fs2schar_pos: + jnz fs2schar_maxval_pos + mov a, b + jnz fs2schar_maxval_pos + mov a, dph + jnz fs2schar_maxval_pos + mov a, dpl + jb acc.7, fs2schar_maxval_pos + ret +fs2schar_maxval_pos: + mov dpl, #0x7F + ret + __endasm; +} + +#else + +/* convert float to signed char */ +signed char __fs2schar (float f) +{ + signed long sl=__fs2slong(f); + if (sl>=SCHAR_MAX) + return SCHAR_MAX; + if (sl<=SCHAR_MIN) + return -SCHAR_MIN; + return sl; +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_fs2sint.c b/hardware/tools/stm8/lib/src/_fs2sint.c new file mode 100644 index 0000000..2ec4dbf --- /dev/null +++ b/hardware/tools/stm8/lib/src/_fs2sint.c @@ -0,0 +1,91 @@ +/*------------------------------------------------------------------------- + _fs2sint.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +// int __fs2sint (float x) +static void dummy(void) __naked +{ + __asm + .globl ___fs2sint +___fs2sint: + lcall ___fs2slong + jnz fs2sint_not_zero + mov a, dpl + orl a, dph + orl a, b + jnz fs2sint_clr_a + ret +fs2sint_clr_a: + clr a +fs2sint_not_zero: + jnb sign_a, fs2sint_pos +fs2sint_neg: + cpl a + jnz fs2sint_maxval_neg + mov a, b + cpl a + jnz fs2sint_maxval_neg + mov a, dph + jnb acc.7, fs2sint_maxval_neg + ret +fs2sint_maxval_neg: + mov dptr, #0x8000 + ret +fs2sint_pos: + jnz fs2sint_maxval_pos + mov a, b + jnz fs2sint_maxval_pos + mov a, dph + jb acc.7, fs2sint_maxval_pos + ret +fs2sint_maxval_pos: + mov dptr, #0x7FFF + ret + __endasm; +} + +#else + +/* convert float to signed int */ +signed int __fs2sint (float f) +{ + signed long sl=__fs2slong(f); + if (sl>=INT_MAX) + return INT_MAX; + if (sl<=INT_MIN) + return -INT_MIN; + return sl; +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_fs2slong.c b/hardware/tools/stm8/lib/src/_fs2slong.c new file mode 100644 index 0000000..2bde867 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_fs2slong.c @@ -0,0 +1,121 @@ +/*------------------------------------------------------------------------- + _fs2slong.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +// long __fs2slong (float x) +static void dummy(void) __naked +{ + __asm + .globl ___fs2slong +___fs2slong: + lcall fsgetarg + clr c + mov a, #158 + subb a, exp_a + jc fs2slong_maxval // |x| >= 2^32 +fs2slong_int_ok: + mov r1, #0 + lcall fs_rshift_a + jnb sign_a, fs2slong_pos +fs2slong_neg: + mov a, r1 + cpl a + add a, #1 + mov dpl, a + mov a, r2 + cpl a + addc a, #0 + mov dph, a + mov a, r3 + cpl a + addc a, #0 + mov b, a + mov a, r4 + cpl a + addc a, #0 + //Check for zero + jnz fs2slong_not_zero + mov a, dpl + orl a, dph + orl a, b + jnz fs2slong_clr_a + ret +fs2slong_clr_a: + clr a +fs2slong_not_zero: + jnb acc.7, fs2slong_maxval_neg // x < -0x80000000 + ret +fs2slong_pos: + mov a, r4 + jb acc.7, fs2slong_maxval_pos // x > 0x7FFFFFFF + mov dpl, r1 + mov dph, r2 + mov b, r3 + ret +fs2slong_maxval: + jnb sign_a, fs2slong_maxval_pos +fs2slong_maxval_neg: + clr a + mov dpl, a + mov dph, a + mov b, a + mov a, #0x80 + ret +fs2slong_maxval_pos: + mov a, #0xFF + mov dpl, a + mov dph, a + mov b, a + mov a, #0x7F + ret + __endasm; +} + +#else + +/* convert float to signed long */ +signed long __fs2slong (float f) +{ + + if (!f) + return 0; + + if (f<0) { + return -__fs2ulong(-f); + } else { + return __fs2ulong(f); + } +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_fs2uchar.c b/hardware/tools/stm8/lib/src/_fs2uchar.c new file mode 100644 index 0000000..4dff533 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_fs2uchar.c @@ -0,0 +1,58 @@ +/*------------------------------------------------------------------------- + _fs2uchar.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +// unsigned char __fs2uchar (float x) +static void dummy(void) __naked +{ + __asm + .globl ___fs2uchar +___fs2uchar: + mov r7, #134 + lcall fs2ulong_begin + mov dpl, a + ret + __endasm; +} + +#else + +/* convert float to unsigned char */ +unsigned char __fs2uchar (float f) +{ + unsigned long ul=__fs2ulong(f); + if (ul>=UCHAR_MAX) return UCHAR_MAX; + return ul; +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_fs2uint.c b/hardware/tools/stm8/lib/src/_fs2uint.c new file mode 100644 index 0000000..688595e --- /dev/null +++ b/hardware/tools/stm8/lib/src/_fs2uint.c @@ -0,0 +1,61 @@ +/*------------------------------------------------------------------------- + _fs2uint.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +// unsigned int __fs2uint (float x) +static void dummy(void) __naked +{ + __asm + .globl ___fs2uint +___fs2uint: + mov r7, #142 + lcall fs2ulong_begin + mov dph, a + mov dpl, b + ret + __endasm; +} + +#else + +unsigned long __fs2ulong (float a1); + +/* convert float to unsigned int */ +unsigned int __fs2uint (float f) +{ + unsigned long ul=__fs2ulong(f); + if (ul>=UINT_MAX) return UINT_MAX; + return ul; +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_fs2ulong.c b/hardware/tools/stm8/lib/src/_fs2ulong.c new file mode 100644 index 0000000..2d43291 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_fs2ulong.c @@ -0,0 +1,122 @@ +/*------------------------------------------------------------------------- + _fs2ulong.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +// unsigned long __fs2ulong (float x) +static void dummy(void) __naked +{ + __asm + .globl ___fs2ulong +___fs2ulong: + mov r7, #158 + .globl fs2ulong_begin +fs2ulong_begin: + lcall fsgetarg + jnb sign_a, fs2ulong_int + ljmp fs_return_zero + +fs2ulong_int: + clr c + mov a, r7 + subb a, exp_a + jnc fs2ulong_int_ok + // if we get here, x >= 2^32 + mov a, #0xFF + mov b, a + mov dph, a + mov dpl, a + ret + +fs2ulong_int_ok: + mov r1, #0 + lcall fs_rshift_a + +fs2ulong_done: + mov dpl, r1 + mov dph, r2 + mov b, r3 + mov a, r4 + ret + __endasm; +} + +#else + +/* +** libgcc support for software floating point. +** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved. +** Permission is granted to do *anything* you want with this file, +** commercial or otherwise, provided this message remains intact. So there! +** I would appreciate receiving any updates/patches/changes that anyone +** makes, and am willing to be the repository for said changes (am I +** making a big mistake?). +** +** Pat Wood +** Pipeline Associates, Inc. +** pipeline!phw@motown.com or +** sun!pipeline!phw or +** uunet!motown!pipeline!phw +*/ + +/* (c)2000/2001: hacked a little by johan.knol@iduna.nl for sdcc */ + + +union float_long +{ + float f; + long l; +}; + +/* convert float to unsigned long */ +unsigned long +__fs2ulong (float a1) +{ + volatile union float_long fl1; + volatile int exp; + volatile long l; + + fl1.f = a1; + + if (!fl1.l || SIGN(fl1.l)) + return (0); + + exp = EXP (fl1.l) - EXCESS - 24; + l = MANT (fl1.l); + + l >>= -exp; + + return l; +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_fsadd.c b/hardware/tools/stm8/lib/src/_fsadd.c new file mode 100644 index 0000000..d3ebe24 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_fsadd.c @@ -0,0 +1,252 @@ +/*------------------------------------------------------------------------- + _fsadd.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + +#define __SDCC_FLOAT_LIB +#include +#include +#include + +#ifdef FLOAT_ASM_MCS51 + +// float __fsadd (float a, float b) __reentrant +static void dummy(void) __naked +{ + __asm + + // extract the two inputs, placing them into: + // sign exponent mantissa + // ---- -------- -------- + // a: sign_a exp_a r4/r3/r2 + // b: sign_b exp_b r7/r6/r5 + // + // r1: used to extend precision of a's mantissa + // r0: general purpose loop counter + + .globl ___fsadd +___fsadd: + lcall fsgetargs + + .globl fsadd_direct_entry +fsadd_direct_entry: + // we're going to extend mantissa to 32 bits temporarily + mov r1, #0 + + // which exponent is greater? + mov a, exp_b + cjne a, exp_a, 00005$ + sjmp 00011$ +00005$: jnc 00010$ + + // a's exponent was greater, so shift b's mantissa + lcall fs_swap_a_b + +00010$: + // b's exponent was greater, so shift a's mantissa + mov a, exp_b + clr c + subb a, exp_a + lcall fs_rshift_a // acc has # of shifts to do + +00011$: + // decide if we need to add or subtract + // sign_a and sign_b are stored in the flag bits of psw, + // so this little trick checks if the arguements have the + // same sign. + mov a, psw + swap a + xrl a, psw + jb acc.1, 00022$ + +00020$: + // add the mantissas (both positive or both negative) + mov a, r2 + add a, r5 + mov r2, a + mov a, r3 + addc a, r6 + mov r3, a + mov a, r4 + addc a, r7 + mov r4, a + // check for overflow past 24 bits + jnc 00021$ + mov a, #1 + lcall fs_rshift_a + mov a, r4 + orl a, #0x80 + mov r4, a +00021$: + ljmp fs_round_and_return + + + +00022$: + // subtract the mantissas (one of them is negative) + clr c + mov a, r2 + subb a, r5 + mov r2, a + mov a, r3 + subb a, r6 + mov r3, a + mov a, r4 + subb a, r7 + mov r4, a + jnc 00025$ + // if we get a negative result, turn it positive and + // flip the sign bit + clr c + clr a + subb a, r1 + mov r1, a + clr a + subb a, r2 + mov r2, a + clr a + subb a, r3 + mov r3, a + clr a + subb a, r4 + mov r4, a + cpl sign_a +00025$: + lcall fs_normalize_a + ljmp fs_round_and_return + + __endasm; +} + +#else + +/* +** libgcc support for software floating point. +** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved. +** Permission is granted to do *anything* you want with this file, +** commercial or otherwise, provided this message remains intact. So there! +** I would appreciate receiving any updates/patches/changes that anyone +** makes, and am willing to be the repository for said changes (am I +** making a big mistake?). +** +** Pat Wood +** Pipeline Associates, Inc. +** pipeline!phw@motown.com or +** sun!pipeline!phw or +** uunet!motown!pipeline!phw +*/ + +union float_long + { + float f; + unsigned long l; + }; + +/* add two floats */ +float __fsadd (float a1, float a2) +{ + long mant1, mant2; + long _AUTOMEM *pfl1; + long _AUTOMEM *pfl2; + int exp1, exp2, expd; + bool sign = false; + + pfl2 = (long _AUTOMEM *)&a2; + exp2 = EXP (*pfl2); + mant2 = MANT (*pfl2) << 4; + if (SIGN (*pfl2)) + mant2 = -mant2; + /* check for zero args */ + if (!*pfl2) + return (a1); + + pfl1 = (long _AUTOMEM *)&a1; + exp1 = EXP (*pfl1); + mant1 = MANT (*pfl1) << 4; + if (SIGN(*pfl1)) + if (*pfl1 & 0x80000000) + mant1 = -mant1; + /* check for zero args */ + if (!*pfl1) + return (a2); + + expd = exp1 - exp2; + if (expd > 25) + return (a1); + if (expd < -25) + return (a2); + + if (expd < 0) + { + expd = -expd; + exp1 += expd; + mant1 >>= expd; + } + else + { + mant2 >>= expd; + } + mant1 += mant2; + + sign = false; + + if (mant1 < 0) + { + mant1 = -mant1; + sign = true; + } + else if (!mant1) + return (0); + + /* normalize */ + while (mant1 < (HIDDEN<<4)) { + mant1 <<= 1; + exp1--; + } + + /* round off */ + while (mant1 & 0xf0000000) { + if (mant1&1) + mant1 += 2; + mant1 >>= 1; + exp1++; + } + + /* turn off hidden bit */ + mant1 &= ~(HIDDEN<<4); + + /* pack up and go home */ + if (exp1 >= 0x100) + *pfl1 = (sign ? (SIGNBIT | __INFINITY) : __INFINITY); + else if (exp1 < 0) + *pfl1 = 0; + else + *pfl1 = PACK (sign ? SIGNBIT : 0 , exp1, mant1>>4); + return (a1); +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_fscmp.c b/hardware/tools/stm8/lib/src/_fscmp.c new file mode 100644 index 0000000..6b44f28 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_fscmp.c @@ -0,0 +1,102 @@ +/*------------------------------------------------------------------------- + _fscmp.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +static void dummy(void) __naked +{ + __asm + + .globl fs_compare_uint32 +fs_compare_uint32: + mov r1, #1 + mov r2, dpl + mov a, @r0 + mov dpl, r7 + cjne a, dpl, compare32_done + dec r0 + mov a, @r0 + cjne a, b, compare32_done + dec r0 + mov a, @r0 + cjne a, dph, compare32_done + dec r0 + mov a, @r0 + mov dpl, r2 + cjne a, dpl, compare32_done + mov r1, #0 +compare32_done: + ret + + + .globl fs_check_negative_zeros +fs_check_negative_zeros: +a_check: + cjne a, #0x80, a_not_neg_zero + mov a, b + jnz a_not_neg_zero_cleanup + mov a, dph + jnz a_not_neg_zero_cleanup + mov a, dpl + jnz a_not_neg_zero_cleanup + mov r7, #0 +a_not_neg_zero_cleanup: + mov a, r7 +a_not_neg_zero: + +b_check: + cjne @r0, #0x80, b_not_neg_zero + dec r0 + cjne @r0, #0, b_not_neg_zero_cleanup_1 + dec r0 + cjne @r0, #0, b_not_neg_zero_cleanup_2 + dec r0 + cjne @r0, #0, b_not_neg_zero_cleanup_3 + inc r0 + inc r0 + inc r0 + mov @r0, #0 + ret +b_not_neg_zero_cleanup_3: + inc r0 +b_not_neg_zero_cleanup_2: + inc r0 +b_not_neg_zero_cleanup_1: + inc r0 +b_not_neg_zero: + ret + + __endasm; +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_fsdiv.c b/hardware/tools/stm8/lib/src/_fsdiv.c new file mode 100644 index 0000000..72893bc --- /dev/null +++ b/hardware/tools/stm8/lib/src/_fsdiv.c @@ -0,0 +1,366 @@ +/*------------------------------------------------------------------------- + _fsdiv.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +// float __fsdiv (float a, float b) __reentrant +static void dummy(void) __naked +{ + __asm + .globl ___fsdiv +___fsdiv: + // extract the two inputs, placing them into: + // sign exponent mantiassa + // ---- -------- --------- + // a: sign_a exp_a r4/r3/r2 + // b: sign_b exp_b r7/r6/r5 + + lcall fsgetargs + + // compute final sign bit + jnb sign_b, 00001$ + cpl sign_a +00001$: + + // if divisor is zero, ... + cjne r7, #0, 00003$ + // if dividend is also zero, return NaN + cjne r4, #0, 00002$ + ljmp fs_return_nan +00002$: + // but dividend is non-zero, return infinity + ljmp fs_return_inf +00003$: + // if dividend is zero, return zero + cjne r4, #0, 00004$ + ljmp fs_return_zero +00004$: + // if divisor is infinity, ... + mov a, exp_b + cjne a, #0xFF, 00006$ + // and dividend is also infinity, return NaN + mov a, exp_a + cjne a, #0xFF, 00005$ + ljmp fs_return_nan +00005$: + // but dividend is not infinity, return zero + ljmp fs_return_zero +00006$: + // if dividend is infinity, return infinity + mov a, exp_a + cjne a, #0xFF, 00007$ + ljmp fs_return_inf +00007$: + + // subtract exponents + clr c + subb a, exp_b + // if no carry then no underflow + jnc 00008$ + add a, #127 + jc 00009$ + ljmp fs_return_zero + +00008$: + add a, #128 + dec a + jnc 00009$ + ljmp fs_return_inf + +00009$: + mov exp_a, a + + // need extra bits on a's mantissa +#ifdef FLOAT_FULL_ACCURACY + clr c + mov a, r5 + subb a, r2 + mov a, r6 + subb a, r3 + mov a, r7 + subb a, r4 + jc 00010$ + dec exp_a + clr c + mov a, r2 + rlc a + mov r1, a + mov a, r3 + rlc a + mov r2, a + mov a, r4 + rlc a + mov r3, a + clr a + rlc a + mov r4, a + sjmp 00011$ +00010$: +#endif + clr a + xch a, r4 + xch a, r3 + xch a, r2 + mov r1, a +00011$: + + // begin long division + push exp_a +#ifdef FLOAT_FULL_ACCURACY + mov b, #25 +#else + mov b, #24 +#endif +00012$: + // compare + clr c + mov a, r1 + subb a, r5 + mov a, r2 + subb a, r6 + mov a, r3 + subb a, r7 + mov a, r4 + subb a, #0 // carry==0 if mant1 >= mant2 + +#ifdef FLOAT_FULL_ACCURACY + djnz b, 00013$ + sjmp 00015$ +00013$: +#endif + jc 00014$ + // subtract + mov a, r1 + subb a, r5 + mov r1, a + mov a, r2 + subb a, r6 + mov r2, a + mov a, r3 + subb a, r7 + mov r3, a + mov a, r4 + subb a, #0 + mov r4, a + clr c + +00014$: + // shift result + cpl c + mov a, r0 + rlc a + mov r0, a + mov a, dpl + rlc a + mov dpl, a + mov a, dph + rlc a + mov dph, a + + // shift partial remainder + clr c + mov a, r1 + rlc a + mov r1, a + mov a, r2 + rlc a + mov r2, a + mov a, r3 + rlc a + mov r3, a + mov a, r4 + rlc a + mov r4, a + +#ifdef FLOAT_FULL_ACCURACY + sjmp 00012$ +00015$: +#else + djnz b, 00012$ +#endif + + // now we've got a division result, so all we need to do + // is round off properly, normalize and output a float + +#ifdef FLOAT_FULL_ACCURACY + cpl c + clr a + mov r1, a + addc a, r0 + mov r2, a + clr a + addc a, dpl + mov r3, a + clr a + addc a, dph + mov r4, a + pop exp_a + jnc 00016$ + inc exp_a + // incrementing exp_a without checking carry is dangerous + mov r4, #0x80 +00016$: +#else + mov r1, #0 + mov a, r0 + mov r2, a + mov r3, dpl + mov r4, dph + pop exp_a +#endif + + lcall fs_normalize_a + ljmp fs_zerocheck_return + __endasm; +} + +#else + +/* +** libgcc support for software floating point. +** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved. +** Permission is granted to do *anything* you want with this file, +** commercial or otherwise, provided this message remains intact. So there! +** I would appreciate receiving any updates/patches/changes that anyone +** makes, and am willing to be the repository for said changes (am I +** making a big mistake?). +** +** Pat Wood +** Pipeline Associates, Inc. +** pipeline!phw@motown.com or +** sun!pipeline!phw or +** uunet!motown!pipeline!phw +*/ + +/* (c)2000/2001: hacked a little by johan.knol@iduna.nl for sdcc */ + +union float_long + { + float f; + long l; + }; + +/* divide two floats */ +static float __fsdiv_org (float a1, float a2) +{ + volatile union float_long fl1, fl2; + volatile long result; + volatile unsigned long mask; + volatile long mant1, mant2; + volatile int exp; + char sign; + + fl1.f = a1; + fl2.f = a2; + + /* subtract exponents */ + exp = EXP (fl1.l) ; + exp -= EXP (fl2.l); + exp += EXCESS; + + /* compute sign */ + sign = SIGN (fl1.l) ^ SIGN (fl2.l); + + /* divide by zero??? */ + if (!fl2.l) + {/* return NaN or -NaN */ + fl2.l = 0x7FC00000; + return (fl2.f); + } + + /* numerator zero??? */ + if (!fl1.l) + return (0); + + /* now get mantissas */ + mant1 = MANT (fl1.l); + mant2 = MANT (fl2.l); + + /* this assures we have 25 bits of precision in the end */ + if (mant1 < mant2) + { + mant1 <<= 1; + exp--; + } + + /* now we perform repeated subtraction of fl2.l from fl1.l */ + mask = 0x1000000; + result = 0; + while (mask) + { + if (mant1 >= mant2) + { + result |= mask; + mant1 -= mant2; + } + mant1 <<= 1; + mask >>= 1; + } + + /* round */ + result += 1; + + /* normalize down */ + exp++; + result >>= 1; + + result &= ~HIDDEN; + + /* pack up and go home */ + if (exp >= 0x100) + fl1.l = (sign ? SIGNBIT : 0) | __INFINITY; + else if (exp < 0) + fl1.l = 0; + else + fl1.l = PACK (sign ? SIGNBIT : 0 , exp, result); + return (fl1.f); +} + +float __fsdiv (float a1, float a2) +{ + float f; + unsigned long *p = (unsigned long *) &f; + + if (a2 == 0.0f && a1 > 0.0f) + *p = 0x7f800000; // inf + else if (a2 == 0.0f && a1 < 0.0f) + *p = 0xff800000; // -inf + else if (a2 == 0.0f && a1 == 0.0f) + *p = 0xffc00000; // nan + else + f = __fsdiv_org (a1, a2); + + return f; +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_fseq.c b/hardware/tools/stm8/lib/src/_fseq.c new file mode 100644 index 0000000..77c4ea7 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_fseq.c @@ -0,0 +1,97 @@ +/*------------------------------------------------------------------------- + _fseq.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +// char __fseq (float a, float b) +static void dummy(void) __naked +{ + __asm + .globl ___fseq +___fseq: + mov r7, a + mov r0, sp + dec r0 + dec r0 + lcall fs_check_negative_zeros + lcall fs_compare_uint32 + mov a, r1 + xrl a, #1 + mov dpl, a + ret + __endasm; +} + +#else + +/* +** libgcc support for software floating point. +** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved. +** Permission is granted to do *anything* you want with this file, +** commercial or otherwise, provided this message remains intact. So there! +** I would appreciate receiving any updates/patches/changes that anyone +** makes, and am willing to be the repository for said changes (am I +** making a big mistake?). +** +** Pat Wood +** Pipeline Associates, Inc. +** pipeline!phw@motown.com or +** sun!pipeline!phw or +** uunet!motown!pipeline!phw +*/ + +/* (c)2000/2001: hacked a little by johan.knol@iduna.nl for sdcc */ + +union float_long + { + float f; + long l; + }; + +/* compare two floats */ +char +__fseq (float a1, float a2) +{ + volatile union float_long fl1, fl2; + + fl1.f = a1; + fl2.f = a2; + + if (fl1.l == fl2.l) + return (1); + if (((fl1.l | fl2.l) & 0x7FFFFFFF) == 0) + return (1); + return (0); +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_fsget1arg.c b/hardware/tools/stm8/lib/src/_fsget1arg.c new file mode 100644 index 0000000..111355b --- /dev/null +++ b/hardware/tools/stm8/lib/src/_fsget1arg.c @@ -0,0 +1,61 @@ +/*------------------------------------------------------------------------- + _fsget1arg.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +static void dummy(void) __naked +{ + // input passed in a,b,dph,dpl + __asm + .globl fsgetarg +fsgetarg: + // extract the input, placing it into: + // sign exponent mantissa + // ---- -------- -------- + // a: sign_a exp_a r4/r3/r2 + // + mov r2, dpl + mov r3, dph + mov c, b.7 + rlc a + mov sign_a, c + mov exp_a, a + jz 00001$ + setb b.7 +00001$: + mov r4, b + ret + __endasm; +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_fsget2args.c b/hardware/tools/stm8/lib/src/_fsget2args.c new file mode 100644 index 0000000..b565b79 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_fsget2args.c @@ -0,0 +1,85 @@ +/*------------------------------------------------------------------------- + _fsget2args.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +static void dummy(void) __naked +{ + // arg1: passed in a,b,dph,dpl + // arg2: passed on stack + __asm + .globl fsgetargs +fsgetargs: + // extract the two inputs, placing them into: + // sign exponent mantissa + // ---- -------- -------- + // a: sign_a exp_a r4/r3/r2 + // b: sign_b exp_b r7/r6/r5 + // + mov r2, dpl + mov r3, dph + mov c, b.7 + rlc a + mov sign_a, c + mov exp_a, a + jz 00001$ + setb b.7 +00001$: + mov r4, b + // now extract the 2nd parameter from the stack + mov a, sp + add a, #249 + mov r0, a + mov a, @r0 + mov r5, a + inc r0 + mov a, @r0 + mov r6, a + inc r0 + mov b, @r0 + inc r0 + mov a, @r0 + mov c, b.7 + rlc a + mov sign_b, c + mov exp_b, a + jz 00002$ + setb b.7 +00002$: + mov r7, b + ret + __endasm; +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_fsgt.c b/hardware/tools/stm8/lib/src/_fsgt.c new file mode 100644 index 0000000..c2e854c --- /dev/null +++ b/hardware/tools/stm8/lib/src/_fsgt.c @@ -0,0 +1,129 @@ +/*------------------------------------------------------------------------- + _fsgt.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +// char __fsgt (float a, float b) __reentrant +static void dummy(void) __naked +{ + __asm + .globl ___fsgt +___fsgt: + mov r7, a + mov r0, sp + dec r0 + dec r0 + lcall fs_check_negative_zeros + setb sign_a + rlc a + mov a, @r0 + jc a_negative +a_positive: + jnb acc.7, ab_positive + // a is positive and b is negative, so a > b + mov dpl, #1 + ret +a_negative: + jb acc.7, ab_negative + // a is negative and b is positive, so a < b + mov dpl, #0 + ret +ab_positive: + clr sign_a +ab_negative: + lcall fs_compare_uint32 + mov a, r1 + jnz ab_different + // a and b are equal + mov dpl, a + ret +ab_different: + jnb sign_a, skip_invert + cpl c +skip_invert: + clr a + rlc a + mov dpl, a + ret + __endasm; +} + +#else + +/* +** libgcc support for software floating point. +** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved. +** Permission is granted to do *anything* you want with this file, +** commercial or otherwise, provided this message remains intact. So there! +** I would appreciate receiving any updates/patches/changes that anyone +** makes, and am willing to be the repository for said changes (am I +** making a big mistake?). +** +** Pat Wood +** Pipeline Associates, Inc. +** pipeline!phw@motown.com or +** sun!pipeline!phw or +** uunet!motown!pipeline!phw +*/ + +/* (c)2000/2001: hacked a little by johan.knol@iduna.nl for sdcc */ + +union float_long + { + float f; + long l; + }; + +/* compare two floats */ +char __fsgt (float a1, float a2) +{ + volatile union float_long fl1, fl2; + + fl1.f = a1; + fl2.f = a2; + + if (((fl1.l | fl2.l) & 0x7FFFFFFF) == 0) + return (0); + + if (fl1.l<0 && fl2.l<0) { + if (fl2.l > fl1.l) + return (1); + return (0); + } + + if (fl1.l > fl2.l) + return (1); + return (0); +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_fslt.c b/hardware/tools/stm8/lib/src/_fslt.c new file mode 100644 index 0000000..4059e26 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_fslt.c @@ -0,0 +1,129 @@ +/*------------------------------------------------------------------------- + _fslt.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +// char __fslt (float a, float b) +static void dummy(void) __naked +{ + __asm + .globl ___fslt +___fslt: + mov r7, a + mov r0, sp + dec r0 + dec r0 + lcall fs_check_negative_zeros + setb sign_a + rlc a + mov a, @r0 + jc a_negative +a_positive: + jnb acc.7, ab_positive + // a is positive and b is negative, so a > b + mov dpl, #0 + ret +a_negative: + jb acc.7, ab_negative + // a is negative and b is positive, so a < b + mov dpl, #1 + ret +ab_positive: + clr sign_a +ab_negative: + lcall fs_compare_uint32 + mov a, r1 + jnz ab_different + // a and b are equal + mov dpl, a + ret +ab_different: + jb sign_a, skip_invert + cpl c +skip_invert: + clr a + rlc a + mov dpl, a + ret + __endasm; +} + +#else + +/* +** libgcc support for software floating point. +** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved. +** Permission is granted to do *anything* you want with this file, +** commercial or otherwise, provided this message remains intact. So there! +** I would appreciate receiving any updates/patches/changes that anyone +** makes, and am willing to be the repository for said changes (am I +** making a big mistake?). +** +** Pat Wood +** Pipeline Associates, Inc. +** pipeline!phw@motown.com or +** sun!pipeline!phw or +** uunet!motown!pipeline!phw +*/ + +/* (c)2000/2001: hacked a little by johan.knol@iduna.nl for sdcc */ + +union float_long + { + float f; + long l; + }; + +/* compare two floats */ +char __fslt (float a1, float a2) +{ + volatile union float_long fl1, fl2; + + fl1.f = a1; + fl2.f = a2; + + if (((fl1.l | fl2.l) & 0x7FFFFFFF) == 0) + return (0); + + if (fl1.l<0 && fl2.l<0) { + if (fl2.l < fl1.l) + return (1); + return (0); + } + + if (fl1.l < fl2.l) + return (1); + return (0); +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_fsmul.c b/hardware/tools/stm8/lib/src/_fsmul.c new file mode 100644 index 0000000..e118bcf --- /dev/null +++ b/hardware/tools/stm8/lib/src/_fsmul.c @@ -0,0 +1,293 @@ +/*------------------------------------------------------------------------- + _fsmul.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +// float __fsmul (float a, float b) __reentrant +static void dummy(void) __naked +{ + __asm + .globl ___fsmul +___fsmul: + // extract the two inputs, placing them into: + // sign exponent mantissa + // ---- -------- -------- + // a: sign_a exp_a r4/r3/r2 + // b: sign_b exp_b r7/r6/r5 + + lcall fsgetargs + + // first check if either input is zero + cjne r4, #0, 00002$ +00001$: + ljmp fs_return_zero + +00002$: + mov a, r7 + jz 00001$ + + // compute final sign bit + jnb sign_b, 00003$ + cpl sign_a +00003$: + + // check if either input is infinity + mov a, exp_b + cjne a, #0xFF, 00004$ + ljmp fs_return_inf +00004$: + mov a, exp_a + cjne a, #0xFF, 00005$ + ljmp fs_return_inf +00005$: + + // add the exponents + add a, exp_b + // if carry then no underflow + jc 00006$ + add a, #130 + jc 00007$ + ljmp fs_return_zero + +00006$: + add a, #131 + dec a + jnc 00007$ + ljmp fs_return_inf + +00007$: + mov exp_a, a + + // now we need to multipy r4/r3/r2 * r7/r6/r5 + // ------------------------------------------ + // r2 * r5 << 0 + // r3 * r5 + r2 * r6 << 8 + // r4 * r5 + r3 * r6 + r2 * r7 << 16 + // r4 * r6 + r3 * r7 << 24 + // r4 * r7 << 32 + // + // This adds quite a bit of code, but it is a LOT faster + // than three calls to __mululong... + + // output goes into r4/r3/r2/r1/r0/xx + + mov a, r2 + mov b, r5 + mul ab // r2 * r5 + // discard lowest 8 bits + mov r0, b + // range 0-FE + + mov a, r2 + mov b, r6 + mul ab // r2 * r6 + add a, r0 + mov r0, a + clr a + addc a, b + mov r1, a + // range 0-FEFF + + mov a, r3 + mov b, r5 + mul ab // r3 * r5 + add a, r0 + // discard lowest 8 bits + mov a, r1 + addc a, b + mov r1, a + clr a + rlc a + xch a, r2 + // range 0-1FD + + mov b, r7 + mul ab // r2 * r7 + add a, r1 + mov r1, a + mov a, r2 + addc a, b + mov r2, a + // range 0-FFFE + + mov a, r3 + mov r0, a + mov b, r6 + mul ab // r3 * r6 + add a, r1 + mov r1, a + mov a, r2 + addc a, b + mov r2, a + clr a + rlc a + mov r3, a + // range 0-1FDFF + + mov a, r4 + mov b, r5 + mul ab // r4 * r5 + add a, r1 + mov r1, a + mov a, r2 + addc a, b + mov r2, a + clr a + addc a, r3 + mov r3, a + // range 0-2FC00 + + mov a, r0 // r3 + mov b, r7 + mul ab // r3 * r7 + add a, r2 + mov r2, a + mov a, r3 + addc a, b + mov r3, a + clr a + rlc a + xch a, r4 + // range 0-100FD00 + + mov r5, a + mov b, r6 + mul ab // r4 * r6 + add a, r2 + mov r2, a + mov a, r3 + addc a, b + mov r3, a + clr a + addc a, r4 + mov r4, a + // range 0-1FEFE00 + + mov a, r5 // r4 + mov b, r7 + mul ab // r4 * r7 + add a, r3 + mov r3, a + mov a, r4 + addc a, b + mov r4, a + // range 40000000-FFFFFE00 + + jb acc.7, 00010$ + lcall fs_normalize_a + +00010$: + ljmp fs_round_and_return + __endasm; +} + +#else + +/* +** libgcc support for software floating point. +** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved. +** Permission is granted to do *anything* you want with this file, +** commercial or otherwise, provided this message remains intact. So there! +** I would appreciate receiving any updates/patches/changes that anyone +** makes, and am willing to be the repository for said changes (am I +** making a big mistake?). +** +** Pat Wood +** Pipeline Associates, Inc. +** pipeline!phw@motown.com or +** sun!pipeline!phw or +** uunet!motown!pipeline!phw +*/ + +/* (c)2000/2001: hacked a little by johan.knol@iduna.nl for sdcc */ + +union float_long + { + float f; + unsigned long l; + }; + +/* multiply two floats */ +float __fsmul (float a1, float a2) { + volatile union float_long fl1, fl2; + volatile unsigned long result; + volatile int exp; + char sign; + + fl1.f = a1; + fl2.f = a2; + + if (!fl1.l || !fl2.l) + return (0); + + /* compute sign and exponent */ + sign = SIGN (fl1.l) ^ SIGN (fl2.l); + exp = EXP (fl1.l) - EXCESS; + exp += EXP (fl2.l); + + fl1.l = MANT (fl1.l); + fl2.l = MANT (fl2.l); + + /* the multiply is done as one 16x16 multiply and two 16x8 multiples */ + result = (fl1.l >> 8) * (fl2.l >> 8); + result += ((fl1.l & (unsigned long) 0xFF) * (fl2.l >> 8)) >> 8; + result += ((fl2.l & (unsigned long) 0xFF) * (fl1.l >> 8)) >> 8; + + /* round, phase 1 */ + result += 0x40; + + if (result & SIGNBIT) + { + /* round, phase 2 */ + result += 0x40; + result >>= 8; + } + else + { + result >>= 7; + exp--; + } + + result &= ~HIDDEN; + + /* pack up and go home */ + if (exp >= 0x100) + fl1.l = (sign ? SIGNBIT : 0) | __INFINITY; + else if (exp < 0) + fl1.l = 0; + else + fl1.l = PACK (sign ? SIGNBIT : 0 , exp, result); + return (fl1.f); +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_fsneq.c b/hardware/tools/stm8/lib/src/_fsneq.c new file mode 100644 index 0000000..b4f106c --- /dev/null +++ b/hardware/tools/stm8/lib/src/_fsneq.c @@ -0,0 +1,94 @@ +/*------------------------------------------------------------------------- + _fsneq.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +// char __fsneq (float a, float b) +static void dummy(void) __naked +{ + __asm + .globl ___fsneq +___fsneq: + mov r7, a + mov r0, sp + dec r0 + dec r0 + lcall fs_check_negative_zeros + lcall fs_compare_uint32 + mov dpl, r1 + ret + __endasm; +} + +#else + +/* +** libgcc support for software floating point. +** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved. +** Permission is granted to do *anything* you want with this file, +** commercial or otherwise, provided this message remains intact. So there! +** I would appreciate receiving any updates/patches/changes that anyone +** makes, and am willing to be the repository for said changes (am I +** making a big mistake?). +** +** Pat Wood +** Pipeline Associates, Inc. +** pipeline!phw@motown.com or +** sun!pipeline!phw or +** uunet!motown!pipeline!phw +*/ + +/* (c)2000/2001: hacked a little by johan.knol@iduna.nl for sdcc */ + +union float_long + { + float f; + long l; + }; + +/* compare two floats */ +char __fsneq (float a1, float a2) +{ + volatile union float_long fl1, fl2; + + fl1.f = a1; + fl2.f = a2; + + if (fl1.l == fl2.l) + return (0); + if (((fl1.l | fl2.l) & 0x7FFFFFFF) == 0) + return (0); + return (1); +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_fsnormalize.c b/hardware/tools/stm8/lib/src/_fsnormalize.c new file mode 100644 index 0000000..4695da8 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_fsnormalize.c @@ -0,0 +1,93 @@ +/*------------------------------------------------------------------------- + _fsnormalize.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +static void dummy(void) __naked +{ + __asm + .globl fs_normalize_a +fs_normalize_a: +#ifdef FLOAT_SHIFT_SPEEDUP + mov r0, #4 + mov a, r4 +00001$: + jnz 00003$ + mov a, exp_a + add a, #248 + jnc 00002$ ;denormalized + mov exp_a, a + clr a + xch a, r1 + xch a, r2 + xch a, r3 + mov r4, a + //mov r4, ar3 + //mov r3, ar2 + //mov r2, ar1 + //mov r1, #0 + djnz r0, 00001$ + ret +#endif +00002$: + mov a, r4 +00003$: + mov r0, #32 + inc exp_a +00004$: + jb acc.7, 00006$ + djnz exp_a, 00005$ + ret ;denormalized +00005$: + clr c + mov a, r1 + rlc a + mov r1, a + mov a, r2 + rlc a + mov r2, a + mov a, r3 + rlc a + mov r3, a + mov a, r4 + rlc a + mov r4, a + djnz r0, 00004$ +00006$: + dec exp_a + ret + __endasm; +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_fsreturnval.c b/hardware/tools/stm8/lib/src/_fsreturnval.c new file mode 100644 index 0000000..f2d3aa9 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_fsreturnval.c @@ -0,0 +1,115 @@ +/*------------------------------------------------------------------------- + _fsreturnval.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +static void dummy(void) __naked +{ + __asm + + .globl fs_round_and_return +fs_round_and_return: +#ifdef FLOAT_FULL_ACCURACY + // discard the extra 8 bits of precision we kept around in r1 + cjne r1, #128, 00001$ + mov a, r2 + rrc a + cpl c +00001$: + jc fs_zerocheck_return + mov a, r2 + add a, #1 + mov r2, a + clr a + addc a, r3 + mov r3, a + clr a + addc a, r4 + mov r4, a + jnc fs_zerocheck_return + mov r4, #0x80 + inc exp_a +#endif + + .globl fs_zerocheck_return +fs_zerocheck_return: + // zero output is a special case + cjne r4, #0, fs_direct_return + cjne r3, #0, fs_direct_return + cjne r2, #0, fs_direct_return + + .globl fs_return_zero +fs_return_zero: + clr a + mov b, a + mov dph, a + mov dpl, a + ret + + .globl fs_direct_return +fs_direct_return: + // collect all pieces and return + mov c, sign_a + mov a, exp_a + rrc a + mov b, r4 + mov b.7, c + mov dph, r3 + mov dpl, r2 + ret + + .globl fs_return_inf +fs_return_inf: + clr a + mov dph, a + mov dpl, a + mov b, #0x80 + cpl a + mov c, sign_a + rrc a + ret + + .globl fs_return_nan +fs_return_nan: + clr a + mov dph, a + mov dpl, a + mov b, #0xC0 + mov a, #0x7F + ret + + __endasm; +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_fsrshift.c b/hardware/tools/stm8/lib/src/_fsrshift.c new file mode 100644 index 0000000..1399ad2 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_fsrshift.c @@ -0,0 +1,110 @@ +/*------------------------------------------------------------------------- + _fsrshift.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +static void dummy(void) __naked +{ + __asm + .globl fs_rshift_a +fs_rshift_a: + jz 00020$ + mov r0, a + add a, exp_a // adjust exponent + jnc 00001$ + mov a, #255 // don't roll over +00001$: + mov exp_a, a +#ifdef FLOAT_SHIFT_SPEEDUP + mov a, r0 + add a, #248 + jnc 00003$ + xch a, r4 + xch a, r3 + xch a, r2 + mov r1, a + clr a + xch a, r4 + //mov r1, ar2 // avoid dependence on register bank + //mov r2, ar3 + //mov r3, ar4 + //mov r4, #0 + add a, #248 + jnc 00003$ + xch a, r3 + xch a, r2 + mov r1, a + clr a + xch a, r3 + //mov r1, ar2 + //mov r2, ar3 + //mov r3, #0 + add a, #248 + jnc 00003$ + xch a, r2 + mov r1, a + clr a + xch a, r2 + //mov r1, ar2 + //mov r2, #0 + add a, #248 + jnc 00003$ + mov r1, #0 + ret +00003$: + add a, #8 + jz 00020$ + mov r0, a +#endif +00005$: + clr c + mov a, r4 + rrc a + mov r4, a + mov a, r3 + rrc a + mov r3, a + mov a, r2 + rrc a + mov r2, a + mov a, r1 + rrc a + mov r1, a + djnz r0, 00005$ +00020$: + ret + __endasm; +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_fssub.c b/hardware/tools/stm8/lib/src/_fssub.c new file mode 100644 index 0000000..b41b46e --- /dev/null +++ b/hardware/tools/stm8/lib/src/_fssub.c @@ -0,0 +1,79 @@ +/*------------------------------------------------------------------------- + _fssub.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +//float __fssub (float a, float b) __reentrant +static void dummy(void) __naked +{ + __asm + .globl ___fssub +___fssub: + mov r0, sp + dec r0 + dec r0 + xch a, @r0 + cpl acc.7 + xch a, @r0 + ljmp ___fsadd + __endasm; +} + +#else + +/* +** libgcc support for software floating point. +** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved. +** Permission is granted to do *anything* you want with this file, +** commercial or otherwise, provided this message remains intact. So there! +** I would appreciate receiving any updates/patches/changes that anyone +** makes, and am willing to be the repository for said changes (am I +** making a big mistake?). +** +** Pat Wood +** Pipeline Associates, Inc. +** pipeline!phw@motown.com or +** sun!pipeline!phw or +** uunet!motown!pipeline!phw +*/ + +/* (c)2000/2001: hacked a little by johan.knol@iduna.nl for sdcc */ + +/* subtract two floats */ +float __fssub (float a1, float a2) +{ + float neg = -a1; + return -(neg + a2); +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_fsswapargs.c b/hardware/tools/stm8/lib/src/_fsswapargs.c new file mode 100644 index 0000000..9b6fdbc --- /dev/null +++ b/hardware/tools/stm8/lib/src/_fsswapargs.c @@ -0,0 +1,69 @@ +/*------------------------------------------------------------------------- + _fsswapargs.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +static void dummy(void) __naked +{ + __asm + .globl fs_swap_a_b +fs_swap_a_b: + mov a, exp_a + xch a, exp_b + mov exp_a, a + // is there a faster way to swap these 2 bits??? + // this trick with psw can play havoc with the resiter bank setting + // mov a, psw + // swap a // depends on sign bits in psw.1 & psw.5 + // mov psw, a + mov c, sign_a + rlc a + mov c, sign_b + mov sign_a, c + rrc a + mov sign_b, c + mov a, r4 + xch a, r7 + mov r4, a + mov a, r3 + xch a, r6 + mov r3, a + mov a, r2 + xch a, r5 + mov r2, a + ret + __endasm; +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_gptrget.c b/hardware/tools/stm8/lib/src/_gptrget.c new file mode 100644 index 0000000..64b71c4 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_gptrget.c @@ -0,0 +1,288 @@ +/*------------------------------------------------------------------------- + _gptrget.c - get value for a generic pointer + + Copyright (c) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* not all devices use P2 to page pdata memory, therefore __XPAGE was + introduced. On some targets __XPAGE itself is a paged SFR so it is + not safe for all platforms to set this. Furthermore some targets + can be configured to behave differently for movx @dptr vs. movx @Ri + (don't drive high byte of address bus for movx @Ri only) */ +#define USE_PDATA_PAGING_REGISTER 0 + +__sbit __at (0xF7) B_7; +__sbit __at (0xF6) B_6; +__sbit __at (0xF5) B_5; + +/* the return value is expected to be in acc, and not in the standard + * location dpl. Therefore we choose return type void here: */ +#if defined DSDCC_MODEL_HUGE +void +_gptrget (char *gptr) __naked +{ +/* This is the banked version with pointers up to 23 bits. + B cannot be trashed */ + + gptr; /* hush the compiler */ + + __asm + ; + ; depending on the pointer type acc. to SDCCsymt.h + ; + jb _B_7,codeptr$ ; >0x80 code ; 3 + jnb _B_6,xdataptr$ ; <0x40 far ; 3 + + mov dph,r0 ; save r0 independant of regbank ; 2 + mov r0,dpl ; use only low order address ; 2 + + jb _B_5,pdataptr$ ; >0x60 pdata ; 3 + ; + ; Pointer to data space + ; + mov a,@r0 ; 1 + dataptrrestore$: + mov r0,dph ; restore r0 ; 2 + mov dph,#0 ; restore dph ; 2 + ret ; 1 + ; + ; pointer to external stack or pdata + ; + pdataptr$: + movx a,@r0 ; 1 + sjmp dataptrrestore$ ; 2 + ; + ; pointer to code area + ; + codeptr$: + ; implementation for SiLabs C8051F12x + mov a,b ; 2 + anl a,#0x03 ; 2 + swap a ; 1 + push _PSBANK ; 2 + anl _PSBANK,#0x0F ; 3 + orl _PSBANK,a ; 2 + + clr a ; 1 + movc a,@a+dptr ; 1 + pop _PSBANK ; 2 + ret ; 1 + ; + ; pointer to xternal data + ; + xdataptr$: + ; implementation for xram a16-a21 tied to P3 + mov _P3,b ; 3 + + movx a,@dptr ; 1 + ret ; 1 + ;=== + ;44 bytes + __endasm; +} + +#elif defined DSDCC_MODEL_MEDIUM + +void +_gptrget (char *gptr) __naked +{ +/* This is the non-banked version with pointers up to 15 bits. + Assumes B is free to be used */ + + gptr; /* hush the compiler */ + + __asm + ; + ; depending on the pointer type acc. to SDCCsymt.h + ; + mov b,dph ; 3 + jb _B_7,codeptr$ ; >0x80 code ; 3 + jnb _B_6,xdataptr$ ; <0x40 far ; 3 + + mov b,r0 ; save r0 independant of regbank ; 2 + mov r0,dpl ; use only low order address ; 2 + + jb _B_5,pdataptr$ ; >0x60 pdata ; 3 + ; + ; Pointer to data space + ; + mov a,@r0 ; 1 + mov r0,b ; restore r0 ; 2 + ret ; 1 + ; + ; pointer to xternal stack or pdata + ; + pdataptr$: + movx a,@r0 ; 1 + mov r0,b ; restore r0 ; 2 + ret ; 1 + ; + ; pointer to code area, max 15 bits + ; + codeptr$: + ; 0x8000 <= dptr <= 0xFFFF + ; no need to AND dph and restore from B if hardware wraps code memory + anl dph,#0x7F ; 3 + clr a ; 1 + movc a,@a+dptr ; 1 + mov dph,b ; 3 + ret ; 1 + ; + ; pointer to xternal data, max 14 bits + ; + xdataptr$: + ; 0 <= dptr <= 0x3FFF + movx a,@dptr ; 1 + ret ; 1 + ;=== + ;35 bytes + __endasm; +} + +#else + +void +_gptrget (char *gptr) __naked +{ +/* This is the new version with pointers up to 16 bits. + B cannot be trashed */ + + gptr; /* hush the compiler */ + + __asm + ; + ; depending on the pointer type acc. to SDCCsymt.h + ; + jb _B_7,codeptr$ ; >0x80 code ; 3 + jnb _B_6,xdataptr$ ; <0x40 far ; 3 + + mov dph,r0 ; save r0 independant of regbank ; 2 + mov r0,dpl ; use only low order address ; 2 + + jb _B_5,pdataptr$ ; >0x60 pdata ; 3 + ; + ; Pointer to data space + ; + mov a,@r0 ; 1 + dataptrrestore$: + mov r0,dph ; restore r0 ; 2 + mov dph,#0 ; restore dph ; 2 + ret ; 1 + ; + ; pointer to xternal stack or pdata + ; + pdataptr$: + movx a,@r0 ; 1 + sjmp dataptrrestore$ ; 2 + ; + ; pointer to code area, max 16 bits + ; + codeptr$: + clr a ; 1 + movc a,@a+dptr ; 1 + ret ; 1 + ; + ; pointer to xternal data, max 16 bits + ; + xdataptr$: + movx a,@dptr ; 1 + ret ; 1 + ;=== + ;27 bytes + __endasm; +} + +#endif + +#ifdef __SDCC_ds390 +/* the return value is expected to be in acc/acc1, and not in the standard + * location dpl/dph. Therefore we choose return type void here: */ + +void +_gptrgetWord (unsigned *gptr) +{ + gptr; /* hush the compiler */ + + __asm + ; + ; depending on the pointer type acc. to SDCCsymt.h + ; + jb _B_7,00003$ ; >0x80 code + jnb _B_6,00002$ ; <0x40 far + + mov dph,r0 ; save r0 independant of regbank + mov r0,dpl ; use only low order address + + jb _B_5,00004$ ; >0x60 pdata + ; + ; Pointer to data space + ; + mov acc1,@r0 + inc r0 + mov a,@r0 + inc dpl + sjmp 00005$ + ; + ; pointer to xternal data + ; + 00002$: + movx a,@dptr + mov acc1,a + inc dptr + movx a,@dptr + sjmp 00006$ +; +; pointer to code area +; + 00003$: + clr a + movc a,@a+dptr + mov acc1,a + clr a + inc dptr + movc a,@a+dptr + sjmp 00006$ +; +; pointer to xternal stack +; + 00004$: + movx a,@r0 + mov acc1,a + inc r0 + movx a,@r0 + inc dpl +; +; restore and return +; + 00005$: + mov r0,dph ; restore r0 + mov dph,#0 ; restore dph + 00006$: + xch a,acc1 + __endasm; + +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_gptrgetc.c b/hardware/tools/stm8/lib/src/_gptrgetc.c new file mode 100644 index 0000000..b67755d --- /dev/null +++ b/hardware/tools/stm8/lib/src/_gptrgetc.c @@ -0,0 +1,145 @@ +/*------------------------------------------------------------------------- + _gptrgetc.c - get value for a generic pointer (used with --xram-movc) + + Copyright (c) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + +/* the return value is expected to be in acc, and not in the standard + * location dpl. Therefore we choose return type void here: */ + +#if 1 + +void +_gptrgetc (char *gptr) __naked +{ +/* This is the new version with pointers up to 16 bits. + B cannot be trashed */ + + gptr; /* hush the compiler */ + + __asm + ; save values passed + ; + ; depending on the pointer type acc. to SDCCsymt.h + ; + jb _B_7,codeptr$ ; >0x80 code ; 3 + jnb _B_6,xdataptr$ ; <0x40 far ; 3 + + mov dph,r0 ; save r0 independant of regbank ; 2 + mov r0,dpl ; use only low order address ; 2 + + jb _B_5,pdataptr$ ; >0x60 pdata ; 3 + ; + ; Pointer to data space + ; + mov a,@r0 ; 1 + mov r0,dph ; restore r0 ; 2 + mov dph,#0 ; restore dph ; 2 + ret ; 1 + ; + ; pointer to external stack or pdata + ; + pdataptr$: + movx a,@r0 ; 1 + mov r0,dph ; restore r0 ; 2 + mov dph,#0 ; restore dph ; 2 + ret ; 1 +; +; pointer to xternal data +; pointer to code area +; + codeptr$: + xdataptr$: + clr a ; 1 + movc a,@a+dptr ; 1 + ret ; 1 + ;=== + ;28 bytes + __endasm; +} + +#else + +void +_gptrgetc (char *gptr) __naked +{ + gptr; /* hush the compiler */ + + __asm + ; save values passed + xch a,r0 + push acc + ; + ; depending on the pointer type acc. to SDCCsymt.h + ; + mov a,b + jz 00001$ ; 0 near + dec a + jz 00003$ ; 1 far + dec a + jz 00003$ ; 2 code + dec a + jz 00004$ ; 3 pdata + dec a ; 4 skip generic pointer + dec a + jz 00001$ ; 5 idata + ; + ; any other value for type + ; return xFF + mov a,#0xff + ret + ; + ; Pointer to data space + ; + 00001$: + mov r0,dpl ; use only low order address + mov a,@r0 + ret +; +; pointer to xternal data +; pointer to code area +; + 00003$: + ; clr a is already 0 + movc a,@a+dptr + ret +; +; pointer to xternal stack +; + 00004$: + mov r0,dpl + movx a,@r0 +; +; restore and return +; + mov r0,a + pop acc + xch a,r0 + ret + __endasm; + +} +#endif diff --git a/hardware/tools/stm8/lib/src/_gptrput.c b/hardware/tools/stm8/lib/src/_gptrput.c new file mode 100644 index 0000000..111f84a --- /dev/null +++ b/hardware/tools/stm8/lib/src/_gptrput.c @@ -0,0 +1,259 @@ +/*------------------------------------------------------------------------- + _gptrput.c - put value for a generic pointer + + Copyright (c) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* not all devices use P2 to page pdata memory, therefore __XPAGE was + introduced. On some targets __XPAGE itself is a paged SFR so it is + not safe for all platforms to set this. Furthermore some targets + can be configured to behave differently for movx @dptr vs. movx @Ri + (don't drive high byte of address bus for movx @Ri only) */ +#define USE_PDATA_PAGING_REGISTER 0 + +__sbit __at (0xF7) B_7; +__sbit __at (0xF6) B_6; +__sbit __at (0xF5) B_5; + +#if defined DSDCC_MODEL_HUGE +void +_gptrput (char *gptr, char c) __naked +{ +/* This is the banked version with pointers up to 22 bits. + B cannot be trashed */ + + gptr; c; /* hush the compiler */ + + __asm + ; + ; depending on the pointer type according to SDCCsymt.h + ; + jb _B_7,codeptr$ ; >0x80 code ; 3 + jnb _B_6,xdataptr$ ; <0x40 far ; 3 + + mov dph,r0 ; save r0 independant of regbank ; 2 + mov r0,dpl ; use only low order address ; 2 + + jb _B_5,pdataptr$ ; >0x60 pdata ; 3 + ; + ; store into near/idata space + ; + mov @r0,a ; 1 + dataptrrestore$: + mov r0,dph ; restore r0 ; 2 + mov dph,#0 ; restore dph ; 2 + ret ; 1 + ; + ; cannot store into code space, lock up + ; + codeptr$: + sjmp . ; 2 + ; + ; store into external stack/pdata space + ; + pdataptr$: + movx @r0,a ; 1 + sjmp dataptrrestore$ ; 2 + ; + ; store into far space + ; + xdataptr$: + mov _P3,b ; 3 + + movx @dptr,a ; 1 + ret ; 1 + + ;=== + ;29 bytes + __endasm; +} + +#elif defined DSDCC_MODEL_MEDIUM + +void +_gptrput (char *gptr, char c) __naked +{ +/* This is the non-banked version with pointers up to 14 bits. + Assumes B is free to be used */ + + gptr; c; /* hush the compiler */ + + __asm + ; + ; depending on the pointer type according to SDCCsymt.h + ; + mov b,dph ; 3 + jb _B_7,codeptr$ ; >0x80 code ; 3 + jnb _B_6,xdataptr$ ; <0x40 far ; 3 + + mov b,r0 ; save r0 independant of regbank ; 2 + mov r0,dpl ; use only low order address ; 2 + + jb _B_5,pdataptr$ ; >0x60 pdata ; 3 + ; + ; store into near/idata space + ; + mov @r0,a ; 1 + dataptrrestore$: + mov r0,b ; restore r0 ; 2 + ret ; 1 + ; + ; cannot store into code space, lock up + ; + codeptr$: + sjmp . ; 2 + ; + ; store into external stack/pdata space + ; + pdataptr$: + movx @r0,a ; 1 + sjmp dataptrrestore$ ; 2 + ; + ; store into far space, max 14 bits + ; + xdataptr$: + ; 0 <= dptr <= 0x3FFF + movx @dptr,a ; 1 + ret ; 1 + ;=== + ;27 bytes + __endasm; +} + +#else + +void +_gptrput (char *gptr, char c) __naked +{ +/* This is the new version with pointers up to 16 bits. + B cannot be trashed */ + + gptr; c; /* hush the compiler */ + + __asm + ; + ; depending on the pointer type according to SDCCsymt.h + ; + jb _B_7,codeptr$ ; >0x80 code ; 3 + jnb _B_6,xdataptr$ ; <0x40 far ; 3 + + mov dph,r0 ; save r0 independant of regbank ; 2 + mov r0,dpl ; use only low order address ; 2 + + jb _B_5,pdataptr$ ; >0x60 pdata ; 3 + ; + ; store into near/idata space + ; + mov @r0,a ; 1 + dataptrrestore$: + mov r0,dph ; restore r0 ; 2 + mov dph,#0 ; restore dph ; 2 + ret ; 1 + ; + ; cannot store into code space, lock up + ; + codeptr$: + sjmp . ; 2 + ; + ; store into external stack/pdata space + ; + pdataptr$: + movx @r0,a ; 1 + sjmp dataptrrestore$ ; 2 + ; + ; store into far space + ; + xdataptr$: + movx @dptr,a ; 1 + ret ; 1 + + ;=== + ;26 bytes + __endasm; +} + +#endif + +#ifdef __SDCC_ds390 + +void +_gptrputWord (int *gptr, int w) __naked +{ +/* The ds390 can write two bytes in one go. + B cannot be trashed */ + + gptr; w; /* hush the compiler */ + + __asm + ; + ; depending on the pointer type acc. to SDCCsymt.h + ; + jb _B_7,codeptr_w$ ; >0x80 code + jnb _B_6,xdataptr_w$ ; <0x40 far + + mov dph,r0 ; save r0 independant of regbank + mov r0,dpl ; use only low order address + + jb _B_5,pdataptr_w$ ; >0x60 pdata +; +; store into near space +; + mov @r0,acc1 + inc r0 + mov @r0,a + dataptrrestore_w$: + mov dpl,r0 + mov r0,dph ; restore r0 + mov dph,#0 ; restore dph + ret + ; + ; cannot store into code space, lock up + ; + codeptr_w$: + sjmp . +; +; store into xstack space +; + pdataptr_w$: + xch a,acc1 + movx @r0,a + inc r0 + xch a,acc1 + movx @r0, a + sjmp dataptrrestore_w$ +; +; store into far space +; + xdataptr_w$: + xch a,acc1 + movx @dptr,a + inc dptr + xch a,acc1 + movx @dptr,a + ret + __endasm; +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_heap.c b/hardware/tools/stm8/lib/src/_heap.c new file mode 100644 index 0000000..be0ca39 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_heap.c @@ -0,0 +1,41 @@ +/*------------------------------------------------------------------------- + _heap.c - memory heap for malloc and friends + + Copyright (C) 2006, Maarten Brock, sourceforge.brock@dse.nl + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* + This is the default heap. If you need a different size (make a copy and) + recompile it with -D HEAP_SIZE= where is whatever you need. + Link the resulting object explicitly with your project. +*/ + +#ifndef HEAP_SIZE +#define HEAP_SIZE 1024 +#endif + +__xdata char __sdcc_heap[HEAP_SIZE]; +const unsigned int __sdcc_heap_size = HEAP_SIZE; + diff --git a/hardware/tools/stm8/lib/src/_itoa.c b/hardware/tools/stm8/lib/src/_itoa.c new file mode 100644 index 0000000..5f96bc2 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_itoa.c @@ -0,0 +1,73 @@ +/*------------------------------------------------------------------------- + _itoa.c - integer to string conversion + + Copyright (c) 1999, Bela Torok, bela.torok@kssg.ch + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/*------------------------------------------------------------------------- + usage: + + _uitoa(unsigned int value, char* string, int radix) + _itoa(int 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) +---------------------------------------------------------------------------*/ + +void _uitoa(unsigned int value, char* string, unsigned char radix) +{ + signed char index = 0, i = 0; + + /* generate the number in reverse order */ + do { + string[index] = '0' + (value % radix); + if (string[index] > '9') + string[index] += 'A' - '9' - 1; + value /= radix; + ++index; + } while (value != 0); + + /* null terminate the string */ + string[index--] = '\0'; + + /* reverse the order of digits */ + while (index > i) { + char tmp = string[i]; + string[i] = string[index]; + string[index] = tmp; + ++i; + --index; + } +} + +void _itoa(int value, char* string, unsigned char radix) +{ + if (value < 0 && radix == 10) { + *string++ = '-'; + value = -value; + } + _uitoa(value, string, radix); +} diff --git a/hardware/tools/stm8/lib/src/_logexpf.c b/hardware/tools/stm8/lib/src/_logexpf.c new file mode 100644 index 0000000..f89046c --- /dev/null +++ b/hardware/tools/stm8/lib/src/_logexpf.c @@ -0,0 +1,129 @@ +/*------------------------------------------------------------------------- + _logexpf.c + + Copyright (C) 2005, Paul Stoffregen + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#define __SDCC_MATH_LIB +#include + + +#ifdef MATH_ASM_MCS51 + +// This code is shared by both logf() and expf(), so it goes in this +// separate file to allow the linker to include it when either +// function is needed, but only 1 copy when both are used. + +void _fs_cordic_rshift_r765_unsigned(void) __naked +{ + __asm + ar2 = 0x02 + ar3 = 0x03 + ar4 = 0x04 + ar5 = 0x05 + ar6 = 0x06 + ar7 = 0x07 + ar0 = 0x00 + ar1 = 0x01 + + add a, #248 + jnc 00003$ + mov b, r5 + mov r5, ar6 + mov r6, ar7 + mov r7, #0 + add a, #248 + jnc 00003$ + mov b, r5 + mov r5, ar6 + mov r6, #0 + add a, #248 + jnc 00003$ + mov b, r5 + mov r5, #0 + add a, #248 + jnc 00003$ + mov b, #0 + ret +00003$: + add a, #8 + jz 00030$ + push ar0 + mov r0, a +00010$: + clr c + mov a, r7 + rrc a + mov r7, a + mov a, r6 + rrc a + mov r6, a + mov a, r5 + rrc a + mov r5, a + mov a, b + rrc a + mov b, a + djnz r0, 00010$ + pop ar0 +00030$: + ret + __endasm; +} + +__code unsigned char _fs_natural_log_table[] = { +0xFF, 0x42, 0x2E, 0x16, // 0.693147180560 +0xF6, 0x91, 0xF9, 0x0C, // 0.405465108108 +0xF2, 0xFD, 0x23, 0x07, // 0.223143551314 +0xEE, 0xE0, 0xC4, 0x03, // 0.117783035656 +0x0C, 0xA3, 0xF0, 0x01, // 0.060624621816 +0xD8, 0x14, 0xFC, 0x00, // 0.030771658667 +0xA3, 0x02, 0x7F, 0x00, // 0.015504186536 +0x55, 0xC0, 0x3F, 0x00, // 0.007782140442 +0x0B, 0xF0, 0x1F, 0x00, // 0.003898640416 +0x01, 0xFC, 0x0F, 0x00, // 0.001951220131 +0x00, 0xFF, 0x07, 0x00, // 0.000976085973 +0xC0, 0xFF, 0x03, 0x00, // 0.000488162080 +0xF0, 0xFF, 0x01, 0x00, // 0.000244110828 +0xFC, 0xFF, 0x00, 0x00, // 0.000122062863 +0xFF, 0x7F, 0x00, 0x00, // 0.000061033294 +0x00, 0x40, 0x00, 0x00, // 0.000030517112 +0x00, 0x20, 0x00, 0x00, // 0.000015258673 +0x00, 0x10, 0x00, 0x00, // 0.000007629365 +0x00, 0x08, 0x00, 0x00, // 0.000003814690 +0x00, 0x04, 0x00, 0x00, // 0.000001907347 +0x00, 0x02, 0x00, 0x00, // 0.000000953674 +0x00, 0x01, 0x00, 0x00, // 0.000000476837 +0x80, 0x00, 0x00, 0x00, // 0.000000238419 +0x40, 0x00, 0x00, 0x00, // 0.000000119209 +0x20, 0x00, 0x00, 0x00, // 0.000000059605 +0x10, 0x00, 0x00, 0x00, // 0.000000029802 +0x08, 0x00, 0x00, 0x00, // 0.000000014901 +0x04, 0x00, 0x00, 0x00, // 0.000000007451 +0x02, 0x00, 0x00, 0x00, // 0.000000003725 +0x01, 0x00, 0x00, 0x00 // 0.000000001863 +}; + +#endif diff --git a/hardware/tools/stm8/lib/src/_ltoa.c b/hardware/tools/stm8/lib/src/_ltoa.c new file mode 100644 index 0000000..2274c65 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_ltoa.c @@ -0,0 +1,84 @@ +/*------------------------------------------------------------------------- + _ltoa.c - integer to string conversion + + Copyright (c) 1999, Bela Torok, bela.torok@kssg.ch + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/*------------------------------------------------------------------------- + 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) +---------------------------------------------------------------------------*/ + +/* "11110000111100001111000011110000" base 2 */ +/* "37777777777" base 8 */ +/* "4294967295" base 10 */ +#define NUMBER_OF_DIGITS 32 /* eventually adapt if base 2 not needed */ + +#if NUMBER_OF_DIGITS < 32 +# warning _ltoa() and _ultoa() are not save for radix 2 +#endif + +#if defined (__SDCC_mcs51) && defined (__SDCC_MODEL_SMALL) && !defined (__SDCC_STACK_AUTO) +# define MEMSPACE_BUFFER __idata /* eventually __pdata or __xdata */ +# pragma nogcse +#else +# define MEMSPACE_BUFFER +#endif + +void _ultoa(unsigned long value, char* string, unsigned char radix) +{ + char MEMSPACE_BUFFER buffer[NUMBER_OF_DIGITS]; /* no space for '\0' */ + unsigned char index = NUMBER_OF_DIGITS; + + do { + unsigned char c = '0' + (value % radix); + if (c > (unsigned char)'9') + c += 'A' - '9' - 1; + buffer[--index] = c; + value /= radix; + } while (value); + + do { + *string++ = buffer[index]; + } while ( ++index != NUMBER_OF_DIGITS ); + + *string = 0; /* string terminator */ +} + +void _ltoa(long value, char* string, unsigned char radix) +{ + if (value < 0 && radix == 10) { + *string++ = '-'; + value = -value; + } + _ultoa(value, string, radix); +} + diff --git a/hardware/tools/stm8/lib/src/_memchr.c b/hardware/tools/stm8/lib/src/_memchr.c new file mode 100644 index 0000000..cd30afa --- /dev/null +++ b/hardware/tools/stm8/lib/src/_memchr.c @@ -0,0 +1,39 @@ +/*------------------------------------------------------------------------- + _memchr.c - part of string library functions + + Copyright (C) 2009, Philipp Klaus Krause . pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +void *memchr(const void *s, int c, size_t n) +{ + unsigned char *p = (unsigned char *)s; + unsigned char *end = p + n; + for(; p != end; p++) + if(*p == c) + return((void *)p); + return(0); +} diff --git a/hardware/tools/stm8/lib/src/_memcmp.c b/hardware/tools/stm8/lib/src/_memcmp.c new file mode 100644 index 0000000..087cc53 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_memcmp.c @@ -0,0 +1,42 @@ +/*------------------------------------------------------------------------- + _memcmp.c - part of string library functions + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +int memcmp (const void * buf1, const 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) ); +} diff --git a/hardware/tools/stm8/lib/src/_memcpy.c b/hardware/tools/stm8/lib/src/_memcpy.c new file mode 100644 index 0000000..45d629c --- /dev/null +++ b/hardware/tools/stm8/lib/src/_memcpy.c @@ -0,0 +1,51 @@ +/*------------------------------------------------------------------------- + _memcpy.c - part of string library functions + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include +#include + +#if !_SDCC_PORT_PROVIDES_MEMCPY + +#undef memcpy /* Avoid conflict with builtin memcpy() in Z80 and some related ports */ + +void * memcpy (void * dst, const void * src, size_t acount) +{ + void * ret = dst; + char * d = dst; + const char * s = src; + + /* + * copy from lower addresses to higher addresses + */ + while (acount--) { + *d++ = *s++; + } + + return(ret); +} +#endif diff --git a/hardware/tools/stm8/lib/src/_memmove.c b/hardware/tools/stm8/lib/src/_memmove.c new file mode 100644 index 0000000..6d2d062 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_memmove.c @@ -0,0 +1,69 @@ +/*------------------------------------------------------------------------- + _memmove.c - part of string library functions + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + Adapted By - Erik Petrich . epetrich@users.sourceforge.net + from _memcpy.c which was originally + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ +#include +#include +#include + +#ifndef _SDCC_PORT_PROVIDES_MEMMOVE +#define _SDCC_PORT_PROVIDES_MEMMOVE 0 +#endif + +#if !_SDCC_PORT_PROVIDES_MEMMOVE + +void * memmove (void * dst, const void * src, size_t acount) +{ + void * ret = dst; + char * d; + const char * s; + + if ((uintptr_t)src < (uintptr_t)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); +} +#endif diff --git a/hardware/tools/stm8/lib/src/_memset.c b/hardware/tools/stm8/lib/src/_memset.c new file mode 100644 index 0000000..7039a12 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_memset.c @@ -0,0 +1,183 @@ +/*------------------------------------------------------------------------- + _memset.c - part of string library functions + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + mcs51 assembler by Frieder Ferlemann (2007) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#undef memset /* Avoid conflict with builtin memset() in Z80 and some related ports */ + +#if defined (_SDCC_NO_ASM_LIB_FUNCS) || !defined (__SDCC_mcs51) || \ + (!defined (__SDCC_MODEL_SMALL) && !defined (__SDCC_MODEL_LARGE)) || \ + (defined (__SDCC_STACK_AUTO) || defined (__SDCC_PARMS_IN_BANK1) ) + +#ifdef __SDCC_BROKEN_STRING_FUNCTIONS +void *memset (void *s, unsigned char c, size_t n) +#else +void *memset (void *s, int c, size_t n) +#endif +{ + register unsigned char *ret = s; + + while (n--) + { + *(unsigned char *) ret = c; + ret = ((unsigned char *) ret) + 1; + } + + return s; +} + +#else + + /* assembler implementation for mcs51 */ + static void dummy(void) __naked + { + __asm + + /* assigning function parameters to registers. + __SDCC_PARMS_IN_BANK1 or __SDCC_STACK_AUTO not yet implemented. */ + #if defined (__SDCC_MODEL_SMALL) + + #if defined(__SDCC_NOOVERLAY) + .area DSEG (DATA) + #else + .area OSEG (OVR,DATA) + #endif + _memset_PARM_2:: + .ds 1 + _memset_PARM_3:: + .ds 2 + + .area CSEG (CODE) + + _memset:: + + ; Assign buf (b holds memspace, no need to touch) + mov r4,dpl + mov r5,dph + ; + ; Assign count + mov r6,_memset_PARM_3 + mov r7,(_memset_PARM_3 + 1) + ; + ; if (!count) return buf; + ; check for count != 0 intermangled with gymnastic + ; preparing djnz instructions + cjne r6,#0x00,COUNT_LSB_NOT_ZERO + mov a,r7 + jz MEMSET_END + dec r7 + COUNT_LSB_NOT_ZERO: + inc r7 + ; + ; This was 8 byte overhead for preparing + ; the count argument for an integer loop with two + ; djnz instructions - it might make sense to + ; let SDCC automatically generate this when + ; it encounters a loop like: + ; for(i=0;i + +#if _SDCC_MANGLES_SUPPORT_FUNS +unsigned unsigned _moduint (unsigned a, unsigned b); +#endif + +/* Assembler-functions are provided for: + mcs51 small + mcs51 small stack-auto +*/ + +#if !defined(__SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS) +# if defined(__SDCC_mcs51) +# if defined(__SDCC_MODEL_SMALL) +# if defined(__SDCC_STACK_AUTO) && !defined(__SDCC_PARMS_IN_BANK1) +# define _MODSINT_ASM_SMALL_AUTO +# else +# define _MODSINT_ASM_SMALL +# endif +# endif +# endif +#endif + +#if defined _MODSINT_ASM_SMALL + +static void +_modsint_dummy (void) __naked +{ + __asm + + #define a0 dpl + #define a1 dph + + .globl __modsint +#if defined(__SDCC_PARMS_IN_BANK1) + #define b0 (b1_0) + #define b1 (b1_1) +#else + // _modsint_PARM_2 shares the same memory with _moduint_PARM_2 + // and is defined in _moduint.c + #define b0 (__modsint_PARM_2) + #define b1 (__modsint_PARM_2 + 1) +#endif +__modsint: + ; a1 in dph + ; b1 in (__modsint_PARM_2 + 1) + + clr F0 ; Flag 0 in PSW + ; available to user for general purpose + mov a,a1 + jnb acc.7,a_not_negative + + setb F0 + + clr a + clr c + subb a,a0 + mov a0,a + clr a + subb a,a1 + mov a1,a + +a_not_negative: + + mov a,b1 + jnb acc.7,b_not_negative + + clr a + clr c + subb a,b0 + mov b0,a + clr a + subb a,b1 + mov b1,a + +b_not_negative: + + lcall __moduint + + jnb F0,not_negative + + clr a + clr c + subb a,a0 + mov a0,a + clr a + subb a,a1 + mov a1,a + +not_negative: + ret + + __endasm; +} + +#elif defined _MODSINT_ASM_SMALL_AUTO + +static void +_modsint_dummy (void) __naked +{ + __asm + + #define a0 dpl + #define a1 dph + + ar0 = 0 ; BUG register set is not considered + ar1 = 1 + + .globl __modsint + +__modsint: + + clr F0 ; Flag 0 in PSW + ; available to user for general purpose + mov a,a1 + jnb acc.7,a_not_negative + + setb F0 + + clr a + clr c + subb a,a0 + mov a0,a + clr a + subb a,a1 + mov a1,a + +a_not_negative: + + mov a,sp + add a,#-2 ; 2 bytes return address + mov r0,a ; r0 points to b1 + mov a,@r0 ; b1 + + jnb acc.7,b_not_negative + + dec r0 + + clr a + clr c + subb a,@r0 ; b0 + mov @r0,a + clr a + inc r0 + subb a,@r0 ; b1 + mov @r0,a + +b_not_negative: + + mov ar1,@r0 ; b1 + dec r0 + mov ar0,@r0 ; b0 + + lcall __modint + + jnb F0,not_negative + + clr a + clr c + subb a,a0 + mov a0,a + clr a + subb a,a1 + mov a1,a + +not_negative: + ret + + __endasm; +} + +#else // _MODSINT_ASM_ + +int _modsint (int a, int b) +{ + register int r; + + r = (unsigned)(a < 0 ? -a : a) % (unsigned)(b < 0 ? -b : b); + + if (a < 0) + return -r; + else + return r; +} + +#endif // _MODSINT_ASM_ diff --git a/hardware/tools/stm8/lib/src/_modslong.c b/hardware/tools/stm8/lib/src/_modslong.c new file mode 100644 index 0000000..d082d1e --- /dev/null +++ b/hardware/tools/stm8/lib/src/_modslong.c @@ -0,0 +1,271 @@ +/*------------------------------------------------------------------------- + _modslong.c - routine for modulus of 32 bit signed long + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#if _SDCC_MANGLES_SUPPORT_FUNS +unsigned long _modulong (unsigned long a, unsigned long b); +#endif + +/* Assembler-functions are provided for: + mcs51 small + mcs51 small stack-auto +*/ + +#if !defined(__SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS) +# if defined(__SDCC_mcs51) +# if defined(__SDCC_MODEL_SMALL) +# if defined(__SDCC_STACK_AUTO) && !defined(__SDCC_PARMS_IN_BANK1) +# define _MODSLONG_ASM_SMALL_AUTO +# else +# define _MODSLONG_ASM_SMALL +# endif +# endif +# endif +#endif + +#if defined _MODSLONG_ASM_SMALL + +static void +_modslong_dummy (void) __naked +{ + __asm + + #define a0 dpl + #define a1 dph + #define a2 b + #define a3 r1 + + .globl __modslong +#if defined(__SDCC_PARMS_IN_BANK1) + #define b0 (b1_0) + #define b1 (b1_1) + #define b2 (b1_2) + #define b3 (b1_3) +#else + // _modslong_PARM_2 shares the same memory with _modulong_PARM_2 + // and is defined in _modulong.c + #define b0 (__modslong_PARM_2) + #define b1 (__modslong_PARM_2 + 1) + #define b2 (__modslong_PARM_2 + 2) + #define b3 (__modslong_PARM_2 + 3) +#endif +__modslong: + ; a3 in acc + ; b3 in (__modslong_PARM_2 + 3) + mov a3,a ; save a3 + + clr F0 ; Flag 0 in PSW + ; available to user for general purpose + jnb acc.7,a_not_negative + + setb F0 + + clr a ; a = -a; + clr c + subb a,a0 + mov a0,a + clr a + subb a,a1 + mov a1,a + clr a + subb a,a2 + mov a2,a + clr a + subb a,a3 + mov a3,a + +a_not_negative: + + mov a,b3 + jnb acc.7,b_not_negative + + clr a ; b = -b; + clr c + subb a,b0 + mov b0,a + clr a + subb a,b1 + mov b1,a + clr a + subb a,b2 + mov b2,a + clr a + subb a,b3 + mov b3,a + +b_not_negative: + + mov a,a3 ; restore a3 in acc + + lcall __modulong + + jnb F0,not_negative + + ; result in (a == r1), b, dph, dpl + clr a + clr c + subb a,a0 + mov a0,a + clr a + subb a,a1 + mov a1,a + clr a + subb a,a2 + mov a2,a + clr a + subb a,a3 + ; result in a, b, dph, dpl +not_negative: + ret + + __endasm; +} + +#elif defined _MODSLONG_ASM_SMALL_AUTO + +static void +_modslong_dummy (void) __naked +{ + __asm + + #define a0 dpl + #define a1 dph + #define a2 b + #define a3 r1 + + #define b0 r2 + #define b1 r3 + #define b2 r4 + #define b3 r5 + + ar2 = 2 ; BUG register set is not considered + ar3 = 3 + ar4 = 4 + ar5 = 5 + + .globl __modslong + +__modslong: + + ; a3 in acc + mov a3,a ; save a3 + + clr F0 ; F0 (Flag 0) + ; available to user for general purpose + jnb acc.7,a_not_negative + + setb F0 + + clr a ; a = -a; + clr c + subb a,a0 + mov a0,a + clr a + subb a,a1 + mov a1,a + clr a + subb a,a2 + mov a2,a + clr a + subb a,a3 + mov a3,a + +a_not_negative: + + mov a,sp + add a,#-2-3 ; 2 bytes return address, 3 bytes param b + mov r0,a ; r1 points to b0 + + mov ar2,@r0 ; load b0 + inc r0 ; r0 points to b1 + mov ar3,@r0 ; b1 + inc r0 + mov ar4,@r0 ; b2 + inc r0 + mov a,@r0 ; b3 + mov b3,a + + jnb acc.7,b_not_negative + + clr a ; b = -b; + clr c + subb a,b0 + mov b0,a + clr a + subb a,b1 + mov b1,a + clr a + subb a,b2 + mov b2,a + clr a + subb a,b3 + mov b3,a + +b_not_negative: + + lcall __modlong + + jnb F0,not_negative + + ; result in (a == r1), b, dph, dpl + clr a + clr c + subb a,a0 + mov a0,a + clr a + subb a,a1 + mov a1,a + clr a + subb a,a2 + mov a2,a + clr a + subb a,a3 ; result in a, b, dph, dpl + +not_negative: + ret + + __endasm; +} + +#else // _MODSLONG_ASM + +long +_modslong (long a, long b) +{ + long r; + + r = (unsigned long)(a < 0 ? -a : a) % (unsigned long)(b < 0 ? -b : b); + + if (a < 0) + return -r; + else + return r; +} + +#endif // _MODSLONG_ASM diff --git a/hardware/tools/stm8/lib/src/_modslonglong.c b/hardware/tools/stm8/lib/src/_modslonglong.c new file mode 100644 index 0000000..b6f757b --- /dev/null +++ b/hardware/tools/stm8/lib/src/_modslonglong.c @@ -0,0 +1,52 @@ +/*------------------------------------------------------------------------- + _modslonglong.c - routine for modulo of 64 bit unsigned long long + + Copyright (C) 2014, Philipp Klaus Krause . pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#pragma std_c99 + +#include +#include + +#ifdef __SDCC_LONGLONG +long long +_modslonglong (long long numerator, long long denominator) +{ + bool numeratorneg = (numerator < 0); + bool denominatorneg = (denominator < 0); + long long r; + + if (numeratorneg) + numerator = -numerator; + if (denominatorneg) + denominator = -denominator; + + r = (unsigned long long)numerator % (unsigned long long)denominator; + + return ((numeratorneg ^ denominatorneg) ? -r : r); +} +#endif + diff --git a/hardware/tools/stm8/lib/src/_moduint.c b/hardware/tools/stm8/lib/src/_moduint.c new file mode 100644 index 0000000..1d47536 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_moduint.c @@ -0,0 +1,197 @@ +/*------------------------------------------------------------------------- + _moduint.c - routine for unsigned int (16 bit) modulus + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + Bug fixes by Martijn van Balen, aed@iae.nl + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* Assembler-functions are provided for: + mcs51 small + mcs51 small stack-auto +*/ + +#if !defined(__SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS) +# if defined(__SDCC_mcs51) +# if defined(__SDCC_MODEL_SMALL) +# if defined(__SDCC_STACK_AUTO) +# define _MODUINT_ASM_SMALL_AUTO +# else +# define _MODUINT_ASM_SMALL +# endif +# endif +# endif +#endif + +#if defined _MODUINT_ASM_SMALL || defined _MODUINT_ASM_SMALL_AUTO + +static void +_moduint_dummy (void) __naked +{ + __asm + + .globl __moduint + +__moduint: + + #define count r2 + #define al dpl + #define ah dph + +#if defined(__SDCC_STACK_AUTO) && !defined(__SDCC_PARMS_IN_BANK1) + + ar0 = 0 ; BUG register set is not considered + ar1 = 1 + + .globl __modint + + mov a,sp + add a,#-2 ; 2 bytes return address + mov r0,a ; r0 points to bh + mov ar1,@r0 ; load bh + dec r0 + mov ar0,@r0 ; load bl + + #define bl r0 + #define bh r1 + +__modint: ; entry point for __modsint + + +#else // __SDCC_STACK_AUTO + +#if !defined(__SDCC_PARMS_IN_BANK1) +#if defined(__SDCC_NOOVERLAY) + .area DSEG (DATA) +#else + .area OSEG (OVR,DATA) +#endif + + .globl __moduint_PARM_2 + .globl __modsint_PARM_2 + +__moduint_PARM_2: +__modsint_PARM_2: + .ds 2 + + .area CSEG (CODE) + + #define bl (__moduint_PARM_2) + #define bh (__moduint_PARM_2 + 1) +#else + #define bl (b1_0) + #define bh (b1_1) +#endif +#endif // __SDCC_STACK_AUTO + + mov a,bl ; avoid endless loop + orl a,bh + jz div_by_0 + + mov count,#1 + +loop1: mov a,bl ; b <<= 1 + add a,acc + mov bl,a + mov a,bh + rlc a + jc msbset + mov bh,a + + mov a,al ; a - b + subb a,bl ; here carry is always clear + mov a,ah + subb a,bh + + jc start + + inc count + sjmp loop1 + +start: clr c + mov a,bh ; b >>= 1; +msbset: rrc a + mov bh,a + mov a,bl + rrc a + mov bl,a + +loop2: clr c + mov a,al ; a - b + subb a,bl + + mov b,a + mov a,ah + subb a,bh + + jc smaller ; a >= b? + + mov ah,a ; -> yes; a = a - b; + mov al,b +smaller: ; -> no + clr c + mov a,bh ; b >>= 1; + rrc a + mov bh,a + mov a,bl + rrc a + mov bl,a + + djnz count,loop2 +div_by_0: + ret + + __endasm; +} + +#else // defined _MODUINT_ASM_SMALL || defined _MODUINT_ASM_SMALL_AUTO + +#define MSB_SET(x) ((x >> (8*sizeof(x)-1)) & 1) + +unsigned int +_moduint (unsigned int a, unsigned int b) +{ + unsigned char count = 0; + + while (!MSB_SET(b)) + { + b <<= 1; + if (b > a) + { + b >>=1; + break; + } + count++; + } + do + { + if (a >= b) + a -= b; + b >>= 1; + } + while (count--); + return a; +} + +#endif // defined _MODUINT_ASM_SMALL || defined _MODUINT_ASM_SMALL_AUTO diff --git a/hardware/tools/stm8/lib/src/_modulong.c b/hardware/tools/stm8/lib/src/_modulong.c new file mode 100644 index 0000000..ee2db80 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_modulong.c @@ -0,0 +1,365 @@ +/*------------------------------------------------------------------------- + _modulong.c - routine for modulus of 32 bit unsigned long + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + Bug fixes by Martijn van Balen, aed@iae.nl + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* Assembler-functions are provided for: + mcs51 small + mcs51 small stack-auto +*/ + +#if !defined(__SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS) +# if defined(__SDCC_mcs51) +# if defined(__SDCC_MODEL_SMALL) +# if defined(__SDCC_STACK_AUTO) && !defined (__SDCC_PARMS_IN_BANK1) +# define _MODULONG_ASM_SMALL_AUTO +# else +# define _MODULONG_ASM_SMALL +# endif +# endif +# endif +#endif + +#if defined _MODULONG_ASM_SMALL + +static void +_modlong_dummy (void) __naked +{ + __asm + + .globl __modulong + + #define a0 dpl + #define a1 dph + #define a2 b + #define a3 r1 + #define count r0 + +__modulong: +#if defined(__SDCC_PARMS_IN_BANK1) + #define b0 (b1_0) + #define b1 (b1_1) + #define b2 (b1_2) + #define b3 (b1_3) +#else +#if defined(__SDCC_NOOVERLAY) + .area DSEG (DATA) +#else + .area OSEG (OVR,DATA) +#endif + + .globl __modulong_PARM_2 + .globl __modslong_PARM_2 + +__modulong_PARM_2: +__modslong_PARM_2: + .ds 4 + + .area CSEG (CODE) + + #define b0 (__modulong_PARM_2) + #define b1 (__modulong_PARM_2 + 1) + #define b2 (__modulong_PARM_2 + 2) + #define b3 (__modulong_PARM_2 + 3) +#endif + ; parameter a comes in a, b, dph, dpl + mov a3,a ; save parameter a3 + + mov a,b0 ; b == 0? avoid endless loop + orl a,b1 + orl a,b2 + orl a,b3 + jz div_by_0 + + mov count,#0 + clr c ; when loop1 jumps immediately to loop2 + +loop1: inc count + + mov a,b3 ; if (!MSB_SET(b)) + jb acc.7,loop2 + + mov a,b0 ; b <<= 1 + add a,acc + mov b0,a + mov a,b1 + rlc a + mov b1,a + mov a,b2 + rlc a + mov b2,a + mov a,b3 + rlc a + mov b3,a + + mov a,a0 ; a - b + subb a,b0 ; here carry is always clear + mov a,a1 + subb a,b1 + mov a,a2 + subb a,b2 + mov a,a3 + subb a,b3 + + jnc loop1 + + + clr c + mov a,b3 ; b >>= 1; + rrc a + mov b3,a + mov a,b2 + rrc a + mov b2,a + mov a,b1 + rrc a + mov b1,a + mov a,b0 + rrc a + mov b0,a + +loop2: ; clr c never set + mov a,a0 ; a - b + subb a,b0 + mov r4,a + mov a,a1 + subb a,b1 + mov r5,a + mov a,a2 + subb a,b2 + mov r6,a + mov a,a3 + subb a,b3 + + jc smaller ; a >= b? + + mov a3,a ; -> yes; a = a - b; + mov a2,r6 + mov a1,r5 + mov a0,r4 +smaller: ; -> no + clr c + mov a,b3 ; b >>= 1; + rrc a + mov b3,a + mov a,b2 + rrc a + mov b2,a + mov a,b1 + rrc a + mov b1,a + mov a,b0 + rrc a + mov b0,a + + djnz count,loop2 + + mov a,a3 ; prepare the return value +div_by_0: + ret + + __endasm; +} + +#elif defined _MODULONG_ASM_SMALL_AUTO + +static void +_modlong_dummy (void) __naked +{ + __asm + + .globl __modulong + +__modulong: + + #define count r0 + + #define a0 dpl + #define a1 dph + #define a2 b + #define a3 r1 + + #define b0 r2 + #define b1 r3 + #define b2 r4 + #define b3 r5 + + ar2 = 2 ; BUG register set is not considered + ar3 = 3 + ar4 = 4 + ar5 = 5 + + .globl __modlong ; entry point for __modslong + + ; parameter a comes in a, b, dph, dpl + mov a3,a ; save parameter a3 + + mov a,sp + add a,#-2-3 ; 2 bytes return address, 3 bytes param b + mov r0,a ; r1 points to b0 + + mov ar2,@r0 ; load b0 + inc r0 ; r0 points to b1 + mov ar3,@r0 ; b1 + inc r0 + mov ar4,@r0 ; b2 + inc r0 + mov ar5,@r0 ; b3 + +__modlong: ; entry point for __modslong + ; a in r1, b, dph, dpl + ; b in r5, r4, r3, r2 + + mov count,#0 + + mov a,b0 ; b == 0? avoid endless loop + orl a,b1 + orl a,b2 + orl a,b3 + jz div_by_0 + + mov count,#0 + clr c ; when loop1 jumps immediately to loop2 + +loop1: inc count + + mov a,b3 ; if (!MSB_SET(b)) + jb acc.7,loop2 + + mov a,b0 ; b <<= 1 + add a,acc + mov b0,a + mov a,b1 + rlc a + mov b1,a + mov a,b2 + rlc a + mov b2,a + mov a,b3 + rlc a + mov b3,a + + mov a,a0 ; a - b + subb a,b0 ; here carry is always clear + mov a,a1 + subb a,b1 + mov a,a2 + subb a,b2 + mov a,a3 + subb a,b3 + + jnc loop1 + + clr c + mov a,b3 ; b >>= 1; + rrc a + mov b3,a + mov a,b2 + rrc a + mov b2,a + mov a,b1 + rrc a + mov b1,a + mov a,b0 + rrc a + mov b0,a + +loop2: ; clr c never set + mov a,a0 ; a - b + subb a,b0 + mov a,a1 + subb a,b1 + mov r6,a ; d1 + mov a,a2 + subb a,b2 + mov r7,a ; d2 + mov a,a3 + subb a,b3 + + jc smaller ; a >= b? + + mov a3,a ; -> yes; a = a - b; + mov a2,r7 + mov a1,r6 + mov a,a0 + subb a,b0 + mov a0,a +smaller: ; -> no + clr c + mov a,b3 ; b >>= 1; + rrc a + mov b3,a + mov a,b2 + rrc a + mov b2,a + mov a,b1 + rrc a + mov b1,a + mov a,b0 + rrc a + mov b0,a + + djnz count,loop2 + + mov a,a3 ; prepare the return value +div_by_0: + ret + + __endasm; +} + +#else // _MODULONG_ASM + +#define MSB_SET(x) ((x >> (8*sizeof(x)-1)) & 1) + +unsigned long +_modulong (unsigned long a, unsigned long b) +{ + unsigned char count = 0; + + while (!MSB_SET(b)) + { + b <<= 1; + if (b > a) + { + b >>=1; + break; + } + count++; + } + do + { + if (a >= b) + a -= b; + b >>= 1; + } + while (count--); + + return a; +} + +#endif // _MODULONG_ASM diff --git a/hardware/tools/stm8/lib/src/_modulonglong.c b/hardware/tools/stm8/lib/src/_modulonglong.c new file mode 100644 index 0000000..77d14b7 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_modulonglong.c @@ -0,0 +1,63 @@ +/*------------------------------------------------------------------------- + _modulonglong.c - routine for modulus of 64 bit unsigned long long + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + Bug fixes by Martijn van Balen, aed@iae.nl + Copyright (C) 2014, Philipp Klaus Krause . pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#ifdef __SDCC_LONGLONG + +#define MSB_SET(x) ((x >> (8*sizeof(x)-1)) & 1) + +unsigned long long +_modulonglong (unsigned long long a, unsigned long long b) +{ + unsigned char count = 0; + + while (!MSB_SET(b)) + { + b <<= 1; + if (b > a) + { + b >>=1; + break; + } + count++; + } + do + { + if (a >= b) + a -= b; + b >>= 1; + } + while (count--); + + return a; +} +#endif + diff --git a/hardware/tools/stm8/lib/src/_mulint.c b/hardware/tools/stm8/lib/src/_mulint.c new file mode 100644 index 0000000..4e0ad44 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_mulint.c @@ -0,0 +1,251 @@ +/*------------------------------------------------------------------------- + _mulint.c - routine for (unsigned) int (16 bit) multiplication + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* Signed and unsigned multiplication are the same - as long as the output + has the same precision as the input. + + Assembler-functions are provided for: + ds390 + mcs51 small + mcs51 small stack-auto + mcs51 large +*/ + +#if !defined(__SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS) +# if defined(__SDCC_ds390) +# if !defined(__SDCC_STACK_AUTO) +# define _MULINT_ASM_LARGE +# endif +# elif defined(__SDCC_mcs51) +# if defined(__SDCC_MODEL_SMALL) +# if defined(__SDCC_STACK_AUTO) && !defined(__SDCC_PARMS_IN_BANK1) +# define _MULINT_ASM_SMALL_AUTO +# else +# define _MULINT_ASM_SMALL +# endif +# else // must be __SDCC_MODEL_LARGE +# if !defined(__SDCC_STACK_AUTO) +# define _MULINT_ASM_LARGE +# endif +# endif +# endif +#endif + +#if defined(_MULINT_ASM_LARGE) + +#pragma save +#pragma less_pedantic +int +_mulint (int a, int b) +{ + a*b; // hush the compiler + + /* mulint= + (int)(lsb_a*lsb_b) + + (char)(msb_a*lsb_b)<<8 + + (char)(lsb_a*msb_b)<<8 + */ + + __asm + mov r2,dph ; msb_a + mov r3,dpl ; lsb_a + + mov b,r3 ; lsb_a +#if defined(__SDCC_PARMS_IN_BANK1) + mov a,b1_0 +#else + mov dptr,#__mulint_PARM_2 + movx a,@dptr ; lsb_b +#endif + mul ab ; lsb_a*lsb_b + mov r0,a + mov r1,b + + mov b,r2 ; msb_a +#if defined(__SDCC_PARMS_IN_BANK1) + mov a,b1_0 +#else + movx a,@dptr ; lsb_b +#endif + mul ab ; msb_a*lsb_b + add a,r1 + mov r1,a + + mov b,r3 ; lsb_a +#if defined(__SDCC_PARMS_IN_BANK1) + mov a,b1_1 +#else + inc dptr + movx a,@dptr ; msb_b +#endif + mul ab ; lsb_a*msb_b + add a,r1 + + mov dph,a + mov dpl,r0 + ret + __endasm; +} +#pragma restore + +#elif defined(_MULINT_ASM_SMALL) || defined(_MULINT_ASM_SMALL_AUTO) + +#pragma save +#pragma less_pedantic +int +_mulint_dummy (void) __naked +{ + __asm + +__mulint: + + .globl __mulint + +#if !defined(__SDCC_STACK_AUTO) || defined(__SDCC_PARMS_IN_BANK1) + +#if defined(__SDCC_NOOVERLAY) + .area DSEG (DATA) +#else + .area OSEG (OVR,DATA) +#endif +#if defined(__SDCC_PARMS_IN_BANK1) + #define bl (b1_0) + #define bh (b1_1) +#else + #define bl (__mulint_PARM_2) + #define bh (__mulint_PARM_2 + 1) +__mulint_PARM_2: + + .globl __mulint_PARM_2 + + .ds 2 +#endif + + .area CSEG (CODE) + + ; globbered registers none + + mov a,dpl ; 1 al + mov b,bl ; 2 bl + mul ab ; 4 al * bl + xch a,dpl ; 1 store low-byte of return value, fetch al + push b ; 2 + + mov b,bh ; 2 bh + mul ab ; 4 al * bh + pop b ; 2 + add a,b ; 1 + xch a,dph ; 1 ah -> acc + + mov b,bl ; 2 bl + mul ab ; 4 ah * bl + add a,dph ; 1 + mov dph,a ; 1 + ret ; 2 + ; 30 + +#else // __SDCC_STACK_AUTO + + ; globbered registers r0 + + mov a,#-2 ; 1 return address 2 bytes + add a,sp ; 1 + mov r0,a ; 1 r0 points to bh + + mov a,@r0 ; 1 bh + mov b,dpl ; 2 al + mul ab ; 4 al * bh + push acc ; 2 + + mov b,dpl ; 2 al + dec r0 ; 1 + mov a,@r0 ; 1 bl + mul ab ; 4 al * bl + + mov dpl,a ; 1 low-byte of return-value + + pop acc ; 2 + add a,b ; 1 + xch a,dph ; 1 ah -> acc + + mov b,@r0 ; 2 bl + mul ab ; 4 ah * bl + add a,dph ; 1 + mov dph,a ; 1 + + ret + +#endif // __SDCC_STACK_AUTO + + __endasm; +} +#pragma restore + +#else + +#if defined(__SDCC_hc08) || defined(__SDCC_s08) || defined(__SDCC_stm8) +// Big-endian +union uu { + struct { unsigned char hi, lo ;} s; + unsigned int t; +}; +#else +// Little-endian +union uu { + struct { unsigned char lo,hi ;} s; + unsigned int t; +}; +#endif + +int +_mulint (int a, int b) +{ +#if !defined(__SDCC_STACK_AUTO) && (defined(__SDCC_MODEL_LARGE) || defined(__SDCC_ds390)) // still needed for large + union uu __xdata *x; + union uu __xdata *y; + union uu t; + x = (union uu __xdata *)&a; + y = (union uu __xdata *)&b; +#else + register union uu *x; + register union uu *y; + union uu t; + x = (union uu *)&a; + y = (union uu *)&b; +#endif + + // sdcc is bad at handling union accesses. So we use (unsigned char)a instead of x->s.lo here. + t.t = (unsigned char)a * (unsigned char)b; + t.s.hi += ((unsigned char)a * y->s.hi) + (x->s.hi * (unsigned char)b); + + return t.t; +} + +#endif + +#undef _MULINT_ASM diff --git a/hardware/tools/stm8/lib/src/_mullong.c b/hardware/tools/stm8/lib/src/_mullong.c new file mode 100644 index 0000000..9bd4161 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_mullong.c @@ -0,0 +1,760 @@ +/*------------------------------------------------------------------------- + _mullong.c - routine for multiplication of 32 bit (unsigned) long + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + Copyright (C) 1999, Jean Louis VERN jlvern@writeme.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* Signed and unsigned multiplication are the same - as long as the output + has the same precision as the input. + + Assembler-functions are provided for: + mcs51 small + mcs51 small stack-auto +*/ + +#if !defined(__SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS) +# if defined(__SDCC_mcs51) +# if defined(__SDCC_MODEL_SMALL) +# if defined(__SDCC_STACK_AUTO) && !defined(__SDCC_PARMS_IN_BANK1) +# define _MULLONG_ASM_SMALL_AUTO +# else +# define _MULLONG_ASM_SMALL +# endif +# elif defined(__SDCC_MODEL_LARGE) +# if !defined(__SDCC_STACK_AUTO) +# define _MULLONG_ASM_LARGE +# endif +# endif +# endif +#endif + +#if defined(_MULLONG_ASM_SMALL) || defined(_MULLONG_ASM_SMALL_AUTO) + +void +_mullong_dummy (void) __naked +{ + __asm + +__mullong: + + .globl __mullong + + ; the result c will be stored in r4...r7 + #define c0 r4 + #define c1 r5 + #define c2 r6 + #define c3 r7 + + #define a0 dpl + #define a1 dph + #define a2 r2 + #define a3 r3 + + ; c0 a0 * b0 + ; c1 a1 * b0 + a0 * b1 + ; c2 a2 * b0 + a1 * b1 + a0 * b2 + ; c3 a3 * b0 + a2 * b1 + a1 * b2 + a0 * b3 + +#if !defined(__SDCC_STACK_AUTO) || defined(__SDCC_PARMS_IN_BANK1) +#if defined(__SDCC_PARMS_IN_BANK1) + #define b0 (b1_0) + #define b1 (b1_1) + #define b2 (b1_2) + #define b3 (b1_3) +#else +#if defined(__SDCC_NOOVERLAY) + .area DSEG (DATA) +#else + .area OSEG (OVR,DATA) +#endif + +__mullong_PARM_2: + + .globl __mullong_PARM_2 + + .ds 4 + + b0 = __mullong_PARM_2 + b1 = (__mullong_PARM_2+1) + b2 = (__mullong_PARM_2+2) + b3 = (__mullong_PARM_2+3) + +#endif + .area CSEG (CODE) + + ; parameter a comes in a, b, dph, dpl + mov r2,b ; save parameter a + mov r3,a + + ; Byte 0 + mov a,a0 + mov b,b0 + mul ab ; a0 * b0 + mov c0,a + mov c1,b + + ; Byte 1 + mov a,a1 + mov b,b0 + mul ab ; a1 * b0 + add a,c1 + mov c1,a + clr a + addc a,b + mov c2,a + + mov a,a0 + mov b,b1 + mul ab ; a0 * b1 + add a,c1 + mov c1,a + mov a,b + addc a,c2 + mov c2,a + clr a + rlc a + mov c3,a + + ; Byte 2 + mov a,a2 + mov b,b0 + mul ab ; a2 * b0 + add a,c2 + mov c2,a + mov a,b + addc a,c3 + mov c3,a + + mov a,a1 + mov b,b1 + mul ab ; a1 * b1 + add a,c2 + mov c2,a + mov a,b + addc a,c3 + mov c3,a + + mov a,a0 + mov b,b2 + mul ab ; a0 * b2 + add a,c2 + mov c2,a + mov a,b + addc a,c3 + mov c3,a + + ; Byte 3 + mov a,a3 + mov b,b0 + mul ab ; a3 * b0 + add a,c3 + mov c3,a + + mov a,a2 + mov b,b1 + mul ab ; a2 * b1 + add a,c3 + mov c3,a + + mov a,a1 + mov b,b2 + mul ab ; a1 * b2 + add a,c3 + mov c3,a + + mov a,a0 + mov b,b3 + mul ab ; a0 * b3 + add a,c3 + + mov b,c2 + mov dph,c1 + mov dpl,c0 + ret + +#else // __SDCC_STACK_AUTO + + ; parameter a comes in a, b, dph, dpl + mov r2,b ; save parameter a + mov r3,a + + #define a0 dpl + #define a1 dph + #define a2 r2 + #define a3 r3 + + #define b0 r1 + + mov a,#-2-3 ; 1 return address 2 bytes, b 4 bytes + add a,sp ; 1 + mov r0,a ; 1 r0 points to b0 + + ; Byte 0 + mov a,a0 + mov b,@r0 ; b0 + mov b0,b ; we need b0 several times + inc r0 ; r0 points to b1 + mul ab ; a0 * b0 + mov c0,a + mov c1,b + + ; Byte 1 + mov a,a1 + mov b,b0 + mul ab ; a1 * b0 + add a,c1 + mov c1,a + clr a + addc a,b + mov c2,a + + mov a,a0 + mov b,@r0 ; b1 + mul ab ; a0 * b1 + add a,c1 + mov c1,a + mov a,b + addc a,c2 + mov c2,a + clr a + rlc a + mov c3,a + + ; Byte 2 + mov a,a2 + mov b,b0 + mul ab ; a2 * b0 + add a,c2 + mov c2,a + mov a,b + addc a,c3 + mov c3,a + + mov a,a1 + mov b,@r0 ; b1 + mul ab ; a1 * b1 + add a,c2 + mov c2,a + mov a,b + addc a,c3 + mov c3,a + + mov a,a0 + inc r0 + mov b,@r0 ; b2 + mul ab ; a0 * b2 + add a,c2 + mov c2,a + mov a,b + addc a,c3 + mov c3,a + + ; Byte 3 + mov a,a3 + mov b,b0 + mul ab ; a3 * b0 + add a,c3 + mov c3,a + + mov a,a1 + mov b,@r0 ; b2 + mul ab ; a1 * b2 + add a,c3 + mov c3,a + + mov a,a2 + dec r0 + mov b,@r0 ; b1 + mul ab ; a2 * b1 + add a,c3 + mov c3,a + + mov a,a0 + inc r0 + inc r0 + mov b,@r0 ; b3 + mul ab ; a0 * b3 + add a,c3 + + mov b,c2 + mov dph,c1 + mov dpl,c0 + + ret + +#endif // __SDCC_STACK_AUTO + + __endasm; +} + +#elif defined(_MULLONG_ASM_LARGE) + +void +_mullong_dummy (void) __naked +{ + __asm + +__mullong: + + .globl __mullong + + ; the result c will be stored in r4...r7 + #define c0 r4 + #define c1 r5 + #define c2 r6 + #define c3 r7 + + ; c0 a0 * b0 + ; c1 a1 * b0 + a0 * b1 + ; c2 a2 * b0 + a1 * b1 + a0 * b2 + ; c3 a3 * b0 + a2 * b1 + a1 * b2 + a0 * b3 + +#if !defined(__SDCC_PARMS_IN_BANK1) + .area XSEG (XDATA) + +__mullong_PARM_2: + + .globl __mullong_PARM_2 + + .ds 4 +#endif + .area CSEG (CODE) + + ; parameter a comes in a, b, dph, dpl + mov r0,dpl ; save parameter a + mov r1,dph + mov r2,b + mov r3,a + + #define a0 r0 + #define a1 r1 + #define a2 r2 + #define a3 r3 + + ; Byte 0 + mov b,a0 +#if defined(__SDCC_PARMS_IN_BANK1) + mov a,b1_0 ; b0 +#else + mov dptr,#__mullong_PARM_2 + movx a,@dptr ; b0 +#endif + mul ab ; a0 * b0 + mov c0,a + mov c1,b + + ; Byte 1 + mov b,a1 +#if defined(__SDCC_PARMS_IN_BANK1) + mov a,b1_0 ; b0 +#else + movx a,@dptr ; b0 +#endif + mul ab ; a1 * b0 + add a,c1 + mov c1,a + clr a + addc a,b + mov c2,a + + mov b,a0 +#if defined(__SDCC_PARMS_IN_BANK1) + mov a,b1_1 ; b1 +#else + inc dptr ; b1 + movx a,@dptr +#endif + mul ab ; a0 * b1 + add a,c1 + mov c1,a + mov a,b + addc a,c2 + mov c2,a + clr a + rlc a + mov c3,a + + ; Byte 2 + mov b,a1 +#if defined(__SDCC_PARMS_IN_BANK1) + mov a,b1_1 ; b1 +#else + movx a,@dptr ; b1 +#endif + mul ab ; a1 * b1 + add a,c2 + mov c2,a + mov a,b + addc a,c3 + mov c3,a + + mov b,a0 +#if defined(__SDCC_PARMS_IN_BANK1) + mov a,b1_2 ; b2 +#else + inc dptr ; b2 + movx a,@dptr +#endif + mul ab ; a0 * b2 + add a,c2 + mov c2,a + mov a,b + addc a,c3 + mov c3,a + + mov b,a2 +#if defined(__SDCC_PARMS_IN_BANK1) + mov a,b1_0 ; b0 +#else + mov dptr,#__mullong_PARM_2 + movx a,@dptr ; b0 +#endif + mul ab ; a2 * b0 + add a,c2 + mov c2,a + mov a,b + addc a,c3 + mov c3,a + + ; Byte 3 + mov b,a3 +#if defined(__SDCC_PARMS_IN_BANK1) + mov a,b1_0 ; b0 +#else + movx a,@dptr ; b0 +#endif + mul ab ; a3 * b0 + add a,c3 + mov c3,a + + mov b,a2 +#if defined(__SDCC_PARMS_IN_BANK1) + mov a,b1_1 ; b1 +#else + inc dptr ; b1 + movx a,@dptr +#endif + mul ab ; a2 * b1 + add a,c3 + mov c3,a + + mov b,a1 +#if defined(__SDCC_PARMS_IN_BANK1) + mov a,b1_2 ; b2 +#else + inc dptr ; b2 + movx a,@dptr +#endif + mul ab ; a1 * b2 + add a,c3 + mov c3,a + + mov b,a0 +#if defined(__SDCC_PARMS_IN_BANK1) + mov a,b1_3 ; b3 +#else + inc dptr ; b3 + movx a,@dptr +#endif + mul ab ; a0 * b3 + add a,c3 + + mov b,c2 + mov dph,c1 + mov dpl,c0 + ret + + __endasm; +} + +#elif defined(__SDCC_USE_XSTACK) && defined(__SDCC_STACK_AUTO) + +void +_mullong_dummy (void) __naked +{ + __asm + +__mullong: + + .globl __mullong + + ; the result c will be stored in r4...r7 + #define c0 r4 + #define c1 r5 + #define c2 r6 + #define c3 r7 + + #define a0 dpl + #define a1 dph + #define a2 r2 + #define a3 r3 + + #define b0 r1 + + ; c0 a0 * b0 + ; c1 a1 * b0 + a0 * b1 + ; c2 a2 * b0 + a1 * b1 + a0 * b2 + ; c3 a3 * b0 + a2 * b1 + a1 * b2 + a0 * b3 + + ; parameter a comes in a, b, dph, dpl + mov r2,b ; save parameter a + mov r3,a + + mov a,#-4 ; 1 b 4 bytes + add a,_spx ; 1 + mov r0,a ; 1 r0 points to b0 + + ; Byte 0 + movx a,@r0 ; b0 + mov b0,a ; we need b0 several times + inc r0 ; r0 points to b1 + mov b,a0 + mul ab ; a0 * b0 + mov c0,a + mov c1,b + + ; Byte 1 + mov a,a1 + mov b,b0 + mul ab ; a1 * b0 + add a,c1 + mov c1,a + clr a + addc a,b + mov c2,a + + mov b,a0 + movx a,@r0 ; b1 + mul ab ; a0 * b1 + add a,c1 + mov c1,a + mov a,b + addc a,c2 + mov c2,a + clr a + rlc a + mov c3,a + + ; Byte 2 + mov a,a2 + mov b,b0 + mul ab ; a2 * b0 + add a,c2 + mov c2,a + mov a,b + addc a,c3 + mov c3,a + + mov b,a1 + movx a,@r0 ; b1 + mul ab ; a1 * b1 + add a,c2 + mov c2,a + mov a,b + addc a,c3 + mov c3,a + + mov b,a0 + inc r0 + movx a,@r0 ; b2 + mul ab ; a0 * b2 + add a,c2 + mov c2,a + mov a,b + addc a,c3 + mov c3,a + + ; Byte 3 + mov a,a3 + mov b,b0 + mul ab ; a3 * b0 + add a,c3 + mov c3,a + + mov b,a1 + movx a,@r0 ; b2 + mul ab ; a1 * b2 + add a,c3 + mov c3,a + + mov b,a2 + dec r0 + movx a,@r0 ; b1 + mul ab ; a2 * b1 + add a,c3 + mov c3,a + + mov b,a0 + inc r0 + inc r0 + movx a,@r0 ; b3 + mul ab ; a0 * b3 + add a,c3 + + mov b,c2 + mov dph,c1 + mov dpl,c0 + + ret + + __endasm; +} + +#else // _MULLONG_ASM + +struct some_struct { + short a ; + char b; + long c ;}; +#if defined(__SDCC_hc08) || defined(__SDCC_s08) || defined(__SDCC_stm8) +/* big endian order */ +union bil { + struct {unsigned char b3,b2,b1,b0 ;} b; + struct {unsigned short hi,lo ;} i; + unsigned long l; + struct { unsigned char b3; unsigned short i12; unsigned char b0;} bi; +} ; +#else +/* little endian order */ +union bil { + struct {unsigned char b0,b1,b2,b3 ;} b; + struct {unsigned short lo,hi ;} i; + unsigned long l; + struct { unsigned char b0; unsigned short i12; unsigned char b3;} bi; +} ; +#endif + +#if defined(__SDCC) + #include +#endif + +#define bcast(x) ((union bil _AUTOMEM *)&(x)) + +/* + 3 2 1 0 + X 3 2 1 0 + ---------------------------- + 0.3 0.2 0.1 0.0 + 1.3 1.2 1.1 1.0 + 2.3 2.2 2.1 2.0 + 3.3 3.2 3.1 3.0 + ---------------------------- + |3.3|1.3|0.2|0.0| A + |2.3|0.3|0.1| B + |3.2|1.2|1.0| C + |2.2|1.1| D + |3.1|2.0| E + |2.1| F + |3.0| G + |-------> only this side 32 x 32 -> 32 +*/ +#if defined(__SDCC_USE_XSTACK) +// currently the original code without u fails with --xstack +// it runs out of pointer registers +long +_mullong (long a, long b) +{ + union bil t, u; + + t.i.hi = bcast(a)->b.b0 * bcast(b)->b.b2; // A + t.i.lo = bcast(a)->b.b0 * bcast(b)->b.b0; // A + u.bi.b3 = bcast(a)->b.b0 * bcast(b)->b.b3; // B + u.bi.i12 = bcast(a)->b.b0 * bcast(b)->b.b1; // B + u.bi.b0 = 0; // B + t.l += u.l; + + t.b.b3 += bcast(a)->b.b3 * bcast(b)->b.b0; // G + t.b.b3 += bcast(a)->b.b2 * bcast(b)->b.b1; // F + t.i.hi += bcast(a)->b.b2 * bcast(b)->b.b0; // E + t.i.hi += bcast(a)->b.b1 * bcast(b)->b.b1; // D + + u.bi.b3 = bcast(a)->b.b1 * bcast(b)->b.b2; // C + u.bi.i12 = bcast(a)->b.b1 * bcast(b)->b.b0; // C + u.bi.b0 = 0; // C + t.l += u.l; + + return t.l; +} +#elif defined(__SDCC_z80) || defined(__SDCC_gbz80) || defined(__SDCC_r2k) || defined(__SDCC_r3k) +/* 32x32->32 multiplication to be used + if 16x16->16 is faster than three 8x8->16. + 2009, by M.Bodrato ( http://bodrato.it/ ) + + z80 and gbz80 don't have any hardware multiplication. + r2k and r3k have 16x16 hardware multiplication. + */ +long +_mullong (long a, long b) +{ + unsigned short i12; + + bcast(a)->i.hi *= bcast(b)->i.lo; + bcast(a)->i.hi += bcast(b)->i.hi * bcast(a)->i.lo; + + /* only (a->i.lo * b->i.lo) 16x16->32 to do. asm? */ + bcast(a)->i.hi += bcast(a)->b.b1 * bcast(b)->b.b1; + + i12 = bcast(b)->b.b0 * bcast(a)->b.b1; + bcast(b)->bi.i12 = bcast(a)->b.b0 * bcast(b)->b.b1; + + /* add up the two partial result, store carry in b3 */ + bcast(b)->b.b3 = ((bcast(b)->bi.i12 += i12) < i12); + + bcast(a)->i.lo = bcast(a)->b.b0 * bcast(b)->b.b0; + + bcast(b)->bi.b0 = 0; + + return a + b; +} +#else +long +_mullong (long a, long b) +{ + union bil t; + + t.i.hi = bcast(a)->b.b0 * bcast(b)->b.b2; // A + t.i.lo = bcast(a)->b.b0 * bcast(b)->b.b0; // A + t.b.b3 += bcast(a)->b.b3 * bcast(b)->b.b0; // G + t.b.b3 += bcast(a)->b.b2 * bcast(b)->b.b1; // F + t.i.hi += bcast(a)->b.b2 * bcast(b)->b.b0; // E <- b lost in .lst + // bcast(a)->i.hi is free ! + t.i.hi += bcast(a)->b.b1 * bcast(b)->b.b1; // D <- b lost in .lst + + bcast(a)->bi.b3 = bcast(a)->b.b1 * bcast(b)->b.b2; // C + bcast(a)->bi.i12 = bcast(a)->b.b1 * bcast(b)->b.b0; // C + + bcast(b)->bi.b3 = bcast(a)->b.b0 * bcast(b)->b.b3; // B + bcast(b)->bi.i12 = bcast(a)->b.b0 * bcast(b)->b.b1; // B + + bcast(b)->bi.b0 = 0; // B + bcast(a)->bi.b0 = 0; // C + t.l += a; + + return t.l + b; +} +#endif + +#endif // _MULLONG_ASM diff --git a/hardware/tools/stm8/lib/src/_mullonglong.c b/hardware/tools/stm8/lib/src/_mullonglong.c new file mode 100644 index 0000000..3b2ee9c --- /dev/null +++ b/hardware/tools/stm8/lib/src/_mullonglong.c @@ -0,0 +1,54 @@ +/*------------------------------------------------------------------------- + _mullonglong.c - routine for multiplication of 64 bit long long + + Copyright (C) 2012, Philipp Klaus Krause . philipp@informatik.uni-frankfurt.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#pragma std_c99 + +#include + +#ifdef __SDCC_LONGLONG + +long long _mullonglong(long long ll, long long lr) +{ + unsigned long long ret = 0ull; + unsigned char i, j; + + for (i = 0; i < sizeof (long long); i++) + { + unsigned char l = ll >> (i * 8); + for(j = 0; (i + j) < sizeof (long long); j++) + { + unsigned char r = lr >> (j * 8); + ret += (unsigned long long)((unsigned short)(l * r)) << ((i + j) * 8); + } + } + + return(ret); +} + +#endif + diff --git a/hardware/tools/stm8/lib/src/_mulschar.c b/hardware/tools/stm8/lib/src/_mulschar.c new file mode 100644 index 0000000..9edb8dd --- /dev/null +++ b/hardware/tools/stm8/lib/src/_mulschar.c @@ -0,0 +1,47 @@ +/*------------------------------------------------------------------------- + _mulschar.c :- routine for signed char (8 bit) multiplication. just calls + routine for signed int multiplication after sign extension + + Copyright (C) 2013, Philipp Klaus Krause . pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +signed int +_mulschar (signed char x, signed char y) +{ + return ((int)x * (int)y); +} + +signed int +_muluschar (unsigned char x, unsigned char y) +{ + return ((int)((signed char)x) * (int)y); +} + +unsigned int +_mulsuchar (signed char x, signed char y) +{ + return ((int)((unsigned char)x) * (int)y); +} + diff --git a/hardware/tools/stm8/lib/src/_rlslonglong.c b/hardware/tools/stm8/lib/src/_rlslonglong.c new file mode 100644 index 0000000..43ac643 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_rlslonglong.c @@ -0,0 +1,41 @@ +/*------------------------------------------------------------------------- + _rlslonglong.c - routine for left shift of 64 bit long long + + Copyright (C) 2012, Philipp Klaus Krause . philipp@informatik.uni-frankfurt.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#pragma std_c99 + +#include + +#ifdef __SDCC_LONGLONG + +long long _rlslonglong(long long l, signed char s) +{ + return((unsigned long long)(l) << s); +} + +#endif + diff --git a/hardware/tools/stm8/lib/src/_rlulonglong.c b/hardware/tools/stm8/lib/src/_rlulonglong.c new file mode 100644 index 0000000..b12590f --- /dev/null +++ b/hardware/tools/stm8/lib/src/_rlulonglong.c @@ -0,0 +1,58 @@ +/*------------------------------------------------------------------------- + _rlulonglong.c - routine for left shift of 64 bit unsigned long long + + Copyright (C) 2012, Philipp Klaus Krause . philipp@informatik.uni-frankfurt.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#pragma std_c99 + +#include + +#ifdef __SDCC_LONGLONG + +unsigned long long _rlulonglong(unsigned long long l, signed char s) +{ + uint32_t *const top = (uint32_t *)((char *)(&l) + 4); + uint16_t *const middle = (uint16_t *)((char *)(&l) + 2); + uint32_t *const bottom = (uint32_t *)(&l); + uint16_t *const b = (uint16_t *)(&l); + + for(;s >= 16; s-= 16) + { + b[3] = b[2]; + b[2] = b[1]; + b[1] = b[0]; + b[0] = 0; + } + + (*top) <<= s; + (*top) |= (((uint32_t)((*middle) & 0xffffu) << s) >> 16); + (*bottom) <<= s; + + return(l); +} + +#endif + diff --git a/hardware/tools/stm8/lib/src/_rrslonglong.c b/hardware/tools/stm8/lib/src/_rrslonglong.c new file mode 100644 index 0000000..9d52e8e --- /dev/null +++ b/hardware/tools/stm8/lib/src/_rrslonglong.c @@ -0,0 +1,57 @@ +/*------------------------------------------------------------------------- + _rrulonglong.c - routine for right shift of 64 bit unsigned long long + + Copyright (C) 2012, Philipp Klaus Krause . philipp@informatik.uni-frankfurt.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#pragma std_c99 + +#include + +#ifdef __SDCC_LONGLONG +// This function is the same as the one from rrulonglong_rrx_s.c, except for the type of top. +long long _rrslonglong(long long l, signed char s) +{ + int32_t *top = (uint32_t *)((char *)(&l) + 4); + uint16_t *middle = (uint16_t *)((char *)(&l) + 3); + uint32_t *bottom = (uint32_t *)(&l); + uint16_t *b = (uint16_t *)(&l); + + for(;s >= 16; s-= 16) + { + b[0] = b[1]; + b[1] = b[2]; + b[2] = b[3]; + b[3] = (b[3] & 0x8000) ? 0xffff : 0x000000; + } + + (*bottom) >>= s; + (*bottom) |= ((uint32_t)((*middle) >> s) << 16); + (*top) |= (((*middle) & 0xffff0000) >> s); + + return(l); +} +#endif + diff --git a/hardware/tools/stm8/lib/src/_rrulonglong.c b/hardware/tools/stm8/lib/src/_rrulonglong.c new file mode 100644 index 0000000..a15d993 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_rrulonglong.c @@ -0,0 +1,57 @@ +/*------------------------------------------------------------------------- + _rrulonglong.c - routine for right shift of 64 bit unsigned long long + + Copyright (C) 2012, Philipp Klaus Krause . philipp@informatik.uni-frankfurt.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#pragma std_c99 + +#include + +#ifdef __SDCC_LONGLONG +// This function is the same as the one from rrslonglong_rrx_s.c, except for the type of top, and b[3]. +unsigned long long _rrulonglong(unsigned long long l, signed char s) +{ + uint32_t *const top = (uint32_t *)((char *)(&l) + 4); + uint16_t *const middle = (uint16_t *)((char *)(&l) + 3); + uint32_t *const bottom = (uint32_t *)(&l); + uint16_t *const b = (uint16_t *)(&l); + + for(;s >= 16; s -= 16) + { + b[0] = b[1]; + b[1] = b[2]; + b[2] = b[3]; + b[3] = 0x000000; + } + + (*bottom) >>= s; + (*middle) |= (((*middle) & 0xffff0000ul) >> s); + (*top) |= (((*middle) & 0xffff0000ul) >> s); + + return(l); +} +#endif + diff --git a/hardware/tools/stm8/lib/src/_schar2fs.c b/hardware/tools/stm8/lib/src/_schar2fs.c new file mode 100644 index 0000000..6987920 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_schar2fs.c @@ -0,0 +1,59 @@ +/*------------------------------------------------------------------------- + _schar2fs.c - Floating point library in optimized assembly for 8051 + + Copyright (C) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +// float __schar2fs (char c) +static void dummy(void) __naked +{ + __asm + .globl ___schar2fs +___schar2fs: + mov r4, dpl + clr a + mov r3, a + mov r2, a + mov r1, a + mov a, #134 + ljmp slong2fs_doit + __endasm; +} + +#else + +/* convert signed char to float */ +float __schar2fs (signed char sc) { + return __slong2fs(sc); +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_ser.c b/hardware/tools/stm8/lib/src/_ser.c new file mode 100644 index 0000000..923eb0f --- /dev/null +++ b/hardware/tools/stm8/lib/src/_ser.c @@ -0,0 +1,184 @@ +/*------------------------------------------------------------------------- + _ser.c - this file contains a simple interrupt driven serial driver with + buffer (no check for overflow!!!). + + Copyright (C) 1999, Sandeep Dutta + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/*KA****************************************************************** +* PROJECT: PL-One/8052 +********************************************************************** +* FILE: ser.c +********************************************************************** +* CHANGES: +* date author description +* -------------------------------------------------------------------- +* 04/26/99 we final +* 04/27/99 we comments +********************************************************************** +* DESCRIPTION: +* This file contains a simple interrupt driven serial driver with +* buffer (no check for overflow!!!). +********************************************************************** +* FUNCTIONS DECLARED: +* ser_init Initialization; must be called first +* ser_putc output one char on the serial line +* ser_getc return a char if one has been received, else 0 +* ser_printString print a 0-terminated string +* ser_charAvail return 1 if a char arrived on serial line +********************************************************************** +* NOTE: +* Remember to enable all interrupts (EA=1) outside of this module!! +********************************************************************** +* COMPILE TIME OPTIONS: - +* DEBUG OPTIONS: - +******************************************************************KE*/ + +#include <8052.h> + +#include "ser.h" + +#define NON_BLOCKING + +unsigned char __xdata ser_txIndexIn; +unsigned char __xdata ser_txIndexOut; +unsigned char __xdata ser_rxIndexIn; +unsigned char __xdata ser_rxIndexOut; + +unsigned char __xdata ser_txBuffer[0x100]; +unsigned char __xdata ser_rxBuffer[0x100]; + +static __bit ser_txBusy; + +void +ser_init(void) +{ + ES = 0; + + ser_txBusy = 0; + + ser_txIndexIn = 0; + ser_txIndexOut = 0; + ser_rxIndexIn = 0; + ser_rxIndexOut = 0; + + T2CON = 0x30; + + /* Baudrate = 19200, oscillator frq. of my processor is 21.4772 MHz */ + RCAP2H = 0xFF; + RCAP2L = 0xDD; + + /* enable counter */ + T2CON = 0x34; + + SCON = 0x50; + + if (TI) { + TI = 0; + } + if (RI) { + RI = 0; + } + + ES=1; +} + +void +ser_interrupt_handler(void) __interrupt 4 __using 1 +{ + ES=0; + + if (RI) { + RI = 0; + ser_rxBuffer[ser_rxIndexIn++] = SBUF; + } + + if (TI) { + TI = 0; + if (ser_txIndexIn == ser_txIndexOut) { + ser_txBusy = 0; + } + else { + SBUF = ser_txBuffer[ser_txIndexOut++]; + } + } + + ES=1; +} + +void +ser_putc(unsigned char c) +{ + ES=0; + + if (ser_txBusy) { + ser_txBuffer[ser_txIndexIn++] = c; + } + else { + ser_txBusy = 1; + SBUF = c; + } + + ES=1; +} + +unsigned char +ser_getc(void) +{ + char tmp; + +#ifdef NON_BLOCKING + if (ser_rxIndexIn != ser_rxIndexOut) { + tmp = ser_rxBuffer[ser_rxIndexOut++]; + } + else { + tmp = 0; + } +#endif + + return(tmp); +} + +void +ser_printString(char *String) +{ + while (*String) { + ser_putc(*String++); + } +} + +char +ser_charAvail(void) +{ + char ret = 0; + + if (ser_rxIndexIn != ser_rxIndexOut) { + ret = 1; + } + + return(ret); +} + +/*********************End of File************************************/ diff --git a/hardware/tools/stm8/lib/src/_setjmp.c b/hardware/tools/stm8/lib/src/_setjmp.c new file mode 100644 index 0000000..9a0747a --- /dev/null +++ b/hardware/tools/stm8/lib/src/_setjmp.c @@ -0,0 +1,484 @@ +/*------------------------------------------------------------------------- + setjmp.c - source file for ANSI routines setjmp & longjmp + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include +#define __SDCC_HIDE_LONGJMP +#include + +#if defined(__SDCC_ds390) + +#include + +int __setjmp (jmp_buf buf) +{ + unsigned char sp, esp; + unsigned long lsp; + + /* registers would have been saved on the + stack anyway so we need to save SP + and the return address */ + __critical { + sp = SP; + esp = ESP; + } + lsp = sp; + lsp |= (unsigned int)(esp << 8); + lsp |= 0x400000; + *buf++ = lsp; + *buf++ = lsp >> 8; + *buf++ = *((unsigned char __xdata *) lsp - 0); + *buf++ = *((unsigned char __xdata *) lsp - 1); + *buf++ = *((unsigned char __xdata *) lsp - 2); + return 0; +} + +int longjmp (jmp_buf buf, int rv) +{ + unsigned long lsp; + + lsp = *buf++; + lsp |= (unsigned int)(*buf++ << 8); + lsp |= 0x400000; + *((unsigned char __xdata *) lsp - 0) = *buf++; + *((unsigned char __xdata *) lsp - 1) = *buf++; + *((unsigned char __xdata *) lsp - 2) = *buf++; + __critical { + SP = lsp; + ESP = lsp >> 8; + } + return rv ? rv : 1; +} + +#elif defined(__SDCC_STACK_AUTO) && defined(__SDCC_USE_XSTACK) + +static void dummy (void) __naked +{ + __asm + +;------------------------------------------------------------ +;Allocation info for local variables in function 'setjmp' +;------------------------------------------------------------ +;buf Allocated to registers dptr b +;------------------------------------------------------------ +;../../device/lib/_setjmp.c:180:int setjmp (jmp_buf buf) +; ----------------------------------------- +; function setjmp +; ----------------------------------------- + .globl ___setjmp +___setjmp: + ar2 = 0x02 + ar3 = 0x03 + ar4 = 0x04 + ar5 = 0x05 + ar6 = 0x06 + ar7 = 0x07 + ar0 = 0x00 + ar1 = 0x01 +;../../device/lib/_setjmp.c:183:*buf++ = bpx; +; genPointerSet +; genGenPointerSet + mov a,_bpx + lcall __gptrput + inc dptr +;../../device/lib/_setjmp.c:184:*buf++ = spx; +; genPointerSet +; genGenPointerSet + mov a,_spx + lcall __gptrput + inc dptr +;../../device/lib/_setjmp.c:185:*buf++ = bp; +; genPointerSet +; genGenPointerSet + mov a,_bp + lcall __gptrput + inc dptr +;../../device/lib/_setjmp.c:186:*buf++ = SP; +; genPointerSet +; genGenPointerSet + mov a,sp + lcall __gptrput + inc dptr +;../../device/lib/_setjmp.c:187:*buf++ = *((unsigned char __data *) SP ); +; genCast +; genPointerGet +; genNearPointerGet +; genPointerSet +; genGenPointerSet + mov r0,sp + mov a,@r0 + lcall __gptrput + inc dptr +;../../device/lib/_setjmp.c:188:*buf = *((unsigned char __data *)SP - 1); +; genCast +; genMinus +; genMinusDec +; peephole 177.g optimized mov sequence + dec r0 +; genPointerGet +; genNearPointerGet + mov a,@r0 +; genPointerSet +; genGenPointerSet + lcall __gptrput +#ifdef __SDCC_MODEL_HUGE + inc dptr +;../../device/lib/_setjmp.c:189:*buf = *((unsigned char __data *)SP - 2); +; genCast +; genMinus +; genMinusDec +; peephole 177.g optimized mov sequence + dec r0 +; genPointerGet +; genNearPointerGet + mov a,@r0 +; genPointerSet +; genGenPointerSet + lcall __gptrput +#endif +;../../device/lib/_setjmp.c:190:return 0; +; genRet + mov dptr,#0x0000 + _RETURN + +;------------------------------------------------------------ +;Allocation info for local variables in function 'longjmp' +;------------------------------------------------------------ +;rv Allocated to stack - offset -2 +;buf Allocated to registers dptr b +;lsp Allocated to registers r5 +;------------------------------------------------------------ +;../../device/lib/_setjmp.c:192:int longjmp (jmp_buf buf, int rv) +; ----------------------------------------- +; function longjmp +; ----------------------------------------- + .globl _longjmp +_longjmp: +; genReceive + mov r0,_spx + dec r0 + movx a,@r0 + mov r2,a + dec r0 + movx a,@r0 + mov r3,a +;../../device/lib/_setjmp.c:193:bpx = *buf++; +; genPointerGet +; genGenPointerGet + lcall __gptrget + mov _bpx,a + inc dptr +;../../device/lib/_setjmp.c:194:spx = *buf++; +; genPointerGet +; genGenPointerGet + lcall __gptrget + mov _spx,a + inc dptr +;../../device/lib/_setjmp.c:195:bp = *buf++; +; genPointerGet +; genGenPointerGet + lcall __gptrget + mov _bp,a + inc dptr +;../../device/lib/_setjmp.c:196:lsp = *buf++; +; genPointerGet +; genGenPointerGet + lcall __gptrget + inc dptr +; genAssign + mov r5,a +;../../device/lib/_setjmp.c:197:*((unsigned char __data *) lsp) = *buf++; +; genCast + mov r0,a +; genPointerGet +; genGenPointerGet + lcall __gptrget + inc dptr +; genPointerSet +; genNearPointerSet + mov @r0,a +;../../device/lib/_setjmp.c:198:*((unsigned char __data *) lsp - 1) = *buf; +; genMinus +; genMinusDec + dec r0 +; genPointerGet +; genGenPointerGet + lcall __gptrget +; genPointerSet +; genNearPointerSet + mov @r0,a +#ifdef __SDCC_MODEL_HUGE + inc dptr +;../../device/lib/_setjmp.c:199:*((unsigned char __data *) lsp - 2) = *buf; +; genMinus +; genMinusDec + dec r0 +; genPointerGet +; genGenPointerGet + lcall __gptrget +; genPointerSet +; genNearPointerSet + mov @r0,a +#endif +;../../device/lib/_setjmp.c:200:SP = lsp; +; genAssign + mov sp,r5 +;../../device/lib/_setjmp.c:201:return rv ? rv : 1; +; genAssign + mov dph,r2 + mov dpl,r3 + mov a,r2 + orl a,r3 + jnz 00001$ + inc dptr +; genRet +00001$: + _RETURN + + __endasm; +} + +#elif defined(__SDCC_STACK_AUTO) + +static void dummy (void) __naked +{ + __asm + +;------------------------------------------------------------ +;Allocation info for local variables in function 'setjmp' +;------------------------------------------------------------ +;buf Allocated to registers dptr b +;------------------------------------------------------------ +;../../device/lib/_setjmp.c:122:int setjmp (unsigned char *buf) +; ----------------------------------------- +; function setjmp +; ----------------------------------------- + .globl ___setjmp +___setjmp: + ar2 = 0x02 + ar3 = 0x03 + ar4 = 0x04 + ar5 = 0x05 + ar6 = 0x06 + ar7 = 0x07 + ar0 = 0x00 + ar1 = 0x01 +; genReceive +;../../device/lib/_setjmp.c:125:*buf = BP; +; genPointerSet +; genGenPointerSet + mov a,_bp + lcall __gptrput + inc dptr +;../../device/lib/_setjmp.c:126:*buf = SP; +; genPointerSet +; genGenPointerSet + mov a,sp + lcall __gptrput + inc dptr +;../../device/lib/_setjmp.c:127:*buf++ = *((unsigned char __data *) SP ); +; genCast + mov r0,sp +; genPointerGet +; genNearPointerGet + mov a,@r0 +; genPointerSet +; genGenPointerSet + lcall __gptrput + inc dptr +;../../device/lib/_setjmp.c:128:*buf++ = *((unsigned char __data *)SP - 1); +; genCast +; genMinus +; genMinusDec + dec r0 +; genPointerGet +; genNearPointerGet + mov a,@r0 +; genPointerSet +; genGenPointerSet + lcall __gptrput +#ifdef __SDCC_MODEL_HUGE + inc dptr +;../../device/lib/_setjmp.c:129:*buf++ = *((unsigned char __data *)SP - 2); +; genCast +; genMinus +; genMinusDec + dec r0 +; genPointerGet +; genNearPointerGet + mov a,@r0 +; genPointerSet +; genGenPointerSet + lcall __gptrput +#endif +;../../device/lib/_setjmp.c:130:return 0; +; genRet + mov dptr,#0x0000 + _RETURN + +;------------------------------------------------------------ +;Allocation info for local variables in function 'longjmp' +;------------------------------------------------------------ +;rv Allocated to stack - offset -3 +;buf Allocated to registers dptr b +;lsp Allocated to registers r5 +;------------------------------------------------------------ +;../../device/lib/_setjmp.c:28:int longjmp (jmp_buf buf, int rv) +; ----------------------------------------- +; function longjmp +; ----------------------------------------- + .globl _longjmp +_longjmp: + ar2 = 0x02 + ar3 = 0x03 + ar4 = 0x04 + ar5 = 0x05 + ar6 = 0x06 + ar7 = 0x07 + ar0 = 0x00 + ar1 = 0x01 +; genReceive + mov r0,sp + dec r0 + dec r0 +#ifdef __SDCC_MODEL_HUGE + dec r0 +#endif + mov ar2,@r0 + dec r0 + mov ar3,@r0 +;../../device/lib/_setjmp.c:30:bp = *buf++; +; genPointerGet +; genGenPointerGet + lcall __gptrget + inc dptr +; genAssign + mov _bp,a +;../../device/lib/_setjmp.c:31:lsp = *buf++; +; genPointerGet +; genGenPointerGet + lcall __gptrget + inc dptr +; genAssign + mov r5,a +;../../device/lib/_setjmp.c:32:*((unsigned char __data *) lsp) = *buf++; +; genCast + mov r0,a +; genPointerGet +; genGenPointerGet + lcall __gptrget + inc dptr +; genPointerSet +; genNearPointerSet + mov @r0,a +;../../device/lib/_setjmp.c:33:*((unsigned char __data *) lsp - 1) = *buf; +; genCast +; genMinus +; genMinusDec + dec r0 +; genPointerGet +; genGenPointerGet + lcall __gptrget +; genPointerSet +; genNearPointerSet + mov @r0,a +#ifdef __SDCC_MODEL_HUGE + inc dptr +;../../device/lib/_setjmp.c:34:*((unsigned char __data *) lsp - 2) = *buf; +; genCast +; genMinus +; genMinusDec + dec r0 +; genPointerGet +; genGenPointerGet + lcall __gptrget +; genPointerSet +; genNearPointerSet + mov @r0,a +#endif +;../../device/lib/_setjmp.c:35:SP = lsp; +; genAssign + mov sp,r5 +;../../device/lib/_setjmp.c:36:return rv ? rv : 1; +; genAssign + mov dph,r2 + mov dpl,r3 + mov a,r2 + orl a,r3 + jnz 00001$ + inc dptr +; genRet +00001$: + _RETURN + + __endasm; +} + +#else + +#include <8051.h> + +extern unsigned char __data spx; +extern unsigned char __data bpx; + +int __setjmp (jmp_buf buf) +{ + /* registers would have been saved on the + stack anyway so we need to save SP + and the return address */ +#ifdef __SDCC_USE_XSTACK + *buf++ = spx; + *buf++ = bpx; +#endif + *buf++ = SP; + *buf++ = *((unsigned char __data *) SP - 0); + *buf++ = *((unsigned char __data *) SP - 1); +#ifdef __SDCC_MODEL_HUGE + *buf++ = *((unsigned char __data *) SP - 2); +#endif + return 0; +} + +int longjmp (jmp_buf buf, int rv) +{ + unsigned char lsp; + +#ifdef __SDCC_USE_XSTACK + spx = *buf++; + bpx = *buf++; +#endif + lsp = *buf++; + *((unsigned char __data *) lsp - 0) = *buf++; + *((unsigned char __data *) lsp - 1) = *buf++; +#ifdef __SDCC_MODEL_HUGE + *((unsigned char __data *) lsp - 2) = *buf++; +#endif + SP = lsp; + return rv ? rv : 1; +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_sint2fs.c b/hardware/tools/stm8/lib/src/_sint2fs.c new file mode 100644 index 0000000..95125b4 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_sint2fs.c @@ -0,0 +1,58 @@ +/*------------------------------------------------------------------------- + _sint2fs.c - Floating point library in optimized assembly for 8051 + + Copyright (C) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +// float long __sint2fs (float x) +static void dummy(void) __naked +{ + __asm + .globl ___sint2fs +___sint2fs: + mov r4, dph + mov r3, dpl + mov r2, #0 + mov r1, #0 + mov a, #142 + ljmp slong2fs_doit + __endasm; +} + +#else + +/* convert signed int to float */ +float __sint2fs (signed int si) { + return __slong2fs(si); +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_slong2fs.c b/hardware/tools/stm8/lib/src/_slong2fs.c new file mode 100644 index 0000000..26c9161 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_slong2fs.c @@ -0,0 +1,86 @@ +/*------------------------------------------------------------------------- + _slong2fs.c - Floating point library in optimized assembly for 8051 + + Copyright (C) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +//float __slong2fs (long x) +static void dummy(void) __naked +{ + __asm + .globl ___slong2fs +___slong2fs: + mov r4, a + mov r3, b + mov r2, dph + mov r1, dpl + mov a, #158 + .globl slong2fs_doit +slong2fs_doit: + mov exp_a, a + clr sign_a + mov a, r4 + jnb acc.7, slong2fs_positive + setb sign_a + mov a, r1 + cpl a + add a, #1 + mov r1, a + mov a, r2 + cpl a + addc a, #0 + mov r2, a + mov a, r3 + cpl a + addc a, #0 + mov r3, a + mov a, r4 + cpl a + addc a, #0 + mov r4, a +slong2fs_positive: + lcall fs_normalize_a + ljmp fs_round_and_return + __endasm; +} + +#else + +/* convert signed long to float */ +float __slong2fs (signed long sl) { + if (sl<0) + return -__ulong2fs(-sl); + else + return __ulong2fs(sl); +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_spx.c b/hardware/tools/stm8/lib/src/_spx.c new file mode 100644 index 0000000..bad2faa --- /dev/null +++ b/hardware/tools/stm8/lib/src/_spx.c @@ -0,0 +1,30 @@ +/*------------------------------------------------------------------------- + _spx.c - just declares bp as a variable + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +__data unsigned char spx ; +__data unsigned char _page_no__; diff --git a/hardware/tools/stm8/lib/src/_startup.c b/hardware/tools/stm8/lib/src/_startup.c new file mode 100644 index 0000000..2f384c1 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_startup.c @@ -0,0 +1,57 @@ +/*------------------------------------------------------------------------- + _startup.c - startup routine for sdcc + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* External startup code can be written in C + here .. Special usage if this routine + returns a non-zero value then global & + static variable initialisation will be skipped. + Beware not to use initialized variables as they + are not initialized yet nor to use pdata/xdata + variables if external data memory needs to be + enabled first. */ + +#if defined(__SDCC_ds390) || defined(__SDCC_ds400) + +/* Disable "ISO C forbids an empty source file" warning message */ +#pragma disable_warning 190 + +#elif defined(__SDCC_mcs51) || defined(__SDCC_z80) + +unsigned char _sdcc_external_startup (void) __nonbanked +{ + return 0; +} + +#else + +unsigned char _sdcc_external_startup () +{ + return 0; +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_strcat.c b/hardware/tools/stm8/lib/src/_strcat.c new file mode 100644 index 0000000..e25a592 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_strcat.c @@ -0,0 +1,41 @@ +/*------------------------------------------------------------------------- + _strcat.c - part of string library functions + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +char * strcat ( char * dst, const 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 */ +} diff --git a/hardware/tools/stm8/lib/src/_strchr.c b/hardware/tools/stm8/lib/src/_strchr.c new file mode 100644 index 0000000..07d18a1 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_strchr.c @@ -0,0 +1,45 @@ +/*------------------------------------------------------------------------- + _strchr.c - part of string library functions + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#undef strchr /* Avoid conflict with builtin strchr() in Z80 and some related ports */ + +#ifdef __SDCC_BROKEN_STRING_FUNCTIONS +char * strchr ( const char * string, char ch ) +#else +char * strchr ( const char * string, int ch ) +#endif +{ + while (*string && *string != ch) + string++; + + if (*string == ch) + return((char *)string); + return ( NULL ); +} diff --git a/hardware/tools/stm8/lib/src/_strcmp.c b/hardware/tools/stm8/lib/src/_strcmp.c new file mode 100644 index 0000000..9312acf --- /dev/null +++ b/hardware/tools/stm8/lib/src/_strcmp.c @@ -0,0 +1,57 @@ +/*------------------------------------------------------------------------- + _strcmp.c - part of string library functions + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include +#include + +#if !_SDCC_PORT_PROVIDES_STRCMP + +int strcmp ( const char * asrc, const char * adst ) +{ +#if _SDCC_Z80_STYLE_LIB_OPT +#pragma noinduction + + char ret = 0; + const char * src = asrc; + const char * dst = adst; + + while( ! (*src - *dst) && *dst) + ++src, ++dst; + + return *src - *dst; +#else + register int ret = 0; + + while( ! (ret = *(unsigned char *)asrc - *(unsigned char *)adst) && *adst) + ++asrc, ++adst; + + return( ret ); +#endif +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_strcpy.c b/hardware/tools/stm8/lib/src/_strcpy.c new file mode 100644 index 0000000..1cc290b --- /dev/null +++ b/hardware/tools/stm8/lib/src/_strcpy.c @@ -0,0 +1,52 @@ +/*------------------------------------------------------------------------- + _strcpy.c - part of string library functions + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include +#include + +#if !_SDCC_PORT_PROVIDES_STRCPY + +char * strcpy ( char * d, const char * s ) +{ +#if _SDCC_Z80_STYLE_LIB_OPT + register char * to = d; + register const char * from = s; + + while (*to++ = *from++) ; + + return d; +#else + register char * d1 = d; + + while (*d1++ = *s++) ; + + return d; +#endif +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_strcspn.c b/hardware/tools/stm8/lib/src/_strcspn.c new file mode 100644 index 0000000..ca22aec --- /dev/null +++ b/hardware/tools/stm8/lib/src/_strcspn.c @@ -0,0 +1,45 @@ +/*------------------------------------------------------------------------- + _strcspn.c - part of string library functions + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +size_t strcspn ( const char * string, const char * control ) +{ + register size_t count = 0; + register char ch; + + while (ch = *string) { + if (strchr(control,ch)) + break; + else + count++; + string++; + } + + return count; +} diff --git a/hardware/tools/stm8/lib/src/_strlen.c b/hardware/tools/stm8/lib/src/_strlen.c new file mode 100644 index 0000000..1a31b42 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_strlen.c @@ -0,0 +1,89 @@ +/*------------------------------------------------------------------------- + _strlen.c - part of string library functions + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + mcs51 assembler by Frieder Ferlemann (2007) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#if (!defined (__SDCC_mcs51)) + + /* Generic routine first */ + size_t strlen ( const char * str ) + { + register int i = 0 ; + + while (*str++) + i++ ; + + return i; + } + +#else + +#if defined(__SDCC) + #include +#endif + + /* Assembler version for mcs51 */ + size_t strlen ( const char * str ) __naked + { + str; /* hush the compiler */ + + __asm + ; dptr holds pointer + ; b holds pointer memspace + ; + + ; char *ptr = str: + mov r2,dpl + mov r3,dph + ; + + ; while ( *ptr ) ptr++; + L00101$: + lcall __gptrget + jz L00102$ + inc dptr + sjmp L00101$ + ; + + L00102$: + ; return ptr - str; + clr c + mov a,dpl + subb a,r2 + mov dpl,a + ; + mov a,dph + subb a,r3 + mov dph,a + ; + _RETURN + __endasm; + } + +#endif diff --git a/hardware/tools/stm8/lib/src/_strncat.c b/hardware/tools/stm8/lib/src/_strncat.c new file mode 100644 index 0000000..9186206 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_strncat.c @@ -0,0 +1,45 @@ +/*------------------------------------------------------------------------- + _strncat.c - part of string library functions + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +char * strncat ( char * front, const char * back, size_t count ) +{ + char *start = front; + + while (*front++); + + front--; + + while (count--) + if (!(*front++ = *back++)) + return(start); + + *front = '\0'; + return(start); +} diff --git a/hardware/tools/stm8/lib/src/_strncmp.c b/hardware/tools/stm8/lib/src/_strncmp.c new file mode 100644 index 0000000..124c413 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_strncmp.c @@ -0,0 +1,42 @@ +/*------------------------------------------------------------------------- + _strncmp.c - part of string library functions + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +int strncmp ( const char * first, const char * last, size_t count ) +{ + if (!count) + return(0); + + while (--count && *first && *first == *last) { + first++; + last++; + } + + return( *first - *last ); +} diff --git a/hardware/tools/stm8/lib/src/_strncpy.c b/hardware/tools/stm8/lib/src/_strncpy.c new file mode 100644 index 0000000..f4aa3c4 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_strncpy.c @@ -0,0 +1,47 @@ +/*------------------------------------------------------------------------- + _strncpy.c - part of string library functions + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#undef strncpy /* Avoid conflict with builtin strncpy() in Z80 and some related ports */ + +char *strncpy ( char * d, const char * s, size_t n ) +{ + register char * d1 = d; + + while ( n && *s ) + { + n-- ; + *d++ = *s++ ; + } + while ( n-- ) + { + *d++ = '\0' ; + } + return d1; +} diff --git a/hardware/tools/stm8/lib/src/_strpbrk.c b/hardware/tools/stm8/lib/src/_strpbrk.c new file mode 100644 index 0000000..63331af --- /dev/null +++ b/hardware/tools/stm8/lib/src/_strpbrk.c @@ -0,0 +1,45 @@ +/*------------------------------------------------------------------------- + _strpbrk.c - part of string library functions + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +char * strpbrk ( const char * string, const char * control ) +{ + char *ret = NULL; + register char ch; + + while (ch = *control) { + char * p = strchr(string, ch); + if (p != NULL && (ret == NULL || p < ret)) { + ret = p; + } + control++; + } + + return (ret); +} diff --git a/hardware/tools/stm8/lib/src/_strrchr.c b/hardware/tools/stm8/lib/src/_strrchr.c new file mode 100644 index 0000000..7e49ac5 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_strrchr.c @@ -0,0 +1,49 @@ +/*------------------------------------------------------------------------- + _strrchr.c - part of string library functions + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#ifdef __SDCC_BROKEN_STRING_FUNCTIONS +char * strrchr ( const char * string, char ch ) +#else +char * strrchr ( const char * string, int ch ) +#endif +{ + const 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) ; +} diff --git a/hardware/tools/stm8/lib/src/_strspn.c b/hardware/tools/stm8/lib/src/_strspn.c new file mode 100644 index 0000000..e2df4e7 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_strspn.c @@ -0,0 +1,45 @@ +/*------------------------------------------------------------------------- + _strspn.c - part of string library functions + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +size_t strspn ( const char * string, const char * control ) +{ + register size_t count = 0; + register char ch ; + + while (ch = *string) { + if ( strchr(control,ch) ) + count++ ; + else + break ; + string++ ; + } + + return count ; +} diff --git a/hardware/tools/stm8/lib/src/_strstr.c b/hardware/tools/stm8/lib/src/_strstr.c new file mode 100644 index 0000000..0a24f28 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_strstr.c @@ -0,0 +1,55 @@ +/*------------------------------------------------------------------------- + _strstr.c - part of string library functions + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +char *strstr ( const char *str1, const char *str2 ) +{ + const char *cp = str1; + const char *s1; + const char *s2; + + if (!*str2) + return ((char*)str1); + + while (*cp) + { + s1 = cp; + s2 = str2; + + while (*s1 && *s2 && !(*s1-*s2)) + s1++, s2++; + + if (!*s2) + return ((char*)cp); + + cp++; + } + + return (NULL) ; +} diff --git a/hardware/tools/stm8/lib/src/_strtok.c b/hardware/tools/stm8/lib/src/_strtok.c new file mode 100644 index 0000000..1929fe4 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_strtok.c @@ -0,0 +1,69 @@ +/*------------------------------------------------------------------------- + _strtok.c - part of string library functions + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#if defined(__SDCC_MODEL_LARGE) || defined (__SDCC_MODEL_FLAT24) +#pragma noinduction +#pragma noinvariant +#endif + +char * strtok ( char * str, const 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; +} diff --git a/hardware/tools/stm8/lib/src/_uchar2fs.c b/hardware/tools/stm8/lib/src/_uchar2fs.c new file mode 100644 index 0000000..486550d --- /dev/null +++ b/hardware/tools/stm8/lib/src/_uchar2fs.c @@ -0,0 +1,59 @@ +/*------------------------------------------------------------------------- + _uchar2fs.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +// float long __uchar2fs (float x) +static void dummy(void) __naked +{ + __asm + .globl ___uchar2fs +___uchar2fs: + clr a + mov r4, dpl + mov r3, a + mov r2, a + mov r1, a + mov a, #134 + ljmp ulong2fs_doit + __endasm; +} + +#else + +/* convert unsigned char to float */ +float __uchar2fs (unsigned char uc) { + return __ulong2fs(uc); +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_uint2fs.c b/hardware/tools/stm8/lib/src/_uint2fs.c new file mode 100644 index 0000000..3669255 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_uint2fs.c @@ -0,0 +1,58 @@ +/*------------------------------------------------------------------------- + _uint2fs.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +// float long __uint2fs (float x) +static void dummy(void) __naked +{ + __asm + .globl ___uint2fs +___uint2fs: + clr a + mov r4, dph + mov r3, dpl + mov r2, a + mov r1, a + mov a, #142 + ljmp ulong2fs_doit + __endasm; +} + +#else + +/* convert unsigned int to float */ +float __uint2fs (unsigned int ui) { + return __ulong2fs(ui); +} + +#endif diff --git a/hardware/tools/stm8/lib/src/_ulong2fs.c b/hardware/tools/stm8/lib/src/_ulong2fs.c new file mode 100644 index 0000000..f97a8f2 --- /dev/null +++ b/hardware/tools/stm8/lib/src/_ulong2fs.c @@ -0,0 +1,120 @@ +/*------------------------------------------------------------------------- + _ulong2fs.c - Floating point library in optimized assembly for 8051 + + Copyright (c) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + + +#define __SDCC_FLOAT_LIB +#include + + +#ifdef FLOAT_ASM_MCS51 + +// float long __ulong2fs (float x) +static void dummy(void) __naked +{ + __asm + .globl ___ulong2fs +___ulong2fs: + mov r4, a + mov r3, b + mov r2, dph + mov r1, dpl + mov a, #158 + .globl ulong2fs_doit +ulong2fs_doit: + clr sign_a +long2fs_doit: + mov exp_a, a + lcall fs_normalize_a + ljmp fs_round_and_return + __endasm; +} + +#else + +/* +** libgcc support for software floating point. +** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved. +** Permission is granted to do *anything* you want with this file, +** commercial or otherwise, provided this message remains intact. So there! +** I would appreciate receiving any updates/patches/changes that anyone +** makes, and am willing to be the repository for said changes (am I +** making a big mistake?). +** +** Pat Wood +** Pipeline Associates, Inc. +** pipeline!phw@motown.com or +** sun!pipeline!phw or +** uunet!motown!pipeline!phw +*/ + +/* (c)2000/2001: hacked a little by johan.knol@iduna.nl for sdcc */ + +union float_long + { + float f; + long l; + }; + +float __ulong2fs (unsigned long a ) +{ + int exp = 24 + EXCESS; + volatile union float_long fl; + + if (!a) + { + return 0.0; + } + + while (a & NORM) + { + // we lose accuracy here + a >>= 1; + exp++; + } + + while (a < HIDDEN) + { + a <<= 1; + exp--; + } + +#if 1 + if ((a&0x7fffff)==0x7fffff) { + a=0; + exp++; + } +#endif + + a &= ~HIDDEN ; + /* pack up and go home */ + fl.l = PACK(0,(unsigned long)exp, a); + + return (fl.f); +} + +#endif diff --git a/hardware/tools/stm8/lib/src/abs.c b/hardware/tools/stm8/lib/src/abs.c new file mode 100644 index 0000000..2cb5a7c --- /dev/null +++ b/hardware/tools/stm8/lib/src/abs.c @@ -0,0 +1,61 @@ +/*------------------------------------------------------------------------- + abs.c - computes absolute value of an integer. + + Copyright (C) 2004, Maarten Brock, sourceforge.brock@dse.nl + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#if defined (__SDCC_mcs51) + +#if defined(__SDCC) + #include +#endif + +static void dummy(void) __naked +{ + __asm + .globl _abs +_abs: + mov a, dph + jnb acc.7, 00001$ + xrl dpl,#0xFF + xrl dph,#0xFF + inc dptr +00001$: + _RETURN + __endasm; +} + +#else + +int abs(int j) +{ + return (j < 0) ? -j : j; +} + +#endif + +//END OF MODULE diff --git a/hardware/tools/stm8/lib/src/acosf.c b/hardware/tools/stm8/lib/src/acosf.c new file mode 100644 index 0000000..e157f80 --- /dev/null +++ b/hardware/tools/stm8/lib/src/acosf.c @@ -0,0 +1,42 @@ +/*------------------------------------------------------------------------- + acosf.c - Computes arc cosine of a 32-bit float + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* Version 1.0 - Initial release */ + +#include +#include + +float asincosf(float x, bool isacos); + +float acosf(float x) _FLOAT_FUNC_REENTRANT +{ + if (x == 1.0) return 0.0; + else if (x ==-1.0) return PI; + else if (x == 0.0) return HALF_PI; + else return asincosf(x, true); +} diff --git a/hardware/tools/stm8/lib/src/aligned_alloc.c b/hardware/tools/stm8/lib/src/aligned_alloc.c new file mode 100644 index 0000000..92f3259 --- /dev/null +++ b/hardware/tools/stm8/lib/src/aligned_alloc.c @@ -0,0 +1,41 @@ +/*------------------------------------------------------------------------- + aligned_alloc.c + + Philipp Klaus Krause, philipp@informatik.uni-frankfurt.de 2013 + + (c) 2015 Goethe-Universität Frankfurt + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#pragma std_c11 + +#include + +/* it is important to declare this function extern before including + the inline definition to give it external linkage */ + +extern void *aligned_alloc(size_t alignment, size_t size); + +#include + diff --git a/hardware/tools/stm8/lib/src/asincosf.c b/hardware/tools/stm8/lib/src/asincosf.c new file mode 100644 index 0000000..9116e07 --- /dev/null +++ b/hardware/tools/stm8/lib/src/asincosf.c @@ -0,0 +1,97 @@ +/*------------------------------------------------------------------------- + asincosf.c - Computes asin or acos of a 32-bit float as outlined in [1] + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* [1] William James Cody and W. M. Waite. _Software manual for the + elementary functions_, Englewood Cliffs, N.J.:Prentice-Hall, 1980. */ + +/* Version 1.0 - Initial release */ + +#include +#include +#include + +#define P1 0.933935835E+0 +#define P2 -0.504400557E+0 +#define Q0 0.560363004E+1 +#define Q1 -0.554846723E+1 +#define Q2 0.100000000E+1 + +#define P(g) (P2 * g + P1) +#define Q(g) ((Q2 * g + Q1) * g + Q0) + +float asincosf(float x, bool isacos) +{ + float y, g, r; + unsigned char i; + bool quartPI = isacos; + + static const float a[2] = { 0.0, QUART_PI }; + static const float b[2] = { HALF_PI, QUART_PI }; + + y = fabsf(x); + if (y < EPS) + { + r = y; + } + else + { + if (y > 0.5) + { + quartPI = !isacos; + if (y > 1.0) + { + errno = EDOM; + return 0.0; + } + g = (0.5 - y) + 0.5; + g = ldexpf(g, -1); + y = sqrtf(g); + y = -(y + y); + } + else + { + g = y * y; + } + r = y + y * ((P(g) * g) / Q(g)); + } + i = quartPI; + if (isacos) + { + if (x < 0.0) + r = (b[i] + r) + b[i]; + else + r = (a[i] - r) + a[i]; + } + else + { + r = (a[i] + r) + a[i]; + if (x < 0.0) + r = -r; + } + return r; +} diff --git a/hardware/tools/stm8/lib/src/asinf.c b/hardware/tools/stm8/lib/src/asinf.c new file mode 100644 index 0000000..478d9c8 --- /dev/null +++ b/hardware/tools/stm8/lib/src/asinf.c @@ -0,0 +1,42 @@ +/*------------------------------------------------------------------------- + asinf.c - Computes asin(x) + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* Version 1.0 - Initial release */ + +#include +#include + +float asincosf(float x, bool isacos); + +float asinf(float x) _FLOAT_FUNC_REENTRANT +{ + if (x == 1.0) return HALF_PI; + else if (x ==-1.0) return -HALF_PI; + else if (x == 0.0) return 0.0; + else return asincosf(x, false); +} diff --git a/hardware/tools/stm8/lib/src/assert.c b/hardware/tools/stm8/lib/src/assert.c new file mode 100644 index 0000000..c007920 --- /dev/null +++ b/hardware/tools/stm8/lib/src/assert.c @@ -0,0 +1,37 @@ +/*------------------------------------------------------------------------- + assert.c + + Copyright (C) 2000, Michael Hope + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include +#include + +void _assert(char *expr, const char *filename, unsigned int linenumber) +{ + printf("Assert(%s) failed at line %u in file %s.\n", + expr, linenumber, filename); + while(1); +} diff --git a/hardware/tools/stm8/lib/src/atan2f.c b/hardware/tools/stm8/lib/src/atan2f.c new file mode 100644 index 0000000..3734578 --- /dev/null +++ b/hardware/tools/stm8/lib/src/atan2f.c @@ -0,0 +1,55 @@ +/*------------------------------------------------------------------------- + atan2f.c - Computes atan2(x) where x is a 32-bit float. + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* Version 1.0 - Initial release */ + +#include +#include + +float atan2f(float x, float y) +{ + float r; + + if ((x==0.0) && (y==0.0)) + { + errno=EDOM; + return 0.0; + } + + if(fabsf(y)>=fabsf(x)) + { + r=atanf(x/y); + if(y<0.0) r+=(x>=0?PI:-PI); + } + else + { + r=-atanf(y/x); + r+=(x<0.0?-HALF_PI:HALF_PI); + } + return r; +} diff --git a/hardware/tools/stm8/lib/src/atanf.c b/hardware/tools/stm8/lib/src/atanf.c new file mode 100644 index 0000000..9b633d9 --- /dev/null +++ b/hardware/tools/stm8/lib/src/atanf.c @@ -0,0 +1,85 @@ +/*------------------------------------------------------------------------- + atanf.c - Computes arctan of a 32-bit float as outlined in [1] + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* [1] William James Cody and W. M. Waite. _Software manual for the + elementary functions_, Englewood Cliffs, N.J.:Prentice-Hall, 1980. */ + +/* Version 1.0 - Initial release */ + +#include +#include + +#define P0 -0.4708325141E+0 +#define P1 -0.5090958253E-1 +#define Q0 0.1412500740E+1 +#define Q1 0.1000000000E+1 + +#define P(g,f) ((P1*g+P0)*g*f) +#define Q(g) (Q1*g+Q0) + +#define K1 0.2679491924 /* 2-sqrt(3) */ +#define K2 0.7320508076 /* sqrt(3)-1 */ +#define K3 1.7320508076 /* sqrt(3) */ + +#ifdef __SDCC_mcs51 + #define myconst __code +#else + #define myconst const +#endif + +float atanf(float x) _FLOAT_FUNC_REENTRANT +{ + float f, r, g; + int n=0; + static myconst float a[]={ 0.0, 0.5235987756, 1.5707963268, 1.0471975512 }; + + f=fabsf(x); + if(f>1.0) + { + f=1.0/f; + n=2; + } + if(f>K1) + { + f=((K2*f-1.0)+f)/(K3+f); + // What it is actually wanted is this more accurate formula, + // but SDCC optimizes it and then it does not work: + // f=(((K2*f-0.5)-0.5)+f)/(K3+f); + n++; + } + if(fabsf(f)1) r=-r; + r+=a[n]; + if(x<0.0) r=-r; + return r; +} diff --git a/hardware/tools/stm8/lib/src/atoi.c b/hardware/tools/stm8/lib/src/atoi.c new file mode 100644 index 0000000..29a3db4 --- /dev/null +++ b/hardware/tools/stm8/lib/src/atoi.c @@ -0,0 +1,52 @@ +/*--------------------------------------------------------------------- + atoi() - convert a string to an integer and return it + + Copyright (C) 2015, Philipp Klaus Krause . pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#include +#include + +int atoi(const char *nptr) +{ + int ret = 0; + bool neg; + + while (isblank (*nptr)) + nptr++; + + neg = (*nptr == '-'); + + if (*nptr == '-' || *nptr == '+') + nptr++; + + while (isdigit (*nptr)) + ret = ret * 10 + (*(nptr++) - '0'); + + return (neg ? -ret : ret); // Since -INT_MIN is INT_MIN in sdcc, the result value always turns out ok. +} + diff --git a/hardware/tools/stm8/lib/src/atol.c b/hardware/tools/stm8/lib/src/atol.c new file mode 100644 index 0000000..3aa5161 --- /dev/null +++ b/hardware/tools/stm8/lib/src/atol.c @@ -0,0 +1,52 @@ +/*--------------------------------------------------------------------- + atol() - convert a string to a long integer and return it + + Copyright (C) 2015, Philipp Klaus Krause . pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#include +#include + +long int atol(const char *nptr) +{ + long int ret = 0; + bool neg; + + while (isblank (*nptr)) + nptr++; + + neg = (*nptr == '-'); + + if (*nptr == '-' || *nptr == '+') + nptr++; + + while (isdigit (*nptr)) + ret = ret * 10 + (*(nptr++) - '0'); + + return (neg ? -ret : ret); // Since -LONG_MIN is LONG_MIN in sdcc, the result value always turns out ok. +} + diff --git a/hardware/tools/stm8/lib/src/atoll.c b/hardware/tools/stm8/lib/src/atoll.c new file mode 100644 index 0000000..cbc81ad --- /dev/null +++ b/hardware/tools/stm8/lib/src/atoll.c @@ -0,0 +1,54 @@ +/*--------------------------------------------------------------------- + atoll() - convert a string to a long long integer and return it + + Copyright (C) 2015, Philipp Klaus Krause . pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#include +#include + +#ifdef __SDCC_LONGLONG +long long int atoll(const char *nptr) +{ + long long int ret = 0; + bool neg; + + while (isblank (*nptr)) + nptr++; + + neg = (*nptr == '-'); + + if (*nptr == '-' || *nptr == '+') + nptr++; + + while (isdigit (*nptr)) + ret = ret * 10 + (*(nptr++) - '0'); + + return (neg ? -ret : ret); // Since -LLONG_MIN is LLONG_MIN in sdcc, the result value always turns out ok. +} +#endif + diff --git a/hardware/tools/stm8/lib/src/bpx.c b/hardware/tools/stm8/lib/src/bpx.c new file mode 100644 index 0000000..ce377d0 --- /dev/null +++ b/hardware/tools/stm8/lib/src/bpx.c @@ -0,0 +1,33 @@ +/*------------------------------------------------------------------------- + bpx.c - just declares bpx as a variable + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#if defined(__SDCC_mcs51) + __data unsigned char bpx ; +#else + __data unsigned int bpx ; +#endif diff --git a/hardware/tools/stm8/lib/src/btowc.c b/hardware/tools/stm8/lib/src/btowc.c new file mode 100644 index 0000000..f2e2d26 --- /dev/null +++ b/hardware/tools/stm8/lib/src/btowc.c @@ -0,0 +1,41 @@ +/*------------------------------------------------------------------------- + btowc.c - convert a single-byte character to a wide character + + Copyright (C) 2016, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#include + +_Static_assert(EOF & 0x80, "Invalid EOF"); + +wint_t btowc(int c) +{ + if(c & 0x80) + return WEOF; + return c; +} + diff --git a/hardware/tools/stm8/lib/src/c16rtomb.c b/hardware/tools/stm8/lib/src/c16rtomb.c new file mode 100644 index 0000000..e4a9646 --- /dev/null +++ b/hardware/tools/stm8/lib/src/c16rtomb.c @@ -0,0 +1,54 @@ +/*------------------------------------------------------------------------- + c32rtomb.c - convert UTF-16 to UTF-8 + + Copyright (C) 2016, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#include + +size_t c16rtomb(char *restrict s, char16_t c16, mbstate_t *restrict ps) +{ + wchar_t codepoint; + + if(ps->c[1] || ps->c[2]) // We already have the high surrogate. Now get the lowe surrogate + { + char16_t high_surrogate = ps->c[1] + (ps->c[2] << 8); + ps->c[1] = ps->c[2] = 0; + codepoint = (high_surrogate << 10) + c16 + 0x10000 - (0xd800 << 10) - 0xdc00; + } + else if (c16 < 0xd7ff || c16 >= 0xe000) // Basic multilingual plane. + codepoint = c16; + else // Get the high surrogate + { + ps->c[1] = c16 & 0xff; + ps->c[2] = c16 >> 8; + return(0); + } + + return(wctomb(s, codepoint)); +} + diff --git a/hardware/tools/stm8/lib/src/c32rtomb.c b/hardware/tools/stm8/lib/src/c32rtomb.c new file mode 100644 index 0000000..c319786 --- /dev/null +++ b/hardware/tools/stm8/lib/src/c32rtomb.c @@ -0,0 +1,38 @@ +/*------------------------------------------------------------------------- + c32rtomb.c - convert a wide character to a multibyte sequence + + Copyright (C) 2016, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#include + +size_t c32rtomb(char *restrict s, char32_t c32, mbstate_t *restrict ps) +{ + ps; + return(wctomb(s, c32)); +} + diff --git a/hardware/tools/stm8/lib/src/calloc.c b/hardware/tools/stm8/lib/src/calloc.c new file mode 100644 index 0000000..c3b662c --- /dev/null +++ b/hardware/tools/stm8/lib/src/calloc.c @@ -0,0 +1,47 @@ +/*------------------------------------------------------------------------- + calloc.c - allocate memory. + + Copyright (C) 2015, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include +#include + +#if defined(__SDCC_mcs51) || defined(__SDCC_ds390) || defined(__SDCC_ds400) +#define XDATA __xdata +#else +#define XDATA +#endif + +void XDATA *calloc (size_t nmemb, size_t size) +{ + void XDATA *ptr; + + if (ptr = malloc(nmemb * size)) + memset(ptr, 0, nmemb * size); + + return(ptr); +} + diff --git a/hardware/tools/stm8/lib/src/ceilf.c b/hardware/tools/stm8/lib/src/ceilf.c new file mode 100644 index 0000000..3070735 --- /dev/null +++ b/hardware/tools/stm8/lib/src/ceilf.c @@ -0,0 +1,41 @@ +/*------------------------------------------------------------------------- + ceilf.c - Returns the integer larger or equal than x + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* Version 1.0 - Initial release */ + +#include + +float ceilf(float x) _FLOAT_FUNC_REENTRANT +{ + long r; + r=x; + if (r<0) + return r; + else + return (r+((r +#include + +float sincosf(float x, bool iscos); + +float cosf(float x) _FLOAT_FUNC_REENTRANT +{ + if (x==0.0) return 1.0; + return sincosf(x, 1); +} diff --git a/hardware/tools/stm8/lib/src/coshf.c b/hardware/tools/stm8/lib/src/coshf.c new file mode 100644 index 0000000..ca86187 --- /dev/null +++ b/hardware/tools/stm8/lib/src/coshf.c @@ -0,0 +1,39 @@ +/*------------------------------------------------------------------------- + coshf.c - Computes cosh(x) where x is a 32-bit float. + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* Version 1.0 - Initial release */ + +#include +#include + +float sincoshf(float x, bool iscosh); + +float coshf(float x) _FLOAT_FUNC_REENTRANT +{ + return sincoshf(x, 1); +} diff --git a/hardware/tools/stm8/lib/src/cotf.c b/hardware/tools/stm8/lib/src/cotf.c new file mode 100644 index 0000000..84a244b --- /dev/null +++ b/hardware/tools/stm8/lib/src/cotf.c @@ -0,0 +1,51 @@ +/*------------------------------------------------------------------------- + cotf.c - Computes cot(x) where x is a 32-bit float. + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* Version 1.0 - Initial release */ + +#include +#include +#include + +float tancotf(float x, bool iscotan); + +float cotf(float x) _FLOAT_FUNC_REENTRANT +{ + float y; + + y=fabsf(x); + if (y<1.0E-30) //This one requires more thinking... + { + errno = ERANGE; + if (x<0.0) + return -HUGE_VALF; + else + return +HUGE_VALF; + } + return tancotf(x, 1); +} diff --git a/hardware/tools/stm8/lib/src/errno.c b/hardware/tools/stm8/lib/src/errno.c new file mode 100644 index 0000000..1374ee4 --- /dev/null +++ b/hardware/tools/stm8/lib/src/errno.c @@ -0,0 +1,29 @@ +/*------------------------------------------------------------------------- + errno.c - just declares errno as a variable + + 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +int errno; diff --git a/hardware/tools/stm8/lib/src/expf.c b/hardware/tools/stm8/lib/src/expf.c new file mode 100644 index 0000000..6870487 --- /dev/null +++ b/hardware/tools/stm8/lib/src/expf.c @@ -0,0 +1,377 @@ +/*------------------------------------------------------------------------- + expf.c - Computes e**x of a 32-bit float as outlined in [1] + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* [1] William James Cody and W. M. Waite. _Software manual for the + elementary functions_, Englewood Cliffs, N.J.:Prentice-Hall, 1980. */ + +/* Version 1.0 - Initial release */ + +#define __SDCC_MATH_LIB +#include +#include +#include + +#ifdef MATH_ASM_MCS51 + +#define __SDCC_FLOAT_LIB +#include + +// TODO: share with other temps +static __bit sign_bit; +static __data unsigned char expf_y[4]; +static __data unsigned char n; + +float expf(float x) +{ + x; + __asm + mov c, acc.7 + mov _sign_bit, c // remember sign + clr acc.7 // and make input positive + mov r0, a + mov c, b.7 + rlc a // extract exponent + add a, #153 + jc expf_not_zero + // input is a very small number, so e^x is 1.000000 + mov dptr, #0 + mov b, #0x80 + mov a, #0x3F + ljmp expf_exit +expf_not_zero: + // TODO: check exponent for very small values, and return zero + mov _n, #0 + mov a, dpl + add a, #0xE8 // is x >= 0.69314718 + mov a, dph + addc a, #0x8D + mov a, b + addc a, #0xCE + mov a, r0 + addc a, #0xC0 + mov a, r0 + jnc expf_no_range_reduction +expf_range_reduction: + mov (_expf_y + 0), dpl // keep copy of x in "exp_y" + mov (_expf_y + 1), dph + mov (_expf_y + 2), b + mov (_expf_y + 3), a + mov r0, #0x3B + push ar0 + mov r0, #0xAA + push ar0 + mov r0, #0xB8 + push ar0 + mov r0, #0x3F + push ar0 + lcall ___fsmul // x * 1.442695041 = x / ln(2) + dec sp + dec sp + dec sp + dec sp + lcall ___fs2uchar // n = int(x * 1.442695041) + mov a, dpl + mov _n, a + add a, #128 + jnc expf_range_ok + lcall fs_return_inf // exponent overflow + ljmp expf_exit +expf_range_ok: + mov r0,#0x00 + mov r1,#0x80 + mov r2,#0x31 + mov r3,#0xBF + lcall expf_scale_and_add + mov (_expf_y + 0), dpl + mov (_expf_y + 1), dph + mov (_expf_y + 2), b + mov (_expf_y + 3), a + mov r0,#0x83 + mov r1,#0x80 + mov r2,#0x5E + mov r3,#0x39 + lcall expf_scale_and_add +expf_no_range_reduction: + + +// Compute e^x using the cordic algorithm. This works over an +// input range of 0 to 0.69314712. Can be extended to work from +// 0 to 1.0 if the results are normalized, but over the range +// we use, the result is always from 1.0 to 1.99999988 (fixed +// exponent of 127) + +expf_cordic_begin: + mov c, b.7 + rlc a // extract exponent to acc + setb b.7 + mov r1, dpl // mantissa to r4/r3/r2/r1 + mov r2, dph + mov r3, b + mov r4, #0 + + // first, align the input into a 32 bit long + cjne a, #121, exp_lshift + sjmp exp_noshift +exp_lshift: + jc exp_rshift + // exp_a is greater than 121, so left shift + add a, #135 + lcall fs_lshift_a + sjmp exp_noshift +exp_rshift: + // exp_a is less than 121, so right shift + cpl a + add a, #122 + lcall fs_rshift_a +exp_noshift: // r4/r3/r2/r1 = x + clr a + mov (_expf_y + 0), a // y = 1.0; + mov (_expf_y + 1), a + mov (_expf_y + 2), a + mov (_expf_y + 3), #0x20 + mov dptr, #__fs_natural_log_table + mov r0, a // r0 = i +exp_cordic_loop: + clr a + movc a, @a+dptr + mov b, a + inc dptr + clr a + movc a, @a+dptr // r7/r6/r5/b = table[i] + mov r5, a + inc dptr + clr a + movc a, @a+dptr + mov r6, a + inc dptr + clr a + movc a, @a+dptr + mov r7, a + inc dptr + clr c + mov a, r1 + subb a, b // compare x to table[i] + mov a, r2 + subb a, r5 + mov a, r3 + subb a, r6 + mov a, r4 + subb a, r7 + jc exp_cordic_skip // if table[i] < x + clr c + mov a, r1 + subb a, b + mov r1, a // x -= table[i] + mov a, r2 + subb a, r5 + mov r2, a + mov a, r3 + subb a, r6 + mov r3, a + mov a, r4 + subb a, r7 + mov r4, a + mov b, (_expf_y + 0) + mov r5, (_expf_y + 1) // r7/r6/r5/b = y >> i + mov r6, (_expf_y + 2) + mov r7, (_expf_y + 3) + mov a, r0 + lcall __fs_cordic_rshift_r765_unsigned + mov a, (_expf_y + 0) + add a, b + mov (_expf_y + 0), a + mov a, (_expf_y + 1) + addc a, r5 + mov (_expf_y + 1), a // y += (y >> i) + mov a, (_expf_y + 2) + addc a, r6 + mov (_expf_y + 2), a + mov a, (_expf_y + 3) + addc a, r7 + mov (_expf_y + 3), a +exp_cordic_skip: + inc r0 + cjne r0, #27, exp_cordic_loop + mov r4, (_expf_y + 3) + mov r3, (_expf_y + 2) + mov r2, (_expf_y + 1) + mov r1, (_expf_y + 0) + mov exp_a, #121 + lcall fs_normalize_a // end of cordic + + mov a, #127 + add a, _n // ldexpf(x, n) + mov exp_a, a + lcall fs_round_and_return + + jnb _sign_bit, expf_done + push dpl + push dph + push b + push acc + mov dptr, #0 + mov b, #0x80 + mov a, #0x3F + lcall ___fsdiv // 1.0 / x + dec sp + dec sp + dec sp + dec sp +expf_done: + clr acc.7 // Result is always positive! +expf_exit: + __endasm; +#pragma less_pedantic +} + +static void dummy1(void) __naked +{ + __asm + .globl fs_lshift_a +expf_scale_and_add: + push ar0 + push ar1 + push ar2 + push ar3 + mov dpl, _n + lcall ___uchar2fs // turn n into float + lcall ___fsmul // n * scale_factor + dec sp + dec sp + dec sp + dec sp + push dpl + push dph + push b + push acc + mov dpl, (_expf_y + 0) + mov dph, (_expf_y + 1) + mov b, (_expf_y + 2) + mov a, (_expf_y + 3) + lcall ___fsadd // x += (n * scale_factor) + dec sp + dec sp + dec sp + dec sp + ret + __endasm; +} + +static void dummy(void) __naked +{ + __asm + .globl fs_lshift_a +fs_lshift_a: + jz fs_lshift_done + push ar0 + mov r0, a +fs_lshift_loop: + clr c + mov a, r1 + rlc a + mov r1, a + mov a, r2 + rlc a + mov r2, a + mov a, r3 + rlc a + mov r3, a + mov a, r4 + rlc a + mov r4, a + djnz r0, fs_lshift_loop + pop ar0 +fs_lshift_done: + ret + __endasm; +} + +#else // not MATH_ASM_MCS51 + +#define P0 0.2499999995E+0 +#define P1 0.4160288626E-2 +#define Q0 0.5000000000E+0 +#define Q1 0.4998717877E-1 + +#define P(z) ((P1*z)+P0) +#define Q(z) ((Q1*z)+Q0) + +#define C1 0.693359375 +#define C2 -2.1219444005469058277e-4 + +#define BIGX 88.72283911 /* ln(HUGE_VALF) */ +#define EXPEPS 1.0E-7 /* exp(1.0E-7)=0.0000001 */ +#define K1 1.4426950409 /* 1/ln(2) */ + +float expf(float x) _FLOAT_FUNC_REENTRANT +{ + int n; + float xn, g, r, z, y; + bool sign; + + if(x>=0.0) + { y=x; sign=0; } + else + { y=-x; sign=1; } + + if(yBIGX) + { + if(sign) + { + errno=ERANGE; + return HUGE_VALF + ; + } + else + { + return 0.0; + } + } + + z=y*K1; + n=z; + + if(n<0) --n; + if(z-n>=0.5) ++n; + xn=n; + g=((y-xn*C1))-xn*C2; + z=g*g; + r=P(z)*g; + r=0.5+(r/(Q(z)-r)); + + n++; + z=ldexpf(r, n); + if(sign) + return 1.0/z; + else + return z; +} + +#endif diff --git a/hardware/tools/stm8/lib/src/fabsf.c b/hardware/tools/stm8/lib/src/fabsf.c new file mode 100644 index 0000000..d9bbe67 --- /dev/null +++ b/hardware/tools/stm8/lib/src/fabsf.c @@ -0,0 +1,41 @@ +/*------------------------------------------------------------------------- + fabsf.c - Returns the absolute value of a 32-bit float. + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* Version 1.0 - Initial release */ + +#include +#include + +float fabsf(float x) _FLOAT_FUNC_REENTRANT +{ + union float_long fl; + + fl.f = x; + fl.l &= 0x7fffffff; + return fl.f; +} diff --git a/hardware/tools/stm8/lib/src/floorf.c b/hardware/tools/stm8/lib/src/floorf.c new file mode 100644 index 0000000..0af721d --- /dev/null +++ b/hardware/tools/stm8/lib/src/floorf.c @@ -0,0 +1,41 @@ +/*------------------------------------------------------------------------- + floorf.c - Returns the integer smaller or equal than x + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* Version 1.0 - Initial release */ + +#include + +float floorf (float x) _FLOAT_FUNC_REENTRANT +{ + long r; + r=x; + if (r<=0) + return (r+((r>x)?-1:0)); + else + return r; +} diff --git a/hardware/tools/stm8/lib/src/free.c b/hardware/tools/stm8/lib/src/free.c new file mode 100644 index 0000000..b131bf7 --- /dev/null +++ b/hardware/tools/stm8/lib/src/free.c @@ -0,0 +1,78 @@ +/*------------------------------------------------------------------------- + free.c - deallocate memory. + + Copyright (C) 2015, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include +#include + +#if defined(__SDCC_mcs51) || defined(__SDCC_ds390) || defined(__SDCC_ds400) +#define XDATA __xdata +#else +#define XDATA +#endif + +typedef struct header XDATA header_t; + +struct header +{ + header_t *next; + header_t *next_free; +}; + +extern header_t *XDATA __sdcc_heap_free; + +void free(void *ptr) +{ + header_t *h, *next_free, *prev_free; + header_t *XDATA *f; + + if(!ptr) + return; + + prev_free = 0; + for(h = __sdcc_heap_free, f = &__sdcc_heap_free; h && h < ptr; prev_free = h, f = &(h->next_free), h = h->next_free); // Find adjacent blocks in free list + next_free = h; + + h = (void XDATA *)((char XDATA *)(ptr) - offsetof(struct header, next_free)); + + // Insert into free list. + h->next_free = next_free; + *f = h; + + if(next_free == h->next) // Merge with next block + { + h->next_free = h->next->next_free; + h->next = h->next->next; + } + + if (prev_free && prev_free->next == h) // Merge with previous block + { + prev_free->next = h->next; + prev_free->next_free = h->next_free; + } +} + diff --git a/hardware/tools/stm8/lib/src/frexpf.c b/hardware/tools/stm8/lib/src/frexpf.c new file mode 100644 index 0000000..bec0e2f --- /dev/null +++ b/hardware/tools/stm8/lib/src/frexpf.c @@ -0,0 +1,47 @@ +/*------------------------------------------------------------------------- + frexpf.c - Returns the exponent and mantisa of a 32 bit float. + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* Version 1.0 - Initial release */ + +#include +#include + +float frexpf(float x, int *pw2) +{ + union float_long fl; + long int i; + + fl.f=x; + /* Find the exponent (power of 2) */ + i = ( fl.l >> 23) & 0x000000ff; + i -= 0x7e; + *pw2 = i; + fl.l &= 0x807fffff; /* strip all exponent bits */ + fl.l |= 0x3f000000; /* mantissa between 0.5 and 1 */ + return(fl.f); +} diff --git a/hardware/tools/stm8/lib/src/gets.c b/hardware/tools/stm8/lib/src/gets.c new file mode 100644 index 0000000..7050dac --- /dev/null +++ b/hardware/tools/stm8/lib/src/gets.c @@ -0,0 +1,67 @@ +/*------------------------------------------------------------------------- + gets.c + + Copyright (C) 2000, Johan Knol + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +char * +gets (char *s) +{ + char c; + unsigned int count = 0; + + while (1) + { + c = getchar (); + switch(c) + { + case '\b': /* backspace */ + if (count) + { + putchar ('\b'); + putchar (' '); + putchar ('\b'); + --s; + --count; + } + break; + + case '\n': + case '\r': /* CR or LF */ + putchar ('\r'); + putchar ('\n'); + *s = 0; + return s; + + default: + *s++ = c; + ++count; + putchar (c); + break; + } + } +} diff --git a/hardware/tools/stm8/lib/src/isalnum.c b/hardware/tools/stm8/lib/src/isalnum.c new file mode 100644 index 0000000..5aa4fe5 --- /dev/null +++ b/hardware/tools/stm8/lib/src/isalnum.c @@ -0,0 +1,41 @@ +/*------------------------------------------------------------------------- + isalnum.c + + Philipp Klaus Krause, philipp@informatik.uni-frankfurt.de 2013 + + (c) 2013 Goethe-Universität Frankfurt + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#ifdef isalnum +#undef isalnum +#endif + +int isalnum (int c) +{ + return (isalpha (c) || isdigit (c)); +} + diff --git a/hardware/tools/stm8/lib/src/isalpha.c b/hardware/tools/stm8/lib/src/isalpha.c new file mode 100644 index 0000000..a146ea5 --- /dev/null +++ b/hardware/tools/stm8/lib/src/isalpha.c @@ -0,0 +1,41 @@ +/*------------------------------------------------------------------------- + isalpha.c + + Philipp Klaus Krause, philipp@informatik.uni-frankfurt.de 2013 + + (c) 2013 Goethe-Universität Frankfurt + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#ifdef isalpha +#undef isalpha +#endif + +int isalpha (int c) +{ + return (isupper (c) || islower (c)); +} + diff --git a/hardware/tools/stm8/lib/src/isblank.c b/hardware/tools/stm8/lib/src/isblank.c new file mode 100644 index 0000000..75b5faf --- /dev/null +++ b/hardware/tools/stm8/lib/src/isblank.c @@ -0,0 +1,40 @@ +/*------------------------------------------------------------------------- + isblank.c + + Philipp Klaus Krause, philipp@informatik.uni-frankfurt.de 2013 + + (c) 2013 Goethe-Universität Frankfurt + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* it is important to declare this function extern before including + the inline definition to give it external linkage */ +extern int isblank (int c); + +/* also include stdio.h before ctype.h here so ctype can perform a + _Static_assert on EOF */ +#include + +#include + diff --git a/hardware/tools/stm8/lib/src/iscntrl.c b/hardware/tools/stm8/lib/src/iscntrl.c new file mode 100644 index 0000000..27fa7e3 --- /dev/null +++ b/hardware/tools/stm8/lib/src/iscntrl.c @@ -0,0 +1,37 @@ +/*------------------------------------------------------------------------- + iscntrl.c + + Philipp Klaus Krause, philipp@informatik.uni-frankfurt.de 2013 + + (c) 2013 Goethe-Universität Frankfurt + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +int iscntrl (int c) +{ + return (c < ' ' || c == 0x7f); +} + diff --git a/hardware/tools/stm8/lib/src/isdigit.c b/hardware/tools/stm8/lib/src/isdigit.c new file mode 100644 index 0000000..7a1e3d7 --- /dev/null +++ b/hardware/tools/stm8/lib/src/isdigit.c @@ -0,0 +1,39 @@ +/*------------------------------------------------------------------------- + isdigit.c + + Philipp Klaus Krause, philipp@informatik.uni-frankfurt.de 2013 + + (c) 2013 Goethe-Universität Frankfurt + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* it is important to declare this function extern before including + the inline definition to give it external linkage */ +extern int isdigit (int c); + +/* also include stdio.h before ctype.h here so ctype can perform a + _Static_assert on EOF */ +#include + +#include diff --git a/hardware/tools/stm8/lib/src/isgraph.c b/hardware/tools/stm8/lib/src/isgraph.c new file mode 100644 index 0000000..0ea0518 --- /dev/null +++ b/hardware/tools/stm8/lib/src/isgraph.c @@ -0,0 +1,37 @@ +/*------------------------------------------------------------------------- + isgraph.c + + Philipp Klaus Krause, philipp@informatik.uni-frankfurt.de 2013 + + (c) 2013 Goethe-Universität Frankfurt + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +int isgraph (int c) +{ + return (c > ' ' && c <= '~'); +} + diff --git a/hardware/tools/stm8/lib/src/isinf.c b/hardware/tools/stm8/lib/src/isinf.c new file mode 100644 index 0000000..5433bd2 --- /dev/null +++ b/hardware/tools/stm8/lib/src/isinf.c @@ -0,0 +1,37 @@ +/*------------------------------------------------------------------------- + isinf.c - Check if a float value is an infinite (positive or negative) + + Copyright (C) 2016, Ben Shi, powerstudio1st@163.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#define __SDCC_FLOAT_LIB +#include +#include + +int isinf (float f) +{ + unsigned long *pl = (unsigned long *) &f; + return *pl == 0x7f800000 || *pl == 0xff800000; +} diff --git a/hardware/tools/stm8/lib/src/islower.c b/hardware/tools/stm8/lib/src/islower.c new file mode 100644 index 0000000..830b760 --- /dev/null +++ b/hardware/tools/stm8/lib/src/islower.c @@ -0,0 +1,39 @@ +/*------------------------------------------------------------------------- + isslower.c + + Philipp Klaus Krause, philipp@informatik.uni-frankfurt.de 2013 + + (c) 2013 Goethe-Universität Frankfurt + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* it is important to declare this function extern before including + the inline definition to give it external linkage */ +extern int islower (int c); + +/* also include stdio.h before ctype.h here so ctype can perform a + _Static_assert on EOF */ +#include + +#include diff --git a/hardware/tools/stm8/lib/src/isnan.c b/hardware/tools/stm8/lib/src/isnan.c new file mode 100644 index 0000000..7257508 --- /dev/null +++ b/hardware/tools/stm8/lib/src/isnan.c @@ -0,0 +1,38 @@ +/*------------------------------------------------------------------------- + isnan.c - Check if a float value is an NaN (Not a Number) + + Copyright (C) 2016, Ben Shi, powerstudio1st@163.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#define __SDCC_FLOAT_LIB +#include +#include + +int isnan (float f) +{ + unsigned long *pl = (unsigned long *) &f; + //return (*pl & 0x7f800000) == 0x7f800000 && (*pl & 0x007fffff) != 0; + return (*pl & 0x7fffffff) > 0x7f800000; +} diff --git a/hardware/tools/stm8/lib/src/isprint.c b/hardware/tools/stm8/lib/src/isprint.c new file mode 100644 index 0000000..923ae59 --- /dev/null +++ b/hardware/tools/stm8/lib/src/isprint.c @@ -0,0 +1,37 @@ +/*------------------------------------------------------------------------- + isprint.c + + Philipp Klaus Krause, philipp@informatik.uni-frankfurt.de 2013 + + (c) 2013 Goethe-Universität Frankfurt + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +int isprint (int c) +{ + return (c >= ' ' && c <= '~'); +} + diff --git a/hardware/tools/stm8/lib/src/ispunct.c b/hardware/tools/stm8/lib/src/ispunct.c new file mode 100644 index 0000000..0e8bf6c --- /dev/null +++ b/hardware/tools/stm8/lib/src/ispunct.c @@ -0,0 +1,37 @@ +/*------------------------------------------------------------------------- + ispunct.c + + Philipp Klaus Krause, philipp@informatik.uni-frankfurt.de 2013 + + (c) 2013 Goethe-Universität Frankfurt + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +int ispunct (int c) +{ + return (isprint (c) && !isspace (c) && !isalnum (c)); +} + diff --git a/hardware/tools/stm8/lib/src/isspace.c b/hardware/tools/stm8/lib/src/isspace.c new file mode 100644 index 0000000..8976d82 --- /dev/null +++ b/hardware/tools/stm8/lib/src/isspace.c @@ -0,0 +1,41 @@ +/*------------------------------------------------------------------------- + isspace.c + + Philipp Klaus Krause, philipp@informatik.uni-frankfurt.de 2013 + + (c) 2013 Goethe-Universität Frankfurt + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#ifdef isspace +#undef isspace +#endif + +int isspace (int c) +{ + return (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v'); +} + diff --git a/hardware/tools/stm8/lib/src/isupper.c b/hardware/tools/stm8/lib/src/isupper.c new file mode 100644 index 0000000..37808b2 --- /dev/null +++ b/hardware/tools/stm8/lib/src/isupper.c @@ -0,0 +1,39 @@ +/*------------------------------------------------------------------------- + isupper.c + + Philipp Klaus Krause, philipp@informatik.uni-frankfurt.de 2013 + + (c) 2013 Goethe-Universität Frankfurt + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* it is important to declare this function extern before including + the inline definition to give it external linkage */ +extern int isupper (int c); + +/* also include stdio.h before ctype.h here so ctype can perform a + _Static_assert on EOF */ +#include + +#include diff --git a/hardware/tools/stm8/lib/src/isxdigit.c b/hardware/tools/stm8/lib/src/isxdigit.c new file mode 100644 index 0000000..fbf4458 --- /dev/null +++ b/hardware/tools/stm8/lib/src/isxdigit.c @@ -0,0 +1,37 @@ +/*------------------------------------------------------------------------- + isxdigit.c + + Philipp Klaus Krause, philipp@informatik.uni-frankfurt.de 2013 + + (c) 2013 Goethe-Universität Frankfurt + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +int isxdigit (int c) +{ + return (c >= '0' && c <= '9' || c >= 'a' && c <= 'f' || c >= 'A' && c <= 'F'); +} + diff --git a/hardware/tools/stm8/lib/src/labs.c b/hardware/tools/stm8/lib/src/labs.c new file mode 100644 index 0000000..53fda49 --- /dev/null +++ b/hardware/tools/stm8/lib/src/labs.c @@ -0,0 +1,70 @@ +/*------------------------------------------------------------------------- + labs.c - computes absolute value of an integer. + + Copyright (C) 2004, Maarten Brock, sourceforge.brock@dse.nl + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#if defined (__SDCC_mcs51) + +#if defined(__SDCC) + #include +#endif + +static void dummy(void) __naked +{ + __asm + .globl _labs +_labs: + jnb acc.7, 00001$ + mov r2,a + clr c + clr a + subb a,dpl + mov dpl,a + clr a + subb a,dph + mov dph,a + clr a + subb a,b + mov b,a + clr a + subb a,r2 +00001$: + _RETURN + __endasm; +} + +#else + +long int labs(long int j) +{ + return (j < 0) ? -j : j; +} + +#endif + +//END OF MODULE diff --git a/hardware/tools/stm8/lib/src/ldexpf.c b/hardware/tools/stm8/lib/src/ldexpf.c new file mode 100644 index 0000000..309a52a --- /dev/null +++ b/hardware/tools/stm8/lib/src/ldexpf.c @@ -0,0 +1,46 @@ +/*------------------------------------------------------------------------- + ldexpf.c - Build a float from a mantisa and exponent. + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* Version 1.0 - Initial release */ + +#include +#include + +float ldexpf(float x, int pw2) +{ + union float_long fl; + long e; + + fl.f = x; + + e=(fl.l >> 23) & 0x000000ff; + e+=pw2; + fl.l= ((e & 0xff) << 23) | (fl.l & 0x807fffff); + + return(fl.f); +} diff --git a/hardware/tools/stm8/lib/src/log10f.c b/hardware/tools/stm8/lib/src/log10f.c new file mode 100644 index 0000000..d9f08ca --- /dev/null +++ b/hardware/tools/stm8/lib/src/log10f.c @@ -0,0 +1,37 @@ +/*------------------------------------------------------------------------- + log10f.c - Computes the base 10 log of a 32 bit float. + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* Version 1.0 - Initial release */ + +#include +#include + +float log10f(float x) _FLOAT_FUNC_REENTRANT +{ + return logf(x)*0.4342944819; +} diff --git a/hardware/tools/stm8/lib/src/logf.c b/hardware/tools/stm8/lib/src/logf.c new file mode 100644 index 0000000..2a6f640 --- /dev/null +++ b/hardware/tools/stm8/lib/src/logf.c @@ -0,0 +1,251 @@ +/*------------------------------------------------------------------------- + logf.c - Computes the natural log of a 32 bit float as outlined in [1]. + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* [1] William James Cody and W. M. Waite. _Software manual for the + elementary functions_, Englewood Cliffs, N.J.:Prentice-Hall, 1980. */ + +/* Version 1.0 - Initial release */ + +#define __SDCC_MATH_LIB +#include +#include + + +#ifdef MATH_ASM_MCS51 + +#define __SDCC_FLOAT_LIB +#include + +// TODO: share with other temps +static __data unsigned char logf_tmp[4]; + +float logf(float x) +{ + x; + __asm + + // extract the two input, placing it into: + // sign exponent mantiassa + // ---- -------- --------- + // x: sign_a exp_a r4/r3/r2 + + lcall fsgetarg +logf_neg_check: + jnb sign_a, logf_zero_check + // TODO: set errno to EDOM (negative numbers not allowed) + lcall fs_return_nan + ljmp logf_exit + +logf_zero_check: + cjne r4, #0, logf_ok + // TODO: set errno to ERANGE (zero not allowed) + setb sign_a + lcall fs_return_inf + ljmp logf_exit + +logf_ok: + push exp_a + mov a, #3 + mov r1, #0 + lcall fs_rshift_a + + clr a + mov (_logf_tmp + 0), a // y = 0 + mov (_logf_tmp + 1), a + mov (_logf_tmp + 2), a + mov (_logf_tmp + 3), a + mov dptr, #__fs_natural_log_table + mov r0, a +logf_cordic_loop: + mov ar7, r4 // r7/r6/r5 = x >> i + mov ar6, r3 + mov ar5, r2 + mov b, r1 + mov a, r0 + lcall __fs_cordic_rshift_r765_unsigned + mov a, r1 // check if x + (x >> i) > 1.0 + add a, b + mov a, r2 + addc a, r5 + mov a, r3 + addc a, r6 + mov a, r4 + addc a, r7 + anl a, #0xE0 + jnz logf_cordic_skip + mov a, r1 // x = x + (x >> i) + add a, b + mov r1, a + mov a, r2 + addc a, r5 + mov r2, a + mov a, r3 + addc a, r6 + mov r3, a + mov a, r4 + addc a, r7 + mov r4, a + clr a // y = y + log_table[i] + movc a, @a+dptr + add a, (_logf_tmp + 0) + mov (_logf_tmp + 0), a + mov a, #1 + movc a, @a+dptr + addc a, (_logf_tmp + 1) + mov (_logf_tmp + 1), a + mov a, #2 + movc a, @a+dptr + addc a, (_logf_tmp + 2) + mov (_logf_tmp + 2), a + mov a, #3 + movc a, @a+dptr + addc a, (_logf_tmp + 3) + mov (_logf_tmp + 3), a +logf_cordic_skip: + inc dptr + inc dptr + inc dptr + inc dptr + inc r0 + cjne r0, #30, logf_cordic_loop + // at this point, _logf_tmp has the natural log of the positive + // normalized fractional part (0.5 to 1.0 -> 0.693 to 0.0) + mov r4, (_logf_tmp + 3) + mov r3, (_logf_tmp + 2) + mov r2, (_logf_tmp + 1) + mov r1, (_logf_tmp + 0) + mov exp_a, #129 + setb sign_a + lcall fs_normalize_a + pop acc + cjne a, #126, logf_exponent + // if the input exponent was 126, then we don't need to add + // anything and we can just return the with we have already + + // TODO: which of these gives best accuracy??? + lcall fs_zerocheck_return + //lcall fs_round_and_return + sjmp logf_exit +logf_exponent: + jc logf_exp_neg + // the input exponent was greater than 126 +logf_exp_pos: + add a, #130 + clr sign_b + sjmp logf_exp_scale +logf_exp_neg: + // the input exponent was less than 126 + cpl a + add a, #127 + setb sign_b +logf_exp_scale: + // r0 has abs(exp - 126) + mov r0, a + // put the log of faction into b, so we can use a to compute + // the offset to be added to it or subtracted from it + lcall fs_swap_a_b + // multiply r0 by log(2), or r0 * 0xB17218 + mov a, #0x18 + mov b, r0 + mul ab + mov r1, a + mov r2, b + mov a, #0xB1 + mov b, r0 + mul ab + mov r3, a + mov r4, b + mov a, #0x72 + mov b, r0 + mul ab + add a, r2 + mov r2, a + mov a, b + addc a, r3 + mov r3, a + clr a + addc a, r4 + mov r4, a + // turn r0 * log(2) into a proper float + mov exp_a, #134 + lcall fs_normalize_a + // now just add log(fractional) +/- log(2) * abs(exp - 126) + lcall fsadd_direct_entry +logf_exit: + __endasm; +#pragma less_pedantic +} + +#else // not MATH_ASM_MCS51 + +/*Constants for 24 bits or less (8 decimal digits)*/ +#define A0 -0.5527074855E+0 +#define B0 -0.6632718214E+1 +#define A(w) (A0) +#define B(w) (w+B0) + +#define C0 0.70710678118654752440 +#define C1 0.693359375 /*355.0/512.0*/ +#define C2 -2.121944400546905827679E-4 + +float logf(float x) _FLOAT_FUNC_REENTRANT +{ +#if defined(__SDCC_mcs51) && defined(__SDCC_MODEL_SMALL) \ + && !defined(__SDCC_NOOVERLAY) + volatile +#endif + float Rz; + float f, z, w, znum, zden, xn; + int n; + + if (x<=0.0) + { + errno=EDOM; + return 0.0; + } + f=frexpf(x, &n); + znum=f-0.5; + if (f>C0) + { + znum-=0.5; + zden=(f*0.5)+0.5; + } + else + { + n--; + zden=znum*0.5+0.5; + } + z=znum/zden; + w=z*z; + + Rz=z+z*(w*A(w)/B(w)); + xn=n; + return ((xn*C2+Rz)+xn*C1); +} + +#endif diff --git a/hardware/tools/stm8/lib/src/malloc.c b/hardware/tools/stm8/lib/src/malloc.c new file mode 100644 index 0000000..18766ec --- /dev/null +++ b/hardware/tools/stm8/lib/src/malloc.c @@ -0,0 +1,108 @@ +/*------------------------------------------------------------------------- + malloc.c - allocate memory. + + Copyright (C) 2015, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include +#include + +#if defined(__SDCC_mcs51) || defined(__SDCC_ds390) || defined(__SDCC_ds400) +#define XDATA __xdata +#else +#define XDATA +#endif + +typedef struct header XDATA header_t; + +struct header +{ + header_t *next; // Next block. Linked list of all blocks, terminated by pointer to end of heap (or to the byte beyond the end of the heap). + header_t *next_free; // Next free block. Used in free blocks only. Overlaps with user data in non-free blocks. Linked list of free blocks, 0-terminated. +}; + +header_t *XDATA __sdcc_heap_free; // First free block, 0 if no free blocks. + +extern header_t __sdcc_heap; +#define HEAP_START &__sdcc_heap + +#if defined(__SDCC_mcs51) || defined(__SDCC_ds390) || defined(__SDCC_ds400) || defined(__SDCC_hc08) || defined(__SDCC_s08) + +extern const unsigned int __sdcc_heap_size; +#define HEAP_END (struct header XDATA *)((char XDATA *)&__sdcc_heap + (__sdcc_heap_size - 1)) // -1 To be sure that HEAP_END is bigger than HEAP_START. + +#else + +extern header_t __sdcc_heap_end; // Just beyond the end of the heap. Must be higher in memory than _sdcc_heap_start. +#define HEAP_END &__sdcc_heap_end + +#endif + +void __sdcc_heap_init(void) +{ + __sdcc_heap_free = HEAP_START; + __sdcc_heap_free->next = HEAP_END; + __sdcc_heap_free->next_free = 0; +} + +void XDATA *malloc(size_t size) +{ + header_t *h; + header_t *XDATA *f; + +#if defined(__SDCC_mcs51) || defined(__SDCC_ds390) || defined(__SDCC_ds400) || defined(__SDCC_hc08) || defined(__SDCC_s08) + if(!__sdcc_heap_free) + __sdcc_heap_init(); +#endif + + if(!size || size + offsetof(struct header, next_free) < size) + return(0); + size += offsetof(struct header, next_free); + if(size < sizeof(struct header)) // Requiring a minimum size makes it easier to implement free(), and avoid memory leaks. + size = sizeof(struct header); + + for(h = __sdcc_heap_free, f = &__sdcc_heap_free; h; f = &(h->next_free), h = h->next_free) + { + size_t blocksize = (char XDATA *)(h->next) - (char XDATA *)h; + if(blocksize >= size) // Found free block of sufficient size. + { + if(blocksize >= size + sizeof(struct header)) // It is worth creating a new free block + { + header_t *const newheader = (header_t *const)((char XDATA*)h + size); + newheader->next = h->next; + newheader->next_free = h->next_free; + *f = newheader; + h->next = newheader; + } + else + *f = h->next_free; + + return(&(h->next_free)); + } + } + + return(0); +} + diff --git a/hardware/tools/stm8/lib/src/mblen.c b/hardware/tools/stm8/lib/src/mblen.c new file mode 100644 index 0000000..123e3dd --- /dev/null +++ b/hardware/tools/stm8/lib/src/mblen.c @@ -0,0 +1,66 @@ +/*------------------------------------------------------------------------- + mblen.c - determine number of bytes in next multibyte character + + Copyright (C) 2016, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +int mblen(const char *s, size_t n) +{ + unsigned char m = 0; + unsigned char c; + + if(!s) + return(0); + + if(!n) + return(-1); + + c = *s; + + if(!c) + return(0); + + if(c <= 0x7f) + return(1); + + while(c & 0x80) + { + c <<= 1; + m++; + } + + if(m > n) + return(-1); + + n = m; + while(--m) + if((*++s & 0xc0) != 0x80) + return(-1); + + return(n); +} + diff --git a/hardware/tools/stm8/lib/src/mbrlen.c b/hardware/tools/stm8/lib/src/mbrlen.c new file mode 100644 index 0000000..4f75ad1 --- /dev/null +++ b/hardware/tools/stm8/lib/src/mbrlen.c @@ -0,0 +1,37 @@ +/*------------------------------------------------------------------------- + mbrlen.c - determine number of bytes in next multibyte character + + Copyright (C) 2016, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +size_t mbrlen(const char *restrict s, size_t n, mbstate_t *restrict ps) +{ + static mbstate_t sps; + + return(mbrtowc(0, s, n, ps ? ps : &sps)); +} + diff --git a/hardware/tools/stm8/lib/src/mbrtoc16.c b/hardware/tools/stm8/lib/src/mbrtoc16.c new file mode 100644 index 0000000..8977691 --- /dev/null +++ b/hardware/tools/stm8/lib/src/mbrtoc16.c @@ -0,0 +1,77 @@ +/*------------------------------------------------------------------------- + mbrtoc32.c - convert UTF-8 to UTF-16 + + Copyright (C) 2016, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#include +#include + +size_t mbrtoc16(char16_t *restrict pc16, const char *restrict s, size_t n, mbstate_t *restrict ps) +{ + char32_t codepoint; + size_t ret; + static mbstate_t sps; + char16_t low_surrogate; + + if(!s) + return(mbrtoc16(0, "", 1, ps)); + + if(!ps) + ps = &sps; + + if(!ps->c[0] && (ps->c[1] || ps->c[2])) + { + if(pc16) + *pc16 = ps->c[1] + (ps->c[2] << 8); + ps->c[1] = ps->c[2] = 0; + return(-3); + } + + ret = mbrtowc(&codepoint, s, n, ps); + + if(ret > MB_LEN_MAX) + return(ret); + + if (codepoint < 0xd7ff || codepoint >= 0xe000 && codepoint <= 0xffff) // Basic multilingual plane + { + if(pc16) + *pc16 = codepoint; + return(ret); + } + + codepoint -= 0x100000; + if(pc16) + *pc16 = ((codepoint >> 10) & 0x3ff) + 0xd800; + low_surrogate = (codepoint & 0x3ff) + 0xdc00; + ps->c[0] = 0; + ps->c[1] = low_surrogate & 0xff; + ps->c[2] = low_surrogate >> 8; + + return(ret); +} + diff --git a/hardware/tools/stm8/lib/src/mbrtoc32.c b/hardware/tools/stm8/lib/src/mbrtoc32.c new file mode 100644 index 0000000..6600bdd --- /dev/null +++ b/hardware/tools/stm8/lib/src/mbrtoc32.c @@ -0,0 +1,53 @@ +/*------------------------------------------------------------------------- + mbrtoc32.c - convert a multibyte sequence to a wide character + + Copyright (C) 2016, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#include +#include + +size_t mbrtoc32(char32_t *restrict pc32, const char *restrict s, size_t n, mbstate_t *restrict ps) +{ + char32_t wc; + size_t ret; + static mbstate_t sps; + + if(!ps) + ps = &sps; + + if(!pc32) + return(mbrtowc(0, s, n, ps)); + + ret = mbrtowc(&wc, s, n, ps); + + if(ret <= MB_LEN_MAX) + *pc32 = wc; + + return(ret); +} + diff --git a/hardware/tools/stm8/lib/src/mbrtowc.c b/hardware/tools/stm8/lib/src/mbrtowc.c new file mode 100644 index 0000000..da3550f --- /dev/null +++ b/hardware/tools/stm8/lib/src/mbrtowc.c @@ -0,0 +1,99 @@ +/*------------------------------------------------------------------------- + mbrtowc.c - convert a multibyte sequence to a wide character + + Copyright (C) 2016, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include +#include + +size_t mbrtowc(wchar_t *restrict pwc, const char *restrict s, size_t n, mbstate_t *restrict ps) +{ + unsigned char first_byte; + unsigned char seqlen; + char mbseq[4]; + wchar_t codepoint; + unsigned char i, j; + static mbstate_t sps; + + if(!s) + return(mbrtowc(0, "", 1, ps)); + if(!n) + goto eilseq; + if(!ps) + { + ps = &sps; + } + + for(i = 0; ps->c[i] && i < 3; i++) + mbseq[i] = ps->c[i]; + + seqlen = 1; + first_byte = ps->c[0] ? ps->c[0] : *s; + + if(first_byte & 0x80) + { + while (first_byte & (0x80 >> seqlen)) + seqlen++; + first_byte &= (0xff >> (seqlen + 1)); + } + + if(seqlen > 4) + goto eilseq; + + if(i + n < seqlen) // Incomplete multibyte character + { + for(;n-- ; i++) + ps->c[i] = *s++; + return(-2); + } + + for(j = 0; j < i; j++) + ps->c[j] = 0; + + for(n = 1, i = i ? i : 1; i < seqlen; i++, n++) + { + mbseq[i] = *s++; + if((mbseq[i] & 0xc0) != 0x80) + goto eilseq; + } + + codepoint = first_byte; + + for(s = mbseq + 1, seqlen--; seqlen; seqlen--) + { + codepoint <<= 6; + codepoint |= (*s & 0x3f); + s++; + } + + *pwc = codepoint; + return(n); + +eilseq: + errno = EILSEQ; + return(-1); +} + diff --git a/hardware/tools/stm8/lib/src/mbsinit.c b/hardware/tools/stm8/lib/src/mbsinit.c new file mode 100644 index 0000000..392cc99 --- /dev/null +++ b/hardware/tools/stm8/lib/src/mbsinit.c @@ -0,0 +1,35 @@ +/*------------------------------------------------------------------------- + mbsinit.c - determine conversion state + + Copyright (C) 2016, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +int mbsinit(const mbstate_t *ps) +{ + return(!ps || !ps->c[0] && !ps->c[1] && !ps->c[2]); +} + diff --git a/hardware/tools/stm8/lib/src/mbstowcs.c b/hardware/tools/stm8/lib/src/mbstowcs.c new file mode 100644 index 0000000..0e7ee16 --- /dev/null +++ b/hardware/tools/stm8/lib/src/mbstowcs.c @@ -0,0 +1,49 @@ +/*------------------------------------------------------------------------- + mbstowcs.c - convert a multibyte string to a wide character string + + Copyright (C) 2016, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#include + +size_t mbstowcs(wchar_t *restrict pwcs, const char *restrict s, size_t n) +{ + size_t m = 0; + while(n--) + { + int b = mbtowc(pwcs++, s, MB_LEN_MAX); + if(!b) + break; + if(b < 0) + return(-1); + s += b; + m++; + } + + return(m); +} + diff --git a/hardware/tools/stm8/lib/src/mbtowc.c b/hardware/tools/stm8/lib/src/mbtowc.c new file mode 100644 index 0000000..0b6ad5f --- /dev/null +++ b/hardware/tools/stm8/lib/src/mbtowc.c @@ -0,0 +1,69 @@ +/*------------------------------------------------------------------------- + mbtowc.c - convert a multibyte sequence to a wide character + + Copyright (C) 2016, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +int mbtowc(wchar_t *pwc, const char *restrict s, size_t n) +{ + wchar_t codepoint; + unsigned char seqlen, i; + unsigned char first_byte; + + if(!s) + return(0); + + seqlen = 1; + first_byte = *s; + + if(first_byte & 0x80) + { + while (first_byte & (0x80 >> seqlen)) + seqlen++; + first_byte &= (0xff >> (seqlen + 1)); + } + + if(n < seqlen) + return(-1); + + for(i = 1; i < seqlen; i++) + if((s[i] & 0xc0) != 0x80) + return(-1); + + codepoint = first_byte; + + for(s++, i = seqlen - 1; i; i--) + { + codepoint <<= 6; + codepoint |= (*s & 0x3f); + s++; + } + + *pwc = codepoint; + return(codepoint ? seqlen : 0); +} + diff --git a/hardware/tools/stm8/lib/src/modff.c b/hardware/tools/stm8/lib/src/modff.c new file mode 100644 index 0000000..2b0056e --- /dev/null +++ b/hardware/tools/stm8/lib/src/modff.c @@ -0,0 +1,37 @@ +/*------------------------------------------------------------------------- + modff.c - Returns both the integer and fraction of a float. + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* Version 1.0 - Initial release */ + +#include + +float modff(float x, float * y) +{ + *y=(long)x; + return (x-*y); +} diff --git a/hardware/tools/stm8/lib/src/powf.c b/hardware/tools/stm8/lib/src/powf.c new file mode 100644 index 0000000..42d8a54 --- /dev/null +++ b/hardware/tools/stm8/lib/src/powf.c @@ -0,0 +1,41 @@ +/*------------------------------------------------------------------------- + powf.c - Computes x**y where x and y are 32-bit floats. + WARNING: less that 6 digits accuracy. + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* Version 1.0 - Initial release */ + +#include +#include + +float powf(float x, float y) +{ + if(y == 0.0) return 1.0; + if(y == 1.0) return x; + if(x <= 0.0) return 0.0; + return expf(logf(x) * y); +} diff --git a/hardware/tools/stm8/lib/src/printf_fast.c b/hardware/tools/stm8/lib/src/printf_fast.c new file mode 100644 index 0000000..b20f385 --- /dev/null +++ b/hardware/tools/stm8/lib/src/printf_fast.c @@ -0,0 +1,1721 @@ +/*------------------------------------------------------------------------- + printf_fast.c - Fast printf routine for use with sdcc/mcs51 + + Copyright (C) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/******************************************************************/ +/** **/ +/** Major features. These determine what capabilities your **/ +/** compiled printf_fast will have. **/ +/** **/ +/******************************************************************/ + +// Include support for 32 bit base 10 integers (%ld and %lu). Without +// this, you won't be able to print 32 bit integers as base 10. They +// will appear in hexadecimal. +#define LONG + +// Include support for floating point numbers (%f). Don't forget to +// enable LONG above, if you want to print floats greater than +// 65535.997. You can have 6 good digits after the decimal point, +// or an 8th if a small error is ok. +/- 2^32 to 1/10^8 isn't the +// full dynamic range of 32 bit floats, but it covers the most +// commonly used range. Adds about 500-600 bytes of code. +//#define FLOAT + +// Include support for minimum field widths (%8d, %20s, %12.5f) +#define FIELD_WIDTH + +// Include fast integer conversion. Without this, a compact but slower +// algorithm is used to convert integers (%d, %u, int part of %f). +// Even the slow algorithm is much faster than a typical C implementation +// based on repetitive division by 10. If you enable this, you get an +// extremely fast version (only 8 table lookups and 8 adds to convert a +// 32 bit integer), but it costs extra code space for larger lookup +// tables and optimized non-looping code. +#define FAST_INTEGER + + +/******************************************************************/ +/** **/ +/** Minor tweaks. These provide small code savings, with **/ +/** a partial loss of functionality. **/ +/** **/ +/******************************************************************/ + + +// If you enabled FLOAT, enabling this replaces the normal %f float +// output with a very compact version that always prints 4 fractional +// digits and does not have round off. Zero will print as "0.0000", +// and 1.999997 will print as "1.9999" (not rounded up to 2). The +// 4th digit is not accurate (+/- 2). This simpler version also +// avoids using 5 bytes of internal data memory. Code size is about +// 240 bytes less. +//#define FLOAT_FIXED4 + +// If you used FLOAT (not FLOAT_FIXED4), this will remove the smart +// default number of digits code. When you use "%f" without a field +// width, normally the smart default width code chooses a good number +// of digits based on size of the number. If you enabled FIELD_WIDTH +// and use a number, like "%.5f", this smart default code is never +// used anyway. Saves about 40 bytes of code. +//#define FLOAT_DEFAULT_FRAC_DIGITS 6 + +// If you used FLOAT (not FLOAT_FIXED4) and you do not specify a +// field width, normally trailing zeros are trimmed. Using this +// removes that feature (saves only a few bytes). +//#define DO_NOT_TRIM_TRAILING_ZEROS + +// Omit saving and restoring registers when calling putchar(). If you +// are desparate for a little more code space, this will give you a +// small savings. You MUST define putchar() with #pragma callee_saves, +// or implement it in assembly and avoid changing the registers. +//#define PUTCHAR_CALLEE_SAVES + + +/* extern void putchar(char ); */ + +// Warning: using static/global variables makes these functions NON-reentrant! +// reentrant keyword is only used for parameter passing method + +static __bit long_flag, short_flag, print_zero_flag, negative_flag; + +#ifdef FIELD_WIDTH +static __bit field_width_flag; +static __bit leading_zero_flag; +static __data unsigned char field_width; +#endif + +#ifdef FLOAT +#define __SDCC_FLOAT_LIB +#include +static __bit continue_float; +#ifndef FLOAT_FIXED4 +static __data unsigned char frac_field_width; +static __data unsigned char float_frac_bcd[4]; +// TODO: can float_frac_bcd be overlaid with temps used by trig functions +#endif +#endif + +#ifndef FAST_INTEGER +#ifdef LONG +static __data unsigned int i2bcd_tmp; // slow 32 int conversion needs temp space +#endif +#endif + + +#ifndef PRINTF_FAST +#define PRINTF_FAST printf_fast +#endif + + +#if !defined(__SDCC_mcs51) || defined(__SDCC_USE_XSTACK) || defined(_SDCC_NO_ASM_LIB_FUNCS) +// Does printf_fast really work on ds390 and ds400? +// If it does, enable them in the line above +#if defined(__SDCC_USE_XSTACK) +#warning "printf_fast not built, does not support --xstack" +#elif defined(_SDCC_NO_ASM_LIB_FUNCS) +#warning "printf_fast not built, _SDCC_NO_ASM_LIB_FUNCS defined" +#endif +#else // defines are compatible with printf_fast + + +void PRINTF_FAST(__code const char *fmt, ...) __reentrant +{ + fmt; /* suppress unreferenced variable warning */ + + __asm + +printf_begin: + mov a, _bp // r0 will point to va_args (stack) + add a, #253 + mov r0, a // r0 points to MSB of fmt + mov dph, @r0 + dec r0 + mov dpl, @r0 // dptr has address of fmt + dec r0 + +printf_main_loop: + clr a + movc a, @a+dptr // get next byte of fmt string + inc dptr + //cjne a, #'%', printf_normal + cjne a, #37, printf_normal + +printf_format: + clr _long_flag + clr _short_flag + clr _print_zero_flag + clr _negative_flag +#ifdef FIELD_WIDTH + clr _field_width_flag + clr _leading_zero_flag + mov r1, #_field_width + mov @r1, #0 +#endif +#ifdef FLOAT + clr _continue_float +#endif + +printf_format_loop: + clr a + movc a, @a+dptr // get next byte of data format + inc dptr + + /* parse and consume the field width digits, even if */ + /* we don't build the code to make use of them */ + add a, #198 + jc printf_nondigit1 + add a, #10 + jnc printf_nondigit2 +#ifdef FIELD_WIDTH +printf_digit: + jnz printf_digit_2 + cjne a, _field_width, printf_digit_2 + setb _leading_zero_flag +printf_digit_2: + setb _field_width_flag + mov r2, a + mov a, @r1 + mov b, #10 + mul ab + add a, r2 + mov @r1, a +#endif + sjmp printf_format_loop +printf_nondigit1: + add a, #10 +printf_nondigit2: + add a, #48 + +printf_format_l: + //cjne a, #'l', printf_format_h + cjne a, #108, printf_format_h + setb _long_flag + sjmp printf_format_loop + +printf_format_h: + //cjne a, #'h', printf_format_s + cjne a, #104, printf_format_s + setb _short_flag + sjmp printf_format_loop + +printf_format_s: + //cjne a, #'s', printf_format_d + cjne a, #115, printf_format_d + ljmp printf_string + +printf_format_d: + //cjne a, #'d', printf_format_u + cjne a, #100, printf_format_u + lcall printf_get_int + ljmp printf_int + +printf_format_u: + //cjne a, #'u', printf_format_c + cjne a, #117, printf_format_c + lcall printf_get_int + ljmp printf_uint + +printf_format_c: + //cjne a, #'c', printf_format_x + cjne a, #99, printf_format_x + dec r0 + mov a, @r0 // Acc has the character to print + dec r0 + sjmp printf_char + +printf_format_x: + //cjne a, #'x', printf_format_f + cjne a, #120, printf_format_f + ljmp printf_hex + +printf_format_f: +#ifdef FLOAT + //cjne a, #'f', printf_format_dot + cjne a, #102, printf_format_dot + ljmp print_float +#endif + +printf_format_dot: + //cjne a, #'.', printf_normal + cjne a, #46, printf_normal +#ifdef FLOAT +#ifdef FLOAT_FIXED4 + mov r1, #ar3 // parse frac field, but discard if FIXED4 +#else + mov r1, #_frac_field_width + mov @r1, #0 +#endif +#endif + sjmp printf_format_loop + +printf_normal: + jz printf_eot +printf_char: + lcall printf_putchar + ljmp printf_main_loop + +printf_eot: + ljmp printf_end + + + /* print a string... just grab each byte with __gptrget */ + /* the user much pass a 24 bit generic pointer */ + +printf_string: + push dph // save addr in fmt onto stack + push dpl + mov b, @r0 // b has type of address (generic *) + dec r0 + mov dph, @r0 + dec r0 + mov dpl, @r0 // dptr has address of user's string + dec r0 + +#ifdef FIELD_WIDTH + jnb _field_width_flag, printf_str_loop + clr _leading_zero_flag // never leading zeros for strings + push dpl + push dph +printf_str_fw_loop: + lcall __gptrget + jz printf_str_space + inc dptr + dec _field_width + mov a, _field_width + jnz printf_str_fw_loop +printf_str_space: + lcall printf_space + pop dph + pop dpl +#endif // FIELD_WIDTH + +printf_str_loop: + lcall __gptrget + jz printf_str_done + inc dptr + lcall printf_putchar + sjmp printf_str_loop +printf_str_done: + pop dpl // restore addr withing fmt + pop dph + ljmp printf_main_loop + + + /* printing in hex is easy because sdcc pushes the LSB first */ + +printf_hex: + lcall printf_hex8 + jb _short_flag, printf_hex_end + lcall printf_hex8 + jnb _long_flag, printf_hex_end + lcall printf_hex8 + lcall printf_hex8 +printf_hex_end: + lcall printf_zero + ljmp printf_main_loop +printf_hex8: + mov a, @r0 + lcall printf_phex_msn + mov a, @r0 + dec r0 + ljmp printf_phex_lsn + + +#ifndef LONG +printf_ld_in_hex: + //mov a, #'0' + mov a, #48 + lcall printf_putchar + //mov a, #'x' + mov a, #120 + lcall printf_putchar + mov a, r0 + add a, #4 + mov r0, a + sjmp printf_hex +#endif + + + /* printing an integer is not so easy. For a signed int */ + /* check if it is negative and print the minus sign and */ + /* invert it to a positive integer */ + +printf_int: + mov a, r5 + jnb acc.7, printf_uint /* check if negative */ + setb _negative_flag + mov a, r1 /* invert integer */ + cpl a + add a, #1 + mov r1, a + jb _short_flag, printf_uint + mov a, r2 + cpl a + addc a, #0 + mov r2, a + jnb _long_flag, printf_uint + mov a, r3 + cpl a + addc a, #0 + mov r3, a + mov a, r4 + cpl a + addc a, #0 + mov r4, a + + + /* printing integers is a lot of work... because it takes so */ + /* long, the first thing to do is make sure we're doing as */ + /* little work as possible, then convert the binary int to */ + /* packed BCD, and finally print each digit of the BCD number */ + +printf_uint: + + jb _short_flag, printf_uint_ck8 + jnb _long_flag, printf_uint_ck16 +printf_uint_ck32: + /* it's a 32 bit int... but if the upper 16 bits are zero */ + /* we can treat it like a 16 bit integer and convert much faster */ +#ifdef LONG + mov a, r3 + jnz printf_uint_begin + mov a, r4 + jnz printf_uint_begin +#else + mov a, r3 + jnz printf_ld_in_hex // print long integer as hex + mov a, r4 // rather than just the low 16 bits + jnz printf_ld_in_hex +#endif + clr _long_flag +printf_uint_ck16: + /* it's a 16 bit int... but if the upper 8 bits are zero */ + /* we can treat it like a 8 bit integer and convert much faster */ + mov a, r2 + jnz printf_uint_begin + setb _short_flag +printf_uint_ck8: + /* it's an 8 bit int... if it's zero, it's a lot faster to just */ + /* print the digit zero and skip all the hard work! */ + mov a, r1 + jnz printf_uint_begin +#ifdef FLOAT + /* never use the "just print zero" shortcut if we're printing */ + /* the integer part of a float (fixes bug 1255403) */ + jb _continue_float, printf_uint_begin +#endif +#ifdef FIELD_WIDTH + jnb _field_width_flag, printf_uint_zero + mov a, _field_width + jz printf_uint_zero + dec _field_width + lcall printf_space +#endif +printf_uint_zero: + //mov a, #'0' + mov a, #48 + lcall printf_putchar + ljmp printf_main_loop + +printf_uint_begin: + push dpl + push dph + lcall printf_int2bcd // bcd number in r3/r2/r7/r6/r5 +printf_uint_2: + +#ifdef FIELD_WIDTH + jnb _field_width_flag, printf_uifw_end +#ifdef LONG +printf_uifw_32: + mov r1, #10 + jnb _long_flag, printf_uifw_16 + mov a, r3 + anl a, #0xF0 + jnz printf_uifw_sub + dec r1 + mov a, r3 + anl a, #0x0F + jnz printf_uifw_sub + dec r1 + mov a, r2 + anl a, #0xF0 + jnz printf_uifw_sub + dec r1 + mov a, r2 + anl a, #0x0F + jnz printf_uifw_sub + dec r1 + mov a, r7 + anl a, #0xF0 + jnz printf_uifw_sub +#endif // LONG +printf_uifw_16: + mov r1, #5 + jb _short_flag, printf_uifw_8 + mov a, r7 + anl a, #0x0F + jnz printf_uifw_sub + dec r1 + mov a, r6 + anl a, #0xF0 + jnz printf_uifw_sub +printf_uifw_8: + mov r1, #3 + mov a, r6 + anl a, #0x0F + jnz printf_uifw_sub + dec r1 + mov a, r5 + anl a, #0xF0 + jnz printf_uifw_sub + dec r1 +printf_uifw_sub: + //r1 has the number of digits for the number + mov a, _field_width + mov c, _negative_flag + subb a, r1 + jc printf_uifw_end + mov _field_width, a + +#ifndef PUTCHAR_CALLEE_SAVES +#ifdef LONG + push ar3 + push ar2 +#endif + push ar7 + push ar6 + push ar5 +#endif + lcall printf_space +#ifndef PUTCHAR_CALLEE_SAVES + pop ar5 + pop ar6 + pop ar7 +#ifdef LONG + pop ar2 + pop ar3 +#endif +#endif + + +printf_uifw_end: +#endif // FIELD_WIDTH + + +printf_uint_doit: + jnb _negative_flag, printf_uint_pos +#ifdef PUTCHAR_CALLEE_SAVES + //mov a, #'-' + mov a, #45 + lcall printf_putchar +#else +#ifdef LONG + push ar3 + push ar2 +#endif + push ar7 + push ar6 + push ar5 + //mov a, #'-' + mov a, #45 + lcall printf_putchar + pop ar5 + pop ar6 + pop ar7 +#ifdef LONG + pop ar2 + pop ar3 +#endif +#endif // PUTCHAR_CALLEE_SAVES + +printf_uint_pos: + jb _short_flag, printf_uint8 +#ifdef LONG + jnb _long_flag, printf_uint16 +printf_uint32: + push ar5 + push ar6 + push ar7 + mov dpl, r2 + mov a, r3 + mov dph, a + lcall printf_phex_msn + mov a, dph + lcall printf_phex_lsn + mov a, dpl + lcall printf_phex_msn + mov a, dpl + lcall printf_phex_lsn + pop acc + mov dpl, a + lcall printf_phex_msn + mov a, dpl + pop dph + pop dpl + sjmp printf_uint16a +#endif // LONG + +printf_uint16: + mov dpl, r5 + mov dph, r6 + mov a, r7 +printf_uint16a: + lcall printf_phex_lsn + mov a, dph + lcall printf_phex_msn + mov a, dph + sjmp printf_uint8a + +printf_uint8: + mov dpl, r5 + mov a, r6 +printf_uint8a: + lcall printf_phex_lsn + mov a, dpl + lcall printf_phex_msn + mov a, dpl + lcall printf_phex_lsn + lcall printf_zero + pop dph + pop dpl +#ifdef FLOAT + jnb _continue_float, 0002$ + ret +0002$: +#endif + ljmp printf_main_loop + + +#ifdef FLOAT +#ifdef FLOAT_FIXED4 + // Print a float the easy way. First, extract the integer part and + // use the integer printing code. Then extract the fractional part, + // convert each bit to 4 digit BCD, and print the BCD sum. Absolutely + // no field width control, always 4 digits printed past the decimal + // point. No round off. 1.9999987 prints as 1.9999, not 2.0000. +print_float: +#ifdef FIELD_WIDTH + jnb _field_width_flag, print_float_begin + mov a, _field_width + add a, #251 + mov _field_width, a + jc print_float_begin + mov _field_width, #0 +#endif +print_float_begin: + push ar0 // keep r0 safe, will need it again + lcall printf_get_float + clr c + mov a, #158 // check for large float we can't print + subb a, r7 + jnc print_float_size_ok +printf_float_too_big: + // TODO: should print some sort of overflow error?? + pop ar0 + ljmp printf_format_loop +print_float_size_ok: + push dpl + lcall fs_rshift_a + pop dpl + setb _continue_float +#ifndef LONG + mov a, r3 + orl a, r4 + jnz printf_float_too_big +#endif + lcall printf_uint // print the integer portion + //mov a, #'.' + mov a, #0x2E + lcall printf_putchar + // now that the integer part is printed, we need to refetch the + // float from the va_args and extract the fractional part + pop ar0 + lcall printf_get_float + push ar0 + push dpl + push dph + mov a, r7 + cjne a, #126, print_float_frac_lshift + sjmp print_float_frac // input between 0.5 to 0.9999 +print_float_frac_lshift: + jc print_float_frac_rshift + //Acc (exponent) is greater than 126 (input >= 1.0) + add a, #130 + mov r5, a +print_float_lshift_loop: + clr c + mov a, r2 + rlc a + mov r2, a + mov a, r3 + rlc a + mov r3, a + mov a, r4 + rlc a + mov r4, a + djnz r5, print_float_lshift_loop + sjmp print_float_frac +print_float_frac_rshift: + //Acc (exponent) is less than 126 (input < 0.5) + cpl a + add a, #127 + lcall fs_rshift_a +print_float_frac: + // now we've got the fractional part, so now is the time to + // convert to BCD... just convert each bit to BCD using a + // lookup table and BCD sum them together + mov r7, #14 + clr a + mov r6, a + mov r5, a + mov dptr, #_frac2bcd // FLOAT_FIXED4 version (14 entries) +print_float_frac_loop: + mov a, r3 + rlc a + mov r3, a + mov a, r4 + rlc a + mov r4, a + jnc print_float_frac_skip + clr a + movc a, @a+dptr + add a, r5 + da a + mov r5, a + mov a, #1 + movc a, @a+dptr + addc a, r6 + da a + mov r6, a +print_float_frac_skip: + inc dptr + inc dptr + djnz r7, print_float_frac_loop + // the BCD sum is in dptr, so all we've got to do is output + // all 4 digits. No trailing zero suppression, no nice round + // off (impossible to change the integer part since we already + // printed it). + mov dph, r6 + mov dpl, r5 + setb _print_zero_flag + mov a, dph + lcall printf_phex_msn + mov a, dph + lcall printf_phex_lsn + mov a, dpl + lcall printf_phex_msn + mov a, dpl + lcall printf_phex_lsn + pop dph + pop dpl + pop ar0 + ljmp printf_main_loop + +#else // not FLOAT_FIXED4 + + +print_float: + // Print a float the not-as-easy way, with a configurable number of + // fractional digits (up to 8) and proper round-off (up to 7 digits). + // First, extract the fractional part, convert to BCD, and then add + // the scaled round-off. Store the rounded fractional digits and + // their carry. Then extract the integer portion, increment it if + // the rounding caused a carry. Use the integer printing to output + // the integer, and then output the stored fractional digits. This + // approach requires 5 bytes of internal RAM to store the 8 fractional + // digits and the number of them we'll actually print. This code is + // a couple hundred bytes larger and a bit slower than the FIXED4 + // version, but it gives very nice results. +print_float_1: +#ifdef FIELD_WIDTH + jnb _field_width_flag, print_float_default_width + // The caller specified exact field width, so use it. Need to + // convert the whole float digits into the integer portion only. + mov a, _field_width + setb c + subb a, _frac_field_width + mov _field_width, a + jnc print_float_begin + mov _field_width, #0 + sjmp print_float_begin +#endif +print_float_default_width: + // The caller didn't specify field width (or FIELD_WIDTH is + // not defined so it's ignored). We've still got to know + // how many fractional digits are going to print, so we can + // round off properly. +#ifdef FLOAT_DEFAULT_FRAC_DIGITS + mov _frac_field_width, #FLOAT_DEFAULT_FRAC_DIGITS +#else + // default fractional field width (between 0 to 7) + // attempt to scale the default number of fractional digits + // based on the magnitude of the float + mov a, @r0 + anl a, #0x7F // ignore sign bit + mov r2, a // r2 is first byte of float + dec r0 + mov ar3, @r0 // r3 is second byte of float + inc r0 + mov r6, dpl + mov r7, dph + mov dptr, #_float_range_table + mov r5, #7 +print_float_default_loop: + clr a + movc a, @a+dptr + add a, r3 + inc dptr + clr a + movc a, @a+dptr + addc a, r2 + jnc print_float_default_done + inc dptr + djnz r5, print_float_default_loop +print_float_default_done: + mov _frac_field_width, r5 + mov dpl, r6 + mov dph, r7 +#endif // not FLOAT_DEFAULT_FRAC_DIGITS + +print_float_begin: + push ar0 // keep r0 safe, will need it again + lcall printf_get_float + push dpl + push dph + mov a, r7 + cjne a, #126, print_float_frac_lshift + sjmp print_float_frac // input between 0.5 to 0.9999 + +print_float_frac_lshift: + jc print_float_frac_rshift + //Acc (exponent) is greater than 126 (input >= 1.0) + add a, #130 + mov r5, a +print_float_lshift_loop: + clr c + mov a, r2 + rlc a + mov r2, a + mov a, r3 + rlc a + mov r3, a + mov a, r4 + rlc a + mov r4, a + djnz r5, print_float_lshift_loop + sjmp print_float_frac +print_float_frac_rshift: + //Acc (exponent) is less than 126 (input < 0.5) + cpl a + add a, #127 + lcall fs_rshift_a +print_float_frac: + // Convert the fraction in r4/r3/r2/r1 into 8 BCD digits in r0/r7/r6/r5 + mov b, #27 + clr a + mov r0, a + mov r7, a + mov r6, a + mov r5, a + mov dptr, #_frac2bcd // FLOAT version (27 entries) +print_float_frac_loop: + mov a, r1 + rlc a + mov r1, a + mov a, r2 + rlc a + mov r2, a + mov a, r3 + rlc a + mov r3, a + mov a, r4 + rlc a + mov r4, a + jnc print_float_frac_skip + clr a + movc a, @a+dptr + add a, r5 + da a + mov r5, a + mov a, #1 + movc a, @a+dptr + addc a, r6 + da a + mov r6, a + mov a, #2 + movc a, @a+dptr + addc a, r7 + da a + mov r7, a + mov a, #3 + movc a, @a+dptr + addc a, r0 + da a + mov r0, a +print_float_frac_skip: + inc dptr + inc dptr + inc dptr + inc dptr + djnz b, print_float_frac_loop +print_float_frac_roundoff: + // Now it's time to round-off the BCD digits to the desired precision. + clr a + mov r4, #0x50 // r4/r3/r2/r1 = 0.5 (bcd rounding) + mov r3, a + mov r2, a + mov r1, a + mov a, _frac_field_width + rl a + rl a + anl a, #0xFC + mov dph, r0 // fs_rshift_a will overwrite r0 & dpl + lcall fs_rshift_a // divide r4/r3/r2/r1 by 10^frac_field_width + mov a, r5 + add a, r1 // add rounding to fractional part + da a + mov _float_frac_bcd+3, a // and store it for later use + mov a, r6 + addc a, r2 + da a + mov _float_frac_bcd+2, a + mov a, r7 + addc a, r3 + da a + mov _float_frac_bcd+1, a + mov a, dph + addc a, r4 + da a + mov _float_frac_bcd+0, a + mov sign_b, c // keep fractional carry in sign_b + pop dph + pop dpl +print_float_int: + // Time to work on the integer portion... fetch the float again, check + // size (exponent), scale to integer, add the fraction's carry, and + // let the integer printing code do all the work. + pop ar0 + lcall printf_get_float + push ar0 + clr c + mov a, #158 // check for large float we can't print + subb a, r7 + jnc print_float_size_ok +printf_float_too_big: + // TODO: should print some sort of overflow error?? + pop ar0 + ljmp printf_format_loop +print_float_size_ok: + push dpl + lcall fs_rshift_a + pop dpl + jnb sign_b, print_float_do_int + // if we get here, the fractional round off caused the + // integer part to increment. Add 1 for a proper result + mov a, r1 + add a, #1 + mov r1, a + clr a + addc a, r2 + mov r2, a +#ifdef LONG + clr a + addc a, r3 + mov r3, a + clr a + addc a, r4 + mov r4, a +#endif + jc printf_float_too_big +print_float_do_int: +#ifndef LONG + mov a, r3 + orl a, r4 + jnz printf_float_too_big +#endif + setb _continue_float + lcall printf_uint // print the integer portion + + +print_float_frac_width: + // Now all we have to do is output the fractional digits that + // were previous computed and stored in memory. +#ifdef FIELD_WIDTH + jb _field_width_flag, print_float_do_frac +#endif +#ifndef DO_NOT_TRIM_TRAILING_ZEROS + // if the user did not explicitly set a + // field width, trim off trailing zeros +print_float_frac_trim: + mov a, _frac_field_width + jz print_float_do_frac + lcall get_float_frac_digit + jnz print_float_do_frac + djnz _frac_field_width, print_float_frac_trim +#endif + +print_float_do_frac: + mov a, _frac_field_width + jz print_float_done + //mov a, #'.' + mov a, #0x2E + lcall printf_putchar + mov r0, #0 + setb _print_zero_flag +print_float_do_frac_loop: + inc r0 + mov a, r0 + lcall get_float_frac_digit + lcall printf_phex_lsn + mov a, r0 + cjne a, _frac_field_width, print_float_do_frac_loop + +print_float_done: + pop ar0 + ljmp printf_main_loop + + + // acc=1 for tenths, acc=2 for hundredths, etc +get_float_frac_digit: + dec a + clr c + rrc a + mov psw.5, c + add a, #_float_frac_bcd + mov r1, a + mov a, @r1 + jb psw.5, get_float_frac_digit_done + swap a +get_float_frac_digit_done: + anl a, #15 + ret + +#endif // end of normal FLOAT code (not FLOAT_FIXED4) + + +// These helper functions are used, regardless of which type of +// FLOAT code is used. + +#if 0 +pm2_print_float: + mov a, r7 + lcall pm2_entry_phex + mov a, #0x20 + lcall pm2_entry_cout + lcall _print_r4321 + mov a, #0x20 + lcall pm2_entry_cout + ret +#endif + + // Fetch a float from the va_args and put it into + // r7(exp) r4/r3/r2(mant) and also clear r1 and preset + // the flags +printf_get_float: + mov a, @r0 + dec r0 + mov r1, a + mov a, @r0 + dec r0 + mov r4, a + rlc a + mov a, r1 + rlc a + mov _negative_flag, c + mov r7, a + jz printf_get_float_2 + orl ar4, #0x80 +printf_get_float_2: + mov a, @r0 + dec r0 + mov r3, a + mov a, @r0 + dec r0 + mov r2, a + mov r1, #0 + clr _short_flag + setb _long_flag + ret +#endif // FLOAT + + + /* read an integer into r1/r2/r3/r4, and msb into r5 */ +printf_get_int: + mov a, @r0 + mov r1, a + mov r5, a + dec r0 + jb _short_flag, printf_get_done + mov r2, ar1 + mov a, @r0 + mov r1, a + dec r0 + jnb _long_flag, printf_get_done + mov r4, ar2 + mov r3, ar1 + mov a, @r0 + mov r2, a + dec r0 + mov a, @r0 + mov r1, a + dec r0 +printf_get_done: + ret + + +#ifdef FAST_INTEGER + + /* convert binary number in r4/r3/r2/r1 into bcd packed number + * in r3/r2/r7/r6/r5. The input number is destroyed in the + * process, to avoid needing extra memory for the result (and + * r1 gets used for temporary storage). dptr is overwritten, + * but r0 is not changed. + */ + +printf_int2bcd: + mov a, r1 + mov b, #100 + div ab + mov r6, a + mov a, #10 + xch a, b + div ab + swap a + orl a, b + mov r5, a + + jnb _short_flag, printf_i2bcd_16 // if 8 bit int, we're done + ret + +printf_i2bcd_16: + mov a, r2 + anl a, #0x0F + mov r1, a + mov dptr, #_int2bcd_2 + movc a, @a+dptr + add a, r5 + da a + mov r5, a + mov a, r1 + orl a, #16 + movc a, @a+dptr + addc a, r6 + da a + mov r6, a + + mov a, r2 + swap a + anl a, #0x0F + mov r1, a + mov dptr, #_int2bcd_3 + movc a, @a+dptr + add a, r5 + da a + mov r5, a + mov a, r1 + orl a, #16 + movc a, @a+dptr + addc a, r6 + da a + mov r6, a + mov a, r1 + orl a, #32 + movc a, @a+dptr + addc a, #0 + da a + mov r7, a + + jb _long_flag, printf_i2bcd_32 // if 16 bit int, we're done + ret + +printf_i2bcd_32: + +#ifdef LONG + mov a, r3 + anl a, #0x0F + mov r1, a + mov dptr, #_int2bcd_4 + movc a, @a+dptr + add a, r5 + da a + mov r5, a + mov a, r1 + orl a, #16 + movc a, @a+dptr + addc a, r6 + da a + mov r6, a + mov a, r1 + orl a, #32 + movc a, @a+dptr + addc a, r7 + da a + mov r7, a + clr a + addc a, #0 + mov r2, a + + mov a, r3 + swap a + anl a, #0x0F + mov r1, a + mov dptr, #_int2bcd_5 + movc a, @a+dptr + add a, r5 + da a + mov r5, a + mov a, r1 + orl a, #16 + movc a, @a+dptr + addc a, r6 + da a + mov r6, a + mov a, r1 + orl a, #32 + movc a, @a+dptr + addc a, r7 + da a + mov r7, a + mov a, r1 + orl a, #48 + movc a, @a+dptr + addc a, r2 + da a + mov r2, a + + mov a, r4 + anl a, #0x0F + mov r1, a + mov dptr, #_int2bcd_6 + mov r3, #0 + lcall printf_bcd_add10 // saves 27 bytes, costs 5 cycles + + mov a, r4 + swap a + anl a, #0x0F + mov r1, a + mov dptr, #_int2bcd_7 +printf_bcd_add10: + movc a, @a+dptr + add a, r5 + da a + mov r5, a + mov a, r1 + orl a, #16 + movc a, @a+dptr + addc a, r6 + da a + mov r6, a + mov a, r1 + orl a, #32 + movc a, @a+dptr + addc a, r7 + da a + mov r7, a + mov a, r1 + orl a, #48 + movc a, @a+dptr + addc a, r2 + da a + mov r2, a + mov a, r1 + orl a, #64 + movc a, @a+dptr + addc a, r3 + da a + mov r3, a +#endif // LONG + ret + + +#else // not FAST_INTEGER + + /* convert binary number in r4/r3/r2/r1 into bcd packed number + * in r3/r2/r7/r6/r5. The input number is destroyed in the + * process, to avoid needing extra memory for the result (and + * r1 gets used for temporary storage). dptr is overwritten, + * but r0 is not changed. + */ + +#ifdef LONG + +printf_int2bcd: + mov a, #8 + jb _short_flag, printf_int2bcd_begin + mov a, #16 + jnb _long_flag, printf_int2bcd_begin + mov a, #32 +printf_int2bcd_begin: + mov b, a + clr a + mov r5, a + mov r6, a + mov r7, a + mov (_i2bcd_tmp + 0), a + mov (_i2bcd_tmp + 1), a + mov dptr, #_int2bcd +printf_i2bcd_loop: + mov a, r4 + rrc a + mov r4, a + mov a, r3 + rrc a + mov r3, a + mov a, r2 + rrc a + mov r2, a + mov a, r1 + rrc a + mov r1, a + jnc print_i2bcd_skip + clr a + movc a, @a+dptr + add a, r5 + da a + mov r5, a + mov a, #1 + movc a, @a+dptr + addc a, r6 + da a + mov r6, a + mov a, #2 + movc a, @a+dptr + addc a, r7 + da a + mov r7, a + mov a, #3 + movc a, @a+dptr + addc a, (_i2bcd_tmp + 0) + da a + mov (_i2bcd_tmp + 0), a + mov a, #4 + movc a, @a+dptr + addc a, (_i2bcd_tmp + 1) + da a + mov (_i2bcd_tmp + 1), a +print_i2bcd_skip: + inc dptr + inc dptr + inc dptr + inc dptr + inc dptr + djnz b, printf_i2bcd_loop + mov r2, (_i2bcd_tmp + 0) + mov r3, (_i2bcd_tmp + 1) + ret + +#else // not LONG + +printf_int2bcd: + mov a, #8 + jb _short_flag, printf_int2bcd_begin + mov a, #16 +printf_int2bcd_begin: + mov b, a + clr a + mov r5, a + mov r6, a + mov r7, a + mov dptr, #_int2bcd +printf_i2bcd_loop: + mov a, r2 + rrc a + mov r2, a + mov a, r1 + rrc a + mov r1, a + jnc printf_i2bcd_add_skip + clr a + movc a, @a+dptr + add a, r5 + da a + mov r5, a + mov a, #1 + movc a, @a+dptr + addc a, r6 + da a + mov r6, a + mov a, #2 + movc a, @a+dptr + addc a, r7 + da a + mov r7, a +printf_i2bcd_add_skip: + inc dptr + inc dptr + inc dptr + djnz b, printf_i2bcd_loop + ret + +#endif // not LONG + + +#endif // not FAST_INTEGER + + +#ifdef FIELD_WIDTH +printf_space_loop: + //mov a, #' ' + mov a, #32 + jnb _leading_zero_flag, printf_space_output + //mov a, #'0' + mov a, #48 +printf_space_output: + lcall printf_putchar + dec _field_width +printf_space: + mov a, _field_width + jnz printf_space_loop + ret +#endif + + /* print a hex digit, either upper 4 bit (msn) or lower 4 bits (lsn) */ + +printf_phex_msn: + swap a +printf_phex_lsn: + anl a, #15 + jnz printf_phex_ok + jnb _print_zero_flag, printf_ret +printf_phex_ok: + setb _print_zero_flag + add a, #0x90 + da a + addc a, #0x40 + da a +printf_putchar: +#ifdef PUTCHAR_CALLEE_SAVES + push dph + push dpl + mov dpl, a + lcall _putchar + pop dpl + pop dph +#else + push dph + push dpl + push ar0 + mov dpl, a + lcall _putchar + pop ar0 + pop dpl + pop dph +#endif +printf_ret: + ret + + /* print a zero if all the calls to print the digits ended up */ + /* being leading zeros */ + +printf_zero: + jb _print_zero_flag, printf_ret + //mov a, #'0' + mov a, #48 + ljmp printf_putchar + +printf_end: + __endasm; +} + + +#ifdef FAST_INTEGER +/* + * #! /usr/bin/perl + * for ($d=0; $d < 8; $d++) { + * $n = 16 ** $d; + * for ($p=0; $p < 5; $p++) { + * last unless (((16 ** $d) * 15) / (10 ** ($p * 2))) % 100; + * printf "code unsigned char int2bcd_%d_%d[15] = {", $d, $p; + * for ($i=0; $i < 16; $i++) { + * printf "0x%02d", + * (((16 ** $d) * $i) / (10 ** ($p * 2))) % 100; + * print ", " if $i < 15; + * } + * print "};\n"; + * } + * } + */ + +#if 0 +static __code unsigned char int2bcd_0[] = { +0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, +0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15}; + +static __code unsigned char int2bcd_1[] = { +0x00, 0x16, 0x32, 0x48, 0x64, 0x80, 0x96, 0x12, +0x28, 0x44, 0x60, 0x76, 0x92, 0x08, 0x24, 0x40, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02}; +#endif + +static __code unsigned char int2bcd_2[] = { +0x00, 0x56, 0x12, 0x68, 0x24, 0x80, 0x36, 0x92, +0x48, 0x04, 0x60, 0x16, 0x72, 0x28, 0x84, 0x40, +0x00, 0x02, 0x05, 0x07, 0x10, 0x12, 0x15, 0x17, +0x20, 0x23, 0x25, 0x28, 0x30, 0x33, 0x35, 0x38}; + +static __code unsigned char int2bcd_3[] = { +0x00, 0x96, 0x92, 0x88, 0x84, 0x80, 0x76, 0x72, +0x68, 0x64, 0x60, 0x56, 0x52, 0x48, 0x44, 0x40, +0x00, 0x40, 0x81, 0x22, 0x63, 0x04, 0x45, 0x86, +0x27, 0x68, 0x09, 0x50, 0x91, 0x32, 0x73, 0x14, +0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x02, +0x03, 0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x06}; + +#ifdef LONG +static __code unsigned char int2bcd_4[] = { +0x00, 0x36, 0x72, 0x08, 0x44, 0x80, 0x16, 0x52, +0x88, 0x24, 0x60, 0x96, 0x32, 0x68, 0x04, 0x40, +0x00, 0x55, 0x10, 0x66, 0x21, 0x76, 0x32, 0x87, +0x42, 0x98, 0x53, 0x08, 0x64, 0x19, 0x75, 0x30, +0x00, 0x06, 0x13, 0x19, 0x26, 0x32, 0x39, 0x45, +0x52, 0x58, 0x65, 0x72, 0x78, 0x85, 0x91, 0x98}; + +static __code unsigned char int2bcd_5[] = { +0x00, 0x76, 0x52, 0x28, 0x04, 0x80, 0x56, 0x32, +0x08, 0x84, 0x60, 0x36, 0x12, 0x88, 0x64, 0x40, +0x00, 0x85, 0x71, 0x57, 0x43, 0x28, 0x14, 0x00, +0x86, 0x71, 0x57, 0x43, 0x29, 0x14, 0x00, 0x86, +0x00, 0x04, 0x09, 0x14, 0x19, 0x24, 0x29, 0x34, +0x38, 0x43, 0x48, 0x53, 0x58, 0x63, 0x68, 0x72, +0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, +0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15}; + +static __code unsigned char int2bcd_6[] = { +0x00, 0x16, 0x32, 0x48, 0x64, 0x80, 0x96, 0x12, +0x28, 0x44, 0x60, 0x76, 0x92, 0x08, 0x24, 0x40, +0x00, 0x72, 0x44, 0x16, 0x88, 0x60, 0x32, 0x05, +0x77, 0x49, 0x21, 0x93, 0x65, 0x38, 0x10, 0x82, +0x00, 0x77, 0x55, 0x33, 0x10, 0x88, 0x66, 0x44, +0x21, 0x99, 0x77, 0x54, 0x32, 0x10, 0x88, 0x65, +0x00, 0x16, 0x33, 0x50, 0x67, 0x83, 0x00, 0x17, +0x34, 0x50, 0x67, 0x84, 0x01, 0x18, 0x34, 0x51, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02}; + +static __code unsigned char int2bcd_7[] = { +0x00, 0x56, 0x12, 0x68, 0x24, 0x80, 0x36, 0x92, +0x48, 0x04, 0x60, 0x16, 0x72, 0x28, 0x84, 0x40, +0x00, 0x54, 0x09, 0x63, 0x18, 0x72, 0x27, 0x81, +0x36, 0x91, 0x45, 0x00, 0x54, 0x09, 0x63, 0x18, +0x00, 0x43, 0x87, 0x30, 0x74, 0x17, 0x61, 0x04, +0x48, 0x91, 0x35, 0x79, 0x22, 0x66, 0x09, 0x53, +0x00, 0x68, 0x36, 0x05, 0x73, 0x42, 0x10, 0x79, +0x47, 0x15, 0x84, 0x52, 0x21, 0x89, 0x58, 0x26, +0x00, 0x02, 0x05, 0x08, 0x10, 0x13, 0x16, 0x18, +0x21, 0x24, 0x26, 0x29, 0x32, 0x34, 0x37, 0x40}; +#endif // LONG + +#else // not FAST_INTEGER + +/* + * #! /usr/bin/perl + * print "__code unsigned char int2bcd[] = {\n"; + * for ($i=0, $n=1; $i<32; $i++, $n*=2) { + * $r = sprintf "%010u", $n; + * $r =~ /([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])/; + * printf "0x%02d, 0x%02d, 0x%02d, 0x%02d, 0x%02d", $5, $4, $3, $2, $1; + * print ',' if $i < 31; + * printf "\t\t// %10u\n", $n; + * } + * print "}\n__code unsigned char int2bcd[] = {\n"; + * for ($i=0, $n=1; $i<16; $i++, $n*=2) { + * $r = sprintf "%06u", $n; + * $r =~ /([0-9][0-9])([0-9][0-9])([0-9][0-9])/; + * printf "0x%02d, 0x%02d, 0x%02d", $3, $2, $1; + * print ',' if $i < 15; + * printf "\t\t// %10u\n", $n; + * } + * print "};\n"; +*/ + +#ifdef LONG +static __code unsigned char int2bcd[] = { +0x01, 0x00, 0x00, 0x00, 0x00, // 1 +0x02, 0x00, 0x00, 0x00, 0x00, // 2 +0x04, 0x00, 0x00, 0x00, 0x00, // 4 +0x08, 0x00, 0x00, 0x00, 0x00, // 8 +0x16, 0x00, 0x00, 0x00, 0x00, // 16 +0x32, 0x00, 0x00, 0x00, 0x00, // 32 +0x64, 0x00, 0x00, 0x00, 0x00, // 64 +0x28, 0x01, 0x00, 0x00, 0x00, // 128 +0x56, 0x02, 0x00, 0x00, 0x00, // 256 +0x12, 0x05, 0x00, 0x00, 0x00, // 512 +0x24, 0x10, 0x00, 0x00, 0x00, // 1024 +0x48, 0x20, 0x00, 0x00, 0x00, // 2048 +0x96, 0x40, 0x00, 0x00, 0x00, // 4096 +0x92, 0x81, 0x00, 0x00, 0x00, // 8192 +0x84, 0x63, 0x01, 0x00, 0x00, // 16384 +0x68, 0x27, 0x03, 0x00, 0x00, // 32768 +0x36, 0x55, 0x06, 0x00, 0x00, // 65536 +0x72, 0x10, 0x13, 0x00, 0x00, // 131072 +0x44, 0x21, 0x26, 0x00, 0x00, // 262144 +0x88, 0x42, 0x52, 0x00, 0x00, // 524288 +0x76, 0x85, 0x04, 0x01, 0x00, // 1048576 +0x52, 0x71, 0x09, 0x02, 0x00, // 2097152 +0x04, 0x43, 0x19, 0x04, 0x00, // 4194304 +0x08, 0x86, 0x38, 0x08, 0x00, // 8388608 +0x16, 0x72, 0x77, 0x16, 0x00, // 16777216 +0x32, 0x44, 0x55, 0x33, 0x00, // 33554432 +0x64, 0x88, 0x10, 0x67, 0x00, // 67108864 +0x28, 0x77, 0x21, 0x34, 0x01, // 134217728 +0x56, 0x54, 0x43, 0x68, 0x02, // 268435456 +0x12, 0x09, 0x87, 0x36, 0x05, // 536870912 +0x24, 0x18, 0x74, 0x73, 0x10, // 1073741824 +0x48, 0x36, 0x48, 0x47, 0x21 // 2147483648 +}; +#else // not LONG +static __code unsigned char int2bcd[] = { +0x01, 0x00, 0x00, // 1 +0x02, 0x00, 0x00, // 2 +0x04, 0x00, 0x00, // 4 +0x08, 0x00, 0x00, // 8 +0x16, 0x00, 0x00, // 16 +0x32, 0x00, 0x00, // 32 +0x64, 0x00, 0x00, // 64 +0x28, 0x01, 0x00, // 128 +0x56, 0x02, 0x00, // 256 +0x12, 0x05, 0x00, // 512 +0x24, 0x10, 0x00, // 1024 +0x48, 0x20, 0x00, // 2048 +0x96, 0x40, 0x00, // 4096 +0x92, 0x81, 0x00, // 8192 +0x84, 0x63, 0x01, // 16384 +0x68, 0x27, 0x03 // 32768 +}; +#endif // not LONG + +#endif // not FAST_INTEGER + + +#ifdef FLOAT +#ifndef FLOAT_FIXED4 + +/* + * #! /usr/bin/perl + * for ($i=0, $f=0.5; $i<24; $i++) { + * $r = sprintf "%.8f", $f; + * $r =~ /0\.([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])/; + * printf "0x%02d, 0x%02d, 0x%02d, 0x%02d", $4, $3, $2, $1; + * print ',' if $i < 23; + * $sum += $r; + * printf "\t\t// %.15f %.8f\n", $f, $sum; + * $f /= 2; + * } + */ + +static __code unsigned char frac2bcd[] = { +0x00, 0x00, 0x00, 0x50, // 0.500000000000000 0.50000000 +0x00, 0x00, 0x00, 0x25, // 0.250000000000000 0.75000000 +0x00, 0x00, 0x50, 0x12, // 0.125000000000000 0.87500000 +0x00, 0x00, 0x25, 0x06, // 0.062500000000000 0.93750000 +0x00, 0x50, 0x12, 0x03, // 0.031250000000000 0.96875000 +0x00, 0x25, 0x56, 0x01, // 0.015625000000000 0.98437500 +0x50, 0x12, 0x78, 0x00, // 0.007812500000000 0.99218750 +0x25, 0x06, 0x39, 0x00, // 0.003906250000000 0.99609375 +0x12, 0x53, 0x19, 0x00, // 0.001953125000000 0.99804687 +0x56, 0x76, 0x09, 0x00, // 0.000976562500000 0.99902343 +0x28, 0x88, 0x04, 0x00, // 0.000488281250000 0.99951171 +0x14, 0x44, 0x02, 0x00, // 0.000244140625000 0.99975585 +0x07, 0x22, 0x01, 0x00, // 0.000122070312500 0.99987792 +0x04, 0x61, 0x00, 0x00, // 0.000061035156250 0.99993896 +0x52, 0x30, 0x00, 0x00, // 0.000030517578125 0.99996948 +0x26, 0x15, 0x00, 0x00, // 0.000015258789062 0.99998474 +0x63, 0x07, 0x00, 0x00, // 0.000007629394531 0.99999237 +0x81, 0x03, 0x00, 0x00, // 0.000003814697266 0.99999618 +0x91, 0x01, 0x00, 0x00, // 0.000001907348633 0.99999809 +0x95, 0x00, 0x00, 0x00, // 0.000000953674316 0.99999904 +0x48, 0x00, 0x00, 0x00, // 0.000000476837158 0.99999952 +0x24, 0x00, 0x00, 0x00, // 0.000000238418579 0.99999976 +0x12, 0x00, 0x00, 0x00, // 0.000000119209290 0.99999988 +0x06, 0x00, 0x00, 0x00, // 0.000000059604645 0.99999994 +0x03, 0x00, 0x00, 0x00, // 0.000000029802322 0.99999997 +0x01, 0x00, 0x00, 0x00, // 0.000000014901161 0.99999998 +0x01, 0x00, 0x00, 0x00 // 0.000000007450581 0.99999999 +}; + +#ifndef FLOAT_DEFAULT_FRAC_DIGITS +// TODO: Perhaps these should be tweaked a bit to take round up +// effects into account... or maybe give more default digits?? +// Range #digits +// 0.0001 - 0.0009999 7 +// 0.001 - 0.009999 6 0.001 = 0x3A83126F 3A83 +// 0.01 - 0.09999 5 0.01 = 0x3C23D70A 3C23 +// 0.1 - 9.9999 4 0.1 = 0x3DCCCCCD, 3DCC +// 10.0 - 99.99 3 10.0 = 0x41200000 4120 +// 100.0 - 999.99 2 100.0 = 0x42C80000 42C8 +// 1000 - 9999.9 1 1000 = 0x447A0000 447A +// 10000+ 0 10000 = 0x461C4000 461C +static __code unsigned int float_range_table[] = { +65536 - 0x3A83, +65536 - 0x3C23, +65536 - 0x3DCC, +65536 - 0x4120, +65536 - 0x42C8, +65536 - 0x447A, +65536 - 0x461C +}; +#endif + +#else // using FLOAT_FIXED4 + +/* +* #! /usr/bin/perl +* for ($i=0, $f=0.5; $i<14; $i++) { +* $r = sprintf "%.4f", $f; +* $r =~ /0\.([0-9][0-9])([0-9][0-9])/; +* printf "0x%02d, 0x%02d", $2, $1; +* print ',' if $i < 13; +* $sum += $r; +* printf "\t\t// %.15f %.4f\n", $f, $sum; +* $f /= 2; +* } +*/ + +static __code unsigned char frac2bcd[] = { +0x00, 0x50, // 0.500000000000000 0.5000 +0x00, 0x25, // 0.250000000000000 0.7500 +0x50, 0x12, // 0.125000000000000 0.8750 +0x25, 0x06, // 0.062500000000000 0.9375 +0x12, 0x03, // 0.031250000000000 0.9687 +0x56, 0x01, // 0.015625000000000 0.9843 +0x78, 0x00, // 0.007812500000000 0.9921 +0x39, 0x00, // 0.003906250000000 0.9960 +0x20, 0x00, // 0.001953125000000 0.9980 +0x10, 0x00, // 0.000976562500000 0.9990 +0x05, 0x00, // 0.000488281250000 0.9995 +0x02, 0x00, // 0.000244140625000 0.9997 +0x01, 0x00, // 0.000122070312500 0.9998 +0x01, 0x00 // 0.000061035156250 0.9999 +}; + +#endif // FLOAT_FIXED4 +#endif // FLOAT + + +#endif // defines compatible with printf_fast diff --git a/hardware/tools/stm8/lib/src/printf_fast_f.c b/hardware/tools/stm8/lib/src/printf_fast_f.c new file mode 100644 index 0000000..c08d75d --- /dev/null +++ b/hardware/tools/stm8/lib/src/printf_fast_f.c @@ -0,0 +1,39 @@ +/*------------------------------------------------------------------------- + printf_fast_f.c - Same as printf_fast, but with floating point enabled + + Copyright (C) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#define __SDCC_FLOAT_LIB +#include + +#ifdef FLOAT_ASM_MCS51 + +#define FLOAT +#define PRINTF_FAST printf_fast_f + +#include "printf_fast.c" + +#endif diff --git a/hardware/tools/stm8/lib/src/printf_large.c b/hardware/tools/stm8/lib/src/printf_large.c new file mode 100644 index 0000000..96a4799 --- /dev/null +++ b/hardware/tools/stm8/lib/src/printf_large.c @@ -0,0 +1,875 @@ +/*----------------------------------------------------------------- + printf_large.c - formatted output conversion + + Copyright (C) 1999, Martijn van Balen + Added %f By - (2000) + Refactored by - Maarten Brock (2004) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#if defined (__SDCC_ds390) || defined (__SDCC_USE_XSTACK) || defined (__SDCC_MODEL_HUGE) +#define USE_FLOATS 1 +#endif + +#include +#include +#include +#include +#include +#include + +#define PTR value.ptr + +#ifdef __SDCC_ds390 +#define NULL_STRING "" +#define NULL_STRING_LENGTH 6 +#endif + +#if defined (__SDCC_mcs51) && defined (__SDCC_MODEL_SMALL) && !defined (__SDCC_STACK_AUTO) +# define MEM_SPACE_BUF __idata +# define MEM_SPACE_BUF_PP __idata +#else +# define MEM_SPACE_BUF +# define MEM_SPACE_BUF_PP _AUTOMEM +#endif + +/****************************************************************************/ + +//typedef const char * ptr_t; +#define ptr_t const char * + +#ifdef toupper +#undef toupper +#endif +#ifdef tolower +#undef tolower +#endif +#ifdef islower +#undef islower +#endif +#ifdef isdigit +#undef isdigit +#endif + +//#define toupper(c) ((c)&=~0x20) +#define toupper(c) ((c)&=0xDF) +#define tolower(c) ((c)|=0x20) +#define islower(c) ((unsigned char)c >= (unsigned char)'a' && (unsigned char)c <= (unsigned char)'z') +#define isdigit(c) ((unsigned char)c >= (unsigned char)'0' && (unsigned char)c <= (unsigned char)'9') + +typedef union +{ + unsigned char byte[5]; + long l; + unsigned long ul; + float f; + const char *ptr; +} value_t; + +#ifndef __SDCC_STACK_AUTO + static bool lower_case; + static pfn_outputchar output_char; + static void* p; + static value_t value; + static int charsOutputted; +#endif + +/****************************************************************************/ + +#ifdef __SDCC_STACK_AUTO + #define OUTPUT_CHAR(c, p) { output_char (c, p); charsOutputted++; } +#else + #define OUTPUT_CHAR(c, p) _output_char (c) + static void + _output_char (unsigned char c) + { + output_char( c, p ); + charsOutputted++; + } +#endif + +/*--------------------------------------------------------------------------*/ + +#ifdef __SDCC_STACK_AUTO + static void + output_digit (unsigned char n, bool lower_case, pfn_outputchar output_char, void* p) + { + register unsigned char c = n + (unsigned char)'0'; + + if (c > (unsigned char)'9') + { + c += (unsigned char)('A' - '0' - 10); + if (lower_case) + c += (unsigned char)('a' - 'A'); + } + output_char( c, p ); + } +#else + static void + output_digit (unsigned char n) + { + register unsigned char c = n + (unsigned char)'0'; + + if (c > (unsigned char)'9') + { + c += (unsigned char)('A' - '0' - 10); + if (lower_case) + c = tolower(c); + } + _output_char( c ); + } +#endif + +/*--------------------------------------------------------------------------*/ + +#ifdef __SDCC_STACK_AUTO + #define OUTPUT_2DIGITS( B ) { output_2digits( B, lower_case, output_char, p ); charsOutputted += 2; } + static void + output_2digits (unsigned char b, bool lower_case, pfn_outputchar output_char, void* p) + { + output_digit( b>>4, lower_case, output_char, p ); + output_digit( b&0x0F, lower_case, output_char, p ); + } +#else + #define OUTPUT_2DIGITS( B ) output_2digits( B ) + static void + output_2digits (unsigned char b) + { + output_digit( b>>4 ); + output_digit( b&0x0F ); + } +#endif + +/*--------------------------------------------------------------------------*/ + +#if defined __SDCC_STACK_AUTO +static void +calculate_digit (value_t _AUTOMEM * value, unsigned char radix) +{ + unsigned long ul = value->ul; + unsigned char _AUTOMEM * pb4 = &value->byte[4]; + unsigned char i = 32; + + do + { + *pb4 = (*pb4 << 1) | ((ul >> 31) & 0x01); + ul <<= 1; + + if (radix <= *pb4 ) + { + *pb4 -= radix; + ul |= 1; + } + } while (--i); + value->ul = ul; +} +#else +static void +calculate_digit (unsigned char radix) +{ + register unsigned long ul = value.ul; + register unsigned char b4 = value.byte[4]; + register unsigned char i = 32; + + do + { + b4 = (b4 << 1); + b4 |= (ul >> 31) & 0x01; + ul <<= 1; + + if (radix <= b4 ) + { + b4 -= radix; + ul |= 1; + } + } while (--i); + value.ul = ul; + value.byte[4] = b4; +} +#endif + +#if USE_FLOATS + +/* This is a very inefficient but direct approach, since we have no math + library yet (e.g. log()). + It does most of the modifiers, but has some restrictions. E.g. the + abs(float) shouldn't be bigger than an unsigned long (that's + about 4294967295), but still makes it usefull for most real-life + applications. +*/ + +#define DEFAULT_FLOAT_PRECISION 6 + +#ifdef __SDCC_STACK_AUTO +#define OUTPUT_FLOAT(F, W, D, L, Z, S, P) output_float(F, W, D, L, Z, S, P, output_char, p) +static unsigned char +output_float (float f, unsigned char reqWidth, + signed char reqDecimals, + bool left, bool zero, bool sign, bool space, + pfn_outputchar output_char, void* p) +{ + unsigned char charsOutputted = 0; + #if defined (__SDCC_mcs51) + char fpBuffer[16]; //mcs51 has only a small stack + #else + char fpBuffer[128]; + #endif +#else +#define OUTPUT_FLOAT(F, W, D, L, Z, S, P) output_float(F, W, D, L, Z, S, P) +static void +output_float (float f, unsigned char reqWidth, + signed char reqDecimals, + bool left, bool zero, bool sign, bool space) +{ + __xdata char fpBuffer[128]; +#endif //__SDCC_STACK_AUTO + bool negative = 0; + unsigned long integerPart; + float rounding; + float decimalPart; + char fpBI=0, fpBD; + unsigned char minWidth, i; + signed char exp = -128; + + // save the sign + if (f<0) + { + negative=1; + f=-f; + } + + if (f>0x00ffffff) + { + // this part is from Frank van der Hulst + + for (exp = 0; f >= 10.0; exp++) f /=10.0; + for ( ; f < 1.0; exp--) f *=10.0; + + if (negative) + { + OUTPUT_CHAR ('-', p); + } + else + { + if (sign) + { + OUTPUT_CHAR ('+', p); + } + } + reqWidth = 0; + left = 0; + zero = 0; + sign = 0; + space = 0; + } + + // display some decimals as default + if (reqDecimals==-1) + reqDecimals=DEFAULT_FLOAT_PRECISION; + + // round the float + rounding = 0.5; + for (i=reqDecimals; i>0; i--) + { + rounding /= 10.0; + } + f += rounding; + + // split the float + integerPart = f; + decimalPart = f - integerPart; + + // fill the buffer with the integerPart (in reversed order!) + while (integerPart) + { + fpBuffer[fpBI++]='0' + integerPart%10; + integerPart /= 10; + } + if (!fpBI) + { + // we need at least a 0 + fpBuffer[fpBI++]='0'; + } + + // fill buffer with the decimalPart (in normal order) + fpBD=fpBI; + + for (i=reqDecimals; i>0; i--) + { + decimalPart *= 10.0; + // truncate the float + integerPart = decimalPart; + fpBuffer[fpBD++] = '0' + integerPart; + decimalPart -= integerPart; + } + + minWidth=fpBI; // we need at least these + minWidth+=reqDecimals?reqDecimals+1:0; // maybe these + if (negative || sign || space) + minWidth++; // and maybe even this :) + + if (!left && reqWidth>i) + { + if (zero) + { + if (negative) + { + OUTPUT_CHAR('-', p); + } + else if (sign) + { + OUTPUT_CHAR('+', p); + } + else if (space) + { + OUTPUT_CHAR(' ', p); + } + while (reqWidth-->minWidth) + { + OUTPUT_CHAR('0', p); + } + } + else + { + while (reqWidth-->minWidth) + { + OUTPUT_CHAR(' ', p); + } + if (negative) + { + OUTPUT_CHAR('-', p); + } + else if (sign) + { + OUTPUT_CHAR('+', p); + } + else if (space) + { + OUTPUT_CHAR(' ', p); + } + } + } + else + { + if (negative) + { + OUTPUT_CHAR('-', p); + } + else if (sign) + { + OUTPUT_CHAR('+', p); + } + else if (space) + { + OUTPUT_CHAR(' ', p); + } + } + + // output the integer part + i=fpBI-1; + do { + OUTPUT_CHAR (fpBuffer[i], p); + } while (i--); + + // ouput the decimal part + if (reqDecimals) + { + OUTPUT_CHAR ('.', p); + i=fpBI; + while (reqDecimals--) + { + OUTPUT_CHAR (fpBuffer[i++], p); + } + } + + if (left && reqWidth>minWidth) + { + while (reqWidth-->minWidth) + { + OUTPUT_CHAR(' ', p); + } + } + + if (exp != -128) + { + OUTPUT_CHAR ('e', p); + if (exp<0) + { + OUTPUT_CHAR ('-', p); + exp = -exp; + } + OUTPUT_CHAR ('0'+exp/10, p); + OUTPUT_CHAR ('0'+exp%10, p); + } +#ifdef __SDCC_STACK_AUTO + return charsOutputted; +#else + return; +#endif //__SDCC_STACK_AUTO +} +#endif //USE_FLOATS + +int +_print_format (pfn_outputchar pfn, void* pvoid, const char *format, va_list ap) +{ + bool left_justify; + bool zero_padding; + bool prefix_sign; + bool prefix_space; + bool signed_argument; + bool char_argument; + bool long_argument; + bool float_argument; +#ifdef __SDCC_STACK_AUTO + bool lower_case; + value_t value; + int charsOutputted; +#endif + bool lsd; + + unsigned char radix; + unsigned char width; + signed char decimals; + unsigned char length; + char c; + +#ifdef __SDCC_STACK_AUTO + #define output_char pfn + #define p pvoid +#else + output_char = pfn; + p = pvoid; +#endif + + // reset output chars + charsOutputted = 0; + +#ifdef __SDCC_ds390 + if (format==0) + { + format=NULL_STRING; + } +#endif + + while( c=*format++ ) + { + if ( c=='%' ) + { + left_justify = 0; + zero_padding = 0; + prefix_sign = 0; + prefix_space = 0; + signed_argument = 0; + char_argument = 0; + long_argument = 0; + float_argument = 0; + radix = 0; + width = 0; + decimals = -1; + +get_conversion_spec: + + c = *format++; + + if (c=='%') + { + OUTPUT_CHAR(c, p); + continue; + } + + if (isdigit(c)) + { + if (decimals==-1) + { + width = 10*width + c - '0'; + if (width == 0) + { + /* first character of width is a zero */ + zero_padding = 1; + } + } + else + { + decimals = 10*decimals + c - '0'; + } + goto get_conversion_spec; + } + + if (c=='.') + { + if (decimals==-1) + decimals=0; + else + ; // duplicate, ignore + goto get_conversion_spec; + } + + if (islower(c)) + { + c = toupper(c); + lower_case = 1; + } + else + lower_case = 0; + + switch( c ) + { + case '-': + left_justify = 1; + goto get_conversion_spec; + case '+': + prefix_sign = 1; + goto get_conversion_spec; + case ' ': + prefix_space = 1; + goto get_conversion_spec; + case 'B': /* byte */ + char_argument = 1; + goto get_conversion_spec; +// case '#': /* not supported */ + case 'H': /* short */ + case 'J': /* intmax_t */ + case 'T': /* ptrdiff_t */ + case 'Z': /* size_t */ + goto get_conversion_spec; + case 'L': /* long */ + long_argument = 1; + goto get_conversion_spec; + + case 'C': + if( char_argument ) + c = va_arg(ap,char); + else + c = va_arg(ap,int); + OUTPUT_CHAR( c, p ); + break; + + case 'S': + PTR = va_arg(ap,ptr_t); + +#ifdef __SDCC_ds390 + if (PTR==0) + { + PTR=NULL_STRING; + length=NULL_STRING_LENGTH; + } + else + { + length = strlen(PTR); + } +#else + length = strlen(PTR); +#endif + if ( decimals == -1 ) + { + decimals = length; + } + if ( ( !left_justify ) && (length < width) ) + { + width -= length; + while( width-- != 0 ) + { + OUTPUT_CHAR( ' ', p ); + } + } + + while ( (c = *PTR) && (decimals-- > 0)) + { + OUTPUT_CHAR( c, p ); + PTR++; + } + + if ( left_justify && (length < width)) + { + width -= length; + while( width-- != 0 ) + { + OUTPUT_CHAR( ' ', p ); + } + } + break; + + case 'P': + PTR = va_arg(ap,ptr_t); + +#if defined (__SDCC_ds390) + { + unsigned char memtype = value.byte[3]; + if (memtype >= 0x80) + c = 'C'; + else if (memtype >= 0x60) + c = 'P'; + else if (memtype >= 0x40) + c = 'I'; + else + c = 'X'; + } + OUTPUT_CHAR(c, p); + OUTPUT_CHAR(':', p); + OUTPUT_CHAR('0', p); + OUTPUT_CHAR('x', p); + OUTPUT_2DIGITS( value.byte[2] ); + OUTPUT_2DIGITS( value.byte[1] ); + OUTPUT_2DIGITS( value.byte[0] ); +#elif defined (__SDCC_mcs51) + { + unsigned char memtype = value.byte[2]; + if (memtype >= 0x80) + c = 'C'; + else if (memtype >= 0x60) + c = 'P'; + else if (memtype >= 0x40) + c = 'I'; + else + c = 'X'; + } + OUTPUT_CHAR(c, p); + OUTPUT_CHAR(':', p); + OUTPUT_CHAR('0', p); + OUTPUT_CHAR('x', p); + if ((c != 'I' /* idata */) && + (c != 'P' /* pdata */)) + { + OUTPUT_2DIGITS( value.byte[1] ); + } + OUTPUT_2DIGITS( value.byte[0] ); +#else + OUTPUT_CHAR('0', p); + OUTPUT_CHAR('x', p); + OUTPUT_2DIGITS( value.byte[1] ); + OUTPUT_2DIGITS( value.byte[0] ); +#endif + break; + + case 'D': + case 'I': + signed_argument = 1; + radix = 10; + break; + + case 'O': + radix = 8; + break; + + case 'U': + radix = 10; + break; + + case 'X': + radix = 16; + break; + + case 'F': + float_argument=1; + break; + + default: + // nothing special, just output the character + OUTPUT_CHAR( c, p ); + break; + } + + if (float_argument) + { + value.f = va_arg(ap, float); +#if !USE_FLOATS + PTR=""; + while (c=*PTR++) + { + OUTPUT_CHAR (c, p); + } + // treat as long hex + //radix=16; + //long_argument=1; + //zero_padding=1; + //width=8; +#else + // ignore b and l conversion spec for now +#ifdef __SDCC_STACK_AUTO + charsOutputted += OUTPUT_FLOAT(value.f, width, decimals, left_justify, + zero_padding, prefix_sign, prefix_space); +#else + OUTPUT_FLOAT(value.f, width, decimals, left_justify, + zero_padding, prefix_sign, prefix_space); +#endif //__SDCC_STACK_AUTO +#endif //USE_FLOATS + } + else if (radix != 0) + { + // Apparently we have to output an integral type + // with radix "radix" + unsigned char MEM_SPACE_BUF store[6]; + unsigned char MEM_SPACE_BUF_PP *pstore = &store[5]; + + // store value in byte[0] (LSB) ... byte[3] (MSB) + if (char_argument) + { + value.l = va_arg(ap, char); + if (!signed_argument) + { + value.l &= 0xFF; + } + } + else if (long_argument) + { + value.l = va_arg(ap, long); + } + else // must be int + { + value.l = va_arg(ap, int); + if (!signed_argument) + { + value.l &= 0xFFFF; + } + } + + if ( signed_argument ) + { + if (value.l < 0) + value.l = -value.l; + else + signed_argument = 0; + } + + length=0; + lsd = 1; + + do { + value.byte[4] = 0; +#if defined __SDCC_STACK_AUTO + calculate_digit(&value, radix); +#else + calculate_digit(radix); +#endif + if (!lsd) + { + *pstore = (value.byte[4] << 4) | (value.byte[4] >> 4) | *pstore; + pstore--; + } + else + { + *pstore = value.byte[4]; + } + length++; + lsd = !lsd; + } while( value.ul ); + + if (width == 0) + { + // default width. We set it to 1 to output + // at least one character in case the value itself + // is zero (i.e. length==0) + width = 1; + } + + /* prepend spaces if needed */ + if (!zero_padding && !left_justify) + { + while ( width > (unsigned char) (length+1) ) + { + OUTPUT_CHAR( ' ', p ); + width--; + } + } + + if (signed_argument) // this now means the original value was negative + { + OUTPUT_CHAR( '-', p ); + // adjust width to compensate for this character + width--; + } + else if (length != 0) + { + // value > 0 + if (prefix_sign) + { + OUTPUT_CHAR( '+', p ); + // adjust width to compensate for this character + width--; + } + else if (prefix_space) + { + OUTPUT_CHAR( ' ', p ); + // adjust width to compensate for this character + width--; + } + } + + /* prepend zeroes/spaces if needed */ + if (!left_justify) + { + while ( width-- > length ) + { + OUTPUT_CHAR( zero_padding ? '0' : ' ', p ); + } + } + else + { + /* spaces are appended after the digits */ + if (width > length) + width -= length; + else + width = 0; + } + + /* output the digits */ + while( length-- ) + { + lsd = !lsd; + if (!lsd) + { + pstore++; + value.byte[4] = *pstore >> 4; + } + else + { + value.byte[4] = *pstore & 0x0F; + } +#ifdef __SDCC_STACK_AUTO + output_digit( value.byte[4], lower_case, output_char, p ); + charsOutputted++; +#else + output_digit( value.byte[4] ); +#endif + } + if (left_justify) + { + while (width-- > 0) + { + OUTPUT_CHAR(' ', p); + } + } + } + } + else + { + // nothing special, just output the character + OUTPUT_CHAR( c, p ); + } + } + + return charsOutputted; +} + +/****************************************************************************/ diff --git a/hardware/tools/stm8/lib/src/printf_tiny.c b/hardware/tools/stm8/lib/src/printf_tiny.c new file mode 100644 index 0000000..0e97973 --- /dev/null +++ b/hardware/tools/stm8/lib/src/printf_tiny.c @@ -0,0 +1,305 @@ +/*------------------------------------------------------------------------- + printf_tiny.c - Tiny printf routine for use with sdcc/mcs51 + + Copyright (C) 2004, Paul Stoffregen, paul@pjrc.com + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* + * This tiny printf uses minimal code space, and it is fully reentrant + * and register bank neutral (usually safe to call from within an + * interrupt routine). Code size is under 270 bytes. Only one library + * function is called (_gptrget, 41 bytes), in addition to calls to + * putchar(). + * + * Five simple formats are supported + * + * %d signed 16 bit integer decimal (-32768 to 32767) + * %u unsigned 16 bit integer decimal (0 to 65535) + * %s string, takes a 24 bit generic pointer + * %c character. You must explicitly cast to char in SDCC + * %x 16 bit integer in hex (0 to FFFF) + * + * For a more complete printf that supports longs, floating point and + * field width, try using printf_fast() or printf_large(). + */ + + +/* This removes the negative number code, causing "%d" to be the same + as "%u". If you don't care about printing negative numbers, this + will save 21 bytes of code. */ +/* #define ALWAYS_PRINT_UNSIGNED */ + +/* Directly output characters to the serial port using simple polling, + rather than calling putchar(). This saves 14 bytes, plus the size + of putchar. */ +/* #define DIRECT_SERIAL_OUTPUT */ + + + +/* extern void putchar(char ); */ + + +#define print_zero_flag PSW.5 + + +#if !defined(__SDCC_mcs51) || defined(__SDCC_USE_XSTACK) || defined(_SDCC_NO_ASM_LIB_FUNCS) +/* Does printf_tiny really work on ds390 and ds400? + If it does, enable them in the line above */ +#if defined(_SDCC_BUILD_LIB) +/* Disable all warnings if building a library */ +#pragma disable_warning 190 +#elif defined(__SDCC_USE_XSTACK) +#warning "printf_tiny not built, does not support --xstack" +#elif defined(_SDCC_NO_ASM_LIB_FUNCS) +#warning "printf_tiny not built, _SDCC_NO_ASM_LIB_FUNCS defined" +#else +/* Disable "ISO C forbids an empty source file" warning message */ +#pragma disable_warning 190 +#endif +#else /* defines are compatible with printf_tiny */ + + + +void printf_tiny(__code const char *fmt, ...) __reentrant +{ + fmt; /* suppress unreferenced variable warning */ + + __asm + +printf_begin: + mov a, _bp /* r0 will point to va_args (stack) */ + add a, #253 + mov r0, a /* r0 points to MSB of fmt */ + mov dph, @r0 + dec r0 + mov dpl, @r0 /* dptr has address of fmt */ + dec r0 + + +printf_main_loop: + clr a + movc a, @a+dptr /* get next byte of fmt string */ + inc dptr + add a, #256 - 37 + jz printf_format /* check for '%' */ + add a, #37 + jz printf_end_h + lcall printf_putchar + sjmp printf_main_loop +printf_end_h: + ljmp printf_end + + +printf_format: + setb print_zero_flag + clr a + movc a, @a+dptr /* get next byte of data format */ + inc dptr + push dph + push dpl + + +printf_format_s: + /*cjne a, #'s', printf_format_c*/ + cjne a, #115, printf_format_c +printf_string: + /* print a string... just grab each byte with __gptrget */ + /* the user much pass a 24 bit generic pointer */ + mov b, @r0 /* b has type of address (generic *) */ + dec r0 + mov dph, @r0 + dec r0 + mov dpl, @r0 /* dptr has address of user's string */ + dec r0 +printf_str_loop: + lcall __gptrget + jz printf_format_done + inc dptr + lcall printf_putchar + sjmp printf_str_loop + + +printf_format_c: + /*cjne a, #'c', printf_format_d*/ + cjne a, #99, printf_format_d + dec r0 + mov a, @r0 /* Acc has the character to print */ + dec r0 + lcall printf_putchar + sjmp printf_format_done + + +printf_format_d: + /*cjne a, #'d', printf_format_u*/ + cjne a, #100, printf_format_x +#ifndef ALWAYS_PRINT_UNSIGNED + mov a, @r0 + jnb acc.7, printf_uint + dec r0 + mov a, @r0 + cpl a + add a, #1 + mov @r0, a + inc r0 + mov a, @r0 + cpl a + addc a, #0 + mov @r0, a + /*mov a, #'-'*/ + mov a, #45 + lcall printf_putchar +#endif + sjmp printf_uint + + +printf_format_x: + /*cjne a, #'x', printf_format_u*/ + cjne a, #120, printf_format_u + mov dph, @r0 + dec r0 + mov dpl, @r0 + dec r0 + clr a +printf_hex: + lcall printf_phex_lsn + mov a, dph + lcall printf_phex_msn + mov a, dph + lcall printf_phex_lsn + mov a, dpl + lcall printf_phex_msn + mov a, dpl + lcall printf_phex_lsn + jnb print_zero_flag, printf_format_done + /*mov a, #'0'*/ + mov a, #48 + lcall printf_putchar +printf_format_done: + pop dpl + pop dph + ljmp printf_main_loop + + +printf_format_u: + /*cjne a, #'u', printf_format_done*/ + cjne a, #117, printf_format_done +printf_uint: + mov a, @r0 + mov r2, a + dec r0 + mov a, @r0 + mov r1, a + dec r0 +printf_int2bcd: + mov r4, #16 + mov r5, #39 + lcall div_by_sub + mov r7, a + mov r4, #232 + mov r5, #3 + lcall div_by_sub + swap a + mov dph, a + mov r4, #100 + mov r5, #0 + lcall div_by_sub + orl dph, a + mov a, r1 + mov b, #10 + div ab + swap a + orl a, b + mov dpl, a + mov a, r7 + sjmp printf_hex + + + /* Divide r2/r1 by r5/r4 using successive subtraction + returns quotient in r2/r1 and remainder in acc. */ +div_by_sub: + mov r3, #0 +div_by_sub_loop: + inc r3 + clr c + mov a, r1 + subb a, r4 + mov r1, a + mov a, r2 + subb a, r5 + mov r2, a + jnc div_by_sub_loop + dec r3 + mov a, r1 + add a, r4 + mov r1, a + mov a, r2 + addc a, r5 + mov r2, a + mov a, r3 + ret + + + /* print a hex digit, either upper 4 bit (msn) or lower 4 bits (lsn) */ +printf_phex_msn: + swap a +printf_phex_lsn: + anl a, #15 + jnz printf_phex_ok + jb print_zero_flag, printf_ret +printf_phex_ok: + clr print_zero_flag + add a, #0x90 + da a + addc a, #0x40 + da a +printf_putchar: +#ifdef DIRECT_SERIAL_OUTPUT + jnb ti, printf_putchar + clr ti + mov sbuf, a +#else + push dph + push dpl + push b + mov dpl, a + mov a, r0 + push acc + lcall _putchar + pop acc + mov r0, a + pop b + pop dpl + pop dph +#endif +printf_ret: + ret + + +printf_end: + __endasm; +} + + +#endif /* defines compatible with printf_tiny */ diff --git a/hardware/tools/stm8/lib/src/printfl.c b/hardware/tools/stm8/lib/src/printfl.c new file mode 100644 index 0000000..3e7a215 --- /dev/null +++ b/hardware/tools/stm8/lib/src/printfl.c @@ -0,0 +1,199 @@ +/*----------------------------------------------------------------- + printfl.c - source file for reduced version of printf + + Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net + 2001060401: Improved by was@icb.snz.chel.su + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* following formats are supported :- + format output type argument-type + %d decimal int + %ld decimal long + %hd decimal char + %x hexadecimal int + %lx hexadecimal long + %hx hexadecimal char + %o octal int + %lo octal long + %ho octal char + %c character char + %s character generic pointer +*/ + +#include +#include +#include + +static __data char radix ; +static __bit long_flag = 0; +static __bit string_flag =0; +static __bit char_flag = 0; +static char * __data str ; +static __data long val; + +/* This great loop fails with the ds390 port (2003-01-13). + + At the beginning resp. end of the loop the compiler inserts a "push ar2" + resp. "pop ar2", which badly interferes with the push/pop in the source. + + Library functions should be rock solid and portable. There's an _ltoa in + the library, so let's use it and don't reinvent the wheel. + + Bernhard +*/ + +#if NICE_LIFO_IMPLEMENTATION_BUT_NOT_PORTABLE +/* just for the SP */ +#include <8051.h> + +static __data volatile char ch; +static __bit sign; + +static void pval(void) +{ + volatile char sp; + unsigned long lval; + sp = SP; + + if (val < 0 && radix != 16) + { + lval = -val; + sign = 1; + } + else { sign = 0; lval = val;} + + if (!long_flag) { + lval &= 0x0000ffff; + } + if (char_flag) { + lval &= 0x000000ff; + } + + do + { + +# if 1 + if(radix != 16) ch = (lval % radix) + '0'; + else ch = "0123456789ABCDEF"[(unsigned char)lval & 0x0f]; + __asm push _ch __endasm; + lval /= radix; +# else + // This only looks more efficient, but isn't. see the .map + ch = (lval % radix) + '0'; + if (ch>'9') ch+=7; + __asm push _ch __endasm; + lval /= radix; +# endif + } + while (lval); + + if (sign) { + ch = '-'; + __asm push _ch __endasm; + } + + while (sp != SP) { + __asm pop _ch __endasm; + putchar(ch); + } +} +#endif + +void printf_small (char * fmt, ... ) __reentrant +{ + va_list ap ; + + va_start(ap,fmt); + + for (; *fmt ; fmt++ ) { + if (*fmt == '%') { + long_flag = string_flag = char_flag = 0; + fmt++ ; + switch (*fmt) { + case 'l': + long_flag = 1; + fmt++; + break; + case 'h': + char_flag = 1; + fmt++; + } + + switch (*fmt) { + case 's': + string_flag = 1; + break; + case 'd': + radix = 10; + break; + case 'x': + radix = 16; + break; + case 'c': + radix = 0; + break; + case 'o': + radix = 8; + break; + } + + if (string_flag) { + str = va_arg(ap, char *); + while (*str) putchar(*str++); + continue ; + } + + if (long_flag) + val = va_arg(ap,long); + else + if (char_flag) + val = va_arg(ap,char); + else + val = va_arg(ap,int); + +#if NICE_LIFO_IMPLEMENTATION_BUT_NOT_PORTABLE + if (radix) pval(); +#else + if (radix) + { + static char __idata buffer[12]; /* 37777777777(oct) */ + char __idata * stri; + + _ltoa (val, buffer, radix); + stri = buffer; + while (*stri) + { + putchar (*stri); + stri++; + } + } +#endif + else + putchar((char)val); + + } else + putchar(*fmt); + } +} diff --git a/hardware/tools/stm8/lib/src/puts.c b/hardware/tools/stm8/lib/src/puts.c new file mode 100644 index 0000000..6d33b94 --- /dev/null +++ b/hardware/tools/stm8/lib/src/puts.c @@ -0,0 +1,38 @@ +/*----------------------------------------------------------------- + puts.c - source file for C function puts() + + Copyright (C) 2016, Philipp Klaus Krause . pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +int puts (const char *s) +{ + while (*s) + if (putchar(*s++) == EOF) + return EOF; + return putchar('\n'); +} + diff --git a/hardware/tools/stm8/lib/src/rand.c b/hardware/tools/stm8/lib/src/rand.c new file mode 100644 index 0000000..7794f2d --- /dev/null +++ b/hardware/tools/stm8/lib/src/rand.c @@ -0,0 +1,57 @@ +/*------------------------------------------------------------------------- + rand.c - random number generator + + Copyright (C) 2017, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. + + This is an xorshift PRNG. See George Marsaglia, "Xorshift RNGs" for details. + The width of 32 bits was chosen to not regress in period length vs. the + PRNG from the C standard, while at the same time minimizing RAM usage. + The parameters a, b, c were chosen to allow the generation of efficient code. +-------------------------------------------------------------------------*/ + +#include + +#include + +static uint32_t s = 0x80000001; + +int rand(void) +{ + register unsigned long t = s; + + t ^= t >> 10; + t ^= t << 9; + t ^= t >> 25; + + s = t; + + return(t & RAND_MAX); +} + +void srand(unsigned int seed) +{ + s = seed | 0x80000000; /* s shall not become 0 */ +} + diff --git a/hardware/tools/stm8/lib/src/realloc.c b/hardware/tools/stm8/lib/src/realloc.c new file mode 100644 index 0000000..9fc5b2f --- /dev/null +++ b/hardware/tools/stm8/lib/src/realloc.c @@ -0,0 +1,129 @@ +/*------------------------------------------------------------------------- + realloc.c - allocate memory. + + Copyright (C) 2015, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include +#include +#include + +#if defined(__SDCC_mcs51) || defined(__SDCC_ds390) || defined(__SDCC_ds400) +#define XDATA __xdata +#else +#define XDATA +#endif + +typedef struct header XDATA header_t; + +struct header +{ + header_t *next; + header_t *next_free; +}; + +extern header_t *XDATA __sdcc_heap_free; + +void __sdcc_heap_init(void); + +void XDATA *realloc(void *ptr, size_t size) +{ + void XDATA *ret; + header_t *h, *next_free, *prev_free; + header_t *XDATA *f, *XDATA *pf; + size_t blocksize, oldblocksize, maxblocksize; + +#if defined(__SDCC_mcs51) || defined(__SDCC_ds390) || defined(__SDCC_ds400) || defined(__SDCC_hc08) || defined(__SDCC_s08) + if(!__sdcc_heap_free) + __sdcc_heap_init(); +#endif + + if(!ptr) + return(malloc(size)); + + if(!size) + { + free(ptr); + return(0); + } + + prev_free = 0, pf = 0; + for(h = __sdcc_heap_free, f = &__sdcc_heap_free; h && h < ptr; prev_free = h, pf = f, f = &(h->next_free), h = h->next_free); // Find adjacent blocks in free list + next_free = h; + + if(!size || size + offsetof(struct header, next_free) < size) + return(0); + blocksize = size + offsetof(struct header, next_free); + if(blocksize < sizeof(struct header)) // Requiring a minimum size makes it easier to implement free(), and avoid memory leaks. + blocksize = sizeof(struct header); + + h = (void XDATA *)((char XDATA *)(ptr) - offsetof(struct header, next_free)); + oldblocksize = (char XDATA *)(h->next) - (char XDATA *)h; + + maxblocksize = oldblocksize; + if(prev_free && prev_free->next == h) // Can merge with previous block + maxblocksize += (char XDATA *)h - (char XDATA *)prev_free; + if(next_free == h->next) // Can merge with next block + maxblocksize += (char XDATA *)(next_free->next) - (char XDATA *)next_free; + + if(blocksize <= maxblocksize) // Can resize in place. + { + if(prev_free && prev_free->next == h) // Always move into previous block to defragment + { + memmove(prev_free, h, blocksize <= oldblocksize ? blocksize : oldblocksize); + h = prev_free; + *pf = next_free; + f = pf; + } + + if(next_free && next_free == h->next) // Merge with following block + { + h->next = next_free->next; + *f = next_free->next_free; + } + + if(maxblocksize >= blocksize + sizeof(struct header)) // Create new block from free space + { + header_t *const newheader = (header_t *const)((char XDATA *)h + blocksize); + newheader->next = h->next; + newheader->next_free = *f; + *f = newheader; + h->next = newheader; + } + + return(&(h->next_free)); + } + + if(ret = malloc(size)) + { + size_t oldsize = oldblocksize - offsetof(struct header, next_free); + memcpy(ret, ptr, size <= oldsize ? size : oldsize); + free(ptr); + return(ret); + } + + return(0); +} + diff --git a/hardware/tools/stm8/lib/src/ser_ir.c b/hardware/tools/stm8/lib/src/ser_ir.c new file mode 100644 index 0000000..75c09ab --- /dev/null +++ b/hardware/tools/stm8/lib/src/ser_ir.c @@ -0,0 +1,154 @@ +/*------------------------------------------------------------------------- + ser_ir.h - source file for serial routines + + Copyright (C) 1999, Josef Wolf + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include "ser_ir.h" + +/* This file implements a serial interrupt handler and its supporting +* routines. Compared with the existing serial.c and _ser.c it has +* following advantages: +* - You can specify arbitrary buffer sizes (umm, up to 255 bytes), +* so it can run on devices with _little_ memory like at89cx051. +* - It won't overwrite characters which already are stored in the +* receive-/transmit-buffer. +*/ + +/* BUG: those definitions (and the #include) should be set dynamically +* (while linking or at runtime) to make this file a _real_ library. +*/ +#include <8051.h> +#define XBUFLEN 4 +#define RBUFLEN 8 + +/* You might want to specify idata, pdata or xdata for the buffers */ +static unsigned char __pdata rbuf[RBUFLEN], xbuf[XBUFLEN]; +static unsigned char rcnt, xcnt, rpos, xpos; +static __bit busy; + +void +ser_init (void) +{ + ES = 0; + rcnt = xcnt = rpos = xpos = 0; /* init buffers */ + busy = 0; + SCON = 0x50; + PCON |= 0x80; /* SMOD = 1; */ + TMOD &= 0x0f; /* use timer 1 */ + TMOD |= 0x20; + TL1 = -3; TH1 = -3; TR1 = 1; /* 19200bps with 11.059MHz crystal */ + ES = 1; +} + +void +ser_handler (void) __interrupt 4 +{ + if (RI) { + RI = 0; + /* don't overwrite chars already in buffer */ + if (rcnt < RBUFLEN) + rbuf [(unsigned char)(rpos+rcnt++) % RBUFLEN] = SBUF; + } + if (TI) { + TI = 0; + if (busy = xcnt) { /* Assignment, _not_ comparison! */ + xcnt--; + SBUF = xbuf [xpos++]; + if (xpos >= XBUFLEN) + xpos = 0; + } + } +} + +void +ser_putc (unsigned char c) +{ + while (xcnt >= XBUFLEN) /* wait for room in buffer */ + ; + ES = 0; + if (busy) { + xbuf[(unsigned char)(xpos+xcnt++) % XBUFLEN] = c; + } else { + SBUF = c; + busy = 1; + } + ES = 1; +} + +unsigned char +ser_getc (void) +{ + unsigned char c; + while (!rcnt) /* wait for character */ + ; + ES = 0; + rcnt--; + c = rbuf [rpos++]; + if (rpos >= RBUFLEN) + rpos = 0; + ES = 1; + return (c); +} + +#pragma save +#pragma noinduction +void +ser_puts (unsigned char *s) +{ + unsigned char c; + while (c=*s++) { + if (c == '\n') ser_putc ('\r'); + ser_putc (c); + } +} +#pragma restore + +void +ser_gets (unsigned char *s, unsigned char len) +{ + unsigned char pos, c; + + pos = 0; + while (pos <= len) { + c = ser_getc (); + if (c == '\r') continue; /* discard CR's */ + s[pos++] = c; + if (c == '\n') break; /* NL terminates */ + } + s[pos] = '\0'; +} + +unsigned char +ser_can_xmt (void) +{ + return XBUFLEN - xcnt; +} + +unsigned char +ser_can_rcv (void) +{ + return rcnt; +} diff --git a/hardware/tools/stm8/lib/src/ser_ir_cts_rts.c b/hardware/tools/stm8/lib/src/ser_ir_cts_rts.c new file mode 100644 index 0000000..ae9dfcf --- /dev/null +++ b/hardware/tools/stm8/lib/src/ser_ir_cts_rts.c @@ -0,0 +1,210 @@ +/*------------------------------------------------------------------------- + ser_ir_cts_rts.c - source file for serial routines + + Copyright (C) 1999, Josef Wolf + + Revisions: + 1.0 Bela Torok Jul. 2000 + RTS / CTS protocol added + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* This file implements a serial interrupt handler and its supporting +* routines. Compared with the existing serial.c and _ser.c it has +* following advantages: +* - You can specify arbitrary buffer sizes (umm, up to 255 bytes), +* so it can run on devices with _little_ memory like at89cx051. +* - It won't overwrite characters which already are stored in the +* receive-/transmit-buffer. +*/ + +/* BUG: those definitions (and the #include) should be set dynamically +* (while linking or at runtime) to make this file a _real_ library. +*/ + +/* RTS/CTS protocol howto: + + + Shematic of cable for RTS/CTS protocol (B. Torok - Jun. 2000) + +<- DB9 female connector -><- RS232 driver/receiver -><- 8051 system -> + connect to PC e.g. MAX232 + + RS232 TTL + level level + + DCD DTR + Pin1---Pin4 + Transmitters/Receivers + RXD + Pin2-----------------------------<<<-------------------TXD + + TXD + Pin3----------------------------->>>-------------------RXD + + GND + Pin5---------------------------------------------------GND + + DSR CTS + Pin6---Pin8----------------------<<<-------------------CTS (see #define CTS) + + RTS + Pin7----------------------------->>>-------------------RTS (see #define RTS) +*/ + + +#include <8051.h> +#include "ser_ir.h" + +#define TXBUFLEN 3 +#define RXBUFLEN 18 // The minimum rx buffer size for safe communications + // is 17. (The UART in the PC has a 16-byte FIFO.) +// TXBUFLEN & RXBUFLEN can be highher if rxbuf[] and txbuf[] is in xdata, max size is limited to 256! + +#define THRESHOLD 16 +#define ENABLE 0 +#define DISABLE 1 + +#define CTS P3_6 // CTS & RTS can be assigned to any free pins +#define RTS P3_7 + +// You might want to specify idata, pdata or xdata for the buffers +static unsigned char rxbuf[RXBUFLEN], txbuf[TXBUFLEN]; +static unsigned char rxcnt, txcnt, rxpos, txpos; +static bit busy; + +void +ser_init () +{ + ES = 0; + rxcnt = txcnt = rxpos = txpos = 0; // init buffers + busy = 0; + SCON = 0x50; // mode 1 - 8-bit UART + PCON |= 0x80; // SMOD = 1; + TMOD &= 0x0f; // use timer 1 + TMOD |= 0x20; +// TL1 = TH1 = 256 - 104; // 600bps with 12 MHz crystal +// TL1 = TH1 = 256 - 52; // 1200bps with 12 MHz crystal +// TL1 = TH1 = 256 - 26; // 2400bps with 12 MHz crystal + TL1 = TH1 = 256 - 13; // 4800bps with 12 MHz crystal + + TR1 = 1; // Enable timer 1 + ES = 1; + + CTS = ENABLE; +} + +void +ser_handler (void) interrupt 4 +{ + if (RI) { + RI = 0; + /* don't overwrite chars already in buffer */ + if(rxcnt < RXBUFLEN) rxbuf [(unsigned char)(rxpos + rxcnt++) % RXBUFLEN] = SBUF; + if(rxcnt >= (RXBUFLEN - THRESHOLD)) CTS = DISABLE; + } + + if (TI) { + TI = 0; + if (busy = txcnt) { /* Assignment, _not_ comparison! */ + txcnt--; + SBUF = txbuf[txpos++]; + if(txpos >= TXBUFLEN) txpos = 0; + } + } +} + +void +ser_putc (unsigned char c) +{ + while(txcnt >= TXBUFLEN); // wait for room in buffer + + while(RTS == DISABLE); + + ES = 0; + if (busy) { + txbuf[(unsigned char)(txpos + txcnt++) % TXBUFLEN] = c; + } else { + SBUF = c; + busy = 1; + } + ES = 1; +} + +unsigned char +ser_getc (void) +{ + unsigned char c; + + while (!rxcnt) { // wait for a character + CTS = ENABLE; + } + + ES = 0; + rxcnt--; + c = rxbuf[rxpos++]; + if (rxpos >= RXBUFLEN) rxpos = 0; + ES = 1; + return (c); +} + +#pragma save +#pragma noinduction +void +ser_puts (unsigned char *s) +{ + unsigned char c; + while (c= *s++) { + if (c == '\n') ser_putc('\r'); + ser_putc (c); + } +} +#pragma restore + +void +ser_gets (unsigned char *s, unsigned char len) +{ + unsigned char pos, c; + + pos = 0; + while (pos <= len) { + c = ser_getc(); + if (c == '\r') continue; // discard CR's + s[pos++] = c; + if (c == '\n') break; // NL terminates + } + s[pos] = '\0'; // terminate string +} + +unsigned char +ser_can_xmt (void) +{ + return TXBUFLEN - txcnt; +} + +unsigned char +ser_can_rcv (void) +{ + return rxcnt; +} diff --git a/hardware/tools/stm8/lib/src/serial.c b/hardware/tools/stm8/lib/src/serial.c new file mode 100644 index 0000000..01c4e81 --- /dev/null +++ b/hardware/tools/stm8/lib/src/serial.c @@ -0,0 +1,108 @@ +/*------------------------------------------------------------------------- + serial.c - this module implements serial interrupt handler and IO + routinwes using two 256 byte cyclic buffers. Bit variables + can be used as flags for real-time kernel tasks + + Copyright (C) 1996, Dmitry S. Obukhov + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* This module contains definition of I8051 registers */ +#include "8052.h" + + +static unsigned char __xdata stx_index_in, srx_index_in, stx_index_out, srx_index_out; +static unsigned char __xdata stx_buffer[0x100]; +static unsigned char __xdata srx_buffer[0x100]; + +static __bit work_flag_byte_arrived; +static __bit work_flag_buffer_transfered; +static __bit tx_serial_buffer_empty; +static __bit rx_serial_buffer_empty; + + +void serial_init(void) +{ + SCON = 0x50; + T2CON = 0x34; + PS = 1; + T2CON = 0x34; + RCAP2H = 0xFF; + RCAP2L = 0xDA; + + RI = 0; + TI = 0; + + stx_index_in = srx_index_in = stx_index_out = srx_index_out = 0; + rx_serial_buffer_empty = tx_serial_buffer_empty = 1; + work_flag_buffer_transfered = 0; + work_flag_byte_arrived = 0; + ES=1; +} + +void serial_interrupt_handler(void) __interrupt 4 __using 1 +{ + ES=0; + if ( RI ) + { + RI = 0; + srx_buffer[srx_index_in++]=SBUF; + work_flag_byte_arrived = 1; + rx_serial_buffer_empty = 0; + } + if ( TI ) + { + TI = 0; + if (stx_index_out == stx_index_in ) + { + tx_serial_buffer_empty = 1; + work_flag_buffer_transfered = 1; + } + else SBUF = stx_buffer[stx_index_out++]; + } + ES=1; +} + +/* Next two functions are interface */ + +void serial_putc(unsigned char c) +{ + stx_buffer[stx_index_in++]=c; + ES=0; + if ( tx_serial_buffer_empty ) + { + tx_serial_buffer_empty = 0; + TI=1; + } + ES=1; +} + +unsigned char serial_getc(void) +{ + unsigned char tmp = srx_buffer[srx_index_out++]; + ES=0; + if ( srx_index_out == srx_index_in) rx_serial_buffer_empty = 1; + ES=1; + return tmp; +} diff --git a/hardware/tools/stm8/lib/src/sincosf.c b/hardware/tools/stm8/lib/src/sincosf.c new file mode 100644 index 0000000..4f627ec --- /dev/null +++ b/hardware/tools/stm8/lib/src/sincosf.c @@ -0,0 +1,97 @@ +/*------------------------------------------------------------------------- + sincosf.c - Computes sin or cos of a 32-bit float as outlined in [1] + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* [1] William James Cody and W. M. Waite. _Software manual for the + elementary functions_, Englewood Cliffs, N.J.:Prentice-Hall, 1980. */ + +/* Version 1.0 - Initial release */ + +#include +#include +#include + +#define r1 -0.1666665668E+0 +#define r2 0.8333025139E-2 +#define r3 -0.1980741872E-3 +#define r4 0.2601903036E-5 + +/* PI=C1+C2 */ +#define C1 3.140625 +#define C2 9.676535897E-4 + +/*A reasonable value for YMAX is the int part of PI*B**(t/2)=3.1416*2**(12)*/ +#define YMAX 12867.0 + +float sincosf(float x, bool iscos) +{ + float y, f, r, g, XN; + int N; + bool sign; + + if(iscos) + { + y=fabsf(x)+HALF_PI; + sign=0; + } + else + { + if(x<0.0) + { y=-x; sign=1; } + else + { y=x; sign=0; } + } + + if(y>YMAX) + { + errno=ERANGE; + return 0.0; + } + + /*Round y/PI to the nearest integer*/ + N=((y*iPI)+0.5); /*y is positive*/ + + /*If N is odd change sign*/ + if(N&1) sign=!sign; + + XN=N; + /*Cosine required? (is done here to keep accuracy)*/ + if(iscos) XN-=0.5; + + y=fabsf(x); + r=(int)y; + g=y-r; + f=((r-XN*C1)+g)-XN*C2; + + g=f*f; + if(g>EPS2) //Used to be if(fabsf(f)>EPS) + { + r=(((r4*g+r3)*g+r2)*g+r1)*g; + f+=f*r; + } + return (sign?-f:f); +} diff --git a/hardware/tools/stm8/lib/src/sincoshf.c b/hardware/tools/stm8/lib/src/sincoshf.c new file mode 100644 index 0000000..84ce37e --- /dev/null +++ b/hardware/tools/stm8/lib/src/sincoshf.c @@ -0,0 +1,100 @@ +/*------------------------------------------------------------------------- + sincoshf.c - Computes sinh or cosh of a 32-bit float as outlined in [1] + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* [1] William James Cody and W. M. Waite. _Software manual for the + elementary functions_, Englewood Cliffs, N.J.:Prentice-Hall, 1980. */ + +/* Version 1.0 - Initial release */ + +#include +#include +#include + +#define P0 -0.713793159E+1 +#define P1 -0.190333999E+0 +#define Q0 -0.428277109E+2 +#define Q1 0.100000000E+1 + +#define P(z) (P1*z+P0) +#define Q(z) (Q1*z+Q0) + +#define K1 0.69316101074218750000E+0 /* ln(v) */ +#define K2 0.24999308500451499336E+0 /* v**(-2) */ +#define K3 0.13830277879601902638E-4 /* v/2-1 */ + +//WMAX is defined as ln(HUGE_VALF)-ln(v)+0.69 +#define WMAX 44.93535952E+0 +//WBAR 0.35*(b+1) +#define WBAR 1.05 +#define YBAR 9.0 /*Works for me*/ + +float sincoshf(float x, bool iscosh) +{ + float y, w, z; + bool sign; + + if (x<0.0) { y=-x; sign=1; } + else { y=x; sign=0; } + + if ((y>1.0) || iscosh) + { + if(y>YBAR) + { + w=y-K1; + if (w>WMAX) + { + errno=ERANGE; + z=HUGE_VALF; + } + else + { + z=expf(w); + z+=K3*z; + } + } + else + { + z=expf(y); + w=1.0/z; + if(!iscosh) w=-w; + z=(z+w)*0.5; + } + if(sign) z=-z; + } + else + { + if (y +#include + +float sincosf(float x, bool iscos); + +float sinf(float x) _FLOAT_FUNC_REENTRANT +{ + if (x==0.0) return 0.0; + return sincosf(x, 0); +} diff --git a/hardware/tools/stm8/lib/src/sinhf.c b/hardware/tools/stm8/lib/src/sinhf.c new file mode 100644 index 0000000..f4ab53e --- /dev/null +++ b/hardware/tools/stm8/lib/src/sinhf.c @@ -0,0 +1,39 @@ +/*------------------------------------------------------------------------- + sinhf.c - Computes sinh(x) where x is a 32-bit float. + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* Version 1.0 - Initial release */ + +#include +#include + +float sincoshf(float x, bool iscosh); + +float sinhf(float x) _FLOAT_FUNC_REENTRANT +{ + return sincoshf(x, 0); +} diff --git a/hardware/tools/stm8/lib/src/sprintf.c b/hardware/tools/stm8/lib/src/sprintf.c new file mode 100644 index 0000000..fdd07d3 --- /dev/null +++ b/hardware/tools/stm8/lib/src/sprintf.c @@ -0,0 +1,61 @@ +/*----------------------------------------------------------------- + sprintf.c - formatted output conversion + + Copyright (C) 1999, Martijn van Balen + Refactored by - Maarten Brock (2004) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include +#include + +static void +put_char_to_string (char c, void* p) _REENTRANT +{ + char **buf = (char **)p; + *(*buf)++ = c; +} + +int +vsprintf (char *buf, const char *format, va_list ap) +{ + int i; + i = _print_format (put_char_to_string, &buf, format, ap); + *buf = 0; + return i; +} + +int +sprintf (char *buf, const char *format, ...) +{ + va_list arg; + int i; + + va_start (arg, format); + i = _print_format (put_char_to_string, &buf, format, arg); + *buf = 0; + va_end (arg); + + return i; +} diff --git a/hardware/tools/stm8/lib/src/sqrtf.c b/hardware/tools/stm8/lib/src/sqrtf.c new file mode 100644 index 0000000..b6bee13 --- /dev/null +++ b/hardware/tools/stm8/lib/src/sqrtf.c @@ -0,0 +1,61 @@ +/*------------------------------------------------------------------------- + sqrtf.c - Computes square root of a 32-bit float as outlined in [1] + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* [1] William James Cody and W. M. Waite. _Software manual for the + elementary functions_, Englewood Cliffs, N.J.:Prentice-Hall, 1980. */ + +/* Version 1.0 - Initial release */ + +#include +#include + +float sqrtf(float x) _FLOAT_FUNC_REENTRANT +{ + float f, y; + int n; + + if (x==0.0) return x; + else if (x==1.0) return 1.0; + else if (x<0.0) + { + errno=EDOM; + return 0.0; + } + f=frexpf(x, &n); + y=0.41731+0.59016*f; /*Educated guess*/ + /*For a 24 bit mantisa (float), two iterations are sufficient*/ + y+=f/y; + y=ldexpf(y, -2) + f/y; /*Faster version of 0.25 * y + f/y*/ + + if (n&1) + { + y*=0.7071067812; + ++n; + } + return ldexpf(y, n/2); +} diff --git a/hardware/tools/stm8/lib/src/strxfrm.c b/hardware/tools/stm8/lib/src/strxfrm.c new file mode 100644 index 0000000..5104ab5 --- /dev/null +++ b/hardware/tools/stm8/lib/src/strxfrm.c @@ -0,0 +1,36 @@ +/*------------------------------------------------------------------------- + _strcmp.c - part of string library functions + + Copyright (C) 2011, Philipp Klaus Krause . pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include "string.h" + +size_t strxfrm(char *dest, const char *src, size_t n) +{ + strncpy(dest, src, n); + return(strlen(src) + 1); +} + diff --git a/hardware/tools/stm8/lib/src/tancotf.c b/hardware/tools/stm8/lib/src/tancotf.c new file mode 100644 index 0000000..d2e1d2c --- /dev/null +++ b/hardware/tools/stm8/lib/src/tancotf.c @@ -0,0 +1,95 @@ +/*------------------------------------------------------------------------- + tancotf.c - Computes tan or cot of a 32-bit float as outlined in [1] + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* [1] William James Cody and W. M. Waite. _Software manual for the + elementary functions_, Englewood Cliffs, N.J.:Prentice-Hall, 1980. */ + +/* Version 1.0 - Initial release */ + +#include +#include +#include + +#define P0 0.100000000E+1 +#define P1 -0.958017723E-1 +#define Q0 0.100000000E+1 +#define Q1 -0.429135777E+0 +#define Q2 0.971685835E-2 + +#define C1 1.5703125 +#define C2 4.83826794897E-4 + +#define P(f,g) (P1*g*f+f) +#define Q(g) ((Q2*g+Q1)*g+Q0) + +//A reasonable choice for YMAX is the integer part of B**(t/2)*PI/2: +#define YMAX 6433.0 + +float tancotf(float x, bool iscotan) +{ + float f, g, xn, xnum, xden; + int n; + + if (fabsf(x) > YMAX) + { + errno = ERANGE; + return 0.0; + } + + /*Round x*2*PI to the nearest integer*/ + n=(x*TWO_O_PI+(x>0.0?0.5:-0.5)); /*works for +-x*/ + xn=n; + + xnum=(int)x; + xden=x-xnum; + f=((xnum-xn*C1)+xden)-xn*C2; + + if (fabsf(f) < EPS) + { + xnum = f; + xden = 1.0; + } + else + { + g = f*f; + xnum = P(f,g); + xden = Q(g); + } + + if(n&1) + //xn is odd + { + if(iscotan) return (-xnum/xden); + else return (-xden/xnum); + } + else + { + if(iscotan) return (xden/xnum); + else return (xnum/xden); + } +} diff --git a/hardware/tools/stm8/lib/src/tanf.c b/hardware/tools/stm8/lib/src/tanf.c new file mode 100644 index 0000000..494a497 --- /dev/null +++ b/hardware/tools/stm8/lib/src/tanf.c @@ -0,0 +1,39 @@ +/*------------------------------------------------------------------------- + tanf.c - Computes tan(x) where x is a 32-bit float. + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* Version 1.0 - Initial release */ + +#include +#include + +float tancotf(float x, bool iscotan); + +float tanf(float x) _FLOAT_FUNC_REENTRANT +{ + return tancotf(x, 0); +} diff --git a/hardware/tools/stm8/lib/src/tanhf.c b/hardware/tools/stm8/lib/src/tanhf.c new file mode 100644 index 0000000..e2e18f3 --- /dev/null +++ b/hardware/tools/stm8/lib/src/tanhf.c @@ -0,0 +1,69 @@ +/*------------------------------------------------------------------------- + tanhf.c - Computes tanh(x) where x is a 32-bit float as outlined in [1]. + + Copyright (C) 2001, 2002, 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 General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +/* [1] William James Cody and W. M. Waite. _Software manual for the + elementary functions_, Englewood Cliffs, N.J.:Prentice-Hall, 1980. */ + +/* Version 1.0 - Initial release */ + +#include +#include + +#define P0 -0.8237728127E+0 +#define P1 -0.3831010665E-2 +#define Q0 0.2471319654E+1 +#define Q1 0.1000000000E+1 + +/* ln(3)/2 */ +#define K1 0.5493061443E+0 +/* SBIG=[ln(2)+(t+1)*ln(B)]/2 */ +#define SBIG 9.01091 + +#define P(g) ((P1*g+P0)*g) +#define Q(g) (Q1*g+Q0) + +float tanhf(float x) _FLOAT_FUNC_REENTRANT +{ + float f, g, r; + + f=fabsf(x); + if(f>SBIG) r=1.0; + else if(f>K1) + { + r=0.5-1.0/(expf(f+f)+1.0); + r+=r; + } + else if(f + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include +#include + +// please note that the tm structure has the years since 1900, +// but time returns the seconds since 1970 + +/* You need some kind of real time clock for the time() function. + Either a rtc-chip or some kind of DCF device will do. For TINI, the + HAVE_RTC is defined in tinibios.h + If not, the conversion routines still work. +*/ + +#ifndef HAVE_RTC +unsigned char RtcRead(struct tm *timeptr) { + // no real time hardware + timeptr; // hush the compiler + return 0; +} +#endif + +// return the calendar time, seconds since the Epoch (Jan 1 1970 00:00:00) +time_t time(time_t *timeptr) { + struct tm now; + time_t t=(time_t) -1; + + if (RtcRead(&now)) { + t=mktime(&now); + } + if (timeptr) { + *timeptr=t; + } + return t; +} + +static _CODE char monthDays[]={31,28,31,30,31,30,31,31,30,31,30,31}; + +_CODE const char * _CODE __month[]={"Jan","Feb","Mar","Apr","May","Jun", + "Jul","Aug","Sep","Oct","Nov","Dec"}; + +_CODE const char * _CODE __day[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; + +static char ascTimeBuffer[32]; + +// validate the tm structure +static void CheckTime(struct tm *timeptr) { + // we could do some normalization here, e.g. + // change 40 october to 9 november + #if !__TIME_UNSIGNED + if (timeptr->tm_sec<0) timeptr->tm_sec=0; + if (timeptr->tm_min<0) timeptr->tm_min=0; + if (timeptr->tm_hour<0) timeptr->tm_hour=0; + if (timeptr->tm_wday<0) timeptr->tm_wday=0; + if (timeptr->tm_mon<0) timeptr->tm_mon=0; + #endif + + if (timeptr->tm_sec>59) timeptr->tm_sec=59; + if (timeptr->tm_min>59) timeptr->tm_min=59; + if (timeptr->tm_hour>23) timeptr->tm_hour=23; + if (timeptr->tm_wday>6) timeptr->tm_wday=6; + if (timeptr->tm_mday<1) timeptr->tm_mday=1; + else if (timeptr->tm_mday>31) timeptr->tm_mday=31; + if (timeptr->tm_mon>11) timeptr->tm_mon=11; + if (timeptr->tm_year<0) timeptr->tm_year=0; +} + +// format the time into "Sat Feb 17 17:45:23 2001\n" +char *asctime(struct tm *timeptr) { + CheckTime(timeptr); + sprintf (ascTimeBuffer, "%s %s %2d %02d:%02d:%02d %04d\n", + __day[timeptr->tm_wday], __month[timeptr->tm_mon], timeptr->tm_mday, + timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec, + timeptr->tm_year+1900); + return ascTimeBuffer; +} + +char *ctime(time_t *timep) { + return asctime(localtime(timep)); +} + +static struct tm lastTime; + +/* convert calendar time (seconds since 1970) to broken-time + This only works for dates between 01-01-1970 00:00:00 and + 19-01-2038 03:14:07 + + A leap year is ((((year%4)==0) && ((year%100)!=0)) || ((year%400)==0)) + but since we have no fancy years between 1970 and 2038 we can do: +*/ + +#define LEAP_YEAR(year) ((year%4)==0) + +// forget about timezones for now +struct tm *localtime(time_t *timep) { + return gmtime(timep); +} + +struct tm *gmtime(time_t *timep) { + unsigned long epoch=*timep; + unsigned int year; + unsigned char month, monthLength; + unsigned long days; + + lastTime.tm_sec=epoch%60; + epoch/=60; // now it is minutes + lastTime.tm_min=epoch%60; + epoch/=60; // now it is hours + lastTime.tm_hour=epoch%24; + epoch/=24; // now it is days + lastTime.tm_wday=(epoch+4)%7; + + year=1970; + days=0; + while((days += (LEAP_YEAR(year) ? 366 : 365)) <= epoch) { + year++; + } + lastTime.tm_year=year-1900; + + days -= LEAP_YEAR(year) ? 366 : 365; + epoch -= days; // now it is days in this year, starting at 0 + lastTime.tm_yday=epoch; + + days=0; + month=0; + monthLength=0; + for (month=0; month<12; month++) { + if (month==1) { // februari + if (LEAP_YEAR(year)) { + monthLength=29; + } else { + monthLength=28; + } + } else { + monthLength = monthDays[month]; + } + + if (epoch>=monthLength) { + epoch-=monthLength; + } else { + break; + } + } + lastTime.tm_mon=month; + lastTime.tm_mday=epoch+1; + + lastTime.tm_isdst=0; + + return &lastTime; +} + +// convert broken time to calendar time (seconds since 1970) +time_t mktime(struct tm *timeptr) { + int year=timeptr->tm_year+1900, month=timeptr->tm_mon, i; + long seconds; + + CheckTime(timeptr); + + // seconds from 1970 till 1 jan 00:00:00 this year + seconds= (year-1970)*(60*60*24L*365); + + // add extra days for leap years + for (i=1970; itm_mday-1)*60*60*24L; + seconds+= timeptr->tm_hour*60*60L; + seconds+= timeptr->tm_min*60; + seconds+= timeptr->tm_sec; + return seconds; +} diff --git a/hardware/tools/stm8/lib/src/tolower.c b/hardware/tools/stm8/lib/src/tolower.c new file mode 100644 index 0000000..90b936c --- /dev/null +++ b/hardware/tools/stm8/lib/src/tolower.c @@ -0,0 +1,37 @@ +/*------------------------------------------------------------------------- + tolower.c + + Philipp Klaus Krause, philipp@informatik.uni-frankfurt.de 2013 + + (c) 2013 Goethe-Universität Frankfurt + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +int tolower (int c) +{ + return (isupper (c) ? c + ('a' - 'A') : c); +} + diff --git a/hardware/tools/stm8/lib/src/toupper.c b/hardware/tools/stm8/lib/src/toupper.c new file mode 100644 index 0000000..2227ea8 --- /dev/null +++ b/hardware/tools/stm8/lib/src/toupper.c @@ -0,0 +1,37 @@ +/*------------------------------------------------------------------------- + toupper.c + + Philipp Klaus Krause, philipp@informatik.uni-frankfurt.de 2013 + + (c) 2013 Goethe-Universität Frankfurt + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +int toupper (int c) +{ + return (islower (c) ? c + ('A' - 'a') : c); +} + diff --git a/hardware/tools/stm8/lib/src/vprintf.c b/hardware/tools/stm8/lib/src/vprintf.c new file mode 100644 index 0000000..34a0488 --- /dev/null +++ b/hardware/tools/stm8/lib/src/vprintf.c @@ -0,0 +1,57 @@ +/*----------------------------------------------------------------- + vprintf.c - formatted output conversion + + Copyright (C) 1999, Martijn van Balen + Refactored by - Maarten Brock (2004) + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include +#include + +static void +put_char_to_stdout (char c, void* p) _REENTRANT +{ + p; //make compiler happy + putchar (c); +} + +int +vprintf (const char *format, va_list ap) +{ + return _print_format (put_char_to_stdout, NULL, format, ap); +} + +int +printf (const char *format, ...) +{ + va_list arg; + int i; + + va_start (arg, format); + i = _print_format (put_char_to_stdout, NULL, format, arg); + va_end (arg); + + return i; +} diff --git a/hardware/tools/stm8/lib/src/wcrtomb.c b/hardware/tools/stm8/lib/src/wcrtomb.c new file mode 100644 index 0000000..2464f9e --- /dev/null +++ b/hardware/tools/stm8/lib/src/wcrtomb.c @@ -0,0 +1,39 @@ +/*------------------------------------------------------------------------- + wcrtomb.c - convert a wide character to a multibyte sequence + + Copyright (C) 2016, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#include + +size_t wcrtomb(char *restrict s, wchar_t wc, mbstate_t *restrict ps) +{ + ps; + + return(wctomb(s, wc)); +} + diff --git a/hardware/tools/stm8/lib/src/wcscmp.c b/hardware/tools/stm8/lib/src/wcscmp.c new file mode 100644 index 0000000..0a4b7bc --- /dev/null +++ b/hardware/tools/stm8/lib/src/wcscmp.c @@ -0,0 +1,42 @@ +/*------------------------------------------------------------------------- + wcscmp.c - compare strings + + Copyright (C) 2016, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +int wcscmp(const wchar_t *s1, const wchar_t *s2) +{ + while(*s1 == *s2 && *s1) + s1++, s2++; + + if(*s1 < *s2) + return(-1); + if(*s1 > *s2) + return(1); + return(0); +} + diff --git a/hardware/tools/stm8/lib/src/wcslen.c b/hardware/tools/stm8/lib/src/wcslen.c new file mode 100644 index 0000000..1340319 --- /dev/null +++ b/hardware/tools/stm8/lib/src/wcslen.c @@ -0,0 +1,42 @@ +/*------------------------------------------------------------------------- + wcslen.c - compute the length of a string + + Copyright (C) 2016, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +size_t wcslen(const wchar_t *s) +{ + register size_t n = 0; + while (*s) + { + n++; + s++; + } + + return n; +} + diff --git a/hardware/tools/stm8/lib/src/wcstombs.c b/hardware/tools/stm8/lib/src/wcstombs.c new file mode 100644 index 0000000..39162b3 --- /dev/null +++ b/hardware/tools/stm8/lib/src/wcstombs.c @@ -0,0 +1,55 @@ +/*------------------------------------------------------------------------- + wctomb.c - convert a wide character string to a multibyte string + + Copyright (C) 2016, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#include + +size_t wcstombs(char *restrict s, const wchar_t *restrict pwcs, size_t n) +{ + size_t m = 0; + char buffer[MB_LEN_MAX]; + + while(n > MB_LEN_MAX || n >= wctomb(buffer, *pwcs)) + { + int b = wctomb(s, *pwcs); + + if(b == 1 && !*s) + break; + if(b < 0) + return(-1); + + n -= b; + m += b; + s += b; + pwcs++; + } + + return(m); +} + diff --git a/hardware/tools/stm8/lib/src/wctob.c b/hardware/tools/stm8/lib/src/wctob.c new file mode 100644 index 0000000..70364f3 --- /dev/null +++ b/hardware/tools/stm8/lib/src/wctob.c @@ -0,0 +1,41 @@ +/*------------------------------------------------------------------------- + wctob.c - convert a wide character to a single-byte character + + Copyright (C) 2016, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +#include + +_Static_assert(WEOF & 0xffffff80, "Invalid WEOF"); + +int wctob(wint_t c) +{ + if(c & 0xffffff80) + return WEOF; + return c; +} + diff --git a/hardware/tools/stm8/lib/src/wctomb.c b/hardware/tools/stm8/lib/src/wctomb.c new file mode 100644 index 0000000..274ae1a --- /dev/null +++ b/hardware/tools/stm8/lib/src/wctomb.c @@ -0,0 +1,67 @@ +/*------------------------------------------------------------------------- + wctomb.c - convert a wide character to a multibyte sequence + + Copyright (C) 2016, Philipp Klaus Krause, pkk@spth.de + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + + As a special exception, if you link this library with other files, + some of which are compiled with SDCC, to produce an executable, + this library does not by itself cause the resulting executable to + be covered by the GNU General Public License. This exception does + not however invalidate any other reasons why the executable file + might be covered by the GNU General Public License. +-------------------------------------------------------------------------*/ + +#include + +int wctomb(char *s, wchar_t wc) +{ + unsigned char n = 0; + + if(!s) + return(0); + + if(wc < 0x80) + { + s[0] = wc; + return(1); + } + else if(wc < 0x800) + { + s[0] = (wc >> 6) & 0x1f | 0xc0; + s[1] = (wc >> 0) & 0x3f | 0x80; + return(2); + } + else if(wc < 0x10000) + { + s[0] = (wc >> 12) & 0x0f | 0xe0; + s[1] = (wc >> 6) & 0x3f | 0x80; + s[2] = (wc >> 0) & 0x3f | 0x80; + return(3); + } + else if(wc < 0x110000) + { + s[0] = (wc >> 18) & 0x07 | 0xf0; + s[1] = (wc >> 12) & 0x3f | 0x80; + s[2] = (wc >> 6) & 0x3f | 0x80; + s[3] = (wc >> 0) & 0x3f | 0x80; + return(4); + } + else + return(-1); +} + diff --git a/hardware/tools/stm8/lib/stm8/stm8.lib b/hardware/tools/stm8/lib/stm8/stm8.lib new file mode 100644 index 0000000..c8d1da7 Binary files /dev/null and b/hardware/tools/stm8/lib/stm8/stm8.lib differ diff --git a/tools/bin/README.md b/tools/bin/README.md new file mode 100644 index 0000000..ced1d5f --- /dev/null +++ b/tools/bin/README.md @@ -0,0 +1,13 @@ +# Unix-like text utilities + +These binaries are taken from the +[MinGW/MSys](http://www.mingw.org/wiki/MSYS) project. They bring some +Unix-like functionality to Windows systems. + +All binaries are 32 bit versions. + + +## Usage + +Include this directory in your `PATH` or move these file into a directory +that is already included in your path. diff --git a/tools/bin/awk.exe b/tools/bin/awk.exe new file mode 100644 index 0000000..0512f9d Binary files /dev/null and b/tools/bin/awk.exe differ diff --git a/tools/bin/cat.exe b/tools/bin/cat.exe new file mode 100644 index 0000000..16a4687 Binary files /dev/null and b/tools/bin/cat.exe differ diff --git a/tools/bin/cut.exe b/tools/bin/cut.exe new file mode 100644 index 0000000..78c2c08 Binary files /dev/null and b/tools/bin/cut.exe differ diff --git a/tools/bin/dash.exe b/tools/bin/dash.exe new file mode 100644 index 0000000..0438a0a Binary files /dev/null and b/tools/bin/dash.exe differ diff --git a/tools/bin/expr.exe b/tools/bin/expr.exe new file mode 100644 index 0000000..33c572d Binary files /dev/null and b/tools/bin/expr.exe differ diff --git a/tools/bin/grep.exe b/tools/bin/grep.exe new file mode 100644 index 0000000..cbf11a1 Binary files /dev/null and b/tools/bin/grep.exe differ diff --git a/tools/bin/head.exe b/tools/bin/head.exe new file mode 100644 index 0000000..45af604 Binary files /dev/null and b/tools/bin/head.exe differ diff --git a/tools/bin/ls.exe b/tools/bin/ls.exe new file mode 100644 index 0000000..f180f43 Binary files /dev/null and b/tools/bin/ls.exe differ diff --git a/tools/bin/make.exe b/tools/bin/make.exe new file mode 100644 index 0000000..81452bc Binary files /dev/null and b/tools/bin/make.exe differ diff --git a/tools/bin/mkdir.exe b/tools/bin/mkdir.exe new file mode 100644 index 0000000..a000145 Binary files /dev/null and b/tools/bin/mkdir.exe differ diff --git a/tools/bin/msys-2.0.dll b/tools/bin/msys-2.0.dll new file mode 100644 index 0000000..023e9a9 Binary files /dev/null and b/tools/bin/msys-2.0.dll differ diff --git a/tools/bin/msys-gcc_s-1.dll b/tools/bin/msys-gcc_s-1.dll new file mode 100644 index 0000000..ade71fe Binary files /dev/null and b/tools/bin/msys-gcc_s-1.dll differ diff --git a/tools/bin/msys-gmp-10.dll b/tools/bin/msys-gmp-10.dll new file mode 100644 index 0000000..197d172 Binary files /dev/null and b/tools/bin/msys-gmp-10.dll differ diff --git a/tools/bin/msys-iconv-2.dll b/tools/bin/msys-iconv-2.dll new file mode 100644 index 0000000..3dc278b Binary files /dev/null and b/tools/bin/msys-iconv-2.dll differ diff --git a/tools/bin/msys-intl-8.dll b/tools/bin/msys-intl-8.dll new file mode 100644 index 0000000..7418c0a Binary files /dev/null and b/tools/bin/msys-intl-8.dll differ diff --git a/tools/bin/msys-mpfr-4.dll b/tools/bin/msys-mpfr-4.dll new file mode 100644 index 0000000..e8ca3fb Binary files /dev/null and b/tools/bin/msys-mpfr-4.dll differ diff --git a/tools/bin/msys-ncursesw6.dll b/tools/bin/msys-ncursesw6.dll new file mode 100644 index 0000000..70a2ce9 Binary files /dev/null and b/tools/bin/msys-ncursesw6.dll differ diff --git a/tools/bin/msys-pcre-1.dll b/tools/bin/msys-pcre-1.dll new file mode 100644 index 0000000..b950f0d Binary files /dev/null and b/tools/bin/msys-pcre-1.dll differ diff --git a/tools/bin/msys-readline6.dll b/tools/bin/msys-readline6.dll new file mode 100644 index 0000000..087834b Binary files /dev/null and b/tools/bin/msys-readline6.dll differ diff --git a/tools/bin/readline5.dll b/tools/bin/readline5.dll new file mode 100644 index 0000000..8287a21 Binary files /dev/null and b/tools/bin/readline5.dll differ diff --git a/tools/bin/sed.exe b/tools/bin/sed.exe new file mode 100644 index 0000000..c79b8ee Binary files /dev/null and b/tools/bin/sed.exe differ diff --git a/tools/bin/tr.exe b/tools/bin/tr.exe new file mode 100644 index 0000000..bef84e4 Binary files /dev/null and b/tools/bin/tr.exe differ diff --git a/tools/bin/uname.exe b/tools/bin/uname.exe new file mode 100644 index 0000000..9da019a Binary files /dev/null and b/tools/bin/uname.exe differ diff --git a/tools/bin/which.exe b/tools/bin/which.exe new file mode 100644 index 0000000..577f75e Binary files /dev/null and b/tools/bin/which.exe differ