diff --git a/cross.mk b/cross.mk old mode 100644 new mode 100755 diff --git a/include/ieee.h b/include/ieee.h new file mode 100644 index 0000000..56ea4ec --- /dev/null +++ b/include/ieee.h @@ -0,0 +1,47 @@ +typedef union // LITTLE ENDIAN +{ + double value; + struct + { + unsigned long lsw; + unsigned long msw; + } parts; +} ieee_double_shape_type; + +/* Get two 32 bit ints from a double. */ + +#define EXTRACT_WORDS(ix0,ix1,d) \ +do { \ + ieee_double_shape_type ew_u; \ + ew_u.value = (d); \ + (ix0) = ew_u.parts.msw; \ + (ix1) = ew_u.parts.lsw; \ +} while (0) + +/* Get the more significant 32 bit int from a double. */ + +#define GET_HIGH_WORD(i,d) \ +do { \ + ieee_double_shape_type gh_u; \ + gh_u.value = (d); \ + (i) = gh_u.parts.msw; \ +} while (0) + +/* Set a double from two 32 bit ints. */ + +#define INSERT_WORDS(d,ix0,ix1) \ +do { \ + ieee_double_shape_type iw_u; \ + iw_u.parts.msw = (ix0); \ + iw_u.parts.lsw = (ix1); \ + (d) = iw_u.value; \ +} while (0) + +#define SET_HIGH_WORD(d,v) \ +do { \ + ieee_double_shape_type sh_u; \ + sh_u.value = (d); \ + sh_u.parts.msw = (v); \ + (d) = sh_u.value; \ +} while (0) + diff --git a/include/math.h b/include/math.h index 666123d..626f0e4 100644 --- a/include/math.h +++ b/include/math.h @@ -12,8 +12,9 @@ extern double sinh(), cosh(), tanh(); extern double gamma(); extern double j0(), j1(), jn(), y0(), y1(), yn(); -#define HUGE 1.701411733192644270e38 -#define LOGHUGE 39 +// ###PITO #define HUGE 1.701411733192644270e38 +#define HUGE 1.79769313486231570000e+308 +#define LOGHUGE 307 int isnanf(float x); int isnan(double x); diff --git a/include/stdarg.h b/include/stdarg.h index 27ffdda..b66ebb7 100644 --- a/include/stdarg.h +++ b/include/stdarg.h @@ -22,8 +22,8 @@ #define va_copy(dest, src) __builtin_va_copy((dest), (src)) -#ifndef _VA_LIST_T -#define _VA_LIST_T +#ifndef _VA_LIST +#define _VA_LIST #ifdef __GNUC__ typedef __builtin_va_list va_list; #endif diff --git a/lib/Makefile b/lib/Makefile old mode 100644 new mode 100755 diff --git a/src/libc/compat/Makefile b/src/libc/compat/Makefile old mode 100644 new mode 100755 diff --git a/src/libc/gen/Makefile b/src/libc/gen/Makefile old mode 100644 new mode 100755 index f6ceacd..254fd60 --- a/src/libc/gen/Makefile +++ b/src/libc/gen/Makefile @@ -19,7 +19,7 @@ STDSRC = abort.c alarm.c atof.c atoi.c atol.c calloc.c closedir.c crypt.c \ getpass.c getpwent.c getloadavg.c getmntinfo.c \ getttyent.c getttynam.c getusershell.c getwd.c \ initgroups.c isatty.c isinff.c isnanf.c ldexp.c malloc.c mktemp.c \ - modff.c ndbm.c nlist.c knlist.c opendir.c perror.c popen.c \ + modff.c modf.c ndbm.c nlist.c knlist.c opendir.c perror.c popen.c \ psignal.c qsort.c random.c readdir.c regex.c scandir.c \ seekdir.c setmode.c sethostname.c setenv.c siglist.c \ signal.c siginterrupt.c sigsetops.c \ @@ -36,7 +36,7 @@ STDOBJ = abort.o alarm.o atof.o atoi.o atol.o calloc.o closedir.o crypt.o \ getpass.o getpwent.o getloadavg.o getmntinfo.o \ getttyent.o getttynam.o getusershell.o getwd.o \ initgroups.o isatty.o isinff.o isnanf.o ldexp.o malloc.o mktemp.o \ - modff.o ndbm.o nlist.o knlist.o opendir.o perror.o popen.o \ + modff.o modf.o ndbm.o nlist.o knlist.o opendir.o perror.o popen.o \ psignal.o qsort.o random.o readdir.o regex.o scandir.o \ seekdir.o setmode.o sethostname.o setenv.o siglist.o \ signal.o siginterrupt.o sigsetops.o \ diff --git a/src/libc/gen/isinff.c b/src/libc/gen/isinff.c index 1755a65..8bba21f 100644 --- a/src/libc/gen/isinff.c +++ b/src/libc/gen/isinff.c @@ -27,4 +27,4 @@ int isinff (float x) /* * For PIC32, double is the same as float. */ -int isinf (double x) __attribute__((alias ("isinff"))); +//int isinf (double x) __attribute__((alias ("isinff"))); diff --git a/src/libc/gen/isnanf.c b/src/libc/gen/isnanf.c index dda3938..c54ba7c 100644 --- a/src/libc/gen/isnanf.c +++ b/src/libc/gen/isnanf.c @@ -27,4 +27,4 @@ int isnanf (float x) /* * For PIC32, double is the same as float. */ -int isnan (double x) __attribute__((alias ("isnanf"))); +//int isnan (double x) __attribute__((alias ("isnanf"))); diff --git a/src/libc/gen/ldexp.c b/src/libc/gen/ldexp.c index 46c1807..858d570 100644 --- a/src/libc/gen/ldexp.c +++ b/src/libc/gen/ldexp.c @@ -1,46 +1,46 @@ #include +#include + +static const double +two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ +twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */ +huge = 1.0e+308, +tiny = 1.0e-307; + +static double +_copysign(double x, double y) +{ + unsigned long hx,hy; + GET_HIGH_WORD(hx,x); + GET_HIGH_WORD(hy,y); + SET_HIGH_WORD(x,(hx&0x7fffffff)|(hy&0x80000000)); + return x; +} double -ldexp(fr, exp) - double fr; - int exp; +ldexp(double x, int n) { - double huge = 1.701411834604692293e38; - int neg; - int i; - - neg = 0; - if (fr < 0) { - fr = -fr; - neg = 1; + unsigned long k,hx,lx; + EXTRACT_WORDS(hx,lx,x); + k = (hx&0x7ff00000)>>20; /* extract exponent */ + if (k==0) { /* 0 or subnormal x */ + if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */ + x *= two54; + GET_HIGH_WORD(hx,x); + k = ((hx&0x7ff00000)>>20) - 54; + if (n< -50000) return tiny*x; /*underflow*/ + } + if (k==0x7ff) return x+x; /* NaN or Inf */ + k = k+n; + if (k > 0x7fe) return huge*_copysign(huge,x); /* overflow */ + if (k > 0) /* normal result */ + {SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); return x;} + if (k <= -54) { + if (n > 50000) /* in case integer overflow in n+k */ + return huge*_copysign(huge,x); /*overflow*/ + else return tiny*_copysign(tiny,x); /*underflow*/ } - fr = frexp(fr, &i); - while (fr < 0.5) { - fr = 2*fr; - i = i-1; - } - exp = exp+i; - if (exp > 127) { - if (neg) - return(-huge); - else - return(huge); - } - if (exp < -127) - return(0); - while (exp > 30) { - fr = fr*(1L<<30); - exp = exp-30; - } - while (exp < -30) { - fr = fr/(1L<<30); - exp = exp+30; - } - if (exp > 0) - fr = fr*(1L< - -/* Get two 32 bit ints from a double. */ - -#define EXTRACT_WORDS(high,low,d) \ - high = *(unsigned long long*) &d; \ - low = (*(unsigned long long*) &d) >> 32 - - -/* Set a double from two 32 bit ints. */ - -#define INSERT_WORDS(d,high,low) \ - *(unsigned long long*) &(x) = (unsigned long long) (high) << 32 | (low) +#include /* * modf(double x, double *iptr) @@ -37,10 +26,12 @@ double modf (double x, double *iptr) unsigned long i; EXTRACT_WORDS (i0, i1, x); + // j0 = ((i0 >> 20) & 0x7ff) - 0x3ff; /* exponent of x */ if (j0 < 20) { /* integer part in high x */ if (j0 < 0) { /* |x|<1 */ INSERT_WORDS (*iptr, i0 & 0x80000000, 0); + // /* *iptr = +-0 */ return x; } else { @@ -48,10 +39,12 @@ double modf (double x, double *iptr) if (((i0 & i) | i1) == 0) { /* x is integral */ *iptr = x; INSERT_WORDS (x, i0 & 0x80000000, 0); + // /* return +-0 */ return x; } else { INSERT_WORDS (*iptr, i0 & (~i), 0); + // return x - *iptr; } } @@ -62,6 +55,7 @@ double modf (double x, double *iptr) return x * one; INSERT_WORDS (x, i0 & 0x80000000, 0); + // /* return +-0 */ return x; } else { /* fraction part in low x */ @@ -69,10 +63,12 @@ double modf (double x, double *iptr) if ((i1 & i) == 0) { /* x is integral */ *iptr = x; INSERT_WORDS (x, i0 & 0x80000000, 0); + // /* return +-0 */ return x; } else { INSERT_WORDS (*iptr, i0, i1 & (~i)); + // return x - *iptr; } } diff --git a/src/libc/gen/modff.c b/src/libc/gen/modff.c index 7eeac60..41a5d94 100644 --- a/src/libc/gen/modff.c +++ b/src/libc/gen/modff.c @@ -52,4 +52,4 @@ float modff (float fx, float *iptr) /* * For PIC32, double is the same as float. */ -double modf (double x, double *iptr) __attribute__((alias ("modff"))); +//double modf (double x, double *iptr) __attribute__((alias ("modff"))); diff --git a/src/libc/gen/ndbm.c b/src/libc/gen/ndbm.c old mode 100644 new mode 100755 diff --git a/src/libc/mips/sys/Makefile b/src/libc/mips/sys/Makefile old mode 100644 new mode 100755 diff --git a/src/libc/stdio/Makefile b/src/libc/stdio/Makefile old mode 100644 new mode 100755 diff --git a/src/libc/stdio/doprnt.c b/src/libc/stdio/doprnt.c index eea7f09..7cc4bf6 100644 --- a/src/libc/stdio/doprnt.c +++ b/src/libc/stdio/doprnt.c @@ -42,7 +42,9 @@ #include /* Max number conversion buffer length: a long in base 2, plus NUL byte. */ -#define MAXNBUF (sizeof(long) * 8 + 1) +//#define MAXNBUF (sizeof(long) * 8 + 1) +/* Max number conversion buffer length: MAXEXP(308) + MAXFRACTION(15) + 2 */ +#define MAXNBUF 308+15+2 static unsigned char *ksprintn (unsigned char *buf, unsigned long v, unsigned char base, int width, unsigned char *lp); @@ -61,6 +63,8 @@ _doprnt (char const *fmt, va_list ap, FILE *stream) int n, width, dwidth, retval, uppercase, extrazeros, sign; unsigned long ul; + double d; + if (! stream) return 0; if (! fmt) @@ -361,7 +365,11 @@ number: if (sign && ((long) ul != 0L)) { case 'F': case 'g': case 'G': { - double d = va_arg (ap, double); + + // ---va_arg alignment fix + d = va_arg(ap, double); + // --- + /* * don't do unrealistic precision; just pad it with * zeroes later, so buffer size stays rational. @@ -583,10 +591,11 @@ cvt (double number, int prec, int sharpflag, unsigned char *negp, unsigned char * get integer portion of number; put into the end of the buffer; the * .01 is added for modf (356.0 / 10, &integer) returning .59999999... */ - for (p = endp - 1; integer; ++expcnt) { - tmp = modf (integer / 10, &integer); - *p-- = (int) ((tmp + .01) * 10) + '0'; - } + p = endp - 1; + for (; integer && p >= startp; ++expcnt) { + tmp = modf(integer * 0.1L , &integer); + *p-- = (int)((tmp + .01L) * 10) + '0'; + } switch (fmtch) { case 'f': /* reverse integer into beginning of buffer */ diff --git a/src/libc/stdio/doscan.c b/src/libc/stdio/doscan.c index c596612..ee73363 100644 --- a/src/libc/stdio/doscan.c +++ b/src/libc/stdio/doscan.c @@ -1,6 +1,10 @@ #include #include #include +#include +#include + +#define HAVE_FLOAT 1 #define SPC 01 #define STP 02 diff --git a/src/libc/stdlib/Makefile b/src/libc/stdlib/Makefile old mode 100644 new mode 100755 diff --git a/src/libc/string/Makefile b/src/libc/string/Makefile index d1fc06b..40daeec 100644 --- a/src/libc/string/Makefile +++ b/src/libc/string/Makefile @@ -7,7 +7,7 @@ TOPSRC = $(shell cd ../../..; pwd) include $(TOPSRC)/target.mk DEFS = -CFLAGS += ${DEFS} -Os +CFLAGS += ${DEFS} SRCS = strcspn.c strpbrk.c strerror.c strsep.c strspn.c strstr.c strtok.c strtok_r.c OBJS = strcspn.o strpbrk.o strerror.o strsep.o strspn.o strstr.o strtok.o strtok_r.o diff --git a/src/libm/asin.c b/src/libm/asin.c index 8373f93..23da206 100644 --- a/src/libm/asin.c +++ b/src/libm/asin.c @@ -39,15 +39,17 @@ asin(arg) double acos(arg) - double arg; +double arg; { - if(arg < 0) - arg = -arg; + double sign = 1.0; + if(arg < 0.0){ + arg = -arg; + sign = -1.0; + } + if(arg > 1.0){ + errno = EDOM; + return(0.0); + } - if(arg > 1.){ - errno = EDOM; - return(0.); - } - - return(pio2 - asin(arg)); -} + return(pio2 - sign*asin(arg)); +} diff --git a/src/libm/atan.c b/src/libm/atan.c index a249167..8ecbea9 100644 --- a/src/libm/atan.c +++ b/src/libm/atan.c @@ -13,7 +13,7 @@ */ #include -double static sq2p1 =2.414213562373095048802e0; +static double sq2p1 =2.414213562373095048802e0; static double sq2m1 = .414213562373095048802e0; static double pio2 =1.570796326794896619231e0; static double pio4 = .785398163397448309615e0; diff --git a/src/libm/ieee.h b/src/libm/ieee.h index 20a8eee..56ea4ec 100644 --- a/src/libm/ieee.h +++ b/src/libm/ieee.h @@ -1,23 +1,47 @@ -/* Get two 32 bit ints from a double. */ - -#define EXTRACT_WORDS(high,low,d) \ - high = *(unsigned long long*) &d; \ - low = (*(unsigned long long*) &d) >> 32 - - -/* Set a double from two 32 bit ints. */ - -#define INSERT_WORDS(d,high,low) \ - *(unsigned long long*) &(x) = (unsigned long long) (high) << 32 | (low) - - -typedef union +typedef union // LITTLE ENDIAN { double value; struct { - uint32_t lsw; - uint32_t msw; + unsigned long lsw; + unsigned long msw; } parts; } ieee_double_shape_type; +/* Get two 32 bit ints from a double. */ + +#define EXTRACT_WORDS(ix0,ix1,d) \ +do { \ + ieee_double_shape_type ew_u; \ + ew_u.value = (d); \ + (ix0) = ew_u.parts.msw; \ + (ix1) = ew_u.parts.lsw; \ +} while (0) + +/* Get the more significant 32 bit int from a double. */ + +#define GET_HIGH_WORD(i,d) \ +do { \ + ieee_double_shape_type gh_u; \ + gh_u.value = (d); \ + (i) = gh_u.parts.msw; \ +} while (0) + +/* Set a double from two 32 bit ints. */ + +#define INSERT_WORDS(d,ix0,ix1) \ +do { \ + ieee_double_shape_type iw_u; \ + iw_u.parts.msw = (ix0); \ + iw_u.parts.lsw = (ix1); \ + (d) = iw_u.value; \ +} while (0) + +#define SET_HIGH_WORD(d,v) \ +do { \ + ieee_double_shape_type sh_u; \ + sh_u.value = (d); \ + sh_u.parts.msw = (v); \ + (d) = sh_u.value; \ +} while (0) + diff --git a/sys/include/signal.h b/sys/include/signal.h index 475dd43..119608d 100644 --- a/sys/include/signal.h +++ b/sys/include/signal.h @@ -113,6 +113,7 @@ struct sigstack { struct sigcontext { int sc_onstack; /* sigstack state to restore */ long sc_mask; /* signal mask to restore */ + int sc_align[2]; /* align to 16 bytes */ int sc_r1; /* r1 to restore */ int sc_r2; /* and other registers */ int sc_r3; diff --git a/sys/kernel/kern_exec.c b/sys/kernel/kern_exec.c old mode 100644 new mode 100755 index 18cfbbf..ee9d404 --- a/sys/kernel/kern_exec.c +++ b/sys/kernel/kern_exec.c @@ -432,7 +432,7 @@ badarg: */ ucp = USER_DATA_END - nc - NBPW; ap = ucp - na*NBPW - 2*NBPW; - u.u_frame [FRAME_SP] = ap - 16; + u.u_frame [FRAME_SP] = (ap - 16) & ~0xf; /* align to 16 bytes */ u.u_frame [FRAME_R4] = na - ne; /* $a0 := argc */ u.u_frame [FRAME_R5] = ap; /* $a1 := argv */ u.u_frame [FRAME_R6] = ap + (na-ne+1)*NBPW; /* $a2 := env */ diff --git a/sys/pic32/Makefile b/sys/pic32/Makefile index d06a76f..f5322cf 100644 --- a/sys/pic32/Makefile +++ b/sys/pic32/Makefile @@ -5,8 +5,7 @@ SUBDIR = baremetal dip duinomite duinomite-uart duinomite-e \ duinomite-e-uart explorer16 max32 max32-eth maximite \ meb pinguino-micro starter-kit ubw32 ubw32-uart \ ubw32-uart-sdram baremetal fubarino fubarino-uart \ - fubarino-uart-sramc mmb-mx7 maximite-color \ - 32mxsdram-uart + fubarino-uart-sramc mmb-mx7 maximite-color 32mxsdram-uart default: diff --git a/sys/pic32/float.h b/sys/pic32/float.h index 3888d80..c5d7980 100644 --- a/sys/pic32/float.h +++ b/sys/pic32/float.h @@ -24,19 +24,29 @@ * The values are dependant upon the presence of the -fno-short-double * compiler option. */ -#define DBL_EPSILON FLT_EPSILON -#define DBL_MAX FLT_MAX -#define DBL_MIN FLT_MIN -#define DBL_DIG FLT_DIG -#define DBL_MANT_DIG FLT_MANT_DIG -#define DBL_MAX_10_EXP FLT_MAX_10_EXP -#define DBL_MAX_EXP FLT_MAX_EXP -#define DBL_MIN_10_EXP FLT_MIN_10_EXP -#define DBL_MIN_EXP FLT_MIN_EXP +//#define DBL_EPSILON FLT_EPSILON +//#define DBL_MAX FLT_MAX +//#define DBL_MIN FLT_MIN +//#define DBL_DIG FLT_DIG +//#define DBL_MANT_DIG FLT_MANT_DIG +//#define DBL_MAX_10_EXP FLT_MAX_10_EXP +//#define DBL_MAX_EXP FLT_MAX_EXP +//#define DBL_MIN_10_EXP FLT_MIN_10_EXP +//#define DBL_MIN_EXP FLT_MIN_EXP /* * These values provide information pertaining to the long double type. */ +#define DBL_EPSILON 2.2204460492503131E-16 +#define DBL_MAX 1.7976931348623157E+308 +#define DBL_MIN 2.2250738585072014E-308 +#define DBL_DIG 15 +#define DBL_MANT_DIG 53 +#define DBL_MAX_10_EXP 308 +#define DBL_MAX_EXP 1024 +#define DBL_MIN_10_EXP (-307) +#define DBL_MIN_EXP (-1021) + #define LDBL_EPSILON 2.2204460492503131E-16 #define LDBL_MAX 1.7976931348623157E+308 #define LDBL_MIN 2.2250738585072014E-308 diff --git a/sys/pic32/gcc-config.mk b/sys/pic32/gcc-config.mk old mode 100644 new mode 100755 diff --git a/sys/pic32/kernel-post.mk b/sys/pic32/kernel-post.mk old mode 100644 new mode 100755 diff --git a/target.mk b/target.mk old mode 100644 new mode 100755 index 00e3c49..effea0a --- a/target.mk +++ b/target.mk @@ -34,8 +34,8 @@ ifndef GCCPREFIX INCLUDES = endif -CC = $(GCCPREFIX)gcc -mips32r2 -EL -msoft-float -nostdinc -fshort-double -I$(TOPSRC)/include $(INCLUDES) -CXX = $(GCCPREFIX)g++ -mips32r2 -EL -msoft-float -nostdinc -fshort-double -I$(TOPSRC)/include $(INCLUDES) +CC = $(GCCPREFIX)gcc -mips32r2 -EL -msoft-float -fno-short-double -nostdinc -I$(TOPSRC)/include $(INCLUDES) +CXX = $(GCCPREFIX)g++ -mips32r2 -EL -msoft-float -fno-short-double -nostdinc -I$(TOPSRC)/include $(INCLUDES) LD = $(GCCPREFIX)ld AR = $(GCCPREFIX)ar RANLIB = $(GCCPREFIX)ranlib @@ -50,7 +50,7 @@ TAGSFILE = tags MANROFF = nroff -man -h -Tascii ELF2AOUT = $(TOPSRC)/tools/elf2aout/elf2aout -CFLAGS = -O +CFLAGS = -O LDFLAGS += -N -nostartfiles -fno-dwarf2-cfi-asm -T$(TOPSRC)/src/elf32-mips.ld \ $(TOPSRC)/src/crt0.o -L$(TOPSRC)/src