summaryrefslogtreecommitdiff
path: root/cesar/hle/tools
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/hle/tools')
-rw-r--r--cesar/hle/tools/Config1
-rw-r--r--cesar/hle/tools/Module4
-rw-r--r--cesar/hle/tools/inc/rpc.h32
-rw-r--r--cesar/hle/tools/src/rpc.c56
-rw-r--r--cesar/hle/tools/src/tools.c10
-rw-r--r--cesar/hle/tools/test/utest/Config1
-rw-r--r--cesar/hle/tools/test/utest/src/test_hle_tools.c34
7 files changed, 138 insertions, 0 deletions
diff --git a/cesar/hle/tools/Config b/cesar/hle/tools/Config
index 0a0efbe41a..889da94bd3 100644
--- a/cesar/hle/tools/Config
+++ b/cesar/hle/tools/Config
@@ -1 +1,2 @@
CONFIG_HLE_TOOLS_DEBUG_DUMP = y
+CONFIG_HLE_TOOLS_RPC = y
diff --git a/cesar/hle/tools/Module b/cesar/hle/tools/Module
index 0c7363a6cc..9575ffad90 100644
--- a/cesar/hle/tools/Module
+++ b/cesar/hle/tools/Module
@@ -3,3 +3,7 @@ SOURCES := tools.c
ifeq ($(CONFIG_HLE_TOOLS_DEBUG_DUMP),y)
SOURCES += debug_dump.c
endif
+
+ifeq ($(CONFIG_HLE_TOOLS_RPC),y)
+SOURCES += rpc.c
+endif
diff --git a/cesar/hle/tools/inc/rpc.h b/cesar/hle/tools/inc/rpc.h
new file mode 100644
index 0000000000..9513ca4fcc
--- /dev/null
+++ b/cesar/hle/tools/inc/rpc.h
@@ -0,0 +1,32 @@
+#ifndef hle_tools_inc_rpc_h
+#define hle_tools_inc_rpc_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2011 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hle/tools/inc/rpc.h
+ * \brief HLE Remote Procedure Call.
+ * \ingroup hle
+ */
+
+BEGIN_DECLS
+
+/**
+ * Receive an RPC message.
+ * \param ctx HLE tools context
+ * \param forward_length length of data in received buffer
+ * \param reverse_length length of buffer for reply
+ * \param cookie sender cookie
+ * \param buffer message buffer
+ */
+void
+hle_tools_rpc_recv (hle_tools_t *ctx, uint forward_length,
+ uint reverse_length, uint cookie, u32 *buffer);
+
+END_DECLS
+
+#endif /* hle_tools_inc_rpc_h */
diff --git a/cesar/hle/tools/src/rpc.c b/cesar/hle/tools/src/rpc.c
new file mode 100644
index 0000000000..78f0b434d5
--- /dev/null
+++ b/cesar/hle/tools/src/rpc.c
@@ -0,0 +1,56 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2011 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hle/tools/src/rpc.c
+ * \brief HLE Remote Procedure Call.
+ * \ingroup hle
+ */
+#include "common/std.h"
+#include "hle/tools/tools.h"
+
+#include "hal/hle/ipmbox.h"
+#include "hal/hle/defs.h"
+#include "inc/context.h"
+#include "inc/rpc.h"
+
+/**
+ * Send RPC response.
+ * \param ctx HLE tools context
+ * \param length length of data in buffer
+ * \param more_data true if another buffer as to be sent
+ * \param cookie received cookie
+ * \param buffer received buffer
+ */
+static void
+hle_tools_rpc_send (hle_tools_t *ctx, uint length, bool more_data,
+ uint cookie, u32 *buffer)
+{
+ dbg_assert (ctx);
+ dbg_assert (buffer);
+ u32 msg[2];
+ msg[0] = BF_FILL (IPMBOX_REG,
+ (MSG_TYPE, HLE_MSG_TYPE_RPC),
+ (MSG_LENGTH, COUNT (msg) - 1),
+ (PARAM_RPC_FORWARD_LENGTH, length),
+ (PARAM_RPC_MORE_DATA, more_data),
+ (PARAM_RPC_COOKIE, cookie));
+ msg[1] = (u32) buffer;
+ ipmbox_tx (ctx->ipmbox, msg, COUNT (msg));
+}
+
+void
+hle_tools_rpc_recv (hle_tools_t *ctx, uint forward_length,
+ uint reverse_length, uint cookie, u32 *buffer)
+{
+ dbg_assert (ctx);
+ dbg_assert (buffer);
+ /* Very simple system for the moment, reply and crash. */
+ hle_tools_rpc_send (ctx, 0, false, cookie, buffer);
+ dbg_fatal ("fatal rpc");
+}
+
diff --git a/cesar/hle/tools/src/tools.c b/cesar/hle/tools/src/tools.c
index cbc2625560..ac6bd1776d 100644
--- a/cesar/hle/tools/src/tools.c
+++ b/cesar/hle/tools/src/tools.c
@@ -16,6 +16,7 @@
#include "hal/hle/defs.h"
#include "inc/context.h"
#include "inc/debug_dump.h"
+#include "inc/rpc.h"
/** Global context. */
hle_tools_t hle_tools_global;
@@ -45,6 +46,15 @@ hle_tools_recv_msg (hle_tools_t *ctx, const u32 *msg, uint length)
hle_tools_debug_dump_send_buffer (ctx->ipmbox, (u32 *) msg[1], 0);
break;
#endif
+#if CONFIG_HLE_TOOLS_RPC
+ case HLE_MSG_TYPE_RPC:
+ hle_tools_rpc_recv (
+ ctx,
+ BF_GET (IPMBOX_REG__PARAM_RPC_FORWARD_LENGTH, msg[0]),
+ BF_GET (IPMBOX_REG__PARAM_RPC_REVERSE_LENGTH_KB, msg[0]) * 1024,
+ BF_GET (IPMBOX_REG__PARAM_RPC_COOKIE, msg[0]), (u32 *) msg[1]);
+ break;
+#endif
default:
/* Ignore message. */
break;
diff --git a/cesar/hle/tools/test/utest/Config b/cesar/hle/tools/test/utest/Config
new file mode 100644
index 0000000000..1221024089
--- /dev/null
+++ b/cesar/hle/tools/test/utest/Config
@@ -0,0 +1 @@
+CONFIG_DEBUG_FATAL_CATCH = y
diff --git a/cesar/hle/tools/test/utest/src/test_hle_tools.c b/cesar/hle/tools/test/utest/src/test_hle_tools.c
index d4c6a89703..0194aca435 100644
--- a/cesar/hle/tools/test/utest/src/test_hle_tools.c
+++ b/cesar/hle/tools/test/utest/src/test_hle_tools.c
@@ -139,6 +139,39 @@ recv_msg_test_suite (test_t t)
} test_end;
}
+void
+rpc_test_suite (test_t t)
+{
+ test_suite_begin (t, "rpc");
+ test_case_begin (t, "basic");
+ test_begin (t, "crash")
+ {
+ dbg_fatal_try_begin
+ {
+ char buffer[1024] = "fatal\n";
+ scenario_entry_t entries[] = {
+ SCENARIO_ACTION (hle_tools_recv_msg,
+ .buffer = { 0x32006130, (u32) buffer },
+ .length = 2),
+ SCENARIO_EVENT (ipmbox_tx,
+ .buffer = { 0x30000130, (u32) buffer },
+ .length = 2),
+ SCENARIO_END
+ };
+ scenario_globals_t globals = {
+ .ipmbox = INVALID_PTR,
+ .hle_tools = hle_tools_init (INVALID_PTR),
+ };
+ scenario_run (t, entries, &globals);
+ }
+ dbg_fatal_try_catch (const char *fatal_message)
+ {
+ test_fail_unless (strcmp (fatal_message, "fatal rpc") == 0);
+ }
+ dbg_fatal_try_end;
+ } test_end;
+}
+
int
main (int argc, char **argv)
{
@@ -146,6 +179,7 @@ main (int argc, char **argv)
test_init (t, argc, argv);
dump_test_suite (t);
recv_msg_test_suite (t);
+ rpc_test_suite (t);
test_result (t);
return test_nb_failed (t) == 0 ? 0 : 1;
}