org 07c00h jmp short BOOT_START nop BOOT_START: ;init mov ax,cs mov ds,ax mov es,ax mov ss,ax mov sp,BaseOfStack ;clear screen call cls ;message ->BootMessage [(cs:BootMessage,4,(0,0))] mov ax,cs push ax mov ax,BootMessage push ax mov ax,4 push ax mov ax,0000h push ax call dispstr add sp,8 ;--message end ;test disk xor ax,ax mov ah,41h mov bx,055aah mov dl,80h int 13h ;--test end jc BOOT_ERROR ;message ->pass test [(cs:PassMessage,4,(1,0))] mov ax,cs push ax mov ax,PassMessage push ax mov ax,4 push ax mov ax,0100h push ax call dispstr add sp,8 ;--message end jmp BOOT_LOADER BOOT_ERROR: ;message ->fail test [(cs:ErrorMessage,5,(1,0))] mov ax,cs push ax mov ax,ErrorMessage push ax mov ax,5 push ax mov ax,0100h push ax call dispstr add sp,8 ;--message end jmp $ ;load loader BOOT_LOADER: call cls ;message ->LoadMessage [(cs:LoadMessage,7,(0,0))] mov ax,cs push ax mov ax,LoadMessage push ax mov ax,7 push ax mov ax,0000h push ax call dispstr add sp,8 ;--message end ;readsector [1,100,1000h:0h] mov eax,1 push eax mov ax,100 push ax mov ax,1000h push ax mov ax,0h push ax call readsector add sp,10 ;--end readsector ;jmp to loader jmp 1000h:0000h ;--end jmp jmp $ ;data ->BootData BaseOfStack equ 07c00h BootMessage: db "boot " PassMessage: db "pass " ErrorMessage: db "error " LoadMessage: db "loading" TestMessage: db "test " DAP: PacketSize: db 10h Reserved: db 0 BlockCount: dw 100 BufferAddr_off: dw 0000h BufferAddr_Seg: dw 1000h BlockNum: dq 1 ;--data end ;function ->cls [clean screen] cls: mov ax,0600h mov bx,0700h mov cx,0 mov dx,0184fh int 10h mov ah,02h mov bh,00h mov dx,00h int 10h ret ;--function end ;function ->dispstr(u32 source,u16 lens,u16 (pos_x,pos_y)) [display string] ;[source es:bp 串地址,lens cx 串长度,pos_x dh 行,pos_y dl 列] dispstr: mov ax,sp add sp,2 pop dx pop cx pop ax mov bp,ax pop ax mov es,ax sub sp,10 mov ax,01301h mov bx,0007 int 10h ret ;--function end ;function ->readsector(u32 Blocknum,u16 blockcount,u16 seg,u16 off) ;[Blocknum 起始块数量,blockcount 读取块总数,seg:off 缓存区地址] readsector: add sp,2 pop ax mov [DAP+4],ax pop ax mov [DAP+6],ax pop ax mov [DAP+2],ax pop eax mov [DAP+8],eax sub sp,12 mov ax,0 mov ds,ax mov ax,DAP mov si,ax mov dl,80h mov ah,42h int 13h ret ;--function end times 200h-2-($-$$) db 0 dw 0xaa55