1 IMPLEMENTATION[ia32,amd64,ux]:
11 #include "jdb_symbol.h"
18 class Jdb_kern_info_idt : public Jdb_kern_info_module
22 static Jdb_kern_info_idt k_I INIT_PRIORITY(JDB_MODULE_INIT_PRIO + 1);
25 Jdb_kern_info_idt::Jdb_kern_info_idt()
26 : Jdb_kern_info_module('I', "Interrupt Descriptor Table (IDT)")
28 Jdb_kern_info::register_subcmd(this);
33 Jdb_kern_info_idt::show()
35 Pseudo_descriptor idt_pseudo;
38 Idt::get (&idt_pseudo);
40 printf("idt base=" L4_PTR_FMT " limit=%04x (%04x bytes)\n",
42 (unsigned)((idt_pseudo.limit() + 1) / sizeof(Idt_entry)),
43 idt_pseudo.limit() + 1);
44 if (!Jdb_core::new_line(line))
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++)
52 if (!Jdb_core::new_line(line))
57 class Jdb_kern_info_test_tsc_scaler : public Jdb_kern_info_module
61 static Jdb_kern_info_test_tsc_scaler k_tts INIT_PRIORITY(JDB_MODULE_INIT_PRIO+1);
64 Jdb_kern_info_test_tsc_scaler::Jdb_kern_info_test_tsc_scaler()
65 : Jdb_kern_info_module('T', "Test TSC scaler")
67 Jdb_kern_info::register_subcmd(this);
72 Jdb_kern_info_test_tsc_scaler::show()
74 while (Kconsole::console()->getchar(false) == -1)
77 t = Cpu::boot_cpu()->ns_to_tsc(Cpu::boot_cpu()->tsc_to_ns(Cpu::rdtsc()));
78 printf("Diff (press any key to stop): %lld\n", Cpu::rdtsc() - t);
82 //---------------------------------------------------------------------------
83 IMPLEMENTATION[ia32,amd64]:
87 class Jdb_kern_info_pic_state : public Jdb_kern_info_module
91 static Jdb_kern_info_pic_state k_p INIT_PRIORITY(JDB_MODULE_INIT_PRIO+1);
94 Jdb_kern_info_pic_state::Jdb_kern_info_pic_state()
95 : Jdb_kern_info_module('p', "PIC ports")
97 Jdb_kern_info::register_subcmd(this);
101 Jdb_kern_info_pic_state::show()
104 static char const hex[] = "0123456789ABCDEF";
106 // show important I/O ports
107 Io::out8_p(Pic::OCW_TEMPLATE | Pic::READ_NEXT_RD | Pic::READ_IS_ONRD,
109 unsigned in_service = Io::in8(Pic::MASTER_ICW);
110 Io::out8_p(Pic::OCW_TEMPLATE | Pic::READ_NEXT_RD | Pic::READ_IR_ONRD,
112 unsigned requested = Io::in8(Pic::MASTER_ICW);
113 unsigned mask = Jdb::pic_status & 0x0ff;
114 printf("master PIC: in service:");
116 putchar((in_service & (1<<i)) ? hex[i] : '-');
117 printf(", request:");
119 putchar((requested & (1<<i)) ? hex[i] : '-');
122 putchar((mask & (1<<i)) ? hex[i] : '-');
125 Io::out8_p( Pic::OCW_TEMPLATE | Pic::READ_NEXT_RD | Pic::READ_IS_ONRD,
127 in_service = Io::in8(Pic::SLAVES_ICW);
128 Io::out8_p( Pic::OCW_TEMPLATE | Pic::READ_NEXT_RD | Pic::READ_IR_ONRD,
130 requested = Io::in8(Pic::SLAVES_ICW);
131 mask = Jdb::pic_status >> 8;
132 printf(" slave PIC: in service:");
134 putchar((in_service & (1<<i)) ? hex[i+8] : '-');
135 printf(", request:");
137 putchar((requested & (1<<i)) ? hex[i+8] : '-');
140 putchar((mask & (1<<i)) ? hex[i+8] : '-');
145 class Jdb_kern_info_misc : public Jdb_kern_info_module
149 static Jdb_kern_info_misc k_i INIT_PRIORITY(JDB_MODULE_INIT_PRIO + 1);
152 Jdb_kern_info_misc::Jdb_kern_info_misc()
153 : Jdb_kern_info_module('i', "Miscellaneous info")
155 Jdb_kern_info::register_subcmd(this);
160 Jdb_kern_info_misc::show()
162 printf ("clck: %08x.%08x\n",
163 (unsigned) (Kip::k()->clock >> 32),
164 (unsigned) (Kip::k()->clock));
168 Pseudo_descriptor gdt_pseudo, idt_pseudo;
169 Gdt::get (&gdt_pseudo);
170 Idt::get (&idt_pseudo);
171 printf ("idt : base=" L4_PTR_FMT " limit=%04x\n"
172 "gdt : base=" L4_PTR_FMT " limit=%04x\n",
173 idt_pseudo.base(), (idt_pseudo.limit()+1)/8,
174 gdt_pseudo.base(), (gdt_pseudo.limit()+1)/8);
177 printf("ldt : %04x", Cpu::get_ldt());
178 if (Cpu::get_ldt() != 0)
180 Gdt_entry *e = Cpu::boot_cpu()->get_gdt()->entries() + (Cpu::boot_cpu()->get_ldt() >> 3);
181 printf(": " L4_PTR_FMT "-" L4_PTR_FMT,
182 e->base(), e->base()+ e->size());
187 "tr : %04x", Cpu::boot_cpu()->get_tr());
188 if(Cpu::get_tr() != 0)
190 Gdt_entry *e = Cpu::boot_cpu()->get_gdt()->entries() + (Cpu::boot_cpu()->get_tr() >> 3);
191 printf(": " L4_PTR_FMT "-" L4_PTR_FMT ", iobitmap at " L4_PTR_FMT,
192 e->base(), e->base()+ e->size(),
193 e->base() + (reinterpret_cast<Tss *>(e->base())->_io_bit_map_offset));
196 "cr0 : " L4_PTR_FMT "\n"
197 "cr4 : " L4_PTR_FMT "\n",
198 Cpu::get_cr0(), Cpu::get_cr4());
201 class Jdb_kern_info_cpu : public Jdb_kern_info_module
205 static Jdb_kern_info_cpu k_c INIT_PRIORITY(JDB_MODULE_INIT_PRIO + 1);
208 Jdb_kern_info_cpu::Jdb_kern_info_cpu()
209 : Jdb_kern_info_module('c', "CPU features")
211 Jdb_kern_info::register_subcmd(this);
216 Jdb_kern_info_cpu::show()
218 const char *perf_type = Perf_cnt::perf_type();
222 static char const * const scheduler_mode[]
223 = { "PIT", "RTC", "APIC", "HPET" };
226 if ((hz = Cpu::boot_cpu()->frequency()))
228 unsigned mhz = hz / 1000000;
230 unsigned khz = hz / 1000;
231 snprintf(cpu_mhz, sizeof(cpu_mhz), "%d.%03d MHz", mhz, khz);
234 printf ("CPU: %s %s (%s)\n",
235 Cpu::boot_cpu()->model_str(), cpu_mhz,
236 Config::found_vmware ? "vmware" : "native");
237 Cpu::boot_cpu()->show_cache_tlb_info(" ");
240 if (Cpu::boot_cpu()->tsc())
242 Unsigned32 hour, min, sec, ns;
243 Cpu::boot_cpu()->tsc_to_s_and_ns(Cpu::rdtsc(), &sec, &ns);
248 snprintf(time, sizeof(time), "%02d:%02d:%02d.%06d",
249 hour, min, sec, ns/1000);
252 strcpy(time, "not available");
254 printf("\nTimer interrupt source: %s (irq vector 0x%02x)"
255 "\nPerformance counters: %s"
256 "\nLast branch recording: %s"
257 "\nDebug store to memory: %s"
258 "\nTime stamp counter: %s"
260 scheduler_mode[Config::Scheduler_mode],
261 Config::scheduler_irq_vector,
262 perf_type ? perf_type : "no",
263 Cpu::boot_cpu()->lbr_type() != Cpu::Lbr_unsupported
264 ? Cpu::boot_cpu()->lbr_type() == Cpu::Lbr_pentium_4 ? "P4" : "P6"
266 Cpu::boot_cpu()->bts_type() != Cpu::Bts_unsupported
267 ? Cpu::boot_cpu()->bts_type() == Cpu::Bts_pentium_4 ? "P4" : "Pentium-M"
273 class Jdb_kern_info_gdt : public Jdb_kern_info_module
276 static unsigned line;
279 static Jdb_kern_info_gdt k_g INIT_PRIORITY(JDB_MODULE_INIT_PRIO + 1);
281 unsigned Jdb_kern_info_gdt::line;
284 Jdb_kern_info_gdt::Jdb_kern_info_gdt()
285 : Jdb_kern_info_module('g', "Global Descriptor Table (GDT)")
287 Jdb_kern_info::register_subcmd(this);
292 Jdb_kern_info_gdt::show_gdt(unsigned cpu)
294 Gdt *gdt = Cpu::cpus.cpu(cpu).get_gdt();
295 unsigned entries = Gdt::gdt_max / 8;
297 if (Config::Max_num_cpus > 1)
298 printf("CPU%d: GDT base=" L4_PTR_FMT " limit=%04x (%04x bytes)\n",
299 cpu, (Mword)gdt, entries, Gdt::gdt_max);
301 printf("GDT base=" L4_PTR_FMT " limit=%04x (%04x bytes)\n",
302 (Mword)gdt, entries, Gdt::gdt_max);
304 if (!Jdb_core::new_line(line))
307 for (unsigned i = 0; i < entries; i++)
309 printf(" %02x: ", i * 8);
311 if (!Jdb_core::new_line(line))
318 Jdb_kern_info_gdt::show()
321 Jdb::foreach_cpu(&show_gdt);
324 // ------------------------------------------------------------------------
325 IMPLEMENTATION [(ia32 || amd64) && hpet_timer]:
329 class Jdb_kern_info_hpet_smm : public Jdb_kern_info_module
332 static Jdb_kern_info_hpet_smm ki_smm INIT_PRIORITY(JDB_MODULE_INIT_PRIO + 1);
335 Jdb_kern_info_hpet_smm::Jdb_kern_info_hpet_smm()
336 : Jdb_kern_info_module('S', "SMM loop using HPET")
338 Jdb_kern_info::register_subcmd(this);
343 Jdb_kern_info_hpet_smm::show()
345 const unsigned config_spin_loops = 10000;
346 const unsigned config_hist_loops = 60;
348 Mword counter_good = 0;
350 Mword hist_loops = config_hist_loops;
352 printf("HPET SMM Check: Press key to stop.\n");
353 printf("HPET SMM Check Loop testing (loops=%d)\n", config_spin_loops);
355 Hpet::hpet()->dump();
356 Hpet::hpet()->enable();
359 Unsigned64 x1 = Hpet::hpet()->counter_val;
361 int i = config_spin_loops;
363 asm volatile("" : : : "memory");
365 Unsigned64 diff = Hpet::hpet()->counter_val - x1;
374 delta = (histsum + histsum / 9) / config_hist_loops;
375 printf("HPET SMM Check threshold=%dhpet-clks %lldus\n",
377 (delta * Hpet::hpet()->counter_clk_period()) / 1000000000ULL);
382 if (diff > delta && diff < (~0UL - delta * 2))
384 printf("%lld %lldus (before %ld good iterations)\n", diff,
385 (diff * Hpet::hpet()->counter_clk_period()) / 1000000000ULL,
388 if (Kconsole::console()->getchar(false) != -1)
394 if (counter_good % 30000 == 2)
395 if (Kconsole::console()->getchar(false) != -1)