Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 1595 → Rev 1594

/kernel/trunk/generic/src/ipc/sysipc.c
553,14 → 553,14
}
 
/** Connect irq handler to task */
__native sys_ipc_register_irq(int irq, irq_code_t *ucode)
__native sys_ipc_register_irq(__native irq, irq_code_t *ucode)
{
if (!(cap_get(TASK) & CAP_IRQ_REG))
return EPERM;
 
if (irq >= IRQ_COUNT || irq <= -IPC_IRQ_RESERVED_VIRTUAL)
if (irq >= IRQ_COUNT)
return (__native) ELIMIT;
 
irq_ipc_bind_arch(irq);
 
return ipc_irq_register(&TASK->answerbox, irq, ucode);
567,12 → 567,12
}
 
/* Disconnect irq handler from task */
__native sys_ipc_unregister_irq(int irq)
__native sys_ipc_unregister_irq(__native irq)
{
if (!(cap_get(TASK) & CAP_IRQ_REG))
return EPERM;
 
if (irq >= IRQ_COUNT || irq <= -IPC_IRQ_RESERVED_VIRTUAL)
if (irq >= IRQ_COUNT)
return (__native) ELIMIT;
 
ipc_irq_unregister(&TASK->answerbox, irq);
/kernel/trunk/generic/src/ipc/ipc.c
335,7 → 335,10
/* Append request to dispatch queue */
list_append(&request->link, &box->dispatched_calls);
} else {
/* This can happen regularly after ipc_cleanup */
/* This can happen regularly after ipc_cleanup, remove
* the warning in the future when the IPC is
* more debugged */
printf("WARNING: Spurious IPC wakeup.\n");
spinlock_unlock(&box->lock);
goto restart;
}
/kernel/trunk/generic/src/ipc/irq.c
156,17 → 156,16
void ipc_irq_unregister(answerbox_t *box, int irq)
{
ipl_t ipl;
int mq = irq + IPC_IRQ_RESERVED_VIRTUAL;
 
ipl = interrupts_disable();
spinlock_lock(&irq_conns[mq].lock);
if (irq_conns[mq].box == box) {
irq_conns[mq].box = NULL;
code_free(irq_conns[mq].code);
irq_conns[mq].code = NULL;
spinlock_lock(&irq_conns[irq].lock);
if (irq_conns[irq].box == box) {
irq_conns[irq].box = NULL;
code_free(irq_conns[irq].code);
irq_conns[irq].code = NULL;
}
 
spinlock_unlock(&irq_conns[mq].lock);
spinlock_unlock(&irq_conns[irq].lock);
interrupts_restore(ipl);
}
 
175,7 → 174,6
{
ipl_t ipl;
irq_code_t *code;
int mq = irq + IPC_IRQ_RESERVED_VIRTUAL;
 
ASSERT(irq_conns);
 
187,62 → 185,23
code = NULL;
 
ipl = interrupts_disable();
spinlock_lock(&irq_conns[mq].lock);
spinlock_lock(&irq_conns[irq].lock);
 
if (irq_conns[mq].box) {
spinlock_unlock(&irq_conns[mq].lock);
if (irq_conns[irq].box) {
spinlock_unlock(&irq_conns[irq].lock);
interrupts_restore(ipl);
code_free(code);
return EEXISTS;
}
irq_conns[mq].box = box;
irq_conns[mq].code = code;
atomic_set(&irq_conns[mq].counter, 0);
spinlock_unlock(&irq_conns[mq].lock);
irq_conns[irq].box = box;
irq_conns[irq].code = code;
atomic_set(&irq_conns[irq].counter, 0);
spinlock_unlock(&irq_conns[irq].lock);
interrupts_restore(ipl);
 
return 0;
}
 
/** Add call to proper answerbox queue
*
* Assume irq_conns[mq].lock is locked */
static void send_call(int mq, call_t *call)
{
spinlock_lock(&irq_conns[mq].box->irq_lock);
list_append(&call->link, &irq_conns[mq].box->irq_notifs);
spinlock_unlock(&irq_conns[mq].box->irq_lock);
waitq_wakeup(&irq_conns[mq].box->wq, 0);
}
 
/** Send notification message
*
*/
void ipc_irq_send_msg(int irq, __native a2, __native a3)
{
call_t *call;
int mq = irq + IPC_IRQ_RESERVED_VIRTUAL;
 
spinlock_lock(&irq_conns[mq].lock);
 
if (irq_conns[mq].box) {
call = ipc_call_alloc(FRAME_ATOMIC);
if (!call) {
spinlock_unlock(&irq_conns[mq].lock);
return;
}
call->flags |= IPC_CALL_NOTIF;
IPC_SET_METHOD(call->data, IPC_M_INTERRUPT);
IPC_SET_ARG1(call->data, irq);
IPC_SET_ARG2(call->data, a2);
IPC_SET_ARG3(call->data, a3);
send_call(mq, call);
}
spinlock_unlock(&irq_conns[mq].lock);
}
 
/** Notify process that an irq had happend
*
* We expect interrupts to be disabled
250,42 → 209,40
void ipc_irq_send_notif(int irq)
{
call_t *call;
int mq = irq + IPC_IRQ_RESERVED_VIRTUAL;
 
ASSERT(irq_conns);
spinlock_lock(&irq_conns[mq].lock);
spinlock_lock(&irq_conns[irq].lock);
 
if (irq_conns[mq].box) {
if (irq_conns[irq].box) {
call = ipc_call_alloc(FRAME_ATOMIC);
if (!call) {
spinlock_unlock(&irq_conns[mq].lock);
spinlock_unlock(&irq_conns[irq].lock);
return;
}
call->flags |= IPC_CALL_NOTIF;
IPC_SET_METHOD(call->data, IPC_M_INTERRUPT);
IPC_SET_ARG1(call->data, irq);
IPC_SET_ARG3(call->data, atomic_preinc(&irq_conns[mq].counter));
IPC_SET_ARG3(call->data, atomic_preinc(&irq_conns[irq].counter));
 
/* Execute code to handle irq */
code_execute(call, irq_conns[mq].code);
send_call(mq, call);
code_execute(call, irq_conns[irq].code);
 
spinlock_lock(&irq_conns[irq].box->irq_lock);
list_append(&call->link, &irq_conns[irq].box->irq_notifs);
spinlock_unlock(&irq_conns[irq].box->irq_lock);
 
waitq_wakeup(&irq_conns[irq].box->wq, 0);
}
spinlock_unlock(&irq_conns[mq].lock);
spinlock_unlock(&irq_conns[irq].lock);
}
 
 
/** Initialize table of interrupt handlers
*
* @param irqcount Count of required hardware IRQs to be supported
*/
/** Initialize table of interrupt handlers */
void ipc_irq_make_table(int irqcount)
{
int i;
 
irqcount += IPC_IRQ_RESERVED_VIRTUAL;
 
irq_conns_size = irqcount;
irq_conns = malloc(irqcount * (sizeof(*irq_conns)), 0);
for (i=0; i < irqcount; i++) {
/kernel/trunk/generic/src/proc/thread.c
388,10 → 388,6
THREAD->state = Exiting;
spinlock_unlock(&THREAD->lock);
scheduler();
 
/* Not reached */
while (1)
;
}
 
 
/kernel/trunk/generic/src/console/klog.c
File deleted
/kernel/trunk/generic/src/main/main.c
74,7 → 74,6
#include <ipc/ipc.h>
#include <macros.h>
#include <adt/btree.h>
#include <console/klog.h>
 
#ifdef CONFIG_SMP
#include <arch/smp/apic.h>
219,7 → 218,6
task_init();
thread_init();
futex_init();
klog_init();
for (i = 0; i < init.cnt; i++)
printf("init[%zd].addr=%.*p, init[%zd].size=%zd\n", i, sizeof(__address) * 2, init.tasks[i].addr, i, init.tasks[i].size);
/kernel/trunk/generic/src/interrupt/interrupt.c
90,7 → 90,6
/** Default 'null' exception handler */
static void exc_undef(int n, istate_t *istate)
{
fault_if_from_uspace(istate, "Unhandled exception %d.", n);
panic("Unhandled exception %d.", n);
}
 
/kernel/trunk/generic/include/ipc/irq.h
29,14 → 29,8
#ifndef __IRQ_H__
#define __IRQ_H__
 
/** Maximum length of IPC IRQ program */
#define IRQ_MAX_PROG_SIZE 10
 
/** Reserved 'virtual' messages for kernel notifications */
#define IPC_IRQ_RESERVED_VIRTUAL 10
 
#define IPC_IRQ_KLOG (-1)
 
typedef enum {
CMD_MEM_READ_1 = 0,
CMD_MEM_READ_2,
65,12 → 59,9
 
#ifdef KERNEL
 
#include <ipc/ipc.h>
 
extern void ipc_irq_make_table(int irqcount);
extern int ipc_irq_register(answerbox_t *box, int irq, irq_code_t *ucode);
extern void ipc_irq_send_notif(int irq);
extern void ipc_irq_send_msg(int irq, __native a2, __native a3);
extern void ipc_irq_unregister(answerbox_t *box, int irq);
extern void irq_ipc_bind_arch(__native irq);
extern void ipc_irq_cleanup(answerbox_t *box);
/kernel/trunk/generic/include/ipc/sysipc.h
47,7 → 47,7
__native sys_ipc_forward_fast(__native callid, __native phoneid,
__native method, __native arg1);
__native sys_ipc_hangup(int phoneid);
__native sys_ipc_register_irq(int irq, irq_code_t *ucode);
__native sys_ipc_unregister_irq(int irq);
__native sys_ipc_register_irq(__native irq, irq_code_t *ucode);
__native sys_ipc_unregister_irq(__native irq);
 
#endif
/kernel/trunk/generic/include/proc/thread.h
150,7 → 150,7
extern void thread_init(void);
extern thread_t *thread_create(void (* func)(void *), void *arg, task_t *task, int flags, char *name);
extern void thread_ready(thread_t *t);
extern void thread_exit(void) __attribute__((noreturn));
extern void thread_exit(void);
 
#ifndef thread_create_arch
extern void thread_create_arch(thread_t *t);
/kernel/trunk/generic/include/console/klog.h
File deleted
/kernel/trunk/generic/include/interrupt.h
32,11 → 32,6
#include <arch/interrupt.h>
#include <typedefs.h>
#include <arch/types.h>
#include <proc/task.h>
#include <proc/thread.h>
#include <arch.h>
#include <console/klog.h>
#include <ipc/irq.h>
 
#ifndef IVT_ITEMS
# define IVT_ITEMS 0
46,17 → 41,6
# define IVT_FIRST 0
#endif
 
#define fault_if_from_uspace(istate, cmd, ...) \
{ \
if (istate_from_uspace(istate)) { \
klog_printf(cmd, ##__VA_ARGS__); \
klog_printf("Task %lld got exception at PC:%P. Task killed.", TASK->taskid, istate_get_pc(istate)); \
task_kill(TASK->taskid); \
thread_exit(); \
} \
}
 
 
extern iroutine exc_register(int n, const char *name, iroutine f);
extern void exc_dispatch(int n, istate_t *t);
void exc_init(void);
/kernel/trunk/generic/include/stackarg.h
49,7 → 49,6
#define va_arg(ap, type) \
(*((type *)((ap).last + ((ap).pos += sizeof(type) ) - sizeof(type))))
 
#define va_copy(dst,src) dst=src
#define va_end(ap)
 
 
/kernel/trunk/generic/include/stdarg.h
40,6 → 40,5
#define va_start(ap, last) __builtin_va_start(ap, last)
#define va_arg(ap, type) __builtin_va_arg(ap, type)
#define va_end(ap) __builtin_va_end(ap)
#define va_copy(dst,src) __builtin_va_copy(dst,src)
 
#endif
/kernel/trunk/arch/sparc64/include/interrupt.h
51,16 → 51,7
{
/* TODO */
}
static inline int istate_from_uspace(istate_t *istate)
{
/* TODO */
}
static inline __native istate_get_pc(istate_t *istate)
{
/* TODO */
}
 
 
extern void interrupt_register(int n, const char *name, iroutine f);
 
#endif
/kernel/trunk/arch/ia64/include/interrupt.h
113,17 → 113,6
istate->cr_ipsr.ri = 0; /* return to instruction slot #0 */
}
 
static inline __native istate_get_pc(istate_t *istate)
{
return istate->cr_iip;
}
#include <panic.h>
static inline int istate_from_uspace(istate_t *istate)
{
panic("TODO: istate_from_uspace not yet implemented");
return 0;
}
 
extern void *ivt;
 
extern void general_exception(__u64 vector, istate_t *istate);
/kernel/trunk/arch/ia64/src/interrupt.c
46,7 → 46,6
#include <ipc/sysipc.h>
#include <ipc/irq.h>
#include <ipc/ipc.h>
#include <interrupt.h>
 
 
#define VECTORS_64_BUNDLE 20
151,6 → 150,8
{
char *desc = "";
 
dump_interrupted_context(istate);
 
switch (istate->cr_isr.ge_code) {
case GE_ILLEGALOP:
desc = "Illegal Operation fault";
175,9 → 176,6
break;
}
 
fault_if_from_uspace(istate, "General Exception (%s)", desc);
 
dump_interrupted_context(istate);
panic("General Exception (%s)\n", desc);
}
 
188,7 → 186,6
#ifdef CONFIG_FPU_LAZY
scheduler_fpu_lazy_request();
#else
fault_if_from_uspace(istate, "Interruption: %#hx (%s)", (__u16) vector, vector_to_string(vector));
dump_interrupted_context(istate);
panic("Interruption: %#hx (%s)\n", (__u16) vector, vector_to_string(vector));
#endif
270,3 → 267,6
panic("not implemented\n");
/* TODO */
}
 
 
 
/kernel/trunk/arch/ppc32/include/exception.h
80,16 → 80,5
{
istate->pc = retaddr;
}
/** Return true if exception happened while in userspace */
#include <panic.h>
static inline int istate_from_uspace(istate_t *istate)
{
panic("istate_from_uspace not yet implemented");
return 0;
}
static inline __native istate_get_pc(istate_t *istate)
{
return istate->pc;
}
 
#endif
/kernel/trunk/arch/ppc32/src/interrupt.c
66,6 → 66,7
/* TODO */
}
 
