Subversion Repositories HelenOS

Rev

Rev 4018 | Rev 4669 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4018 Rev 4117
Line 32... Line 32...
32
/** @file
32
/** @file
33
 *  @brief Exception handlers and exception initialization routines.
33
 *  @brief Exception handlers and exception initialization routines.
34
 */
34
 */
35
 
35
 
36
#include <arch/exception.h>
36
#include <arch/exception.h>
37
#include <arch/debug/print.h>
-
 
38
#include <arch/memstr.h>
37
#include <arch/memstr.h>
39
#include <arch/regutils.h>
38
#include <arch/regutils.h>
40
#include <interrupt.h>
39
#include <interrupt.h>
41
#include <arch/machine.h>
-
 
42
#include <arch/mm/page_fault.h>
40
#include <arch/mm/page_fault.h>
43
#include <arch/barrier.h>
41
#include <arch/barrier.h>
-
 
42
#include <arch/drivers/gxemul.h>
44
#include <print.h>
43
#include <print.h>
45
#include <syscall/syscall.h>
44
#include <syscall/syscall.h>
46
 
45
 
47
/** Offset used in calculation of exception handler's relative address.
46
/** Offset used in calculation of exception handler's relative address.
48
 *
47
 *
Line 258... Line 257...
258
}
257
}
259
 
258
 
260
/** Low-level Prefetch Abort Exception handler. */
259
/** Low-level Prefetch Abort Exception handler. */
261
static void prefetch_abort_exception_entry(void)
260
static void prefetch_abort_exception_entry(void)
262
{
261
{
-
 
262
    asm volatile (
263
    asm("sub lr, lr, #4");
263
        "sub lr, lr, #4"
-
 
264
    );
-
 
265
   
264
    PROCESS_EXCEPTION(EXC_PREFETCH_ABORT);
266
    PROCESS_EXCEPTION(EXC_PREFETCH_ABORT);
265
}
267
}
266
 
268
 
267
/** Low-level Data Abort Exception handler. */
269
/** Low-level Data Abort Exception handler. */
268
static void data_abort_exception_entry(void)
270
static void data_abort_exception_entry(void)
269
{
271
{
-
 
272
    asm volatile (
270
    asm("sub lr, lr, #8");
273
        "sub lr, lr, #8"
-
 
274
    );
-
 
275
   
271
    PROCESS_EXCEPTION(EXC_DATA_ABORT);
276
    PROCESS_EXCEPTION(EXC_DATA_ABORT);
272
}
277
}
273
 
278
 
274
/** Low-level Interrupt Exception handler.
279
/** Low-level Interrupt Exception handler.
275
 *
280
 *
Line 277... Line 282...
277
 * because of possible occurence of nested interrupt exception, which
282
 * because of possible occurence of nested interrupt exception, which
278
 * would overwrite (and thus spoil) stack pointer.
283
 * would overwrite (and thus spoil) stack pointer.
279
 */
284
 */
