NewReset 36.8 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
KbdScanActive   # 1
                # 2
KbdFlags        # 4
Neil Turton's avatar
Neil Turton committed
30

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

Kevin Bracey's avatar
Kevin Bracey committed
33
        ASSERT  @ <= ?InitIRQWs
Neil Turton's avatar
Neil Turton committed
34 35 36 37 38 39 40 41 42


; 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!)

43
GetConfiguredSize Entry "r1"
Jeffrey Lee's avatar
Jeffrey Lee committed
44
        LDR     r1, =ZeroPage
Neil Turton's avatar
Neil Turton committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58
        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

59 60 61 62 63
; 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
64 65
FudgeConfigureRMA
        Push    lr
Jeffrey Lee's avatar
Jeffrey Lee committed
66
        LDR     R10, =ZeroPage
Neil Turton's avatar
Neil Turton committed
67 68 69 70 71 72
        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
73
        LDR     r4, =ZeroPage+FreePoolDANode
74 75
        LDR     r7, [r4, #DANode_PMP]
        LDR     r8, [r4, #DANode_PMPSize]
Neil Turton's avatar
Neil Turton committed
76
10
77 78 79 80 81 82 83
        CMP     r8, #0                          ; if no free memory left
        BEQ     %FT20                           ; then tidy up
        SUB     r8, r8, #1                      ; move free pool pointer backwards
        MOV     lr, #-1
        LDR     r2, [r7, r8, LSL #2]
        STR     lr, [r7, r8, LSL #2]
        BL      Call_CAM_Mapping
Neil Turton's avatar
Neil Turton committed
84 85 86 87 88
        ADD     r3, r3, r10                     ; advance "to" pointer
        ADD     r5, r5, r10                     ; one more page done
        SUBS    r0, r0, r10
        BNE     %BT10
20
89
        STR     r8, [r4, #DANode_PMPSize]
Neil Turton's avatar
Neil Turton committed
90 91 92 93
NoMoreMemory
        STR     R5, [R1]
        Pull    "PC"

94
; MassageScreenSize - called from screen DA creation and ReadSysInfo
Neil Turton's avatar
Neil Turton committed
95 96

MassageScreenSize ROUT
Kevin Bracey's avatar
Kevin Bracey committed
97
        Push    lr
Jeffrey Lee's avatar
Jeffrey Lee committed
98
        LDR     lr, =ZeroPage
99 100 101 102
        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
103 104
        Pull    pc, NE

Neil Turton's avatar
Neil Turton committed
105 106
        CMP     r0, #0
        BNE     CmosScreenWillDo
Jeffrey Lee's avatar
Jeffrey Lee committed
107 108 109
      [ ZeroPage <> 0
        LDR     r0, =ZeroPage
      ]
Neil Turton's avatar
Neil Turton committed
110 111 112 113 114 115 116 117 118 119
        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
120
        Pull    pc
Neil Turton's avatar
Neil Turton committed
121 122 123

        LTORG

124 125
    ! 0, "*** DUMMY CONT_Break, soft breaks/resets will not work yet with HAL"
CONT_Break
126
        AddressHAL
127
        MOV     a1, #1
128
        LDR     a2, =L1PT
129
        CallHAL HAL_Reset
130

131 132
Continue_after_HALInit

Neil Turton's avatar
Neil Turton committed
133 134 135 136 137 138
;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
139 140 141 142 143 144 145 146

; 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
147
        LDR     R1, =ZeroPage+ProcVec_Start
Neil Turton's avatar
Neil Turton committed
148 149 150 151 152 153 154 155 156 157
        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
158 159
        LDR     R0, =ZeroPage+4
        LDR     R3, =ZeroPage+EndMOSROMVecs-MOSROMVecs
Neil Turton's avatar
Neil Turton committed
160 161 162 163

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
164
        TEQ     R0, R3
Neil Turton's avatar
Neil Turton committed
165 166
        BNE     %BT40

Kevin Bracey's avatar
Kevin Bracey committed
167 168
        ChangedProcVecs r0

Neil Turton's avatar
Neil Turton committed
169
 [ CacheCMOSRAM
Kevin Bracey's avatar
Kevin Bracey committed
170
        DebugTX "InitCMOSCache entry"
Neil Turton's avatar
Neil Turton committed
171
        BL      InitCMOSCache           ; initialise cache of CMOS RAM
Kevin Bracey's avatar
Kevin Bracey committed
172
        DebugTX "InitCMOSCache done"
173
        TEQ     R0, #0                  ; returns zero on failure
Jeffrey Lee's avatar
Jeffrey Lee committed
174 175 176
      [ ZeroPage <> 0
        LDREQ   R0, =ZeroPage
      ]
177 178 179
        LDREQ   R1, [R0, #HAL_StartFlags]
        ORREQ   R1, R1, #OSStartFlag_NoCMOS
        STREQ   R1, [R0, #HAL_StartFlags]
Neil Turton's avatar
Neil Turton committed
180 181 182
 ]

; Now copy the initialised data
Jeffrey Lee's avatar
Jeffrey Lee committed
183
        LDR     R0, =ZeroPage+IRQ1V
Neil Turton's avatar
Neil Turton committed
184 185 186 187 188 189 190 191 192

; 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
193
        LDR     R3, =ZeroPage+(EndData-StartData+IRQ1V)
Neil Turton's avatar
Neil Turton committed
194 195 196
DatCopy
        LDR     R2, [R1], #4
        STR     R2, [R0], #4
Jeffrey Lee's avatar
Jeffrey Lee committed
197
        TEQ     R0, R3
Neil Turton's avatar
Neil Turton committed
198 199 200
        BNE     DatCopy

        ADR     r2, CONT_Break
Jeffrey Lee's avatar
Jeffrey Lee committed
201
        LDR     r0, =ZeroPage
Neil Turton's avatar
Neil Turton committed
202 203
        STR     r2, [r0, #ResetIndirection]

Jeffrey Lee's avatar
Jeffrey Lee committed
204 205
        MOV     r3, #0                  ; initialise abort list
        STR     r3, [r0, #AbortIndirection]
Neil Turton's avatar
Neil Turton committed
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224

; 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
225 226
        LDR     R1, [R1]
        STR     R1, [R0]
Neil Turton's avatar
Neil Turton committed
227

Robert Sprowson's avatar
Robert Sprowson committed
228
; conversion SWIs all go through same despatch point
Neil Turton's avatar
Neil Turton committed
229 230
        LDR     R0, =SvcTable
        ADRL    R1, despatchConvert
Robert Sprowson's avatar
Robert Sprowson committed
231 232 233
        STR     R1, [R0, #OS_ConvertStandardDateAndTime * 4]
        STR     R1, [R0, #OS_ConvertDateAndTime * 4]

Neil Turton's avatar
Neil Turton committed
234 235 236 237
        MOV     R2, #OS_ConvertHex1
conversionSWIfill
        STR     R1, [R0, R2, LSL #2]
        ADD     R2, R2, #1
Robert Sprowson's avatar
Robert Sprowson committed
238 239
        CMP     R2, #OS_ConvertVariform
        BLS     conversionSWIfill
Neil Turton's avatar
Neil Turton committed
240

241 242 243
; 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
244
        LDR     r0, =ZeroPage
245
        ARMop   IMB_Full,,,r0
Kevin Bracey's avatar
Kevin Bracey committed
246
        DebugTX "IMB_Full done"
Neil Turton's avatar
Neil Turton committed
247

248 249 250 251 252 253 254
      [ CacheablePageTables
; If we want cacheable page tables, now is a good time to enable them
; (can't easily enable them earlier on due to the page tables being temporarily
; doubly-mapped during MMU init)
        BL      MakePageTablesCacheable
      ]

Neil Turton's avatar
Neil Turton committed
255 256
; Initialise CAO ptr to none.

Jeffrey Lee's avatar
Jeffrey Lee committed
257
        LDR     R0, =ZeroPage
258
        LDR     R1, =DuffEntry          ; nothing will be here!!
Neil Turton's avatar
Neil Turton committed
259 260
        STR     R1, [R0, #Curr_Active_Object]

Neil Turton's avatar
Neil Turton committed
261
KeyWait * 200000                 ; 1/5 sec wait (in microseconds)
262
us      * 1
Neil Turton's avatar
Neil Turton committed
263

264 265
        AddressHAL
        MOV     r6, #25                 ; Check for keyboard 25 times (5 secs max).
Jeffrey Lee's avatar
Jeffrey Lee committed
266
        LDR     r4, =ZeroPage+InitIRQWs
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281

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

        TST     r0, #KbdFlag_Done
        BNE     kbddone

        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
282
        LDR     r1, =ZeroPage+InitIRQWs
283 284 285
        MOV     r0, #0
        STRB    r0, [r1, #KbdScanActive]
        MSR     CPSR_c, #SVC32_mode
Jeffrey Lee's avatar
Jeffrey Lee committed
286
        DebugTX "Keyboard scan complete"
Neil Turton's avatar
Neil Turton committed
287

288
 [ ValidateCMOS
Neil Turton's avatar
Neil Turton committed
289
; Do a POR if some super-critical values are shagged or if checksum is invalid.
290
        MOV     R3, #-1                 ; do all RAM if we do any
Neil Turton's avatar
Neil Turton committed
291
        BL      ValChecksum             ; Always check the checksum
292
        BNE     cmos_reset
293 294
 ]

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

Jeffrey Lee's avatar
Jeffrey Lee committed
298
        LDR     R0, =ZeroPage+HAL_StartFlags
299
        LDR     R1, [R0]
300
        TST     R1, #OSStartFlag_NoCMOS ; If no CMOS, reset for sensible cache
Kevin Bracey's avatar
Kevin Bracey committed
301
        BNE     cmos_reset
302
        TST     R1, #OSStartFlag_POR
303
        BEQ     no_cmos_reset           ; not a power on reset
304
        DebugTX "POR detected"
305 306 307 308 309
        TST     R1, #OSStartFlag_NoCMOSReset
        BNE     no_cmos_reset
        TST     R1, #OSStartFlag_CMOSReset
        BNE     cmos_reset

Jeffrey Lee's avatar
Jeffrey Lee committed
310
        LDR     R0, =ZeroPage+InitIRQWs
311 312
        LDR     R7, [R0, #KbdFlags]
        TST     R7, #KbdFlag_R:OR:KbdFlag_T:OR:KbdFlag_Delete:OR:KbdFlag_Copy
Robert Sprowson's avatar
Robert Sprowson committed
313 314 315
        LDRNE   R3, =ZeroPage
        MOVNE   R14, #1
        STRNEB  R14, [R3, #MentionCMOSReset]
Neil Turton's avatar
Neil Turton committed
316 317 318
        BEQ     no_cmos_reset           ; power on bit checked again there

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

321
        TST     R7, #KbdFlag_Copy:OR:KbdFlag_Delete
Neil Turton's avatar
Neil Turton committed
322 323 324 325 326
        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
327
    ]
Neil Turton's avatar
Neil Turton committed
328
cmos_reset
329
        DebugTX "Reset CMOS"
Robert Sprowson's avatar
Robert Sprowson committed
330
        ADD     sp, sp, #4              ; junk CannotReset flag from stack
Neil Turton's avatar
Neil Turton committed
331

Robert Sprowson's avatar
Robert Sprowson committed
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
        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
355 356

; IF R or Delete pressed THEN set sync 0 ELSE set sync Auto
Jeffrey Lee's avatar
Jeffrey Lee committed
357
        LDR     R0, =ZeroPage+InitIRQWs
358 359
        LDR     R1, [R0, #KbdFlags]
        TST     R1, #KbdFlag_R:OR:KbdFlag_Delete
Neil Turton's avatar
Neil Turton committed
360 361 362 363 364
        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
365 366
    [ ChecksumCMOS
        BL      MakeChecksum            ; create a valid checksum
367
    ]
Robert Sprowson's avatar
Robert Sprowson committed
368
        B       hard_reset              ; CMOS reset only checked on power on, so was hard
Neil Turton's avatar
Neil Turton committed
369 370 371 372 373 374 375 376 377 378 379 380 381 382

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

hard_reset
hard_reset_forced
383
        LDR     r8, =ZeroPage
Neil Turton's avatar
Neil Turton committed
384 385 386

        Pull    "R2"                    ; discard old IOC state

387
        DebugTX "InitDynamicAreas"
Neil Turton's avatar
Neil Turton committed
388 389 390 391 392 393

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

        BL      InitDynamicAreas

394 395 396 397 398
; RMA
        Push    "r0-r12"
        MOV     r1, #ChangeDyn_RMA      ; Area number
        MOV     r2, #4096               ; Initial size
        MOV     r3, #RMAAddress         ; Base address
399
        MOV     r4, #AreaFlags_RMA      ; Area flags
400 401 402 403 404 405 406 407
        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
408
; Screen
Neil Turton's avatar
Neil Turton committed
409 410 411 412
        Push    "r0-r12"
        MOV     r0, #ScreenSizeCMOS
        BL      Read

Jeffrey Lee's avatar
Jeffrey Lee committed
413
        LDR     r5, =ZeroPage
Neil Turton's avatar
Neil Turton committed
414 415
        LDR     r10, [r5, #Page_Size]   ; needed by MassageScreenSize
        MUL     r0, r10, r0             ; convert to bytes
416 417 418
        LDR     r5, [r5, #VideoSizeFlags] ; maximum size
        MOV     r5, r5, LSR #12
        MOV     r5, r5, LSL #12
Neil Turton's avatar
Neil Turton committed
419 420 421 422
        BL      MassageScreenSize

        MOV     r1, #ChangeDyn_Screen   ; area number
        MOV     r2, r0                  ; initial size
Kevin Bracey's avatar
Kevin Bracey committed
423
        MOV     r3, #-1                 ; Base address dynamic
424
        LDR     r4, =AreaFlags_Screen   ; area flags
Neil Turton's avatar
Neil Turton committed
425 426 427 428 429 430 431
        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
432
        STR     r3, [r7, #ScreenEndAddr]
Neil Turton's avatar
Neil Turton committed
433 434
        Pull    "r0-r12"

Kevin Bracey's avatar
Kevin Bracey committed
435
; SpriteArea
Neil Turton's avatar
Neil Turton committed
436 437
        Push    "r0-r12"
        MOV     r0, #0                  ; initialise SpriteSize to zero
Jeffrey Lee's avatar
Jeffrey Lee committed
438
      [ ZeroPage = 0
Neil Turton's avatar
Neil Turton committed
439
        STR     r0, [r0, #SpriteSize]   ; (fixes bug MED-00811)
Jeffrey Lee's avatar
Jeffrey Lee committed
440 441 442 443
      |
        LDR     r1, =ZeroPage
        STR     r0, [r1, #SpriteSize]   ; (fixes bug MED-00811)
      ]
Neil Turton's avatar
Neil Turton committed
444 445 446 447 448 449

        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
450
        MOV     r4, #AreaFlags_Sprites  ; Area flags
451
        MOV     r5, #16*1024*1024       ; Maximum size (changed from -1, address space preservation)
Neil Turton's avatar
Neil Turton committed
452 453 454 455 456 457 458
        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
459
; RAMDisc
Neil Turton's avatar
Neil Turton committed
460 461 462 463
        Push    "r0-r12"

        MOV     r1, #ChangeDyn_RamFS    ; Area number
        MOV     r3, #-1                 ; Base address dynamic
464 465 466
        ARM_read_ID r4
        AND     r4, r4, #&F000
        CMP     r4, #&A000
467 468
        MOVEQ   r4, #AreaFlags_RAMDisc_SA ; Area flags, if StrongARM  (introduced for Ursula)
        MOVNE   r4, #AreaFlags_RAMDisc  ; Area flags
469 470 471 472 473 474
      [ PMPRAMFS
        MOV     r5, #PMPRAMFS_Size*4096
        ORR     r4, r4, #DynAreaFlags_PMP
        MOV     r2, #0
        ORR     r4, r4, #DynAreaFlags_NeedsSpecificPages
        MOV     r9, #0
475
      |
476 477
        MOV     r0, #RAMDiscCMOS        ; find out how much RAM disc configured
        BL      GetConfiguredSize       ; in: r0 = CMOS address, out: r2 = size
478
        MOV     r5, #MaxRAMFS_Size*1024*1024      ; A trade off between nice big disc and complete waste of address space
479
      ]
Neil Turton's avatar
Neil Turton committed
480 481 482 483 484
        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!
485 486 487 488 489 490 491 492
      [ PMPRAMFS
        ; Currently, physical memory pools must be created with 0 size, then resized afterwards
        MOV     r0, #RAMDiscCMOS        ; find out how much RAM disc configured
        BL      GetConfiguredSize       ; in: r0 = CMOS address, out: r2 = size
        MOVS    r1, r2
        MOV     r0, #ChangeDyn_RamFS
        SWINE   XOS_ChangeDynamicArea
      ]
Neil Turton's avatar
Neil Turton committed
493 494
        Pull    "r0-r12"

Kevin Bracey's avatar
Kevin Bracey committed
495
; FontArea
Neil Turton's avatar
Neil Turton committed
496 497 498 499 500 501
        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
502
        MOV     r4, #AreaFlags_FontArea ; Area flags
Kevin Bracey's avatar
Kevin Bracey committed
503 504
        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
505 506 507 508 509 510 511
        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"

512
        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
513
        MOV     R3, #32*1024            ; aplwork start
Jeffrey Lee's avatar
Jeffrey Lee committed
514
        LDR     R1, =ZeroPage+AplWorkSize ; aplwork size
515
        MOV     r11, #AreaFlags_AppSpace
516
        BL      FudgeConfigureRMA       ; put some memory in aplspace
Neil Turton's avatar
Neil Turton committed
517

Jeffrey Lee's avatar
Jeffrey Lee committed
518
        LDR     R0, =ZeroPage
Neil Turton's avatar
Neil Turton committed
519 520 521 522 523
        LDR     R1, [R0, #AplWorkSize]
        ADD     R1, R1, #32*1024
        STR     R1, [R0, #AplWorkSize]
        STR     R1, [R0, #MemLimit]

524
        DebugTX "InitVectors"
Neil Turton's avatar
Neil Turton committed
525 526
        BL      InitVectors               ; ready for OsByte to read mode

Jeffrey Lee's avatar
Jeffrey Lee committed
527 528 529 530 531
        LDR     R1, =ZeroPage+ModuleSWI_HashTab
        MOV     R2, #ModuleSHT_Entries
      [ ZeroPage <> 0
        MOV     R0, #0
      ]
Neil Turton's avatar
Neil Turton committed
532 533
clearmswis
        SUBS    R2, R2, #1
Jeffrey Lee's avatar
Jeffrey Lee committed
534 535 536 537 538 539
        STR     R0, [R1, R2, LSL #2]
        BGT     clearmswis

      [ ZeroPage <> 0
        LDR     R2, =ZeroPage
      ]
Neil Turton's avatar
Neil Turton committed
540 541 542

     [  International
        MOV     R1, #-1                                 ; We don't have a message file yet !
Jeffrey Lee's avatar
Jeffrey Lee committed
543 544
        STRB    R1, [R2, #ErrorSemaphore]               ; Don't translate errors.
        STR     R0, [R2, #KernelMessagesBlock]          ; No message file open.
545
      [ CacheCommonErrors
Jeffrey Lee's avatar
Jeffrey Lee committed
546
        STR     R0, [R2, #CachedErrorBlocks]            ; No cached errors
547
      ]
Neil Turton's avatar
Neil Turton committed
548 549
     ]

Jeffrey Lee's avatar
Jeffrey Lee committed
550
        LDR     R0, =ZeroPage+HAL_StartFlags
551 552
        LDR     R1, [R0]
        TST     R1, #OSStartFlag_POR
Kevin Bracey's avatar
Kevin Bracey committed
553 554 555 556

        ; 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
557
        LDREQ   R0, =ZeroPage+OsbyteVars + :INDEX: LastBREAK
Neil Turton's avatar
Neil Turton committed
558 559
        LDREQB  R0, [R0]
        TSTEQ   R0, #&80                ; tbs set if memory cleared
Kevin Bracey's avatar
Kevin Bracey committed
560
 ]
Neil Turton's avatar
Neil Turton committed
561 562 563 564 565
        MOVNE   R0, #PowerOnReset
        MOVEQ   R0, #ControlReset


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

Jeffrey Lee's avatar
Jeffrey Lee committed
570
        LDR     R1, =ZeroPage+InitIRQWs
571 572 573
        LDR     R0, [R1, #KbdFlags]
        AND     R1, R0, #KbdFlag_Shift
        AND     R0, R0, #KbdFlag_Present
Neil Turton's avatar
Neil Turton committed
574 575
        Push    "R0, R1"                ; save until after MOSInit

576
        DebugTX "InitIRQ1"
577
        BL      InitialiseIRQ1Vtable
Neil Turton's avatar
Neil Turton committed
578

Jeffrey Lee's avatar
Jeffrey Lee committed
579
        LDR     R3, =ZeroPage
Neil Turton's avatar
Neil Turton committed
580
        ADRL    R1, Default_PIRQHandler_Node
Jeffrey Lee's avatar
Jeffrey Lee committed
581 582
        STR     R1, [R3, #PIRQ_Chain]
        STR     R1, [R3, #PFIQasIRQ_Chain]
Neil Turton's avatar
Neil Turton committed
583 584 585
 ASSERT Default_PFIQasIRQHandler_Node = Default_PIRQHandler_Node

        MOV     R0, #0                  ; put in IRQ handler, word at 0
Jeffrey Lee's avatar
Jeffrey Lee committed
586 587 588
        STRB    r0, [r3, #FIQclaim_interlock]
        STRB    r0, [r3, #CallBack_Flag]
        STR     r0, [r3, #CallBack_Vector]
Neil Turton's avatar
Neil Turton committed
589

590 591 592 593 594 595 596
; 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
597
        LDRVC   R0, =ZeroPage
598 599
        STRVC   R2, [R0, #ProcVec_Branch0]

Neil Turton's avatar
Neil Turton committed
600 601 602 603 604 605
        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
606
        LDR     R2, =ZeroPage+InitIRQWs                 ; clear temp ws
607 608 609 610
        MOV     R3, #0
        MOV     R4, #0
        STMIA   R2!, {R3,R4}
        STMIA   R2!, {R3,R4}
611
        DebugTX "IMB_Full"
612

613 614 615 616
   ;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
617
        ChangedProcVecs r0
Jeffrey Lee's avatar
Jeffrey Lee committed
618
        LDR     r0,=ZeroPage
Neil Turton's avatar
Neil Turton committed
619

Neil Turton's avatar
Neil Turton committed
620 621
        MOV     R1, #&100
        STR     R1, [R0, #RCLimit]
Jeffrey Lee's avatar
Jeffrey Lee committed
622 623 624
        MOV     R1, #0
        STR     R1, [R0, #ReturnCode]
        STR     R1, [R0, #TickNodeChain]
Neil Turton's avatar
Neil Turton committed
625

626
; clear the keyboard workspace (tidy!)
Jeffrey Lee's avatar
Jeffrey Lee committed
627
        ADD     R0, R0, #&1C
Kevin Bracey's avatar
Kevin Bracey committed
628
        MOV     R2, #InitWsEnd - &1C
629 630
        BL      memset

Neil Turton's avatar
Neil Turton committed
631 632 633 634
;now put in error handler and escape handler
        BL      DEFHAN
        BL      DEFHN2
        MOV     R0, #ExceptionDumpArea
Jeffrey Lee's avatar
Jeffrey Lee committed
635
        LDR     R1, =ZeroPage+DUMPER
Neil Turton's avatar
Neil Turton committed
636 637 638
        SWI     XOS_ChangeEnvironment

        VDWS    WsPtr                   ; main MOS initialisation
639
        DebugTX "VduInit"
Neil Turton's avatar
Neil Turton committed
640
        BL      VduInit
641
        DebugTX "ExecuteInit"
Neil Turton's avatar
Neil Turton committed
642
        BL      ExecuteInit
643
        DebugTX "KeyInit"
Neil Turton's avatar
Neil Turton committed
644
        BL      KeyInit
645
        DebugTX "MouseInit"
Neil Turton's avatar
Neil Turton committed
646
        BL      MouseInit
647
        DebugTX "OscliInit"
Neil Turton's avatar
Neil Turton committed
648 649
        BL      OscliInit               ; before initialising modules

650
        DebugTX "Enabling IRQs"
Kevin Bracey's avatar
Kevin Bracey committed
651
        WritePSRc SVC_mode, R14         ; enable IRQs
652
        DebugTX "IRQs on"
Neil Turton's avatar
Neil Turton committed
653

Kevin Bracey's avatar
Kevin Bracey committed
654 655 656
 [ DebugTerminal
        MOV     R0, #RdchV
        ADRL    R1, DebugTerminal_Rdch
Jeffrey Lee's avatar
Jeffrey Lee committed
657
        LDR     R2, =ZeroPage
Kevin Bracey's avatar
Kevin Bracey committed
658 659 660 661 662
        LDR     R2, [R2, #HAL_Workspace]
        SWI     XOS_Claim
        MOV     R0, #WrchV
        ADRL    R1, DebugTerminal_Wrch
        SWI     XOS_Claim
663
        DebugTX "Debug terminal on"
Kevin Bracey's avatar
Kevin Bracey committed
664 665
 ]

Neil Turton's avatar
Neil Turton committed
666 667 668 669 670 671 672 673 674 675 676
        BL      InitialiseMode          ; select correct screen mode, in case any
                                        ; module prints anything in initialisation

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

; HardResetPart2
677
        DebugTX "HAL_InitDevices"
Ben Avison's avatar
Ben Avison committed
678 679
        AddressHAL
        MOV     R0, #0
Jeffrey Lee's avatar
Jeffrey Lee committed
680
      [ ZeroPage = 0
Ben Avison's avatar
Ben Avison committed
681 682
        STR     R0, [R0, #DeviceCount]
        STR     R0, [R0, #DeviceTable]
Jeffrey Lee's avatar
Jeffrey Lee committed
683 684 685 686 687
      |
        LDR     R1, =ZeroPage
        STR     R0, [R1, #DeviceCount]
        STR     R0, [R1, #DeviceTable]
      ]
Ben Avison's avatar
Ben Avison committed
688
        CallHAL HAL_InitDevices         ; get HAL to register any devices it has
689
        BL      LookForHALCacheController
690
        DebugTX "InitVariables"
Neil Turton's avatar
Neil Turton committed
691
        BL      InitVariables
692
        DebugTX "AMBControl_Init"
Neil Turton's avatar
Neil Turton committed
693
        BL      AMBControl_Init         ; initialise AMBControl section
694
        DebugTX "ModuleInit"
Neil Turton's avatar
Neil Turton committed
695 696 697 698 699 700 701 702 703 704
        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
705
        LDR     R0, =ZeroPage
Neil Turton's avatar
Neil Turton committed
706
        LDR     R0, [R0, #Page_Size]
707
        MUL     R3, R0, R2              ; size spare wanted
Neil Turton's avatar
Neil Turton committed
708 709 710 711 712 713 714 715 716 717 718
        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

719 720 721
        ; Update RTC now all the modules are running
        SWI     XOS_ResyncTime

722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
        ; 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
737 738 739 740 741
  [ DebugROMInit
        SWI     XOS_WriteS
        =       "Service_PostInit",0
        SWI     XOS_NewLine
  ]
Neil Turton's avatar
Neil Turton committed
742 743 744 745
        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
746
; Changed to use OS_LeaveOS 16-Oct-02
Neil Turton's avatar
Neil Turton committed
747

Neil Turton's avatar
Neil Turton committed
748 749 750 751 752
  [ DebugROMInit
        SWI     XOS_WriteS
        =       "callbacks",0
        SWI     XOS_NewLine
  ]
Ben Avison's avatar
Ben Avison committed
753
        SWI     XOS_LeaveOS
Neil Turton's avatar
Neil Turton committed
754 755 756
        SWI     XOS_EnterOS             ; switch back to SVC mode (IRQs, FIQs enabled)
; end of added code

Jeffrey Lee's avatar
Jeffrey Lee committed
757 758
     [ International                    ; Open the kernel messages file.
        LDR     r0, =ZeroPage+KernelMessagesBlock+4
Neil Turton's avatar
Neil Turton committed
759 760 761 762
        ADR     r1, MessageFileName
        MOV     r2, #0                  ; Use file directly.
        SWI     XMessageTrans_OpenFile
        MOVVC   r0, #-1
Jeffrey Lee's avatar
Jeffrey Lee committed
763
      [ ZeroPage = 0
Neil Turton's avatar
Neil Turton committed
764
        STRVC   r0, [r0, #KernelMessagesBlock+1]  ; Message file is now open.
Jeffrey Lee's avatar
Jeffrey Lee committed
765 766 767
      |
        LDR     lr, =ZeroPage
        STRVC   r0, [lr, #KernelMessagesBlock]  ; Message file is now open.
Neil Turton's avatar
Neil Turton committed
768
      ]
Jeffrey Lee's avatar
Jeffrey Lee committed
769
     ]
Neil Turton's avatar
Neil Turton committed
770 771 772

SkipHardResetPart2                      ; code executed on all types of reset
      [ International
Jeffrey Lee's avatar
Jeffrey Lee committed
773
        LDR     r0, =ZeroPage
Neil Turton's avatar
Neil Turton committed
774 775
        LDR     r1, [r0, #KernelMessagesBlock] ; if we've managed to open message file
        TEQ     r1, #0
Jeffrey Lee's avatar
Jeffrey Lee committed
776
        ASSERT  (ZeroPage :AND: 255) = 0
Neil Turton's avatar
Neil Turton committed
777 778 779 780
        STRNEB  r0, [r0, #ErrorSemaphore] ; then allow errors to be translated
      ]

        BL      InitialiseMode
Robert Sprowson's avatar
Robert Sprowson committed
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803
        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
804 805 806 807
        SWI     XOS_WriteS
        =       10, "$SystemName ", 0   ; now RISC OS (no +) again
        ALIGN

Kevin Bracey's avatar
Kevin Bracey committed
808 809 810 811
        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
812 813 814

        LDR     R0, =ZeroPage
        LDR     R0, [R0, #RAMLIMIT]
Kevin Bracey's avatar
Kevin Bracey committed
815 816 817
        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
818 819 820 821 822 823 824
        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
825

826
        BL      ARM_PrintProcessorType
Neil Turton's avatar
Neil Turton committed
827

Robert Sprowson's avatar
Robert Sprowson committed
828
        MOV     r0, #0                  ; Set DomainId to 0 every reset
Jeffrey Lee's avatar
Jeffrey Lee committed
829
      [ ZeroPage = 0
Neil Turton's avatar
Neil Turton committed
830
        STR     r0, [r0, #DomainId]     ; before calling anyone
Jeffrey Lee's avatar
Jeffrey Lee committed
831 832 833 834
      |
        LDR     r1, =ZeroPage
        STR     r0, [r1, #DomainId]     ; before calling anyone
      ]
Neil Turton's avatar
Neil Turton committed
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857

; 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

        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!

858 859 860 861 862 863 864 865 866 867
; 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]
868 869 870 871
        LDR     r0, [r0, #FreePoolDANode+DANode_PMPSize]
        CMP     r0, #DynArea_PMP_BigPageCount
        MOVLO   r0, r0, LSL #12
        LDRHS   r0, =DynArea_PMP_BigByteCount
872 873 874 875 876 877 878
        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
879 880 881
        CMP     r1, #PowerOnReset
        BNE     %FT75

Jeffrey Lee's avatar
Jeffrey Lee committed
882
        LDR     r1, =ZeroPage+HAL_StartFlags
883 884 885
        LDR     r1, [r1]
        TST     r1, #OSStartFlag_NoCMOSReset
        BNE     %FT75
Neil Turton's avatar
Neil Turton committed
886 887 888 889 890

; 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
891
        LDR     r3, =ZeroPage
Neil Turton's avatar
Neil Turton committed
892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933
        LDR     r3, [r3, #MetroGnome]
        ADD     r3, r3, #10             ; Hang about for a little while

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
        BL      InitialiseMode
Neil Turton's avatar
Neil Turton committed
934

Neil Turton's avatar
Neil Turton committed
935 936
      [ International
        SWI     XOS_WriteI+10
Robert Sprowson's avatar
Robert Sprowson committed
937 938 939
        BVS     %FT65
        BL      WriteS_Translated
        =       "MonType:Monitor type reconfigured",10,13,10,0
Neil Turton's avatar
Neil Turton committed
940
        ALIGN
Robert Sprowson's avatar
Robert Sprowson committed
941
65
Neil Turton's avatar
Neil Turton committed
942 943
      |
        SWI     XOS_WriteS
Robert Sprowson's avatar
Robert Sprowson committed
944
        =       10,"Monitor type reconfigured",10,13,10,0
Neil Turton's avatar
Neil Turton committed
945 946 947 948 949 950 951
        ALIGN
      ]
        B       %FT75

BranchThroughZeroInstruction2
        LDR     PC, .+ProcVec_Branch0

952 953
        LTORG

Neil Turton's avatar
Neil Turton committed
954 955 956 957 958 959 960 961 962 963 964 965 966
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
967 968
        ALIGN 32

Robert Sprowson's avatar
Robert Sprowson committed
969 970 971 972 973
      [ International
MessageFileName DCB     "Resources:$.Resources.Kernel.Messages",0
        ALIGN
      ]

Neil Turton's avatar
Neil Turton committed
974
70
Jeffrey Lee's avatar
Jeffrey Lee committed
975
        LDR     r14, =ZeroPage
Neil Turton's avatar
Neil Turton committed
976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
        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
1023
        LDR     r3, =ZeroPage
Neil Turton's avatar
Neil Turton committed
1024 1025 1026 1027 1028 1029 1030 1031
        LDR     r3, [r3, #MetroGnome]
        ADD     r3, r3, #10             ; Hang about for a little while

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

Jeffrey Lee's avatar
Jeffrey Lee committed
1032
        LDR     r0, =ZeroPage
Neil Turton's avatar
Neil Turton committed
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048
        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
Robert Sprowson's avatar
Robert Sprowson committed
1049
        LDR     R2, [R3, #Module_TitleStr]
Neil Turton's avatar
Neil Turton committed
1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060
        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
1061
str_booterror   DCB     "Boot$$Error",0
Neil Turton's avatar
Neil Turton committed
1062 1063 1064 1065 1066 1067
                ALIGN


AutoBootCosNoKbd
      [ International
        SWI     XOS_WriteI+7
Robert Sprowson's avatar
Robert Sprowson committed
1068 1069
        BVS     %FT81
        BL      WriteS_Translated
Neil Turton's avatar
Neil Turton committed
1070 1071
        =       "NoKbd:No keyboard present - autobooting", 10,13,0
        ALIGN
Robert Sprowson's avatar
Robert Sprowson committed
1072
81
Neil Turton's avatar
Neil Turton committed
1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089
      |
        SWI     XOS_WriteS
        =       7, "No keyboard present - autobooting", 10,13,0
        ALIGN
      ]
        B       Hortoculture_Kicking


RealIRQHandler
        LDR     PC, .-&18+ProcVec_IRQ

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

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

1090
IsKeyPressedAtReset Entry "r0-r2"
Neil Turton's avatar
Neil Turton committed
1091 1092 1093 1094 1095 1096 1097 1098 1099

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

        END