summaryrefslogtreecommitdiff
path: root/libc/bcc
diff options
context:
space:
mode:
authorRobert de Bath <rdebath@poboxes.com>1996-11-03 22:33:35 +0100
committerLubomir Rintel <lkundrak@v3.sk>2013-10-23 23:33:35 +0200
commitc218c617b5be443b7968308506969ad2b726d73c (patch)
tree0051f396af56133d24fcf2ab757fabc78c1a09bf /libc/bcc
parent0936b9aeab611665645a4e6bafaded7ca76dd189 (diff)
parent0d2fbe9b1bd284ce2cad55be17e8f2c896031a25 (diff)
downloaddev86-c218c617b5be443b7968308506969ad2b726d73c.tar.gz
Import Dev86src-0.0.8.tar.gzv0.0.8
Diffstat (limited to 'libc/bcc')
-rw-r--r--libc/bcc/Makefile16
-rw-r--r--libc/bcc/bcc_i386.c149
-rw-r--r--libc/bcc/heap.c88
-rw-r--r--libc/bcc/ldiv.c3
4 files changed, 246 insertions, 10 deletions
diff --git a/libc/bcc/Makefile b/libc/bcc/Makefile
index 4f52133..991b50e 100644
--- a/libc/bcc/Makefile
+++ b/libc/bcc/Makefile
@@ -4,10 +4,20 @@
TOP=..
include $(TOP)/Make.defs
+CFLAGS=$(CCFLAGS)
# Support for integer arithmetic
+ifeq ($(LIB_CPU),i86)
IOBJ=__idiv.o __idivu.o __imod.o __imodu.o __imul.o __isl.o __isr.o __isru.o
ISRC=bcc_int.c
+endif
+
+# Support for integer arithmetic when compiling for the i386
+ifeq ($(LIB_CPU),i386)
+ISRC=bcc_i386.c
+IOBJ=__idiv.o __idivu.o __imod.o __imodu.o __imul.o __isl.o __isr.o __isru.o \
+ __divsi3.o
+endif
# Support for long arithmetic on little-endian (normal) longs
LSRC=bcc_long.c
@@ -30,7 +40,13 @@ PSRC=bcc_io.c
POBJ=__inport.o __inportb.o __outport.o __outportb.o __peekb.o __peekw.o \
__pokeb.o __pokew.o
+ifeq ($(LIB_CPU),i86)
OBJ=__ldivmod.o $(IOBJ) $(LOBJ) $(AOBJ)
+endif
+ifeq ($(LIB_CPU),i386)
+OBJ=$(IOBJ) $(AOBJ)
+endif
+
OLDOBJ=$(ROBJ) $(POBJ)
all: $(OBJ)
diff --git a/libc/bcc/bcc_i386.c b/libc/bcc/bcc_i386.c
new file mode 100644
index 0000000..d994628
--- /dev/null
+++ b/libc/bcc/bcc_i386.c
@@ -0,0 +1,149 @@
+/************************************************************************/
+/* This file contains the BCC compiler helper functions */
+/* Support for 386 integer arithmetic
+ * __divsi3.o __idiv.o __idivu.o __imod.o __imodu.o __imul.o
+ * __isl.o __isr.o __isru.o
+ */
+
+#ifdef __AS386_32__
+#asm
+ .text ! This is common to all.
+ .align 4
+#endasm
+
+#ifdef L___divsi3
+#asm
+! divsi3.s
+ .globl ___divsi3
+ ___divsi3:
+ push edx
+ mov eax,[esp+4+4]
+ cdq
+ idiv [esp+4+4+4]
+ pop edx
+ ret
+
+ .globl ___udivsi3
+ .text
+ .align 4
+
+ ___udivsi3:
+ push edx
+ mov eax,[esp+4+4]
+ sub edx,edx
+ div [esp+4+4+4]
+ pop edx
+ ret
+#endasm
+#endif
+
+#ifdef L___idiv
+#asm
+! idiv.s
+! idiv_ doesn`t preserve edx (returns remainder in it)
+
+ .globl idiv_
+idiv_:
+ cdq
+ idiv ebx
+ ret
+#endasm
+#endif
+
+#ifdef L___idivu
+#asm
+! idivu.s
+! idiv_u doesn`t preserve edx (returns remainder in it)
+
+ .globl idiv_u
+idiv_u:
+ xor edx,edx
+ div ebx
+ ret
+#endasm
+#endif
+
+#ifdef L___imod
+#asm
+! imod.s
+! imod doesn`t preserve edx (returns quotient in it)
+
+ .globl imod
+imod:
+ cdq
+ idiv ebx
+ mov eax,edx ! instruction queue full so xchg slower
+ ret
+#endasm
+#endif
+
+#ifdef L___imodu
+#asm
+! imodu.s
+! imodu doesn`t preserve edx (returns quotient in it)
+
+ .globl imodu
+imodu:
+ xor edx,edx
+ div ebx
+ mov eax,edx ! instruction queue full so xchg slower
+ ret
+#endasm
+#endif
+
+#ifdef L___imul
+#asm
+! imul.s
+! imul_, imul_u don`t preserve edx
+
+ .globl imul_
+ .globl imul_u
+imul_:
+imul_u:
+ imul ebx
+ ret
+#endasm
+#endif
+
+#ifdef L___isl
+#asm
+! isl.s
+! isl, islu don`t preserve cl
+
+ .globl isl
+ .globl islu
+isl:
+islu:
+ mov cl,bl
+ shl eax,cl
+ ret
+#endasm
+#endif
+
+#ifdef L___isr
+#asm
+! isr.s
+! isr doesn`t preserve cl
+
+ .globl isr
+isr:
+ mov cl,bl
+ sar eax,cl
+ ret
+#endasm
+#endif
+
+#ifdef L___isru
+#asm
+! isru.s
+! isru doesn`t preserve cl
+
+ .globl isru
+isru:
+ mov cl,bl
+ shr eax,cl
+ ret
+#endasm
+#endif
+
+#endif
diff --git a/libc/bcc/heap.c b/libc/bcc/heap.c
index af4e898..6a6ce2c 100644
--- a/libc/bcc/heap.c
+++ b/libc/bcc/heap.c
@@ -3,6 +3,8 @@
* under the GNU Library General Public License.
*/
+#include <errno.h>
+
/****************************************************************************/
#ifdef L_errno
@@ -11,8 +13,9 @@ int errno = 0; /* libc error value */
/****************************************************************************/
-#ifdef L___brk_addr
#ifdef __AS386_16__
+
+#ifdef L___brk_addr
#asm
.data
export brk_addr
@@ -20,14 +23,12 @@ brk_addr: .word __end ! This holds the current return for sbrk(0)
.text
#endasm
#endif
-#endif
/****************************************************************************/
#ifdef L_sbrk
-#ifdef __AS386_16__
int sbrk(brk_off)
-unsigned int brk_off;
+int brk_off;
{
#asm
mov bx,sp
@@ -36,14 +37,14 @@ unsigned int brk_off;
#endif
test ax,ax
jnz has_change
- mov ax,[brk_addr] ! Simple one; read current - can`t fail.
+ mov ax,[brk_addr] ! Simple one, read current - can`t fail.
jmp eof
has_change:
js go_down
add ax,[brk_addr] ! Goin up!
jc Enomem
- sub bx,#64 ! Safety space
+ sub bx,#512 ! Safety space 512 bytes
cmp bx,ax ! Too close ?
jb Enomem
@@ -71,22 +72,20 @@ eof:
#endasm
}
#endif
-#endif
/****************************************************************************/
#ifdef L_brk
-#ifdef __AS386_16__
int
brk(new_brk)
-void * new_brk;
+char * new_brk;
{
#asm
mov bx,sp
#if !__FIRST_ARG_IN_AX__
mov ax,[bx+2] ! Fetch the requested value
#endif
- sub bx,#64 ! Safety space
+ sub bx,#512 ! Safety space 512 bytes
cmp bx,ax ! Too close ?
jb Enomem
cmp ax,#__end
@@ -111,6 +110,75 @@ brk_ok:
#endasm
}
#endif
+
#endif
/****************************************************************************/
+
+#ifdef __AS386_32__
+extern char * __brk_addr;
+extern char * __brk();
+
+#ifdef L___brk_addr
+char * __brk_addr = 0; /* This holds the current return for sbrk(0) */
+
+char *
+__brk(val)
+{
+#asm
+#if __FIRST_ARG_IN_AX__
+ mov ebx,eax
+#else
+ mov ebx,[esp+4]
+#endif
+ mov eax,#45
+ int $80
+#endasm
+}
+
+__brk_addr_init()
+{
+ if( __brk_addr == 0 && (__brk_addr = __brk(0)) == 0 )
+ {
+ errno = ENOMEM;
+ return -1;
+ }
+ return 0;
+}
+#endif
+
+#ifdef L_sbrk
+char *
+sbrk(brk_off)
+int brk_off;
+{
+ char * new_brk;
+ if( __brk_addr_init() ) return (char*)-1;
+ if( brk_off == 0 ) return __brk_addr;
+
+ new_brk = __brk_addr + brk_off;
+ __brk_addr = __brk(new_brk);
+ if( __brk_addr != new_brk )
+ {
+ errno = ENOMEM;
+ return (char*)-1;
+ }
+ return __brk_addr - brk_off;
+}
+#endif
+
+#ifdef L_brk
+int
+brk(new_brk)
+char * new_brk;
+{
+ if( __brk_addr_init() ) return -1;
+
+ __brk_addr = __brk(new_brk);
+ if( __brk_addr == new_brk ) return 0;
+ errno = ENOMEM;
+ return -1;
+}
+#endif
+
+#endif
diff --git a/libc/bcc/ldiv.c b/libc/bcc/ldiv.c
index 6bfef0a..aab0701 100644
--- a/libc/bcc/ldiv.c
+++ b/libc/bcc/ldiv.c
@@ -1,3 +1,5 @@
+
+#ifdef __AS386_16__
#asm
.text
export _ldiv
@@ -24,4 +26,5 @@ _ldiv:
.data
.bss
#endasm
+#endif