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

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
User avatar
rJah
Posts: 20
Joined: Tue Jun 26, 2007 12:36 pm

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

Post 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
This is not a productive area of discussion
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Make sure your 'struct regs' is packed (__attribute((packed)))?
User avatar
rJah
Posts: 20
Joined: Tue Jun 26, 2007 12:36 pm

Post 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
This is not a productive area of discussion
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

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

Post 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
User avatar
rJah
Posts: 20
Joined: Tue Jun 26, 2007 12:36 pm

Post 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.
This is not a productive area of discussion
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post 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?
Post Reply