ゆとりーなの日記

日記的な事を書いて行くと思はれる

アセンブリでマクロ

H8の割り込みハンドラ、こいつはアセンブリで書いているわけですがハンドラの数だけ似たようなコピペをするのが気持ち悪いんでどうにかなんないのと思い最初Cプリプロセッサで足掻いてみたのですがどうも上手くいきませんでした。
調べてみたらgnu asにはマクロの機能があるらしく、これを使えば複数命令を1命令みたく記述出来るようなのでこれを使ってみました。引数も使えるようなので、割り込みIDは引数で渡してやれるのが安定っぽいです。

#include "intr.h"

.macro interrupt num
  mov.l er6, @-er7
  mov.l er5, @-er7
  mov.l er4, @-er7
  mov.l er3, @-er7
  mov.l er2, @-er7
  mov.l er1, @-er7
  mov.l er0, @-er7
  mov.l er7, er1
  mov.l #_interrupt_stack, sp
  mov.l er1, @-er7
  mov.w \num, r0
  jsr   @_interrupt
  mov.l @er7+, er1
  mov.l er1, er7
  mov.l @er7+, er0
  mov.l @er7+, er1
  mov.l @er7+, er2
  mov.l @er7+, er3
  mov.l @er7+, er4
  mov.l @er7+, er5
  mov.l @er7+, er6
  rte
.endm

  .h8300h
  .section .text  
  
  .global	_interrupt_nmi
  .type	_interrupt_nmi, @function
_interrupt_nmi:
  interrupt #AQ_INTERRUPT_NMI
  
  .global	_interrupt_trap0
  .type	_interrupt_trap0, @function
_interrupt_trap0:
  interrupt #AQ_INTERRUPT_TRAP0
  
  .global	_interrupt_trap1
  .type	_interrupt_trap1, @function
_interrupt_trap1:
  interrupt #AQ_INTERRUPT_TRAP1
  
  .global	_interrupt_trap2
  .type	_interrupt_trap2, @function
_interrupt_trap2:
  interrupt #AQ_INTERRUPT_TRAP2

  .global	_interrupt_trap3
  .type	_interrupt_trap3, @function
_interrupt_trap3:
  interrupt #AQ_INTERRUPT_TRAP3
  
  .global	_interrupt_irq0
  .type	_interrupt_irq0, @function
_interrupt_irq0:
  interrupt #AQ_INTERRUPT_IRQ0
  
  .global	_interrupt_irq1
  .type	_interrupt_irq1, @function
_interrupt_irq1:
  interrupt #AQ_INTERRUPT_IRQ1
  
  .global	_interrupt_irq2
  .type	_interrupt_irq2, @function
_interrupt_irq2:
  interrupt #AQ_INTERRUPT_IRQ2

  .global	_interrupt_irq3
  .type	_interrupt_irq3, @function
_interrupt_irq3:
  interrupt #AQ_INTERRUPT_IRQ3
  
  .global	_interrupt_irq4
  .type	_interrupt_irq4, @function
_interrupt_irq4:
  interrupt #AQ_INTERRUPT_IRQ4

  .global	_interrupt_irq5
  .type	_interrupt_irq5, @function
_interrupt_irq5:
  interrupt #AQ_INTERRUPT_IRQ5
  
  .global	_interrupt_wovi
  .type	_interrupt_wovi, @function
_interrupt_wovi:
  interrupt #AQ_INTERRUPT_WOVI
  
  .global	_interrupt_cmi
  .type	_interrupt_cmi, @function
_interrupt_cmi:
  interrupt #AQ_INTERRUPT_CMI
  
  .global	_interrupt_adi
  .type	_interrupt_adi, @function
_interrupt_adi:
  interrupt #AQ_INTERRUPT_ADI
  
  .global	_interrupt_imia0
  .type	_interrupt_imia0, @function
_interrupt_imia0:
  interrupt #AQ_INTERRUPT_IMIA0
  
  .global	_interrupt_imib0
  .type	_interrupt_imib0, @function
_interrupt_imib0:
  interrupt #AQ_INTERRUPT_IMIB0
  
  .global	_interrupt_ovi0
  .type	_interrupt_ovi0, @function
_interrupt_ovi0:
  interrupt #AQ_INTERRUPT_OVI0
 
  .global	_interrupt_imia1
  .type	_interrupt_imia1, @function
_interrupt_imia1:
  interrupt #AQ_INTERRUPT_IMIA1
  
  .global	_interrupt_imib1
  .type	_interrupt_imib1, @function
_interrupt_imib1:
  interrupt #AQ_INTERRUPT_IMIB1
  
  .global	_interrupt_ovi1
  .type	_interrupt_ovi1, @function
_interrupt_ovi1:
  interrupt #AQ_INTERRUPT_OVI1
  
  .global	_interrupt_imia2
  .type	_interrupt_imia2, @function