280
static void irq_exception_entry(void)
285
static void irq_exception_entry(void)
281
{
286
{
-
 
287
    asm volatile (
282
    asm("sub lr, lr, #4");
288
        "sub lr, lr, #4"
-
 
289
    );
-
 
290
   
283
    setup_stack_and_save_regs();
291
    setup_stack_and_save_regs();
284
   
292
   
285
    switch_to_irq_servicing_mode();
293
    switch_to_irq_servicing_mode();
286
   
294
   
287
    CALL_EXC_DISPATCH(EXC_IRQ)
295
    CALL_EXC_DISPATCH(EXC_IRQ)
Line 297... Line 305...
297
{
305
{
298
    istate->r0 = syscall_handler(istate->r0, istate->r1, istate->r2,
306
    istate->r0 = syscall_handler(istate->r0, istate->r1, istate->r2,
299
        istate->r3, istate->r4, istate->r5, istate->r6);
307
        istate->r3, istate->r4, istate->r5, istate->r6);
300
}
308
}
301
 
309
 
-
 
310
/** Returns the mask of active interrupts. */
-
 
311
static inline uint32_t gxemul_irqc_get_sources(void)
-
 
312
{
-
 
313
    return *((uint32_t *) gxemul_irqc);
-
 
314
}
-
 
315
 
302
/** Interrupt Exception handler.
316
/** Interrupt Exception handler.
303
 *
317
 *
304
 * Determines the sources of interrupt and calls their handlers.
318
 * Determines the sources of interrupt and calls their handlers.
305
 */
319
 */
306
static void irq_exception(int exc_no, istate_t *istate)
320
static void irq_exception(int exc_no, istate_t *istate)
307
{
321
{
-
 
322
    uint32_t sources = gxemul_irqc_get_sources();
-
 
323
    unsigned int i;
-
 
324
   
-
 
325
    for (i = 0; i < GXEMUL_IRQC_MAX_IRQ; i++) {
-
 
326
        if (sources & (1 << i)) {
308
    machine_irq_exception(exc_no, istate);
327
            irq_t *irq = irq_dispatch_and_lock(i);
-
 
328
            if (irq) {
-
 
329
                /* The IRQ handler was found. */
-
 
330
                irq->handler(irq);
-
 
331
                spinlock_unlock(&irq->lock);
-
 
332
            } else {
-
 
333
                /* Spurious interrupt.*/
-
 
334
                printf("cpu%d: spurious interrupt (inum=%d)\n",
-
 
335
                    CPU->id, i);
-
 
336
            }
-
 
337
        }
-
 
338
    }
309
}
339
}
310
 
340
 
311
/** Fills exception vectors with appropriate exception handlers. */
341
/** Fills exception vectors with appropriate exception handlers. */
312
void install_exception_handlers(void)
342
void install_exception_handlers(void)
313
{
343
{
Line 327... Line 357...
327
        (unsigned *) EXC_DATA_ABORT_VEC);
357
        (unsigned *) EXC_DATA_ABORT_VEC);
328
   
358
   
329
    install_handler((unsigned) irq_exception_entry,
359
    install_handler((unsigned) irq_exception_entry,
330
        (unsigned *) EXC_IRQ_VEC);
360
        (unsigned *) EXC_IRQ_VEC);
331
   
361
   
332
    install_handler((unsigned)fiq_exception_entry,
362
    install_handler((unsigned) fiq_exception_entry,
333
        (unsigned *) EXC_FIQ_VEC);
363
        (unsigned *) EXC_FIQ_VEC);
334
}
364
}
335
 
365
 
336
#ifdef HIGH_EXCEPTION_VECTORS
366
#ifdef HIGH_EXCEPTION_VECTORS
337
/** Activates use of high exception vectors addresses. */
367
/** Activates use of high exception vectors addresses. */
Line 377... Line 407...
377
 *
407
 *
378
 * @param istate Structure to be printed.
408
 * @param istate Structure to be printed.
379
 */
409
 */
380
void print_istate(istate_t *istate)
410
void print_istate(istate_t *istate)
381
{
411
{
382
    dprintf("istate dump:\n");
412
    printf("istate dump:\n");
383
 
413
   
384
    dprintf(" r0: %x    r1: %x    r2: %x    r3: %x\n",
414
    printf(" r0: %x    r1: %x    r2: %x    r3: %x\n",
385
        istate->r0, istate->r1, istate->r2, istate->r3);
415
        istate->r0, istate->r1, istate->r2, istate->r3);
386
    dprintf(" r4: %x    r5: %x    r6: %x    r7: %x\n",
416
    printf(" r4: %x    r5: %x    r6: %x    r7: %x\n",
387
        istate->r4, istate->r5, istate->r6, istate->r7);
417
        istate->r4, istate->r5, istate->r6, istate->r7);
388
    dprintf(" r8: %x    r8: %x   r10: %x   r11: %x\n",
418
    printf(" r8: %x    r8: %x   r10: %x   r11: %x\n",
389
        istate->r8, istate->r9, istate->r10, istate->r11);
419
        istate->r8, istate->r9, istate->r10, istate->r11);
390
    dprintf(" r12: %x    sp: %x    lr: %x  spsr: %x\n",
420
    printf(" r12: %x    sp: %x    lr: %x  spsr: %x\n",
391
        istate->r12, istate->sp, istate->lr, istate->spsr);
421
        istate->r12, istate->sp, istate->lr, istate->spsr);
392
 
422
   
393
    dprintf(" pc: %x\n", istate->pc);
423
    printf(" pc: %x\n", istate->pc);
394
}
424
}
395
 
425
 
396
/** @}
426
/** @}
397
 */
427
 */