3
$\begingroup$

I'm currently working on designing a relatively simple processor using a custom ISA . It will use interrupts for I/O .

From what i know , once the interrupt controller issues an interrupt , the processor acknowledges it and set it's PC to the IVT , from where it executes the relevant interrupt handler , which specifies what the CPU does .

These interrupt handlers are set by the OS and cannot be modified by the user-mode process.

My question is this : how does the process know when an interrupt has occurred ? the cpu might execute the handler and place the acquired controller data in a memory location , but how is the application notified ? what are the common methods of doing this ?

For example , say i have a platform game ; when i press the assigned jump key , the cpu will acquire the keyboard data , but how does it go from there to actually making the sprite jump in a video game ? does the app still have to check for controller input at regular intervals ?

$\endgroup$

2 Answers 2

3
$\begingroup$

The interrupt handler adds the new data to an input queue. Typically the user level process will have a thread waiting for input to appear, or will poll periodically to see if new input is available. If your process does neither, it would never notice the new data.

$\endgroup$
1
$\begingroup$

In your keyboard example, the operating system will receive interrupts and figure out that a key has been pressed or released. But who to tell?

Usually you will have multiple applications running simultaneously. Only one will receive the notification about the key being pressed. Usually that is an important security measure: While I type this message, I want the keys to go to the browser, not to any other application. Worse, if I type a credit card number, I most definitely don't want any random application to know about it. So the operating system will tell one application.

On MacOS for example, a data structure describing the event (key "X" was pressed while the shift and control key were held) will be added to a queue maintained by the application, and every time that queue is non-empty the application will have told the operating system which function to call (simplified version), and that function is called. Other operating systems will likely do very similar things.

$\endgroup$
3
  • $\begingroup$ So basically , the software still has to do some kind of polling ? $\endgroup$ Apr 13, 2018 at 21:08
  • 1
    $\begingroup$ @coaxialgamer Uh, no. As gnasher729 said, the application will register an "event handler" to the queue which the operating system will call when events are added to the queue by the operating system in response to an interrupt. $\endgroup$ Apr 13, 2018 at 22:59
  • $\begingroup$ I understand that . The input is added to a queue , and a thread ( the event listener ) is usually in charge of checking said queue . Doesn't this mean that thread has to check the queue at regular intervals , ie polling? @Derek Elkins $\endgroup$ Apr 14, 2018 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.