NewIRQs 24.1 KB
Newer Older
Neil Turton's avatar
Neil Turton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
; Copyright 1996 Acorn Computers Ltd
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
;     http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
        TTL     => NewIRQs

; *****************************************************************************
;
; Main IRQ routine:
;     Push  workregs,lr
;     IRQsema -> TOS
;     stack -> IRQsema
;     call IRQ1V
;     IRQs off
;     TOS ->IRQsema
;     process callback, pulling workregs,pc at some point
;
; *****************************************************************************

Neil Turton's avatar
Neil Turton committed
30
        ALIGN 32
31 32 33 34

Initial_IRQ_Code ROUT
        SUB     lr, lr, #4
        Push    "r0, lr"
35
        MRS     lr, SPSR
36 37 38 39
        Push    "r1-r3, r11, r12, lr"
; ** For Pete's sake remember to change the heap manager if you change the above
; ** register list!!!!!!! And the [sp_irq, #4*5] below

Kevin Bracey's avatar
Kevin Bracey committed
40
  [ :LNOT:No26bitCode
41
        BIC     r0, lr, #&1F            ; clear out foreground mode bits
Kevin Bracey's avatar
Kevin Bracey committed
42
        ORR     r0, r0, #I32_bit + IRQ26_mode ; force IRQ_26 mode and I bit set
43
        MSR     CPSR_c, r0
Kevin Bracey's avatar
Kevin Bracey committed
44
  ]
45

Jeffrey Lee's avatar
Jeffrey Lee committed
46
        LDR     r12, =ZeroPage
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
        LDR     r0, [r12, #IRQsema]
        Push    r0
        STR     sp_irq, [r12, #IRQsema]
        MOV     lr, pc
        LDR     pc, [r12, #IRQ1V]

; IRQ1V called with r0-r3,r11,r12 trashable. r12=0

; Stu has a theory that 1N cycle can be saved by the default IRQ1V pointing
; at a location containing a branch to our code; we then do something like
;  LDR R0, [R12, #IRQ1V]
;  CMP R0, #OurIRQ1V
;  BNE somebodysonIRQ1V
;  .... fall into default IRQ1V code

62 63 64 65
        Push     "r10"
        MOV      r10, #UnthreadV
        BL       CallVector
        Pull     "r10"
66

Jeffrey Lee's avatar
Jeffrey Lee committed
67
        LDR      r11, =ZeroPage
68 69
        Pull     r0
        STR      r0, [r11, #IRQsema]
70

Kevin Bracey's avatar
Kevin Bracey committed
71
  [ :LNOT:No26bitCode
72
        MRS      r0, CPSR
73
        ORR      r0, r0, #&10
74
        MSR      CPSR_c, r0                     ; switch back to IRQ32 mode
Kevin Bracey's avatar
Kevin Bracey committed
75
  ]
76 77 78 79

        LDRB     r11, [r11, #CallBack_Flag]
        TEQ      r11, #0
        Pull     "r1-r3, r11, r12, lr", EQ
80
        MSREQ    SPSR_cxsf, lr
81 82 83 84 85 86
        Pull     "r0, pc", EQ, ^

        TST      r11, #CBack_Postpone
        LDREQ    lr, [sp_irq, #4*5]     ; get SPSR off stack
        TSTEQ    lr, #I32_bit :OR: &0F  ; check we came from USR26 or USR32 mode, with IRQs enabled
        Pull     "r1-r3, r11, r12, lr", NE
87
        MSRNE    SPSR_cxsf, lr
88 89
        Pull     "r0, pc", NE, ^

Kevin Bracey's avatar
Kevin Bracey committed
90
; Do a CallBack: asked for, not postponed, and we're returning into USR26/32 mode.
91 92 93 94

        ASSERT   IRQ32_mode :AND: SVC32_mode = IRQ32_mode ; so the following dodgy ops work

        Pull     "r1-r3, r11, r12"
95
        MRS      r0, CPSR
96
        ORR      r0, r0, #SVC32_mode
97
        MSR      CPSR_c, r0
98 99
        Push     "r10-r12"                               ; push r10-r12 onto the SVC stack
        BIC      r0, r0, #IRQ32_mode :EOR: SVC32_mode
100
        MSR      CPSR_c, r0
101
        Pull     "r10-r12"                      ; SPSR, R0, LR really
Ben Avison's avatar
Ben Avison committed
102
 [ No26bitCode :LOR: FixCallBacks
103
        ORR      r0, r0, #SVC32_mode
Kevin Bracey's avatar
Kevin Bracey committed
104
 |
105 106
        BIC      r0, r0, #&1F
        ORR      r0, r0, #SVC26_mode
Neil Turton's avatar
Neil Turton committed
107
 ]
108
        MSR      CPSR_c, r0
Kevin Bracey's avatar
Kevin Bracey committed
109 110 111
        Push     r12                            ; Save the return address
        MOV      r14, r10                       ; SPSR into R14
        MOV      r0, r11                        ; restore original R0
Jeffrey Lee's avatar
Jeffrey Lee committed
112
        LDR      r10, =ZeroPage
Neil Turton's avatar
Neil Turton committed
113
        LDRB     r11, [r10, #CallBack_Flag]
Ben Avison's avatar
Ben Avison committed
114 115 116
      [ FixCallBacks
        B        Do_CallBack_postpone_already_clear
      |
Neil Turton's avatar
Neil Turton committed
117
        B        Do_CallBack
Ben Avison's avatar
Ben Avison committed
118
      ]
Neil Turton's avatar
Neil Turton committed
119 120 121 122 123 124 125 126

        LTORG

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Default IRQ1V: despatch on interrupting device

; Now copied to RAM, together with vector entries and device tables

127 128
        ASSERT    HAL ; Pre-HAL code is gone. Sorry!

Kevin Bracey's avatar
Kevin Bracey committed
129 130 131 132 133 134 135
                  ^ 0
IRQDesp_Link      # 4
IRQDesp_R12Val    # 4
IRQDesp_CallAddr  # 4

IRQDesp_Link_Unshared * 1       ; flag in Link (for _this_ node)

136
       ASSERT   IRQDesp_CallAddr = IRQDesp_R12Val + 4
Neil Turton's avatar
Neil Turton committed
137

Neil Turton's avatar
Neil Turton committed
138 139
DefaultIRQ1Vcode ROUT

Kevin Bracey's avatar
Kevin Bracey committed
140
        Push    "r9,lr"
Jeffrey Lee's avatar
Jeffrey Lee committed
141 142 143 144 145 146
      [ ZeroPage = 0
        MOV     r9, #0
      |
        LDR     r9, %FT02
      ]
        AddressHAL r9                   ; modifies r9
147
        CallHAL HAL_IRQSource
148
        Pull    "r9"
Kevin Bracey's avatar
Kevin Bracey committed
149
        ADR     r2, Devices
150
        ADD     r1, r0, r0, LSL #1      ; multiply by 3
Kevin Bracey's avatar
Kevin Bracey committed
151 152 153 154 155 156
        ADD     r11, r2, r1, LSL #2     ; so table contains DevNo * 3
01      MOV     lr, pc
        LDMIA   r11, {r11, r12, pc}
        TST     r11, #IRQDesp_Link_Unshared
        BEQ     %BT01
        Pull    pc
Jeffrey Lee's avatar
Jeffrey Lee committed
157 158 159 160
      [ ZeroPage <> 0
02
        DCD     ZeroPage
      ]
Neil Turton's avatar
Neil Turton committed
161 162

; ******* IRQ device handlers entered with r0-r3,r11,r12,r14 trashable *******
163
;   r0  =  device number (if HAL)
164
;   r3  -> IOC (not in HAL world, unless IOMD HAL is helpful)
Neil Turton's avatar
Neil Turton committed
165 166 167
;   r12 =  what they asked for
;   r14 =  return address to MOS IRQ exit sequence

168 169
DefaultIRQ1Vcode_end

Kevin Bracey's avatar
Kevin Bracey committed
170
Devices * DefaultIRQ1Vcode_end + 12
171

Kevin Bracey's avatar
Kevin Bracey committed
172
NoInterrupt     * -1
173

174
DevicesEnd * Devices + MaxInterrupts * 12
175

176
        ASSERT  DevicesEnd - DefaultIRQ1Vcode <= DefIRQ1Vspace
177 178 179 180 181

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

InitialiseIRQ1Vtable

182
        Push    "v1-v3,sb,lr"
183 184 185 186 187 188 189 190 191 192 193 194 195
; copy IRQ handler: not done with rest of copying
; because soft break needs the info to free any claimed blocks.

        LDR     a1, =DefaultIRQ1V
        ADRL    a2, DefaultIRQ1Vcode
        ADRL    a3, DefaultIRQ1Vcode_end
CopyDefaultIRQ1V
        LDR     a4, [a2], #4
        STR     a4, [a1], #4
        CMP     a2, a3
        BNE     CopyDefaultIRQ1V

        AddressHAL
Kevin Bracey's avatar
Kevin Bracey committed
196 197
        ADD     v1, a1, #12
        ADD     a3, v1, #MaxInterrupts*12
198
        MOV     a2, #0
Kevin Bracey's avatar
Kevin Bracey committed
199 200
        MOV     a4, #-1
        LDR     ip, =IRQ
201 202
FillInDefaultIRQ1VDevices
        STMIA   a1!, {a2, a4, ip}
Kevin Bracey's avatar
Kevin Bracey committed
203
        ADD     a4, a4, #1
204 205 206 207 208 209
        CMP     a1, a3
        BNE     FillInDefaultIRQ1VDevices

; Now fill in our basic device handlers. First the timer.
        MOV     a1, #0
        CallHAL HAL_TimerDevice
Jeffrey Lee's avatar
Jeffrey Lee committed
210
        LDR     a2, =ZeroPage+OsbyteVars
211 212 213
        LDR     a3, =TickOne
        ADD     a1, a1, a1, LSL #1
        ADD     a1, v1, a1, LSL #2
Kevin Bracey's avatar
Kevin Bracey committed
214
        STMIB   a1, {a2, a3}
215 216 217 218

; Now the VSync
        MOV     a1, #0
        CallHAL HAL_VideoFlybackDevice
Kevin Bracey's avatar
Kevin Bracey committed
219
        CMP     a1, #-1
Jeffrey Lee's avatar
Jeffrey Lee committed
220
        LDRNE   a2, =ZeroPage+OsbyteVars
Kevin Bracey's avatar
Kevin Bracey committed
221 222 223 224
        LDRNE   a3, =VsyncIRQ
        ADDNE   a1, a1, a1, LSL #1
        ADDNE   a1, v1, a1, LSL #2
        STMNEIB a1, {a2, a3}
John Ballance's avatar
John Ballance committed
225 226

1
227
 [ NumberOfPodules > 0
Kevin Bracey's avatar
Kevin Bracey committed
228 229
; Now Podule bits
        MOV     a1, #IRQDesp_Link_Unshared
Jeffrey Lee's avatar
Jeffrey Lee committed
230
        LDR     a2, =ZeroPage+PFIQasIRQ_Chain - (PodDesp_Link-PodDesp_R12Val)
Kevin Bracey's avatar
Kevin Bracey committed
231 232 233
        ADR     a3, PFIQasIRQ_Despatch
        ADD     lr, v1, #8*12
        STMIA   lr, {a1, a2, a3}
Jeffrey Lee's avatar
Jeffrey Lee committed
234
        LDR     a2, =ZeroPage+PIRQ_Chain - (PodDesp_Link-PodDesp_R12Val)
Kevin Bracey's avatar
Kevin Bracey committed
235 236 237 238 239 240
        ADR     a3, PIRQ_Despatch
        ADD     lr, v1, #13*12
        STMIA   lr, {a1, a2, a3}
 ]

; Now IIC - if any
Jeffrey Lee's avatar
Jeffrey Lee committed
241
        LDR     v2, =ZeroPage+IICBus_Base
242 243 244
        MOV     v3, #0
80
        LDR     a1, [v2, #IICBus_Type]
Kevin Bracey's avatar
Kevin Bracey committed
245 246 247 248 249
        TST     a1, #IICFlag_HighLevel
        TSTNE   a1, #IICFlag_Background
        BEQ     %FT90
        SUB     sp, sp, #12
        MOV     a1, sp
250
        MOV     a2, v3
Kevin Bracey's avatar
Kevin Bracey committed
251 252 253 254
        CallHAL HAL_IICDevice
; I think it's safe to call A SWI here...
        LDMIA   sp!, {r0, r3, r4}
        LDR     r1, =IICIRQ
255
        MOV     r2, v3
Kevin Bracey's avatar
Kevin Bracey committed
256 257
        SWI     XOS_ClaimDeviceVector
90
258 259 260 261
        ADD     v2, v2, #IICBus_Size
        ADD     v3, v3, #1
        CMP     v3, #IICBus_Count
        BNE     %BT80
262

263
        Pull    "v1-v3,sb,pc"
264 265


Neil Turton's avatar
Neil Turton committed
266 267 268 269 270 271 272
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Specialist despatchers for podules

                  ^  0
PodDesp_Address   #  4     ; address of IRQ status byte
PodDesp_Mask      #  4     ; for use on above
PodDesp_R12Val    #  4
Kevin Bracey's avatar
Kevin Bracey committed
273
PodDesp_CallAddr  #  4     ; address to call if (?Address EOR (Mask>>8)) AND Mask <> 0
Neil Turton's avatar
Neil Turton committed
274 275 276 277 278 279 280 281 282 283 284 285 286 287
PodDesp_Link      #  4     ; next node
PodDesp_NodeSize  #  0

; In    r12 =    PFIQasIRQ_Chain - (PodDesp_Link-PodDesp_R12Val)
;             or PIRQ_Chain - (PodDesp_Link-PodDesp_R12Val)     from despatcher

PFIQasIRQ_Despatch ROUT
PIRQ_Despatch ; All the same thing now

01      LDR     r12, [r12, #PodDesp_Link-PodDesp_R12Val]
        LDMIA   r12!, {r1, r2}           ; address and mask

; TMD 09-Jun-89: Don't corrupt r0 - it's needed by the default IRQ2 routine
        LDRB    r1, [r1]
Robert Sprowson's avatar
Robert Sprowson committed
288
        EOR     r1, r1, r2, LSR #8
Neil Turton's avatar
Neil Turton committed
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
        ANDS    r1, r1, r2
        BEQ     %BT01
        LDMIA   r12, {r12, pc}

Default_PIRQHandler_Node
Default_PFIQasIRQHandler_Node
        &       .+4                     ; address we know has non-zero value!
        &       -1                      ; mask
        &       0                       ; handler r12
        &       IRQ                     ; handler code
        &       0                       ; null link for naff release checking

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Claim of device vectors

; r0 = Device number
; r1 = call address
; r2 = r12 value
307 308
; r3 = interrupt location      } when podules are
; r4 = interrupt mask/polarity } supported and r0 = podule device number
Kevin Bracey's avatar
Kevin Bracey committed
309 310 311

CDV_Flags * &FF000000
CDV_Shared * 1:SHL:31
Neil Turton's avatar
Neil Turton committed
312 313 314 315 316 317 318 319 320

DeviceVector_Claim ROUT

        Push    "r0-r3, lr"

01      SWI     XOS_ReleaseDeviceVector ; Release until bored
        BVC     %BT01

        LDR     r0, [sp]
Kevin Bracey's avatar
Kevin Bracey committed
321 322 323
 [ HAL
        BIC     r0, r0, #CDV_Flags
 ]
324 325 326
        LDR     lr, =ZeroPage
        LDR     lr, [lr, #IRQMax]
        CMP     r0, lr
Kevin Bracey's avatar
Kevin Bracey committed
327
        BHS     DV_Fail_NaffDevNo
Neil Turton's avatar
Neil Turton committed
328

329 330
 [ NumberOfPodules > 0
        ! 0,    "ClaimDeviceVector has podule IRQ/FIQs assembled in"
Neil Turton's avatar
Neil Turton committed
331 332 333
        CMP     r0, #Podule_DevNo
        CMPNE   r0, #PFIQasIRQ_DevNo
        BEQ     PoduleChainClaim
Kevin Bracey's avatar
Kevin Bracey committed
334
 ]
Neil Turton's avatar
Neil Turton committed
335 336 337
        MOV     r3, #12
        BL      ClaimSysHeapNode
        BVS     DV_Exit
Kevin Bracey's avatar
Kevin Bracey committed
338 339
        LDR     r11, [sp]
        BIC     r0, r11, #CDV_Flags
Neil Turton's avatar
Neil Turton committed
340 341 342
        ADD     r0, r0, r0, LSL #1      ; *3
        LDR     r1, =DefaultIRQ1V-DefaultIRQ1Vcode+Devices
        ADD     r1, r1, r0, LSL #2
Kevin Bracey's avatar
Kevin Bracey committed
343
        WritePSRc SVC_mode+I_bit, r10   ; IRQs off for update (on again on SWI exit)
Neil Turton's avatar
Neil Turton committed
344 345
        LDMIA   r1, {r0, r3, r10}
        STMIA   r2, {r0, r3, r10}       ; copy current head into node
Kevin Bracey's avatar
Kevin Bracey committed
346 347 348 349 350 351 352
 [ HAL
        MOV     r10, r2
        TST     r11, #CDV_Shared
        ORREQ   r10, r10, #IRQDesp_Link_Unshared
        LDR     r11, [sp, #4*2]         ; r12 value
        LDR     r12, [sp, #4*1]         ; call address
 |
Neil Turton's avatar
Neil Turton committed
353 354 355
        LDR     r10, [sp, #4*2]         ; r12 value
        LDR     r11, [sp, #4*1]         ; call address
        MOV     r12, r2
Kevin Bracey's avatar
Kevin Bracey committed
356
 ]
Neil Turton's avatar
Neil Turton committed
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
        STMIA   r1, {r10-r12}           ; copy given info into head


DV_Exit STRVS   r0, [sp]                ; Common exit for both claim + release
        Pull    "r0-r3, lr"
        B       SLVK_TestV


DV_Fail_NaffDevNo
        ADR     r0, ErrorBlock_NaffDevNo
      [ International
        BL      TranslateError
      |
        SETV
      ]
        B       DV_Exit

        MakeErrorBlock NaffDevNo

376
 [ NumberOfPodules > 0
Neil Turton's avatar
Neil Turton committed
377 378 379 380 381 382 383 384 385 386 387
PoduleChainClaim
        MOV     r3, #PodDesp_NodeSize
        BL      ClaimSysHeapNode
        BVS     DV_Exit
        MOV     r10, r2
        LDMFD   sp, {r0-r3}
        STR     r1, [r10, #PodDesp_CallAddr]
        STR     r2, [r10, #PodDesp_R12Val]
        STR     r3, [r10, #PodDesp_Address]
        STR     r4, [r10, #PodDesp_Mask]
        CMP     r0, #Podule_DevNo
Jeffrey Lee's avatar
Jeffrey Lee committed
388 389
        LDREQ   r0, =ZeroPage+PIRQ_Chain
        LDRNE   r0, =ZeroPage+PFIQasIRQ_Chain
Kevin Bracey's avatar
Kevin Bracey committed
390
        WritePSRc SVC_mode+I_bit, r1    ; IRQs off for update
Neil Turton's avatar
Neil Turton committed
391 392 393 394
        LDR     r1, [r0]
        STR     r1, [r10, #PodDesp_Link]
        STR     r10, [r0]
        B       DV_Exit
Kevin Bracey's avatar
Kevin Bracey committed
395
 ]
Neil Turton's avatar
Neil Turton committed
396 397 398 399 400 401 402 403 404 405 406 407 408

; .............................................................................
; Release of device vectors

; r0 = Device number
; r1 = call address
; r2 = r12 value
; r0 = PFIQ|PIRQ devno -> r3 = interrupt location (LDRB always used)
;                         r4 = interrupt mask

DeviceVector_Release ROUT

        Push    "r0-r3, lr"             ; Ensure same regset as above
Kevin Bracey's avatar
Kevin Bracey committed
409 410 411
 [ HAL
        BIC     r0, r0, #CDV_Flags
 ]
412 413 414
        LDR     lr, =ZeroPage
        LDR     lr, [lr, #IRQMax]
        CMP     r0, lr
Kevin Bracey's avatar
Kevin Bracey committed
415
        BHS     DV_Fail_NaffDevNo
Neil Turton's avatar
Neil Turton committed
416

Kevin Bracey's avatar
Kevin Bracey committed
417
        WritePSRc SVC_mode + I_bit, r12 ; IRQs off while holding context
418 419
 [ NumberOfPodules > 0
        ! 0,    "ReleaseDeviceVector has podule IRQ/FIQs assembled in"
Neil Turton's avatar
Neil Turton committed
420 421 422
        CMP     r0, #Podule_DevNo
        CMPNE   r0, #PFIQasIRQ_DevNo
        BEQ     PoduleChainRelease
Kevin Bracey's avatar
Kevin Bracey committed
423
 ]
Neil Turton's avatar
Neil Turton committed
424 425 426 427 428 429

        ADD     r0, r0, r0, LSL #1      ; *3
        LDR     r12, =DefaultIRQ1V-DefaultIRQ1Vcode+Devices
        ADD     r12, r12, r0, LSL #2    ; address of node
        MOV     r11, #-1                ; "fudge" predecessor node

Kevin Bracey's avatar
Kevin Bracey committed
430 431 432
 [ HAL
01      LDMIB   r12, {r3, r10}
 |
Neil Turton's avatar
Neil Turton committed
433
01      LDMIA   r12, {r3, r10}
Kevin Bracey's avatar
Kevin Bracey committed
434
 ]
Neil Turton's avatar
Neil Turton committed
435 436 437 438
        CMP     r3, r2
        CMPEQ   r10, r1
        BEQ     %FT02                   ; found it
        MOV     r11, r12
Kevin Bracey's avatar
Kevin Bracey committed
439 440 441 442
        LDR     r12, [r12, #IRQDesp_Link]
 [ HAL
        BICS    r12, r12, #IRQDesp_Link_Unshared
 |
Neil Turton's avatar
Neil Turton committed
443
        CMP     r12, #0
Kevin Bracey's avatar
Kevin Bracey committed
444
 ]
Neil Turton's avatar
Neil Turton committed
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
        BNE     %BT01

11      ADR     r0, ErrorBlock_BadDevVecRel
      [ International
        BL      TranslateError
      |
        SETV
      ]
        B       DV_Exit

        MakeErrorBlock BadDevVecRel


02      CMP     r11, #-1
        BEQ     %FT03
        MOV     r2, r12
Kevin Bracey's avatar
Kevin Bracey committed
461 462 463 464 465 466 467 468
        LDR     r12, [r2, #IRQDesp_Link]
 [ HAL
        LDR     r14, [r11, #IRQDesp_Link]       ; preserve r11's "unshared" flag
        BIC     r12, r12, #IRQDesp_Link_Unshared
        AND     r14, r14, #IRQDesp_Link_Unshared
        ORR     r12, r12, r14
 ]
        STR     r12, [r11, #IRQDesp_Link] ; node delinked
Neil Turton's avatar
Neil Turton committed
469 470
        B       %FT04

Kevin Bracey's avatar
Kevin Bracey committed
471
03      LDR     r2, [r12, #IRQDesp_Link]; freeable = nextnode
472 473 474
 [ HAL
        BIC     r2, r2, #IRQDesp_Link_Unshared
 ]
Neil Turton's avatar
Neil Turton committed
475 476 477 478 479 480 481
        LDMIA   r2,  {r0, r1, r3}       ; copy next node into head posn
        STMIA   r12, {r0, r1, r3}

04
        BL      FreeSysHeapNode         ; free block
        B       DV_Exit

482
 [ NumberOfPodules > 0
Neil Turton's avatar
Neil Turton committed
483 484
PoduleChainRelease
        CMP     r0, #Podule_DevNo
Jeffrey Lee's avatar
Jeffrey Lee committed
485 486
        LDREQ   r0, =ZeroPage+PIRQ_Chain-PodDesp_Link
        LDRNE   r0, =ZeroPage+PFIQasIRQ_Chain-PodDesp_Link
Neil Turton's avatar
Neil Turton committed
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505

10      LDR     r12, [r0, #PodDesp_Link]
        CMP     r12, #0
        BEQ     %BT11
        LDR     r11, [r12, #PodDesp_Address]
        CMP     r11, r3
        LDREQ   r11, [r12, #PodDesp_Mask]
        CMPEQ   r11, r4
        LDREQ   r11, [r12, #PodDesp_CallAddr]
        CMPEQ   r11, r1
        LDREQ   r11, [r12, #PodDesp_R12Val]
        CMPEQ   r11, r2
        MOVNE   r0, r12
        BNE     %BT10

        LDR     r11, [r12, #PodDesp_Link]
        STR     r11, [r0,  #PodDesp_Link]
        MOV     r2, r12
        B       %BT04
Kevin Bracey's avatar
Kevin Bracey committed
506
 ]
Neil Turton's avatar
Neil Turton committed
507 508 509 510 511 512 513 514 515 516

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Default device owner for IRQ not recognised by system: pass to IRQ2V

IRQ ROUT

        Push    "r10, lr"
        MOV     r10, #IrqV
        BL      CallVector

Kevin Bracey's avatar
Kevin Bracey committed
517
 [ HAL
Jeffrey Lee's avatar
Jeffrey Lee committed
518 519
        Pull    "r10, lr"
        Pull    "pc"                    ; new-style CDV - pull return address
Kevin Bracey's avatar
Kevin Bracey committed
520
 |
Neil Turton's avatar
Neil Turton committed
521
        Pull    "r10, pc"               ; return: someone will always claim it.
Kevin Bracey's avatar
Kevin Bracey committed
522
 ]
Neil Turton's avatar
Neil Turton committed
523 524 525

; *****************************************************************************
; Default IRQ2V:
Kevin Bracey's avatar
Kevin Bracey committed
526 527 528 529
 [ HAL
;   r0  must still have devno in it
;   r12 is 0 (from vector)
 |
Neil Turton's avatar
Neil Turton committed
530 531
;   r0  must still have devno*3 in it
;   r12 is 0 (from vector)
Kevin Bracey's avatar
Kevin Bracey committed
532
 ]
Neil Turton's avatar
Neil Turton committed
533 534 535 536 537 538 539

; Clear mask, clear IRQ as appropriate/possible

; NB. a cheap way of dividing by ~3 is *11,/32: accurate for 0..31 result ...

NOIRQ ROUT

Kevin Bracey's avatar
Kevin Bracey committed
540
 [ HAL
Kevin Bracey's avatar
Kevin Bracey committed
541 542
        TEQ     r0, #0
        Pull    pc, MI
Kevin Bracey's avatar
Kevin Bracey committed
543 544 545 546 547
        MOV     r11, r9
        AddressHAL
        CallHAL HAL_IRQDisable
        MOV     r9, r11
 |
Neil Turton's avatar
Neil Turton committed
548 549 550 551
01      SUBS    r0, r0, #3
        ADDGE   r12, r12, #1
        BGT     %BT01                   ; r12 := r0 DIV 3

Kevin Bracey's avatar
Kevin Bracey committed
552 553 554
        CMP     R12, #8
        MOVLO   R0, #IOCIRQMSKA
        BLO     %FT03
Neil Turton's avatar
Neil Turton committed
555

Kevin Bracey's avatar
Kevin Bracey committed
556 557 558 559
        CMP     R12, #16
        SUBLO   R12, R12, #8
        MOVLO   R0, #IOCIRQMSKB
        BLO     %FT03
Neil Turton's avatar
Neil Turton committed
560

Kevin Bracey's avatar
Kevin Bracey committed
561 562 563 564
        CMP     R12, #IOMD_MouseRxFull_DevNo
        SUBLO   R12, R12, #IOMD_DMAChannel0_DevNo
        MOVLO   R0, #IOMD_DMAMSK
        BLO     %FT03
Neil Turton's avatar
Neil Turton committed
565

Kevin Bracey's avatar
Kevin Bracey committed
566 567 568 569
 [ MorrisSupport
        CMP     R12, #IOMD_C_Bit0_DevNo
        SUBLO   R12, R12, #IOMD_MouseRxFull_DevNo       ;reduce to bit number 0..7
        MOVLO   R0, #IOMD_IRQMSKD                       ; in IRQ D interrupt register
Neil Turton's avatar
Neil Turton committed
570

Kevin Bracey's avatar
Kevin Bracey committed
571 572
        SUBHS   R12, R12, #IOMD_C_Bit0_DevNo
        MOVHS   R0, #IOMD_IRQMSKC
Neil Turton's avatar
Neil Turton committed
573 574 575 576 577 578 579
 ]

03
        ADD     r0, r0, #IOC
        MOV     r1, #1
        MOV     r1, r1, LSL r12         ; bit to clear

580
        MRS     lr, CPSR
Kevin Bracey's avatar
Kevin Bracey committed
581 582
        BIC     r12, lr, #&0F
        ORR     r12, r12, #I32_bit+F32_bit+IRQ_mode
583
        MSR     CPSR_c, r12
Neil Turton's avatar
Neil Turton committed
584 585 586
        LDRB    r12, [r0]       ; FIQs off for updating IOCIRQMSKA
        BIC     r12, r12, r1
        STRB    r12, [r0]       ; relevant IRQ disabled
587
        MSR     CPSR_c, lr      ; absolute minimum FIQ disable period
Neil Turton's avatar
Neil Turton committed
588 589

        STRB    r1, [r0, #IOCIRQCLRA-IOCIRQMSKA] ; Clear IRQ
Kevin Bracey's avatar
Kevin Bracey committed
590
 ]
Kevin Bracey's avatar
Kevin Bracey committed
591
        Pull    pc              ; claim vector
Neil Turton's avatar
Neil Turton committed
592 593 594 595 596 597 598 599 600 601

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; The following bits have been appropriated from source.pmf.oseven to make
; sure Tim's old code doesn't overwrite us when he gets back!

; SWI OS_GenerateEvent: call event vector if enabled

GenEvent ROUT

        Push    lr
Kevin Bracey's avatar
Kevin Bracey committed
602
        WritePSRc SVC_mode+I_bit, lr    ; Disable IRQs. MUST call these ones
Neil Turton's avatar
Neil Turton committed
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
        BL      OSEVEN                  ; in SVC mode as people expect it
        Pull    lr
        B       SLVK

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Subroutine call version

; In    r0 = event type
;       r1,r2 parameters

; Out   C=0 => event was enabled, or was >= 32 anyway
;       C=1 => event was disabled, so vector not called

OSEVEN ROUT

        Push    lr

        CMP     r0, #31                 ; Events >= 32 are ALWAYS raised. SKS
                                        ; flags are HI if so, ie. NE
Jeffrey Lee's avatar
Jeffrey Lee committed
622
      [ ZeroPage = 0
Neil Turton's avatar
Neil Turton committed
623
        LDRLSB  r14, [r0, #OsbyteVars + :INDEX: EventSemaphores]
Jeffrey Lee's avatar
Jeffrey Lee committed
624 625 626 627
      |
        LDRLS   r14, =ZeroPage+OsbyteVars+:INDEX:EventSemaphores
        LDRLSB  r14, [r0, r14]
      ]
Neil Turton's avatar
Neil Turton committed
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648
                                        ; get semaphore for this event 0..31
        CMPLS   r14, #0                 ; non-zero => enabled
        Pull    pc, EQ                  ; if disabled, exit with C=1

        Push    "r0-r3, r10-r12" ; r3 excessive ???
        MOV     r10, #EventV            ; call event vector
        BL      CallVector
        CLC                             ; indicate event enabled
        Pull    "r0-r3, r10-r12, pc"

; ...................... default owner of EventV ..............................
; Call Event handler

; In    r12 = EvtHan_ws

DefEvent ROUT

        MOV     lr, pc                  ; link with all the bits
        LDMIA   r12, {r12, pc}          ; call EventHandler, returns to ...

        TEQ     r12, #1
Kevin Bracey's avatar
Kevin Bracey committed
649
        Pull    pc,NE
Neil Turton's avatar
Neil Turton committed
650

Jeffrey Lee's avatar
Jeffrey Lee committed
651
      [ ZeroPage = 0
Neil Turton's avatar
Neil Turton committed
652 653 654
        LDRB    r14, [r12, #CallBack_Flag-1] ; IRQs are still disabled
        ORR     r14, r14, #CBack_OldStyle
        STRB    r14, [r12, #CallBack_Flag-1]
Jeffrey Lee's avatar
Jeffrey Lee committed
655 656 657 658 659 660 661
      |
        LDR     r12, =ZeroPage
        LDRB    r14, [r12, #CallBack_Flag] ; IRQs are still disabled
        ORR     r14, r14, #CBack_OldStyle
        STRB    r14, [r12, #CallBack_Flag]
      ]

Kevin Bracey's avatar
Kevin Bracey committed
662
        Pull    pc                      ; claim EventV
Neil Turton's avatar
Neil Turton committed
663 664 665 666 667

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Process timer zero IRQ device (100Hz clock)
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Neil Turton's avatar
Neil Turton committed
668 669
        ALIGN 32

Neil Turton's avatar
Neil Turton committed
670 671
TickOne ROUT

672
 [ HAL
Kevin Bracey's avatar
Kevin Bracey committed
673
        ; Don't push r14 - we're using new interface, and claim the vector
674
        Push    "r0,r9,r12"
675
        AddressHAL
676 677 678 679

        ; In some chips, Timer0 is latched in the timer block instead of,
        ; or as well as in the interrupt controller
        MOV     R0, #0 ; clear latch for Timer0
680
        CallHAL HAL_TimerIRQClear
681 682

        Pull    "r0" ; get device number back
683
        CallHAL HAL_IRQClear
Kevin Bracey's avatar
Kevin Bracey committed
684
        Pull    "r9,r12"
685
 |
Kevin Bracey's avatar
Kevin Bracey committed
686 687
        Push    r14

Neil Turton's avatar
Neil Turton committed
688 689
        MOV     R0, #timer0_bit
        STRB    R0, [R3, #IOCIRQCLRA]   ; clear timer 0 interrupt
690
 ]
Neil Turton's avatar
Neil Turton committed
691

Jeffrey Lee's avatar
Jeffrey Lee committed
692
        LDR     R1, =ZeroPage
693 694 695 696
        LDR     R0, [R1, #MetroGnome]
        ADD     R0, R0, #1
        STR     R0, [R1, #MetroGnome]

Neil Turton's avatar
Neil Turton committed
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765
        LDRB    R0, CentiCounter        ; Counter for VDU CTRL timing
        SUBS    R0, R0, #1
        STRCSB  R0, CentiCounter        ; decrement if not zero

        LDR     R0, IntervalTimer +0
        ADDS    R0, R0, #1              ; Increment the low 4 bytes
        STR     R0, IntervalTimer +0

        LDREQB  R0, IntervalTimer +4
        ADDEQ   R0, R0, #1              ; and carry into 5th byte if necessary
        STREQB  R0, IntervalTimer +4

        Push    "R4,R12"                ; R0-R3 already pushed

        TEQEQ   R0, #&100               ; has interval timer crossed zero ?
        MOVEQ   R0, #Event_IntervalTimer ; Event ITCZ
        BLEQ    OSEVEN

        BL      CentiSecondTick         ; Notify keyboard of a centisecond

        Pull    "R4,R12"

        LDR     R0, RealTime +0         ; Increment 5-byte real time
        ADDS    R0, R0, #1
        STR     R0, RealTime +0
        LDRCSB  R0, RealTime +4
        ADDCS   R0, R0, #1              ; Won't wrap until 2248 and then it
        STRCSB  R0, RealTime +4         ; all falls over anyway

        LDRB    R0, TimerState          ; get switch state
        TEQ     R0, #5                  ; toggles between 5 and 10

        LDREQ   R1, TimerAlpha +0       ; either load from one
        LDREQB  R2, TimerAlpha +4

        LDRNE   R1, TimerBeta +0        ; or the other
        LDRNEB  R2, TimerBeta +4

        ADREQ   R3, TimerBeta +0        ; and point to t'other
        ADRNE   R3, TimerAlpha +0

        ADDS    R1, R1, #1              ; increment
        ADC     R2, R2, #0              ; with carry

        STR     R1, [R3]                ; and store back
        STRB    R2, [R3, #4]

        EOR     R0, R0, #&0F            ; 5 <-> 10
        STRB    R0, TimerState

        Push    R10

 [ TickIrqReenter
        MOV     R10, #TickerV           ; call 100Hz vector
        BL      CallVector              ; IRQ's still disabled

        BL      ProcessTickEventChain   ; Re-enables IRQs
 |
        BL      ProcessTickEventChain

        MOV     R10, #TickerV           ; call 100Hz vector
        BL      CallVector
 ]
        Pull    "R10,PC"

; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Process VSync IRQ device
; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Neil Turton's avatar
Neil Turton committed
766
        ALIGN 32
John Ballance's avatar
John Ballance committed
767
FalseVsyncIRQ ROUT
Jeffrey Lee's avatar
Jeffrey Lee committed
768
        LDR     R1, =ZeroPage
John Ballance's avatar
John Ballance committed
769 770 771 772 773
        LDR     R0, [R1, #MetroGnome]
        TST     R0, #1
        MOVEQ   pc, lr
        Push    "lr"
        B       VsyncIRQ_ExtEntry
Neil Turton's avatar
Neil Turton committed
774

Neil Turton's avatar
Neil Turton committed
775 776
VsyncIRQ ROUT

Kevin Bracey's avatar
Kevin Bracey committed
777
        ; Don't push r14 - we're using new interface, and claim the vector
Kevin Bracey's avatar
Kevin Bracey committed
778
        Push    "r9,r12"
Kevin Bracey's avatar
Kevin Bracey committed
779
        AddressHAL
780
        CallHAL HAL_IRQClear            ; Clear the vsync interrupt
Kevin Bracey's avatar
Kevin Bracey committed
781
        Pull    "r9,r12"
Neil Turton's avatar
Neil Turton committed
782

Kevin Bracey's avatar
Kevin Bracey committed
783
VsyncIRQ_ExtEntry
Neil Turton's avatar
Neil Turton committed
784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823
        LDRB    R0, CFStime             ; decrement 'CFS' timer !
        SUB     R0, R0, #1
        STRB    R0, CFStime

        VDWS    WsPtr                   ; Do our stuff before issuing VSYNC event
        BL      VsyncCall
        BYTEWS  WsPtr

        MOV     R0, #Event_VSync        ; VSYNC event number
        BL      OSEVEN

        LDRB    R1, FlashCount
        SUBS    R1, R1, #1
        Pull    PC, CC                  ; was zero, so frozen
        STRNEB  R1, FlashCount          ; else if now non-zero, store it back
        Pull    PC, NE                  ; not time to flash yet

        LDRB    R1, FlashState          ; Get the state and
        EORS    R1, R1, #1              ; flip to the other one (setting flags)
        STRB    R1, FlashState

        LDREQB  R2, SpacPeriod          ; get appropriate new period
        LDRNEB  R2, MarkPeriod
        STRB    R2, FlashCount          ; and put into counter

        VDWS    WsPtr
        Push    R4
        BEQ     dothesecondflash

dothefirstflash
        BL      DoFirstFlash
        Pull    "R4, PC"

dothesecondflash
        BL      DoSecondFlash
        Pull    "R4, PC"

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

        END