From 673f690a37f6673a3262e933709c79de8a66f48c Mon Sep 17 00:00:00 2001 From: Robert de Bath Date: Mon, 22 Jul 2002 23:35:31 +0200 Subject: Import Dev86src-0.16.4.tar.gz --- libc/bios/Makefile | 10 ++- libc/bios/bios_disk.c | 158 +++++++++++++++++++++++++++++++++++++++++++++ libc/bios/fs_dos.c | 98 ++++------------------------ libc/bios/rawio.c | 11 ++++ libc/include/bios.h | 1 + libc/include/ctype.h | 5 +- libc/include/stdio.h | 11 ++-- libc/misc/Makefile | 2 +- libc/misc/crypt.c | 4 +- libc/misc/ctype.c | 14 ---- libc/misc/ctypefn.c | 25 +++++++ libc/stdio/Makefile | 6 +- libc/stdio/stdio.c | 34 +++++++++- libc/stdio/stdio.h | 11 ++-- libc/syscall/syscall.dev86 | 17 +++-- 15 files changed, 279 insertions(+), 128 deletions(-) create mode 100644 libc/bios/bios_disk.c create mode 100644 libc/misc/ctypefn.c (limited to 'libc') diff --git a/libc/bios/Makefile b/libc/bios/Makefile index cd97308..692d535 100644 --- a/libc/bios/Makefile +++ b/libc/bios/Makefile @@ -14,7 +14,11 @@ BOBJ=bios_putch.o bios_getch.o bios_getche.o bios_cputs.o bios_kbhit.o \ CSRC=bios_min.c COBJ=bios_putc.o bios_getc.o -OBJ=$(AOBJ) $(BOBJ) $(COBJ) time.o fileops.o fs_dos.o rawio.o vt52.o ansi.o +DSRC=bios_disk.c +DOBJ=bios_disk_read.o bios_disk_write.o bios_disk_reset.o bios_get_dpt.o + +OBJ=$(AOBJ) $(BOBJ) $(COBJ) $(DOBJ) \ + time.o fileops.o fs_dos.o rawio.o vt52.o ansi.o CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS) @@ -32,6 +36,10 @@ $(LIBC)($(BOBJ)): $(BSRC) $(LIBC)($(COBJ)): $(CSRC) $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o $(AR) $(ARFLAGS) $@ $*.o + +$(LIBC)($(DOBJ)): $(DSRC) + $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o + $(AR) $(ARFLAGS) $@ $*.o else all: @: diff --git a/libc/bios/bios_disk.c b/libc/bios/bios_disk.c new file mode 100644 index 0000000..e0d9961 --- /dev/null +++ b/libc/bios/bios_disk.c @@ -0,0 +1,158 @@ + +#if !__FIRST_ARG_IN_AX__ +#ifdef __AS386_16__ + +#include +#include + +#ifdef L_bios_disk_read +_bios_disk_read(drive, cyl, head, sect, length, buffer) +{ +#asm + push bp + mov bp,sp + + push es + push ds + pop es + + mov dl,[bp+2+__bios_disk_read.drive] + mov ch,[bp+2+__bios_disk_read.cyl] + mov dh,[bp+2+__bios_disk_read.head] + mov bx,[bp+2+__bios_disk_read.buffer] + +#if 0 + mov ax,[bp+2+__bios_disk_read.cyl] ! Bits 10-11 of cylinder, AMI BIOS. + mov cl,#4 + sar ax,cl + and al,#$C0 + xor dh,al +#endif + + mov cl,[bp+2+__bios_disk_read.sect] + and cl,#$3F + mov ax,[bp+2+__bios_disk_read.cyl] ! Bits 8-9 of cylinder. + sar ax,#1 + sar ax,#1 + and al,#$C0 + or cl,al + + mov al,[bp+2+__bios_disk_read.length] + mov ah,#$02 + int $13 + jc read_err1 + mov ax,#0 +read_err1: + xchg ah,al + xor ah,ah + + pop es + pop bp +#endasm +} +#endif + +#ifdef L_bios_disk_write +_bios_disk_write(drive, cyl, head, sect, length, buffer) +{ +#asm + push bp + mov bp,sp + + push es + push ds + pop es + + mov dl,[bp+2+__bios_disk_write.drive] + mov ch,[bp+2+__bios_disk_write.cyl] + mov dh,[bp+2+__bios_disk_write.head] + mov bx,[bp+2+__bios_disk_write.buffer] + +#if 0 + mov ax,[bp+2+__bios_disk_write.cyl] ! Bits 10-11 of cylinder, AMI BIOS. + mov cl,#4 + sar ax,cl + and al,#$C0 + xor dh,al +#endif + + mov cl,[bp+2+__bios_disk_write.sect] + and cl,#$3F + mov ax,[bp+2+__bios_disk_write.cyl] ! Bits 8-9 of cylinder. + sar ax,#1 + sar ax,#1 + and al,#$C0 + or cl,al + + mov al,[bp+2+__bios_disk_write.length] + mov ah,#$03 + int $13 + jc read_err2 + mov ax,#0 +read_err2: + xchg ah,al + xor ah,ah + + pop es + pop bp +#endasm +} +#endif + +#ifdef L_bios_get_dpt +long +_bios_get_dpt(drive) +{ +#asm + push bp + mov bp,sp + + push di + push es + + mov dl,[bp+2+__bios_get_dpt.drive] + + mov ah,#$08 + int $13 + jnc func_ok + mov cx,ax + mov dx,#-1 +func_ok: + mov ax,cx + + pop es + pop di + pop bp +#endasm +} +#endif + +#ifdef L_bios_disk_reset +_bios_disk_reset(drive) +{ +#asm + push bp + mov bp,sp + + push di + push es + + mov dl,[bp+2+__bios_disk_reset.drive] + + mov ah,#$08 + int $13 + jnc reset_ok + mov cx,ax + mov dx,#-1 +reset_ok: + mov ax,cx + + pop es + pop di + pop bp +#endasm +} +#endif + +#endif +#endif diff --git a/libc/bios/fs_dos.c b/libc/bios/fs_dos.c index 28ee962..b826d45 100644 --- a/libc/bios/fs_dos.c +++ b/libc/bios/fs_dos.c @@ -1,13 +1,14 @@ +#ifdef DEBUG #include +#endif + #include #include #include #include "io.h" #include "rawio.h" -#define DONT_BUFFER_FAT - #define DOS_SECT(P) get_uint(P,0x0B) #define DOS_CLUST(P) get_byte(P,0x0D) #define DOS_RESV(P) get_uint(P,0x0E) @@ -22,6 +23,7 @@ #define DOS4_MAXSECT(P) get_long(P,0x20) #define DOS4_PHY_DRIVE(P) get_byte(P,0x24) #define DOS4_SERIAL(P) get_long(P,0x27) +#define DOS4_FATTYPE(P) get_uint(P,0x39) /* These assume alignment is not a problem */ #define get_byte(P,Off) *((unsigned char*)((char*)(P)+(Off))) @@ -33,15 +35,11 @@ static int dir_nentry, dir_sect; static int dos_clust0, dos_spc, dos_fatpos; static int last_serial = 0; -#ifdef BUFFER_FAT -static char * fat_buf = 0; -#endif - struct filestatus { char fname[12]; unsigned short first_cluster; unsigned short cur_cluster; - unsigned short sector_no; + unsigned short sector_no; /* Max filesize = 32M */ long file_length; }; @@ -61,11 +59,10 @@ int mode; char conv_name[12]; char *d, *s; int i; - int dodir = 0; struct filestatus* cur_file; #ifdef DEBUG - printf("fsdos_open_file(%x, %s, %d, %d, %d)\n", + fprintf(stderr, "fsdos_open_file(%x, %s, %d, %d, %d)\n", iob, fname, flags, mode, sizeof(iob)); #endif iob->block_read = fsdos_read_block; @@ -74,9 +71,6 @@ int mode; /* Get the superblock */ if( read_bootblock() < 0 ) return -1; - if(strcmp(fname, ".") == 0) - dodir = 1; - else { /* Convert the name to MSDOS directory format */ strcpy(conv_name, " "); @@ -97,38 +91,7 @@ int mode; } } #ifdef DEBUG - printf("fsdos_open_file: converted filename=<%s>\n", conv_name); -#endif - -#ifdef BUFFER_FAT - rawio_read_sector(0, sect); - - if( !dodir ) - { - /* Read in and buffer the FAT */ - if( fat_buf ) free(fat_buf); - fat_buf = malloc(DOS_FATLEN(sect) * 512); - if( fat_buf == 0 ) - { - errno = ENOMEM; - return -1; - } - else - { - int fatsec = DOS_RESV(sect); - int nsec = DOS_FATLEN(sect); - - for(i=0; i\n", conv_name); #endif /* Scan the root directory for the file */ @@ -141,37 +104,7 @@ int mode; return -1; } d = s + (i%16)*32; - if( dodir ) - { - char dtime[20]; - char lbuf[90]; - *lbuf = 0; - - sprintf(dtime, " %02d/%02d/%04d %02d:%02d", - (get_uint(d,24)&0x1F), - ((get_uint(d,24)>>5)&0xF), - ((get_uint(d,24)>>9)&0x7F)+1980, - ((get_uint(d,22)>>11)&0x1F), - ((get_uint(d,22)>>5)&0x3F) - ); - if( *d > ' ' && *d <= '~' ) switch(d[11]&0x18) - { - case 0: - printf("%-8.8s %-3.3s %10ld%s\n", d, d+8, get_long(d,28), dtime); - break; - case 0x10: - printf("%-8.8s %-3.3s %s\n", d, d+8, dtime); - break; - case 8: - if( (d[11] & 7) == 0 ) - printf("%-11.11s %s\n", d, dtime); - break; - } -#if 0 - if( more_strn(lbuf, sizeof(lbuf)) < 0 ) break; -#endif - } - else if( memcmp(d, conv_name, 11) == 0 && (d[11]&0x18) == 0 ) + if( memcmp(d, conv_name, 11) == 0 && (d[11]&0x18) == 0 ) { /* Name matches and is normal file */ #ifdef DEBUG @@ -233,11 +166,6 @@ ioblock* iob; free(cur_file); iob->context = NULL; -#ifdef BUFFER_FAT - if( fat_buf ) free(fat_buf); - fat_buf = 0; -#endif - rawio_reset_disk(); return 0; } @@ -278,7 +206,9 @@ long block; /* ignored for now */ #endif if (iob == NULL || iob->context == NULL) { +#ifdef DEBUG fprintf(stderr, "rb: no context\n"); +#endif errno = EBADF; return -1; } @@ -345,9 +275,6 @@ long block; /* ignored for now */ unsigned int val, val2; val = cur_file->cur_cluster + (cur_file->cur_cluster>>1); -#ifdef BUFFER_FAT - val2 = get_uint(fat_buf, val); -#else if (rawio_read_sector(dos_fatpos+(val/512), sect) <= 0) return -1; if( val%512 == 511 ) { @@ -357,7 +284,6 @@ long block; /* ignored for now */ } else val2 = get_uint(sect, (val%512)); -#endif if( odd ) val2>>=4; @@ -380,7 +306,7 @@ static int read_bootblock() int rv, media_byte = 0; #ifdef DEBUG - printf("fs_dos:read_bootblock:\n"); + fprintf(stderr, "fs_dos:read_bootblock:\n"); #endif if (rawio_read_sector(1, sect) <= 0) return -1; media_byte = *(unsigned char*)sect; @@ -412,7 +338,7 @@ static int read_bootblock() } #ifdef DEBUG - printf("read_bootblock: heads(%d), spt(%d), dir_sect(%d)\n", + fprintf(stderr, "read_bootblock: heads(%d), spt(%d), dir_sect(%d)\n", rawio_disk_heads, rawio_disk_spt, dir_sect); diff --git a/libc/bios/rawio.c b/libc/bios/rawio.c index 1bb0e4d..2da573b 100644 --- a/libc/bios/rawio.c +++ b/libc/bios/rawio.c @@ -2,7 +2,10 @@ * rawio.c - plagiarised from ../../bootblocks/trk_buf.c */ +#ifdef DEBUG #include +#endif + #include #include #include @@ -124,18 +127,24 @@ char* buffer; data_buf1 = malloc(512); if( data_buf1 == 0 ) { +#ifdef DEBUG fprintf(stderr, "Cannot allocate memory for disk read!!!\n"); +#endif return 0; } +#ifdef DEBUG fprintf(stderr, "WARNING: Single sector read\n"); +#endif do { rv = rawio_phy_read(rawio_disk_drive, phy_c, phy_h, phy_s+1, 1, data_buf1); tries--; +#ifdef DEBUG if( rv ) fprintf(stderr, "Error in phy_read(%d,%d,%d,%d,%d,%d);\n", rawio_disk_drive, phy_c, phy_h, phy_s+1, 1, data_buf1); +#endif } while(rv && tries > 0); @@ -239,8 +248,10 @@ int phy_c, phy_h, phy_s; rv = rawio_phy_read(rawio_disk_drive, phy_c, phy_h, phy_s/data_len+1, data_len, data_buf1); tries--; +#ifdef DEBUG if( rv ) fprintf(stderr, "Error in phy_read(%d,%d,%d,%d,%d,%d);\n", rawio_disk_drive, phy_c, phy_h, phy_s/data_len+1, data_len, data_buf1); +#endif } while(rv && tries > 0); diff --git a/libc/include/bios.h b/libc/include/bios.h index 20aa5ca..8c60d34 100644 --- a/libc/include/bios.h +++ b/libc/include/bios.h @@ -22,6 +22,7 @@ int __peek_es __P((unsigned int off)); int __deek_es __P((unsigned int off)); #define movedata __movedata +long _bios_get_dpt(drive); #ifdef __LIBC__ diff --git a/libc/include/ctype.h b/libc/include/ctype.h index a724a4c..245b1c0 100644 --- a/libc/include/ctype.h +++ b/libc/include/ctype.h @@ -15,8 +15,9 @@ extern unsigned char __ctype[]; #define __CT_p 0x20 /* punctuation */ #define __CT_x 0x40 /* hexadecimal */ -#define toupper(c) (islower(c) ? (c)^0x20 : (c)) -#define tolower(c) (isupper(c) ? (c)^0x20 : (c)) +/* Define these as simple old style ascii versions */ +#define toupper(c) (((c)>='a'&&(c)<='z') ? (c)^0x20 : (c)) +#define tolower(c) (((c)>='A'&&(c)<='Z') ? (c)^0x20 : (c)) #define _toupper(c) ((c)^0x20) #define _tolower(c) ((c)^0x20) #define toascii(c) ((c)&0x7F) diff --git a/libc/include/stdio.h b/libc/include/stdio.h index fd10923..cbdacc3 100644 --- a/libc/include/stdio.h +++ b/libc/include/stdio.h @@ -111,11 +111,14 @@ extern int fputc __P((int, FILE*)); extern int fclose __P((FILE*)); extern int fflush __P((FILE*)); extern char *fgets __P((char*, size_t, FILE*)); -extern FILE *__fopen __P((char*, int, FILE*, char*)); -#define fopen(__file, __mode) __fopen((__file), -1, (FILE*)0, (__mode)) -#define freopen(__file, __mode, __fp) __fopen((__file), -1, (__fp), (__mode)) -#define fdopen(__file, __mode) __fopen((char*)0, (__file), (FILE*)0, (__mode)) +extern FILE *fopen __P((char*, char*)); +extern FILE *fdopen __P((int, char*)); +extern FILE *freopen __P((char*, char*, FILE*)); + +#ifdef __LIBC__ +extern FILE *__fopen __P((char*, int, FILE*, char*)); +#endif extern int fputs __P((char*, FILE*)); extern int puts __P((char*)); diff --git a/libc/misc/Makefile b/libc/misc/Makefile index 74a2637..b779802 100644 --- a/libc/misc/Makefile +++ b/libc/misc/Makefile @@ -10,7 +10,7 @@ ESRC=atexit.c EOBJ=on_exit.o atexit.o __do_exit.o GOBJ=atoi.o atol.o ltoa.o ltostr.o \ - ctype.o qsort.o bsearch.o rand.o lsearch.o getopt.o \ + ctype.o ctypefn.o qsort.o bsearch.o rand.o lsearch.o getopt.o \ itoa.o cputype.o strtol.o crypt.o UOBJ=getenv.o putenv.o popen.o system.o setenv.o getcwd.o tmpnam.o diff --git a/libc/misc/crypt.c b/libc/misc/crypt.c index db69325..be51948 100644 --- a/libc/misc/crypt.c +++ b/libc/misc/crypt.c @@ -6,7 +6,7 @@ /* * I've: * Compared the TEA implementation to a reference source - OK - * Noted the cycles count at 64 is twice the suggested value. + * Reduced the cycles count from 64 to 32 (the suggested value) * Changed the types of 'n' and 'i' for better code with bcc. * Removed a possible overrun of rkey by looping the values, it's now * possible to _choose_ every bit of the 128bit PW with a 32 character word. @@ -26,7 +26,7 @@ crypt(const char * key, const char * salt) k is the key, v is the data to be encrypted. */ unsigned long v[2], sum=0, delta=0x9e3779b9, k[4]; - int n=64, i, j; + int n=32, i, j; static char rkey[16]; /* Our constant string will be a string of zeros .. */ diff --git a/libc/misc/ctype.c b/libc/misc/ctype.c index 0425f00..d684e15 100644 --- a/libc/misc/ctype.c +++ b/libc/misc/ctype.c @@ -9,9 +9,6 @@ #include -#undef toupper -#undef tolower - unsigned char __ctype[257] = { 0, /* -1 */ @@ -56,14 +53,3 @@ unsigned char __ctype[257] = __CT_p, __CT_p, __CT_p, __CT_c /* 0x7C..0x7F */ }; -int toupper(c) -int c; -{ - return(islower(c) ? (c ^ 0x20) : (c)); -} - -int tolower(c) -int c; -{ - return(isupper(c) ? (c ^ 0x20) : (c)); -} diff --git a/libc/misc/ctypefn.c b/libc/misc/ctypefn.c new file mode 100644 index 0000000..921da31 --- /dev/null +++ b/libc/misc/ctypefn.c @@ -0,0 +1,25 @@ +/* Copyright (C) 1995,1996 Robert de Bath + * This file is part of the Linux-8086 C library and is distributed + * under the GNU Library General Public License. + */ + +/* + * CTYPE.C Character classification and conversion + */ + +#include + +#undef toupper +#undef tolower + +int toupper(c) +int c; +{ + return(islower(c) ? (c ^ 0x20) : (c)); +} + +int tolower(c) +int c; +{ + return(isupper(c) ? (c ^ 0x20) : (c)); +} diff --git a/libc/stdio/Makefile b/libc/stdio/Makefile index 0fd8d97..9e96427 100644 --- a/libc/stdio/Makefile +++ b/libc/stdio/Makefile @@ -7,9 +7,9 @@ CFLAGS=$(CCFLAGS) $(LIBDEFS) -DFLOATS endif ASRC=stdio.c -AOBJ=_stdio_init.o fputc.o fgetc.o fflush.o fgets.o gets.o fputs.o \ - puts.o fread.o fwrite.o fopen.o fclose.o fseek.o rewind.o ftell.o \ - setbuffer.o setvbuf.o ungetc.o +AOBJ=_stdio_init.o fputc.o fgetc.o fflush.o fgets.o gets.o fputs.o \ + puts.o fread.o fwrite.o fopen.o fdopen.o freopen.o __fopen.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 diff --git a/libc/stdio/stdio.c b/libc/stdio/stdio.c index 6b0dba0..b8e68a5 100644 --- a/libc/stdio/stdio.c +++ b/libc/stdio/stdio.c @@ -582,9 +582,39 @@ FILE * fp; #endif #ifdef L_fopen +FILE * +fopen(file, mode) +char * file; +char * mode; +{ + return __fopen(file, -1, (FILE*)0, mode); +} +#endif + +#ifdef L_freopen +FILE * +freopen(file, mode, fp) +char * file; +char * mode; +FILE * fp; +{ + return __fopen(file, -1, fp, mode); +} +#endif + +#ifdef L_fdopen +FILE * +fdopen(file, mode) +int file; +char * mode; +{ + return __fopen((char*)0, file, (FILE*)0, mode); +} +#endif + +#ifdef L___fopen /* - * This Fopen is all three of fopen, fdopen and freopen. The macros in - * stdio.h show the other names. + * This is the common code for all three of fopen, fdopen and freopen. */ FILE * __fopen(fname, fd, fp, mode) diff --git a/libc/stdio/stdio.h b/libc/stdio/stdio.h index fd10923..cbdacc3 100644 --- a/libc/stdio/stdio.h +++ b/libc/stdio/stdio.h @@ -111,11 +111,14 @@ extern int fputc __P((int, FILE*)); extern int fclose __P((FILE*)); extern int fflush __P((FILE*)); extern char *fgets __P((char*, size_t, FILE*)); -extern FILE *__fopen __P((char*, int, FILE*, char*)); -#define fopen(__file, __mode) __fopen((__file), -1, (FILE*)0, (__mode)) -#define freopen(__file, __mode, __fp) __fopen((__file), -1, (__fp), (__mode)) -#define fdopen(__file, __mode) __fopen((char*)0, (__file), (FILE*)0, (__mode)) +extern FILE *fopen __P((char*, char*)); +extern FILE *fdopen __P((int, char*)); +extern FILE *freopen __P((char*, char*, FILE*)); + +#ifdef __LIBC__ +extern FILE *__fopen __P((char*, int, FILE*, char*)); +#endif extern int fputs __P((char*, FILE*)); extern int puts __P((char*)); diff --git a/libc/syscall/syscall.dev86 b/libc/syscall/syscall.dev86 index 2c5384c..d572487 100644 --- a/libc/syscall/syscall.dev86 +++ b/libc/syscall/syscall.dev86 @@ -4,17 +4,15 @@ # ELKSemu and elks itself. Changes to this may require changes in # all three of those packages. # -# . = Ok, with comment -# * = Needs libc code (Prefix __) -# - = Obsolete/not required -# @ = May be required later +# '.' = Ok, with comment +# '*' = Needs libc code (Prefix __) +# '-' = Obsolete/not required +# '@' = May be required later +# '=' = Depends on stated config variable # # An initial plus on the call number specifies that this call is # implemented in the kernel. # -# Package versions are matched. -# Dev86/Elksemu version - 0.13.1 -# Elks version - 0.0.66 # # Name No Args Flag, comment # @@ -69,7 +67,7 @@ signal +48 2 * have put the despatch table in user space. getinfo 49 1 @ possible? gets pid,ppid,uid,euid etc fcntl +50 3 acct 51 1 @ Accounting to named file (off if null) -phys 52 3 - Replaced my mmap() +phys 52 3 - Replaced by mmap() lock 53 1 @ Prevent swapping for this proc if flg!=0 ioctl +54 3 . make this and fcntl the same ? reboot +55 3 . the magic number is 0xfee1,0xdead,... @@ -82,7 +80,7 @@ settimeofday +61 2 gettimeofday +62 2 select +63 5 . 5 paramaters is possible readdir +64 3 * -insmod +65 1 +insmod 65 1 - Removed support for modules fchown +66 3 dlload +67 2 setsid +68 0 @@ -91,6 +89,7 @@ bind +70 3 listen +71 2 accept +72 3 connect +73 3 +knlvsn +74 1 = CONFIG_SYS_VERSION # # Name No Args Flag&comment # -- cgit v1.2.1