#include <print.h>
/** Handler of externul interrupts */
void extint_handler(int n, istate_t *istate)
{
/kernel/trunk/arch/amd64/src/interrupt.c
79,7 → 79,6
 
void null_interrupt(int n, istate_t *istate)
{
fault_if_from_uspace(istate, "unserviced interrupt: %d", n);
print_info_errcode(n, istate);
panic("unserviced interrupt\n");
}
105,7 → 104,6
io_perm_bitmap_install();
return;
}
fault_if_from_uspace(istate, "general protection fault");
}
 
print_info_errcode(n, istate);
114,7 → 112,6
 
void ss_fault(int n, istate_t *istate)
{
fault_if_from_uspace(istate, "stack fault");
print_info_errcode(n, istate);
panic("stack fault\n");
}
124,7 → 121,6
#ifdef CONFIG_FPU_LAZY
scheduler_fpu_lazy_request();
#else
fault_if_from_uspace(istate, "fpu fault");
panic("fpu fault");
#endif
}
/kernel/trunk/arch/amd64/src/mm/page.c
183,8 → 183,6
access = PF_ACCESS_READ;
if (as_page_fault(page, access, istate) == AS_PF_FAULT) {
fault_if_from_uspace(istate, "Page fault: %#x", page);
 
print_info_errcode(n, istate);
printf("Page fault address: %llX\n", page);
panic("page fault\n");
/kernel/trunk/arch/amd64/include/interrupt.h
86,20 → 86,10
__u64 stack[]; /* Additional data on stack */
};
 
