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