/kernel/trunk/generic/include/syscall/syscall.h |
---|
31,10 → 31,11 |
typedef enum { |
SYS_CTL = 0, |
SYS_IO = 1, |
SYS_IPC_CALL = 2, |
SYS_IPC_ANSWER = 3, |
SYS_IPC_WAIT = 4, |
SYS_IO, |
SYS_IPC_CALL_SYNC, |
SYS_IPC_CALL_ASYNC, |
SYS_IPC_ANSWER, |
SYS_IPC_WAIT, |
SYSCALL_END |
} syscall_t; |
/kernel/trunk/generic/include/ipc/ipc.h |
---|
77,6 → 77,7 |
extern call_t * ipc_wait_for_call(answerbox_t *box, int flags); |
extern void ipc_answer(answerbox_t *box, call_t *request); |
extern void ipc_call(phone_t *phone, call_t *request); |
extern void ipc_call_sync(phone_t *phone, call_t *request); |
extern void ipc_phone_destroy(phone_t *phone); |
extern void ipc_phone_init(phone_t *phone, answerbox_t *box); |
extern void ipc_call_free(call_t *call); |
/kernel/trunk/generic/src/syscall/syscall.c |
---|
55,15 → 55,17 |
return count; |
} |
/** Send a call over syscall |
/** Send a call over IPC, wait for reply, return to user |
* |
* @return Call identification, returns -1 on fatal error, |
-2 on 'Too many async request, handle answers first |
*/ |
static __native sys_ipc_call(__native phoneid, __native arg1, __native arg2) |
static __native sys_ipc_call_sync(__native phoneid, __native arg1, |
__native arg2, __native *respdata) |
{ |
call_t *call; |
phone_t *phone; |
/* Special answerbox for synchronous messages */ |
if (phoneid >= IPC_MAX_PHONES) |
return -ENOENT; |
72,7 → 74,36 |
if (!phone->callee) |
return -ENOENT; |
call = ipc_call_alloc(); |
call->data[0] = arg1; |
call->data[1] = arg2; |
ipc_call_sync(phone, call); |
copy_to_uspace(respdata, &call->data, sizeof(__native) * IPC_CALL_LEN); |
return 0; |
} |
/** Send an asynchronous call over ipc |
* |
* @return Call identification, returns -1 on fatal error, |
-2 on 'Too many async request, handle answers first |
*/ |
static __native sys_ipc_call_async(__native phoneid, __native arg1, |
__native arg2) |
{ |
call_t *call; |
phone_t *phone; |
if (phoneid >= IPC_MAX_PHONES) |
return -ENOENT; |
phone = &TASK->phones[phoneid]; |
if (!phone->callee) |
return -ENOENT; |
/* TODO: Check that we did not exceed system imposed maximum |
* of asynchrnously sent messages |
* - the userspace should be able to handle it correctly |
124,7 → 155,8 |
syshandler_t syscall_table[SYSCALL_END] = { |
sys_ctl, |
sys_io, |
sys_ipc_call, |
sys_ipc_call_sync, |
sys_ipc_call_async, |
sys_ipc_answer, |
sys_ipc_wait_for_call |
}; |
/kernel/trunk/generic/src/ipc/ipc.c |
---|
105,8 → 105,21 |
spinlock_unlock(&box->lock); |
} |
/** Helper function to facilitate synchronous calls */ |
void ipc_call_sync(phone_t *phone, call_t *request) |
{ |
answerbox_t sync_box; |
/** Send a request using phone to answerbox |
ipc_answerbox_init(&sync_box); |
/* We will receive data on special box */ |
request->callerbox = &sync_box; |
ipc_call(phone, request); |
ipc_wait_for_call(&sync_box, 0); |
} |
/** Send a asynchronous request using phone to answerbox |
* |
* @param phone Phone connected to answerbox |
* @param request Request to be sent |
199,6 → 212,8 |
call = ipc_wait_for_call(&TASK->answerbox, 0); |
printf("Received phone call - %P %P\n", |
call->data[0], call->data[1]); |
call->data[0] = 0xbabaaaee;; |
call->data[1] = 0xaaaaeeee; |
ipc_answer(&TASK->answerbox, call); |
printf("Call answered.\n"); |
} |
/kernel/trunk/arch/amd64/include/syscall.h |
---|
31,7 → 31,8 |
#include <arch/types.h> |
extern __native syscall_handler(__native id, __native a1, __native a2, __native a3); |
extern __native syscall_handler(__native a1,__native a2, __native a3, |
__native a4, __native id); |
extern void syscall_setup_cpu(void); |
#endif |
/kernel/trunk/arch/amd64/src/syscall.c |
---|
63,10 → 63,10 |
/** Dispatch system call */ |
__native syscall_handler(__native a1, __native a2, __native a3, |
__native id) |
__native a4, __native id) |
{ |
if (id < SYSCALL_END) |
return syscall_table[id](a1,a2,a3); |
return syscall_table[id](a1,a2,a3,a4); |
else |
panic("Undefined syscall %d", id); |
} |
/kernel/trunk/arch/mips32/src/exception.c |
---|
134,10 → 134,11 |
static void syscall_exception(int n, istate_t *istate) |
{ |
interrupts_enable(); |
if (istate->a3 < SYSCALL_END) |
istate->v0 = syscall_table[istate->a3](istate->a0, |
if (istate->t0 < SYSCALL_END) |
istate->v0 = syscall_table[istate->t0](istate->a0, |
istate->a1, |
istate->a2); |
istate->a2, |
istate->a3); |
else |
panic("Undefined syscall %d", istate->a3); |
istate->epc += 4; |
/kernel/trunk/arch/ia32/src/interrupt.c |
---|
107,10 → 107,10 |
void syscall(int n, istate_t *istate) |
{ |
interrupts_enable(); |
if (istate->edx < SYSCALL_END) |
istate->eax = syscall_table[istate->edx](istate->eax, istate->ebx, istate->ecx); |
if (istate->esi < SYSCALL_END) |
istate->eax = syscall_table[istate->esi](istate->eax, istate->ebx, istate->ecx, istate->edx); |
else |
panic("Undefined syscall %d", istate->edx); |
panic("Undefined syscall %d", istate->esi); |
interrupts_disable(); |
} |