; 
; Copyright(c)2010, RISC OS Open Ltd
; Allrightsreserved.
; 
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met: 
;     * Redistributions of source code must retain the above copyright
;       notice, this list of conditions and the following disclaimer.
;     * Redistributions in binary form must reproduce the above copyright
;       notice, this list of conditions and the following disclaimer in the
;       documentation and/or other materials provided with the distribution.
;     * Neither the name of RISC OS Open Ltd nor the names of its contributors
;       may be used to endorse or promote products derived from this software
;       without specific prior written permission.
; 
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
; POSSIBILITY OF SUCH DAMAGE.
; 
        SUBT Exported VFPSupport constants

OldOpt  SETA    {OPT}
        OPT     OptNoList+OptNoP1List

SWIClass        SETS    VFPSupportSWI_Name

        ^       VFPSupportSWI_Base

        AddSWI  CheckContext
        AddSWI  CreateContext
        AddSWI  DestroyContext
        AddSWI  ChangeContext
        AddSWI  ExamineContext
        AddSWI  FastAPI
        AddSWI  ActiveContext
        AddSWI  Version
        AddSWI  Features
        AddSWI  ExceptionDump
        AddSWI  ElementaryFunctions

VFPSupportSWICheckValue     *       @

; Base flags used for CheckContext, CreateContext, ExamineContext

VFPSupport_Context_UserMode             * 1 :SHL: 0
VFPSupport_Context_AppSpace             * 1 :SHL: 1

; Additional flags suitable for CreateContext/CheckContext

VFPSupport_CreateContext_LazyActivate   * 1 :SHL: 30
VFPSupport_CreateContext_Activate       * 1 :SHL: 31

; Additional flags returned by ExamineContext

VFPSupport_Context_LazyActivation       * 1 :SHL: 29
VFPSupport_Context_StatusRegsActive     * 1 :SHL: 30
VFPSupport_Context_VFPMemory            * 1 :SHL: 31

; Flags for ChangeContext

VFPSupport_ChangeContext_Lazy           * 1 :SHL: 0
VFPSupport_ChangeContext_AppSpace       * 1 :SHL: 1

; Flags for ExamineContext

VFPSupport_ExamineContext_Serialise     * 1 :SHL: 0

; Field formats for ExamineContext

VFPSupport_Field_FPSCR                  * 0
VFPSupport_Field_FPEXC                  * 1
VFPSupport_Field_FPINST                 * 2
VFPSupport_Field_FPINST2                * 3
VFPSupport_Field_FSTMX                  * 4
VFPSupport_Field_RegDump                * 5

; Reason codes for Features

VFPSupport_Features_SystemRegs          * 0
VFPSupport_Features_VFPExceptions       * 1
VFPSupport_Features_Misc                * 2
VFPSupport_Features_SystemRegs2         * 3

; Misc feature flags
VFPSupport_MiscFeature_VFPVectors_HW    * 1 :SHL: 0 ; VFP short vectors are supported by hardware
VFPSupport_MiscFeature_VFPVectors_SW    * 1 :SHL: 1 ; VFP short vectors are supported by software
VFPSupport_MiscFeature_ElementaryFns    * 1 :SHL: 2 ; VFP implementation of elementary functions are provided

; Flags for ExceptionDump

VFPSupport_ExceptionDump_GetDump        * 1 :SHL: 0
VFPSupport_ExceptionDump_GetContext     * 1 :SHL: 1
VFPSupport_ExceptionDump_Clear          * 1 :SHL: 2
VFPSupport_ExceptionDump_Create         * 1 :SHL: 3

; Elementary functions available
                                        ^ 0
VFPSupport_Fn_sin                       # 1
VFPSupport_Fn_cos                       # 1
VFPSupport_Fn_tan                       # 1
VFPSupport_Fn_asin                      # 1
VFPSupport_Fn_acos                      # 1
VFPSupport_Fn_atan                      # 1
VFPSupport_Fn_atan2                     # 1
VFPSupport_Fn_log                       # 1
VFPSupport_Fn_log10                     # 1
VFPSupport_Fn_exp                       # 1
VFPSupport_Fn_pow                       # 1
VFPSupport_Fn_fma                       # 1
VFPSupport_Fns                          * :INDEX: @

; VFP status register fields, as per ARMv7 ARM

FPEXC_IOF                    * 1 :SHL: 0
FPEXC_DZF                    * 1 :SHL: 1
FPEXC_OFF                    * 1 :SHL: 2
FPEXC_UFF                    * 1 :SHL: 3
FPEXC_IXF                    * 1 :SHL: 4
FPEXC_IDF                    * 1 :SHL: 7
FPEXC_VECITR_SHIFT           * 8
FPEXC_VECITR_MASK            * 7 :SHL: 8
FPEXC_TFV                    * 1 :SHL: 26
FPEXC_VV                     * 1 :SHL: 27
FPEXC_FP2V                   * 1 :SHL: 28
FPEXC_DEX                    * 1 :SHL: 29
FPEXC_EN                     * 1 :SHL: 30
FPEXC_EX                     * 1 :SHL: 31

