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

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
jeandaniel
Posts: 14
Joined: Wed Nov 14, 2007 3:26 pm
Location: Paris, France

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

Post 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 :/
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

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

Post 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
jeandaniel
Posts: 14
Joined: Wed Nov 14, 2007 3:26 pm
Location: Paris, France

Post 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
Attachments
nonos.zip
(36.13 KiB) Downloaded 54 times
Last edited by jeandaniel on Wed Nov 28, 2007 11:02 am, edited 1 time in total.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

How can other people help if you PM AJ all your data?
jeandaniel
Posts: 14
Joined: Wed Nov 14, 2007 3:26 pm
Location: Paris, France

Post 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.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post 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
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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.
jeandaniel
Posts: 14
Joined: Wed Nov 14, 2007 3:26 pm
Location: Paris, France

Post 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 ???
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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.
jeandaniel
Posts: 14
Joined: Wed Nov 14, 2007 3:26 pm
Location: Paris, France

Post 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
Attachments
nonos.zip
(60.41 KiB) Downloaded 49 times
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Well it doesn't work- the floppy image generated is 16KB big, which strikes me as strange.
nick8325
Member
Member
Posts: 200
Joined: Wed Oct 18, 2006 5:49 am

Post 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.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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.
jeandaniel
Posts: 14
Joined: Wed Nov 14, 2007 3:26 pm
Location: Paris, France

Post by jeandaniel »

yeah thx a lot ;)
Post Reply