Middle 69 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
; 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     => Middle

Kevin Bracey's avatar
Kevin Bracey committed
17 18 19 20 21 22 23 24 25 26
; Compatibility fudgery for OS_ReadLine and ReadLineV with 32-bit addresses

 [ No26bitCode
ReadLineSWI
        Push    "r4,lr"
        MOV     r4, #0
        SWI     XOS_ReadLine32
        Pull    "r4,lr"
        ; Pass back NZCV bits
        MRS     r11, CPSR
27
      [ NoARMT2
Kevin Bracey's avatar
Kevin Bracey committed
28 29 30
        BIC     lr,  lr,  #N_bit+Z_bit+C_bit+V_bit
        AND     r11, r11, #N_bit+Z_bit+C_bit+V_bit
        ORR     lr, lr, r11
31 32 33 34 35
      |
        ASSERT (N_bit+Z_bit+C_bit+V_bit)=&F0000000
        MOV     r11, r11, LSR #28
        BFI     lr, r11, #28, #4
      ]
Kevin Bracey's avatar
Kevin Bracey committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
        B       SLVK

ReadLine32SWI
        MOV     r11, #OS_ReadLine
        B       VecSwiDespatch
 |
ReadLine32SWI
        TST     r0, #ARM_CC_Mask-3
        BNE     %FT90
        AND     r11, r4, #ARM_CC_Mask
        ORR     r0, r0, r11
        Push    "r4,lr"
        AND     r4, r4, #&FF
        SWI     XOS_ReadLine
        Pull    "r4,lr"
        B       SLVK_TestV

90      Push    "lr"
        BL      SetErrorBadAddress
        Pull    "lr"
        B       SLVK_SetV
 ]

Neil Turton's avatar
Neil Turton committed
59 60 61 62
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; VecRdLine - Read line from input stream (OSWORD 0 equivalent)

; In    r0 -> buffer for characters
Kevin Bracey's avatar
Kevin Bracey committed
63 64 65 66 67
 [ :LNOT:No26bitCode
;               bit 31 set means don't reflect characters that don't go in the buffer
;               bit 30 set means reflect with the character in R4
 ]
;       r1 =  max length of line (excluding carriage return)
Neil Turton's avatar
Neil Turton committed
68 69
;       r2 = lowest character put into buffer
;       r3 = highest character put into buffer
Kevin Bracey's avatar
Kevin Bracey committed
70 71 72 73 74 75 76 77
 [ No26bitCode
;       r4 = flags
;               bit 31 set means don't reflect characters that don't go in the buffer
;               bit 30 set means reflect with the character in R4
;               bits 7-0 = character to echo if r4 bit 30 is set
 |
;       r4 = character to echo if r1 bit 30 is set
 ]
Neil Turton's avatar
Neil Turton committed
78 79
;       wp -> OsbyteVars

80 81
; Out   r0, r2, r3 corrupted
;       r1 = length of line (excluding carriage return)
Neil Turton's avatar
Neil Turton committed
82 83 84 85 86 87 88 89
;       C=0 => line terminated by return (CR or LF)
;       C=1 => line terminated by ESCAPE

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

VecRdLine ROUT

        Push    "R4-R7"
90

Kevin Bracey's avatar
Kevin Bracey committed
91 92 93 94 95
 [ No26bitCode
        MOV     R7, R4                  ; R7 = flags + echo byte
        MOV     R4, R0                  ; R4 -> buffer
 |
        AND     R7, R0, #&C0000000      ; extract flags
Neil Turton's avatar
Neil Turton committed
96 97 98
        AND     R4, R4, #&FF
        ORR     R7, R7, R4              ; got flags, potential echo byte in R7

Kevin Bracey's avatar
Kevin Bracey committed
99 100
        BIC     R4, R0, #ARM_CC_Mask-3  ; R4 -> buffer
 ]
Neil Turton's avatar
Neil Turton committed
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 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

        MOV     R6, #0                  ; R6 = index into buffer
        STRB    R6, PageModeLineCount   ; reset page lines

        B       %FT10
        LTORG

05
        SWI     XOS_WriteC
        BVS     ReadLine_Vset
10
        SWI     XOS_ReadC
        BVS     ReadLine_Vset
        BCS     %FT70                   ; ESCAPE

        LDRB    R5, WrchDest            ; does output include VDU ?
        TST     R5, #2
        BNE     %FT30                   ; no, then still buffer

        LDRB    R5, VDUqueueItems       ; is VDU queueing ?
        TEQ     R5, #0
        BNE     %BT05                   ; yes, then just print

30
        TEQ     R0, #127                ; is it DELETE ?
        TEQNE   R0, #8                  ; or backspace?
        BNE     %FT40                   ; no, then skip

        TEQ     R6, #0                  ; yes, then have we any chars ?
        BEQ     %BT10                   ; no, then loop
        SUB     R6, R6, #1              ; go back 1 char
        MOV     R0, #127
        B       %BT05                   ; print DEL and loop

40
        TEQ     R0, #21                 ; is it CTRL-U ?
        BNE     %FT50                   ; no, then skip

        TEQ     R6, #0                  ; yes, then have we any chars ?
        BEQ     %BT10                   ; no, then loop

45
        SWI     XOS_WriteI+127          ; print DELs to start of line
        BVS     ReadLine_Vset
        SUBS    R6, R6, #1
        BNE     %BT45
        B       %BT10                   ; then loop

50
        TEQ     R0, #13                 ; is it CR ?
        TEQNE   R0, #10                 ; or LF ?
        MOVEQ   r0, #13                 ; always store CR if so
        STRB    R0, [R4, R6]            ; store byte in buffer
        BEQ     %FT60                   ; Exit if either

        CMP     R6, R1                  ; is buffer full ?
        MOVCS   R0, #7                  ; if so, beep and loop
        BCS     %BT05

        CMP     R0, R2                  ; is char >= min ?
        CMPCS   R3, R0                  ; and char <= max ?
        ADDCS   R6, R6, #1              ; if so, then inc pointer
        BCS     %FT80
164
        TST     R7, #&80000000          ; no reflection
165
        BNE     %BT10                   ; of non-entered chars
Neil Turton's avatar
Neil Turton committed
166

167
80      TST     R7, #&40000000
Neil Turton's avatar
Neil Turton committed
168 169 170 171 172 173 174 175 176 177 178 179 180
        ANDNE   R0, R7, #&FF            ; echo char -> R0

        B       %BT05                   ; echo character

60      SWI     XOS_NewLine
        BVS     ReadLine_Vset

; insert code here to call NetVec with R0 = &0D

70
        CLRV
EndReadLine
        MOVVC   R0, R4                  ; restore R0
Jeffrey Lee's avatar
Jeffrey Lee committed
181
        LDR     R5, =ZeroPage
