mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 17:34:57 +00:00
[EXT2]
Fix remaining issues, bootsector compiles with GAS and ML. Sadly GAs sucks a bit and does neither allow to specify byte offsets, nor does it chose this itself to save space. As a result the code gets several bytes larger and I had to trim the messages even more. svn path=/trunk/; revision=53938
This commit is contained in:
parent
ec00096fc0
commit
e8469d97f6
2 changed files with 99 additions and 90 deletions
|
@ -2,7 +2,7 @@
|
||||||
if(ARCH MATCHES i386 OR ARCH MATCHES amd64)
|
if(ARCH MATCHES i386 OR ARCH MATCHES amd64)
|
||||||
|
|
||||||
CreateBootSectorTarget2(dosmbr ${CMAKE_CURRENT_SOURCE_DIR}/dosmbr.S ${CMAKE_CURRENT_BINARY_DIR}/dosmbr.bin 7c00)
|
CreateBootSectorTarget2(dosmbr ${CMAKE_CURRENT_SOURCE_DIR}/dosmbr.S ${CMAKE_CURRENT_BINARY_DIR}/dosmbr.bin 7c00)
|
||||||
#CreateBootSectorTarget2(ext2 ${CMAKE_CURRENT_SOURCE_DIR}/ext2.S ${CMAKE_CURRENT_BINARY_DIR}/ext2.bin 0)
|
CreateBootSectorTarget2(ext2 ${CMAKE_CURRENT_SOURCE_DIR}/ext2.S ${CMAKE_CURRENT_BINARY_DIR}/ext2.bin 0)
|
||||||
CreateBootSectorTarget2(fat32 ${CMAKE_CURRENT_SOURCE_DIR}/fat32.S ${CMAKE_CURRENT_BINARY_DIR}/fat32.bin 7c00)
|
CreateBootSectorTarget2(fat32 ${CMAKE_CURRENT_SOURCE_DIR}/fat32.S ${CMAKE_CURRENT_BINARY_DIR}/fat32.bin 7c00)
|
||||||
CreateBootSectorTarget2(fat ${CMAKE_CURRENT_SOURCE_DIR}/fat.S ${CMAKE_CURRENT_BINARY_DIR}/fat.bin 7c00)
|
CreateBootSectorTarget2(fat ${CMAKE_CURRENT_SOURCE_DIR}/fat.S ${CMAKE_CURRENT_BINARY_DIR}/fat.bin 7c00)
|
||||||
CreateBootSectorTarget2(isoboot ${CMAKE_CURRENT_SOURCE_DIR}/isoboot.S ${CMAKE_CURRENT_BINARY_DIR}/isoboot.bin 7000)
|
CreateBootSectorTarget2(isoboot ${CMAKE_CURRENT_SOURCE_DIR}/isoboot.S ${CMAKE_CURRENT_BINARY_DIR}/isoboot.bin 7000)
|
||||||
|
@ -13,11 +13,7 @@ add_cd_file(TARGET fat32 DESTINATION loader NO_CAB FILE ${CMAKE_CURRENT_BINARY_D
|
||||||
add_cd_file(TARGET fat DESTINATION loader NO_CAB FILE ${CMAKE_CURRENT_BINARY_DIR}/fat.bin FOR all)
|
add_cd_file(TARGET fat DESTINATION loader NO_CAB FILE ${CMAKE_CURRENT_BINARY_DIR}/fat.bin FOR all)
|
||||||
add_cd_file(TARGET isoboot DESTINATION loader NO_CAB FILE ${CMAKE_CURRENT_BINARY_DIR}/isoboot.bin FOR all)
|
add_cd_file(TARGET isoboot DESTINATION loader NO_CAB FILE ${CMAKE_CURRENT_BINARY_DIR}/isoboot.bin FOR all)
|
||||||
add_cd_file(TARGET isobtrt DESTINATION loader NO_CAB FILE ${CMAKE_CURRENT_BINARY_DIR}/isobtrt.bin FOR all)
|
add_cd_file(TARGET isobtrt DESTINATION loader NO_CAB FILE ${CMAKE_CURRENT_BINARY_DIR}/isobtrt.bin FOR all)
|
||||||
|
add_cd_file(TARGET ext2 DESTINATION loader NO_CAB FILE ${CMAKE_CURRENT_BINARY_DIR}/ext2.bin FOR all)
|
||||||
if(NOT MSVC)
|
|
||||||
CreateBootSectorTarget(ext2 ${CMAKE_CURRENT_SOURCE_DIR}/ext2.asm ${CMAKE_CURRENT_BINARY_DIR}/ext2.bin 0)
|
|
||||||
add_cd_file(TARGET ext2 DESTINATION loader NO_CAB FILE ${CMAKE_CURRENT_BINARY_DIR}/ext2.bin FOR all)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,9 @@
|
||||||
// [bp-0x0c] Here we will store the size of the disk as the BIOS reports in CHS form
|
// [bp-0x0c] Here we will store the size of the disk as the BIOS reports in CHS form
|
||||||
// [bp-0x10] Here we will store the number of LBA sectors read
|
// [bp-0x10] Here we will store the number of LBA sectors read
|
||||||
|
|
||||||
|
#include <asm.inc>
|
||||||
|
.code16
|
||||||
|
|
||||||
SECTORS_PER_TRACK = HEX(04)
|
SECTORS_PER_TRACK = HEX(04)
|
||||||
NUMBER_OF_HEADS = HEX(08)
|
NUMBER_OF_HEADS = HEX(08)
|
||||||
BIOS_CHS_DRIVE_SIZE = HEX(0C)
|
BIOS_CHS_DRIVE_SIZE = HEX(0C)
|
||||||
|
@ -18,40 +21,46 @@ EXT2_S_IFMT = HEX(0f0)
|
||||||
EXT2_S_IFREG = HEX(080)
|
EXT2_S_IFREG = HEX(080)
|
||||||
|
|
||||||
|
|
||||||
org 7c00h
|
//org 7c00h
|
||||||
|
|
||||||
segment .text
|
|
||||||
|
|
||||||
bits 16
|
|
||||||
|
|
||||||
start:
|
start:
|
||||||
jmp short main
|
jmp short main
|
||||||
nop
|
nop
|
||||||
|
|
||||||
BootDrive db HEX(80)
|
BootDrive:
|
||||||
|
.byte HEX(80)
|
||||||
//BootPartition db 0 // Moved to end of boot sector to have a standard format across all boot sectors
|
//BootPartition db 0 // Moved to end of boot sector to have a standard format across all boot sectors
|
||||||
//SectorsPerTrack db 63 // Moved to [bp-SECTORS_PER_TRACK]
|
//SectorsPerTrack db 63 // Moved to [bp-SECTORS_PER_TRACK]
|
||||||
//NumberOfHeads dw 16 // Moved to [bp-NUMBER_OF_HEADS]
|
//NumberOfHeads dw 16 // Moved to [bp-NUMBER_OF_HEADS]
|
||||||
//BiosCHSDriveSize dd (1024 * 1024 * 63) // Moved to [bp-BIOS_CHS_DRIVE_SIZE]
|
//BiosCHSDriveSize dd (1024 * 1024 * 63) // Moved to [bp-BIOS_CHS_DRIVE_SIZE]
|
||||||
//LBASectorsRead dd 0 // Moved to [bp-LBA_SECTORS_READ]
|
//LBASectorsRead dd 0 // Moved to [bp-LBA_SECTORS_READ]
|
||||||
|
|
||||||
Ext2VolumeStartSector dd 263088 // Start sector of the ext2 volume
|
Ext2VolumeStartSector:
|
||||||
Ext2BlockSize dd 2 // Block size in sectors
|
.long 263088 // Start sector of the ext2 volume
|
||||||
Ext2BlockSizeInBytes dd 1024 // Block size in bytes
|
Ext2BlockSize:
|
||||||
Ext2PointersPerBlock dd 256 // Number of block pointers that can be contained in one block
|
.long 2 // Block size in sectors
|
||||||
Ext2GroupDescPerBlock dd 32 // Number of group descriptors per block
|
Ext2BlockSizeInBytes:
|
||||||
Ext2FirstDataBlock dd 1 // First data block (1 for 1024-byte blocks, 0 for bigger sizes)
|
.long 1024 // Block size in bytes
|
||||||
Ext2InodesPerGroup dd 2048 // Number of inodes per group
|
Ext2PointersPerBlock:
|
||||||
Ext2InodesPerBlock dd 8 // Number of inodes per block
|
.long 256 // Number of block pointers that can be contained in one block
|
||||||
|
Ext2GroupDescPerBlock:
|
||||||
|
.long 32 // Number of group descriptors per block
|
||||||
|
Ext2FirstDataBlock:
|
||||||
|
.long 1 // First data block (1 for 1024-byte blocks, 0 for bigger sizes)
|
||||||
|
Ext2InodesPerGroup:
|
||||||
|
.long 2048 // Number of inodes per group
|
||||||
|
Ext2InodesPerBlock:
|
||||||
|
.long 8 // Number of inodes per block
|
||||||
|
|
||||||
Ext2ReadEntireFileLoadSegment:
|
Ext2ReadEntireFileLoadSegment:
|
||||||
dw 0
|
.word 0
|
||||||
Ext2InodeIndirectPointer:
|
Ext2InodeIndirectPointer:
|
||||||
dd 0
|
.long 0
|
||||||
Ext2InodeDoubleIndirectPointer:
|
Ext2InodeDoubleIndirectPointer:
|
||||||
dd 0
|
.long 0
|
||||||
Ext2BlocksLeftToRead:
|
Ext2BlocksLeftToRead:
|
||||||
dd 0
|
.long 0
|
||||||
|
|
||||||
main:
|
main:
|
||||||
xor ax,ax // Setup segment registers
|
xor ax,ax // Setup segment registers
|
||||||
|
@ -61,16 +70,16 @@ main:
|
||||||
mov bp, HEX(7c00)
|
mov bp, HEX(7c00)
|
||||||
mov sp, HEX(7b00) // Setup a stack
|
mov sp, HEX(7b00) // Setup a stack
|
||||||
|
|
||||||
|
mov si, offset BootDrive
|
||||||
cmp byte ptr [bp+BootDrive], HEX(0ff) // If they have specified a boot drive then use it
|
cmp byte ptr [si], HEX(0ff) // If they have specified a boot drive then use it
|
||||||
jne GetDriveParameters
|
jne GetDriveParameters
|
||||||
|
|
||||||
mov [bp+BootDrive],dl // Save the boot drive
|
mov [si],dl // Save the boot drive
|
||||||
|
|
||||||
|
|
||||||
GetDriveParameters:
|
GetDriveParameters:
|
||||||
mov ah,08h
|
mov ah, 8
|
||||||
mov dl,[bp+BootDrive] // Get boot drive in dl
|
mov dl,[si] // Get boot drive in dl
|
||||||
int HEX(13) // Request drive parameters from the bios
|
int HEX(13) // Request drive parameters from the bios
|
||||||
jnc CalcDriveSize // If the call succeeded then calculate the drive size
|
jnc CalcDriveSize // If the call succeeded then calculate the drive size
|
||||||
|
|
||||||
|
@ -125,7 +134,7 @@ Ext2ReadGroupDesc:
|
||||||
shl eax,5 // Group = (Group * sizeof(GROUP_DESCRIPTOR) /* 32 */)
|
shl eax,5 // Group = (Group * sizeof(GROUP_DESCRIPTOR) /* 32 */)
|
||||||
xor edx,edx
|
xor edx,edx
|
||||||
div dword ptr [bp+Ext2GroupDescPerBlock] // Group = (Group / Ext2GroupDescPerBlock)
|
div dword ptr [bp+Ext2GroupDescPerBlock] // Group = (Group / Ext2GroupDescPerBlock)
|
||||||
add eax, [bp+Ext2FirstDataBlock] // Group = Group + Ext2FirstDataBlock + 1
|
add eax, dword ptr [bp+Ext2FirstDataBlock] // Group = Group + Ext2FirstDataBlock + 1
|
||||||
inc eax // EAX now has the group descriptor block number
|
inc eax // EAX now has the group descriptor block number
|
||||||
// EDX now has the group descriptor offset in the block
|
// EDX now has the group descriptor offset in the block
|
||||||
|
|
||||||
|
@ -142,10 +151,10 @@ Ext2ReadGroupDesc:
|
||||||
// Instead of using the call instruction we will
|
// Instead of using the call instruction we will
|
||||||
// just put Ext2ReadBlock right after this routine
|
// just put Ext2ReadBlock right after this routine
|
||||||
|
|
||||||
// Reads ext2 block into [ES:BX]
|
// Reads ext2 block into ES:[BX]
|
||||||
// EAX has logical block number to read
|
// EAX has logical block number to read
|
||||||
Ext2ReadBlock:
|
Ext2ReadBlock:
|
||||||
mov ecx, [bp+Ext2BlockSize]
|
mov ecx, dword ptr [bp+Ext2BlockSize]
|
||||||
mul ecx
|
mul ecx
|
||||||
jmp ReadSectors
|
jmp ReadSectors
|
||||||
|
|
||||||
|
@ -193,11 +202,11 @@ Ext2ReadInode:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
// Reads logical sectors into [ES:BX]
|
// Reads logical sectors into ES:[BX]
|
||||||
// EAX has logical sector number to read
|
// EAX has logical sector number to read
|
||||||
// CX has number of sectors to read
|
// CX has number of sectors to read
|
||||||
ReadSectors:
|
ReadSectors:
|
||||||
add eax, [bp+Ext2VolumeStartSector] // Add the start of the volume
|
add eax, dword ptr [bp+Ext2VolumeStartSector] // Add the start of the volume
|
||||||
cmp eax, [bp-BIOS_CHS_DRIVE_SIZE] // Check if they are reading a sector outside CHS range
|
cmp eax, [bp-BIOS_CHS_DRIVE_SIZE] // Check if they are reading a sector outside CHS range
|
||||||
jae ReadSectorsLBA // Yes - go to the LBA routine
|
jae ReadSectorsLBA // Yes - go to the LBA routine
|
||||||
// If at all possible we want to use LBA routines because
|
// If at all possible we want to use LBA routines because
|
||||||
|
@ -208,7 +217,7 @@ ReadSectors:
|
||||||
CheckInt13hExtensions: // Now check if this computer supports extended reads
|
CheckInt13hExtensions: // Now check if this computer supports extended reads
|
||||||
mov ah, HEX(41) // AH = 41h
|
mov ah, HEX(41) // AH = 41h
|
||||||
mov bx, HEX(55aa) // BX = 55AAh
|
mov bx, HEX(55aa) // BX = 55AAh
|
||||||
mov dl,[bp+BootDrive] // DL = drive (80h-FFh)
|
mov dl, byte ptr [bp+BootDrive] // DL = drive (80h-FFh)
|
||||||
int HEX(13) // IBM/MS INT 13 Extensions - INSTALLATION CHECK
|
int HEX(13) // IBM/MS INT 13 Extensions - INSTALLATION CHECK
|
||||||
jc ReadSectorsCHS // CF set on error (extensions not supported)
|
jc ReadSectorsCHS // CF set on error (extensions not supported)
|
||||||
cmp bx, HEX(0aa55) // BX = AA55h if installed
|
cmp bx, HEX(0aa55) // BX = AA55h if installed
|
||||||
|
@ -228,7 +237,7 @@ ReadSectorsLBA:
|
||||||
ReadSectorsSetupDiskAddressPacket:
|
ReadSectorsSetupDiskAddressPacket:
|
||||||
mov [bp-LBA_SECTORS_READ],cx
|
mov [bp-LBA_SECTORS_READ],cx
|
||||||
mov word ptr [bp-LBA_SECTORS_READ+2],0
|
mov word ptr [bp-LBA_SECTORS_READ+2],0
|
||||||
o32 push 0
|
data32 push 0
|
||||||
push eax // Put 64-bit logical block address on stack
|
push eax // Put 64-bit logical block address on stack
|
||||||
push es // Put transfer segment on stack
|
push es // Put transfer segment on stack
|
||||||
push bx // Put transfer offset on stack
|
push bx // Put transfer offset on stack
|
||||||
|
@ -237,9 +246,9 @@ ReadSectorsSetupDiskAddressPacket:
|
||||||
mov si,sp // Setup disk address packet on stack
|
mov si,sp // Setup disk address packet on stack
|
||||||
|
|
||||||
|
|
||||||
mov dl, [bp+BootDrive] // Drive number
|
mov dl, byte ptr [bp+BootDrive] // Drive number
|
||||||
mov ah,42h // Int 13h, AH = 42h - Extended Read
|
mov ah, HEX(42) // Int 13h, AH = 42h - Extended Read
|
||||||
int 13h // Call BIOS
|
int HEX(13) // Call BIOS
|
||||||
jc PrintDiskError // If the read failed then abort
|
jc PrintDiskError // If the read failed then abort
|
||||||
|
|
||||||
add sp, 16 // Remove disk address packet from stack
|
add sp, 16 // Remove disk address packet from stack
|
||||||
|
@ -247,7 +256,7 @@ ReadSectorsSetupDiskAddressPacket:
|
||||||
popad // Restore sector count & logical sector number
|
popad // Restore sector count & logical sector number
|
||||||
|
|
||||||
push bx
|
push bx
|
||||||
mov ebx,DWORD [bp-LBA_SECTORS_READ]
|
mov ebx, [bp-LBA_SECTORS_READ]
|
||||||
add eax,ebx // Increment sector to read
|
add eax,ebx // Increment sector to read
|
||||||
shl ebx,5
|
shl ebx,5
|
||||||
mov dx,es
|
mov dx,es
|
||||||
|
@ -261,7 +270,7 @@ ReadSectorsSetupDiskAddressPacket:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
// Reads logical sectors into [ES:BX]
|
// Reads logical sectors into ES:[BX]
|
||||||
// EAX has logical sector number to read
|
// EAX has logical sector number to read
|
||||||
// CX has number of sectors to read
|
// CX has number of sectors to read
|
||||||
ReadSectorsCHS:
|
ReadSectorsCHS:
|
||||||
|
@ -270,15 +279,15 @@ ReadSectorsCHS:
|
||||||
ReadSectorsCHSLoop:
|
ReadSectorsCHSLoop:
|
||||||
pushad
|
pushad
|
||||||
xor edx,edx
|
xor edx,edx
|
||||||
mov ecx,DWORD [bp-SECTORS_PER_TRACK]
|
mov ecx, [bp-SECTORS_PER_TRACK]
|
||||||
div ecx // Divide logical by SectorsPerTrack
|
div ecx // Divide logical by SectorsPerTrack
|
||||||
inc dl // Sectors numbering starts at 1 not 0
|
inc dl // Sectors numbering starts at 1 not 0
|
||||||
mov cl,dl // Sector in CL
|
mov cl,dl // Sector in CL
|
||||||
mov edx,eax
|
mov edx,eax
|
||||||
shr edx,16
|
shr edx,16
|
||||||
div WORD [bp-NUMBER_OF_HEADS] // Divide logical by number of heads
|
div word ptr [bp-NUMBER_OF_HEADS] // Divide logical by number of heads
|
||||||
mov dh,dl // Head in DH
|
mov dh,dl // Head in DH
|
||||||
mov dl,[bp+BootDrive] // Drive number in DL
|
mov dl, byte ptr [bp+BootDrive] // Drive number in DL
|
||||||
mov ch,al // Cylinder in CX
|
mov ch,al // Cylinder in CX
|
||||||
ror ah,2 // Low 8 bits of cylinder in CH, high 2 bits
|
ror ah,2 // Low 8 bits of cylinder in CH, high 2 bits
|
||||||
// in CL shifted to bits 6 & 7
|
// in CL shifted to bits 6 & 7
|
||||||
|
@ -316,8 +325,8 @@ Reboot:
|
||||||
mov si,msgAnyKey // Press any key message
|
mov si,msgAnyKey // Press any key message
|
||||||
call PutChars // Display it
|
call PutChars // Display it
|
||||||
xor ax,ax
|
xor ax,ax
|
||||||
int 16h // Wait for a keypress
|
int HEX(16) // Wait for a keypress
|
||||||
int 19h // Reboot
|
int HEX(19) // Reboot
|
||||||
|
|
||||||
PutChars:
|
PutChars:
|
||||||
lodsb
|
lodsb
|
||||||
|
@ -326,16 +335,16 @@ PutChars:
|
||||||
call PutCharsCallBios
|
call PutCharsCallBios
|
||||||
jmp short PutChars
|
jmp short PutChars
|
||||||
PutCharsCallBios:
|
PutCharsCallBios:
|
||||||
mov ah,0eh
|
mov ah, HEX(0e)
|
||||||
mov bx,07h
|
mov bx, HEX(07)
|
||||||
int 10h
|
int HEX(10)
|
||||||
retn
|
ret
|
||||||
Done:
|
Done:
|
||||||
mov al,0dh
|
mov al, HEX(0d)
|
||||||
call PutCharsCallBios
|
call PutCharsCallBios
|
||||||
mov al,0ah
|
mov al, HEX(0a)
|
||||||
call PutCharsCallBios
|
call PutCharsCallBios
|
||||||
retn
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -344,14 +353,15 @@ msgDiskError:
|
||||||
// Sorry, need the space...
|
// Sorry, need the space...
|
||||||
//msgAnyKey db 'Press any key to restart',0
|
//msgAnyKey db 'Press any key to restart',0
|
||||||
msgAnyKey:
|
msgAnyKey:
|
||||||
.ascii "Press any key", NUL
|
.ascii "Press key", NUL
|
||||||
|
|
||||||
times 509-($-$$) db 0 // Pad to 509 bytes
|
// times 509-($-$$) db 0 // Pad to 509 bytes
|
||||||
|
.org 509
|
||||||
|
|
||||||
BootPartition:
|
BootPartition:
|
||||||
db 0
|
.byte 0
|
||||||
|
|
||||||
dw HEX(0aa55) // BootSector signature
|
.word HEX(0aa55) // BootSector signature
|
||||||
|
|
||||||
|
|
||||||
// End of bootsector
|
// End of bootsector
|
||||||
|
@ -367,14 +377,14 @@ LoadRootDirectory:
|
||||||
call Ext2ReadInode // Read in the inode
|
call Ext2ReadInode // Read in the inode
|
||||||
|
|
||||||
// Point ES:DI to the inode structure at 6000:8000
|
// Point ES:DI to the inode structure at 6000:8000
|
||||||
push WORD HEX(6000)
|
push HEX(6000)
|
||||||
pop es
|
pop es
|
||||||
mov di, HEX(8000)
|
mov di, HEX(8000)
|
||||||
push di
|
push di
|
||||||
push es // Save these for later
|
push es // Save these for later
|
||||||
|
|
||||||
// Get root directory size from inode structure
|
// Get root directory size from inode structure
|
||||||
mov eax, [es:di+4]
|
mov eax, es:[di+4]
|
||||||
push eax
|
push eax
|
||||||
|
|
||||||
// Now that the inode has been read in load
|
// Now that the inode has been read in load
|
||||||
|
@ -410,7 +420,7 @@ SearchRootDirectory:
|
||||||
jz FoundFile
|
jz FoundFile
|
||||||
|
|
||||||
// Nope, didn't find it in this entry, keep looking
|
// Nope, didn't find it in this entry, keep looking
|
||||||
movzx ecx,word ptr [es:di+4]
|
movzx ecx,word ptr es:[di+4]
|
||||||
add edx,ecx
|
add edx,ecx
|
||||||
|
|
||||||
// Check to see if we have reached the
|
// Check to see if we have reached the
|
||||||
|
@ -420,14 +430,14 @@ SearchRootDirectory:
|
||||||
jmp PrintFileNotFound
|
jmp PrintFileNotFound
|
||||||
|
|
||||||
FoundFile:
|
FoundFile:
|
||||||
mov eax,[es:di] // Get inode number from directory entry
|
mov eax,es:[di] // Get inode number from directory entry
|
||||||
call Ext2ReadInode // Read in the inode
|
call Ext2ReadInode // Read in the inode
|
||||||
|
|
||||||
// Point ES:DI to the inode structure at 6000:8000
|
// Point ES:DI to the inode structure at 6000:8000
|
||||||
pop es
|
pop es
|
||||||
pop di // These were saved earlier
|
pop di // These were saved earlier
|
||||||
|
|
||||||
mov cx,[es:di] // Get the file mode so we can make sure it's a regular file
|
mov cx, es:[di] // Get the file mode so we can make sure it's a regular file
|
||||||
and ch,EXT2_S_IFMT // Mask off everything but the file type
|
and ch,EXT2_S_IFMT // Mask off everything but the file type
|
||||||
cmp ch,EXT2_S_IFREG // Make sure it's a regular file
|
cmp ch,EXT2_S_IFREG // Make sure it's a regular file
|
||||||
je LoadFreeLoader
|
je LoadFreeLoader
|
||||||
|
@ -439,8 +449,8 @@ LoadFreeLoader:
|
||||||
|
|
||||||
call Ext2ReadEntireFile // Read freeldr.sys to 0000:8000
|
call Ext2ReadEntireFile // Read freeldr.sys to 0000:8000
|
||||||
|
|
||||||
mov dl,[bp+BootDrive]
|
mov dl, byte ptr [bp+BootDrive]
|
||||||
mov dh,[bp+BootPartition]
|
mov dh, byte ptr [bp+BootPartition]
|
||||||
push 0 // push segment (0x0000)
|
push 0 // push segment (0x0000)
|
||||||
mov eax, [HEX(8000) + HEX(0A8)] // load the RVA of the EntryPoint into eax
|
mov eax, [HEX(8000) + HEX(0A8)] // load the RVA of the EntryPoint into eax
|
||||||
add eax, HEX(8000) // RVA -> VA
|
add eax, HEX(8000) // RVA -> VA
|
||||||
|
@ -470,7 +480,7 @@ Ext2ReadEntireFile:
|
||||||
// We will do this by rounding the
|
// We will do this by rounding the
|
||||||
// file size up to the next block
|
// file size up to the next block
|
||||||
// size and then dividing by the block size
|
// size and then dividing by the block size
|
||||||
mov eax,DWORD [bp+Ext2BlockSizeInBytes] // Get the block size in bytes
|
mov eax, dword ptr [bp+Ext2BlockSizeInBytes] // Get the block size in bytes
|
||||||
push eax
|
push eax
|
||||||
dec eax // Ext2BlockSizeInBytes -= 1
|
dec eax // Ext2BlockSizeInBytes -= 1
|
||||||
add eax, es:[di+4] // Add the file size
|
add eax, es:[di+4] // Add the file size
|
||||||
|
@ -480,22 +490,22 @@ Ext2ReadEntireFile:
|
||||||
push eax
|
push eax
|
||||||
|
|
||||||
// Make sure the file size isn't zero
|
// Make sure the file size isn't zero
|
||||||
cmp eax,byte 0
|
cmp eax, 0
|
||||||
jnz Ext2ReadEntireFile2
|
jnz Ext2ReadEntireFile2
|
||||||
jmp PrintFileSizeError
|
jmp PrintFileSizeError
|
||||||
|
|
||||||
Ext2ReadEntireFile2:
|
Ext2ReadEntireFile2:
|
||||||
// Save the indirect & double indirect pointers
|
// Save the indirect & double indirect pointers
|
||||||
mov edx,DWORD [es:di+ HEX(58)] // Get indirect pointer
|
mov edx, es:[di+ HEX(58)] // Get indirect pointer
|
||||||
mov [bp+Ext2InodeIndirectPointer],edx // Save indirect pointer
|
mov dword ptr [bp+Ext2InodeIndirectPointer], edx // Save indirect pointer
|
||||||
mov edx,DWORD [es:di+ HEX(5c)] // Get double indirect pointer
|
mov edx, es:[di+ HEX(5c)] // Get double indirect pointer
|
||||||
mov [bp+Ext2InodeDoubleIndirectPointer],edx // Save double indirect pointer
|
mov dword ptr [bp+Ext2InodeDoubleIndirectPointer],edx // Save double indirect pointer
|
||||||
|
|
||||||
// Now copy the direct pointers to 7000:0000
|
// Now copy the direct pointers to 7000:0000
|
||||||
// so that we can call Ext2ReadDirectBlocks
|
// so that we can call Ext2ReadDirectBlocks
|
||||||
push ds // Save DS
|
push ds // Save DS
|
||||||
push es
|
push es
|
||||||
push WORD HEX(7000)
|
push HEX(7000)
|
||||||
pop es
|
pop es
|
||||||
pop ds
|
pop ds
|
||||||
mov si, HEX(8028)
|
mov si, HEX(8028)
|
||||||
|
@ -513,15 +523,15 @@ Ext2ReadEntireFile2:
|
||||||
|
|
||||||
// Check to see if we actually have
|
// Check to see if we actually have
|
||||||
// blocks left to read
|
// blocks left to read
|
||||||
cmp eax,byte 0
|
cmp eax, 0
|
||||||
jz Ext2ReadEntireFileDone
|
jz Ext2ReadEntireFileDone
|
||||||
|
|
||||||
// Now we have read all the direct blocks in
|
// Now we have read all the direct blocks in
|
||||||
// the inode. So now we have to read the indirect
|
// the inode. So now we have to read the indirect
|
||||||
// block and read all it's direct blocks
|
// block and read all it's direct blocks
|
||||||
push eax // Save the total block count
|
push eax // Save the total block count
|
||||||
mov eax,DWORD [BYTE bp+Ext2InodeIndirectPointer] // Get the indirect block pointer
|
mov eax, dword ptr [bp+Ext2InodeIndirectPointer] // Get the indirect block pointer
|
||||||
push WORD HEX(7000)
|
push HEX(7000)
|
||||||
pop es
|
pop es
|
||||||
xor bx,bx // Set the load address to 7000:0000
|
xor bx,bx // Set the load address to 7000:0000
|
||||||
call Ext2ReadBlock // Read the block
|
call Ext2ReadBlock // Read the block
|
||||||
|
@ -529,7 +539,7 @@ Ext2ReadEntireFile2:
|
||||||
// Now we have all the block pointers from the
|
// Now we have all the block pointers from the
|
||||||
// indirect block in the right location so read them in
|
// indirect block in the right location so read them in
|
||||||
pop eax // Restore the total block count
|
pop eax // Restore the total block count
|
||||||
mov ecx,DWORD [BYTE bp+Ext2PointersPerBlock] // Get the number of block pointers that one block contains
|
mov ecx, dword ptr [bp+Ext2PointersPerBlock] // Get the number of block pointers that one block contains
|
||||||
call Ext2ReadDirectBlockList
|
call Ext2ReadDirectBlockList
|
||||||
|
|
||||||
// Check to see if we actually have
|
// Check to see if we actually have
|
||||||
|
@ -542,9 +552,9 @@ Ext2ReadEntireFile2:
|
||||||
// we have to read the double indirect block
|
// we have to read the double indirect block
|
||||||
// and read all it's indirect blocks
|
// and read all it's indirect blocks
|
||||||
// (whew, it's a good thing I don't support triple indirect blocks)
|
// (whew, it's a good thing I don't support triple indirect blocks)
|
||||||
mov [bp+Ext2BlocksLeftToRead],eax // Save the total block count
|
mov dword ptr [bp+Ext2BlocksLeftToRead],eax // Save the total block count
|
||||||
mov eax,DWORD [bp+Ext2InodeDoubleIndirectPointer] // Get the double indirect block pointer
|
mov eax, dword ptr [bp+Ext2InodeDoubleIndirectPointer] // Get the double indirect block pointer
|
||||||
push WORD HEX(7800)
|
push HEX(7800)
|
||||||
pop es
|
pop es
|
||||||
push es // Save an extra copy of this value on the stack
|
push es // Save an extra copy of this value on the stack
|
||||||
xor bx,bx // Set the load address to 7000:8000
|
xor bx,bx // Set the load address to 7000:8000
|
||||||
|
@ -554,28 +564,28 @@ Ext2ReadEntireFile2:
|
||||||
xor di,di
|
xor di,di
|
||||||
|
|
||||||
Ext2ReadIndirectBlock:
|
Ext2ReadIndirectBlock:
|
||||||
mov eax,DWORD [es:di] // Get indirect block pointer
|
mov eax, es:[di] // Get indirect block pointer
|
||||||
add di,BYTE 4 // Update DI for next array index
|
add di, 4 // Update DI for next array index
|
||||||
push es
|
push es
|
||||||
push di
|
push di
|
||||||
|
|
||||||
push WORD HEX(7000)
|
push HEX(7000)
|
||||||
pop es
|
pop es
|
||||||
xor bx,bx // Set the load address to 7000:0000
|
xor bx,bx // Set the load address to 7000:0000
|
||||||
call Ext2ReadBlock // Read the indirect block
|
call Ext2ReadBlock // Read the indirect block
|
||||||
|
|
||||||
// Now we have all the block pointers from the
|
// Now we have all the block pointers from the
|
||||||
// indirect block in the right location so read them in
|
// indirect block in the right location so read them in
|
||||||
mov eax,DWORD [bp+Ext2BlocksLeftToRead] // Restore the total block count
|
mov eax, dword ptr [bp+Ext2BlocksLeftToRead] // Restore the total block count
|
||||||
mov ecx,DWORD [bp+Ext2PointersPerBlock] // Get the number of block pointers that one block contains
|
mov ecx, dword ptr [bp+Ext2PointersPerBlock] // Get the number of block pointers that one block contains
|
||||||
call Ext2ReadDirectBlockList
|
call Ext2ReadDirectBlockList
|
||||||
mov [bp+Ext2BlocksLeftToRead],eax // Save the total block count
|
mov dword ptr [bp+Ext2BlocksLeftToRead],eax // Save the total block count
|
||||||
pop di
|
pop di
|
||||||
pop es
|
pop es
|
||||||
|
|
||||||
// Check to see if we actually have
|
// Check to see if we actually have
|
||||||
// blocks left to read
|
// blocks left to read
|
||||||
cmp eax,byte 0
|
cmp eax, 0
|
||||||
jnz Ext2ReadIndirectBlock
|
jnz Ext2ReadIndirectBlock
|
||||||
|
|
||||||
Ext2ReadEntireFileDone:
|
Ext2ReadEntireFileDone:
|
||||||
|
@ -606,12 +616,12 @@ CallExt2ReadDirectBlocks:
|
||||||
// CX contains the number of blocks to read
|
// CX contains the number of blocks to read
|
||||||
Ext2ReadDirectBlocks:
|
Ext2ReadDirectBlocks:
|
||||||
|
|
||||||
push WORD HEX(7000)
|
push HEX(7000)
|
||||||
pop es
|
pop es
|
||||||
xor di,di // Set ES:DI = 7000:0000
|
xor di,di // Set ES:DI = 7000:0000
|
||||||
|
|
||||||
Ext2ReadDirectBlocksLoop:
|
Ext2ReadDirectBlocksLoop:
|
||||||
mov eax,[es:di] // Get direct block pointer from array
|
mov eax,es:[di] // Get direct block pointer from array
|
||||||
add di, 4 // Update DI for next array index
|
add di, 4 // Update DI for next array index
|
||||||
|
|
||||||
push cx // Save number of direct blocks left
|
push cx // Save number of direct blocks left
|
||||||
|
@ -660,14 +670,17 @@ DisplayItAndReboot:
|
||||||
msgFreeLdr:
|
msgFreeLdr:
|
||||||
.ascii "freeldr.sys not found", NUL
|
.ascii "freeldr.sys not found", NUL
|
||||||
msgFileSize:
|
msgFileSize:
|
||||||
.ascii "File size is 0", NUL
|
.ascii "File size 0", NUL
|
||||||
msgRegFile:
|
msgRegFile:
|
||||||
.ascii "freeldr.sys isnt a regular file", NUL
|
.ascii "freeldr.sys isnt a regular file", NUL
|
||||||
filename:
|
filename:
|
||||||
.ascii "freeldr.sys"
|
.ascii "freeldr.sys"
|
||||||
msgLoading:
|
msgLoading:
|
||||||
.ascii "Loading FreeLoader...", NUL
|
.ascii "Loading...", NUL
|
||||||
|
|
||||||
times 1022-($-$$) db 0 // Pad to 1022 bytes
|
// times 1022-($-$$) db 0 // Pad to 1022 bytes
|
||||||
|
.org 1022
|
||||||
|
|
||||||
dw HEX(0aa55) // BootSector signature
|
.word HEX(0aa55) // BootSector signature
|
||||||
|
|
||||||
|
END
|
||||||
|
|
Loading…
Reference in a new issue