Reading kernel into memory

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
Cyf
Posts: 2
Joined: Tue Jan 06, 2009 5:08 pm

Reading kernel into memory

Post by Cyf »

I am sorry because the topic may have been discussed thousand times before, but I cannot work it out.

I'm trying to read the second floppy sector to 0x10000 using extended read int 13h AH = 0x42, but carry is set and AH contains the errorcode 1.

The code is this (dl contains 0):

Code: Select all

READ_SECTORS equ 5
[...]
	mov si, TestMSG
	call StrOut ; just a test message to see if it gets here

	mov ah, 42h	; Funktionsnummer 42h
	mov si, DAP	; Offset des DAP
	int 13h		; Interrupt
	; here it jumps into Panic-Code, displaying the error
	jc short Panic	; Carry bei Fehler, Fehlercode in AH, bei Erfolg AH = 0

	; Meldung ausgeben
	mov si, LoadedMSG
	call StrOut
[...]

align 4			; Füllbytes um einen durch 4 teilbaren Offset für die DAP zu erreichen
DAP:
	db 10h		; size of DAP (16 Byte)
	db 0		; unused
	dw READ_SECTORS ; Anzahl zu lesende Sektoren (0 bis max. 127) / erfolgreich gelesene Sektoren
	dw 0000h	; Zieladresse 16-bit Offset
	dw 1000h	; Zieladresse 16-bit Segment
	dq 1		; absolute Nummer des Sektors ab dem gelesen werden soll (beginnt bei 0)
Can anyone see my mistake? I checked if extended read is supported (which should be) before.
Also whats the "better" way to load the kernel int 13 AH = 2h or AH = 42h? Does it make any difference except the different way of adressing?

(Please excuse if there are any mistakes, english isn't my native language.)

Thanks,
Cyf
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: Reading kernel into memory

Post by Combuster »

The int13 extentions you are using are not supported by all bioses, and if they are, they need not include floppy support. (in your case, it returns invalid parameter, most likely referring to the drive number)

Its better to use int 13h, ah=02h instead
"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 ]
Cyf
Posts: 2
Joined: Tue Jan 06, 2009 5:08 pm

Re: Reading kernel into memory

Post by Cyf »

I noticed some really strage behavior now while making some try-and-error test. (yeah I know this should not be the way to design an OS normally, but anyway I wanted to see if it works)

I wondered if I may have to reset the floppy drive before so, I added this here before:

Code: Select all

	xor ah, ah
	int 13h
	jc short Panic
Now the error code changed to 0x20 meaning that the controller wasn't ready, so I added a loop before to spend time on doing nothing:

Code: Select all

	mov cx, 0xFFFF
	foobar:
	times 15 PAUSE
	dec cx
	or cx, cx
	jnz foobar
	
However, now there was no error. I deleted the int 13h ah = 0 before to see, if this changed the result. nope.
It only caused the 0x20 error.
So that meant the cx register altered the 0x1 error.
So I changed the loop like this:

Code: Select all

	pop cx
	mov cx, 0xFFFF
	foobar:
	times 15 PAUSE
	dec cx
	or cx, cx
	jnz foobar
	push cx
	
The 0x1 error was there again, so CX seemed to cause the error on int 13h AH = 42h. CX wasn't assigned at this time and set by BIOS to 0x7E. That actually means my BIOS is doing some wired undocumented things with this interrupt.

On the other hand I tested after that if only setting CX to 0 causes an error (which shouldn't so) and it does. I repeated the test with only the loop without push/pop before and it randomly caused sometimes errorcode 1, sometimes it succeded, which could mean it is an issue, how long the loop is running before, but I haven't got any good explanation of such behavior.

I tested with MS Visual PC 2007 (jeah I know, as soon as my new hd is here I am going the change to Linux, however I need Windows for school because we're doing Delphi stuff and there isn't enough space left for a second OS), the displayed BIOS version in the VM is:
AMIBIOS(C)2001 American Megatrends, Inc
BIOS Date: 02/22/06 20:54:49 Ver: 08.00.02

Guess I better change to int 13 function 2, I only wanted the extended one because there is no need to loop until the floppy controller is ready after the necessary floppy reset.

[Edit]Anyway the version with push/pop seems always to cause errorcode 1 always.
Post Reply