【问题标题】:What environment can I use to write binary code of the operating system?可以用什么环境来编写操作系统的二进制代码?
【发布时间】:2015-06-26 05:38:18
【问题描述】:

为了学习操作系统的引导,我用这种方式做了一些简单的测试:

  • 我安装oracle viratualbox并创建硬盘

  • 我安装 hex-editor HxD 并将代码写入此硬盘,打开显示此硬盘的文件

在我写的第一个 512 字节扇区的末尾 55 AA 在 1FE 和 1FF 字节中,

以及我从第一个扇区的第一个字节编写的其他代码。

这样我必须从 HxD 中解除对 hdd 文件的阻止,因为 virtualbox 在完成之前无法启动它。

我想使用虚拟机或者其他真机(第二种方式不太方便),因为它创建了一个独立的开发环境。

我怎样才能更有效地进行测试以学习引导(以及在简单开发之后)操作系统?

【问题讨论】:

    标签: assembly binary operating-system hex-editors mbr


    【解决方案1】:

    当我进行这种开发时,我会从头开始构建磁盘映像,并将虚拟机作为软盘指向它。这样,您的汇编程序的输出,即目标文件,可以成为软盘的完整引导扇区,您可以轻松地链接加载更多扇区。例如:

    ;   x86 architecture systems all support MBR style boot sectors.  An
    ;   MBR boot sector must be 512 bytes in length and have machine
    ;   language code originating at 0000:7c00.  Additionally, it must
    ;   have the signature "0x55aa" as the final word in the sector or it
    ;   is not a valid boot sector.
    
    
    
    org 0x7c00                  ; BIOS will load the MBR to this location 
                                ; and then jump here to continue execution
    
    ; Your code here!
    
                                ; As stated above, the boot sector must 
    times   510-($-$$) db 0     ; Create padding to fill out to 510 bytes
    dw      0xaa55              ; Magic number in the trailer of a boot sector
                                ; We write it as 0xaa55 because we're little
                                ; endian and it will be reversed to the required
                                ; 0x55 0xaa
    

    只需添加您的初始代码。创建一个指向名为“floppy.img”或类似名称的目标文件的链接,然后告诉 VirtualBox 在哪里可以找到它。瞧!

    您没有问,但我希望您能看到您实际上可以将所有代码放入此文件中;只需在0xaa55 之后添加要从后续扇区链式加载的代码,您就可以将其加载到内存中,因为您知道它位于下一个扇区的开头。

    【讨论】:

    • 如果您遇到麻烦,请告诉我。我当然可以发布更多示例代码来充实它。不过,我不想剥夺你的乐趣。 :)
    • 哦,非常感谢,现在我将尝试在 mbr 的开头将“Hello, world”打印到屏幕上,我是一个深度初学者,现在使用 hiew32 将汇编程序转换为二进制 :)
    • 我发现了 fasm (flatassembler.net) - 将汇编命令转换为十六进制的好方法,还发现了 bochs (bochs.sourceforge.net) - IA-32 模拟器
    猜你喜欢
    • 1970-01-01
    • 2013-02-13
    • 2011-10-16
    • 1970-01-01
    • 2012-08-02
    • 2015-06-17
    • 2020-11-05
    • 2010-10-02
    • 1970-01-01
    相关资源
    最近更新 更多