.intel_syntax noprefix
.extern x86_64_ISR_Handler

.macro ISR_NOERRORCODE num
    .global x86_64_ISR\num
x86_64_ISR\num:
    push 0
    push \num
    jmp isr_common
.endm

.macro ISR_ERRORCODE num
    .global x86_64_ISR\num
x86_64_ISR\num:
    push \num
    jmp isr_common
.endm

.include "arch/x86_64/isrs_gen.inc"   // ← update path if needed

isr_common:
    push rax
    push rbx
    push rcx
    push rdx
    push rbp
    push rsi
    push rdi
    push r8
    push r9
    push r10
    push r11
    push r12
    push r13
    push r14
    push r15

    mov rdi, rsp               // Registers* in RDI
    call x86_64_ISR_Handler

    pop r15
    pop r14
    pop r13
    pop r12
    pop r11
    pop r10
    pop r9
    pop r8
    pop rdi
    pop rsi
    pop rbp
    pop rdx
    pop rcx
    pop rbx
    pop rax

    add rsp, 16                // pop interrupt + error code
    iretq