哪个值应该用于SP用于引导过程? [英] Which value should be used for SP for booting process?

查看:185
本文介绍了哪个值应该用于SP用于引导过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在BIOS中的引导顺序将加载的第一个有效的MBR它发现到计算机的物理内存地址0x7C00。

哪些值应该用于SP的启动过程?

 组织7C00h处;设置位置计数器。
MOV AX,XXX;什么是XXX?
MOV SP,斧
;现在推送POP是安全的


解决方案

的任何值SS:SP ,以便有对你的code足够的堆栈空间的中断服务程序就可以了。

和,当然,你的筹码不应该与任何code或其他数据的碰撞,或碰到ROM或内存映射设备地址范围。

BIOS不保证什么 SS:SP 您的引导扇区会收到。所以,只改变 SP 是不正确的。

例如,你可以做到这一点(如果没有任何code或你的数据在这个位置):

  ...
MOV AX,0
MOV SS,AX
MOV SP,斧
...

SP 0:

这将 SS设定为0。但不要惊慌。接下来的推首先将递减 SP 0到从0XFFFE和写入0:0xFFFE,而不是0:0

这会给你的0x10000 - (0x7c00 +为0x200)= 33280字节的引导扇区的结束和最大堆栈指针地址之间的空间。这是足够的堆栈空间。

另外请注意,改变当两个 SS SP ,你要么必须做到这一点与中断禁用或第一变化 SS 然后更改 SP 在紧随其后的指令(如上所示)。

另外,您可以使用 LSS SP,... 指令,但它需要作为参数远地址的地址,这意味着新的 SS:SP 价值首先需要在内存的某个地方。

另一种方式来改变 SS SP 是使用 PUSH RETF

The bootstrap sequence in the BIOS will load the first valid MBR that it finds into the computer's physical memory at address 0x7C00.

Which value should be used for SP for booting process?

org 7c00h      ; set location counter.
mov ax, XXX    ; What is XXX?
mov sp, ax
; Now PUSH an POP are safe

解决方案

Any value of SS:SP such that there's enough stack space for your code AND interrupt service routines is OK.

And, of course, your stack shouldn't collide with any of your code or other data or run into ROM or a memory-mapped device address range.

The BIOS does not guarantee what SS:SP your boot sector will receive. So, changing only SP isn't right.

You could for example do this (if there isn't any code or data of yours at this location):

...
mov ax, 0
mov ss, ax
mov sp, ax
...

This will set SS:SP to 0:0. Don't panic yet. The next push will first decrement SP from 0 to 0xFFFE and write to 0:0xFFFE, not to 0:0.

This will give you 0x10000 - (0x7c00 + 0x200) = 33280 bytes of space between the end of your boot sector and the maximum stack pointer address. That's plenty of stack space.

Also note that when changing both SS and SP, you either have to do that with interrupts disabled or first change SS and then change SP in the immediately following instruction (like shown above).

Alternatively you could use the LSS SP, ... instruction, but it takes as an argument an address of a far address, meaning your new SS:SP value would first need to be somewhere in the memory.

Yet another way to change SS and SP is to use PUSH and RETF.

这篇关于哪个值应该用于SP用于引导过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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