diff options
author | Robert de Bath <rdebath@poboxes.com> | 1999-01-23 13:29:22 +0100 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2013-10-23 23:40:39 +0200 |
commit | e62b35169cdcd13632ae353b1e5ffde7dec44201 (patch) | |
tree | 2646548ca84edb365354a6e68459f92943532cee /bootblocks | |
parent | 2233d47f9d89c107b6c425626d6eb2669363b055 (diff) | |
download | dev86-e62b35169cdcd13632ae353b1e5ffde7dec44201.tar.gz |
Import Dev86src-0.14.7.tar.gzv0.14.7
Diffstat (limited to 'bootblocks')
-rw-r--r-- | bootblocks/Makefile | 18 | ||||
-rw-r--r-- | bootblocks/README | 43 | ||||
-rw-r--r-- | bootblocks/bootlist.s | 7 | ||||
-rw-r--r-- | bootblocks/bzimage.c | 28 | ||||
-rw-r--r-- | bootblocks/commands.c | 81 | ||||
-rw-r--r-- | bootblocks/cprintf.c | 136 | ||||
-rw-r--r-- | bootblocks/fs_dos.c | 130 | ||||
-rw-r--r-- | bootblocks/fs_tar.c | 11 | ||||
-rw-r--r-- | bootblocks/help.c | 14 | ||||
-rw-r--r-- | bootblocks/i86_funcs.c | 11 | ||||
-rw-r--r-- | bootblocks/lsys.c | 30 | ||||
-rw-r--r-- | bootblocks/makeboot.c | 212 | ||||
-rw-r--r-- | bootblocks/mbr.s | 2 | ||||
-rw-r--r-- | bootblocks/min_buf.c | 21 | ||||
-rw-r--r-- | bootblocks/monitor.c | 19 | ||||
-rw-r--r-- | bootblocks/monitor.h | 12 | ||||
-rw-r--r-- | bootblocks/msdos.s | 167 | ||||
-rw-r--r-- | bootblocks/noboot.s | 10 | ||||
-rw-r--r-- | bootblocks/skip.s | 21 | ||||
-rw-r--r-- | bootblocks/standalone.c | 2 | ||||
-rw-r--r-- | bootblocks/tarboot.s | 4 | ||||
-rw-r--r-- | bootblocks/trk_buf.c | 64 |
22 files changed, 786 insertions, 257 deletions
diff --git a/bootblocks/Makefile b/bootblocks/Makefile index 7ad0907..ebdcf08 100644 --- a/bootblocks/Makefile +++ b/bootblocks/Makefile @@ -21,16 +21,17 @@ SSRC=sysboot.s \ tarboot.s skip.s com_bcc.s tich.s \ bootlist.s mbr.s msdos.s noboot.s -encap: $(SSRC:s=v) $(CSRC:c=v) minixhd.v -bin: $(SSRC:s=bin) $(CSRC:c=bin) minixhd.bin +encap: $(SSRC:s=v) $(CSRC:c=v) minixhd.v msdos16.v +bin: $(SSRC:s=bin) $(CSRC:c=bin) minixhd.bin msdos16.bin MOBJ=monitor.o commands.o i86_funcs.o relocate.o help.o bzimage.o \ - trk_buf.o min_buf.o unix.o fs.o fs_tar.o fs_min.o fs_dos.o + trk_buf.o min_buf.o unix.o fs.o fs_tar.o fs_min.o fs_dos.o cprintf.o MSRC=monitor.c commands.c i86_funcs.c relocate.c help.c bzimage.c \ - trk_buf.c min_buf.c unix.c fs.c fs_tar.c fs_min.c fs_dos.c + trk_buf.c min_buf.c unix.c fs.c fs_tar.c fs_min.c fs_dos.c cprintf.c MINC=i86_funcs.h readfs.h monitor.h -BOOTBLOCKS=sysboot.v noboot.v skip.v msdos.v tarboot.v minix.v minixhd.v mbr.v +BOOTBLOCKS=sysboot.v noboot.v skip.v msdos.v msdos16.v \ + tarboot.v minix.v minixhd.v mbr.v EXTRAS=minix.h elf_info.c elf_info.h standalone.c li86.s \ zimage.s minix_elks.c crc.c lsys.c @@ -59,13 +60,16 @@ minix_elks.s: minix_elks.c Makefile minix.v minixhd.s: minix.c Makefile $(BCC) -Mf -O -DHARDDISK $(MINIXDEFS) -S minix.c -o minixhd.s +msdos16.s: msdos.s + sed 's/^fatbits=12/fatbits=16/' < msdos.s > msdos16.s + makeboot: makeboot.c $(BOOTBLOCKS) $(HOSTCC) $(HOSTCCFLAGS) -o makeboot makeboot.c makeboot.com: makeboot.c $(BOOTBLOCKS) $(BCC) -Md -O -o makeboot.com makeboot.c -lsys.com: lsys.c msdos.v +lsys.com: lsys.c msdos.v msdos16.v $(BCC) -Md -O -o lsys.com lsys.c version.h: @@ -74,7 +78,7 @@ version.h: clean realclean: rm -f monitor makeboot bootblocks.tar.gz - rm -f minix.s minixhd.s minix_elks.s version.h + rm -f minix.s minixhd.s minix_elks.s version.h msdos16.s rm -f *.com *.o *.bin *.out *.lst *.sym *.v *.tmp tgz: minix.bin monitor.out makeboot.com makeboot diff --git a/bootblocks/README b/bootblocks/README index ab115e3..d5054c6 100644 --- a/bootblocks/README +++ b/bootblocks/README @@ -37,12 +37,12 @@ Contents 1.2 ) Dosfs boot sector - Install with makeboot, the boot sector requires the floppy to be double - sided and makeboot checks for this. This boot sector loads and executes - a binary BOOTFILE.SYS from the root directory of the floppy. The file - can be any length and is loaded at $07C00. Because of the load address - this boot sector can be configured to load another boot sector, for - example LILO can be succesfully used in this way. + Install with makeboot, there is also a version for 16 bit FAT floppies + (eg LS-120 disks) This boot sector loads and executes a binary + BOOTFILE.SYS from the root directory of the floppy. The file can + be any length and is loaded at $07C00. Because of the load address + this boot sector can be configured to load another boot sector, + for example LILO can be succesfully used in this way. In fact LILO can be succesfully used in this way on a 2M disk, but you must create the floppy with the real dos 2M package as superformat @@ -53,6 +53,9 @@ Contents as my testing has gone this is only significant on 8086 machines, all others (286 8Mhz +) are fast enough to keep up at a 1-1 interleve. + Unfortunatly the most recent versions of superformat (5.0+) defeat this + because they do not correctly calculate intersector gaps. + 1.3 ) Minixfs boot block This boot block has varients for floppy and harddisk and works similarly @@ -63,7 +66,7 @@ Contents The sector looks for a file or directory called 'boot' if it's a directory it loads that and does the search again. When it finds a - file it loads it at location $10000 and executes it, beware this + file it loads it at location $10000 and executes it, note this is limited to a file size of 519k. There is also support for a helper boot which mean this is the only @@ -83,6 +86,8 @@ Contents tar file but when booted from will load and execute 'monitor.out' at location $00800 (Yes thats 2k!) + Warning: the tar boot sector moves the BPB to the location $666. + 1.5 ) Skip boot sector This bootsector displays a message then loads and executes the hard disk @@ -90,7 +95,8 @@ Contents 1.6 ) Panic boot sector - Displays the message 'PANIC! NO OS Found!' and freezes. + Displays the message 'PANIC! NO OS Found!' (or the message specified + on install) and freezes. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- @@ -127,34 +133,19 @@ Contents $ cp monitor.out /mnt/bootfile.sys $ cp /usr/src/linux/arch/i386/boot/zImage /mnt/vmlinuz - $ echo 'root=/dev/ram ramdisk_file=ramdisk.gz mem=80M' > /mnt/vmlinuz.cmd + $ echo 'root=/dev/ram ramdisk_file=ramdisk.gz mem=80M' > /mnt/vmlinuz.cfg $ cp /archive/ramdisk.gz /mnt/ramdisk.gz $ umount /dev/fd0 The stuff about ramdisk is only if you want an init ramdisk, if the ramdisk name begins with a '+' the program will ask for another disk first. - You can also use: - - vmlinuz.app: Arguments prepended to the Linux command line. - vmlinuz.cmd: Arguments appended to the Linux command line. - vmlinux.dfl: Arguments appended to the Linux command line. - - If there's a *.cmd file you won't be asked anything. If there's a *.dfl or - neither you'll be asked: - - vmlinuz: - - where you can type a command line to override the *.dfl file. If there's - a *.cmd file the *.dfl file is ignored, the *.app file is placed at the - start of the line whichever you do. - If the file isn't called 'vmlinuz' you can still boot it by typing "=linux" at the prompt '>' where 'linux' is the name of the bzImage file. Escape or ^C will interrupt the boot and drop you to the '>' prompt. Esacpe or ^C at the '>' prompt will reboot - (This may be a little sensitive :-) + (This may be a little too sensitive :-) A file called 'help.txt' will be displayed upto the first line that starts with a '%', chunks after that (seperated by '%'s) will be displayed when @@ -162,4 +153,4 @@ Contents -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -Robert de Bath <rdebath@poboxes.com> 22 Mar 1998 +Robert de Bath <rdebath@poboxes.com> 31 Dec 1998 diff --git a/bootblocks/bootlist.s b/bootblocks/bootlist.s index 9230796..a9c603c 100644 --- a/bootblocks/bootlist.s +++ b/bootblocks/bootlist.s @@ -17,10 +17,9 @@ BOOTSEG = 0x07c0 LOADSEG = 0x07e0 ! Just after boot sector. public linear -linear = 1 ! Is linear processing done ? - +linear = 1 ! Is linear processing done ? (0 doesn't work) public floppy -floppy = 0 *linear ! Allow for floppy drive ? +floppy = 0 *linear ! Allow for floppy drive ? (don't work) public reloc reloc = 1 *linear ! Auto configure of bootpart. @@ -93,7 +92,7 @@ load_addrs: adc dl,al mov al,ah else - lodsw + lodsw ; XXX Broken, doesn't set AL correctly. mov cx,ax lodsw mov dx,ax diff --git a/bootblocks/bzimage.c b/bootblocks/bzimage.c index cb713d7..1d7ff73 100644 --- a/bootblocks/bzimage.c +++ b/bootblocks/bzimage.c @@ -29,7 +29,7 @@ int load_crc = 0; static char buffer[1024]; cmd_bzimage(ptr) -char * ptr; +register char * ptr; { char * image; int ch; @@ -103,8 +103,8 @@ char * command_line; (int)(len/1024), (int)(len*10/1024%10)); return -1; } - if( main_mem_top < 3072 ) - printf("RTFM warning: Linux really needs at least 4MB of memory.\n"); + if( main_mem_top <= 3072 ) + printf("RTFM warning: Linux needs at least 4MB of memory.\n"); #endif low_sects = buffer[497] + 1; /* setup sects + boot sector */ @@ -220,6 +220,7 @@ char * command_line; printf("linux "); if( linux_command_line ) printf("%s", linux_command_line); + printf("\n"); fflush(stdout); if( a20_closed() ) open_a20(); @@ -289,6 +290,8 @@ char * command_line; /* Default boot drive is auto-detected floppy */ if( __peek_es(508) == 0 ) __poke_es(508, 0x200); + printf("Starting ...\n");; + #if ZIMAGE_LOAD_SEG == 0x10000 if( is_zimage ) /* Copy 512k from high memory then start */ @@ -319,8 +322,8 @@ char * command_line; } check_magics(fname, image_buf) -char * fname; -char * image_buf; +register char * fname; +register char * image_buf; { is_zimage = 0; @@ -371,7 +374,7 @@ unsigned int address; retry: tc--; - /* + if( x86_test ) return 0; /* In an EMU we can't write to high mem but we'll pretend we can for debuggering */ @@ -407,9 +410,9 @@ static char * read_cmdfile(iname) char * iname; { + char * ptr = strchr(iname, '.'); char buf[16]; long len; - char * ptr = strchr(iname, '.'); buf[8] = '\0'; strncpy(buf, iname, 8); @@ -427,7 +430,7 @@ char * iname; } if( read_block(buffer) >= 0 ) { - int i; + register int i; for(i=0; i<len; i++) if( buffer[i] < ' ' ) buffer[i] = ' '; buffer[len] = '\0'; @@ -445,7 +448,7 @@ input_cmd(iname) char * iname; { char lbuf[20]; - int cc; + register int cc; for(;;) { @@ -462,8 +465,11 @@ char * iname; if( cc == 0xAD ) /* ALT-X */ return 0; - sprintf(lbuf, "$%02x", cc); - cmd_help(lbuf); +#ifdef NOCOMMAND + cmd_type("helpprmt.txt"); +#else + help_key(cc); +#endif continue; } if( buffer[cc-1] == '\n' ) buffer[cc-1] = '\0'; diff --git a/bootblocks/commands.c b/bootblocks/commands.c index 459430d..9720cfe 100644 --- a/bootblocks/commands.c +++ b/bootblocks/commands.c @@ -1,29 +1,6 @@ #include "monitor.h" -#ifndef NOCOMMAND -extern unsigned int current_address; -extern int number_base; - -int cmd_quit(args) -char * args; -{ - printf("Bye\n"); - exit(0); -} - -int cmd_nop(ptr) -char * ptr; -{ -} - -int cmd_dir(ptr) -char * ptr; -{ - open_file("."); - return 0; -} - int cmd_type(ptr) char * ptr; { @@ -49,6 +26,29 @@ char * ptr; return 0; } +#ifndef NOCOMMAND +extern unsigned int current_address; +extern int number_base; + +int cmd_quit(args) +char * args; +{ + printf("Bye\n"); + exit(0); +} + +int cmd_nop(ptr) +char * ptr; +{ +} + +int cmd_dir(ptr) +char * ptr; +{ + open_file("."); + return 0; +} + int cmd_more(ptr) char * ptr; { @@ -117,12 +117,45 @@ int len; #ifndef NOMONITOR +cmd_monhelp() { +static char * helps[] = { + "Monitor help\n", + "zimage filename [args] Start Linux-386\n", + "bzimage filename [args] Start Linux-386\n", + "=filename [args] Start Linux-386\n", + "quit Reboot\n", + "help Display help file\n", + "dir Display directory\n", + "type Display file to screen\n", + "more Display file to screen\n", + "m[em] [address] Hexdump memory\n", + "seg [val] Set/show default segment\n", + "rel [segment] Relocate this program\n", + "base [val] Set default number base (or 'n' cmd)\n", + "init Re-init program\n", + "r[egs] Display register values\n", + + 0 +}; + char **p = helps; + more_char(-1); + + while(*p) + if( more_strn(*p, strlen(*p)) <0 ) + break; + else + p++; + printf("\n"); + return 0; +} + cmd_regs() { #ifdef __STANDALONE__ - printf("REGS: AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x\n", + printf(": AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x", __argr.x.ax, __argr.x.bx, __argr.x.cx, __argr.x.dx, __argr.x.si, __argr.x.di); + printf(" CS=%04x DS=%04x ES=%04x\n", __get_cs(), __get_ds(), __get_es()); #else printf("Only in standalone\n"); #endif diff --git a/bootblocks/cprintf.c b/bootblocks/cprintf.c new file mode 100644 index 0000000..3fefda3 --- /dev/null +++ b/bootblocks/cprintf.c @@ -0,0 +1,136 @@ + +#include <stdarg.h> + +static unsigned char * __numout(long i, int base); + +cputchar(ch) +int ch; +{ + if(ch == '\n') bios_putc('\r'); + return bios_putc(ch); +} + +cprintf(char * fmt, ...) +{ + register int c; + int count = 0; + int type, base; + long val; + char * cp; + char padch=' '; + int minsize = 0; + va_list ap; + + va_start(ap, fmt); + + while(c=*fmt++) + { + if(c!='%') + { + cputchar(c); + count++; + } + else + { + type=1; + padch = *fmt; + minsize=0; + if(padch == '-') fmt++; + + for(;;) + { + c=*fmt++; + if( c<'0' || c>'9' ) break; + minsize*=10; minsize+=c-'0'; + } + + while( c=='.' || (c>='0' && c<='9')) { c=*fmt++; } + + if( padch == '-' ) minsize = -minsize; + else + if( padch == '0' ) padch='0'; else padch=' '; + + if( c == 0 ) break; + if(c=='h') + { + c=*fmt++; + type = 0; + } + else if(c=='l') + { + c=*fmt++; + type = 2; + } + + switch(c) + { + case 'x': base=16; if(0) { + case 'o': base= 8; } if(0) { + case 'd': base=10; } + switch(type) + { + case 0: val=va_arg(ap, short); break; + case 1: val=va_arg(ap, int); break; + case 2: val=va_arg(ap, long); break; + default:val=0; break; + } + cp = __numout(val,base); + if(0) { + case 's': + cp=va_arg(ap, char *); + } + if( minsize > 0 ) + { + minsize -= strlen(cp); + while(minsize>0) { cputchar(padch); minsize--; } + minsize=0; + } + if( minsize < 0 ) minsize= -minsize-strlen(cp); + while(*cp) + cputchar(*cp++); + while(minsize>0) { cputchar(' '); minsize--; } + break; + case 'c': + cputchar(va_arg(ap, int)); + break; + default: + cputchar(c); + break; + } + } + } + va_end(ap); + return count; +} + +static char nstring[]="0123456789ABCDEF"; + +static unsigned char * +__numout(long i, int base) +{ + static unsigned char out[16]; + int n; + int flg = 0; + unsigned long val; + + if (i<0 && base==10) + { + flg = 1; + i = -i; + } + val = i; + + for (n = 0; n < 15; n++) + out[n] = ' '; + out[15] = '\0'; + n = 14; + do + { + out[n] = nstring[val % base]; + n--; + val /= base; + } + while(val); + if(flg) out[n--] = '-'; + return &out[n+1]; +} diff --git a/bootblocks/fs_dos.c b/bootblocks/fs_dos.c index bc223fc..6b0638e 100644 --- a/bootblocks/fs_dos.c +++ b/bootblocks/fs_dos.c @@ -19,19 +19,24 @@ #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))) #define get_uint(P,Off) *((unsigned short*)((char*)(P)+(Off))) #define get_long(P,Off) *((long*)((char*)(P)+(Off))) +typedef long Tsect; + static int read_bootblock(); static int dir_nentry, dir_sect; -static int dos_clust0, dos_spc, dos_fatpos, dos_fatlen; +static Tsect dos_clust0, dos_spc; +static int dos_fatpos, dos_fatlen, dos_fattype; static int last_serial = 0; #ifdef BUFFER_FAT static char * fat_buf = 0; +int use_fatbuf = 0; #endif static @@ -39,7 +44,7 @@ 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; } cur_file = { "", 0, 0, 0 }; @@ -47,7 +52,6 @@ struct filestatus { dos_open_file(fname) char * fname; { - extern union REGS __argr; char conv_name[12]; char *s, *d; int i; @@ -86,22 +90,31 @@ char * fname; memset(&cur_file, '\0', sizeof(cur_file)); #ifdef BUFFER_FAT - if( !dodir ) + if( !dodir && dos_fattype == 12 ) { /* Read in and buffer the FAT */ if( fat_buf ) free(fat_buf); fat_buf = malloc(dos_fatlen * 512); - if( fat_buf == 0 ) return -1; + if( fat_buf == 0 ) + use_fatbuf = 0; else { + use_fatbuf = 1; for(i=0; i<dos_fatlen; i++) { s = read_sector(dos_fatpos+i); - if(s == 0) return -1; + if(s == 0) + { + use_fatbuf = 0; + free(fat_buf); + fat_buf = 0; + } memcpy(fat_buf+i*512, s, 512); } } } + else + use_fatbuf = 0; #endif /* Scan the root directory for the file */ @@ -115,30 +128,36 @@ char * fname; #ifdef NOCOMMAND break; #else - char dtime[20]; + int dtime = 0; 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); + printf("%-8.8s %-3.3s %10ld", d, d+8, get_long(d,28)); + dtime=1; break; case 0x10: - printf("%-8.8s %-3.3s <DIR> %s\n", d, d+8, dtime); + printf("%-8.8s %-3.3s <DIR> ", d, d+8); + dtime=1; break; case 8: if( (d[11] & 7) == 0 ) - printf("%-11.11s <LBL> %s\n", d, dtime); + { + printf("%-11.11s <LBL> ", d); + dtime=1; + } break; } + if( dtime ) + printf(dtime, " %02d/%02d/%04d %02d:%02d\n", + (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( more_strn(lbuf, sizeof(lbuf)) < 0 ) break; #endif } @@ -151,7 +170,7 @@ char * fname; cur_file.cur_cluster = cur_file.first_cluster; cur_file.sector_no = 0; -#ifdef __ELKS__ +#ifdef DEBUG fprintf(stderr, "Opened first cluster %d, len %ld\n", cur_file.first_cluster, cur_file.file_length @@ -204,16 +223,18 @@ char * buffer; /* Is there an opened file ? */ if( cur_file.fname[0] == 0 ) { -#ifdef __ELKS__ +#ifdef DEBUG fprintf(stderr, "File is not currently open!\n"); #endif return -1; } - /* Are we before the EOF ? NB: FAT12 ONLY! */ - if( cur_file.cur_cluster >= 0xFF0 || cur_file.cur_cluster < 2 ) + /* Are we before the EOF ? */ + if( ( dos_fattype == 12 && cur_file.cur_cluster >= 0xFF0 ) || + ( dos_fattype == 16 && (cur_file.cur_cluster&0xFFF0) == 0xFFF0 ) || + cur_file.cur_cluster < 2 ) { -#ifdef __ELKS__ +#ifdef DEBUG fprintf(stderr, "Hit end of file; cluster 0x%03x\n", cur_file.cur_cluster); #endif @@ -222,9 +243,11 @@ char * buffer; for(s=0; s<2; s++) { - unsigned int sectno; + Tsect sectno; - if( cur_file.cur_cluster >= 0xFF0 || cur_file.cur_cluster < 2 ) + if( ( dos_fattype == 12 && cur_file.cur_cluster >= 0xFF0 ) || + ( dos_fattype == 16 && (cur_file.cur_cluster&0xFFF0) == 0xFFF0 ) || + cur_file.cur_cluster < 2 ) { memset(buffer, '\0', 512); buffer += 512; @@ -242,31 +265,43 @@ char * buffer; cur_file.sector_no++; if( cur_file.sector_no % dos_spc == 0 ) { - int odd = (cur_file.cur_cluster&1); - unsigned int val, val2; + if( dos_fattype == 12 ) + { + int odd = (cur_file.cur_cluster&1); + unsigned int val, val2; - val = cur_file.cur_cluster + (cur_file.cur_cluster>>1); + val = cur_file.cur_cluster + (cur_file.cur_cluster>>1); #ifdef BUFFER_FAT - val2 = get_uint(fat_buf, val); -#else - ptr = read_sector(dos_fatpos+(val/512)); - if( ptr == 0 ) return -1; - if( val%512 == 511 ) + if( use_fatbuf ) + val2 = get_uint(fat_buf, val); + else +#endif + { + ptr = read_sector(dos_fatpos+(val/512)); + if( ptr == 0 ) return -1; + if( val%512 == 511 ) + { + val2 = (ptr[511]&0xFF); + ptr = read_sector(dos_fatpos+(val/512)+1); + if( ptr == 0 ) return -1; + val2 |= (ptr[0]<<8); + } + else + val2 = get_uint(ptr, (val%512)); + } + + if( odd ) val2>>=4; + + val2 &= 0xFFF; + + cur_file.cur_cluster = val2; + } + else { - val2 = (ptr[511]&0xFF); - ptr = read_sector(dos_fatpos+(val/512)+1); + ptr = read_sector(dos_fatpos+(cur_file.cur_cluster/256)); if( ptr == 0 ) return -1; - val2 |= (ptr[0]<<8); + cur_file.cur_cluster = get_uint(ptr, (cur_file.cur_cluster%256*2)); } - else - val2 = get_uint(ptr, (val%512)); -#endif - - if( odd ) val2>>=4; - - val2 &= 0xFFF; - - cur_file.cur_cluster = val2; } buffer += 512; @@ -303,6 +338,13 @@ static int read_bootblock() dos_fatpos = DOS_RESV(sptr); dos_fatlen = DOS_FATLEN(sptr); dos_spc = DOS_CLUST(sptr); + dos_fattype = DOS4_FATTYPE(sptr); + switch(dos_fattype) + { + case '1'+'6'*256: dos_fattype = 16; break; + case '1'+'2'*256: + default: dos_fattype = 12; break; + } if( dos_spc < 1 ) dos_spc = 1; dos_clust0 = dir_sect + (dir_nentry+15)/16 - 2*dos_spc; diff --git a/bootblocks/fs_tar.c b/bootblocks/fs_tar.c index 1dac3a4..a5cd55d 100644 --- a/bootblocks/fs_tar.c +++ b/bootblocks/fs_tar.c @@ -49,7 +49,9 @@ tar_open_file(fname) char * fname; { HEADER * sptr; +#ifndef NOCOMMAND int dodir = 0; +#endif int sectno; #ifdef __STANDALONE__ @@ -64,9 +66,11 @@ char * fname; tar_set_drive(); +#ifndef NOCOMMAND if( strcmp(fname, ".") == 0 ) dodir=1; else +#endif { if( tar_status.diskoffset == 0 && strcmp(fname, tar_status.name) == 0 ) return tar_rewind_file(); @@ -92,8 +96,10 @@ char * fname; if( sptr->member.m_linked != 0 && sptr->member.m_linked != '0' ) ; +#ifndef NOCOMMAND else if( dodir ) printf("%s %d tape blocks\n", sptr->member.m_name, (int)v-1); +#endif else if( strcmp(fname, sptr->member.m_name, NAME_SIZE) == 0 ) { strncpy(tar_status.name, sptr->member.m_name, NAME_SIZE); @@ -229,10 +235,10 @@ int type; } valid_tar_checksum(sptr) -HEADER * sptr; +register HEADER * sptr; { register char *ptr; - register int ac = 0; + int ac = 0; ptr = sptr->hdr_block; while (ptr < sptr->hdr_block+sizeof(sptr->hdr_block)) @@ -257,6 +263,7 @@ tar_set_drive() */ if( disk_spt <= 9 ) disk_cyls = 40; if( disk_spt == 21 || disk_spt > 36 ) disk_cyls = 82; + else if( disk_spt == 32 ) disk_cyls = 1024; else disk_cyls = 80; #else disk_spt = 18; /* Testing only */ diff --git a/bootblocks/help.c b/bootblocks/help.c index 3d53fad..049aa3d 100644 --- a/bootblocks/help.c +++ b/bootblocks/help.c @@ -7,6 +7,8 @@ #include "monitor.h" +#ifndef NOCOMMAND + struct keys { int key; int rel; @@ -33,12 +35,19 @@ struct keys { cmd_help(ptr) char * ptr; { -static int lastpage = 0; int helpkey = 1; - int i; getnum(&ptr, &helpkey); + return help_key(helpkey); +} + +help_key(helpkey) +int helpkey; +{ +static int lastpage = 0; + int i; + for(i=0; keys[i].key; i++) if( keys[i].key == helpkey || i == helpkey ) break; @@ -90,3 +99,4 @@ int page; return 0; } +#endif diff --git a/bootblocks/i86_funcs.c b/bootblocks/i86_funcs.c index b45343e..7b88da2 100644 --- a/bootblocks/i86_funcs.c +++ b/bootblocks/i86_funcs.c @@ -116,12 +116,10 @@ void cpu_check() void mem_check() { - if (x86_test) - { - main_mem_top = 16384; - return; /* If not standalone don't try */ - } - +#ifndef __STANDALONE__ + main_mem_top = 16384; + return; /* If not standalone don't try */ +#else { #asm int 0x12 ! Amount of boot memory @@ -150,6 +148,7 @@ got_ext: { /* It say 64Mb-1k - Hmmmm I think it might be 128! */ } +#endif } #define RIGHTS (0x93000000L) diff --git a/bootblocks/lsys.c b/bootblocks/lsys.c index 77f3931..442e920 100644 --- a/bootblocks/lsys.c +++ b/bootblocks/lsys.c @@ -1,5 +1,6 @@ #include "msdos.v" +#include "msdos16.v" #define DOS_SYSID 0x03 #define DOS_SECT 0x0B @@ -31,8 +32,8 @@ char ** argv; if( argc > 1 ) { - static char * s = "Usage: sys a:"; - if( argc == 1 && argv[1][1] == ':' && argv[1][2] == 0 ) + static char * s = "Usage: lsys [a:]\n"; + if( argc == 2 && argv[1][1] == ':' && argv[1][2] <= ' ' ) { if( argv[1][0] == 'a' || argv[1][0] == 'A' ) drive = 0; @@ -57,26 +58,37 @@ char ** argv; if( buffer[DOS_MEDIA] != buffer[512] || buffer[DOS_MEDIA] < 0xF0 || buffer[DOS_NFAT] > 2 || - buffer[DOS_SECT+1] != 2 || - buffer[DOS_HEADS] != 2 ) + buffer[DOS_SECT+1] != 2 ) fatal("Floppy has invalid format"); - for(i=0; i<msdos_dosfs_stat; i++) - buffer[i] = msdos_data[i]; - for(i=msdos_codestart; i<512; i++) - buffer[i] = msdos_data[i]; + if( memcmp(buffer+DOS4_FATTYPE, "FAT16", 5) ) + { + for(i=0; i<msdos_dosfs_stat; i++) + buffer[i] = msdos_data[i]; + for(i=msdos_codestart; i<512; i++) + buffer[i] = msdos_data[i]; + } + else + { + for(i=0; i<msdos16_dosfs_stat; i++) + buffer[i] = msdos16_data[i]; + for(i=msdos_codestart; i<512; i++) + buffer[i] = msdos16_data[i]; + } for(tries=0; tries<6; tries++) - if( (rv = dos_sect_read(drive, 0, 0, 1, buffer)) == 0 ) + if( (rv = dos_sect_write(drive, 0, 0, 1, buffer)) == 0 ) break; if( rv ) fatal("Cannot write bootsector"); + write(0, "Wrote bootsector\r\n", 18); return 0; } fatal(str) { write(0, str, strlen(str)); + write(0, "\r\n", 2); exit(1); } diff --git a/bootblocks/makeboot.c b/bootblocks/makeboot.c index 4eda4c6..c749d20 100644 --- a/bootblocks/makeboot.c +++ b/bootblocks/makeboot.c @@ -2,10 +2,12 @@ #include <stdio.h> #include <ctype.h> #include <time.h> +#include <string.h> #include "sysboot.v" #include "noboot.v" #include "msdos.v" +#include "msdos16.v" #include "skip.v" #include "tarboot.v" #include "minix.v" @@ -31,18 +33,39 @@ struct bblist { char * desc; char * data; int size; + int name_type; + int boot_name; int fstype; + int fsmod; } bblocks[] = { -{ "tar", "Bootable GNU tar volume lable", tarboot_data, tarboot_size, FS_TAR}, -{ "dosfs","Boot file BOOTFILE.SYS from dosfs", msdos_data, msdos_size, FS_ADOS}, -{ "none", "No OS bootblock, just message", noboot_data, noboot_size, FS_DOS}, -{ "skip", "Bypasses floppy boot with message", skip_data, skip_size, FS_DOS}, -{ "minix","Minix floppy FS booter", minix_data, minix_size, FS_ZERO}, -{ "hdmin","Minix Hard disk FS booter", minixhd_data, minixhd_size, FS_ZERO}, -{ "mbr", "Master boot record for HD", mbr_data,mbr_size, FS_MBR}, -{ "stat", "Display dosfs superblock", 0, 0, FS_STAT}, -{ "copy", "Copy boot block to makeboot.sav", 0, 0, FS_STAT}, -{ "Zap", "Clear boot block to NULs", 0, 1024, FS_NONE}, +{ "tar", "Bootable GNU tar volume lable", + tarboot_data, tarboot_size, 0, 0, FS_TAR}, +{ "dosfs","Boot file BOOTFILE.SYS from dos floppy", + msdos_data, msdos_size, + 1, msdos_boot_name-msdos_start, FS_DOS, 12}, +{ "dos16","Boot file BOOTFILE.SYS from 16 bit dos floppy", + msdos16_data, msdos16_size, + 1, msdos16_boot_name-msdos16_start, FS_DOS, 16}, +{ "none", "No OS bootblock, just message", + noboot_data, noboot_size, + 2, noboot_boot_message-noboot_start, FS_DOS}, +{ "skip", "Bypasses floppy boot with message", + skip_data, skip_size, + 2, skip_mesg-skip_start, FS_DOS}, +{ "minix","Minix floppy FS booter", + minix_data, minix_size, + 2, minix_bootfile-minix_start, FS_ZERO}, +{ "hdmin","Minix Hard disk FS booter", + minixhd_data, minixhd_size, + 2, minixhd_bootfile-minixhd_start, FS_ZERO}, +{ "mbr", "Master boot record for HD", + mbr_data,mbr_size, 0, 0, FS_MBR}, +{ "stat", "Display dosfs superblock", + 0, 0, 0, 0, FS_STAT}, +{ "copy", "Copy boot block to makeboot.sav", + 0, 0, 0, 0, FS_STAT}, +{ "Zap", "Clear boot block to NULs", + 0, 1024, 0, 0, FS_NONE}, 0 }; @@ -60,6 +83,8 @@ int write_zero = 1; /* Write sector 0 */ int write_one = 0; /* Write sector 1 */ int bs_offset = 0; /* Offset of _real_ bootsector for 2m floppies */ +char * boot_id = 0; + main(argc, argv) int argc; char ** argv; @@ -76,6 +101,10 @@ char ** argv; } if( argc != 3 ) Usage(); + boot_id = strchr(argv[1], '='); + if( boot_id ) + *boot_id++ = '\0'; + if( (i=strlen(argv[1])) < 2 ) Usage(); for(ptr = bblocks; ptr->name; ptr++) if( strncmp(argv[1], ptr->name, i) == 0 ) break; @@ -93,12 +122,10 @@ char ** argv; { case FS_NONE: /* override */ break; - case FS_ADOS: - check_simpledos(); - break; case FS_DOS: case FS_STAT: check_msdos(); + if(ptr->fsmod) check_simpledos(ptr->fsmod); break; case FS_TAR: check_tar(); @@ -123,7 +150,6 @@ char ** argv; save_super(buffer); close_disk(); exit(0); - case FS_ADOS: case FS_DOS: for(i=0; i<sysboot_dosfs_stat; i++) buffer[i] = ptr->data[i]; @@ -139,9 +165,10 @@ char ** argv; copy_mbr(ptr->data); break; + case FS_ZERO: case FS_NONE: if( ptr->data ) - memcpy(buffer, ptr->data, 512); + memcpy(buffer, ptr->data, ptr->size); else { memset(buffer, '\0', 1024); @@ -150,6 +177,19 @@ char ** argv; break; } + if( boot_id ) switch(ptr->name_type) + { + case 1: + set_dosname(ptr->boot_name); + break; + case 2: + set_asciz(ptr->boot_name); + break; + default: + fprintf(stderr, "Cannot specify boot file for this block\n"); + exit(1); + } + if( bs_offset ) { if( write_zero ) do_2m_write(); @@ -172,11 +212,12 @@ Usage() progname = "makeboot"; #ifdef __MSDOS__ - fprintf(stderr, "Usage: %s [-f] bootname a:\n", progname); + fprintf(stderr, "Usage: %s [-f] bootblock[=bootname] a:\n", progname); #else - fprintf(stderr, "Usage: %s [-f] bootname /dev/fd0\n", progname); + fprintf(stderr, "Usage: %s [-f] bootblock[=bootname] /dev/fd0\n", progname); #endif - fprintf(stderr, "Blocks\n"); + fprintf(stderr, "\nThe bootname is a filename to use with the block,\n"); + fprintf(stderr, "the blocks are:\n"); for(;ptr->name; ptr++) fprintf(stderr, "\t%s\t%s\n", ptr->name, ptr->desc); exit(1); @@ -189,6 +230,9 @@ open_disk(diskname) char * diskname; { #ifdef __MSDOS__ + /* Freedos fix */ + if( diskname[2] == '\r' ) diskname[2] = 0; + if( strcmp("a:", diskname) == 0 ) { disktype = 1; return 0; } if( strcmp("b:", diskname) == 0 ) { disktype = 2; return 0; } if( strcmp("A:", diskname) == 0 ) { disktype = 1; return 0; } @@ -199,7 +243,7 @@ char * diskname; if( diskfd == 0 ) diskfd = fopen(diskname, "r"); if( diskfd == 0 ) { - fprintf(stderr, "Cannot open %s\n", diskname); + fprintf(stderr, "Cannot open '%s'\n", diskname); exit(1); } return 0; @@ -516,7 +560,8 @@ copy_tarblock() struct bootfields { int offset; int length; - int value; + unsigned value; + long lvalue; } dosflds[] = { @@ -606,6 +651,7 @@ char * bootsect; v = v*256 + (0xFF&( bootsect[dosflds[i].offset+j] )); } dosflds[i].value = v; + dosflds[i].lvalue = v; } else dosflds[i].value = 0; @@ -616,7 +662,11 @@ save_super(bootsect) char * bootsect; { FILE * fd; - fd = fopen("makeboot.sav", "wb"); + char * fname = "makeboot.sav"; + if( boot_id ) fname = boot_id; + + printf("Copying boot block to '%s'\n", fname); + fd = fopen(fname, "wb"); fwrite(bootsect, 1024, 1, fd); fclose(fd); } @@ -675,11 +725,12 @@ check_msdos() if(!force) exit(2); } -check_simpledos() +check_simpledos(bb_fatbits) +int bb_fatbits; { - int numclust = 0xFFFF; + unsigned numclust = 0xFFFF; char * err = 0; - check_msdos(); + int fatbits = 0; /* Work out how many real clusters there are */ if( dosflds[DOS_MAXSECT].value + 2 > 2 ) @@ -687,29 +738,112 @@ check_simpledos() - dosflds[DOS_RESV].value - dosflds[DOS_NFAT].value * dosflds[DOS_FATLEN].value - ((dosflds[DOS_NROOT].value+15)/16) - ) / dosflds[DOS_MAXSECT].value + 2; + ) / dosflds[DOS_CLUST].value + 2; + else + numclust = ( dosflds[DOS4_MAXSECT].lvalue + - dosflds[DOS_RESV].value + - dosflds[DOS_NFAT].value * dosflds[DOS_FATLEN].value + - ((dosflds[DOS_NROOT].value+15)/16) + ) / dosflds[DOS_CLUST].value + 2; + + if( memcmp(buffer+dosflds[DOS4_FATTYPE].offset, "FAT12", 5) == 0 ) + fatbits=12; + else if( memcmp(buffer+dosflds[DOS4_FATTYPE].offset, "FAT16", 5) == 0 ) + fatbits=16; + else + fatbits=12+4*(numclust > 0xFF0); if( dosflds[DOS_NFAT].value > 2 ) err = "Too many fat copies on disk"; - else if( dosflds[DOS_HIDDEN].value != 0 ) - err = "Dubious MSDOS floppy, it's got hidden sectors."; else if( dosflds[DOS_NROOT].value < 15 ) err = "Root directory has unreasonable size."; else if( dosflds[DOS_SECT].value != 512 ) err = "Drive sector size isn't 512 bytes sorry no-go."; - else if( dosflds[DOS_HEADS].value != 2 ) - err = "Drive doesn't have two heads, this is required."; - else if( numclust > 0xFF0 ) - err = "Filesystem has a 16 bit fat, only 12bits allowed."; - else if( dosflds[DOS_RESV].value + dosflds[DOS_FATLEN].value > - dosflds[DOS_SPT].value ) - err = "The bootblock needs all of fat1 on the first track."; - else - return; + else if( fatbits != bb_fatbits ) + err = "Filesystem has the wrong fat type for this bootblock."; + else if( numclust * dosflds[DOS_CLUST].lvalue / + dosflds[DOS_SPT].value > 65535 ) + err = "Maximum of 65535 tracks allowed, sorry"; - fprintf(stderr, "ERROR: %s\n\n", err); - print_super(buffer); - if(!force) exit(2); + if( !err && bb_fatbits == 12 ) + { + if( (0x7C00-msdos_start-512)/512 < dosflds[DOS_FATLEN].value ) + err = "The FAT is too large to load in the available space."; + else if( dosflds[DOS_RESV].value + dosflds[DOS_FATLEN].value > + dosflds[DOS_SPT].value ) + err = "The bootblock needs all of fat1 on the first track."; + else if( msdos_heads == 2 && dosflds[DOS_HEADS].value != 2 ) + err = "Drive doesn't have two heads, this is required."; + else if( dosflds[DOS_HIDDEN].lvalue != 0 ) + err = "MSDOS floppies shouldn't have hidden sectors."; + } + + if( err ) + { + fprintf(stderr, "ERROR: %s\n\n", err); + print_super(buffer); + if(!force) exit(2); + } +} + +set_dosname(boot_name) +int boot_name; +{ + char dos_name[20]; + int i,j; + + strcpy(dos_name, " "); + + for(i=0; boot_id[i] && boot_id[i] != '.' && i<16; i++) + dos_name[i] = toupper(boot_id[i]); + + if( boot_id[i] == '.' ) + { + for(j=8,i++; boot_id[i] && boot_id[i] != '.' && j<16; i++,j++) + dos_name[j] = toupper(boot_id[i]); + } + + printf("Bootfile set to '%11.11s'\n", dos_name); + + memcpy(buffer+boot_name, dos_name, 11); +} + +set_asciz(boot_name) +int boot_name; +{ + int i, j; + + for(i=boot_name; buffer[i]; i++) ; + for( ; !buffer[i]; i++) ; + i = i - boot_name -1; + + if( strlen(boot_id) > i ) + { + fprintf(stderr, "Filename '%s' is too long for bootblock\n"); + exit(1); + } + else + { + for(i=0,j=boot_name; boot_id[i]; i++) + { + if( boot_id[i] == '\\' && boot_id[i+1] ) + { + i++; + switch(boot_id[i]) + { + case 'n': buffer[j++] = '\n'; break; + case 'r': buffer[j++] = '\r'; break; + case 'b': buffer[j++] = '\b'; break; + case 't': buffer[j++] = '\t'; break; + case 'a': buffer[j++] = '\007'; break; + case 'e': buffer[j++] = '\033'; break; + default: buffer[j++] = boot_id[i]; break; + } + } + else buffer[j++] = boot_id[i]; + } + buffer[j] = 0; + } } check_mbr() diff --git a/bootblocks/mbr.s b/bootblocks/mbr.s index 0d8560e..3a22984 100644 --- a/bootblocks/mbr.s +++ b/bootblocks/mbr.s @@ -90,7 +90,7 @@ bad_boot: cmp si,#bootblock_magic jnz check_active - # Check for Disk manager partitions (12 more!) + ! Check for Disk manager partitions (12 more!) if diskman cmp word ptr diskman_magic,#$55AA jnz no_diskman diff --git a/bootblocks/min_buf.c b/bootblocks/min_buf.c index 97324f3..797ee7b 100644 --- a/bootblocks/min_buf.c +++ b/bootblocks/min_buf.c @@ -8,17 +8,18 @@ int disk_drive = 0; int disk_spt = 7; -int disk_heads = 2; +int disk_heads = 0; int disk_cyls = 0; int bad_track = -1; -static int track_no = -1; +static int track_no = -1; +static int buf_len = 0; static char buffer[MAXTRK*512]; void reset_disk() { disk_spt = 7; - disk_heads = 2; + disk_heads = 0; disk_cyls = 0; bad_track = -1; } @@ -35,6 +36,7 @@ long sectno; int ltrack; if( sectno == 0 ) reset_disk(); + if( buf_len != disk_spt ) track_no = -1; if( disk_spt < 1 || disk_heads < 1 ) phy_s = sectno; @@ -45,31 +47,34 @@ long sectno; phy_c = sectno/disk_spt/disk_heads; } -#ifdef __ELKS__ +#ifdef DEBUG fprintf(stderr, "read_sector(%ld = %d,%d,%d)\n", sectno, phy_c, phy_h, phy_s); #endif ltrack = phy_c*disk_heads+phy_h; - if( disk_spt > 7 && disk_spt <= MAXTRK + if( disk_spt > 1 && disk_spt <= MAXTRK && track_no != ltrack && ltrack != bad_track) { rv = phy_read(disk_drive, phy_c, phy_h, 1, disk_spt, buffer); if( rv == 0 ) + { track_no = ltrack; + buf_len = disk_spt; + } else bad_track = ltrack; } - if( track_no == phy_c*disk_heads+phy_h ) + if( track_no == ltrack ) return buffer + phy_s * 512; do { rv = phy_read(disk_drive, phy_c, phy_h, phy_s+1, 1, buffer); tries--; - if( rv ) printf("Error in phy_read(%d,%d,%d,%d,%d,%d);\n", - disk_drive, phy_c, phy_h, phy_s+1, 1, buffer); } while(rv && tries > 0); + if( rv ) printf("Disk error 0x%02x %d:%d:%d:%d[%2d] -> 0x%04x[]\n", + rv, disk_drive, phy_c, phy_h, phy_s+1, 1, buffer); if(rv) return 0; else return buffer; } diff --git a/bootblocks/monitor.c b/bootblocks/monitor.c index a44bad7..4fecfd7 100644 --- a/bootblocks/monitor.c +++ b/bootblocks/monitor.c @@ -8,7 +8,7 @@ typedef int (*proc)(); int cmd_quit(), cmd_dump(), cmd_seg(), cmd_rel(), cmd_bzimage(), cmd_help(); int cmd_nop(), cmd_memdump(), cmd_set_base(), cmd_dir(), cmd_type(), cmd_more(); -int cmd_regs(); +int cmd_regs(), cmd_monhelp(); void init_prog(); @@ -33,6 +33,7 @@ static char minibuf[2] = " "; init_prog(); #ifdef __STANDALONE__ +#if 0 #ifndef NOCOMMAND if( __get_ds() != 0x1000 ) { @@ -42,12 +43,17 @@ static char minibuf[2] = " "; printf("Relocated to CS=$%04x DS=$%04x\n", __get_cs(), __get_ds()); } #endif +#else + printf("Loaded at CS=$%04x DS=$%04x\n", __get_cs(), __get_ds()); +#endif if( (__argr.x.dx & 0xFF) == 0 ) #endif { +#ifdef NOCOMMAND + cmd_type("help.txt"); +#else display_help(0); -#ifndef NOCOMMAND if( x86 > 2 && !x86_emu ) /* Check some basics */ #endif cmd_bzimage((void*)0); @@ -70,8 +76,9 @@ static char minibuf[2] = " "; command_buf[ch] = '\0'; if( ch == 1 && command_buf[0] != '\n' ) { - sprintf(command_buf, "?$%02x\n", command_buf[0]&0xFF); - printf("%s", command_buf); + putchar('\n'); + help_key(command_buf[0]&0xFF); + continue; } if( command_buf[ch-1] == '\n' ) command_buf[ch-1] = 0; @@ -241,7 +248,6 @@ struct t_cmd_list cmd_list[] = {"exit", cmd_quit}, {"quit", cmd_quit}, {"q", cmd_quit}, {"#", cmd_nop}, {"help", cmd_help}, /* Display from help.txt */ - {"?", cmd_help}, /* Display from help.txt */ {"dir", cmd_dir}, /* Display directory */ {"cat", cmd_type}, /* Cat/Type a file to the screen */ {"type", cmd_type}, /* Cat/Type a file to the screen */ @@ -249,6 +255,8 @@ struct t_cmd_list cmd_list[] = #ifndef NOMONITOR /* Debugger/monitor commands */ + {"?", cmd_monhelp}, /* Display builtin help */ + {"memdump",cmd_memdump}, {"mem",cmd_memdump}, {"m", cmd_memdump}, /* Display bytes */ {"seg", cmd_seg}, /* Set default segment */ @@ -257,6 +265,7 @@ struct t_cmd_list cmd_list[] = {"n", cmd_set_base}, {"init", init_prog}, + {"regs", cmd_regs}, {"reg", cmd_regs}, {"r", cmd_regs}, diff --git a/bootblocks/monitor.h b/bootblocks/monitor.h index de42a20..7674afd 100644 --- a/bootblocks/monitor.h +++ b/bootblocks/monitor.h @@ -2,7 +2,7 @@ #include <stdio.h> #include <errno.h> #include <ctype.h> -#include <dos.h> +#include <bios.h> #include <malloc.h> #include "i86_funcs.h" #include "readfs.h" @@ -11,14 +11,12 @@ #define X_DOSFLOPPY #define X_CALC_CRC - #ifdef __STANDALONE__ #define COLOUR extern union REGS __argr; #endif - #ifdef TARFLOPPY #define SINGLEFS #define NOMONITOR @@ -45,3 +43,11 @@ extern union REGS __argr; #define file_length dos_file_length #define read_block dos_read_block #endif + +#if 1 +#undef putchar +#define putchar cputchar +#define printf cprintf +#define fflush(x) +#endif + diff --git a/bootblocks/msdos.s b/bootblocks/msdos.s index 72e2a11..11a4fe4 100644 --- a/bootblocks/msdos.s +++ b/bootblocks/msdos.s @@ -1,32 +1,42 @@ -! -! This is a bootblock to load an execute a standalone program from an -! MSDOS filesystem on a floppy disk. -! -! The file loaded is called 'BOOTFILE.SYS' it can be changed at install time -! by following the label boot_name. -! -! The file is loaded at address $7C00, this means it can be the image of a -! boot block (eg LILO). It's also checked for the magic number associated -! with a Linux-8086 standalone executable and this is used if found. +!--------------------------------------------------------------------------- +!! This is a bootblock to load an execute a standalone program from an +!! MSDOS filesystem on a floppy disk. +!! +!! The file loaded is called 'BOOTFILE.SYS' and is loaded at address $7C00. +!--------------------------------------------------------------------------- +! The filename can be changed at install time by following the label +! boot_name, because the file is loaded at address $7C00 it can be the +! image of a boot block (eg LILO). It's also checked for the magic number +! associated with a Linux-8086 standalone executable and this is used if +! it's found. ! ! There are a number of assumptions made by the code concerning the layout ! of the msdos files system: ! -! 1) All of the first FAT must be on the first track. +! 1) All of the first 12 bit FAT must be on the first track. ! 2) The FAT must be 12 bit ! 3) The value of the hidden sectors field must be zero -! 4) There must be two heads on the disk. ! ! All these are true for mtools created floppies on normal PC drives. -! +!--------------------------------------------------------------------------- ORGADDR=$0500 use16 ! Some configuration values LOADSEG= $7C0 +export fatbits +fatbits=12 ! Set to 12 or 16 (16 for LS-120 disks) + +export heads + +if fatbits =12 +heads=2 ! This can be 0,1 or 2. 0 is dynamic. +else +heads=0 ! This can be 0,1 or 2. 0 is dynamic. +endif -!------------------------------------------------------------------------- +!--------------------------------------------------------------------------- ! Absolute position macro, fails if code before it is too big. macro locn if *-start>?1 @@ -35,18 +45,16 @@ macro locn .blkb ?1 + start-* mend -heads=2 ! This can be 1 or 2 ONLY. (1 is untested) - org ORGADDR start: include sysboot.s +!--------------------------------------------------------------------------- ! Data into the temp area, 30 clear bytes org floppy_temp root_count: .blkw 1 -old_bpb: .blkw 2 -bios_disk: .blkb 12 +!--------------------------------------------------------------------------- locn(codestart-start) cld ! Assume _nothing_! @@ -68,7 +76,6 @@ cont: ! DONT Need to fix BPB for fd0 to correct sectors (Like linux bootblock does) ! as we only ever read one sector at a time. - ! For each sector in root dir ! For each dir entry ! If entry name is == boot_name @@ -102,7 +109,7 @@ nextsect: mov si,bx nextentry: - ! Test attributes for !dir !label here ? + ! TODO: Test attributes for !dir !label here ? ! test entry name push si @@ -129,13 +136,16 @@ bad_entry: jp nextsect jmp no_system -! Convert a cluster number in AX into a CHS in CX:DX +!--------------------------------------------------------------------------- +! Convert a cluster number in DI into a CHS in CX:DX linclust: + mov ax,di sub ax,#2 mov dl,[dos_clust] xor dh,dh mul dx add ax,bp ! Add sector number of first data sector. + adc dx,#0 jmp linsect2 ! @@ -144,22 +154,36 @@ linclust: ! linsect: mov ax,di -linsect2: +linsect1: xor dx,dx +linsect2: + if fatbits =16 + add ax,[dos_hidden] + adc dx,[dos_hidden+2] + endif div [dos_spt] inc dx - mov cl,dl ! Sector num - xor dx,dx ! Drive 0 + mov cl,dl ! Sector num + xor dx,dx ! Drive 0 if heads =2 - shr ax,#1 ! Assume dos_heads == 2 - adc dh,#0 ! Head num + shr ax,#1 ! Assume dos_heads == 2 + adc dh,#0 ! Head num + endif + if heads =0 + div [dos_heads] + xchg dh,dl + endif + mov ch,al ! Cylinder bits 0-7 + if heads =0 + sar ax,#1 ! Cylinder bits 8&9 + sar ax,#1 + and al,#$C0 + or cl,al endif - mov ch,al ! Cylinder ret -error_msg: - .asciz "\r\nError during initial boot\r\nPress a key:" - +!--------------------------------------------------------------------------- +! Error processing. no_system: floppy_error: @@ -178,7 +202,7 @@ EOS: int $19 ! This should be OK as we haven't touched anything. jmpi $0,$FFFF ! Wam! Try or die! -! +!--------------------------------------------------------------------------- ! This loads the boot program 1 sector at a time, funny thing is it actually ! loads at exactly the same speed as loading a track at a time, at least on ! my slow old 286/8Mhz. Oh well, we need the space so if you're worried just @@ -186,6 +210,7 @@ EOS: ! load_system: + if fatbits =12 push ax ! Save cluster we're loading ! 1) Load FAT @@ -198,19 +223,20 @@ load_system: xor dx,dx ! Head zero int $13 jc floppy_error + pop di ! Cluster to start load. + else + mov di,ax + endif mov ax,#LOADSEG mov es,ax - pop di ! Cluster to start load. ! load whole cluster next_cluster: mov si,[dos_clust] ! How big is a cluster and si,#255 - - mov ax,di ! Find it's physical address - call linclust + call linclust ! Find it's physical address next: mov ax,#$0201 @@ -231,6 +257,12 @@ next: jnz sectok xor dh,dh endif + if heads=0 + inc dh + cmp dh,[dos_heads] ! Nb low byte only. + jnz sectok + xor dh,dh + endif inc ch sectok: inc cl @@ -242,6 +274,7 @@ sectok: jmp maincode next_fat: + if fatbits =12 mov ax,di shr ax,#1 pushf ! Save if odd number @@ -255,8 +288,44 @@ noshift: and di,#$FFF cmp di,#$FF0 ! FFF is EOF, clear carry flag. ! FF0+ are badblocks etc. + endif + + if fatbits =16 + mov ax,di + ! load fat sector AH (if it's not already loaded) + + xchg ah,al + xor ah,ah + add ax,[dos_resv] + + cmp ax,[fatsect] + jz got_fsect + mov [fatsect],ax + + call linsect1 + + push es + mov bx,#fat_table + xor ax,ax + mov es,ax + mov ax,#$0201 + int $13 + pop es + jnc got_fsect + br floppy_error + +got_fsect: + ! Load di with cluster number in di + and di,#$FF + shl di,#1 + mov di,fat_table[di] + cmp di,#$FFF0 + endif + ret +!--------------------------------------------------------------------------- +! File is now loaded, execute it. maincode: mov bx,#7 mov ax,#$0E3E @@ -292,7 +361,22 @@ impure: ! AX=ds, BX=cs, CX=X, DX=X, SI=X, DI=0, BP=X, ES=X, DS=*, SS=*, CS=* retf bad_magic: - jmpi $7C00,0 ! No magics, just go. + pop cx + jmpi LOADSEG<<4,0 ! No magics, just go. + +!--------------------------------------------------------------------------- +! initilised data + +fatsect: + .word 0 + +! if fatbits =16 +error_msg: + .asciz "\r\nError during initial boot\r\nPress a key:" +! else +! error_msg: +! .asciz "\r\nBoot error:" +! endif export boot_name boot_name: @@ -300,6 +384,13 @@ boot_name: name_end: ! NNNNNNNNEEE -locn(512) +if fatbits =16 +locn(510) + .word 0 ! This is a floppy so it should not need the magic _but_ + ! the debian MBR requires the magic even on floppies + ! so only clear on a superfloppy (LS-120). +endif + fat_table: ! This is the location that the fat table is loaded. - ! Note: The fat must be entirely on track zero. + ! Note: The fat must be entirely on track zero if 12 bit. +!--------------------------------------------------------------------------- diff --git a/bootblocks/noboot.s b/bootblocks/noboot.s index 7ab9f4e..22e1312 100644 --- a/bootblocks/noboot.s +++ b/bootblocks/noboot.s @@ -13,11 +13,8 @@ org codestart mov sp,ax jmpi code,#0 -no_os: - .asciz "PANIC! NO OS Found!\r\n" - code: ! SI = pointer to error message - mov si,#no_os + mov si,#boot_message nextc: lodsb cmp al,#0 @@ -30,3 +27,8 @@ eos: ! Wait for a key then reboot xor ax,ax int $16 jmpi $0,$FFFF ! Wam! Try or die! + +export boot_message +boot_message: + .asciz "PANIC! NO OS Found!\r\n" + diff --git a/bootblocks/skip.s b/bootblocks/skip.s index 3e55cd9..0c1184d 100644 --- a/bootblocks/skip.s +++ b/bootblocks/skip.s @@ -52,16 +52,6 @@ error: call prtmsg jmp hcode - if BOOTDISK = 0x80 -mesg: .asciz "Bypassing floppy boot\r\n" - else -mesg: .asciz "Booting drive two\r\n" - endif - -mesg2: .asciz "Disk error\r\n" -mesg3: .asciz "Retrying\r\n" -mesg4: .asciz "Press a key:" - prtmsg: lodsb cmp al,#0 @@ -82,3 +72,14 @@ reboot: int $19 ! This should be OK as we haven't touched anything. jmpi $0,$FFFF ! Wam! Try or die! +mesg2: .asciz "Disk error\r\n" +mesg3: .asciz "Retrying\r\n" +mesg4: .asciz "Press a key:" + +export mesg + if BOOTDISK = 0x80 +mesg: .asciz "Bypassing floppy boot\r\n" + else +mesg: .asciz "Booting drive two\r\n" + endif + diff --git a/bootblocks/standalone.c b/bootblocks/standalone.c index 3fb0e28..8344c64 100644 --- a/bootblocks/standalone.c +++ b/bootblocks/standalone.c @@ -1,5 +1,5 @@ -#include <dos.h> +#include <bios.h> #include <errno.h> #asm entry _int_80 ! Tell ld86 we really do need this file. diff --git a/bootblocks/tarboot.s b/bootblocks/tarboot.s index 2e31570..f872ad0 100644 --- a/bootblocks/tarboot.s +++ b/bootblocks/tarboot.s @@ -93,7 +93,7 @@ endif call probe_floppy call get_size ! Get number of clicks in di - cmp di,#0 + test di,di jz nogood ! If it`s zero .. Hmm if STACK = 0 @@ -122,7 +122,7 @@ hcode: ! For 3.5 inch floppies 36 is 2.88 Mb, 18 is 1.44Mb, 21 is 1.68Mb on ! a 1.44Mb floppy drive. 15 and 9 are for 5.25 inch floppies. -disksizes: .byte 36,21,18,15,9 +disksizes: .byte 36,32,21,18,15,9 ! End of part 1 !-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- diff --git a/bootblocks/trk_buf.c b/bootblocks/trk_buf.c index f9ae3c8..69c7eaa 100644 --- a/bootblocks/trk_buf.c +++ b/bootblocks/trk_buf.c @@ -3,12 +3,15 @@ #ifndef MINI_BUF +/* #define DEBUG 1 */ + int disk_drive = 0; int disk_spt = 7; int disk_heads = 2; int disk_cyls = 0; +long disk_partition_offset = 0; /* FIXME: fetch from __argr */ -static int last_drive = 0; +static int last_drive = -1; static int data_len = 0; static long data_trk1 = 0; static char * data_buf1 = 0; @@ -32,6 +35,7 @@ void reset_disk() disk_spt = 7; /* Defaults for reading Boot area. */ disk_heads = 2; disk_cyls = 0; + disk_partition_offset = 0; } #if defined(__MSDOS__) || defined(__STANDALONE__) else @@ -40,6 +44,13 @@ void reset_disk() long dpt; int v; +#ifdef __STANDALONE__ + if( disk_partition_offset == 0 && disk_drive == __argr.h.dl ) + { + disk_partition_offset = __argr.x.cx + ((long)__argr.h.dh<<16); + } +#endif + disk_spt = 17; /* Defaults for reading Boot area. */ disk_heads = 1; disk_cyls = 0; @@ -72,12 +83,15 @@ long sectno; if( disk_drive != last_drive || sectno == 0 ) reset_disk(); + if( disk_partition_offset > 0 ) + sectno += disk_partition_offset; + if( disk_spt < 0 || disk_spt > 63 || disk_heads < 1 ) { phy_s = sectno; reset_disk(); -#ifdef __ELKS__ +#if DEBUG > 1 fprintf(stderr, "read_sector(%ld = %d,%d,%d)\n", sectno, phy_c, phy_h, phy_s+1); #endif @@ -88,7 +102,7 @@ long sectno; phy_h = sectno/disk_spt%disk_heads; phy_c = sectno/disk_spt/disk_heads; -#ifdef __ELKS__ +#if DEBUG > 1 fprintf(stderr, "read_sector(%ld = %d,%d,%d)\n", sectno, phy_c, phy_h, phy_s+1); #endif @@ -106,10 +120,15 @@ long sectno; return 0; } -#ifdef __ELKS__ +#ifdef DEBUG fprintf(stderr, "WARNING: Single sector read\n"); #endif +#ifdef DEBUG + fprintf(stderr, "phy_read(%d,%d,%d,%d,%d,0x%x)\n", + disk_drive, phy_c, phy_h, phy_s+1, 1, data_buf1); +#endif + do { rv = phy_read(disk_drive, phy_c, phy_h, phy_s+1, 1, data_buf1); @@ -133,14 +152,23 @@ int phy_c, phy_h, phy_s; /* Big tracks get us short of memory so limit it. */ nlen = (disk_spt-1)/24; nlen = (disk_spt+nlen)/(nlen+1); + /* trk_no = (long)phy_c*disk_heads*4+phy_h*4+phy_s/nlen+1; + */ + + trk_no = (long)(phy_c*disk_heads+phy_h)*((disk_spt+4)/nlen)+phy_s/nlen+1; + +#if DEBUG > 1 + fprintf(stderr, "Info len=%d,%d trk=%ld,%ld,%ld\n", + data_len,nlen, trk_no,data_trk1,data_trk2); +#endif if( data_len != nlen ) { if( data_buf1 ) free(data_buf1); if( data_buf2 ) free(data_buf2); data_buf1 = data_buf2 = 0; - data_len = disk_spt; + data_len = nlen; } if( trk_no == bad_track ) return -1; @@ -151,9 +179,15 @@ int phy_c, phy_h, phy_s; * 2) Neither has it, need to swap to overwrite least recent. */ - /* So we always swap */ - p = data_buf1; data_buf1 = data_buf2; data_buf2 = p; - t = data_trk1; data_trk1 = data_trk2; data_trk2 = t; + /* But sequential reads may spoil this so don't swap if we are shifting + * to the next track. + */ + + if( trk_no == data_trk2 || trk_no != data_trk1 + 1 ) + { + p = data_buf1; data_buf1 = data_buf2; data_buf2 = p; + t = data_trk1; data_trk1 = data_trk2; data_trk2 = t; + } /* The other one right ? */ if( data_buf1 && trk_no == data_trk1 ) return 0; @@ -165,8 +199,11 @@ int phy_c, phy_h, phy_s; { data_buf1 = malloc(disk_spt*512); -#ifdef __ELKS__ - fprintf(stderr, "Allocated buffer to %d\n", data_buf1); +#ifdef DEBUG + if( data_buf1 ) + fprintf(stderr, "Allocated buffer to %d\n", data_buf1); + else + fprintf(stderr, "Failed to allocated buffer.\n"); #endif } if( data_buf1 == 0 ) @@ -180,9 +217,14 @@ int phy_c, phy_h, phy_s; /* Not enough memory for track read. */ if( data_buf1 == 0 ) return -1; +#ifdef DEBUG + fprintf(stderr, "phy_read(%d,%d,%d,%d,%d,0x%x)\n", + disk_drive, phy_c, phy_h, phy_s/data_len*data_len+1, data_len, data_buf1); +#endif + do /* the physical read */ { - rv = phy_read(disk_drive, phy_c, phy_h, phy_s/data_len+1, data_len, + rv = phy_read(disk_drive, phy_c, phy_h, phy_s/data_len*data_len+1, data_len, data_buf1); tries--; } |