[Pdbg] [PATCH 2/2] libpdbg: Allow programs to register their own hardware units
Alistair Popple
alistair at popple.id.au
Tue Sep 3 17:59:34 AEST 2019
Signed-off-by: Alistair Popple <alistair at popple.id.au>
---
libpdbg/hwunit.c | 3 ---
libpdbg/hwunit.h | 18 ------------------
libpdbg/libpdbg.h | 35 ++++++++++++++++++++++++++++++++++-
libpdbg/target.h | 10 ----------
4 files changed, 34 insertions(+), 32 deletions(-)
diff --git a/libpdbg/hwunit.c b/libpdbg/hwunit.c
index 5c40d23..c7ec63d 100644
--- a/libpdbg/hwunit.c
+++ b/libpdbg/hwunit.c
@@ -21,9 +21,6 @@
#define MAX_HW_UNITS 1024
-struct pdbg_target pdbg_target_size;
-uint8_t pdbg_target_size_test[sizeof(struct pdbg_target)];
-
static const struct hw_unit_info *g_hw_unit[MAX_HW_UNITS];
static int g_hw_unit_count;
diff --git a/libpdbg/hwunit.h b/libpdbg/hwunit.h
index a359af0..be88701 100644
--- a/libpdbg/hwunit.h
+++ b/libpdbg/hwunit.h
@@ -26,26 +26,8 @@
* remove a bunch of tedious container_of() typing */
#define translate_cast(x) (uint64_t (*)(struct pdbg_target *, uint64_t)) (x)
-struct hw_unit_info {
- void *hw_unit;
- size_t size;
-};
-
-void pdbg_hwunit_register(const struct hw_unit_info *hw_unit);
const struct hw_unit_info *pdbg_hwunit_find_compatible(const char *compat);
-/*
- * If this macro fails to compile for you, you've probably not
- * declared the struct pdbg_target as the first member of the
- * container struct. Not doing so will break other assumptions.
- */
-#define DECLARE_HW_UNIT(name) \
- __attribute__((unused)) static inline void name ##_hw_unit_check(void) { \
- ((void)sizeof(char[1 - 2 * (container_off(typeof(name), target) != 0)])); \
- } \
- const struct hw_unit_info __used name ##_hw_unit = \
- { .hw_unit = &name, .size = sizeof(name) };
-
struct htm {
struct pdbg_target target;
int (*start)(struct htm *);
diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h
index e752681..534a803 100644
--- a/libpdbg/libpdbg.h
+++ b/libpdbg/libpdbg.h
@@ -12,9 +12,42 @@
extern "C" {
#endif
-struct pdbg_target;
+struct pdbg_target {
+ char *name;
+ char *compatible;
+ char *class;
+ int (*probe)(struct pdbg_target *target);
+ void (*release)(struct pdbg_target *target);
+ uint64_t (*translate)(struct pdbg_target *target, uint64_t addr);
+ struct pdbg_target *parent;
+ void *priv;
+};
+
struct pdbg_target_class;
+struct hw_unit_info {
+ void *hw_unit;
+ size_t size;
+};
+
+/*
+ * If this macro fails to compile for you, you've probably not
+ * declared the struct pdbg_target as the first member of the
+ * container struct. Not doing so will break other assumptions.
+ */
+#define DECLARE_HW_UNIT(name) \
+ __attribute__((unused)) static inline void name ##_hw_unit_check(void) { \
+ ((void)sizeof(char[1 - 2 * (container_off(typeof(name), target) != 0)])); \
+ } \
+ const struct hw_unit_info __used name ##_hw_unit = \
+ { .hw_unit = &name, .size = sizeof(name) };
+
+/*
+ * Registers a hardware unit implementation. Must be called
+ * prior to pdbg_targets_init().
+ */
+void pdbg_hwunit_register(const struct hw_unit_info *hw_unit);
+
/* loops/iterators */
struct pdbg_target *__pdbg_next_compatible_node(struct pdbg_target *root,
struct pdbg_target *prev,
diff --git a/libpdbg/target.h b/libpdbg/target.h
index ba2b20d..7d88d23 100644
--- a/libpdbg/target.h
+++ b/libpdbg/target.h
@@ -32,16 +32,6 @@ struct pdbg_target_class {
struct list_node class_head_link;
};
-struct pdbg_target {
- char *name;
- char *compatible;
- char *class;
- int (*probe)(struct pdbg_target *target);
- void (*release)(struct pdbg_target *target);
- uint64_t (*translate)(struct pdbg_target *target, uint64_t addr);
- struct pdbg_target *parent;
-};
-
struct pdbg_target_priv {
int index;
enum pdbg_target_status status;
--
2.20.1
More information about the Pdbg
mailing list