参考书:一个64位操作系统的设计与实现
第一个boot程序代码如下,基本上没有不理解的地方
org 0x7c00 ;必须指定位置,不然编译器会将其放到位置0
BaseOfStack equ 0x7c00
Label_Start:
mov ax, cs
mov ds, ax
mov es, ax
mov ss, ax
mov sp, BaseOfStack
;======= clear screen
mov ax, 0600h ;中断10h,ax不同的值有不同功能
mov bx, 0700h
mov cx, 0
mov dx, 0184fh
int 10h
;======= set focus
mov ax, 0200h
mov bx, 0000h
mov dx, 0000h
int 10h
;======= display on screen : Start Booting......
mov ax, 1301h
mov bx, 000fh
mov dx, 0000h
mov cx, StartBootMessagend-StartBootMessage
push ax
mov ax, ds
mov es, ax
pop ax
mov bp, StartBootMessage
int 10h
;======= reset floppy
xor ah, ah
xor dl, dl
int 13h
jmp $
StartBootMessage: db "Start Boot..."
StartBootMessagend:
;======= fill zero until whole sector
times 510 - ($ - $$) db 0
dw 0xaa55
在安装boches的时候出现问题,Ubuntu是16.04, bochs官网的下载不了,最后从github上下载 https://github.com/lubomyr/bochs,版本是bochs2.6.11
安装步骤参考https://blog.csdn.net/dc_726/article/details/7032440)
配置文件bochsre如下
###############################################################
# Configuration file for Bochs
###############################################################
# how much memory the emulated machine will have
megs: 32
# filename of ROM images
romimage: file=/usr/local/share/bochs/BIOS-bochs-latest
vgaromimage: file=/usr/local/share/bochs/VGABIOS-lgpl-latest
# what disk images will be used
floppya: 1_44=a.img, status=inserted
# choose the boot disk.
boot: floppy
# where do we send log messages?
# log: bochsout.txt
# disable the mouse
mouse: enabled=1
# enable key mapping, using US layout as default.
keyboard:keymap=/usr/local/share/bochs/keymaps/x11-pc-us.map
将bin烧写到fd
dd if=boot.bin of=a.img bs=512 count=1 conv=notrunc
正常进入debug模式,运行结果如下: