InitDieSvc 28.7 KB
Newer Older
Neil Turton's avatar
Neil Turton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
; 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.
;
;>InitDieSvc

 TTL    "Initialisation, finalisation and service call handling"

; >>>>>>>>>
; InitEntry
; >>>>>>>>>

23
DirBufferName
24 25
        = "DirBuffer:%0 Dir Buffer",0
        ALIGN
26 27

MapArea = "MapArea:%0 Map (Drive %1)",0
28
        ALIGN
29

Neil Turton's avatar
Neil Turton committed
30 31 32 33 34 35 36 37 38
InitEntry ROUT          ; NO REENTRANCY CHECK NEEDED
        Push    "R7-R11,LR"

        ; Macro to disallow rip-off RAM loaded version (te he ;-)
        ChkKernelVersion

        ; Check if we're the base incarnation and return if we are
        CMPS    R11, #&3000000
        RSBLOS  LR, R11, #0
39
        BHS     %FT70
Neil Turton's avatar
Neil Turton committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

        ; Parameter is ascii string number which is address of
        ; parameter block higher up the stack which we passed
        ; to ourselves.
        MOV     R0, #16
        MOV     R1, R10
        SWI     XOS_ReadUnsigned
        BVS     %FT99
        MOV     R9, R2          ;ptr to stacked parameters

        ; Don't know what this faff's about
        MOV     R10,#1          ;init flag

        ; Save pointer to private word in r11 for use later
        MOV     R11, R12

        ; Pick up contents of parameter block
        LDMIA   R9, {R0-R6}
 [ Debug1
        DLINE   "Parameters read from supplied block:",cc
60
        DREG    R0,,cc
Neil Turton's avatar
Neil Turton committed
61 62 63 64 65 66 67 68
        DREG    R1," ",cc
        DREG    R2," ",cc
        DREG    R3," ",cc
        DREG    R4," ",cc
        DREG    R5," ",cc
        DREG    R6," "
 ]
        ; Split out Floppies and Winnies
69 70 71 72
        ASSERT  DriveConfig_FloppyCount_Shift = 0
        AND     R7, R3, #DriveConfig_FloppyCount_Mask   ;floppies
        MOV     R8, R3, LSR #DriveConfig_FixedDiscCount_Shift
        AND     R8, R8, #DriveConfig_FixedDiscCount_Mask; winnies
Neil Turton's avatar
Neil Turton committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133

        ; Lower bound the DirCache size
        CMPS    R4, #CacheMin
        MOVLO   R4, #CacheMin

        ; Evaluate:
        ; r1 = buffer space needed
        ; r2 = process block size
        MOVS    R1, R5, LSL #10 ;using file cache ?
        MOVEQ   R2, #ShortProcessBlk
        BEQ     %FT02           ;no file cache

        ADD     R1, R1, R5, LSL #(10-BufScale)  ;length of file buffers

        MOV     R2, #ProcessPairs+(ExtraPairs+1)*8
 [ {TRUE}
 ; if scatter entry extension disabled number of entries = buffers*4+extrapairs
        ADD     R2, R2, R5, LSL #3 + 2          ;length of process block
 |
        ADD     R2, R2, R5, LSL #3              ;length of process block
 ]

