Watchdog 8.85 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
; 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.
;
; watchdog source

        [ NewErrorSystem

watchdogguard   DCD     &E240569E

        [ WatchdogTimer

Kevin Bracey's avatar
Kevin Bracey committed
23 24
BreakWatchdogHandler
        Push    "R0-R1"
Neil Turton's avatar
Neil Turton committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

       |

BreakWatchdogHandler

        TEQ     R0,#Event_Keyboard
        MOVNE   PC,lr
        TEQ     R1,#1                   ; only interested in key down
        MOVNE   PC,lr
        [ SnapShot
        TEQ     R2,#13
        BEQ     capturescreen
        ]
        TEQ     R2,#15                  ; break key
        MOVNE   PC,lr
Kevin Bracey's avatar
Kevin Bracey committed
40
        Push    "R0-R1"
Neil Turton's avatar
Neil Turton committed
41 42
        ]

Kevin Bracey's avatar
Kevin Bracey committed
43
        [ No32bitCode
Neil Turton's avatar
Neil Turton committed
44 45 46
        MOV     R0,PC
        TEQP    PC,#SVC_mode
        NOP
Kevin Bracey's avatar
Kevin Bracey committed
47 48 49 50 51 52
        |
        MRS     R0,CPSR
        ORR     R1,R0,#SVC_mode
        BIC     R1,R1,#I32_bit+F32_bit
        MSR     CPSR_c,R1
        ]
Neil Turton's avatar
Neil Turton committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101

        Push    "R0-R2,LR"
        LDR     R0,watchdogcodew
        TEQ     R0,#0
        BNE     watchdogend
        LDR     R0,watchdogarea
        LDR     R1,watchdogguard
        CMP     R0,R1
        BEQ     watchdogend

        [ WatchdogTimer
; the event based system has already checked for break key.

        MOV     R0,#121
        MOV     R1,#44:EOR:128                         ; Break
        SWI     XOS_Byte
        CMP     R1,#&ff
        BNE     watchdogend
        ]

        MOV     R0,#121
        MOV     R1,#2:EOR:128                          ; Alt
        SWI     XOS_Byte
        CMP     R1,#&ff
        BNE     watchdogend
        MOV     R0,#121
        MOV     R1,#1:EOR:128                          ; Ctrl
        SWI     XOS_Byte
        CMP     R1,#&ff
        BEQ     watchdogend                            ; only Break
        MOV     R0,#121
        MOV     R1,#0:EOR:128                          ; Shift
        SWI     XOS_Byte
        CMP     R1,#&ff
        BEQ     watchdogend

        LDR     R1,watchdogguard
        STR     R1,watchdogarea
        LDR     R1,taskhandle
        STR     R1,watchdogtask
        MOV     R1,#-1
        STR     R1,watchdogtaskno
        ADR     R0,watchdogcallback
        MOV     R1,R12
        SWI     XOS_AddCallBack
        MOV     R0,#124
        SWI     XOS_Byte                                ; clear escape condition
watchdogend
        Pull    "R0-R2,LR"
Kevin Bracey's avatar
Kevin Bracey committed
102
        [ No32bitCode
Neil Turton's avatar
Neil Turton committed
103 104
        TEQP    PC,R0
        NOP
Kevin Bracey's avatar
Kevin Bracey committed
105 106 107 108
        |
        MSR     CPSR_c,R0
        ]
        Pull    "R0-R1,PC"
Neil Turton's avatar
Neil Turton committed
109 110 111 112 113 114 115

        LTORG

kill_labels
        DCB     "Watchdog:Stop,Cancel,Next Task"
        DCB     0

116
	ALIGN
Neil Turton's avatar
Neil Turton committed
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
watchdogcallback
        Push    "R0-R7,R14"

        LDR     R0,watchdogtask                 ; R0 = task handle
        LDR     R1,[wsptr,R0]                   ; R1 -> task record
        TEQ     R1,#task_unused
        LDRNE   R7,taskhandle                   ; save this as we may have to page
        STRNE   R0,taskhandle
;
        BLNE    fulltaskhandle
        STRNE   R7,taskhandle                   ; put it back just in case
        MOVNE   R0,R14
        MOVEQ   R0,#0
; setup meaningful task handle =0 if none, else current

        SWI     XTaskManager_TaskNameFromHandle       ; get task name
        ADRVS   R0,notaskname

        MOV     R4,R0

        LDR     R0,commandflag
        TEQ     R0,#cf_active

        ADRNE   R0,killapptoken
        ADREQ   R0,killprogtoken

        ADRL    R2,watchdogerrtxt
        MOV     R3,#?watchdogerrtxt
        MOV     R5,#0
        BL      LookupToken

        ADRL    R0,watchdogerror
        LDR     R1,=&050DEAD0                   ; user1
        STR     R1,[R0]
        MOV     R1,#256+2048+512                   ; new bits
        ADR     R2,watchdogappname
        MOV     R3,#0
        MOV     R4,#1
        SUB     SP,SP,#64
        Push    "R0-R4"
        ADR     R0,kill_labels
        ADD     R2,SP,#20
        MOV     R3,#64
        BL      LookupToken1
        MOV     R5,R2

        MOV     R0,#124
        SWI     XOS_Byte                        ; BASIC may have caused an escape condition

        Pull    "R0-R4"
        SWI     XWimp_ReportError
        ADD     SP,SP,#64
        CMP     R1,#5                           ; next
        BNE     watchdognext
taskloop
        LDR     R0,watchdogtaskno
        ADD     R0,R0,#1
        CMP     R0,#maxtasks
        BEQ     watchdognext
        STR     R0,watchdogtaskno
        ADRL    R3,taskpointers
        ADD     R0,R3,R0, LSL #2
        LDR     R2,[R0]
        TEQ     R2,#task_unused
        BEQ     taskloop
        SUB     R0,R0,wsptr
        STR     R0,watchdogtask
        ADR     R0,watchdogcallback
        MOV     R1,R12
        SWI     XOS_AddCallBack
187 188 189 190 191
      [ NCErrorBox
        ADRL    R1, ptrpreserveflag
        MOV     R0, #1
        STR     R0, [R1]                         ; note not to move the pointer
      ]
Neil Turton's avatar
Neil Turton committed
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
        Pull    "R0-R7,PC"
watchdognext
        CMP     R1,#3                            ; kill
        CMPNE   R1,#1                            ; ok if text mode
        STR     R1,watchdogarea

        Pull    "R0-R7,PC",NE

        LDR     R0,watchdogtask
        STR     R0,newtaskhandle
        BL      printjobrunning

        LDR     R14,taskhandle

        TEQ     R0,R14                  ; current task going to die?
        BEQ     %FT05

209 210 211 212
        MOV     R7, R14                 ; keep [taskhandle] so we can restore it later
        STR     R0, taskhandle
        BL      fulltaskhandle          ; R14 = full task handle for watchdogtask
        STR     R7, taskhandle
Neil Turton's avatar
Neil Turton committed
213

214 215 216
        MOV     R0, R14
        LDR     R1, taskidentifier5
        SWI     XWimp_CloseDown         ; kill the selected task (!= current task)
Neil Turton's avatar
Neil Turton committed
217 218 219

        Pull    "R0-R7,PC"

220
taskidentifier5 DCB "TASK"
Neil Turton's avatar
Neil Turton committed
221 222 223 224 225 226 227 228 229 230

05
        SWI     XHourglass_Smash        ; turn off hourglass (if displayed)
                                        ; If kill message was textual, this wont have
                                        ; been done

                                        ; errorstack held the most recently used sprite area
        LDR     R0,errorstack-8
        CMP     R0,#&8000               ; were we in a sprite ?

Ben Avison's avatar
Ben Avison committed
231
        Pull    "R0-R7" ,LO
Neil Turton's avatar
Neil Turton committed
232

Ben Avison's avatar
Ben Avison committed
233
        SWILO   OS_Exit                 ; can safely exit
Neil Turton's avatar
Neil Turton committed
234 235 236
        LDR     R14,orig_applicationspacesize
        CMP     R0,R14

Ben Avison's avatar
Ben Avison committed
237
        Pull    "R0-R7",HS
Neil Turton's avatar
Neil Turton committed
238

Ben Avison's avatar
Ben Avison committed
239
        SWIHS   OS_Exit                 ; outside app space
Neil Turton's avatar
Neil Turton committed
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271

        MOV     R0,#SpriteReason_SwitchOutputToSprite
        MOV     R1,#0
        MOV     R2,#0
        MOV     R3,#0
        SWI     XOS_SpriteOp            ; make sure output is switched to the screen

        Pull    "R0-R7"

        SWI     OS_Exit

        LTORG

killapptoken
        DCB     "KillApp",0

        ALIGN

killprogtoken
        DCB     "KillProg",0  ; we're in command mode

        ALIGN

notaskname
        DCB     "Unknown",0

        ALIGN

watchdogappname
        DCB     "Window Manager",0
        ALIGN

272
printjobrunning Entry R0
Neil Turton's avatar
Neil Turton committed
273 274
        LDR     R14,taskhandle
        TEQ     R0,R14                  ; killing current task ?
Kevin Bracey's avatar
Kevin Bracey committed
275
        EXIT    NE
Neil Turton's avatar
Neil Turton committed
276
        SWI     XPDriver_CurrentJob
Kevin Bracey's avatar
Kevin Bracey committed
277
        EXIT    VS
Neil Turton's avatar
Neil Turton committed
278
        TEQ     R0,#0
Kevin Bracey's avatar
Kevin Bracey committed
279
        EXIT    EQ
Neil Turton's avatar
Neil Turton committed
280
        SWI     XPDriver_AbortJob
Kevin Bracey's avatar
Kevin Bracey committed
281
        EXIT
Neil Turton's avatar
Neil Turton committed
282 283 284 285 286 287 288


        ]

        LTORG

