Interrupt handlers from an OS standpoint
Posted: Sat Nov 22, 2014 8:52 pm
Hey everyone,
First off, I decided to post this here as I thought it wasn't as 'targeted' as threads are in the mainline OS development subforum. Forgive me, if that doesn't appear to be the case.
Obviously, in real mode interrupts are specified by the 256-entry vector table at the beginning of memory (starting at 0h). I know how to then arrange for an interrupt servicing routine's address to be placed in that table such that on the trigger of that interrupt, that routine is executed. However, what I don't understand is how to make this situation "track" or map over to the current running process, even if there aren't multiple processes in action. Let me try to paint a little picture in code to illustrate what I'm talking about; I may be describing poorly something others of you know very well.
I'm right now writing the keyboard POST/initializer for an operating system I'm trying to run on a homebrew AT that I discuss a little bit in the first post here. All goes well until I hit the point where I need to start interacting with the device.
Obviously, the device will respond with an interrupt when it puts data into the 8042 buffer, in which case the ISR can put the data into AX or AL or something of that nature for when it returns. Because the CPU is stalled and waiting for the interrupt via the HLT instruction, it's a no-brainer to figure out that all I would need to do in the next line of code is read out of that register and the data is there.
Making such an ISR a minute bit more complex would be to pump the 8042 buffer to memory and then include a pointer to the base of the copied buffer stack, in which case reading would only be trivially more difficult. This would allow for me to begin to pave the way on implementation of things like scanf and such.
Here's what I see. If an ISR like that is used, then execution in a scenario where the code is not designed to halt and wait for the interrupt would just overwrite it and not accomplish the task. Suppose I'm testing a driver in my OS by having it take network data and print it to the screen (heh, not anytime soon), and I want the Escape key to cancel the program. That's fine, but when the ISR returns with the key in AL or pointer or however, it'll just be overwritten by the program, which won't quit.
Doing much deliberation on this, I realized I need two stages of interrupt handling. The interrupt service routine, which determines what a program or process does with an event, and the interrupt handler, which manages the event on the hardware level, focuses the data and asserts that process ISR.
I thought a little bit on how to implement it, but stopped when I realized that the sheer magnitude of it just made my brain hurt and I would need to consult others for advice. What I thought of in terms of how it would work was the new process coming into effect would retarget the interrupt handler to that process's ISR, if it employed them.
So, the initial discussion focuses at two things -
First, is this the manner in which these things work? These are just my thoughts on how I thought such a scenario would be implemented, but I have no idea if I'm on the right track or if I'm dead wrong.
Second of all, can anyone help me start to figure out how to implement such a thing, if it is indeed the correct way of doing things?
First off, I decided to post this here as I thought it wasn't as 'targeted' as threads are in the mainline OS development subforum. Forgive me, if that doesn't appear to be the case.
Obviously, in real mode interrupts are specified by the 256-entry vector table at the beginning of memory (starting at 0h). I know how to then arrange for an interrupt servicing routine's address to be placed in that table such that on the trigger of that interrupt, that routine is executed. However, what I don't understand is how to make this situation "track" or map over to the current running process, even if there aren't multiple processes in action. Let me try to paint a little picture in code to illustrate what I'm talking about; I may be describing poorly something others of you know very well.
I'm right now writing the keyboard POST/initializer for an operating system I'm trying to run on a homebrew AT that I discuss a little bit in the first post here. All goes well until I hit the point where I need to start interacting with the device.
Code: Select all
8042_DEV_CONF:
SEI # Enable interrupts
# Send device commands here.
HLT # Halt and wait for interrupt.
Making such an ISR a minute bit more complex would be to pump the 8042 buffer to memory and then include a pointer to the base of the copied buffer stack, in which case reading would only be trivially more difficult. This would allow for me to begin to pave the way on implementation of things like scanf and such.
Here's what I see. If an ISR like that is used, then execution in a scenario where the code is not designed to halt and wait for the interrupt would just overwrite it and not accomplish the task. Suppose I'm testing a driver in my OS by having it take network data and print it to the screen (heh, not anytime soon), and I want the Escape key to cancel the program. That's fine, but when the ISR returns with the key in AL or pointer or however, it'll just be overwritten by the program, which won't quit.
Doing much deliberation on this, I realized I need two stages of interrupt handling. The interrupt service routine, which determines what a program or process does with an event, and the interrupt handler, which manages the event on the hardware level, focuses the data and asserts that process ISR.
I thought a little bit on how to implement it, but stopped when I realized that the sheer magnitude of it just made my brain hurt and I would need to consult others for advice. What I thought of in terms of how it would work was the new process coming into effect would retarget the interrupt handler to that process's ISR, if it employed them.
So, the initial discussion focuses at two things -
First, is this the manner in which these things work? These are just my thoughts on how I thought such a scenario would be implemented, but I have no idea if I'm on the right track or if I'm dead wrong.
Second of all, can anyone help me start to figure out how to implement such a thing, if it is indeed the correct way of doing things?