Int 13h 42h error

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.
Post Reply
MollenOS
Member
Member
Posts: 202
Joined: Wed Oct 26, 2011 12:00 pm

Int 13h 42h error

Post 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
Octocontrabass
Member
Member
Posts: 5588
Joined: Mon Mar 25, 2013 7:01 pm

Re: Int 13h 42h error

Post 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?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Int 13h 42h error

Post 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
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.
djmauretto
Member
Member
Posts: 116
Joined: Wed Oct 22, 2008 2:21 am
Location: Roma,Italy

Re: Int 13h 42h error

Post 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	

MollenOS
Member
Member
Posts: 202
Joined: Wed Oct 26, 2011 12:00 pm

Re: Int 13h 42h error

Post 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
User avatar
bace
Member
Member
Posts: 34
Joined: Fri Jan 16, 2015 10:41 am
Location: United Kingdom

Re: Int 13h 42h error

Post by bace »

That stack should be aligned at a 2 byte boundary...

Code: Select all

mov sp, 0x7C00
"for example, turning off the system’s power through the movement of a large red switch" - the Advanced Configuration and Power Interface Specification
djmauretto
Member
Member
Posts: 116
Joined: Wed Oct 22, 2008 2:21 am
Location: Roma,Italy

Re: Int 13h 42h error

Post by djmauretto »

Post all your boot code please.
Octocontrabass
Member
Member
Posts: 5588
Joined: Mon Mar 25, 2013 7:01 pm

Re: Int 13h 42h error

Post 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.
Post Reply