Exception halts the system.

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
abhishekmaharana
Posts: 16
Joined: Sat Aug 23, 2008 4:13 am

Exception halts the system.

Post by abhishekmaharana »

Hello and sorry for yet another newbie question.

In my timer driver(protected mode kernel) using inline assembly in gcc, I get an exception and the system halts.
ACTUALLY I was trying to read the number of ticks from the BIOS but got an exception. my code is given below-

Code: Select all

__asm__ __volatile__ ("movl $0 5eax;");
__asm__ __volatile__ ("int $31;");//31 is for 1Ah
putint(r->eax);//r=struct regs pointer variable
without this bit of code,the system is running smoothly.
Can you please point out what is going wrong?
Thanks and regards.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Exception halts the system.

Post by neon »

You cant use bios interrupts in protected mode. There are methods around this (like v86 mode or switching between real and protected modes) though if you need to use the bios.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Exception halts the system.

Post by Troy Martin »

You could always write a timer interrupt and set up the PIC.
Last edited by Troy Martin on Thu Apr 16, 2009 8:34 pm, edited 1 time in total.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
Zenith
Member
Member
Posts: 224
Joined: Tue Apr 10, 2007 4:42 pm

Re: Exception halts the system.

Post by Zenith »

You're in protected mode, so the BIOS functions... do not function :lol:. Especially if you've moved the IDT to a different place.

The reason you're causing an exception is because you're calling one directly! Interrupt 31 is classified as a reserved exception (in protected and long mode) by Intel, and if you call it, then it'll occur, and an emulator would report it as an exception :roll:. There'd probably be no code to handle it, leading to a triple fault, and crashing the computer.

Here's an article on using the Real Time Clock (if you want to get the date and time), and here's an article on using the Programmable Interval Timer (PIT) to generate an interrupt at set time intervals.

Good luck :)

EDIT: Damn, I'm slow at replying. TroyMartin, don't be too hard on him. From his previous posts, he seems like a welcome change to the regular how-2-rite-os!? n00bs that we usually have. How many of us were actually aware of the functionality of 16-bit real mode and programming the PIT before we started OSDev? 8)
"Sufficiently advanced stupidity is indistinguishable from malice."
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Exception halts the system.

Post by Troy Martin »

Boredom hit the better of me.

ahhh god I'm gonna hear from James about this in the morning...
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Exception halts the system.

Post by neon »

Zenith wrote:How many of us were actually aware of the functionality of 16-bit real mode and programming the PIT before we started OSDev? 8)
Im sure alot of members here... *ahem* (Except the PIT for me..)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: Exception halts the system.

Post by 01000101 »

I've decided not to lock this thread (yet) as it would be both unfair to the OP to not get a chance to reply and unfair in that this could potentially be a good learning experience for a starter. Let's not be to harsh just yet, it's better to deal with a little bit of foolishness and help him/her out than to be overly-harsh and make a fool of yourself. :wink:

keep in mind: OSDev.org - The Place to Start for Operating System Developers

@OP: PIT information and a few starter tutorials, get readin'!
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Exception halts the system.

Post by Troy Martin »

I learned real mode and stuffs through indirect OSDev. I meddled around with MikeOS to learn the basics and then learned more assembly and OSDev.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
abhishekmaharana
Posts: 16
Joined: Sat Aug 23, 2008 4:13 am

Re: Exception halts the system.

Post by abhishekmaharana »

Thank you everybody.I didn't know that we can't call BIOS routines in protected mode.
And thanks for being considerate enough to entertain a newbie.

Thank you Zenith for those two links.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Exception halts the system.

Post by JamesM »

Troy Martin wrote:Boredom hit the better of me.

ahhh god I'm gonna hear from James about this in the morning...
No, you're not, because you edited your post too quickly ;)
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Exception halts the system.

Post by Troy Martin »

*whew*

Newbie latency and spark-o-the-moment thought triumph again!
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
Post Reply