Virtual functions and Kernel Code

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.
Post Reply
vasdenjas

Virtual functions and Kernel Code

Post by vasdenjas »

Hi,

I'm trying to write a (very) simple kernel in C++ using object orientation. I wanted to implement device drivers using something similar to an "interface" in Java, in other words, and entirely virtual abstract base class. However, when I try to compile any code with virtual functions, it doesn't link. I understand that I will probably have to re-write some of the C++ library, but can someone tell me where to start, and what to look for.

I'm using gcc (g++) version 3.2.2, and ld version 2.13.90

Thanks
carbonBased

RE:Virtual functions and Kernel Code

Post by carbonBased »

What's the exact error you get?

I created a _minimal_ C++ run-time implementation for Trion... it does little more then stop LD's complains about missing symbols.

If I recall correctly, the only thing I had to define to get virtual functions working was something like this:

       void __cxa_pure_virtual(void)
        {
                console.WriteLine("Kernel Panic: Calling pure virtual method.");
        }

Which I have defined inside an extern "C" { } block.

I _believe_ that's all you should need.  I have implemented other functions, however, to take care of global constructors and destructors, so if you need any help in those areas, let me know.

These will probably be of use, as well:
        void  __cxa_atexit(void (*arg1)(void*), void* arg2, void* arg3) { }
        void* __dso_handle = &__dso_handle;

Keep in mind, these are all specific to gcc 3.x, and will not satisfy LD with pre 3.x compilers.

Cheers,
Jeff
vasdenjas

RE:Virtual functions and Kernel Code

Post by vasdenjas »

Hi,

Thanks. Thats exactly what I needed. I thought it was far more complicated.
Post Reply