为什么我的引导加载程序的堆栈段位于 0x3FF(实模式 IVT 结束)?
“地址 0x500 是 BIOS 使用的最后一个地址”是 维基百科 的内容 -
“00000000-000003FF实模式IVT(中断向量表)”是osdev.org 关于 BIOS 内存映射的文章说道。
那么你能告诉我为什么 NASM 将我的 .com 文件的堆栈指针放置到 0x3FF 而我的指令指针从 0x7C00 开始吗?对我来说,SP 最直观的位置就是 0x7C00 的正下方。
"address 0x500 is the last one used by the BIOS" is what Wikipedia
-
"00000000-000003FF Real Mode IVT (Interrupt Vector Table)" is what osdev.org's article over the BIOS memory map says.
So can you tell me why NASM places my .com file's stack pointer to 0x3FF while my instruction pointer starts at 0x7C00? To me the most intuitive place for SP would be right below 0x7C00.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
简单的答案是引导扇区有一个 BIOS 使用的有效(可能很小)堆栈。
令人高兴的答案是 3FFh 对于某些 BIOS 来说是有效的堆栈位置。事实上,在本例中它是 IVT 的下部,因为 BIOS 不使用这些中断向量。这不是什么秘密。
The simple answer is that the boot sector has a valid (and probably small) stack which was used by the BIOS.
The happy answer is that 3FFh is a valid stack location for some BIOS. The fact that in this case it is the lower part of the IVT is because those interrupt vectors are not used by the BIOS. It is no secret.
我不认为 BIOS 会为您维护有效的堆栈。因此,您应该在您拥有的任何可用内存中自行设置一个堆栈。我在引导加载程序中的一般启动顺序如下:
NASM 不会执行您告诉它的任何操作。这就是使用汇编的要点。每行汇编代码都有 1:1 比例的计算机执行的操作码。因此,如果 BIOS 没有为您设置堆栈,并且您的汇编代码中没有任何位置设置堆栈,那么堆栈将处于某种无效状态。 Nasm 不会插入魔术代码来设置堆栈。
I don't believe BIOSes are expected to maintain a valid stack for you. So you should setup a stack yourself in whatever free memory you have. My general startup sequence in bootloaders is as so:
NASM Does not do anything than what you tell it. This is the point of using assembly. Every line of assembly code has a 1:1 ratio of opcodes executed by the computer. So, if the BIOS does not setup a stack for you, and no where in your assembly code do you setup a stack, then the stack will be in some invalid state. Nasm will not insert magic code to setup a stack.
我不熟悉 NASM,但我很确定它将您的堆栈段寄存器 (SS) 设置为 0 以外的值,因此 SS:SP 指向完全不同的地方。
编辑:等等,您的段或指针是否设置为03FF?
I'm not familiar with NASM, but I'm pretty sure it sets your Stack Segment register (SS) to something else than 0, so SS:SP points somewhere entirely different.
Edit: Wait, is your segment or pointer set to 03FF?
改变寄存器内容的不是汇编器(通过可执行文件中的任何隐藏命令,在本例中是引导程序)。
根据Intel手册,导致SP包含如此奇数值的原因都不是CPU。
http://www.intel.com/design/pentiumii/manuals/243192。 htm
因为不存在运行代码的现有操作系统,导致 SP(和其他寄存器)状态的唯一选择是 BIOS。不幸的是,BIOS 是闭源的“商业秘密”,因此“为什么”的问题将得到解答。 http://www.coreboot.org/Welcome_to_coreboot 上的 Coreboot 可能会给出一些提示,说明为什么事情是这样的确实如此,但 Coreboot 似乎有时会做一些与传统 BIOS 非常不同的事情......
It's not the assembler that alters the contents of register(s) (by any hidden commands in the executable file, in this case the bootleader).
According to Intel manual it's neither the CPU that causes SP to contain such odd value.
http://www.intel.com/design/pentiumii/manuals/243192.htm
Because there's no existing OS in which the code is run the only option left to cause the state of SP (and other registers) is BIOS. Unfortunately BIOSes are closed source "trade secrets" and thus the question "why" will be left answered. Coreboot at http://www.coreboot.org/Welcome_to_coreboot might give some hints to why things are like they are but Coreboot seems to do things sometimes very different from traditional BIOSes...