Index: trunk/bootcode/regular/driveio.asm
===================================================================
--- trunk/bootcode/regular/driveio.asm	(revision 151)
+++ trunk/bootcode/regular/driveio.asm	(revision 152)
@@ -382,5 +382,5 @@
 
 IFDEF   AUX_DEBUG
-        IF 1
+        IF 0
         DBG_TEXT_OUT_AUX    'DriveIO_LoadLVMSector:'
         PUSHRF
@@ -414,4 +414,60 @@
         mov     cx, wptr cs:[CurPartition_Location+6]   ; BIOS cyl & sec
 
+        ; Do the actual loading.
+        ; This is in a separate function so that LVM records can also be
+        ; loaded using the MBR/EBR LBA addresses from IPT entries.
+        call    DriveIO_LoadLVMSectorXBR
+        jc      DIOLLVMS_NoLVMSector
+
+        ; We're done, indicate success and return
+        clc
+        jmp     DIOLLVMS_Done
+
+    DIOLLVMS_NoLVMSector:
+
+        ; Clear the sector buffer
+        mov     si, offset [LVMSector]
+        call    ClearSectorBuffer
+        mov     bptr [si+LocLVM_SignatureStart], 0
+
+        ; Indicate no valid LVM sector was loaded
+        stc
+
+    DIOLLVMS_Done:
+
+        ret
+DriveIO_LoadLVMSector   EndP
+
+
+
+
+
+;------------------------------------------------------------------------------
+; Attempts to load the corresponding LVM sector for a partition
+;------------------------------------------------------------------------------
+; IN    : AX    - LBA lo of MBR or EBR
+;       : BX    - LBA hi of MBR or EBR
+;       ; DL    - BIOS disk number
+;       ; SI    - Pointer to sector buffer (usually [LVMSec])
+; OUT   : CF=0  - A valid LVM sector was loaded
+; NOTE  : LocIPT_AbsolutePartTable and LocIPT_Drive can provide LBA and DISK
+;------------------------------------------------------------------------------
+DriveIO_LoadLVMSectorXBR    Proc    Near
+
+IFDEF   AUX_DEBUG
+        IF 1
+        DBG_TEXT_OUT_AUX    'DriveIO_LoadLVMSectorXBR:'
+        PUSHRF
+            call    DEBUG_DumpRegisters
+            ;~ call    AuxIO_DumpSector
+            ;~ call    AuxIO_DumpParagraph
+            ;~ call    AuxIO_TeletypeNL
+        POPRF
+        ENDIF
+ENDIF
+
+        ; Save all registers
+        pusha
+
         ; Calculate the entry in the DISKINFO array for this disk,
         ; and put the LVM_SPT in DI
@@ -423,5 +479,5 @@
         ; If the LVM_SPT is ZERO, no LVM info is present and we quit with CY
         test    di, di                          ; See if it is 0
-        jz      DIOLLVMS_NoLVMSector            ; Quit if so
+        jz      DriveIO_LoadLVMSectorXBR_no_lvm ; Quit if so
 
         ; Adjust the location to point to the LVM sector
@@ -431,6 +487,5 @@
         sbb     bx, 0       ; Propagate borrow to LBA hi
 
-        ; Load the LVM sector into [LVMSector]
-        mov     si, offset [LVMSector]          ; Points to sector buffer
+        ; Load the LVM sector into sector buffer pointed to by SI
         mov     di, ds                          ; Segment of that buffer
         call    DriveIO_ReadSectorLBA           ; Read the LVM sector
@@ -441,5 +496,11 @@
         PUSHRF
             call    DEBUG_DumpRegisters
-            call    AuxIO_DumpSector
+            ;~ call    AuxIO_DumpSector
+            mov     cx, 3
+        @@:
+            call    AuxIO_DumpParagraph
+            call    AuxIO_TeletypeNL
+            add     si, 16
+            loop @B
             ;~ call    AuxIO_DumpParagraph
             ;~ call    AuxIO_TeletypeNL
@@ -448,29 +509,24 @@
 ENDIF
 
-        jc      DIOLLVMS_NoLVMSector            ; Quit on error
+        jc      DriveIO_LoadLVMSectorXBR_no_lvm ; Quit on error
 
         ; Check the validity of the LVM sector, quit with CY if invalid
         call    LVM_ValidateSector              ; Check signature and CRC
-        jnc     DIOLLVMS_NoLVMSector            ; Quit if not valid
+        jnc     DriveIO_LoadLVMSectorXBR_no_lvm ; Quit if not valid
 
         ; We're done, indicate success and return
         clc
-        jmp     DIOLLVMS_Done
-
-    DIOLLVMS_NoLVMSector:
-
-        ; Clear the sector buffer
-        mov     si, offset [LVMSector]
-        call    ClearSectorBuffer
-        mov     bptr [si+LocLVM_SignatureStart], 0
-
+        jmp     DriveIO_LoadLVMSectorXBR_done
+
+    DriveIO_LoadLVMSectorXBR_no_lvm:
         ; Indicate no valid LVM sector was loaded
         stc
 
