Page 1 of 1

Int 13h 42h error

Posted: Sat Mar 07, 2015 8:48 am
by MollenOS
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

My readsector function:

Code: Select all

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
And this is my Disk Package:

Code: Select all

; 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

Re: Int 13h 42h error

Posted: Sat Mar 07, 2015 9:46 am
by Octocontrabass
MollenOS wrote:this error only occurs on real hardware:
What device are you booting from?

What does your stack setup look like?

Can you provide a complete set of code that demonstrates the problem?

Re: Int 13h 42h error

Posted: Sat Mar 07, 2015 9:46 am
by Brendan
Hi,

The only real bug I could see is this:

Code: Select all

    add bx, word [wBytesPerSector]
    jno .SkipEs
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

Re: Int 13h 42h error

Posted: Sat Mar 07, 2015 9:58 am
by djmauretto
Have you tried to verify if these extensions are supported by the drive?

Code: Select all

MOV     DL, [bPhysicalDriveNum]
MOV     AH,41h		                  ; EDD INSTALLATION CHECK
MOV     BX,55AAh
INT     13h
JC      @Error	

CMP     BX,0AA55h		; Supported ?
JNZ     @Error	

TEST    CX,0001h		; EDD functions (AH=42h-44h,47h,48h) supported ?
JZ      @Error	


Re: Int 13h 42h error

Posted: Sat Mar 07, 2015 4:47 pm
by MollenOS
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?

This is how i setup the stack:

Code: Select all

Main:
	; Disable Interrupts, unsafe
	cli

	; Far jump to fix segment
	jmp 	0x0:FixCS

FixCS:
	; Fix segment registers to 0
	xor 	        ax, ax
	mov		ds, ax
	mov		es, ax

	; Set stack
	mov		ss, ax
	mov		ax, 0x7BFF
	mov		sp, ax

	; Done, now we need interrupts again
	sti

	; Step 0. Save DL
	mov 	byte [bPhysicalDriveNum], dl

Re: Int 13h 42h error

Posted: Sat Mar 07, 2015 5:53 pm
by bace
That stack should be aligned at a 2 byte boundary...

Code: Select all

mov sp, 0x7C00

Re: Int 13h 42h error

Posted: Sun Mar 08, 2015 3:49 am
by djmauretto
Post all your boot code please.

Re: Int 13h 42h error

Posted: Sun Mar 08, 2015 5:40 am
by Octocontrabass
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.