NewIRQs 23.4 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

John Ballance's avatar
John Ballance committed
216
1
217
 [ NumberOfPodules > 0
Kevin Bracey's avatar
Kevin Bracey committed
218 219
; Now Podule bits
        MOV     a1, #IRQDesp_Link_Unshared
Jeffrey Lee's avatar
Jeffrey Lee committed
220
        LDR     a2, =ZeroPage+PFIQasIRQ_Chain - (PodDesp_Link-PodDesp_R12Val)
Kevin Bracey's avatar
Kevin Bracey committed
221
        ADR     a3, PFIQasIRQ_Despatch
222
        ADD     lr, v1, #PFIQasIRQ_DevNo*12
Kevin Bracey's avatar
Kevin Bracey committed
223
        STMIA   lr, {a1, a2, a3}
Jeffrey Lee's avatar
Jeffrey Lee committed
224
        LDR     a2, =ZeroPage+PIRQ_Chain - (PodDesp_Link-PodDesp_R12Val)
Kevin Bracey's avatar
Kevin Bracey committed
225
        ADR     a3, PIRQ_Despatch
226
        ADD     lr, v1, #Podule_DevNo*12
Kevin Bracey's avatar
Kevin Bracey committed
227 228 229 230
        STMIA   lr, {a1, a2, a3}
 ]

; Now IIC - if any
Jeffrey Lee's avatar
Jeffrey Lee committed
231
        LDR     v2, =ZeroPage+IICBus_Base
232 233 234
        MOV     v3, #0
80
        LDR     a1, [v2, #IICBus_Type]
Kevin Bracey's avatar
Kevin Bracey committed
235 236 237
        TST     a1, #IICFlag_HighLevel
        TSTNE   a1, #IICFlag_Background
        BEQ     %FT90
Robert Sprowson's avatar
Robert Sprowson committed
238
        MOV     a1, v3
Kevin Bracey's avatar
Kevin Bracey committed
239 240 241
        CallHAL HAL_IICDevice
; I think it's safe to call A SWI here...
        LDR     r1, =IICIRQ
242
        MOV     r2, v3
Kevin Bracey's avatar
Kevin Bracey committed
243 244
        SWI     XOS_ClaimDeviceVector
90
245 246 247 248
        ADD     v2, v2, #IICBus_Size
        ADD     v3, v3, #1
        CMP     v3, #IICBus_Count
        BNE     %BT80
249

250
        Pull    "v1-v3,sb,pc"
251 252


Neil Turton's avatar
Neil Turton committed
253 254 255 256 257 258 259
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; 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
260
PodDesp_CallAddr  #  4     ; address to call if (?Address EOR (Mask>>8)) AND Mask <> 0
Neil Turton's avatar
Neil Turton committed
261 262 263 264 265 266 267 268 269 270 271 272 273 274
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
275
        EOR     r1, r1, r2, LSR #8
Neil Turton's avatar
Neil Turton committed
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
        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
294 295
; r3 = interrupt location      } when podules are
; r4 = interrupt mask/polarity } supported and r0 = podule device number
Kevin Bracey's avatar
Kevin Bracey committed
296 297 298

CDV_Flags * &FF000000
CDV_Shared * 1:SHL:31
Neil Turton's avatar
Neil Turton committed
299 300 301 302 303 304 305 306 307

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
308 309 310
 [ HAL
        BIC     r0, r0, #CDV_Flags
 ]
