sj95126 wrote:
I can't believe they didn't do this from the very beginning.
Me neither. Although it wasn't a big problem in the beginning. With the 8259 PICs, the interrupts were all static. It wasn't until the advent of the IOAPIC that the number of interrupts became a runtime variable, and with the advent of MSI, the number of interrupts truly exploded.
sj95126 wrote:
In fact, since they would have only needed 8 bits for the interrupt number, they could have used the rest as flags, including a flag that would indicate whether an error code is on the stack, instead of weirdness like #DF pushing an error code that's always 0.
Or just push an error code in every exception. Or no exception, and have an error code register. Either way would be fine to have a uniform interrupt frame. But no, can't have that.
nexos wrote:
I think I once spent an hour creating all my interrupt stubs.
Honestly, I lifted mine from Linux. Oh, err... I mean, I was inspired by Linux. The idea is to encode the interrupt number in a signed byte, so we can always use the small push encoding. Which I do like this:
Code:
.global irq_base
.align 8
irq_base:
.set irq, 32
.rept 256-32
pushq $127-irq
jmp irq_common
.align 8
.set irq, irq+1
.endr
Then in the common handler, I only need to reduce that variable by 127, and I have the negative interrupt number on stack.
And for the exceptions, I have an assembly label named for the exception, and a C function called the same thing, but with a "do_" in front, and the assembler stub calls the C function. And everything can be generated from one macro:
Code:
.macro excpt label,push_error=1,read_cr2=0
\label:
.if \push_error
pushq $0
.endif
save_regs
movq %rsp, %rdi
movq %rsp, %r12 /* non-volatile register */
.if \read_cr2
movq %cr2, %rsi
.endif
andq $-16,%rsp
xorq %r13,%r13
testq $3, 18*8(%rsp)
jz 1f
incq %r13
swapgs
1:
cld
call do_\label
jmp interrupt_return
.endm
Oh yeah, and one more idea lifted from Linux: The interrupt return code can be unified into a single place, because after calling the specific handler, it is all the same.