Advertisement
Guest User

coto: own GBA/NDS IRQ handler ya know.

a guest
Feb 16th, 2015
457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 2.30 KB | None | 0 0
  1. @this is Coto's IRQ handler
  2. @----------------------------------interrupt request handler---------------------------------------------
  3. @IRQ BIOS Setup (this is definitely from coto's asm)
  4. @Note: MUST be on WRAM that is not protected, like VECTORS
  5. @also known as : le hook
  6.  
  7. .global irqbiosinst
  8. .type   irqbiosinst STT_FUNC
  9. irqbiosinst:
  10.    
  11.     mov r0,#0
  12.     MRC P15, 0 ,r0, c9,c1,0             @TCM Data TCM Base and Virtual Size
  13.     MOV r0, r0, LSR #0xc
  14.     MOV r0, r0, LSL #0xc
  15.     LDR R1,=0x3ffc                      @IRQ handler
  16.     add r0,r0,r1
  17.     adr r2,inter_irq
  18.    
  19.     //test: ldr r1,=0xc070c070  @test should make dtcm+0x3ffc jump to garbage
  20.    
  21.     str r2,[r0]
  22.     bx lr
  23.  
  24. .global irqexcepstack
  25. irqexcepstack:
  26.     .word   0x00000000  @r0     a1
  27.     .word   0x00000000  @r1     a2
  28.     .word   0x00000000  @r2     a3
  29.     .word   0x00000000  @r3     a4
  30.     .word   0x00000000  @r4     s1
  31.     .word   0x00000000  @r5     s2
  32.     .word   0x00000000  @r6     s3
  33.     .word   0x00000000  @r7     s4
  34.     .word   0x00000000  @r8     s5
  35.     .word   0x00000000  @r9     s6
  36.     .word   0x00000000  @r10    sl
  37.     .word   0x00000000  @r11    ip
  38.     .word   0x00000000  @r12    fp
  39.     .word   0x00000000  @r13    sp
  40.     .word   0x00000000  @r14    lr
  41.     .word   0x00000000  @r15    pc
  42.    
  43. .global inter_irq
  44. inter_irq:             
  45.  
  46. @new NDS9 BIOS handler
  47. ldr     r0,=irqexcepstack
  48. stmia   r0,{r1-r13,r14}
  49.  
  50. @disable IME
  51. ldr r12,=0x04000208
  52. //mov r11,#0
  53. str r12,[r12]
  54.  
  55. @ie / if
  56. ldr r10,=0x04000210
  57. ldr r9,[r10]
  58. ldr r8,=0x04000214
  59. ldr r7,[r8]
  60.  
  61. and r7,r7,r9 @mask only if set on ie (switch)
  62.  
  63. //* IRQ handler */
  64. stmdb sp!,{r0-r12,r14}
  65.  
  66.     MOV r0,r7,ror #0    // case 0
  67.         ldrcs r0,=vblank_thread
  68.         movcs lr,pc
  69.         bxcs r0
  70.    
  71.     MOV r0,r7,ror #1    // case 1
  72.         ldrcs r0,=hblank_thread
  73.         movcs lr,pc
  74.         bxcs r0
  75.    
  76.     MOV r0,r7,ror #2    // case 2
  77.         ldrcs r0,=vcount_thread
  78.         movcs lr,pc
  79.         bxcs r0
  80.    
  81.     MOV r0,r7,ror #18   // case 18
  82.         ldrcs r0,=fifo_thread
  83.         movcs lr,pc
  84.         bxcs r0
  85.    
  86. ldmia sp!,{r0-r12,r14}
  87.  
  88. /* IRQ Handler end ,dont modify anything else */
  89.  
  90. @bios flag mix
  91. MRC P15, 0 ,r0, c9,c1,0             @TCM Data TCM Base and Virtual Size
  92. MOV r0, r0, LSR #0xC
  93. MOV r0, r0, LSL #0xC
  94.  
  95. ldr r1,=0x3ff8                      @dtcm+0x3ff8 = BIOS Interrupt Flags - Check bits (ARM9)
  96. ldr r6,[r0,r1]
  97.  
  98. orr r7,r7,r6                        @if = r7 / bios f = r6
  99.  
  100. str r7,[r8]                         @serve IF
  101. str r7,[r0,r1]
  102.  
  103. @enable IME
  104. mov r11,#1
  105. str r11,[r12]
  106.  
  107. ldr     r0,=irqexcepstack
  108. ldmia   r0,{r1-r13,r14}
  109.  
  110. bx r14 @back to NDS9bios (it will return from IRQ PSR mode there)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement