Changeset 874621f in mainline


Ignore:
Timestamp:
2006-06-06T07:40:51Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0dbc4e7
Parents:
6f9a9bc
Message:

Added kernel circular buffer klog.
Added automatic killing of tasks raising inappropriate exceptions.
TODO Fix vsnprintf return value(and behaviour according to specs) and remove workaround in klog.

Files:
2 added
29 edited

Legend:

Unmodified
Added
Removed
  • Makefile

    r6f9a9bc r874621f  
    123123        generic/src/console/console.c \
    124124        generic/src/console/kconsole.c \
     125        generic/src/console/klog.c \
    125126        generic/src/console/cmd.c \
    126127        generic/src/cpu/cpu.c \
  • arch/amd64/include/interrupt.h

    r6f9a9bc r874621f  
    8787};
    8888
     89/** Return true if exception happened while in userspace */
     90static inline int istate_from_uspace(istate_t *istate)
     91{
     92        return !(istate->rip & 0x8000000000000000);
     93}
     94
    8995static inline void istate_set_retaddr(istate_t *istate, __address retaddr)
    9096{
    9197        istate->rip = retaddr;
     98}
     99static inline __native istate_get_pc(istate_t *istate)
     100{
     101        return istate->rip;
    92102}
    93103
  • arch/amd64/src/interrupt.c

    r6f9a9bc r874621f  
    8080void null_interrupt(int n, istate_t *istate)
    8181{
     82        fault_if_from_uspace(istate, "unserviced interrupt: %d", n);
    8283        print_info_errcode(n, istate);
    8384        panic("unserviced interrupt\n");
     
    105106                        return;
    106107                }
     108                fault_if_from_uspace(istate, "general protection fault");
    107109        }
    108110
     
    113115void ss_fault(int n, istate_t *istate)
    114116{
     117        fault_if_from_uspace(istate, "stack fault");
    115118        print_info_errcode(n, istate);
    116119        panic("stack fault\n");
     
    122125        scheduler_fpu_lazy_request();
    123126#else
     127        fault_if_from_uspace(istate, "fpu fault");
    124128        panic("fpu fault");
    125129#endif
  • arch/amd64/src/mm/page.c

    r6f9a9bc r874621f  
    184184       
    185185        if (as_page_fault(page, access, istate) == AS_PF_FAULT) {
     186                fault_if_from_uspace(istate, "Page fault: %#x", page);
     187
    186188                print_info_errcode(n, istate);
    187189                printf("Page fault address: %llX\n", page);
  • arch/ia32/include/interrupt.h

    r6f9a9bc r874621f  
    8484};
    8585
     86/** Return true if exception happened while in userspace */
     87static inline int istate_from_uspace(istate_t *istate)
     88{
     89        return !(istate->eip & 0x80000000);
     90}
     91
    8692static inline void istate_set_retaddr(istate_t *istate, __address retaddr)
    8793{
    8894        istate->eip = retaddr;
     95}
     96
     97static inline __native istate_get_pc(istate_t *istate)
     98{
     99        return istate->eip;
    89100}
    90101
  • arch/ia32/src/interrupt.c

    r6f9a9bc r874621f  
    8080void null_interrupt(int n, istate_t *istate)
    8181{
     82        fault_if_from_uspace(istate, "unserviced interrupt: %d", n);
     83
    8284        PRINT_INFO_ERRCODE(istate);
    8385        panic("unserviced interrupt: %d\n", n);
     
    105107                        return;
    106108                }
     109                fault_if_from_uspace(istate, "general protection fault");
    107110        }
    108111
     
    113116void ss_fault(int n, istate_t *istate)
    114117{
     118        fault_if_from_uspace(istate, "stack fault");
     119
    115120        PRINT_INFO_ERRCODE(istate);
    116121        panic("stack fault\n");
     
    119124void simd_fp_exception(int n, istate_t *istate)
    120125{
    121 
    122         PRINT_INFO_ERRCODE(istate);
    123126        __u32 mxcsr;
    124127        asm
     
    127130                :"=m"(mxcsr)
    128131        );
     132        fault_if_from_uspace(istate, "SIMD FP exception(19), MXCSR: %#zX",
     133                             (__native)mxcsr);
     134
     135        PRINT_INFO_ERRCODE(istate);
    129136        printf("MXCSR: %#zX\n",(__native)(mxcsr));
    130137        panic("SIMD FP exception(19)\n");
     
    136143        scheduler_fpu_lazy_request();
    137144#else
     145        fault_if_from_uspace(istate, "fpu fault");
    138146        panic("fpu fault");
    139147#endif
  • arch/ia32/src/mm/page.c

    r6f9a9bc r874621f  
    104104
    105105        if (as_page_fault(page, access, istate) == AS_PF_FAULT) {
     106                fault_if_from_uspace(istate, "Page fault: %#x", page);
     107
    106108                PRINT_INFO_ERRCODE(istate);
    107109                printf("page fault address: %#x\n", page);
  • arch/ia64/include/interrupt.h

    r6f9a9bc r874621f  
    114114}
    115115
     116static inline __native istate_get_pc(istate_t *istate)
     117{
     118        return istate->cr_iip;
     119}
     120#include <panic.h>
     121static inline int istate_from_uspace(istate_t *istate)
     122{
     123        panic("TODO: istate_from_uspace not yet implemented");
     124        return 0;
     125}
     126
    116127extern void *ivt;
    117128
  • arch/ia64/src/interrupt.c

    r6f9a9bc r874621f  
    4747#include <ipc/irq.h>
    4848#include <ipc/ipc.h>
     49#include <interrupt.h>
    4950
    5051
     
    151152        char *desc = "";
    152153
    153         dump_interrupted_context(istate);
    154 
    155154        switch (istate->cr_isr.ge_code) {
    156155            case GE_ILLEGALOP:
     
    177176        }
    178177
     178        fault_if_from_uspace(istate, "General Exception (%s)", desc);
     179
     180        dump_interrupted_context(istate);
    179181        panic("General Exception (%s)\n", desc);
    180182}
     
    187189        scheduler_fpu_lazy_request();   
    188190#else
     191        fault_if_from_uspace(istate, "Interruption: %#hx (%s)", (__u16) vector, vector_to_string(vector));
    189192        dump_interrupted_context(istate);
    190193        panic("Interruption: %#hx (%s)\n", (__u16) vector, vector_to_string(vector));
     
    268271        /* TODO */
    269272}
    270 
    271 
    272 
  • arch/mips32/include/arg.h

    r6f9a9bc r874621f  
    4545        (((type *)((ap) = (va_list)( (sizeof(type) <= 4) ? ((__address)((ap) + 2*4 - 1) & (~3)) : ((__address)((ap) + 2*8 -1) & (~7)) )))[-1])
    4646
     47#define va_copy(dst,src) ((dst)=(src))
     48
    4749#define va_end(ap)
    4850
  • arch/mips32/include/exception.h

    r6f9a9bc r874621f  
    3535
    3636#include <typedefs.h>
     37#include <arch/cp0.h>
    3738
    3839#define EXC_Int         0
     
    99100}
    100101
     102/** Return true if exception happened while in userspace */
     103static inline int istate_from_uspace(istate_t *istate)
     104{
     105        return istate->status & cp0_status_um_bit;
     106}
     107static inline __native istate_get_pc(istate_t *istate)
     108{
     109        return istate->epc;
     110}
     111
    101112extern void exception(istate_t *istate);
    102113extern void tlb_refill_entry(void);
  • arch/mips32/src/exception.c

    r6f9a9bc r874621f  
    7979static void unhandled_exception(int n, istate_t *istate)
    8080{
     81        fault_if_from_uspace(istate, "unhandled exception %s", exctable[n]);
     82       
    8183        print_regdump(istate);
    8284        panic("unhandled exception %s\n", exctable[n]);
     
    120122        if (cp0_cause_coperr(cp0_cause_read()) == fpu_cop_id)
    121123                scheduler_fpu_lazy_request();
    122         else
     124        else {
     125                fault_if_from_uspace(istate, "unhandled Coprocessor Unusable Exception");
    123126                panic("unhandled Coprocessor Unusable Exception\n");
     127        }
    124128}
    125129#endif
  • arch/mips32/src/mm/tlb.c

    r6f9a9bc r874621f  
    4040#include <debug.h>
    4141#include <align.h>
     42#include <interrupt.h>
    4243
    4344static void tlb_refill_fail(istate_t *istate);
     
    337338        if (s)
    338339                sym2 = s;
     340
     341        fault_if_from_uspace(istate, "TLB Refill Exception on %P", cp0_badvaddr_read());
    339342        panic("%X: TLB Refill Exception at %X(%s<-%s)\n", cp0_badvaddr_read(), istate->epc, symbol, sym2);
    340343}
     
    348351        if (s)
    349352                symbol = s;
     353        fault_if_from_uspace(istate, "TLB Invalid Exception on %P", cp0_badvaddr_read());
    350354        panic("%X: TLB Invalid Exception at %X(%s)\n", cp0_badvaddr_read(), istate->epc, symbol);
    351355}
     
    358362        if (s)
    359363                symbol = s;
     364        fault_if_from_uspace(istate, "TLB Modified Exception on %P", cp0_badvaddr_read());
    360365        panic("%X: TLB Modified Exception at %X(%s)\n", cp0_badvaddr_read(), istate->epc, symbol);
    361366}
  • arch/ppc32/include/exception.h

    r6f9a9bc r874621f  
    8181        istate->pc = retaddr;
    8282}
     83/** Return true if exception happened while in userspace */
     84#include <panic.h>
     85static inline int istate_from_uspace(istate_t *istate)
     86{
     87        panic("istate_from_uspace not yet implemented");
     88        return 0;
     89}
     90static inline __native istate_get_pc(istate_t *istate)
     91{
     92        return istate->pc;
     93}
    8394
    8495#endif
  • arch/ppc32/src/interrupt.c

    r6f9a9bc r874621f  
    6767}
    6868
    69 #include <print.h>
    7069/** Handler of externul interrupts */
    7170void extint_handler(int n, istate_t *istate)
  • arch/ppc64/include/exception.h

    r6f9a9bc r874621f  
    8181        istate->pc = retaddr;
    8282}
     83/** Return true if exception happened while in userspace */
     84#include <panic.h>
     85static inline int istate_from_uspace(istate_t *istate)
     86{
     87        panic("istate_from_uspace not yet implemented");
     88        return 0;
     89}
     90static inline __native istate_get_pc(istate_t *istate)
     91{
     92        return istate->pc;
     93}
    8394
    8495#endif
  • arch/sparc64/include/interrupt.h

    r6f9a9bc r874621f  
    5252        /* TODO */
    5353}
     54static inline int istate_from_uspace(istate_t *istate)
     55{
     56        /* TODO */
     57}
     58static inline __native istate_get_pc(istate_t *istate)
     59{
     60        /* TODO */
     61}
     62
    5463
    5564extern void interrupt_register(int n, const char *name, iroutine f);
  • generic/include/interrupt.h

    r6f9a9bc r874621f  
    3333#include <typedefs.h>
    3434#include <arch/types.h>
     35#include <proc/task.h>
     36#include <proc/thread.h>
     37#include <arch.h>
     38#include <console/klog.h>
     39#include <ipc/irq.h>
    3540
    3641#ifndef IVT_ITEMS
     
    4247#endif
    4348
     49#define fault_if_from_uspace(istate, cmd, ...) \
     50{ \
     51        if (istate_from_uspace(istate)) { \
     52                klog_printf(cmd, ##__VA_ARGS__); \
     53                klog_printf("Task %lld got exception at PC:%P. Task killed.", TASK->taskid, istate_get_pc(istate)); \
     54                task_kill(TASK->taskid); \
     55                thread_exit(); \
     56        } \
     57}
     58
     59
    4460extern iroutine exc_register(int n, const char *name, iroutine f);
    4561extern void exc_dispatch(int n, istate_t *t);
  • generic/include/ipc/irq.h

    r6f9a9bc r874621f  
    3030#define __IRQ_H__
    3131
     32/** Maximum length of IPC IRQ program */
    3233#define IRQ_MAX_PROG_SIZE 10
     34
     35/** Reserved 'virtual' messages for kernel notifications */
     36#define IPC_IRQ_RESERVED_VIRTUAL 10
     37
     38#define IPC_IRQ_KLOG  (-1)
    3339
    3440typedef enum {
     
    6066#ifdef KERNEL
    6167
     68#include <ipc/ipc.h>
     69
    6270extern void ipc_irq_make_table(int irqcount);
    6371extern int ipc_irq_register(answerbox_t *box, int irq, irq_code_t *ucode);
    6472extern void ipc_irq_send_notif(int irq);
     73extern void ipc_irq_send_msg(int irq, __native a2, __native a3);
    6574extern void ipc_irq_unregister(answerbox_t *box, int irq);
    6675extern void irq_ipc_bind_arch(__native irq);
  • generic/include/ipc/sysipc.h

    r6f9a9bc r874621f  
    4848                              __native method, __native arg1);
    4949__native sys_ipc_hangup(int phoneid);
    50 __native sys_ipc_register_irq(__native irq, irq_code_t *ucode);
    51 __native sys_ipc_unregister_irq(__native irq);
     50__native sys_ipc_register_irq(int irq, irq_code_t *ucode);
     51__native sys_ipc_unregister_irq(int irq);
    5252
    5353#endif
  • generic/include/proc/thread.h

    r6f9a9bc r874621f  
    151151extern thread_t *thread_create(void (* func)(void *), void *arg, task_t *task, int flags, char *name);
    152152extern void thread_ready(thread_t *t);
    153 extern void thread_exit(void);
     153extern void thread_exit(void) __attribute__((noreturn));
    154154
    155155#ifndef thread_create_arch
  • generic/include/stackarg.h

    r6f9a9bc r874621f  
    5050        (*((type *)((ap).last + ((ap).pos  += sizeof(type) ) - sizeof(type))))
    5151
     52#define va_copy(dst,src)       dst=src
    5253#define va_end(ap)
    5354
  • generic/include/stdarg.h

    r6f9a9bc r874621f  
    4141#define va_arg(ap, type)                __builtin_va_arg(ap, type)
    4242#define va_end(ap)                      __builtin_va_end(ap)
     43#define va_copy(dst,src)                __builtin_va_copy(dst,src)
    4344
    4445#endif
  • generic/src/interrupt/interrupt.c

    r6f9a9bc r874621f  
    9191static void exc_undef(int n, istate_t *istate)
    9292{
     93        fault_if_from_uspace(istate, "Unhandled exception %d.", n);
    9394        panic("Unhandled exception %d.", n);
    9495}
  • generic/src/ipc/ipc.c

    r6f9a9bc r874621f  
    336336                list_append(&request->link, &box->dispatched_calls);
    337337        } else {
    338                 /* This can happen regularly after ipc_cleanup, remove
    339                  * the warning in the future when the IPC is
    340                  * more debugged */
    341                 printf("WARNING: Spurious IPC wakeup.\n");
     338                /* This can happen regularly after ipc_cleanup */
    342339                spinlock_unlock(&box->lock);
    343340                goto restart;
  • generic/src/ipc/irq.c

    r6f9a9bc r874621f  
    157157{
    158158        ipl_t ipl;
     159        int mq = irq + IPC_IRQ_RESERVED_VIRTUAL;
    159160
    160161        ipl = interrupts_disable();
    161         spinlock_lock(&irq_conns[irq].lock);
    162         if (irq_conns[irq].box == box) {
    163                 irq_conns[irq].box = NULL;
    164                 code_free(irq_conns[irq].code);
    165                 irq_conns[irq].code = NULL;
    166         }
    167 
    168         spinlock_unlock(&irq_conns[irq].lock);
     162        spinlock_lock(&irq_conns[mq].lock);
     163        if (irq_conns[mq].box == box) {
     164                irq_conns[mq].box = NULL;
     165                code_free(irq_conns[mq].code);
     166                irq_conns[mq].code = NULL;
     167        }
     168
     169        spinlock_unlock(&irq_conns[mq].lock);
    169170        interrupts_restore(ipl);
    170171}
     
    175176        ipl_t ipl;
    176177        irq_code_t *code;
     178        int mq = irq + IPC_IRQ_RESERVED_VIRTUAL;
    177179
    178180        ASSERT(irq_conns);
     
    186188
    187189        ipl = interrupts_disable();
    188         spinlock_lock(&irq_conns[irq].lock);
    189 
    190         if (irq_conns[irq].box) {
    191                 spinlock_unlock(&irq_conns[irq].lock);
     190        spinlock_lock(&irq_conns[mq].lock);
     191
     192        if (irq_conns[mq].box) {
     193                spinlock_unlock(&irq_conns[mq].lock);
    192194                interrupts_restore(ipl);
    193195                code_free(code);
    194196                return EEXISTS;
    195197        }
    196         irq_conns[irq].box = box;
    197         irq_conns[irq].code = code;
    198         atomic_set(&irq_conns[irq].counter, 0);
    199         spinlock_unlock(&irq_conns[irq].lock);
     198        irq_conns[mq].box = box;
     199        irq_conns[mq].code = code;
     200        atomic_set(&irq_conns[mq].counter, 0);
     201        spinlock_unlock(&irq_conns[mq].lock);
    200202        interrupts_restore(ipl);
    201203
     
    203205}
    204206
    205 /** Notify process that an irq had happend
    206  *
    207  * We expect interrupts to be disabled
    208  */
    209 void ipc_irq_send_notif(int irq)
     207/** Add call to proper answerbox queue
     208 *
     209 * Assume irq_conns[mq].lock is locked */
     210static void send_call(int mq, call_t *call)
     211{
     212        spinlock_lock(&irq_conns[mq].box->irq_lock);
     213        list_append(&call->link, &irq_conns[mq].box->irq_notifs);
     214        spinlock_unlock(&irq_conns[mq].box->irq_lock);
     215               
     216        waitq_wakeup(&irq_conns[mq].box->wq, 0);
     217}
     218
     219/** Send notification message
     220 *
     221 */
     222void ipc_irq_send_msg(int irq, __native a2, __native a3)
    210223{
    211224        call_t *call;
    212 
    213         ASSERT(irq_conns);
    214         spinlock_lock(&irq_conns[irq].lock);
    215 
    216         if (irq_conns[irq].box) {
     225        int mq = irq + IPC_IRQ_RESERVED_VIRTUAL;
     226
     227        spinlock_lock(&irq_conns[mq].lock);
     228
     229        if (irq_conns[mq].box) {
    217230                call = ipc_call_alloc(FRAME_ATOMIC);
    218231                if (!call) {
    219                         spinlock_unlock(&irq_conns[irq].lock);
     232                        spinlock_unlock(&irq_conns[mq].lock);
    220233                        return;
    221234                }
     
    223236                IPC_SET_METHOD(call->data, IPC_M_INTERRUPT);
    224237                IPC_SET_ARG1(call->data, irq);
    225                 IPC_SET_ARG3(call->data, atomic_preinc(&irq_conns[irq].counter));
     238                IPC_SET_ARG2(call->data, a2);
     239                IPC_SET_ARG3(call->data, a3);
     240               
     241                send_call(mq, call);
     242        }
     243        spinlock_unlock(&irq_conns[mq].lock);
     244}
     245
     246/** Notify process that an irq had happend
     247 *
     248 * We expect interrupts to be disabled
     249 */
     250void ipc_irq_send_notif(int irq)
     251{
     252        call_t *call;
     253        int mq = irq + IPC_IRQ_RESERVED_VIRTUAL;
     254
     255        ASSERT(irq_conns);
     256        spinlock_lock(&irq_conns[mq].lock);
     257
     258        if (irq_conns[mq].box) {
     259                call = ipc_call_alloc(FRAME_ATOMIC);
     260                if (!call) {
     261                        spinlock_unlock(&irq_conns[mq].lock);
     262                        return;
     263                }
     264                call->flags |= IPC_CALL_NOTIF;
     265                IPC_SET_METHOD(call->data, IPC_M_INTERRUPT);
     266                IPC_SET_ARG1(call->data, irq);
     267                IPC_SET_ARG3(call->data, atomic_preinc(&irq_conns[mq].counter));
    226268
    227269                /* Execute code to handle irq */
    228                 code_execute(call, irq_conns[irq].code);
    229 
    230                 spinlock_lock(&irq_conns[irq].box->irq_lock);
    231                 list_append(&call->link, &irq_conns[irq].box->irq_notifs);
    232                 spinlock_unlock(&irq_conns[irq].box->irq_lock);
    233 
    234                 waitq_wakeup(&irq_conns[irq].box->wq, 0);
    235         }
     270                code_execute(call, irq_conns[mq].code);
    236271               
    237         spinlock_unlock(&irq_conns[irq].lock);
    238 }
    239 
    240 
    241 /** Initialize table of interrupt handlers */
     272                send_call(mq, call);
     273        }
     274               
     275        spinlock_unlock(&irq_conns[mq].lock);
     276}
     277
     278
     279/** Initialize table of interrupt handlers
     280 *
     281 * @param irqcount Count of required hardware IRQs to be supported
     282 */
    242283void ipc_irq_make_table(int irqcount)
    243284{
    244285        int i;
     286
     287        irqcount +=  IPC_IRQ_RESERVED_VIRTUAL;
    245288
    246289        irq_conns_size = irqcount;
  • generic/src/ipc/sysipc.c

    r6f9a9bc r874621f  
    554554
    555555/** Connect irq handler to task */
    556 __native sys_ipc_register_irq(__native irq, irq_code_t *ucode)
     556__native sys_ipc_register_irq(int irq, irq_code_t *ucode)
    557557{
    558558        if (!(cap_get(TASK) & CAP_IRQ_REG))
    559559                return EPERM;
    560560
    561         if (irq >= IRQ_COUNT)
     561        if (irq >= IRQ_COUNT || irq <= -IPC_IRQ_RESERVED_VIRTUAL)
    562562                return (__native) ELIMIT;
    563 
     563       
    564564        irq_ipc_bind_arch(irq);
    565565
     
    568568
    569569/* Disconnect irq handler from task */
    570 __native sys_ipc_unregister_irq(__native irq)
     570__native sys_ipc_unregister_irq(int irq)
    571571{
    572572        if (!(cap_get(TASK) & CAP_IRQ_REG))
    573573                return EPERM;
    574574
    575         if (irq >= IRQ_COUNT)
     575        if (irq >= IRQ_COUNT || irq <= -IPC_IRQ_RESERVED_VIRTUAL)
    576576                return (__native) ELIMIT;
    577577
  • generic/src/main/main.c

    r6f9a9bc r874621f  
    7575#include <macros.h>
    7676#include <adt/btree.h>
     77#include <console/klog.h>
    7778
    7879#ifdef CONFIG_SMP
     
    219220        thread_init();
    220221        futex_init();
     222        klog_init();
    221223       
    222224        for (i = 0; i < init.cnt; i++)
  • generic/src/proc/thread.c

    r6f9a9bc r874621f  
    389389        spinlock_unlock(&THREAD->lock);
    390390        scheduler();
     391
     392        /* Not reached */
     393        while (1)
     394                ;
    391395}
    392396
Note: See TracChangeset for help on using the changeset viewer.