gcc - 如何在 NASM 中编写 GRUB stage1.S?

标签 gcc assembly operating-system nasm bootloader

我正在尝试使用 NASM 和 gcc 编写多阶段引导加载程序。 为此,我指的是 grub 引导加载程序源。

我写了一个 stage1 loader,但是卡在了 over writing partition MBR表。

在 grub stage1.S 中,他们使用这样的代码来跳过分区表:

. = _start + STAGE1_PARTEND
.word   STAGE1_SIGNATURE

我如何在 NASM 中做到这一点?

使用时间它将覆盖分区表。

所以请帮助我。

最佳答案

Assigning a value to . is treated the same as a .org directive
(参见 this page)。

因此,您粘贴的代码正在更改 current origin_start + STAGE1_PARTEND 并在其中放置一个值为 STAGE1_SIGNATURE 的单词。

所以在 NASM 代码中你应该能够做类似的事情:

fill: times _start+STAGE1_PARTEND-$ db 0
dw    STAGE1_SIGNATURE
                     ; .word is 16 bits on x86 (regardless of .code16 / .code64)

另见 this example在 NASM 手册中展示了如何以这种方式填充 BIOS 引导扇区,作为 MASM 风格 org 或 GAS 风格 的替代品。 = new_position 实际上在平面二进制输出文件中寻找并填充填充。

关于gcc - 如何在 NASM 中编写 GRUB stage1.S?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14294121/

相关文章:

gcc - 从cygwin64编译32位代码

c++ - 放置外部虚拟表

assembly - 如何在汇编时连接字符串(使用 CATSTR?)

c - "busy wait"与 "sleep"的权衡是什么?

process - 进程之间的上下文切换是否会使 MMU(内存控制单元)失效?

android - Android 版 Swift : `ld` cannot find `-lgcc` in swift for android compilation linking step

c - strstr:使用不同版本的 gcc 时行为不同

c++ - 在 Xcode 中构建 C++ 和汇编源代码

assembly - 如果改变CS段寄存器会发生什么? (你会怎么做?)

go - 为什么 Go 中的堆是可执行的?