strreplace: clean up and simplify
[profile/ivi/syslinux.git] / core / adv.inc
index c1a2628..0b45a6c 100644 (file)
@@ -67,24 +67,20 @@ adv_init:
                cmp byte [ADVDrive],-1
                jne adv_read
 
-;%if IS_SYSLINUX || IS_MDSLINUX || IS_EXTLINUX
-%if IS_EXTLINUX                ; Not yet implemented for the other derivatives
-               ;
-               ; Update pointers to default ADVs...
-               ;
-               mov bx,[LDLSectors]
-               shl bx,2
-               mov ecx,[bsHidden]
-               mov eax,[bx+SectorPtrs-8]
-               mov edx,[bx+SectorPtrs-4]
-               add eax,ecx
-               add edx,ecx
-               mov [ADVSec0],eax
-               mov [ADVSec1],edx
+%if IS_SYSLINUX || IS_EXTLINUX
+               cmp word [ADVSectors],2         ; Not present?
+               jb adv_verify
+
+               mov eax,[Hidden]
+               mov edx,[Hidden+4]
+               add [ADVSec0],eax
+               adc [ADVSec0+4],edx
+               add [ADVSec1],eax
+               adc [ADVSec1+4],edx
                mov al,[DriveNumber]
                mov [ADVDrive],al
+               jmp adv_read
 %endif
-               ; ** fall through to adv_verify **
 
                ;
                ; Initialize the ADV data structure in memory
@@ -298,23 +294,26 @@ adv_cleanup:
 ;              Returns CF=1 if the ADV cannot be written.
 ;
 adv_write:
-               cmp dword [ADVSec0],0
+               push eax
+               mov eax,[ADVSec0]
+               or eax,[ADVSec0+4]
                je .bad
-               cmp dword [ADVSec1],0
+               mov eax,[ADVSec1]
+               or eax,[ADVSec1+4]
                je .bad
                cmp byte [ADVDrive],-1
                je .bad
 
-               push ax
                call adv_cleanup
                mov ah,3                        ; Write
                call adv_read_write
-               pop ax
 
                clc
+               pop eax
                ret
 .bad:                                          ; No location for ADV set
                stc
+               pop eax
                ret
 
 ;
@@ -356,10 +355,12 @@ adv_read_write:
 .noedd:
 
                mov eax,[ADVSec0]
+               mov edx,[ADVSec0+4]
                mov bx,adv0
                call .doone
 
                mov eax,[ADVSec1]
+               mov edx,[ADVSec1+4]
                mov bx,adv1
                call .doone
 
@@ -367,7 +368,6 @@ adv_read_write:
                ret
 
 .doone:
-               xor edx,edx                     ; Zero-extend LBA
                push si
                jmp si
 
@@ -407,6 +407,9 @@ adv_read_write:
                push eax
                push bp
 
+               and edx,edx                     ; > 2 TiB not possible
+               jnz .cb_overflow
+
                mov dl,[ADVDrive]
                and dl,dl
                ; Floppies: can't trust INT 13h 08h, we better know
@@ -443,6 +446,7 @@ adv_read_write:
                 ; Dividing by sectors to get (track,sector): we may have
                 ; up to 2^18 tracks, so we need to use 32-bit arithmetric.
                 ;
+               xor edx,edx
                 div esi
                 xor cx,cx
                 xchg cx,dx              ; CX <- sector index (0-based)
@@ -493,11 +497,13 @@ adv_read_write:
                jmp .cb_done
 
                section .data16
-               alignz 4
-ADVSec0                dd 0                    ; Not specified
-ADVSec1                dd 0                    ; Not specified
+               alignz 8
+ADVSec0                dq 0                    ; Not specified
+ADVSec1                dq 0                    ; Not specified
 ADVDrive       db -1                   ; No ADV defined
 ADVCHSInfo     db -1                   ; We have CHS info for this drive
 
                section .bss16
 ADVOp          resb 1
+
+               section .text16