[SOS] Virtual PC
LfvrChris at aol.com
LfvrChris at aol.com
Lun 29 Aou 21:27:30 CEST 2005
Bonsoir,
Quelqu'un peut-il me filer un tuyau car j'avoue que pour le moment j'ai
du mal à comprendre ce qui se passe ?
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 !!!
Est-ce que quelqu'un dans la salle utilise Virtual PC, mon but etant
d'avoir un bootloader qui fonctionne sur tous les émulateurs.
Pour ceux que cela interresse, ci-dessous le source du bootloader.
Cordialement,
Krys
------------Début du bootloader-------------
[BITS 16] ; Set 16 bit code generation
[ORG 0x0000] ; Set code start address to 000h (SYS File)
jmp START
OEM db ' ' ;OEM String
BytesPerSector dw 0x0200 ;Bytes per sector (fixed)
SectorsPerCluster db 0x01 ;Sectors per cluster (fixed)
ReservedSectors dw 0x0001 ;Number of reserved sectors (fixed)
TotalFats db 0x02 ;Number of fat copies
MaxRootEntries dw 0x00E0 ;Number of directories (512*14/32)
TotalSectorsSmall dw 0x0B40 ;Number of sectors (18*80*2)
MediaDescriptor db 0xF0 ;Media Descriptor (Floppy Disk)
SectorsPerFat dw 0x0009 ;Number of sectors
SectorsPerTrack dw 0x0012 ;Number of sectors per Track
NumHeads dw 0x0002 ;Number of Heads
HiddenSectors dd 0x00000000 ;
TotalSectorsLarge dd 0x00000000 ;
DriveNumber db 0x00 ;Drive number (fixed)
Flags db 0x00 ;
Signature db 0x29 ;
VolumeID dd 0x05102001 ;
VolumeLabel db ' ' ;
SystemID db 'FAT12 ' ;
DataSector dw 0x0000
Cluster dw 0x0000
Dummy db 0x00
;Constantes
%define LoaderSegment 0x0100
%define LoaderOffset 0x0000
%define BootSegment 0xFFFF
%define BootOffset 0x0000
%define Buffer EndSector+0x0002
ImageName db 'LOADER BIN'
FailureMessage db 0x0D,0x0A,'Error, Press Any Key to reboot',0x00
CrLfMessage db 0x0D,0x0A,0x00
DotMessage db '.',0x00
Failure:
mov si, FailureMessage
call Write
xor ah, ah
int 0x16
jmp BootSegment:BootOffset
Write:
lodsb
or al, al
jz Write_01
mov ah, 0x0E
mov bx, 0x0007
int 0x10
jmp Write
Write_01:
ret
;Convert LBA adressing scheme to CHS adressing scheme.
ReadSectors:
mov di, 0x0003
ReadSectors_01:
push ax
push bx
push cx
xor dx, dx
;AbsoluteSector=(LogicalSector div SectorsPerTrack)+0x0001.
div word [SectorsPerTrack]
inc dl
mov byte [Dummy], dl
xor dx, dx
;AbsoluteHead=(LogicalSector div SectorPerTrack) mod NumHeads (in register
dl).
div word [NumHeads]
mov dh, byte [DriveNumber]
xchg dl, dh
;AbsoluteTrack=(LogicalSector div (SectorPerTrack*NumHeads)) (in register
al).
mov cx, ax
xchg cl, ch
shl cl, 0x0006
or cl, byte [Dummy]
mov al, 0x01
mov ah, 0x02
int 0x13
jnc ReadSectors_02
xor ax, ax
int 0x13
dec di
pop cx
pop bx
pop ax
jnz ReadSectors_01
;Call the "Failure" function.
call Failure
ReadSectors_02:
mov si, DotMessage
call Write
pop cx
pop bx
pop ax
add bx, word [BytesPerSector]
inc ax
loop ReadSectors
ret
START:
;Code located at 0x00007C00, adjust segment registers.
mov ax, 0x07C0
mov ds, ax
mov es, ax
;Create Stack at 0x0009FFFF.
cli
mov ax, 0x9000
mov ss, ax
mov sp, 0xFFFF
sti
;Save current driver.
mov byte [DriveNumber], dl
;Clean the screen.
mov ax, 0x0003
int 0x0010
;Compute size of root directory and store in "CX" register.
xor cx, cx
xor dx, dx
;Calculate the number of sectors for Root Directory.
;For a floppy: 32 bytes*224 directories/512 bytes per sector.
;SectorPerRootDirectory=14.
mov ax, 0x0020
mul word [MaxRootEntries]
div word [BytesPerSector]
xchg ax, cx
;Compute location of Root Directory and store in DataSector.
;DataSector=(SectorPerRootDirectory)14+(ReservedSectors)1+(TotalFats*SectorsPe
rFat)18.
;DataSector=33.
mov al, byte [TotalFats]
mul word [SectorsPerFat]
add ax, word [ReservedSectors]
mov word [DataSector], ax
add word [DataSector], cx
;Copy Root Directory into Root Buffer at 0x07C0:0x0200 or 0x00007E00.
mov bx, Buffer
call ReadSectors
;Jump a line on the screen.
mov si, CrLfMessage
call Write
;Browse Root Buffer for Binary Image.
mov cx, word [MaxRootEntries]
mov di, Buffer
cld
NextRootEntry:
push cx
mov cx, 0x000B
mov si, ImageName
push di
rep cmpsb
pop di
pop cx
je LoadFat
add di, 0x0020
loop NextRootEntry
;Error beccause we didn't find the file in the Root Buffer.
call Failure
;Loading the Fat.
LoadFat:
;Save starting cluster of boot image.
mov dx, [di+001Ah]
mov word [Cluster], dx
;Compute size of Fat.
mov cx, word [SectorsPerFat]
;Compute location of Fat.
mov ax, word [ReservedSectors]
;Copy Fat into Fat Buffer at 0x07C0:0x0200 or 0x00007E00.
mov bx, Buffer
call ReadSectors
;Jump a line on the screen.
mov si, CrLfMessage
call Write
;Copy Image file into memory at 0x0100:0x0000 or 0x00001000.
mov ax, LoaderSegment
mov es, ax
mov bx, LoaderOffset
push bx
LoadImage:
mov ax, word [Cluster]
pop bx
;Subtract 2 from the logical cluster number (because they start at 2).
sub ax, 0x0002
xor cx, cx
mov cl, byte [SectorsPerCluster]
mul cx
add ax, word [DataSector]
xor cx, cx
mov cl, byte [SectorsPerCluster]
call ReadSectors
push bx
;Compute next sector.
mov ax, word [Cluster]
mov cx, ax
mov dx, ax
;Divide by two.
shr dx, 0x0001
add cx, dx
mov bx, Buffer
add bx, cx
mov dx, word [bx]
test ax, 0x0001
jnz OddCluster
EvenCluster:
and dx, 0000111111111111b
jmp NextCluster
OddCluster:
shr dx, 0x0004
NextCluster:
mov word [Cluster], dx
cmp dx, 0x0FF0
jb LoadImage
;We identify the FAT, here it's a FAT12.
xor ax, ax
;FAT12 is the filesystem type of the boot device.
push ax
;Far jump to the loader at adress 0x0100:0x0000 or 0x00001000.
jmp LoaderSegment:LoaderOffset
TIMES 510-($-$$) db 0x00
EndSector:
dw 0xAA55
-------------- section suivante --------------
Une pièce jointe HTML a été enlevée...
URL: http://the-doors.enix.org/pipermail/sos/attachments/20050829/57b8a5ed/attachment.htm
Plus d'informations sur la liste de diffusion Sos