?????????????win xp??bochs??nasm????????VHD
?????????????????????????????????????512?????????????????????55aa??????????????????????510??????????????ù????
?????????????????????????????????????????????????????е?512???????????0x7e00????
????MBR????????
;MBR.ASM
SECTION ALIGN=16 VSTART=0x7C00
LBA_BASE_ADDRESS EQU 5
MOV AX ?? [cs:SS_BASE]
MOV SS ?? AX
XOR SP ?? SP
MOV AX ?? [cs:DS_BASE]
MOV DS ?? AX
XOR BX ?? BX
MOV CX ?? 512
write_memory:
mov byte [bx] ?? 0x02
inc bx
loop write_memory
xor bx ?? bx
CALL WRITE_DISK
JMP $
;
;
;
;DS:BX MEMORY ADDRESS
;
WRITE_DISK:
mov dx ?? 0x1f2
mov al ?? 0x01
call out_port
call pio_delay
mov dx ?? 0x1f3
mov al ?? 0x03
call out_port
call pio_delay
mov dx ?? 0x1f4
mov al ?? 0x00
call out_port
call pio_delay
mov dx ?? 0x1f5
mov al ?? 0x00
call out_port
call pio_delay
mov dx ?? 0x1f6
mov al ?? 0xe0
call out_port
call pio_delay
call check_drdy
;wait?until?the?controller?is?not?busy
busy_hd:
call read_status
and al ?? 0x80
jnz busy_hd
;wait?until?the?controller?accepts?command
accept_hd:
call read_status
and al ?? 0x40
jz accept_hd
mov dx ?? 0x1f7
mov al ?? 0x30
call out_port
call pio_delay
;wait until the controller is not busy
busy_hd1:
call read_status
and al ?? 0x80
jnz busy_hd1
;wait until the controller accepts command
accept_hd2:
call read_status
and al ?? 0x88
cmp al ?? 0x08
jnz accept_hd2
mov cx ??   512
mov al ?? 0x12
mov dx ?? 0x1f0
s:
call out_port
loop s
mov dx?? 0x1f0     ; port
mov di?? bx        ; buf
mov cx?? 256
cld
rep outsw
accept_hd3:
call read_status
test al ?? 0x40
jz accept_hd3
ret
out_port:
out dx ?? al
ret
;;
check_drdy:
mov dx ?? 0x1f7
in al?? dx
test al?? 0x40
jz check_drdy
ret
read_status:
mov dx ?? 0x1f7
in al ?? dx
ret
;;
pio_delay:
nop
nop
nop
nop
ret
DS_BASE DW 0x1000
SS_BASE DW 0x2000
TARGET_PROGRAM_ADDRESS DB 0x02
TARGET_PROGRAM_SIZE DB 0x01
times 510 - ($-$$) db 0
dw 0xaa55