zap8600 wrote:
How would I write an ISR in C?
In a typical OS, you would need
an assembly wrapper to save and restore the registers so you can manipulate the task's state. To keep code size down, you can have 256 entry points (one for each ISR) that push the vector onto the stack and jump to a common assembly wrapper, and then pass that value to the C function so it can dispatch a handler depending on the interrupt vector.
zap8600 wrote:
The following code is from the
wiki.
GCC's __attribute__((interrupt)) is meant for things like single-threaded bare metal programs. It's not suitable for an OS.
zap8600 wrote:
What does the function need to do?
That depends on what caused the interrupt. If it's an exception, you'll probably want to display the contents of the saved registers and halt the CPU for now. (In the future, you might instead terminate the offending program, or send a signal, or fix whatever caused the exception and return.) If it's a hardware interrupt, you need to respond appropriately for the hardware in question. That might mean calling a driver handler, or it might mean masking the IRQ and waking a driver thread, or maybe something else.
zap8600 wrote:
How many of these do I need to define?
At minimum, you need enough to cover the CPU's exception vectors and whichever hardware IRQs you want to support. They can all share most of the code, as long as each has a unique entry point that keeps track of the vector somehow.
The CPU itself supports up to 256 vectors, and you may end up needing all them in the future.
zap8600 wrote:
What does interrupt_frame need to be?
A struct that matches the layout of the values placed on the stack. Since you should be writing your own assembly stub, what goes into the struct will depend on the assembly code you write.
zap8600 wrote:
Or does this handle the ISRs and the ISRs are different?
Different from what?