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

Jeffrey Lee's avatar
Jeffrey Lee committed
40
        LDR     r12, =ZeroPage
41 42 43 44 45 46
        LDR     r0, [r12, #IRQsema]
        Push    r0
        STR     sp_irq, [r12, #IRQsema]
        MOV     lr, pc
        LDR     pc, [r12, #IRQ1V]

Jeffrey Lee's avatar
Jeffrey Lee committed
47
; IRQ1V called with r0-r3,r11,r12 trashable. r12=ZeroPage
48 49 50 51 52 53 54 55

; 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

56 57 58 59
        Push     "r10"
        MOV      r10, #UnthreadV
        BL       CallVector
        Pull     "r10"
60

Jeffrey Lee's avatar
Jeffrey Lee committed
61
        LDR      r11, =ZeroPage
62 63
        Pull     r0
        STR      r0, [r11, #IRQsema]
64

65 66
        LDRB     r11, [r11, #CallBack_Flag]
        TEQ      r11, #0
67 68 69 70 71 72
        BNE      %FT10
05
        MyCLREX  r0, r1
        Pull     "r1-r3, r11, r12, lr"
        MSR      SPSR_cxsf, lr
        Pull     "r0, pc",, ^
73

74
10
75 76 77
        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
78
        BNE      %BT05
79

Kevin Bracey's avatar
Kevin Bracey committed
80
; Do a CallBack: asked for, not postponed, and we're returning into USR26/32 mode.
81 82 83 84

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

        Pull     "r1-r3, r11, r12"
85
        MRS      r0, CPSR
86
        ORR      r0, r0, #SVC32_mode
87
        MSR      CPSR_c, r0
88 89
        Push     "r10-r12"                               ; push r10-r12 onto the SVC stack
        BIC      r0, r0, #IRQ32_mode :EOR: SVC32_mode
90
        MSR      CPSR_c, r0
91 92
        Pull     "r10-r12"                      ; SPSR, R0, LR really
        ORR      r0, r0, #SVC32_mode
93
        MSR      CPSR_c, r0
Kevin Bracey's avatar
Kevin Bracey committed
94 95 96
        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
97
        LDR      r10, =ZeroPage
Neil Turton's avatar
Neil Turton committed
98
        LDRB     r11, [r10, #CallBack_Flag]
Ben Avison's avatar
Ben Avison committed
99
        B        Do_CallBack_postpone_already_clear
Neil Turton's avatar
Neil Turton committed
100 101 102 103 104 105 106 107

        LTORG

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

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

Kevin Bracey's avatar
Kevin Bracey committed
108 109 110 111 112 113 114
                  ^ 0
IRQDesp_Link      # 4
IRQDesp_R12Val    # 4
IRQDesp_CallAddr  # 4

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

115
       ASSERT   IRQDesp_CallAddr = IRQDesp_R12Val + 4
Neil Turton's avatar
Neil Turton committed
116

Neil Turton's avatar
Neil Turton committed
117 118
DefaultIRQ1Vcode ROUT

Kevin Bracey's avatar
Kevin Bracey committed
119
        Push    "r9,lr"
Jeffrey Lee's avatar
Jeffrey Lee committed
120 121 122 123 124 125
      [ ZeroPage = 0
        MOV     r9, #0
      |
        LDR     r9, %FT02
      ]
        AddressHAL r9                   ; modifies r9
126
        CallHAL HAL_IRQSource
127
        Pull    "r9"
Kevin Bracey's avatar
Kevin Bracey committed
128
        ADR     r2, Devices
129
        ADD     r1, r0, r0, LSL #1      ; multiply by 3
Kevin Bracey's avatar
Kevin Bracey committed
130 131 132 133 134 135
        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
136 137 138 139
      [ ZeroPage <> 0
02
        DCD     ZeroPage
      ]
Neil Turton's avatar
Neil Turton committed
140

Jeffrey Lee's avatar
Jeffrey Lee committed
141 142
; IRQ handlers are called as follows:
;   r0  =  device number
Neil Turton's avatar
Neil Turton committed
143
;   r12 =  what they asked for
Jeffrey Lee's avatar
Jeffrey Lee committed
144 145
;  [r13]=  return address to claim IRQ. r0-r3, r12, r14 corruptible.
;   r14 =  return address to pass on to next handler (unhandled shared IRQ). r1-r2, r12, r14 corruptible.
Neil Turton's avatar
Neil Turton committed
146

147 148
DefaultIRQ1Vcode_end

Kevin Bracey's avatar
Kevin Bracey committed
149
Devices * DefaultIRQ1Vcode_end + 12
150

Kevin Bracey's avatar
Kevin Bracey committed
151
NoInterrupt     * -1
152

153
DevicesEnd * Devices + MaxInterrupts * 12
154

155
        ASSERT  DevicesEnd - DefaultIRQ1Vcode <= DefIRQ1Vspace
156 157 158 159 160

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

InitialiseIRQ1Vtable

161
        Push    "v1-v3,sb,lr"
162 163 164 165 166 167 168 169 170 171 172 173 174
; 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
175 176
        ADD     v1, a1, #12
        ADD     a3, v1, #MaxInterrupts*12
177
        MOV     a2, #0
Kevin Bracey's avatar
Kevin Bracey committed
178 179
        MOV     a4, #-1
        LDR     ip, =IRQ
180 181
FillInDefaultIRQ1VDevices
        STMIA   a1!, {a2, a4, ip}
Kevin Bracey's avatar
Kevin Bracey committed
182
        ADD     a4, a4, #1
183 184 185 186 187 188
        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
189
        LDR     a2, =ZeroPage+OsbyteVars
190 191 192
        LDR     a3, =TickOne
        ADD     a1, a1, a1, LSL #1
        ADD     a1, v1, a1, LSL #2
Kevin Bracey's avatar
Kevin Bracey committed
193
        STMIB   a1, {a2, a3}
194

John Ballance's avatar
John Ballance committed
195
1
196
 [ NumberOfPodules > 0
Kevin Bracey's avatar
Kevin Bracey committed
197 198
; Now Podule bits
        MOV     a1, #IRQDesp_Link_Unshared
Jeffrey Lee's avatar
Jeffrey Lee committed
199
        LDR     a2, =ZeroPage+PFIQasIRQ_Chain - (PodDesp_Link-PodDesp_R12Val)
Kevin Bracey's avatar
Kevin Bracey committed
200
        ADR     a3, PFIQasIRQ_Despatch
201
        ADD     lr, v1, #PFIQasIRQ_DevNo*12
Kevin Bracey's avatar
Kevin Bracey committed
202
        STMIA   lr, {a1, a2, a3}
Jeffrey Lee's avatar
Jeffrey Lee committed
203
        LDR     a2, =ZeroPage+PIRQ_Chain - (PodDesp_Link-PodDesp_R12Val)
Kevin Bracey's avatar
Kevin Bracey committed
204
        ADR     a3, PIRQ_Despatch
205
        ADD     lr, v1, #Podule_DevNo*12
Kevin Bracey's avatar
Kevin Bracey committed
206 207 208 209
        STMIA   lr, {a1, a2, a3}
 ]

; Now IIC - if any
Jeffrey Lee's avatar
Jeffrey Lee committed
210
        LDR     v2, =ZeroPage+IICBus_Base
211 212 213
        MOV     v3, #0
80
        LDR     a1, [v2, #IICBus_Type]
Kevin Bracey's avatar
Kevin Bracey committed
214 215 216
        TST     a1, #IICFlag_HighLevel
        TSTNE   a1, #IICFlag_Background
        BEQ     %FT90
Robert Sprowson's avatar
Robert Sprowson committed
217
        MOV     a1, v3
Kevin Bracey's avatar
Kevin Bracey committed
218 219 220
        CallHAL HAL_IICDevice
; I think it's safe to call A SWI here...
        LDR     r1, =IICIRQ
221
        MOV     r2, v3
Kevin Bracey's avatar
Kevin Bracey committed
222 223
        SWI     XOS_ClaimDeviceVector
90
224 225 226 227
        ADD     v2, v2, #IICBus_Size
        ADD     v3, v3, #1
        CMP     v3, #IICBus_Count
        BNE     %BT80
228

229
        Pull    "v1-v3,sb,pc"
230 231


Neil Turton's avatar
Neil Turton committed
232 233 234 235 236 237 238
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; 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
239
PodDesp_CallAddr  #  4     ; address to call if (?Address EOR (Mask>>8)) AND Mask <> 0
Neil Turton's avatar
Neil Turton committed
240 241 242 243 244 245 246 247 248 249 250 251 252 253
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
254
        EOR     r1, r1, r2, LSR #8
Neil Turton's avatar
Neil Turton committed
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
        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
273 274
; r3 = interrupt location      } when podules are
; r4 = interrupt mask/polarity } supported and r0 = podule device number
Kevin Bracey's avatar
Kevin Bracey committed
275 276 277

CDV_Flags * &FF000000
CDV_Shared * 1:SHL:31
Neil Turton's avatar
Neil Turton committed
278 279 280 281 282 283 284 285 286

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
287
        BIC     r0, r0, #CDV_Flags
288 289 290
        LDR     lr, =ZeroPage
        LDR     lr, [lr, #IRQMax]
        CMP     r0, lr
Kevin Bracey's avatar
Kevin Bracey committed
291
        BHS     DV_Fail_NaffDevNo
Neil Turton's avatar
Neil Turton committed
292

293 294
 [ NumberOfPodules > 0
        ! 0,    "ClaimDeviceVector has podule IRQ/FIQs assembled in"
Neil Turton's avatar
Neil Turton committed
295 296 297
        CMP     r0, #Podule_DevNo
        CMPNE   r0, #PFIQasIRQ_DevNo
        BEQ     PoduleChainClaim
Kevin Bracey's avatar
Kevin Bracey committed
298
 ]
Neil Turton's avatar
Neil Turton committed
299 300 301
        MOV     r3, #12
        BL      ClaimSysHeapNode
        BVS     DV_Exit
Kevin Bracey's avatar
Kevin Bracey committed
302 303
        LDR     r11, [sp]
        BIC     r0, r11, #CDV_Flags
Neil Turton's avatar
Neil Turton committed
304 305 306
        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
307
        WritePSRc SVC_mode+I_bit, r10   ; IRQs off for update (on again on SWI exit)
Neil Turton's avatar
Neil Turton committed
308 309
        LDMIA   r1, {r0, r3, r10}
        STMIA   r2, {r0, r3, r10}       ; copy current head into node
Kevin Bracey's avatar
Kevin Bracey committed
310 311 312 313 314
        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
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
        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

334
 [ NumberOfPodules > 0
Neil Turton's avatar
Neil Turton committed
335 336 337 338 339 340 341 342 343 344 345
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
346 347
        LDREQ   r0, =ZeroPage+PIRQ_Chain
        LDRNE   r0, =ZeroPage+PFIQasIRQ_Chain
Kevin Bracey's avatar
Kevin Bracey committed
348
        WritePSRc SVC_mode+I_bit, r1    ; IRQs off for update
Neil Turton's avatar
Neil Turton committed
349 350 351 352
        LDR     r1, [r0]
        STR     r1, [r10, #PodDesp_Link]
        STR     r10, [r0]
        B       DV_Exit
Kevin Bracey's avatar
Kevin Bracey committed
353
 ]
Neil Turton's avatar
Neil Turton committed
354 355 356 357 358 359 360 361 362 363 364 365 366

; .............................................................................
; 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
367
        BIC     r0, r0, #CDV_Flags
368 369 370
        LDR     lr, =ZeroPage
        LDR     lr, [lr, #IRQMax]
        CMP     r0, lr
Kevin Bracey's avatar
Kevin Bracey committed
371
        BHS     DV_Fail_NaffDevNo
Neil Turton's avatar
Neil Turton committed
372

Kevin Bracey's avatar
Kevin Bracey committed
373
        WritePSRc SVC_mode + I_bit, r12 ; IRQs off while holding context
374 375
 [ NumberOfPodules > 0
        ! 0,    "ReleaseDeviceVector has podule IRQ/FIQs assembled in"
Neil Turton's avatar
Neil Turton committed
376 377 378
        CMP     r0, #Podule_DevNo
        CMPNE   r0, #PFIQasIRQ_DevNo
        BEQ     PoduleChainRelease
Kevin Bracey's avatar
Kevin Bracey committed
379
 ]
Neil Turton's avatar
Neil Turton committed
380 381 382 383 384 385

        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
386
01      LDMIB   r12, {r3, r10}
Neil Turton's avatar
Neil Turton committed
387 388 389 390
        CMP     r3, r2
        CMPEQ   r10, r1
        BEQ     %FT02                   ; found it
        MOV     r11, r12
Kevin Bracey's avatar
Kevin Bracey committed
391 392
        LDR     r12, [r12, #IRQDesp_Link]
        BICS    r12, r12, #IRQDesp_Link_Unshared
Neil Turton's avatar
Neil Turton committed
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
        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
409 410 411 412 413 414
        LDR     r12, [r2, #IRQDesp_Link]
        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
415 416
        B       %FT04

Kevin Bracey's avatar
Kevin Bracey committed
417
03      LDR     r2, [r12, #IRQDesp_Link]; freeable = nextnode
418
        BIC     r2, r2, #IRQDesp_Link_Unshared
Neil Turton's avatar
Neil Turton committed
419 420 421 422 423 424 425
        LDMIA   r2,  {r0, r1, r3}       ; copy next node into head posn
        STMIA   r12, {r0, r1, r3}

04
        BL      FreeSysHeapNode         ; free block
        B       DV_Exit

426
 [ NumberOfPodules > 0
Neil Turton's avatar
Neil Turton committed
427 428
PoduleChainRelease
        CMP     r0, #Podule_DevNo
Jeffrey Lee's avatar
Jeffrey Lee committed
429 430
        LDREQ   r0, =ZeroPage+PIRQ_Chain-PodDesp_Link
        LDRNE   r0, =ZeroPage+PFIQasIRQ_Chain-PodDesp_Link
Neil Turton's avatar
Neil Turton committed
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449

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
450
 ]
Neil Turton's avatar
Neil Turton committed
451 452 453 454 455 456 457 458 459 460

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

IRQ ROUT

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

Jeffrey Lee's avatar
Jeffrey Lee committed
461 462
        Pull    "r10, lr"
        Pull    "pc"                    ; new-style CDV - pull return address
Neil Turton's avatar
Neil Turton committed
463 464 465

; *****************************************************************************
; Default IRQ2V:
Kevin Bracey's avatar
Kevin Bracey committed
466 467
;   r0  must still have devno in it
;   r12 is 0 (from vector)
Neil Turton's avatar
Neil Turton committed
468 469 470 471 472

; Clear mask, clear IRQ as appropriate/possible

NOIRQ ROUT

Kevin Bracey's avatar
Kevin Bracey committed
473 474
        TEQ     r0, #0
        Pull    pc, MI
Kevin Bracey's avatar
Kevin Bracey committed
475 476 477 478
        MOV     r11, r9
        AddressHAL
        CallHAL HAL_IRQDisable
        MOV     r9, r11
Kevin Bracey's avatar
Kevin Bracey committed
479
        Pull    pc              ; claim vector
Neil Turton's avatar
Neil Turton committed
480 481 482 483 484 485 486 487 488 489

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; 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
490
        WritePSRc SVC_mode+I_bit, lr    ; Disable IRQs. MUST call these ones
Neil Turton's avatar
Neil Turton committed
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
        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
510
      [ ZeroPage = 0
Neil Turton's avatar
Neil Turton committed
511
        LDRLSB  r14, [r0, #OsbyteVars + :INDEX: EventSemaphores]
Jeffrey Lee's avatar
Jeffrey Lee committed
512 513 514 515
      |
        LDRLS   r14, =ZeroPage+OsbyteVars+:INDEX:EventSemaphores
        LDRLSB  r14, [r0, r14]
      ]
Neil Turton's avatar
Neil Turton committed
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
                                        ; 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

Jeffrey Lee's avatar
Jeffrey Lee committed
533 534 535 536 537 538 539
        ; Scrollwheel handling - (vector-based) event watchers are allowed to
        ; suppress scroll updates by claiming the vector. If we made it all the
        ; way to this default handler, then the scroll update should be applied.
        TEQ     r0, #Event_Expansion
        TEQEQ   r1, #Event_Expansion_PointerScroll
        BLEQ    PointerScrollApply

Neil Turton's avatar
Neil Turton committed
540 541 542 543
        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
544
        Pull    pc,NE
Neil Turton's avatar
Neil Turton committed
545

Jeffrey Lee's avatar
Jeffrey Lee committed
546
      [ ZeroPage = 0
Neil Turton's avatar
Neil Turton committed
547 548 549
        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
550 551 552 553 554 555 556
      |
        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
557
        Pull    pc                      ; claim EventV
Neil Turton's avatar
Neil Turton committed
558 559 560 561 562

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

Neil Turton's avatar
Neil Turton committed
563 564
        ALIGN 32

Neil Turton's avatar
Neil Turton committed
565 566
TickOne ROUT

Kevin Bracey's avatar
Kevin Bracey committed
567
        ; Don't push r14 - we're using new interface, and claim the vector
568
        Push    "r0,r9,r12"
569
        AddressHAL
570 571 572 573

        ; 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
574
        CallHAL HAL_TimerIRQClear
575 576

        Pull    "r0" ; get device number back
577
        CallHAL HAL_IRQClear
Kevin Bracey's avatar
Kevin Bracey committed
578
        Pull    "r9,r12"
Neil Turton's avatar
Neil Turton committed
579

Jeffrey Lee's avatar
Jeffrey Lee committed
580
        LDR     R1, =ZeroPage
581 582 583 584
        LDR     R0, [R1, #MetroGnome]
        ADD     R0, R0, #1
        STR     R0, [R1, #MetroGnome]

Neil Turton's avatar
Neil Turton committed
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
        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
; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

648 649 650 651 652 653 654 655 656 657 658 659 660
UpdateFalseVsync ROUT
        ; claim or release falsevsync vector if vsyncs supported/not supported
        TST     r0, #GVDisplayFeature_NoVsyncIRQ ; are VSyncs not generated?
        Entry   "r0-r2"
        MOV     r0, #TickerV
        ADR     r1, FalseVsyncIRQ
        LDR     r2, =ZeroPage+OsbyteVars
        BEQ     %ft2
        SWI     XOS_Claim
        EXIT
2       SWI     XOS_Release
        EXIT

Neil Turton's avatar
Neil Turton committed
661
        ALIGN 32
John Ballance's avatar
John Ballance committed
662
FalseVsyncIRQ ROUT
Jeffrey Lee's avatar
Jeffrey Lee committed
663
        LDR     R1, =ZeroPage
John Ballance's avatar
John Ballance committed
664 665 666 667
        LDR     R0, [R1, #MetroGnome]
        TST     R0, #1
        MOVEQ   pc, lr
        Push    "lr"
Jeffrey Lee's avatar
Jeffrey Lee committed
668
        ; Fall through...
Neil Turton's avatar
Neil Turton committed
669

Jeffrey Lee's avatar
Jeffrey Lee committed
670
VsyncIRQ_ExtEntry ROUT
Neil Turton's avatar
Neil Turton committed
671 672 673 674 675 676 677 678 679 680 681 682 683 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
        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