• Jeffrey Lee's avatar
    Reimplement AMBControl ontop of the PMP system · cefb4815
    Jeffrey Lee authored
    Detail:
      With this set of changes, each AMB node is now the owner of a fake DANode which is linked to a PMP.
      From a user's perspective the behaviour of AMBControl is the same as before, but rewriting it to use PMPs internally offers the following (potential) benefits:
      * Reduction in the amount of code which messes with the CAM & page tables, simplifying future work/maintenance. Some of the AMB ops (grow, shrink) now just call through to OS_ChangeDynamicArea. However all of the old AMB routines were well-optimised, so to avoid a big performance hit for common operations not all of them have been removed (e.g. mapslot / mapsome). Maybe one day these optimal routines will be made available for use by regular PMP DAs.
      * Removal of the slow Service_MemoryMoved / Service_PagesSafe handlers that had to do page list fixup after the core kernel had reclaimed/moved pages. Since everything is a PMP, the kernel will now deal with this on behalf of AMB.
      * Removal of a couple of other slow code paths (e.g. Do_AMB_MakeUnsparse calls from OS_ChangeDynamicArea)
      * Potential for more flexible mapping of application space in future, e.g. sparse allocation of memory to the wimp slot
      * Simpler transition to an ASID-based task swapping scheme on ARMv6+?
      Other changes of note:
      * AMB_LazyMapIn switch has been fixed up to work correctly (i.e. turning it off now disables lazy task swapping and all associated code instead of producing a build error)
      * The DANode for the current app should be accessed via the GetAppSpaceDANode macro. This will either return the current AMB DANode, or AppSpaceDANode (if e.g. pre-Wimp). However be aware that AppSpaceDANode retains the legacy behaviour of having a base + size relative to &0, while the AMB DANodes (identifiable via the PMP flag) are sane and have their base + size relative to &8000.
      * Mostly-useless DebugAborts switch removed
      * AMBPhysBin (page number -> phys addr lookup table) removed. Didn't seem to give any tangible performance benefit, and was imposing hidden restrictions on memory usage (all phys RAM fragments in PhysRamTable must be multiple of 512k). And if it really was a good optimisation, surely it should have been applied to all areas of the kernel, not just AMB!
      Other potential future improvements:
      * Turn the fake DANodes into real dynamic areas, reducing the amount of special code needed in some places, but allow the DAs to be hidden from OS_DynamicArea 3 so that apps/users won't get too confused
      * Add a generic abort trapping system to PMPs/DAs (lazy task swapping abort handler is still a special case)
      File changes:
      - s/ARM600, s/VMSAv6, s/ExtraSWIs - Remove DebugAborts
      - s/ArthurSWIs - Remove AMB service call handler dispatch
      - s/ChangeDyn - AMB_LazyMapIn switch fixes. Add alternate internal entry points for some PMP ops to allow the DANode to be specified (used by AMB)
      - s/Exceptions - Remove DebugAborts, AMB_LazyMapIn switch fixes
      - s/Kernel - Define GetAppSpaceDANode macro, AMB_LazyMapIn switch fix
      - s/MemInfo - AMB_LazyMapIn switch fixes
      - s/AMBControl/AMB - Update GETs
      - s/AMBControl/Memory - Remove block size quantisation, AMB_BlockResize (page list blocks are now allocated by PMP code)
      - s/AMBControl/Options - Remove PhysBin definitions, AMBMIRegWords (moved to Workspace file), AMB_LimpidFreePool switch. Add AMB_Debug switch.
      - s/AMBControl/Workspace - Update AMBNode to contain an embedded DANode. Move AMBMIRegWords here from Options file.
      - s/AMBControl/allocate - Fake DA node initialisation
      - s/AMBControl/deallocate - Add debug output
      - s/AMBControl/growp, growshrink, mapslot, mapsome, shrinkp - Rewrite to use PMP ops where possible, add debug output
      - s/AMBControl/main - Remove PhysBin initialisation. Update the enumerate/mjs_info call.
      - s/AMBControl/memmap - Low-level memory mapping routines updated or rewritten as appropriate.
      - s/AMBControl/readinfo - Update to cope with DANode
      - s/AMBControl/service - Remove old service call handlers
      - s/AMBControl/handler - DA handler for responding to PMP calls from OS_ChangeDynamicArea; just calls through to growpages/shrinkpages as appropriate.
    Admin:
      Tested on pretty much everything currently supported
    
    
    Version 5.66. Tagged as 'Kernel-5_66'
    cefb4815
