]> git.proxmox.com Git - mirror_edk2.git/blobdiff - DuetPkg/BootSector/Mbr.S
Make end of line consistent for DuetPkg. There is no other update.
[mirror_edk2.git] / DuetPkg / BootSector / Mbr.S
index 74852681f8b9c5d6d9dc409ead02f9aef989934b..a2431e19319bf0a831bfad3aa8db0bf977a9906c 100644 (file)
-#------------------------------------------------------------------------------
-#*
-#*   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.
-#*
-#*    Mbr.asm
-#*
-#*   Abstract:
-#*
-#------------------------------------------------------------------------------
-
-.equ                      BLOCK_SIZE, 0x0200
-.equ                      BLOCK_MASK, 0x01ff
-.equ                      BLOCK_SHIFT, 9
-
-# ****************************************************************************
-# Code loaded by BIOS at 0x0000:0x7C00
-# ****************************************************************************
-
-.org 0x0
-
+#------------------------------------------------------------------------------\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
+#*    Mbr.asm\r
+#*\r
+#*   Abstract:\r
+#*\r
+#------------------------------------------------------------------------------\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 0x0\r
+\r
 .global _start\r
-_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 Target DBR from hard disk to 0x0000:0x7C00
-# ****************************************************************************
-
-        xorw  %ax, %ax
-        movb  MbrPartitionIndicator(%bp), %al          # AX = MbrPartitionIndex
-        cmpb  $0xff, %al                               # 0xFF means do legacy MBR boot
-        jnz   EfiDbr
-LegacyMbr: 
-        movl  $0x0000600, %eax                    # Assume LegacyMBR is backuped in Sector 6
-        jmp   StartReadTo7C00                     # EAX = Header/Sector/Tracker/Zero
-
-EfiDbr: 
-        cmpb  $4, %al                             # MbrPartitionIndex should < 4
-        jae   BadDbr
-        shlw  $4, %ax                             # AX  = MBREntrySize * Index
-        addw  $0x1be, %ax                         # AX  = MBREntryOffset
-        movw  %ax, %di                            # DI  = MBREntryOffset
-
-        # Here we don't use the C/H/S information provided by Partition table
-        #  but calculate C/H/S from LBA ourselves
-        #       Ci: Cylinder number
-        #       Hi: Header number
-        #       Si: Sector number
-        movl  %es:8(%bp,%di,), %eax               # Start LBA
-        movl  %eax, %edx
-        shrl  $16, %edx                           # DX:AX = Start LBA
-                                                  #       = Ci * (H * S) + Hi * S + (Si - 1)
-
-        # Calculate C/H/S according to LBA
-        movw  $0x7bfa, %bp
-        divw  2(%bp)                              # AX = Hi + H*Ci
-                                                  # DX = Si - 1
-        incw  %dx                                 # DX = Si
-        pushw %dx                                 # 0000:7bfa = Si  <----
-        xorw  %dx, %dx                            # DX:AX = Hi + H*Ci
-        divw  4(%bp)                              # AX = Ci         <----
-                                                  # DX = Hi         <----
-
-StartReadTo7C00: 
-
-        movb  (%bp), %cl                          # Si
-        movb  %al, %ch                            # Ci[0-7]
-        orb   %ah, %cl                            # Ci[8,9]
-        movw  $0x7c00, %bx                        # ES:BX = 0000:7C00h
-        movb  $0x2, %ah                           # Function 02h
-        movb  $1, %al                             # 1 Sector
-        movb  %dl, %dh                            # Hi
-        movw  $0x600, %bp
-        movb  PhysicalDrive(%bp), %dl             # Drive number
-        int   $0x13
-        jc    BadDbr
-
-
-
-# ****************************************************************************
-# Transfer control to BootSector - Jump to 0x0000:0x7C00
-# ****************************************************************************
-        xorw  %ax, %ax
-        pushw %ax                                 # PUSH 0x0000 - Segment
-        movw  $0x7c00, %di
-        pushw %di                                 # PUSH 0x7C00 - Offset
-        retl                                      # JMP 0x0000:0x7C00
-
-# ****************************************************************************
-# ERROR Condition:
-# ****************************************************************************
-
-BadDbr: 
-    pushw %ax
-    movw $0xb800, %ax
-    movw %ax, %es
-    movw $0x60, %ax
-    movw %ax, %ds
-    leaw %cs:ErrorString, %si
-    movw $320, %di
-    popw %ax
-    call A2C
-    movb %ah, 16(%si)
-    movb %al, 18(%si)
-    movw $10, %cx
-    rep
-    movsw
-Halt: 
-    jmp   Halt
-
-StartString: 
-.byte 'M', 0x0c, 'B', 0x0c, 'R', 0x0c, ' ', 0x0c, 'S', 0x0c, 't', 0x0c, 'a', 0x0c, 'r', 0x0c, 't', 0x0c, '!', 0x0c
-ErrorString: 
-.byte 'M', 0x0c, 'B', 0x0c, 'R', 0x0c, ' ', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, ':', 0x0c, '?', 0x0c, '?', 0x0c
-
-# ****************************************************************************
-# A2C - convert Ascii code stored in AH to character stored in AX
-# ****************************************************************************
-A2C: 
-    movb %ah, %al
-    shrb $4, %ah
-    andb $0xF, %al
-    addb '0', %ah
-    addb '0', %al
-
-    cmpb '9', %ah
-    jle  A2C_L1
-    addb $7, %ah
-A2C_L1: 
-
-    cmpb '9', %al
-    jle A2C_L2
-    addb $7, %al
-A2C_L2: 
-    ret
-
-
-# ****************************************************************************
-# PhysicalDrive - Used to indicate which disk to be boot
-#                 Can be patched by tool
-# ****************************************************************************
-.org   0x01B6
-PhysicalDrive:        .byte 0x80
-
-# ****************************************************************************
-# MbrPartitionIndicator - Used to indicate which MBR partition to be boot
-#                         Can be patched by tool
-#                         OxFF means boot to legacy MBR. (LBA OFFSET 6)
-# ****************************************************************************
-.org   0x01B7
-MbrPartitionIndicator: .byte 0
-
-# ****************************************************************************
-# Unique MBR signature
-# ****************************************************************************
-.org   0x01B8
-    .ascii "DUET"
-
-# ****************************************************************************
-# Unknown
-# ****************************************************************************
-.org   0x01BC
-    .word 0
-
-# ****************************************************************************
-# MBR Entry - To be patched
-# ****************************************************************************
-.org   0x01BE
-    .long 0,0,0,0
-.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
-
-
-
+_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
+\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 Target DBR from hard disk to 0x0000:0x7C00\r
+# ****************************************************************************\r
+\r
+        xorw  %ax, %ax\r
+        movb  MbrPartitionIndicator(%bp), %al          # AX = MbrPartitionIndex\r
+        cmpb  $0xff, %al                               # 0xFF means do legacy MBR boot\r
+        jnz   EfiDbr\r
+LegacyMbr: \r
+        movl  $0x0000600, %eax                    # Assume LegacyMBR is backuped in Sector 6\r
+        jmp   StartReadTo7C00                     # EAX = Header/Sector/Tracker/Zero\r
+\r
+EfiDbr: \r
+        cmpb  $4, %al                             # MbrPartitionIndex should < 4\r
+        jae   BadDbr\r
+        shlw  $4, %ax                             # AX  = MBREntrySize * Index\r
+        addw  $0x1be, %ax                         # AX  = MBREntryOffset\r
+        movw  %ax, %di                            # DI  = MBREntryOffset\r
+\r
+        # Here we don't use the C/H/S information provided by Partition table\r
+        #  but calculate C/H/S from LBA ourselves\r
+        #       Ci: Cylinder number\r
+        #       Hi: Header number\r
+        #       Si: Sector number\r
+        movl  %es:8(%bp,%di,), %eax               # Start LBA\r
+        movl  %eax, %edx\r
+        shrl  $16, %edx                           # DX:AX = Start LBA\r
+                                                  #       = Ci * (H * S) + Hi * S + (Si - 1)\r
+\r
+        # Calculate C/H/S according to LBA\r
+        movw  $0x7bfa, %bp\r
+        divw  2(%bp)                              # AX = Hi + H*Ci\r
+                                                  # DX = Si - 1\r
+        incw  %dx                                 # DX = Si\r
+        pushw %dx                                 # 0000:7bfa = Si  <----\r
+        xorw  %dx, %dx                            # DX:AX = Hi + H*Ci\r
+        divw  4(%bp)                              # AX = Ci         <----\r
+                                                  # DX = Hi         <----\r
+\r
+StartReadTo7C00: \r
+\r
+        movb  (%bp), %cl                          # Si\r
+        movb  %al, %ch                            # Ci[0-7]\r
+        orb   %ah, %cl                            # Ci[8,9]\r
+        movw  $0x7c00, %bx                        # ES:BX = 0000:7C00h\r
+        movb  $0x2, %ah                           # Function 02h\r
+        movb  $1, %al                             # 1 Sector\r
+        movb  %dl, %dh                            # Hi\r
+        movw  $0x600, %bp\r
+        movb  PhysicalDrive(%bp), %dl             # Drive number\r
+        int   $0x13\r
+        jc    BadDbr\r
+\r
+\r
+\r
+# ****************************************************************************\r
+# Transfer control to BootSector - Jump to 0x0000:0x7C00\r
+# ****************************************************************************\r
+        xorw  %ax, %ax\r
+        pushw %ax                                 # PUSH 0x0000 - Segment\r
+        movw  $0x7c00, %di\r
+        pushw %di                                 # PUSH 0x7C00 - Offset\r
+        retl                                      # JMP 0x0000:0x7C00\r
+\r
+# ****************************************************************************\r
+# ERROR Condition:\r
+# ****************************************************************************\r
+\r
+BadDbr: \r
+    pushw %ax\r
+    movw $0xb800, %ax\r
+    movw %ax, %es\r
+    movw $0x60, %ax\r
+    movw %ax, %ds\r
+    leaw %cs:ErrorString, %si\r
+    movw $320, %di\r
+    popw %ax\r
+    call A2C\r
+    movb %ah, 16(%si)\r
+    movb %al, 18(%si)\r
+    movw $10, %cx\r
+    rep\r
+    movsw\r
+Halt: \r
+    jmp   Halt\r
+\r
+StartString: \r
+.byte 'M', 0x0c, 'B', 0x0c, 'R', 0x0c, ' ', 0x0c, 'S', 0x0c, 't', 0x0c, 'a', 0x0c, 'r', 0x0c, 't', 0x0c, '!', 0x0c\r
+ErrorString: \r
+.byte 'M', 0x0c, 'B', 0x0c, 'R', 0x0c, ' ', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, ':', 0x0c, '?', 0x0c, '?', 0x0c\r
+\r
+# ****************************************************************************\r
+# A2C - convert Ascii code stored in AH to character stored in AX\r
+# ****************************************************************************\r
+A2C: \r
+    movb %ah, %al\r
+    shrb $4, %ah\r
+    andb $0xF, %al\r
+    addb '0', %ah\r
+    addb '0', %al\r
+\r
+    cmpb '9', %ah\r
+    jle  A2C_L1\r
+    addb $7, %ah\r
+A2C_L1: \r
+\r
+    cmpb '9', %al\r
+    jle A2C_L2\r
+    addb $7, %al\r
+A2C_L2: \r
+    ret\r
+\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
+# MbrPartitionIndicator - Used to indicate which MBR partition to be boot\r
+#                         Can be patched by tool\r
+#                         OxFF means boot to legacy MBR. (LBA OFFSET 6)\r
+# ****************************************************************************\r
+.org   0x01B7\r
+MbrPartitionIndicator: .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
+# MBR Entry - To be patched\r
+# ****************************************************************************\r
+.org   0x01BE\r
+    .long 0,0,0,0\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