/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"); |
} |