Changeset e3038b4 in mainline


Ignore:
Timestamp:
2010-06-28T22:45:51Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
49eb681
Parents:
05e3cb8 (diff), e4a4b44 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge unified panic architecture (Phase 1).

Note that this is still work in progress as there are the following sharp edges:

  • imprecise detection of read/write accesses on some architectures
  • missing or imperfect capability to print stack traces on some architectures
  • istate_t on some architectures may contain too little valuable information
  • basically all trap frames need to be reorganized to look like a normal stack frame on the stack trace so that there are no missing frames
  • panic_common() could print more information about the current context such as the task name, thread name, ASID etc.
  • functions that call panic_*() should be protected against inlining to avoid missing or confusing stack frames in the stack trace
Location:
kernel
Files:
1 added
5 deleted
37 edited

Legend:

Unmodified
Added
Removed
  • kernel/Makefile

    r05e3cb8 re3038b4  
    201201        generic/src/debug/symtab.c \
    202202        generic/src/debug/stacktrace.c \
     203        generic/src/debug/panic.c \
    203204        generic/src/interrupt/interrupt.c \
    204205        generic/src/main/main.c \
  • kernel/arch/abs32le/src/abs32le.c

    r05e3cb8 re3038b4  
    114114}
    115115
    116 void panic_printf(const char *fmt, ...)
     116void istate_decode(istate_t *istate)
    117117{
    118         va_list args;
    119        
    120         va_start(args, fmt);
    121         vprintf(fmt, args);
    122         va_end(args);
    123        
    124         halt();
     118        (void) istate;
    125119}
    126120
  • kernel/arch/amd64/include/interrupt.h

    r05e3cb8 re3038b4  
    112112extern void (* eoi_function)(void);
    113113
    114 extern void decode_istate(int n, istate_t *istate);
    115114extern void interrupt_init(void);
    116115extern void trap_virtual_enable_irqs(uint16_t irqmask);
  • kernel/arch/amd64/include/types.h

    r05e3cb8 re3038b4  
    5050} fncptr_t;
    5151
    52 /**< Formats for uintptr_t, size_t */
     52/* Formats for uintptr_t, size_t */
    5353#define PRIp  "llx"
    5454#define PRIs  "llu"
    5555
    56 /**< Formats for (u)int8_t, (u)int16_t, (u)int32_t, (u)int64_t and (u)native_t */
     56/* Formats for (u)int8_t, (u)int16_t, (u)int32_t, (u)int64_t and (u)native_t */
    5757#define PRId8   "d"
    5858#define PRId16  "d"
  • kernel/arch/amd64/src/asm_utils.S

    r05e3cb8 re3038b4  
    5151.global interrupt_handlers
    5252.global syscall_entry
    53 .global panic_printf
    54 
    55 panic_printf:
    56         movabsq $halt, %rax
    57         movq %rax, (%rsp)
    58         jmp printf
    59 
    6053.global cpuid
    6154.global has_cpuid
     
    234227        save_all_gpr
    235228        cld
    236        
    237         # Stop stack traces here
    238         xorq %rbp, %rbp
    239        
    240         movq $(\i), %rdi    # %rdi - first parameter
    241         movq %rsp, %rsi     # %rsi - pointer to istate
    242         call exc_dispatch   # exc_dispatch(i, istate)
     229
     230        #
     231        # Stop stack traces here if we came from userspace.
     232        #
     233        movq %cs, %rax
     234        xorq %rdx, %rdx
     235        cmpq %rax, IREGISTER_SPACE+16(%rsp)
     236        cmovneq %rdx, %rbp
     237
     238        movq $(\i), %rdi        # %rdi - first parameter
     239        movq %rsp, %rsi         # %rsi - pointer to istate
     240        call exc_dispatch       # exc_dispatch(i, istate)
    243241       
    244242        restore_all_gpr
     
    290288        pushq %rcx
    291289        pushq %r11
    292        
    293         movq %r10, %rcx   # Copy the 4th argument where it is expected
     290        pushq %rbp
     291
     292        xorq %rbp, %rbp         # stop the stack traces here
     293
     294        movq %r10, %rcx         # Copy the 4th argument where it is expected
    294295        pushq %rax
    295296        call syscall_handler
    296297        addq $8, %rsp
    297        
     298               
     299        popq %rbp
    298300        popq %r11
    299301        popq %rcx
  • kernel/arch/amd64/src/interrupt.c

    r05e3cb8 re3038b4  
    6363void (* eoi_function)(void) = NULL;
    6464
    65 void decode_istate(int n, istate_t *istate)
    66 {
    67         const char *symbol = symtab_fmt_name_lookup(istate->rip);
    68        
    69         printf("-----EXCEPTION(%d) OCCURED----- ( %s )\n", n, __func__);
    70         printf("%%rip: %#llx (%s)\n", istate->rip, symbol);
    71         printf("ERROR_WORD=%#llx\n", istate->error_word);
    72         printf("%%cs=%#llx, rflags=%#llx, %%cr0=%#llx\n", istate->cs,
    73             istate->rflags, read_cr0());
    74         printf("%%rax=%#llx, %%rcx=%#llx, %%rdx=%#llx\n", istate->rax,
     65void istate_decode(istate_t *istate)
     66{
     67        printf("error_word=%#llx\n", istate->error_word);
     68        printf("cs =%#0.16llx\trflags=%#0.16llx\n", istate->cs,
     69            istate->rflags);
     70        printf("rax=%#0.16llx\trbx=%#0.16llx\trcx=%#0.16llx\n", istate->rax,
    7571            istate->rcx, istate->rdx);
    76         printf("%%rsi=%#llx, %%rdi=%#llx, %%r8=%#llx\n", istate->rsi,
     72        printf("rsi=%#0.16llx\trdi=%#0.16llx\tr8 =%#0.16llx\n", istate->rsi,
    7773            istate->rdi, istate->r8);
    78         printf("%%r9=%#llx, %%r10=%#llx, %%r11=%#llx\n", istate->r9,
     74        printf("r9 =%#0.16llx\tr10=%#0.16llx\tr11=%#0.16llx\n", istate->r9,
    7975            istate->r10, istate->r11);
    80         printf("%%rsp=%#llx\n", &istate->stack[0]);
    81        
    82         stack_trace_istate(istate);
    8376}
    8477
     
    9588{
    9689        fault_if_from_uspace(istate, "Unserviced interrupt: %u.", n);
    97         decode_istate(n, istate);
    98         panic("Unserviced interrupt.");
     90        panic_badtrap(istate, n, "Unserviced interrupt.");
    9991}
    10092
     
    10294{
    10395        fault_if_from_uspace(istate, "Divide error.");
    104         decode_istate(n, istate);
    105         panic("Divide error.");
     96        panic_badtrap(istate, n, "Divide error.");
    10697}
    10798
     
    129120                fault_if_from_uspace(istate, "General protection fault.");
    130121        }
    131        
    132         decode_istate(n, istate);
    133         panic("General protection fault.");
     122        panic_badtrap(istate, n, "General protection fault.");
    134123}
    135124
     
    137126{
    138127        fault_if_from_uspace(istate, "Stack fault.");
    139         decode_istate(n, istate);
    140         panic("Stack fault.");
     128        panic_badtrap(istate, n, "Stack fault.");
    141129}
    142130
  • kernel/arch/amd64/src/mm/page.c

    r05e3cb8 re3038b4  
    8989       
    9090        if (as_page_fault(page, access, istate) == AS_PF_FAULT) {
    91                 fault_if_from_uspace(istate, "Page fault: %p.", page);
    92                 decode_istate(n, istate);
    93                 panic("Page fault: %p", page);
     91                fault_if_from_uspace(istate, "Page fault: %#x.", page);
     92                panic_memtrap(istate, access, page, "Page fault.");
    9493        }
    9594}
  • kernel/arch/arm32/Makefile.inc

    r05e3cb8 re3038b4  
    4646        arch/$(KARCH)/src/context.S \
    4747        arch/$(KARCH)/src/dummy.S \
    48         arch/$(KARCH)/src/panic.S \
    4948        arch/$(KARCH)/src/cpu/cpu.c \
    5049        arch/$(KARCH)/src/ddi/ddi.c \
  • kernel/arch/arm32/include/exception.h

    r05e3cb8 re3038b4  
    2828 */
    2929
    30 /** @addtogroup arm32   
     30/** @addtogroup arm32
    3131 * @{
    3232 */
     
    141141extern void install_exception_handlers(void);
    142142extern void exception_init(void);
    143 extern void print_istate(istate_t *istate);
    144143extern void reset_exception_entry(void);
    145144extern void irq_exception_entry(void);
  • kernel/arch/arm32/src/exc_handler.S

    r05e3cb8 re3038b4  
    9898        stmfd r13!, {r13, lr}^
    9999        stmfd r13!, {r2}
     100
     101        # Stop stack traces here
     102        mov fp, #0
     103       
    100104        b 2f
    101105
     
    123127        stmfd r13!, {r2}
    1241282:
    125         # Stop stack traces here
    126         mov fp, #0
    127129.endm
    128130
  • kernel/arch/arm32/src/exception.c

    r05e3cb8 re3038b4  
    173173 * @param istate Structure to be printed.
    174174 */
    175 void print_istate(istate_t *istate)
     175void istate_decode(istate_t *istate)
    176176{
    177         printf("istate dump:\n");
    178        
    179         printf(" r0: %x    r1: %x    r2: %x    r3: %x\n",
     177        printf("r0 =%#0.8lx\tr1 =%#0.8lx\tr2 =%#0.8lx\tr3 =%#0.8lx\n",
    180178            istate->r0, istate->r1, istate->r2, istate->r3);
    181         printf(" r4: %x    r5: %x    r6: %x    r7: %x\n",
     179        printf("r4 =%#0.8lx\tr5 =%#0.8lx\tr6 =%#0.8lx\tr7 =%#0.8lx\n",
    182180            istate->r4, istate->r5, istate->r6, istate->r7);
    183         printf(" r8: %x    r8: %x   r10: %x    fp: %x\n",
     181        printf("r8 =%#0.8lx\tr9 =%#0.8lx\tr10=%#0.8lx\tfp =%#0.8lx\n",
    184182            istate->r8, istate->r9, istate->r10, istate->fp);
    185         printf(" r12: %x    sp: %x    lr: %x  spsr: %x\n",
     183        printf("r12=%#0.8lx\tsp =%#0.8lx\tlr =%#0.8lx\tspsr=%#0.8lx\n",
    186184            istate->r12, istate->sp, istate->lr, istate->spsr);
    187        
    188         printf(" pc: %x\n", istate->pc);
    189 
    190         stack_trace_istate(istate);
    191185}
    192186
  • kernel/arch/arm32/src/mm/page.c

    r05e3cb8 re3038b4  
    2727 */
    2828
    29 /** @addtogroup arm32mm 
     29/** @addtogroup arm32mm
    3030 * @{
    3131 */
  • kernel/arch/arm32/src/mm/page_fault.c

    r05e3cb8 re3038b4  
    183183        if (ret == AS_PF_FAULT) {
    184184                fault_if_from_uspace(istate, "Page fault: %#x.", badvaddr);
    185                 print_istate(istate);
    186                 printf("page fault - pc: %x, va: %x, status: %x(%x), "
    187                     "access:%d\n", istate->pc, badvaddr, fsr.status, fsr,
    188                     access);
    189                
    190                 panic("Page fault.");
     185                panic_memtrap(istate, access, badvaddr, "Page fault.");
    191186        }
    192187}
     
    203198
    204199        if (ret == AS_PF_FAULT) {
    205                 printf("prefetch_abort\n");
    206                 print_istate(istate);
    207                 panic("page fault - prefetch_abort at address: %x.",
    208                     istate->pc);
     200                panic_memtrap(istate, PF_ACCESS_EXEC, istate->pc,
     201                    "Page fault - prefetch_abort.");
    209202        }
    210203}
  • kernel/arch/ia32/Makefile.inc

    r05e3cb8 re3038b4  
    7676ARCH_SOURCES = \
    7777        arch/$(KARCH)/src/context.S \
    78         arch/$(KARCH)/src/debug/panic.s \
    7978        arch/$(KARCH)/src/debug/stacktrace.c \
    8079        arch/$(KARCH)/src/debug/stacktrace_asm.S \
  • kernel/arch/ia32/include/interrupt.h

    r05e3cb8 re3038b4  
    113113extern void (* eoi_function)(void);
    114114
    115 extern void decode_istate(istate_t *istate);
    116115extern void interrupt_init(void);
    117116extern void trap_virtual_enable_irqs(uint16_t irqmask);
  • kernel/arch/ia32/src/asm.S

    r05e3cb8 re3038b4  
    163163        pushl %edi      # remember return user address
    164164
     165        xorl %ebp, %ebp # stop stack traces here
     166
    165167        pushl %gs       # remember TLS
    166168
     
    196198# and call exc_dispatch().
    197199#
    198 #define INTERRUPT_ALIGN 64
     200#define INTERRUPT_ALIGN 128
    199201.macro handler i n
    200202       
     
    224226                movw %ax, %ds
    225227                movw %ax, %es
    226                
     228       
     229                xorl %ebp, %ebp
     230
    227231                cld
    228232                sti
     
    230234                call syscall_handler
    231235                cli
    232                 addl $28, %esp         # clean-up of parameters
     236
     237                movl 20(%esp), %ebp     # restore EBP
     238                addl $28, %esp          # clean-up of parameters
    233239               
    234240                popl %gs
     
    280286                movw %ax, %es
    281287               
    282                 # stop stack traces here
     288                # stop stack traces here if we came from userspace
     289                cmpl $8, 40(%esp)
     290                jz 0f
    283291                xorl %ebp, %ebp
    284                
     292
     2930:             
    285294                pushl %esp          # *istate
    286295                pushl $(\i)         # intnum
  • kernel/arch/ia32/src/interrupt.c

    r05e3cb8 re3038b4  
    6363void (* eoi_function)(void) = NULL;
    6464
    65 void decode_istate(istate_t *istate)
    66 {
    67         const char *symbol = symtab_fmt_name_lookup(istate->eip);
    68        
    69         if (CPU)
    70                 printf("----------------EXCEPTION OCCURED (cpu%u)----------------\n", CPU->id);
    71         else
    72                 printf("----------------EXCEPTION OCCURED----------------\n");
    73        
    74         printf("%%eip: %#lx (%s)\n", istate->eip, symbol);
    75         printf("ERROR_WORD=%#lx\n", istate->error_word);
    76         printf("%%cs=%#lx,flags=%#lx\n", istate->cs, istate->eflags);
    77         printf("%%eax=%#lx, %%ecx=%#lx, %%edx=%#lx, %%esp=%p\n", istate->eax, istate->ecx, istate->edx, &istate->stack[0]);
    78         printf("stack: %#lx, %#lx, %#lx, %#lx\n", istate->stack[0], istate->stack[1], istate->stack[2], istate->stack[3]);
    79         printf("       %#lx, %#lx, %#lx, %#lx\n", istate->stack[4], istate->stack[5], istate->stack[6], istate->stack[7]);
    80        
    81         stack_trace_istate(istate);
     65void istate_decode(istate_t *istate)
     66{
     67        printf("error_word=%#lx\n", istate->error_word);
     68        printf("cs =%#0.8lx\teflags=%#0.8lx\n", istate->cs, istate->eflags);
     69        printf("eax=%#0.8lx\tecx=%#0.8lx\tedx=%#0.8lx\n",
     70            istate->eax, istate->ecx, istate->edx);
    8271}
    8372
     
    9483{
    9584        fault_if_from_uspace(istate, "Unserviced interrupt: %u.", n);
    96        
    97         decode_istate(istate);
    98         panic("Unserviced interrupt: %u.", n);
     85        panic_badtrap(istate, n, "Unserviced interrupt: %u.", n);
    9986}
    10087
     
    10289{
    10390        fault_if_from_uspace(istate, "Divide error.");
    104        
    105         decode_istate(istate);
    106         panic("Divide error.");
     91        panic_badtrap(istate, n, "Divide error.");
    10792}
    10893
     
    128113                fault_if_from_uspace(istate, "General protection fault.");
    129114        }
    130        
    131         decode_istate(istate);
    132         panic("General protection fault.");
     115        panic_badtrap(istate, n, "General protection fault.");
    133116}
    134117
     
    136119{
    137120        fault_if_from_uspace(istate, "Stack fault.");
    138        
    139         decode_istate(istate);
    140         panic("Stack fault.");
     121        panic_badtrap(istate, n, "Stack fault.");
    141122}
    142123
     
    149130        );
    150131       
    151         fault_if_from_uspace(istate, "SIMD FP exception(19), MXCSR: %#zx.",
     132        fault_if_from_uspace(istate, "SIMD FP exception(19), MXCSR=%#0.8x.",
    152133            (unative_t) mxcsr);
    153        
    154         decode_istate(istate);
    155         printf("MXCSR: %#lx\n", mxcsr);
    156         panic("SIMD FP exception(19).");
     134        panic_badtrap(istate, n, "SIMD FP exception, MXCSR=%#0.8x");
    157135}
    158136
     
    164142#else
    165143        fault_if_from_uspace(istate, "FPU fault.");
    166         panic("FPU fault.");
     144        panic_badtrap(istate, n, "FPU fault.");
    167145#endif
    168146}
  • kernel/arch/ia32/src/mm/page.c

    r05e3cb8 re3038b4  
    115115        if (as_page_fault(page, access, istate) == AS_PF_FAULT) {
    116116                fault_if_from_uspace(istate, "Page fault: %#x.", page);
    117                
    118                 decode_istate(istate);
    119                 printf("page fault address: %#lx\n", page);
    120                 panic("Page fault.");
     117                panic_memtrap(istate, access, page, "Page fault.");
    121118        }
    122119}
  • kernel/arch/ia64/src/asm.S

    r05e3cb8 re3038b4  
    137137        br cpu_halt
    138138
    139 .global panic_printf
    140 panic_printf:
    141         {
    142                 br.call.sptk.many b0=printf
    143         }
    144         br halt
    145 
    146139/** Switch to userspace - low level code.
    147140 *
  • kernel/arch/ia64/src/interrupt.c

    r05e3cb8 re3038b4  
    133133}
    134134
    135 static void dump_interrupted_context(istate_t *istate)
    136 {
    137         putchar('\n');
    138         printf("Interrupted context dump:\n");
     135void istate_decode(istate_t *istate)
     136{
    139137        printf("ar.bsp=%p\tar.bspstore=%p\n", istate->ar_bsp,
    140138            istate->ar_bspstore);
     
    183181       
    184182        fault_if_from_uspace(istate, "General Exception (%s).", desc);
    185        
    186         dump_interrupted_context(istate);
    187         panic("General Exception (%s).", desc);
     183        panic_badtrap(istate, vector, "General Exception (%s).", desc);
    188184}
    189185
     
    195191        fault_if_from_uspace(istate, "Interruption: %#hx (%s).",
    196192            (uint16_t) vector, vector_to_string(vector));
    197         dump_interrupted_context(istate);
    198         panic("Interruption: %#hx (%s).", (uint16_t) vector,
    199             vector_to_string(vector));
     193        panic_badtrap(istate, vector, "Interruption: %#hx (%s).",
     194            (uint16_t) vector, vector_to_string(vector));
    200195#endif
    201196}
     
    226221        fault_if_from_uspace(istate, "Interruption: %#hx (%s).",
    227222            (uint16_t) vector, vector_to_string(vector));
    228         dump_interrupted_context(istate);
    229         panic("Interruption: %#hx (%s).", (uint16_t) vector,
    230             vector_to_string(vector));
     223        panic_badtrap(istate, vector, "Interruption: %#hx (%s).",
     224            (uint16_t) vector, vector_to_string(vector));
    231225}
    232226
  • kernel/arch/ia64/src/mm/tlb.c

    r05e3cb8 re3038b4  
    500500                if (as_page_fault(va, PF_ACCESS_EXEC, istate) == AS_PF_FAULT) {
    501501                        fault_if_from_uspace(istate, "Page fault at %p.", va);
    502                         panic("%s: va=%p, rid=%d, iip=%p.", __func__, va, rid,
    503                             istate->cr_iip);
     502                        panic_memtrap(istate, PF_ACCESS_EXEC, va,
     503                            "Page fault.");
    504504                }
    505505        }
     
    622622                if (as_page_fault(va, PF_ACCESS_READ, istate) == AS_PF_FAULT) {
    623623                        fault_if_from_uspace(istate, "Page fault at %p.", va);
    624                         panic("%s: va=%p, rid=%d, iip=%p.", __func__, va, rid,
    625                             istate->cr_iip);
     624                        panic_memtrap(istate, PF_ACCESS_READ, va,
     625                            "Page fault.");
    626626                }
    627627        }
     
    671671                if (as_page_fault(va, PF_ACCESS_WRITE, istate) == AS_PF_FAULT) {
    672672                        fault_if_from_uspace(istate, "Page fault at %p.", va);
    673                         panic("%s: va=%p, rid=%d, iip=%p.", __func__, va, rid,
    674                             istate->cr_iip);
     673                        panic_memtrap(istate, PF_ACCESS_WRITE, va,
     674                            "Page fault.");
    675675                }
    676676        }
     
    708708                if (as_page_fault(va, PF_ACCESS_EXEC, istate) == AS_PF_FAULT) {
    709709                        fault_if_from_uspace(istate, "Page fault at %p.", va);
    710                         panic("%s: va=%p, rid=%d, iip=%p.", __func__, va, rid,
    711                             istate->cr_iip);
     710                        panic_memtrap(istate, PF_ACCESS_EXEC, va,
     711                            "Page fault.");
    712712                }
    713713        }
     
    745745                if (as_page_fault(va, PF_ACCESS_READ, istate) == AS_PF_FAULT) {
    746746                        fault_if_from_uspace(istate, "Page fault at %p.", va);
    747                         panic("%s: va=%p, rid=%d, iip=%p.", __func__, va, rid,
    748                             istate->cr_iip);
     747                        panic_memtrap(istate, PF_ACCESS_READ, va,
     748                            "Page fault.");
    749749                }
    750750        }
     
    778778        if (as_page_fault(va, PF_ACCESS_WRITE, istate) == AS_PF_FAULT) {
    779779                fault_if_from_uspace(istate, "Page fault at %p.", va);
    780                 panic("%s: va=%p, rid=%d, iip=%p.", __func__, va, rid,
    781                     istate->cr_iip);
     780                panic_memtrap(istate, PF_ACCESS_WRITE, va, "Page fault.");
    782781        }
    783782        page_table_unlock(AS, true);
     
    819818                if (as_page_fault(va, PF_ACCESS_READ, istate) == AS_PF_FAULT) {
    820819                        fault_if_from_uspace(istate, "Page fault at %p.", va);
    821                         panic("%s: va=%p, rid=%d.", __func__, va, rid);
     820                        panic_memtrap(istate, PF_ACCESS_READ, va,
     821                            "Page fault.");
    822822                }
    823823        }
  • kernel/arch/mips32/Makefile.inc

    r05e3cb8 re3038b4  
    5454        arch/$(KARCH)/src/start.S \
    5555        arch/$(KARCH)/src/context.S \
    56         arch/$(KARCH)/src/panic.S \
    5756        arch/$(KARCH)/src/mips32.c \
    5857        arch/$(KARCH)/src/asm.S \
  • kernel/arch/mips32/src/exception.c

    r05e3cb8 re3038b4  
    7272};
    7373
    74 static void print_regdump(istate_t *istate)
    75 {
    76         printf("PC: %#x(%s) RA: %#x(%s), SP(%p)\n", istate->epc,
    77             symtab_fmt_name_lookup(istate->epc), istate->ra,
    78             symtab_fmt_name_lookup(istate->ra), istate->sp);
     74void istate_decode(istate_t *istate)
     75{
     76        printf("at=%p\tv0=%p\tv1=%p\n", istate->at, istate->v0, istate->v1);
     77        printf("a0=%p\ta1=%p\ta2=%p\n", istate->a0, istate->a1, istate->a2);
     78        printf("a3=%p\tt0=%p\tt1=%p\n", istate->a3, istate->t0, istate->t1);
     79        printf("t2=%p\tt3=%p\tt4=%p\n", istate->t2, istate->t3, istate->t4);
     80        printf("t5=%p\tt6=%p\tt7=%p\n", istate->t5, istate->t6, istate->t7);
     81        printf("t8=%p\tt9=%p\tgp=%p\n", istate->t8, istate->t9, istate->gp);
     82        printf("sp=%p\tra=%p\t\n", istate->sp, istate->ra);
     83        printf("lo=%p\thi=%p\t\n", istate->lo, istate->hi);
     84        printf("cp0_status=%p\tcp0_epc=%p\tk1=%p\n",
     85            istate->status, istate->epc, istate->k1);
    7986}
    8087
     
    8289{
    8390        fault_if_from_uspace(istate, "Unhandled exception %s.", exctable[n]);
    84        
    85         print_regdump(istate);
    86         panic("Unhandled exception %s.", exctable[n]);
     91        panic_badtrap(istate, n, "Unhandled exception %s.", exctable[n]);
    8792}
    8893
     
    125130                scheduler_fpu_lazy_request();
    126131        else {
    127                 fault_if_from_uspace(istate, "Unhandled Coprocessor Unusable Exception.");
    128                 panic("Unhandled Coprocessor Unusable Exception.");
     132                fault_if_from_uspace(istate,
     133                    "Unhandled Coprocessor Unusable Exception.");
     134                panic_badtrap(istate, n,
     135                    "Unhandled Coprocessor Unusable Exception.");
    129136        }
    130137}
     
    162169static void syscall_exception(unsigned int n, istate_t *istate)
    163170{
    164         panic("Syscall is handled through shortcut.");
     171        fault_if_from_uspace(istate, "Syscall is handled through shortcut.");
    165172}
    166173
  • kernel/arch/mips32/src/mm/tlb.c

    r05e3cb8 re3038b4  
    321321void tlb_refill_fail(istate_t *istate)
    322322{
    323         const char *symbol = symtab_fmt_name_lookup(istate->epc);
    324         const char *sym2 = symtab_fmt_name_lookup(istate->ra);
    325        
    326         fault_if_from_uspace(istate, "TLB Refill Exception on %p.",
    327             cp0_badvaddr_read());
    328         panic("%x: TLB Refill Exception at %x (%s<-%s).", cp0_badvaddr_read(),
    329             istate->epc, symbol, sym2);
     323        uintptr_t va = cp0_badvaddr_read();
     324       
     325        fault_if_from_uspace(istate, "TLB Refill Exception on %p.", va);
     326        panic_memtrap(istate, PF_ACCESS_READ, va, "TLB Refill Exception.");
    330327}
    331328
     
    333330void tlb_invalid_fail(istate_t *istate)
    334331{
    335         const char *symbol = symtab_fmt_name_lookup(istate->epc);
    336        
    337         fault_if_from_uspace(istate, "TLB Invalid Exception on %p.",
    338             cp0_badvaddr_read());
    339         panic("%x: TLB Invalid Exception at %x (%s).", cp0_badvaddr_read(),
    340             istate->epc, symbol);
     332        uintptr_t va = cp0_badvaddr_read();
     333       
     334        fault_if_from_uspace(istate, "TLB Invalid Exception on %p.", va);
     335        panic_memtrap(istate, PF_ACCESS_READ, va, "TLB Invalid Exception.");
    341336}
    342337
    343338void tlb_modified_fail(istate_t *istate)
    344339{
    345         const char *symbol = symtab_fmt_name_lookup(istate->epc);
    346        
    347         fault_if_from_uspace(istate, "TLB Modified Exception on %p.",
    348             cp0_badvaddr_read());
    349         panic("%x: TLB Modified Exception at %x (%s).", cp0_badvaddr_read(),
    350             istate->epc, symbol);
     340        uintptr_t va = cp0_badvaddr_read();
     341       
     342        fault_if_from_uspace(istate, "TLB Modified Exception on %p.", va);
     343        panic_memtrap(istate, PF_ACCESS_WRITE, va, "TLB Modified Exception.");
    351344}
    352345
  • kernel/arch/ppc32/Makefile.inc

    r05e3cb8 re3038b4  
    4040ARCH_SOURCES = \
    4141        arch/$(KARCH)/src/context.S \
    42         arch/$(KARCH)/src/debug/panic.s \
    4342        arch/$(KARCH)/src/debug/stacktrace.c \
    4443        arch/$(KARCH)/src/debug/stacktrace_asm.S \
  • kernel/arch/ppc32/include/types.h

    r05e3cb8 re3038b4  
    5050} fncptr_t;
    5151
    52 /**< Formats for uintptr_t, size_t */
     52/** Formats for uintptr_t, size_t */
    5353#define PRIp  "x"
    5454#define PRIs  "u"
    5555
    56 /**< Formats for (u)int8_t, (u)int16_t, (u)int32_t, (u)int64_t and (u)native_t */
     56/** Formats for (u)int8_t, (u)int16_t, (u)int32_t, (u)int64_t and (u)native_t */
    5757#define PRId8   "d"
    5858#define PRId16  "d"
  • kernel/arch/ppc32/src/interrupt.c

    r05e3cb8 re3038b4  
    5050                :: [dec] "r" (1000)
    5151        );
     52}
     53
     54void istate_decode(istate_t *istate)
     55{
     56        printf("r0 =%p\tr1 =%p\tr2 =%p\n", istate->r0, istate->sp, istate->r2);
     57        printf("r3 =%p\tr4 =%p\tr5 =%p\n", istate->r3, istate->r4, istate->r5);
     58        printf("r6 =%p\tr7 =%p\tr8 =%p\n", istate->r6, istate->r7, istate->r8);
     59        printf("r9 =%p\tr10=%p\tr11=%p\n",
     60            istate->r9, istate->r10, istate->r11);
     61        printf("r12=%p\tr13=%p\tr14=%p\n",
     62            istate->r12, istate->r13, istate->r14);
     63        printf("r15=%p\tr16=%p\tr17=%p\n",
     64            istate->r15, istate->r16, istate->r17);
     65        printf("r18=%p\tr19=%p\tr20=%p\n",
     66            istate->r18, istate->r19, istate->r20);
     67        printf("r21=%p\tr22=%p\tr23=%p\n",
     68            istate->r21, istate->r22, istate->r23);
     69        printf("r24=%p\tr25=%p\tr26=%p\n",
     70            istate->r24, istate->r25, istate->r26);
     71        printf("r27=%p\tr28=%p\tr29=%p\n",
     72            istate->r27, istate->r28, istate->r29);
     73        printf("r30=%p\tr31=%p\n", istate->r30, istate->r31);
     74        printf("cr =%p\tpc =%p\tlr =%p\n", istate->cr, istate->pc, istate->lr);
     75        printf("ctr=%p\txer=%p\tdar=%p\n",
     76            istate->ctr, istate->xer, istate->dar);
     77        printf("srr1=%p\n", istate->srr1);
    5278}
    5379
  • kernel/arch/ppc32/src/mm/tlb.c

    r05e3cb8 re3038b4  
    111111static void pht_refill_fail(uintptr_t badvaddr, istate_t *istate)
    112112{
    113         const char *symbol = symtab_fmt_name_lookup(istate->pc);
    114         const char *sym2 = symtab_fmt_name_lookup(istate->lr);
    115        
    116         fault_if_from_uspace(istate,
    117             "PHT Refill Exception on %p.", badvaddr);
    118         panic("%p: PHT Refill Exception at %p (%s<-%s).", badvaddr,
    119             istate->pc, symbol, sym2);
     113        fault_if_from_uspace(istate, "PHT Refill Exception on %p.", badvaddr);
     114        panic_memtrap(istate, PF_ACCESS_READ, badvaddr,
     115            "PHT Refill Exception.");
    120116}
    121117
  • kernel/arch/sparc64/Makefile.inc

    r05e3cb8 re3038b4  
    6464        arch/$(KARCH)/src/asm.S \
    6565        arch/$(KARCH)/src/$(USARCH)/asm.S \
    66         arch/$(KARCH)/src/panic.S \
    6766        arch/$(KARCH)/src/console.c \
    6867        arch/$(KARCH)/src/context.S \
  • kernel/arch/sparc64/include/types.h

    r05e3cb8 re3038b4  
    5252typedef uint8_t asi_t;
    5353
    54 /**< Formats for uintptr_t, size_t */
     54/** Formats for uintptr_t, size_t */
    5555#define PRIp  "llx"
    5656#define PRIs  "llu"
    5757
    58 /**< Formats for (u)int8_t, (u)int16_t, (u)int32_t, (u)int64_t and (u)native_t */
     58/** Formats for (u)int8_t, (u)int16_t, (u)int32_t, (u)int64_t and (u)native_t */
    5959#define PRId8   "d"
    6060#define PRId16  "d"
  • kernel/arch/sparc64/src/mm/sun4u/tlb.c

    r05e3cb8 re3038b4  
    2727 */
    2828
    29 /** @addtogroup sparc64mm       
     29/** @addtogroup sparc64mm
    3030 * @{
    3131 */
     
    5858static void dtlb_pte_copy(pte_t *, size_t, bool);
    5959static void itlb_pte_copy(pte_t *, size_t);
    60 static void do_fast_instruction_access_mmu_miss_fault(istate_t *, const char *);
     60static void do_fast_instruction_access_mmu_miss_fault(istate_t *, uintptr_t,
     61    const char *);
    6162static void do_fast_data_access_mmu_miss_fault(istate_t *, tlb_tag_access_reg_t,
    6263    const char *);
     
    222223                 * Forward the page fault to the address space page fault
    223224                 * handler.
    224                  */             
     225                 */
    225226                page_table_unlock(AS, true);
    226227                if (as_page_fault(page_16k, PF_ACCESS_EXEC, istate) ==
    227228                    AS_PF_FAULT) {
    228229                        do_fast_instruction_access_mmu_miss_fault(istate,
    229                             __func__);
     230                            istate->tpc, __func__);
    230231                }
    231232        }
     
    258259                        /* NULL access in kernel */
    259260                        do_fast_data_access_mmu_miss_fault(istate, tag,
    260                             __func__);
     261                            "Dereferencing NULL pointer");
    261262                } else if (page_8k >= end_of_identity) {
    262263                        /*
     
    438439
    439440void do_fast_instruction_access_mmu_miss_fault(istate_t *istate,
    440     const char *str)
    441 {
    442         fault_if_from_uspace(istate, "%s.", str);
    443         dump_istate(istate);
    444         panic("%s.", str);
     441    uintptr_t va, const char *str)
     442{
     443        fault_if_from_uspace(istate, "%s, Address=%p.", str, va);
     444        panic_memtrap(istate, PF_ACCESS_EXEC, va, "%s.", str);
    445445}
    446446
     
    451451
    452452        va = tag.vpn << MMU_PAGE_WIDTH;
    453         if (tag.context) {
    454                 fault_if_from_uspace(istate, "%s, Page=%p (ASID=%d).", str, va,
    455                     tag.context);
    456         }
    457         dump_istate(istate);
    458         printf("Faulting page: %p, ASID=%d.\n", va, tag.context);
    459         panic("%s.", str);
     453        fault_if_from_uspace(istate, "%s, Page=%p (ASID=%d).", str, va,
     454            tag.context);
     455        panic_memtrap(istate, PF_ACCESS_READ, va, "%s.", str);
    460456}
    461457
     
    466462
    467463        va = tag.vpn << MMU_PAGE_WIDTH;
    468 
    469         if (tag.context) {
    470                 fault_if_from_uspace(istate, "%s, Page=%p (ASID=%d).", str, va,
    471                     tag.context);
    472         }
    473         printf("Faulting page: %p, ASID=%d\n", va, tag.context);
    474         dump_istate(istate);
    475         panic("%s.", str);
     464        fault_if_from_uspace(istate, "%s, Page=%p (ASID=%d).", str, va,
     465            tag.context);
     466        panic_memtrap(istate, PF_ACCESS_WRITE, va, "%s.", str);
    476467}
    477468
  • kernel/arch/sparc64/src/mm/sun4v/tlb.c

    r05e3cb8 re3038b4  
    2828 */
    2929
    30 /** @addtogroup sparc64mm       
     30/** @addtogroup sparc64mm
    3131 * @{
    3232 */
     
    6262static void itlb_pte_copy(pte_t *);
    6363static void dtlb_pte_copy(pte_t *, bool);
    64 static void do_fast_instruction_access_mmu_miss_fault(istate_t *, const char *);
     64static void do_fast_instruction_access_mmu_miss_fault(istate_t *, uintptr_t,
     65    const char *);
    6566static void do_fast_data_access_mmu_miss_fault(istate_t *, uint64_t,
    6667    const char *);
     
    235236                 * Forward the page fault to the address space page fault
    236237                 * handler.
    237                  */             
     238                 */
    238239                page_table_unlock(AS, true);
    239240                if (as_page_fault(va, PF_ACCESS_EXEC, istate) == AS_PF_FAULT) {
    240241                        do_fast_instruction_access_mmu_miss_fault(istate,
    241                             __func__);
     242                            istate->tpc, __func__);
    242243                }
    243244        }
     
    354355}
    355356
    356 void do_fast_instruction_access_mmu_miss_fault(istate_t *istate,
     357void do_fast_instruction_access_mmu_miss_fault(istate_t *istate, uintptr_t va,
    357358    const char *str)
    358359{
    359         fault_if_from_uspace(istate, "%s.", str);
    360         dump_istate(istate);
    361         panic("%s.", str);
     360        fault_if_from_uspace(istate, "%s, Address=%p.", str, va);
     361        panic_memtrap(istate, PF_ACCESS_EXEC, va, "%s.", str);
    362362}
    363363
     
    365365    uint64_t page_and_ctx, const char *str)
    366366{
    367         if (DMISS_CONTEXT(page_and_ctx)) {
    368                 fault_if_from_uspace(istate, "%s, Page=%p (ASID=%d)\n", str, DMISS_ADDRESS(page_and_ctx),
    369                     DMISS_CONTEXT(page_and_ctx));
    370         }
    371         dump_istate(istate);
    372         printf("Faulting page: %p, ASID=%d\n", DMISS_ADDRESS(page_and_ctx), DMISS_CONTEXT(page_and_ctx));
    373         panic("%s\n", str);
     367        fault_if_from_uspace(istate, "%s, Page=%p (ASID=%d).", str,
     368            DMISS_ADDRESS(page_and_ctx), DMISS_CONTEXT(page_and_ctx));
     369        panic_memtrap(istate, PF_ACCESS_READ, DMISS_ADDRESS(page_and_ctx),
     370            "%s.");
    374371}
    375372
     
    377374    uint64_t page_and_ctx, const char *str)
    378375{
    379         if (DMISS_CONTEXT(page_and_ctx)) {
    380                 fault_if_from_uspace(istate, "%s, Page=%p (ASID=%d)\n", str, DMISS_ADDRESS(page_and_ctx),
    381                     DMISS_CONTEXT(page_and_ctx));
    382         }
    383         printf("Faulting page: %p, ASID=%d\n", DMISS_ADDRESS(page_and_ctx), DMISS_CONTEXT(page_and_ctx));
    384         dump_istate(istate);
    385         panic("%s\n", str);
     376        fault_if_from_uspace(istate, "%s, Page=%p (ASID=%d).", str,
     377            DMISS_ADDRESS(page_and_ctx), DMISS_CONTEXT(page_and_ctx));
     378        panic_memtrap(istate, PF_ACCESS_WRITE, DMISS_ADDRESS(page_and_ctx),
     379            "%s.");
    386380}
    387381
  • kernel/arch/sparc64/src/trap/exception.c

    r05e3cb8 re3038b4  
    4444#include <symtab.h>
    4545
    46 void dump_istate(istate_t *istate)
     46void istate_decode(istate_t *istate)
    4747{
    4848        const char *tpcs = symtab_fmt_name_lookup(istate->tpc);
     
    5858{
    5959        fault_if_from_uspace(istate, "%s.", __func__);
    60         dump_istate(istate);
    61         panic("%s.", __func__);
     60        panic_badtrap(istate, n, "%s.", __func__);
    6261}
    6362
     
    6665{
    6766        fault_if_from_uspace(istate, "%s.", __func__);
    68         dump_istate(istate);
    69         panic("%s.", __func__);
     67        panic_badtrap(istate, n, "%s.", __func__);
    7068}
    7169
     
    7472{
    7573        fault_if_from_uspace(istate, "%s.", __func__);
    76         dump_istate(istate);
    77         panic("%s.", __func__);
     74        panic_badtrap(istate, n, "%s.", __func__);
    7875}
    7976
     
    8279{
    8380        fault_if_from_uspace(istate, "%s.", __func__);
    84         dump_istate(istate);
    85         panic("%s.", __func__);
     81        panic_badtrap(istate, n, "%s.", __func__);
    8682}
    8783
     
    9086{
    9187        fault_if_from_uspace(istate, "%s.", __func__);
    92         dump_istate(istate);
    93         panic("%s.", __func__);
     88        panic_badtrap(istate, n, "%s.", __func__);
    9489}
    9590
     
    9893{
    9994        fault_if_from_uspace(istate, "%s.", __func__);
    100         dump_istate(istate);
    101         panic("%s.", __func__);
     95        panic_badtrap(istate, n, "%s.", __func__);
    10296}
    10397
     
    118112#else
    119113        fault_if_from_uspace(istate, "%s.", __func__);
    120         dump_istate(istate);
    121         panic("%s.", __func__);
     114        panic_badtrap(istate, n, "%s.", __func__);
    122115#endif
    123116}
     
    127120{
    128121        fault_if_from_uspace(istate, "%s.", __func__);
    129         dump_istate(istate);
    130         panic("%s.", __func__);
     122        panic_badtrap(istate, n, "%s.", __func__);
    131123}
    132124
     
    135127{
    136128        fault_if_from_uspace(istate, "%s.", __func__);
    137         dump_istate(istate);
    138         panic("%s.", __func__);
     129        panic_badtrap(istate, n, "%s.", __func__);
    139130}
    140131
     
    143134{
    144135        fault_if_from_uspace(istate, "%s.", __func__);
    145         dump_istate(istate);
    146         panic("%s.", __func__);
     136        panic_badtrap(istate, n, "%s.", __func__);
    147137}
    148138
     
    151141{
    152142        fault_if_from_uspace(istate, "%s.", __func__);
    153         dump_istate(istate);
    154         panic("%s.", __func__);
     143        panic_badtrap(istate, n, "%s.", __func__);
    155144}
    156145
     
    159148{
    160149        fault_if_from_uspace(istate, "%s.", __func__);
    161         dump_istate(istate);
    162         describe_dmmu_fault();
    163         panic("%s.", __func__);
     150        panic_badtrap(istate, n, "%s.", __func__);
    164151}
    165152
     
    168155{
    169156        fault_if_from_uspace(istate, "%s.", __func__);
    170         dump_istate(istate);
    171         panic("%s.", __func__);
     157        panic_badtrap(istate, n, "%s.", __func__);
    172158}
    173159
     
    176162{
    177163        fault_if_from_uspace(istate, "%s.", __func__);
    178         dump_istate(istate);
    179         panic("%s.", __func__);
     164        panic_badtrap(istate, n, "%s.", __func__);
    180165}
    181166
     
    184169{
    185170        fault_if_from_uspace(istate, "%s.", __func__);
    186         dump_istate(istate);
    187         panic("%s.", __func__);
     171        panic_badtrap(istate, n, "%s.", __func__);
    188172}
    189173
     
    192176{
    193177        fault_if_from_uspace(istate, "%s.", __func__);
    194         dump_istate(istate);
    195         panic("%s.", __func__);
     178        panic_badtrap(istate, n, "%s.", __func__);
    196179}
    197180
     
    200183{
    201184        fault_if_from_uspace(istate, "%s.", __func__);
    202         dump_istate(istate);
    203         panic("%s.", __func__);
     185        panic_badtrap(istate, n, "%s.", __func__);
    204186}
    205187
     
    208190{
    209191        fault_if_from_uspace(istate, "%s.", __func__);
    210         dump_istate(istate);
    211         panic("%s.", __func__);
     192        panic_badtrap(istate, n, "%s.", __func__);
    212193}
    213194
     
    216197{
    217198        fault_if_from_uspace(istate, "%s.", __func__);
    218         dump_istate(istate);
    219         panic("%s.", __func__);
     199        panic_badtrap(istate, n, "%s.", __func__);
    220200}
    221201
  • kernel/generic/include/debug.h

    r05e3cb8 re3038b4  
    5555        do { \
    5656                if (!(expr)) \
    57                         panic("Assertion failed (%s)", #expr); \
     57                        panic_assert("%s", #expr); \
    5858        } while (0)
    5959
     
    7272        do { \
    7373                if (!(expr)) \
    74                         panic("Assertion failed (%s, %s)", #expr, msg); \
     74                        panic_assert("%s, %s", #expr, msg); \
    7575        } while (0)
    7676
  • kernel/generic/include/interrupt.h

    r05e3cb8 re3038b4  
    6464extern void irq_initialize_arch(irq_t *);
    6565
     66extern void istate_decode(istate_t *);
     67
    6668#endif
    6769
  • kernel/generic/include/panic.h

    r05e3cb8 re3038b4  
    11/*
    2  * Copyright (c) 2001-2004 Jakub Jermar
     2 * Copyright (c) 2010 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    3737
    3838#include <typedefs.h>
    39 #include <stacktrace.h>
    40 #include <print.h>
    4139
    42 #ifdef CONFIG_DEBUG
     40#define panic(fmt, ...) \
     41        panic_common(PANIC_OTHER, NULL, 0, 0, fmt, ##__VA_ARGS__)
    4342
    44 #define panic(format, ...) \
    45         do { \
    46                 silent = false; \
    47                 printf("Kernel panic in %s() at %s:%u\n", \
    48                     __func__, __FILE__, __LINE__); \
    49                 stack_trace(); \
    50                 panic_printf("Panic message: " format "\n", \
    51                     ##__VA_ARGS__);\
    52         } while (0)
     43#define panic_assert(fmt, ...) \
     44        panic_common(PANIC_ASSERT, NULL, 0, 0, fmt, ##__VA_ARGS__)
    5345
    54 #else /* CONFIG_DEBUG */
     46#define panic_badtrap(istate, n, fmt, ...) \
     47        panic_common(PANIC_BADTRAP, istate, 0, n, fmt, ##__VA_ARGS__)
    5548
    56 #define panic(format, ...) \
    57         do { \
    58                 silent = false; \
    59                 panic_printf("Kernel panic: " format "\n", ##__VA_ARGS__); \
    60                 stack_trace(); \
    61         } while (0)
     49#define panic_memtrap(istate, access, addr, fmt, ...) \
     50        panic_common(PANIC_MEMTRAP, istate, access, addr, fmt, ##__VA_ARGS__)
    6251
    63 #endif /* CONFIG_DEBUG */
     52typedef enum {
     53        PANIC_OTHER,
     54        PANIC_ASSERT,
     55        PANIC_BADTRAP,
     56        PANIC_MEMTRAP
     57} panic_category_t;
     58
     59struct istate;
    6460
    6561extern bool silent;
    6662
    67 extern void panic_printf(const char *fmt, ...) __attribute__((noreturn));
     63extern void panic_common(panic_category_t, struct istate *, int,
     64    uintptr_t, const char *, ...) __attribute__ ((noreturn));
    6865
    6966#endif
  • kernel/generic/src/debug/stacktrace.c

    r05e3cb8 re3038b4  
    3737#include <typedefs.h>
    3838#include <symtab.h>
     39#include <print.h>
    3940
    4041#define STACK_FRAMES_MAX        20
Note: See TracChangeset for help on using the changeset viewer.