summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cesar/hle/inc/context.h12
-rw-r--r--cesar/hle/src/hle.c10
-rw-r--r--cesar/hle/tools/inc/context.h25
-rw-r--r--cesar/hle/tools/inc/debug_dump.h4
-rw-r--r--cesar/hle/tools/src/debug_dump.c26
-rw-r--r--cesar/hle/tools/src/tools.c16
-rw-r--r--cesar/hle/tools/test/utest/inc/scenario_defs.h4
-rw-r--r--cesar/hle/tools/test/utest/src/scenario_defs.c4
-rw-r--r--cesar/hle/tools/test/utest/src/test_hle_tools.c4
-rw-r--r--cesar/hle/tools/tools.h12
10 files changed, 85 insertions, 32 deletions
diff --git a/cesar/hle/inc/context.h b/cesar/hle/inc/context.h
index 906d4cb034..9c8fb18893 100644
--- a/cesar/hle/inc/context.h
+++ b/cesar/hle/inc/context.h
@@ -20,6 +20,13 @@
#include "hal/hle/ipmbox.h"
+#if MODULE_INCLUDED (hle_tools)
+# define HLE_TOOLS 1
+# include "hle/tools/tools.h"
+#else
+# define HLE_TOOLS 0
+#endif
+
struct hle_t
{
/** CL context */
@@ -28,6 +35,11 @@ struct hle_t
/** ipmbox context */
ipmbox_t *ipmbox;
+#if HLE_TOOLS
+ /** HLE tools context. */
+ hle_tools_t *hle_tools;
+#endif
+
/** Interface buffer add callback. */
hle_interface_buffer_add_cb_t interface_buffer_add_cb;
/** Interface mme receive callback. */
diff --git a/cesar/hle/src/hle.c b/cesar/hle/src/hle.c
index 911e1d4e1c..f583a85688 100644
--- a/cesar/hle/src/hle.c
+++ b/cesar/hle/src/hle.c
@@ -22,12 +22,6 @@
#include "mac/common/ntb.h"
#include "common/module.h"
-#if MODULE_INCLUDED (hle_tools)
-# define HLE_TOOLS 1
-# include "hle/tools/tools.h"
-#else
-# define HLE_TOOLS 0
-#endif
/** Hle global context */
static hle_t hle_global;
@@ -220,7 +214,7 @@ hle_ipmbox_recv (hle_t *ctx, u32 *msg_buffer, uint length)
break;
#if HLE_TOOLS
case HLE_MSG_TYPE_DEBUG_DUMP:
- hle_tools_recv_msg (ctx->ipmbox, m, msg_length);
+ hle_tools_recv_msg (ctx->hle_tools, m, msg_length);
break;
#endif
}
@@ -251,7 +245,7 @@ hle_init (cl_t *cl)
hle_trace_init (&hle_global);
/* Initialize tools if enabled. */
#if HLE_TOOLS
- hle_tools_init (hle_global.ipmbox);
+ hle_global.hle_tools = hle_tools_init (hle_global.ipmbox);
#endif
/* Tracing */
HLE_TRACE (INIT, mac_ntb());
diff --git a/cesar/hle/tools/inc/context.h b/cesar/hle/tools/inc/context.h
new file mode 100644
index 0000000000..50eab7cbcb
--- /dev/null
+++ b/cesar/hle/tools/inc/context.h
@@ -0,0 +1,25 @@
+#ifndef hle_tools_inc_context_h
+#define hle_tools_inc_context_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2011 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hle/tools/inc/context.h
+ * \brief HLE tools context.
+ * \ingroup hle
+ */
+
+#include "hal/hle/forward.h"
+
+/** HLE tools context. */
+struct hle_tools_t
+{
+ /** Ipmbox context. */
+ ipmbox_t *ipmbox;
+};
+
+#endif /* hle_tools_inc_context_h */
diff --git a/cesar/hle/tools/inc/debug_dump.h b/cesar/hle/tools/inc/debug_dump.h
index 62d23cb28c..7321072a7b 100644
--- a/cesar/hle/tools/inc/debug_dump.h
+++ b/cesar/hle/tools/inc/debug_dump.h
@@ -17,10 +17,10 @@ BEGIN_DECLS
/**
* Initialise debug dump code.
- * \param ipmbox ipmbox context
+ * \param ctx HLE tools context
*/
void
-hle_tools_debug_dump_init (ipmbox_t *ipmbox);
+hle_tools_debug_dump_init (hle_tools_t *ctx);
/**
* Send back a dump buffer.
diff --git a/cesar/hle/tools/src/debug_dump.c b/cesar/hle/tools/src/debug_dump.c
index ad13cc1777..3a747e728c 100644
--- a/cesar/hle/tools/src/debug_dump.c
+++ b/cesar/hle/tools/src/debug_dump.c
@@ -18,9 +18,12 @@
* filled and sent back to ARM side.
*/
#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/debug_dump.h"
void
hle_tools_debug_dump_send_buffer (ipmbox_t *ipmbox,
@@ -38,7 +41,7 @@ hle_tools_debug_dump_send_buffer (ipmbox_t *ipmbox,
/**
* Synchronous dump to ARM side.
- * \param user user parameter (ipmbox context)
+ * \param user user parameter (HLE tools context)
* \param text text buffer with text to write
* \param text_size size of text to write, or 0 for end of dump
* \return sent size
@@ -49,7 +52,7 @@ hle_tools_dump (void *user, const char *text, uint text_size)
const u32 *msg_buffer;
uint msg_buffer_length;
const u32 *m, *mend;
- uint msg, type;
+ uint msg, msg_length, type;
u32 *buffer;
uint buffer_length;
uint dump, dumped;
@@ -57,20 +60,21 @@ hle_tools_dump (void *user, const char *text, uint text_size)
uint wb;
int sent = text_size;
bool end_of_dump = text_size == 0;
- ipmbox_t *ipmbox = user;
- dbg_assert (ipmbox);
+ hle_tools_t *ctx = user;
+ dbg_assert (ctx);
/** Loop until satisfied. */
while (text_size || end_of_dump)
{
/* Get mailbox content. */
msg_buffer = NULL;
- msg_buffer_length = ipmbox_rx_sync (ipmbox, &msg_buffer);
+ msg_buffer_length = ipmbox_rx_sync (ctx->ipmbox, &msg_buffer);
m = msg_buffer;
mend = msg_buffer + msg_buffer_length;
/* Read messages. */
while (m != mend)
{
msg = m[0];
+ msg_length = 1 + BF_GET (IPMBOX_REG__MSG_LENGTH, msg);
type = BF_GET (IPMBOX_REG__MSG_TYPE, msg);
switch (type)
{
@@ -99,24 +103,26 @@ hle_tools_dump (void *user, const char *text, uint text_size)
*buffer++ = w;
text_size -= dumped;
/* Send back message. */
- hle_tools_debug_dump_send_buffer (ipmbox, (u32 *) m[1], dumped);
+ hle_tools_debug_dump_send_buffer (ctx->ipmbox, (u32 *) m[1],
+ dumped);
/* Clear end_of_dump flag, it was sent. */
end_of_dump = false;
break;
default:
- /* Ignore message. */
+ /* Forward to general tools. */
+ hle_tools_recv_msg (ctx, m, msg_length);
break;
}
/* Message length + the message header. */
- m += BF_GET (IPMBOX_REG__MSG_LENGTH, msg) + 1;
+ m += msg_length;
}
}
return sent;
}
void
-hle_tools_debug_dump_init (ipmbox_t *ipmbox)
+hle_tools_debug_dump_init (hle_tools_t *ctx)
{
- dbg_register_dump_callback (hle_tools_dump, ipmbox);
+ dbg_register_dump_callback (hle_tools_dump, ctx);
}
diff --git a/cesar/hle/tools/src/tools.c b/cesar/hle/tools/src/tools.c
index faa7157a44..cbc2625560 100644
--- a/cesar/hle/tools/src/tools.c
+++ b/cesar/hle/tools/src/tools.c
@@ -14,19 +14,27 @@
#include "hle/tools/tools.h"
#include "hal/hle/defs.h"
+#include "inc/context.h"
#include "inc/debug_dump.h"
-void
+/** Global context. */
+hle_tools_t hle_tools_global;
+
+hle_tools_t *
hle_tools_init (ipmbox_t *ipmbox)
{
+ hle_tools_t *ctx = &hle_tools_global;
+ ctx->ipmbox = ipmbox;
#if CONFIG_HLE_TOOLS_DEBUG_DUMP
- hle_tools_debug_dump_init (ipmbox);
+ hle_tools_debug_dump_init (ctx);
#endif
+ return ctx;
}
void
-hle_tools_recv_msg (ipmbox_t *ipmbox, const u32 *msg, uint length)
+hle_tools_recv_msg (hle_tools_t *ctx, const u32 *msg, uint length)
{
+ dbg_assert (ctx);
dbg_assert (msg && length);
hle_msg_type_t type = BF_GET (IPMBOX_REG__MSG_TYPE, msg[0]);
switch (type)
@@ -34,7 +42,7 @@ hle_tools_recv_msg (ipmbox_t *ipmbox, const u32 *msg, uint length)
#if CONFIG_HLE_TOOLS_DEBUG_DUMP
case HLE_MSG_TYPE_DEBUG_DUMP:
/* Nothing to dump. */
- hle_tools_debug_dump_send_buffer (ipmbox, (u32 *) msg[1], 0);
+ hle_tools_debug_dump_send_buffer (ctx->ipmbox, (u32 *) msg[1], 0);
break;
#endif
default:
diff --git a/cesar/hle/tools/test/utest/inc/scenario_defs.h b/cesar/hle/tools/test/utest/inc/scenario_defs.h
index 45b78ca538..39f7578abe 100644
--- a/cesar/hle/tools/test/utest/inc/scenario_defs.h
+++ b/cesar/hle/tools/test/utest/inc/scenario_defs.h
@@ -14,10 +14,12 @@
*/
#include "hal/hle/ipmbox.h"
+#include "hle/tools/tools.h"
/* Scenario globals. */
#define SCENARIO_DEFS_GLOBALS \
- ipmbox_t *ipmbox;
+ ipmbox_t *ipmbox; \
+ hle_tools_t *hle_tools;
struct scenario_ipmbox_buffer_t
{
diff --git a/cesar/hle/tools/test/utest/src/scenario_defs.c b/cesar/hle/tools/test/utest/src/scenario_defs.c
index 086dcfce40..dce387fac6 100644
--- a/cesar/hle/tools/test/utest/src/scenario_defs.c
+++ b/cesar/hle/tools/test/utest/src/scenario_defs.c
@@ -25,7 +25,7 @@ scenario_action_hle_tools_dump_cb (scenario_globals_t *globals,
{
test_within (scenario.t);
scenario_action_hle_tools_dump_t *p = &params->action_hle_tools_dump;
- int sent = hle_tools_dump (globals->ipmbox, p->text, p->text_size);
+ int sent = hle_tools_dump (globals->hle_tools, p->text, p->text_size);
test_fail_unless (sent == p->sent);
}
@@ -35,7 +35,7 @@ scenario_action_hle_tools_recv_msg_cb (scenario_globals_t *globals,
{
scenario_action_hle_tools_recv_msg_t *p =
&params->action_hle_tools_recv_msg;
- hle_tools_recv_msg (globals->ipmbox, p->buffer, p->length);
+ hle_tools_recv_msg (globals->hle_tools, p->buffer, p->length);
}
uint
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 c61190837c..d4c6a89703 100644
--- a/cesar/hle/tools/test/utest/src/test_hle_tools.c
+++ b/cesar/hle/tools/test/utest/src/test_hle_tools.c
@@ -46,6 +46,7 @@ dump_test (test_t t, const char *sdump, const char *s1, const char *s2,
};
scenario_globals_t globals = {
.ipmbox = INVALID_PTR,
+ .hle_tools = hle_tools_init (INVALID_PTR),
};
scenario_run (t, entries, &globals);
#if DEFS_BIG_ENDIAN
@@ -114,6 +115,7 @@ recv_msg_test_suite (test_t t)
};
scenario_globals_t globals = {
.ipmbox = INVALID_PTR,
+ .hle_tools = hle_tools_init (INVALID_PTR),
};
scenario_run (t, entries, &globals);
} test_end;
@@ -131,6 +133,7 @@ recv_msg_test_suite (test_t t)
};
scenario_globals_t globals = {
.ipmbox = INVALID_PTR,
+ .hle_tools = hle_tools_init (INVALID_PTR),
};
scenario_run (t, entries, &globals);
} test_end;
@@ -141,7 +144,6 @@ main (int argc, char **argv)
{
test_t t;
test_init (t, argc, argv);
- hle_tools_init (INVALID_PTR);
dump_test_suite (t);
recv_msg_test_suite (t);
test_result (t);
diff --git a/cesar/hle/tools/tools.h b/cesar/hle/tools/tools.h
index 0d22a997de..a585e0fd5d 100644
--- a/cesar/hle/tools/tools.h
+++ b/cesar/hle/tools/tools.h
@@ -13,27 +13,31 @@
* \ingroup hle
*/
-#include "hal/hle/ipmbox.h"
+#include "hal/hle/forward.h"
#include "config/hle/tools.h"
+/* Forward declaration. */
+typedef struct hle_tools_t hle_tools_t;
+
BEGIN_DECLS
/**
* Initialise HLE tools.
* \param ipmbox ipmbox context
+ * \return HLE tools context
*/
-void
+hle_tools_t *
hle_tools_init (ipmbox_t *ipmbox);
/**
* Handle one message received from mailbox.
- * \param ipmbox ipmbox context
+ * \param ctx HLE tools context
* \param msg message to handle
* \param length message length
*/
void
-hle_tools_recv_msg (ipmbox_t *ipmbox, const u32 *msg, uint length);
+hle_tools_recv_msg (hle_tools_t *ctx, const u32 *msg, uint length);
END_DECLS