Ну попробуй этот код, может пойдёт.
Код:
.model tiny
.stack 0
.code
.686p
DATASEG equ 7C0h ;Сегмент данных
segBootBin equ 8100h ;Сегмент, в который загрузится файл BOOT.BIN
SelCS equ 8 ;Селекторы защищённого режима
SelDS equ 10h
Start:
jmp near ptr Start2 ; Jump to start of code
BS_OEMName DB "EOS 0.1"
BPB_BytsPerSec DW 200h ; Size of a physical sector
BPB_SecPerClus DB 1 ; Sectors per allocation unit
BPB_RsvdSecCnt DW 1 ; Number of reserved sectors
BPB_NumFATs DB 2 ; Number of fats
BPB_RootEntCnt DW 0E0h ; Number of direc entries
BPB_TotalSec DW 0B40h ; Number of sectors - number of hidden
; sectors (0 when 32 bit sector number)
BPB_MediaByte DB 0F0H ; MediaByte byte
BPB_FATSz16 DW 9 ; Number of fat sectors
BPB_SecPerTrk DW 0x12 ; Sectors per track
BPB_NumHeads DW 2 ; Number of drive heads
BPB_HiddenSecs DD 0 ; Number of hidden sectors
BPB_BigTotalSec DD 0 ; 32 bit version of number of sectors
BS_BootDrv DB 0
BS_Reserved1 DB 0
BS_ExtBootSig DB 0x29
BS_SerialNum DD 1
BS_VolumeLabel DB "NO NAME "
BS_FatId DB "FAT12 "
org 40h ;Align 8
TableGDT db 0FFh,0FFh,0,0,0,9Ah,0CFh,0 ;Code 32bit
db 0FFh,0FFh,0,0,0,92h,0CFh,0 ;Data 32bit
pGDT dw 8 * 3 - 1
dd DATASEG * 16 + offset TableGDT - 8 ;Shift to descriptor #0
FilesData dw 0
segRootDir dw 0
segFAT dw 0
nMemFreePtr dw DATASEG + 20h
sFileBootBin db "BOOT BIN"
sMsgError db "Error", 0
Start2:
mov ax,DATASEG
mov ds,ax
xor ax,ax
mov ss,ax
mov sp,DATASEG * 16
sti
cld
Start3 proc
mov [BS_BootDrv],dl
;Load FAT
mov ax,[BPB_FATSz16]
shl ax,9 ; * 0x200
call MemAlloc
mov [segFAT],bx
mov es,bx ;Ptr segment
xor bx,bx ;Ptr offset
mov cx,[BPB_FATSz16] ;Count
mov ax,[BPB_RsvdSecCnt] ;Index
call ReadSectors
jc mError1
;Load Root Directory
mov ax,[BPB_RootEntCnt]
shl ax,5 ; * 0x20
call MemAlloc
mov [segRootDir],bx
mov es,bx ;Ptr segment
xor bx,bx ;Ptr offset
;Calculate Dir sectors
mov cx,[BPB_RootEntCnt] ;Count
shl cx,5 ; * 0x20
add cx,1E0h ;Round to 0x200
shr cx,9 ; / 0x200
mov [FilesData],cx
movzx ax,[BPB_NumFATs] ;Index
mul [BPB_FATSz16]
add ax,[BPB_RsvdSecCnt] ;Add Boot-sector
add [FilesData],ax
call ReadSectors
jc mError1
;Search BOOT.BIN in directory. Result in es:di
mov ax,[segRootDir]
mov es,ax ;Dir segment
xor di,di ;Dir offset
mov dx,[BPB_RootEntCnt]
LoopDir1:
mov si,offset sFileBootBin
xor bx,bx
m1:
mov al,[si + bx]
cmp al,es:[di + bx]
jne m2
inc bx
cmp bl,0Bh
jb m1
jmp m3
m2:
add di,20h
dec dx
jnz LoopDir1
jmp mError1
m3:
;Load file BOOT.BIN
mov dx,es:[di + 1Ah] ;First cluster
mov ax,[segFAT]
mov fs,ax ;fs -> FAT
mov ax,segBootBin
mov es,ax ;Ptr segment
mov ax,dx
ReadFile1:
xor bx,bx ;Ptr offset
dec ax
dec ax
movzx cx,[BPB_SecPerClus] ;Count
dec cl
push cx ;Push shift count
shl ax,cl
inc cl
add ax,[FilesData] ;Index
call ReadSectors
pop cx ;Pop shift count
jc mError1
mov bx,20h ;Segment step
shl bx,cl
mov ax,es ;Next block
add ax,bx
mov es,ax
mov si,dx ;Get next index from FAT
shl si,1
add si,dx
shr si,1
mov ax,fs:[si]
test dl,1
jnz m10
and ax,0FFFh
jmp m11
m10:
shr ax,4
m11:
mov dx,ax
cmp ax,0FF8h
jb ReadFile1
;Set PM
cli
lgdt fword ptr [pGDT]
mov eax,1 ;Set PM
mov cr0,eax
mov ax,SelDS
mov ds,ax
mov es,ax
mov ss,ax
mov esp,9FC00h - 16 ;With _LibMain parameters
;Execute BOOT.BIN
pushd SelCS
pushd segBootBin * 16
retfd
mError1:
mov bx,offset sMsgError
call puts
jmp $
Start3 endp
;In: ax Size
;Out: bx Segment
MemAlloc proc
mov bx,[nMemFreePtr]
add ax,0Fh ;Round to 16
shr ax,4
add [nMemFreePtr],ax ;Update pointer
ret
MemAlloc endp
;In: ax LBA Index, es:bx Buffer, cx Count
;Out: CF == 0 Success, CF != 0 Error, bx = Buffer end.
ReadSectors proc
push si
mov si,32
Repeat1:
pusha
;Translate LBA to CHS
mov cx,[BPB_SecPerTrk] ;N / Smax
xor dx,dx
div cx
push dx ;Sector
mov cx,[BPB_NumHeads] ; / Hmax
xor dx,dx
div cx
pop cx ;Sector
inc cl
mov ch,al ;Cylinder
mov dh,dl ;Head
mov dl,[BS_BootDrv]
mov ax,201h ;"Fn Read", 1 sector
int 13h
popa
jc Error1
inc ax
add bx,0x200 ;Next sector
loop Repeat1
pop si
clc
ret
Error1:
dec si
jnz Repeat1
pop si
stc
ret
ReadSectors endp
;In: bx - String
puts proc
Loop1:
mov al,[bx]
test al,al
jz Return
inc bx
push bx
mov bx,0
mov ah,0Eh
int 10h
pop bx
jmp Loop1
Return:
ret
puts endp
db 510-($-$$) dup(0)
db 0x55, 0xAA
end Start