Error code 0x01 after reading past 2 track

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
ByteBit
Posts: 6
Joined: Mon Jun 16, 2014 2:40 pm

Error code 0x01 after reading past 2 track

Post by ByteBit »

I'm really confused right now. My code works for both the first and second track but it stops working when reading past those
(ah=0x01: invalid function in AH or invalid parameter). I think it's more the second part of the error message, because I don't
think function 0x02 is wrong for reading disk sectors.

Here the code:

Code: Select all

int __NOINLINE __REGPARM readDiskSector(const int sector, const int device_id, const int heads, const int tracks, const int sector_count) {
	char str[7];
	str[6] = 0;
	
	int h = sector/(sector_count/heads);
	int c = (sector-h*(sector_count/heads))/tracks;
	int s = sector-c*tracks-h*(sector_count/heads)+1;
	
	printChar(0x20);
	printChar('H');
	toHexString(h,str);
	print(str);
	printChar(',');
	printChar('T');
	toHexString(c,str);
	print(str);
	printChar(',');
	printChar('S');
	toHexString(s,str);
	print(str);
	printChar(0x20);
	
	int ret = 0;
	__asm__ __volatile__("push %%es\n"
						 "mov %%al,%%ch\n"
						 "mov %%cl,%%dh\n"
						 "mov %%dl,%%cl\n"
						 "mov %%bl,%%dl\n"
						 "mov $0x1000,%%ax\n"
						 "mov %%ax,%%es\n"
						 "mov $0x0000,%%bx\n"
						 "mov $0x0201,%%ax\n"
						 "int $0x13\n"
						 "pop %%es\n"
						 "jnc disk_read_successful\n"
						 "mov %%ah,%%al\n"
						 "xor %%ah,%%ah\n": "=a"(ret) : "a"(0x0000|h),"b"(0x0000|device_id),"c"(0x0000|(c & 0xFF)),"d"(0x0000|(s|((c>>2)&0xC0))) : "memory");
						 
	printChar(0x20);
	toHexString(ret,str);
	print(str);
	printChar(0x20);
	
	__asm__ __volatile__("disk_read_successful:");
	return ret;
}
Tested on:
QEMU - 0.13.0
Oracle VM VirtualBox - 4.3.0
--> No difference in behaviour

Compiling system: Windows 7 64Bit + gcc
Bootloader: modified MikeOS loader with Unreal mode and A20 gate support

Image

BtW: I now that the values for ch and dh are swapped here, but If they're not I can't actually read past the first track, so I guessed it's better to be able to read two tracks at least.
(Already asked that here, but I did not get any good replies apart from complains about my coding style http://stackoverflow.com/questions/2458 ... irst-track)

[Edited]
Last edited by ByteBit on Fri Jul 18, 2014 2:50 pm, edited 1 time in total.
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: Error code 0x01 after reading past 2 track

Post by Combuster »

ByteBit wrote:apart from complains about my coding style
Because it introduces so many options for really bad behaviour.

But really, doing real mode code in gcc is a big giant hack. It is known to work if you know what you're doing, but a person who knows what he's doing also knows how to debug properly, which means you are most likely just stabbing in the dark. And since you're blatantly violating pretty much all the rules there are on inline assembly, I'm not even going to bother looking for fixes until you rewrite the thing in pure assembly.

Edit: I looked up the SE link afterwards. Contrary to the Posting Checklist, most of my concerns were already mentioned and you failed to correct any of them. We will still try to help you within reason, but you have quite a fair bit to make up for now.
"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 ]
ByteBit
Posts: 6
Joined: Mon Jun 16, 2014 2:40 pm

Re: Error code 0x01 after reading past 2 track

Post by ByteBit »

Combuster wrote:I'm not even going to bother looking for fixes until you rewrite the thing in pure assembly.
I finally did it through linking C and external assembly, thanks to Comubster for giving me that hint (indirectly).
Post Reply