From df538463687d768b6ee8247ff4412b78850e7404 Mon Sep 17 00:00:00 2001 From: Robert de Bath Date: Sun, 17 Feb 2002 23:02:29 +0100 Subject: Import Dev86src-0.16.2.tar.gz --- libc/Makefile | 2 +- libc/README | 5 +-- libc/bios/Makefile | 2 +- libc/bios/bios.c | 54 +++++++++++++++++++---- libc/bios/bios_vid.c | 119 ++++++++++++++++++++------------------------------- libc/conio/Makefile | 22 ++++++---- libc/conio/conio.c | 7 --- libc/conio/cprintf.c | 5 +++ libc/include/a.out.h | 1 + 9 files changed, 117 insertions(+), 100 deletions(-) (limited to 'libc') diff --git a/libc/Makefile b/libc/Makefile index 6d6c5bb..01e05d7 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -11,7 +11,7 @@ endif VERMAJOR=0 VERMINOR=16 -VERPATCH=1 +VERPATCH=2 VER=$(VERMAJOR).$(VERMINOR).$(VERPATCH) CC=bcc diff --git a/libc/README b/libc/README index 653ed06..89e0188 100644 --- a/libc/README +++ b/libc/README @@ -25,12 +25,11 @@ gtermcap GNU termcap i386fp BCC's floating point routines for 386 code. include Some include files, some new others Glib or Glib hacked. kinclude Kernel include files, here for now. -malloc1 Robert's malloc routines -malloc2 Joel's malloc routines +malloc Malloc routines misc Various larger functions msdos This is the syscall directory for msdos. regexp Standard regular expression parser -stdio2 Robert's standard I/O +stdio Robert's standard I/O string The functions for string.h syscall All the system call functions, and some tied lib ones. termios Termimal mode control. diff --git a/libc/bios/Makefile b/libc/bios/Makefile index 116776e..3b01e77 100644 --- a/libc/bios/Makefile +++ b/libc/bios/Makefile @@ -8,7 +8,7 @@ AOBJ=bios_start.o bios_isatty.o bios_nofiles.o \ bios_read.o bios_write.o bios_lseek.o bios_close.o BSRC=bios_vid.c -BOBJ=bios_putc.o bios_getc.o bios_khit.o bios_rdline.o +BOBJ=bios_putc.o bios_getc.o bios_getce.o bios_khit.o bios_rdline.o OBJ=$(AOBJ) $(BOBJ) time.o fileops.o fs_dos.o rawio.o diff --git a/libc/bios/bios.c b/libc/bios/bios.c index e0e5c23..ab592a0 100644 --- a/libc/bios/bios.c +++ b/libc/bios/bios.c @@ -3,6 +3,8 @@ * under the GNU Library General Public License. */ +#undef AOUT_STANDALONE + #if !__FIRST_ARG_IN_AX__ #ifdef __AS386_16__ #ifdef __STANDALONE__ @@ -22,7 +24,7 @@ void (*__cleanup)() = 0; .data export ___argr ___argr: - .word 0,0,0,0,0,0,0 ! A struct REGS + .word 0,0,0,0,0,0,0,0 ! A struct REGS: ax, bx, cx, dx, si, di, cflag, flags defarg: .word boot_str, 0 boot_str: @@ -34,20 +36,49 @@ loop_save: export ___cstartup ! Crt0 startup ___cstartup: cli +#ifndef AOUT_STANDALONE + seg cs + cmp word ptr [0],#$20CD ! "int 20h" at psp: CS:0000 + jne not_dos + + ! DOS - only AX has a defined value. + ! All the segment registers are pointing at the PSP + ! SP points to the top of the segment so is probably useable. + + push ax ! Save AX + mov ax,cs + add ax,#$10 ! bump CS by 0x10 + push ax + mov ax,#is_dos ! resume address + push ax + retf ! continue at next instruction +dos_flag: + .word 0 ! Set to 1 if DOS +is_dos: + seg cs + inc dos_flag + pop ax ! restore saved AX + +not_dos: mov sp,cs add sp,#__segoff mov ds,sp mov ss,sp + mov bp,#__heap_top + mov sp,#___argr+14 + seg cs + push [dos_flag] ! Set the carry flag if we're under DOS. +#else + mov bp,sp mov sp,#___argr+12 +#endif push di push si push dx push cx push bx push ax - xor bp,bp mov sp,bp - push bp sti zap_bss: ! Clear the BSS @@ -61,6 +92,7 @@ zap_bss: ! Clear the BSS rep stosb + !mov bp,ax ! Top frame pointer, only needed if we get a debugger push [_environ] mov ax,#defarg ! Don`t define __mkargv, standalone programs don`t push ax ! get any arguments. @@ -107,12 +139,19 @@ no_clean: export __exit __exit: +#ifndef AOUT_STANDALONE + seg cs + cmp [dos_flag],#0 ! Should we do a DOS exit + je do_reboot + int #$20 +do_reboot: +#endif xor ax,ax mov es,ax mov ax,cs seg es mov [$E6*4+2],ax - mov ax,#reti_ins + mov ax,#iret_ins seg es mov [$E6*4],ax mov ax,#$FFFF @@ -121,8 +160,8 @@ __exit: seg es mov [$472],#$1234 ! Warm reboot. jmpi $0000,$FFFF -reti_ins: - reti +iret_ins: + iret #endasm @@ -141,8 +180,7 @@ char * buf; for(v=len; v>0; v--) { c= *buf++; - if( c == '\n') bios_putc('\r'); - bios_putc(c); + putch(c); } return len; } diff --git a/libc/bios/bios_vid.c b/libc/bios/bios_vid.c index 8bf375a..bbe7545 100644 --- a/libc/bios/bios_vid.c +++ b/libc/bios/bios_vid.c @@ -7,7 +7,6 @@ #define VT52_CON /* IMO the best, no clear to EOS/EOL tho */ #define XANSI_CON /* Largest but still not complete */ #define XDUMB_CON /* Can't do much */ -#define XSPEC_CON /* Incomplete, best for slow links */ #if !__FIRST_ARG_IN_AX__ #ifdef __AS386_16__ @@ -27,7 +26,7 @@ static int con_colour = 0; static unsigned char con_row, con_col; #ifdef VT52_CON -bios_putc(c) +putch(c) int c; { static int ctrl = 0; @@ -85,7 +84,9 @@ static int ctrl = 0; asm_putc(c); break; case CTRL('I'): - asm_putc(' '); /* Only some BIOS's have this, so play safe */ + asm_gpos(); + con_col = ((con_col+8)& -8); + asm_cpos(con_row, con_col); break; case CTRL('L'): asm_cpos(0,0); @@ -110,7 +111,7 @@ static int ansi_argc = 0; static int ansi_argv[MAX_ARGS]; static void do_ansi(); -bios_putc(c) +putch(c) int c; { if( con_mode==0 ) asm_coninit(); @@ -123,6 +124,11 @@ int c; asm_colour(last_attr); asm_putc(c); break; + case CTRL('I'): + asm_gpos(); + con_col = ((con_col+8)& -8); + asm_cpos(con_row, con_col); + break; case CTRL('L'): asm_cpos(0,0); asm_cls(); @@ -233,68 +239,12 @@ int ctrl, argc, *argv; } #endif -#ifdef SPEC_CON -static char vidbuf[3]; -static int vidcnt=0; - -bios_putc(c) -int c; -{ - if( con_mode==0 ) asm_coninit(); - if( vidcnt == 0 ) - { - if( c & 0xE0 ) - { asm_colour(last_attr) ; asm_putc(c); } - else switch(c) - { - default: - asm_putc(c); - break; - case CTRL('L'): - asm_cpos(0,0); - asm_cls(); - break; - case CTRL('P'): - case CTRL(']'): - vidbuf[vidcnt++] = c; - break; - } - } - else - { - vidbuf[vidcnt++] = c; - if( vidcnt < 3 && - (vidbuf[0] != CTRL(']') || vidbuf[1] < '`' || vidbuf[1] > 'p')) - return; - - if( vidbuf[0] == CTRL('P') ) - { - if( vidbuf[1] >= 32 && vidbuf[1] <= 56 - && vidbuf[2] >= 32 && vidbuf[2] <= 111 ) - asm_cpos((vidbuf[1]-32), (vidbuf[2]-32)); - } - else - { - if( vidbuf[1] >= '`' ) - last_attr = ( (vidbuf[1]&0xF) | (last_attr&0xF0)); - else - last_attr = ( (vidbuf[2]&0xF) | ((vidbuf[1]&0xF)<<4)); - - if( !con_colour ) - last_attr = (last_attr&0x88) + ((last_attr&7)?0x07:0x70); - } - vidcnt=0; - } -} -#endif - #ifdef DUMB_CON -bios_putc(c) +putch(c) int c; { if( con_mode==0 ) asm_coninit(); - if( c & 0xE0 ) asm_putc(c); - else switch(c) + switch(c) { default: asm_putc(c); @@ -327,6 +277,13 @@ static asm_putc(c) mov bx,sp mov ax,[bx+2] #endif + cmp al,#$0A + jne not_nl + mov ax,#$0E0D + mov bx,#7 + int $10 + mov al,#$0A +not_nl: mov ah,#$0E mov bx,#7 int $10 @@ -404,6 +361,25 @@ static asm_gpos() /****************************************************************************/ +#ifdef L_bios_getce +getche() +{ + static char linebuf[80]; + static int nextc = 0, endc=0; + int rv; + + if (nextc >= endc) + { + endc = bios_readline(linebuf, sizeof(linebuf)); + nextc= 0; + } + if (endc <= nextc) return 3; + rv = linebuf[endc++]; + if (endc == nextc) return '\r'; + return rv; +} +#endif + #ifdef L_bios_rdline bios_rdline(buf, len) char * buf; @@ -415,13 +391,13 @@ int len; if( len < 0 ) { errno = EINVAL; return -1; } if( len == 0 ) { - if( bios_khit() == 0 ) return 0; + if( kbhit() == 0 ) return 0; errno = EINTR; return -1; } if( len == 1 ) { - buf[0]=((ch=bios_getc())&0xFF?ch&0xFF:((ch>>8)&0xFF|0x80)); + buf[0]=((ch=getch())&0xFF?ch&0xFF:((ch>>8)&0xFF|0x80)); return 1; } @@ -429,32 +405,31 @@ int len; { if(ch != '\003') { - ch = bios_getc(); + ch = getch(); if( pos == 0 && (ch&0xFF) == 0 ) { buf[0] = ((ch>>8)|0x80); return 1; } ch &= 0x7F; - if( ch == '\033' ) ch=3; /* ESC= Interrupt too */ } if( ch == '\r' ) { - bios_putc('\r'); bios_putc('\n'); + putch('\n'); buf[pos++] = '\n'; return pos; } if( ch >= ' ' && ch != 0x7F && pos < len-1) - bios_putc(buf[pos++] = ch); + putch(buf[pos++] = ch); else if( (ch == '\003' || ch == '\b') && pos > 0 ) { - bios_putc('\b'); bios_putc(' '); bios_putc('\b'); + putch('\b'); putch(' '); putch('\b'); pos--; } else if( ch == '\003' ) return 0; else - bios_putc('\007'); + putch('\007'); } } #endif @@ -462,7 +437,7 @@ int len; /****************************************************************************/ #ifdef L_bios_getc -bios_getc() +getch() { #asm xor ax,ax @@ -474,7 +449,7 @@ bios_getc() /****************************************************************************/ #ifdef L_bios_khit -bios_khit() +kbhit() { #asm mov ah,#1 diff --git a/libc/conio/Makefile b/libc/conio/Makefile index bd86b2c..662b0ec 100644 --- a/libc/conio/Makefile +++ b/libc/conio/Makefile @@ -3,19 +3,23 @@ # under the GNU Library General Public License. ASRC=conio.c -AOBJ=getch.o getche.o kbhit.o putch.o cputs.o +AOBJ=getch.o getche.o kbhit.o putch.o -OBJ=$(AOBJ) cprintf.o +BSRC=conio.c +BOBJ=cputs.o + +BIOSOBJ=$(BOBJ) cprintf.o +DOSOBJ=$(AOBJ) $(BOBJ) cprintf.o CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS) ifeq ($(LIB_CPU)-$(LIB_OS),i86-BIOS) -all: $(LIBC)($(OBJ)) - @$(RM) $(OBJ) +all: $(LIBC)($(BIOSOBJ)) + @$(RM) $(BIOSOBJ) else ifeq ($(LIB_CPU)-$(LIB_OS),i86-DOS) -all: $(LIBC)($(OBJ)) - @$(RM) $(OBJ) +all: $(LIBC)($(DOSOBJ)) + @$(RM) $(DOSOBJ) else all: @: @@ -26,11 +30,13 @@ $(LIBC)($(AOBJ)): $(ASRC) $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o $(AR) $(ARFLAGS) $@ $*.o +$(LIBC)($(BOBJ)): $(BSRC) + $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o + $(AR) $(ARFLAGS) $@ $*.o + $(LIBC)(cprintf.o): cprintf.c $(CC) -c -ansi $(ARCH) $(CCFLAGS) $(DEFS) $*.c $(AR) $(ARFLAGS) $@ $*.o - - clean: rm -f *.o libc.a diff --git a/libc/conio/conio.c b/libc/conio/conio.c index c0e9cbb..ee311a5 100644 --- a/libc/conio/conio.c +++ b/libc/conio/conio.c @@ -58,13 +58,6 @@ putch() mov bx,sp mov ax,[bx+2] #endif - cmp al,#$0A - jne not_nl - mov ax,#$0E0D - mov bx,#7 - int $10 - mov al,#$0A -not_nl: mov ah,#$0E mov bx,#7 int $10 diff --git a/libc/conio/cprintf.c b/libc/conio/cprintf.c index 4bc3bac..5194376 100644 --- a/libc/conio/cprintf.c +++ b/libc/conio/cprintf.c @@ -1,3 +1,8 @@ +/* Copyright (C) 1999-2002 Robert de Bath + * This file is part of the Linux-8086 C library and is distributed + * under the GNU Library General Public License. + */ + #include #include diff --git a/libc/include/a.out.h b/libc/include/a.out.h index bd58346..677d73e 100644 --- a/libc/include/a.out.h +++ b/libc/include/a.out.h @@ -48,6 +48,7 @@ struct exec { /* a.out header */ #define A_UZP 0x01 /* unmapped zero page (pages) */ #define A_PAL 0x02 /* page aligned executable */ #define A_NSYM 0x04 /* new style symbol table */ +#define A_STAND 0x08 /* standalone executable */ #define A_EXEC 0x10 /* executable */ #define A_SEP 0x20 /* separate I/D */ #define A_PURE 0x40 /* pure text */ -- cgit v1.2.1