编写mbr.S代码
bash
;LOADER_BASE_ADDR equ 0x900
;LOADER_START_SECTOR equ 0x2
%include "boot.inc"
SECTION MBR vstart=0x7c00
mov ax,cs
mov ds,ax
mov es,ax
mov ss,ax
mov fs,ax
mov sp,0x7c00
mov ax,0xb800
mov gs,ax
mov ax,0x0600
mov bx,0x0700
mov cx,0
mov dx, 184fh
int 10h
mov byte [gs:0x00], '1'
mov byte [gs:0x01], 0xA4
mov byte [gs:0x02], ' '
mov byte [gs:0x03], 0xA4
mov byte [gs:0x04], 'M'
mov byte [gs:0x05], 0xA4
mov byte [gs:0x06], 'B'
mov byte [gs:0x07], 0xA4
mov byte [gs:0x08], 'R'
mov byte [gs:0x09], 0xA4
mov eax,LOADER_START_SECTOR
mov bx, LOADER_BASE_ADDR
mov cx,1
call rd_disk_m_16
jmp LOADER_BASE_ADDR
rd_disk_m_16:
mov esi,eax
mov di,cx
mov dx,0x1f2
mov al,cl
out dx,al
mov eax,esi
mov dx,0x1f3
out dx,al
mov cl,8
shr eax,cl
mov dx,0x1f4
out dx,al
shr eax,cl
mov dx,0x1f5
out dx,al
shr eax,cl
and al,0x0f
or al,0xe0
mov dx,0x1f6
out dx,al
mov dx,0x1f7
mov al,0x20
out dx,al
.not_ready:
nop
in al,dx
and al,0x88
cmp al,0x08
jnz .not_ready
mov ax,di
mov dx,256
mul dx
mov cx,ax
mov dx,0x1f0
.go_on_ready:
in ax,dx
mov [bx],ax
add bx,2
loop .go_on_ready
ret
times 510-($-$$) db 0
db 0x55,0xaa
编写boot.inc代码
bash
LOADER_BASE_ADDR equ 0x900
LOADER_START_SECTOR equ 0x2
编写loader.S代码
bash
;LOADER_BASE_ADDR equ 0x900
;LOADER_START_SECTOR equ 0x2
%include "boot.inc"
SECTION LOADER vstart=LOADER_BASE_ADDR
mov byte [gs:0x00], '2'
mov byte [gs:0x01], 0xA4
mov byte [gs:0x02], ' '
mov byte [gs:0x03], 0xA4
mov byte [gs:0x04], 'L'
mov byte [gs:0x05], 0xA4
mov byte [gs:0x06], 'O'
mov byte [gs:0x07], 0xA4
mov byte [gs:0x08], 'A'
mov byte [gs:0x09], 0xA4
mov byte [gs:0x0a], 'D'
mov byte [gs:0x0b], 0xA4
mov byte [gs:0x0c], 'E'
mov byte [gs:0x0d], 0xA4
mov byte [gs:0x0e], 'R'
mov byte [gs:0x0f], 0xA4
jmp $
编译mbr.S,loader.S
bash
nasm -I include/ -o mbr.bin mbr.S
dd if=/home/truthos/oscode/c3/b/boot/mbr.bin of=/home/truthos/bochs/hd60M.img bs=512 count=1 conv=notrunc
nasm -I include/ -o loader.bin loader.S
dd if=/home/truthos/oscode/c3/b/boot/loader.bin of=/home/truthos/bochs/hd60M.img bs=512 count=1 seek=2 conv=notrunc
启用bochs查看效果。