Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: Installing ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 17 Topic 26124 of 26960
Post > Topic >>

Re: Installing a C function into the IDT

by The Prisoner <nospam@[EMAIL PROTECTED] > May 8, 2008 at 10:34 PM

jacob navia wrote:
> The Prisoner wrote:
> 
>> Hey-
>>
>> I was reading about interrupts, and I got to thinking it would be a 
>> real neat thing to use interrupts for program-wide exception handling. 
>> What I haven't been able to find is a clear guide or example program 
>> for how to install a C function into the IDT. And what happens about 
>> passing arguments?
>>
>> I'd like to have something like this:
>>
>> void malloc_failure();
>>
>> Say I install this as interrupt slot 42, then I can do:
>>
>> if(!(p=(int*)malloc(1000*4))) // array of 1000 ints
>>   __asm__ ("int $0x42");
>>
>> Is there any reason for this not to work? How do I set up the 
>> interrupts? Would I need root privelidges to do that?
>>
>> Thanks!!
> 
> 
> This would be interrupt based exception handling... a risky business.

Jacob,

Why would it be risky? I'm glad it's not completely crazy if it's a 
known technique.

It would be good because if you have a project with many *.c files, you 
could just access one global exception-handling function without having 
to put a declaration for it in every single source file.

> It would be difficult to write it in C. Normally interrupt servicing
> routines should return with a return from interrupt instruction, and not
> just a return like a normal function does. You compiler would need
> to sup****t that...
 >
> Besides, interrupt routines should not destroy any registers, and the
> registers it uses should have been saved...

OK... so I guess you need a bit of inline assembler before the interrupt 
call, where you push registers. Then just before the end of the C 
handler function, you have some more inline assembler that pops the 
registers back and returns from interrupt.

This is starting to sound like it could work.

How do you put the function's address into the IDT? I guess it may be 
simpler to have a void function taking a void parameter so there's no 
need to worry about passing arguments.
 




 17 Posts in Topic:
Installing a C function into the IDT
The Prisoner <nospam@[  2008-05-08 21:47:34 
Re: Installing a C function into the IDT
jacob navia <jacob@[EM  2008-05-08 23:00:44 
Re: Installing a C function into the IDT
The Prisoner <nospam@[  2008-05-08 22:34:27 
Re: Installing a C function into the IDT
Ian Collins <ian-news@  2008-05-09 09:42:17 
Re: Installing a C function into the IDT
Keith Thompson <kst-u@  2008-05-08 15:17:31 
Re: Installing a C function into the IDT
Keith Thompson <kst-u@  2008-05-08 15:31:59 
Re: Installing a C function into the IDT
Ian Collins <ian-news@  2008-05-09 10:46:21 
Re: Installing a C function into the IDT
Erik Trulsson <ertr101  2008-05-08 23:58:43 
Re: Installing a C function into the IDT
jt@[EMAIL PROTECTED] (Je  2008-05-08 22:14:45 
Re: Installing a C function into the IDT
Keith Thompson <kst-u@  2008-05-08 15:23:50 
Re: Installing a C function into the IDT
The Prisoner <nospam@[  2008-05-08 23:29:32 
Re: Installing a C function into the IDT
Ian Collins <ian-news@  2008-05-09 10:51:44 
Re: Installing a C function into the IDT
jt@[EMAIL PROTECTED] (Je  2008-05-08 23:17:28 
Re: Installing a C function into the IDT
"cr88192" <c  2008-05-09 16:33:26 
Re: Installing a C function into the IDT
Antoninus Twink <nospa  2008-05-09 14:58:07 
Re: Installing a C function into the IDT
Ben Bacarisse <ben.use  2008-05-09 00:46:39 
Re: Installing a C function into the IDT
Owen Jacobson <angryba  2008-05-08 22:01:14 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 16:36:46 CDT 2008.