]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/jdb/ia32/jdb_iomap.cpp
Update
[l4.git] / kernel / fiasco / src / jdb / ia32 / jdb_iomap.cpp
1 IMPLEMENTATION[io]:
2
3 #include <cstdio>
4 #include <cctype>
5
6 #include "config.h"
7 #include "jdb.h"
8 #include "jdb_module.h"
9 #include "kmem.h"
10 #include "mem_layout.h"
11 #include "simpleio.h"
12 #include "space.h"
13 #include "static_init.h"
14 #include "task.h"
15
16 class Jdb_iomap : public Jdb_module
17 {
18 public:
19   Jdb_iomap() FIASCO_INIT;
20 private:
21   static char     first_char;
22   static Space    *space;
23   Address         task;
24 };
25
26 char     Jdb_iomap::first_char;
27 Space   *Jdb_iomap::space;
28
29
30 static void
31 Jdb_iomap::show()
32 {
33   // base addresses of the two IO bitmap pages
34   Address bitmap_1, bitmap_2;
35   bitmap_1 = space->virt_to_phys(Mem_layout::Io_bitmap);
36   bitmap_2 = space->virt_to_phys(Mem_layout::Io_bitmap + Config::PAGE_SIZE);
37
38   Jdb::clear_screen();
39
40   printf("\nIO bitmap for space %p ", space);
41   if(bitmap_1 == ~0UL && bitmap_2 == ~0UL)
42     { // no memory mapped for the IO bitmap
43       puts("not mapped");
44       return;
45     }
46   else
47     {
48       putstr("mapped to [");
49       if (bitmap_1 != ~0UL)
50         printf(L4_PTR_FMT " ", (Address)Kmem::phys_to_virt(bitmap_1));
51       else
52         putstr("   --    ");
53
54       if (bitmap_2 != ~0UL)
55         printf("/ " L4_PTR_FMT, (Address)Kmem::phys_to_virt(bitmap_2));
56       else
57         putstr("/    --   ");
58     }
59
60   puts("]\n\nPorts assigned:");
61
62   bool mapped = false, any_mapped = false;
63   unsigned count=0;
64
65   for(unsigned i = 0; i < Mem_layout::Io_port_max; i++ )
66     {
67       if (space->io_lookup(i) != mapped)
68         {
69           if(! mapped)
70             {
71               mapped = any_mapped = true;
72               printf("%04x-", i);
73             }
74           else
75             {
76               mapped = false;
77               printf("%04x ", i-1);
78             }
79         }
80       if(mapped)
81         count++;
82     }
83   if(mapped)
84     printf("%04x ", (unsigned)Mem_layout::Io_port_max -1);
85
86   if (!any_mapped)
87     putstr("<none>");
88
89   printf("\n\nPort counter: %lu ", space->get_io_counter() );
90   if(count == space->get_io_counter())
91     puts("(correct)");
92   else
93     printf("%sshould be %u\033[m\n", Jdb::esc_emph, count);
94 }
95
96 PUBLIC
97 Jdb_module::Action_code
98 Jdb_iomap::action(int cmd, void *&args, char const *&fmt, int &next_char)
99 {
100   if (cmd == 0)
101     {
102       if (args == &first_char)
103         {
104           if (isxdigit(first_char))
105             {
106               fmt       = "%q";
107               args      = &task;
108               next_char = first_char;
109               return EXTRA_INPUT_WITH_NEXTCHAR;
110             }
111           else
112             task = 0;
113         }
114       else if (args != &task)
115         return NOTHING;
116
117       if (!task)
118         return NOTHING;
119
120       space = cxx::dyn_cast<Task*>(reinterpret_cast<Kobject*>(task));
121       if (!space)
122         return NOTHING;
123
124       show();
125     }
126
127   return NOTHING;
128 }
129
130 PUBLIC
131 Jdb_module::Cmd const *
132 Jdb_iomap::cmds() const
133 {
134   static Cmd cs[] =
135     {
136         { 0, "r", "iomap", "%C",
137           "r[<taskno>]\tdisplay IO bitmap of current/given task",
138           &first_char },
139     };
140   return cs;
141 }
142
143 PUBLIC
144 int
145 Jdb_iomap::num_cmds() const
146 {
147   return 1;
148 }
149
150 IMPLEMENT
151 Jdb_iomap::Jdb_iomap()
152   : Jdb_module("INFO")
153 {}
154
155 static Jdb_iomap jdb_iomap INIT_PRIORITY(JDB_MODULE_INIT_PRIO);
156