]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/jdb/ia32/jdb_kern_info-ia32-amd64.cpp
update
[l4.git] / kernel / fiasco / src / jdb / ia32 / jdb_kern_info-ia32-amd64.cpp
1 IMPLEMENTATION[ia32,amd64,ux]:
2
3 #include <cstdio>
4 #include <cstring>
5 #include "simpleio.h"
6
7 #include "config.h"
8 #include "cpu.h"
9 #include "gdt.h"
10 #include "idt.h"
11 #include "jdb_symbol.h"
12 #include "perf_cnt.h"
13 #include "pic.h"
14 #include "space.h"
15 #include "tss.h"
16
17
18 class Jdb_kern_info_idt : public Jdb_kern_info_module
19 {
20 };
21
22 static Jdb_kern_info_idt k_I INIT_PRIORITY(JDB_MODULE_INIT_PRIO+1);
23
24 PUBLIC
25 Jdb_kern_info_idt::Jdb_kern_info_idt()
26   : Jdb_kern_info_module('I', "Interrupt Descriptor Table (IDT)")
27 {
28   Jdb_kern_info::register_subcmd(this);
29 }
30
31 PUBLIC
32 void
33 Jdb_kern_info_idt::show()
34 {
35   Pseudo_descriptor idt_pseudo;
36   unsigned line = 0;
37
38   Idt::get (&idt_pseudo);
39
40   printf("idt base="L4_PTR_FMT"  limit=%04x (%04x bytes)\n",
41          idt_pseudo.base(),
42          (unsigned)((idt_pseudo.limit() + 1) / sizeof(Idt_entry)),
43          idt_pseudo.limit() + 1);
44   if (!Jdb_core::new_line(line))
45     return;
46
47   Idt_entry *ie = reinterpret_cast<Idt_entry*>(idt_pseudo.base());
48   for (unsigned i=0; i<(idt_pseudo.limit()+1)/sizeof(Idt_entry); i++)
49     {
50       printf("%3x: ",i);
51       ie[i].show();
52       if (!Jdb_core::new_line(line))
53         return;
54     }
55 }
56
57
58 //---------------------------------------------------------------------------
59 IMPLEMENTATION[ia32,amd64]:
60
61 #include "io.h"
62
63
64 class Jdb_kern_info_pic_state : public Jdb_kern_info_module
65 {
66 };
67
68 static Jdb_kern_info_pic_state k_p INIT_PRIORITY(JDB_MODULE_INIT_PRIO+1);
69
70 PUBLIC
71 Jdb_kern_info_pic_state::Jdb_kern_info_pic_state()
72   : Jdb_kern_info_module('p', "PIC ports")
73 {
74   Jdb_kern_info::register_subcmd(this);
75 }
76
77 void
78 Jdb_kern_info_pic_state::show()
79 {
80   int i;
81   static char const hex[] = "0123456789ABCDEF";
82           
83   // show important I/O ports
84   Io::out8_p(Pic::OCW_TEMPLATE | Pic::READ_NEXT_RD | Pic::READ_IS_ONRD, 
85              Pic::MASTER_ICW );
86   unsigned in_service = Io::in8(Pic::MASTER_ICW);
87   Io::out8_p(Pic::OCW_TEMPLATE | Pic::READ_NEXT_RD | Pic::READ_IR_ONRD,
88              Pic::MASTER_ICW);
89   unsigned requested = Io::in8(Pic::MASTER_ICW);
90   unsigned mask = Jdb::pic_status & 0x0ff;
91   printf("master PIC: in service:");
92   for (i=7; i>=0; i--)
93     putchar((in_service & (1<<i)) ? hex[i] : '-');
94   printf(", request:");
95   for (i=7; i>=0; i--)
96     putchar((requested & (1<<i)) ? hex[i] : '-');
97   printf(", mask:");
98   for (i=7; i>=0; i--)
99     putchar((mask & (1<<i)) ? hex[i] : '-');
100   putchar('\n');
101           
102   Io::out8_p( Pic::OCW_TEMPLATE | Pic::READ_NEXT_RD | Pic::READ_IS_ONRD, 
103               Pic::SLAVES_ICW);
104   in_service = Io::in8(Pic::SLAVES_ICW);
105   Io::out8_p( Pic::OCW_TEMPLATE | Pic::READ_NEXT_RD | Pic::READ_IR_ONRD, 
106               Pic::SLAVES_ICW);
107   requested = Io::in8(Pic::SLAVES_ICW);
108   mask = Jdb::pic_status >> 8;
109   printf(" slave PIC: in service:");
110   for (i=7; i>=0; i--)
111     putchar((in_service & (1<<i)) ? hex[i+8] : '-');
112   printf(", request:");
113   for (i=7; i>=0; i--)
114     putchar((requested & (1<<i)) ? hex[i+8] : '-');
115   printf(", mask:");
116   for (i=7; i>=0; i--)
117     putchar((mask & (1<<i)) ? hex[i+8] : '-');
118   putchar('\n');
119 }
120
121
122 class Jdb_kern_info_misc : public Jdb_kern_info_module
123 {
124 };
125
126 static Jdb_kern_info_misc k_i INIT_PRIORITY(JDB_MODULE_INIT_PRIO+1);
127
128 PUBLIC
129 Jdb_kern_info_misc::Jdb_kern_info_misc()
130   : Jdb_kern_info_module('i', "Miscellaneous info")
131 {
132   Jdb_kern_info::register_subcmd(this);
133 }
134
135 PUBLIC
136 void
137 Jdb_kern_info_misc::show()
138 {
139   printf ("clck: %08x.%08x\n",
140           (unsigned) (Kip::k()->clock >> 32),
141           (unsigned) (Kip::k()->clock));
142
143   show_pdir();
144
145   Pseudo_descriptor gdt_pseudo, idt_pseudo;
146   Gdt::get (&gdt_pseudo);
147   Idt::get (&idt_pseudo);
148   printf ("idt : base="L4_PTR_FMT"  limit=%04x\n"
149           "gdt : base="L4_PTR_FMT"  limit=%04x\n",
150           idt_pseudo.base(), (idt_pseudo.limit()+1)/8,
151           gdt_pseudo.base(), (gdt_pseudo.limit()+1)/8);
152
153   // print LDT
154   printf("ldt : %04x", Cpu::get_ldt());
155   if (Cpu::get_ldt() != 0)
156     {
157       Gdt_entry *e = Cpu::boot_cpu()->get_gdt()->entries() + (Cpu::boot_cpu()->get_ldt() >> 3);
158       printf(": "L4_PTR_FMT"-"L4_PTR_FMT,
159           e->base(), e->base()+ e->size());
160     }
161
162   // print TSS
163   printf("\n"
164          "tr  : %04x", Cpu::boot_cpu()->get_tr());
165   if(Cpu::get_tr() != 0)
166     {
167       Gdt_entry *e = Cpu::boot_cpu()->get_gdt()->entries() + (Cpu::boot_cpu()->get_tr() >> 3);
168       printf(": "L4_PTR_FMT"-"L4_PTR_FMT", iobitmap at "L4_PTR_FMT, 
169           e->base(), e->base()+ e->size(),
170           e->base() + (reinterpret_cast<Tss *>(e->base())->_io_bit_map_offset));
171     }
172   printf("\n"
173          "cr0 : "L4_PTR_FMT"\n"
174          "cr4 : "L4_PTR_FMT"\n",
175          Cpu::get_cr0(), Cpu::get_cr4());
176 }
177
178 class Jdb_kern_info_cpu : public Jdb_kern_info_module
179 {
180 };
181
182 static Jdb_kern_info_cpu k_c INIT_PRIORITY(JDB_MODULE_INIT_PRIO+1);
183
184 PUBLIC
185 Jdb_kern_info_cpu::Jdb_kern_info_cpu()
186   : Jdb_kern_info_module('c', "CPU features")
187 {
188   Jdb_kern_info::register_subcmd(this);
189 }
190
191 PUBLIC
192 void
193 Jdb_kern_info_cpu::show()
194 {
195   const char *perf_type = Perf_cnt::perf_type();
196   char cpu_mhz[32];
197   char time[32];
198   unsigned hz;
199   static char const * const scheduler_mode[] = { "PIT", "RTC", "APIC" };
200
201   cpu_mhz[0] = '\0';
202   if ((hz = Cpu::boot_cpu()->frequency()))
203     {
204       unsigned mhz = hz / 1000000;
205       hz -= mhz * 1000000;
206       unsigned khz = hz / 1000;
207       snprintf(cpu_mhz, sizeof(cpu_mhz), "%d.%03d MHz", mhz, khz);
208     }
209
210   printf ("CPU: %s %s (%s)\n",
211           Cpu::boot_cpu()->model_str(), cpu_mhz,
212           Config::found_vmware ? "vmware" : "native");
213   Cpu::boot_cpu()->show_cache_tlb_info("     ");
214   show_features();
215
216   if (Cpu::boot_cpu()->tsc())
217     {
218       Unsigned32 hour, min, sec, ns;
219       Cpu::boot_cpu()->tsc_to_s_and_ns(Cpu::rdtsc(), &sec, &ns);
220       hour = sec  / 3600;
221       sec -= hour * 3600;
222       min  = sec  / 60;
223       sec -= min  * 60;
224       snprintf(time, sizeof(time), "%02d:%02d:%02d.%06d", 
225                hour, min, sec, ns/1000);
226     }
227   else
228     strcpy(time, "not available");
229
230   printf("\nTimer interrupt source: %s (irq vector 0x%02x)"
231          "\nPerformance counters: %s"
232          "\nLast branch recording: %s"
233          "\nDebug store to memory: %s"
234          "\nTime stamp counter: %s"
235          "\n",
236          scheduler_mode[Config::scheduler_mode],
237          Config::scheduler_irq_vector,
238          perf_type ? perf_type : "no",
239          Cpu::boot_cpu()->lbr_type() != Cpu::Lbr_unsupported 
240             ? Cpu::boot_cpu()->lbr_type() == Cpu::Lbr_pentium_4 ? "P4" : "P6"
241             : "no",
242          Cpu::boot_cpu()->bts_type() != Cpu::Bts_unsupported
243             ? Cpu::boot_cpu()->bts_type() == Cpu::Bts_pentium_4 ? "P4" : "Pentium-M"
244             : "no",
245          time
246          );
247 }
248
249
250 class Jdb_kern_info_gdt : public Jdb_kern_info_module
251 {
252 private:
253   static unsigned line;
254 };
255
256 static Jdb_kern_info_gdt k_g INIT_PRIORITY(JDB_MODULE_INIT_PRIO+1);
257
258 unsigned Jdb_kern_info_gdt::line;
259
260 PUBLIC
261 Jdb_kern_info_gdt::Jdb_kern_info_gdt()
262   : Jdb_kern_info_module('g', "Global Descriptor Table (GDT)")
263 {
264   Jdb_kern_info::register_subcmd(this);
265 }
266
267 PRIVATE static
268 void
269 Jdb_kern_info_gdt::show_gdt(unsigned cpu)
270 {
271   Gdt *gdt = Cpu::cpus.cpu(cpu).get_gdt();
272   unsigned entries = Gdt::gdt_max / 8;
273
274   if (Config::Max_num_cpus > 1)
275     printf("CPU%d: GDT base="L4_PTR_FMT"  limit=%04x (%04x bytes)\n",
276            cpu, (Mword)gdt, entries, Gdt::gdt_max);
277   else
278     printf("GDT base="L4_PTR_FMT"  limit=%04x (%04x bytes)\n",
279            (Mword)gdt, entries, Gdt::gdt_max);
280
281   if (!Jdb_core::new_line(line))
282     return;
283
284   for (unsigned i = 0; i < entries; i++)
285     {
286       printf(" %02x: ", i * 8);
287       (*gdt)[i].show();
288       if (!Jdb_core::new_line(line))
289         return;
290     }
291 }
292
293 PUBLIC
294 void
295 Jdb_kern_info_gdt::show()
296 {
297   line = 0;
298   Jdb::foreach_cpu(&show_gdt);
299 }