gpt4 book ai didi

assembly - 为什么 BIOS 需要在第二条指令中将(看似)随机地址中的值与零进行比较?

转载 作者:行者123 更新时间:2023-12-02 19:22:53 38 4
gpt4 key购买 nike

我正在尝试通过深入了解操作系统的底层细节来学习操作系统。我现在上的类(class)是MIT 6.828 Operating System Engineering 。该实验室要求学生追踪 BIOS 以获取一些说明。 BIOS的前3条汇编指令列表如下:

0xffff0:    ljmp    $0xf000,$0xe05b
0xfe05b: cmpl $0x0,%cs:0x6c48
0xfe062: jne 0xfd2e1

我不明白的是第二个: cmpl $0x0,%cs:0x6c48 。它有什么作用?为什么在 jmp 到特定位置之前需要这个条件?我在网上搜索了一段时间,但仍然找不到解释。更棘手的是,我发现不同的人有不同的地址进行比较,例如此处的 0x6ac80x65a40x6c48

最佳答案

该比较的具体内容取决于 BIOS 制造商,但它显然是 POST (Power on Self Test) 处理的一些标志。某些 BIOS 可能具有完全不同的代码,看起来与这些指令完全不同。由于您使用的是 QEMU,因此使用的默认 BIOS 是 SeaBIOScmpl 用于确定 reboot or a resume 是否正在执行:

As noted above, on emulators SeaBIOS handles the 0xFFFF0000:FFF0 machine startup execution vector. This vector is also called on machine faults and on some machine "resume" events. It can also be called (as 0xF0000:FFF0) by software as a request to reboot the machine (on emulators, coreboot, and CSM).

The SeaBIOS "resume and reboot" code handles these calls and attempts to determine the desired action of the caller. Code flow starts in 16bit mode in romlayout.S:reset_vector() which calls romlayout.S:entry_post() which calls romlayout.S:entry_resume() which calls resume.c:handle_resume(). Depending on the request the handle_resume() code may transition to 32bit mode.

您可以查看 SeaBIOS 的 source code 中的 entry_post 代码,这是 jmp $0xf000,$0xe05b 所带的位置:。

        ORG 0xe05b
entry_post:
cmpl $0, %cs:HaveRunPost // Check for resume/reboot
jnz entry_resume
ENTRY_INTO32 _cfunc32flat_handle_post // Normal entry point

如果 %cs:HaveRunPost 处的 32 位值不为零,则为恢复操作,否则为重新启动操作。一个 SeaBIOS 版本与另一个版本之间的 HaveRunPost 地址或任何内部 BIOS 变量可能有所不同。这可能是因为版本之间的代码发生了变化;用于构建 ROM 的编译器/编译器选项; BIOS 功能选择等。

关于assembly - 为什么 BIOS 需要在第二条指令中将(看似)随机地址中的值与零进行比较?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59479227/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com