Project

General

Profile

Statistics
| Branch: | Revision:

scoutos / prex-0.9.0 / bsp / hal / arm / arch / trap.c @ 03e9c04a

History | View | Annotate | Download (3.84 KB)

1
/*-
2
 * Copyright (c) 2005-2009, Kohsuke Ohtani
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
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 * 3. Neither the name of the author nor the names of any co-contributors
14
 *    may be used to endorse or promote products derived from this software
15
 *    without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
 * SUCH DAMAGE.
28
 */
29

    
30
/*
31
 * trap.c - called from the abort handler when a processor detect abort.
32
 */
33

    
34
#include <sys/signal.h>
35
#include <kernel.h>
36
#include <task.h>
37
#include <hal.h>
38
#include <exception.h>
39
#include <cpu.h>
40
#include <trap.h>
41
#include <cpufunc.h>
42
#include <context.h>
43
#include <locore.h>
44

    
45
#ifdef DEBUG
46
/*
47
 * Trap name
48
 */
49
static char *const trap_name[] = {
50
        "Undefined Instruction",
51
        "Prefetch Abort",
52
        "Data Abort"
53
};
54
#define MAXTRAP (sizeof(trap_name) / sizeof(void *) - 1)
55
#endif        /* !DEBUG */
56

    
57
/*
58
 * abort/exception mapping table.
59
 * ARM exception is translated to the architecture
60
 * independent exception code.
61
 */
62
static const int exception_map[] = {
63
        SIGILL,                /* Undefined instruction */
64
        SIGSEGV,        /* Prefech abort */
65
        SIGSEGV,        /* Data abort */
66
};
67

    
68
/*
69
 * Trap handler
70
 * Invoke the exception handler if it is needed.
71
 */
72
void
73
trap_handler(struct cpu_regs *regs)
74
{
75
        u_long trap_no = regs->r0;
76

    
77
        if ((regs->cpsr & PSR_MODE) == PSR_SVC_MODE &&
78
            trap_no == TRAP_DATA_ABORT &&
79
            (regs->pc - 4 == (uint32_t)known_fault1 ||
80
             regs->pc - 4 == (uint32_t)known_fault2 ||
81
             regs->pc - 4 == (uint32_t)known_fault3)) {
82
                DPRINTF(("\n*** Detect Fault! address=%x task=%s ***\n",
83
                         get_faultaddress(), curtask->name));
84
                regs->pc = (uint32_t)copy_fault;
85
                return;
86
        }
87
#ifdef DEBUG
88
        printf("=============================\n");
89
        printf("Trap %x: %s\n", (u_int)trap_no, trap_name[trap_no]);
90
        if (trap_no == TRAP_DATA_ABORT)
91
                printf(" Fault address=%x\n", get_faultaddress());
92
        else if (trap_no == TRAP_PREFETCH_ABORT)
93
                printf(" Fault address=%x\n", regs->pc);
94
        printf("=============================\n");
95

    
96
        trap_dump(regs);
97
        for (;;) ;
98
#endif
99
        if ((regs->cpsr & PSR_MODE) != PSR_USR_MODE)
100
                panic("Kernel exception");
101

    
102
        exception_mark(exception_map[trap_no]);
103
        exception_deliver();
104
}
105

    
106
#ifdef DEBUG
107
void
108
trap_dump(struct cpu_regs *r)
109
{
110

    
111
        printf("Trap frame %x\n", r);
112
        printf(" r0  %08x r1  %08x r2  %08x r3  %08x r4  %08x r5  %08x\n",
113
               r->r0, r->r1, r->r2, r->r3, r->r4, r->r5);
114
        printf(" r6  %08x r7  %08x r8  %08x r9  %08x r10 %08x r11 %08x\n",
115
               r->r6, r->r7, r->r8, r->r9, r->r10, r->r11);
116
        printf(" r12 %08x sp  %08x lr  %08x pc  %08x cpsr %08x\n",
117
               r->r12, r->sp, r->lr, r->pc, r->cpsr);
118

    
119
        printf(" >> interrupt is %s\n",
120
               (r->cpsr & PSR_INT_MASK) ? "disabled" : "enabled");
121

    
122
        printf(" >> task=%s\n", curtask->name);
123
}
124
#endif /* !DEBUG */