/** Return true if exception happened while in userspace */
static inline int istate_from_uspace(istate_t *istate)
{
return !(istate->rip & 0x8000000000000000);
}
 
static inline void istate_set_retaddr(istate_t *istate, __address retaddr)
{
istate->rip = retaddr;
}
static inline __native istate_get_pc(istate_t *istate)
{
return istate->rip;
}
 
extern void (* disable_irqs_function)(__u16 irqmask);
extern void (* enable_irqs_function)(__u16 irqmask);
/kernel/trunk/arch/ppc64/include/exception.h
80,16 → 80,5
{
istate->pc = retaddr;
}
/** Return true if exception happened while in userspace */
#include <panic.h>
static inline int istate_from_uspace(istate_t *istate)
{
panic("istate_from_uspace not yet implemented");
return 0;
}
static inline __native istate_get_pc(istate_t *istate)
{
return istate->pc;
}
 
#endif
/kernel/trunk/arch/mips32/include/exception.h
34,7 → 34,6
#endif
 
#include <typedefs.h>
#include <arch/cp0.h>
 
#define EXC_Int 0
#define EXC_Mod 1
99,16 → 98,6
istate->epc = retaddr;
}
 
/** Return true if exception happened while in userspace */
static inline int istate_from_uspace(istate_t *istate)
{
return istate->status & cp0_status_um_bit;
}
static inline __native istate_get_pc(istate_t *istate)
{
return istate->epc;
}
 
