Page 1 of 1

kernel in C++ : adding a class method makes crashing the os

Posted: Wed Nov 28, 2007 7:43 am
by jeandaniel
Hi, we are 2 students developping an os in C++.
We have made idt,gdt,irq0 and irq1 to work.
We have got a shell with commands.
this is our Commands'class

#ifndef COMMANDES_HPP
#define COMMANDES_HPP

#include "video.hpp"
#include "iostream.hpp"
#include "keyboard.hpp"

class Commandes
{
private:
void clear();
void systeme();
#if 0
void exit();
#endif
Video * v;
Keyboard key;
unsigned char couleur;
public:
Commandes();
void setArg(Video& vid,unsigned char couleurShell);
void execute(char * querry);
};

#endif

so the os goes good but if we add the exit methode it crash, and if we add some code in an other commands'method too.
If you have any idea :/

Posted: Wed Nov 28, 2007 8:31 am
by JamesM
You mean if you change that "#ifdef 0" to "#ifdef 1", the kernel crashes?

I can't see why that would happen. Or do you mean *calling* the exit function causes the crash? :s

Re: kernel in C++ : adding a class method makes crashing the

Posted: Wed Nov 28, 2007 8:44 am
by AJ
Hi,

First, when you change the class header, all source files referencing the class are recompiled (if you are using a custom makefile, this may not automatically happen).

Second, are you using a custom malloc/new implementation. The bug may be with your malloc() routine (when you go over a certain class size, malloc() doesn't like it). This could be for any number of reasons - particularly if you are using paging.

Thirdly, what format is the binary? If you are crashing if you add *any* new methods, chances are that it is the binary relocation / fixup code that needs some attention.

As JamesM said - more detail please. What happens? Triple-fault? Have you got to the stage where you can display a register dumpp on a crash? Does the computer just hang? etc...

Cheers,
AJ

Posted: Wed Nov 28, 2007 10:58 am
by jeandaniel
firstly we didn't have implemented malloc in our os yet.
we are using ELF format
i sent you a zip containing our os sources.
thx a lot
ps: we are using nasm/as/C and C++
for example the irq0 call a C function which call a C++ function

Posted: Wed Nov 28, 2007 11:00 am
by JamesM
How can other people help if you PM AJ all your data?

Posted: Wed Nov 28, 2007 11:04 am
by jeandaniel
i'm developping on a iMac with vmware fusion ( i compile on Debian etch)
and my friend is developping on Suse using vmware workstation.

Posted: Wed Nov 28, 2007 11:30 am
by AJ
Hi,

I don't have time to read through sources at the moment anyway, but how about trying the C PlusPlus wiki article and looking at a few of those suggestions from previously - like reviewing your elf loader, checking you have enough stack space and so on.

It would also be useful to see the Bochs register dump when your program crashes. I'll look tomorrow if I get a chance, but at least have a look at debugging in an emulator first.

Cheers,
Adam

Posted: Thu Nov 29, 2007 2:44 am
by JamesM
Just tried to test your OS, and after running "make" I don't get a valid floppy image: bochs and qemu both fall over trying to read it.

Posted: Fri Nov 30, 2007 1:52 am
by jeandaniel
Should i implement malloc/free in order to continue ( perhaps by the fact i haven't implemented malloc/free yet, our os is writing in the stack ?)
if we don't use malloc ( new ...) is the size of our code limited ???

Posted: Fri Nov 30, 2007 2:21 am
by JamesM
If you don't have a malloc implementation you can't use 'new' and that's it. The size of your code isn't limited at all. How do you make your OS? I tried (see above) but didn't end up with a valid image.

Posted: Fri Nov 30, 2007 4:07 am
by jeandaniel
i sent you the working version of our OS
If you add some code it will crash.
We don't understand why :/
thx

Posted: Fri Nov 30, 2007 4:21 am
by JamesM
Well it doesn't work- the floppy image generated is 16KB big, which strikes me as strange.

Posted: Fri Nov 30, 2007 6:18 am
by nick8325
Your bootsector only loads 15KB of data, and your kernel is almost 15KB. If you add more code, the kernel will become too big and the bootsector won't load all of it. You should increase KSIZE in bootsect.asm.

Posted: Fri Nov 30, 2007 8:22 am
by JamesM
Nice spot nick, I wanted to get it running first before i debugged it! Did anyone actually get it to run? qemu and bochs complain bitterly...

EDIT: After investigation it seems likely that the code is being compiled to a larger size on my system, so your kernel is crashing. nick's answer is right.

Posted: Fri Nov 30, 2007 8:54 am
by jeandaniel
yeah thx a lot ;)