Hi guys, first of all I'd like to present myself, I'm Luca and I'm working on developing a Kernel for my thesis.
I'm following the brokenthorn.com tutorial, that are great and very well explained.
The problem is that those tutorials use VS.
I prefer to compile my code using gcc.
What are the main important things that I've to keep in mind while following those tutorials using gcc instead of VS ?
I've also another question: is possible to have both and elf and pe loader on the same system ? I can't see why not..
Thanks for the help,
Luca
[About Brokenthorn Tutorials] Using GCC instead of VS
Re: [About Brokenthorn Tutorials] Using GCC instead of VS
Hi,
You should use the Bare Bones tutorial instead, as it has been carefully reviewed by this community to show how to properly use a cross-gcc for development of a 32-bit multiboot kernel. This is a simple and reliable way to get started. You can likely port the contents of your BrokenThorn tutorial to the Bare Bones base, but you should probably be careful of any information that contradicts Bare Bones. Another thing to watch out for is that other tutorials occasionally use non-portable code or other nasty tricks that won't work with gcc or simply is bad advise. Note how Bare Bones is a minimal kernel, it's not meant as a good skeleton for further development.
Yes, it's possible to have an PE and ELF loader on the same system. In a bootloader it even makes a lot of sense. However, in an opertating system, do you really want both? The fact is that one of the formats will be a second-class citizen and it'll just contribute greatly to the complexity of your OS with no immediate gain. If you are thinking about Windows emulation - don't. Smarter people than you have spend decades on doing it and you should join their projects instead.
You should use the Bare Bones tutorial instead, as it has been carefully reviewed by this community to show how to properly use a cross-gcc for development of a 32-bit multiboot kernel. This is a simple and reliable way to get started. You can likely port the contents of your BrokenThorn tutorial to the Bare Bones base, but you should probably be careful of any information that contradicts Bare Bones. Another thing to watch out for is that other tutorials occasionally use non-portable code or other nasty tricks that won't work with gcc or simply is bad advise. Note how Bare Bones is a minimal kernel, it's not meant as a good skeleton for further development.
Yes, it's possible to have an PE and ELF loader on the same system. In a bootloader it even makes a lot of sense. However, in an opertating system, do you really want both? The fact is that one of the formats will be a second-class citizen and it'll just contribute greatly to the complexity of your OS with no immediate gain. If you are thinking about Windows emulation - don't. Smarter people than you have spend decades on doing it and you should join their projects instead.
Re: [About Brokenthorn Tutorials] Using GCC instead of VS
Hi,
I was aware of the bare bones tutorial,it is really cool and well documented, by the way I'd like to study from BrokenThorn tutorials because they are more detailed and completed.
The problem is that I'm having troubles to port the "base" source of Tutorial 14 to compile it with gcc (instead of VC++). I've to find a way to do that, or I've to find somebody that can give me some hint on how to do that.
Absolutely not I was just asking
EDIT: I've managed to compile almost files using gcc (I've also written a build script), the only file I cannot port is cstd.cpp, so for the moment I can't use InitializeConstructors() function
I was aware of the bare bones tutorial,it is really cool and well documented, by the way I'd like to study from BrokenThorn tutorials because they are more detailed and completed.
The problem is that I'm having troubles to port the "base" source of Tutorial 14 to compile it with gcc (instead of VC++). I've to find a way to do that, or I've to find somebody that can give me some hint on how to do that.
Code: Select all
If you are thinking about Windows emulation - don't. Smarter people than you have spend decades on doing it and you should join their projects instead.
EDIT: I've managed to compile almost files using gcc (I've also written a build script), the only file I cannot port is cstd.cpp, so for the moment I can't use InitializeConstructors() function
Re: [About Brokenthorn Tutorials] Using GCC instead of VS
Hello,
With regards to using GCC we typically recommend the articles written by JamesM due to it targeting GCC. Most of the series code base should build fine with GCC with little modifications except the C++ run time component (cstd.cpp in the series kernel) which would need a complete rewrite or port.
More specifically, the following needs to be ported for use with GCC.
1. MSVC specific code. Basically any code block using #ifdef MSC_VER ... #endif is MSVC specific. Although we have tried to insure compatibility outside of these blocks we cannot make any guarantee. For maximum compatibility, we recommend abstracting compiler specific code in such a way that would allow easy building across multiple tool chains.
2. All inline assembly language. For maximum compatibility, we recommend not using inline assembly language at all. That is, using an external assembler and linking the resulting object file.
3. All of cstd.cpp. Please see the following Wiki article: C++ which covers how to add some C++ support for both GCC and MSVC. The article is primarily targeting GCC however and most example code assumes GCC. If you decide not to use C++ then this step can be skipped.
4. C ISR's. The series code base implements all interrupt service routines (ISR) in C. This was done for simplicity only; it is non portable and will break on GCC. Two solutions are
Solution A. Write the ISR's in a separate assembly language file and link it in; have those ISR's call an interrupt handler entry point in C. Please see JameM's articles linked above for an example that does this. (Recommended.)
Solution B. Write the ISR's in C however fix the stack for use with GCC. (Can break between versions.)
After these modifications, the software should build without error assuming no other compatibility issues exist within the code base. (If there is, please let us know so that it may be corrected.)
We also recommend the use of make for project management in order to limit operating system specific build scripts. If compatibility between build systems is not a concern however then it does not matter.
With regards to using GCC we typically recommend the articles written by JamesM due to it targeting GCC. Most of the series code base should build fine with GCC with little modifications except the C++ run time component (cstd.cpp in the series kernel) which would need a complete rewrite or port.
More specifically, the following needs to be ported for use with GCC.
1. MSVC specific code. Basically any code block using #ifdef MSC_VER ... #endif is MSVC specific. Although we have tried to insure compatibility outside of these blocks we cannot make any guarantee. For maximum compatibility, we recommend abstracting compiler specific code in such a way that would allow easy building across multiple tool chains.
2. All inline assembly language. For maximum compatibility, we recommend not using inline assembly language at all. That is, using an external assembler and linking the resulting object file.
3. All of cstd.cpp. Please see the following Wiki article: C++ which covers how to add some C++ support for both GCC and MSVC. The article is primarily targeting GCC however and most example code assumes GCC. If you decide not to use C++ then this step can be skipped.
4. C ISR's. The series code base implements all interrupt service routines (ISR) in C. This was done for simplicity only; it is non portable and will break on GCC. Two solutions are
Solution A. Write the ISR's in a separate assembly language file and link it in; have those ISR's call an interrupt handler entry point in C. Please see JameM's articles linked above for an example that does this. (Recommended.)
Solution B. Write the ISR's in C however fix the stack for use with GCC. (Can break between versions.)
After these modifications, the software should build without error assuming no other compatibility issues exist within the code base. (If there is, please let us know so that it may be corrected.)
We also recommend the use of make for project management in order to limit operating system specific build scripts. If compatibility between build systems is not a concern however then it does not matter.
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: [About Brokenthorn Tutorials] Using GCC instead of VS
Thanks Mike for the help.neon wrote:Hello,
With regards to using GCC we typically recommend the articles written by JamesM due to it targeting GCC. Most of the series code base should build fine with GCC with little modifications except the C++ run time component (cstd.cpp in the series kernel) which would need a complete rewrite or port.
More specifically, the following needs to be ported for use with GCC.
1. MSVC specific code. Basically any code block using #ifdef MSC_VER ... #endif is MSVC specific. Although we have tried to insure compatibility outside of these blocks we cannot make any guarantee. For maximum compatibility, we recommend abstracting compiler specific code in such a way that would allow easy building across multiple tool chains.
2. All inline assembly language. For maximum compatibility, we recommend not using inline assembly language at all. That is, using an external assembler and linking the resulting object file.
3. All of cstd.cpp. Please see the following Wiki article: C++ which covers how to add some C++ support for both GCC and MSVC. The article is primarily targeting GCC however and most example code assumes GCC. If you decide not to use C++ then this step can be skipped.
4. C ISR's. The series code base implements all interrupt service routines (ISR) in C. This was done for simplicity only; it is non portable and will break on GCC. Two solutions are
Solution A. Write the ISR's in a separate assembly language file and link it in; have those ISR's call an interrupt handler entry point in C. Please see JameM's articles linked above for an example that does this. (Recommended.)
Solution B. Write the ISR's in C however fix the stack for use with GCC. (Can break between versions.)
After these modifications, the software should build without error assuming no other compatibility issues exist within the code base. (If there is, please let us know so that it may be corrected.)
We also recommend the use of make for project management in order to limit operating system specific build scripts. If compatibility between build systems is not a concern however then it does not matter.
I don't plan to use C++, I'd like to use C instead.
Can I totally skip cstd.cpp then ? so if I understood correctly, I can avoid to call InitializeConstructors() before the kernel main().. is this correct ?
Thanks
Re: [About Brokenthorn Tutorials] Using GCC instead of VS
Hello,
So, if you decide to use C you would only need to modify (1), (2), and (4) to get it working with GCC and can ignore (3) and just ignore cstd.cpp and InitializeConstructors.
Yes to both. They are C++ specific and so can be skipped if just using C. In addition, most of the code in the series can be ported to C with very little modifications since no OOP specific elements are used. No C specific code is in the series that is not also C++ so it should technically work without modifications (except of course the MSVC specific stuff in the above post.)Luca91 wrote:I don't plan to use C++, I'd like to use C instead.
Can I totally skip cstd.cpp then ? so if I understood correctly, I can avoid to call InitializeConstructors() before the kernel main().. is this correct ?
So, if you decide to use C you would only need to modify (1), (2), and (4) to get it working with GCC and can ignore (3) and just ignore cstd.cpp and InitializeConstructors.
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();}