Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/interrupt/interrupt.c

    r07640dfd rda1bafb  
    3232/**
    3333 * @file
    34  * @brief       Interrupt redirector.
     34 * @brief Interrupt redirector.
    3535 *
    3636 * This file provides means of registering interrupt handlers
    3737 * by kernel functions and calling the handlers when interrupts
    3838 * occur.
     39 *
    3940 */
    4041
     
    6162
    6263/** Register exception handler
    63  *
    64  * @param n Exception number
    65  * @param name Description
    66  * @param f Exception handler
    67  */
    68 iroutine exc_register(int n, const char *name, iroutine f)
     64 *
     65 * @param n       Exception number
     66 * @param name    Description
     67 * @param handler Exception handler
     68 *
     69 */
     70iroutine exc_register(int n, const char *name, iroutine handler)
    6971{
    7072        ASSERT(n < IVT_ITEMS);
    7173       
    72         iroutine old;
    73        
    7474        spinlock_lock(&exctbl_lock);
    7575       
    76         old = exc_table[n].f;
    77         exc_table[n].f = f;
     76        iroutine old = exc_table[n].f;
     77        exc_table[n].f = handler;
    7878        exc_table[n].name = name;
    7979       
     
    8787 * Called directly from the assembler code.
    8888 * CPU is interrupts_disable()'d.
     89 *
    8990 */
    9091void exc_dispatch(int n, istate_t *istate)
    9192{
    9293        ASSERT(n < IVT_ITEMS);
    93 
     94       
    9495        /* Account user cycles */
     96        if (THREAD) {
     97                irq_spinlock_lock(&THREAD->lock, false);
     98                thread_update_accounting(true);
     99                irq_spinlock_unlock(&THREAD->lock, false);
     100        }
     101       
     102#ifdef CONFIG_UDEBUG
    95103        if (THREAD)
    96                 thread_update_accounting(true);
    97 
     104                THREAD->udebug.uspace_state = istate;
     105#endif
     106       
     107        exc_table[n].f(n + IVT_FIRST, istate);
     108       
    98109#ifdef CONFIG_UDEBUG
    99         if (THREAD) THREAD->udebug.uspace_state = istate;
    100 #endif
    101        
    102         exc_table[n].f(n + IVT_FIRST, istate);
    103 
    104 #ifdef CONFIG_UDEBUG
    105         if (THREAD) THREAD->udebug.uspace_state = NULL;
    106 #endif
    107 
     110        if (THREAD)
     111                THREAD->udebug.uspace_state = NULL;
     112#endif
     113       
    108114        /* This is a safe place to exit exiting thread */
    109         if (THREAD && THREAD->interrupted && istate_from_uspace(istate))
     115        if ((THREAD) && (THREAD->interrupted) && (istate_from_uspace(istate)))
    110116                thread_exit();
    111 
    112         if (THREAD)
     117       
     118        if (THREAD) {
     119                irq_spinlock_lock(&THREAD->lock, false);
    113120                thread_update_accounting(false);
    114 }
    115 
    116 /** Default 'null' exception handler */
     121                irq_spinlock_unlock(&THREAD->lock, false);
     122        }
     123}
     124
     125/** Default 'null' exception handler
     126 *
     127 */
    117128static void exc_undef(int n, istate_t *istate)
    118129{
     
    121132}
    122133
    123 /** Terminate thread and task if exception came from userspace. */
     134/** Terminate thread and task if exception came from userspace.
     135 *
     136 */
    124137void fault_if_from_uspace(istate_t *istate, const char *fmt, ...)
    125138{
    126         task_t *task = TASK;
    127         va_list args;
    128 
    129139        if (!istate_from_uspace(istate))
    130140                return;
    131 
     141       
    132142        printf("Task %s (%" PRIu64 ") killed due to an exception at "
    133             "program counter %p.\n", task->name, task->taskid,
     143            "program counter %p.\n", TASK->name, TASK->taskid,
    134144            istate_get_pc(istate));
    135 
     145       
    136146        stack_trace_istate(istate);
    137 
     147       
    138148        printf("Kill message: ");
     149       
     150        va_list args;
    139151        va_start(args, fmt);
    140152        vprintf(fmt, args);
    141153        va_end(args);
    142154        printf("\n");
    143 
     155       
    144156        /*
    145157         * Userspace can subscribe for FAULT events to take action
     
    152164                event_notify_3(EVENT_FAULT, LOWER32(TASK->taskid),
    153165                    UPPER32(TASK->taskid), (unative_t) THREAD);
    154 
     166               
    155167#ifdef CONFIG_UDEBUG
    156168                /* Wait for a debugging session. */
     
    158170#endif
    159171        }
    160 
    161         task_kill(task->taskid);
     172       
     173        task_kill(TASK->taskid);
    162174        thread_exit();
    163175}
     
    165177#ifdef CONFIG_KCONSOLE
    166178
    167 /** kconsole cmd - print all exceptions */
     179/** Print all exceptions
     180 *
     181 */
    168182static int cmd_exc_print(cmd_arg_t *argv)
    169183{
    170184#if (IVT_ITEMS > 0)
    171185        unsigned int i;
    172 
     186       
    173187        spinlock_lock(&exctbl_lock);
    174 
     188       
    175189#ifdef __32_BITS__
    176190        printf("Exc Description          Handler    Symbol\n");
    177191        printf("--- -------------------- ---------- --------\n");
    178192#endif
    179 
     193       
    180194#ifdef __64_BITS__
    181195        printf("Exc Description          Handler            Symbol\n");
     
    185199        for (i = 0; i < IVT_ITEMS; i++) {
    186200                const char *symbol = symtab_fmt_name_lookup((unative_t) exc_table[i].f);
    187 
     201               
    188202#ifdef __32_BITS__
    189203                printf("%-3u %-20s %10p %s\n", i + IVT_FIRST, exc_table[i].name,
    190204                        exc_table[i].f, symbol);
    191205#endif
    192 
     206               
    193207#ifdef __64_BITS__
    194208                printf("%-3u %-20s %18p %s\n", i + IVT_FIRST, exc_table[i].name,
     
    210224        return 1;
    211225}
    212 
    213226
    214227static cmd_info_t exc_info = {
     
    221234};
    222235
    223 #endif
    224 
    225 /** Initialize generic exception handling support */
     236#endif /* CONFIG_KCONSOLE */
     237
     238/** Initialize generic exception handling support
     239 *
     240 */
    226241void exc_init(void)
    227242{
    228         int i;
    229 
     243        (void) exc_undef;
     244       
     245#if (IVT_ITEMS > 0)
     246        unsigned int i;
     247       
    230248        for (i = 0; i < IVT_ITEMS; i++)
    231249                exc_register(i, "undef", (iroutine) exc_undef);
    232 
     250#endif
     251       
    233252#ifdef CONFIG_KCONSOLE
    234253        cmd_initialize(&exc_info);
Note: See TracChangeset for help on using the changeset viewer.