Changeset da1bafb in mainline for kernel/generic/src/interrupt/interrupt.c
- Timestamp:
- 2010-05-24T18:57:31Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0095368
- Parents:
- 666f492
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/interrupt/interrupt.c
r666f492 rda1bafb 32 32 /** 33 33 * @file 34 * @brief 34 * @brief Interrupt redirector. 35 35 * 36 36 * This file provides means of registering interrupt handlers 37 37 * by kernel functions and calling the handlers when interrupts 38 38 * occur. 39 * 39 40 */ 40 41 … … 61 62 62 63 /** 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 */ 70 iroutine exc_register(int n, const char *name, iroutine handler) 69 71 { 70 72 ASSERT(n < IVT_ITEMS); 71 73 72 iroutine old;73 74 74 spinlock_lock(&exctbl_lock); 75 75 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; 78 78 exc_table[n].name = name; 79 79 … … 87 87 * Called directly from the assembler code. 88 88 * CPU is interrupts_disable()'d. 89 * 89 90 */ 90 91 void exc_dispatch(int n, istate_t *istate) 91 92 { 92 93 ASSERT(n < IVT_ITEMS); 93 94 94 95 /* Account user cycles */ 95 96 if (THREAD) { 96 spinlock_lock(&THREAD->lock);97 irq_spinlock_lock(&THREAD->lock, false); 97 98 thread_update_accounting(true); 98 spinlock_unlock(&THREAD->lock);99 } 100 99 irq_spinlock_unlock(&THREAD->lock, false); 100 } 101 101 102 #ifdef CONFIG_UDEBUG 102 if (THREAD) THREAD->udebug.uspace_state = istate; 103 if (THREAD) 104 THREAD->udebug.uspace_state = istate; 103 105 #endif 104 106 105 107 exc_table[n].f(n + IVT_FIRST, istate); 106 108 107 109 #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 111 114 /* 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))) 113 116 thread_exit(); 114 117 115 118 if (THREAD) { 116 spinlock_lock(&THREAD->lock);119 irq_spinlock_lock(&THREAD->lock, false); 117 120 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 */ 123 128 static void exc_undef(int n, istate_t *istate) 124 129 { … … 127 132 } 128 133 129 /** Terminate thread and task if exception came from userspace. */ 134 /** Terminate thread and task if exception came from userspace. 135 * 136 */ 130 137 void fault_if_from_uspace(istate_t *istate, const char *fmt, ...) 131 138 { 132 task_t *task = TASK;133 va_list args;134 135 139 if (!istate_from_uspace(istate)) 136 140 return; 137 141 138 142 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, 140 144 istate_get_pc(istate)); 141 145 142 146 stack_trace_istate(istate); 143 147 144 148 printf("Kill message: "); 149 150 va_list args; 145 151 va_start(args, fmt); 146 152 vprintf(fmt, args); 147 153 va_end(args); 148 154 printf("\n"); 149 155 150 156 /* 151 157 * Userspace can subscribe for FAULT events to take action … … 158 164 event_notify_3(EVENT_FAULT, LOWER32(TASK->taskid), 159 165 UPPER32(TASK->taskid), (unative_t) THREAD); 160 166 161 167 #ifdef CONFIG_UDEBUG 162 168 /* Wait for a debugging session. */ … … 164 170 #endif 165 171 } 166 167 task_kill( task->taskid);172 173 task_kill(TASK->taskid); 168 174 thread_exit(); 169 175 } … … 171 177 #ifdef CONFIG_KCONSOLE 172 178 173 /** kconsole cmd - print all exceptions */ 179 /** Print all exceptions 180 * 181 */ 174 182 static int cmd_exc_print(cmd_arg_t *argv) 175 183 { 176 184 #if (IVT_ITEMS > 0) 177 185 unsigned int i; 178 186 179 187 spinlock_lock(&exctbl_lock); 180 188 181 189 #ifdef __32_BITS__ 182 190 printf("Exc Description Handler Symbol\n"); 183 191 printf("--- -------------------- ---------- --------\n"); 184 192 #endif 185 193 186 194 #ifdef __64_BITS__ 187 195 printf("Exc Description Handler Symbol\n"); … … 191 199 for (i = 0; i < IVT_ITEMS; i++) { 192 200 const char *symbol = symtab_fmt_name_lookup((unative_t) exc_table[i].f); 193 201 194 202 #ifdef __32_BITS__ 195 203 printf("%-3u %-20s %10p %s\n", i + IVT_FIRST, exc_table[i].name, 196 204 exc_table[i].f, symbol); 197 205 #endif 198 206 199 207 #ifdef __64_BITS__ 200 208 printf("%-3u %-20s %18p %s\n", i + IVT_FIRST, exc_table[i].name, … … 216 224 return 1; 217 225 } 218 219 226 220 227 static cmd_info_t exc_info = { … … 227 234 }; 228 235 229 #endif 230 231 /** Initialize generic exception handling support */ 236 #endif /* CONFIG_KCONSOLE */ 237 238 /** Initialize generic exception handling support 239 * 240 */ 232 241 void exc_init(void) 233 242 { 234 int i; 235 243 (void) exc_undef; 244 245 #if (IVT_ITEMS > 0) 246 unsigned int i; 247 236 248 for (i = 0; i < IVT_ITEMS; i++) 237 249 exc_register(i, "undef", (iroutine) exc_undef); 238 250 #endif 251 239 252 #ifdef CONFIG_KCONSOLE 240 253 cmd_initialize(&exc_info);
Note:
See TracChangeset
for help on using the changeset viewer.