关于《orange‘s一个操作系统的实现》中调用门部分的补充和纠正

在《orange‘s一个操作系统的实现》中书对调用门中参数复制一点一略而过,并没有对参数大小等做出解释!上网找了很久发现并没有太多这方面的描述于是自已动手实验了一下并查了80386指令手册得出如下结论:

经过实验发现:如果调用门是向32位代码段跳转时,那么调用门在用param count复制时以一个参数为双字大小进得复制,也是就要复制的参数大小为(param count)*4字节,如果调用门是向16位代码段跳转时,那么调用门在用param count复制时以一个参数为单字大小进得复制,也是就要复制的参数大小为(param count)*2字节。那么什么时候向32位代码段中跳转,什么时候向16位代码段中跳呢?这关系到门描述符中TYPE字段中的内容,如果TYPE字段的值为4则为16位门描述符用来向16位代码跳转,如果TYPE字段的值为c时则为32位门描述符,用来向32位代码段跳转!

在指令返回时本书中那副堆栈示意图旁边那段代码疑似有错误,因为RET 中的参数应与调用门中的(param count)就该是对应关系,也就是说如果是16位调用门跳转时返回时应用retf/ret  (param count)*2来返回,如果是32位调用门跳转时返回时就用retf/ret  (param count)*4,这样堆栈才能平衡!但那一小段代码竟用ret 3!

以下为参考资料和实验代码:


Changing Size of Call
When adding 32-bit gates to 16-bit procedures, it is important to consider
the number of parameters. The count field of the gate descriptor specifies
the size of the parameter string to copy from the current stack to the stack
of the more privileged procedure. The count field of a 16-bit gate specifies
the number of words to be copied, whereas the count field of a 32-bit gate
specifies the number of doublewords to be copied; therefore, the 16-bit
procedure must use an even number of words as parameters.

There are three ways to cause a 16-bit procedure to execute a 32-bit call:
1. Use a 16-bit call to a 32-bit interface procedure that then uses a
  32-bit call to invoke the intended target.
2. Bind the 16-bit call to a 32-bit call gate.
3. Modify the 16-bit procedure, inserting an operand-size prefix before
  the call, thereby changing it to a 32-bit call.
Likewise, there are three ways to cause a 32-bit procedure to execute a
16-bit call:
1.
Use a 32-bit call to a 32-bit interface procedure that then uses a
16-bit call to invoke the intended target.

 

2. Bind the 32-bit call to a 16-bit call gate.
3. Modify the 32-bit procedure, inserting an operand-size prefix before
  the call, thereby changing it to a 16-bit call. (Be certain that the
 return offset does not exceed 64K.)
Programmers can utilize any of the preceding methods to make a CALL in a
USE16 segment match the corresponding RET in a USE32 segment, or to make a
CALL in a USE32 segment match the corresponding RET in a USE16 segment.


以下为代码:

代码: 


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
orange's个操作系统实现》是一本关于操作系统实现的书籍,其第六章无法运行可能有以下几个原因。 首先,书的代码可能存在错误。编写代码时,一些细节的失误可能导致程序无法正确运行。这可能是作者在编写书籍时出现的问题,或者是影响到第六章的代码遗漏或错误。在实际操作,我们应该检查在书提供的代码并尝试找到错误。 第二,缺少必要的软件或工具。在开发操作系统时,通常需要使用一些特定的软件和工具,例如汇编器、编译器、链接器等。如果这些软件或工具没有正确安装或配置,可能会导致第六章的代码无法运行。 第三,硬件环境不符合要求。在实际操作系统的开发,硬件环境的要求可能较高。如果硬件配置不符合第六章所述的要求,例如内存容量过低或者缺少某些关键的硬件设备,那么无法保证代码能够正确运行。 最后,操作系统开发环境的设置可能有问题。正确设置开发环境是操作系统开发的关键。如果遗漏了某些设置步骤,例如环境变量的配置或者文件路径的设置等,那么第六章的代码可能无法正常运行。 针对以上可能的原因,我们可以先检查书代码的正确性,然后逐步检查所需软件和工具的安装与配置,以及硬件环境是否符合要求。如果仍然无法解决问题,我们可以尝试在相关的开发社区或论坛上寻求帮助,与其他开发者交流并寻找解决方案。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值