; 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.readinfo

; handle read info. reason code

;entry:
;     R0 = reason code and flags
;          bits 0-7   4 (reason code)
;          bits 8-31  reserved (must be 0)
;     R2 = handle

;exit:
;     R1 = current mapping start address; -1 means mapped out
;     R3 = currently allocated number of pages

readinfo
        Push    "R0,LR"

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

        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     badhandle_rinfo
      ]

        LDR     R3,[R1,#AMBNode_DANode+DANode_PMPSize]
        LDR     LR,[R1,#AMBNode_DANode+DANode_Size]
        CMP     LR,#0
        MOVEQ   R1,#-1
        LDRNE   R1,[R1,#AMBNode_DANode+DANode_Base]
        Pull    "R0,LR"
        B       SLVK

        LTORG

      [ ValidateAMBHandles
badhandle_rinfo
        Pull    "R0,LR"
        B       badhandle
      ]

    END