summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorRobert de Bath <rdebath@poboxes.com>2005-01-23 15:31:04 +0100
committerLubomir Rintel <lkundrak@v3.sk>2013-10-23 23:48:50 +0200
commit62c27c1c5cb6257b13dfc9be0394e0d2e86f2735 (patch)
treef702b7e5f80293367e1b6f9812bd45e80378be26 /libc
parent6cb598cc5f1c8ae6d14381c2776338584368257e (diff)
downloaddev86-62c27c1c5cb6257b13dfc9be0394e0d2e86f2735.tar.gz
Import Dev86src-0.16.17.tar.gzv0.16.17
Diffstat (limited to 'libc')
-rw-r--r--libc/error/Makefile10
-rw-r--r--libc/i386fp/Makefile4
-rw-r--r--libc/i386fp/ecvt.c122
-rw-r--r--libc/i386sys/Makefile2
-rw-r--r--libc/i386sys/setjmp3.c56
-rw-r--r--libc/i386sys/syscall.dat140
-rw-r--r--libc/include/stdarg.h1
-rw-r--r--libc/include/stdlib.h2
-rw-r--r--libc/include/sys/cdefs.h2
-rw-r--r--libc/misc/Makefile2
-rw-r--r--libc/misc/atof.c16
-rw-r--r--libc/misc/strtod.c4
-rw-r--r--libc/stdio/Makefile2
-rw-r--r--libc/stdio/printf.c73
14 files changed, 415 insertions, 21 deletions
diff --git a/libc/error/Makefile b/libc/error/Makefile
index 01a488f..f604c3b 100644
--- a/libc/error/Makefile
+++ b/libc/error/Makefile
@@ -4,14 +4,16 @@
CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
-ifeq ($(PLATFORM),i86-FAST)
-OBJ=error.o sys_errlist.o perror.o sys_siglist.o __assert.o
-else
ifeq ($(LIB_OS),ELKS)
+
+ifneq ($(LIB_CPU),i86)
OBJ=error2.o perror.o sys_siglist.o __assert.o
else
-OBJ=__assert.o
+OBJ=error.o sys_errlist.o perror.o sys_siglist.o __assert.o
endif
+
+else
+OBJ=__assert.o
endif
all: $(LIBC)($(OBJ))
diff --git a/libc/i386fp/Makefile b/libc/i386fp/Makefile
index 298ca18..e26ce21 100644
--- a/libc/i386fp/Makefile
+++ b/libc/i386fp/Makefile
@@ -9,12 +9,12 @@ FPSRC =fadd.x fcomp.x fdiv.x fmul.x fbsr.x \
fperr.c fperror.x fptoi.x fpushd.x fpulld.x \
fpushi.x fpushf.x fpullf.x frexp.x ftst.x \
gcclib.x \
- fabs.x ldexp.x modf.c \
+ fabs.x ldexp.x ecvt.c \
fperr.h fplib.h
FPOBJ =fadd.o fcomp.o fdiv.o fmul.o fpbsr.o \
fperr.o fperror.o fptoi.o fpushd.o fpulld.o \
fpushi.o fpushf.o fpullf.o frexp.o ftst.o \
- fabs.o ldexp.o modf.o
+ fabs.o ldexp.o ecvt.o
LIB =.
CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
diff --git a/libc/i386fp/ecvt.c b/libc/i386fp/ecvt.c
new file mode 100644
index 0000000..6e0cef1
--- /dev/null
+++ b/libc/i386fp/ecvt.c
@@ -0,0 +1,122 @@
+
+#define DIGMAX 30 /* max # of digits in string */
+#define DIGPREC 17 /* max # of significant digits */
+#define ECVT 0
+#define FCVT 1
+static char digstr[DIGMAX + 1 + 1]; /* +1 for end of string */
+
+ /* +1 in case rounding adds */
+ /* another digit */
+static double negtab[] =
+ { 1e-256, 1e-128, 1e-64, 1e-32, 1e-16, 1e-8, 1e-4, 1e-2, 1e-1, 1.0 };
+static double postab[] =
+ { 1e+256, 1e+128, 1e+64, 1e+32, 1e+16, 1e+8, 1e+4, 1e+2, 1e+1 };
+
+static char *_cvt();
+
+/*************************
+ * Convert double val to a string of
+ * decimal digits.
+ * ndig = # of digits in resulting string
+ * Returns:
+ * *pdecpt = position of decimal point from left of first digit
+ * *psign = nonzero if value was negative
+ */
+char *
+ecvt(val, ndig, pdecpt, psign)
+double val;
+int ndig, *pdecpt, *psign;
+
+{
+ return _cvt(ECVT, val, ndig, pdecpt, psign);
+}
+
+char *
+fcvt(val, nfrac, pdecpt, psign)
+double val;
+int nfrac, *pdecpt, *psign;
+
+{
+ return _cvt(FCVT, val, nfrac, pdecpt, psign);
+}
+
+static char *
+_cvt(cnvflag, val, ndig, pdecpt, psign)
+double val;
+int ndig, *pdecpt, *psign;
+
+{
+ int decpt, pow, i;
+ char *p;
+ *psign = (val < 0) ? ((val = -val), 1) : 0;
+ ndig = (ndig < 0) ? 0 : (ndig < DIGMAX) ? ndig : DIGMAX;
+ if (val == 0) {
+ for (p = &digstr[0]; p < &digstr[ndig]; p++)
+ *p = '0';
+ decpt = 0;
+ } else {
+ /* Adjust things so that 1 <= val < 10 */
+ /* in these loops if val == MAXDOUBLE) */
+ decpt = 1;
+ pow = 256;
+ i = 0;
+ while (val < 1) {
+ while (val < negtab[i + 1]) {
+ val /= negtab[i];
+ decpt -= pow;
+ }
+ pow >>= 1;
+ i++;
+ }
+ pow = 256;
+ i = 0;
+ while (val >= 10) {
+ while (val >= postab[i]) {
+ val /= postab[i];
+ decpt += pow;
+ }
+ pow >>= 1;
+ i++;
+ }
+ if (cnvflag == FCVT) {
+ ndig += decpt;
+ ndig = (ndig < 0) ? 0 : (ndig < DIGMAX) ? ndig : DIGMAX;
+ }
+
+ /* Pick off digits 1 by 1 and stuff into digstr[] */
+ /* Do 1 extra digit for rounding purposes */
+ for (p = &digstr[0]; p <= &digstr[ndig]; p++) {
+ int n;
+
+ /* 'twould be silly to have zillions of digits */
+ /* when only DIGPREC are significant */
+ if (p >= &digstr[DIGPREC])
+ *p = '0';
+
+ else {
+ n = val;
+ *p = n + '0';
+ val = (val - n) * 10; /* get next digit */
+ }
+ }
+ if (*--p >= '5') { /* if we need to round */
+ while (1) {
+ if (p == &digstr[0]) { /* if at start */
+ ndig += cnvflag;
+ decpt++; /* shift dec pnt */
+ digstr[0] = '1'; /* "100000..." */
+ break;
+ }
+ *p = '0';
+ --p;
+ if (*p != '9') {
+ (*p)++;
+ break;
+ }
+ } /* while */
+ } /* if */
+ } /* else */
+ *pdecpt = decpt;
+ digstr[ndig] = 0; /* terminate string */
+ return &digstr[0];
+}
diff --git a/libc/i386sys/Makefile b/libc/i386sys/Makefile
index 756ce43..665f71a 100644
--- a/libc/i386sys/Makefile
+++ b/libc/i386sys/Makefile
@@ -12,7 +12,7 @@ DSRC=dirent.c
DOBJ=opendir.o closedir.o readdir.o
ifeq ($(LIB_CPU)-$(LIB_OS),i386-ELKS)
-OBJ=$(LOBJ3) $(LOBJ) $(EOBJ) $(DOBJ)
+OBJ=$(LOBJ3) $(LOBJ) $(EOBJ) $(DOBJ) setjmp3.o
SYSCALLS=syscalls
CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
diff --git a/libc/i386sys/setjmp3.c b/libc/i386sys/setjmp3.c
new file mode 100644
index 0000000..160795d
--- /dev/null
+++ b/libc/i386sys/setjmp3.c
@@ -0,0 +1,56 @@
+
+#include <setjmp.h>
+
+#if __AS386_32__
+
+int
+setjmp(env)
+jmp_buf env;
+{
+#asm
+export __setjmp
+__setjmp:
+
+ pop ecx ! PC
+#if __FIRST_ARG_IN_AX__
+ mov ebx,eax
+#else
+ mov ebx,esp
+ mov ebx,[ebx] ! TOS is prt -> env
+#endif
+ mov [ebx+0],ecx ! PC
+ mov [ebx+4],esp ! This registers are all that may be constant.
+ mov [ebx+8],ebp
+ mov [ebx+12],esi ! Is saving these the "right thing" ?
+ mov [ebx+16],edi
+ xor eax,eax
+ jmp ecx
+#endasm
+}
+
+void
+longjmp(env, rv)
+jmp_buf env;
+int rv;
+{
+#asm
+export __longjmp
+__longjmp:
+
+ pop ecx ! pc
+#if __FIRST_ARG_IN_AX__
+ mov ebx,eax ! env->
+#else
+ pop ebx ! env->
+#endif
+ pop eax ! rv
+ mov ecx,[ebx+0] ! PC
+ mov esp,[ebx+4]
+ mov ebp,[ebx+8]
+ mov esi,[ebx+12]
+ mov edi,[ebx+16]
+ jmp ecx
+#endasm
+}
+
+#endif
diff --git a/libc/i386sys/syscall.dat b/libc/i386sys/syscall.dat
index da9ad6c..595e75a 100644
--- a/libc/i386sys/syscall.dat
+++ b/libc/i386sys/syscall.dat
@@ -1,4 +1,3 @@
-
#
# Name No Args Flag, comment
#
@@ -6,6 +5,8 @@
# * = Needs libc code (Prefix __)
# - = Obsolete/not required
#
+# Last updated 2005-01-01
+#
# Name N C
setup 0 X
exit 1 1 *
@@ -60,7 +61,7 @@ signal 48 2
geteuid 49 0
getegid 50 0
acct 51 1
-phys 52 X -
+umount2 52 X -
lock 53 X -
ioctl 54 3
fcntl 55 3
@@ -111,7 +112,7 @@ statfs 99 2
fstatfs 100 2
ioperm 101 3
socketcall 102 2 * This is a lib internal for socket stuff
-klog 103 X
+syslog 103 X
setitimer 104 3
getitimer 105 2
dv32_stat 106 2 * Has correct args for 32 bit dev_t
@@ -121,7 +122,7 @@ olduname 109 X -
iopl 110 1
vhangup 111 0
idle 112 0 - System internal
-vm86 113 1
+vm86 113 1 * WARNING now vm86old
wait4 114 4
swapoff 115 1
sysinfo 116 1
@@ -152,4 +153,133 @@ _llseek 140 X
getdents 141 3 * New style readdir ?
_newselect 142 X
flock 143 2
-syscall_flock 143 X
+msync 144 X
+readv 145 X
+writev 146 X
+getsid 147 X
+fdatasync 148 X
+_sysctl 149 X
+mlock 150 X
+munlock 151 X
+mlockall 152 X
+munlockall 153 X
+sched_setparam 154 X
+sched_getparam 155 X
+sched_setscheduler 156 X
+sched_getscheduler 157 X
+sched_yield 158 X
+sched_get_priority_max 159 X
+sched_get_priority_min 160 X
+sched_rr_get_interval 161 X
+nanosleep 162 2
+mremap 163 X
+setresuid 164 X
+getresuid 165 X
+vm86 166 X
+query_module 167 X
+poll 168 X
+nfsservctl 169 X
+setresgid 170 X
+getresgid 171 X
+prctl 172 X
+rt_sigreturn 173 X
+rt_sigaction 174 X
+rt_sigprocmask 175 X
+rt_sigpending 176 X
+rt_sigtimedwait 177 X
+rt_sigqueueinfo 178 X
+rt_sigsuspend 179 X
+pread64 180 X
+pwrite64 181 X
+chown 182 X
+getcwd 183 X
+capget 184 X
+capset 185 X
+sigaltstack 186 X
+sendfile 187 X
+getpmsg 188 X
+putpmsg 189 X
+vfork 190 X
+ugetrlimit 191 X
+mmap2 192 X
+truncate64 193 X
+ftruncate64 194 X
+stat64 195 X
+lstat64 196 X
+fstat64 197 X
+lchown32 198 X
+getuid32 199 X
+getgid32 200 X
+geteuid32 201 X
+getegid32 202 X
+setreuid32 203 X
+setregid32 204 X
+getgroups32 205 X
+setgroups32 206 X
+fchown32 207 X
+setresuid32 208 X
+getresuid32 209 X
+setresgid32 210 X
+getresgid32 211 X
+chown32 212 X
+setuid32 213 X
+setgid32 214 X
+setfsuid32 215 X
+setfsgid32 216 X
+pivot_root 217 X
+mincore 218 X
+madvise 219 X
+madvise1 219 X
+getdents64 220 X
+fcntl64 221 X
+Unused 223 X - /* is unused */
+gettid 224 X
+readahead 225 X
+setxattr 226 X
+lsetxattr 227 X
+fsetxattr 228 X
+getxattr 229 X
+lgetxattr 230 X
+fgetxattr 231 X
+listxattr 232 X
+llistxattr 233 X
+flistxattr 234 X
+removexattr 235 X
+lremovexattr 236 X
+fremovexattr 237 X
+tkill 238 X
+sendfile64 239 X
+futex 240 X
+sched_setaffinity 241 X
+sched_getaffinity 242 X
+set_thread_area 243 X
+get_thread_area 244 X
+io_setup 245 X
+io_destroy 246 X
+io_getevents 247 X
+io_submit 248 X
+io_cancel 249 X
+fadvise64 250 X
+Unused 251 X - /* is unused */
+exit_group 252 X
+lookup_dcookie 253 X
+epoll_create 254 X
+epoll_ctl 255 X
+epoll_wait 256 X
+remap_file_pages 257 X
+set_tid_address 258 X
+timer_create 259 X
+timer_settime (__NR_timer_create+1) X
+timer_gettime (__NR_timer_create+2) X
+timer_getoverrun (__NR_timer_create+3) X
+timer_delete (__NR_timer_create+4) X
+clock_settime (__NR_timer_create+5) X
+clock_gettime (__NR_timer_create+6) X
+clock_getres (__NR_timer_create+7) X
+clock_nanosleep (__NR_timer_create+8) X
+statfs64 268 X
+fstatfs64 269 X
+tgkill 270 X
+utimes 271 X
+fadvise64_64 272 X
+vserver 273 X
diff --git a/libc/include/stdarg.h b/libc/include/stdarg.h
index f5f6fbf..c5fcfac 100644
--- a/libc/include/stdarg.h
+++ b/libc/include/stdarg.h
@@ -26,6 +26,7 @@
#ifndef __STDARG_H
#define __STDARG_H
+#include <features.h>
#ifdef sparc
# define _VA_ALIST_ "__builtin_va_alist"
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
index aeb7a43..11699ca 100644
--- a/libc/include/stdlib.h
+++ b/libc/include/stdlib.h
@@ -24,10 +24,10 @@ extern unsigned long strtoul __P ((const char * nptr,
char ** endptr, int base));
#ifndef __HAS_NO_FLOATS__
extern double strtod __P ((const char * nptr, char ** endptr));
+extern double atof __P ((__const char *__nptr));
#endif
extern long int atol __P ((__const char *__nptr));
-extern double atof __P ((__const char *__nptr));
extern int atoi __P ((__const char *__nptr));
/* Returned by `div'. */
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index ce975f0..bf41935 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -10,7 +10,9 @@
/* This is not a typedef so `const __ptr_t' does the right thing. */
#define __ptr_t void *
+#ifndef __HAS_NO_FLOATS__
typedef long double __long_double_t;
+#endif
#else
diff --git a/libc/misc/Makefile b/libc/misc/Makefile
index b779802..85614a7 100644
--- a/libc/misc/Makefile
+++ b/libc/misc/Makefile
@@ -27,7 +27,7 @@ endif
# No ELKS strtod() until BCC does 16 bit FP...
ifneq ($(LIB_CPU),i86)
-OBJ+=strtod.o
+OBJ+=strtod.o atof.o
endif
CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
diff --git a/libc/misc/atof.c b/libc/misc/atof.c
new file mode 100644
index 0000000..aeadaa5
--- /dev/null
+++ b/libc/misc/atof.c
@@ -0,0 +1,16 @@
+/* Copyright (C) Robert de Bath <robert@debath.co.uk>
+ * This file is part of the Linux-8086 C library and is distributed
+ * under the GNU Library General Public License.
+ */
+
+double
+#ifdef __STDC__
+atof(const char *p)
+#else
+atof(p)
+char *p;
+#endif
+{
+ return strtod(p, (char**)0);
+}
+
diff --git a/libc/misc/strtod.c b/libc/misc/strtod.c
index cef9d9f..8acb423 100644
--- a/libc/misc/strtod.c
+++ b/libc/misc/strtod.c
@@ -20,9 +20,6 @@
#include <stdlib.h>
#include <ctype.h>
-#ifndef __AS386_16__
-/* BCC-16 has broken FP code */
-
double
strtod(const char *nptr, char ** endptr)
{
@@ -97,4 +94,3 @@ strtod(const char *nptr, char ** endptr)
}
return (negative ? -number:number);
}
-#endif
diff --git a/libc/stdio/Makefile b/libc/stdio/Makefile
index 3c85f40..221ad8f 100644
--- a/libc/stdio/Makefile
+++ b/libc/stdio/Makefile
@@ -12,7 +12,7 @@ AOBJ=_stdio_init.o fputc.o fgetc.o fflush.o fgets.o gets.o fputs.o \
fclose.o fseek.o rewind.o ftell.o setbuffer.o setvbuf.o ungetc.o
PSRC=printf.c
-POBJ=printf.o sprintf.o fprintf.o vprintf.o vsprintf.o vfprintf.o
+POBJ=printf.o sprintf.o fprintf.o vprintf.o vsprintf.o vfprintf.o fp_print.o
SSRC=scanf.c
SOBJ=scanf.o sscanf.o fscanf.o vscanf.o vsscanf.o vfscanf.o
diff --git a/libc/stdio/printf.c b/libc/stdio/printf.c
index 6e7b3e1..b7b0b81 100644
--- a/libc/stdio/printf.c
+++ b/libc/stdio/printf.c
@@ -129,7 +129,7 @@ static FILE string[1] =
#ifdef L_vfprintf
-#ifdef FLOATS
+#ifndef __HAS_NO_FLOATS__
int (*__fp_print)() = 0;
#endif
@@ -344,7 +344,7 @@ register va_list ap;
sign, pad, width, preci, buffer_mode);
break;
-#if FLOATS
+#ifndef __HAS_NO_FLOATS__
case 'e': /* float */
case 'f':
case 'g':
@@ -378,3 +378,72 @@ register va_list ap;
return (cnt);
}
#endif
+
+#ifdef L_fp_print
+#ifndef __HAS_NO_FLOATS__
+
+#ifdef __AS386_16__
+#asm
+ loc 1 ! Make sure the pointer is in the correct segment
+auto_func: ! Label for bcc -M to work.
+ .word ___xfpcvt ! Pointer to the autorun function
+ .text ! So the function after is also in the correct seg.
+#endasm
+#endif
+
+#ifdef __AS386_32__
+#asm
+ loc 1 ! Make sure the pointer is in the correct segment
+auto_func: ! Label for bcc -M to work.
+ .long ___xfpcvt ! Pointer to the autorun function
+ .text ! So the function after is also in the correct seg.
+#endasm
+#endif
+
+void
+__fp_print_func(pval, style, preci, ptmp)
+ double * pval;
+ int style;
+ int preci;
+ char * ptmp;
+{
+ int decpt, negative;
+ char * cvt;
+ double val = *pval;
+
+ if (preci < 0) preci = 6;
+
+ cvt = fcvt(val, preci, &decpt, &negative);
+ if(negative)
+ *ptmp++ = '-';
+
+ if (decpt<0) {
+ *ptmp++ = '0';
+ *ptmp++ = '.';
+ while(decpt<0) {
+ *ptmp++ = '0'; decpt++;
+ }
+ }
+
+ while(*cvt) {
+ *ptmp++ = *cvt++;
+ if (decpt == 1)
+ *ptmp++ = '.';
+ decpt--;
+ }
+
+ while(decpt > 0) {
+ *ptmp++ = '0';
+ decpt--;
+ }
+}
+
+void
+__xfpcvt()
+{
+ extern int (*__fp_print)();
+ __fp_print = __fp_print_func;
+}
+
+#endif
+#endif