summaryrefslogtreecommitdiff
path: root/bootblocks
diff options
context:
space:
mode:
authorRobert de Bath <rdebath@poboxes.com>1998-09-22 17:44:32 +0200
committerLubomir Rintel <lkundrak@v3.sk>2013-10-23 23:40:35 +0200
commit2233d47f9d89c107b6c425626d6eb2669363b055 (patch)
tree429df42a8f6ed7174868af04edd364cd778a4d54 /bootblocks
parentec5f28e3f1400b5dacb88eda2d9db472a20b4349 (diff)
downloaddev86-2233d47f9d89c107b6c425626d6eb2669363b055.tar.gz
Import Dev86src-0.14.5.tar.gzv0.14.5
Diffstat (limited to 'bootblocks')
-rw-r--r--bootblocks/Makefile32
-rw-r--r--bootblocks/bzimage.c238
-rw-r--r--bootblocks/commands.c210
-rw-r--r--bootblocks/fs.c9
-rw-r--r--bootblocks/fs_dos.c27
-rw-r--r--bootblocks/fs_min.c2
-rw-r--r--bootblocks/fs_tar.c8
-rw-r--r--bootblocks/help.c3
-rw-r--r--bootblocks/i86_funcs.c32
-rw-r--r--bootblocks/i86_funcs.h2
-rw-r--r--bootblocks/lsys.c134
-rw-r--r--bootblocks/makeboot.c42
-rw-r--r--bootblocks/mbr.s5
-rw-r--r--bootblocks/min_buf.c105
-rw-r--r--bootblocks/monitor.c334
-rw-r--r--bootblocks/monitor.h47
-rw-r--r--bootblocks/relocate.c11
-rw-r--r--bootblocks/sysboot.s15
-rw-r--r--bootblocks/tich.s2
-rw-r--r--bootblocks/trk_buf.c9
-rw-r--r--bootblocks/unix.c11
21 files changed, 791 insertions, 487 deletions
diff --git a/bootblocks/Makefile b/bootblocks/Makefile
index c37f35c..7ad0907 100644
--- a/bootblocks/Makefile
+++ b/bootblocks/Makefile
@@ -4,10 +4,11 @@ HOSTCCFLAGS=-O
BCC=bcc
CC=$(BCC)
-CFLAGS=-ansi -Ms -Oi -O -s
+CFLAGS=-ansi -Ms -Oi -O -s $(MONDEFS)
# CFLAGS=-ansi -Ms
ASFLAGS=-0 -w
-MDEFS=-DDOTS
+MINIXDEFS=-DDOTS
+MONDEFS=
# LST=-l $*.lst
# CLST=-A-l -A$*.lst
@@ -23,46 +24,49 @@ SSRC=sysboot.s \
encap: $(SSRC:s=v) $(CSRC:c=v) minixhd.v
bin: $(SSRC:s=bin) $(CSRC:c=bin) minixhd.bin
-MOBJ=monitor.o i86_funcs.o relocate.o help.o bzimage.o trk_buf.o unix.o \
- fs.o fs_tar.o fs_min.o fs_dos.o
-MSRC=monitor.c i86_funcs.c relocate.c help.c bzimage.c trk_buf.c unix.c \
- fs.c fs_tar.c fs_min.c fs_dos.c
-MINC=i86_funcs.h readfs.h
+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
+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
+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
EXTRAS=minix.h elf_info.c elf_info.h standalone.c li86.s \
- zimage.s minix_elks.c crc.c
+ zimage.s minix_elks.c crc.c lsys.c
install:
monitor.out: $(MOBJ)
- $(CC) $(CFLAGS) -H0x10000 $(MOBJ) -o monitor.out
+ $(CC) $(CFLAGS) -H0x10000 $(MOBJ) -o monitor.out -M > monitor.sym
$(MOBJ): $(MINC) version.h
monitor: $(MSRC) $(MINC)
@rm -f $(MOBJ)
- make 'CFLAGS=-ansi -H0x8000' monitor.out
+ make 'CFLAGS=-ansi -H0x8000 $(MONDEFS)' monitor.out
mv monitor.out monitor
@rm -f $(MOBJ)
bzimage.o: bzimage.c zimage.v
minix.s: minix.c Makefile
- $(BCC) -Mf -O -DTRY_FLOPPY $(MDEFS) -S minix.c
+ $(BCC) -Mf -O -DTRY_FLOPPY $(MINIXDEFS) -S minix.c
minix_elks.s: minix_elks.c Makefile minix.v
- $(BCC) -Mf -O $(MDEFS) -S minix_elks.c
+ $(BCC) -Mf -O $(MINIXDEFS) -S minix_elks.c
minixhd.s: minix.c Makefile
- $(BCC) -Mf -O -DHARDDISK $(MDEFS) -S minix.c -o minixhd.s
+ $(BCC) -Mf -O -DHARDDISK $(MINIXDEFS) -S minix.c -o minixhd.s
makeboot: makeboot.c $(BOOTBLOCKS)
$(HOSTCC) $(HOSTCCFLAGS) -o makeboot makeboot.c
makeboot.com: makeboot.c $(BOOTBLOCKS)
- $(BCC) -Md -o makeboot.com makeboot.c
+ $(BCC) -Md -O -o makeboot.com makeboot.c
+
+lsys.com: lsys.c msdos.v
+ $(BCC) -Md -O -o lsys.com lsys.c
version.h:
head -1 ../Libc_version | \
diff --git a/bootblocks/bzimage.c b/bootblocks/bzimage.c
index afb6dde..cb713d7 100644
--- a/bootblocks/bzimage.c
+++ b/bootblocks/bzimage.c
@@ -3,13 +3,9 @@
* friends use.
*/
-#include <stdio.h>
-#include <dos.h>
-#include "i86_funcs.h"
-#include "readfs.h"
+#include "monitor.h"
int auto_flag = 1;
-char * append_line = 0; /* A preset append line value */
static char * initrd_name = 0; /* Name of init_ramdisk to load */
static long initrd_start = 0;
@@ -17,6 +13,7 @@ static long initrd_length = 0;
static int vga_mode = -1; /* SVGA_MODE = normal */
static int is_zimage = 0;
+static char * image_name = 0;
static int image_length; /* Length of image in sectors */
static long image_size; /* Length of image file in bytes */
@@ -25,11 +22,12 @@ static char * input_cmd();
#define ZIMAGE_LOAD_SEG 0x10000 /* Segment that zImage data is loaded */
#define COMMAND_LINE_POS 0x4000 /* Offset in segment 0x9000 of command line */
-#define CALC_CRC
-int has_command_line = 0;
+static char * linux_command_line = 0;
int load_crc = 0;
+static char buffer[1024];
+
cmd_bzimage(ptr)
char * ptr;
{
@@ -57,7 +55,6 @@ bzimage(fname, command_line)
char * fname;
char * command_line;
{
- char buffer[1024];
long len;
char * ptr;
int low_sects;
@@ -67,19 +64,24 @@ char * command_line;
initrd_start = initrd_length = 0;
vga_mode = -1;
is_zimage = 0;
+ image_name = strdup(fname);
- if( open_file(fname) < 0 )
+ /* Ok, deal with the command line */
+ if( build_linuxarg(fname, command_line) < 0 )
+ return -1;
+
+ if( open_file(image_name) < 0 )
{
if( auto_flag == 0 )
- printf("Cannot find file %s\n", fname);
+ printf("Cannot find file %s\n", image_name);
return -1;
}
- printf("Loading %s\n", fname);
+ printf("Loading %s\n", image_name);
- if( read_block(buffer) < 0 || check_magics(fname, buffer) < 0 )
+ if( read_block(buffer) < 0 || check_magics(image_name, buffer) < 0 )
{
- printf("Cannot execute file %s\n", fname);
+ printf("Cannot execute file %s\n", image_name);
return -1;
}
@@ -97,8 +99,8 @@ char * command_line;
len = (image_size=file_length()) * 3 / 1024;
if( main_mem_top < len )
{
- printf("This kernel needs at least %ld.%ldM of main memory\n",
- len/1024, len*10/1024%10);
+ printf("This kernel needs at least %d.%dM of main memory\n",
+ (int)(len/1024), (int)(len*10/1024%10));
return -1;
}
if( main_mem_top < 3072 )
@@ -115,8 +117,8 @@ char * command_line;
{
if( image_length > 0x7FF0/32 )
{
- printf("This zImage file is too large, maximum is %ld bytes\n",
- (0x7FF0/32 + low_sects)*512L );
+ printf("This zImage file is too large, maximum is %dk bytes\n",
+ (0x7FF0/32 + low_sects)/2 );
return -1;
}
}
@@ -127,8 +129,8 @@ char * command_line;
if( image_length > (__get_cs()>>5) - ZIMAGE_LOAD_SEG/32 )
{
- printf("This zImage file is too large, maximum is %ld bytes\n",
- ((__get_cs()>>5) - ZIMAGE_LOAD_SEG/32 + low_sects)*512L );
+ printf("This zImage file is too large, maximum is %dk bytes\n",
+ ((__get_cs()>>5) - ZIMAGE_LOAD_SEG/32 + low_sects)/2 );
return -1;
}
}
@@ -144,8 +146,9 @@ char * command_line;
{
int v;
- printf("%ldk to go \r", len/1024); fflush(stdout);
+ printf("%dk to go \r", (int)(len/1024)); fflush(stdout);
+#ifndef NOCOMMAND
v = (bios_khit()&0x7F);
if( v == 3 || v == 27 )
{
@@ -153,10 +156,11 @@ char * command_line;
bios_getc();
return -1;
}
+#endif
if( read_block(buffer) < 0 )
{
- printf("Error loading %s\n", fname);
+ printf("Error loading %s\n", image_name);
return -1;
}
@@ -184,6 +188,8 @@ char * command_line;
}
}
}
+ close_file();
+
#ifdef CALC_CRC
load_crc = display_crc(0);
#endif
@@ -192,12 +198,7 @@ char * command_line;
if( check_crc() < 0 && !keep_going() ) return -1;
#endif
- /* Yesss, loaded! */
- printf("Loaded, "); fflush(stdout);
-
- /* Ok, deal with the command line */
- if( build_linuxarg(auto_flag, fname, append_line, command_line) < 0 )
- return -1;
+ printf(" \r"); fflush(stdout);
if( initrd_name )
if( load_initrd(address) < 0 )
@@ -207,14 +208,20 @@ char * command_line;
if( check_crc() < 0 && !keep_going() ) return -1;
#endif
- printf("Starting ...\n");
-
- if( x86 < 3 )
+ if( x86 < 3 || x86_emu )
{
- printf("RTFM error: Linux-i386 needs a CPU >= 80386\n");
+ if( x86 < 3 )
+ printf("RTFM error: Linux-i386 needs a CPU >= 80386\n");
+ else if( x86_emu )
+ printf("RTFM error: Linux-i386 cannot be run in an emulator.\n");
if( !keep_going() ) return -1;
}
+ printf("linux ");
+ if( linux_command_line )
+ printf("%s", linux_command_line);
+ fflush(stdout);
+
if( a20_closed() ) open_a20();
if( a20_closed() )
{
@@ -228,20 +235,19 @@ char * command_line;
if( !keep_going() ) return -1;
}
-#ifdef __ELKS__
- printf("Cannot start.\n");
- return -1;
-#endif
-
__set_es(0x9000);
/* Save pointer to command line */
- if( has_command_line )
+ if( linux_command_line )
{
__doke_es(0x0020, 0xA33F);
__doke_es(0x0022, COMMAND_LINE_POS);
+ __movedata(__get_ds(), (unsigned)linux_command_line+1, 0x9000, COMMAND_LINE_POS, strlen(linux_command_line));
+ free(linux_command_line);
}
+ __set_es(0x9000);
+
#if ZIMAGE_LOAD_SEG != 0x10000
#if ZIMAGE_LOAD_SEG != 0x1000
if( is_zimage )
@@ -261,7 +267,7 @@ char * command_line;
#endif
#endif
- /* Tell the kernel where it is */
+ /* Tell the kernel where ramdisk is */
if( initrd_name )
{
__set_es(0x9000);
@@ -312,27 +318,27 @@ char * command_line;
}
}
-check_magics(fname, buffer)
+check_magics(fname, image_buf)
char * fname;
-char * buffer;
+char * image_buf;
{
is_zimage = 0;
/* Boot sector magic number */
- if( *(unsigned short*)(buffer+510) != 0xAA55 ||
+ if( *(unsigned short*)(image_buf+510) != 0xAA55 ||
/* Setup start */
- memcmp(buffer+0x202, "HdrS", 4) != 0 ||
+ memcmp(image_buf+0x202, "HdrS", 4) != 0 ||
/* Setup version */
- *(unsigned short*)(buffer+0x206) < 0x200 )
+ *(unsigned short*)(image_buf+0x206) < 0x200 )
{
printf("File %s is not a linux Image file\n", fname);
return -1;
}
/* Code 32 start address for zImage */
- if( *(unsigned long*)(buffer+0x214) == 0x1000 )
+ if( *(unsigned long*)(image_buf+0x214) == 0x1000 )
{
printf("File %s is a zImage file\n", fname);
is_zimage = 1;
@@ -340,9 +346,9 @@ char * buffer;
}
else
/* Code 32 start address bzImage */
- if( *(unsigned long*)(buffer+0x214) != 0x100000 )
+ if( *(unsigned long*)(image_buf+0x214) != 0x100000 )
{
- printf("File %s is not a bzImage file\n", fname);
+ printf("File %s is a strange Image file\n", fname);
return -1;
}
printf("File %s is a bzImage file\n", fname);
@@ -351,26 +357,26 @@ char * buffer;
}
#ifndef __ELKS__
-putsect(buffer, address)
-char * buffer;
+putsect(put_buf, address)
+char * put_buf;
unsigned int address;
{
int rv, tc=3;
/* In real mode memory, just put it directly */
if( address < 0xA00 )
{
- __movedata(__get_ds(), buffer, address*16, 0, 512);
+ __movedata(__get_ds(), put_buf, address*16, 0, 512);
return 0;
}
retry:
tc--;
-#if 0
- if( x86_emu )
+ /*
+ if( x86_test )
return 0; /* In an EMU we can't write to high mem but
we'll pretend we can for debuggering */
-#endif
- if( (rv=ext_put(buffer, address, 512)) != 0 )
+
+ if( (rv=ext_put(put_buf, address, 512)) != 0 )
{
switch(rv)
{
@@ -391,10 +397,6 @@ retry:
printf("Error %d while copying to extended memory\n", rv);
break;
}
- if( x86 < 3 )
- printf("RTFM error: Linux-i386 needs a CPU >= 80386\n");
- else if( x86_emu )
- printf("RTFM error: Linux-i386 cannot be run in an emulator.\n");
return -1;
}
return 0;
@@ -402,29 +404,21 @@ retry:
#endif
static char *
-read_cmdfile(iname, extno)
+read_cmdfile(iname)
char * iname;
-int extno;
{
- char buffer[1024];
char buf[16];
long len;
char * ptr = strchr(iname, '.');
buf[8] = '\0';
strncpy(buf, iname, 8);
- switch(extno)
- {
- case 1: strcat(buf, ".cmd"); break;
- case 2: strcat(buf, ".app"); break;
- case 3: strcat(buf, ".dfl"); break;
- default: return 0;
- }
+ strcat(buf, ".cfg");
if( ptr == 0 && open_file(buf) >= 0 )
{
/* Ah, a command line ... */
- if( extno == 1 ) printf("Loading %s\n", buf);
+ printf("Loading %s\n", buf);
len = file_length();
if( len > 1023 )
{
@@ -438,9 +432,11 @@ int extno;
if( buffer[i] < ' ' ) buffer[i] = ' ';
buffer[len] = '\0';
+ close_file(); /* Free up loads a room */
return strdup(buffer);
}
}
+ close_file(); /* Free up loads a room */
return 0;
}
@@ -448,7 +444,6 @@ char *
input_cmd(iname)
char * iname;
{
- char buffer[1024];
char lbuf[20];
int cc;
@@ -479,50 +474,46 @@ char * iname;
return strdup(buffer);
}
-build_linuxarg(auto_flg, image, append, cmd)
-int auto_flg;
-char *image, *append, *cmd;
+build_linuxarg(image, cmd)
+char *image, *cmd;
{
static char * auto_str = "auto";
static char * image_str = "BOOT_IMAGE=";
int len = 0;
char * ptr, *s, *d;
-
char * free_cmd = 0;
- char * free_app = 0;
- char * free_dfl = 0;
+ char * free_inp = 0, * inp = 0;
- has_command_line = 0;
+ image_name = strdup(image);
- if( append == 0 )
- append = free_app = read_cmdfile(image, 2);
+ if( linux_command_line ) free(linux_command_line);
+ linux_command_line = 0;
if( cmd == 0 )
- cmd = free_cmd = read_cmdfile(image, 1);
-
- if( cmd == 0 )
- free_dfl = read_cmdfile(image, 3);
-
- close_file(); /* Free up loads a room */
+ cmd = free_cmd = read_cmdfile(image);
if( cmd == 0 )
{
- cmd = free_cmd = input_cmd(image);
- auto_flg = 0;
+ if( auto_flag ) return 0;
+ printf("No such command file\n");
+ return -1;
}
- if( cmd == 0 )
+ if( auto_flag )
{
- printf("Aborted execution\n");
- return -1;
+ ptr = strdup(cmd);
+ for(s=strtok(ptr, " "); s; s=strtok((char*)0, " "))
+ {
+ if( strncasecmp(s, "prompt",6) == 0 && free_inp == 0)
+ inp = free_inp = input_cmd(image);
+ }
+ free(ptr);
}
- else if( *cmd == 0 )
- cmd = free_dfl;
- if( auto_flg ) len += strlen(auto_str) + 1;
+ if( auto_flag ) len += strlen(auto_str) + 1;
if( image ) len += strlen(image_str) + strlen(image) + 1;
- if( append ) len += strlen(append) + 1;
if( cmd ) len += strlen(cmd) + 1;
+ if( inp ) len += strlen(inp) + 1;
if( len == 0 ) return 0;
@@ -531,20 +522,17 @@ static char * image_str = "BOOT_IMAGE=";
{
printf("Unable to create linux command line\n");
if( free_cmd ) free(free_cmd);
- if( free_app ) free(free_app);
- if( free_dfl ) free(free_dfl);
+ if( free_inp ) free(free_inp);
return -1;
}
*ptr = 0; ptr[1] = 0;
- if( auto_flg ) { strcat(ptr, " "); strcat(ptr, auto_str); }
- if( image ) { strcat(ptr, " "); strcat(ptr, image_str); strcat(ptr, image); }
- if( append ) { strcat(ptr, " "); strcat(ptr, append); }
+ if( auto_flag ) { strcat(ptr, " "); strcat(ptr, auto_str); }
if( cmd ) { strcat(ptr, " "); strcat(ptr, cmd); }
+ if( inp ) { strcat(ptr, " "); strcat(ptr, inp); }
if( free_cmd ) free(free_cmd);
- if( free_app ) free(free_app);
- if( free_dfl ) free(free_dfl);
+ if( free_inp ) free(free_inp);
if( (d = malloc(len+1)) == 0 )
{
@@ -555,16 +543,16 @@ static char * image_str = "BOOT_IMAGE=";
*d = '\0';
for(s=strtok(ptr, " "); s; s=strtok((char*)0, " "))
{
- if( strncmp(s, "vga=",4) == 0 )
+ if( strncasecmp(s, "vga=",4) == 0 )
{
- if( strncmp(s+4, "ask", 3) == 0 )
+ if( strncasecmp(s+4, "ask", 3) == 0 )
vga_mode = -3;
else
{
s+=4; getnum(&s, &vga_mode);
}
}
- else if( strncmp(s, "ramdisk_file=", 13) == 0 )
+ else if( strncasecmp(s, "ramdisk_file=", 13) == 0 )
{
if( initrd_name ) free(initrd_name);
if( s[13] )
@@ -572,6 +560,16 @@ static char * image_str = "BOOT_IMAGE=";
else
initrd_name = 0;
}
+ else if( strncasecmp(s, image_str, 11) == 0 )
+ {
+ if( image_name ) free(image_name);
+ if( s[11] )
+ image_name = strdup(s+11);
+ else
+ image_name = strdup(image);
+ }
+ else if( strncasecmp(s, "prompt",6) == 0 )
+ ;
else
{
strcat(d, " ");
@@ -579,6 +577,8 @@ static char * image_str = "BOOT_IMAGE=";
}
}
free(ptr); ptr = d;
+
+ strcat(ptr, " "); strcat(ptr, image_str); strcat(ptr, image_name);
len = strlen(ptr);
if( len > 2048 )
@@ -590,18 +590,9 @@ static char * image_str = "BOOT_IMAGE=";
#ifdef __ELKS__
fprintf(stderr, "Command line: '%s'\n", ptr+1);
-#else
-/* Commented to allow for CRC check.
- __set_es(0x9000);
- __doke_es(0x0020, 0xA33F);
- __doke_es(0x0022, COMMAND_LINE_POS);
-*/
-
- __movedata(__get_ds(), (unsigned)ptr+1, 0x9000, COMMAND_LINE_POS, len);
- has_command_line = 1;
#endif
- free(ptr);
+ linux_command_line = ptr;
return 0;
}
@@ -609,18 +600,26 @@ static char * image_str = "BOOT_IMAGE=";
keep_going()
{
static int burning = 0;
- char buf[1];
+ char buf[4];
int cc;
printf("Keep going ? "); fflush(stdout);
+#ifdef __STANDALONE__
cc = read(0, buf, 1);
- if( cc == 1 && (*buf == 'Y' || *buf == 'y') )
+#else
+ cc = read(0, buf, 4);
+#endif
+ if( cc >= 1 && (*buf == 'Y' || *buf == 'y') )
{
printf("Yes, Ok%s\n", burning?"":", burn baby burn!");
return burning=1;
}
+#ifdef NOCOMMAND
+ printf("No, Ok press enter to reboot\n");
+#else
printf("No, Ok returning to monitor prompt\n");
+#endif
return 0;
}
@@ -631,8 +630,6 @@ unsigned int k_top;
long file_len;
char * fname = initrd_name;
- char buffer[1024];
-
/* Top of accessable memory */
if( main_mem_top >= 15360 ) address = 0xFFFF;
else address = 0x1000 + main_mem_top*4;
@@ -668,6 +665,7 @@ unsigned int k_top;
for( ; rd_len>0 ; rd_len--)
{
+#ifndef NOCOMMAND
int v = (bios_khit()&0x7F);
if( v == 3 || v == 27 )
{
@@ -675,6 +673,7 @@ unsigned int k_top;
bios_getc();
return -1;
}
+#endif
printf("%dk to go \r", rd_len); fflush(stdout);
if( read_block(buffer) < 0 )
@@ -687,7 +686,9 @@ unsigned int k_top;
if( putsect(buffer+512, address) < 0 ) return -1;
address+=2;
}
- printf("Loaded, ");
+ printf(" \r"); fflush(stdout);
+
+ close_file();
initrd_start = ((long) rd_start <<8);
initrd_length = file_len;
@@ -698,7 +699,6 @@ unsigned int k_top;
#ifdef CALC_CRC
check_crc()
{
- char buffer[512];
int low_sects;
unsigned int address = 0x900;
long len;
diff --git a/bootblocks/commands.c b/bootblocks/commands.c
new file mode 100644
index 0000000..459430d
--- /dev/null
+++ b/bootblocks/commands.c
@@ -0,0 +1,210 @@
+
+#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;
+{
+ char * fname;
+ char buffer[1024];
+ long len;
+
+ while(*ptr == ' ') ptr++;
+ if( (fname=ptr) == 0 ) return 0;
+ while(*ptr & *ptr != ' ') ptr++;
+
+ if( open_file(fname) >= 0 ) for(len=file_length(); len>0; len-=1024)
+ {
+ if( read_block(buffer) < 0 ) break;
+ if( len > 1024 )
+ write(1, buffer, 1024);
+ else
+ write(1, buffer, len);
+ }
+ else
+ printf("Cannot open file '%s'\n", fname);
+ close_file();
+ return 0;
+}
+
+int cmd_more(ptr)
+char * ptr;
+{
+ char * fname;
+ char buffer[1024];
+ long len;
+ int cc;
+ char * sptr;
+
+ while(*ptr == ' ') ptr++;
+ if( (fname=ptr) == 0 ) return 0;
+ while(*ptr & *ptr != ' ') ptr++;
+
+ more_char(-1);
+
+ if( open_file(fname) >= 0 ) for(len=file_length(); len>0; len-=1024)
+ {
+ if( read_block(buffer) < 0 ) break;
+ if( len > 1024 ) cc = 1024; else cc = len;
+ for(sptr=buffer; cc>0 ; cc--,sptr++)
+ {
+ if( more_char(*sptr & 0xFF) < 0 ) goto break_break;
+ }
+ }
+ else
+ printf("Cannot open file '%s'\n", fname);
+break_break:;
+ close_file();
+ return 0;
+}
+
+more_char(ch)
+int ch;
+{
+static int line_number = 0;
+
+ if( ch == -1 ) { line_number = 0; return 0; }
+
+ if( (ch & 0xE0 ) || ch == '\n' )
+ putchar(ch);
+ if( ch == '\n' && ++line_number == 24)
+ {
+ char buf[4];
+ printf("More ?"); fflush(stdout);
+ if( read(0, buf, 1) <= 0 ) return -1;
+ if( buf[0] == 3 || buf[0] == '\033'
+ || buf[0] == 'q' || buf[0] == 'Q' ) return -1;
+ if( buf[0] == '\r' ) line_number--;
+ if( buf[0] == ' ' ) line_number=2;
+ printf("\r \r");
+ }
+ return 0;
+}
+
+more_strn(str, len)
+char * str;
+int len;
+{
+ for(; len>0 && *str ; len--,str++)
+ if( more_char( *str & 0xFF ) < 0 ) return -1;
+ return 0;
+}
+#endif
+
+/**************************************************************************/
+
+#ifndef NOMONITOR
+
+cmd_regs()
+{
+#ifdef __STANDALONE__
+ printf("REGS: AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x\n",
+ __argr.x.ax, __argr.x.bx, __argr.x.cx, __argr.x.dx,
+ __argr.x.si, __argr.x.di);
+#else
+ printf("Only in standalone\n");
+#endif
+}
+
+int cmd_memdump(ptr)
+char * ptr;
+{
+ int count = 128;
+ int i,j;
+ int es = __get_es();
+
+#define rmem(x) __peek_es( (x)+current_address )
+
+ getnum(&ptr, &current_address);
+ getnum(&ptr, &count);
+
+ for(i=0; i<count; i+=16)
+ {
+ printf("%04x:%04x:", es, current_address);
+ for(j=0; j<16; j++)
+ printf(" %s%02x", (j==8)?" ":"", rmem(j));
+ printf(" ");
+ for(j=0; j<16; j++)
+ if( rmem(j) >= ' ' && rmem(j) <= '~' )
+ putchar(rmem(j));
+ else
+ putchar('.');
+ putchar('\n');
+ current_address += 16;
+ current_address &= 0xFFFF;
+ }
+
+#undef rmem
+}
+
+int cmd_seg(ptr)
+char * ptr;
+{
+ int es = __get_es();
+
+ if( getnum(&ptr, &es) )
+ {
+ __set_es(es);
+ current_address = 0;
+ }
+ else
+ printf("Current segment 0x%04x\n", es);
+ return 0;
+}
+
+int cmd_set_base(ptr)
+{
+ int obase = number_base;
+ int nbase;
+ number_base = 10;
+
+ if( getnum(&ptr, &nbase) )
+ {
+ if( nbase < 2 || nbase > 36 )
+ printf("Can't use that base\n");
+ else
+ obase = nbase;
+ }
+ else printf("Current base is %d\n", obase);
+
+ number_base = obase;
+ return 0;
+}
+
+int cmd_rel(ptr)
+char * ptr;
+{
+ int nseg = 0xFFFF;
+ int cs = __get_cs();
+
+ getnum(&ptr, &nseg);
+
+ relocator(nseg);
+ if( __get_cs() == cs )
+ printf("Didn't relocate; CS=$%04x DS=$%04x\n", __get_cs(), __get_ds());
+ else
+ printf("Relocated to CS=$%04x DS=$%04x\n", __get_cs(), __get_ds());
+}
+#endif
diff --git a/bootblocks/fs.c b/bootblocks/fs.c
index ee81c55..037f8a4 100644
--- a/bootblocks/fs.c
+++ b/bootblocks/fs.c
@@ -1,8 +1,7 @@
-#ifdef __ELKS__
-#include <stdio.h>
-#endif
-#include "readfs.h"
+#include "monitor.h"
+
+#ifndef SINGLEFS
int fs_type = 0;
@@ -79,3 +78,5 @@ char * buffer;
}
return -1;
}
+
+#endif
diff --git a/bootblocks/fs_dos.c b/bootblocks/fs_dos.c
index d2ca5eb..bc223fc 100644
--- a/bootblocks/fs_dos.c
+++ b/bootblocks/fs_dos.c
@@ -1,10 +1,9 @@
-#include <stdio.h>
-#include <ctype.h>
-#include <malloc.h>
-#include "readfs.h"
+#include "monitor.h"
-#define DONT_BUFFER_FAT
+#ifdef MINI_BUF
+#define BUFFER_FAT
+#endif
#define DOS_SECT(P) get_uint(P,0x0B)
#define DOS_CLUST(P) get_byte(P,0x0D)
@@ -28,7 +27,7 @@
static int read_bootblock();
static int dir_nentry, dir_sect;
-static int dos_clust0, dos_spc, dos_fatpos;
+static int dos_clust0, dos_spc, dos_fatpos, dos_fatlen;
static int last_serial = 0;
#ifdef BUFFER_FAT
@@ -87,22 +86,17 @@ char * fname;
memset(&cur_file, '\0', sizeof(cur_file));
#ifdef BUFFER_FAT
- s = read_sector(0);
-
if( !dodir )
{
/* Read in and buffer the FAT */
if( fat_buf ) free(fat_buf);
- fat_buf = malloc(DOS_FATLEN(s) * 512);
+ fat_buf = malloc(dos_fatlen * 512);
if( fat_buf == 0 ) return -1;
else
{
- int fatsec = DOS_RESV(s);
- int nsec = DOS_FATLEN(s);
-
- for(i=0; i<nsec; i++)
+ for(i=0; i<dos_fatlen; i++)
{
- s = read_sector(fatsec+i);
+ s = read_sector(dos_fatpos+i);
if(s == 0) return -1;
memcpy(fat_buf+i*512, s, 512);
}
@@ -118,6 +112,9 @@ char * fname;
d = s + (i%16)*32;
if( dodir )
{
+#ifdef NOCOMMAND
+ break;
+#else
char dtime[20];
char lbuf[90];
*lbuf = 0;
@@ -143,6 +140,7 @@ char * fname;
break;
}
if( more_strn(lbuf, sizeof(lbuf)) < 0 ) break;
+#endif
}
else if( memcmp(d, conv_name, 11) == 0 && (d[11]&0x18) == 0 )
{ /* Name matches and is normal file */
@@ -303,6 +301,7 @@ static int read_bootblock()
dir_nentry = DOS_NROOT(sptr);
dos_fatpos = DOS_RESV(sptr);
+ dos_fatlen = DOS_FATLEN(sptr);
dos_spc = DOS_CLUST(sptr);
if( dos_spc < 1 ) dos_spc = 1;
dos_clust0 = dir_sect + (dir_nentry+15)/16 - 2*dos_spc;
diff --git a/bootblocks/fs_min.c b/bootblocks/fs_min.c
index 78a5fc9..4f4c33e 100644
--- a/bootblocks/fs_min.c
+++ b/bootblocks/fs_min.c
@@ -1,5 +1,5 @@
-#include "readfs.h"
+#include "monitor.h"
min_open_file(fname)
char * fname;
diff --git a/bootblocks/fs_tar.c b/bootblocks/fs_tar.c
index 2a30ee2..1dac3a4 100644
--- a/bootblocks/fs_tar.c
+++ b/bootblocks/fs_tar.c
@@ -1,7 +1,5 @@
-#include <stdio.h>
-#include <dos.h>
-#include "readfs.h"
+#include "monitor.h"
#define HEADER_SIZE 512
#define NAME_SIZE 100
@@ -38,10 +36,6 @@ void tar_set_drive();
static int disk_size = 0;
-#ifdef __STANDALONE__
-extern union REGS __argr;
-#endif
-
struct tx {
char name[NAME_SIZE];
int first_sectno;
diff --git a/bootblocks/help.c b/bootblocks/help.c
index 5083fdc..3d53fad 100644
--- a/bootblocks/help.c
+++ b/bootblocks/help.c
@@ -5,8 +5,7 @@
* previous and next page.
*/
-#include <stdio.h>
-#include "readfs.h"
+#include "monitor.h"
struct keys {
int key;
diff --git a/bootblocks/i86_funcs.c b/bootblocks/i86_funcs.c
index 90fbbbc..b45343e 100644
--- a/bootblocks/i86_funcs.c
+++ b/bootblocks/i86_funcs.c
@@ -1,24 +1,21 @@
-#include <stdio.h>
-#include <errno.h>
-#include <dos.h>
-#include "i86_funcs.h"
+#include "monitor.h"
int x86 = 0; /* CPU major number */
char *x86_name = ""; /* and it's name */
int x86_emu = 0; /* Is this a PC emulator ? */
int x86_a20_closed = 1; /* Is the A20 gate closed ? */
-int x86_test = 0; /* In test mode */
int x86_fpu = 0;
+int x86_test = 0; /* In test mode */
+
unsigned boot_mem_top = 0x2000; /* Default 128k, the minimum */
long main_mem_top = 0; /* K of extended memory */
int a20_closed()
{
register int v, rv = 0;
- if (x86_test)
- return 1; /* If not standalone don't try */
+ if (x86_test) return 1; /* If not standalone don't try */
__set_es(0);
v = __peek_es(512);
@@ -36,7 +33,7 @@ int a20_closed()
return x86_a20_closed = rv;
}
-void open_a20()
+static void asm_open_a20()
{
#asm
call empty_8042
@@ -53,10 +50,12 @@ empty_8042:
#endasm
}
+void open_a20() { if(!x86_test) asm_open_a20(); }
+
/* This calls the BIOS to open the A20 gate, officially this is only supported
on PS/2s but if the normal routine fails we may as well try this.
*/
-void bios_open_a20()
+void asm_bios_open_a20()
{
#asm
mov ax,#$2401
@@ -69,6 +68,8 @@ bios_failed_a20:
#endasm
}
+void bios_open_a20() { if(!x86_test) asm_bios_open_a20(); }
+
void cpu_check()
{
static char *name_808x[] =
@@ -105,11 +106,22 @@ void cpu_check()
x86_name = cpubuf;
if (c & 0x01) x86_emu = 1; /* Already in protected mode !!! */
}
+
+#ifdef __STANDALONE__
+ x86_test = x86_emu;
+#else
+ x86_test = 1;
+#endif
}
void mem_check()
{
- if (x86_test) return; /* If not standalone don't try */
+ if (x86_test)
+ {
+ main_mem_top = 16384;
+ return; /* If not standalone don't try */
+ }
+
{
#asm
int 0x12 ! Amount of boot memory
diff --git a/bootblocks/i86_funcs.h b/bootblocks/i86_funcs.h
index 9eb1b05..2fdb860 100644
--- a/bootblocks/i86_funcs.h
+++ b/bootblocks/i86_funcs.h
@@ -6,8 +6,8 @@ extern int x86; /* CPU major number (0-3) */
extern char *x86_name; /* and it's name */
extern int x86_emu; /* Is this a PC emulator ? */
extern int x86_a20_closed; /* Is the A20 gate closed ? */
-extern int x86_test; /* In test mode */
extern int x86_fpu;
+extern int x86_test; /* Running in test mode ? */
extern unsigned boot_mem_top; /* Top of RAM below 1M */
extern long main_mem_top; /* Top of RAM above 1M */
diff --git a/bootblocks/lsys.c b/bootblocks/lsys.c
new file mode 100644
index 0000000..77f3931
--- /dev/null
+++ b/bootblocks/lsys.c
@@ -0,0 +1,134 @@
+
+#include "msdos.v"
+
+#define DOS_SYSID 0x03
+#define DOS_SECT 0x0B
+#define DOS_CLUST 0x0D
+#define DOS_RESV 0x0E
+#define DOS_NFAT 0x10
+#define DOS_NROOT 0x11
+#define DOS_MAXSECT 0x13
+#define DOS_MEDIA 0x15
+#define DOS_FATLEN 0x16
+#define DOS_SPT 0x18
+#define DOS_HEADS 0x1A
+#define DOS_HIDDEN 0x1C
+#define DOS4_MAXSECT 0x20
+#define DOS4_PHY_DRIVE 0x24
+#define DOS4_SERIAL 0x27
+#define DOS4_LABEL 0x2B
+#define DOS4_FATTYPE 0x36
+
+unsigned char buffer[1024];
+
+int drive = 0;
+
+main(argc, argv)
+int argc;
+char ** argv;
+{
+ int tries, rv, i;
+
+ if( argc > 1 )
+ {
+ static char * s = "Usage: sys a:";
+ if( argc == 1 && argv[1][1] == ':' && argv[1][2] == 0 )
+ {
+ if( argv[1][0] == 'a' || argv[1][0] == 'A' )
+ drive = 0;
+ else if( argv[1][0] == 'b' || argv[1][0] == 'B' )
+ drive = 1;
+ else
+ fatal(s);
+ }
+ else
+ fatal(s);
+ }
+
+ for(tries=0; tries<6; tries++)
+ if( (rv = dos_sect_read(drive, 0, 0, 1, buffer)) == 0 )
+ break;
+ if( rv == 0 )
+ for(tries=0; tries<6; tries++)
+ if( (rv = dos_sect_read(drive, 0, 0, 2, buffer+512)) == 0 )
+ break;
+ if( rv ) fatal("Cannot read bootsector");
+
+ if( buffer[DOS_MEDIA] != buffer[512] ||
+ buffer[DOS_MEDIA] < 0xF0 ||
+ buffer[DOS_NFAT] > 2 ||
+ buffer[DOS_SECT+1] != 2 ||
+ buffer[DOS_HEADS] != 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];
+
+ for(tries=0; tries<6; tries++)
+ if( (rv = dos_sect_read(drive, 0, 0, 1, buffer)) == 0 )
+ break;
+ if( rv ) fatal("Cannot write bootsector");
+
+ return 0;
+}
+
+fatal(str)
+{
+ write(0, str, strlen(str));
+ exit(1);
+}
+
+dos_sect_write(drv, track, head, sector, loadaddr)
+{
+#asm
+ push bp
+ mov bp,sp
+
+ push ds
+ pop es
+
+ mov dh,[bp+2+_dos_sect_write.head]
+ mov dl,[bp+2+_dos_sect_write.drv]
+ mov cl,[bp+2+_dos_sect_write.sector]
+ mov ch,[bp+2+_dos_sect_write.track]
+
+ mov bx,[bp+2+_dos_sect_write.loadaddr]
+
+ mov ax,#$0301
+ int $13
+ jc write_err
+ mov ax,#0
+write_err:
+
+ pop bp
+#endasm
+}
+
+dos_sect_read(drv, track, head, sector, loadaddr)
+{
+#asm
+ push bp
+ mov bp,sp
+
+ push ds
+ pop es
+
+ mov dh,[bp+2+_dos_sect_read.head]
+ mov dl,[bp+2+_dos_sect_read.drv]
+ mov cl,[bp+2+_dos_sect_read.sector]
+ mov ch,[bp+2+_dos_sect_read.track]
+
+ mov bx,[bp+2+_dos_sect_read.loadaddr]
+
+ mov ax,#$0201
+ int $13
+ jc read_err
+ mov ax,#0
+read_err:
+
+ pop bp
+#endasm
+}
+
diff --git a/bootblocks/makeboot.c b/bootblocks/makeboot.c
index 53b5a82..4eda4c6 100644
--- a/bootblocks/makeboot.c
+++ b/bootblocks/makeboot.c
@@ -22,6 +22,10 @@ unsigned char buffer[1024];
#define FS_ZERO 5 /* Boot sector must be Zapped */
#define FS_MBR 6 /* Boot sector is an MBR */
+#ifndef __MSDOS__
+#define NOT_HAS_2M20
+#endif
+
struct bblist {
char * name;
char * desc;
@@ -192,6 +196,7 @@ char * diskname;
#endif
disktype = 0;
diskfd = fopen(diskname, "r+");
+ if( diskfd == 0 ) diskfd = fopen(diskname, "r");
if( diskfd == 0 )
{
fprintf(stderr, "Cannot open %s\n", diskname);
@@ -243,6 +248,7 @@ char * loadaddr;
fprintf(stderr, "Cannot write sector %d\n", sectno);
return -1;
}
+ printf("Wrote sector %d\n", sectno);
return 0;
}
@@ -649,9 +655,17 @@ check_msdos()
( dosflds[DOS_MEDIA].value != (0xFF&buffer[512])
&& dosflds[DOS_RESV].value == 1 ) )
{
- printf("Bad 2nd boot block - reloading first\n");
- if( read_sector(0, buffer) != 0 )
- exit(1);
+ if( force )
+ {
+ printf("Bad 2nd boot block - reloading first\n");
+ if( read_sector(0, buffer) != 0 )
+ exit(1);
+ }
+ else
+ {
+ printf("Bad 2nd boot block\n");
+ exit(1);
+ }
}
check_msdos();
}
@@ -735,6 +749,8 @@ char * mbr_data;
/**************************************************************************/
+#ifdef HAS_2M20
+
char boot_sector_2m_23_82[] = {
0xe9,0x7d,0x00,0x32,0x4d,0x2d,0x53,0x54,0x56,0x30,0x34,0x00,0x02,0x01,0x01,0x00,
0x02,0xe0,0x00,0xbc,0x0e,0xfa,0x0b,0x00,0x17,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
@@ -968,21 +984,28 @@ char program_2m_vsn_20[] = {
0x26,0x88,0x26,0x43,0x00,0xbf,0xfc,0x09,0xbe,0x4c,0x00,0xfc,0xfa,0xa5,0xa5,0xc7,
0x44,0xfc,0x5b,0x00,0x8c,0x44,0xfe,0xfb,0x1f,0xcb,0x00,0x00,0xd9,0x09,0x55,0xaa
};
+#endif
+
+char program_2m_magic[] = {
+0x2b,0x00,0x43,0x00,0x32,0x30,0x32,0x4d,0x2d,0x53,0x54,0x56,0x00,0x00,0x00,0x00
+};
do_2m_write()
{
int i;
+ char * mbr;
if( read_sector(bs_offset+1, buffer+512) != 0 )
exit(1);
- if( memcmp(buffer+512, program_2m_vsn_20, 16) == 0 )
+ if( memcmp(buffer+512, program_2m_magic, 16) == 0 )
{
/* Seems to be properly formatted already */
write_sector(bs_offset, buffer);
return;
}
+#ifdef HAS_2M20
else if( disk_trck != 82 || disk_sect != 22 )
{
fprintf(stderr, "To be bootable a 2M disk must be 22 sectors 82 tracks or formatted with 2m20.\n");
@@ -994,10 +1017,13 @@ do_2m_write()
/* This needs to be altered to allow for the disk format description to
be copied from the old boot sector */
+ if( disk_sect == 23 ) mbr = boot_sector_2m_23_82;
+ else mbr = boot_sector_2m_22_82;
+
for(i=0; i<sysboot_dosfs_stat; i++)
- buffer[i] = boot_sector_2m_22_82[i];
+ buffer[i] = mbr[i];
for(i=sysboot_codestart; i<512; i++)
- buffer[i] = boot_sector_2m_22_82[i];
+ buffer[i] = mbr[i];
write_sector(0, buffer);
@@ -1005,4 +1031,8 @@ do_2m_write()
{
write_sector(bs_offset+i/512+1, program_2m_vsn_20+i);
}
+#else
+ fprintf(stderr, "To be bootable a 2M disk must be formatted with the 2m20 device driver.\n");
+ exit(1);
+#endif
}
diff --git a/bootblocks/mbr.s b/bootblocks/mbr.s
index c0fa542..0d8560e 100644
--- a/bootblocks/mbr.s
+++ b/bootblocks/mbr.s
@@ -180,14 +180,11 @@ pre_boot_table:
endif
if diskman
- if *>ORGADDR+0xfc
- fail! Disk manager partition overlap
- endif
org ORGADDR+0xFC
public diskman_magic
diskman_magic:
- .word $55AA
+ .word 0xAA55
low_partition:
public partition_16
partition_16 = low_partition+0x00
diff --git a/bootblocks/min_buf.c b/bootblocks/min_buf.c
new file mode 100644
index 0000000..97324f3
--- /dev/null
+++ b/bootblocks/min_buf.c
@@ -0,0 +1,105 @@
+
+#include "monitor.h"
+
+#ifdef MINI_BUF
+#ifndef MAXTRK
+#define MAXTRK 21
+#endif
+
+int disk_drive = 0;
+int disk_spt = 7;
+int disk_heads = 2;
+int disk_cyls = 0;
+int bad_track = -1;
+
+static int track_no = -1;
+static char buffer[MAXTRK*512];
+
+void reset_disk()
+{
+ disk_spt = 7;
+ disk_heads = 2;
+ disk_cyls = 0;
+ bad_track = -1;
+}
+
+char * read_lsector(sectno)
+long sectno;
+{
+ int tries = 5;
+ int rv = 0;
+
+ int phy_s = 1;
+ int phy_h = 0;
+ int phy_c = 0;
+ int ltrack;
+
+ if( sectno == 0 ) reset_disk();
+
+ if( disk_spt < 1 || disk_heads < 1 )
+ phy_s = sectno;
+ else
+ {
+ phy_s = sectno%disk_spt;
+ phy_h = sectno/disk_spt%disk_heads;
+ phy_c = sectno/disk_spt/disk_heads;
+ }
+
+#ifdef __ELKS__
+ 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
+ && 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;
+ else
+ bad_track = ltrack;
+ }
+ if( track_no == phy_c*disk_heads+phy_h )
+ 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) return 0; else return buffer;
+}
+
+#if defined(__MSDOS__) || defined(__STANDALONE__)
+phy_read(drive, cyl, head, sect, length, buffer)
+{
+#asm
+ push bp
+ mov bp,sp
+
+ push ds
+ pop es
+
+ mov dl,[bp+2+_phy_read.drive]
+ mov ch,[bp+2+_phy_read.cyl]
+ mov dh,[bp+2+_phy_read.head]
+ mov cl,[bp+2+_phy_read.sect]
+ mov al,[bp+2+_phy_read.length]
+ mov bx,[bp+2+_phy_read.buffer]
+
+ mov ah,#$02
+ int $13
+ jc read_err
+ mov ax,#0
+read_err:
+
+ pop bp
+#endasm
+}
+#endif
+
+#endif
diff --git a/bootblocks/monitor.c b/bootblocks/monitor.c
index 4b7b75c..a44bad7 100644
--- a/bootblocks/monitor.c
+++ b/bootblocks/monitor.c
@@ -1,22 +1,15 @@
-#include <stdio.h>
-#include <errno.h>
-#include <ctype.h>
-#include <dos.h>
-#include "i86_funcs.h"
-#include "readfs.h"
+#include "monitor.h"
#include "version.h"
-#ifdef __STANDALONE__
-#define NOT_VT52COLOUR
-#define NOT_ANSICOLOUR
-#endif
-
char command_buf[256];
typedef int (*proc)();
-int cmd_quit(), cmd_dump(), cmd_seg(), cmd_rel();
+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();
+
void init_prog();
extern struct t_cmd_list {
@@ -24,19 +17,10 @@ extern struct t_cmd_list {
proc func;
} cmd_list[];
-static unsigned int current_address;
-static int number_base = 16;
-#ifdef __STANDALONE__
- extern union REGS __argr;
-#endif
+unsigned int current_address;
+int number_base = 16;
-#ifdef __STANDALONE__
main()
-#else
-main(argc, argv)
-int argc;
-char ** argv;
-#endif
{
static char minibuf[2] = " ";
int ch, i;
@@ -45,11 +29,11 @@ static char minibuf[2] = " ";
#ifdef __STANDALONE__
printf("\r");
-#else
- if( argc > 1 && strcmp(argv[1], "-t") == 0 ) x86_test=0; else x86_test=1;
#endif
init_prog();
+#ifdef __STANDALONE__
+#ifndef NOCOMMAND
if( __get_ds() != 0x1000 )
{
relocator(-1);
@@ -57,27 +41,26 @@ static char minibuf[2] = " ";
if( __get_ds() > 0x1000 ) relocator(2);
printf("Relocated to CS=$%04x DS=$%04x\n", __get_cs(), __get_ds());
}
+#endif
-#ifdef __STANDALONE__
if( (__argr.x.dx & 0xFF) == 0 )
#endif
{
display_help(0);
-
+#ifndef NOCOMMAND
if( x86 > 2 && !x86_emu ) /* Check some basics */
- cmd_bzimage((void*)0);
-#if 0
- else
- printf("System is not an 80386 compatible in real mode, load aborted.\nUse 'bzimage' command to attempt load.\n");
#endif
+ cmd_bzimage((void*)0);
}
+#ifdef NOCOMMAND
+ printf("Unable to boot, sorry\nreboot:");
+ fflush(stdout);
+ read(0, command_buf, sizeof(command_buf)-1) ;
+#else
for (;;)
{
-#ifdef ANSICOLOUR
- printf("\033[36m");
-#endif
-#ifdef VT52COLOUR
+#ifdef COLOUR
printf("\033S \033R+\033Sa\033Rc");
#endif
printf(">");
@@ -120,10 +103,7 @@ static char minibuf[2] = " ";
if( strcmp(cptr->command, cmd) == 0 )
break;
}
-#ifdef ANSICOLOUR
- printf("\033[37m");
-#endif
-#ifdef VT52COLOUR
+#ifdef COLOUR
printf("\033S \033Sa\033Rg");
#endif
fflush(stdout);
@@ -132,23 +112,34 @@ static char minibuf[2] = " ";
else
printf("Command not found.\n");
}
+#endif
}
/****************************************************************************/
void init_prog()
{
-#ifdef ANSICOLOUR
- printf("\033[H\033[0;44;37m\033[2J");
-#endif
-#ifdef VT52COLOUR
+#ifdef COLOUR
printf("\033E\033Rg\033Sa\033J");
#endif
-#ifdef VERSION
- printf("Linux x86 boot monitor, Version %s.\n", VERSION);
+ printf("Linux x86");
+#ifdef NOCOMMAND
+#ifdef TARFLOPPY
+ printf(" TAR floppy booter");
+#else
+#ifdef DOSFLOPPY
+ printf(" DOS floppy booter");
#else
- printf("Linux x86 boot monitor.\n");
+ printf(" floppy booter");
#endif
+#endif
+#else
+ printf(" boot monitor");
+#endif
+#ifdef VERSION
+ printf(", Version %s", VERSION);
+#endif
+ printf(".\n");
cpu_check();
mem_check();
@@ -156,7 +147,7 @@ void init_prog()
printf("Processor: %s", x86_name);
if(x86_fpu) printf(" with FPU");
if(x86_emu) printf(" in protected mode");
- if(!x86_test && x86 > 1)
+ if(x86 > 1)
{
printf(", A20 gate ");
if( a20_closed() )
@@ -174,41 +165,15 @@ void init_prog()
printf("There is %dk of boot memory", boot_mem_top/64);
if( main_mem_top )
{
- printf(" %ld.%ldM %sof main memory",
- main_mem_top/1024,
- (10*main_mem_top)/1024%10,
+ printf(" %d.%dM %sof main memory",
+ (int)(main_mem_top/1024),
+ (int)((10*main_mem_top)/1024%10),
main_mem_top >= 0xFC00L ?"(perhaps more) ":""
);
}
printf("\n");
}
-#ifdef __STANDALONE__
-reg_line()
-{
- printf("REGS: AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x\n",
- __argr.x.ax, __argr.x.bx, __argr.x.cx, __argr.x.dx,
- __argr.x.si, __argr.x.di);
-}
-#endif
-
-#ifdef VT52COLOUR
-colour_line()
-{
- printf("Colours: \033S ");
- printf("\033R_UNL\033S ");
- printf("\033R*BLK\033S ");
- printf("\033R+BLD\033S ");
- printf("\033R!REV\033S ");
- printf("\033Sa\033Rg ");
- printf("\033R@@\033Raa\033Rbb\033Rcc\033Rdd\033Ree\033Rff\033Rgg");
- printf("\033Rhh\033Rii\033Rjj\033Rkk\033Rll\033Rmm\033Rnn\033Roo");
- printf("\033Sa\033Rg\n");
-
- printf("\033S \033Sa\033Rg");
-}
-#endif
-
/****************************************************************************/
int
@@ -264,216 +229,25 @@ unsigned int * valptr;
return flg;
}
-more_char(ch)
-int ch;
-{
-static int line_number = 0;
-
- if( ch == -1 ) { line_number = 0; return 0; }
-
- if( (ch & 0xE0 ) || ch == '\n' )
- putchar(ch);
- if( ch == '\n' && ++line_number == 24)
- {
- char buf[4];
- printf("More ?"); fflush(stdout);
- if( read(0, buf, 1) <= 0 ) return -1;
- if( buf[0] == 3 || buf[0] == '\033'
- || buf[0] == 'q' || buf[0] == 'Q' ) return -1;
- if( buf[0] == '\r' ) line_number--;
- if( buf[0] == ' ' ) line_number=2;
- printf("\r \r");
- }
- return 0;
-}
-
-more_strn(str, len)
-char * str;
-int len;
-{
- for(; len>0 && *str ; len--,str++)
- if( more_char( *str & 0xFF ) < 0 ) return -1;
- return 0;
-}
-
-/****************************************************************************/
-
-int cmd_quit(args)
-char * args;
-{
- printf("Bye\n");
- exit(0);
-}
-
-cmd_memdump(ptr)
-char * ptr;
-{
- int count = 128;
- int i,j;
- int es = __get_es();
-
-#define rmem(x) __peek_es( (x)+current_address )
-
- getnum(&ptr, &current_address);
- getnum(&ptr, &count);
-
- for(i=0; i<count; i+=16)
- {
- printf("%04x:%04x:", es, current_address);
- for(j=0; j<16; j++)
- printf(" %s%02x", (j==8)?" ":"", rmem(j));
- printf(" ");
- for(j=0; j<16; j++)
- if( rmem(j) >= ' ' && rmem(j) <= '~' )
- putchar(rmem(j));
- else
- putchar('.');
- putchar('\n');
- current_address += 16;
- current_address &= 0xFFFF;
- }
-
-#undef rmem
-}
-
-int cmd_nop(ptr)
-char * ptr;
-{
-}
-
-int cmd_seg(ptr)
-char * ptr;
-{
- int es = __get_es();
-
- if( getnum(&ptr, &es) )
- {
- __set_es(es);
- current_address = 0;
- }
- else
- printf("Current segment 0x%04x\n", es);
- return 0;
-}
-
-int cmd_set_base(ptr)
-{
- int obase = number_base;
- int nbase;
- number_base = 10;
-
- if( getnum(&ptr, &nbase) )
- {
- if( nbase < 2 || nbase > 36 )
- printf("Can't use that base\n");
- else
- obase = nbase;
- }
- else printf("Current base is %d\n", obase);
-
- number_base = obase;
- return 0;
-}
-
-int cmd_rel(ptr)
-char * ptr;
-{
- int nseg = 0xFFFF;
- int cs = __get_cs();
-
- getnum(&ptr, &nseg);
-
- relocator(nseg);
- if( __get_cs() == cs )
- printf("Didn't relocate; CS=$%04x DS=$%04x\n", __get_cs(), __get_ds());
- else
- printf("Relocated to CS=$%04x DS=$%04x\n", __get_cs(), __get_ds());
-}
-
-int cmd_dir(ptr)
-char * ptr;
-{
- open_file(".");
- return 0;
-}
-
-int cmd_type(ptr)
-char * ptr;
-{
- char * fname;
- char buffer[1024];
- long len;
-
- while(*ptr == ' ') ptr++;
- if( (fname=ptr) == 0 ) return 0;
- while(*ptr & *ptr != ' ') ptr++;
-
- if( open_file(fname) >= 0 ) for(len=file_length(); len>0; len-=1024)
- {
- if( read_block(buffer) < 0 ) break;
- if( len > 1024 )
- write(1, buffer, 1024);
- else
- write(1, buffer, len);
- }
- else
- printf("Cannot open file '%s'\n", fname);
- close_file();
- return 0;
-}
-
-int cmd_more(ptr)
-char * ptr;
-{
- char * fname;
- char buffer[1024];
- long len;
- int cc;
- char * sptr;
-
- while(*ptr == ' ') ptr++;
- if( (fname=ptr) == 0 ) return 0;
- while(*ptr & *ptr != ' ') ptr++;
-
- more_char(-1);
-
- if( open_file(fname) >= 0 ) for(len=file_length(); len>0; len-=1024)
- {
- if( read_block(buffer) < 0 ) break;
- if( len > 1024 ) cc = 1024; else cc = len;
- for(sptr=buffer; cc>0 ; cc--,sptr++)
- {
- if( more_char(*sptr & 0xFF) < 0 ) goto break_break;
- }
- }
- else
- printf("Cannot open file '%s'\n", fname);
-break_break:;
- close_file();
- return 0;
-}
-
-/****************************************************************************/
-
-/* Others */
-extern int cmd_bzimage();
-extern int cmd_help();
-
/****************************************************************************/
+#ifndef NOCOMMAND
struct t_cmd_list cmd_list[] =
{
+ {"zimage", cmd_bzimage}, /* Load and run 386 zimage file */
+ {"bzimage",cmd_bzimage}, /* Load and run 386 bzimage file */
+ {"=", cmd_bzimage}, /* Load and run 386 bzimage file */
+
{"exit", cmd_quit}, {"quit", cmd_quit}, {"q", cmd_quit},
{"#", cmd_nop},
{"help", cmd_help}, /* Display from help.txt */
{"?", cmd_help}, /* Display from help.txt */
- {"zimage", cmd_bzimage}, /* Load and run 386 zimage file */
- {"bzimage",cmd_bzimage}, /* Load and run 386 bzimage file */
- {"=", cmd_bzimage}, /* Load and run 386 bzimage file */
{"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 */
{"more", cmd_more}, /* More a file to the screen */
+#ifndef NOMONITOR
/* Debugger/monitor commands */
{"memdump",cmd_memdump}, {"mem",cmd_memdump}, {"m", cmd_memdump},
/* Display bytes */
@@ -482,14 +256,9 @@ struct t_cmd_list cmd_list[] =
{"base", cmd_set_base},
{"n", cmd_set_base},
-#ifdef VT52COLOUR
- {"colour", colour_line},
-#endif
{"init", init_prog},
-#ifdef __STANDALONE__
- {"reg", reg_line},
- {"r", reg_line},
-#endif
+ {"reg", cmd_regs},
+ {"r", cmd_regs},
/*
{"edit", cmd_edit}, Alter memory
@@ -505,5 +274,8 @@ struct t_cmd_list cmd_list[] =
{"call", cmd_call}, load and run a bcc linux-8086 program.
*/
+#endif
+
{0,0}
};
+#endif
diff --git a/bootblocks/monitor.h b/bootblocks/monitor.h
new file mode 100644
index 0000000..de42a20
--- /dev/null
+++ b/bootblocks/monitor.h
@@ -0,0 +1,47 @@
+
+#include <stdio.h>
+#include <errno.h>
+#include <ctype.h>
+#include <dos.h>
+#include <malloc.h>
+#include "i86_funcs.h"
+#include "readfs.h"
+
+#define X_TARFLOPPY
+#define X_DOSFLOPPY
+#define X_CALC_CRC
+
+
+#ifdef __STANDALONE__
+#define COLOUR
+
+extern union REGS __argr;
+#endif
+
+
+#ifdef TARFLOPPY
+#define SINGLEFS
+#define NOMONITOR
+#define NOCOMMAND
+#define MINI_BUF
+
+#define open_file tar_open_file
+#define rewind_file tar_rewind_file
+#define close_file tar_close_file
+#define file_length tar_file_length
+#define read_block tar_read_block
+#endif
+
+#ifdef DOSFLOPPY
+#define SINGLEFS
+#define NOMONITOR
+#define NOCOMMAND
+#define MINI_BUF
+#define MAXTRK 24
+
+#define open_file dos_open_file
+#define rewind_file dos_rewind_file
+#define close_file dos_close_file
+#define file_length dos_file_length
+#define read_block dos_read_block
+#endif
diff --git a/bootblocks/relocate.c b/bootblocks/relocate.c
index 7f8b124..5e14d0e 100644
--- a/bootblocks/relocate.c
+++ b/bootblocks/relocate.c
@@ -1,7 +1,5 @@
-#include <stdio.h>
-#include <dos.h>
-#include "i86_funcs.h"
+#include "monitor.h"
static unsigned memseg = 0, memlen = 0;
@@ -21,11 +19,10 @@ void
relocator(newseg)
unsigned newseg;
{
+#ifdef __STANDALONE__
unsigned moved, codelen;
unsigned es = __get_es();
- if( x86_test ) return; /* I don't think so! */
-
/* Where do we start */
if(memseg == 0)
{
@@ -90,3 +87,7 @@ unsigned newseg;
L_x:
retf
#endasm
+
+#else
+}
+#endif
diff --git a/bootblocks/sysboot.s b/bootblocks/sysboot.s
index c7be509..558d02e 100644
--- a/bootblocks/sysboot.s
+++ b/bootblocks/sysboot.s
@@ -57,30 +57,25 @@ public bootblock_magic
.blkb sysboot_start+0x1BE-*
partition_1:
-.byte 0 ! IN
-.blkb 7 ! SH,SS,ST,OS,EH,ES,ET
+.blkb 8 ! IN,SH,SS,ST,OS,EH,ES,ET
.blkw 2 ! Linear position (0 based)
.blkw 2 ! Linear length
.blkb sysboot_start+0x1CE-*
partition_2:
-.byte 0 ! IN
-.blkb 7 ! SH,SS,ST,OS,EH,ES,ET
+.blkb 8 ! IN,SH,SS,ST,OS,EH,ES,ET
.blkw 2 ! Linear position (0 based)
.blkw 2 ! Linear length
.blkb sysboot_start+0x1DE-*
partition_3:
-.byte 0 ! IN
-.blkb 7 ! SH,SS,ST,OS,EH,ES,ET
+.blkb 8 ! IN,SH,SS,ST,OS,EH,ES,ET
.blkw 2 ! Linear position (0 based)
.blkw 2 ! Linear length
.blkb sysboot_start+0x1EE-*
partition_4:
-.byte 0 ! IN
-.blkb 7 ! SH,SS,ST,OS,EH,ES,ET
+.blkb 8 ! IN,SH,SS,ST,OS,EH,ES,ET
.blkw 2 ! Linear position (0 based)
.blkw 2 ! Linear length
-bootblock_magic:
.blkb sysboot_start+0x1FE-*
+bootblock_magic:
.word 0xAA55
-
diff --git a/bootblocks/tich.s b/bootblocks/tich.s
index 830f742..15bc238 100644
--- a/bootblocks/tich.s
+++ b/bootblocks/tich.s
@@ -35,4 +35,4 @@ mesg:
emesg:
org 510
- .word 0xAA55
+ .word 0
diff --git a/bootblocks/trk_buf.c b/bootblocks/trk_buf.c
index 7fbb4c9..f9ae3c8 100644
--- a/bootblocks/trk_buf.c
+++ b/bootblocks/trk_buf.c
@@ -1,9 +1,7 @@
-#include <stdio.h>
-#include <dos.h>
-#include <ctype.h>
-#include <malloc.h>
-#include "readfs.h"
+#include "monitor.h"
+
+#ifndef MINI_BUF
int disk_drive = 0;
int disk_spt = 7;
@@ -273,3 +271,4 @@ func_ok:
}
#endif
+#endif
diff --git a/bootblocks/unix.c b/bootblocks/unix.c
index e6eb41e..455d9b1 100644
--- a/bootblocks/unix.c
+++ b/bootblocks/unix.c
@@ -1,7 +1,7 @@
-#ifdef __ELKS__
+#include "monitor.h"
-#include <stdio.h>
+#ifdef __ELKS__
bios_khit() {
return 0;
@@ -31,11 +31,16 @@ extern long lseek();
int rv = 0;
long offset;
int i;
+extern int disk_spt;
+ int spt = 18;
if( phy_fd == -1 ) open_fd();
if( phy_fd < 0 ) return -1;
+ if( len <= 0 ) return -1;
+
+ if( disk_spt > 1 ) spt = disk_spt;
- offset = (((cyl*2 + head)*18L + sect-1)*512L);
+ offset = (((cyl*2 + head)*(long)spt + sect-1)*512L);
fprintf(stderr, "PHY_READ(d%d, c%d, h%d, s%d, l%d, b%d) (Sect=%ld)\n",
drive, cyl, head, sect, len, buffer, offset/512);