https://www.jianshu.com/writer#/notebooks/19149135/notes/71282488
从这里我们已经有了boot.bin
,且这个boot.bin
可以放入软盘中启动虚拟机。
接下来我们研究一下怎么写进光盘,然后用光盘启动虚拟机。
https://stackoverflow.com/questions/34268518/creating-a-bootable-iso-image-with-custom-bootloader
最好的答案出在这里,我们实践一下。
boot.s
.code16
.global init
init:
mov $0x07c0, %ax
mov %ax, %ds
mov $0x07e0, %ax
mov %ax, %ss
mov $0x2000, %sp
mov %cs, %bx
call print_register
mov $0x3a, %al
mov $0x0e, %ah
int $0x10
call next
next:
pop %bx
sub $(next-init), %bx # starting point of memory address, now stored in %bx
call print_register
jmp .
print_register: # always print out value in %bx
mov %bh, %cl
shr $0x4, %cl
and $0x0f, %cl
call print_digit
mov %bh, %cl
and $0x0f, %cl
call print_digit
mov %bl, %cl
shr $0x4, %cl
and $0x0f, %cl
call print_digit
mov %bl, %cl
and $0x0f, %cl
call print_digit
ret
print_digit: # %cl has digit to be printed
cmp $0x9, %cl
jg print_digit_atof
print_digit_1to9:
add $0x30, %cl
jmp print_digit_out
print_digit_atof:
add $0x57, %cl
print_digit_out:
mov %cl, %al
mov $0x0e, %ah
int $0x10
ret
.=510
.byte 0x55
.byte 0xaa
把myos.iso
放入虚拟机光驱,启动
$ as -o boot.o boot.s
$ ld -o boot.bin --oformat binary -e init boot.o
$ mkdir iso
$ cp boot.bin iso/
$ genisoimage -o myos.iso -b boot.bin -boot-load-size 1 -no-emul-boot -hide floppy.img iso/
![](https://img.haomeiwen.com/i5875644/078153224b4fb355.png)
参考
https://www.jianshu.com/writer#/notebooks/19149135/notes/71282488
https://stackoverflow.com/questions/34268518/creating-a-bootable-iso-image-with-custom-bootloader
网友评论