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