Page 2 of 3
Re: Grub Error 13 with pe format kernel
Posted: Fri Nov 20, 2009 12:02 pm
by neon
Hello,
Kevin wrote:gedd wrote:LD script has no equivalent on Visual Studio and it is much complicated
Not having an equivalent for linker scripts cleary is a disadvantage (I haven't checked if it's true for VS). For example, how are you going to ensure that the multiboot header will always be in the first 8k as your kernel grows?
There is not a linker script afaik but you can control function order. ie, you can insure your entry point is always the first function in the linker map. That which can contain the multiboot header, and using #pragma can align it properly as well.
Its what I am doing to support multiboot (although I dont use Grub) anyways.
Re: Grub Error 13 with pe format kernel
Posted: Fri Nov 20, 2009 3:05 pm
by gedd
The problem is the following : even if you align code and reorder function, the DOS header, file header, PE header ...etc are at the beginning of file, before the Magic number required to have a "recognized format"
Re: Grub Error 13 with pe format kernel
Posted: Fri Nov 20, 2009 3:30 pm
by neon
meh, 8k is plenty enough room. Resources and data are stored at the end of the PE file, so the headers altogether will remain the same when adding content to the file. All the headers combined are not that big.
Re: Grub Error 13 with pe format kernel
Posted: Fri Nov 20, 2009 5:35 pm
by gedd
Too big , or not too big ....
This is not the question, if GRUB found other data than a multiboot header at the begining of file it not recognise the format : error 13
Re: Grub Error 13 with pe format kernel
Posted: Fri Nov 20, 2009 5:51 pm
by neon
Hello,
gedd wrote:Too big , or not too big ....
This is not the question, if GRUB found other data than a multiboot header at the begining of file it not recognise the format : error 13
Specification states that it must be within the first 8kb of the binary file. It is never at the beginning of the file. Knowing Grub follows the multiboot specification, it should find the structure fine if its within the first 8kb without error.
Re: Grub Error 13 with pe format kernel
Posted: Fri Nov 20, 2009 11:12 pm
by Firestryke31
Another idea might be to rewrite the DOS part of the EXE with a return (or whatever the equivalent is), some padding, then the multiboot structure. Seeing as the DOS part is ignored in everything but, well, DOS, it shouldn't cause too many problems to simply exit.
Re: Grub Error 13 with pe format kernel
Posted: Sat Nov 21, 2009 7:53 am
by gedd
neon wrote:Specification states that it must be within the first 8kb of the binary file. It is never at the beginning of the file. Knowing Grub follows the multiboot specification, it should find the structure fine if its within the first 8kb without error.
Oups, shame on me !
I will make some tests in this way
Re: Grub Error 13 with pe format kernel
Posted: Mon Nov 23, 2009 8:27 am
by gedd
I made some test and verification
My pe kernel is arround 2,5 k so my multiboot header is in the 8k limit
No change i still have an error 13
I try to place multiboot in the dos stub, no way , error 13 again
Does anyone has ever made a PE kernel with grub ?
Re: Grub Error 13 with pe format kernel
Posted: Mon Nov 23, 2009 9:35 am
by fronty
Is the header correctly aligned? Spec says it has to be 32-bit aligned.
Re: Grub Error 13 with pe format kernel
Posted: Mon Nov 23, 2009 10:08 am
by gedd
Yes MAGIC number is @0x400
Re: Grub Error 13 with pe format kernel
Posted: Wed Nov 25, 2009 2:08 am
by gedd
Well i resume :
To be GRUB/multiboot compliant a kernel not in the elf format must :
- have multiboot header placed in the first 8k
- be 32 aligned
- have AOUT Kludge info following standard multiboot header info
My PE kernel is compliant with all of this requirement.
Anything else required ?
Re: Grub Error 13 with pe format kernel
Posted: Wed Nov 25, 2009 2:29 am
by Combuster
gedd wrote: - have correct multiboot header placed in the first 8k
- be 32 aligned
- have valid AOUT Kludge info following standard multiboot header info
Fixed that for you.
Oh and, don't try to load under 1M
Re: Grub Error 13 with pe format kernel
Posted: Wed Nov 25, 2009 2:36 am
by gedd
Having a
correct multiboot was implicit.
so , is this multiboot is correct ?
Code: Select all
multiboot_header:
dd(0x1BADB002) ; magic
dd(1 << 16)|(1<<0)|(1<<1) ; flags
dd(-(0x1BADB002 + ((1 << 16)|(1<<0)|(1<<1)))) ; checksum
dd(0x00101000) ; header_addr
dd(0x00101000) ; load_addr
dd(0x00102000) ; load_end_addr
dd(0x00102000) ; bss_end_addr
dd(0x00101030) ; entry_addr
dd(0x00000000) ; mode_type
dd(0x00000000) ; width
dd(0x00000000) ; height
dd(0x00000000) ; depth
Combuster wrote:Oh and, don't try to load under 1M
Grub loading himself the specified kernel, i assume it does it at 1M no ?
Re: Grub Error 13 with pe format kernel
Posted: Thu Nov 26, 2009 4:18 am
by gedd
Someone here have ever made a PE file kernel loaded by Grub ?
Re: Grub Error 13 with pe format kernel
Posted: Thu Nov 26, 2009 8:09 am
by Solar
What does mbchk say about your kernel binary?
Apart from that, I found
no references that it would indeed be
possible to load a PE kernel using GRUB. It mentions ELF and the various a.out formats all over the place, but every article I googled combining GRUB and "PE format" recommends going the cross-compiler / ELF format way.
That doesn't mean it can't be done, it just means you're in pretty much uncharted territory.
Which is why we made it dead simple to build the crosscompiler environment. Using Cygwin is not exactly rocket science, and the
points Creature made are very valid: If you encounter problems further down the road, one half the people here
couldn't reproduce your problems even if they wanted to, because they're on Linux.