Page 2 of 2
Re: JMP vs. RETF [Solved] + Problem with Bootloader [Unsolved]
Posted: Tue Apr 14, 2009 5:48 am
by kay10
I don't post the whole code again, just the part where it doesn't work anymore.
Code: Select all
EXEC_FILE:
PUSH ES ; ES = 0x1000
PUSH BX ; BX = 0x0000
RETF ; Jumps to the kernel
When it should jump to the kernel, it doesn't, if I write something like this
Code: Select all
EXEC_FILE:
PUSH ES ; ES = 0x1000
PUSH BX ; BX = 0x0000
MOV SI, LoadMsg ; NEW
CALL PRINT ; NEW
RETF ; Jumps to the kernel
the LoadMsg will be printed and then it just stops working, it just doesn't execute the kernel.
The cursor continues blinking until I press the reset button.
I thought there have to be a mistake in my READ_SECTORS function, but I don't know whether there is a mistake and where it is if there is one.
Re: JMP vs. RETF [Solved] + Problem with Bootloader [Unsolved]
Posted: Tue Apr 14, 2009 6:02 am
by Love4Boobies
Well, instead of having someone looking over the whole code you could, for example, print a character wherever there is a loop. That way you'll know where the infinite loop is for sure.
Re: JMP vs. RETF [Solved] + Problem with Bootloader [Unsolved]
Posted: Tue Apr 14, 2009 8:25 am
by kay10
Love4Boobies wrote:you could, for example, print a character wherever there is a loop. That way you'll know where the infinite loop is for sure.
That's the problem, there is no infinite loop in my OLD code (the one with ORG 0x0000), it looks like everything works correctly until it should execute the kernel.
I think he tries to jump to 0x1000:0x0000, but there is no kernel, because he loaded it somewhere else.
If it is like this, I can't explain why it works under emulators/virtual machines.
The NEW code (with ORG 0x7C00) works even worse than the old one, but there I know where the mistake comes from (as I said it in post 13), but I don't know how to solve it.
I sum it up again, the READ_SECTORS function starts, he converts the LBA adress to the correct CHS adress, but after loading the sector, the carry flag is set, so a mistake happenend and then he tries to load the sector again and the carry flag is set again. That would be the infinite loop with the NEW code (After 5 retries he stops).
That's why I prefer the old one.
Re: JMP vs. RETF [Solved] + Problem with Bootloader [Unsolved]
Posted: Tue Apr 14, 2009 9:53 am
by frank
At the very biginning of the file the jmp START should be jmp 0x07C0:START if using ORG 0 or jmp 0x0000:START if using ORG 0x7c00. BIOSes don't alway jump to 0000:7C00 like they should. Then make sure you set ds and es to 0, except for that 1 part where you are loading the second stage and jumping to it.
Re: JMP vs. RETF [Solved] + Problem with Bootloader [Unsolved]
Posted: Tue Apr 14, 2009 10:44 am
by kay10
Thanks frank, but Windows doesn't recognize it as a FAT12 formatted floppy anymore if I change the code as you recommend.
I start to believe that my PC is the reason for my problem, is that possible?
Re: JMP vs. RETF [Solved] + Problem with Bootloader [Unsolved]
Posted: Tue Apr 14, 2009 10:48 am
by Combuster
in that case
Code: Select all
org 0x0000
bits 16
jmp start
bpbBla1: times x DB y
bpbBla2: DB "more of the BPB here"
start: JMP 0x07C0:start2
start2: YOUR [code], [here]
the BPB needs to be in a fixed location, a far jump takes far more bytes than a near jump...
Re: JMP vs. RETF [Solved] + Problem with Bootloader [Unsolved]
Posted: Tue Apr 14, 2009 11:16 am
by kay10
Combuster wrote:in that case
Code: Select all
org 0x0000
bits 16
jmp start
bpbBla1: times x DB y
bpbBla2: DB "more of the BPB here"
start: JMP 0x07C0:start2
start2: YOUR [code], [here]
the BPB needs to be in a fixed location, a far jump takes far more bytes than a near jump...
Yes, that's what I'm using since I started coding my bootloader, I just wanted to mention that franks code doesn't work as expected.
It would be great if someone consented to test my bootloader, so I can be sure my PC isn't messing it up.
I attach the bootloader binary (please add any kernel.bin you want, the bootloader needs it
).
Thanks everybody for your help.
Re: JMP vs. RETF [Solved] + Problem with Bootloader [Unsolved]
Posted: Tue Apr 14, 2009 4:14 pm
by Troy Martin
Just want to put something down here: I've heard that some old BIOSes won't boot a sector under one of the two circumstances:
- There's no boot signature (db 0x55, 0xAA)
- The beginning of the sector doesn't start with 0xEB, a byte, 0x90 (JMP SHORT <byte> ; NOP [the <byte> is the first byte after the BPB])
However, the second is very, very poor work on behalf of the old BIOS manufacturer, as a non-FAT12 floppy probably won't have those bytes at the beginning.
Re: JMP vs. RETF [Solved] + Problem with Bootloader [Unsolved]
Posted: Wed Apr 15, 2009 11:34 am
by kay10
I solved it!!!
My PC didn't accept the stacks position in the memory!
I changed this code
Code: Select all
MAIN:
MOV AX, 0x9000
MOV SS, AX
XOR SP, SP
into the following one:
Code: Select all
MAIN:
XOR AX, AX
MOV SS, AX
MOV SP, 0xFFFF
And now it works!!!
I hope this might be helpful for somebody.
Thank you all the same!