Page 1 of 1

ISR error in c++ kernel, c kernel works fine

Posted: Thu Jul 26, 2007 2:50 pm
by rJah
Hi, all.
This is the first time I had to resort to posting, because i always found a solution on this forum before.

Anyway, the story so far is this:
I started with Bran's kernel development tutorial and then added a PMM and a VMM. Then I decided to start version 0.02 of my OS, because the code had become to complex and i needed to clean it up. At that time I decided to rewrite the whole thing using c++ because I prefer the OO approach.

I have the PMM, VMM, GDT and IDT classes and they work fine. I also have the ISR class which installs the routines and my isr_common_stub calls a void fault_handler function that is not in the ISR class.

I install the isrs, enable interrupts and then generate a divide by zero exception. In the fault handler I print out the register contents on the stack:

Code: Select all

gs: 0x10    fs: 0x10     es: 0x10    ds: 0x480010
edi: 0x2ca44    esi: 0x2ca43     ebp: 0x487fe8   esp: 0x487fac
eax: 0x8    ebx: 0x2c8e0     ecx: 0xb8000    edx: 0x4881ec
eip: 0x8    cs: 0x206    eflg: 0x4008ed  esp3: 0x2c8e0
ss: 0x2badb002
int_no: 8   err_code: 4197307
As you can see, the problem is in the int_no and err_code. I allwys get int_no=8 and err_code=gibberish, but in the C kernel this worked fine (and I enabled paging before anything else, just like now).

So my question is this:
Does c++ do something differently or do I have to implement support fo exceptions for this to work?

Thanks all

Posted: Thu Jul 26, 2007 3:36 pm
by pcmattman
Make sure your 'struct regs' is packed (__attribute((packed)))?

Posted: Thu Jul 26, 2007 3:48 pm
by rJah
Yeah, it is. But I realised that I AM getting a double fault when I turn interrupts on. I dont know why it took me so long to realise that.
Thanks for the help anyway

Posted: Fri Jul 27, 2007 1:01 am
by JamesM
I allwys get int_no=8
Remember that the code segment selector in bran's tutorial is 0x8. You could be accidentally getting that in int_no. Check you're register struct. (Agreeing with pcmattman)

EDIT:

Is you're struct regs now a class, now you've moved to c++? If it is, the attribute packed probably won't work and the compiler may move some ugly in front of it. Especially if you haven't disabled RTTI. Quickly change it back to a struct and check it again.

JamesM

Posted: Fri Jul 27, 2007 1:15 am
by AJ
Yes - if you look at CS, it contains what I suspect should be in EFLAGS. SS contans what suspiciously looks like the multiboot magic value, which should probably be in a register, and you have a divide by zero exception when none of the 8 general purpose registers contain zero - can that happen?

Again, your Error Code and int no. values seem to contain the CS:EIP return address combination, I think?

Cheers,
Adam

Posted: Fri Jul 27, 2007 5:34 pm
by rJah
The regs are a struct, packed, everything is the same except the install functions are now in classes. The ISR class installs the _isrs. The fault_handler is a global function. And I do disable RTTI.

I'll take a look at it tomorow. Now I really need to get some sleep.

Posted: Tue Jul 31, 2007 3:27 pm
by Candy
rJah wrote:The regs are a struct, packed, everything is the same except the install functions are now in classes. The ISR class installs the _isrs. The fault_handler is a global function. And I do disable RTTI.

I'll take a look at it tomorow. Now I really need to get some sleep.
Did you check the sizeof(x) to see whether it matches what you think it should?