1    /* 
     2     * Copyright (c) 2012, Texas Instruments Incorporated
     3     * All rights reserved.
     4     *
     5     * Redistribution and use in source and binary forms, with or without
     6     * modification, are permitted provided that the following conditions
     7     * are met:
     8     *
     9     * *  Redistributions of source code must retain the above copyright
    10     *    notice, this list of conditions and the following disclaimer.
    11     *
    12     * *  Redistributions in binary form must reproduce the above copyright
    13     *    notice, this list of conditions and the following disclaimer in the
    14     *    documentation and/or other materials provided with the distribution.
    15     *
    16     * *  Neither the name of Texas Instruments Incorporated nor the names of
    17     *    its contributors may be used to endorse or promote products derived
    18     *    from this software without specific prior written permission.
    19     *
    20     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    21     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    22     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    23     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    24     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    25     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    26     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    27     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    28     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    29     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    30     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    31     * */
    32    /*
    33     *  ======== Exception.xdc ========
    34     *
    35     */
    36    
    37    package ti.sysbios.family.arm.exc;
    38    
    39    import xdc.rov.ViewInfo;
    40    
    41    import xdc.runtime.Error;
    42    
    43    import ti.sysbios.BIOS;
    44    
    45    /*!
    46     *  ======== Exception ========
    47     *  Exception Module
    48     *
    49     *  The Exception module is a basic ARM exception handler.
    50     *  When an exception occurs, the execution state is saved into
    51     *  a buffer with a structure of type {@link #ExcContext ExcContext}.
    52     *
    53     *  By default, a formatted dump of this structure is also sent to
    54     *  the console using System_printf(). This behavior can be suppressed
    55     *  by setting the {@link #enableDecode} config parameter to 'false'.
    56     *
    57     *  An ROV view of the exception context is provided when
    58     *  attached to the target board with CCS.
    59     *
    60     *  @a(Notes)
    61     *  No attempt is made to return from an exception as these are
    62     *  generally fatal in nature.
    63     *
    64     *  When used, the Exception module will override the default 
    65     *  exception handlers provided by the current Hwi module.
    66     */
    67    
    68    @ModuleStartup          /* generates call to Exception_Module_startup at startup */
    69    module Exception
    70    {
    71        /*! Exception hook function type definition. */
    72        typedef Void (*ExceptionHookFuncPtr)(ExcContext *);
    73    
    74        /* Exception types */
    75        enum Type {
    76            Type_Supervisor = 0x13,         /*! Supervisor (SWI). */
    77            Type_PreAbort   = 0x17,         /*! Abort exception. */
    78            Type_DataAbort  = 0x18,         /*! Abort exception. */
    79            Type_UndefInst  = 0x1b          /*! Undefined instruction exception. */
    80        };
    81    
    82        /*!
    83         *  Exception Context - Register contents at the time of an exception.
    84         */
    85        struct ExcContext {
    86            /* Thread Context */
    87            BIOS.ThreadType threadType; /* Type of thread executing at */
    88                                        /* the time the exception occurred */
    89            Ptr     threadHandle;       /* Handle to thread executing at */
    90                                        /* the time the exception occurred */
    91            Ptr     threadStack;        /* Address of stack contents of thread */
    92                                        /* executing at the time the exception */
    93                                        /* occurred */
    94            SizeT   threadStackSize;    /* size of thread stack */
    95    
    96            Type    type;
    97    
    98            /* Internal Registers */
    99            Ptr     r0;
   100            Ptr     r1;
   101            Ptr     r2;
   102            Ptr     r3;
   103            Ptr     r4;
   104            Ptr     r5;
   105            Ptr     r6;
   106            Ptr     r7;
   107            Ptr     r8;
   108            Ptr     r9;
   109            Ptr     r10;
   110            Ptr     r11;
   111            Ptr     r12;
   112            Ptr     sp;
   113            Ptr     lr;
   114            Ptr     pc;
   115            Ptr     psr;
   116        }
   117    
   118        @Facet
   119        metaonly config ViewInfo.Instance rovViewInfo = 
   120            ViewInfo.create({
   121                viewMap: [
   122                    ['Basic',    
   123                        {
   124                            type: ViewInfo.TREE,     
   125                            viewInitFxn: 'viewInitBasic',
   126                            structName: 'ExcContext'
   127                        }
   128                    ]
   129                ]
   130            });
   131        
   132        /*! Error raised when a SWI exception occurs */
   133        config Error.Id E_swi = {
   134            msg: "E_swi: pc = 0x%08x, lr = 0x%08x."
   135        };
   136    
   137        /*! Error raised when an prefetch abort exception occurs */
   138        config Error.Id E_prefetchAbort = {
   139            msg: "E_prefetchAbort: pc = 0x%08x, lr = 0x%08x."
   140        };
   141    
   142        /*! Error raised when an data abort exception occurs */
   143        config Error.Id E_dataAbort = {
   144            msg: "E_dataAbort: pc = 0x%08x, lr = 0x%08x."
   145        };
   146    
   147        /*! Error raised when an undefined instruction exception occurs */
   148        config Error.Id E_undefinedInstruction = {
   149            msg: "E_undefinedInstruction: pc = 0x%08x, lr = 0x%08x."
   150        };
   151    
   152        /*!
   153         *  Enable full exception decoding, default is true.
   154         *
   155         *  When enabled, the exception handler will fully
   156         *  decode an exception and dump the registers to the
   157         *  system console.
   158         *
   159         *  When set to false, only an Error is printed on the console.
   160         *
   161         *  In either case, the full exception context is always
   162         *  saved and visible with ROV.
   163         */
   164        config Bool enableDecode = true;
   165    
   166        /*! @_nodoc 
   167         *  Exception stack pointer. Default = null.
   168         *  (Indicates that stack is to be created using
   169         *  staticPlace()
   170         */
   171        config Ptr excStack = null;
   172    
   173        /*! 
   174         * Exception stack size in MAUs.
   175         * Default is 128 bytes.
   176         */
   177        metaonly config SizeT excStackSize = 128;
   178    
   179        /*! 
   180         *  Memory section used for Exception stack.
   181         *  Default is null, which results in the stack
   182         *  being placed in .bss.
   183         */
   184        metaonly config String excStackSection = null;
   185    
   186        /*!
   187         *  User Exception Context Buffer Address
   188         *
   189         *  By default, when an exception occurs, an {@link #ExcContext}
   190         *  structure is allocated on the exception stack and filled in 
   191         *  by the exception handler.
   192         *
   193         *  If {@link #excContextBuffer} is initialized by the user, the 
   194         *  {@link #ExcContext} structure will be placed at that address instead.
   195         *
   196         *  The buffer must be large enough to contain an {@link #ExcContext}
   197         *  structure.
   198         */
   199        metaonly config Ptr excContextBuffer;
   200        
   201        /*!
   202         *  User Exception Stack Buffer Address
   203         *  
   204         *  When an exception occurs, a pointer to the base address
   205         *  of the stack being used by the thread causing the exception is stored
   206         *  in the ExcContext buffer.
   207         *  
   208         *  If {@link #excStackBuffer} is initialized by the user, the 
   209         *  entire contents of that stack will also be 
   210         *  copied to the address specified.
   211         *
   212         *  The buffer must be large enough to contain the largest task stack or ISR
   213         *  stack defined in the application.
   214         */
   215        metaonly config Ptr excStackBuffer;
   216        
   217        /*!
   218         *  User Exception hook function.
   219         *
   220         *  Called just after exception context has been initialized.
   221         */
   222        config ExceptionHookFuncPtr excHookFunc = null;
   223    
   224    internal:   /* not for client use */
   225    
   226        /* assembly code mode registers setup */
   227        Void init();
   228    
   229        /*!
   230         *  ======== excHandlerAsm ========
   231         *  asm code common exception handler
   232         */
   233        Void excHandlerAsm();
   234    
   235        /*!
   236         *  ======== excHandlerDataAsm ========
   237         *  asm code Data Abort exception handler
   238         */
   239        Void excHandlerDataAsm();
   240    
   241        /*!
   242         *  ======== excHandler ========
   243         *  C function exception Handler
   244         */
   245        Void excHandler(UInt *excStack, UInt lr);
   246    
   247        /*!
   248         *  ======== excDumpContext ========
   249         */
   250        Void excDumpContext(UInt pc);
   251    
   252        struct Module_State {
   253            Bool        excActive;          // TRUE if an exception has occurred
   254            ExcContext  *excContext;        // Exception context
   255            Ptr         excStackBuffer;     // where to copy thread's stack
   256            Char        excStack[];         // buffer used for exception stack
   257            SizeT       excStackSize;
   258        };
   259    }
   260    /*
   261     *  @(#) ti.sysbios.family.arm.exc; 2, 0, 0, 0,120; 2-24-2012 11:39:32; /db/vtree/library/trees/avala/avala-q28x/src/ xlibrary
   262    
   263     */
   264