NewReset 66.9 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.
;
        SUBT    => NewReset

Robert Sprowson's avatar
Robert Sprowson committed
17 18
; Reset types
SoftReset       * 0
Neil Turton's avatar
Neil Turton committed
19 20 21 22 23 24 25 26
PowerOnReset    * 1
ControlReset    * 2

; CMOS RAM resetting stuff:
CMOSLimit       * &F0

; Keyboard flags
                ^ 1
27 28 29 30 31
 [ HAL
KbdScanActive   # 1
                # 2
KbdFlags        # 4
 |
Neil Turton's avatar
Neil Turton committed
32 33 34 35 36 37 38 39 40 41
CTRL_Down_Flag  # 1
SHIFT_Down_Flag # 1
KB_There_Flag   # 1

R_Down_Flag     # 1      ; note that these 4 form one word!!
T_Down_Flag     # 1
Del_Down_Flag   # 1
Copy_Down_Flag  # 1

KeyDataPtr      # 4
42 43

Port2Present    # 1      ; note that these 4 form one word!!
Neil Turton's avatar
Neil Turton committed
44
Port3Present    # 1
45 46
KeyState        # 1
KeyMSB          # 1
47
 ]
Neil Turton's avatar
Neil Turton committed
48

Kevin Bracey's avatar
Kevin Bracey committed
49
; On ARM600, InitIRQWs is in zero page - check it's big enough
Neil Turton's avatar
Neil Turton committed
50

Kevin Bracey's avatar
Kevin Bracey committed
51
        ASSERT  @ <= ?InitIRQWs
Neil Turton's avatar
Neil Turton committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83


;       AddCamEntries
;
; in:   r0 -> appropriate part of CAM map
;       r1 = ap (+ CB bits in new world)
;       r2 = log address
;       r7 = amount of cam map to do
;       r8 = PageSize
;
; out:  r0, r3-r12 preserved
;       r1 corrupted
;       r2 updated by relevant amount

AddCamEntries ROUT
        Push    "r0, lr"
        MOV     lr, r1                  ; access privs (PPL)
        MOV     r1, r7
01
        STMIA   r0!, {r2, lr}           ; store logaddr, PPL
        ADD     r2, r2, r8              ; increment address by 1 page
        SUBS    r1, r1, #8              ; decrement count of how much to do
        BNE     %BT01
        Pull    "r0, pc"

; GetConfiguredSize - convert CMOS address into amount of memory
; in:   r0 = CMOS address
; out:  r0 corrupted
;       r2 = amount in bytes

; NB this routine doesn't do screen size mangling (yet!)

84
GetConfiguredSize Entry "r1"
Jeffrey Lee's avatar
Jeffrey Lee committed
85
        LDR     r1, =ZeroPage