mapslot 3.3 KB
; 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.
;
; > s.mapslot

; handle mapping of entire slot in or out (bit 8 of R0 clear)
; or mapping of some of slot (bit 8 of R0 set)

; entry:
;     R0 = bits 0..7 = 3 (reason code 3); bit 8 set for mapsome
;     R1 = start (logical) address; 0 means application start; -1 means map out
;     R2 = handle
;     R3,R4 used if bit 8 set - see mapsome
;
; Note that if bit 8 is clear, the use is restricted to mapping in or out of
; whole slots only. Hence if bit 8 is clear, behaviour is undefined unless
; R1 is one of: 0, &8000 or -1.
;
mapslot ROUT

        TST     R0,#&100   ;if bit 8 set, then mapsome
        BNE     mapsome

        Push    "R0-R6,LR"

      [ AMB_Debug
        DebugReg r1, "mapslot "
        DebugReg r2
      ]

        MOVS    R5,R1                    ;save entry R1
        MOVEQ   R5,#ApplicationStart     ;0 means application start

      [ ValidateAMBHandles
        ;validate handle
        LDR     R0,AMBNhandles
        CMP     R2,R0
        BGT     badmapslot
        CMP     R2,#1
        BLT     badmapslot
      ]

        LDR     R0,AMBNodeHandles   ; R0 -> handle array
        LDR     R1,[R0,R2,LSL #2]   ; R1 -> node

      [ ValidateAMBHandles
        ;check we have a proper id for node handle
        LDR     R3,=AMBMagicNodeID
        LDR     LR,[R1,#AMBNode_id]
        CMP     LR,R3
        BNE     badmapslot
      ]

        LDR     R3,[R1,#AMBNode_DANode+DANode_PMPSize]

        LDR   R2,AMBMappedInNode
        CMP   R1,R2
        CMPEQ R5,#-1
        BEQ   ms_domapout  ;do map if already mapped in, and asked to map out

        CMP   R1,R2
        CMPNE R5,#-1
        BEQ   ms_done      ;else do map only if not already mapped in, and asked to map in

        Push    "r1,r7,r10"
        ADD     r10,r1,#AMBNode_DANode
        MOV     r1,#0
        MOV     r5,r3
        MOV     r7,#0
        BL      AMB_SetMemMapEntries_MapIn_Lazy
        Pull    "r1,r7,r10"
        B       ms_donemap

ms_domapout
        Push    "r1,r5,r7,r10"
        ADD     r10,r1,#AMBNode_DANode
        MOV     r1,#0
        MOVS    r5,r3
        MOV     r7,#0
        BLNE    AMB_SetMemMapEntries_MapOut_Lazy
        Pull    "r1,r5,r7,r10"

ms_donemap
;update AplWorkSize, MemLimit
        LDR     R2,[R1,#AMBNode_DANode+DANode_PMPSize]
        LDR     R3,=ZeroPage
        MOV     R0,#ApplicationStart
        CMP     R5,#-1
        ADDNE   R0,R0,R2,LSL #Log2PageSize
        STR     R0,[R3,#AplWorkSize]
        STR     R0,[R3,#MemLimit]
        CMP     R5,#-1
        MOVEQ   R3,#0
        MOVNE   R3,R1
        STR     R3,AMBMappedInNode

ms_done
;;;        STRVS   R0,[SP]
        CLRV
        Pull    "R0-R6,LR"
        B       SLVK_TestV

        LTORG

      [ ValidateAMBHandles
badmapslot
        Pull    "R0-R6,LR"
        B       badhandle
      ]

    END