【问题标题】:Running an OS on VirtualBox在 VirtualBox 上运行操作系统
【发布时间】:2012-05-21 06:07:20
【问题描述】:

我在 Windows 7 上使用 VirtualBox 4.1.14,并试图让它运行我的测试操作系统。我正在使用下面的汇编代码,并使用

编译它

nasm -f bin -o boot.bin boot.asm

我正在尝试将生成的 bin 文件转换为 VB4.1.14 可以使用的 ISO(我不想花钱或受到试用程序的任何限制)。我曾尝试下载不同的转换器,如 bin2iso,但每当我尝试打开其中生成的 ISO 时,VB 都会出现不同的错误,如 VERR_NOT_SUPPORTED 等。

我希望该解决方案是一个命令行工具,这样我就可以在批处理脚本中使用它来加快测试速度。

BITS 16

start:
    mov ax, 07C0h       ; Set up 4K stack space after this bootloader
    add ax, 288     ; (4096 + 512) / 16 bytes per paragraph
    mov ss, ax
    mov sp, 4096

    mov ax, 07C0h       ; Set data segment to where we're loaded
    mov ds, ax


    mov si, text_string ; Put string position into SI
    call print_string   ; Call our string-printing routine

    jmp $           ; Jump here - infinite loop!


    text_string db 'This is my cool new OS!', 0


print_string:           ; Routine: output string in SI to screen
    mov ah, 0Eh     ; int 10h 'print char' function

.repeat:
    lodsb           ; Get character from string
    cmp al, 0
    je .done        ; If char is zero, end of string
    int 10h         ; Otherwise, print it
    jmp .repeat

.done:
    ret


    times 510-($-$$) db 0   ; Pad remainder of boot sector with 0s
    dw 0xAA55       ; The standard PC boot signature

【问题讨论】:

  • 只是一个建议。但是大多数与此类似的示例都将指令“cli”放在开始标签之后以关闭可屏蔽的外部中断。您可能也想考虑这样做。
  • 虽然我会指出,由于您在这里执行无限循环,因此实际上不需要使用“cli”指令。该指令最常用作处理器同步工具,以避免驱动程序和内核之间的竞争条件。当与“hlt”指令结合使用时,它也常用于暂停系统。与您使用的无限循环相比,使用“cli”然后“hlt”通常是有意停止系统的首选方法。

标签: assembly operating-system virtualbox nasm bin


【解决方案1】:

您可以使用 dd(在 dd 中搜索 windows)为初学者创建软盘。二进制文件仅写入 1440 kib 文件的前 256 个字节。

dd if=/dev/zero of=floppy.img ibs=1k count=1440
dd if=boot.img of=floppy.img conv=notrunc

我们开始吧:

【讨论】:

  • copy:有没有办法用 C 来做到这一点?我可以用 NASM 做到这一点,但我想我想从 C 开始,然后继续往下走。
  • @tekknolagi 您需要设置编译器以输出 16 位代码的平面二进制文件。那是possible,但不可取。一个更好的主意是在 Assembly 中编写您的 bootloader,然后再切换到 C,或者使用 existing bootloader
  • @tekknolagi 您的 CPU 以 16 位模式启动(遗留原因,您仍然可以在其上启动旧 DOS)。您可以稍后切换到 32 位模式。
  • @copy 啊,好的。这对我来说是全新的:)
  • 我迟到了,但在我的测试中,没有必要将其写入 1440 kib 文件。只需将扩展名更改为 .img,我就可以直接从我的输出二进制文件启动 virtualbox;对于以后可能偶然发现此线程的任何人,您需要add a floppy disk controller 才能从中启动。
【解决方案2】:

您可以使用mkisofs 工具,如this answer to a different question。该工具也可用于 Linux。

【讨论】:

    猜你喜欢
    • 2016-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-04
    • 2011-07-06
    • 2010-09-05
    相关资源
    最近更新 更多