Booting PE files - and a lot more
Booting PE files - and a lot more
Hey there!
Okay. Got some things to ask
First. Suppose I use FreeBASIC's compiler for Windows, to write a small bare-bones kernel.
But - I get a PE file.
Now, I know it's possible to boot a PE file, but how does one do that?
Is it possible to use GRUB? Or GRUB4DOS?
Or can it be done with a custom bootloader?
And do you know of any tutorial, which can walk me through the process?
Second. The PE kernel is ready, and it's booted fine.
But, I want to link it with the OSKit libraries, which are ELF libraries, if I'm right.
So is it possible to link the PE kernel with those ELF libraries?
If yes, again, how?
Third. The ELF libraries are linked just fine.
Now, when I want to write a small program, which runs in userspace inside my PE kernel, does that program have to be a PE file, or can it be an ELF as well?
Thanks
Okay. Got some things to ask
First. Suppose I use FreeBASIC's compiler for Windows, to write a small bare-bones kernel.
But - I get a PE file.
Now, I know it's possible to boot a PE file, but how does one do that?
Is it possible to use GRUB? Or GRUB4DOS?
Or can it be done with a custom bootloader?
And do you know of any tutorial, which can walk me through the process?
Second. The PE kernel is ready, and it's booted fine.
But, I want to link it with the OSKit libraries, which are ELF libraries, if I'm right.
So is it possible to link the PE kernel with those ELF libraries?
If yes, again, how?
Third. The ELF libraries are linked just fine.
Now, when I want to write a small program, which runs in userspace inside my PE kernel, does that program have to be a PE file, or can it be an ELF as well?
Thanks
Re: Booting PE files - and a lot more
Please read FreeBASIC and FreeBasic Barebones in our Wiki...
...which is incidentially linked in the FORUM RULES sticky thread in the OS Development subboard, which would have been more appropriate for your clearly OS-related questions, as well as prominently linked in the header ("The OSDev.org Wiki - Got a question? Search this first!").
The keyword I used to find those two Wiki pages for you was "FreeBasic". There is also an article on PE format.
...which is incidentially linked in the FORUM RULES sticky thread in the OS Development subboard, which would have been more appropriate for your clearly OS-related questions, as well as prominently linked in the header ("The OSDev.org Wiki - Got a question? Search this first!").
The keyword I used to find those two Wiki pages for you was "FreeBasic". There is also an article on PE format.
Every good solution is obvious once you've found it.
Re: Booting PE files - and a lot more
Hey, Solar!
What's up?
Okay. Yeah, I read all of that.
I know for one, that I can use C libraries in FreeBASIC code, but the thing is - is there no issue when it comes to linking an ELF library to a PE file?
As for the PE booting part...again, the wiki wasn't exactly illuminating..but i'll survive
Thanks!
What's up?
Okay. Yeah, I read all of that.
I know for one, that I can use C libraries in FreeBASIC code, but the thing is - is there no issue when it comes to linking an ELF library to a PE file?
As for the PE booting part...again, the wiki wasn't exactly illuminating..but i'll survive
Thanks!
Re: Booting PE files - and a lot more
No you didn't. The FB Barebones tells you how to get ELF binaries out of your FB compiler.rudimk wrote:Yeah, I read all of that.
Every good solution is obvious once you've found it.
Re: Booting PE files - and a lot more
I didSolar wrote:No you didn't. The FB Barebones tells you how to get ELF binaries out of your FB compiler.rudimk wrote:Yeah, I read all of that.
I don't want ELF binaries.
I'd like to boot PEs, just for a change!
Yeah, I could simply do a cross compiler, and copy the the ld, ar and as binaries to the platform folders.
But like I mentioned before, I don't want ELFs.
So there
Re: Booting PE files - and a lot more
Then you usually can't use GRUB. But loading a PE file isn't particularly difficult. Just remember that your loader probably won't fit in 510 bytes, so it must be able to load the rest of itself. It should locate the remainder of itself on the disk and load it to address 7dfeh. Then, load the PE file and other needed files, set up protected mode and paging, and copy each section to the correct address. The first 510 bytes of the loader, along with the boot signature, should be written to the boot sector, and the rest of it to whereever you want. You don't need a tutorial for this, as all this is straightforward to figure out on your own.
The format you use for application programs and drivers, is of course completely unrelated to the format used for the system image.
The format you use for application programs and drivers, is of course completely unrelated to the format used for the system image.
Re: Booting PE files - and a lot more
Okay.Gigasoft wrote:Then you usually can't use GRUB. But loading a PE file isn't particularly difficult. Just remember that your loader probably won't fit in 510 bytes, so it must be able to load the rest of itself. It should locate the remainder of itself on the disk and load it to address 7dfeh. Then, load the PE file and other needed files, set up protected mode and paging, and copy each section to the correct address. The first 510 bytes of the loader, along with the boot signature, should be written to the boot sector, and the rest of it to whereever you want. You don't need a tutorial for this, as all this is straightforward to figure out on your own.
The format you use for application programs and drivers, is of course completely unrelated to the format used for the system image.
I see.
<comprehension dawns>
I guess I just need to stay up a couple of nights, and tweak my way around!
But linking my PE kernel to an ELF library - that's possible, right?
Because if it isn't, then I'd have to go the cross-compiler way, and end up with an ELF kernel..
Thanks!
- Combuster
- 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: Booting PE files - and a lot more
Common sense says that you can't turn a application into a library. Common sense also doesn't mix ELF and PE.But linking my PE kernel to an ELF library - that's possible, right?
That and there are numerous ABI differences between windows-targeted freebasic, and the crosscompiler configuration.
Re: Booting PE files - and a lot more
Combuster is correct: you cannot just use external libraries unless your kernel itself has code that knows how to load them. Furthermore, if external library needs to communicate with kernel or other libraries you must have an ABI or IPC in place and all libraries must be compiled for those specific interfaces. You cannot just pull some binaries out of thin air and start using them. You will be better off just linking the code you need into your kernel.Combuster wrote:Common sense says that you can't turn a application into a library. Common sense also doesn't mix ELF and PE.But linking my PE kernel to an ELF library - that's possible, right?
That and there are numerous ABI differences between windows-targeted freebasic, and the crosscompiler configuration.
There must be a reason. Preferably a good one. I choose to have PE format because then I could debug my non hardware specific code under MSVS and run the kernel in simulation mode under Windows (see here).rudimk wrote:I don't want ELF binaries.
I'd like to boot PEs, just for a change!
However, I am not sure that my approach is suitable for you. Regardless how you compile your kernel, you still have to apply very strict linker rules and obey restrictions of the boot environment. For example, anything more complex then "Hello World" will require to setup your own GDT, IDT, handle Interrupts and Exceptions, manage memory, etc...
When all other things taken into consideration the difference between choosing ELF and PE format, given that link and boot instructions for both are already well documented, becomes negligible.
Re: Booting PE files - and a lot more
You can boot PE files with Grub via multiboot, personally I have only done it with C kernels though. It might be possible to boot this way if you can position the multiboot header correctly with FreeBASIC.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Re: Booting PE files - and a lot more
As far as the OSkit libraries go -- it is not hard to build them as PE files. GCC under cygwin automatically builds all files as PE, not ELF.
There is no convenient way to link ELF and PE binaries together. It is probably doable, but you really shouldn't consider hacking it, as said above. Too error prone, if nothing else. It's much easier to build yourself the cross compiler. And, as I said above, even easier to use one that's already set up for you.
As for question #3 -- you get to choose your own executable/linkable format when you build your compiler in your own OS. If you insist that your kernel be PE, and you want your compiler to be able to build your kernel, then a PE output format must be available. But you can have multiple supported output formats in gcc and many other compilers.
There is no convenient way to link ELF and PE binaries together. It is probably doable, but you really shouldn't consider hacking it, as said above. Too error prone, if nothing else. It's much easier to build yourself the cross compiler. And, as I said above, even easier to use one that's already set up for you.
As for question #3 -- you get to choose your own executable/linkable format when you build your compiler in your own OS. If you insist that your kernel be PE, and you want your compiler to be able to build your kernel, then a PE output format must be available. But you can have multiple supported output formats in gcc and many other compilers.
Re: Booting PE files - and a lot more
Hmm.bewing wrote:As far as the OSkit libraries go -- it is not hard to build them as PE files. GCC under cygwin automatically builds all files as PE, not ELF.
There is no convenient way to link ELF and PE binaries together. It is probably doable, but you really shouldn't consider hacking it, as said above. Too error prone, if nothing else. It's much easier to build yourself the cross compiler. And, as I said above, even easier to use one that's already set up for you.
As for question #3 -- you get to choose your own executable/linkable format when you build your compiler in your own OS. If you insist that your kernel be PE, and you want your compiler to be able to build your kernel, then a PE output format must be available. But you can have multiple supported output formats in gcc and many other compilers.
Guess you got a point.
Maybe hacking those libraries is going to be a not-so-good idea.
Ah, well. I'll build the cross compiler.
I see.
Well, I'm still not sure about the self hosting thing - having the compiler inside the OS build the OS..Got eons of time for that!
Thanks a ton!