-    DIOLLVMS_Done:
-
-        ret
-DriveIO_LoadLVMSector   EndP
-
+    DriveIO_LoadLVMSectorXBR_done:
+        ; Restore all registers
+        popa
+
+        ret
+DriveIO_LoadLVMSectorXBR    EndP
 
 
@@ -501,5 +557,5 @@
 
 IFDEF   AUX_DEBUG
-        IF 1
+        IF 0
         DBG_TEXT_OUT_AUX    'DriveIO_SaveLVMSector:'
         PUSHRF
@@ -513,9 +569,5 @@
         ; Quit with CY if LVM is ignored in SETUP
         test    byte ptr [CFG_IgnoreLVM], 1     ; ZF=0 means ignore LVM
-        jnz     DIOSLVMS_SevereError            ; Quit if so
-
-        ; Check the validity of the LVM sector, quit with CY if invalid
-        call    LVM_ValidateSector              ; Check signature and CRC
-        jnc     DIOSLVMS_SevereError            ; Quit if not valid
+        jnz     DIOSLVMS_NoLVMSector            ; Quit if so
 
         ; Load the location of the current partition being acted upon.
@@ -532,4 +584,44 @@
         mov     cx, wptr cs:[CurPartition_Location+6]   ; BIOS cyl & sec
 
+        ; Do the actual saving.
+        ; This is in a separate function so that LVM records can also be
+        ; saved using the MBR/EBR LBA addresses from IPT entries.
+        call    DriveIO_SaveLVMSectorXBR
+        jc      DIOSLVMS_NoLVMSector
+
+        ; We're done, indicate success and return
+        clc
+        jmp     DIOSLVMS_Done
+
+    DIOSLVMS_NoLVMSector:
+        ; Indicate no valid LVM sector was saved
+        stc
+
+    DIOSLVMS_Done:
+        ret
+DriveIO_SaveLVMSector   EndP
+
+
+;------------------------------------------------------------------------------
+; Attempts to save the corresponding LVM sector for a partition
+;------------------------------------------------------------------------------
+; IN    : AX    - LBA lo of MBR or EBR
+;       : BX    - LBA hi of MBR or EBR
+;       ; DL    - BIOS disk number
+;       ; SI    - Pointer to sector buffer (usually [LVMSec])
+; OUT   : CF=0  - A valid LVM sector was saved
+; NOTE  : LocIPT_AbsolutePartTable and LocIPT_Drive can provide LBA and DISK
+;------------------------------------------------------------------------------
+DriveIO_SaveLVMSectorXBR    Proc    Near
+
+        ; Save all registers
+        pusha
+
+        ; Check the validity of the LVM sector, quit with CY if invalid
+        push    ax                              ; Save LBA lo
+        call    LVM_ValidateSector              ; Check signature and CRC
+        pop     ax                              ; Restore LBA lo
+        jnc     DriveIO_SaveLVMSectorXBR_no_lvm ; Quit if not valid
+
         ; Calculate the entry in the DISKINFO array for this disk,
         ; and put the LVM_SPT in DI
@@ -541,5 +633,5 @@
         ; If the LVM_SPT is ZERO, no LVM info is present and we quit with CY
         test    di, di                          ; See if it is 0
-        jz      DIOSLVMS_SevereError            ; Quit if so
+        jz      DriveIO_SaveLVMSectorXBR_no_lvm ; Quit if so
 
         ; Adjust the location to point to the LVM sector
@@ -549,4 +641,8 @@
         sbb     bx, 0       ; Propagate borrow to LBA hi
 
+        ; Save the LVM sector pointed to by SI
+        mov     di, ds                          ; Segment of that buffer
+        call    DriveIO_WriteSectorLBA          ; Read the LVM sector
+
 IFDEF   AUX_DEBUG
         IF 1
@@ -561,21 +657,20 @@
 ENDIF
 
-        ; Save the LVM sector pointed to by SI
-        mov     di, ds                          ; Segment of that buffer
-        call    DriveIO_WriteSectorLBA          ; Read the LVM sector
-        clc
-        jc      DIOSLVMS_SevereError            ; Quit on error
+        jc      DriveIO_SaveLVMSectorXBR_no_lvm ; Quit on error
 
         ; We're done, indicate success and return
         clc
-        jmp     DIOSLVMS_Done
-
-    DIOSLVMS_SevereError:
-        ; Indicate no valid LVM sector was saved
+        jmp     DriveIO_SaveLVMSectorXBR_done
+
+    DriveIO_SaveLVMSectorXBR_no_lvm:
+        ; Indicate no valid LVM sector was loaded
         stc
 
-    DIOSLVMS_Done:
-        ret
-DriveIO_SaveLVMSector   EndP
+    DriveIO_SaveLVMSectorXBR_done:
+        ; Restore all registers
+        popa
+
+        ret
+DriveIO_SaveLVMSectorXBR    EndP
 
 
