Ignore:
Timestamp:
2010-05-24T18:57:31Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0095368
Parents:
666f492
Message:

major code revision

  • replace spinlocks taken with interrupts disabled with irq_spinlocks
  • change spacing (not indendation) to be tab-size independent
  • use unsigned integer types where appropriate (especially bit flags)
  • visual separation
  • remove argument names in function prototypes
  • string changes
  • correct some formating directives
  • replace various cryptic single-character variables (t, a, m, c, b, etc.) with proper identifiers (thread, task, timeout, as, itm, itc, etc.)
  • unify some assembler constructs
  • unused page table levels are now optimized out in compile time
  • replace several ints (with boolean semantics) with bools
  • use specifically sized types instead of generic types where appropriate (size_t, uint32_t, btree_key_t)
  • improve comments
  • split asserts with conjuction into multiple independent asserts
File:
1 edited

Legend:

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

    r666f492 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 */
    9596        if (THREAD) {
    96                 spinlock_lock(&THREAD->lock);
     97                irq_spinlock_lock(&THREAD->lock, false);
    9798                thread_update_accounting(true);
    98                 spinlock_unlock(&THREAD->lock);
    99         }
    100 
     99                irq_spinlock_unlock(&THREAD->lock, false);
     100        }
     101       
    101102#ifdef CONFIG_UDEBUG
    102         if (THREAD) THREAD->udebug.uspace_state = istate;
     103        if (THREAD)
     104                THREAD->udebug.uspace_state = istate;
    103105#endif
    104106       
    105107        exc_table[n].f(n + IVT_FIRST, istate);
    106 
     108       
    107109#ifdef CONFIG_UDEBUG
    108         if (THREAD) THREAD->udebug.uspace_state = NULL;
    109 #endif
    110 
     110        if (THREAD)
     111                THREAD->udebug.uspace_state = NULL;
     112#endif
     113       
    111114        /* This is a safe place to exit exiting thread */
    112         if (THREAD && THREAD->interrupted && istate_from_uspace(istate))
     115        if ((THREAD) && (THREAD->interrupted) && (istate_from_uspace(istate)))
    113116                thread_exit();
    114 
     117       
    115118        if (THREAD) {
    116                 spinlock_lock(&THREAD->lock);
     119                irq_spinlock_lock(&THREAD->lock, false);
    117120                thread_update_accounting(false);
    118                 spinlock_unlock(&THREAD->lock);
    119         }
    120 }
    121 
    122 /** Default 'null' exception handler */
     121                irq_spinlock_unlock(&THREAD->lock, false);
     122        }
     123}
     124
     125/** Default 'null' exception handler
     126 *
     127 */
    123128static void exc_undef(int n, istate_t *istate)
    124129{
     
    127132}
    128133
    129 /** Terminate thread and task if exception came from userspace. */
     134/** Terminate thread and task if exception came from userspace.
     135 *
     136 */
    130137void fault_if_from_uspace(istate_t *istate, const char *fmt, ...)
    131138{
    132         task_t *task = TASK;
    133         va_list args;
    134 
    135139        if (!istate_from_uspace(istate))
    136140                return;
    137 
     141       
    138142        printf("Task %s (%" PRIu64 ") killed due to an exception at "
    139             "program counter %p.\n", task->name, task->taskid,
     143            "program counter %p.\n", TASK->name, TASK->taskid,
    140144            istate_get_pc(istate));
    141 
     145       
    142146        stack_trace_istate(istate);
    143 
     147       
    144148        printf("Kill message: ");
     149       
     150        va_list args;
    145151        va_start(args, fmt);
    146152        vprintf(fmt, args);
    147153        va_end(args);
    148154        printf("\n");
    149 
     155       
    150156        /*
    151157         * Userspace can subscribe for FAULT events to take action
     
    158164                event_notify_3(EVENT_FAULT, LOWER32(TASK->taskid),
    159165                    UPPER32(TASK->taskid), (unative_t) THREAD);
    160 
     166               
    161167#ifdef CONFIG_UDEBUG
    162168                /* Wait for a debugging session. */
     
    164170#endif
    165171        }
    166 
    167         task_kill(task->taskid);
     172       
     173        task_kill(TASK->taskid);
    168174        thread_exit();
    169175}
     
    171177#ifdef CONFIG_KCONSOLE
    172178
    173 /** kconsole cmd - print all exceptions */
     179/** Print all exceptions
     180 *
     181 */
    174182static int cmd_exc_print(cmd_arg_t *argv)
    175183{
    176184#if (IVT_ITEMS > 0)
    177185        unsigned int i;
    178 
     186       
    179187        spinlock_lock(&exctbl_lock);
    180 
     188       
    181189#ifdef __32_BITS__
    182190        printf("Exc Description          Handler    Symbol\n");
    183191        printf("--- -------------------- ---------- --------\n");
    184192#endif
    185 
     193       
    186194#ifdef __64_BITS__
    187195        printf("Exc Description          Handler            Symbol\n");
     
    191199        for (i = 0; i < IVT_ITEMS; i++) {
    192200                const char *symbol = symtab_fmt_name_lookup((unative_t) exc_table[i].f);
    193 
     201               
    194202#ifdef __32_BITS__
    195203                printf("%-3u %-20s %10p %s\n", i + IVT_FIRST, exc_table[i].name,
    196204                        exc_table[i].f, symbol);
    197205#endif
    198 
     206               
    199207#ifdef __64_BITS__
    200208                printf("%-3u %-20s %18p %s\n", i + IVT_FIRST, exc_table[i].name,
     
    216224        return 1;
    217225}
    218 
    219226
    220227static cmd_info_t exc_info = {
     
    227234};
    228235
    229 #endif
    230 
    231 /** Initialize generic exception handling support */
     236#endif /* CONFIG_KCONSOLE */
     237
     238/** Initialize generic exception handling support
     239 *
     240 */
    232241void exc_init(void)
    233242{
    234         int i;
    235 
     243        (void) exc_undef;
     244       
     245#if (IVT_ITEMS > 0)
     246        unsigned int i;
     247       
    236248        for (i = 0; i < IVT_ITEMS; i++)
    237249                exc_register(i, "undef", (iroutine) exc_undef);
    238 
     250#endif
     251       
    239252#ifdef CONFIG_KCONSOLE
    240253        cmd_initialize(&exc_info);
Note: See TracChangeset for help on using the changeset viewer.