FPSCR_IOC                    * 1 :SHL: 0
FPSCR_DZC                    * 1 :SHL: 1
FPSCR_OFC                    * 1 :SHL: 2
FPSCR_UFC                    * 1 :SHL: 3
FPSCR_IXC                    * 1 :SHL: 4
FPSCR_IDC                    * 1 :SHL: 7
FPSCR_CUMULATIVE_FLAGS       * FPSCR_IOC+FPSCR_DZC+FPSCR_OFC+FPSCR_UFC+FPSCR_IXC+FPSCR_IDC
FPSCR_IOE                    * 1 :SHL: 8
FPSCR_DZE                    * 1 :SHL: 9
FPSCR_OFE                    * 1 :SHL: 10
FPSCR_UFE                    * 1 :SHL: 11
FPSCR_IXE                    * 1 :SHL: 12
FPSCR_IDE                    * 1 :SHL: 15
FPSCR_ENABLE_FLAGS           * FPSCR_IOE+FPSCR_DZE+FPSCR_OFE+FPSCR_UFE+FPSCR_IXE+FPSCR_IDE
FPSCR_LEN_SHIFT              * 16
FPSCR_LEN_MASK               * 7 :SHL: 16
FPSCR_STRIDE_SHIFT           * 20
FPSCR_STRIDE_MASK            * 3 :SHL: 20
FPSCR_RMODE_SHIFT            * 22
FPSCR_RMODE_MASK             * 3 :SHL: 22
FPSCR_RMODE_NEAREST          * 0 :SHL: 22
FPSCR_RMODE_UP               * 1 :SHL: 22
FPSCR_RMODE_DOWN             * 2 :SHL: 22
FPSCR_RMODE_ZERO             * 3 :SHL: 22
FPSCR_FZ                     * 1 :SHL: 24
FPSCR_DN                     * 1 :SHL: 25
FPSCR_AHP                    * 1 :SHL: 26
FPSCR_QC                     * 1 :SHL: 27
FPSCR_V                      * 1 :SHL: 28
FPSCR_C                      * 1 :SHL: 29
FPSCR_Z                      * 1 :SHL: 30
FPSCR_N                      * 1 :SHL: 31


; Errors

        ^        ErrorBase_VFPSupport
        AddError VFPSupport_NoHW, "No VFP/NEON hardware present"
        AddError VFPSupport_BadHW, "Unsupported VFP/NEON version"
        AddError VFPSupport_FeatureUnavailable, "A requested VFP/NEON feature is unavailable"
        AddError VFPSupport_BadContext, "Bad VFP context"
        AddError VFPSupport_BadFeature, "Bad VFPSupport_Features reason code"
        AddError VFPSupport_NoHW2, "VFPSupport module or VFP/NEON coprocessor not found" ; Generic error for VFP/NEON dependent programs to use. Where possible programs should use custom error text to specify the exact hardware required - VFPv1, NEON, etc.
        AddError VFPSupport_Instanced, "Only one instance of VFPSupport can be active at a time"
        AddError VFPSupport_BadFlags, "Invalid flags passed to VFPSupport SWI"

        ^        ErrorBase_VectorFloatingPoint
        ; Floating point exception errors
        AddError VFPSupport_IO, "Vector floating point exception: invalid operation"
        AddError VFPSupport_DZ, "Vector floating point exception: division by zero"
        AddError VFPSupport_OF, "Vector floating point exception: overflow"
        AddError VFPSupport_UF, "Vector floating point exception: underflow"
        AddError VFPSupport_IX, "Vector floating point exception: inexact operation"
        AddError VFPSupport_ID, "Vector floating point exception: input subnormal"

        ; Errors generated by the support code - numbered from top end of block down, to keep separate from the errors programmers should expect to see
        AddError VFPSupport_SupCode_NoContext, "No VFP context active", ErrorBase_VectorFloatingPoint+&FF
        AddError VFPSupport_SupCode_NotEN, "VFP coprocessor not enabled", ErrorBase_VectorFloatingPoint+&FE
        AddError VFPSupport_SupCode_ENMismatch, "VFP coprocessor enable state mismatch", ErrorBase_VectorFloatingPoint+&FD
        AddError VFPSupport_SupCode_Unexpected, "Unexpected VFP instruction", ErrorBase_VectorFloatingPoint+&FC
        AddError VFPSupport_SupCode_SupDiv0, "Divide by zero in VFP support code", ErrorBase_VectorFloatingPoint+&FB
        AddError VFPSupport_SupCode_UnkExcep, "Unknown VFP exception requested", ErrorBase_VectorFloatingPoint+&FA



        OPT     OldOpt
        END