02
        ; Start accumulating in r3 the space needed:
        ; r3=buffer space + 1*process block(for the floppy)
        ADD     R3, R1, R2

        ; Add a process block for the Winnie(s) if needed
        TEQS    R8, #0          ;do we need winnie process block ?
        ADDNE   R3, R3, R2      ;total file cache space

        ; Add enough for the stuff below the DirCache
        MinOps  ADD, ADD, R3, R3, (:INDEX:DirCache)

        ; calc buffer hash table size and add it on (it's first power of 2 gt filecache buffer count)
        MOV     R0, #1
03
        CMPS    R0, R5
        MOVLO   R0, R0, LSL #1
        BLO     %BT03
        ADD     R3, R3, R0, LSL #2

        ;add space for Dir Cache
        ADD     R3, R3, R4

        ;add space for defect maps for all drives, +(4+floppies)*512
        ASSERT  SzDefectList = (1 :SHL: 9)
        ADD     R3, R3, #4 :SHL: 9              ; winnie defect maps
        ADD     R3, R3, R7, LSL #9              ; + floppy defect maps

        Push    "R0-R2"                 ;save file cache lengths

        ; Allocate the main workspace
        MOV     R0, #ModHandReason_Claim
        SWI     XOS_Module              ;claim workspace
        MOV     SB, R2

        ADDVS   SP, SP, #3*4
        BVS     %FT95
        Pull    "R0-R2"

134

Neil Turton's avatar
Neil Turton committed
135 136 137 138
        ; Attach main workspace to private word
        STR     SB, [R11]
        STR     R11, PrivateWord

139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
        Push    "r0-r2"
        MOV     r0, #6
        MOV     r1, #0
        MOV     r2, #OSRSI6_IRQsema
        SWI     XOS_ReadSysInfo
        MOVVS   r2, #0
        CMP     r2, #0
        LDREQ   r2, =Legacy_IRQsema
        STR     r2, ptr_IRQsema
        MOV     r0, #6
        MOV     r2, #OSRSI6_CannotReset
        SWI     XOS_ReadSysInfo
        MOVVS   r2, #0
        CMP     r2, #0
        LDREQ   r2, =Legacy_CannotReset
        STR     r2, ptr_CannotReset
        Pull    "r0-r2"

Neil Turton's avatar
Neil Turton committed
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
        sbaddr  R3, DirCache
 [ Debug1
        DREG    SB, "Static base:"
        DREG    R3, "Dir cache:"
 ]

        ; Skip the DirCache, now at file cache
        ADD     R3, R3, R4

 [ Debug1
        DREG    R3, "File cache low limit:"
 ]

        ; Skip file buffers
        ADD     R3, R3, R1

        ; Mark where the file buffers start at the moment
        STR     R3, FileBufsStart

        ; Mark where the file buffers end (also where the floppy process block is)
 [ Debug1
        DREG    R3, "Floppy process block:"
 ]
        STR     R3, FileBufsEnd
        ASSERT  FloppyProcessBlk=FileBufsEnd

        ; Initialise the floppy process block to be inactive
        MOV     R4, #Inactive
 [ DebugP
        DREG    r3, "Process ",cc
        DREG    r4, " going inactive with "
 ]
        STRB    R4, [R3,#Process]
        TEQ     R5, #0
        MOVNE   LR, #0
        STRNE   LR, [R3, #ProcessWriteBehindLeft]
        ASSERT  ProcessWriteBehindDrive :MOD: 4 = 0
        ASSERT  ProcessWriteBehindDisc = ProcessWriteBehindDrive + 1
        MOVNE   LR, #-1
        STRNE   LR, [R3,#ProcessWriteBehindDrive]

198
        ; Set up the Winnie process block (BadPtr used as 'bad process block' indicator')
Neil Turton's avatar
Neil Turton committed
199 200 201 202
        ; and initialise it to inactive if there're winnies present
        ADD     R3, R3, R2
        TEQS    R8, #0
        MOVNE   LR, R3
203
        MOVEQ   LR, #BadPtr
Neil Turton's avatar
Neil Turton committed
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 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
        STR     LR, WinnieProcessBlk
 [ Debug1
        Push    "R3"
        MOV     R3, LR
        DREG    R3, "Winnie process block:"
        Pull    "R3"
 ]
 [ DebugP
        DREG    r3, "Process ",cc
        DREG    r4, " going inactive with "
 ]
        STRNEB  R4, [R3,#Process]

        TEQNE   R5, #0
        MOVNE   LR, #0
        STRNE   LR, [R3,#ProcessWriteBehindLeft]
        ASSERT  ProcessWriteBehindDrive :MOD: 4 = 0
        ASSERT  ProcessWriteBehindDisc = ProcessWriteBehindDrive + 1
        MOVNE   LR, #-1
        STRNE   LR, [R3,#ProcessWriteBehindDrive]

        TEQ     r8, #0
        ADDNE   R3, R3, R2


        STRB    R5, MaxFileBuffers
        STRB    R5, UnclaimedFileBuffers

        ; Set up cache buffers and cache hash table
 [ Debug1
        DREG    R3, "Buffer hash table:"
 ]
        STR     R3, BufHash

        ; hash table
        SUB     R0, R0, #1
        STRB    R0, BufHashMask

        ADRL    LR, DummyBuf            ;initialise buffer hash table
05
        STR     LR, [R3], #4
        SUBS    R0, R0, #1
        BPL     %BT05

        ; cache buffers
        sbaddr  R0, BufChainsRoot
        MOV     R1, #6
08
        STR     R0, [R0,#YoungerBuf]
        STR     R0, [R0,#OlderBuf]
        ADD     R0, R0, #ChainRootSz
        SUBS    R1, R1, #1
        BNE     %BT08

        LDMIA   R9, {R0-R2,R4}
        ASSERT  ParentPrivate=ParentBase+4
        ASSERT  Floppies=ParentPrivate+4
        ASSERT  Winnies=Floppies+1
        ASSERT  Drive=Winnies+1
        ASSERT  StartUpOptions=Drive+1
264 265 266

 [ DynamicMaps

267 268
        ; with dynamic free space maps, we ignore WinnieSizes.  The maps
        ; are only allocated as and when they're needed.
269 270

        ADD     LR, SB, #:INDEX:ParentBase
271
        EOR     R4, R4, #4 :SHL: DriveConfig_DefaultDrive_Shift ;convert to internal drive numbering
272 273 274
        STMIA   LR, {R1,R2,R4}

 |
Neil Turton's avatar
Neil Turton committed
275 276
        ASSERT  WinnieSizes=StartUpOptions+1
        ADD     LR, SB, #:INDEX:ParentBase
277
        EOR     R4, R4, #4 :SHL: DriveConfig_DefaultDrive_Shift ;convert to internal drive numbering
Neil Turton's avatar
Neil Turton committed
278
        STMIA   LR, {R1,R2,R4,R6}
279
   [ Debug1
Neil Turton's avatar
Neil Turton committed
280
        DREG    R6, "Winnie sizes:"
281
   ]
Neil Turton's avatar
Neil Turton committed
282 283 284 285 286 287 288
        ; Set floppy sizes to sizes needed for extant E format floppies
        LDR     LR, =(SzNewFloppyFs/256) * &01010101
        MOV     R2, R7, ASL #3  ; Floppies*8
        RSB     R2, R2, #32     ; 32 - Floppies*8
        MOV     LR, LR, LSR R2  ; Ensures top bytes which correspond to non-existing drives get zeroed
        STR     LR, FloppySizes

289 290
 ] ; DynamicMaps

291
        ASSERT  SzCreateDesc = 5*4
Neil Turton's avatar
Neil Turton committed
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
        LDMIA   R0, {R0,R2,R4,R5,LR}    ;copy FS descriptor block from parent
        ASSERT  Create_Title=1*4        ;convert parent module offsets to absolute
        ADD     R2, R2, R1
        ASSERT  Create_BootText=2*4
        ADD     R4, R4, R1
        ASSERT  Create_LowLevel=3*4
        ADD     R5, R5, R1
        ASSERT  Create_Misc=4*4
        ADD     LR, LR, R1

        sbaddr  R1, FS_Flags
        STMIA   R1, {R0,R2,R4,R5,LR}
 [ Debug1
        DREG    R0, "Init block:",cc
        DREG    R2, " ",cc
        DREG    R4, " ",cc
        DREG    R5, " ",cc
        MOV     R0, LR
        DREG    R0, " "
 ]

313
;initialise hardware-specific bits
314
        BL      InitialiseHardware
315

316
;check location of System Heap
317
        MOV     R0, #ChangeDyn_SysHeap
318 319 320 321
        SWI     XOS_ReadDynamicArea
        LDRVS   R0, =&01C02000
        STR     R0, SysHeapStart

Neil Turton's avatar
Neil Turton committed
322 323 324 325 326 327 328 329 330 331 332 333 334
;initialise critical subroutine workspace
        sbaddr  R0, CriticalStack1
        STR     R0, CriticalSP1
        sbaddr  R0, CriticalStack2
        STR     R0, CriticalSP2

;initialise most Globals
        baddr   R0, DefGlobals
        sbaddr  R1, DefGlobStart
        MOV     R2, #SzDefGlobals
        BL      BlockMove
        BL      InvalidateFragCache

335 336 337 338 339 340
; reset the directory cache
        BL      LockDirCache
        BL      InvalidateDirCache
        BL      CheckDirCache
        BL      UnlockDirCache

Neil Turton's avatar
Neil Turton committed
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
;initialise Drive & disc records, ptrs to Free space Maps and defect lists
        sbaddr  R4, DrvRecs
        sbaddr  R5, DiscRecs
        ASSERT  SzDefectList=&200

        MOV     R2, #0          ;ctr
        ADD     R7, R7, #4      ;first non existent floppy Drive
10
        ; Disc record initialisation
        ASSERT  (DiscFlags :MOD: 4)=0
        ASSERT  Priority = DiscFlags+1
        ASSERT  DiscsDrv = Priority+1
        ASSERT  DiscUsage = DiscsDrv+1
        MOV     LR, #DefDiscRecEnd
        STR     LR, [R5,#DiscFlags]

        ; Initialise drive record
        MOV     LR, #Uncertain :OR: Unknown
        STRB    LR, [R4,#DrvsDisc]
        MOV     LR, #0
        STRB    LR, [R4, #DrvFlags]
        STRB    LR, [R4, #LockCount]
        STR     LR, [R4,#ChangedSeqNum]

365
 [ DynamicMaps
366 367 368
        STR     LR, [R4, #DrvsFsMapAddr]
        STR     LR, [R4, #DrvsFsMapFlags]
        STR     LR, [R4, #DrvsFsMapSize]
369 370
 ]

Neil Turton's avatar
Neil Turton committed
371 372 373 374 375 376 377 378 379 380 381
        ; Save R2 and R3 over need for them
        Push    "R2, R3"

        ; Check that this drive exists - store a 0 for non-existant drives
        TST     R2, #4
        MOVEQ   LR, R8
        MOVNE   LR, R7
        CMP     R2, LR
        MOVHS   r2, #0
        BHS     %FT15

382 383
 [ DynamicMaps

384
        ; if we're using dynamic areas for the free space maps, then the
Robert Sprowson's avatar
Robert Sprowson committed
385
        ; map for each configured drive is created as a dynamic area
386

387
        SUB     SP, SP, #256+4
388

389
        Push    "R2-R5"
390

391
        ADRL    R0, MapArea
392

393 394 395 396 397 398 399 400 401
        EOR     LR, R2, #4
        ADD     LR, LR, #'0'
        STR     LR, [SP, #256+4*4]
        ADD     R2, SP, #4*4
        MOV     R3, #256
        LDR     R4, FS_Title
        ADD     R5, SP, #256+4*4
        BL      message_lookup_to_buffer02      ; do the message lookup
        Pull    "R2-R5"
402

403
        ; now null terminated string at SP (or V set)
404

405
;       BVC     %FT14                   ; if no error, then message block is OK
406
;
407 408
;       MOV     LR, SP
;       ADRL    R3, MapAreaDefault
409
;13
410 411 412 413
;       LDRB    r0, [r3], #1
;       TEQS    r0, #0
;       STRNEB  r0, [lr], #1
;       BNE     %BT13
414
;
415 416 417 418 419
;       ; now insert the drive number
;       EOR     r3, r2, #4
;       ADD     r3, r3, #'0'
;       STRB    r3, [lr], #1
;       STRB    r0, [lr], #1            ; and the terminator
420 421 422

14
 [ Debug1
423
        DSTRING sp, "Dynamic name: "
424 425
 ]

426
        Push    "R1,R2,R4-R8"
427

428
        MOV     R0, #DAReason_Create
429 430 431
        MOV     R1, #-1                 ; don't care about the number
        MOV     R2, #0                  ; initial size of area
        MOV     R3, #-1                 ; don't care about the base
432
        MOV     R4, #2 + DynAreaFlags_NotUserDraggable ; supervisor only
433 434 435 436
        MOV     R5, #FsMapMaxSize       ; max size of area
        MOV     R6, #0                  ; no handler
        MOV     R7, #0                  ; no workspace for handler
        ADD     R8, SP, #7*4            ; name pointer
437

438 439 440 441
        BL      OnlyXOS_DynamicArea     ; do the dynamic area thing
        MOVVC   R0, R1                  ; dynamic area number
        MOVVS   R0, #0
        Pull    "R1,R2,R4-R8"
442

443
        ADD     SP, SP, #256+4
444
 [ Debug1
445 446
        DREG    R3, "Dynamic area base: "
        DREG    R0, "Dynamic area num : "
447
 ]
448 449 450 451
        STR     R3, [R4, #DrvsFsMapAddr]; store the dynamic area base ptr
        STR     R0, [R4, #DrvsFsMapArea]; area number
        MOV     R0, #0                  ;
        STR     R0, [R4, #DrvsFsMapSize]; allocated size
452 453

15
454
        Pull    "R2,R3"
455 456
 |

Neil Turton's avatar
Neil Turton committed
457 458 459 460 461 462 463 464 465
        ; Get size byte, skip allocation if size is 0
        ASSERT  FloppySizes = WinnieSizes+4
        sbaddr  LR, WinnieSizes
        LDRB    R2, [LR, R2]
        ADDS    R3, R2, R2, ASL #8
        BEQ     %FT15

        ; Claim the block, mapping fails to no block
        MOV     R0, #ModHandReason_Claim
466
   [ Debug1
Neil Turton's avatar
Neil Turton committed
467
        DREG    R3, "Claiming map block of size "
468
   ]
Neil Turton's avatar
Neil Turton committed
469 470
        BL      OnlyXOS_Module
        MOVVS   R2, #0
471
   [ Debug1
Neil Turton's avatar
Neil Turton committed
472
        DebugError "Claim error on maps:"
473
   ]
Neil Turton's avatar
Neil Turton committed
474 475 476 477 478 479 480 481 482 483 484 485

15
        ; Save the block's address, restore R2 and R3 and set Winnie/Floppy Size to 0 if no block
        STR     R2, [R4, #DrvsFsMap]
        MOVS    R0, R2

        Pull    "R2, R3"

        ; If stored a 0, set Winnie/FloppySize to 0
        sbaddr  LR, WinnieSizes,EQ
        STREQB  R0, [LR,R2]

486 487
 ] ; DynamicMaps

Neil Turton's avatar
Neil Turton committed
488 489 490 491 492 493 494 495 496 497
20
        ; Map allocation done for this drive

        ; Move to next disc and drive
        ADD     R4, R4, #SzDrvRec
        ADD     R5, R5, #SzDiscRec
        ADD     R2, R2, #1
        CMPS    R2, #8
        BLO     %BT10

498 499 500
 ; here we allocate the dir buffer

 [ BigDir
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
        ASSERT  BigDirMinSize>=NewDirSize
        ASSERT  BigDirMinSize>=OldDirSize
        ; have to create a dynamic area.  call it 'FileCore DirBuffer'
        Push    "R0-R8"

        MOV     R0, #0
        STR     R0, DirBufferPtr
        STR     R0, DirBufferArea

        SUB     SP, SP, #256            ; buffer for message lookup

        ADRL    R0, DirBufferName       ; get the message ptr
        MOV     R2, SP
        MOV     R3, #256
        LDR     R4, FS_Title            ; name of filing system
        BL      message_lookup_to_buffer01      ; do the message lookup
        BVC     %FT01

        ADD     SP, SP, #256
        STR     R0, [SP]
        Pull    "R0-R8"
        B       %FT85
523 524
01

525
        MOV     R0, #DAReason_Create
526 527 528 529
        MOV     R1, #-1                 ; don't care about the number
        MOV     R2, #BigDirMinSize      ; initial size of area
        STR     R2, DirBufferSize       ; store the size
        MOV     R3, #-1                 ; don't care about the base
530
        MOV     R4, #2 + DynAreaFlags_NotUserDraggable ; supervisor only
531 532 533 534 535 536
        MOV     R5, #BigDirMaxSize      ; max size of area
        MOV     R6, #0                  ; no handler
        MOV     R7, #0                  ; no workspace for handler
        MOV     R8, SP                  ; name for dir buffer
        BL      OnlyXOS_DynamicArea     ; try to create the area
        ADD     SP, SP, #256            ; free buffer
537
 [ Debug1
538
        DebugError "Dynamic area creation:"
539
 ]
540 541 542 543
        BVC     %FT01
        STR     R0, [SP]
        Pull    "R0-R8"
        B       %FT85
544 545
01
 [ Debug1
546 547
        DREG    R1, "DirBufferArea: "
        DREG    R3, "DirBufferPtr : "
548
 ]
549 550 551
        STR     R1, DirBufferArea
        STR     R3, DirBufferPtr
        Pull    "R0-R8"
552 553
 ]

Neil Turton's avatar
Neil Turton committed
554 555 556 557
        ; Set up DefectSpace
        SUB     R3, R3, SB
        STR     R3, DefectSpace

558
        ; Read the Truncate CMOS bit and toggle its sense when we store it
559
        MOV     r0, #OsByte_ReadCMOS
Neil Turton's avatar
Neil Turton committed
560 561 562 563 564 565
        MOV     r1, #FileSwitchCMOS
        SWI     XOS_Byte
        BVS     %FT85
        TST     r2, #FileSwitchTruncateNamesCMOSBit
        LDRB    lr, Flags
        ORREQ   lr, lr, #TruncateNames
566
        STREQB  lr, Flags
Neil Turton's avatar
Neil Turton committed
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
 [ Debug1
        DREG    r2, "FileSwitchCMOS="
        MOV     r2, lr
        DREG    r2, "Flags="
 ]

        BL      ReadCaseTables

        ; Declare ourselves
        BL      DeclareFS       ;(R11->R0,V)
 [ Debug1
        DebugError "Declare error:"
 ]
        BVS     %FT85           ; Middle of Die code
        BL      FileCoreExit
 [ ExceptionTrap
        baddr   LR, Exception-8
        MOV     LR, LR, LSR #2
        ORR     LR, LR, #&EA000000
        MOV     R1, #0
        STR     LR, [R1]
        STR     LR, [R1,#4]
        STR     LR, [R1,#&C]
        STR     LR, [R1,#&10]
        STR     LR, [R1,#&14]
 ]
593 594 595
70
        CLRV
        Pull    "R7-R11,PC"
Neil Turton's avatar
Neil Turton committed
596 597 598 599 600 601 602 603 604 605

        LTORG

; >>>>>>>>
; DieEntry
; >>>>>>>>

DieEntry
        getSB
        TEQS    SB, #0
606
        MOVEQ   PC, LR                  ;if base incarnation
Neil Turton's avatar
Neil Turton committed
607
        Push    "R7-R11,LR"
608
 [ Debug1
609
        DLINE   "FileCore DieEntry"
610
 ]
Neil Turton's avatar
Neil Turton committed
611 612 613 614
        MOV     LR, #1
        STRB    LR, ReEntrance
        MOV     R10,#0
        MOV     R1, #8
615
        BL      CloseAllByDisc          ;close all files for this incarnation
Neil Turton's avatar
Neil Turton committed
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
        MOVVS   R9, R0
 [ Debug
        DebugError "CloseAll Error:"
 ]
        ; UnDeclare FS from FileSwitch
        MOV     R0, #FSControl_RemoveFS
        LDR     R1, FS_Title
        BL      OnlyXOS_FSControl
 [ Debug
        DebugError "Error from RemoveFS:"
 ]
85
        ; Reentry point from init routine above on failure to register FS with FileSwitch
        MOVVS   R9, R0

631
 [ Debug1
632
        DLINE   "FileCore killing parent"
633 634
 ]

Neil Turton's avatar
Neil Turton committed
635 636
        ; Delete the parent of this incarnation (eg ADFS)
        LDR     R1, ParentBase
Robert Sprowson's avatar
Robert Sprowson committed
637
        LDR     R0, [R1,#Module_TitleStr]
Neil Turton's avatar
Neil Turton committed
638 639 640 641
        ADD     R1, R1, R0
        MOV     R0, #ModHandReason_Delete
        SWI     XOS_Module

642
 [ Debug
643
        DebugError "killing (filecore's) parent error: "
644 645 646
 ]

 [ BigDir
647
        ; free the dynamic area for the dir buffer
648
        MOV     R0, #DAReason_Remove
649 650
        LDR     R1, DirBufferArea
        TEQS    R1, #0
651
 [ Debug1
652 653
        BEQ     %FT01
        DREG    R1, "Removing DirBufferArea: "
654 655 656
01
 ]

657
        SWI     XOS_DynamicArea
658 659

 [ Debug1
660
        DLINE   "Removed DirBufferArea"
661 662
 ]
 [ Debug
663
        DebugError "Error from removing dir buffer area: "
664 665 666
 ]
 ]

Neil Turton's avatar
Neil Turton committed
667 668 669 670
        MOV     R4, #8          ; return all map spaces
        B       %FT94
93
        DrvRecPtr  R2,R4
671
  [ DynamicMaps
672
        MOV     R0, #DAReason_Remove
673 674
        LDR     R1, [R2, #DrvsFsMapArea]
        TEQS    R1, #0
675
 [ Debug1
676 677
        BEQ     %FT01
        DREG    R1, "removing dynamic map: "
678 679
01
 ]
680
        BLNE    OnlyXOS_DynamicArea     ; ditch the dynamic area
681
   [ Debug
682
        DebugError "Error from removing disc map area: "
683 684
   ]
  |
Neil Turton's avatar
Neil Turton committed
685 686 687 688
        LDR     R2, [R2,#DrvsFsMap]
        BICS    R2, R2, #HiFsBits
        MOVNE   R0, #ModHandReason_Free
        BLNE    OnlyXOS_Module  ;ignore errors
689
  ]
Neil Turton's avatar
Neil Turton committed
690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
94
        SUBS    R4, R4, #1
        BPL     %BT93

        BL      FileCoreExit

        ; Release message file
        LDR     R0, message_file_open
        TEQ     R0, #0
        ADRNE   R0, message_file_block
        SWINE   XMessageTrans_CloseFile ; Ignore error from this

        MOV     R0, #ModHandReason_Free
        MOV     R2, SB
        SWI     XOS_Module          ;Free workspace
 [ Debug
        DebugError "Heap error:"
 ]
95
 [ Debug
        BVC     %FT01
        DREG    R10, "Error - ",cc
        DREG    R0, "..."
01
 ]

716 717 718
 [ NewErrors
        MOVVS   R9, R0
 |
Neil Turton's avatar
Neil Turton committed
719
        ORRVS   R9, R0, #ExternalErrorBit
720
 ]
Neil Turton's avatar
Neil Turton committed
721 722
        MOVS    R0, R9
        MOVNES  R10,R10         ;only error on init
723
        BEQ     %BT70
Neil Turton's avatar
Neil Turton committed
724 725 726 727 728

        BL      FindErrBlock    ;(R0->R0,V)
99
 [ Debug
        DebugError "FileCore init error:"
729 730
 ]
 [ Debug1
731
        DLINE   "Exit from Filecore DieEntry"
Neil Turton's avatar
Neil Turton committed
732 733 734 735
 ]
        Pull    "R7-R11,PC"

FSHdr
736 737 738 739 740 741
        DCD     OpenFileEntry  - Module_BaseAddr
        DCD     GetBytesEntry  - Module_BaseAddr
        DCD     PutBytesEntry  - Module_BaseAddr
        DCD     OsArgsEntry    - Module_BaseAddr
        DCD     CloseFileEntry - Module_BaseAddr
        DCD     OsFileEntry    - Module_BaseAddr
Neil Turton's avatar
Neil Turton committed
742
        DCD     fsinfo_flushnotify :OR: fsinfo_multifsextensions :OR: fsinfo_dontuseload :OR: fsinfo_extrainfo
743
        DCD     OsFunEntry     - Module_BaseAddr
744
        DCD     0               ; FS_extra info flags
Neil Turton's avatar
Neil Turton committed
745 746 747 748 749 750 751 752 753 754 755 756

; =========
; DeclareFS
; =========

; Entry R11 ptr to private word

DeclareFS ROUT
        Push    "r0-r10,lr"
        SUB     sp, sp, #FS_size

        MOV     r0, sp
757
        baddr   r1, Module_BaseAddr
Neil Turton's avatar
Neil Turton committed
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783
        baddr   r2, FSHdr

        ASSERT  FS_name=0*4
        ASSERT  FS_startuptext=1*4
        LDR     r3, FS_Title
        SUB     r3, r3, r1
        LDR     r4, FS_BootText
        SUB     r4, r4, r1
        STMIA   r0!, {r3,r4}

        ASSERT  FS_open=2*4
        ASSERT  FS_get=3*4
        ASSERT  FS_put=4*4
        ASSERT  FS_args=5*4
        ASSERT  FS_close=6*4
        ASSERT  FS_file=7*4
        LDMIA   r2!, {r3-r8}
        STMIA   r0!, {r3-r8}

        ASSERT  FS_info = 8*4
        ASSERT  FS_func=9*4
        ASSERT  FS_gbpb=10*4
        ASSERT  FS_extra=11*4
        LDMIA   r2!, {r3,r4,r6}
        LDRB    lr, FS_Id
        ORR     r3, r3, lr
784
        MOV     r5, #0                          ;no FS_gbpb entry
Neil Turton's avatar
Neil Turton committed
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810
        STMIA   r0!, {r3,r4,r5,r6}

        MOV     r0, #FSControl_AddFS            ;declare as filing system
        SUB     r2, sp, r1
        MOV     r3, r11
        BL      OnlyXOS_FSControl
 [ Debug1
        DebugError "Error on declaring FileCore:"
 ]

        MOVVC   r0, #FSControl_AddSecondaryFS
        LDRVC   r1, FS_Title
        LDRVC   r2, ParentBase
        LDRVC   r3, ParentPrivate
        BLVC    OnlyXOS_FSControl
 [ Debug1
        DebugError "Error after declaring secondary FS:"
 ]
        ADD     sp, sp, #FS_size
        STRVS   r0, [sp]
        Pull    "r0-r10,pc"

ReadCaseTables ROUT
        Push    "lr"
        MOV     r0, #-1
        SWI     XTerritory_UpperCaseTable
811
        MOVVS   r0, #BadPtr
Neil Turton's avatar
Neil Turton committed
812
        STR     r0, UpperCaseTable
813
        Pull    "pc"
Neil Turton's avatar
Neil Turton committed
814 815 816 817

; >>>>>>>>>>>>
; ServiceEntry
; >>>>>>>>>>>>
Robert Sprowson's avatar
Robert Sprowson committed
818 819 820 821 822 823 824 825
        ASSERT  Service_ClaimFIQ < Service_Memory
        ASSERT  Service_Memory < Service_Reset
        ASSERT  Service_Reset < Service_FSRedeclare
        ASSERT  Service_FSRedeclare < Service_IdentifyDisc
        ASSERT  Service_IdentifyDisc < Service_EnumerateFormats
        ASSERT  Service_EnumerateFormats < Service_IdentifyFormat
        ASSERT  Service_IdentifyFormat < Service_DisplayFormatHelp
        ASSERT  Service_DisplayFormatHelp < Service_TerritoryStarted
826
ServiceTable
827 828
        &       0       ; flags word
        &       ServiceEntry2   - Module_BaseAddr
829

830 831 832 833 834 835 836 837 838
        &       Service_ClaimFIQ
        &       Service_Memory
        &       Service_Reset
        &       Service_FSRedeclare
        &       Service_IdentifyDisc
        &       Service_EnumerateFormats
        &       Service_IdentifyFormat
        &       Service_DisplayFormatHelp
        &       Service_TerritoryStarted
Robert Sprowson's avatar
Robert Sprowson committed
839
        &       0       ; terminator
840

841
        &       ServiceTable    - Module_BaseAddr
Neil Turton's avatar
Neil Turton committed
842
ServiceEntry ROUT
843
        MOV     r0, r0
Robert Sprowson's avatar
Robert Sprowson committed
844
        ; Rapid service rejection
Neil Turton's avatar
Neil Turton committed
845 846 847 848 849 850 851 852 853
        TEQ     r1, #Service_ClaimFIQ
        TEQNE   r1, #Service_Memory
        TEQNE   r1, #Service_FSRedeclare
        TEQNE   r1, #Service_Reset
        TEQNE   r1, #Service_IdentifyDisc
        TEQNE   r1, #Service_EnumerateFormats
        TEQNE   r1, #Service_IdentifyFormat
        TEQNE   r1, #Service_DisplayFormatHelp
        TEQNE   r1, #Service_TerritoryStarted
854
        MOVNE   pc, lr
855
ServiceEntry2
Neil Turton's avatar
Neil Turton committed
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886
        ; Service entry and check for base invocation of FileCore
        Push    "R0-R2,R11,R12,LR"      ;need entry R12 stacked for FSRedeclare
        getSB
        TEQ     SB, #0
        BEQ     DoService_WithoutSB

        ; Switch amoungst the recognised services
        TEQ     r1, #Service_ClaimFIQ
        BEQ     DoService_ClaimFIQ
        TEQ     r1, #Service_Memory
        BEQ     DoService_Memory
        TEQ     r1, #Service_FSRedeclare
        BEQ     DoService_FSRedeclare
        TEQ     r1, #Service_Reset
        BEQ     DoService_Reset
        TEQ     r1, #Service_TerritoryStarted
        BEQ     DoService_TerritoryStarted
        B       DoService_PassedOn


DoService_Reset
        LDRB    R0, Interlocks
        BIC     R0, R0, #&FF :EOR: NoOpenFloppy :EOR: NoOpenWinnie
        STRB    R0, Interlocks
        LDRB    LR, MaxFileBuffers      ;IF drivers can run in background
        TEQS    LR, #0
        BEQ     %FT11

        LDR     R0, FloppyProcessBlk
        BL      %FT95

Robert Sprowson's avatar
Robert Sprowson committed
887
        LDR     R0, WinnieProcessBlk
888
        TSTS    R0, #BadPtrBits
Neil Turton's avatar
Neil Turton committed
889 890 891
        BLEQ    %FT95

        LDR     LR, FirstFcb
892
        TSTS    LR, #BadPtrBits         ;AND at least one file open
Neil Turton's avatar
Neil Turton committed
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 934 935 936 937 938 939 940 941 942 943 944
        MOVEQ   R0, #TickerV
        ADREQL  R1, TickerEntry
        MOVEQ   R2, SB                  ;restart scheduler
        SWIEQ   XOS_Claim               ;(R0,R1->R0,V)
11

        LDRB    LR, ReEntrance
        TEQS    LR, #0
        BEQ     %FT90                   ;no aborted activity
        MOV     LR, #1
        STRB    LR, ReEntrance

        BL      ReturnBuffer            ;return chunks claimed for data move

        MOV     R0, #7
55                              ;make disc <-> drive mapping consistent
        DiscRecPtr  R1,R0
        MOV     LR, #0
        STRB    LR, [R1,#DiscUsage]
        LDRB    R1, [R1,#DiscsDrv]
        CMPS    R1, #8
        BHS     %FT60
        DrvRecPtr  R1,R1
        LDRB    R1, [R1,#DrvsDisc]
        BIC     R1, R1, #Uncertain
        TEQS    R1, R0
        BLNE    UnlinkByDisc
60
        DrvRecPtr  R1,R0
        LDRB    R1, [R1,#DrvsDisc]
        BIC     R1, R1, #Uncertain
        CMPS    R1, #8
        BHS     %FT65
        DiscRecPtr  R1,R1
        LDRB    R1, [R1,#DiscsDrv]
        TEQS    R1, R0
        BLNE    UnlinkByDrive
65
        SUBS    R0, R0, #1
        BPL     %BT55
85
        BL      FileCoreExit
90
        B       DoService_PassedOn

95                           ;routine to tidy up background transfer on reset
        LDRB    R1, [R0, #Process]
        TSTS    R1, #ReadAhead :OR: WriteBehind
        LDRNE   R1, [R0, #ProcessStatus]
        TSTNES  R1, #Active
        MOVNE   R1, #DataLostErr
        STRNE   R1, [R0, #ProcessError]
945 946 947
 [ NewErrors
        BEQ     %FT96
        LDR     R1, FS_Flags
948
        TSTS    R1, #CreateFlag_NewErrorSupport
949 950 951 952 953
        LDR     R1, [R0, #ProcessStartPtr]
        MOVNE   R1, R1, LSR #2
        STR     R1, [R0, #ProcessStatus]
96
 |
Neil Turton's avatar
Neil Turton committed
954 955
        LDRNE   R1, [R0, #ProcessStartPtr]
        STRNE   R1, [R0, #ProcessStatus]
956
 ]
957
        MOV     PC, LR
Neil Turton's avatar
Neil Turton committed
958 959 960 961 962 963



DoService_ClaimFIQ
        MOV     LR, #&FF
        STRB    LR, BackgroundFiqLock
964
        WritePSRc SVC_mode,LR,,R0       ;enable IRQs
Neil Turton's avatar
Neil Turton committed
965 966 967 968 969
02                              ;wait until finished with FIQ
        LDRB    LR, FiqOwnership
        TEQS    LR, #0
        BNE     %BT02
        STRB    LR, BackgroundFiqLock
970
        RestPSR R0,,cf
Neil Turton's avatar
Neil Turton committed
971 972 973 974 975 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
        B       DoService_PassedOn


DoService_Memory
        LDRB    R0, ScatterEntries
06
        SUBS    R0, R0, #1
        BMI     DoService_PassedOn
        sbaddr  R1, ScatterSource
        LDRB    R1, [R1,R0]
        TEQS    R1, #UseApplicArea
        BNE     %BT06
        B       DoService_Claimed


DoService_FSRedeclare
        LDR     R11,[SP,#4*4]   ;entry R12 -> private word
        BL      DeclareFS       ;(R11->R0,V)
        B       DoService_PassedOn

DoService_TerritoryStarted
        BL      ReadCaseTables
        B       DoService_PassedOn

DoService_IdentifyDisc
        ; Identify our own disc
        B       IdentifyFileCoreDisc

DoService_WithoutSB
        ; Pass around services for the base incarnation

        ; Pull regs not corrupted by non-SB services
        Pull    "r0-r2,r11"

        ; Construct return address to pass on service call location
1006
        JumpAddress lr, DoService_PassedOnWithoutSB, forward
Neil Turton's avatar
Neil Turton committed
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018

        ; Branch off to relevant service handler routine
        TEQ     r1, #Service_EnumerateFormats
        BEQ     FileCoreService_EnumerateFormats
        TEQ     r1, #Service_IdentifyFormat
        BEQ     FileCoreService_IdentifyFormat
        TEQ     r1, #Service_DisplayFormatHelp
        BEQ     FileCoreService_DisplayFormatHelp
        TEQ     r1, #Service_IdentifyDisc
        BEQ     DoService_IdentifyDisc

DoService_PassedOnWithoutSB
1019
        Pull    "R12,PC"
Neil Turton's avatar
Neil Turton committed
1020
DoService_PassedOn
1021
        Pull    "R0-R2,R11,R12,PC"
Neil Turton's avatar
Neil Turton committed
1022
DoService_Claimed
1023 1024 1025 1026
        Pull    "R0"
        MOV     R1, #0
        ADD     SP, SP, #4
        Pull    "R2,R11,R12,PC"
Neil Turton's avatar
Neil Turton committed
1027 1028

        END