Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

C++ in Kernel Land

Sign in to follow this  



I just fixed a tricky bug in the Kernel. The hardest thing is not setting up the complier, but rather, the language, itself.

There are alot of C++ constructs that require the runtime to work with. Not defining these constructs will lead to errors and triple faults. A few examples are as follows:

  • Exception handling requires runtime support to handle uncaught exceptions;
  • C++ new and delete operators rely on an existing memory manager;
  • All global ctors and dtors must be initialized by the runtime library;
  • Initil stack frame that which calls main();
  • RTTI requires runtime support, this includes keywords such as typeid;

    There are more then this. Because we cannot use the runtime, WE have to do all of this ourselves.

    The bug that I just fixed was none of the above. It was when I found out that global and static variables failed to initialize. That is, this would work:

    void foo () {

    int i=0; // i==0

    This did NOT work:

    void foo () {

    static int i=0; // i==???

    The solution was that, in C++, global and static variables--That are initialized, but never modified, gets placed inside another section within the PE executable--.edata.

    This section, however DID exist. The primary problem is that of Memory misalignment, where the code would reference a memory location based off of the wrong base address.

    After setting the initil base address, everything worked just fine.

    Notice that, in the high level (C++ level), this has NOTHING to do with static and global variables.

    This is an example of me stating that While we are working with C++, we are still working in a low level envirement!


    Next tutorial started

    The next tutorial has started. It will cover:

  • Setting the build envirement (Setting up MSVC++ 2005) for Kernel land
  • A simple (But basic) way of loading and executing the Kernel's program main entry point from Stage 2. I will go over the PE file format, but not in alot of detail here--We will do that inside of the Task Manager.
  • Setting up C++ to work (At a basic level, as there are some things that C++ requires that we simply cannot handle yet--such as new/delete)

    Guess thats all for now...[looksaround]
  • Sign in to follow this  


    Recommended Comments

    There are no comments to display.

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    • Advertisement

    Important Information

    By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

    GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

    Sign me up!