diff options
-rw-r--r-- | DuetPkg/BootSector/BootSector.inf | 2 | ||||
-rw-r--r-- | DuetPkg/BootSector/Gpt.S | 297 | ||||
-rw-r--r-- | DuetPkg/BootSector/bs32.S | 310 |
3 files changed, 609 insertions, 0 deletions
diff --git a/DuetPkg/BootSector/BootSector.inf b/DuetPkg/BootSector/BootSector.inf index e42d97281d..39d81463d8 100644 --- a/DuetPkg/BootSector/BootSector.inf +++ b/DuetPkg/BootSector/BootSector.inf @@ -20,8 +20,10 @@ bs16.asm | MSFT
bs32.asm | INTEL
bs32.asm | MSFT
+# bs32.S | GCC ## It can not be compiled. It is added just for version control.
Gpt.asm | INTEL
Gpt.asm | MSFT
+# Gpt.S | GCC ## It can not be compiled. It is added just for version control.
Mbr.asm | INTEL
Mbr.asm | MSFT
start.asm | INTEL
diff --git a/DuetPkg/BootSector/Gpt.S b/DuetPkg/BootSector/Gpt.S new file mode 100644 index 0000000000..763513c7a0 --- /dev/null +++ b/DuetPkg/BootSector/Gpt.S @@ -0,0 +1,297 @@ +#------------------------------------------------------------------------------
+#*
+#* Copyright 2006 - 2007, Intel Corporation
+#* All rights reserved. This program and the accompanying materials
+#* are licensed and made available under the terms and conditions of the BSD License
+#* which accompanies this distribution. The full text of the license may be found at
+#* http://opensource.org/licenses/bsd-license.php
+#*
+#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#*
+#* gpt.asm
+#*
+#* Abstract:
+#*
+#------------------------------------------------------------------------------
+
+ #.MODEL small
+# .dosseg
+ .stack:
+ .486p:
+ .code:
+
+.equ BLOCK_SIZE, 0x0200
+.equ BLOCK_MASK, 0x01ff
+.equ BLOCK_SHIFT, 9
+
+# ****************************************************************************
+# Code loaded by BIOS at 0x0000:0x7C00
+# ****************************************************************************
+
+ .org 0x00
+Start:
+
+# ****************************************************************************
+# Start Print
+# ****************************************************************************
+
+ movw $0xb800, %ax
+ movw %ax, %es
+ movw $0x7c0, %ax
+ movw %ax, %ds
+ leaw %cs:StartString, %si
+ movw $10, %cx
+ movw $160, %di
+ rep
+ movsw
+
+# ****************************************************************************
+# Print over
+# ****************************************************************************
+
+# ****************************************************************************
+# Initialize segment registers and copy code at 0x0000:0x7c00 to 0x0000:0x0600
+# ****************************************************************************
+ xorw %ax, %ax # AX = 0x0000
+ movw $0x7c00, %bx # BX = 0x7C00
+ movw $0x600, %bp # BP = 0x0600
+ movw RelocatedStart, %si # SI = Offset(RelocatedStart)
+ movw $0x200, %cx # CX = 0x0200
+ subw %si, %cx # CS = 0x0200 - Offset(RelocatedStart)
+ leaw (%bp,%si,), %di # DI = 0x0600 + Offset(RelocatedStart)
+ leaw (%bx,%si,), %si # BX = 0x7C00 + Offset(RelocatedStart)
+ movw %ax, %ss # SS = 0x0000
+ movw %bx, %sp # SP = 0x7C00
+ movw %ax, %es # ES = 0x0000
+ movw %ax, %ds # DS = 0x0000
+ pushw %ax # PUSH 0x0000
+ pushw %di # PUSH 0x0600 + Offset(RelocatedStart)
+ cld # Clear the direction flag
+ rep
+ movsb # Copy 0x0200 bytes from 0x7C00 to 0x0600
+ retl # JMP 0x0000:0x0600 + Offset(RelocatedStart)
+
+# ****************************************************************************
+# Code relocated to 0x0000:0x0600
+# ****************************************************************************
+
+RelocatedStart:
+# ****************************************************************************
+# Get Driver Parameters to 0x0000:0x7BFC
+# ****************************************************************************
+ xorw %ax, %ax # ax = 0
+ movw %ax, %ss # ss = 0
+ addw $0x1000, %ax
+ movw %ax, %ds
+
+ movw $0x7c00, %sp # sp = 0x7c00
+ movw %sp, %bp # bp = 0x7c00
+
+ movb $8, %ah # ah = 8 - Get Drive Parameters Function
+ movb %dl, PhysicalDrive(%bp) # BBS defines that BIOS would pass the booting driver number to the loader through DL
+ int $0x13 # Get Drive Parameters
+ xorw %ax, %ax # ax = 0
+ movb %dh, %al # al = dh
+ incb %al # MaxHead = al + 1
+ pushw %ax # 0000:7bfe = MaxHead
+ movb %cl, %al # al = cl
+ andb $0x3f, %al # MaxSector = al & 0x3f
+ pushw %ax # 0000:7bfc = MaxSector
+
+# ****************************************************************************
+# Read GPT Header from hard disk to 0x0000:0x0800
+# ****************************************************************************
+ xorw %ax, %ax
+ movw %ax, %es # Read to 0x0000:0x0800
+ movw $0x800, %di # Read to 0x0000:0x0800
+ movl $1, %eax # Read LBA #1
+ movl $0, %edx # Read LBA #1
+ movw $1, %bx # Read 1 Block
+ pushw %es
+ call ReadBlocks
+ popw %es
+
+# ****************************************************************************
+# Read Target GPT Entry from hard disk to 0x0000:0x0A00
+# ****************************************************************************
+ cmpl $0x20494645, %es:(%di) # Check for "EFI "
+ jne BadGpt
+ cmpl $0x54524150, %es:4(%di) # Check for "PART"
+ jne BadGpt
+ cmpl $0x00010000, %es:8(%di) # Check Revision - 0x10000
+ jne BadGpt
+
+ movl %es:84(%di), %eax # EAX = SizeOfPartitionEntry
+ mulb GptPartitionIndicator(%bp) # EAX = SizeOfPartitionEntry * GptPartitionIndicator
+ movl %eax, %edx # EDX = SizeOfPartitionEntry * GptPartitionIndicator
+ shrl $BLOCK_SHIFT, %eax # EAX = (SizeOfPartitionEntry * GptPartitionIndicator) / BLOCK_SIZE
+ andl $BLOCK_MASK, %edx # EDX = Targer PartitionEntryLBA Offset
+ # = (SizeOfPartitionEntry * GptPartitionIndicator) % BLOCK_SIZE
+ pushl %edx
+ movl %es:72(%di), %ecx # ECX = PartitionEntryLBA (Low)
+ movl %es:76(%di), %ebx # EBX = PartitionEntryLBA (High)
+ addl %ecx, %eax # EAX = Target PartitionEntryLBA (Low)
+ # = (PartitionEntryLBA +
+ # (SizeOfPartitionEntry * GptPartitionIndicator) / BLOCK_SIZE)
+ adcl %ebx, %edx # EDX = Target PartitionEntryLBA (High)
+
+ movw $0xA00, %di # Read to 0x0000:0x0A00
+ movw $1, %bx # Read 1 Block
+ pushw %es
+ call ReadBlocks
+ popw %es
+
+# ****************************************************************************
+# Read Target DBR from hard disk to 0x0000:0x7C00
+# ****************************************************************************
+ popl %edx # EDX = (SizeOfPartitionEntry * GptPartitionIndicator) % BLOCK_SIZE
+ addw %dx, %di # DI = Targer PartitionEntryLBA Offset
+ cmpl $0xC12A7328, %es:(%di) # Check for EFI System Partition "C12A7328-F81F-11d2-BA4B-00A0C93EC93B"
+ jne BadGpt
+ cmpl $0x11d2F81F, %es:4(%di) #
+ jne BadGpt
+ cmpl $0xA0004BBA, %es:8(%di) #
+ jne BadGpt
+ cmpl $0x3BC93EC9, %es:0xc(%di) #
+ jne BadGpt
+
+ movl %es:32(%di), %eax # EAX = StartingLBA (Low)
+ movl %es:36(%di), %edx # EDX = StartingLBA (High)
+ movw $0x7C00, %di # Read to 0x0000:0x7C00
+ movw $1, %bx # Read 1 Block
+ call ReadBlocks
+
+# ****************************************************************************
+# Transfer control to BootSector - Jump to 0x0000:0x7C00
+# ****************************************************************************
+ xorw %ax, %ax
+ pushw %ax # PUSH 0x0000
+ movw $0x7c00, %di
+ pushw %di # PUSH 0x7C00
+ retl # JMP 0x0000:0x7C00
+
+# ****************************************************************************
+# ReadBlocks - Reads a set of blocks from a block device
+#
+# EDX:EAX = Start LBA
+# BX = Number of Blocks to Read (must < 127)
+# ES:DI = Buffer to store sectors read from disk
+# ****************************************************************************
+
+# si = DiskAddressPacket
+
+ReadBlocks:
+ pushal
+ pushw %ds
+ xorw %cx, %cx
+ movw %cx, %ds
+ movw $0x600, %bp # bp = 0x600
+ leaw AddressPacket(%bp), %si
+ movb %bl, %ds:2(%si) # 02 = Number Of Block transfered
+ movw %di, %ds:4(%si) # 04 = Transfer Buffer Offset
+ movw %es, %ds:6(%si) # 06 = Transfer Buffer Segment
+ movl %eax, %ds:8(%si) # 08 = Starting LBA (Low)
+ movl %edx, %ds:0xc(%si) # 0C = Starting LBA (High)
+ movb $0x42, %ah # ah = Function 42
+ movb PhysicalDrive(%bp), %dl # dl = Drive Number
+ int $0x13
+ jc BadGpt
+ popw %ds
+ popal
+ ret
+
+# ****************************************************************************
+# Address Packet used by ReadBlocks
+# ****************************************************************************
+AddressPacket:
+ .byte 0x10 # Size of address packet
+ .byte 0x0 # Reserved. Must be 0
+ .byte 0x1 # Read blocks at a time (To be fixed each times)
+ .byte 0x0 # Reserved. Must be 0
+ .word 0x000 # Destination Address offset (To be fixed each times)
+ .word 0x000 # Destination Address segment (To be fixed each times)
+AddressPacketLba:
+ .long 0x0,0x0 # Start LBA (To be fixed each times)
+AddressPacketEnd:
+
+# ****************************************************************************
+# ERROR Condition:
+# ****************************************************************************
+
+BadGpt:
+ movw $0xb800, %ax
+ movw %ax, %es
+ movw $0x60, %ax
+ movw %ax, %ds
+ leaw %cs:ErrorString, %si
+ movw $10, %cx
+ movw $320, %di
+ rep
+ movsw
+Halt:
+ jmp Halt
+
+StartString:
+ .byte 'G', 0x0c, 'P', 0x0c, 'T', 0x0c, ' ', 0x0c, 'S', 0x0c, 't', 0x0c, 'a', 0x0c, 'r', 0x0c, 't', 0x0c, '!', 0x0c
+ErrorString:
+ .byte 'G', 0x0c, 'P', 0x0c, 'T', 0x0c, ' ', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, 'o', 0x0c, 'r', 0x0c, '!', 0x0c
+
+# ****************************************************************************
+# PhysicalDrive - Used to indicate which disk to be boot
+# Can be patched by tool
+# ****************************************************************************
+ .org 0x01B6
+PhysicalDrive: .byte 0x80
+
+# ****************************************************************************
+# GptPartitionIndicator - Used to indicate which GPT partition to be boot
+# Can be patched by tool
+# ****************************************************************************
+ .org 0x01B7
+GptPartitionIndicator: .byte 0
+
+# ****************************************************************************
+# Unique MBR signature
+# ****************************************************************************
+ .org 0x01B8
+ .ascii "DUET"
+
+# ****************************************************************************
+# Unknown
+# ****************************************************************************
+ .org 0x01BC
+ .word 0
+
+# ****************************************************************************
+# PMBR Entry - Can be patched by tool
+# ****************************************************************************
+ .org 0x01BE
+ .byte 0 # Boot Indicator
+ .byte 0xff # Start Header
+ .byte 0xff # Start Sector
+ .byte 0xff # Start Track
+ .byte 0xee # OS Type
+ .byte 0xff # End Header
+ .byte 0xff # End Sector
+ .byte 0xff # End Track
+ .long 1 # Starting LBA
+ .long 0xFFFFFFFF # End LBA
+
+ .org 0x01CE
+ .long 0,0,0,0
+ .org 0x01DE
+ .long 0,0,0,0
+ .org 0x01EE
+ .long 0,0,0,0
+
+# ****************************************************************************
+# Sector Signature
+# ****************************************************************************
+
+ .org 0x01FE
+SectorSignature:
+ .word 0xaa55 # Boot Sector Signature
+
+
+
diff --git a/DuetPkg/BootSector/bs32.S b/DuetPkg/BootSector/bs32.S new file mode 100644 index 0000000000..5d876739f9 --- /dev/null +++ b/DuetPkg/BootSector/bs32.S @@ -0,0 +1,310 @@ +#------------------------------------------------------------------------------
+#*
+#* Copyright 2006 - 2007, Intel Corporation
+#* All rights reserved. This program and the accompanying materials
+#* are licensed and made available under the terms and conditions of the BSD License
+#* which accompanies this distribution. The full text of the license may be found at
+#* http://opensource.org/licenses/bsd-license.php
+#*
+#* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#*
+#* bs32.asm
+#*
+#* Abstract:
+#*
+#------------------------------------------------------------------------------
+
+ #.MODEL small
+ .stack:
+ .486p:
+ .code:
+
+.equ FAT_DIRECTORY_ENTRY_SIZE, 0x0020
+.equ FAT_DIRECTORY_ENTRY_SHIFT, 5
+.equ BLOCK_SIZE, 0x0200
+.equ BLOCK_MASK, 0x01ff
+.equ BLOCK_SHIFT, 9
+ # "EFILDR_____"
+.equ LOADER_FILENAME_PART1, 0x4c494645 # "EFIL"
+.equ LOADER_FILENAME_PART2, 0x30325244 # "DR20"
+.equ LOADER_FILENAME_PART3, 0x20202030 # "0___"
+
+ .org 0x00
+Ia32Jump:
+ jmp BootSectorEntryPoint # JMP inst - 3 bytes
+ nop
+
+OemId: .ascii "INTEL " # OemId - 8 bytes
+# BPB data below will be fixed by tool
+SectorSize: .word 0 # Sector Size - 16 bits
+SectorsPerCluster: .byte 0 # Sector Per Cluster - 8 bits
+ReservedSectors: .word 0 # Reserved Sectors - 16 bits
+NoFats: .byte 0 # Number of FATs - 8 bits
+RootEntries: .word 0 # Root Entries - 16 bits
+Sectors: .word 0 # Number of Sectors - 16 bits
+Media: .byte 0 # Media - 8 bits - ignored
+SectorsPerFat: .word 0 # Sectors Per FAT - 16 bits
+SectorsPerTrack: .word 0 # Sectors Per Track - 16 bits - ignored
+Heads: .word 0 # Heads - 16 bits - ignored
+HiddenSectors: .long 0 # Hidden Sectors - 32 bits - ignored
+LargeSectors: .long 0 # Large Sectors - 32 bits
+
+#******************************************************************************
+#
+#The structure for FAT32 starting at offset 36 of the boot sector. (At this point,
+#the BPB/boot sector for FAT12 and FAT16 differs from the BPB/boot sector for FAT32.)
+#
+#******************************************************************************
+
+SectorsPerFat32: .long 0 # Sectors Per FAT for FAT32 - 4 bytes
+ExtFlags: .word 0 # Mirror Flag - 2 bytes
+FSVersion: .word 0 # File System Version - 2 bytes
+RootCluster: .long 0 # 1st Cluster Number of Root Dir - 4 bytes
+FSInfo: .word 0 # Sector Number of FSINFO - 2 bytes
+BkBootSector: .word 0 # Sector Number of Bk BootSector - 2 bytes
+Reserved: .fill 12, 1, 0 # Reserved Field - 12 bytes
+PhysicalDrive: .byte 0 # Physical Drive Number - 1 byte
+Reserved1: .byte 0 # Reserved Field - 1 byte
+Signature: .byte 0 # Extended Boot Signature - 1 byte
+VolId: .ascii " " # Volume Serial Number - 4 bytes
+FatLabel: .ascii " " # Volume Label - 11 bytes
+FileSystemType: .ascii "FAT32 " # File System Type - 8 bytes
+BootSectorEntryPoint:
+ #ASSUME ds:@code
+ #ASSUME ss:@code
+
+# ****************************************************************************
+# Start Print
+# ****************************************************************************
+ leaw %cs:StartString, %si
+ call PrintString
+
+# ****************************************************************************
+# Print over
+# ****************************************************************************
+
+ movw %cs, %ax # ax = 0
+ movw %ax, %ss # ss = 0
+ addw $0x1000, %ax
+ movw %ax, %ds
+
+ movw $0x7c00, %sp # sp = 0x7c00
+ movw %sp, %bp # bp = 0x7c00
+
+ movb $8, %ah # ah = 8 - Get Drive Parameters Function
+ movb %dl, PhysicalDrive(%bp) # BBS defines that BIOS would pass the booting driver number to the loader through DL
+ int $0x13 # Get Drive Parameters
+ xorw %ax, %ax # ax = 0
+ movb %dh, %al # al = dh
+ incb %al # MaxHead = al + 1
+ pushw %ax # 0000:7bfe = MaxHead
+ movb %cl, %al # al = cl
+ andb $0x3f, %al # MaxSector = al & 0x3f
+ pushw %ax # 0000:7bfc = MaxSector
+
+ cmpw $0xaa55, SectorSignature(%bp) # Verify Boot Sector Signature
+ jne BadBootSector
+ movw RootEntries(%bp), %cx # cx = RootEntries
+ shlw $FAT_DIRECTORY_ENTRY_SHIFT, %cx # cx = cx * 32 = cx * sizeof(FAT_DIRECTORY_ENTRY) = Size of Root Directory in bytes
+ movw %cx, %bx # bx = size of the Root Directory in bytes
+ andw $BLOCK_MASK, %bx # See if it is an even number of sectors long
+ jne BadBootSector # If is isn't, then the boot sector is bad.
+ movw %cx, %bx # bx = size of the Root Directory in bytes
+ shrw $BLOCK_SHIFT, %bx # bx = size of Root Directory in sectors
+ movb NoFats(%bp), %al # al = NoFats
+ xorb %ah, %ah # ah = 0 ==> ax = NoFats
+ mulw SectorsPerFat32(%bp) # ax = NoFats * SectorsPerFat
+ addw ReservedSectors(%bp), %ax # ax = NoFats * SectorsPerFat + ReservedSectors = RootLBA
+ addw %bx, %ax # ax = NoFats * SectorsPerFat + ReservedSectors + RootDirSectors = FirstClusterLBA
+ movw %ax, (%bp) # Save FirstClusterLBA for later use
+
+ movw RootCluster(%bp), %ax # ax = StartCluster of Root Directory
+ subw $2, %ax # ax = StartCluster - 2
+ xorb %bh, %bh
+ movb SectorsPerCluster(%bp), %bl # bx = SectorsPerCluster
+ mulw %bx # ax = (StartCluster - 2) * SectorsPerCluster
+ addw (%bp), %ax # ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
+ pushw %ds
+ popw %es
+ xorw %di, %di # Store directory in es:di = 1000:0000
+ call ReadBlocks # Read StartCluster of Root Directory
+
+ # dx - variable storage (initial value is 0)
+ # bx - loader (initial value is 0)
+ xorw %dx, %dx
+ xorw %bx, %bx
+
+FindEFILDR:
+ cmpl $LOADER_FILENAME_PART1, (%di)
+ jne FindVARSTORE
+ cmpl $LOADER_FILENAME_PART2, 4(%di)
+ jne FindVARSTORE
+ cmpl $LOADER_FILENAME_PART3, 7(%di)
+ jne FindVARSTORE
+ movw 26(%di), %bx # bx = Start Cluster for EFILDR <----------------------------------
+ testw %dx, %dx
+ je FindNext # Efivar.bin is not loaded
+ jmp FoundAll
+
+FindVARSTORE:
+ # if the file is not loader file, see if it's "EFIVAR BIN"
+ cmpl $0x56494645, (%di) # Compare to "EFIV"
+ jne FindNext
+ cmpl $0x20205241, 4(%di) # Compare to "AR "
+ jne FindNext
+ cmpl $0x4e494220, 7(%di) # Compare to " BIN"
+ jne FindNext
+ movw %di, %dx # dx = Offset of Start Cluster for Efivar.bin <---------------------
+ addw $26, %dx
+ testw %bx, %bx
+ je FindNext # Efildr is not loaded
+ jmp FoundAll
+
+FindNext:
+ # go to next find
+ addw $FAT_DIRECTORY_ENTRY_SIZE, %di # Increment di
+ subw $FAT_DIRECTORY_ENTRY_SIZE, %cx # Decrement cx
+ # TODO: jump to FindVarStore if ...
+ jne FindEFILDR
+ jmp NotFoundAll
+
+FoundAll:
+FoundEFILDR:
+ movw %bx, %cx # cx = Start Cluster for EFILDR <----------------------------------
+ movw %cs, %ax # Destination = 2000:0000
+ addw $0x2000, %ax
+ movw %ax, %es
+ xorw %di, %di
+ReadFirstClusterOfEFILDR:
+ movw %cx, %ax # ax = StartCluster
+ subw $2, %ax # ax = StartCluster - 2
+ xorb %bh, %bh
+ movb SectorsPerCluster(%bp), %bl # bx = SectorsPerCluster
+ pushw %dx
+ mulw %bx
+ popw %dx # ax = (StartCluster - 2) * SectorsPerCluster
+ addw (%bp), %ax # ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
+ xorb %bh, %bh
+ movb SectorsPerCluster(%bp), %bl # bx = Number of Sectors in a cluster
+ pushw %es
+ call ReadBlocks
+ popw %ax
+JumpIntoFirstSectorOfEFILDR:
+ movw %ax, JumpSegment(%bp)
+JumpFarInstruction:
+ .byte 0xea
+JumpOffset:
+ .word 0x000
+JumpSegment:
+ .word 0x2000
+
+
+PrintString:
+ movw $0xb800, %ax
+ movw %ax, %es
+ movw $0x7c0, %ax
+ movw %ax, %ds
+ movw $7, %cx
+ movw $160, %di
+ rep
+ movsw
+ ret
+# ****************************************************************************
+# ReadBlocks - Reads a set of blocks from a block device
+#
+# AX = Start LBA
+# BX = Number of Blocks to Read
+# ES:DI = Buffer to store sectors read from disk
+# ****************************************************************************
+
+# cx = Blocks
+# bx = NumberOfBlocks
+# si = StartLBA
+
+ReadBlocks:
+ pusha
+ addl LBAOffsetForBootSector(%bp), %eax # Add LBAOffsetForBootSector to Start LBA
+ addl HiddenSectors(%bp), %eax # Add HiddenSectors to Start LBA
+ movl %eax, %esi # esi = Start LBA
+ movw %bx, %cx # cx = Number of blocks to read
+ReadCylinderLoop:
+ movw $0x7bfc, %bp # bp = 0x7bfc
+ movl %esi, %eax # eax = Start LBA
+ xorl %edx, %edx # edx = 0
+ movzwl (%bp), %ebx # bx = MaxSector
+ divl %ebx # ax = StartLBA / MaxSector
+ incw %dx # dx = (StartLBA % MaxSector) + 1
+ subw %dx, %bx # bx = MaxSector - Sector
+ incw %bx # bx = MaxSector - Sector + 1
+ cmpw %bx, %cx # Compare (Blocks) to (MaxSector - Sector + 1)
+ jg LimitTransfer
+ movw %cx, %bx # bx = Blocks
+LimitTransfer:
+ pushw %cx
+ movb %dl, %cl # cl = (StartLBA % MaxSector) + 1 = Sector
+ xorw %dx, %dx # dx = 0
+ divw 2(%bp) # ax = ax / (MaxHead + 1) = Cylinder
+ # dx = ax % (MaxHead + 1) = Head
+
+ pushw %bx # Save number of blocks to transfer
+ movb %dl, %dh # dh = Head
+ movw $0x7c00, %bp # bp = 0x7c00
+ movb PhysicalDrive(%bp), %dl # dl = Drive Number
+ movb %al, %ch # ch = Cylinder
+ movb %bl, %al # al = Blocks
+ movb $2, %ah # ah = Function 2
+ movw %di, %bx # es:bx = Buffer address
+ int $0x13
+ jc DiskError
+ popw %bx
+ popw %cx
+ movzwl %bx, %ebx
+ addl %ebx, %esi # StartLBA = StartLBA + NumberOfBlocks
+ subw %bx, %cx # Blocks = Blocks - NumberOfBlocks
+ movw %es, %ax
+ shlw $(BLOCK_SHIFT-4), %bx
+ addw %bx, %ax
+ movw %ax, %es # es:di = es:di + NumberOfBlocks*BLOCK_SIZE
+ cmpw $0, %cx
+ jne ReadCylinderLoop
+ popa
+ ret
+
+# ****************************************************************************
+# ERROR Condition:
+# ****************************************************************************
+NotFoundAll:
+ # if we found EFILDR, continue
+ testw %bx, %bx
+ jne FoundEFILDR
+BadBootSector:
+DiskError:
+ leaw %cs:ErrorString, %si
+ call PrintString
+Halt:
+ jmp Halt
+
+StartString:
+ .byte 'B', 0x0c, 'S', 0x0c, 't', 0x0c, 'a', 0x0c, 'r', 0x0c, 't', 0x0c, '!', 0x0c
+ErrorString:
+ .byte 'B', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, 'o', 0x0c, 'r', 0x0c, '!', 0x0c
+
+# ****************************************************************************
+# LBA Offset for BootSector, need patched by tool for HD boot.
+# ****************************************************************************
+
+ .org 0x01fa
+LBAOffsetForBootSector:
+ .long 0x0
+
+# ****************************************************************************
+# Sector Signature
+# ****************************************************************************
+
+ .org 0x01fe
+SectorSignature:
+ .word 0xaa55 # Boot Sector Signature
+
+
+
|