|
|
1.1 root 1: /*
2: * Creation Date: <2003/12/19 23:09:56 samuel>
3: * Time-stamp: <2004/01/07 19:36:42 samuel>
4: *
5: * <bindings.h>
6: *
7: * Forth bindings
8: *
9: * Copyright (C) 2003, 2004 Samuel Rydh ([email protected])
10: *
11: * This program is free software; you can redistribute it and/or
12: * modify it under the terms of the GNU General Public License
13: * version 2
14: *
15: */
16:
17: #ifndef _H_BINDINGS
18: #define _H_BINDINGS
19:
20: #include "kernel/stack.h"
21: #include "kernel/kernel.h"
22:
23: #define PUSH3(a,b,c) do { PUSH((a)); PUSH((b)); PUSH((c)); } while(0)
24: #define PUSH2(a,b) do { PUSH((a)); PUSH((b)); } while(0)
25: #define RET( v ) do { PUSH(v); return; } while(0)
26:
27: /* initialization */
28: extern int initialize_forth( void );
29:
30: /* panic */
31: extern int forth_segv_handler( char *segv_addr );
32:
33: /* active package */
34: extern phandle_t find_dev( const char *path );
35: extern phandle_t get_cur_dev( void );
36: extern phandle_t activate_device( const char *str );
37: extern void device_end( void );
38: extern void activate_dev( phandle_t ph );
39:
40:
41: /* ihandle related */
42: extern phandle_t ih_to_phandle( ihandle_t ih );
43: extern ihandle_t my_parent( void );
44: extern ihandle_t my_self( void );
45: extern char *my_args_copy( void );
46:
47: extern xt_t find_package_method( const char *meth, phandle_t ph );
48: extern xt_t find_ih_method( const char *method, ihandle_t ih );
49: extern xt_t find_parent_method( const char *method );
50: extern void call_package( xt_t xt, ihandle_t ihandle );
51: extern void call_parent( xt_t xt );
52: extern void call_parent_method( const char *method );
53:
54: /* package */
55: extern ihandle_t open_package( const char *argstr, phandle_t ph );
56: extern ihandle_t open_dev( const char *spec );
57: extern void close_package( ihandle_t ih );
58: extern void close_dev( ihandle_t ih );
59:
60: /* property access */
61: extern void set_property( phandle_t ph, const char *name,
62: const char *buf, int len );
63: extern void set_int_property( phandle_t ph, const char *name,
64: u32 val );
65: extern u32 get_int_property( phandle_t ph, const char *name,
66: int *retlen );
67: extern char *get_property( phandle_t ph, const char *name,
68: int *retlen );
69:
70: /* device tree iteration */
71: extern phandle_t dt_iter_begin( void );
72: extern phandle_t dt_iterate( phandle_t last_tree );
73: extern phandle_t dt_iterate_type( phandle_t last_tree,
74: const char *type );
75: static inline phandle_t dt_find_type( const char *type ) {
76: return dt_iterate_type( 0, type );
77: }
78:
79: /* forth bindings */
80: extern cell feval( const char *str );
81: extern void bind_xtfunc( const char *name, xt_t xt,
82: ucell arg, void (*func)(void) );
83: extern void bind_func( const char *name, void (*func)(void) );
84: extern xt_t bind_noname_func( void (*func)(void) );
85: extern void push_str( const char *str );
86: extern char *pop_fstr_copy( void );
87:
88: extern int _fword( const char *word, xt_t *cache_xt );
89: extern cell _eword( const char *word, xt_t *cache_xt, int nargs );
90: extern int _selfword( const char *method, xt_t *cache_xt );
91: extern int _parword( const char *method, xt_t *cache_xt );
92:
93: #define fword(w) ({ static xt_t cache_xt = 0; _fword(w, &cache_xt); })
94: #define eword(w, nargs) ({ static xt_t cache_xt = 0; _eword(w, &cache_xt, nargs); })
95: #define selfword(w) ({ static xt_t cache_xt = 0; _selfword(w, &cache_xt); })
96: #define parword(w) ({ static xt_t cache_xt = 0; _parword(w, &cache_xt); })
97:
98: extern void throw( int error );
99:
100:
101: /* node bindings */
102: extern void make_openable( int only_parents );
103:
104:
105: typedef struct {
106: const char *name;
107: void *func;
108: } method_t;
109:
110: #define REGISTER_NAMED_NODE( name, path ) do { \
111: bind_new_node( name##_flags_, name##_size_, \
112: path, name##_m, sizeof(name##_m)/sizeof(method_t)); \
113: } while(0)
114:
115: #define REGISTER_NAMED_NODE_PHANDLE( name, path, phandle ) do { \
116: phandle = \
117: bind_new_node( name##_flags_, name##_size_, \
118: path, name##_m, sizeof(name##_m)/sizeof(method_t)); \
119: } while(0)
120:
121: #define REGISTER_NODE_METHODS( name, path ) do { \
122: const char *paths[1]; \
123: \
124: paths[0] = path; \
125: bind_node( name##_flags_, name##_size_, \
126: paths, 1, name##_m, sizeof(name##_m)/sizeof(method_t)); \
127: } while(0)
128:
129: #define DECLARE_UNNAMED_NODE( name, flags, size ) \
130: static const int name##_flags_ = flags; \
131: static const int name##_size_ = size;
132:
133: #define DECLARE_NODE( name, flags, size, paths... ) \
134: static const char * const name##_p[] = { paths }; \
135: DECLARE_UNNAMED_NODE(name, flags, size)
136:
137: #define NODE_METHODS( name ) \
138: static const method_t name##_m[]
139:
140: #define REGISTER_NODE( name ) do { \
141: bind_node( name##_flags_, name##_size_, \
142: name##_p, sizeof(name##_p)/sizeof(char*), \
143: name##_m, sizeof(name##_m)/sizeof(method_t) ); \
144: } while(0)
145:
146: extern void bind_node( int flags, int size, const char * const *paths, int npaths,
147: const method_t *methods, int nmethods );
148:
149: extern phandle_t bind_new_node( int flags, int size, const char *name,
150: const method_t *methods, int nmethods );
151:
152: #define INSTALL_OPEN 1 /* install trivial open and close methods */
153:
154:
155:
156: #endif /* _H_BINDINGS */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.