]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/jdb/jdb_io_apic.cpp
9025c89fdadc5adb6e1885593c0b053776cf0612
[l4.git] / kernel / fiasco / src / jdb / jdb_io_apic.cpp
1 IMPLEMENTATION:
2
3 #include <cstdio>
4 #include "simpleio.h"
5
6 #include "apic.h"
7 #include "io_apic.h"
8 #include "jdb.h"
9 #include "jdb_module.h"
10 #include "jdb_screen.h"
11 #include "static_init.h"
12 #include "types.h"
13
14
15 /**
16  * Private 'exit' module.
17  * 
18  * This module handles the 'exit' or '^' command that
19  * makes a call to exit() and virtually reboots the system.
20  */
21 class Jdb_io_apic_module : public Jdb_module
22 {
23 public:
24   Jdb_io_apic_module() FIASCO_INIT;
25 };
26
27 static Jdb_io_apic_module jdb_io_apic_module INIT_PRIORITY(JDB_MODULE_INIT_PRIO);
28
29 PRIVATE static
30 void
31 Jdb_io_apic_module::print_lapic(unsigned cpu, void *)
32 {
33   printf("\nLocal APIC [%u, %08x]: tpr=%2x ppr=%2x\n", cpu, Apic::get_id(), Apic::tpr(),
34          Apic::reg_read(0xa0));
35   printf("  Running: tpr=%02x\n", Jdb::apic_tpr.cpu(cpu));
36
37   unsigned const regs[] = { 0x200, 0x100, 0x180 };
38   char const *const regn[] = { "IRR", "ISR", "TMR" };
39   for (unsigned r = 0; r < 3; ++r)
40     {
41       printf("  %s:", regn[r]);
42       for (int i = 3; i >= 0; --i)
43         {
44           unsigned long v = Apic::reg_read(regs[r] + i * 0x10);
45           printf(" %08lx", v);
46         }
47       puts("");
48     }
49 }
50
51 PRIVATE static
52 void
53 Jdb_io_apic_module::remote_print_lapic(unsigned cpu)
54 {
55   Jdb::remote_work(cpu, print_lapic, 0);
56 }
57
58 PUBLIC
59 Jdb_module::Action_code
60 Jdb_io_apic_module::action (int cmd, void *&, char const *&, int &)
61 {
62   if (cmd!=0)
63     return NOTHING;
64
65   if (!Io_apic::active())
66     {
67       printf("\nIO APIC not present!\n");
68       return NOTHING;
69     }
70   printf("\nState of IO APIC\n");
71   Io_apic::dump();
72
73   // print global LAPIC state
74   unsigned khz;
75   char apic_state[80];
76   int apic_disabled;
77   strcpy (apic_state, "N/A");
78   if ((apic_disabled = Apic::test_present_but_disabled()))
79     strcpy (apic_state, "disabled by BIOS");
80   if ((khz = Apic::get_frequency_khz()))
81     {
82       unsigned mhz = khz / 1000;
83       khz -= mhz * 1000;
84       snprintf(apic_state, sizeof(apic_state), "yes (%d.%03d MHz)"
85               "\n  local APIC spurious interrupts/bug/error: %d/%d/%d",
86               mhz, khz,
87               apic_spurious_interrupt_cnt,
88               apic_spurious_interrupt_bug_cnt,
89               apic_error_cnt);
90     }
91   printf("\nLocal APIC (general): %s"
92          "\nWatchdog: %s"
93          "\n",
94          apic_state,
95          Config::watchdog
96             ? "active"
97             : Apic::is_present()
98                ? "disabled"
99                : apic_disabled
100                   ? "not supported (Local APIC disabled)"
101                   : "not supported (no Local APIC)"
102       );
103   Jdb::foreach_cpu(&remote_print_lapic);
104
105   return NOTHING;
106 }
107
108 PUBLIC
109 int
110 Jdb_io_apic_module::num_cmds() const
111
112   return 1;
113 }
114
115 PUBLIC
116 Jdb_module::Cmd const *
117 Jdb_io_apic_module::cmds() const
118 {
119   static Cmd cs[] =
120     { { 0, "A", "apic", "", "apic\tdump state of IOAPIC", (void*)0 } };
121
122   return cs;
123 }
124
125 IMPLEMENT
126 Jdb_io_apic_module::Jdb_io_apic_module()
127   : Jdb_module("INFO")
128 {}