extern void exception(istate_t *istate);
extern void tlb_refill_entry(void);
extern void exception_entry(void);
/kernel/trunk/arch/mips32/include/arg.h
44,8 → 44,6
#define va_arg(ap, type) \
(((type *)((ap) = (va_list)( (sizeof(type) <= 4) ? ((__address)((ap) + 2*4 - 1) & (~3)) : ((__address)((ap) + 2*8 -1) & (~7)) )))[-1])
 
#define va_copy(dst,src) ((dst)=(src))
 
#define va_end(ap)
 
#endif
/kernel/trunk/arch/mips32/src/mm/tlb.c
39,7 → 39,6
#include <print.h>
#include <debug.h>
#include <align.h>
#include <interrupt.h>
 
static void tlb_refill_fail(istate_t *istate);
static void tlb_invalid_fail(istate_t *istate);
337,8 → 336,6
s = get_symtab_entry(istate->ra);
if (s)
sym2 = s;
 
fault_if_from_uspace(istate, "TLB Refill Exception on %P", cp0_badvaddr_read());
panic("%X: TLB Refill Exception at %X(%s<-%s)\n", cp0_badvaddr_read(), istate->epc, symbol, sym2);
}
 
350,7 → 347,6
char *s = get_symtab_entry(istate->epc);
if (s)
symbol = s;
fault_if_from_uspace(istate, "TLB Invalid Exception on %P", cp0_badvaddr_read());
panic("%X: TLB Invalid Exception at %X(%s)\n", cp0_badvaddr_read(), istate->epc, symbol);
}
 
