]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/jdb/jdb_obj_space.cpp
26e2fb35ed2c0076d24dd6e6200398c882d5d8a1
[l4.git] / kernel / fiasco / src / jdb / jdb_obj_space.cpp
1 IMPLEMENTATION:
2
3 #include <cstdio>
4
5 #include "config.h"
6 #include "jdb.h"
7 #include "jdb_screen.h"
8 #include "jdb_table.h"
9 #include "jdb_kobject.h"
10 #include "kernel_console.h"
11 #include "kmem.h"
12 #include "keycodes.h"
13 #include "space.h"
14 #include "task.h"
15 #include "thread_object.h"
16 #include "static_init.h"
17 #include "types.h"
18
19
20 class Jdb_obj_space : public Jdb_table, public Jdb_kobject_handler
21 {
22 public:
23   enum Mode
24   {
25     Name,
26     Raw,
27     End_mode
28   };
29
30 private:
31   Address _base;
32   Space  *_task;
33   Mode    _mode;
34
35   bool show_kobject(Kobject_common *, int) { return false; }
36
37 };
38
39 static inline
40 Jdb_obj_space::Mode
41 operator ++ (Jdb_obj_space::Mode &m)
42 {
43   long _m = m;
44   ++_m;
45   if (_m >= Jdb_obj_space::End_mode)
46     _m = 0;
47
48   m = Jdb_obj_space::Mode(_m);
49
50   return m;
51 }
52
53 //char Jdb_obj_space_m::first_char;
54
55 PUBLIC
56 Jdb_obj_space::Jdb_obj_space(Address base = 0, int level = 0)
57 : Jdb_kobject_handler(0),
58   _base(base),
59   _task(0),
60   _mode(Name)
61 {
62   (void)level;
63   Jdb_kobject::module()->register_handler(this);
64 }
65
66 PUBLIC
67 unsigned
68 Jdb_obj_space::col_width(unsigned column) const
69 {
70   if (column == 0)
71     return Jdb_screen::Col_head_size;
72   else
73     return 16;
74 }
75
76 PUBLIC
77 unsigned long
78 Jdb_obj_space::cols() const
79 {
80   return 5;
81 }
82
83 PUBLIC
84 unsigned long
85 Jdb_obj_space::rows() const
86 { return Obj_space::Map_max_address / (cols()-1); }
87
88 PUBLIC
89 void
90 Jdb_obj_space::print_statline(unsigned long row, unsigned long col)
91 {
92   static char buf[128];
93   unsigned rights;
94
95   Kobject_iface *o = item(index(row,col), &rights);
96   if (!o)
97     {
98       Jdb::printf_statline("objs", "<Space>=mode", "%lx: -- INVALID --",
99                            index(row,col));
100       return;
101     }
102
103   unsigned len = Jdb_kobject::obj_description(buf, sizeof(buf), true, o->dbg_info());
104   Jdb::printf_statline("objs", "<Space>=mode",
105                        "%lx: %-*s", index(row,col), len, buf);
106 }
107
108 PUBLIC
109 void
110 Jdb_obj_space::print_entry(Address entry)
111 {
112   unsigned rights;
113   Kobject_iface *o = item(entry, &rights);
114
115   if (!o)
116     printf("       --       ");
117   else
118     {
119       char r = '-';
120       switch (_mode)
121         {
122         case Name:
123           switch (rights)
124             {
125             case L4_fpage::WX: r = '*'; break;
126             case L4_fpage::W:  r = 'w'; break;
127             case L4_fpage::X:  r = 'x'; break;
128             }
129           printf("%05lx%c %-*s", o->dbg_info()->dbg_id(), r, 9, Jdb_kobject::kobject_type(o));
130           break;
131         case Raw:
132         default:
133           printf("%16lx", Mword(o) | rights);
134           break;
135         }
136     }
137 }
138
139 PUBLIC
140 void
141 Jdb_obj_space::draw_entry(unsigned long row, unsigned long col)
142 {
143   if (col==0)
144     printf("%06lx ", index(row, 1));
145   else
146     print_entry(index(row, col));
147 }
148
149 PRIVATE
150 Address
151 Jdb_obj_space::index(unsigned long row, unsigned long col)
152 {
153   Mword e = (col-1) + (row * (cols()-1));
154   return _base + e;
155 }
156
157 PRIVATE
158 bool
159 Jdb_obj_space::handle_user_keys(int c, Kobject_iface *o)
160 {
161   if (!o)
162     return false;
163
164   bool handled = false;
165   for (Jdb_kobject::Handler_iter h = Jdb_kobject::module()->global_handlers.begin();
166        h != Jdb_kobject::module()->global_handlers.end(); ++h)
167     handled |= h->handle_key(o, c);
168
169   if (Jdb_kobject_handler *h = Jdb_kobject::module()->find_handler(o))
170     handled |= h->handle_key(o, c);
171
172   return handled;
173 }
174
175
176 PUBLIC
177 unsigned
178 Jdb_obj_space::key_pressed(int c, unsigned long &row, unsigned long &col)
179 {
180   switch (c)
181     {
182     default:
183       {
184         unsigned rights;
185         if (handle_user_keys(c, item(index(row, col), &rights)))
186           return Redraw;
187         return Nothing;
188       }
189
190     case KEY_CURSOR_HOME: // return to previous or go home
191       return Back;
192
193     case ' ':
194       ++_mode;
195       return Redraw;
196     }
197 }
198
199 PUBLIC
200 bool
201 Jdb_obj_space::handle_key(Kobject_common *o, int code)
202 {
203   if (code != 'o')
204     return false;
205
206   Space *t = Kobject::dcast<Task*>(o);
207   if (!t)
208     {
209       Thread *th = Kobject::dcast<Thread_object *>(o);
210       if (!th || !th->space())
211         return false;
212
213       t = th->space();
214     }
215
216   _task = t;
217   show(0,0);
218
219   return true;
220 }
221
222 static Jdb_obj_space jdb_obj_space INIT_PRIORITY(JDB_MODULE_INIT_PRIO);
223
224 // ------------------------------------------------------------------------
225 IMPLEMENTATION [obj_space_virt]:
226
227 PUBLIC
228 Kobject_iface *
229 Jdb_obj_space::item(Address entry, unsigned *rights)
230 {
231   Mword dummy;
232   Obj_space::Capability *c = _task->cap_virt(entry);
233   if (!c)
234     return 0;
235
236   Mword mapped = Jdb::peek((Mword*)c, _task, dummy);
237
238   if (!mapped)
239     return 0;
240
241   Kobject_iface *o = (Kobject_iface*)(dummy & ~3UL);
242   *rights = dummy & 3;
243
244   return o;
245 }
246
247 // ------------------------------------------------------------------------
248 IMPLEMENTATION [obj_space_phys]:
249 PUBLIC
250 Kobject_iface *
251 Jdb_obj_space::item(Address entry, unsigned *rights)
252 {
253   Obj_space::Capability *c = _task->get_cap(entry);
254
255   if (!c)
256     return 0;
257
258   Kobject_iface *o = c->obj();
259   *rights = c->rights();
260
261   return o;
262 }