Executing C Kernel #101

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.
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Executing C Kernel #101

Post 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.)
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
Haroogan
Member
Member
Posts: 28
Joined: Thu Aug 04, 2011 1:10 pm

Re: Executing C Kernel #101

Post 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.
immibis
Posts: 19
Joined: Fri Dec 18, 2009 12:38 am

Re: Executing C Kernel #101

Post 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".
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Executing C Kernel #101

Post 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.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
Post Reply