Grub Error 13 with pe format kernel

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.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Grub Error 13 with pe format kernel

Post 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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
gedd
Member
Member
Posts: 104
Joined: Thu Apr 10, 2008 1:47 am

Re: Grub Error 13 with pe format kernel

Post 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"
[ Grub 2 | Visual Studio 2013 | PE File ]
The OsDev E.T.
Don't send OsDev MIB !
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Grub Error 13 with pe format kernel

Post 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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
gedd
Member
Member
Posts: 104
Joined: Thu Apr 10, 2008 1:47 am

Re: Grub Error 13 with pe format kernel

Post 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
[ Grub 2 | Visual Studio 2013 | PE File ]
The OsDev E.T.
Don't send OsDev MIB !
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Grub Error 13 with pe format kernel

Post 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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: Grub Error 13 with pe format kernel

Post 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.
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
gedd
Member
Member
Posts: 104
Joined: Thu Apr 10, 2008 1:47 am

Re: Grub Error 13 with pe format kernel

Post 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
[ Grub 2 | Visual Studio 2013 | PE File ]
The OsDev E.T.
Don't send OsDev MIB !
gedd
Member
Member
Posts: 104
Joined: Thu Apr 10, 2008 1:47 am

Re: Grub Error 13 with pe format kernel

Post 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 ?
[ Grub 2 | Visual Studio 2013 | PE File ]
The OsDev E.T.
Don't send OsDev MIB !
fronty
Member
Member
Posts: 188
Joined: Mon Jan 14, 2008 5:53 am
Location: Helsinki

Re: Grub Error 13 with pe format kernel

Post by fronty »

Is the header correctly aligned? Spec says it has to be 32-bit aligned.
gedd
Member
Member
Posts: 104
Joined: Thu Apr 10, 2008 1:47 am

Re: Grub Error 13 with pe format kernel

Post by gedd »

Yes MAGIC number is @0x400
[ Grub 2 | Visual Studio 2013 | PE File ]
The OsDev E.T.
Don't send OsDev MIB !
gedd
Member
Member
Posts: 104
Joined: Thu Apr 10, 2008 1:47 am

Re: Grub Error 13 with pe format kernel

Post 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 ?
[ Grub 2 | Visual Studio 2013 | PE File ]
The OsDev E.T.
Don't send OsDev MIB !
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 with pe format kernel

Post 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
"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 ]
gedd
Member
Member
Posts: 104
Joined: Thu Apr 10, 2008 1:47 am

Re: Grub Error 13 with pe format kernel

Post 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 ?
[ Grub 2 | Visual Studio 2013 | PE File ]
The OsDev E.T.
Don't send OsDev MIB !
gedd
Member
Member
Posts: 104
Joined: Thu Apr 10, 2008 1:47 am

Re: Grub Error 13 with pe format kernel

Post by gedd »

Someone here have ever made a PE file kernel loaded by Grub ?
[ Grub 2 | Visual Studio 2013 | PE File ]
The OsDev E.T.
Don't send OsDev MIB !
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Grub Error 13 with pe format kernel

Post 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.
Every good solution is obvious once you've found it.
Locked