Neil Turton's avatar
Neil Turton committed
182 183 184 185
        LDRB    R5, [R5, #ESC_Status]
        MOVS    R5, R5, LSL #(32-6)     ; shift esc bit into carry

        MOV     R1, R6                  ; R1 := length
Kevin Bracey's avatar
Kevin Bracey committed
186 187 188
 [ No26bitCode
        Pull    "R4-R7, pc"             ; Always claiming vector
 |
Neil Turton's avatar
Neil Turton committed
189 190 191 192 193
        Pull    "R4-R7, lr"             ; Always claiming vector
        BIC     lr, lr, #V_bit :OR: C_bit
        MOV     r12, pc
        AND     r12, r12, #V_bit :OR: C_bit
        ORRS    pc, lr, r12             ; back with C, V affected.
Kevin Bracey's avatar
Kevin Bracey committed
194
 ]
Neil Turton's avatar
Neil Turton committed
195 196 197 198 199 200 201 202 203 204

ReadLine_Vset
        SETV
        B       EndReadLine

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; SWI OS_Control (deprecated): set handlers

SCTRL   Push    "R0-R3, lr"

Kevin Bracey's avatar
Kevin Bracey committed
205
        WritePSRc SVC_mode+I_bit, R0    ; need IRQs off to get consistent state
Neil Turton's avatar
Neil Turton committed
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
        MOV     R0, #EventHandler
        MOV     R1, R3
        BL      CallCESWI
        STR     R1, [stack, #3*4]

        MOV     R0, #EscapeHandler
        LDR     R1, [stack, #2*4]
        BL      CallCESWI
        STR     R1, [stack, #2*4]

        MOV     R0, #ErrorHandler
        Pull    "R1, R3"
        BL      CallCESWI
        MOV     R0, R1
        MOV     R1, R3

        Pull    "R2, R3, lr"
        ExitSWIHandler


CallCESWI
        Push    lr
        MOV     r2, #0                  ; readonly
        SWI     XOS_ChangeEnvironment
        Pull    pc

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; SWI OS_SetEnv (deprecated): Environment setting

SSTENV  Push    "R0, R1, lr"
Kevin Bracey's avatar
Kevin Bracey committed
236
        WritePSRc SVC_mode+I_bit, R0    ; no irqs - want consistent set.
Neil Turton's avatar
Neil Turton committed
237 238 239 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
        MOV     R0, #AddressExceptionHandler
        MOV     R1, R7
        SWI     XOS_ChangeEnvironment
        MOV     R7, R1

        MOV     R0, #DataAbortHandler
        MOV     R1, R6
        SWI     XOS_ChangeEnvironment
        MOV     R6, R1

        MOV     R0, #PrefetchAbortHandler
        MOV     R1, R5
        SWI     XOS_ChangeEnvironment
        MOV     R5, R1

        MOV     R0, #UndefinedHandler
        MOV     R1, R4
        SWI     XOS_ChangeEnvironment
        MOV     R4, R1

        MOV     R0, #MemoryLimit
        LDR     R1, [stack, #4]
        SWI     XOS_ChangeEnvironment
        STR     R1, [stack, #4]

        MOV     R0, #ExitHandler
        Pull    "R1"
        BL      CallCESWI
        Push    "R1"

Jeffrey Lee's avatar
Jeffrey Lee committed
267
        LDR     R12, =ZeroPage
Neil Turton's avatar
Neil Turton committed
268 269 270 271 272 273 274 275 276 277
        LDR     R2, [R12, #RAMLIMIT]    ; this is read-only
        MOV     R3, #0                  ; never any Brazil-type buffering
                                        ; m2 tools will complain if there is!
        Pull    "R0, R1, lr"
        ExitSWIHandler

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Change user state SWIs
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Kevin Bracey's avatar
Kevin Bracey committed
278
SINTON  BIC     lr, lr, #I32_bit
Neil Turton's avatar
Neil Turton committed
279 280
        ExitSWIHandler

Kevin Bracey's avatar
Kevin Bracey committed
281
SINTOFF ORR     lr, lr, #I32_bit
Neil Turton's avatar
Neil Turton committed
282 283
        ExitSWIHandler

Kevin Bracey's avatar
Kevin Bracey committed
284 285 286 287 288
SENTERSWI
        TST   lr, #2_11100
        ORREQ lr, lr, #SVC26_mode       ; 26-bit modes -> SVC26
        BICNE lr, lr, #2_11111
        ORRNE lr, lr, #SVC32_mode       ; others -> SVC32
Neil Turton's avatar
Neil Turton committed
289 290
        ExitSWIHandler

291 292 293 294
SLEAVESWI
        BIC   lr, lr, #2_01111
        ExitSWIHandler

Neil Turton's avatar
Neil Turton committed
295 296 297 298 299
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; SWI OS_BreakPt: user breakpoint - unsuitable for debugging SVC mode code!

SBRKPT ROUT

300
        ADD     sp, sp, #4              ; discard stacked SWI number
Jeffrey Lee's avatar
Jeffrey Lee committed
301
        LDR     r10, =ZeroPage
302
        LDR     r10, [r10, #BrkBf]
Kevin Bracey's avatar
Kevin Bracey committed
303
  [ No26bitCode
304 305 306 307 308 309
        STR     r12, [r10, #16*4]       ; original PSR (with V)
        Pull    r14
        TST     r12, #T32_bit
        SUBEQ   r14, r14, #4
        SUBNE   r14, r14, #2            ; r14 = PC of the SWI
        TST     r12, #2_01111
Kevin Bracey's avatar
Kevin Bracey committed
310
  |
311 312
        FakeLR  r11,,r12                ; r12+[sp] -> lr (r11 temp reg)
        SUB     r14, r14, #4            ; r14 = PC of the SWI
Kevin Bracey's avatar
Kevin Bracey committed
313 314
        TST     r14, #SVC_mode
  ]
315
        STR     r14, [r10, #15*4]       ; PC of the SWI put in.
Kevin Bracey's avatar
Kevin Bracey committed
316
        BNE     %FT01                   ; NE if not in user mode
Jeffrey Lee's avatar
Jeffrey Lee committed
317
        STR     r0, [r10], #4
318
        MOV     r0, r10
Neil Turton's avatar
Neil Turton committed
319
        LDMFD   sp, {r10-r12}
320 321 322 323 324 325

  [ SASTMhatbroken
        STMIA   r0!,{r1-r12}
        STMIA   r0, {r13_usr,r14_usr}^ ; user mode case done.
        SUB     r0, r0, #12*4
  |
Neil Turton's avatar
Neil Turton committed
326
        STMIA   r0, {r1-r12, r13_usr, r14_usr}^ ; user mode case done.
Neil Turton's avatar
Neil Turton committed
327
        NOP
328
  ]
Neil Turton's avatar
Neil Turton committed
329 330

10      LDR     stack, =SVCSTK
Jeffrey Lee's avatar
Jeffrey Lee committed
331
        LDR     r12, =ZeroPage+BrkAd_ws
Neil Turton's avatar
Neil Turton committed
332 333
        LDMIA   r12, {r12, pc}          ; call breakpoint handler

334 335
; Non-user mode case
01      AND     r11, r12, #2_01111      ; SVC26/SVC32 mode?
Kevin Bracey's avatar
Kevin Bracey committed
336 337
        TEQ     r11, #SVC_mode
        BEQ     %FT02                   ; [yes]
Neil Turton's avatar
Neil Turton committed
338

339
; Non-user, non-supervisor - must be IRQ, ABT, UND or SYS (no SWIs from FIQ)
Jeffrey Lee's avatar
Jeffrey Lee committed
340
        STR     r0, [r10], #4
341 342 343
        MOV     r0, r10
        BIC     r14, r12, #T32_bit      ; don't go into Thumb mode
        LDMFD   sp, {r10-r12}           ; Not banked
344
        MSR     CPSR_c, R14             ; get at registers r13 and r14
Jeffrey Lee's avatar
Jeffrey Lee committed
345 346 347
        STMIA   r0, {r1-r12}
        STR     sp, [r0, #12*4]
        STR     r14, [r0, #13*4]
Kevin Bracey's avatar
Kevin Bracey committed
348
        WritePSRc SVC_mode, r12
Neil Turton's avatar
Neil Turton committed
349 350
        B       %BT10

351
; Supervisor mode case
Neil Turton's avatar
Neil Turton committed
352 353
02      MOV     r14, r12                ; supervisor mode. R14 in buffer dead
        LDMFD   sp!, {r10-r12}
Jeffrey Lee's avatar
Jeffrey Lee committed
354 355
        STMIA   r14, {r0-r12}
        STR     r13, [r14, #13*4]
356 357
        LDR     r12, =&DEADDEAD
        STR     r12, [r14, #14*4]       ; mark R14 as dead
Neil Turton's avatar
Neil Turton committed
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
        B       %BT10

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; SWI OS_UnusedSWI (deprecated): Set the unused SWI handler

SUNUSED Push    "R1, lr"
        MOV     R1, R0
        MOV     R0, #UnusedSWIHandler
        SWI     XOS_ChangeEnvironment
        MOV     R0, R1
        Pull    "R1, lr"
        ExitSWIHandler

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; SWI OS_SetCallBack: Set callback flag

SSETCALL ROUT

376
        MSR     CPSR_c, #I32_bit + SVC32_mode
Jeffrey Lee's avatar
Jeffrey Lee committed
377
        LDR     r10, =ZeroPage
Neil Turton's avatar
Neil Turton committed
378 379 380
        LDRB    r11, [r10, #CallBack_Flag]
        ORR     r11, r11, #CBack_OldStyle
        STRB    r11, [r10, #CallBack_Flag]
Kevin Bracey's avatar
Kevin Bracey committed
381 382 383
        ADD     sp, sp, #4              ; Skip saved R11
        B       back_to_user_irqs_already_off
                                        ; Do NOT exit via normal mechanism
Neil Turton's avatar
Neil Turton committed
384 385 386 387 388 389

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; SWI read mouse information
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

VecMouse
Kevin Bracey's avatar
Kevin Bracey committed
390
     WritePSRc SVC_mode+I_bit, R10
Neil Turton's avatar
Neil Turton committed
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
     MOV   R10, #MouseV
     Push "lr"
     BL    CallVector
     Pull "lr"
     ExitSWIHandler

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; SWI OS_SerialOp when not in kernel
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

SerialOp ROUT
        MOV     r10, #SerialV
        Push    lr
        BL      CallVector
        Pull    lr
        BICCC   lr, lr, #C_bit
        ORRCS   lr, lr, #C_bit
        B       SLVK_TestV

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Supervisor routines to set default handlers
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

; Reset Error and Escape handlers

DEFHAN LDR  R1, =GeneralMOSBuffer         ; decent length error buffer
       ADR  R0, ERRORH
       ADR  R2, ESCAPH
       MOV  R3, #0
       MOV  R4, R14
       SWI  XOS_Control

       MOV  r0, #UpCallHandler
       ADR  r1, DefUpcallHandler
       MOV  r2, #0
       SWI  XOS_ChangeEnvironment

       MOV  PC, R4

; Reset Exception, Event, BreakPoint, UnusedSWI, Exit and CallBack handlers

DEFHN2 MOV  R12, R14
       MOV  R0, #0
       MOV  R1, #0
       MOV  R2, #0
       ADR  R3, EVENTH
       SWI  XOS_Control
438
       LDR  R0, =ZeroPage+DUMPER
Neil Turton's avatar
Neil Turton committed
439 440 441 442 443 444
       ADR  R1, NOCALL
       SWI  XOS_CallBack
       ADRL R0, CLIEXIT
       MOV  R1, #0
       MOV  R2, #0
       ADR  R4, UNDEF
445
       ADRL R5, ABORTP
Neil Turton's avatar
Neil Turton committed
446 447 448
       ADRL R6, ABORTD
       ADRL R7, ADDREX
       SWI  XOS_SetEnv
449
       LDR  R0, =ZeroPage+DUMPER
Neil Turton's avatar
Neil Turton committed
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
       ADR  R1, DEFBRK
       SWI  XOS_BreakCtrl
       ADRL R0, NoHighSWIHandler
       SWI  XOS_UnusedSWI
       MOV  PC, R12

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; system handlers
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

DefUpcallHandler
ESCAPH
EVENTH  MOV     pc, lr


Jeffrey Lee's avatar
Jeffrey Lee committed
465
NOCALL  LDR     r0, =ZeroPage               ; default callback routine
Neil Turton's avatar
Neil Turton committed
466
        LDR     r14, [r0, #CallBf]
Kevin Bracey's avatar
Kevin Bracey committed
467 468
 [ No26bitCode
        LDR     r0, [r14, #4*16]
469
        MSR     SPSR_cxsf, r0
Kevin Bracey's avatar
Kevin Bracey committed
470
 ]
Neil Turton's avatar
Neil Turton committed
471 472 473 474 475 476 477 478 479
        LDMIA   r14, {r0-r12, r13_usr, r14_usr}^ ; load user's regs
        NOP
        LDR     r14, [r14, #4*15]
        MOVS    pc, r14


ERRORH ROUT

      [ International
Jeffrey Lee's avatar
Jeffrey Lee committed
480 481 482
        SWI     XOS_EnterOS

        LDR     R0,=ZeroPage+KernelMessagesBlock+4
Neil Turton's avatar
Neil Turton committed
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
        ADR     R1,ErrorToken
        MOV     R2,#0
        SWI     XMessageTrans_Lookup
        MOVVC   R12,R2
        ADRVS   R12,ErrorText

01
        LDRB    R0,[R12],#1
        CMP     R0,#32
        BLT     %FT99
        CMP     R0,#"%"
        SWINE   XOS_WriteC
        BVS     %FT99
        BNE     %BT01

        LDRB    R0,[R12],#1              ; Found a %
        CMP     R0,#32
        BLT     %FT99

        CMP     R0,#"0"
        LDREQ   R0,=GeneralMOSBuffer+8
        BEQ     %FT10
        CMP     R0,#"1"
        BNE     %BT01

        LDR     R3,=GeneralMOSBuffer+4
        LDR     R0,[R3]
Jeffrey Lee's avatar
Jeffrey Lee committed
510
        LDR     R1,=ZeroPage+MOSConvertBuffer
Neil Turton's avatar
Neil Turton committed
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
        MOV     R2,#12
        SWI     XOS_ConvertHex8

02
        LDRB    R1, [R0], #1
        CMP     R1, #"0"
        BEQ     %BT02
        CMP     R1, #0
        SUBEQ   R0, R0, #1
        SUB     R0, R0, #1

10
        SWI     XOS_Write0
        BVC     %BT01

99
        SWI     XOS_NewLine

Jeffrey Lee's avatar
Jeffrey Lee committed
529
        LDR     R0, =ZeroPage
Neil Turton's avatar
Neil Turton committed
530 531 532
        STRB    R0, [R0, #ErrorSemaphore]                 ; Enable error translation, in case we got here in the
                                                        ; middle of looking up an error

Kevin Bracey's avatar
Kevin Bracey committed
533
        B       GOSUPV                          ; switches back to User mode for us
Neil Turton's avatar
Neil Turton committed
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550

ErrorToken      =       "Error:"
ErrorText       =       "Error: %0 (Error Number &%1)",0
        ALIGN
      |

        SWI     OS_WriteS
        =       10,13,"Error:",10,13, 0
        ALIGN
        LDR     r0, =GeneralMOSBuffer+4
        BL      PrintError
        B       GOSUPV
      ]


DEFBRK
      [ International
Kevin Bracey's avatar
Kevin Bracey committed
551
        WritePSRc 0, lr
Neil Turton's avatar
Neil Turton committed
552
        MOV     r0, r0
Jeffrey Lee's avatar
Jeffrey Lee committed
553
        LDR     r13, =ZeroPage
Neil Turton's avatar
Neil Turton committed
554 555 556 557 558 559 560 561 562
        LDR     r13, [r13, #BrkBf]
        LDR     r0, [r13, #15*4]
        LDR     r1, =GeneralMOSBuffer
        MOV     r2, #?GeneralMOSBuffer
        SWI     OS_ConvertHex8

; r0 -> address

        MOV     R4,R0
Jeffrey Lee's avatar
Jeffrey Lee committed
563
        LDR     R0,=ZeroPage+KernelMessagesBlock+4
Neil Turton's avatar
Neil Turton committed
564 565 566 567 568 569 570 571 572 573 574 575 576
        ADR     R1,BreakToken
        LDR     R2,=GeneralMOSBuffer+16
        MOV     R3,#256-16
        SWI     XMessageTrans_Lookup
        MOVVC   R0,R2
        ADRVS   R0,BreakText
        SWI     OS_Write0
        SWI     OS_NewLine

      |
        SWI     OS_WriteS
        = "Stopped at break point at &", 0
        ALIGN
Kevin Bracey's avatar
Kevin Bracey committed
577
        WritePSRc 0, lr
Neil Turton's avatar
Neil Turton committed
578
        MOV     r0, r0
Jeffrey Lee's avatar
Jeffrey Lee committed
579
        LDR     r13, =ZeroPage
Neil Turton's avatar
Neil Turton committed
580 581 582 583 584 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
        LDR     r13, [r13, #BrkBf]
        LDR     r0, [r13, #15*4]
        LDR     r1, =GeneralMOSBuffer
        MOV     r2, #?GeneralMOSBuffer
        SWI     OS_ConvertHex8
        SWI     OS_Write0
        SWI     OS_NewLine
      ]

Quit_Code
        SWI     OS_Exit

      [ International

BreakToken      =       "BreakPt:"
BreakText       =       "Stopped at break point at &%0",0
        ALIGN

      ]

PrintError
        MOV    R12, R14
        LDR    R10, [R0], #4
        SWI    XOS_Write0
        BVS    %FT02
      [ :LNOT: International
        SWI    XOS_WriteS
        =     " (Error number &", 0
        BVS    %FT02
      ]
        LDR    R1,=GeneralMOSBuffer
        MOV    R2, #&E0
        MOV    R0, R10
        SWI    XOS_ConvertHex8       ; can't fail!
01      LDRB   R1, [R0], #1
        CMP    R1, #"0"
        BEQ    %BT01
        CMP    R1, #0
        SUBEQ  R0, R0, #1
      [ International                   ; We might not have any stack so ..
        SUB    R11,R0, #1               ; R11 -> Error number
Jeffrey Lee's avatar
Jeffrey Lee committed
621
        LDR    R0, =ZeroPage+KernelMessagesBlock+4
Neil Turton's avatar
Neil Turton committed
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 648 649 650 651 652 653 654 655
        ADR    R1, PrintErrorString
        MOV    R2,#0                    ; Don't copy message
        SWI    XMessageTrans_Lookup
        ADRVS  R2,PrintErrorString+4    ; If no MessageTrans point at english text.
11
        LDRB   R0,[R2],#1
        CMP    R0,#32
        BLT    %FT13
        CMP    R0,#"%"
        SWINE  XOS_WriteC
        BVS    %FT13
        BNE    %BT11

        LDRB    R0,[R2],#1
        CMP     R0,#32
        BLT     %FT13                   ; Just in case the % is the last character !

        CMP     R0,#"0"                 ; We only know about %0
        BNE     %BT11

12
        LDRB    R0,[R11],#1              ; Print error number.
        CMP     R0,#32
        BLT     %BT11
        SWI     XOS_WriteC
        BVC     %BT12

13
      |
        SUB    R0, R0, #1
        SWI    XOS_Write0
        SWIVC  XOS_WriteI+")"
      ]
        SWIVC  XOS_NewLine
Kevin Bracey's avatar
Kevin Bracey committed
656
02      MOV    PC, R12
Neil Turton's avatar
Neil Turton committed
657 658 659 660 661 662 663 664 665 666 667 668 669

      [ International
PrintErrorString
        =     "Err: (Error number &%0)", 0
        ALIGN
      ]

        LTORG

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Exception handling

DumpyTheRegisters  ROUT
Kevin Bracey's avatar
Kevin Bracey committed
670 671 672 673 674 675
  [ No26bitCode
; In ABT32 or UND32, PC, PSR already stored, PSR in R1
        MOV     R4, R14                 ; put error address into unbanked register
        TST     R1, #&0F
  |
; In SVC26, fake 26-bit PC at 0
Neil Turton's avatar
Neil Turton committed
676 677 678
        LDR     R1, [R0, -R0]         ; PC when exception happened
        STR     R1, [R0, #(15-8)*4]   ; In the right slot now ...
        TST     R1, #SVC_mode
Kevin Bracey's avatar
Kevin Bracey committed
679
  ]
680 681 682 683 684
  [ SASTMhatbroken
        STMEQIA R0!,{R8-R12}
        STMEQIA R0, {R13,R14}^        ; user mode case done.
        SUBEQ   R0, R0, #5*4
  |
Neil Turton's avatar
Neil Turton committed
685
        STMEQIA R0, {R8-R14}^         ; user mode case done.
686
  ]
Kevin Bracey's avatar
Kevin Bracey committed
687 688 689 690 691
        BEQ     UNDEF2

  [ No26bitCode
        ORR     R2, R1, #I32_bit :OR: F32_bit
        BIC     R2, R2, #T32_bit
692
        MSR     CPSR_c, R2              ; change into original mode
Jeffrey Lee's avatar
Jeffrey Lee committed
693
        STMIA   R0, {R8-R12}            ; save the banked registers
Kevin Bracey's avatar
Kevin Bracey committed
694 695

        AND     R2, R1, #&0F
Jeffrey Lee's avatar
Jeffrey Lee committed
696
        STR     SP, [R0, #5*4]
Kevin Bracey's avatar
Kevin Bracey committed
697
        EORS    R2, R2, #FIQ_mode       ; Was we in FIQ ? Zero if so
Jeffrey Lee's avatar
Jeffrey Lee committed
698 699
        STR     R14, [R0, #6*4]

Jeffrey Lee's avatar
Jeffrey Lee committed
700
     [ HAL
Ben Avison's avatar
Ben Avison committed
701 702
        BNE     UNDEF2
        MSR     CPSR_c, #I32_bit+F32_bit+SVC32_mode ; into SVC mode so we have a stack
Jeffrey Lee's avatar
Jeffrey Lee committed
703 704 705
      [ ZeroPage <> 0
        LDR     R2, =ZeroPage
      ]
Ben Avison's avatar
Ben Avison committed
706 707
        AddressHAL R2
        CallHAL HAL_FIQDisableAll
Jeffrey Lee's avatar
Jeffrey Lee committed
708
     |
Kevin Bracey's avatar
Kevin Bracey committed
709 710
        MOVEQ   R3, #IOC
        STREQB  R2, [R3, #IOCFIQMSK]    ; Blow away all FIQ sources
Jeffrey Lee's avatar
Jeffrey Lee committed
711
     ]
Kevin Bracey's avatar
Kevin Bracey committed
712
UNDEF2
713
        MSR     CPSR_c, #I32_bit+F32_bit+SVC32_mode ; into SVC mode
Neil Turton's avatar
Neil Turton committed
714

Kevin Bracey's avatar
Kevin Bracey committed
715 716 717 718
        MOV     R14, R4                 ; corrupt R14_SVC (but already saved if we were in SVC)
; ... and fall into
UNDEF1
  |
Neil Turton's avatar
Neil Turton committed
719 720 721 722 723 724 725 726 727 728 729
        TST     R1, #1                ; SWI mode?
        TSTNE   R1, #2
        BNE     %FT02
        ORR     R1, R1, #I_bit :OR: F_bit
                                 ; keep interrupts off until handlers restored
        TEQP    R1, #0                  ; get at registers
        NOP
        STMIA   R0, {R8-R14}
        TEQP    PC, #SVC_mode :OR: I_bit :OR: F_bit
        AND     R1, R1, #SVC_mode
        EORS    R2, R1, #FIQ_mode       ; Was we in FIQ ? Zero if so
Ben Avison's avatar
Ben Avison committed
730 731 732 733 734 735 736
      [ HAL
        BNE     UNDEF1
        MOV     R4, R14                 ; R14_SVC will be corrupted by the HAL call
        AddressHAL R2
        CallHAL HAL_FIQDisableAll
        MOV     R14, R4
      |
Neil Turton's avatar
Neil Turton committed
737 738
        MOVEQ   R3, #IOC
        STREQB  R2, [R3, #IOCFIQMSK]    ; Blow away all FIQ sources
Ben Avison's avatar
Ben Avison committed
739
      ]
Neil Turton's avatar
Neil Turton committed
740 741 742 743
        B       UNDEF1

02      STMIA   R0, {R8-R14}
; ... and fall into
Kevin Bracey's avatar
Kevin Bracey committed
744 745 746 747
UNDEF2
UNDEF1
  ]
        LDR     sp, =SVCSTK             ; Flatten superstack
Neil Turton's avatar
Neil Turton committed
748

Jeffrey Lee's avatar
Jeffrey Lee committed
749
        LDR     R0, =ZeroPage
Neil Turton's avatar
Neil Turton committed
750 751 752 753 754 755 756
        LDR     R0, [R0, #ExceptionDump]
        ADD     R1, R0, #10*4           ; point at dumped R10
        LDMIA   R1, {R10-R12}           ; try and put back user registers
        Push    "R10-R12"               ; for error handler to find on stack
        LDR     R1, [R0, #15*4]
        Push    R1

757
       [ :LNOT:No26bitCode
Neil Turton's avatar
Neil Turton committed
758 759 760 761
        LDR     R0, BranchThroughZeroInstruction ; load the B RESET1 instr.
        STR     R0, [R1, -R1]           ; and store it at zero again

        BIC     R14, R14, #ARM_CC_Mask
Kevin Bracey's avatar
Kevin Bracey committed
762
       ]
Neil Turton's avatar
Neil Turton committed
763 764 765
        LDR     R0, =GeneralMOSBuffer+128 ; so can do deviant sharing !

       [ International
Jeffrey Lee's avatar
Jeffrey Lee committed
766
        LDR     r10, =ZeroPage
Neil Turton's avatar
Neil Turton committed
767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785
        LDRB    r10, [r10, #ErrorSemaphore]
        TEQ     r10, #0                 ; if ok to translate error
        MOVEQ   r10, r14
        BEQ     %FT10
       ]

        LDR     r11, [r14], #4          ; Copy error number
        STR     r11, [r0], #4

01      LDRB    r11, [r14], #1          ; Copy error string
        STRB    r11, [r0], #1
        CMP     r11, #"%"               ; Test for "%" near end of string
        BNE     %BT01
10
        SUB     r1, r0, #1              ; point, ready for conversion

        LDR     R2, =GeneralMOSBuffer+?GeneralMOSBuffer
        SUB     r2, r2, r1              ; amount left in buffer

Jeffrey Lee's avatar
Jeffrey Lee committed
786
        LDR     R0, =ZeroPage
Neil Turton's avatar
Neil Turton committed
787 788
        LDR     R0, [R0, #ExceptionDump]
        LDR     R0, [R0, #15*4]         ; saved PC
Kevin Bracey's avatar
Kevin Bracey committed
789
      [ :LNOT: No26bitCode
Neil Turton's avatar
Neil Turton committed
790
        BIC     R0, R0, #ARM_CC_Mask
Kevin Bracey's avatar
Kevin Bracey committed
791
      ]
Neil Turton's avatar
Neil Turton committed
792 793 794
        SWI     XOS_ConvertHex8

      [ International
Jeffrey Lee's avatar
Jeffrey Lee committed
795
        LDR     r4, =ZeroPage
Neil Turton's avatar
Neil Turton committed
796 797 798 799 800 801 802 803 804 805
        LDRB    r4, [r4, #ErrorSemaphore]
        TEQ     r4, #0
        LDRNE   R0, =GeneralMOSBuffer+128
        MOVEQ   R4, R0
        MOVEQ   R0, R10
        BLEQ    TranslateError_UseR4
      |
        LDR     R0, =GeneralMOSBuffer+128
      ]

Kevin Bracey's avatar
Kevin Bracey committed
806 807
      [ No26bitCode
        ; Flatten UND and ABT stacks, jic
808
        MRS     R2, CPSR
Kevin Bracey's avatar
Kevin Bracey committed
809 810
        BIC     R2, R2, #F32_bit + &1F
        ORR     R3, R2, #ABT32_mode
811
        MSR     CPSR_c, R3                      ; FIQs back on
Kevin Bracey's avatar
Kevin Bracey committed
812 813
        LDR     r13_abort, =ABTSTK
        ORR     R3, R2, #UND32_mode
814
        MSR     CPSR_c, R3
Kevin Bracey's avatar
Kevin Bracey committed
815 816
        LDR     r13_undef, =UNDSTK
        ORR     R3, R2, #IRQ32_mode
817
        MSR     CPSR_c, R3
Kevin Bracey's avatar
Kevin Bracey committed
818
      |
Neil Turton's avatar
Neil Turton committed
819
        TEQP    PC, #IRQ_mode+I_bit
Kevin Bracey's avatar
Kevin Bracey committed
820
      ]
Jeffrey Lee's avatar
Jeffrey Lee committed
821 822
        LDR     R1, =ZeroPage
      [ ZeroPage = 0
Neil Turton's avatar
Neil Turton committed
823
        STR     R1, [R1, #IRQsema]
Jeffrey Lee's avatar
Jeffrey Lee committed
824 825 826 827
      |
        MOV     R2, #0
        STR     R2, [R1, #IRQsema]
      ]
Robert Sprowson's avatar
Robert Sprowson committed
828
        LDR     r13_irq, =IRQSTK
Neil Turton's avatar
Neil Turton committed
829 830 831 832 833
        SWI     OS_GenerateError

        LTORG

UNDEF ROUT
Kevin Bracey's avatar
Kevin Bracey committed
834 835 836 837 838
 [ No26bitCode
        ; In UND32 mode, with a stack
        Push    R14
        SETPSR  F_bit :OR: I_bit, R14
 |
Neil Turton's avatar
Neil Turton committed
839 840
        TEQP    pc, #F_bit :OR: I_bit :OR: SVC_mode ; FIQ off too
        STR     R14, [R0, -R0]
Kevin Bracey's avatar
Kevin Bracey committed
841
 ]
Jeffrey Lee's avatar
Jeffrey Lee committed
842
        LDR     R14, =ZeroPage
Neil Turton's avatar
Neil Turton committed
843 844
        LDR     R14, [R14, #ExceptionDump]
        STMIA   R14!, {R0-R7}
Kevin Bracey's avatar
Kevin Bracey committed
845
 [ No26bitCode
846
        MRS     R1, SPSR
Kevin Bracey's avatar
Kevin Bracey committed
847 848 849 850
        STR     R1, [R14, #(16-8)*4]            ; save PSR
        Pull    R0
        STR     R0, [R14, #(15-8)*4]            ; save PC
 ]
Neil Turton's avatar
Neil Turton committed
851 852 853 854 855
        MOV     R0, R14
        BL      DumpyTheRegisters
        MakeErrorBlock UndefinedInstruction

ABORTP ROUT
Kevin Bracey's avatar
Kevin Bracey committed
856 857 858 859 860
 [ No26bitCode
        ; In ABT32 mode, with a stack
        Push    R14
        SETPSR  F_bit :OR: I_bit, R14
 |
Neil Turton's avatar
Neil Turton committed
861 862
        TEQP    pc, #F_bit :OR: I_bit :OR: SVC_mode ; FIQ off too
        STR     R14, [R0, -R0]
Kevin Bracey's avatar
Kevin Bracey committed
863
 ]
Jeffrey Lee's avatar
Jeffrey Lee committed
864
        LDR     R14, =ZeroPage
Neil Turton's avatar
Neil Turton committed
865 866
        LDR     R14, [R14, #ExceptionDump]
        STMIA   R14!, {R0-R7}
Kevin Bracey's avatar
Kevin Bracey committed
867
 [ No26bitCode
868
        MRS     R1, SPSR
Kevin Bracey's avatar
Kevin Bracey committed
869 870 871 872
        STR     R1, [R14, #(16-8)*4]            ; save PSR
        Pull    R0
        STR     R0, [R14, #(15-8)*4]            ; save PC
 ]
Neil Turton's avatar
Neil Turton committed
873 874 875 876 877 878
        MOV     R0, R14
        BL      DumpyTheRegisters

        MakeErrorBlock InstructionAbort

ABORTD ROUT
Kevin Bracey's avatar
Kevin Bracey committed
879 880 881 882 883
 [ No26bitCode
        ; In ABT32 mode, with a stack
        Push    R14
        SETPSR  F_bit :OR: I_bit, R14
 |
Neil Turton's avatar
Neil Turton committed
884 885
        TEQP    pc, #F_bit :OR: I_bit :OR: SVC_mode ; FIQ off too
        STR     R14, [R0, -R0]
Kevin Bracey's avatar
Kevin Bracey committed
886
 ]
Jeffrey Lee's avatar
Jeffrey Lee committed
887
        LDR     R14, =ZeroPage
Neil Turton's avatar
Neil Turton committed
888 889
        LDR     R14, [R14, #ExceptionDump]
        STMIA   R14!, {R0-R7}
Kevin Bracey's avatar
Kevin Bracey committed
890
 [ No26bitCode
891
        MRS     R1, SPSR
Kevin Bracey's avatar
Kevin Bracey committed
892 893 894 895
        STR     R1, [R14, #(16-8)*4]            ; save PSR
        Pull    R0
        STR     R0, [R14, #(15-8)*4]            ; save PC
 ]
Neil Turton's avatar
Neil Turton committed
896 897 898 899 900 901
        MOV     R0, R14
        BL      DumpyTheRegisters
        MakeErrorBlock DataAbort


ADDREX ROUT
Kevin Bracey's avatar
Kevin Bracey committed
902 903
; This really can't happen. Honest
 [ No26bitCode
904 905 906
        ; ??? in ABT32 mode, with a stack?
        Push    R14
        SETPSR  F_bit :OR: I_bit, R14
Kevin Bracey's avatar
Kevin Bracey committed
907
 |
Neil Turton's avatar
Neil Turton committed
908 909
        TEQP    pc, #F_bit :OR: I_bit :OR: SVC_mode ; FIQ off too
        STR     R14, [R0, -R0]
Kevin Bracey's avatar
Kevin Bracey committed
910
 ]
Jeffrey Lee's avatar
Jeffrey Lee committed
911
        LDR     R14, =ZeroPage
Neil Turton's avatar
Neil Turton committed
912 913
        LDR     R14, [R14, #ExceptionDump]
        STMIA   R14!, {R0-R7}
Kevin Bracey's avatar
Kevin Bracey committed
914
 [ No26bitCode
915
        MRS     R1, SPSR
Kevin Bracey's avatar
Kevin Bracey committed
916
        STR     R1, [R14, #(16-8)*4]            ; save PSR
917 918
        Pull    R0
        STR     R0, [R14, #(15-8)*4]
Kevin Bracey's avatar
Kevin Bracey committed
919
 ]
920
        MOV     R0, R14
Neil Turton's avatar
Neil Turton committed
921 922 923 924 925 926
        BL      DumpyTheRegisters

        MakeErrorBlock AddressException


; Can branch through zero in any mode
927
; We go through a trampoline which stores R1 and R14 (at R14 on entry)
Neil Turton's avatar
Neil Turton committed
928

929 930
Branch0_NoTrampoline_DummyRegs
        &       &DEADDEAD, &DEADDEAD
Neil Turton's avatar
Neil Turton committed
931
RESET1 ROUT
932 933 934
Branch0_NoTrampoline
        ADR     R14, Branch0_NoTrampoline_DummyRegs
Branch0_FromTrampoline
Neil Turton's avatar
Neil Turton committed
935

Jeffrey Lee's avatar
Jeffrey Lee committed
936
        LDR     R1, =ZeroPage
Neil Turton's avatar
Neil Turton committed
937
        LDR     R1, [R1, #ExceptionDump]
Jeffrey Lee's avatar
Jeffrey Lee committed
938 939
        STMIA   R1, {R0-R12}
        STR     R13, [R1, #13*4]
940 941 942 943
        LDR     R0, [R14, #0]
        STR     R0, [R1, #1*4]
        LDR     R0, [R14, #4]
        STR     R0, [R1, #14*4]
Kevin Bracey's avatar
Kevin Bracey committed
944 945 946 947 948
 [ XScaleJTAGDebug
        MRS     R0, CPSR
        AND     R0, R0, #&1F
        TEQ     R0, #&15        ; Debug mode?
        BNE     %FT20
Jeffrey Lee's avatar
Jeffrey Lee committed
949
        LDR     R13, =ZeroPage
Kevin Bracey's avatar
Kevin Bracey committed
950 951 952
        LDR     R0, [R13, #ProcessorFlags]
        ORR     R0, R0, #CPUFlag_XScaleJTAGconnected
        STR     R0, [R13, #ProcessorFlags]
953
        LDMIA   R1, {R0, R1}
Kevin Bracey's avatar
Kevin Bracey committed
954 955 956
        B       DebugStub
20
 ]
Stewart Brodie's avatar
Stewart Brodie committed
957
 [ No26bitCode
Kevin Bracey's avatar
Kevin Bracey committed
958 959
        MOV     R0, #0
        STR     R0, [R1, #15*4]
960
        MRS     R0, CPSR
Kevin Bracey's avatar
Kevin Bracey committed
961
        STR     R0, [R1, #16*4]
Stewart Brodie's avatar
Stewart Brodie committed
962
 |
963
        MRS     R0, CPSR                        ; Fake up a combined PC+PSR (PC=0)
Stewart Brodie's avatar
Stewart Brodie committed
964 965 966 967 968 969
        AND     R1, R0, #I32_bit :OR: F32_bit
        AND     R0, R0, #&F0000003
        ORR     R0, R0, R1, LSL #IF32_26Shift
        MOV     R1, #0
        LDR     R1, [R1, #ExceptionDump]
        STR     R0, [R1, #15*4]
Kevin Bracey's avatar
Kevin Bracey committed
970
 ]
971
        MOV     R0, #0
Neil Turton's avatar
Neil Turton committed
972 973 974 975 976
        SWI     XOS_EnterOS

        BL      UNDEF1
        MakeErrorBlock BranchThrough0

977
 [ :LNOT: No26bitCode
Neil Turton's avatar
Neil Turton committed
978 979 980 981
BranchThroughZeroInstruction
 [ ProcessorVectors
        LDR     PC, .+ProcVec_Branch0
 |
982 983
        B       .+Branch0_Trampoline
 ]
Neil Turton's avatar
Neil Turton committed
984 985
 ]

Kevin Bracey's avatar
Kevin Bracey committed
986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014
 [ XScaleJTAGDebug
        ; Magic from the Multi-ICE User Guide
        ALIGN   32
DebugStub ROUT
        ARM_read_control R13
        AND     R13, R13, #MMUC_I
        ORR     R14, R14, R13, LSR #12
        ARM_read_control R13
        ORR     R13, R13, #MMUC_I
        ARM_write_control R13
        ADR     R13, DebugStubLine2
        MCR     p15, 0, R13, C7, C5, 1
        MCR     p15, 0, R13, C7, C5, 6
10      MRC     p14, 0, R15, C14, C0
        BVS     %BT10
        MOV     R13, #&00B00000
        MCR     p14, 0, R13, C8, C0
20      MRC     p14, 0, R15, C14, C0
        BPL     %BT20
        ARM_read_control R13
        TST     R14, #1
        BICEQ   R13, R13, #MMUC_I
        ARM_write_control R13
        MRC     p14, 0, R13, C9, C0
        MOV     PC, R13
        ALIGN   32
DebugStubLine2
        SPACE   32
 ]
Neil Turton's avatar
Neil Turton committed
1015 1016 1017 1018 1019 1020 1021 1022

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; SWI to call the UpCall vector
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

DoAnUpCall ROUT

        Push    lr                  ; better have one of these to pull later !
Kevin Bracey's avatar
Kevin Bracey committed
1023
 [ No26bitCode
1024
        MRS     r12, CPSR
1025
      [ NoARMT2
Kevin Bracey's avatar
Kevin Bracey committed
1026 1027 1028 1029
        BIC     r12, r12, #&F0000000
        BIC     r12, r12, #I32_bit:OR:F32_bit
        AND     r10, lr, #&F0000000 ; copy user flags (I bit clear)
        ORR     r10, r10, r12
1030 1031 1032 1033 1034
      |
        MOV     lr, lr, LSR #28
        BIC     r10, r12, #I32_bit:OR:F32_bit
        BFI     r10, lr, #28, #4 ; copy user flags (I bit clear)
      ]
1035
        MSR     CPSR_cf, r10        ; ints on, stay in SVC mode, flags in psr
Kevin Bracey's avatar
Kevin Bracey committed
1036
 |
Neil Turton's avatar
Neil Turton committed
1037 1038
        AND     r10, lr, #&F0000000 ; copy user flags (I_bit clear)
        TEQP    r10, #SVC_mode      ; ints on, stay in SVC mode, flags in psr
Kevin Bracey's avatar
Kevin Bracey committed
1039
 ]
Neil Turton's avatar
Neil Turton committed
1040 1041
        MOV     r10, #UpCallV
        BL      CallVector
1042
 [ NoARMT2
Neil Turton's avatar
Neil Turton committed
1043 1044
        Pull    lr
        BIC     lr, lr, #&F0000000
1045
   [ No26bitCode
1046
        MRS     R10, CPSR
Kevin Bracey's avatar
Kevin Bracey committed
1047
        MOV     R10, R10, LSR #(32-4)
1048
   |
Neil Turton's avatar
Neil Turton committed
1049
        MOV     R10, PC, LSR #(32-4)
1050
   ]
Neil Turton's avatar
Neil Turton committed
1051
        ORR     lr, lr, R10, LSL #(32-4)
1052 1053 1054 1055 1056 1057 1058
 |
        ASSERT  No26bitCode
        MRS     R10, CPSR
        Pull    lr
        MOV     R10, R10, LSR #28
        BFI     lr, R10, #28, #4
 ]
Neil Turton's avatar
Neil Turton committed
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076
        ExitSWIHandler

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; SWI OS_ChangeEnvironment: Call the environment change vector
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

ChangeEnvironment ROUT

        Push    lr
        MOV     R10, #ChangeEnvironmentV
        BL      CallVector
        Pull    lr
        B       SLVK_TestV


; ..... and the default handler .....

AdjustOurSet
Kevin Bracey's avatar
Kevin Bracey committed
1077
        WritePSRc SVC_mode+I_bit, R14
Neil Turton's avatar
Neil Turton committed
1078 1079 1080
        CMP     R0, #MaxEnvNumber
        BHI     AOS_Silly

1081
  [ {FALSE}
Neil Turton's avatar
Neil Turton committed
1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110
        CMP     r0, #CallBackHandler
        BLEQ    testcallbackpending
  ]

        ADR     R10, AOS_Table
        ADD     R11, R0, R0, LSL #1   ; number * 3
        ADD     R10, R10, R11, LSL #2 ; point at entry

        MOV     R12, R1
        LDR     R11, [R10]
        CMP     R11, #0
        LDRNE   R1,  [R11]
        CMPNE   R12, #0
        STRNE   R12, [R11]

        MOV     R12, R2
        LDR     R11, [R10, #4]
        CMP     R11, #0
        LDRNE   R2,  [R11]
        CMPNE   R12, #0
        STRNE   R12, [R11]

        MOV     R12, R3
        LDR     R11, [R10, #8]
        CMP     R11, #0
        LDRNE   R3,  [R11]
        CMPNE   R12, #0
        STRNE   R12, [R11]

Kevin Bracey's avatar
Kevin Bracey committed
1111 1112 1113
 [ No26bitCode
        Pull    pc
 |
Neil Turton's avatar
Neil Turton committed
1114
        Pull    pc,,^
Kevin Bracey's avatar
Kevin Bracey committed
1115
 ]
Neil Turton's avatar
Neil Turton committed
1116 1117 1118 1119 1120 1121 1122

AOS_Silly
        ADR     r0, ErrorBlock_BadEnvNumber
      [ International
        BL      TranslateError
      ]
exit_AOS
Kevin Bracey's avatar
Kevin Bracey committed
1123 1124 1125 1126
 [ No26bitCode
        SETV
        Pull    "pc"
 |
Neil Turton's avatar
Neil Turton committed
1127 1128
        Pull    "lr"
        ORRS    pc, lr, #V_bit
Kevin Bracey's avatar
Kevin Bracey committed
1129
 ]
Neil Turton's avatar
Neil Turton committed
1130 1131 1132
        MakeErrorBlock BadEnvNumber

AOS_Table
Jeffrey Lee's avatar
Jeffrey Lee committed
1133
        &  ZeroPage+MemLimit     ;  MemoryLimit
Neil Turton's avatar
Neil Turton committed
1134 1135 1136
        &  0
        &  0

Jeffrey Lee's avatar
Jeffrey Lee committed
1137
        &  ZeroPage+UndHan       ; UndefinedHandler
Neil Turton's avatar
Neil Turton committed
1138 1139 1140
        &  0
        &  0

Jeffrey Lee's avatar
Jeffrey Lee committed
1141
        &  ZeroPage+PAbHan       ; PrefetchAbortHandler
Neil Turton's avatar
Neil Turton committed
1142 1143 1144
        &  0
        &  0

Jeffrey Lee's avatar
Jeffrey Lee committed
1145
        &  ZeroPage+DAbHan       ; DatabortHandler
Neil Turton's avatar
Neil Turton committed
1146 1147 1148
        &  0
        &  0

Jeffrey Lee's avatar
Jeffrey Lee committed
1149
        &  ZeroPage+AdXHan       ; AddressExceptionHandler
Neil Turton's avatar
Neil Turton committed
1150 1151 1152 1153 1154 1155 1156
        &  0
        &  0

        &  0            ; OtherExceptionHandler
        &  0
        &  0

Jeffrey Lee's avatar
Jeffrey Lee committed
1157 1158 1159
        &  ZeroPage+ErrHan       ; ErrorHandler
        &  ZeroPage+ErrHan_ws
        &  ZeroPage+ErrBuf
Neil Turton's avatar
Neil Turton committed
1160

Jeffrey Lee's avatar
Jeffrey Lee committed
1161 1162 1163
        &  ZeroPage+CallAd       ; CallBackHandler
        &  ZeroPage+CallAd_ws
        &  ZeroPage+CallBf
Neil Turton's avatar
Neil Turton committed
1164

Jeffrey Lee's avatar
Jeffrey Lee committed
1165 1166 1167
        &  ZeroPage+BrkAd        ; BreakPointHandler
        &  ZeroPage+BrkAd_ws
        &  ZeroPage+BrkBf
Neil Turton's avatar
Neil Turton committed
1168

Jeffrey Lee's avatar
Jeffrey Lee committed
1169 1170
        &  ZeroPage+EscHan       ; EscapeHandler
        &  ZeroPage+EscHan_ws
Neil Turton's avatar
Neil Turton committed
1171 1172
        &  0

Jeffrey Lee's avatar
Jeffrey Lee committed
1173 1174
        &  ZeroPage+EvtHan       ; EventHandler
        &  ZeroPage+EvtHan_ws
Neil Turton's avatar
Neil Turton committed
1175 1176
        &  0

Jeffrey Lee's avatar
Jeffrey Lee committed
1177 1178
        &  ZeroPage+SExitA       ; ExitHandler
        &  ZeroPage+SExitA_ws
Neil Turton's avatar
Neil Turton committed
1179 1180
        &  0

Jeffrey Lee's avatar
Jeffrey Lee committed
1181 1182
        &  ZeroPage+HiServ       ; UnusedSWIHandler
        &  ZeroPage+HiServ_ws
Neil Turton's avatar
Neil Turton committed
1183 1184
        &  0

Jeffrey Lee's avatar
Jeffrey Lee committed
1185
        &  ZeroPage+ExceptionDump ; ExceptionDumpArea
Neil Turton's avatar
Neil Turton committed
1186 1187 1188
        &  0
        &  0

Jeffrey Lee's avatar
Jeffrey Lee committed
1189
        &  ZeroPage+AplWorkSize  ; application space size
Neil Turton's avatar
Neil Turton committed
1190 1191 1192
        &  0
        &  0

Jeffrey Lee's avatar
Jeffrey Lee committed
1193
        &  ZeroPage+Curr_Active_Object
Neil Turton's avatar
Neil Turton committed
1194 1195 1196
        &  0
        &  0

Jeffrey Lee's avatar
Jeffrey Lee committed
1197 1198
        &  ZeroPage+UpCallHan
        &  ZeroPage+UpCallHan_ws
Neil Turton's avatar
Neil Turton committed
1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247
        &  0

        assert (.-AOS_Table)/12 = MaxEnvNumber

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; SWI OS_ReadDefaultHandler

; In    r0 = environment number

ReadDefaultHandler ROUT

        CMP     r0, #(dhte-defhantab)/12
        MOVHS   r0, #0                  ; return wally value
        ADD     r10, r0, r0, LSL #1     ; *3
        ADD     r10, pc, r10, LSL #2    ; *4 (pc = defhantab-4)
        LDMIB   r10, {r1-r3}            ; gives additional +4
        ExitSWIHandler

defhantab
     & 0                ; wally entry
     & 0
     & 0

     & UNDEF            ; UndefinedHandler
     & 0
     & 0

     & ABORTP           ; PrefetchAbortHandler
     & 0
     & 0

     & ABORTD           ; DataAbortHandler
     & 0
     & 0

     & ADDREX           ; AddressExceptionHandler
     & 0
     & 0

     & 0                ; OtherExceptionHandler
     & 0
     & 0

     & ERRORH           ; ErrorHandler
     & 0
     & GeneralMOSBuffer

     & NOCALL           ; CallBackHandler
     & 0
1248
     & ZeroPage+DUMPER
Neil Turton's avatar
Neil Turton committed
1249 1250 1251

     & DEFBRK           ; BreakPointHandler
     & 0
1252
     & ZeroPage+DUMPER
Neil Turton's avatar
Neil Turton committed
1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293

     & ESCAPH           ; EscapeHandler
     & 0
     & GeneralMOSBuffer

     & EVENTH           ; EventHandler
     & 0
     & 0

     & CLIEXIT          ; ExitHandler
     & 0
     & 0

     & NoHighSWIHandler ; UnusedSWIHandler
     & 0
     & 0

     & 0                ; exception dump
     & 0
     & 0

     & 0                ; app space size
     & 0
     & 0

     & 0                ; cao pointer
     & 0
     & 0

     & DefUpcallHandler ; upcall handler
     & 0
     & 0

dhte

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; In    r0 = sysinfo handle

; Out   r0 = sysinfo for r0in

ReadSysInfo_Code ROUT
1294
        CMP     r0,#14 ;R0 > 13, so illegal value
Kevin Bracey's avatar
Kevin Bracey committed
1295 1296
        ADDLO   PC, PC, R0,LSL #2
        B       ReadSysInfo_InvalidReason
Neil Turton's avatar
Neil Turton committed
1297

Kevin Bracey's avatar
Kevin Bracey committed
1298 1299 1300 1301 1302 1303 1304 1305 1306 1307
        B       %FT00
        B       %FT10
        B       %FT20
        B       %FT30
        B       %FT40
        B       %FT50
        B       %FT60
        B       %FT70
        B       %FT80
        B       %FT90
1308 1309 1310
        B       ReadSysInfo_InvalidReason ; ROL's "read OS version" call
        B       %FT110
        B       %FT120
1311
        B       %FT130
Kevin Bracey's avatar
Kevin Bracey committed
1312 1313

ReadSysInfo_InvalidReason
Neil Turton's avatar
Neil Turton committed
1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332
        ADR     r0, ErrorBlock_BadReadSysInfo
      [ International
        Push    "lr"
        BL      TranslateError
        Pull    "lr"
      ]
        ORR     lr, lr, #V_bit
        ExitSWIHandler

        MakeErrorBlock BadReadSysInfo

; ReadSysInfo(0) - return configured screensize in r0

00
        Push    "r1, r2, lr"
        MOV     r0, #ReadCMOS
        MOV     r1, #ScreenSizeCMOS
        SWI     XOS_Byte
        AND     r0, r2, #&7F            ; top bit is reserved
Jeffrey Lee's avatar
Jeffrey Lee committed
1333
        LDR     r10, =ZeroPage
Neil Turton's avatar
Neil Turton committed
1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349
        LDR     r10, [r10, #Page_Size]
        MUL     r0, r10, r0
        BL      MassageScreenSize       ; adjust for min and max or default values
        Pull    "r1, r2, lr"
        ExitSWIHandler

; ReadSysInfo(1) - returns configured mode/wimpmode in r0
;                          configured monitortype in r1
;                          configured sync in r2
;                          (all de-autofied)

10
        Push    "r3-r5, lr"
        BL      Read_Configd_Sync
        MOV     r2, r0
 [ ModeSelectors
Jeffrey Lee's avatar
Jeffrey Lee committed
1350
        LDR     r1, =ZeroPage+VduDriverWorkSpace+CurrentMonitorType      ; read current monitortype
Neil Turton's avatar
Neil Turton committed
1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404
        LDR     r1, [r1]
 |
        BL      Read_Configd_MonitorType
        MOV     r1, r0
 ]
        BL      Read_Configd_Mode
        CMP     r0, #-1                         ; if none of the three are auto, don't bother with translation
        CMPNE   r1, #-1
        CMPNE   r2, #-1
        BNE     %FT15
        BL      TranslateMonitorLeadType        ; issue service or work it out ourselves
        CMP     r0, #-1                         ; if mode auto
        MOVEQ   r0, r3                          ; then replace with default
        CMP     r1, #-1                         ; if monitortype auto
        MOVEQ   r1, r4                          ; then replace with default
        CMP     r2, #-1                         ; if sync auto
        MOVEQ   r2, r5                          ; then replace with default
15
        Pull    "r3-r5, lr"
        ExitSWIHandler

; ReadSysInfo(2)
;
; in:   r0 = 2
;
; out:  r0 = hardware configuration word 0
;               bits 0-7 = special functions chip type
;                               0 => none
;                               1 => IOEB
;               bits 8-15 = I/O control chip type
;                               0 => IOC
;                               1 => IOMD
;               bits 16-23 = memory control chip type
;                               0 => MEMC1/MEMC1a
;                               1 => IOMD
;               bits 24-31 = video control chip type
;                               0 => VIDC1a
;                               1 => VIDC20
;       r1 = hardware configuration word 1
;               bits 0-7 = I/O chip type
;                               0 => absent
;                               1 => 82C710/711 or SMC'665 or similar
;               bits 8-31 reserved (set to 0)
;       r2 = hardware configuration word 2
;               bits 0-7 = LCD controller type
;                               0 => absent
;                               1 => present (type 1) eg A4 portable
;                               2 => present (type 2) eg Stork portable
;               bits 8-15 = IOMD variant
;                               0 => IOMD
;                               1 => IOMDL ie ARM7500 (Morris)
;               bits 16-23 = VIDC20 variant
;                               0 => VIDC20
;                               1 => VIDC2L ie ARM7500 (Morris)
1405 1406 1407 1408 1409 1410
;               bits 24-31 = miscellaneous flags
;                      bit 24   0 => IIC bus slow (100kHz)
;                               1 => IIC bus fast (400kHz)
;                      bit 25   0 => keep I/O clocks running during idle
;                               1 => stop I/O clocks during idle
;                      bits 26-31 reserved (set to 0)
Neil Turton's avatar
Neil Turton committed
1411 1412 1413 1414 1415
;       r3 = word 0 of unique machine ID, or 0 if unavailable
;       r4 = word 1 of unique machine ID, or 0 if unavailable

; Bits in IOSystemType

1416 1417 1418 1419 1420 1421 1422 1423
IOST_COMBOMASK  * 7
IOST_82C710     * 1
IOST_82C711     * 2
IOST_37C665     * 3
IOST_37C669     * 4
IOST_UMC669     * 5
IOST_IOEB       * 8     ; On IOMD systems this really means IOMD.
IOST_LC         * 16
Neil Turton's avatar
Neil Turton committed
1424 1425 1426 1427
 [ MorrisSupport
IOST_7500       * 32    ;Running on ARM7500 (Morris) so actually IOMDL and VIDC2L
IOST_BATMAN     * 64    ;Stork keyboard/battery controller seems to be present
 ]
Kevin Bracey's avatar
Kevin Bracey committed
1428 1429 1430 1431 1432 1433 1434 1435 1436 1437

 [ HAL
20
        Push    "r9,r14"
        AddressHAL
        SUB     sp, sp, #12
        ADD     a1, sp, #0
        ADD     a2, sp, #4
        ADD     a3, sp, #8
        CallHAL HAL_HardwareInfo
Jeffrey Lee's avatar
Jeffrey Lee committed
1438
        LDR     r12, =ZeroPage
Kevin Bracey's avatar
Kevin Bracey committed
1439 1440
        LDR     r3, [r12, #RawMachineID+0]
        LDR     r4, [r12, #RawMachineID+4]
Kevin Bracey's avatar
Kevin Bracey committed
1441 1442 1443 1444
        MOV     r3, r3, LSR #8                  ; lose first 8 bits
        ORR     r3, r3, r4, LSL #24             ; and put bits 0..7 of r3 into bits 24..31 of r2
        MOV     r4, r4, LSL #8                  ; lose CRC bits
        MOV     r4, r4, LSR #16                 ; and move the rest down to the bottom
Kevin Bracey's avatar
Kevin Bracey committed
1445 1446 1447
        Pull    "r0-r2,r9,r14"
        ExitSWIHandler
 |
Neil Turton's avatar
Neil Turton committed
1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465
20
        MOV     r0, #0
        LDR     r3, [r0, #RawMachineID+0]
        LDR     r4, [r0, #RawMachineID+4]
        MOV     r3, r3, LSR #8                  ; lose first 8 bits
        ORR     r3, r3, r4, LSL #24             ; and put bits 0..7 of r3 into bits 24..31 of r2
        MOV     r4, r4, LSL #8                  ; lose CRC bits
        MOV     r4, r4, LSR #16                 ; and move the rest down to the bottom
        LDRB    r0, [r0, #IOSystemType]

        ANDS    r2, r0, #IOST_LC
        MOVNE   r2, #1                          ; make r2 0 or 1
 [ MorrisSupport
        TST     r0, #IOST_BATMAN
        MOVNE   r2, #2                          ;NE, its a Stork portable
        TST     r0, #IOST_7500
        ORRNE   r2, r2, #&00000100              ;NE, Morris based machine with IOMDL
        ORRNE   r2, r2, #&00010000              ;NE, and VIDC2L
1466 1467 1468
 ]
        MOV     r1, #0
        LDRB    r1, [r1, #NVRamSpeed]
Dan Ellis's avatar
Dan Ellis committed
1469

1470 1471 1472 1473 1474
        SUB     r1, r1, #1                      ; catch zero = slow (just in case)
        CMP     r1, #3-1                        ; speed is 3 for 400kHz, 10 for 100kHz.
        ORRLS   r2, r2, #&01000000              ; indicate fast speed
 [ StopClocksDuringIdle
        ORR     r2, r2, #&02000000
Neil Turton's avatar
Neil Turton committed
1475
 ]
1476
        ANDS    r1, r0, #IOST_COMBOMASK
Neil Turton's avatar
Neil Turton committed
1477 1478 1479 1480
        MOVNE   r1, #1                          ; make r1 0 or 1

        LDR     r0, =&01010100
        ExitSWIHandler
Kevin Bracey's avatar
Kevin Bracey committed
1481
 ]
Neil Turton's avatar
Neil Turton committed
1482 1483 1484 1485 1486

; ReadSysInfo(3)
;
; in:   r0 = 3
;
1487 1488 1489 1490 1491 1492 1493 1494
; out:  r0 = I/O chip base features mask                710     711     665     669     UMC669
;               Bits 0..3   Base IDE type               1       1       1       1       1
;               Bits 4..7   Base FDC type               1       1       1       1       1
;               Bits 8..11  Base parallel type          1       1       1       1       1
;               Bits 12..15 Base 1st serial type        1       1       1       1       1
;               Bits 16..19 Base 2nd serial type        0       1       1       1       1
;               Bits 20..23 Base Config type            1       2       3       4       5
;               Bits 24..31 Reserved                    0       0       0       0       0
Neil Turton's avatar
Neil Turton committed
1495
;
1496 1497 1498 1499 1500 1501 1502 1503
;       r1 = I/O chip extra features mask               710     711     665     669     UMC669
;               Bits 0..3   IDE extra features          0       0       0       0       0
;               Bits 4..7   FDC extra features          0       0       0       0       0
;               Bits 8..11  parallel extra features     0       0       1       1       1
;               Bits 12..15 1st serial extra features   0       0       1       1       1
;               Bits 16..19 2nd serial extra features   0       0       1       1       1
;               Bits 20..23 config extra features       0       0       0       0       0
;               Bits 24..31 Reserved                    0       0       0       0       0
Neil Turton's avatar
Neil Turton committed
1504 1505 1506 1507 1508
;
;       r2-r4 undefined (reserved for future expansion)
;

30
Kevin Bracey's avatar
Kevin Bracey committed
1509 1510 1511 1512 1513 1514 1515 1516 1517 1518
 [ HAL
        Push    "r9,r14"
        AddressHAL
        SUB     sp, sp, #8
        ADD     a1, sp, #0
        ADD     a2, sp, #4
        CallHAL HAL_SuperIOInfo
        Pull    "a1,a2,r9,r14"
        ExitSWIHandler
 |
Neil Turton's avatar
Neil Turton committed
1519 1520
        MOV     r0, #0                          ; used as index and as default value
        LDRB    r1, [r0, #IOSystemType]
1521 1522 1523 1524 1525 1526 1527 1528
        ANDS    r1, r1, #IOST_COMBOMASK
        TEQ     r1, #IOST_82C710
        LDREQ   r0, =&00101111
        MOVEQ   r1, #0
        TEQ     r1, #IOST_82C711
        LDREQ   r0, =&00211111
        MOVEQ   r1, #0
        CMP     r1, #IOST_37C665
1529 1530 1531 1532 1533
 [ ReassignedIOMDInterrupts
; If the device numbers have been reassigned, we can't really call the devices compatible.
; Also, we've lost the floppy and hard disc interrupts, so mark as not present.
        LDRHS   r0, =&00022200
 |
1534
        LDRHS   r0, =&00011111
1535
 ]
1536 1537
        ORRHS   r0, r0, r1, LSL #20
        LDRHS   r1, =&00011100
Neil Turton's avatar
Neil Turton committed
1538 1539 1540 1541
        MOV     r2, #0
        MOV     r3, #0
        MOV     r4, #0
        ExitSWIHandler
Kevin Bracey's avatar
Kevin Bracey committed
1542
 ]
Neil Turton's avatar
Neil Turton committed
1543

Kevin Bracey's avatar
Kevin Bracey committed
1544
; ReadSysInfo(4)
Neil Turton's avatar
Neil Turton committed
1545 1546 1547
;
; On entry:       r0 = 4 (reason code)
;
Kevin Bracey's avatar
Kevin Bracey committed
1548 1549
; On exit:        r0 = LS32bits of Ethernet Network Address (or 0)
;                 r1 = MS16bits of Ethernet Network Address (or 0)
Neil Turton's avatar
Neil Turton committed
1550 1551 1552 1553 1554 1555
;
; Use:            Code loaded from the dedicated Network Expansion Card or
;                 from a normal Expansion Card should use the value returned
;                 by this call in preference to a locally provided value.

40
Jeffrey Lee's avatar
Jeffrey Lee committed
1556
        LDR     r0, =ZeroPage
Neil Turton's avatar
Neil Turton committed
1557
        LDRB    r1, [ r0, #RawMachineID ]               ; The family byte
Kevin Bracey's avatar
Kevin Bracey committed
1558
        TEQ     r1, #&81                                ; Excellent,a custom part - we'll use it
Neil Turton's avatar
Neil Turton committed
1559 1560 1561 1562
        BNE     ExitNoEthernetAddress
        LDR     r1, [ r0, #RawMachineID+4 ]             ; Acorn's ID and part#
        BIC     r1, r1, #&FF000000                      ; Remove the CRC
        LDR     r0, =&0050A4                            ; Acorn's ID is &005
Kevin Bracey's avatar
Kevin Bracey committed
1563
        TEQ     r1, r0                                  ; Is this an Acorn part?
Jeffrey Lee's avatar
Jeffrey Lee committed
1564
        LDR     r0, =ZeroPage
Kevin Bracey's avatar
Kevin Bracey committed
1565
        BNE     %FT45
Neil Turton's avatar
Neil Turton committed
1566 1567
        LDR     r0, [ r0, #RawMachineID ]
        MOV     r0, r0, LSR #8                          ; Lose family byte
Kevin Bracey's avatar
Kevin Bracey committed
1568 1569
        LDR     r1, =&0000A4100000
        ADD     r0, r1, r0                              ; Add Acorn base Ethernet address to number from Dallas
Neil Turton's avatar
Neil Turton committed
1570 1571 1572 1573 1574 1575 1576
        [ STB
        TST     r0, #1:SHL:23                           ; Check not overflowed into secondary range
        BNE     ExitNoEthernetAddress
        MOV     r1, r0, LSR #24                         ; Check not overflowed out of Acorn's range
        TEQ     r1, #&A4
        BNE     ExitNoEthernetAddress
        ]
Kevin Bracey's avatar
Kevin Bracey committed
1577 1578 1579 1580 1581 1582 1583 1584 1585 1586
        MOV     r1, #0                                  ; Top 16 bits are zero in Acorn's MAC address allocation
        ExitSWIHandler
45
        MOV     r1, r1, LSR #8                          ; It's unique,but not an Acorn part - extract MAC address verbatim
        Push    "r2"
        LDR     r2, [ r0, #RawMachineID ]
        MOV     r2, r2, LSR #8
        LDRB    r0, [r0, #RawMachineID+4]
        ORR     r0, r2, r0, LSL#24
        Pull    "r2"
Neil Turton's avatar
Neil Turton committed
1587 1588 1589
        ExitSWIHandler

ExitNoEthernetAddress
1590
        [ :LNOT: STB
Neil Turton's avatar
Neil Turton committed
1591 1592 1593
        MOV     r0, #0
        MOV     r1, #0
        ExitSWIHandler
Neil Turton's avatar
Neil Turton committed
1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604
        |
        Push    "r2,lr"
        MOV     r1, #Service_MachineAddress             ; See if anyone else can provide it
        BL      Issue_Service
        TEQ     r1, #0
        MOVEQ   r1, r2
        BLNE    GetMachineAddressCMOS
        Pull    "r2,lr"
        ExitSWIHandler
        ]

Robert Catherall's avatar
Robert Catherall committed
1605 1606 1607
 [ STB

NVRAM_TAG_MACAddress
Kevin Bracey's avatar
Kevin Bracey committed
1608
        = "MACAddress", 0
Robert Catherall's avatar
Robert Catherall committed
1609
NVRAM_TAG_MACAddressChecksum
Kevin Bracey's avatar
Kevin Bracey committed
1610
        = "MACAddressChecksum", 0
Robert Catherall's avatar
Robert Catherall committed
1611 1612 1613 1614 1615 1616 1617
NVRAM_TAG_MACAddress2nd
        = "MACAddress2nd", 0
NVRAM_TAG_MACAddressChecksum2nd
        = "MACAddressChecksum2nd", 0

        ALIGN

Neil Turton's avatar
Neil Turton committed
1618 1619 1620 1621 1622
GetMachineAddressCMOS
; Out:  r0 = lower 4 bytes (or 0)
;       r1 = upper 2 bytes (or 0)
;       EQ => valid, NE => invalid
;
Robert Catherall's avatar
Robert Catherall committed
1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739
        Entry   "r2-r5", 8                              ; Preserve these + get 8 bytes workspace

        ADR     r0,NVRAM_TAG_MACAddress
        ADR     r3,NVRAM_TAG_MACAddressChecksum
        BL      CheckOneCopyOfMachineAddressCMOS        ; Get 1st copy of MAC in r0=low 4 bytes,
                                                        ; r1=upper 2 bytes of MAC in bytes 0,1  stored checksum in byte 2,  calculated checksum in byte 3
 [ MACNVRAM2copies
        MOV     r4,r0
        MOV     r5,r1

        ADR     r0,NVRAM_TAG_MACAddress2nd
        ADR     r3,NVRAM_TAG_MACAddressChecksum2nd
        BL      CheckOneCopyOfMachineAddressCMOS        ; Get 2nd copy of MAC

        CMP     r0,r4
        CMPEQ   r1,r5
        BNE     %FT41                                   ; Have different values - i.e one (possibly both) is wrong/broken
 ] ;two copies of MAC

        MOV     r2,r1,LSR#16                            ; move checksum values into low bytes
        AND     r3,r2,#&ff                              ; r3=stored checksum
        MOV     r2,r2,LSR#8                             ; r2=calculated checksum
        CMP     r2,r3                                   ; do the checksums match
        BNE     %FT43                                   ; if not then we have unrecoverable fault, both values identical but checksums broken
                                                        ; this would be the case for an unprogrammed CMOS
        MOV     r2,#&ff
        ORR     r2,r2,r2,LSL#8                          ; mask for removing checksums
        AND     r1,r1,r2                                ; #&0000ffff remove checksums from r1
        EXIT                                            ; return with valid MAC in r0,r1 and flags set to EQ by branch just above

 [ MACNVRAM2copies
;two copies differ
41
        MOV     r2,r5,LSR#16                            ; move checksum for 1st copy into low bytes
        AND     r3,r2,#&ff                              ; r3=stored checksum
        MOV     r2,r2,LSR#8                             ; r2=calculated checksum
        CMP     r2,r3                                   ; do the checksums match
        BEQ     %FT45                                   ; okay need to repair second set

        MOV     r2,r1,LSR#16                            ; move checksum for 2nd copy into low bytes
        AND     r3,r2,#&ff                              ; r3=stored checksum
        MOV     r2,r2,LSR#8                             ; r2=calculated checksum
        CMP     r2,r3                                   ; do the checksums match
        BEQ     %FT46                                   ; okay need to repair first set
 ]
;we arrive here if we have a situation from which no sensible MAC can be derived
;i) both values are broken
43
        MOV     r0,#0
        MOV     r1,#0
        EXIT                                            ;return with r0,r1 both zero to indicate no valid address, two possible paths here both have NE flags
 [ MACNVRAM2copies
;checksum is valid for first set so repair second set
45
        ADR     r3,NVRAM_TAG_MACAddress2nd
        ADR     r0,NVRAM_TAG_MACAddressChecksum2nd
        B       %FT47

;checksum is valid for second set so repair first set
46
        MOV     r4,r0                                   ;get values of 2nd set into write registers
        MOV     r5,r1
        ADR     r3,NVRAM_TAG_MACAddress
        ADR     r0,NVRAM_TAG_MACAddressChecksum

;store MAC (+ check sum) in r4,r5, and checksum in r2 to NVRAM tags given by r0 and r3
47
 [ 1=2
        ; forgot that NVRAM_Write will fail
        ; on locked locations such as .. the MAC addresses...
        ; this will be modified shortly to call a new SWI provided
        ; by the NVRAM module to turn a tag into an address and
        ; then perform the write using routines in the i2cutils
        ; section of the kernel.

        MOV     r1, sp                                  ;some workspace
        STRB    r2, [r1,#0]                             ;store the checksum
        MOV     r2, #1
        SWI     XNVRAM_Write
        ;TST     r0, #&80000000                          ; Check for errors
        ;BNE     %FT48                                   ; Oh dear

        BIC     r5,r5,#&ffff0000                        ;get rid of checksum - we already have a value in r2 extracted earlier
        MOV     r0,r3                                   ;NVRAM_TAG_MACAddress
        MOV     r1,sp                                   ;workspace

        MOV     r3,r5
        STRB    r3,[r1,#1]
        MOV     r3,r3,LSR#8
        STRB    r3,[r1,#0]
        MOV     r3,r4
        STRB    r3,[r1,#5]
        MOV     r3,r3,LSR#8
        STRB    r3,[r1,#4]
        MOV     r3,r3,LSR#8
        STRB    r3,[r1,#3]
        MOV     r3,r3,LSR#8
        STRB    r3,[r1,#2]

        MOV     r2,#6
        SWI     XNVRAM_Write
        ;TST     r0, #&80000000                          ; Check for errors
        ;BNE     %FT48                                   ; Oh dear
 ]
;return with the values from r4,r5 in r0,r1 and flags eq
;48
        MOV     r0,r4
        MOV     r1,r5
        CMP     r1,r1                                   ;make flags equal - is this required?
        EXIT

 ] ; MACNVRAM2copies

;On entry r0 points to MAC address Tag name
;         r3 points to Checksum Tag name
CheckOneCopyOfMachineAddressCMOS
        Entry   ,8
1740

Kevin Bracey's avatar
Kevin Bracey committed
1741 1742 1743 1744 1745
        MOV     r1, sp
        MOV     r2, #6
        SWI     XNVRAM_Read
        MOVVS   r0, #&ffffffff
        TST     r0, #&80000000                          ; Check for errors
Robert Catherall's avatar
Robert Catherall committed
1746
        BNE     MachineAddressNVRAMError
1747

Robert Catherall's avatar
Robert Catherall committed
1748
        MOV     r0, r3
Kevin Bracey's avatar
Kevin Bracey committed
1749 1750
        ADD     r1, sp, #6
        MOV     r2, #1
Robert Catherall's avatar
Robert Catherall committed
1751
        SWI     XNVRAM_Read
Kevin Bracey's avatar
Kevin Bracey committed
1752 1753
        MOVVS   r0, #&ffffffff
        TST     r0, #&80000000                          ; Check for errors
Robert Catherall's avatar
Robert Catherall committed
1754 1755
        BNE     MachineAddressNVRAMError

Kevin Bracey's avatar
Kevin Bracey committed
1756 1757
        MOV     r0, #0
        MOV     r1, #0
Neil Turton's avatar
Neil Turton committed
1758

Kevin Bracey's avatar
Kevin Bracey committed
1759 1760
        LDRB    r3, [sp, #0]                            ; Get the first byte into checksum
        MOV     r1, r3, ASL #8                          ; Store into result
1761

Kevin Bracey's avatar
Kevin Bracey committed
1762 1763 1764
        LDRB    r2, [sp, #1]                            ; Get the next byte
        ADD     r3, r3, r2                              ; Add to the checksum
        ORR     r1, r1, r2, ASL #0                      ; Store into the result
1765

Kevin Bracey's avatar
Kevin Bracey committed
1766 1767 1768
        LDRB    r2, [sp, #2]                            ; Get the next byte
        ADD     r3, r3, r2                              ; Add to the checksum
        MOV     r0, r2, ASL #24                         ; Store into the result
Neil Turton's avatar
Neil Turton committed
1769

Kevin Bracey's avatar
Kevin Bracey committed
1770 1771 1772
        LDRB    r2, [sp, #3]                            ; Get the next byte
        ADD     r3, r3, r2                              ; Add to the checksum
        ORR     r0, r0, r2, ASL #16                     ; Store into the result
1773

Kevin Bracey's avatar
Kevin Bracey committed
1774 1775 1776
        LDRB    r2, [sp, #4]                            ; Get the next byte
        ADD     r3, r3, r2                              ; Add to the checksum
        ORR     r0, r0, r2, ASL #8                      ; Store into the result
1777

Kevin Bracey's avatar
Kevin Bracey committed
1778 1779 1780
        LDRB    r2, [sp, #5]                            ; Get the next byte
        ADD     r3, r3, r2                              ; Add to the checksum
        ORR     r0, r0, r2, ASL #0                      ; Store into the result
1781

Kevin Bracey's avatar
Kevin Bracey committed
1782 1783 1784
        LDRB    r2, [sp, #6]                            ; Get the checksum
        AND     r3, r3, #&FF
        EOR     r3, r3, #&FF
Robert Catherall's avatar
Robert Catherall committed
1785 1786 1787 1788
        ORR     r1,r1,r2,LSL#16                            ;put stored checksum in byte 2
        ORR     r1,r1,r3,LSL#24                            ;put calculated checksum in byte 3
49
        EXIT
1789

Robert Catherall's avatar
Robert Catherall committed
1790 1791 1792 1793
MachineAddressNVRAMError
        MOV     r0,#0
        MOV     r1,#0
        EXIT
1794

Robert Catherall's avatar
Robert Catherall committed
1795
 ]
Neil Turton's avatar
Neil Turton committed
1796

Kevin Bracey's avatar
Kevin Bracey committed
1797
; ReadSysInfo(5)
Neil Turton's avatar
Neil Turton committed
1798 1799 1800
;
; On entry:       r0 = 5 (reason code)
;
Kevin Bracey's avatar
Kevin Bracey committed
1801 1802
; On exit:        r0 = LSW of Raw data from unique id chip
;                 r1 = MSW of Raw data from unique id chip
Neil Turton's avatar
Neil Turton committed
1803 1804

50
Jeffrey Lee's avatar
Jeffrey Lee committed
1805
        LDR     r0, =ZeroPage
Neil Turton's avatar
Neil Turton committed
1806 1807 1808 1809
        LDR     r1, [r0, #RawMachineID+4]
        LDR     r0, [r0, #RawMachineID+0]
        ExitSWIHandler

Kevin Bracey's avatar
Kevin Bracey committed
1810
; ReadSysInfo(6) - read kernel values (Acorn use only; eg. SoftLoad, ROMPatch)
1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829
;
; On entry:       r0 =  6 (reason code)
;                 r1 -> input block, 1 word per entry, giving number of value required, terminated by -1
;           OR:   r1 =  0 if just 1 value is required, and this is to beturned in r2
;                 r2 -> output block, 1 word per entry, will be filled in on output
;           OR:   r2 =  number of single value required, if r1 = 0
;
; On exit:
;   if r1 entry != 0:
;         r0,r1,r2 preserved
;         output block filled in, filled in value(s) set to 0 if unrecognised/no longer meaningful value(s)
;   if r1 entry = 0:
;         r0,r1 preserved
;         r2 = single value required, or set to 0 if if unrecognised/no longer meaningful value
;
;  valid value numbers available - see table below
;

60
1830
        Push    "r0-r4"
1831 1832 1833 1834
        ADR     r3,osri6_table
        CMP     r1,#0
        BEQ     %FT64
62
1835 1836
        LDR     r4,[r1],#4
        CMP     r4,#-1
1837
        BEQ     %FT66
1838 1839
        CMP     r4,#osri6_maxvalue
        LDRLS   r0,[r3,r4,LSL #2]
1840
        MOVHI   r0,#0
1841 1842 1843 1844 1845 1846 1847 1848 1849
        ; Fix up the DevicesEnd values
        TEQ     r4,#OSRSI6_Danger_DevicesEnd
        TEQNE   r4,#OSRSI6_DevicesEnd
        STRNE   r0,[r2],#4
        BNE     %BT62
        LDR     r4,=ZeroPage
        LDR     r4,[r4,#IRQMax]
        ADD     r0,r0,r4,LSL #3
        ADD     r0,r0,r4,LSL #2
1850 1851 1852 1853
        STR     r0,[r2],#4
        B       %BT62
64
        CMP     r2,#osri6_maxvalue
1854 1855 1856 1857 1858 1859 1860 1861 1862 1863
        LDRLS   r0,[r3,r2,LSL #2]
        MOVHI   r0,#0
        ; Fix up the DevicesEnd values
        TEQ     r2,#OSRSI6_Danger_DevicesEnd
        TEQNE   r2,#OSRSI6_DevicesEnd
        LDREQ   r1,=ZeroPage
        LDREQ   r1,[r1,#IRQMax]
        ADDEQ   r0,r0,r1,LSL #3
        ADDEQ   r0,r0,r1,LSL #2
        STR     r0,[sp,#2*4]
1864
66
1865
        Pull    "r0-r4"
1866 1867 1868
        ExitSWIHandler

osri6_table
1869 1870
    DCD  ZeroPage+CamEntriesPointer                   ;0
    DCD  ZeroPage+MaxCamEntry                         ;1
1871
    DCD  PageFlags_Unavailable                        ;2
1872
    DCD  ZeroPage+PhysRamTable                        ;3
1873
    DCD  0                                            ;4 (was ARMA_Cleaner_flipflop)
1874 1875 1876 1877 1878 1879 1880 1881
    DCD  ZeroPage+TickNodeChain                       ;5
    DCD  ZeroPage+ROMModuleChain                      ;6
    DCD  ZeroPage+DAList                              ;7
    DCD  ZeroPage+AppSpaceDANode                      ;8
    DCD  ZeroPage+Module_List                         ;9
    DCD  ZeroPage+ModuleSHT_Entries                   ;10
    DCD  ZeroPage+ModuleSWI_HashTab                   ;11
    DCD  ZeroPage+IOSystemType                        ;12
1882 1883 1884 1885 1886
    DCD  L1PT                                         ;13
    DCD  L2PT                                         ;14
    DCD  UNDSTK                                       ;15
    DCD  SVCSTK                                       ;16
    DCD  SysHeapStart                                 ;17
1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898
    ; **DANGER** - this block conflicts with ROL's allocations
    ; ROL use:
    ; 18 = kernel messagetrans block
    ; 19 = error semaphore
    ; 20 = OS_PrettyPrint dictionary
    ; 21 = Timer 0 latch value
    ; 22 = FastTickerV counts per second
    ; 23 = Vector claimants table
    ; 24 = Number of vectors supported
    ; 25 = IRQSTK
    ; 26 = JTABLE-SWIRelocation
    ; 27 = Address of branch back to OS after SWIs
1899 1900
    DCD  JTABLE-SWIRelocation                         ;18 - relocated base of OS SWI despatch table
    DCD  DefaultIRQ1V+(Devices-DefaultIRQ1Vcode)      ;19 - relocated base of IRQ device head nodes
1901
    DCD  DefaultIRQ1V+(Devices-DefaultIRQ1Vcode)      ;20 - relocated end of IRQ device head nodes. NOTE: Gets fixed up when read
1902 1903
    DCD  IRQSTK                                       ;21 - top of the IRQ stack
    DCD  SoundWorkSpace                               ;22 - workspace (8K) and buffers (2*4K)
1904 1905
    DCD  ZeroPage+IRQsema                             ;23 - the address of the IRQ semaphore
    %    (256-(.-osri6_table))
1906 1907 1908
    ; Use 64+ for a repeat of the danger zone, and our new allocations
    DCD  JTABLE-SWIRelocation                         ;64 - relocated base of OS SWI despatch table
    DCD  DefaultIRQ1V+(Devices-DefaultIRQ1Vcode)      ;65 - relocated base of IRQ device head nodes
1909
    DCD  DefaultIRQ1V+(Devices-DefaultIRQ1Vcode)      ;66 - relocated end of IRQ device head nodes. NOTE: Gets fixed up when read
1910 1911 1912
    DCD  IRQSTK                                       ;67 - top of the IRQ stack
    DCD  SoundWorkSpace                               ;68 - workspace (8K) and buffers (2*4K)
    DCD  ZeroPage+IRQsema                             ;69 - the address of the IRQ semaphore
1913
    ; New allocations
1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925
    DCD  ZeroPage+DomainId                            ;70 - current Wimp task handle
    DCD  ZeroPage+OsbyteVars-&A6                      ;71 - OS_Byte vars (previously available via OS_Byte &A6/VarStart)
    DCD  ZeroPage+VduDriverWorkSpace+FgEcfOraEor      ;72
    DCD  ZeroPage+VduDriverWorkSpace+BgEcfOraEor      ;73
    DCD  DebuggerSpace                                ;74
    DCD  DebuggerSpace_Size                           ;75
    DCD  ZeroPage+CannotReset                         ;76
    DCD  ZeroPage+MetroGnome                          ;77 - OS_ReadMonotonicTime
    DCD  ZeroPage+CLibCounter                         ;78
    DCD  ZeroPage+RISCOSLibWord                       ;79
    DCD  ZeroPage+CLibWord                            ;80
    DCD  ZeroPage+FPEAnchor                           ;81
1926
    DCD  ZeroPage+ESC_Status                          ;82
1927
osri6_maxvalue * (.-4-osri6_table) :SHR: 2
1928 1929


Kevin Bracey's avatar
Kevin Bracey committed
1930 1931
; ReadSysInfo(7)  - read 32-bit Abort information for last unexpected abort
;                      (prefetch or data)
1932 1933 1934 1935 1936 1937 1938 1939 1940
;
; On entry:       r0 =  6 (reason code)
;
; On exit:        r1 = 32-bit PC for last abort
;                 r2 = 32-bit PSR for last abort
;                 r3 = fault address for last abort (same as PC for prefetch abort)
;
70
        Push    "r0"
Jeffrey Lee's avatar
Jeffrey Lee committed
1941
        LDR     r0, =ZeroPage+Abort32_dumparea
1942
        LDMIA   r0, {r2, r3}
1943 1944 1945 1946
        LDR     r1, [r0,#2*4]
        Pull    "r0"
        ExitSWIHandler

Kevin Bracey's avatar
Kevin Bracey committed
1947
; ReadSysInfo(8) - Returns summary information on host platform.
1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959
;
; On entry:
;    r0 = 8 (reason code 8)
;
; On exit:
;    r0 = platform class
;         currently defined classes are:
;            0 = unspecified platform (r1,r2 will be 0)
;            1 = Medusa   (currently returned for Risc PC only)
;            2 = Morris   (currently returned for A7000 only)
;            3 = Morris+  (currently returned for A7000+ only)
;            4 = Phoebe   (currently returned for Risc PC 2 only)
Kevin Bracey's avatar
Kevin Bracey committed
1960
;            5 = HAL      (returned for machines running a HAL)
1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973
;            all other values currently reserved
;    r1 = 32 additional platform specifier flags (if defined)
;         bits 0..31 = value of flags 0..31 if defined, 0 if undefined
;    r2 = defined status of the 32 flags in r1
;         bits 0..31 = status of flags 0..31
;                      0 = flag is undefined in this OS version
;                      1 = flag is defined in this OS version
;
; The current flag definitions for r1 (1=supported, 0=unsupported) are :
;
;     0     = Podule expansion card(s)
;     1     = PCI expansion card(s)
;     2     = additional processor(s)
1974
;     3     = software power off
1975 1976
;     4     = OS in RAM, else executing in ROM
;     5..31 reserved (currently undefined)
1977 1978
;
80
1979
 [ HAL
1980 1981 1982 1983 1984 1985 1986
        Push    "r9,r14"
        AddressHAL
        SUB     sp, sp, #8
        ADD     a2, sp, #0
        ADD     a3, sp, #4
        CallHAL HAL_PlatformInfo
        Pull    "a2,a3,r9,r14"
1987 1988 1989
        MOV     r0, #5
        ExitSWIHandler
 |
1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005
        Push    "r3-r5"
        ADR     r3, %86
        MOV     r4, #IOMD_Base
        LDRB    r4, [r4, #IOMD_ID0]
82
        LDR     r5, [r3], #4
        TEQ     r5, #&80000000     ;terminator
        TEQNE   r5, r4
        LDMEQIA r3, {r0-r2}
        BEQ     %FT84
        ADD     r3, r3, #3*4
        B       %BT82
84
        Pull    "r3-r5"
        ExitSWIHandler
86
Kevin Bracey's avatar
Kevin Bracey committed
2006
        DCD     IOMD_Original :AND: &FF,   1, &00000005, &0000000F
2007 2008 2009 2010
        DCD     IOMD_7500     :AND: &FF,   2, &00000001, &0000000F
        DCD     IOMD_7500FE   :AND: &FF,   3, &00000001, &0000000F
        DCD     IOMD_IOMD2    :AND: &FF,   4, &0000000F, &0000000F
        DCD     &80000000,                 0,         0,         0  ;terminator
2011
 ]
2012

Kevin Bracey's avatar
Kevin Bracey committed
2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034
; OS_ReadSysInfo 9 - Read ROM info
;
; On entry:
;    r0 = 9 (reason code 9)
;    r1 = item number to return
;
; On exit:
;    r0 = pointer to requested string (NULL terminated) or NULL if it wasn't found
;
; Currently defined item numbers are:
;
;    0   = OS name
;    1   = Part number
;    2   = Build date
;    3   = Dealer name
;    4   = User name
;    5   = User address

90
        CMP     R1, #0
        ADREQ   R0, RSI9_OSname     ; The OS name
        BEQ     %FT95
2035
        CMP     R1, #2              ; The build date (dynamically generated)
Kevin Bracey's avatar
Kevin Bracey committed
2036
        MOVNE   R0, #0              ; Other ones are unimplemented
2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061
        BNE     %FT95
        LDR     R0, =ROMBuildDate
        LDRB    R1, [R0]
        CMP     R1, #0
        BNE     %FT94
        ; Build date string hasn't been generated yet. Generate it.
        Push    "r0,r2-r3,lr"
        MOV     R0, #0
        BL      ExtendedROMFooter_FindTag
        CMP     R0, #0              ; Found it?
        STREQ   R0, [R13]
        BEQ     %FT93
        ; For compatability, make this string match the same format as the old
        ; string. Conveniently, this matches the format string used by OS_Word
        ; 14
        LDR     R1, [R13]
        MOV     R2, #?ROMBuildDate
        ADRL    R3, TimeFormat
        SWI     XOS_ConvertDateAndTime
        MOVVS   R0, #0
        STRVS   R0, [R13]
93
        Pull    "r0,r2-r3,lr"
94
        MOV     R1, #2
Kevin Bracey's avatar
Kevin Bracey committed
2062 2063 2064
95
        ExitSWIHandler

2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077
; OS_ReadSysInfo 11 - Read debug information
;
; On entry:
;    r0 = 11 (reason code 11)
;
; On exit:
;    r0 = pointer to function for debug character output
;    r1 = pointer to function for debug character input
;

110
        ; Check if both HAL_DebugTX and HAL_DebugRX are available
        Push    "r8-r9,r14"
2078
        MOV     R8, #OSHW_LookupRoutine
2079 2080
        MOV     R9, #EntryNo_HAL_DebugTX
        SWI     XOS_Hardware
2081
        MOVVC   R8, #OSHW_LookupRoutine
2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124
        MOVVC   R9, #EntryNo_HAL_DebugRX
        SWIVC   XOS_Hardware
        Pull    "r8-r9,r14"
        BVS     ReadSysInfo_InvalidReason
        ADR     R0, RSI_DebugTX
        ADR     R1, RSI_DebugRX
        ExitSWIHandler

RSI_DebugTX
        ; In:
        ; R0 = char
        ; Privileged mode
        ; Out:
        ; R0-R3, PSR corrupt
        Push    "r9,r12,r14"
        AddressHAL
        CallHAL HAL_DebugTX
        Pull    "r9,r12,pc"

RSI_DebugRX
        ; In:
        ; Privileged mode
        ; Out:
        ; R0=char read, or -1
        ; R1-R3, PSR corrupt
        Push    "r9,r12,r14"
        AddressHAL
        CallHAL HAL_DebugRX
        Pull    "r9,r12,pc"

; OS_ReadSysInfo 12 - Read extended machine ID
;
; On entry:
;    r0 = 12 (reason code 12)
;    r1 = Pointer to word-aligned buffer, or 0 to read size
;
; On exit:
;    r0 = Size of extended machine ID, or 0 if none/corrupt
;    Buffer in R1 filled, if applicable
;

120
        Push    "r1-r3,r9,r14"
2125 2126
        AddressHAL
        MOV     R0, R1 ; HAL takes the buffer pointer in R0
2127 2128 2129 2130
        CallHAL HAL_ExtMachineID
        Pull    "r1-r3,r9,r14"
        ExitSWIHandler

2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163
; OS_ReadSysInfo 13 - Validate key handler
;
; On entry:
;    r0 = 13 (reason code 13)
;    r1 = key handler address (0 to just return valid flags)
;
; On exit:
;    r0 = Mask of supported key handler flags
;         Or pointer to error block
;

130
        LDR     R0, =KeyHandler_Flag_Wide
        CMP     R1, #0
        ExitSWIHandler EQ
        Push    "R2"
        LDR     R2, [R1, #KeyHandler_KeyTranSize]
        TST     R2, #KeyHandler_HasFlags
        LDRNE   R2, [R1, #KeyHandler_Flags]
        BICNES  R2, R2, R0
        Pull    "R2"
        ExitSWIHandler EQ
        ADR     R0, ErrorBlock_BadKeyHandler
      [ International
        Push    "lr"
        BL      TranslateError
        Pull    "lr"
      ]
        ORR     lr, lr, #V_bit
        ExitSWIHandler

        MakeErrorBlock BadKeyHandler

2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179
;
; Extended ROM footer functions
;
; These operate on a new tag-based structure located at the end of the ROM
; image. Each entry consists of a one-byte ID, a one-byte length, and then N
; bytes of data. The length byte doesn't count the two initial header bytes.
;
; The end of the list is implicity terminated by a footer word; the footer word
; contains the length of the structure in the low two bytes (minus the length of
; the footer word), and a 16-bit CRC in the top two bytes (again, minus the
; footer word). The footer word will be word-aligned, but everything else is
; assumed to be byte aligned.
;
; Current tags:
;
; 0     ROM build date, stored as 5-byte time (length = 5)
2180 2181
; 1     Compressed ROM softload hint (length = 8). First word is negative
;       checksum of uncompressed image, second word is OS header offset.
2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240
;

ExtendedROMFooter_Find  ROUT
        ; Find the header word for the extended ROM footer. Returns -1 if not found.
        Push    "r1-r4,lr"
        LDR     r4, =ZeroPage
        LDR     r0, [r4, #ExtendedROMFooter]
        CMP     r0, #0
        BNE     %FT10
        ; Examine the end of the ROM image
        ; Footer should be located just before the standard 20 byte footer
        LDR     r2, =ROM+OSROM_ImageSize*1024-24
        LDR     r1, [r2]
        CMP     r1, #-1
        MOVEQ   r0, r1
        BEQ     %FT09
        ; Check CRC
        MOV     r1, r1, LSL #16
        SUB     r1, r2, r1, LSR #16
        MOV     r3, #1
        SWI     XOS_CRC
        MOVVS   r0, #-1
        BVS     %FT09
        LDR     r1, [r2]
        CMP     r0, r1, LSR #16
        MOVNE   r0, #-1
        MOVEQ   r0, r2
09
        STR     r0, [r4, #ExtendedROMFooter]
10
        Pull    "r1-r4,pc"

ExtendedROMFooter_FindTag  ROUT
        ; Find the tag number given in R0.
        ; Returns data pointer in R0 & length in R1 on success.
        ; Returns 0 in R0 (and corrupt R1) for failure.
        Push    "r2-r3,lr"
        MOV     r2, r0
        BL      ExtendedROMFooter_Find
        CMP     r0, #-1
        BEQ     %FT09
        MOV     r3, r0
        LDR     r0, [r0]
        MOV     r0, r0, LSL #16
        SUB     r0, r3, r0, LSR #16
05
        CMP     r0, r3
        BEQ     %FT09
        LDRB    lr, [r0], #1
        LDRB    r1, [r0], #1
        CMP     lr, r2
        BEQ     %FT10
        ADD     r0, r0, r1
        B       %BT05
09
        MOV     r0, #0
10
        Pull    "r2-r3,pc"

Kevin Bracey's avatar
Kevin Bracey committed
2241
RSI9_OSname    = "$SystemName $VString",0
2242

Kevin Bracey's avatar
Kevin Bracey committed
2243
        ALIGN
Neil Turton's avatar
Neil Turton committed
2244 2245 2246
        LTORG

        END