<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY id=role_body style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Arial"
bottomMargin=7 leftMargin=7 topMargin=7 rightMargin=7><FONT id=role_document
face=Arial color=#000000 size=2>
<DIV>Bonsoir,</DIV>
<DIV> </DIV>
<DIV> Quelqu'un peut-il me filer un tuyau car j'avoue que
pour le moment j'ai du mal à comprendre ce qui se passe ?</DIV>
<DIV> Voilà, j'ai un Bootloader qui fonctionne sous Qemu,
Bochs, VmWare et sur machine réelle, malheureusement il ne veut pas fonctionner
sur Virtual PC !!!</DIV>
<DIV> Est-ce que quelqu'un dans la salle utilise Virtual
PC, mon but etant d'avoir un bootloader qui fonctionne sur tous les
émulateurs.</DIV>
<DIV> </DIV>
<DIV>Pour ceux que cela interresse, ci-dessous le source du bootloader.</DIV>
<DIV> </DIV>
<DIV>Cordialement,</DIV>
<DIV> </DIV>
<DIV>Krys</DIV>
<DIV> </DIV>
<DIV>------------Début du bootloader-------------</DIV>
<DIV> </DIV>
<DIV>[BITS
16]
; Set 16 bit code generation<BR>[ORG
0x0000]
; Set code start address to 000h (SYS File)</DIV>
<DIV> </DIV>
<DIV> jmp START</DIV>
<DIV> </DIV>
<DIV> OEM
db ' ' ;OEM
String<BR> BytesPerSector dw
0x0200 ;Bytes per sector
(fixed)<BR> SectorsPerCluster db
0x01 ;Sectors per
cluster (fixed)<BR> ReservedSectors dw
0x0001 ;Number of reserved
sectors
(fixed)<BR> TotalFats
db 0x02 ;Number of
fat copies<BR> MaxRootEntries dw
0x00E0 ;Number of directories
(512*14/32)<BR> TotalSectorsSmall dw
0x0B40 ;Number of sectors
(18*80*2)<BR> MediaDescriptor db
0xF0 ;Media
Descriptor (Floppy Disk)<BR> SectorsPerFat dw
0x0009 ;Number of
sectors<BR> SectorsPerTrack dw
0x0012 ;Number of sectors per
Track<BR> NumHeads
dw 0x0002 ;Number of
Heads<BR> HiddenSectors dd
0x00000000 ;<BR> TotalSectorsLarge dd
0x00000000
;<BR> DriveNumber db
0x00 ;Drive number
(fixed)<BR> Flags
db 0x00
;<BR> Signature db
0x29
;<BR> VolumeID
dd 0x05102001
;<BR> VolumeLabel db
' '
;<BR> SystemID
db 'FAT12 ' ;</DIV>
<DIV> </DIV>
<DIV> DataSector dw
0x0000<BR> Cluster dw
0x0000<BR> <BR> Dummy
db 0x00<BR> <BR>;Constantes <BR> %define LoaderSegment
0x0100<BR> %define LoaderOffset 0x0000<BR> <BR> %define
BootSegment 0xFFFF<BR> %define BootOffset
0x0000<BR> <BR> %define
Buffer
EndSector+0x0002<BR> <BR> ImageName db 'LOADER BIN'</DIV>
<DIV> </DIV>
<DIV> FailureMessage db
0x0D,0x0A,'Error, Press Any Key to
reboot',0x00<BR> CrLfMessage
db
0x0D,0x0A,0x00<BR> DotMessage
db '.',0x00</DIV>
<DIV> </DIV>
<DIV><BR>Failure:<BR> mov si,
FailureMessage<BR> call
Write<BR> xor ah,
ah<BR> int
0x16<BR> jmp
BootSegment:BootOffset</DIV>
<DIV> </DIV>
<DIV>
<BR>Write:<BR>
lodsb<BR> or al,
al<BR> jz
Write_01<BR> mov ah,
0x0E<BR> mov bx,
0x0007<BR> int
0x10<BR> jmp
Write<BR>
Write_01:<BR> ret</DIV>
<DIV> </DIV>
<DIV> <BR>;Convert LBA adressing
scheme to CHS adressing scheme.
<BR>ReadSectors:<BR> mov di,
0x0003<BR>
ReadSectors_01:<BR> push
ax<BR> push
bx<BR> push
cx<BR> xor dx,
dx<BR>;AbsoluteSector=(LogicalSector div
SectorsPerTrack)+0x0001.<BR> div word
[SectorsPerTrack]<BR> inc
dl<BR> mov byte [Dummy],
dl<BR> xor dx,
dx<BR>;AbsoluteHead=(LogicalSector div SectorPerTrack) mod NumHeads (in register
dl).<BR> div word
[NumHeads]<BR> mov dh, byte
[DriveNumber]<BR> xchg dl,
dh<BR>;AbsoluteTrack=(LogicalSector div (SectorPerTrack*NumHeads)) (in register
al).
<BR> mov cx,
ax<BR> xchg cl,
ch<BR> shl cl,
0x0006<BR> or cl, byte
[Dummy]<BR> mov al,
0x01<BR> mov ah,
0x02<BR> int
0x13<BR> jnc
ReadSectors_02<BR> xor ax,
ax<BR> int
0x13<BR> dec
di<BR> pop
cx<BR> pop
bx<BR> pop
ax<BR> jnz ReadSectors_01<BR>;Call the
"Failure" function.
<BR> call
Failure<BR>
ReadSectors_02:<BR> mov si,
DotMessage<BR> call
Write<BR> pop
cx<BR> pop
bx<BR> pop
ax<BR> add bx, word
[BytesPerSector]<BR> inc
ax<BR> loop
ReadSectors<BR> ret</DIV>
<DIV> </DIV>
<DIV> <BR>START:<BR>;Code located at
0x00007C00, adjust segment
registers.<BR> mov ax,
0x07C0<BR> mov ds,
ax<BR> mov es, ax<BR>;Create Stack at
0x0009FFFF.<BR>
cli<BR> mov ax,
0x9000<BR> mov ss,
ax<BR> mov sp,
0xFFFF<BR> sti<BR>;Save current
driver.<BR> mov byte [DriveNumber],
dl<BR>;Clean the screen.<BR> mov ax,
0x0003<BR> int 0x0010<BR>;Compute size
of root directory and store in "CX"
register.<BR> xor cx,
cx<BR> xor dx, dx<BR>;Calculate the
number of sectors for Root Directory.<BR>;For a floppy: 32 bytes*224
directories/512 bytes per
sector.<BR>;SectorPerRootDirectory=14.<BR>
mov ax, 0x0020<BR> mul word
[MaxRootEntries]<BR> div word
[BytesPerSector]<BR> xchg ax,
cx<BR>;Compute location of Root Directory and store in
DataSector.<BR>;DataSector=(SectorPerRootDirectory)14+(ReservedSectors)1+(TotalFats*SectorsPerFat)18.<BR>;DataSector=33.<BR>
mov al, byte [TotalFats]<BR> mul word
[SectorsPerFat]<BR> add ax, word
[ReservedSectors]<BR> mov word
[DataSector], ax<BR> add word
[DataSector], cx<BR>;Copy Root Directory into Root Buffer at 0x07C0:0x0200 or
0x00007E00.<BR> mov bx,
Buffer<BR> call ReadSectors<BR>;Jump a
line on the screen.<BR> mov si,
CrLfMessage<BR> call Write<BR>;Browse
Root Buffer for Binary Image.<BR> mov
cx, word [MaxRootEntries]<BR> mov di,
Buffer<BR>
cld<BR>
NextRootEntry:<BR> push
cx<BR> mov cx,
0x000B<BR> mov si,
ImageName<BR> push
di<BR> rep
cmpsb<BR> pop
di<BR> pop
cx<BR> je
LoadFat<BR> add di,
0x0020<BR> loop
NextRootEntry<BR>;Error beccause we didn't find the file in the Root
Buffer.
<BR> call Failure<BR>;Loading the
Fat.<BR> LoadFat:<BR>;Save starting cluster of
boot image.<BR> mov dx,
[di+001Ah]<BR> mov word [Cluster],
dx<BR>;Compute size of Fat.<BR> mov
cx, word [SectorsPerFat]<BR>;Compute location of
Fat.<BR> mov ax, word
[ReservedSectors]<BR>;Copy Fat into Fat Buffer at 0x07C0:0x0200 or
0x00007E00.<BR> mov bx,
Buffer<BR> call ReadSectors<BR>;Jump a
line on the screen.<BR> mov si,
CrLfMessage<BR> call Write<BR>;Copy
Image file into memory at 0x0100:0x0000 or
0x00001000.<BR> mov ax,
LoaderSegment<BR> mov es,
ax<BR> mov bx,
LoaderOffset<BR> push
bx<BR>
LoadImage:<BR> mov ax, word
[Cluster]<BR> pop bx<BR>;Subtract 2
from the logical cluster number (because they start at
2).
<BR> sub ax,
0x0002<BR> xor cx,
cx<BR> mov cl, byte
[SectorsPerCluster]<BR> mul
cx<BR> add ax, word
[DataSector]<BR> xor cx,
cx<BR> mov cl, byte
[SectorsPerCluster]<BR> call
ReadSectors<BR> push bx<BR>;Compute
next sector.<BR> mov ax, word
[Cluster]<BR> mov cx,
ax<BR> mov dx, ax<BR>;Divide by
two.<BR> shr dx,
0x0001<BR> add cx,
dx<BR> mov bx,
Buffer<BR> add bx,
cx<BR> mov dx, word
[bx]<BR> test ax,
0x0001<BR> jnz
OddCluster<BR>
EvenCluster:<BR> and dx,
0000111111111111b<BR> jmp
NextCluster<BR>
OddCluster:<BR> shr dx,
0x0004<BR>
NextCluster:<BR> mov word [Cluster],
dx<BR> cmp dx,
0x0FF0<BR> jb LoadImage<BR>;We
identify the FAT, here it's a FAT12.
<BR> xor ax, ax<BR>;FAT12 is the
filesystem type of the boot
device.<BR> push ax<BR>;Far jump to
the loader at adress 0x0100:0x0000 or
0x00001000.<BR> jmp
LoaderSegment:LoaderOffset</DIV>
<DIV> </DIV>
<DIV> TIMES 510-($-$$) db 0x00<BR>
EndSector:<BR> dw 0xAA55</DIV>
<DIV> </DIV>
<DIV> </DIV></FONT></BODY></HTML>