如何在软盘上测试我的引导加载程序

时间:2014-02-05 06:21:51

标签: linux assembly operating-system virtualbox bootloader

这是我的代码: http://pastebin.com/pSncVNPK

    [BITS 16]           ;Tells the assembler that its a 16 bit code
    [ORG 0x7C00]        ;Origin, tell the assembler that where the code will
                        ;be in memory after it is been loaded

    MOV SI, HelloString ;Store string pointer to SI
    CALL PrintString    ;Call print string procedure
    JMP $       ;Infinite loop, hang it here.


PrintCharacter: ;Procedure to print character on screen     
                ;Assume that ASCII value is in register
    AL MOV AH, 0x0E ;Tell BIOS that we need to print one charater on screen.
    MOV BH, 0x00    ;Page no.
    MOV BL, 0x07    ;Text attribute 0x07 is lightgrey font on black background

    INT 0x10    ;Call video interrupt RET       ;Return to calling procedure



PrintString:    ;Procedure to print string on screen
                ;Assume that string starting pointer is in register SI

next_character: ;Label to fetch next character from string
    MOV AL, [SI]    ;Get a byte from string and store in AL register
    INC SI      ;Increment SI pointer
    OR AL, AL   ;Check if value in AL is zero (end of string)
    JZ exit_function ;If end then return
    CALL PrintCharacter ;Else print the character which is in AL register
    JMP next_character  ;Fetch next character from string
exit_function:  ;End label
    RET     ;Return from procedure


    ;Data
    HelloString db 'Hello World', 0 ;HelloWorld string ending with 0

    TIMES 510 - ($ - $$) db 0   ;Fill the rest of sector with 0
    DW 0xAA55           ;Add boot signature at the end of bootloader

正如您所看到的,语法似乎是正确的,将其编译成.bin文件,但我试图弄清楚如何测试它。请对待我,因为我有点慢,因为我花了HOURS搜索这个主题,似乎什么都没有用,我甚至尝试使用十六进制编辑器按照一些教程,但它没有工作。这似乎是我最接近使用这些说明的: http://puu.sh/6KzUo.png

来自此链接:How to make an bootable iso(not cd or flash drive) for testing your own boot loader?

除非我不太了解第6步,因为VM框不允许我选择img文件作为可启动磁盘。

谢谢!

1 个答案:

答案 0 :(得分:2)

如果您只需要将软盘添加到磁盘控制器中,请按照以下步骤操作:

单击软盘控制器。带有绿色加号的软盘图标应出现在您选择的左侧。点击这个小图标。

enter image description here


现在应该出现一个对话框:

enter image description here

选择“选择磁盘”

将出现文件选择框---此时,从文件选择框中选择.img文件。

enter image description here

从这一点开始,您应该能够从软盘启动虚拟机并测试引导加载程序。