Page 3 of 3

Re: Executing C Kernel #101

Posted: Sun Aug 14, 2011 2:35 pm
by xenos
Yes, sbss and ebss are two labels, and they point to start and end of the bss section. (At least this is what this piece of a linker script defines them to be.)

Re: Executing C Kernel #101

Posted: Mon Aug 15, 2011 7:02 am
by Haroogan
I've just implemented C++ bare bones:

Code: Select all

class Test
{
    public:
        Test()
        {
            mem = reinterpret_cast<unsigned short *>(0xB8000);

            * mem++ = 0x4041;
        }

        ~Test()
        {
            * mem++ = 0x4042;
        }
    private:
        unsigned short * mem;
};

Test test;

extern unsigned long StartConstructors;
extern unsigned long EndConstructors;
extern unsigned long StartDestructors;
extern unsigned long EndDestructors;

extern "C" void Main( void* mbd, unsigned int magic )
{
   if ( magic != 0x2BADB002 )
   {

   }

   for(unsigned long *constructor(&StartConstructors); constructor < &EndConstructors; ++constructor)
       ((void (*) (void)) (*constructor)) ();

   char * boot_loader_name =(char*) ((long*)mbd)[16];

   for(unsigned long *destructor(&StartDestructors); destructor < &EndDestructors; ++destructor)
       ((void (*) (void)) (*destructor)) ();
}
Everything compiles and runs fine, but the problem is that Destructors for global objects are not invoked at all. You can see it in "Test" class. There was one post about it somewhere here, but still no solution. Shall I ignore that?

P. S. I've added ICPPABI stuff.

EDIT: I've noticed that "__cxa_finalize" is never invoked too.

Re: Executing C Kernel #101

Posted: Mon Aug 15, 2011 8:03 pm
by immibis
Haroogan wrote:
EDIT: I've noticed that "__cxa_finalize" is never invoked too.
I believe you have to invoke it yourself. The compiler certainly doesn't know when your OS has "exited".

Re: Executing C Kernel #101

Posted: Tue Aug 16, 2011 1:16 am
by xenos
Have you looked up the C++ article in the wiki? It describes the usage of global objects in a kernel quite well.

My personal preference is to use no global objects at all, and to create / destroy all objects when they are needed.