This macro can be used to generating a C binding for a static method, passing the phandle into the target C function.
The key difference between this and BIND_NODE_METHODS is that the C parameter is a package variable rather than an instance variable which cannot exist in a static method context.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- include/libopenbios/bindings.h | 7 +++++++ libopenbios/bindings.c | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)
diff --git a/include/libopenbios/bindings.h b/include/libopenbios/bindings.h index 6b0302d..9874c81 100644 --- a/include/libopenbios/bindings.h +++ b/include/libopenbios/bindings.h @@ -82,6 +82,7 @@ extern cell feval( const char *str ); extern void bind_xtfunc( const char *name, xt_t xt, ucell arg, void (*func)(void) ); extern void bind_func( const char *name, void (*func)(void) ); +extern void bind_2argfunc( const char *name, ucell arg2, ucell arg1, void (*func)(void) ); extern xt_t bind_noname_func( void (*func)(void) ); extern void push_str( const char *str ); extern char *pop_fstr_copy( void ); @@ -121,6 +122,10 @@ typedef struct { name##_m, sizeof(name##_m)/sizeof(method_t)); \ } while(0)
+#define BIND_NODE_STATIC_METHOD(ph, name, func) do { \ + bind_node_static_method(ph, name, ph, func); \ +} while(0) + #define DECLARE_UNNAMED_NODE( name, flags, size ) \ static const int name##_flags_ = flags; \ static const int name##_size_ = size; @@ -147,6 +152,8 @@ extern void bind_node( int flags, int size, const char * const *paths, int npat extern phandle_t bind_new_node( int flags, int size, const char *name, const method_t *methods, int nmethods );
+extern void bind_node_static_method( phandle_t ph, const char *name, ucell arg, void *func ); + #define INSTALL_OPEN 1 /* install trivial open and close methods */
diff --git a/libopenbios/bindings.c b/libopenbios/bindings.c index 9b4308b..2ef8d57 100644 --- a/libopenbios/bindings.c +++ b/libopenbios/bindings.c @@ -116,6 +116,16 @@ bind_xtfunc( const char *name, xt_t xt, ucell arg, void (*func)(void) ) fword("is-xt-cfunc"); }
+void +bind_2argfunc( const char *name, ucell arg2, ucell arg1, void (*func)(void) ) +{ + PUSH( arg2 ); + PUSH( arg1 ); + PUSH( pointer2cell(func) ); + push_str( name ); + fword("is-2arg-cfunc"); +} + xt_t bind_noname_func( void (*func)(void) ) { @@ -494,6 +504,22 @@ bind_node_methods(phandle_t ph, int flags, int size, const method_t *methods, in activate_dev( save_ph ); }
+static void +add_static_method(const char *name, ucell arg, void *func) +{ + bind_2argfunc( name, arg, pointer2cell(func), &call1_func ); +} + +void +bind_node_static_method(phandle_t ph, const char *name, ucell arg, void *func) +{ + phandle_t save_ph = get_cur_dev(); + + activate_dev(ph); + add_static_method(name, arg, func); + activate_dev( save_ph ); +} + void bind_node( int flags, int size, const char * const *paths, int npaths, const method_t *methods, int nmet )