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, */
|
|
|
|
/* write to the Free Software Foundation, 675 Mass Ave, */
|
|
|
|
/* Cambridge, MA 02139, USA. */
|
|
|
|
/****************************************************************/
|
|
|
|
|
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"
|
|
|
|
#include "init-dat.h"
|
|
|
|
|
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-04-22 00:32:53 +02:00
|
|
|
/*
|
|
|
|
These are the far variables from the DOS data segment that we need here. The
|
|
|
|
init procedure uses a different default DS data segment, which is discarded
|
|
|
|
after use. I hope to clean this up to use the DOS List of List and Swappable
|
|
|
|
Data Area obtained via INT21.
|
|
|
|
|
|
|
|
-- Bart
|
|
|
|
*/
|
2001-09-23 22:39:44 +02:00
|
|
|
extern UBYTE DOSFAR nblkdev,
|
|
|
|
DOSFAR lastdrive; /* value of last drive */
|
2001-04-22 00:32:53 +02:00
|
|
|
|
|
|
|
GLOBAL BYTE
|
2001-09-23 22:39:44 +02:00
|
|
|
DOSFAR os_major, /* major version number */
|
|
|
|
DOSFAR os_minor, /* minor version number */
|
|
|
|
DOSFAR dosidle_flag,
|
|
|
|
DOSFAR BootDrive, /* Drive we came up from */
|
|
|
|
DOSFAR default_drive; /* default drive for dos */
|
|
|
|
|
|
|
|
GLOBAL BYTE DOSFAR os_release[];
|
|
|
|
GLOBAL BYTE DOSFAR copyright[];
|
|
|
|
GLOBAL seg DOSFAR RootPsp; /* Root process -- do not abort */
|
|
|
|
|
|
|
|
extern struct dpb FAR * DOSFAR DPBp; /* First drive Parameter Block */
|
|
|
|
extern cdstbl FAR * DOSFAR CDSp; /* Current Directory Structure */
|
|
|
|
|
|
|
|
extern struct dhdr FAR * DOSFAR clock, /* CLOCK$ device */
|
|
|
|
FAR * DOSFAR syscon; /* console device */
|
|
|
|
extern struct dhdr DOSTEXTFAR con_dev, /* console device drive */
|
|
|
|
DOSTEXTFAR clk_dev, /* Clock device driver */
|
|
|
|
DOSTEXTFAR blk_dev; /* Block device (Disk) driver */
|
2001-04-22 00:32:53 +02:00
|
|
|
extern UWORD
|
2001-09-23 22:39:44 +02:00
|
|
|
DOSFAR ram_top; /* How much ram in Kbytes */
|
|
|
|
extern iregs FAR * DOSFAR user_r; /* User registers for int 21h call */
|
2001-07-28 20:13:06 +02:00
|
|
|
extern BYTE FAR _HMATextEnd[];
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
#ifdef VERSION_STRINGS
|
|
|
|
static BYTE *mainRcsId = "$Id$";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* $Log$
|
2001-09-23 22:39:44 +02:00
|
|
|
* Revision 1.21 2001/09/23 20:39:44 bartoldeman
|
|
|
|
* FAT32 support, misc fixes, INT2F/AH=12 support, drive B: handling
|
|
|
|
*
|
2001-07-28 20:13:06 +02:00
|
|
|
* Revision 1.20 2001/07/28 18:13:06 bartoldeman
|
|
|
|
* Fixes for FORMAT+SYS, FATFS, get current dir, kernel init memory situation.
|
|
|
|
*
|
2001-07-22 03:58:58 +02:00
|
|
|
* Revision 1.19 2001/07/22 01:58:58 bartoldeman
|
|
|
|
* Support for Brian's FORMAT, DJGPP libc compilation, cleanups, MSCDEX
|
|
|
|
*
|
2001-07-10 00:19:33 +02:00
|
|
|
* Revision 1.18 2001/07/09 22:19:33 bartoldeman
|
|
|
|
* LBA/FCB/FAT/SYS/Ctrl-C/ioctl fixes + memory savings
|
|
|
|
*
|
2001-06-03 16:16:18 +02:00
|
|
|
* Revision 1.17 2001/06/03 14:16:18 bartoldeman
|
|
|
|
* BUFFERS tuning and misc bug fixes/cleanups (2024c).
|
|
|
|
*
|
2001-04-29 19:34:41 +02:00
|
|
|
* Revision 1.16 2001/04/29 17:34:40 bartoldeman
|
|
|
|
* A new SYS.COM/config.sys single stepping/console output/misc fixes.
|
|
|
|
*
|
2001-04-22 00:32:53 +02:00
|
|
|
* Revision 1.15 2001/04/21 22:32:53 bartoldeman
|
|
|
|
* Init DS=Init CS, fixed stack overflow problems and misc bugs.
|
|
|
|
*
|
2001-04-16 03:45:26 +02:00
|
|
|
* Revision 1.14 2001/04/16 01:45:26 bartoldeman
|
|
|
|
* Fixed handles, config.sys drivers, warnings. Enabled INT21/AH=6C, printf %S/%Fs
|
|
|
|
*
|
2001-04-15 05:21:50 +02:00
|
|
|
* Revision 1.13 2001/04/15 03:21:50 bartoldeman
|
|
|
|
* See history.txt for the list of fixes.
|
|
|
|
*
|
2001-03-31 00:27:42 +02:00
|
|
|
* Revision 1.12 2001/03/30 22:27:42 bartoldeman
|
|
|
|
* Saner lastdrive handling.
|
2001-03-30 22:11:14 +02:00
|
|
|
*
|
2001-03-30 21:30:06 +02:00
|
|
|
* Revision 1.10 2001/03/30 19:30:06 bartoldeman
|
|
|
|
* Misc fixes and implementation of SHELLHIGH. See history.txt for details.
|
|
|
|
*
|
2001-03-25 19:11:54 +02:00
|
|
|
* Revision 1.9 2001/03/25 17:11:54 bartoldeman
|
|
|
|
* Fixed sys.com compilation. Updated to 2023. Also: see history.txt.
|
|
|
|
*
|
2001-03-21 03:56:26 +01:00
|
|
|
* Revision 1.8 2001/03/21 02:56:26 bartoldeman
|
|
|
|
* See history.txt for changes. Bug fixes and HMA support are the main ones.
|
|
|
|
*
|
2000-08-06 07:50:17 +02:00
|
|
|
* Revision 1.7 2000/08/06 05:50:17 jimtabor
|
|
|
|
* Add new files and update cvs with patches and changes
|
|
|
|
*
|
2000-06-21 20:16:46 +02:00
|
|
|
* Revision 1.6 2000/06/21 18:16:46 jimtabor
|
|
|
|
* Add UMB code, patch, and code fixes
|
|
|
|
*
|
2000-05-26 21:25:19 +02:00
|
|
|
* Revision 1.5 2000/05/26 19:25:19 jimtabor
|
|
|
|
* Read History file for Change info
|
|
|
|
*
|
2000-05-25 22:56:23 +02:00
|
|
|
* Revision 1.4 2000/05/25 20:56:21 jimtabor
|
|
|
|
* Fixed project history
|
|
|
|
*
|
2000-05-17 21:15:12 +02:00
|
|
|
* Revision 1.3 2000/05/17 19:15:12 jimtabor
|
|
|
|
* Cleanup, add and fix source.
|
|
|
|
*
|
2000-05-08 06:30:00 +02:00
|
|
|
* Revision 1.2 2000/05/08 04:30:00 jimtabor
|
|
|
|
* Update CVS to 2020
|
|
|
|
*
|
2000-05-25 22:56:23 +02:00
|
|
|
* Revision 1.1.1.1 2000/05/06 19:34:53 jhall1
|
|
|
|
* The FreeDOS Kernel. A DOS kernel that aims to be 100% compatible with
|
|
|
|
* MS-DOS. Distributed under the GNU GPL.
|
2000-05-17 21:15:12 +02:00
|
|
|
*
|
2000-05-08 06:30:00 +02:00
|
|
|
* Revision 1.14 2000/03/31 05:40:09 jtabor
|
|
|
|
* Added Eric W. Biederman Patches
|
2000-05-06 21:34:20 +02:00
|
|
|
*
|
|
|
|
* Revision 1.13 2000/03/09 06:07:11 kernel
|
|
|
|
* 2017f updates by James Tabor
|
|
|
|
*
|
|
|
|
* Revision 1.12 1999/09/23 04:40:48 jprice
|
|
|
|
* *** empty log message ***
|
|
|
|
*
|
|
|
|
* Revision 1.10 1999/08/25 03:18:09 jprice
|
|
|
|
* ror4 patches to allow TC 2.01 compile.
|
|
|
|
*
|
|
|
|
* Revision 1.9 1999/04/16 21:43:40 jprice
|
|
|
|
* ror4 multi-sector IO
|
|
|
|
*
|
|
|
|
* Revision 1.8 1999/04/16 12:21:22 jprice
|
|
|
|
* Steffen c-break handler changes
|
|
|
|
*
|
|
|
|
* Revision 1.7 1999/04/16 00:53:33 jprice
|
|
|
|
* Optimized FAT handling
|
|
|
|
*
|
|
|
|
* Revision 1.6 1999/04/12 03:21:17 jprice
|
|
|
|
* more ror4 patches. Changes for multi-block IO
|
|
|
|
*
|
|
|
|
* Revision 1.5 1999/04/11 04:33:39 jprice
|
|
|
|
* ror4 patches
|
|
|
|
*
|
|
|
|
* Revision 1.3 1999/04/04 22:57:47 jprice
|
|
|
|
* no message
|
|
|
|
*
|
|
|
|
* Revision 1.2 1999/04/04 18:51:43 jprice
|
|
|
|
* no message
|
|
|
|
*
|
|
|
|
* Revision 1.1.1.1 1999/03/29 15:41:18 jprice
|
|
|
|
* New version without IPL.SYS
|
|
|
|
*
|
|
|
|
* Revision 1.5 1999/02/08 05:55:57 jprice
|
|
|
|
* Added Pat's 1937 kernel patches
|
|
|
|
*
|
|
|
|
* Revision 1.4 1999/02/01 01:48:41 jprice
|
|
|
|
* Clean up; Now you can use hex numbers in config.sys. added config.sys screen function to change screen mode (28 or 43/50 lines)
|
|
|
|
*
|
|
|
|
* Revision 1.3 1999/01/30 08:28:12 jprice
|
|
|
|
* Clean up; Fixed bug with set attribute function.
|
|
|
|
*
|
|
|
|
* Revision 1.2 1999/01/22 04:13:26 jprice
|
|
|
|
* Formating
|
|
|
|
*
|
|
|
|
* Revision 1.1.1.1 1999/01/20 05:51:01 jprice
|
|
|
|
* Imported sources
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Rev 1.12 06 Dec 1998 8:45:30 patv
|
|
|
|
* Changed due to new I/O subsystem.
|
|
|
|
*
|
|
|
|
* Rev 1.11 22 Jan 1998 4:09:24 patv
|
|
|
|
* Fixed pointer problems affecting SDA
|
|
|
|
*
|
|
|
|
* Rev 1.10 04 Jan 1998 23:15:20 patv
|
|
|
|
* Changed Log for strip utility
|
|
|
|
*
|
|
|
|
* Rev 1.9 04 Jan 1998 17:26:16 patv
|
|
|
|
* Corrected subdirectory bug
|
|
|
|
*
|
|
|
|
* Rev 1.8 03 Jan 1998 8:36:48 patv
|
|
|
|
* Converted data area to SDA format
|
|
|
|
*
|
|
|
|
* Rev 1.7 06 Feb 1997 21:35:46 patv
|
|
|
|
* Modified to support new version format and changed debug message to
|
|
|
|
* output drive letter instead of number.
|
|
|
|
*
|
|
|
|
* Rev 1.6 22 Jan 1997 13:05:02 patv
|
|
|
|
* Now does correct default drive initialization.
|
|
|
|
*
|
|
|
|
* Rev 1.5 16 Jan 1997 12:47:00 patv
|
|
|
|
* pre-Release 0.92 feature additions
|
|
|
|
*
|
|
|
|
* Rev 1.3 29 May 1996 21:03:32 patv
|
|
|
|
* bug fixes for v0.91a
|
|
|
|
*
|
|
|
|
* Rev 1.2 19 Feb 1996 3:21:36 patv
|
|
|
|
* Added NLS, int2f and config.sys processing
|
|
|
|
*
|
|
|
|
* Rev 1.1 01 Sep 1995 17:54:18 patv
|
|
|
|
* First GPL release.
|
|
|
|
*
|
|
|
|
* Rev 1.0 02 Jul 1995 8:33:18 patv
|
|
|
|
* Initial revision.
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern WORD days[2][13];
|
2000-06-21 20:16:46 +02:00
|
|
|
extern BYTE FAR * lpBase;
|
2001-07-28 20:13:06 +02:00
|
|
|
extern BYTE FAR * lpOldTop;
|
|
|
|
extern BYTE FAR * lpTop;
|
2000-06-21 20:16:46 +02:00
|
|
|
extern BYTE FAR * upBase;
|
2001-07-28 20:13:06 +02:00
|
|
|
extern BYTE _ib_start[], _ib_end[], _init_end[];
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
INIT VOID configDone(VOID);
|
|
|
|
INIT static void InitIO(void);
|
|
|
|
|
2001-04-15 05:21:50 +02:00
|
|
|
INIT static VOID update_dcb(struct dhdr FAR *);
|
2000-05-06 21:34:20 +02:00
|
|
|
INIT static VOID init_kernel(VOID);
|
|
|
|
INIT static VOID signon(VOID);
|
|
|
|
INIT VOID kernel(VOID);
|
|
|
|
INIT VOID FsConfig(VOID);
|
2001-09-23 22:39:44 +02:00
|
|
|
INIT VOID InitPrinters(VOID);
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
BYTE _acrtused = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
__segment DosDataSeg = 0; /* serves for all references to the DOS DATA segment
|
|
|
|
necessary for MSC+our funny linking model
|
|
|
|
*/
|
|
|
|
__segment DosTextSeg = 0;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-09-23 22:39:44 +02:00
|
|
|
INIT VOID ASMCFUNC FreeDOSmain(void)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2001-09-23 22:39:44 +02:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
extern FAR DATASTART;
|
|
|
|
extern FAR prn_dev;
|
|
|
|
DosDataSeg = (__segment)&DATASTART;
|
|
|
|
DosTextSeg = (__segment)&prn_dev;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-03-30 21:30:06 +02:00
|
|
|
setvec(0, int0_handler); /* zero divide */
|
2001-03-21 03:56:26 +01:00
|
|
|
setvec(1, empty_handler); /* single step */
|
|
|
|
setvec(3, empty_handler); /* debug breakpoint */
|
2001-04-22 00:32:53 +02:00
|
|
|
setvec(6, empty_handler); /* invalid opcode */
|
2001-03-21 03:56:26 +01:00
|
|
|
|
2001-04-22 00:32:53 +02:00
|
|
|
/* clear the Init BSS area (what normally the RTL does */
|
|
|
|
memset(_ib_start, 0, _ib_end - _ib_start);
|
2001-03-21 03:56:26 +01:00
|
|
|
|
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! */
|
|
|
|
printf("KERNEL: Boot drive = %c\n", 'A' + BootDrive - 1);
|
|
|
|
#endif
|
|
|
|
signon();
|
|
|
|
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";
|
|
|
|
int drive,fileno;
|
2001-04-22 00:32:53 +02:00
|
|
|
for (drive = 'C'; drive < 'A'+nblkdev; drive++)
|
2001-03-30 21:30:06 +02:00
|
|
|
{
|
|
|
|
filename[0] = drive;
|
2001-04-22 00:32:53 +02:00
|
|
|
if ((fileno = open(filename, O_RDONLY)) >= 0)
|
|
|
|
close(fileno);
|
2001-03-30 21:30:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-21 03:56:26 +01:00
|
|
|
INIT void init_kernel(void)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
|
|
|
COUNT i;
|
2001-04-15 05:21:50 +02:00
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
os_major = MAJOR_RELEASE;
|
|
|
|
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 */
|
|
|
|
lpTop = MK_FP(ram_top * 64 - (FP_OFF(_init_end)+15)/16 -
|
|
|
|
(FP_OFF(_HMATextEnd)+15)/16, 0);
|
|
|
|
|
|
|
|
MoveKernel(FP_SEG(lpTop));
|
|
|
|
lpOldTop = lpTop = MK_FP(FP_SEG(lpTop) - 0xfff, 0xfff0);
|
|
|
|
|
2000-05-17 21:15:12 +02:00
|
|
|
/* Fake int 21h stack frame */
|
2001-09-23 22:39:44 +02:00
|
|
|
user_r = (iregs FAR *) MK_FP(DOS_PSP,0xD0);
|
2000-05-17 21:15:12 +02:00
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
#ifndef KDB
|
|
|
|
for (i = 0x20; i <= 0x3f; i++)
|
|
|
|
setvec(i, empty_handler);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Initialize IO subsystem */
|
|
|
|
InitIO();
|
2001-09-23 22:39:44 +02:00
|
|
|
InitPrinters();
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
#ifndef KDB
|
|
|
|
/* 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);
|
|
|
|
#endif
|
|
|
|
|
2001-06-03 16:16:18 +02:00
|
|
|
init_PSPSet(DOS_PSP);
|
2001-04-15 05:21:50 +02:00
|
|
|
init_PSPInit(DOS_PSP);
|
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
/* Do first initialization of system variable buffers so that */
|
|
|
|
/* we can read config.sys later. */
|
|
|
|
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)
|
|
|
|
update_dcb(&blk_dev);
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* Now config the temporary file system */
|
|
|
|
FsConfig();
|
|
|
|
|
|
|
|
#ifndef KDB
|
|
|
|
/* Now process CONFIG.SYS */
|
|
|
|
DoConfig();
|
2001-04-16 03:45:26 +02:00
|
|
|
|
|
|
|
/* Close all (device) files */
|
|
|
|
for (i = 0; i < lastdrive; i++)
|
2001-04-22 00:32:53 +02:00
|
|
|
close(i);
|
2001-04-16 03:45:26 +02:00
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
/* and do final buffer allocation. */
|
|
|
|
PostConfig();
|
2001-04-15 05:21:50 +02:00
|
|
|
nblkdev = 0;
|
|
|
|
update_dcb(&blk_dev);
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-04-15 05:21:50 +02:00
|
|
|
/* Init the file system one more time */
|
2000-05-06 21:34:20 +02:00
|
|
|
FsConfig();
|
|
|
|
|
|
|
|
/* and process CONFIG.SYS one last time to load device drivers. */
|
|
|
|
DoConfig();
|
|
|
|
configDone();
|
2000-05-08 06:30:00 +02:00
|
|
|
|
2001-04-16 03:45:26 +02:00
|
|
|
/* Close all (device) files */
|
|
|
|
for (i = 0; i < lastdrive; i++)
|
2001-04-22 00:32:53 +02:00
|
|
|
close(i);
|
2001-04-16 03:45:26 +02:00
|
|
|
|
2000-05-08 06:30:00 +02:00
|
|
|
/* Now config the final file system */
|
|
|
|
FsConfig();
|
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
#endif
|
2001-04-22 00:32:53 +02:00
|
|
|
InitializeAllBPBs();
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
INIT VOID FsConfig(VOID)
|
|
|
|
{
|
|
|
|
REG COUNT i;
|
2001-04-15 05:21:50 +02:00
|
|
|
struct dpb FAR *dpb;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* The system file tables need special handling and are "hand */
|
2001-04-22 00:32:53 +02:00
|
|
|
/* built. Included is the stdin, stdout, stdaux and stdprn. */
|
2001-04-29 19:34:41 +02:00
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
/* 0 is /dev/con (stdin) */
|
2001-04-22 00:32:53 +02:00
|
|
|
open("CON", O_RDWR);
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* 1 is /dev/con (stdout) */
|
2001-04-22 00:32:53 +02:00
|
|
|
dup2(STDIN, STDOUT);
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* 2 is /dev/con (stderr) */
|
2001-04-22 00:32:53 +02:00
|
|
|
dup2(STDIN, STDERR);
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* 3 is /dev/aux */
|
2001-04-22 00:32:53 +02:00
|
|
|
open("AUX", O_RDWR);
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* 4 is /dev/prn */
|
2001-04-22 00:32:53 +02:00
|
|
|
open("PRN", O_WRONLY);
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* Log-in the default drive. */
|
|
|
|
/* Get the boot drive from the ipl and use it for default. */
|
|
|
|
default_drive = BootDrive - 1;
|
2001-04-15 05:21:50 +02:00
|
|
|
dpb = DPBp;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-04-15 05:21:50 +02:00
|
|
|
/* Initialize the current directory structures */
|
2000-06-21 20:16:46 +02:00
|
|
|
for (i = 0; i < lastdrive ; i++)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2001-03-21 03:56:26 +01:00
|
|
|
struct cds FAR *pcds_table = &CDSp->cds_table[i];
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
fbcopy((VOID FAR *) "A:\\\0",
|
2001-03-21 03:56:26 +01:00
|
|
|
(VOID FAR *) pcds_table->cdsCurrentPath, 4);
|
|
|
|
|
|
|
|
pcds_table->cdsCurrentPath[0] += i;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-04-15 05:21:50 +02:00
|
|
|
if (i < 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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2001-03-21 03:56:26 +01:00
|
|
|
INIT VOID signon()
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2001-09-23 22:39:44 +02:00
|
|
|
printf("\n%S" ,(void FAR *)os_release);
|
|
|
|
|
|
|
|
printf("Kernel compatibility %d.%d",
|
|
|
|
os_major, os_minor );
|
|
|
|
|
|
|
|
#if defined(__TURBOC__)
|
|
|
|
printf(" - TURBOC");
|
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
printf(" - MSC");
|
|
|
|
#elif defined(__WATCOMC__)
|
|
|
|
printf(" - WATCOMC");
|
|
|
|
#else
|
|
|
|
generate some bullshit error here, as the compiler should be known
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined (I386)
|
|
|
|
printf(" - 80386 CPU required");
|
|
|
|
#elif defined (I186)
|
|
|
|
printf(" - 80186 CPU required");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WITHFAT32
|
|
|
|
printf(" - FAT32 support");
|
|
|
|
#endif
|
|
|
|
printf("\n\n%S",(void FAR *)copyright);
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
|
2001-03-21 03:56:26 +01:00
|
|
|
INIT void kernel()
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
2001-04-22 00:32:53 +02:00
|
|
|
#if 0
|
2000-05-06 21:34:20 +02:00
|
|
|
BYTE FAR *ep,
|
|
|
|
*sp;
|
2001-04-22 00:32:53 +02:00
|
|
|
#endif
|
|
|
|
exec_blk exb;
|
|
|
|
CommandTail Cmd;
|
|
|
|
int rc;
|
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
#ifndef KDB
|
2001-04-22 00:32:53 +02:00
|
|
|
static BYTE master_env[] = "PATH=.\0\0\0\0\0";
|
|
|
|
/* static BYTE *path = "PATH=.";*/
|
2000-05-06 21:34:20 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef KDB
|
|
|
|
kdb();
|
|
|
|
#else
|
2001-04-22 00:32:53 +02:00
|
|
|
#if 0
|
2000-05-06 21:34:20 +02:00
|
|
|
/* create the master environment area */
|
2001-04-22 00:32:53 +02:00
|
|
|
|
|
|
|
if (allocmem(0x2, &exb.exec.env_seg))
|
|
|
|
init_fatal("cannot allocate master environment space");
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
/* populate it with the minimum environment */
|
2001-04-22 00:32:53 +02:00
|
|
|
++exb.exec.env_seg;
|
|
|
|
ep = MK_FP(exb.exec.env_seg, 0);
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
for (sp = path; *sp != 0;)
|
|
|
|
*ep++ = *sp++;
|
|
|
|
|
|
|
|
*ep++ = '\0';
|
|
|
|
*ep++ = '\0';
|
|
|
|
*((int FAR *)ep) = 0;
|
|
|
|
ep += sizeof(int);
|
2001-04-22 00:32:53 +02:00
|
|
|
#else
|
|
|
|
exb.exec.env_seg = DOS_PSP+8;
|
|
|
|
fmemcpy(MK_FP(exb.exec.env_seg, 0), master_env, sizeof(master_env));
|
|
|
|
#endif
|
|
|
|
#endif
|
2001-04-29 19:34:41 +02:00
|
|
|
|
2001-04-22 00:32:53 +02:00
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
RootPsp = ~0;
|
2001-04-22 00:32:53 +02:00
|
|
|
|
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 */
|
2001-04-29 19:34:41 +02:00
|
|
|
fstrncpy(Cmd.ctBuffer, Config.cfgInitTail,
|
|
|
|
sizeof(Config.cfgInitTail)-1);
|
2001-04-22 00:32:53 +02:00
|
|
|
|
|
|
|
for (Cmd.ctCount = 0; Cmd.ctCount < 127; Cmd.ctCount++)
|
|
|
|
if (Cmd.ctBuffer[Cmd.ctCount] == '\r')
|
|
|
|
break;
|
|
|
|
|
2001-04-29 19:34:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* if stepping CONFIG.SYS (F5/F8), tell COMMAND.COM about it */
|
|
|
|
|
|
|
|
if (Cmd.ctCount < 127 - 3)
|
|
|
|
{
|
|
|
|
extern int singleStep ;
|
|
|
|
extern int SkipAllConfig;
|
|
|
|
char *insertString = NULL;
|
|
|
|
|
|
|
|
if (singleStep) insertString = " /Y"; /* single step AUTOEXEC */
|
|
|
|
|
|
|
|
if (SkipAllConfig) insertString = " /D"; /* disable AUTOEXEC */
|
|
|
|
|
|
|
|
if (insertString)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* insert /D, /Y as first argument */
|
|
|
|
int cmdEnd,i,slen = strlen(insertString);
|
|
|
|
|
|
|
|
for (cmdEnd = 0;cmdEnd < 127; cmdEnd++)
|
|
|
|
{
|
|
|
|
if (Cmd.ctBuffer[cmdEnd] == ' ' ||
|
|
|
|
Cmd.ctBuffer[cmdEnd] == '\t' ||
|
|
|
|
Cmd.ctBuffer[cmdEnd] == '\r')
|
|
|
|
{
|
|
|
|
for (i = 127 - slen; i >= cmdEnd; i--)
|
|
|
|
Cmd.ctBuffer[i+slen] = Cmd.ctBuffer[i];
|
|
|
|
|
|
|
|
fmemcpy(&Cmd.ctBuffer[cmdEnd], insertString,slen);
|
|
|
|
|
|
|
|
Cmd.ctCount += slen;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-04-22 00:32:53 +02:00
|
|
|
exb.exec.cmd_line = (CommandTail FAR *) & Cmd;
|
|
|
|
exb.exec.fcb_1 = exb.exec.fcb_2 = (fcb FAR *) 0;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("Process 0 starting: %s\n\n", Config.cfgInit);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
while ((rc = init_DosExec(Config.cfgP_0_startmode, &exb, Config.cfgInit)) != SUCCESS)
|
|
|
|
{
|
|
|
|
BYTE *pLine;
|
2001-04-29 19:34:41 +02:00
|
|
|
printf("\nBad or missing Command Interpreter: %d - %s\n", rc, Cmd.ctBuffer);
|
2001-04-22 00:32:53 +02:00
|
|
|
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';
|
|
|
|
|
|
|
|
/* 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");
|
|
|
|
|
|
|
|
Cmd.ctCount = rc-(pLine-Cmd.ctBuffer);
|
|
|
|
|
|
|
|
#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 */
|
|
|
|
static VOID update_dcb(struct dhdr FAR * dhp)
|
|
|
|
{
|
|
|
|
REG COUNT Index;
|
|
|
|
COUNT nunits = dhp->dh_name[0];
|
|
|
|
struct dpb FAR *dpb;
|
|
|
|
|
|
|
|
if (nblkdev==0)
|
|
|
|
dpb = DPBp;
|
|
|
|
else {
|
|
|
|
for (dpb = DPBp; (ULONG)dpb->dpb_next != 0xffffffffl; dpb = dpb->dpb_next)
|
|
|
|
;
|
|
|
|
dpb = dpb->dpb_next = (struct dpb FAR *)KernelAlloc(nunits*sizeof(struct dpb));
|
|
|
|
}
|
|
|
|
|
|
|
|
for(Index = 0; Index < nunits; Index++)
|
|
|
|
{
|
|
|
|
dpb->dpb_next = dpb+1;
|
|
|
|
dpb->dpb_unit = nblkdev;
|
|
|
|
dpb->dpb_subunit = Index;
|
|
|
|
dpb->dpb_device = dhp;
|
|
|
|
dpb->dpb_flags = M_CHANGED;
|
|
|
|
if ((CDSp != 0) && (nblkdev < lastdrive))
|
|
|
|
{
|
|
|
|
CDSp->cds_table[nblkdev].cdsDpb = dpb;
|
|
|
|
CDSp->cds_table[nblkdev].cdsFlags = CDSPHYSDRV;
|
|
|
|
}
|
|
|
|
++dpb;
|
|
|
|
++nblkdev;
|
|
|
|
}
|
|
|
|
(dpb-1)->dpb_next = (void FAR *)0xFFFFFFFFl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
/* If cmdLine is NULL, this is an internal driver */
|
|
|
|
|
2000-06-21 20:16:46 +02:00
|
|
|
BOOL init_device(struct dhdr FAR * dhp, BYTE FAR * cmdLine, COUNT mode, COUNT r_top)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
|
|
|
request rq;
|
2000-06-21 20:16:46 +02:00
|
|
|
|
2001-04-15 05:21:50 +02:00
|
|
|
UCOUNT maxmem = ((UCOUNT)r_top << 6) - FP_SEG(dhp);
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-04-15 05:21:50 +02:00
|
|
|
if (maxmem >= 0x1000)
|
2000-05-06 21:34:20 +02:00
|
|
|
maxmem = 0xFFFF;
|
2001-04-15 05:21:50 +02:00
|
|
|
else
|
|
|
|
maxmem <<= 4;
|
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);
|
|
|
|
rq.r_endaddr = MK_FP(FP_SEG(dhp), maxmem);
|
|
|
|
rq.r_bpbptr = (void FAR *)(cmdLine ? cmdLine : "\n");
|
|
|
|
rq.r_firstunit = nblkdev;
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
if (rq.r_status & S_ERROR)
|
|
|
|
return TRUE;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2000-06-21 20:16:46 +02:00
|
|
|
if(cmdLine){
|
|
|
|
if (mode)
|
2001-04-16 03:45:26 +02:00
|
|
|
{
|
|
|
|
/* Don't link in device drivers which do not take up memory */
|
|
|
|
if (rq.r_endaddr == (BYTE FAR *)dhp)
|
|
|
|
return TRUE;
|
|
|
|
else
|
2000-06-21 20:16:46 +02:00
|
|
|
upBase = rq.r_endaddr;
|
2001-04-16 03:45:26 +02:00
|
|
|
}
|
2000-06-21 20:16:46 +02:00
|
|
|
else
|
2001-04-16 03:45:26 +02:00
|
|
|
{
|
|
|
|
if (rq.r_endaddr == (BYTE FAR *)dhp)
|
|
|
|
return TRUE;
|
|
|
|
else
|
2000-06-21 20:16:46 +02:00
|
|
|
lpBase = rq.r_endaddr;
|
|
|
|
}
|
2001-04-16 03:45:26 +02:00
|
|
|
}
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2001-04-15 05:21:50 +02:00
|
|
|
if (!(dhp->dh_attr & ATTR_CHAR) && (rq.r_nunits != 0)) {
|
|
|
|
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)
|
|
|
|
syscon = dhp;
|
|
|
|
else if (dhp->dh_attr & ATTR_CLOCK)
|
|
|
|
clock = dhp;
|
|
|
|
|
2000-05-26 21:25:19 +02:00
|
|
|
return FALSE;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INIT static void InitIO(void)
|
|
|
|
{
|
|
|
|
/* Initialize driver chain */
|
2001-03-21 03:56:26 +01:00
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
setvec(0x29, int29_handler); /* Requires Fast Con Driver */
|
2001-04-22 00:32:53 +02:00
|
|
|
init_device(&con_dev, NULL, NULL, ram_top);
|
|
|
|
init_device(&clk_dev, NULL, NULL, ram_top);
|
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 :-)
|
|
|
|
*/
|
|
|
|
|
|
|
|
INIT VOID InitPrinters(VOID)
|
|
|
|
{
|
|
|
|
iregs r;
|
|
|
|
int num_printers,i;
|
|
|
|
|
|
|
|
init_call_intr(0x11,&r); /* get equipment list */
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|