Page 2 of 3
Re: GRUB error 13: I *have* searched :|
Posted: Tue Sep 01, 2009 7:23 am
by terry
Because you said, "Thanks" I'll give you one more hint just to help you figure out more quickly if it really is an issue with multiboot headers.
Look in your loader.s file. You should see something in it that mentions Multiboot Headers. Verify that it matches exactly with the tutorial you are following. (The header is the part with MAGIC, FLAGS, and then CHECKSUM).
Then, just to be doubly-sure, load your kernel.bin into a hex editor and make sure you find your header in the file. It should be pretty close to the beginning (look at the Multiboot specification to get exactly how close).
One other check that you should do is to load your floppy.img file in a hex editor and make sure that your kernel really starts *exactly* in the file where you think it should.
Standard disclaimer: There are tons of little tiny things that could be causing the problems you are seeing so it is possible that nothing I've told you is even related to your problem.
<deleted>
Posted: Tue Sep 01, 2009 7:41 am
by CJKay
<deleted>
Re: GRUB error 13: I *have* searched :|
Posted: Tue Sep 01, 2009 7:52 am
by NickJohnson
The header will not have the words "multiboot", "FLAGS", "MAGIC", etc. because those are just macros within the assembler. Look at the binary in hex (not characters), and you should see the magic number 1BADB002 which signifies the start of the header.
I'm guessing your problem is that the header is in the wrong place - it *must* be linked to be the first thing after the ELF header. Could you post your linker script, and the positioning of the header within it's section?
Re: GRUB error 13: I *have* searched :|
Posted: Tue Sep 01, 2009 7:55 am
by terry
You probably aren't looking quite far enough. In my little kernel the Multiboot Header starts at offset 0x1000.
Google "Multiboot header" and look at any documentation you can find on gnu.org. In particular, look at section 3 of that documentation. This will tell you how to recognize what a multiboot header should look like (and no, you shouldn't see the words FLAGS, or CHECKSUM, or anything like that in your executable).
Also, when interpreting the numbers make sure you remember that the numbers are little-endian.
Edit: Looks like someone already posted some of the info I told you to look up in documentation.
<deleted>
Posted: Tue Sep 01, 2009 7:57 am
by CJKay
<deleted>
Re: GRUB error 13: I *have* searched :|
Posted: Tue Sep 01, 2009 8:11 am
by terry
I would check to make sure that your floppy image is correct. Your kernel must start on a 0x200 byte boundary. If either your kernel isn't on the right boundary or you don't correctly identify the sector when you try to boot in grub that would also explain the problems you are experiencing.
EDIT: Also, your linker script is the *.ld file.
EDIT Again: He edited his post above to reflect my comment.
<deleted>
Posted: Tue Sep 01, 2009 8:34 am
by CJKay
<deleted>
Re: GRUB error 13: Fixed :)
Posted: Tue Sep 01, 2009 10:53 am
by terry
Hi CJKay,
Just my two cents....
Try not to delete a lot of content when you edit your posts. If you do, then future people who search through the forums trying to find answers to their questions will get much less from the posts.
EDIT: Congratulations on fixing your problem by the way.
Re: GRUB error 13: I *have* searched :|
Posted: Tue Sep 01, 2009 11:40 am
by gravaera
CJKay wrote:I fixed it
.
That was 10 hours of scrupulous work, only to find I had to redownload GRUB's stage 2
.
Thanks so much for your help guys, even if it didn't help with the actual problem
. I learned a lot in the process so it's not all bad.
Thanks
.
I was going to post up the solution since page one, but I decided against it since I assumed that if you couldn't troubleshoot something that simple, it would be better if you didn't get through. I had that problem in the beginning. When I was downloading the GrUB files, I went and took 0.94 since it was at the top. (More convenient).When I eventually went through the whole thing again, I decided to take the newest version, and presto: 0.97 worked!
<deleted>
Posted: Tue Sep 01, 2009 12:06 pm
by CJKay
<deleted>
Re: GRUB error 13: Fixed :)
Posted: Tue Sep 01, 2009 1:53 pm
by eddyb
CJKay wrote:Well, onto paging!
One more thing, how can I pass the end-of-kernel address from the linker? I have "__END_OF_KERNEL = .;" in linker.ld but how can I pass it through to C as a variable?
Thanks guys lol
IIRC, you can do
Code: Select all
extern int __END_OF_KERNEL;
address_of_the_end_of_the_kernel = &__END_OF_KERNEL;// __END_OF_KERNEL is a variable that's at the end of your kernel and &__END_OF_KERNEL gives you its address
Re: GRUB error 13: Fixed :)
Posted: Tue Sep 01, 2009 2:16 pm
by gravaera
Umm...as clarification: that doesn't just pop up magically, by the way. You'd need to edit your linker script.
<deleted>
Posted: Tue Sep 01, 2009 2:24 pm
by CJKay
<deleted>
Re: GRUB error 13: Fixed :)
Posted: Tue Sep 01, 2009 2:45 pm
by Combuster
Code: Select all
unsigned int page_aligned_end = (((unsigned int*)__END_OF_KERNEL) & 0xFFFFF000) + 0x1000;
I get: "error: invalid operands to binary & (have 'unsigned int *' and 'unsigned int')".
What do I do here? If I remove the pointer it compiles, but doesn't do what I need. If I keep the pointer like the tutorial says it errors :S.
I've also tried &__END_OF_KERNEL but that gives the same error too.
So much for pointer skills.
end_of_kernel is a symbol identifying a constant location. You give it a type in the extern declaration, which makes C think it is a variable of a sort, whose data is stored at the location defined by the symbol. So naturally if you ask for end_of_kernel, you'll get the
value at the end of the kernel (which obviously isn't there). if you ask for &end_of_kernel, you get the address of that variable, which is the same as the value of the symbol.
Other problem: gcc wont allow you to do several operations on pointers for good reason (
most people who do that are morons). So you will have to change the type somewhere too.
Now you should have enough info to figure this one out.
Re: GRUB error 13: Fixed :)
Posted: Tue Sep 01, 2009 3:06 pm
by gravaera
@OP: The problem is that you're trying to use a pointer and a plain integer as operands to the & operator. Your compiler is telling you that it's uncomfortable with that. Simply cast them all to either pointers, or integers. A pointer is nothing more than a number, by the way (in the simplest of terms).
To make things too obvious: remove the * operator on the first operand.