; SPDX-License-Identifier: MPL-2.0
global sh_irq_common_stub
extern sh_irq_dispatch

%macro SH_IRQ_NOERR 1
global sh_irq_noerr_%1
sh_irq_noerr_%1:
  push 0              ; fake error code
  push %1             ; vector
  jmp sh_irq_common_stub
%endmacro

%macro SH_IRQ_ERR 1
global sh_irq_err_%1
sh_irq_err_%1:
  push %1             ; vector (CPU already pushed error code)
  jmp sh_irq_common_stub
%endmacro

SH_IRQ_NOERR 0 ; div by zero
SH_IRQ_NOERR 1 ; debug
SH_IRQ_NOERR 2 ; nmi
SH_IRQ_NOERR 3 ; breakpoint
SH_IRQ_NOERR 4 ; overflow
SH_IRQ_NOERR 5 ; bound range exceeded
SH_IRQ_NOERR 6 ; invalid opcode
SH_IRQ_NOERR 7 ; device not available
SH_IRQ_ERR 8 ; double fault
SH_IRQ_NOERR 9 ; coprocessor segment overrun
SH_IRQ_ERR 10 ; invalid tss
SH_IRQ_ERR 11 ; segment not present
SH_IRQ_ERR 12 ; stack segment fault
SH_IRQ_ERR 13 ; general protection fault
SH_IRQ_ERR 14 ; page fault
SH_IRQ_NOERR 16 ; x87 floating point exception
SH_IRQ_ERR 17 ; alignment check
SH_IRQ_NOERR 18 ; machine check
SH_IRQ_NOERR 19 ; simd floating point exception
SH_IRQ_NOERR 20 ; virtualization exception
SH_IRQ_ERR 21 ; control protection exception
SH_IRQ_NOERR 28 ; hypervisor injection exception
SH_IRQ_ERR 29 ; vmm communication exception
SH_IRQ_ERR 30 ; security exception
SH_IRQ_NOERR 32 ; PIC IRQ0 aka PIT tick
SH_IRQ_NOERR 33 ; IOAPIC legacy IRQ
SH_IRQ_NOERR 34 ; IOAPIC legacy IRQ
SH_IRQ_NOERR 35 ; IOAPIC legacy IRQ
SH_IRQ_NOERR 36 ; IOAPIC legacy IRQ
SH_IRQ_NOERR 37 ; IOAPIC legacy IRQ
SH_IRQ_NOERR 38 ; IOAPIC legacy IRQ
SH_IRQ_NOERR 39 ; IOAPIC legacy IRQ
SH_IRQ_NOERR 40 ; IOAPIC legacy IRQ
SH_IRQ_NOERR 41 ; IOAPIC legacy IRQ
SH_IRQ_NOERR 42 ; IOAPIC legacy IRQ
SH_IRQ_NOERR 43 ; IOAPIC legacy IRQ
SH_IRQ_NOERR 44 ; IOAPIC legacy IRQ
SH_IRQ_NOERR 45 ; IOAPIC legacy IRQ
SH_IRQ_NOERR 46 ; IOAPIC legacy IRQ
SH_IRQ_NOERR 47 ; IOAPIC legacy IRQ
SH_IRQ_NOERR 254 ; lapic one shot timer vector
SH_IRQ_NOERR 255 ; spurious vector for lapic

section .text

sh_irq_common_stub:
  push rax
  push rcx
  push rdx
  push r8
  push r9
  push r10
  push r11

  mov rdi, rsp
  call sh_irq_dispatch

  pop r11
  pop r10
  pop r9
  pop r8
  pop rdx
  pop rcx
  pop rax

  add rsp, 16
  iretq
