Commit feba5441 authored by Anton Burtsev's avatar Anton Burtsev Committed by Vikram Narayanan

More client-server code

parent 3d1d609c
#include "server-idl.h"
struct server_interface {
int (*test_func1) (unsigned long a, long b, char c);
int (*test_func2) (unsigned long a);
};
/* Caller stubs */
......@@ -22,17 +18,13 @@ int register_server_callee(struct server_interface *server) {
/* Main execution loop */
int execution_loop(void) {
int ret;
capability_t api_cap = current->utcb->boot_info.boot_caps[LCD_BOOT_API_CAP];
capability_t reply_cap = current->utcb->boot_info.boot_caps[LCD_BOOT_REPLY_CAP];
int ret;
enum client_interface call;
capability_t server = current->utcb->boot_info.boot_caps[LCD_BOOT_FREE_CAP0];
capability_t server_interface;
capability_t server_reply;
struct message_info *msg = &current->utcb->msg_info;
ret = lcd_alloc_cap(&current->cap_cache, &server_interface);
if(ret) {
printk(KERN_ERR "Failed to allocate free capability\n");
......@@ -52,8 +44,8 @@ int execution_loop(void) {
call = msg->regs[0];
switch (call) {
case LCD_CREATE_SYNC_ENDPOINT:
ret = lcd_api_create_sync_endpoint(lcd_api, reply_cap);
case client_interface_register_server:
ret = register(lcd_api, reply_cap);
break;
default:
printk(KERN_ERR "lcd_api: invalid call number:%d\n", call);
......@@ -84,6 +76,7 @@ int execution_loop_thread(void *p) {
return -EINVAL;
}
/* Introduction code */
ret = lcd_prepare_introduction(lcd_api_cap(),
lcd_api_reply_cap(),
&client_server_rvp,
......@@ -93,13 +86,6 @@ int execution_loop_thread(void *p) {
return -EINVAL;
}
/* Introduction code */
ret = lcd_prepare_introduction(&client_server_rvp);
if (ret) {
printk(KERN_ERR "client failed to initialize client-server environtment\n");
return -EINVAL;
}
return execution_loop();
};
......
......@@ -5,6 +5,7 @@ enum client_interface {
client_interface_register_server,
};
int register_server(capability_t client, capability _t server);
int register_server(capability_t client, struct server_interface *server);
int register_server_callee(capability_t server, );
#endif
......@@ -27,6 +27,7 @@ struct server_interface *server;
int register_server(struct server_interface *s) {
server = s;
client_main();
};
EXPORT_SYMBOL(register_server);
......
/*
* Author: Anton Burtsev <aburtsev@flux.utah.edu>
* Copyright: University of Utah
*
*/
#ifndef _LCD_TEST_
struct server_interface {
int (*test_func1) (unsigned long a, long b, char c);
int (*test_func2) (unsigned long a);
};
#include "server-idl.h"
int terminate_loop;
void terminate_execution_loop() {
terminate_loop = 1;
};
/* Caller stubs */
int test_func1(unsigned long a, long b, char c) {
int test_func1_caller(capability_t server, unsigned long a, long b, char c) {
int ret;
msg->regs[0] = ;
msg->regs[1] = 1;
msg->regs[2] = 2;
msg->regs[3] = 3;
msg->regs[0] = server_interface_test_func1;
msg->regs[1] = (uint64_t) a;
msg->regs[2] = (uint64_t) b;
msg->regs[3] = (uint64_t) c;
msg->valid_regs = 4;
msg->cap_regs[0] = server_reply;
msg->cap_regs[0] = server;
msg->valid_cap_regs = 1;
ret = ipc_call(server_interface, msg);
ret = ipc_call(server, msg);
if (ret) {
printk(KERN_ERR "client failed to ivoke server:%d\n", ret);
/* XXX: BU: make up some result, which? */
return ret;
};
return (int) msg->regs[0];
}
int test_func2(unsigned long a) {
int test_func2_caller(unsigned long a) {
int ret;
msg->regs[0] = server_interface_test_func2;
msg->regs[1] = (uint64_t) a;
msg->valid_regs = 2;
msg->cap_regs[0] = server;
msg->valid_cap_regs = 1;
ret = ipc_call(server, msg);
if (ret) {
printk(KERN_ERR "client failed to ivoke server:%d\n", ret);
/* XXX: BU: make up some result, which? */
return ret;
};
return (int) msg->regs[0];
}
/* Callee stubs */
int test_func1_srv(unsigned long a, long b, char c) {
int test_func1_callee(struct message_info *msg, capability_t reply_cap) {
int ret;
unsigned long a = (unsigned long) msg->regs[1];
long b = (long) msg->regs[2];
char c = (char) msg->regs[3];
ret = test_func1(a, b, c);
msg->regs[0] = ret;
msg->valid_regs = 1;
msg->valid_cap_regs = 0;
ret = ipc_reply(reply_cap, msg);
if(ret) {
printk(KERN_ERR "IPC reply failed: %d\n", ret);
return ret;
};
return ret;
}
int test_func2_callee(struct message_info *msg, capability_t reply_cap) {
int ret;
unsigned long a = (unsigned long) msg->regs[1];
ret = test_func2(a);
msg->regs[0] = ret;
msg->valid_regs = 1;
msg->valid_cap_regs = 0;
ret = ipc_reply(reply_cap, msg);
if(ret) {
printk(KERN_ERR "IPC reply failed: %d\n", ret);
return ret;
};
return ret;
}
int test_func2_srv(unsigned long a) {
/* Main execution loop */
int execution_loop(void) {
int ret;
enum client_interface call;
//capability_t client = current->utcb->boot_info.boot_caps[LCD_BOOT_FREE_CAP0];
capability_t server_interface;
struct message_info *msg = &current->utcb->msg_info;
while(!terminate_loop) {
msg->valid_regs = 3;
ret = ipc_recv(server_interface, msg);
if (ret) {
printk(KERN_ERR "server failed ipc_recv:%d\n", ret);
return ret;
};
call = msg->regs[0];
switch (call) {
case server_interface_test_func1:
ret = test_func1_callee(msg, server_interface);
break;
case server_interface_test_func2:
ret = test_func2_callee(msg, server_interface);
break;
default:
printk(KERN_ERR "lcd_api: invalid call number:%d\n", call);
msg->valid_regs = 0;
msg->valid_cap_regs = 0;
ipc_reply(server_interface, msg);
};
};
return 0;
};
int execution_loop_thread(void *p) {
int ret;
ret = lcd_init_current();
if (ret) {
printk(KERN_ERR "Failed to init current thread with LCD:%d\n", ret);
return -EINVAL;
}
/* Introduction code */
ret = lcd_accept_client_introduction();
if (ret) {
printk(KERN_ERR "client failed to initialize client-server environtment\n");
return -EINVAL;
}
return execution_loop();
};
int execution_loop_thread_init(void) {
struct task_struct *t;
t = kthread_create(execution_loop_thread, NULL, "cs-client");
if (!t) {
printk(KERN_ERR "Failed to create module thread\n");
return -EINVAL;
};
wake_up_process(t);
return 0;
}
......@@ -7,11 +7,14 @@ enum server_interface {
}
/* Caller stubs */
int test_func1(unsigned long a, long b, char c);
int test_func2(unsigned long a);
int test_func1_caller(capability_t server, unsigned long a, long b, char c);
int test_func2_caller(capability_t server, unsigned long a);
/* Callee stubs */
int test_func1_srv(unsigned long a, long b, char c);
int test_func2_srv(unsigned long a);
int test_func1_callee(struct message_info *msg, capability_t reply_cap);
int test_func2_callee(struct message_info *msg, capability_t reply_cap);
/* Introduction code */
extern int accept_client_introduction(void);
#endif
......@@ -23,80 +23,27 @@
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("LCD client-server test server");
extern int lcd_client_server_init_server(void);
int module_execution_loop(void) {
int ret;
capability_t rvp_cap = current->utcb->boot_info.boot_rvp;
struct message_info *msg = &current->utcb->msg_info;
msg->regs[0] = 1;
msg->regs[1] = 2;
msg->regs[2] = 3;
msg->regs[3] = 4;
msg->regs[4] = 5;
msg->regs[5] = 6;
msg->valid_regs = 6;
ret = ipc_send(rvp_cap, msg);
if (ret) {
printk(KERN_ERR "sender failed:%d\n", ret);
return ret;
};
msg->valid_regs = 8;
ret = ipc_recv(rvp_cap, msg);
if (ret) {
printk(KERN_ERR "sender failed to recv:%d\n", ret);
return ret;
};
printk(KERN_INFO "Sender got: %lld,%lld,%lld,%lld,%lld,%lld,%lld,%lld\n",
msg->regs[0], msg->regs[1], msg->regs[2], msg->regs[3],
msg->regs[4], msg->regs[5], msg->regs[6], msg->regs[7]);
return 0;
int test_func1(unsigned long a, long b, char c) {
printk(KERN_INFO "test_func1: a:%llu, b:%li, c:%c\n", a, b, c);
return a + b;
};
int module_thread(void *p) {
int ret;
ret = lcd_client_server_init_server();
if (ret) {
printk(KERN_ERR "sender failed to initialize ping-pong environtment\n");
return -EINVAL;
}
return module_execution_loop();
int test_func2(unsigned long a) {
printk(KERN_INFO "test_func1: a:%llu\n", a);
return a * 10;
};
int module_thread_init(void) {
struct task_struct *t;
t = kthread_create(module_thread, NULL, "cs-server");
if (!t) {
printk(KERN_ERR "Failed to create module thread\n");
return -EINVAL;
};
wake_up_process(t);
return 0;
}
static int __init server_init(void)
{
printk(KERN_ERR "IPC ping-pong, sender module loaded\n");
return module_thread_init();
execution_loop_thread_init();
register_server();
}
static void __exit server_exit(void)
{
terminate_execution_loop();
return;
}
module_init(server_init);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment