2000-05-06 21:34:20 +02:00
|
|
|
/****************************************************************/
|
|
|
|
/* */
|
|
|
|
/* main.c */
|
|
|
|
/* DOS-C */
|
|
|
|
/* */
|
|
|
|
/* Main Kernel Functions */
|
|
|
|
/* */
|
|
|
|
/* Copyright (c) 1995, 1996 */
|
|
|
|
/* Pasquale J. Villani */
|
|
|
|
/* All Rights Reserved */
|
|
|
|
/* */
|
|
|
|
/* This file is part of DOS-C. */
|
|
|
|
/* */
|
|
|
|
/* DOS-C is free software; you can redistribute it and/or */
|
|
|
|
/* modify it under the terms of the GNU General Public License */
|
|
|
|
/* as published by the Free Software Foundation; either version */
|
|
|
|
/* 2, or (at your option) any later version. */
|
|
|
|
/* */
|
|
|
|
/* DOS-C is distributed in the hope that it will be useful, but */
|
|
|
|
/* WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
|
|
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
|
|
|
|
/* the GNU General Public License for more details. */
|
|
|
|
/* */
|
|
|
|
/* You should have received a copy of the GNU General Public */
|
|
|
|
/* License along with DOS-C; see the file COPYING. If not, */
|
2003-06-30 20:46:37 +02:00
|
|
|
/* write to the Free Software Foundation, Inc., */
|
|
|
|
/* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */
|
2000-05-06 21:34:20 +02:00
|
|
|
/****************************************************************/
|
|
|
|
|
2001-04-22 00:32:53 +02:00
|
|
|
#include "portab.h"
|
2000-05-06 21:34:20 +02:00
|
|
|
#include "init-mod.h"
|
2001-09-23 22:39:44 +02:00
|
|
|
#include "dyndata.h"
|
|
|
|
|
2003-06-20 21:54:18 +02:00
|
|
|
#ifdef VERSION_STRINGS
|
|
|
|
static BYTE *mainRcsId =
|
|
|
|
"$Id$";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static char copyright[] =
|
2003-06-15 15:24:53 +02:00
|
|
|
"(C) Copyright 1995-2003 Pasquale J. Villani and The FreeDOS Project.\n"
|
2001-11-04 20:47:39 +01:00
|
|
|
"All Rights Reserved. This is free software and comes with ABSOLUTELY NO\n"
|
|
|
|
"WARRANTY; you can redistribute it and/or modify it under the terms of the\n"
|
|
|
|
"GNU General Public License as published by the Free Software Foundation;\n"
|
|
|
|
"either version 2, or (at your option) any later version.\n";
|
2001-09-23 22:39:44 +02:00
|
|
|
|
2003-06-15 16:38:13 +02:00
|
|
|
struct _KernelConfig InitKernelConfig = { "", 0, 0, 0, 0, 0, 0, 0 };
|
2001-11-04 20:47:39 +01:00
|
|
|
|
2002-01-23 23:29:41 +01:00
|
|
|
STATIC VOID InitIO(void);
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2002-01-23 23:29:41 +01:00
|
|
|
STATIC VOID update_dcb(struct dhdr FAR *);
|
|
|
|
STATIC VOID init_kernel(VOID);
|
|
|
|
STATIC VOID signon(VOID);
|
|
|
|
STATIC VOID kernel(VOID);
|
|
|
|
STATIC VOID FsConfig(VOID);
|
|
|
|
STATIC VOID InitPrinters(VOID);
|
2003-06-20 21:54:18 +02:00
|
|
|
STATIC void CheckContinueBootFromHarddisk(void);
|
2002-12-09 01:17:15 +01:00
|
|
|
|
2001-09-23 22:39:44 +02:00
|
|
|
#ifdef _MSC_VER
|
2001-11-18 15:01:12 +01:00
|
|
|
BYTE _acrtused = 0;
|
2001-09-23 22:39:44 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
__segment DosDataSeg = 0; /* serves for all references to the DOS DATA segment
|
|
|
|
necessary for MSC+our funny linking model
|
|
|
|
*/
|
|
|
|
__segment DosTextSeg = 0;
|
2001-09-23 22:39:44 +02:00
|
|
|
|
2003-08-28 23:03:47 +02:00
|
|
|
struct lol FAR *LoL;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2003-08-28 23:03:47 +02:00
|
|
|
#else
|
2003-06-20 21:54:18 +02:00
|
|
|
struct lol FAR *LoL = &DATASTART;
|
2003-08-28 23:03:47 +02:00
|
|
|
#endif
|
2003-06-20 21:54:18 +02:00
|
|
|
|
2002-02-09 01:40:33 +01:00
|
|
|
/* little functions - could be ASM but does not really matter in this context */
|
|
|
|
void memset(void *s, int c, unsigned n)
|
|
|
|
{
|
|
|
|
char *t = s;
|
|
|
|
while(n--) *t++ = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
void fmemset(void far *s, int c, unsigned n)
|
|
|
|
{
|
|
|
|
char far *t = s;
|
|
|
|
while(n--) *t++ = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
void strcpy(char *dest, const char *src)
|
|
|
|
{
|
|
|
|
while(*src)
|
|
|
|
*dest++ = *src++;
|
|
|
|
*dest = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
void fmemcpy(void far *dest, const void far *src, unsigned n)
|
|
|
|
{
|
|
|
|
char far *d = dest;
|
|
|
|
const char far *s = src;
|
|
|
|
while(n--) *d++ = *s++;
|
|
|
|
}
|
|
|
|
|
2002-01-23 23:29:41 +01:00
|
|
|
VOID ASMCFUNC FreeDOSmain(void)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2001-11-18 15:01:12 +01:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
extern FAR prn_dev;
|
|
|
|
DosDataSeg = (__segment) & DATASTART;
|
|
|
|
DosTextSeg = (__segment) & prn_dev;
|
2003-08-28 23:03:47 +02:00
|
|
|
LoL = &DATASTART;
|
2001-11-18 15:01:12 +01:00
|
|
|
#endif
|
|
|
|
|
2002-01-23 23:29:41 +01:00
|
|
|
|
|
|
|
/* if the kernel has been UPX'ed,
|
|
|
|
CONFIG info is stored at 50:e2 ..fc
|
|
|
|
and the bootdrive (passed from BIOS)
|
|
|
|
at 50:e0
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (fmemcmp(MK_FP(0x50,0xe0+2),"CONFIG",6) == 0) /* UPX */
|
2002-02-17 11:39:35 +01:00
|
|
|
{
|
2003-06-30 20:46:37 +02:00
|
|
|
UBYTE drv;
|
|
|
|
|
|
|
|
fmemcpy(&InitKernelConfig, MK_FP(0,0x5e0+2), sizeof(InitKernelConfig));
|
|
|
|
|
|
|
|
drv = *(UBYTE FAR *)MK_FP(0,0x5e0) + 1;
|
|
|
|
if (drv >= 0x80)
|
|
|
|
drv = 3; /* C: */
|
|
|
|
LoL->BootDrive = drv;
|
2002-01-23 23:29:41 +01:00
|
|
|
|
2003-06-30 20:46:37 +02:00
|
|
|
*(DWORD FAR *)MK_FP(0,0x5e0+2) = 0;
|
2002-02-17 11:39:35 +01:00
|
|
|
}
|
2002-01-23 23:29:41 +01:00
|
|
|
else
|
2002-02-17 11:39:35 +01:00
|
|
|
{
|
|
|
|
fmemcpy(&InitKernelConfig, &LowKernelConfig, sizeof(InitKernelConfig));
|
|
|
|
}
|
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
setvec(0, int0_handler); /* zero divide */
|
|
|
|
setvec(1, empty_handler); /* single step */
|
|
|
|
setvec(3, empty_handler); /* debug breakpoint */
|
2002-08-03 18:54:09 +02:00
|
|
|
setvec(6, int6_handler); /* invalid opcode */
|
2001-11-18 15:01:12 +01:00
|
|
|
|
2003-06-15 16:38:13 +02:00
|
|
|
|
|
|
|
CheckContinueBootFromHarddisk();
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
/* clear the Init BSS area (what normally the RTL does */
|
|
|
|
memset(_ib_start, 0, _ib_end - _ib_start);
|
|
|
|
|
2002-05-09 00:49:35 +02:00
|
|
|
signon();
|
2000-05-06 21:34:20 +02:00
|
|
|
init_kernel();
|
2001-03-21 03:56:26 +01:00
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
#ifdef DEBUG
|
|
|
|
/* Non-portable message kludge alert! */
|
2003-06-15 17:53:58 +02:00
|
|
|
printf("KERNEL: Boot drive = %c\n", 'A' + LoL->BootDrive - 1);
|
2000-05-06 21:34:20 +02:00
|
|
|
#endif
|
2003-03-13 00:06:48 +01:00
|
|
|
|
|
|
|
DoInstall();
|
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
kernel();
|
|
|
|
}
|
|
|
|
|
2001-03-30 21:30:06 +02:00
|
|
|
/*
|
|
|
|
InitializeAllBPBs()
|
|
|
|
|
|
|
|
or MakeNortonDiskEditorHappy()
|
|
|
|
|
|
|
|
it has been determined, that FDOS's BPB tables are initialized,
|
|
|
|
only when used (like DIR H:).
|
|
|
|
at least one known utility (norton DE) seems to access them directly.
|
|
|
|
ok, so we access for all drives, that the stuff gets build
|
|
|
|
*/
|
2001-04-15 05:21:50 +02:00
|
|
|
void InitializeAllBPBs(VOID)
|
2001-03-30 21:30:06 +02:00
|
|
|
{
|
|
|
|
static char filename[] = "A:-@JUNK@-.TMP";
|
2001-11-18 15:01:12 +01:00
|
|
|
int drive, fileno;
|
2003-06-15 17:53:58 +02:00
|
|
|
for (drive = 'C'; drive < 'A' + LoL->nblkdev; drive++)
|
2001-11-18 15:01:12 +01:00
|
|
|
{
|
|
|
|
filename[0] = drive;
|
|
|
|
if ((fileno = open(filename, O_RDONLY)) >= 0)
|
|
|
|
close(fileno);
|
|
|
|
}
|
|
|
|
}
|
2001-03-30 21:30:06 +02:00
|
|
|
|
2002-01-23 23:29:41 +01:00
|
|
|
STATIC void init_kernel(void)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
|
|
|
COUNT i;
|
2001-11-18 15:01:12 +01:00
|
|
|
|
2003-06-15 21:26:49 +02:00
|
|
|
LoL->os_setver_major = LoL->os_major = MAJOR_RELEASE;
|
|
|
|
LoL->os_setver_minor = LoL->os_minor = MINOR_RELEASE;
|
2001-04-15 05:21:50 +02:00
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
/* Init oem hook - returns memory size in KB */
|
|
|
|
ram_top = init_oem();
|
2000-06-21 20:16:46 +02:00
|
|
|
|
2001-07-28 20:13:06 +02:00
|
|
|
/* move kernel to high conventional RAM, just below the init code */
|
2001-11-18 15:01:12 +01:00
|
|
|
lpTop = MK_FP(ram_top * 64 - (FP_OFF(_init_end) + 15) / 16 -
|
|
|
|
(FP_OFF(_HMATextEnd) + 15) / 16, 0);
|
|
|
|
|
2001-07-28 20:13:06 +02:00
|
|
|
MoveKernel(FP_SEG(lpTop));
|
|
|
|
lpOldTop = lpTop = MK_FP(FP_SEG(lpTop) - 0xfff, 0xfff0);
|
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
for (i = 0x20; i <= 0x3f; i++)
|
|
|
|
setvec(i, empty_handler);
|
|
|
|
|
|
|
|
/* Initialize IO subsystem */
|
|
|
|
InitIO();
|
2001-09-23 22:39:44 +02:00
|
|
|
InitPrinters();
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* set interrupt vectors */
|
|
|
|
setvec(0x1b, got_cbreak);
|
|
|
|
setvec(0x20, int20_handler);
|
|
|
|
setvec(0x21, int21_handler);
|
|
|
|
setvec(0x22, int22_handler);
|
|
|
|
setvec(0x23, empty_handler);
|
|
|
|
setvec(0x24, int24_handler);
|
|
|
|
setvec(0x25, low_int25_handler);
|
|
|
|
setvec(0x26, low_int26_handler);
|
|
|
|
setvec(0x27, int27_handler);
|
|
|
|
setvec(0x28, int28_handler);
|
|
|
|
setvec(0x2a, int2a_handler);
|
|
|
|
setvec(0x2f, int2f_handler);
|
|
|
|
|
2001-06-03 16:16:18 +02:00
|
|
|
init_PSPSet(DOS_PSP);
|
2003-08-31 00:17:42 +02:00
|
|
|
set_DTA(MK_FP(DOS_PSP, 0x80));
|
2001-04-15 05:21:50 +02:00
|
|
|
init_PSPInit(DOS_PSP);
|
2003-07-12 22:56:11 +02:00
|
|
|
((psp far *)MK_FP(DOS_PSP, 0))->ps_environ = DOS_PSP + 8;
|
2001-04-15 05:21:50 +02:00
|
|
|
|
2002-12-09 01:17:15 +01:00
|
|
|
Init_clk_driver();
|
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
/* Do first initialization of system variable buffers so that */
|
|
|
|
/* we can read config.sys later. */
|
2003-06-15 17:53:58 +02:00
|
|
|
LoL->lastdrive = Config.cfgLastdrive;
|
2001-07-10 00:19:33 +02:00
|
|
|
|
|
|
|
/* init_device((struct dhdr FAR *)&blk_dev, NULL, NULL, ram_top); */
|
|
|
|
blk_dev.dh_name[0] = dsk_init();
|
2001-07-28 20:13:06 +02:00
|
|
|
|
|
|
|
PreConfig();
|
|
|
|
|
2001-07-10 00:19:33 +02:00
|
|
|
/* Number of units */
|
|
|
|
if (blk_dev.dh_name[0] > 0)
|
2001-11-18 15:01:12 +01:00
|
|
|
update_dcb(&blk_dev);
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* Now config the temporary file system */
|
|
|
|
FsConfig();
|
|
|
|
|
|
|
|
/* Now process CONFIG.SYS */
|
2002-01-23 23:29:41 +01:00
|
|
|
DoConfig(0);
|
|
|
|
DoConfig(1);
|
2001-04-16 03:45:26 +02:00
|
|
|
|
2003-06-15 15:24:53 +02:00
|
|
|
/* initialize near data and MCBs */
|
|
|
|
PreConfig2();
|
|
|
|
/* and process CONFIG.SYS one last time for device drivers */
|
|
|
|
DoConfig(2);
|
|
|
|
|
2003-06-20 21:54:18 +02:00
|
|
|
|
2001-04-16 03:45:26 +02:00
|
|
|
/* Close all (device) files */
|
2003-07-14 21:17:01 +02:00
|
|
|
for (i = 0; i < 20; i++)
|
2001-04-22 00:32:53 +02:00
|
|
|
close(i);
|
2001-11-18 15:01:12 +01:00
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
/* and do final buffer allocation. */
|
|
|
|
PostConfig();
|
|
|
|
|
2001-04-15 05:21:50 +02:00
|
|
|
/* Init the file system one more time */
|
2000-05-06 21:34:20 +02:00
|
|
|
FsConfig();
|
2003-06-20 21:54:18 +02:00
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
configDone();
|
2000-05-08 06:30:00 +02:00
|
|
|
|
2001-04-22 00:32:53 +02:00
|
|
|
InitializeAllBPBs();
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
|
2002-01-23 23:29:41 +01:00
|
|
|
STATIC VOID FsConfig(VOID)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2003-06-20 21:54:18 +02:00
|
|
|
struct dpb FAR *dpb = LoL->DPBp;
|
|
|
|
int i;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-04-15 05:21:50 +02:00
|
|
|
/* Initialize the current directory structures */
|
2003-06-15 17:53:58 +02:00
|
|
|
for (i = 0; i < LoL->lastdrive; i++)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2003-06-15 17:53:58 +02:00
|
|
|
struct cds FAR *pcds_table = &LoL->CDSp[i];
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-11-18 00:26:45 +01:00
|
|
|
fmemcpy(pcds_table->cdsCurrentPath, "A:\\\0", 4);
|
2001-03-21 03:56:26 +01:00
|
|
|
|
|
|
|
pcds_table->cdsCurrentPath[0] += i;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2003-06-15 17:53:58 +02:00
|
|
|
if (i < LoL->nblkdev && (ULONG) dpb != 0xffffffffl)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2001-04-15 05:21:50 +02:00
|
|
|
pcds_table->cdsDpb = dpb;
|
2001-03-21 03:56:26 +01:00
|
|
|
pcds_table->cdsFlags = CDSPHYSDRV;
|
2001-04-15 05:21:50 +02:00
|
|
|
dpb = dpb->dpb_next;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-21 03:56:26 +01:00
|
|
|
pcds_table->cdsFlags = 0;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
2001-03-21 03:56:26 +01:00
|
|
|
pcds_table->cdsStrtClst = 0xffff;
|
|
|
|
pcds_table->cdsParam = 0xffff;
|
|
|
|
pcds_table->cdsStoreUData = 0xffff;
|
|
|
|
pcds_table->cdsJoinOffset = 2;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
|
2003-06-15 17:53:58 +02:00
|
|
|
/* Log-in the default drive. */
|
|
|
|
init_setdrive(LoL->BootDrive - 1);
|
|
|
|
|
2002-01-23 23:29:41 +01:00
|
|
|
/* The system file tables need special handling and are "hand */
|
|
|
|
/* built. Included is the stdin, stdout, stdaux and stdprn. */
|
2002-10-22 04:40:19 +02:00
|
|
|
/* a little bit of shuffling is necessary for compatibility */
|
2002-01-23 23:29:41 +01:00
|
|
|
|
2002-10-22 04:40:19 +02:00
|
|
|
/* sft_idx=0 is /dev/aux */
|
|
|
|
open("AUX", O_RDWR);
|
|
|
|
|
|
|
|
/* handle 1, sft_idx=1 is /dev/con (stdout) */
|
2002-01-23 23:29:41 +01:00
|
|
|
open("CON", O_RDWR);
|
|
|
|
|
2002-10-22 04:40:19 +02:00
|
|
|
/* 3 is /dev/aux */
|
|
|
|
dup2(STDIN, STDAUX);
|
2002-01-23 23:29:41 +01:00
|
|
|
|
2002-10-22 04:40:19 +02:00
|
|
|
/* 0 is /dev/con (stdin) */
|
|
|
|
dup2(STDOUT, STDIN);
|
2002-01-23 23:29:41 +01:00
|
|
|
|
2002-10-22 04:40:19 +02:00
|
|
|
/* 2 is /dev/con (stdin) */
|
|
|
|
dup2(STDOUT, STDERR);
|
2002-01-23 23:29:41 +01:00
|
|
|
|
|
|
|
/* 4 is /dev/prn */
|
|
|
|
open("PRN", O_WRONLY);
|
|
|
|
|
2001-04-15 05:21:50 +02:00
|
|
|
/* Initialize the disk buffer management functions */
|
2001-03-21 03:56:26 +01:00
|
|
|
/* init_call_init_buffers(); done from CONFIG.C */
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
|
2002-01-23 23:29:41 +01:00
|
|
|
STATIC VOID signon()
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2003-06-15 17:53:58 +02:00
|
|
|
printf("\r%S", MK_FP(FP_SEG(LoL), FP_OFF(LoL->os_release)));
|
2001-09-23 22:39:44 +02:00
|
|
|
|
2002-05-09 00:49:35 +02:00
|
|
|
printf("Kernel compatibility %d.%d", MAJOR_RELEASE, MINOR_RELEASE);
|
2001-09-23 22:39:44 +02:00
|
|
|
|
|
|
|
#if defined(__TURBOC__)
|
2001-11-18 15:01:12 +01:00
|
|
|
printf(" - TURBOC");
|
2001-09-23 22:39:44 +02:00
|
|
|
#elif defined(_MSC_VER)
|
2001-11-18 15:01:12 +01:00
|
|
|
printf(" - MSC");
|
2001-09-23 22:39:44 +02:00
|
|
|
#elif defined(__WATCOMC__)
|
2001-11-18 15:01:12 +01:00
|
|
|
printf(" - WATCOMC");
|
2002-08-03 18:54:09 +02:00
|
|
|
#elif defined(__GNUC__)
|
|
|
|
printf(" - GNUC"); /* this is hypothetical only */
|
2001-09-23 22:39:44 +02:00
|
|
|
#else
|
2001-11-18 15:01:12 +01:00
|
|
|
generate some bullshit error here, as the compiler should be known
|
2001-09-23 22:39:44 +02:00
|
|
|
#endif
|
|
|
|
#if defined (I386)
|
2001-11-18 15:01:12 +01:00
|
|
|
printf(" - 80386 CPU required");
|
2001-09-23 22:39:44 +02:00
|
|
|
#elif defined (I186)
|
2001-11-18 15:01:12 +01:00
|
|
|
printf(" - 80186 CPU required");
|
|
|
|
#endif
|
2001-09-23 22:39:44 +02:00
|
|
|
|
|
|
|
#ifdef WITHFAT32
|
2001-11-18 15:01:12 +01:00
|
|
|
printf(" - FAT32 support");
|
|
|
|
#endif
|
|
|
|
printf("\n\n%S", (void FAR *)copyright);
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
|
2002-01-23 23:29:41 +01:00
|
|
|
STATIC void kernel()
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2001-04-22 00:32:53 +02:00
|
|
|
exec_blk exb;
|
|
|
|
CommandTail Cmd;
|
|
|
|
int rc;
|
|
|
|
|
2002-02-16 20:20:20 +01:00
|
|
|
BYTE master_env[32];
|
|
|
|
char *masterenv_ptr = master_env;
|
2001-11-18 15:01:12 +01:00
|
|
|
|
2002-02-16 20:20:20 +01:00
|
|
|
/* build the startup environment */
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2002-02-16 20:20:20 +01:00
|
|
|
memset(master_env,0,sizeof(master_env));
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2002-02-16 20:20:20 +01:00
|
|
|
/* initial path setting. is this useful ?? */
|
|
|
|
masterenv_ptr += sprintf(masterenv_ptr, "PATH=.");
|
|
|
|
|
|
|
|
/* export the current selected config menu */
|
2002-05-09 00:49:35 +02:00
|
|
|
if (Menus)
|
2002-02-16 20:20:20 +01:00
|
|
|
{
|
2002-05-09 00:49:35 +02:00
|
|
|
masterenv_ptr += sprintf(masterenv_ptr, "CONFIG=%c", MenuSelected+'0');
|
2002-02-16 20:20:20 +01:00
|
|
|
}
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
exb.exec.env_seg = DOS_PSP + 8;
|
2001-04-22 00:32:53 +02:00
|
|
|
fmemcpy(MK_FP(exb.exec.env_seg, 0), master_env, sizeof(master_env));
|
2001-04-29 19:34:41 +02:00
|
|
|
|
2001-04-22 00:32:53 +02:00
|
|
|
/* process 0 */
|
|
|
|
/* Execute command.com /P from the drive we just booted from */
|
2002-02-09 01:40:33 +01:00
|
|
|
memset(Cmd.ctBuffer, 0, sizeof(Cmd.ctBuffer));
|
|
|
|
fmemcpy(Cmd.ctBuffer, Config.cfgInitTail, sizeof(Config.cfgInitTail));
|
2001-04-22 00:32:53 +02:00
|
|
|
|
2002-02-09 01:40:33 +01:00
|
|
|
for (Cmd.ctCount = 0; Cmd.ctCount < sizeof(Cmd.ctBuffer); Cmd.ctCount++)
|
2001-04-22 00:32:53 +02:00
|
|
|
if (Cmd.ctBuffer[Cmd.ctCount] == '\r')
|
|
|
|
break;
|
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
/* if stepping CONFIG.SYS (F5/F8), tell COMMAND.COM about it */
|
|
|
|
|
2002-02-09 01:40:33 +01:00
|
|
|
if (Cmd.ctCount < sizeof(Cmd.ctBuffer) - 3)
|
2001-11-18 15:01:12 +01:00
|
|
|
{
|
|
|
|
char *insertString = NULL;
|
|
|
|
|
|
|
|
if (singleStep)
|
|
|
|
insertString = " /Y"; /* single step AUTOEXEC */
|
2001-04-29 19:34:41 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (SkipAllConfig)
|
|
|
|
insertString = " /D"; /* disable AUTOEXEC */
|
2001-04-29 19:34:41 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (insertString)
|
|
|
|
{
|
2001-04-29 19:34:41 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
/* insert /D, /Y as first argument */
|
2002-08-03 18:54:09 +02:00
|
|
|
char *p, *q;
|
2001-04-29 19:34:41 +02:00
|
|
|
|
2002-08-03 18:54:09 +02:00
|
|
|
for (p = Cmd.ctBuffer; p < &Cmd.ctBuffer[Cmd.ctCount]; p++)
|
2001-04-29 19:34:41 +02:00
|
|
|
{
|
2002-08-03 18:54:09 +02:00
|
|
|
if (*p == ' ' || *p == '\t' || *p == '\r')
|
2001-04-29 19:34:41 +02:00
|
|
|
{
|
2002-08-03 18:54:09 +02:00
|
|
|
for (q = &Cmd.ctBuffer[Cmd.ctCount - 1]; q >= p; q--)
|
|
|
|
q[3] = q[0];
|
2001-11-18 15:01:12 +01:00
|
|
|
|
2002-08-03 18:54:09 +02:00
|
|
|
fmemcpy(p, insertString, 3);
|
2001-11-18 15:01:12 +01:00
|
|
|
|
2002-08-03 18:54:09 +02:00
|
|
|
Cmd.ctCount += 3;
|
2001-11-18 15:01:12 +01:00
|
|
|
break;
|
2001-04-29 19:34:41 +02:00
|
|
|
}
|
2001-11-18 15:01:12 +01:00
|
|
|
}
|
|
|
|
}
|
2001-04-29 19:34:41 +02:00
|
|
|
}
|
|
|
|
|
2001-04-22 00:32:53 +02:00
|
|
|
exb.exec.cmd_line = (CommandTail FAR *) & Cmd;
|
2002-05-09 00:49:35 +02:00
|
|
|
exb.exec.fcb_1 = exb.exec.fcb_2 = (fcb FAR *) 0xfffffffful;
|
|
|
|
|
2001-04-22 00:32:53 +02:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("Process 0 starting: %s\n\n", Config.cfgInit);
|
|
|
|
#endif
|
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
while ((rc =
|
|
|
|
init_DosExec(Config.cfgP_0_startmode, &exb,
|
|
|
|
Config.cfgInit)) != SUCCESS)
|
2001-04-22 00:32:53 +02:00
|
|
|
{
|
|
|
|
BYTE *pLine;
|
2001-11-18 15:01:12 +01:00
|
|
|
printf("\nBad or missing Command Interpreter: %d - %s\n", rc,
|
|
|
|
Cmd.ctBuffer);
|
|
|
|
printf
|
|
|
|
("\nPlease enter the correct location (for example C:\\COMMAND.COM):\n");
|
|
|
|
rc = read(STDIN, Cmd.ctBuffer, sizeof(Cmd.ctBuffer) - 1);
|
|
|
|
Cmd.ctBuffer[rc] = '\0';
|
2001-04-22 00:32:53 +02:00
|
|
|
|
|
|
|
/* Get the string argument that represents the new init pgm */
|
|
|
|
pLine = GetStringArg(Cmd.ctBuffer, Config.cfgInit);
|
|
|
|
|
|
|
|
/* Now take whatever tail is left and add it on as a single */
|
|
|
|
/* string. */
|
|
|
|
strcpy(Cmd.ctBuffer, pLine);
|
|
|
|
|
|
|
|
/* and add a DOS new line just to be safe */
|
|
|
|
strcat(Cmd.ctBuffer, "\r\n");
|
2001-11-18 15:01:12 +01:00
|
|
|
|
|
|
|
Cmd.ctCount = rc - (pLine - Cmd.ctBuffer);
|
2001-04-22 00:32:53 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("Process 0 starting: %s\n\n", Config.cfgInit);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
printf("\nSystem shutdown complete\nReboot now.\n");
|
|
|
|
for (;;) ;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
|
2001-04-15 05:21:50 +02:00
|
|
|
/* check for a block device and update device control block */
|
2002-01-23 23:29:41 +01:00
|
|
|
STATIC VOID update_dcb(struct dhdr FAR * dhp)
|
2001-04-15 05:21:50 +02:00
|
|
|
{
|
|
|
|
REG COUNT Index;
|
|
|
|
COUNT nunits = dhp->dh_name[0];
|
|
|
|
struct dpb FAR *dpb;
|
|
|
|
|
2003-06-15 17:53:58 +02:00
|
|
|
if (LoL->nblkdev == 0)
|
|
|
|
dpb = LoL->DPBp;
|
2001-11-18 15:01:12 +01:00
|
|
|
else
|
|
|
|
{
|
2003-06-15 17:53:58 +02:00
|
|
|
for (dpb = LoL->DPBp; (ULONG) dpb->dpb_next != 0xffffffffl;
|
2001-11-18 15:01:12 +01:00
|
|
|
dpb = dpb->dpb_next)
|
2001-04-15 05:21:50 +02:00
|
|
|
;
|
2001-11-18 15:01:12 +01:00
|
|
|
dpb = dpb->dpb_next =
|
2003-06-15 15:24:53 +02:00
|
|
|
KernelAlloc(nunits * sizeof(struct dpb), 'E', Config.cfgDosDataUmb);
|
2001-04-15 05:21:50 +02:00
|
|
|
}
|
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
for (Index = 0; Index < nunits; Index++)
|
|
|
|
{
|
|
|
|
dpb->dpb_next = dpb + 1;
|
2003-06-15 17:53:58 +02:00
|
|
|
dpb->dpb_unit = LoL->nblkdev;
|
2001-04-15 05:21:50 +02:00
|
|
|
dpb->dpb_subunit = Index;
|
|
|
|
dpb->dpb_device = dhp;
|
|
|
|
dpb->dpb_flags = M_CHANGED;
|
2003-06-15 17:53:58 +02:00
|
|
|
if ((LoL->CDSp != 0) && (LoL->nblkdev < LoL->lastdrive))
|
2001-04-15 05:21:50 +02:00
|
|
|
{
|
2003-06-15 17:53:58 +02:00
|
|
|
LoL->CDSp[LoL->nblkdev].cdsDpb = dpb;
|
|
|
|
LoL->CDSp[LoL->nblkdev].cdsFlags = CDSPHYSDRV;
|
2001-04-15 05:21:50 +02:00
|
|
|
}
|
|
|
|
++dpb;
|
2003-06-15 17:53:58 +02:00
|
|
|
++LoL->nblkdev;
|
2001-04-15 05:21:50 +02:00
|
|
|
}
|
2001-11-18 15:01:12 +01:00
|
|
|
(dpb - 1)->dpb_next = (void FAR *)0xFFFFFFFFl;
|
2001-04-15 05:21:50 +02:00
|
|
|
}
|
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
/* If cmdLine is NULL, this is an internal driver */
|
|
|
|
|
2003-06-15 15:24:53 +02:00
|
|
|
BOOL init_device(struct dhdr FAR * dhp, char *cmdLine, COUNT mode,
|
2002-10-22 04:40:19 +02:00
|
|
|
char FAR *r_top)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
|
|
|
request rq;
|
2003-06-15 15:24:53 +02:00
|
|
|
int i;
|
|
|
|
char name[8];
|
2003-06-30 20:46:37 +02:00
|
|
|
char *p, *q;
|
|
|
|
|
|
|
|
for (p = q = cmdLine; *p && *p != ' ' && *p != '\t'; p++)
|
|
|
|
{
|
2003-08-28 22:53:21 +02:00
|
|
|
if (*p == '\\' || *p == '/' || *p == ':')
|
2003-06-30 20:46:37 +02:00
|
|
|
q = p + 1;
|
|
|
|
}
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
char ch = *q;
|
|
|
|
if (ch != '\0')
|
|
|
|
q++;
|
|
|
|
if (ch == '.')
|
|
|
|
ch = 0;
|
|
|
|
name[i] = ch;
|
|
|
|
}
|
2003-06-15 15:24:53 +02:00
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
rq.r_unit = 0;
|
|
|
|
rq.r_status = 0;
|
|
|
|
rq.r_command = C_INIT;
|
|
|
|
rq.r_length = sizeof(request);
|
2002-10-22 04:40:19 +02:00
|
|
|
rq.r_endaddr = r_top;
|
2000-05-06 21:34:20 +02:00
|
|
|
rq.r_bpbptr = (void FAR *)(cmdLine ? cmdLine : "\n");
|
2003-06-15 17:53:58 +02:00
|
|
|
rq.r_firstunit = LoL->nblkdev;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
execrh((request FAR *) & rq, dhp);
|
2001-04-22 00:32:53 +02:00
|
|
|
|
2000-05-26 21:25:19 +02:00
|
|
|
/*
|
|
|
|
* Added needed Error handle
|
|
|
|
*/
|
2003-07-12 22:56:11 +02:00
|
|
|
if ((rq.r_status & (S_ERROR | S_DONE)) == S_ERROR)
|
2000-05-26 21:25:19 +02:00
|
|
|
return TRUE;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (cmdLine)
|
|
|
|
{
|
2003-06-15 15:24:53 +02:00
|
|
|
/* Don't link in device drivers which do not take up memory */
|
|
|
|
if (rq.r_endaddr == (BYTE FAR *) dhp)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
KernelAllocPara(FP_SEG(rq.r_endaddr) + (FP_OFF(rq.r_endaddr) + 15)/16
|
|
|
|
- FP_SEG(dhp), 'D', name, mode);
|
2001-04-16 03:45:26 +02:00
|
|
|
}
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
if (!(dhp->dh_attr & ATTR_CHAR) && (rq.r_nunits != 0))
|
|
|
|
{
|
2001-04-15 05:21:50 +02:00
|
|
|
dhp->dh_name[0] = rq.r_nunits;
|
|
|
|
update_dcb(dhp);
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
2001-04-15 05:21:50 +02:00
|
|
|
|
2001-04-22 00:32:53 +02:00
|
|
|
if (dhp->dh_attr & ATTR_CONIN)
|
2003-06-15 17:53:58 +02:00
|
|
|
LoL->syscon = dhp;
|
2001-04-22 00:32:53 +02:00
|
|
|
else if (dhp->dh_attr & ATTR_CLOCK)
|
2003-06-15 17:53:58 +02:00
|
|
|
LoL->clock = dhp;
|
2001-04-22 00:32:53 +02:00
|
|
|
|
2000-05-26 21:25:19 +02:00
|
|
|
return FALSE;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
|
2002-01-23 23:29:41 +01:00
|
|
|
STATIC void InitIO(void)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2003-06-20 21:54:18 +02:00
|
|
|
struct dhdr far *device = &LoL->nul_dev;
|
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
/* Initialize driver chain */
|
|
|
|
setvec(0x29, int29_handler); /* Requires Fast Con Driver */
|
2003-06-20 21:54:18 +02:00
|
|
|
do {
|
|
|
|
init_device(device, NULL, NULL, lpTop);
|
|
|
|
device = device->dh_next;
|
|
|
|
}
|
|
|
|
while (FP_OFF(device) != 0xffff);
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
|
2001-04-22 00:32:53 +02:00
|
|
|
/* issue an internal error message */
|
|
|
|
VOID init_fatal(BYTE * err_msg)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2001-04-22 00:32:53 +02:00
|
|
|
printf("\nInternal kernel error - %s\nSystem halted\n", err_msg);
|
|
|
|
for (;;) ;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
2001-09-23 22:39:44 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Initialize all printers
|
|
|
|
|
|
|
|
this should work. IMHO, this might also be done on first use
|
|
|
|
of printer, as I never liked the noise by a resetting printer, and
|
|
|
|
I usually much more often reset my system, then I print :-)
|
|
|
|
*/
|
|
|
|
|
2002-01-23 23:29:41 +01:00
|
|
|
STATIC VOID InitPrinters(VOID)
|
2001-09-23 22:39:44 +02:00
|
|
|
{
|
2001-11-18 15:01:12 +01:00
|
|
|
iregs r;
|
|
|
|
int num_printers, i;
|
2001-09-23 22:39:44 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
init_call_intr(0x11, &r); /* get equipment list */
|
2001-09-23 22:39:44 +02:00
|
|
|
|
2001-11-18 15:01:12 +01:00
|
|
|
num_printers = (r.a.x >> 14) & 3; /* bits 15-14 */
|
|
|
|
|
|
|
|
for (i = 0; i < num_printers; i++)
|
|
|
|
{
|
|
|
|
r.a.x = 0x0100; /* initialize printer */
|
|
|
|
r.d.x = i;
|
|
|
|
init_call_intr(0x17, &r);
|
|
|
|
}
|
2001-09-23 22:39:44 +02:00
|
|
|
}
|
|
|
|
|
2003-06-15 16:38:13 +02:00
|
|
|
/*****************************************************************
|
|
|
|
if kernel.config.BootHarddiskSeconds is set,
|
|
|
|
the default is to boot from harddisk, because
|
|
|
|
the user is assumed to just have forgotten to
|
|
|
|
remove the floppy/bootable CD from the drive.
|
|
|
|
|
|
|
|
user has some seconds to hit ANY key to continue
|
|
|
|
to boot from floppy/cd, else the system is
|
|
|
|
booted from HD
|
|
|
|
*/
|
|
|
|
|
|
|
|
EmulatedDriveStatus(int drive,char statusOnly)
|
|
|
|
{
|
|
|
|
iregs r;
|
2003-07-15 14:32:35 +02:00
|
|
|
char buffer[0x13];
|
2003-06-15 16:38:13 +02:00
|
|
|
buffer[0] = 0x13;
|
|
|
|
|
|
|
|
r.a.b.h = 0x4b; /* bootable CDROM - get status */
|
|
|
|
r.a.b.l = statusOnly;
|
|
|
|
r.d.b.l = (char)drive;
|
|
|
|
r.si = (int)buffer;
|
|
|
|
init_call_intr(0x13, &r);
|
|
|
|
|
|
|
|
if (r.flags & 1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-06-20 21:54:18 +02:00
|
|
|
STATIC void CheckContinueBootFromHarddisk(void)
|
2003-06-15 16:38:13 +02:00
|
|
|
{
|
2003-06-17 13:55:44 +02:00
|
|
|
char *bootedFrom = "Floppy/CD";
|
2003-06-15 16:38:13 +02:00
|
|
|
iregs r;
|
2003-06-17 13:55:44 +02:00
|
|
|
int key;
|
|
|
|
|
2003-06-15 16:38:13 +02:00
|
|
|
if (InitKernelConfig.BootHarddiskSeconds == 0)
|
|
|
|
return;
|
|
|
|
|
2003-06-15 17:53:58 +02:00
|
|
|
if (LoL->BootDrive >= 3)
|
2003-06-15 16:38:13 +02:00
|
|
|
{
|
2003-07-15 14:32:35 +02:00
|
|
|
#if 0
|
2003-06-15 16:38:13 +02:00
|
|
|
if (!EmulatedDriveStatus(0x80,1))
|
2003-07-15 14:32:35 +02:00
|
|
|
#endif
|
2003-06-15 16:38:13 +02:00
|
|
|
{
|
|
|
|
/* already booted from HD */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2003-07-15 14:32:35 +02:00
|
|
|
#if 0
|
2003-06-15 16:38:13 +02:00
|
|
|
if (!EmulatedDriveStatus(0x00,1))
|
2003-07-15 14:32:35 +02:00
|
|
|
#endif
|
2003-06-15 16:38:13 +02:00
|
|
|
bootedFrom = "Floppy";
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n"
|
|
|
|
"\n"
|
|
|
|
"\n"
|
|
|
|
" Hit any key within %d seconds to continue booot from %s\n"
|
2003-06-17 13:55:44 +02:00
|
|
|
" Hit 'H' or wait %d seconds to boot from Harddisk\n",
|
2003-06-15 16:38:13 +02:00
|
|
|
InitKernelConfig.BootHarddiskSeconds,
|
2003-06-17 13:55:44 +02:00
|
|
|
bootedFrom,
|
|
|
|
InitKernelConfig.BootHarddiskSeconds
|
2003-06-15 16:38:13 +02:00
|
|
|
);
|
|
|
|
|
2003-06-17 13:55:44 +02:00
|
|
|
key = GetBiosKey(InitKernelConfig.BootHarddiskSeconds);
|
|
|
|
|
2003-06-18 21:27:40 +02:00
|
|
|
if (key != -1 && (key & 0xff) != 'h' && (key & 0xff) != 'H')
|
2003-06-15 16:38:13 +02:00
|
|
|
{
|
|
|
|
/* user has hit a key, continue to boot from floppy/CD */
|
|
|
|
printf("\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reboot from harddisk */
|
|
|
|
EmulatedDriveStatus(0x00,0);
|
|
|
|
EmulatedDriveStatus(0x80,0);
|
|
|
|
|
|
|
|
/* now jump and run */
|
|
|
|
r.a.x = 0x0201;
|
|
|
|
r.c.x = 0x0001;
|
|
|
|
r.d.x = 0x0080;
|
|
|
|
r.b.x = 0x7c00;
|
|
|
|
r.es = 0;
|
|
|
|
|
|
|
|
init_call_intr(0x13, &r);
|
|
|
|
|
|
|
|
{
|
2003-06-16 00:58:29 +02:00
|
|
|
void (far *reboot)(void) = (void (far*)(void)) MK_FP(0x0,0x7c00);
|
2003-06-15 16:38:13 +02:00
|
|
|
|
|
|
|
(*reboot)();
|
|
|
|
}
|
|
|
|
}
|