#include "defs.h"
extern void pg_fault_debug(pg_dir_t*, void*);
+extern void _task_sig_stub();
void sched_tick(void);
extern int sys_cxnet(long, long, long, long, long, long, long);
extern void _i8259_eoi(u32_t);
#endif /* CONFIG_APIC */
+void task_signal_deliver(task_t *task, stack_frame_t *stk, int signum)
+{
+ struct {
+ void *eip;
+ void *handler;
+ int signal;
+ void *data;
+ siginfo_t si;
+ } __attribute__((packed)) stkfrm;
+
+ stkfrm.data = NULL;
+ stkfrm.signal = signum;
+ stkfrm.eip = (void*)stk->eip;
+ stkfrm.handler = process_get_sighandler((process_t*)task->t_proc, signum);
+ stk->eip = (u32_t)_task_sig_stub;
+ stk->prevesp -= sizeof(stkfrm);
+
+ /* copy the data onto the user-mode stack */
+ process_memcpy_ktop((process_t*)task->t_proc, (void*)stk->prevesp, &stkfrm, sizeof(stkfrm));
+
+ return;
+}
+
void _int_handle(stack_frame_t ctx)
{
switch(ctx.intn) {
void _exc_handle(stack_frame_t ctx)
{
process_t *cproc;
+ task_t *ctask;
- cproc = process_get_current();
+ ctask = task_get_current();
+ cproc = (process_t*)ctask->t_proc;
if(ctx.cs == KERNEL_CODE) {
/* kernel bug */
int sig;
+ dbg_printf("User-mode exception %u at 0x%08x\n", ctx.intn, ctx.eip);
+
+ if(ctx.intn == EXC_PAGEFAULT) {
+ u32_t cr2;
+ pg_dir_t *pd;
+
+ asm volatile("movl %%cr2, %%eax; movl %%eax, %0" : "=r"(cr2));
+ dbg_printf("CR2: 0x%08x\n", cr2);
+
+ if(process_get_pagedir(cproc, &pd) == 0) {
+ pg_fault_debug(pd, (void*)cr2);
+ }
+ for(;;);
+ }
+
+
switch(ctx.intn) {
default:
case EXC_DEBUG:
}
/*
- * Deliver the signal to the current process. The process_signal_deliver()
- * function will make sure that the signal is handled by the current task.
+ * Deliver the signal to the currently executing task
*/
- process_signal_deliver(cproc, sig);
+ task_signal_deliver(ctask, &ctx, sig);
}
return;