<deleted>

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.
terry
Posts: 13
Joined: Tue Mar 17, 2009 12:43 pm

Re: GRUB error 13: I *have* searched :|

Post 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.
CJKay
Posts: 20
Joined: Sun Aug 30, 2009 6:32 pm

<deleted>

Post by CJKay »

<deleted>
Last edited by CJKay on Wed Jul 12, 2017 1:46 pm, edited 1 time in total.
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: GRUB error 13: I *have* searched :|

Post 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?
terry
Posts: 13
Joined: Tue Mar 17, 2009 12:43 pm

Re: GRUB error 13: I *have* searched :|

Post 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. :)
CJKay
Posts: 20
Joined: Sun Aug 30, 2009 6:32 pm

<deleted>

Post by CJKay »

<deleted>
Last edited by CJKay on Wed Jul 12, 2017 1:46 pm, edited 1 time in total.
terry
Posts: 13
Joined: Tue Mar 17, 2009 12:43 pm

Re: GRUB error 13: I *have* searched :|

Post 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.
Last edited by terry on Tue Sep 01, 2009 9:27 am, edited 1 time in total.
CJKay
Posts: 20
Joined: Sun Aug 30, 2009 6:32 pm

<deleted>

Post by CJKay »

<deleted>
Last edited by CJKay on Wed Jul 12, 2017 1:46 pm, edited 1 time in total.
terry
Posts: 13
Joined: Tue Mar 17, 2009 12:43 pm

Re: GRUB error 13: Fixed :)

Post 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.
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: GRUB error 13: I *have* searched :|

Post 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 :P. I learned a lot in the process so it's not all bad.
Thanks :D.
:D 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!
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
CJKay
Posts: 20
Joined: Sun Aug 30, 2009 6:32 pm

<deleted>

Post by CJKay »

<deleted>
Last edited by CJKay on Wed Jul 12, 2017 1:47 pm, edited 1 time in total.
eddyb
Member
Member
Posts: 248
Joined: Fri Aug 01, 2008 7:52 am

Re: GRUB error 13: Fixed :)

Post 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
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: GRUB error 13: Fixed :)

Post by gravaera »

Umm...as clarification: that doesn't just pop up magically, by the way. You'd need to edit your linker script.
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
CJKay
Posts: 20
Joined: Sun Aug 30, 2009 6:32 pm

<deleted>

Post by CJKay »

<deleted>
Last edited by CJKay on Wed Jul 12, 2017 1:47 pm, edited 1 time in total.
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: GRUB error 13: Fixed :)

Post 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.
"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
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: GRUB error 13: Fixed :)

Post 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.
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
Post Reply