]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Port Intel .asm to GNU .S
authorjji4 <jji4@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 20 Feb 2009 03:01:49 +0000 (03:01 +0000)
committerjji4 <jji4@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 20 Feb 2009 03:01:49 +0000 (03:01 +0000)
These .S files now is not for compiler but for us to control the version.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7548 6f19259b-4bc3-4df7-8a09-765794883524

DuetPkg/BootSector/BootSector.inf
DuetPkg/BootSector/Gpt.S [new file with mode: 0644]
DuetPkg/BootSector/bs32.S [new file with mode: 0644]

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