SWIWimp_SetWatchdogState
289 290
        MyEntry "SetWatchdogState"

Neil Turton's avatar
Neil Turton committed
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
        [ NewErrorSystem
        TEQ     R0,#0
        BNE     %FT01
        LDR     R14,watchdogcodew
        TEQ     R14,#0                          ; already disabled ?
        EOREQ   R1,R1,R12
        STREQ   R1,watchdogcodew
        BEQ     ExitWimp
01
        LDR     R0,watchdogcodew
        EOR     R0,R0,R12
        EORS    R0,R0,R1
        STREQ   R0,watchdogcodew
        ]
        B       ExitWimp

        [ SnapShot
capturescreen
Kevin Bracey's avatar
Kevin Bracey committed
309 310
        Push    "R0-R1"
        [ No32bitCode
Neil Turton's avatar
Neil Turton committed
311 312 313
        MOV     R0,PC
        TEQP    PC,#SVC_mode                            ; need a stack!!!
        NOP
Kevin Bracey's avatar
Kevin Bracey committed
314 315 316 317 318 319
        |
        MRS     R0,CPSR
        BIC     R1,R0,#I32_bit+F32_bit
        ORR     R1,R1,#SVC_mode
        MSR     CPSR_c,R1
        ]
Neil Turton's avatar
Neil Turton committed
320 321 322 323 324 325 326 327 328 329 330 331 332 333

        Push    "R0-R2,LR"
        MOV     R0,#121
        MOV     R1,#2:EOR:128                          ; Alt
        SWI     XOS_Byte
        CMP     R1,#&ff
        ADREQ   R0,screen_callback
        SWIEQ   XOS_AddCallBack
        B       watchdogend

screen_callback
        Push    "R0-R3,lr"
        MOV     R3,#1
        ADR     R2,scrn_pathname
334
        MOV     R0,#SpriteReason_ScreenSave
Neil Turton's avatar
Neil Turton committed
335 336 337 338 339 340 341 342 343 344 345 346 347
        SWI     XOS_SpriteOp
        MOVVS   R1,#1
        MOVVS   R2,#0
        SWIVS   XWimp_ReportError
        Pull    "R0-R3,PC"

scrn_pathname
        DCB     "<Wimp$scrapdir>.!!Screen!!",0

        ALIGN
 ]

        END