『楼 主』:
原创:DOS启动教学初步(四):COMMADN.COM模块
使用 LLM 解释/回答一下
COMMAND.COM是命令处理程序模块,为DOS的外壳。构成MS-DOS操作系统与用户之间的接口。它接受用户输入的DOS命令,进行解释并加以执行。该模块由3部分组成:
1、外壳初始化程序CMDINIT;
2、COMMAND.COM的暂驻内存模块CCPT;
3、COMMAND.COM的常驻内存模块CCPR;
在SYSINIT把COMMAND.COM读入主存后,就把系统的控制权交给了CMDINIT,自己随之被覆盖而消失。CMDINIT接过控制权后,要做如下3方面的工作:
1、设置DOS的有关中断向量;
2、检查有无AUTOEXEC.BAT,若有,调入并执行;
3、让COMMAND.COM暂驻模块投入运行,以等待用户键入的命令。
COMMAND.COM暂驻模块CCPT由SYSINIT初始化程序将其装入,并定位于主存储器的高端。该模块主要由4部分程序组成:A、命令接收及解释程序;B、内部命令程序;C、批命令处理程序;D、外部命令装入程序。
该模块负责接收并解释由用户键入的命令及其参数,若是内部命令,则调用此模块中的相应子程序执行;若是外部命令(用户应用程序等也相当于外部命令)。则使用INT 21H的4BH号功能(即EXEC功能),将外部命令读入并执行。
CCPT实际上被放在供用户程序使用的暂驻程序区的顶端,因此有可能发生这样的情形:CCPT被加载的用户程序所覆盖,这正是把它取名为暂驻模块的原因。之所以这样安排,主要是出自“尽量的给用户程序留出较大的内存空间”之故。但如果CCPT被用户程序覆盖,一旦用户程序运行完毕,DOS系统也就无法再去接收键盘命令,所以为了既能给用户提供大的内存空间,又能确保正常的系统运作,势必还需要COMMAND.COM常驻模块的支持。
COMMAND.COM常驻模块CCPR主要由一个检查并重新安装暂驻模块程序构成。在CCPT加载用户程序时,就把用户程序运行完毕后的返回点指向CCPR。因此在用户程序运行完毕后,常驻模块CCPR立即取得控制权。如果检查发现暂驻模块CCPT被覆盖,则就启动重新安装程序,把它从磁盘上再次装入暂驻程序区的顶端。要注意,这时当前磁盘驱动器必须是DOS系统盘,这样安装程序才会找到COMMAND.COM暂驻模块,顺利完成装入任务。
综上述,把COMMAND.COM模块分成两部分,各占一个主存区,一个暂驻,一个常驻,但它们却是完成DOS命令处理不可分割的整体:暂驻模块完成命令处理的主体工作,常驻模块确保系统的正常运行。这样安排的结果,为用户提供了一个尽可能大的主存空间。
COMMAND.COM is a command processor module and serves as the shell of DOS. It forms the interface between the MS-DOS operating system and the user. It accepts the DOS commands entered by the user, interprets them, and executes them. This module is composed of 3 parts:
1. Shell initialization program CMDINIT;
2. Temporarily resident memory module CCPT of COMMAND.COM;
3. Resident memory module CCPR of COMMAND.COM.
After SYSINIT reads COMMAND.COM into the main memory, it hands over the control of the system to CMDINIT and disappears by being overwritten. After taking over the control, CMDINIT has to do the following 3 aspects of work:
1. Set the relevant interrupt vectors of DOS;
2. Check if there is AUTOEXEC.BAT. If there is, load and execute it;
3. Make the temporarily resident module of COMMAND.COM start running to wait for the commands typed by the user.
The temporarily resident module CCPT of COMMAND.COM is loaded by the SYSINIT initialization program and located at the high end of the main memory. This module is mainly composed of 4 parts of programs: A. Command receiving and interpreting program; B. Internal command program; C. Batch command processing program; D. External command loading program.
This module is responsible for receiving and interpreting the commands and their parameters typed by the user. If it is an internal command, it calls the corresponding subroutine in this module to execute; if it is an external command (user applications, etc. are also equivalent to external commands), it uses the 4BH function of INT 21H (that is, the EXEC function) to read in and execute the external command.
CCPT is actually placed at the top of the temporarily resident program area for user programs to use. Therefore, there may be a situation where CCPT is overwritten by the loaded user program. This is the reason why it is named the temporarily resident module. The main reason for such an arrangement is mainly "to leave a larger memory space for user programs as much as possible". But if CCPT is overwritten by the user program, once the user program finishes running, the DOS system will no longer be able to receive keyboard commands. So in order to provide a large memory space for users and ensure the normal operation of the system, it is necessary to rely on the support of the resident memory module of COMMAND.COM.
The resident memory module CCPR of COMMAND.COM is mainly composed of a program that checks and reinstalls the temporarily resident module. When CCPT loads the user program, it points the return point after the user program finishes running to CCPR. Therefore, after the user program finishes running, the resident module CCPR immediately gains the control. If it is found that the temporarily resident module CCPT is overwritten, it starts the reinstallation program and loads it from the disk to the top of the temporarily resident program area again. It should be noted that the current disk drive must be the DOS system disk at this time, so that the installation program can find the temporarily resident module of COMMAND.COM and successfully complete the loading task.
In conclusion, the COMMAND.COM module is divided into two parts, each occupying one main memory area, one temporarily resident and one resident. But they are an inseparable whole for completing the DOS command processing: the temporarily resident module completes the main work of command processing, and the resident module ensures the normal operation of the system. The result of such an arrangement provides the user with as large a main memory space as possible.
|