Neil Turton's avatar
Neil Turton committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99
        LDR     r1, [r1, #Page_Size]
        ADRL    lr, PageShifts-1
        LDRB    r1, [lr, r1, LSR #12]   ; r1 = log2 pagesize
        MOV     r2, #127                ; mask of value

        TEQ     r0, #FontCMOS           ; if fontsize
        MOVEQ   r1, #12                 ; then in units of 4K, not pagesize
        MOVEQ   r2, #255                ; and use full byte

        BL      Read                    ; read CMOS ram
        AND     r2, r0, r2              ; value anded with mask
        MOV     r2, r2, LSL r1          ; and shifted up accordingly
        EXIT

100 101 102 103 104
; FudgeConfigureRMA - move pages from free pool to somewhere
; r0 = number of pages to attempt to move
; r1 = where to store number of bytes moved
; r3 = base address of where to put memory
; r11 = ap + CB
Neil Turton's avatar
Neil Turton committed
105 106
FudgeConfigureRMA
        Push    lr
Jeffrey Lee's avatar
Jeffrey Lee committed
107
        LDR     R10, =ZeroPage
Neil Turton's avatar
Neil Turton committed
108 109 110 111 112 113
        LDR     R10, [R10, #Page_Size]
        MUL     R0, R10, R0             ; get size in bytes
        MOV     R5, #0                  ; amount moved
        CMP     R0, #0
        BEQ     NoMoreMemory

Jeffrey Lee's avatar
Jeffrey Lee committed
114
        LDR     r4, =ZeroPage+FreePoolDANode
Neil Turton's avatar
Neil Turton committed
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
        MOV     r6, r11                         ; r6 = ap + CB
        LDR     r7, [r4, #DANode_Base]
        LDR     r8, [r4, #DANode_Size]
        ADD     r7, r7, r8                      ; r7 -> end of free pool +1
10
        CMP     r8, r10                         ; if no free memory left
        BCC     %FT20                           ; then tidy up
        SUB     r7, r7, r10                     ; move free pool pointer backwards
        Push    "r0, r1"
        MOV     r0, r7
        MOV     r1, r3
        BL      MovePageAtR0ToR1WithAccessR6
        Pull    "r0, r1"
        ADD     r3, r3, r10                     ; advance "to" pointer
        SUB     r8, r8, r10                     ; one less page of free memory
        ADD     r5, r5, r10                     ; one more page done
        SUBS    r0, r0, r10
        BNE     %BT10
20
        STR     r8, [r4, #DANode_Size]
NoMoreMemory
        STR     R5, [R1]
        Pull    "PC"

139
; MassageScreenSize - called from screen DA creation and ReadSysInfo
Neil Turton's avatar
Neil Turton committed
140 141

MassageScreenSize ROUT
Kevin Bracey's avatar
Kevin Bracey committed
142
        Push    lr
Jeffrey Lee's avatar
Jeffrey Lee committed
143
        LDR     lr, =ZeroPage
144 145 146 147
        LDR     lr, [lr, #VideoSizeFlags]
        TST     lr, #OSAddRAM_VRAMNotForGeneralUse
        MOVNE   r0, lr, LSR #12
        MOVNE   r0, r0, LSL #12
Kevin Bracey's avatar
Kevin Bracey committed
148 149
        Pull    pc, NE

Neil Turton's avatar
Neil Turton committed
150 151
        CMP     r0, #0
        BNE     CmosScreenWillDo
Jeffrey Lee's avatar
Jeffrey Lee committed
152 153 154
      [ ZeroPage <> 0
        LDR     r0, =ZeroPage
      ]
Neil Turton's avatar
Neil Turton committed
155 156 157 158 159 160 161 162 163 164
        LDR     r0, [r0, #RAMLIMIT]
        CMP     r0, #512*1024
        MOVEQ   r0, #80*1024
        MOVNE   r0, #160*1024
CmosScreenWillDo
        CMP     r0, #20*1024            ; ensure mode 0 gettable
        ADDCC   r0, r0, r10             ; if not, then add another page
        BCC     CmosScreenWillDo
        CMP     r0, #ScreenMaxSize
        MOVHI   r0, #ScreenMaxSize
Kevin Bracey's avatar
Kevin Bracey committed
165
        Pull    pc
Neil Turton's avatar
Neil Turton committed
166 167 168

        LTORG

169 170 171
  [ HAL
    ! 0, "*** DUMMY CONT_Break, soft breaks/resets will not work yet with HAL"
CONT_Break
172
        AddressHAL
173
        MOV     a1, #1
174
        LDR     a2, =L1PT
175
        CallHAL HAL_Reset
176 177 178 179 180
  ]


  [ :LNOT: HAL

Neil Turton's avatar
Neil Turton committed
181 182 183 184 185 186
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Data tables: VIDC := mode 0, all palette black

VIDCTAB

; Program Control Register first, to clear power-down bit
Kevin Bracey's avatar
Kevin Bracey committed
187 188 189
; Now depending upon the VIDCClockSource flag, re-program the clock source.
   [ VIDCClockSource = "VCO"
     [ VCOstartfix
190
        & &E0000404     ; CR: FIFO load 16 words, 1 bpp, ck/2, vclk (allow for doubled VCO freq)
Kevin Bracey's avatar
Kevin Bracey committed
191
     |
Neil Turton's avatar
Neil Turton committed
192
        & &E0000400     ; CR: FIFO load 16 words, 1 bpp, ck/1, vclk
Kevin Bracey's avatar
Kevin Bracey committed
193 194 195 196 197 198
     ]
   ]
   [ VIDCClockSource = "HCLK"
        & &E0000401     ; CR: FIFO load 16 words, 1 bpp, ck/1, hclk
   ]
   [ VIDCClockSource = "RCLK"
199
        & &E0000406     ; CR: FIFO load 16 words, 1 bpp, ck/2, rclk
200
   ]
Neil Turton's avatar
Neil Turton committed
201 202 203 204 205 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

; Don't bother programming all 256 palette entries, we'll be here all night
; Since we're setting up a 1 bit-per-pixel mode, just do colours 0 and 1

        & &10000000     ; Palette address register = 0
        & &00000000     ; Colour 0 = black
        & &00000000     ; Colour 1 = black
        & &40000000     ; Border colour = black
        & &50000000     ; Pointer colour 1 = black
        & &60000000     ; Pointer colour 2 = black
        & &70000000     ; Pointer colour 3 = black

; Get a stable display up so we get stable signals

        & &800003F8     ; HCR  = 76 + 88 + 96 + 640 + 96 + 28
        & &81000044     ; HSWR = 76
        & &82000098     ; HBSR = 76 + 88
        & &830000F2     ; HDSR = 76 + 88 + 96
        & &84000372     ; HDER = 76 + 88 + 96 + 640
        & &850003D8     ; HBER = 76 + 88 + 96 + 640 + 96
        & &860000F3     ; HCSR = HDSR

        & &90000137     ; VCR  = 3 + 19 + 16 + 256 + 16 + 2
        & &91000002     ; VSWR = 3
        & &92000015     ; VBSR = 3 + 19
        & &93000025     ; VDSR = 3 + 19 + 16
        & &94000125     ; VDER = 3 + 19 + 16 + 256
        & &95000135     ; VBER = 3 + 19 + 16 + 256 + 16
        & &96000025     ; VCSR = VDSR
        & &97000025     ; VCER = VDSR

        & &B1000001     ; SCR: sound disabled (+use 24MHz clock)

        & &C00F1003     ; EREG = comp sync, DACs on, ereg output ext lut
235 236 237
   [ VCOstartfix
        & &D0000302     ; FSYNREG, clk = (3+1)/(2+1) * 24MHz = 32MHz  (higher frequency as part of fix)
   |
Neil Turton's avatar
Neil Turton committed
238
        & &D0000305     ; FSYNREG, clk = (3+1)/(5+1) * 24MHz = 16MHz
239
   ]
Neil Turton's avatar
Neil Turton committed
240 241 242 243 244 245
        & &F0013000     ; DCR: bus D[31:0], Hdisc       ;RCM 29/9/94: changed from &F0012000 at PSwindells request
        & &FFFFFFFF     ; That's the lot


VIDCPhys        *       &03400000       ; used to address VIDC when MMU is off

246

Neil Turton's avatar
Neil Turton committed
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
; Entered here after RESET (or BREAK)

; This code must be capable of being executed at a non-ROM address and with the MMU off,
; and running in 32-bit mode up until the call to MemSize.

CONT_Break
        MOV     r1, #1          ; parameter passed to InitMEMC, to indicate Break not Reset
        B       Continue

CONT    ROUT
        MOV     r1, #0          ; parameter passed to InitMEMC, to indicate Reset not Break
Continue

; First bang MEMC to ensure safety

        BL      InitMEMC        ; initialise MEMC CR, and turn off MMU if it's on

; VInit etc set on ze mode change: no DMA going yet so don't set owt.

        MOV     R1, #VIDCPhys   ; Must ALWAYS initialise VIDC on reset or else
        ADR     R2, VIDCTAB     ; we may get vsync interrupts that stiff us
10      LDR     R0, [R2], #4    ; permanently as VIDC is in an undefined state
        CMP     R0, #-1         ; so have mode 0 with all black palette
        STRNE   R0, [R1]
        BNE     %BT10

; Now bang IOC (disable all but keyboard interrupts)

        MOV     R1, #IOC
        MOV     R0, #&FF                ; all inputs
        STRB    R0, [R1, #IOCControl]   ; in case called by Tim

        MOV     R0, #0
        STRB    R0, [R1, #IOCIRQMSKA]   ; kein interrupts
        STRB    R0, [R1, #IOCFIQMSK]    ; disable FIQs
        STRB    R0, [R1, #IOMD_DMAMSK]  ; disable DMA interrupts, too
283 284
        STRB    R0, [R1, #IOMD_IRQMSKC] ; and the rest...
        STRB    R0, [R1, #IOMD_IRQMSKD]
Neil Turton's avatar
Neil Turton committed
285

286
  [ Keyboard_Type = "A1A500" :LOR: Keyboard_Type = "PC"
Neil Turton's avatar
Neil Turton committed
287
        MOV     R0, #KARTRxBit          ; used for Archi keyboard or IOMD PC keyboard
288
  ]
Neil Turton's avatar
Neil Turton committed
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
        STRB    R0, [R1, #IOCIRQMSKB]   ; allow communication with kbd, when I_bit gets cleared

; now bits to allow CMOS read/write : need timer

        LDR     R0, =20000-1    ; R0 = Timer delay (units of 0.5 microsecond)
                                ; 20000*0.5E-6 = 0.01 Seconds (100Hz ticker)
                                ; TMD 21-May-93: "-1" correction applied

        STRB    R0, [R1, #Timer0LL]     ; Set up the delay
        MOV     R0, R0, LSR #8
        STRB    R0, [R1, #Timer0LH]
        STRB    R0, [R1, #Timer0GO]     ; and start the ticks

        MOV     R0, #timer0_bit
        STRB    R0, [R1, #IOCIRQCLRA]   ; Clear pending t0 interrupt j.i.c.

305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
  [ VCOstartfix
        ;2nd part of fix for VCO failing to start on A7000 (esp. 7500FE) - forcing PCOMP high for about 3 ms
        LDRB    R0, [R1,#IOMD_ID0]
        CMP     R0, #&E7
        LDREQB  R0, [R1,#IOMD_ID1]
        CMPEQ   R0, #&D4
        BEQ     vcofix_notMorris      ; risky to force PCOMP on Risc PC
        MOV     R0, #VIDCPhys
        LDR     R2, =&D0000342        ; VIDC20 FSYNREG, as in VIDCTAB but with force PCOMP high
        STR     R2, [R0]
        MOV     R0, #3072*2           ; time delay of about 3 ms (0.5 us units)
        STRB    R0, [R1, #Timer0LR]   ; copy counter into output latch
        LDRB    R2, [R1, #Timer0CL]   ; R2 := low output latch
vcofix_waitloop
        STRB    R0, [R1, #Timer0LR]   ; copy counter into output latch
        LDRB    R3, [R1, #Timer0CL]   ; R3 := low output latch
        TEQ     R3, R2                ; unchanged ?
        BEQ     vcofix_waitloop       ; then loop
        MOV     R2, R3                ; copy anyway
        SUBS    R0, R0, #1            ; decrement count
        BNE     vcofix_waitloop       ; loop if not finished
        MOV     R0, #VIDCPhys
        LDR     R2, =&D0000302        ; VIDC20 FSYNREG, as in VIDCTAB (PCOMP low again)
        STR     R2, [R0]
vcofix_notMorris
  ]

Neil Turton's avatar
Neil Turton committed
332 333 334 335
; now size memory

        BL      MemSize                 ; out: r0 = page size, r1 = memory size, r2 = MEMC CR value, r3-r14 corrupt

336
MemSized
Neil Turton's avatar
Neil Turton committed
337 338 339 340
        MOV     R8, R0                  ; R8 = page size in bytes
        MOV     R13, R1                 ; R13 is now the RAM size
        MOV     R9, R2                  ; need this to set soft copy right

341 342 343 344 345
   [ EmulatorSupport
        ARM_on_emulator R7
        MOVEQ   R7,#&80
        ORREQ   R7,R7,#&3E00            ; r7 := &3E80 = 16000 (standard Risc PC value)
        BLNE    TimeCPU                 ; r7 := CPU speed in kHz/MEMC1a flag
Neil Turton's avatar
Neil Turton committed
346
   |
Neil Turton's avatar
Neil Turton committed
347
        BL      TimeCPU                 ; r7 := CPU speed in kHz/MEMC1a flag
Neil Turton's avatar
Neil Turton committed
348
   ]
Neil Turton's avatar
Neil Turton committed
349 350 351 352 353 354 355 356 357 358 359 360 361

; the fixed areas give us : IRQ stack (in cursor), SVC stack (in sysheap base)
; and bottom block makes most sense done here

; now keyboard initialisation: initialise baud rate, send dummy, read dummy

        MOV     R0, #InitKbdWs
        MOV     R1, #0
        STRB    R1, [R0, #CTRL_Down_Flag] ; clear CTRL down flag, R down flag
        STRB    R1, [R0, #SHIFT_Down_Flag]
        STRB    R1, [R0, #KB_There_Flag]
        STR     R1, [R0, #R_Down_Flag]  ; all CMOS reset flags
        STR     R1, [R0, #KeyDataPtr]
362 363
        STR     R1, [R0, #Port2Present] ; all KbdRes vars

Neil Turton's avatar
Neil Turton committed
364 365 366 367 368 369 370
        B       SetUpKbd                ; No stack yet so branch and branch back.
SetUpKbdReturn


; set up reset interrupt handler (reads, discards keys, setting flags if CTRL or R)
; NB on ARM600 we need to go into 32-bit mode, so we can safely overwrite vectors

371
        MRS     r0, CPSR                ; switch into IRQ32, still IRQs disabled
Neil Turton's avatar
Neil Turton committed
372 373
        BIC     r0, r0, #&1F
        ORR     r1, r0, #IRQ32_mode
374
        MSR     CPSR_c, r1
Neil Turton's avatar
Neil Turton committed
375 376 377 378 379 380 381 382

        LDR     sp_irq, =IRQSTK         ; set up sp_irq

        ADRL    R2, MOSROMVecs          ; pick up from table
        LDR     R2, [R2, #&18]          ; this gets overwritten while active,
        MOV     R3, #0
        STR     R2, [R3, #&18]          ; but hopefully by the same value!

383
        ADDR    R2, IRQ_Test_CTRL_or_R_Pressed ; (could use ADRL, but ADDR macro is nicer)
Kevin Bracey's avatar
Kevin Bracey committed
384
        STR     R2, [R3, #InitIRQHandler] ; instruction is now a LDR PC,InitKbdHandler
Kevin Bracey's avatar
Kevin Bracey committed
385

Neil Turton's avatar
Neil Turton committed
386
        ORR     r0, r0, #SVC32_mode     ; switch into SVC32
Neil Turton's avatar
Neil Turton committed
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405

 [ StrongARM
   ;for StrongARM, we need to do an IMB type thing for modifying code in vector area
        ARM_read_ID r1
        AND     r1,r1,#&F000
        CMP     r1,#&A000
        BNE     vectorpoke_notSA_1
        MOV     r1,#0                   ;we clean one cache entry, 0..1F, = vector area
  [ SAcleanflushbroken
        ARMA_clean_DCentry r1
        ARMA_flush_DCentry r1
  |
        ARMA_cleanflush_DCentry r1
  ]
        ARMA_drain_WB
        ARMA_flush_IC
vectorpoke_notSA_1
 ]

Neil Turton's avatar
Neil Turton committed
406
        BIC     r0, r0, #I32_bit        ; and enable IRQs
407
        MSR     CPSR_c, r0
Neil Turton's avatar
Neil Turton committed
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 438

 ; in SVC32 from now until we've finished poking around with vectors



 [ :LNOT: AlwaysClearRAM

; IF por OR FX200 bit set THEN clear memory
        MOV     R0, #IOC
        LDRB    R1, [R0, #IOCIRQSTAA]
        ANDS    R1, R1, #por_bit
        BNE     %FT20

        LDR     R0, =OsbyteVars + :INDEX: ESCBREAK
        LDRB    R1, [R0]
        CMP     R1, #2                  ; unlike popular rumour, bit 1 ain't
        CMPNE   R1, #3                  ; a flag
        BNE     %FT30
20
 ]
        BL      ClearPhysRAM
30
        MOV     r0, #0
        STR     r9, [r0, #MEMC_CR_SoftCopy] ; set soft copy.
        STR     r7, [r0, #MemorySpeed]  ; Remember CPU speed/MEMC1a flag
        STR     r8, [r0, #Page_Size]    ; r8 is still page size from way up there
        STR     r13, [r0, #RAMLIMIT]    ; save sussed memory size in LogRam

        LDR     sp, =SVCSTK             ; set up a stack

; do as much other initialisation as possible, to give keyboard stuff time
Neil Turton's avatar
Neil Turton committed
439 440 441 442
 [ StrongARM
        BL      Processor_Type          ; Determines the processor type & stores it in page 0.
 ]

443 444 445

  ]    ; :LNOT: HAL

446 447
Continue_after_HALInit

Neil Turton's avatar
Neil Turton committed
448 449 450 451 452 453
;StrongARM: OK, there is quite a bit of code poking below, to various addresses. We'll
;           defer IMB consideration till the poking's done, then do a full IMB (full
;           data cache clean). This avoids various little IMB's and removes chance of leaving
;           some unnoticed poked code in data cache. The deferral should be safe, because none
;           of the poked code will be used yet awhile (given that current IRQ hardware vector is
;           not actually changed below).
Neil Turton's avatar
Neil Turton committed
454 455 456 457 458 459 460 461 462

 [ ProcessorVectors
; Copy default processor vector table and default preveneers.
; Code relies on preveneers being immediately after processor vector table
; but could easily be changed into 2 copy loops.
        ASSERT  ProcVecPreVeneers = ProcVec_End
        ASSERT  DefaultPreVeneers = DefaultProcVecs+ProcVec_End-ProcVec_Start

        ADRL    R0, DefaultProcVecs
Jeffrey Lee's avatar
Jeffrey Lee committed
463
        LDR     R1, =ZeroPage+ProcVec_Start
Neil Turton's avatar
Neil Turton committed
464 465 466 467 468 469 470 471 472 473 474
        MOV     R2, #ProcVec_End-ProcVec_Start+ProcVecPreVeneersSize
39
        LDR     R3, [R0], #4
        STR     R3, [R1], #4
        SUBS    R2, R2, #4
        BNE     %BT39
 ]

; copy handler addresses
        ADRL    R1, MOSROMVecs+4        ; don't copy to 0: key stuff is using
                                        ; it as workspace!
Jeffrey Lee's avatar
Jeffrey Lee committed
475 476
        LDR     R0, =ZeroPage+4
        LDR     R3, =ZeroPage+EndMOSROMVecs-MOSROMVecs
Neil Turton's avatar
Neil Turton committed
477 478 479 480

40
        LDR     R2, [R1], #4            ; N.B. IRQ handler better be same as the one in there
        STR     R2, [R0], #4
Jeffrey Lee's avatar
Jeffrey Lee committed
481
        TEQ     R0, R3
Neil Turton's avatar
Neil Turton committed
482 483
        BNE     %BT40

Kevin Bracey's avatar
Kevin Bracey committed
484 485
        ChangedProcVecs r0

Kevin Bracey's avatar
Kevin Bracey committed
486
 [ :LNOT: No26bitCode
Neil Turton's avatar
Neil Turton committed
487 488
; Now we have set up the hardware vectors we can drop back to SVC26 mode

489
        MRS     r0, CPSR
Neil Turton's avatar
Neil Turton committed
490 491
        BIC     r0, r0, #&1F
        ORR     r0, r0, #SVC26_mode
492
        MSR     CPSR_c, r0
Neil Turton's avatar
Neil Turton committed
493 494 495
 ]

 [ CacheCMOSRAM
Kevin Bracey's avatar
Kevin Bracey committed
496
        DebugTX "InitCMOSCache entry"
Neil Turton's avatar
Neil Turton committed
497
        BL      InitCMOSCache           ; initialise cache of CMOS RAM
Kevin Bracey's avatar
Kevin Bracey committed
498
        DebugTX "InitCMOSCache done"
499
        TEQ     R0, #0                  ; returns zero on failure
Jeffrey Lee's avatar
Jeffrey Lee committed
500 501 502
      [ ZeroPage <> 0
        LDREQ   R0, =ZeroPage
      ]
503 504 505
        LDREQ   R1, [R0, #HAL_StartFlags]
        ORREQ   R1, R1, #OSStartFlag_NoCMOS
        STREQ   R1, [R0, #HAL_StartFlags]
Neil Turton's avatar
Neil Turton committed
506 507 508
 ]

; Now copy the initialised data
Jeffrey Lee's avatar
Jeffrey Lee committed
509
        LDR     R0, =ZeroPage+IRQ1V
Neil Turton's avatar
Neil Turton committed
510 511 512 513 514 515 516 517 518

; first save IOC soft copy so can restore it

        LDRB    R2, [R0, #IOCControlSoftCopy-IRQ1V]
        Push    "R2"
        LDRB    R2, [R0, #CannotReset-IRQ1V]
        Push    "R2"

        ADRL    r1, StartData
Jeffrey Lee's avatar
Jeffrey Lee committed
519
        LDR     R3, =ZeroPage+(EndData-StartData+IRQ1V)
Neil Turton's avatar
Neil Turton committed
520 521 522
DatCopy
        LDR     R2, [R1], #4
        STR     R2, [R0], #4
Jeffrey Lee's avatar
Jeffrey Lee committed
523
        TEQ     R0, R3
Neil Turton's avatar
Neil Turton committed
524 525 526
        BNE     DatCopy

        ADR     r2, CONT_Break
Jeffrey Lee's avatar
Jeffrey Lee committed
527
        LDR     r0, =ZeroPage
Neil Turton's avatar
Neil Turton committed
528 529
        STR     r2, [r0, #ResetIndirection]

Jeffrey Lee's avatar
Jeffrey Lee committed
530 531
        MOV     r3, #0                  ; initialise abort list
        STR     r3, [r0, #AbortIndirection]
Neil Turton's avatar
Neil Turton committed
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550

; Now the SWI despatch + low part of SWI table
        ADRL    R3, DirtyBranch
        LDR     R0, =SWIDespatch
SVCTabCopy                              ; so copy the table
        LDR     R2, [R1], #4
        STR     R2, [R0], #4
        TEQ     R1, R3
        BNE     SVCTabCopy

; pad to 1K table here, rather than use ROM space
        ADRL    R2, NoSuchSWI
        LDR     R4, =1024+SvcTable      ; end of table
PadSVCTable
        CMP     R0, R4
        STRNE   R2, [R0], #4
        BNE     PadSVCTable

; now the dirty branch
Kevin Bracey's avatar
Kevin Bracey committed
551 552
        LDR     R1, [R1]
        STR     R1, [R0]
Neil Turton's avatar
Neil Turton committed
553

Robert Sprowson's avatar
Robert Sprowson committed
554
; conversion SWIs all go through same despatch point
Neil Turton's avatar
Neil Turton committed
555 556
        LDR     R0, =SvcTable
        ADRL    R1, despatchConvert
Robert Sprowson's avatar
Robert Sprowson committed
557 558 559
        STR     R1, [R0, #OS_ConvertStandardDateAndTime * 4]
        STR     R1, [R0, #OS_ConvertDateAndTime * 4]

Neil Turton's avatar
Neil Turton committed
560 561 562 563
        MOV     R2, #OS_ConvertHex1
conversionSWIfill
        STR     R1, [R0, R2, LSL #2]
        ADD     R2, R2, #1
Robert Sprowson's avatar
Robert Sprowson committed
564 565
        CMP     R2, #OS_ConvertVariform
        BLS     conversionSWIfill
Neil Turton's avatar
Neil Turton committed
566

567 568 569
; OK, that completes the poking around, some of which is code. Now let's
; do a full IMB type thing, to be safe
;
Jeffrey Lee's avatar
Jeffrey Lee committed
570
        LDR     r0, =ZeroPage
571
        ARMop   IMB_Full,,,r0
Kevin Bracey's avatar
Kevin Bracey committed
572
        DebugTX "IMB_Full done"
Neil Turton's avatar
Neil Turton committed
573 574 575

; Initialise CAO ptr to none.

Jeffrey Lee's avatar
Jeffrey Lee committed
576
        LDR     R0, =ZeroPage
577
        LDR     R1, =DuffEntry          ; nothing will be here!!
Neil Turton's avatar
Neil Turton committed
578 579
        STR     R1, [R0, #Curr_Active_Object]

Neil Turton's avatar
Neil Turton committed
580
KeyWait * 200000                 ; 1/5 sec wait (in microseconds)
581 582 583 584 585
 [ HAL
us      * 1
 |
us      * 2
 ]
Neil Turton's avatar
Neil Turton committed
586

587
 [ HAL
588 589
        AddressHAL
        MOV     r6, #25                 ; Check for keyboard 25 times (5 secs max).
Jeffrey Lee's avatar
Jeffrey Lee committed
590
        LDR     r4, =ZeroPage+InitIRQWs
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611

kbdwait
        CallHAL HAL_KbdScan
        STR     r0, [r4, #KbdFlags]

        TST     r0, #KbdFlag_Done
        BNE     kbddone

      [ EmulatorSupport
        ARM_on_emulator r0
        MOVEQ   r0, #us
        LDRNE   r0, =KeyWait*us         ; Wait 1/5 second (give keys down a chance to come in).
      |
        LDR     r0, =KeyWait*us         ; Wait 1/5 second (give keys down a chance to come in).
      ]
        CallHAL HAL_CounterDelay
        SUBS    r6, r6, #1              ; else wait a maximum of 5 seconds.
        BNE     kbdwait
kbddone
        MSR     CPSR_c, #I32_bit+SVC32_mode
        CallHAL HAL_KbdScanFinish
Jeffrey Lee's avatar
Jeffrey Lee committed
612
        LDR     r1, =ZeroPage+InitIRQWs
613 614 615
        MOV     r0, #0
        STRB    r0, [r1, #KbdScanActive]
        MSR     CPSR_c, #SVC32_mode
Jeffrey Lee's avatar
Jeffrey Lee committed
616
        DebugTX "Keyboard scan complete"
617
 |
Neil Turton's avatar
Neil Turton committed
618 619 620
    [ KeyWait <> 0
; Check for keyboard there every 1/5 sec. but give up after 2 secs.
        MOV     r2, #IOC
Mike Stephens's avatar
Mike Stephens committed
621
        MOV     r6, #10                 ; Check for keyboard 10 times (2 secs max).
Neil Turton's avatar
Neil Turton committed
622 623 624
        MOV     r4, #InitKbdWs
kbdwait
        LDRB    r5, [r4, #KB_There_Flag]
625 626
      [ EmulatorSupport
        ARM_on_emulator r0
627 628
        MOVEQ   r0, #us
        LDRNE   r0, =KeyWait*us         ; Wait 1/5 second (give keys down a chance to come in).
629
      |
630
        LDR     r0, =KeyWait*us         ; Wait 1/5 second (give keys down a chance to come in).
631
      ]
Neil Turton's avatar
Neil Turton committed
632 633 634
        BL      DoMicroDelay
        TEQ     r5, #0                  ; If keyboard was there 1/5 second ago then
        BNE     kbdthere                ;   continue reset
Mike Stephens's avatar
Mike Stephens committed
635
        SUBS    r6, r6, #1              ; else wait a maximum of 2 seconds.
Neil Turton's avatar
Neil Turton committed
636 637 638
        BNE     kbdwait
kbdthere
    ]
639
 ]
Neil Turton's avatar
Neil Turton committed
640

641
 [ ValidateCMOS
Neil Turton's avatar
Neil Turton committed
642
; Do a POR if some super-critical values are shagged or if checksum is invalid.
643
        MOV     R3, #-1                 ; do all RAM if we do any
Neil Turton's avatar
Neil Turton committed
644
        BL      ValChecksum             ; Always check the checksum
645
        BNE     cmos_reset
646 647 648 649
 ]

 [ ValidateCMOS :LAND: STB

Neil Turton's avatar
Neil Turton committed
650 651 652
; ScreenSizeCMOS, RAMDiscCMOS, SysHeapCMOS, RMASizeCMOS and SpriteSizeCMOS
; should be 0. Happily they are at consecutive addresses so we can loop through
; them.
653
        MOV     R1, #ScreenSizeCMOS
Neil Turton's avatar
Neil Turton committed
654
reset_loop
655 656 657 658 659 660 661
        MOV     R0, R1
        BL      Read
        TEQ     R0, #0
        BNE     cmos_reset
        INC     R1
        TEQ     R1, #SpriteSizeCMOS
        BHI     reset_loop
Neil Turton's avatar
Neil Turton committed
662

663
; Year should be >=1995, <=2037 (when 32 bit signed Unix time breaks)
664 665
        MOV     R0, #YearCMOS+1
        BL      Read
666 667
        MOV     R1, R0
        MOV     R0, #YearCMOS+0
668
        BL      Read
669 670 671 672 673
        MOV     R2, #100
        MLA     R0, R2, R1, R0
        LDR     R1, =1995
        SUB     R0, R0, R1
        CMP     R0, #2037 - 1995
674
        BHI     cmos_reset
Neil Turton's avatar
Neil Turton committed
675 676

; Bit 4 of DBTBCMOS should be 1 (Boot)
677 678
        MOV     R0, #DBTBCMOS
        BL      Read
679 680
        TST     R0, #(1:SHL:4)
        BEQ     cmos_reset
Neil Turton's avatar
Neil Turton committed
681 682 683
 ]


684
; IF power-on bit set AND R/T/Del/Copy pressed THEN reset CMOS RAM
Neil Turton's avatar
Neil Turton committed
685
; note that memory cleared if POR, so key info has had plenty of time!
Robert Sprowson's avatar
Robert Sprowson committed
686

687
 [ HAL
Jeffrey Lee's avatar
Jeffrey Lee committed
688
        LDR     R0, =ZeroPage+HAL_StartFlags
689
        LDR     R1, [R0]
690
        TST     R1, #OSStartFlag_NoCMOS ; If no CMOS, reset for sensible cache
Kevin Bracey's avatar
Kevin Bracey committed
691
        BNE     cmos_reset
692
        TST     R1, #OSStartFlag_POR
693
        BEQ     no_cmos_reset           ; not a power on reset
694
        DebugTX "POR detected"
695
      [ CheckProtectionLink
696 697
        TST     R1, #OSStartFlag_NoCMOSReset
        BNE     no_cmos_reset
698
      ]
699 700 701
        TST     R1, #OSStartFlag_CMOSReset
        BNE     cmos_reset
 |
Neil Turton's avatar
Neil Turton committed
702 703 704 705 706
        MOV     R0, #IOC
        LDRB    R1, [R0, #IOCIRQSTAA]
        ANDS    R1, R1, #por_bit
        BEQ     no_cmos_reset

707
      [ CheckProtectionLink
Neil Turton's avatar
Neil Turton committed
708 709
        LDR     r0, =IOMD_MonitorType

710 711
        ; on Issue A's the protection bit is only weakly pulled up,
        ; so force it high, then read it back
Neil Turton's avatar
Neil Turton committed
712 713 714 715 716 717 718
        LDRB    r1, [r0]
        ORR     r1, r1, #IOMD_ProtectionLinkBit
        STRB    r1, [r0]

        LDRB    r1, [r0]
        TST     r1, #IOMD_ProtectionLinkBit
        BEQ     no_cmos_reset           ; if zero then CMOS is protected
719
      ]
Neil Turton's avatar
Neil Turton committed
720

721 722
    [ STB :LAND: IOMD_C_FrontPanelButton <> 0
      [ FrontPanelButtClearsCMOS
Neil Turton's avatar
Neil Turton committed
723 724 725 726
        MOV     r0, #IOMD_Base          ; if front panel button pressed then CMOS reset
        LDRB    r0, [r0, #IOMD_CLINES]
        TST     r0, #IOMD_C_FrontPanelButton
        BEQ     cmos_reset
727 728
      ]
    ]
Neil Turton's avatar
Neil Turton committed
729

730
 ]
731

Jeffrey Lee's avatar
Jeffrey Lee committed
732
        LDR     R0, =ZeroPage+InitIRQWs
733 734 735 736
 [ HAL
        LDR     R7, [R0, #KbdFlags]
        TST     R7, #KbdFlag_R:OR:KbdFlag_T:OR:KbdFlag_Delete:OR:KbdFlag_Copy
 |
Robert Sprowson's avatar
Robert Sprowson committed
737
        LDR     R7, [R0, #R_Down_Flag]  ; Picks up R/T/Del/Copy flags all in one
Neil Turton's avatar
Neil Turton committed
738
        CMP     R7, #0
739
 ]
Robert Sprowson's avatar
Robert Sprowson committed
740 741 742
        LDRNE   R3, =ZeroPage
        MOVNE   R14, #1
        STRNEB  R14, [R3, #MentionCMOSReset]
Neil Turton's avatar
Neil Turton committed
743 744 745
        BEQ     no_cmos_reset           ; power on bit checked again there

; CMOS reset detectified.
Robert Sprowson's avatar
Robert Sprowson committed
746
; Wipe it, then squirt in the MOS's table of default values
Neil Turton's avatar
Neil Turton committed
747

748
 [ HAL
749
        TST     R7, #KbdFlag_Copy:OR:KbdFlag_Delete
750
 |
751 752 753
        ASSERT  (Del_Down_Flag - R_Down_Flag) = 2
        ASSERT  (Copy_Down_Flag - Del_Down_Flag) = 1
        MOVS    R3, R7, LSR #16         ; full reset or just system?
754
 ]
Neil Turton's avatar
Neil Turton committed
755 756 757 758 759
        MOVNE   R3, #-1                 ; Del or Copy does all RAM
        MOVEQ   R3, #UserCMOS           ; R or T just system
    [ ChecksumCMOS
        BL      ValChecksum             ; unless the CMOS ram's corrupt ..
        MOVNE   R3, #-1                 ; .. then blast it anyway.
Robert Sprowson's avatar
Robert Sprowson committed
760
    ]
Neil Turton's avatar
Neil Turton committed
761
cmos_reset
762
        DebugTX "Reset CMOS"
Robert Sprowson's avatar
Robert Sprowson committed
763
        ADD     sp, sp, #4              ; junk CannotReset flag from stack
Neil Turton's avatar
Neil Turton committed
764

Robert Sprowson's avatar
Robert Sprowson committed
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787
        MOV     R4, #0
cmrlp
        CMP     R3, #-1
        BEQ     cmrall                  ; ignore system-only wipe checks
        CMP     R4, #UserCMOS
        MOVEQ   R4, #&50                ; skip User (30-45) & 3rd party (46-59) & high podules (60-79)
        BEQ     cmrall
        CMP     R4, #PoduleCMOS
        MOVEQ   R4, #&80                ; skip low podules (112-127)
        BEQ     cmrall
        TEQ     R4, #NewADFSCMOS        ; documented in 'Troubleshooting' in
        TEQNE   R4, #CountryCMOS        ; the RISC OS 3.7 user guide as preserved
        BEQ     cmrskip
cmrall
        MOV     R1, R4
        BL      NVMemory_ResetValue     ; get the reset value
        MOVS    R1, R2                  ; when -ve, leave alone
        MOVPL   R0, R4
        BLPL    Write                   ; CMOS(R0) := R1
cmrskip
        ADD     R4, R4, #1
        CMP     R4, #CMOSLimit
        BCC     cmrlp
Neil Turton's avatar
Neil Turton committed
788 789

; IF R or Delete pressed THEN set sync 0 ELSE set sync Auto
Jeffrey Lee's avatar
Jeffrey Lee committed
790
        LDR     R0, =ZeroPage+InitIRQWs
791 792 793 794
 [ HAL
        LDR     R1, [R0, #KbdFlags]
        TST     R1, #KbdFlag_R:OR:KbdFlag_Delete
 |
Neil Turton's avatar
Neil Turton committed
795 796 797 798
        LDRB    R1, [R0, #R_Down_Flag]
        CMP     R1, #0
        LDREQB  R1, [R0, #Del_Down_Flag]
        CMPEQ   R1, #0
799
 ]
Neil Turton's avatar
Neil Turton committed
800 801 802 803 804
        MOV     R0, #VduCMOS
        MOVNE   R1, #MonitorTypeAuto :OR: Sync_Auto     ; if R or Del
        MOVEQ   R1, #MonitorTypeAuto :OR: Sync_Separate ; if T or Copy
        BL      Write

Robert Sprowson's avatar
Robert Sprowson committed
805 806
    [ ChecksumCMOS
        BL      MakeChecksum            ; create a valid checksum
807
    ]
Robert Sprowson's avatar
Robert Sprowson committed
808
        B       hard_reset              ; CMOS reset only checked on power on, so was hard
Neil Turton's avatar
Neil Turton committed
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841

no_cmos_reset                           ; R1 has por_bit set if power on
        Push    "r1"
        MOV     r0, #SystemSpeedCMOS
        BL      Read
        BIC     r1, r0, #CMOSResetBit   ; clear bit indicating CMOS reset
        MOV     r0, #SystemSpeedCMOS
        BL      Write
        Pull    "r1"

        Pull    r0                      ; always pull CannotReset flag
 [ SoftResets
        TST     r1, #por_bit
        BNE     hard_reset              ; it was a power-on, so it's a hard reset
        CMP     r0, #0
 [ DebugForcedReset
        MOVNE   r2, #Reset_CannotResetFlag
 ]
        BNE     hard_reset_forced

; IF control pressed OR memory implausible (Check SysHpd, CAM map sensible) THEN hard reset

        LDR     R0, =SysHeapStart
        LDR     R8, [R0, #:INDEX: hpdmagic]
        LDR     R2, =magic_heap_descriptor
        CMP     R8, R2                  ; check sysheap initialised
 [ DebugForcedReset
        MOVNE   r2, #Reset_SysHeapCorrupt
 ]
        BNE     hard_reset_forced

; also check CAM map sensible

Jeffrey Lee's avatar
Jeffrey Lee committed
842
        LDR     R5, =ZeroPage
Neil Turton's avatar
Neil Turton committed
843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869
        LDR     R4, [R5, #Page_Size]    ; R4 = page size
        ADRL    R3, PageShifts-1
        LDRB    R4, [R3, R4, LSR #12]   ; R4 = log2(pagesize)
        LDR     R3, [R5, #RAMLIMIT]     ; R3 = total RAM size
        MOV     R2, R3, LSR R4          ; number of pages=total memory / pagesize
        CMP     R2, #256                ; but if fewer than 128 (eg 64 on A305) (NB if <256 then <=128)
        MOVCC   R2, #128                ; then use 128 (all MEMC1's pages need initialising,
                                        ; even if half of them are not in use)
        SUB     R2, R2, #1
        LDR     R3, =CamEntriesForVicky

        LDR     R4, [R5, #MaxCamEntry]  ; get highest CAM entry
        LDR     R5, [R5, #CamEntriesPointer] ; and pointer to CAM soft copy

        CMP     R5, R3                  ; if not the same
 [ DebugForcedReset
        MOVNE   r2, #Reset_WrongCamMapAddress
        BNE     hard_reset_forced
 ]
        CMPEQ   R4, R2                  ; or number of pages not the same
 [ DebugForcedReset
        MOVNE   r2, #Reset_WrongNumberOfPages
 ]
        BNE     hard_reset_forced       ; then do a hard reset

; now check all cam contains sensible values

Jeffrey Lee's avatar
Jeffrey Lee committed
870
        LDR     R4, =ZeroPage
Neil Turton's avatar
Neil Turton committed
871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886
        LDR     R4, [R4, #Page_Size]
        SUB     R4, R4, #1
        ORR     R4, R4, #&F0000000      ; can have addresses above 64M
CamCheck
        LDR     R3, [R5, R2, LSL #2]
        BIC     r3, r3, #&F0000000      ; remove PPL
        TST     R3, R4
 [ DebugForcedReset
        MOVNE   r2, #Reset_CamMapCorrupt
 ]
        BNE     hard_reset_forced       ; wally entry: not pagesize multiple, or >= 32M
        SUBS    R2, R2, #1
        BPL     CamCheck

; leave CTRL test till last, so the keyboard's had as much time to
; wiggle the wet string as we can give it
Jeffrey Lee's avatar
Jeffrey Lee committed
887
        LDR     R0, =ZeroPage+InitKbdWs
Neil Turton's avatar
Neil Turton committed
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911
        LDRB    R1, [R0, #CTRL_Down_Flag]
        CMP     R1, #0
        BNE     hard_reset

soft_reset
; clear out 4K of scratchspace, to use as a reverse CAM soft copy;
; set bytes to indicate page mapped to that address. Can then recalculate
; end of memory.

; This code doesn't currently work on ARM600 versions -
; 4K of workspace isn't enough to do this with a 4K page size
; We'd probably want to do it differently anyway, using the L2PT
; But since we're removing soft resets it's not worth the effort

        ASSERT  MEMM_Type <> "ARM600"

        MOV     R5, #ScratchSpace
        MOV     R1, #4*1024
        MOV     R2, #0
clrscratch
        SUBS    R1, R1, #4
        STRPL   R2, [R5, R1]
        BPL     clrscratch

Jeffrey Lee's avatar
Jeffrey Lee committed
912 913
        LDR     r7, =ZeroPage
        LDR     R2, [R7, #Page_Size]
Neil Turton's avatar
Neil Turton committed
914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952
        ADRL    R8, PageShifts-1
        LDRB    R8, [R8, R2, LSR #12]

        LDR     r2, [r7, #RAMLIMIT]
        MOV     r2, r2, LSR r8          ; last valid page
        SUB     r2, r2, #1

        LDR     R7, [R7, #CamEntriesPointer]
        LDR     R12, =DuffEntry

restoreCAMloop
        LDR    R3, [R7, R2, LSL #2]
        MOV    r11, r3, LSR #28
        BIC    r3, r3, #&F0000000

        MOV    R0, R3, LSR R8              ; logram page number
        LDRB   R4, [R5, R0]
        CMP    r4, #0                      ; check for doubly mapped pages
        BEQ    rclon

        ORR    r3, r12, #&30000000         ; force to invalid place if so.
        STR    r3, [R7, R2, LSL #2]
        MOV    r3, r12
        MOV    r11, #3                     ; protected
        MOV    R0, R3, LSR R8
        LDRB   R4, [R5, R0]
rclon
        CMP    r3, #16*1024*1024           ; in application space?
        MOVLT  r11, #0                     ; noprot if so
        STRLT  r3, [R7, R2, LSL #2]
        ADD    R4, R4, #1
        STRB   R4, [R5, R0]                ; sema for interesting pages
        BL     BangCam
        SUBS   R2, R2, #1
        BPL    restoreCAMloop

; now do post-scan to see if we need to do more CAM bashing to get pages back.
; any entries that aren't validateable should be remapped.

Jeffrey Lee's avatar
Jeffrey Lee committed
953
        LDR     R1, =ZeroPage
Neil Turton's avatar
Neil Turton committed
954
        MOV     R12, #ScratchSpace
Jeffrey Lee's avatar
Jeffrey Lee committed
955 956
        LDR     R2, [R1, #Page_Size]
        MOV     R7, #0
Neil Turton's avatar
Neil Turton committed
957 958 959 960 961 962 963 964
findapplend
        LDRB    R3, [R12], #1
        CMP     R3, #0
        ADDNE   R7, R7, R2
        BNE     findapplend
        STR     R7, [R1, #AplWorkSize]  ; verified value
        LDR     R3, [R1, #RAMLIMIT]     ; calc last valid page:
        MOV     R3, R3, LSR R8          ; RAMLIMIT >> R8
Jeffrey Lee's avatar
Jeffrey Lee committed
965
        LDR     R4, [R1, #CamEntriesPointer] ; no PPL
Neil Turton's avatar
Neil Turton committed
966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988
testforremap
        SUBS    R3, R3, #1
        BMI     finishedremap
        LDR     R0, [R4, R3, LSL #2]
        BIC     r0, r0, #&F0000000      ; remove PPL
        ADD     R1, R0, R2
        SWI     XOS_ValidateAddress
        BCC     testforremap

        Push    "R2-R4"
        MOV     R0, R0, LSR R8          ; curr logram page number
        LDRB    R4, [R5, R0]
        SUB     R4, R4, #1
        STRB    R4, [R5, R0]            ; dec sema
        MOV     R2, R3                  ; entry no
        MOV     R3, R7                  ; addr to set to
        BL      BangCamUpdate
        Pull    "R2-R4"
holefilled
        ADD     R7, R7, R2
        LDRB    R0, [R12], #1           ; reinspect our reverse map
        CMP     R0, #0
        BNE     holefilled
Jeffrey Lee's avatar
Jeffrey Lee committed
989 990 991
      [ ZeroPage <> 0
        LDR     R0, =ZeroPage
      ]
Neil Turton's avatar
Neil Turton committed
992 993 994 995 996
        STR     R7, [R0, #AplWorkSize]
        B       testforremap

finishedremap
        MOV     R12, #NVECTORS-1
Jeffrey Lee's avatar
Jeffrey Lee committed
997
        LDR     R11, =ZeroPage+VecPtrTab
Neil Turton's avatar
Neil Turton committed
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013
freenextvec
        LDR     R2, [R11, R12, LSL #2]
loseveclink
        LDR     R3, [R2, #TailPtr]
        BL      FreeSysHeapNode
        MOVVC   R2, R3
        BVC     loseveclink
        CMP     R3, #0                  ; were we at the end of the chain?
 [ DebugForcedReset
        MOVNE   r2, #Reset_VectorChainCorrupt
 ]
        BNE     hard_reset_forced
        SUBS    R12, R12, #1
        BPL     freenextvec
; so that's the code for restore default vectors, basically
        BL      InitVectors
Jeffrey Lee's avatar
Jeffrey Lee committed
1014
        LDR     R0, =ZeroPage
Neil Turton's avatar
Neil Turton committed
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057
        LDR     R1, [R0, #AplWorkSize]
        STR     R1, [R0, #MemLimit]

        LDR     R3, =TickNodeChain
        LDR     R2, [R3]

loseticknodes
        CMP     R2, #0
        BEQ     ticknodesallgone

        LDR     R3, [R2]
        BL      FreeSysHeapNode
 [ DebugForcedReset
        MOVVS   r2, #Reset_TickNodesCorrupt
 ]
        BVS     hard_reset_forced
        MOV     R2, R3
        B       loseticknodes

ticknodesallgone
; and now it's time to free the IRQ structures

        MOV     R12, #(NoInterrupt-1)*12+8      ; last device link offset
        LDR     R11, =DefaultIRQ1V-DefaultIRQ1Vcode+Devices
freenextdev
        LDR     R2, [R11, R12]
losedevlink
        CMP     R2, #0
        BEQ     stepdevice

        LDR     R3, [R2, #8]
        BL      FreeSysHeapNode
 [ DebugForcedReset
        MOVVS   r2, #Reset_DeviceVectorCorrupt
 ]
        BVS     hard_reset_forced
        MOV     R2, R3
        B       losedevlink
stepdevice
        SUBS    R12, R12, #12
        BPL     freenextdev

; now the PIRQ structures and CallBack_Vector
Jeffrey Lee's avatar
Jeffrey Lee committed
1058
        LDR     R11, =ZeroPage+PIRQ_Chain
Neil Turton's avatar
Neil Turton committed
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
        MOV     r4, #PodDesp_Link
losepirqchain
        LDR     R2, [R11]
        CMP     r2, #0                  ; for CallBack_Vector
        BEQ     doobry
losepirqlink
        LDR     R3, [R2, r4]
        BL      FreeSysHeapNode
        MOVVC   R2, R3
        BVC     losepirqlink
        CMP     R3, #0                  ; were we at the end of the chain?
 [ DebugForcedReset
        MOVNE   r2, #Reset_PoduleOrCallBackCorrupt
 ]
        BNE     hard_reset_forced
Jeffrey Lee's avatar
Jeffrey Lee committed
1074
        LDR     R2, =ZeroPage+PIRQ_Chain
Neil Turton's avatar
Neil Turton committed
1075
        CMP     R11, R2
1076
        LDR     R2, =ZeroPage+PFIQasIRQ_Chain
Neil Turton's avatar
Neil Turton committed
1077 1078
        MOVEQ   R11, R2
        CMPNE   r11, r2
Jeffrey Lee's avatar
Jeffrey Lee committed
1079
        LDREQ   r11, =ZeroPage+CallBack_Vector
Neil Turton's avatar
Neil Turton committed
1080 1081 1082 1083 1084 1085 1086
    [ PodDesp_Link <> 0
        MOVEQ   r4, #0
    ]
        BEQ     losepirqchain


doobry  Pull    "R1"                    ; IOCControl restoration
Jeffrey Lee's avatar
Jeffrey Lee committed
1087
        LDR     R0, =ZeroPage
Neil Turton's avatar
Neil Turton committed
1088
        STRB    R1, [R0, #IOCControlSoftCopy]
Jeffrey Lee's avatar
Jeffrey Lee committed
1089
        ASSERT  :LNOT: HAL
Neil Turton's avatar
Neil Turton committed
1090 1091 1092 1093 1094 1095
        MOV     R0, #IOC                ; and bash the hardware
        STRB    R1, [R0, #IOCControl]

        MOV     R0, #SoftReset
        B       ResetPart1Done

Robert Sprowson's avatar
Robert Sprowson committed
1096
 ] ; SoftResets
Neil Turton's avatar
Neil Turton committed
1097 1098 1099 1100 1101 1102

hard_reset
 [ DebugForcedReset
        MOV     r2, #0                  ; indicate normal hard reset
 ]
hard_reset_forced
1103
        LDR     r8, =ZeroPage
Neil Turton's avatar
Neil Turton committed
1104
 [ DebugForcedReset
Jeffrey Lee's avatar
Jeffrey Lee committed
1105
        STR     r2, [r8]                ; store to logical address zero
Neil Turton's avatar
Neil Turton committed
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115
 ]

        Pull    "R2"                    ; discard old IOC state

; fill in relevant CamMap entries, so can soft start.

        LDR     R8, [R8, #Page_Size]
        ADRL    R1, PageShifts-1
        LDRB    R1, [R1, R8, LSR #12]

Jeffrey Lee's avatar
Jeffrey Lee committed
1116
        LDR     r2, =ZeroPage
1117
        LDR     r0, [r2, #VideoSizeFlags] ; offset from start of physical pages to static part
Neil Turton's avatar
Neil Turton committed
1118 1119 1120 1121 1122 1123 1124 1125
        MOV     r0, r0, LSR r1          ; r0 := cam entry number
        MOV     r0, r0, LSL #3          ; r0 := offset into CAM map for start of static part

        MOV     R7, #32*1024*8
        MOV     R7, R7, LSR R1          ; r7 := cam entry offset for 32K

        LDR     R12, [R2, #RAMLIMIT]    ; R12 = total RAM size

1126
 [ :LNOT:HAL
Neil Turton's avatar
Neil Turton committed
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153
                                        ; new code which allows for MEMC2's small pages
        MOV     R1, R12, LSR R1         ; R1 = number of pages
        CMP     R1, #256                ; but if fewer than 128 (eg 64 on A305) (NB if <256 then <=128)
        MOVCC   R1, #128                ; then use 128 (all MEMC1's pages need initialising,
                                        ; even if half of them are not in use)

        SUB     R3, R1, #1
        STR     R3, [R2, #MaxCamEntry]

        LDR     R1, =CamEntriesForVicky
        STR     R1, [R2, #CamEntriesPointer]


; On ARM600 we must zap all the soft CAM map before adding any entries,
; since the old contents are used in BangCamUpdate

        Push    "r0"
        ADD     r2, r1, r3, LSL #3      ; r2 -> last entry to do
        LDR     r0, =DuffEntry
        MOV     lr, #AP_Duff            ; PPL = no access
WallopDuffOnes
        STMDA   r2!, {r0, lr}           ; store address, PPL
        CMP     r2, r1
        BCS     WallopDuffOnes
        Pull    "r0"
        ADD     R0, R0, R1

1154
        LDR     R2, =CursorChunkAddress
Neil Turton's avatar
Neil Turton committed
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167
        LDR     r1, =AP_CursorChunk
        BL      AddCamEntries

        CMP     R12, #512*1024
        SUBEQ   R0, R0, R7              ; previous entries
        ADDNE   R0, R0, R7              ; next entries
        MOV     R2, #0
        MOV     r1, #AP_PageZero
        BL      AddCamEntries

        CMP     R12, #512*1024
        SUBEQ   R0, R0, R7              ; previous entries
        ADDNE   R0, R0, R7              ; next entries
1168
        LDR     R2, =SysHeapChunkAddress
Neil Turton's avatar
Neil Turton committed
1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179
        MOV     r1, #AP_SysHeap :OR: PageFlags_Unavailable
        BL      AddCamEntries

        ADD     R0, R0, R7              ; next entries (ignore 512K machines)
        MOV     r7, #0
        LDR     r7, [r7, #L2PTSize]
        MOV     r7, r7, LSR #12-3       ; number of pages * 8
        LDR     R2, =L2PT
        LDR     r1, =AP_L2PT :OR: PageFlags_Unavailable
        BL      AddCamEntries

1180 1181
        ADD     r2, r0, #((L1PT-L2PT):SHR:(12-3))   ; point at PPL for 1st L1 page
        ADD     r2, r2, #4
Neil Turton's avatar
Neil Turton committed
1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196
        LDR     r1, =AP_L1PT
        STR     r1, [r2], #8            ; store 4 CAM entries for 4 x 4K = 16K of L1
        STR     r1, [r2], #8            ; mark them as unavailable for removal
        STR     r1, [r2], #8
        STR     r1, [r2], #8

        ADD     R0, R0, R7              ; add on enough pages for L2PT

        MOV     r7, #0
        LDR     r7, [r7, #SoftCamMapSize] ; number of bytes in soft cam map
        ADD     r7, r7, #UndStackSize
        MOV     r7, r7, LSR #12-3       ; number of bytes of cam map for this
        LDR     R2, =UndStackSoftCamChunk
        MOV     r1, #AP_UndStackSoftCam
        BL      AddCamEntries
1197
 ]
1198
        DebugTX "InitDynamicAreas"
Neil Turton's avatar
Neil Turton committed
1199 1200 1201 1202 1203 1204

; let's boogie with the CMOS for a bit
; read info and move as much memory as we can

        BL      InitDynamicAreas

1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218
; RMA
        Push    "r0-r12"
        MOV     r1, #ChangeDyn_RMA      ; Area number
        MOV     r2, #4096               ; Initial size
        MOV     r3, #RMAAddress         ; Base address
        MOV     r4, #AP_RMA             ; Area flags
        MOV     r5, #RMAMaxSize         ; Maximum size
        ADRL    r6, DynAreaHandler_RMA  ; Pointer to handler
        MOV     r7, r3                  ; Workspace ptr points at area itself
        ADRL    r8, AreaName_RMA        ; Title string - node will have to be reallocated
                                        ; after module init, to internationalise it
        BL      DynArea_Create          ; ignore any error, we're stuffed if we get one!
        Pull    "r0-r12"

Kevin Bracey's avatar
Kevin Bracey committed
1219
; Screen
Neil Turton's avatar
Neil Turton committed
1220 1221 1222 1223
        Push    "r0-r12"
        MOV     r0, #ScreenSizeCMOS
        BL      Read

Jeffrey Lee's avatar
Jeffrey Lee committed
1224
        LDR     r5, =ZeroPage
Neil Turton's avatar
Neil Turton committed
1225 1226
        LDR     r10, [r5, #Page_Size]   ; needed by MassageScreenSize
        MUL     r0, r10, r0             ; convert to bytes
1227 1228 1229
        LDR     r5, [r5, #VideoSizeFlags] ; maximum size
        MOV     r5, r5, LSR #12
        MOV     r5, r5, LSL #12
Neil Turton's avatar
Neil Turton committed
1230 1231 1232 1233
        BL      MassageScreenSize

        MOV     r1, #ChangeDyn_Screen   ; area number
        MOV     r2, r0                  ; initial size
Kevin Bracey's avatar
Kevin Bracey committed
1234
        MOV     r3, #-1                 ; Base address dynamic
Neil Turton's avatar
Neil Turton committed
1235 1236 1237 1238 1239 1240 1241 1242
        LDR     r4, =AP_Screen          ; area flags
        ADRL    r6, DynAreaHandler_Screen ; handler
        VDWS    r7                      ; workspace pointer
        MOV     r8, #0
        STR     r8, [r7, #CursorFlags]  ; put zero in CursorFlags as an indication that VDU not yet inited
        STR     r2, [r7, #TotalScreenSize]
        ADRL    r8, AreaName_Screen     ; area name
        BL      DynArea_Create
Kevin Bracey's avatar
Kevin Bracey committed
1243
        STR     r3, [r7, #ScreenEndAddr]
Neil Turton's avatar
Neil Turton committed
1244 1245
        Pull    "r0-r12"

1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261
  [ LongCommandLines :LAND: (:LNOT: HAL)
        ;sort out the Kernel buffers dynamic area
        Push    "r0-r12"
        MOV     r1, #ChangeDyn_Kbuffs   ; Area number
        MOV     r2, #KbuffsSize         ; Initial (and in fact permanent) size
        LDR     r3, =KbuffsBaseAddress  ; Base address
        MOV     r4, #AP_Kbuffs          ; Area flags
        MOV     r5, #KbuffsMaxSize      ; Maximum size
        MOV     r6, #0                  ; no handler
        MOV     r7, #0
        ADRL    r8, AreaName_Kbuffs     ; Title string - node will have to be reallocated
                                        ; after module init, to internationalise it
        BL      DynArea_Create          ; ignore any error, we're stuffed if we get one!
        Pull    "r0-r12"
  ]

Kevin Bracey's avatar
Kevin Bracey committed
1262
; SpriteArea
Neil Turton's avatar
Neil Turton committed
1263 1264
        Push    "r0-r12"
        MOV     r0, #0                  ; initialise SpriteSize to zero
Jeffrey Lee's avatar
Jeffrey Lee committed
1265
      [ ZeroPage = 0
Neil Turton's avatar
Neil Turton committed
1266
        STR     r0, [r0, #SpriteSize]   ; (fixes bug MED-00811)
Jeffrey Lee's avatar
Jeffrey Lee committed
1267 1268 1269 1270
      |
        LDR     r1, =ZeroPage
        STR     r0, [r1, #SpriteSize]   ; (fixes bug MED-00811)
      ]
Neil Turton's avatar
Neil Turton committed
1271 1272 1273 1274 1275 1276 1277

        MOV     r0, #SpriteSizeCMOS     ; find out how much spritesize configured
        BL      GetConfiguredSize       ; in: r0 = CMOS address, out: r2 = size

        MOV     r1, #ChangeDyn_SpriteArea ; Area number
        MOV     r3, #-1                 ; Base address dynamic
        MOV     r4, #AP_Sprites         ; Area flags
1278
        MOV     r5, #16*1024*1024       ; Maximum size (changed from -1, address space preservation)
Neil Turton's avatar
Neil Turton committed
1279 1280 1281 1282 1283 1284 1285
        ADRL    r6, DynAreaHandler_Sprites ; Pointer to handler
        MOV     r7, #-1                 ; Use base address as workspace ptr
        ADRL    r8, AreaName_SpriteArea ; Title string - node will have to be reallocated
                                        ; after module init, to internationalise it
        BL      DynArea_Create          ; ignore any error, we're stuffed if we get one!
        Pull    "r0-r12"

Kevin Bracey's avatar
Kevin Bracey committed
1286
; RAMDisc
Neil Turton's avatar
Neil Turton committed
1287 1288 1289 1290 1291 1292
        Push    "r0-r12"
        MOV     r0, #RAMDiscCMOS        ; find out how much RAM disc configured
        BL      GetConfiguredSize       ; in: r0 = CMOS address, out: r2 = size

        MOV     r1, #ChangeDyn_RamFS    ; Area number
        MOV     r3, #-1                 ; Base address dynamic
1293 1294 1295 1296 1297 1298 1299 1300
        ARM_read_ID r4
        AND     r4, r4, #&F000
        CMP     r4, #&A000
        MOVEQ   r4, #AP_RAMDisc_SA      ; Area flags, if StrongARM  (introduced for Ursula)
        MOVNE   r4, #AP_RAMDisc         ; Area flags
      [ {FALSE}
        MOV     r5, #16*1024*1024       ; Limit maximum size to 16MB while fiddling with FileCore
      |
1301
        MOV     r5, #MaxRAMFS_Size*1024*1024      ; A trade off between nice big disc and complete waste of address space
1302
      ]
Neil Turton's avatar
Neil Turton committed
1303 1304 1305 1306 1307 1308 1309
        ADRL    r6, DynAreaHandler_RAMDisc ; Pointer to handler
        MOV     r7, #-1                 ; Use base address as workspace ptr
        ADRL    r8, AreaName_RAMDisc    ; Title string - node will have to be reallocated
                                        ; after module init, to internationalise it
        BL      DynArea_Create          ; ignore any error, we're stuffed if we get one!
        Pull    "r0-r12"

Kevin Bracey's avatar
Kevin Bracey committed
1310
; FontArea
Neil Turton's avatar
Neil Turton committed
1311 1312 1313 1314 1315 1316 1317
        Push    "r0-r12"
        MOV     r0, #FontCMOS           ; find out how much font cache configured
        BL      GetConfiguredSize       ; in: r0 = CMOS address, out: r2 = size

        MOV     r1, #ChangeDyn_FontArea ; Area number
        MOV     r3, #-1                 ; Base address dynamic
        MOV     r4, #AP_FontArea        ; Area flags
Kevin Bracey's avatar
Kevin Bracey committed
1318 1319
        MOV     r5, #32*1024*1024       ; Maximum size changed from -1 for Ursula (limit address
                                        ; space usage on large memory machines)
Neil Turton's avatar
Neil Turton committed
1320 1321 1322 1323 1324 1325 1326
        ADRL    r6, DynAreaHandler_FontArea ; Pointer to handler
        MOV     r7, #-1                 ; Use base address as workspace ptr
        ADRL    r8, AreaName_FontArea   ; Title string - node will have to be reallocated
                                        ; after module init, to internationalise it
        BL      DynArea_Create          ; ignore any error, we're stuffed if we get one!
        Pull    "r0-r12"

1327
        LDR     R0, =(1024*1024):SHR:12 ; 1MB of RAM in aplspace should be plenty for ROM init. Theoretically we don't need any at all, but having some there should make it easier to debug any ROM init failures.
Neil Turton's avatar
Neil Turton committed
1328
        MOV     R3, #32*1024            ; aplwork start
Jeffrey Lee's avatar
Jeffrey Lee committed
1329
        LDR     R1, =ZeroPage+AplWorkSize ; aplwork size
Neil Turton's avatar
Neil Turton committed
1330
        MOV     r11, #AP_AppSpace
1331
        BL      FudgeConfigureRMA       ; put some memory in aplspace
Neil Turton's avatar
Neil Turton committed
1332

Jeffrey Lee's avatar
Jeffrey Lee committed
1333
        LDR     R0, =ZeroPage
Neil Turton's avatar
Neil Turton committed
1334 1335 1336 1337 1338
        LDR     R1, [R0, #AplWorkSize]
        ADD     R1, R1, #32*1024
        STR     R1, [R0, #AplWorkSize]
        STR     R1, [R0, #MemLimit]

1339
        DebugTX "InitVectors"
Neil Turton's avatar
Neil Turton committed
1340 1341
        BL      InitVectors               ; ready for OsByte to read mode

Jeffrey Lee's avatar
Jeffrey Lee committed
1342 1343 1344 1345 1346
        LDR     R1, =ZeroPage+ModuleSWI_HashTab
        MOV     R2, #ModuleSHT_Entries
      [ ZeroPage <> 0
        MOV     R0, #0
      ]
Neil Turton's avatar
Neil Turton committed
1347 1348
clearmswis
        SUBS    R2, R2, #1
Jeffrey Lee's avatar
Jeffrey Lee committed
1349 1350 1351 1352 1353 1354
        STR     R0, [R1, R2, LSL #2]
        BGT     clearmswis

      [ ZeroPage <> 0
        LDR     R2, =ZeroPage
      ]
Neil Turton's avatar
Neil Turton committed
1355 1356 1357

     [  International
        MOV     R1, #-1                                 ; We don't have a message file yet !
Jeffrey Lee's avatar
Jeffrey Lee committed
1358 1359
        STRB    R1, [R2, #ErrorSemaphore]               ; Don't translate errors.
        STR     R0, [R2, #KernelMessagesBlock]          ; No message file open.
1360
      [ CacheCommonErrors
Jeffrey Lee's avatar
Jeffrey Lee committed
1361
        STR     R0, [R2, #CachedErrorBlocks]            ; No cached errors
1362
      ]
Neil Turton's avatar
Neil Turton committed
1363 1364
     ]

1365
  [ HAL
Jeffrey Lee's avatar
Jeffrey Lee committed
1366
        LDR     R0, =ZeroPage+HAL_StartFlags
1367 1368 1369
        LDR     R1, [R0]
        TST     R1, #OSStartFlag_POR
  |
Neil Turton's avatar
Neil Turton committed
1370 1371 1372 1373
        MOV     R0, #IOC
        LDRB    R1, [R0, #IOCIRQSTAA]
        ANDS    R1, R1, #por_bit
        STRNEB  R1, [R0, #IOCIRQCLRA]   ; clear POR if set
1374
  ]
Neil Turton's avatar
Neil Turton committed
1375

Kevin Bracey's avatar
Kevin Bracey committed
1376 1377 1378 1379

        ; Make the choice between PowerOn and Hard reset based purely on
        ; the state of the POR bit and NOT on whether memory was cleared.
 [ {FALSE}
Jeffrey Lee's avatar
Jeffrey Lee committed
1380
        LDREQ   R0, =ZeroPage+OsbyteVars + :INDEX: LastBREAK
Neil Turton's avatar
Neil Turton committed
1381 1382
        LDREQB  R0, [R0]
        TSTEQ   R0, #&80                ; tbs set if memory cleared
Kevin Bracey's avatar
Kevin Bracey committed
1383
 ]
Neil Turton's avatar
Neil Turton committed
1384 1385 1386 1387 1388
        MOVNE   R0, #PowerOnReset
        MOVEQ   R0, #ControlReset


ResetPart1Done                          ; R0 is reset type
Kevin Bracey's avatar
Kevin Bracey committed
1389
        WritePSRc SVC_mode + I_bit, r1  ; interrupts off since kbd bash done
Jeffrey Lee's avatar
Jeffrey Lee committed
1390
        LDR     R1, =ZeroPage+OsbyteVars + :INDEX: LastBREAK
Neil Turton's avatar
Neil Turton committed
1391 1392
        STRB    R0, [R1]

Jeffrey Lee's avatar
Jeffrey Lee committed
1393
        LDR     R1, =ZeroPage+InitIRQWs
1394 1395 1396 1397 1398
 [ HAL
        LDR     R0, [R1, #KbdFlags]
        AND     R1, R0, #KbdFlag_Shift
        AND     R0, R0, #KbdFlag_Present
 |
Neil Turton's avatar
Neil Turton committed
1399 1400
        LDRB    R0, [R1, #KB_There_Flag]
        LDRB    R1, [R1, #SHIFT_Down_Flag]
1401
 ]
Neil Turton's avatar
Neil Turton committed
1402 1403
        Push    "R0, R1"                ; save until after MOSInit

1404
        DebugTX "InitIRQ1"
1405
        BL      InitialiseIRQ1Vtable
Neil Turton's avatar
Neil Turton committed
1406

Jeffrey Lee's avatar
Jeffrey Lee committed
1407
        LDR     R3, =ZeroPage
Neil Turton's avatar
Neil Turton committed
1408
        ADRL    R1, Default_PIRQHandler_Node
Jeffrey Lee's avatar
Jeffrey Lee committed
1409 1410
        STR     R1, [R3, #PIRQ_Chain]
        STR     R1, [R3, #PFIQasIRQ_Chain]
Neil Turton's avatar
Neil Turton committed
1411 1412 1413
 ASSERT Default_PFIQasIRQHandler_Node = Default_PIRQHandler_Node

        MOV     R0, #0                  ; put in IRQ handler, word at 0
Jeffrey Lee's avatar
Jeffrey Lee committed
1414 1415 1416
        STRB    r0, [r3, #FIQclaim_interlock]
        STRB    r0, [r3, #CallBack_Flag]
        STR     r0, [r3, #CallBack_Vector]
Neil Turton's avatar
Neil Turton committed
1417

1418 1419 1420 1421 1422 1423 1424
; Create the Branch Through 0 Trampoline in the system heap
        MOV     R3, #Branch0_Trampoline_Size
        BL      ClaimSysHeapNode
        ADRVCL  R0, Branch0_Trampoline
        ASSERT  Branch0_Trampoline_Init = 20
        LDMVCIA R0, {R1,R3,R4,R5,R14}
        STMVCIA R2, {R1,R3,R4,R5,R14}
Jeffrey Lee's avatar
Jeffrey Lee committed
1425
        LDRVC   R0, =ZeroPage
1426 1427
        STRVC   R2, [R0, #ProcVec_Branch0]

Kevin Bracey's avatar
Kevin Bracey committed
1428
 [ :LNOT: No26bitCode
Neil Turton's avatar
Neil Turton committed
1429 1430 1431

; we're poking locations 0 and &18 here, so we'd best go back to SVC32

1432
        MRS     r2, CPSR
Neil Turton's avatar
Neil Turton committed
1433 1434
        BIC     r3, r2, #&1F
        ORR     r3, r3, #SVC32_mode
1435
        MSR     CPSR_c, r3
Neil Turton's avatar
Neil Turton committed
1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449
 ]

 [ DebugForcedReset
        LDR     R1, [R0]
        TEQ     R1, #0                                  ; if normal hard reset
        LDREQ   R1, BranchThroughZeroInstruction2       ; then get branchthruzero code
 |
        LDR     R1, BranchThroughZeroInstruction2
 ]
        STR     R1, [R0]                                ; put branch through 0 code at 0

        LDR     R1, RealIRQHandler
        STR     R1, [R0, #&18]

Jeffrey Lee's avatar
Jeffrey Lee committed
1450
        LDR     R2, =ZeroPage+InitIRQWs                 ; clear temp ws
1451 1452 1453 1454
        MOV     R3, #0
        MOV     R4, #0
        STMIA   R2!, {R3,R4}
        STMIA   R2!, {R3,R4}
1455
        DebugTX "IMB_Full"
1456

1457 1458 1459 1460
   ;we need to do an IMB type thing for modifying code in vector area,
   ;and for copying irq handler code
   ;
        ARMop   IMB_Full,,,r0
Kevin Bracey's avatar
Kevin Bracey committed
1461
        ChangedProcVecs r0
Jeffrey Lee's avatar
Jeffrey Lee committed
1462
        LDR     r0,=ZeroPage
Neil Turton's avatar
Neil Turton committed
1463

Kevin Bracey's avatar
Kevin Bracey committed
1464

Kevin Bracey's avatar
Kevin Bracey committed
1465
 [ :LNOT:No26bitCode
Neil Turton's avatar
Neil Turton committed
1466 1467 1468

; now back to SVC26

1469
        MSR     CPSR_c, r2
Neil Turton's avatar
Neil Turton committed
1470
 ]
1471

Neil Turton's avatar
Neil Turton committed
1472 1473
        MOV     R1, #&100
        STR     R1, [R0, #RCLimit]
Jeffrey Lee's avatar
Jeffrey Lee committed
1474 1475 1476
        MOV     R1, #0
        STR     R1, [R0, #ReturnCode]
        STR     R1, [R0, #TickNodeChain]
Neil Turton's avatar
Neil Turton committed
1477

1478
; clear the keyboard workspace (tidy!)
Jeffrey Lee's avatar
Jeffrey Lee committed
1479
        ADD     R0, R0, #&1C
Kevin Bracey's avatar
Kevin Bracey committed
1480
        MOV     R2, #InitWsEnd - &1C
1481 1482
        BL      memset

Neil Turton's avatar
Neil Turton committed
1483 1484 1485 1486
;now put in error handler and escape handler
        BL      DEFHAN
        BL      DEFHN2
        MOV     R0, #ExceptionDumpArea
Jeffrey Lee's avatar
Jeffrey Lee committed
1487
        LDR     R1, =ZeroPage+DUMPER
Neil Turton's avatar
Neil Turton committed
1488 1489 1490
        SWI     XOS_ChangeEnvironment

        VDWS    WsPtr                   ; main MOS initialisation
1491
        DebugTX "VduInit"
Neil Turton's avatar
Neil Turton committed
1492
        BL      VduInit
1493
        DebugTX "ExecuteInit"
Neil Turton's avatar
Neil Turton committed
1494
        BL      ExecuteInit
1495
        DebugTX "KeyInit"
Neil Turton's avatar
Neil Turton committed
1496
        BL      KeyInit
1497
        DebugTX "MouseInit"
Neil Turton's avatar
Neil Turton committed
1498
        BL      MouseInit
1499
        DebugTX "OscliInit"
Neil Turton's avatar
Neil Turton committed
1500 1501
        BL      OscliInit               ; before initialising modules

1502
        DebugTX "Enabling IRQs"
Kevin Bracey's avatar
Kevin Bracey committed
1503
        WritePSRc SVC_mode, R14         ; enable IRQs
1504
        DebugTX "IRQs on"
Neil Turton's avatar
Neil Turton committed
1505

Kevin Bracey's avatar
Kevin Bracey committed
1506 1507 1508
 [ DebugTerminal
        MOV     R0, #RdchV
        ADRL    R1, DebugTerminal_Rdch
Jeffrey Lee's avatar
Jeffrey Lee committed
1509
        LDR     R2, =ZeroPage
Kevin Bracey's avatar
Kevin Bracey committed
1510 1511 1512 1513 1514
        LDR     R2, [R2, #HAL_Workspace]
        SWI     XOS_Claim
        MOV     R0, #WrchV
        ADRL    R1, DebugTerminal_Wrch
        SWI     XOS_Claim
1515
        DebugTX "Debug terminal on"
Kevin Bracey's avatar
Kevin Bracey committed
1516 1517
 ]

1518
        [ DoInitialiseMode :LOR: :LNOT: Embedded_UI
Neil Turton's avatar
Neil Turton committed
1519 1520
        BL      InitialiseMode          ; select correct screen mode, in case any
                                        ; module prints anything in initialisation
Neil Turton's avatar
Neil Turton committed
1521
        ]
Neil Turton's avatar
Neil Turton committed
1522 1523 1524 1525 1526 1527 1528 1529 1530

        MOV     R0, #&FD                ; read last reset type
        MOV     R1, #0
        MOV     R2, #&FF
        SWI     XOS_Byte
        CMP     R1, #SoftReset          ; soft reset?
        BEQ     SkipHardResetPart2

; HardResetPart2
Ben Avison's avatar
Ben Avison committed
1531
 [ HAL
1532
        DebugTX "HAL_InitDevices"
Ben Avison's avatar
Ben Avison committed
1533 1534
        AddressHAL
        MOV     R0, #0
Jeffrey Lee's avatar
Jeffrey Lee committed
1535
      [ ZeroPage = 0
Ben Avison's avatar
Ben Avison committed
1536 1537
        STR     R0, [R0, #DeviceCount]
        STR     R0, [R0, #DeviceTable]
Jeffrey Lee's avatar
Jeffrey Lee committed
1538 1539 1540 1541 1542
      |
        LDR     R1, =ZeroPage
        STR     R0, [R1, #DeviceCount]
        STR     R0, [R1, #DeviceTable]
      ]
Ben Avison's avatar
Ben Avison committed
1543
        CallHAL HAL_InitDevices         ; get HAL to register any devices it has
1544
        BL      LookForHALCacheController
Ben Avison's avatar
Ben Avison committed
1545
 |
Neil Turton's avatar
Neil Turton committed
1546
        BL      L1L2PTenhancements      ; little tricks on cacheability etc for performance
1547
 ]
1548
        DebugTX "InitVariables"
Neil Turton's avatar
Neil Turton committed
1549
        BL      InitVariables
1550
        DebugTX "AMBControl_Init"
Neil Turton's avatar
Neil Turton committed
1551
        BL      AMBControl_Init         ; initialise AMBControl section
1552
        DebugTX "ModuleInit"
Neil Turton's avatar
Neil Turton committed
1553 1554 1555 1556 1557 1558 1559 1560 1561 1562
        BL      ModuleInit              ; initialise modules
                                        ; scan podules, copy modules.

        MOV     R0, #0                  ; shrink sysheap as far as will go.
        SUB     R1, R0, #4*1024*1024
        SWI     XOS_ChangeDynamicArea
        MOV     R0, #ReadCMOS
        MOV     R1, #SysHeapCMOS
        SWI     XOS_Byte
        AND     R2, R2, #2_111111       ; mask to same size as status
Jeffrey Lee's avatar
Jeffrey Lee committed
1563
        LDR     R0, =ZeroPage
Neil Turton's avatar
Neil Turton committed
1564
        LDR     R0, [R0, #Page_Size]
1565
        MUL     R3, R0, R2              ; size spare wanted
Neil Turton's avatar
Neil Turton committed
1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576
        BL      ClaimSysHeapNode
        MOV     R0, #HeapReason_Free
        SWI     XOS_Heap

        MOV     R0, #ReadCMOS
        MOV     R1, #FileLangCMOS
        SWI     XOS_Byte
        MOV     R1, R2
        MOV     R0, #FSControl_SelectFS ; set configured filing system
        SWI     XOS_FSControl

1577 1578 1579
        ; Update RTC now all the modules are running
        SWI     XOS_ResyncTime

1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594
        ; OS_ReadSysInfo 9,2 now relies on the Territory module, which may
        ; enable IRQs. But the PRMs say OS_ReadSysInfo shouldn't alter the IRQ
        ; state. So call it once here just to initialise the string which it
        ; uses the Territory module to generate.
        ; This won't account for any modules using it during ModuleInit, but
        ; that should be pretty rare (or at least rare from within IRQ-sensitive
        ; code)
        MOV     R0, #9
        MOV     R1, #2
        SWI     XOS_ReadSysInfo

  [ UseNewFX0Error
        ; Also, *FX 0
        BL      InitNewFX0Error
  ]
Neil Turton's avatar
Neil Turton committed
1595 1596 1597 1598 1599
  [ DebugROMInit
        SWI     XOS_WriteS
        =       "Service_PostInit",0
        SWI     XOS_NewLine
  ]
Neil Turton's avatar
Neil Turton committed
1600 1601 1602 1603
        MOV     r1, #Service_PostInit   ; issue post-initialisation service
        BL      Issue_Service

; New code added here by TMD 01-Apr-92
Ben Avison's avatar
Ben Avison committed
1604
; Changed to use OS_LeaveOS 16-Oct-02
Neil Turton's avatar
Neil Turton committed
1605

Neil Turton's avatar
Neil Turton committed
1606 1607 1608 1609 1610
  [ DebugROMInit
        SWI     XOS_WriteS
        =       "callbacks",0
        SWI     XOS_NewLine
  ]
Ben Avison's avatar
Ben Avison committed
1611
        SWI     XOS_LeaveOS
Neil Turton's avatar
Neil Turton committed
1612
        SWI     XOS_EnterOS             ; switch back to SVC mode (IRQs, FIQs enabled)
Kevin Bracey's avatar
Kevin Bracey committed
1613
  [ :LNOT: HAL :LAND: RO371Timings
1614 1615
        BL      finalmemoryspeed
  ]
Neil Turton's avatar
Neil Turton committed
1616 1617
; end of added code

Jeffrey Lee's avatar
Jeffrey Lee committed
1618 1619
     [ International                    ; Open the kernel messages file.
        LDR     r0, =ZeroPage+KernelMessagesBlock+4
Neil Turton's avatar
Neil Turton committed
1620 1621 1622 1623
        ADR     r1, MessageFileName
        MOV     r2, #0                  ; Use file directly.
        SWI     XMessageTrans_OpenFile
        MOVVC   r0, #-1
Jeffrey Lee's avatar
Jeffrey Lee committed
1624
      [ ZeroPage = 0
Neil Turton's avatar
Neil Turton committed
1625
        STRVC   r0, [r0, #KernelMessagesBlock+1]  ; Message file is now open.
Jeffrey Lee's avatar
Jeffrey Lee committed
1626 1627 1628
      |
        LDR     lr, =ZeroPage
        STRVC   r0, [lr, #KernelMessagesBlock]  ; Message file is now open.
Neil Turton's avatar
Neil Turton committed
1629
      ]
Jeffrey Lee's avatar
Jeffrey Lee committed
1630
     ]
Neil Turton's avatar
Neil Turton committed
1631 1632 1633

SkipHardResetPart2                      ; code executed on all types of reset
      [ International
Jeffrey Lee's avatar
Jeffrey Lee committed
1634
        LDR     r0, =ZeroPage
Neil Turton's avatar
Neil Turton committed
1635 1636
        LDR     r1, [r0, #KernelMessagesBlock] ; if we've managed to open message file
        TEQ     r1, #0
Jeffrey Lee's avatar
Jeffrey Lee committed
1637
        ASSERT  (ZeroPage :AND: 255) = 0
Neil Turton's avatar
Neil Turton committed
1638 1639 1640
        STRNEB  r0, [r0, #ErrorSemaphore] ; then allow errors to be translated
      ]

Robert Sprowson's avatar
Robert Sprowson committed
1641
      [ DoInitialiseMode :LOR: :LNOT: Embedded_UI
Neil Turton's avatar
Neil Turton committed
1642
        BL      InitialiseMode
Robert Sprowson's avatar
Robert Sprowson committed
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
      ]
    [ :LNOT: Embedded_UI
        LDR     R0, =ZeroPage
        LDRB    R14, [R0, #MentionCMOSReset]
        TEQ     R14, #0
        BEQ     %FT12
      [ International
        SWI     XOS_WriteI+10
        BVS     %FT09
        BL      WriteS_Translated
        =       "CmosRst:CMOS RAM reset, press ESCAPE to continue",0
        ALIGN
09
      |
        SWI     XOS_WriteS
        =       10,"CMOS RAM reset, press ESCAPE to continue",0
        ALIGN
      ]
10
        SWI     XOS_ReadEscapeState
        BCC     %BT10
        MOV     R0, #124
        SWI     XOS_Byte                ; Clear the condition
        SWI     XOS_WriteI+12           ; Clear the screen
12
Neil Turton's avatar
Neil Turton committed
1668 1669 1670 1671
        SWI     XOS_WriteS
        =       10, "$SystemName ", 0   ; now RISC OS (no +) again
        ALIGN

Kevin Bracey's avatar
Kevin Bracey committed
1672 1673 1674 1675
        MOV     R0, #8
        ORR     R0, R0, #&500
        SWI     XOS_Memory              ; returns amount of soft ROM (pages) in r1
        MOVVS   R1, #0
Robert Sprowson's avatar
Robert Sprowson committed
1676 1677 1678

        LDR     R0, =ZeroPage
        LDR     R0, [R0, #RAMLIMIT]
Kevin Bracey's avatar
Kevin Bracey committed
1679 1680 1681
        MLA     R0, R1, R2, R0          ; convert pages to bytes and add in

        MOV     R0, R0, LSR #20         ; /(1024*1024) down to megabytes
Neil Turton's avatar
Neil Turton committed
1682 1683 1684 1685 1686 1687 1688
        LDR     R1, =GeneralMOSBuffer
        MOV     R2, #?GeneralMOSBuffer
        SWI     XOS_ConvertInteger4
        SWI     XOS_Write0
        SWI     XOS_WriteS
        =       "MB", 10,13, 10, 0      ; title complete
        ALIGN
Neil Turton's avatar
Neil Turton committed
1689

1690
        BL      ARM_PrintProcessorType
Robert Sprowson's avatar
Robert Sprowson committed
1691 1692 1693
    |
        ! 0,    "Banner & printing of processor type disabled"
    ]
Neil Turton's avatar
Neil Turton committed
1694

Robert Sprowson's avatar
Robert Sprowson committed
1695
        MOV     r0, #0                  ; Set DomainId to 0 every reset
Jeffrey Lee's avatar
Jeffrey Lee committed
1696
      [ ZeroPage = 0
Neil Turton's avatar
Neil Turton committed
1697
        STR     r0, [r0, #DomainId]     ; before calling anyone
Jeffrey Lee's avatar
Jeffrey Lee committed
1698 1699 1700 1701
      |
        LDR     r1, =ZeroPage
        STR     r0, [r1, #DomainId]     ; before calling anyone
      ]
Neil Turton's avatar
Neil Turton committed
1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715

; issue reset service call

        MOV     R1, #Service_Reset
        SWI     XOS_ServiceCall

; now set up the default FIQ owner

        MOV     R1, #Service_ClaimFIQ
        SWI     XOS_ServiceCall

        MOV     R1, #Service_ReleaseFIQ
        SWI     XOS_ServiceCall

Neil Turton's avatar
Neil Turton committed
1716 1717
 [ SoftResets :LAND: STB
        ! 0, "!!!! SoftReset is true => resets close all open files !!!!"
Neil Turton's avatar
Neil Turton committed
1718 1719
        MOV     R0, #FSControl_Shut     ; Open files get closed at reset
        SWI     XOS_FSControl
Neil Turton's avatar
Neil Turton committed
1720
 ]
Neil Turton's avatar
Neil Turton committed
1721 1722 1723 1724 1725 1726 1727 1728 1729 1730

        BL      PostInit

        MOV     r0, #&FD                ; read last reset type (again!)
        MOV     r1, #0
        MOV     r2, #&FF
        SWI     XOS_Byte
        CMP     r1, #SoftReset          ; a softie?
        SWINE   XOS_WriteI+7            ; go beep! Yaay!

1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748
; Now that ROM modules have mostly finished allocating memory, move a large
; chunk of the free memory from the free pool into application space so that
; the boot sequence and configured language have something to play around with
; (particularly if booting into BASIC!)
; However be careful not to move everything, otherwise anything which locks
; application space during boot could cripple important background processes
; like USB
        Push    "r1"
        LDR     r0, =ZeroPage
        LDR     r1, [r0, #AplWorkSize]
        LDR     r0, [r0, #FreePoolDANode+DANode_Size]
        SUB     r1, r1, #32*1024
        SUB     r1, r1, r0
        MOV     r1, r1, ASR #1          ; 50% each sounds fair
        MOV     r0, #ChangeDyn_FreePool
        SWI     XOS_ChangeDynamicArea
        Pull    "r1"

Neil Turton's avatar
Neil Turton committed
1749 1750 1751
        CMP     r1, #PowerOnReset
        BNE     %FT75

1752
 [ HAL :LAND: CheckProtectionLink
Jeffrey Lee's avatar
Jeffrey Lee committed
1753
        LDR     r1, =ZeroPage+HAL_StartFlags
1754 1755 1756 1757
        LDR     r1, [r1]
        TST     r1, #OSStartFlag_NoCMOSReset
        BNE     %FT75
 |
1758
      [ CheckProtectionLink
Neil Turton's avatar
Neil Turton committed
1759 1760 1761 1762
        LDR     r1, =IOMD_MonitorType   ; check link bit again
        LDRB    r1, [r1]                ; no need to preload bus, since should
        TST     r1, #IOMD_ProtectionLinkBit ; be still there from earlier
        BEQ     %FT75                   ; zero => protected
1763
      ]
1764
 ]
Neil Turton's avatar
Neil Turton committed
1765 1766 1767 1768 1769 1770


; if any monitor key pressed, reconfigure, otherwise hang around for a bit
; till keys get a chance to come in again after being reset for the umpteenth
; time by yet another keyboard handler! SKS 07-Jun-88

Jeffrey Lee's avatar
Jeffrey Lee committed
1771
        LDR     r3, =ZeroPage
Neil Turton's avatar
Neil Turton committed
1772
        LDR     r3, [r3, #MetroGnome]
1773 1774 1775 1776
 [ EmulatorSupport
        ARM_on_emulator r0
        ADDEQ   r3, r3, #1
        ADDNE   r3, r3, #10             ; Hang about for a little while
Neil Turton's avatar
Neil Turton committed
1777
 |
Neil Turton's avatar
Neil Turton committed
1778
        ADD     r3, r3, #10             ; Hang about for a little while
Neil Turton's avatar
Neil Turton committed
1779
 ]
Neil Turton's avatar
Neil Turton committed
1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818

KeypadStar_key  * -92

HorologicalDelayLoop1
        MOV     r0, #&79                        ; scan keyboard
        MOV     r1, #&FF                        ; starting at (&FF + 1) AND &FF
60
        ADD     r1, r1, #1
        AND     r1, r1, #&FF
        SWI     XOS_Byte
        TEQ     r1, #&FF                        ; if no key down
        BEQ     %FT70                           ; then check if we've run out of time

        ADR     r2, MonitorKeypadTable
62
        LDRB    r14, [r2], #2                   ; search for key in table
        TEQ     r14, #&FF
        BEQ     %FT70
        TEQ     r1, r14
        BNE     %BT62
        LDRB    r3, [r2, #-1]                   ; get corresponding CMOS bits
        MOV     r0, #ReadCMOS
        MOV     r1, #VduCMOS
        SWI     XOS_Byte
        BIC     r2, r2, #MonitorTypeBits
        ORR     r2, r2, r3
        MOV     r0, #WriteCMOS
        SWI     XOS_Byte

        TEQ     r3, #MonitorTypeAuto            ; if we're setting monitortype auto
        BNE     %FT64
        ADRL    r0, ModeCMOSTable +8            ; then configure mode auto
        LDR     r2, [r0, #-8]                   ; (load auto value)
        BL      WriteMultiField
        ADRL    r0, SyncCMOSTable +8            ; and configure sync auto
        LDR     r2, [r0, #-8]                   ; (load auto value)
        BL      WriteMultiField

64
1819
    [ DoInitialiseMode :LOR: :LNOT: Embedded_UI
Neil Turton's avatar
Neil Turton committed
1820
        BL      InitialiseMode
Neil Turton's avatar
Neil Turton committed
1821

Neil Turton's avatar
Neil Turton committed
1822 1823
      [ International
        SWI     XOS_WriteI+10
Robert Sprowson's avatar
Robert Sprowson committed
1824 1825 1826
        BVS     %FT65
        BL      WriteS_Translated
        =       "MonType:Monitor type reconfigured",10,13,10,0
Neil Turton's avatar
Neil Turton committed
1827
        ALIGN
Robert Sprowson's avatar
Robert Sprowson committed
1828
65
Neil Turton's avatar
Neil Turton committed
1829 1830
      |
        SWI     XOS_WriteS
Robert Sprowson's avatar
Robert Sprowson committed
1831
        =       10,"Monitor type reconfigured",10,13,10,0
Neil Turton's avatar
Neil Turton committed
1832 1833
        ALIGN
      ]
Neil Turton's avatar
Neil Turton committed
1834
    ]
Neil Turton's avatar
Neil Turton committed
1835 1836 1837 1838 1839 1840
        B       %FT75

BranchThroughZeroInstruction2
 [ ProcessorVectors
        LDR     PC, .+ProcVec_Branch0
 |
1841
        B       .+Branch0_Trampoline
Neil Turton's avatar
Neil Turton committed
1842 1843
 ]

1844 1845
        LTORG

Neil Turton's avatar
Neil Turton committed
1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858
MonitorKeypadTable      ; internal key number, CMOS bits
        =       106, MonitorType0
        =       107, MonitorType1
        =       124, MonitorType2
        =       108, MonitorType3
        =       122, MonitorType4
        =       123, MonitorType5
        =       26,  MonitorType6
        =       27,  MonitorType7
        =       42,  MonitorType8
        =       43,  MonitorType9
        =       76,  MonitorTypeAuto    ; keypad dot
        =       &FF
Neil Turton's avatar
Neil Turton committed
1859 1860
        ALIGN 32

Robert Sprowson's avatar
Robert Sprowson committed
1861 1862 1863 1864 1865 1866
      [ International
MessageFileName DCB     "Resources:$.Resources.Kernel.Messages",0
        ALIGN
      ]

 [ StrongARM :LAND: :LNOT: HAL
Neil Turton's avatar
Neil Turton committed
1867 1868 1869 1870 1871 1872
cputable
        DCD &6000,0,0
        DCD &6100,1,0
        DCD &7000,2,0
        DCD &7100,3,0
        DCD &8100,4,2_11101
1873
        DCD &a100,5,2_11011 ;corrected for 3.71 (SA does not abort for vector reads in 26-bit mode)
1874 1875
        DCD &7500,6,0
        DCD &7501,7,0
Neil Turton's avatar
Neil Turton committed
1876 1877 1878
        DCD -1

Processor_Type
1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892
        MOV     r0,#IOMD_Base
        LDRB    r1,[r0,#IOMD_ID0]
        CMP     r1,#&E7
        LDRB    r1,[r0,#IOMD_ID1]
        CMPEQ   r1,#&D4
        BEQ     PT_RiscPC               ; E7,D4 means Risc PC
        CMP     r1,#&5B
        MOVEQ   r0,#&7500               ; 5B means 7500
        BEQ     PT_lookup
        CMP     r1,#&AA
        MOVEQ   r0,#&7500
        ORREQ   r0,r0,#&0001            ; AA means 7500FE - mark as 7501
        BEQ     PT_lookup
PT_RiscPC
Neil Turton's avatar
Neil Turton committed
1893 1894 1895 1896 1897
        ReadCop  R0,CR_ID               ; see data sheets for values
        ; ARM 600 funny
        TST     R0,#&f000
        MOVEQ   R0,R0, LSL #4
        AND     R0,R0,#&ff00
1898
PT_lookup
Neil Turton's avatar
Neil Turton committed
1899 1900 1901 1902 1903
        ADR     R1,cputable
66
        LDR     R2,[R1],#4
        TEQ     R2,#0
        MOVMI   R0,#0
1904
        STRMI   R2,[R0,#ProcessorType]
Neil Turton's avatar
Neil Turton committed
1905 1906 1907 1908 1909 1910 1911
        MOVMI   PC,LR
        TEQ     R2,R0
        ADDNE   R1,R1,#8
        BNE     %BT66
        LDMIA   R1,{R0,R2}
        MOV     R1,#0
        STRB    R0,[R1,#ProcessorType]
1912
        STR     R2,[R1,#ProcessorFlags]
Neil Turton's avatar
Neil Turton committed
1913 1914 1915
        MOV     PC,LR
 ]

Neil Turton's avatar
Neil Turton committed
1916
70
Jeffrey Lee's avatar
Jeffrey Lee committed
1917
        LDR     r14, =ZeroPage
Neil Turton's avatar
Neil Turton committed
1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964
        LDR     r14, [r14, #MetroGnome]
        CMP     r14, r3
        BLO     HorologicalDelayLoop1
75


; Deal with SHIFT pressed/SHIFT-BREAK configured:
; do appropriate FSControl if wanted

        Pull    "R0"                    ; first check kbd there

        CMP     R0, #0
        BEQ     AutoBootCosNoKbd

        MOV     R0, #&FF
        MOV     R1, #0
        MOV     R2, #&FF                ; read shifty state
        SWI     XOS_Byte
        AND     R0, R1, #8              ; picka da bit
        EOR     R0, R0, #8              ; invert sense
        Pull    "R1"
        CMP     R1, #0
        MOVNE   R1, #8
        EORS    R1, R1, R0
        BEQ     %FT80

Hortoculture_Kicking
        MOV     R0, #FSControl_BootupFS
        SWI     XOS_FSControl
        BVC     %FT80

        Push    "r3,r4"
        ADD     r1, r0, #4              ; Set Boot$Error if it failed (Desktop will report it).
        ADR     r0, str_booterror
        MOV     r2, #1024               ; Big enough that terminator will be reached.
        MOV     r3, #0
        MOV     r4, #VarType_String
        SWI     XOS_SetVarVal
        SUBVS   r0, r1, #4              ; If setting Boot$Error failed then report original error as before.
        BLVS    PrintError
        SWIVS   XOS_NewLine
        Pull    "r3,r4"
80
; if either * pressed, drop into * prompt, otherwise hang around for a bit
; till keys get a chance to come in again after being reset for the umpteenth
; time by yet another keyboard handler! SKS 01-Jun-88

Jeffrey Lee's avatar
Jeffrey Lee committed
1965
        LDR     r3, =ZeroPage
Neil Turton's avatar
Neil Turton committed
1966
        LDR     r3, [r3, #MetroGnome]
1967 1968 1969 1970 1971
 [ EmulatorSupport
        ARM_on_emulator r1
        ADDEQ   r3, r3, #1
        ADDNE   r3, r3, #10             ; Hang about for a little while
 |
Neil Turton's avatar
Neil Turton committed
1972
        ADD     r3, r3, #10             ; Hang about for a little while
Neil Turton's avatar
Neil Turton committed
1973
 ]
Neil Turton's avatar
Neil Turton committed
1974 1975 1976 1977 1978 1979

HorologicalDelayLoop2
        MOV     r1, #KeypadStar_key :AND: &FF
        BL      IsKeyPressedAtReset
        BEQ     DoStartSuper            ; EQ -> start up supervisor

Jeffrey Lee's avatar
Jeffrey Lee committed
1980
        LDR     r0, =ZeroPage
Neil Turton's avatar
Neil Turton committed
1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008
        LDR     r0, [r0, #MetroGnome]
        CMP     r0, r3
        BLO     HorologicalDelayLoop2


; Start configured language module if keypad-* wasn't pressed

        MOV     R0, #ReadCMOS
        MOV     R1, #LanguageCMOS
        SWI     XOS_Byte

        MOV     R0, #ModHandReason_GetNames
        SUB     R1, R2, #1
        MOV     R2, #0                  ; preferred incarnation
        SWI     XOS_Module
        ADRVSL  R3, UtilityMod
        LDR     R2, [R3, #Module_Title]
        CMP     R2, #0
        ADDNE   R1, R3, R2
DoStartSuper
        ADREQL  R1, UtilModTitle        ; ALWAYS enter via SWI: sets CAO etc.
        MOV     R0, #ModHandReason_Enter
        ADRL    R2, crstring            ; no environment
        SWI     XOS_Module
        CMP     r0, r0                  ; set EQ if failed to enter config.lang
        B       DoStartSuper            ; -> force Super entry


Jeffrey Lee's avatar
Jeffrey Lee committed
2009
str_booterror   DCB     "Boot$$Error",0
Neil Turton's avatar
Neil Turton committed
2010 2011 2012 2013
                ALIGN


AutoBootCosNoKbd
2014
    [ :LNOT: Embedded_UI
Neil Turton's avatar
Neil Turton committed
2015 2016
      [ International
        SWI     XOS_WriteI+7
Robert Sprowson's avatar
Robert Sprowson committed
2017 2018
        BVS     %FT81
        BL      WriteS_Translated
Neil Turton's avatar
Neil Turton committed
2019 2020
        =       "NoKbd:No keyboard present - autobooting", 10,13,0
        ALIGN
Robert Sprowson's avatar
Robert Sprowson committed
2021
81
Neil Turton's avatar
Neil Turton committed
2022 2023 2024 2025 2026
      |
        SWI     XOS_WriteS
        =       7, "No keyboard present - autobooting", 10,13,0
        ALIGN
      ]
Neil Turton's avatar
Neil Turton committed
2027
    ]
Neil Turton's avatar
Neil Turton committed
2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043
        B       Hortoculture_Kicking


RealIRQHandler
 [ ProcessorVectors
        LDR     PC, .-&18+ProcVec_IRQ
 |
        B     Initial_IRQ_Code+.-&18
 ]

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; In    r1 = INKEY -ve key code to look for

; Out   EQ: key pressed
;       NE: key not pressed

2044
IsKeyPressedAtReset Entry "r0-r2"
Neil Turton's avatar
Neil Turton committed
2045 2046 2047 2048 2049 2050 2051 2052 2053

        MOV     r0, #129
        MOV     r2, #&FF
        SWI     XOS_Byte
        TEQ     r1, #&FF
        TEQEQ   r2, #&FF
        EXIT

        END