diff options
Diffstat (limited to 'libc/bios')
-rw-r--r-- | libc/bios/Makefile | 10 | ||||
-rw-r--r-- | libc/bios/bios_disk.c | 158 | ||||
-rw-r--r-- | libc/bios/fs_dos.c | 98 | ||||
-rw-r--r-- | libc/bios/rawio.c | 11 |
4 files changed, 190 insertions, 87 deletions
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 <bios.h> +#include <errno.h> + +#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 <stdio.h> +#endif + #include <ctype.h> #include <malloc.h> #include <errno.h> #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<nsec; i++) - { - if (rawio_read_sector(fatsec+i, sect) == 0) - { - errno = EIO; - return -1; - } - memcpy(fat_buf+i*512, sect, 512); - } - } - } + fprintf(stderr, "fsdos_open_file: converted filename=<%s>\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 <DIR> %s\n", d, d+8, dtime); - break; - case 8: - if( (d[11] & 7) == 0 ) - printf("%-11.11s <LBL> %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 <stdio.h> +#endif + #include <bios.h> #include <ctype.h> #include <malloc.h> @@ -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); |