_interrupt_imia2:
  interrupt #AQ_INTERRUPT_IMIA2
  
  .global	_interrupt_imib2
  .type	_interrupt_imib2, @function
_interrupt_imib2:
  interrupt #AQ_INTERRUPT_IMIB2
  
  .global	_interrupt_ovi2
  .type	_interrupt_ovi2, @function
_interrupt_ovi2:
  interrupt #AQ_INTERRUPT_OVI2
  
  .global	_interrupt_cmia0
  .type	_interrupt_cmia0, @function
_interrupt_cmia0:
  interrupt #AQ_INTERRUPT_CMIA0
  
  .global	_interrupt_cmib0
  .type	_interrupt_cmib0, @function
_interrupt_cmib0:
  interrupt #AQ_INTERRUPT_CMIB0
  
  .global	_interrupt_cmiab1
  .type	_interrupt_cmiab1, @function
_interrupt_cmiab1:
  interrupt #AQ_INTERRUPT_CMIAB1
  
  .global	_interrupt_tovi01
  .type	_interrupt_tovi01, @function
_interrupt_tovi01:
  interrupt #AQ_INTERRUPT_TOVI01
  
  .global	_interrupt_cmia2
  .type	_interrupt_cmia2, @function
_interrupt_cmia2:
  interrupt #AQ_INTERRUPT_CMIA2
  
  .global	_interrupt_cmib2
  .type	_interrupt_cmib2, @function
_interrupt_cmib2:
  interrupt #AQ_INTERRUPT_CMIB2
  
  .global	_interrupt_cmiab3
  .type	_interrupt_cmiab3, @function
_interrupt_cmiab3:
  interrupt #AQ_INTERRUPT_CMIAB3
  
  .global	_interrupt_tovi23
  .type	_interrupt_tovi23, @function
_interrupt_tovi23:
  interrupt #AQ_INTERRUPT_TOVI23
  
  .global	_interrupt_dend0a
  .type	_interrupt_dend0a, @function
_interrupt_dend0a:
  interrupt #AQ_INTERRUPT_DEND0A
  
  .global	_interrupt_dend0b
  .type	_interrupt_dend0b, @function
_interrupt_dend0b:
  interrupt #AQ_INTERRUPT_DEND0B
  
  .global	_interrupt_dend1a
  .type	_interrupt_dend1a, @function
_interrupt_dend1a:
  interrupt #AQ_INTERRUPT_DEND1A
  
  .global	_interrupt_dend1b
  .type	_interrupt_dend1b, @function
_interrupt_dend1b:
  interrupt #AQ_INTERRUPT_DEND1B
  
  .global	_interrupt_eri0
  .type	_interrupt_eri0, @function
_interrupt_eri0:
  interrupt #AQ_INTERRUPT_ERI0
  
  .global	_interrupt_rxi0
  .type	_interrupt_rxi0, @function
_interrupt_rxi0:
  interrupt #AQ_INTERRUPT_RXI0
  
  .global	_interrupt_txi0
  .type	_interrupt_txi0, @function
_interrupt_txi0:
  interrupt #AQ_INTERRUPT_TXI0
  
  .global	_interrupt_tei0
  .type	_interrupt_tei0, @function
_interrupt_tei0:
  interrupt #AQ_INTERRUPT_TEI0
  
  .global	_interrupt_eri1
  .type	_interrupt_eri1, @function
_interrupt_eri1:
  interrupt #AQ_INTERRUPT_ERI1

  .global	_interrupt_rxi1
  .type	_interrupt_rxi1, @function
_interrupt_rxi1:
  interrupt #AQ_INTERRUPT_RXI1
  
  .global	_interrupt_txi1
  .type	_interrupt_txi1, @function
_interrupt_txi1:
  interrupt #AQ_INTERRUPT_TXI1
  
  .global	_interrupt_tei1
  .type	_interrupt_tei1, @function
_interrupt_tei1:
  interrupt #AQ_INTERRUPT_TEI1
  
  .global	_interrupt_eri2
  .type	_interrupt_eri2, @function
_interrupt_eri2:
  interrupt #AQ_INTERRUPT_ERI2

  .global	_interrupt_rxi2
  .type	_interrupt_rxi2, @function
_interrupt_rxi2:
  interrupt #AQ_INTERRUPT_RXI2

  .global	_interrupt_txi2
  .type	_interrupt_txi2, @function
_interrupt_txi2:
  interrupt #AQ_INTERRUPT_TXI2

  .global	_interrupt_tei2
  .type	_interrupt_tei2, @function
_interrupt_tei2:
  interrupt #AQ_INTERRUPT_TEI2

これで大分落ち着きました。一つ一つ割り込みハンドラ分けようと思ったので何十個もコピペするのは流石にだるいと思ってたので結構助かりました。