JMP vs. RETF [Solved] + Problem with Bootloader [SOLVED!]

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.
kay10
Member
Member
Posts: 30
Joined: Mon Apr 13, 2009 6:10 am
Location: Oldenburg, Germany

Re: JMP vs. RETF [Solved] + Problem with Bootloader [Unsolved]

Post 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.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: JMP vs. RETF [Solved] + Problem with Bootloader [Unsolved]

Post 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.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
kay10
Member
Member
Posts: 30
Joined: Mon Apr 13, 2009 6:10 am
Location: Oldenburg, Germany

Re: JMP vs. RETF [Solved] + Problem with Bootloader [Unsolved]

Post 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.
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Re: JMP vs. RETF [Solved] + Problem with Bootloader [Unsolved]

Post 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.
kay10
Member
Member
Posts: 30
Joined: Mon Apr 13, 2009 6:10 am
Location: Oldenburg, Germany

Re: JMP vs. RETF [Solved] + Problem with Bootloader [Unsolved]

Post 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? :shock:
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: JMP vs. RETF [Solved] + Problem with Bootloader [Unsolved]

Post 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...
"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 ]
kay10
Member
Member
Posts: 30
Joined: Mon Apr 13, 2009 6:10 am
Location: Oldenburg, Germany

Re: JMP vs. RETF [Solved] + Problem with Bootloader [Unsolved]

Post 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 :wink: ).
Thanks everybody for your help.
Attachments
bootfat12.rar
FAT12 Bootloader
(549 Bytes) Downloaded 96 times
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: JMP vs. RETF [Solved] + Problem with Bootloader [Unsolved]

Post 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.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
kay10
Member
Member
Posts: 30
Joined: Mon Apr 13, 2009 6:10 am
Location: Oldenburg, Germany

Re: JMP vs. RETF [Solved] + Problem with Bootloader [Unsolved]

Post by kay10 »

I solved it!!! :D

My PC didn't accept the stacks position in the memory! #-o

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!!! 8)
I hope this might be helpful for somebody.

Thank you all the same!
Post Reply