311 312 313
        LDR     lr, =ZeroPage
        LDR     lr, [lr, #IRQMax]
        CMP     r0, lr
Kevin Bracey's avatar
Kevin Bracey committed
314
        BHS     DV_Fail_NaffDevNo
Neil Turton's avatar
Neil Turton committed
315

316 317
 [ NumberOfPodules > 0
        ! 0,    "ClaimDeviceVector has podule IRQ/FIQs assembled in"
Neil Turton's avatar
Neil Turton committed
318 319 320
        CMP     r0, #Podule_DevNo
        CMPNE   r0, #PFIQasIRQ_DevNo
        BEQ     PoduleChainClaim
Kevin Bracey's avatar
Kevin Bracey committed
321
 ]
Neil Turton's avatar
Neil Turton committed
322 323 324
        MOV     r3, #12
        BL      ClaimSysHeapNode
        BVS     DV_Exit
Kevin Bracey's avatar
Kevin Bracey committed
325 326
        LDR     r11, [sp]
        BIC     r0, r11, #CDV_Flags
Neil Turton's avatar
Neil Turton committed
327 328 329
        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
330
        WritePSRc SVC_mode+I_bit, r10   ; IRQs off for update (on again on SWI exit)
Neil Turton's avatar
Neil Turton committed
331 332
        LDMIA   r1, {r0, r3, r10}
        STMIA   r2, {r0, r3, r10}       ; copy current head into node
Kevin Bracey's avatar
Kevin Bracey committed
333 334 335 336 337 338 339
 [ 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
340 341 342
        LDR     r10, [sp, #4*2]         ; r12 value
        LDR     r11, [sp, #4*1]         ; call address
        MOV     r12, r2
Kevin Bracey's avatar
Kevin Bracey committed
343
 ]
Neil Turton's avatar
Neil Turton committed
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
        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

363
 [ NumberOfPodules > 0
Neil Turton's avatar
Neil Turton committed
364 365 366 367 368 369 370 371 372 373 374
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
375 376
        LDREQ   r0, =ZeroPage+PIRQ_Chain
        LDRNE   r0, =ZeroPage+PFIQasIRQ_Chain
Kevin Bracey's avatar
Kevin Bracey committed
377
        WritePSRc SVC_mode+I_bit, r1    ; IRQs off for update
Neil Turton's avatar
Neil Turton committed
378 379 380 381
        LDR     r1, [r0]
        STR     r1, [r10, #PodDesp_Link]
        STR     r10, [r0]
        B       DV_Exit
Kevin Bracey's avatar
Kevin Bracey committed
382
 ]
Neil Turton's avatar
Neil Turton committed
383 384 385 386 387 388 389 390 391 392 393 394 395

; .............................................................................
; 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
396 397 398
 [ HAL
        BIC     r0, r0, #CDV_Flags
 ]
399 400 401
        LDR     lr, =ZeroPage
        LDR     lr, [lr, #IRQMax]
        CMP     r0, lr
Kevin Bracey's avatar
Kevin Bracey committed
402
        BHS     DV_Fail_NaffDevNo
Neil Turton's avatar
Neil Turton committed
403

Kevin Bracey's avatar
Kevin Bracey committed
404
        WritePSRc SVC_mode + I_bit, r12 ; IRQs off while holding context
405 406
 [ NumberOfPodules > 0
        ! 0,    "ReleaseDeviceVector has podule IRQ/FIQs assembled in"
Neil Turton's avatar
Neil Turton committed
407 408 409
        CMP     r0, #Podule_DevNo
        CMPNE   r0, #PFIQasIRQ_DevNo
        BEQ     PoduleChainRelease
Kevin Bracey's avatar
Kevin Bracey committed
410
 ]
Neil Turton's avatar
Neil Turton committed
411 412 413 414 415 416

        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
417 418 419
 [ HAL
01      LDMIB   r12, {r3, r10}
 |
Neil Turton's avatar
Neil Turton committed
420
01      LDMIA   r12, {r3, r10}
Kevin Bracey's avatar
Kevin Bracey committed
421
 ]
Neil Turton's avatar
Neil Turton committed
422 423 424 425
        CMP     r3, r2
        CMPEQ   r10, r1
        BEQ     %FT02                   ; found it
        MOV     r11, r12
Kevin Bracey's avatar
Kevin Bracey committed
426 427 428 429
        LDR     r12, [r12, #IRQDesp_Link]
 [ HAL
        BICS    r12, r12, #IRQDesp_Link_Unshared
 |
Neil Turton's avatar
Neil Turton committed
430
        CMP     r12, #0
Kevin Bracey's avatar
Kevin Bracey committed
431
 ]
Neil Turton's avatar
Neil Turton committed
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
        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
448 449 450 451 452 453 454 455
        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
456 457
        B       %FT04

Kevin Bracey's avatar
Kevin Bracey committed
458
03      LDR     r2, [r12, #IRQDesp_Link]; freeable = nextnode
459 460 461
 [ HAL
        BIC     r2, r2, #IRQDesp_Link_Unshared
 ]
Neil Turton's avatar
Neil Turton committed
462 463 464 465 466 467 468
        LDMIA   r2,  {r0, r1, r3}       ; copy next node into head posn
        STMIA   r12, {r0, r1, r3}

04
        BL      FreeSysHeapNode         ; free block
        B       DV_Exit

469
 [ NumberOfPodules > 0
Neil Turton's avatar
Neil Turton committed
470 471
PoduleChainRelease
        CMP     r0, #Podule_DevNo
Jeffrey Lee's avatar
Jeffrey Lee committed
472 473
        LDREQ   r0, =ZeroPage+PIRQ_Chain-PodDesp_Link
        LDRNE   r0, =ZeroPage+PFIQasIRQ_Chain-PodDesp_Link
Neil Turton's avatar
Neil Turton committed
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492

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
493
 ]
Neil Turton's avatar
Neil Turton committed
494 495 496 497 498 499 500 501 502 503

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; 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
504
 [ HAL
Jeffrey Lee's avatar
Jeffrey Lee committed
505 506
        Pull    "r10, lr"
        Pull    "pc"                    ; new-style CDV - pull return address
Kevin Bracey's avatar
Kevin Bracey committed
507
 |
Neil Turton's avatar
Neil Turton committed
508
        Pull    "r10, pc"               ; return: someone will always claim it.
Kevin Bracey's avatar
Kevin Bracey committed
509
 ]
Neil Turton's avatar
Neil Turton committed
510 511 512

; *****************************************************************************
; Default IRQ2V:
Kevin Bracey's avatar
Kevin Bracey committed
513 514 515 516
 [ HAL
;   r0  must still have devno in it
;   r12 is 0 (from vector)
 |
Neil Turton's avatar
Neil Turton committed
517 518
;   r0  must still have devno*3 in it
;   r12 is 0 (from vector)
Kevin Bracey's avatar
Kevin Bracey committed
519
 ]
Neil Turton's avatar
Neil Turton committed
520 521 522 523 524 525 526

; 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
527
 [ HAL
Kevin Bracey's avatar
Kevin Bracey committed
528 529
        TEQ     r0, #0
        Pull    pc, MI
Kevin Bracey's avatar
Kevin Bracey committed
530 531 532 533 534
        MOV     r11, r9
        AddressHAL
        CallHAL HAL_IRQDisable
        MOV     r9, r11
 |
Neil Turton's avatar
Neil Turton committed
535 536 537 538
01      SUBS    r0, r0, #3
        ADDGE   r12, r12, #1
        BGT     %BT01                   ; r12 := r0 DIV 3

Kevin Bracey's avatar
Kevin Bracey committed
539 540 541
        CMP     R12, #8
        MOVLO   R0, #IOCIRQMSKA
        BLO     %FT03
Neil Turton's avatar
Neil Turton committed
542

Kevin Bracey's avatar
Kevin Bracey committed
543 544 545 546
        CMP     R12, #16
        SUBLO   R12, R12, #8
        MOVLO   R0, #IOCIRQMSKB
        BLO     %FT03
Neil Turton's avatar
Neil Turton committed
547

Kevin Bracey's avatar
Kevin Bracey committed
548 549 550 551
        CMP     R12, #IOMD_MouseRxFull_DevNo
        SUBLO   R12, R12, #IOMD_DMAChannel0_DevNo
        MOVLO   R0, #IOMD_DMAMSK
        BLO     %FT03
Neil Turton's avatar
Neil Turton committed
552

Kevin Bracey's avatar
Kevin Bracey committed
553 554 555 556
 [ 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
557

Kevin Bracey's avatar
Kevin Bracey committed
558 559
        SUBHS   R12, R12, #IOMD_C_Bit0_DevNo
        MOVHS   R0, #IOMD_IRQMSKC
Neil Turton's avatar
Neil Turton committed
560 561 562 563 564 565 566
 ]

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

567
        MRS     lr, CPSR
Kevin Bracey's avatar
Kevin Bracey committed
568 569
        BIC     r12, lr, #&0F
        ORR     r12, r12, #I32_bit+F32_bit+IRQ_mode
570
        MSR     CPSR_c, r12
Neil Turton's avatar
Neil Turton committed
571 572 573
        LDRB    r12, [r0]       ; FIQs off for updating IOCIRQMSKA
        BIC     r12, r12, r1
        STRB    r12, [r0]       ; relevant IRQ disabled
574
        MSR     CPSR_c, lr      ; absolute minimum FIQ disable period
Neil Turton's avatar
Neil Turton committed
575 576

        STRB    r1, [r0, #IOCIRQCLRA-IOCIRQMSKA] ; Clear IRQ
Kevin Bracey's avatar
Kevin Bracey committed
577
 ]
Kevin Bracey's avatar
Kevin Bracey committed
578
        Pull    pc              ; claim vector
Neil Turton's avatar
Neil Turton committed
579 580 581 582 583 584 585 586 587 588

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; 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
589
        WritePSRc SVC_mode+I_bit, lr    ; Disable IRQs. MUST call these ones
Neil Turton's avatar
Neil Turton committed
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
        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
609
      [ ZeroPage = 0
Neil Turton's avatar
Neil Turton committed
610
        LDRLSB  r14, [r0, #OsbyteVars + :INDEX: EventSemaphores]
Jeffrey Lee's avatar
Jeffrey Lee committed
611 612 613 614
      |
        LDRLS   r14, =ZeroPage+OsbyteVars+:INDEX:EventSemaphores
        LDRLSB  r14, [r0, r14]
      ]
Neil Turton's avatar
Neil Turton committed
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
                                        ; 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
636
        Pull    pc,NE
Neil Turton's avatar
Neil Turton committed
637

Jeffrey Lee's avatar
Jeffrey Lee committed
638
      [ ZeroPage = 0
Neil Turton's avatar
Neil Turton committed
639 640 641
        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
642 643 644 645 646 647 648
      |
        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
649
        Pull    pc                      ; claim EventV
Neil Turton's avatar
Neil Turton committed
650 651 652 653 654

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

Neil Turton's avatar
Neil Turton committed
655 656
        ALIGN 32

Neil Turton's avatar
Neil Turton committed
657 658
TickOne ROUT

659
 [ HAL
Kevin Bracey's avatar
Kevin Bracey committed
660
        ; Don't push r14 - we're using new interface, and claim the vector
661
        Push    "r0,r9,r12"
662
        AddressHAL
663 664 665 666

        ; 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
667
        CallHAL HAL_TimerIRQClear
668 669

        Pull    "r0" ; get device number back
670
        CallHAL HAL_IRQClear
Kevin Bracey's avatar
Kevin Bracey committed
671
        Pull    "r9,r12"
672
 |
Kevin Bracey's avatar
Kevin Bracey committed
673 674
        Push    r14

Neil Turton's avatar
Neil Turton committed
675 676
        MOV     R0, #timer0_bit
        STRB    R0, [R3, #IOCIRQCLRA]   ; clear timer 0 interrupt
677
 ]
Neil Turton's avatar
Neil Turton committed
678

Jeffrey Lee's avatar
Jeffrey Lee committed
679
        LDR     R1, =ZeroPage
680 681 682 683
        LDR     R0, [R1, #MetroGnome]
        ADD     R0, R0, #1
        STR     R0, [R1, #MetroGnome]

Neil Turton's avatar
Neil Turton committed
684 685 686 687 688 689 690 691 692 693 694 695 696 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
        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

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

        BL      ProcessTickEventChain   ; Re-enables IRQs

        Pull    "R10,PC"

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

Neil Turton's avatar
Neil Turton committed
747
        ALIGN 32
John Ballance's avatar
John Ballance committed
748
FalseVsyncIRQ ROUT
Jeffrey Lee's avatar
Jeffrey Lee committed
749
        LDR     R1, =ZeroPage
John Ballance's avatar
John Ballance committed
750 751 752 753
        LDR     R0, [R1, #MetroGnome]
        TST     R0, #1
        MOVEQ   pc, lr
        Push    "lr"
Jeffrey Lee's avatar
Jeffrey Lee committed
754
        ; Fall through...
Neil Turton's avatar
Neil Turton committed
755

Jeffrey Lee's avatar
Jeffrey Lee committed
756
VsyncIRQ_ExtEntry ROUT
Neil Turton's avatar
Neil Turton committed
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796
        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