Calling Global Constructors [C++]
Posted: Mon Apr 06, 2015 5:23 am
Hello everyone,
I would like to write an own OS kernel in C++. Despite, following the wiki entry from http://wiki.osdev.org/Calling_Global_Constructors, as well as the forum discussions in http://forum.osdev.org/viewtopic.php?f= ... hilit=crtn, my kernel seems not to execute the global constructors - despite the crti.o and the crtn.o object files are included into the build process. This leads to the fact that all class method invocations use not initialized class variables and pointers and thus force the Qemu to crash.
In short: My build-system uses an i686-elf cross compiler (though, I need to mention that I did not build the cross-compiler by myself but rather downloaded a pre-built version from http://wiki.osdev.org/GCC_Cross-Compiler - i686-elf 4.9.2 target, x86_64 Linux host). To enable the C++ constructors to be called, I have built the crti.o and crtn.o files, as mentioned in the wiki entry above. Since it was not mentioned anywhere, I have not created any special linker entries for the .init/.fini sections - they seem to be correctly linked into the kernel object file. The purpose of these runtime related files (together with crtbegin.o and crtend.o) generate the function "_init", which is called right at the beginning of my bootstrap code; This means, even before any initialization of GDT, IDT, etc. Right after the invocation of "_init", I am calling the custom function "k_early_init" to initialize the VGA (class Video) for the beginning. However, since "video" is a global class object, it fails at this point (The cursor remains blinking, but the debug interface of qemu reveals that there was an error).
The following links provide further information about my current state:
It would be amazing if you could help me with my concern.
Thank you very much in advance.
crt*.S: http://pastebin.com/WbiWmgWq
boot.S: http://pastebin.com/DFuhLANc
kernel.cpp: http://pastebin.com/fZ1ZWqt7
Makefile: http://pastebin.com/zsH4cYsF
linker.ld: http://pastebin.com/hetKcuQ5
Best regards
I would like to write an own OS kernel in C++. Despite, following the wiki entry from http://wiki.osdev.org/Calling_Global_Constructors, as well as the forum discussions in http://forum.osdev.org/viewtopic.php?f= ... hilit=crtn, my kernel seems not to execute the global constructors - despite the crti.o and the crtn.o object files are included into the build process. This leads to the fact that all class method invocations use not initialized class variables and pointers and thus force the Qemu to crash.
In short: My build-system uses an i686-elf cross compiler (though, I need to mention that I did not build the cross-compiler by myself but rather downloaded a pre-built version from http://wiki.osdev.org/GCC_Cross-Compiler - i686-elf 4.9.2 target, x86_64 Linux host). To enable the C++ constructors to be called, I have built the crti.o and crtn.o files, as mentioned in the wiki entry above. Since it was not mentioned anywhere, I have not created any special linker entries for the .init/.fini sections - they seem to be correctly linked into the kernel object file. The purpose of these runtime related files (together with crtbegin.o and crtend.o) generate the function "_init", which is called right at the beginning of my bootstrap code; This means, even before any initialization of GDT, IDT, etc. Right after the invocation of "_init", I am calling the custom function "k_early_init" to initialize the VGA (class Video) for the beginning. However, since "video" is a global class object, it fails at this point (The cursor remains blinking, but the debug interface of qemu reveals that there was an error).
The following links provide further information about my current state:
It would be amazing if you could help me with my concern.
Thank you very much in advance.
crt*.S: http://pastebin.com/WbiWmgWq
boot.S: http://pastebin.com/DFuhLANc
kernel.cpp: http://pastebin.com/fZ1ZWqt7
Makefile: http://pastebin.com/zsH4cYsF
linker.ld: http://pastebin.com/hetKcuQ5
Best regards