[SOLVED]int 13h ah=42h error code 4

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
Caleb1994
Member
Member
Posts: 83
Joined: Sun Feb 13, 2011 4:55 pm

[SOLVED]int 13h ah=42h error code 4

Post by Caleb1994 »

Hello, I'm new to OS development, and semi-new to assembly, but not to programming in general.

I'm trying to write a basic bootloader (no filesystem yet, just trying to read from the drive). I'm using Notepad++,nasm,dd(both from cygwin), and virtualbox.

Every time I run it, I get error code 4, which according to http://www.ctyme.com/intr/rb-0606.htm#Table234, means that the sector is wrong or there was a generic read error. Not much info there.

Here is the source to my ReadDrive subroutine:

Code: Select all

; Read the root directory into 'disk_buffer'
; The DiskAddrPack is expected to be completely filled
; with all relevent data
; Also dl holds the device to read from
ReadDrive:
	mov si,DiskAddrPack								; Tell int 13h where to find the settings
	mov ah,42h										; Extended Read Sectors from drive function
	int 13h											; Read!
	
	ret
Here is the DiskAddrPack structure:

Code: Select all

;This is a packet of information about how, and what to read from a drive (used with the ReadDrive function)
DiskAddrPack:
	.Size: db 10h									; Size of the Disk Address Packet
	.Reserved1: db 0									; Unused, always zero
	.NSector: db 0									; Number of sectors to read
	.Reserved2: db 0									; Unused, always zero
	.Buffer:										; Pointer to the buffer to store the data (DS:DiskAddrPack.Buffer, segment:offset)
	.BufferOffset: dw 0
	.BufferSegment: dw 07C0h
	.SectorIndex:									; The entire 8 bytes
	.SectorIndexL: dd 0								; Low 4 bytes
	.SectorIndexH: dd 0								; High 4 bytes
and the code i'm using to call it (should just load the next sector into an address)

Code: Select all

	mov byte[DiskAddrPack.NSector],1				; Read one sector
	mov word[DiskAddrPack.BufferOffset],2000h
	mov dword[DiskAddrPack.SectorIndexL],1                 ; Read sector one
	mov dword[DiskAddrPack.SectorIndexH],0
	mov dl,00h										; Set the read device
	call ReadDrive									; Read from the drive
Does anyone have an Idea? I've been googling all day, and can figure out anything.

That's all the code that partains to the reading of the sector. If you need anything else let me know.

Oh yeah, also I'm doing this from a floppy image.
Last edited by Caleb1994 on Thu Feb 17, 2011 2:09 pm, edited 1 time in total.
M2004
Member
Member
Posts: 65
Joined: Sun Mar 07, 2010 2:12 am

Re: int 13h ah=42h error code 4

Post by M2004 »

It seems your trying to use int 13h extended services on first floppy drive.
I think you should stick with the CHS method if you you are
trying to boot from floppy. Else you need to (at least) change the drive number.

regards
mac2004
Caleb1994
Member
Member
Posts: 83
Joined: Sun Feb 13, 2011 4:55 pm

Re: int 13h ah=42h error code 4

Post by Caleb1994 »

Yes I am. I was not aware that you couldn't use it with a floppy.

I chose 42h because it seemed easier to use since you didn't have to calculate the head/track. I'm not sure how to do all that, and it seems I'm having trouble finding good information on exactly how to find the correct track/head through google. I'm geusing that for the second sector in the floppy, it would be Head 0, Track 0, Sector 1, but I would like to calculate it programmaticly so I can load different sectors if I ever need to. lol

If someone could either provide me with the equation to find the head/track from a sector number, let me know, or if you have a website I could check out, that would be great. Thanks.

But your last sentance hints that you can use it with floppies? What would the drive number need to be? I like 42h. It just looks nicer, so if i could use it, that would be great.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: int 13h ah=42h error code 4

Post by Combuster »

Learn to search: both http://en.wikipedia.org/wiki/CHS and http://en.wikipedia.org/wiki/LBA have the information you need, and I didn't even need to use google to find that out.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Caleb1994
Member
Member
Posts: 83
Joined: Sun Feb 13, 2011 4:55 pm

Re: int 13h ah=42h error code 4

Post by Caleb1994 »

I switched to CHS and it worked perfectly! Thanks =D> ! I had been to the CHS page, but for some reason I didn't notice their CHS to LBA equation which is easily reversible, but as I just saw, those equations are already there on the LBA wiki. lol

Again, sorry if it sounded dumb. I'm new to low-level stuff like this. I'm used to C/C++ where to read from a drive you just give it the byte index to read from, and the number of bytes to read, and the address to load to. I'm new and just dabbling :P

I know of a working bootloader, and a small kernel exectuable that just prints a prompt, and asks for your name (I was playing with the keyboard input interrupts :D)
Post Reply