]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/jdb/jdb_attach_irq.cpp
update
[l4.git] / kernel / fiasco / src / jdb / jdb_attach_irq.cpp
1 IMPLEMENTATION:
2
3 #include <cstdio>
4
5 #include "irq_chip.h"
6 #include "irq.h"
7 #include "irq_mgr.h"
8 #include "jdb_module.h"
9 #include "kernel_console.h"
10 #include "static_init.h"
11 #include "thread.h"
12 #include "types.h"
13
14
15 //===================
16 // Std JDB modules
17 //===================
18
19 /**
20  * 'IRQ' module.
21  *
22  * This module handles the 'R' command that
23  * provides IRQ attachment and listing functions.
24  */
25 class Jdb_attach_irq : public Jdb_module
26 {
27 public:
28   Jdb_attach_irq() FIASCO_INIT;
29 private:
30   static char     subcmd;
31 };
32
33 char     Jdb_attach_irq::subcmd;
34 static Jdb_attach_irq jdb_attach_irq INIT_PRIORITY(JDB_MODULE_INIT_PRIO);
35
36 IMPLEMENT
37 Jdb_attach_irq::Jdb_attach_irq()
38   : Jdb_module("INFO")
39 {}
40
41 PUBLIC
42 Jdb_module::Action_code
43 Jdb_attach_irq::action( int cmd, void *&args, char const *&, int & )
44 {
45   if (cmd)
46     return NOTHING;
47
48   if ((char*)args == &subcmd)
49     {
50       switch (subcmd)
51         {
52         case 'l': // list
53             {
54               Irq_base *r;
55               putchar('\n');
56               unsigned n = Irq_mgr::mgr->nr_irqs();
57               for (unsigned i = 0; i < n; ++i)
58                 {
59                   r = static_cast<Irq*>(Irq_mgr::mgr->irq(i));
60                   if (!r)
61                     continue;
62                   printf("IRQ %02x/%02d\n", i, i);
63                 }
64               return NOTHING;
65             }
66         }
67     }
68   return NOTHING;
69 }
70
71 PUBLIC
72 int
73 Jdb_attach_irq::num_cmds() const
74 {
75   return 1;
76 }
77
78 PUBLIC
79 Jdb_module::Cmd const *
80 Jdb_attach_irq::cmds() const
81 {
82   static Cmd cs[] =
83     {   { 0, "R", "irq", " [l]ist/[a]ttach: %c",
84            "R{l}\tlist IRQ threads", &subcmd }
85     };
86
87   return cs;
88 }
89
90
91 IMPLEMENTATION:
92
93 #include "jdb_kobject.h"
94 #include "irq.h"
95
96 class Jdb_kobject_irq : public Jdb_kobject_handler
97 {
98 };
99
100
101 /* This macro does kind of hacky magic, It uses heuristics to compare
102  * If a C++ object object has a desired type. Therefore the vtable pointer
103  * (*z) of an object is compared to a desired vtable pointer (with some fuzz).
104  * The fuzz is necessary because there is usually a prefix data structure
105  * in each vtable and the size depends on the compiler.
106  * We use a range from x to x + 6 * wordsize.
107  *
108  * It is generally uncritical if this macro delivers a false negative. In
109  * such a case the JDB may deliver less information to the user. However, it
110  * critical to have a false positive, because JDB would probably crash.
111  */
112 #define FIASCO_JDB_CMP_VTABLE(n, o) \
113   extern char n[]; \
114   char const *const *z = reinterpret_cast<char const* const*>(o); \
115   return (*z >= n && *z <= n + 6 * sizeof(Mword)) ? (o) : 0
116
117
118 PUBLIC static
119 Irq_sender *
120 Jdb_kobject_irq::dcast_h(Irq_sender *i)
121 {
122   FIASCO_JDB_CMP_VTABLE(_ZTV10Irq_sender, i);
123 }
124
125 PUBLIC static
126 Irq_muxer *
127 Jdb_kobject_irq::dcast_h(Irq_muxer *i)
128 {
129   FIASCO_JDB_CMP_VTABLE(_ZTV9Irq_muxer, i);
130 }
131
132 PUBLIC template<typename T>
133 static
134 T
135 Jdb_kobject_irq::dcast(Kobject_common *o)
136 {
137   Irq *i = Kobject::dcast<Irq*>(o);
138   if (!i)
139     return 0;
140
141   return dcast_h(static_cast<T>(i));
142 }
143
144 PUBLIC inline
145 Jdb_kobject_irq::Jdb_kobject_irq()
146   : Jdb_kobject_handler(Irq::static_kobj_type)
147 {
148   Jdb_kobject::module()->register_handler(this);
149 }
150
151 PUBLIC
152 char const *
153 Jdb_kobject_irq::kobject_type() const
154 {
155   return JDB_ANSI_COLOR(white) "IRQ" JDB_ANSI_COLOR(default);
156 }
157
158
159 PUBLIC
160 bool
161 Jdb_kobject_irq::handle_key(Kobject_common *o, int key)
162 {
163   (void)o; (void)key;
164   return false;
165 }
166
167
168
169 PUBLIC
170 Kobject_common *
171 Jdb_kobject_irq::follow_link(Kobject_common *o)
172 {
173   Irq_sender *t = Jdb_kobject_irq::dcast<Irq_sender*>(o);
174   Kobject_common *k = t ? Kobject::from_dbg(Kobject_dbg::pointer_to_obj(t->owner())) : 0;
175   return k ? k : o;
176 }
177
178 PUBLIC
179 bool
180 Jdb_kobject_irq::show_kobject(Kobject_common *, int)
181 { return true; }
182
183 PUBLIC
184 int
185 Jdb_kobject_irq::show_kobject_short(char *buf, int max, Kobject_common *o)
186 {
187   Irq *i = Kobject::dcast<Irq*>(o);
188   Kobject_common *w = follow_link(o);
189   Irq_sender *t = Jdb_kobject_irq::dcast<Irq_sender*>(o);
190
191   return snprintf(buf, max, " I=%3lx %s L=%lx T=%lx F=%x Q=%d",
192                   i->pin(), i->chip()->chip_type(), i->obj_id(),
193                   w != o ?  w->dbg_info()->dbg_id() : 0,
194                   (unsigned)i->flags(),
195                   t ? t->queued() : -1);
196 }
197
198 static
199 bool
200 filter_irqs(Kobject_common const *o)
201 { return Kobject::dcast<Irq const *>(o); }
202
203 static Jdb_kobject_list::Mode INIT_PRIORITY(JDB_MODULE_INIT_PRIO) tnt("[IRQs]", filter_irqs);
204
205 static Jdb_kobject_irq jdb_kobject_irq INIT_PRIORITY(JDB_MODULE_INIT_PRIO);