DOS如何将程序加载到内存中? [英] How does DOS load a program into memory?

查看:187
本文介绍了DOS如何将程序加载到内存中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MS-DOS采取什么步骤将COM或EXE文件加载到内存中?网上仍然有关于这种情况的参考吗?我能想到的最好的方法可能是指dosbox源代码。

What steps does MS-DOS take to load a COM or EXE file into memory? Are there still references online as to how this happens? The best I can think of is possibly referring to dosbox source.

推荐答案

当要求command.com执行.com或.exe文件,它将调用中断服务21h / AH = 4B,即EXEC服务。由调用程序决定:

When command.com is asked to execute a .com or .exe file, it will call the interrupt service 21h/AH=4B, the EXEC service. It is up to the calling program to:


  • 构建DOS EXEC参数块(请参阅 http://www.delorie.com/djgpp/doc/rbinter/it/90/15.html
    (包括有关环境变量,命令行参数,FCB和返回时寄存器值的信息)

  • 释放调用程序未使用的所有内存

  • 设置调用参数寄存器


    • ah = 4Bh( EXEC服务类型)

    • al = 00h(加载并执行功能)

    • ds:dx->程序名称

    • es:bx-> ptr到exec参数块

    • build a DOS EXEC parameter block (see http://www.delorie.com/djgpp/doc/rbinter/it/90/15.html ) (includes information on environment variables, command lines arguments, FCBs and register values on return)
    • free up all memory the calling program isn't using
    • setup calling argument registers
      • ah = 4Bh ('EXEC' service type)
      • al = 00h ('load and execute' function)
      • ds:dx -> program name
      • es:bx -> ptr to exec parameter block

      在调用中断21h时(这对我来说是朦胧的):

      When interrupt 21h is called (here's where it gets hazy for me):


      • 分配了一个页面对齐的内存块

      • 文件扩展名被忽略,inste广告DOS将检查文件的前两个字节
        是否为签名 MZ或 ZM(如果是EXE),并且没有COM的签名。


      • 读取exe标头以获得初始寄存器值

      • 将exe代码复制到内存中

      • 重定位表(请参见 http: //en.wikipedia.org/wiki/Relocation_table ),并在内存中调整
        远指针

      • 设置寄存器值

        • exe header is read for initial register values
        • copy code section from exe into memory
        • relocation table (see http://en.wikipedia.org/wiki/Relocation_table) is read and far pointers are adjusted in memory
        • setup register values
          • AL,AH drive letter status
          • DS,ES -> PSP segment (see http://en.wikipedia.org/wiki/Program_Segment_Prefix )
          • SS:SP -> stack pointer (defined in exe header)

          com:


          • 将整个.com文件复制到内存中

          • 设置寄存器值


            • AL,AH驱动器盘符状态

            • CS,DS,ES,SS-> PSP段

            • SP =前64k段中可用的最后一个字的偏移量

            • copy entire .com file into memory
            • setup register values
              • AL,AH drive letter status
              • CS,DS,ES,SS -> PSP segment
              • SP = offset of last word available in first 64k segment

              程序现在应该正在执行。

              Program should now be executing.

              注意:

              在Microsoft的KB文档中查找可执行文件的优先级,它提到
              使用 MS-DOS EXEC函数(21h中断服务4Bh)来执行.com和.exe文件
              http://support.microsoft.com/kb/35284

              In Microsoft's KB document "Order of Precedence in Locating Executable Files", it mentions the use of "MS-DOS EXEC function (interrupt 21h service 4Bh)" for executing .com and .exe files http://support.microsoft.com/kb/35284

              所以我们可以在Int 21 / AH = 4Bh上查看拉尔夫·布朗的中断列表

              So we can look at Ralph Brown's Interrupt List on Int 21/AH=4Bh

              • http://www.cs.cmu.edu/~ralf/files.html
              • Int 21/AH=4Bh http://www.delorie.com/djgpp/doc/rbinter/id/51/29.html
              • Int 21/AH=4Bh http://www.ctyme.com/intr/rb-2939.htm

              以及使用示例:

              • Art of Assembly / 19.1.1.1 Load and Execute http://webster.cs.ucr.edu/AoA/DOS/ch19/CH19-1.html#HEADING1-10

              和dos exe标头格式:

              and the dos exe header format:

              • http://www.delorie.com/djgpp/doc/rbinter/it/94/15.html
              • http://www.delorie.com/djgpp/doc/exe/

              (这是基于谷歌搜索,所以请免费添加建议)

              (this is based off some googling, so please feel free to add suggestions)

              这篇关于DOS如何将程序加载到内存中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