361,7 → 357,6
char *s = get_symtab_entry(istate->epc);
if (s)
symbol = s;
fault_if_from_uspace(istate, "TLB Modified Exception on %P", cp0_badvaddr_read());
panic("%X: TLB Modified Exception at %X(%s)\n", cp0_badvaddr_read(), istate->epc, symbol);
}
 
/kernel/trunk/arch/mips32/src/exception.c
78,8 → 78,6
 
static void unhandled_exception(int n, istate_t *istate)
{
fault_if_from_uspace(istate, "unhandled exception %s", exctable[n]);
print_regdump(istate);
panic("unhandled exception %s\n", exctable[n]);
}
121,10 → 119,8
{
if (cp0_cause_coperr(cp0_cause_read()) == fpu_cop_id)
scheduler_fpu_lazy_request();
else {
fault_if_from_uspace(istate, "unhandled Coprocessor Unusable Exception");
else
panic("unhandled Coprocessor Unusable Exception\n");
}
}
#endif
 
/kernel/trunk/arch/ia32/src/interrupt.c
79,8 → 79,6
 
void null_interrupt(int n, istate_t *istate)
{
fault_if_from_uspace(istate, "unserviced interrupt: %d", n);
 
PRINT_INFO_ERRCODE(istate);
panic("unserviced interrupt: %d\n", n);
}
106,7 → 104,6
io_perm_bitmap_install();
return;
}
fault_if_from_uspace(istate, "general protection fault");
}
 
PRINT_INFO_ERRCODE(istate);
115,8 → 112,6
 
void ss_fault(int n, istate_t *istate)
{
fault_if_from_uspace(istate, "stack fault");
 
PRINT_INFO_ERRCODE(istate);
panic("stack fault\n");
}
123,6 → 118,8
 
void simd_fp_exception(int n, istate_t *istate)
{
 
PRINT_INFO_ERRCODE(istate);
__u32 mxcsr;
asm
(
129,10 → 126,6
"stmxcsr %0;\n"
:"=m"(mxcsr)
);
fault_if_from_uspace(istate, "SIMD FP exception(19), MXCSR: %#zX",
(__native)mxcsr);
 
PRINT_INFO_ERRCODE(istate);
printf("MXCSR: %#zX\n",(__native)(mxcsr));
panic("SIMD FP exception(19)\n");
}
142,7 → 135,6
#ifdef CONFIG_FPU_LAZY
scheduler_fpu_lazy_request();
#else
fault_if_from_uspace(istate, "fpu fault");
panic("fpu fault");
#endif
}
/kernel/trunk/arch/ia32/src/mm/page.c
103,8 → 103,6
access = PF_ACCESS_READ;
 
if (as_page_fault(page, access, istate) == AS_PF_FAULT) {
fault_if_from_uspace(istate, "Page fault: %#x", page);
 
PRINT_INFO_ERRCODE(istate);
printf("page fault address: %#x\n", page);
panic("page fault\n");
/kernel/trunk/arch/ia32/include/interrupt.h
83,22 → 83,11
__u32 stack[];
};
 
/** Return true if exception happened while in userspace */
static inline int istate_from_uspace(istate_t *istate)
{
return !(istate->eip & 0x80000000);
}
 
static inline void istate_set_retaddr(istate_t *istate, __address retaddr)
{
istate->eip = retaddr;
}
 
static inline __native istate_get_pc(istate_t *istate)
{
return istate->eip;
}
 
extern void (* disable_irqs_function)(__u16 irqmask);
extern void (* enable_irqs_function)(__u16 irqmask);
extern void (* eoi_function)(void);
/kernel/trunk/Makefile
122,7 → 122,6
generic/src/console/chardev.c \
generic/src/console/console.c \
generic/src/console/kconsole.c \
generic/src/console/klog.c \
generic/src/console/cmd.c \
generic/src/cpu/cpu.c \
generic/src/ddi/ddi.c \