Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Decided to rewrite my bootsector for many reasons (loss of source code for bootloaders were one of them)
However, I ran into an issue I can't seem to understand why, there is no further explanation of the problem and it works on all emulators, this error only occurs on real hardware: Error code 02 -> Address mark not found
ReadSector2:
; Error Counter
.Start:
mov di, 5
.sLoop:
; Save states
push ax
push bx
push cx
mov word [DiskPackage.Segment], es
mov word [DiskPackage.Offset], bx
mov word [DiskPackage.Sector], ax
mov word [DiskPackage.SectorsToRead], 1
mov ax, 0x4200
mov dl, byte [bPhysicalDriveNum]
mov si, DiskPackage
int 0x13
jnc .Success
.Fail:
xor ax, ax
int 0x13
dec di
pop cx
pop bx
pop ax
jnz .sLoop
; Give control to next OS, we failed
int 0x18
.Success:
; Next sector
pop cx
pop bx
pop ax
add bx, word [wBytesPerSector]
jno .SkipEs
mov dx, es
add dh, 0x10
mov es, dx
.SkipEs:
inc ax
loop .Start
; Done
ret
; This is used for the extended read function (int 0x13)
DiskPackage: db 0x10
db 0
.SectorsToRead dw 1
.Offset dw 0x0500
.Segment dw 0x0000
.Sector dq 0
The overflow flag is used for signed integer overflow (e.g. when BX goes from +32767 to -32768). For unsigned integer overflow (e.g. when BX goes from +65535 to 0) you want to use the carry flag, or "jnc .SkipEs".
The symptoms ("Error code 02 -> Address mark not found") don't make sense to me. This error means that the BIOS tried to read the sector, but the address mark (that marks the beginning of the sector on the disk track) wasn't found by the disk controller. It's extremely rare for this error to happen for hard drives. For floppy drives (where the "address mark not found" error is actually plausible) you shouldn't be using "int 0x13 extensions" in the first place because the extensions typically aren't supported for floppy drives.
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
I am booting from an USB Disk drive, not using floppy, and my old bootsector did use extended read just like this one, so I know that the drive supports extended read functions, I don't know if that information helps you?
"for example, turning off the system’s power through the movement of a large red switch" - the Advanced Configuration and Power Interface Specification
MollenOS wrote:I am booting from an USB Disk drive,
LBA 0 must contain a valid MBR with a valid partition table with the boot flag set for exactly one entry, and must not contain a BPB. If you do not meet these requirements, some BIOSes will use floppy disk mode, and extended int 13h functions will not work.
Check the value of DL you've received from the BIOS. It will be 80h if the BIOS is using hard disk mode, or 00h if the BIOS is using floppy disk mode.