icant read sectors. please help

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
sagar474
Posts: 6
Joined: Mon May 09, 2011 11:15 pm

icant read sectors. please help

Post by sagar474 »

Code: Select all

BITS 16
start:
	mov ax, 07C0h						; Set data segment to where we're loaded
	mov ds, ax						; 
	mov ax,9000h						;initlise the stack 
	mov ss,ax						;
	mov sp,100h						;



call read_sector;


read_sector:
.Reset:
	mov		ah, 0					; reset floppy disk function
	mov		dl, 0					; drive 0 is floppy drive
	int		0x13					; call BIOS
	jc		.Reset					; If Carry Flag (CF) is set, there was an error. Try resetting again
 
	mov		ax, 0x1000				; we are going to read sector to into address 0x1000:0
	mov		es, ax
	xor		bx, bx
 
.Read:
	mov		ah, 0x02				; function 2
	mov		al, 1					; read 1 sector
	mov		ch, 1					; we are reading the second sector past us, so its still on track 1
	mov		cl, 2					; sector to read (The second sector)
	mov		dh, 0					; head number
	mov		dl, 0					; drive number. Remember Drive 0 is floppy drive.
	int		0x13					; call BIOS - Read the sector
	jc		.Read					; Error, so try again
 
	jmp		0x1000:0x0				; jump to execute the sector!
;---------------------------------------------------------------------------------------

times 510-($-$$) db 0	; Pad remainder of boot sector with 0s
	dw 0xAA55		; The standard PC boot signature
mov al,41h;
mov ah,0eh;
int 10h;
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: icant read sectors. please help

Post by thepowersgang »

Very helpful</sarcasm>

Please read the forum rules, specifically the link about "Asking questions the smart way"

That said, I suggest looking at Ralf Brown's Interrupt List to make sure you are passing the correct arguments to INT 0x13.

From a quick look, I believe that the track number should be 0 (unless you want to be reading from the second track)
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
User avatar
Coty
Member
Member
Posts: 286
Joined: Thu Feb 12, 2009 5:12 pm

Re: icant read sectors. please help

Post by Coty »

Also note that it's possible that your emu crashes because you IMG is less than 2 sectors... If you load a sector that is incomplete QEmu will crash! Also some other emu doesn't like images less than 360kb...

QEmu will load this successfully if I pad out the second sector, and adjust the track number (first track isn't 1).
My hero, is Mel.
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: icant read sectors. please help

Post by Combuster »

If your floppy image is not the full 1.44MB, emu's will indeed blow up in various degrees of nastiness.

Try bochs as your emulator, it will complain whenever you screw up your write commands instead of silently doing something unexpected - in this case it would probably have saved you from asking the question altogether.
"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 ]
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: icant read sectors. please help

Post by Chandra »

At any case, the 'read sector' function shouldn't have failed at all(unless you are reading from a defective media). So I'm assuming the original issue is with loading the kernel/2nd stage loader(and not loading the sector) which shall be worked out by correcting the cylinder no.
Cheers.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
Bietje
Member
Member
Posts: 100
Joined: Wed Apr 20, 2011 6:57 am

Re: icant read sectors. please help

Post by Bietje »

You should try

Code: Select all

xor ch, ch
instead of setting it to 1.
Post Reply