7 #include "jdb_module.h"
8 #include "jdb_screen.h"
9 #include "kernel_console.h"
10 #include "static_init.h"
20 * This module handles some commands that
21 * change Jdb prompt and screen settings.
23 class Jdb_pcm : public Jdb_module
26 Jdb_pcm() FIASCO_INIT;
29 static char prompt_color;
30 static char direct_enable;
31 static int screen_height;
32 static int screen_width;
36 char Jdb_pcm::prompt_color;
37 char Jdb_pcm::direct_enable;
38 int Jdb_pcm::screen_height;
39 int Jdb_pcm::screen_width;
41 static Jdb_pcm jdb_pcm INIT_PRIORITY(JDB_MODULE_INIT_PRIO);
45 Jdb_pcm::get_coords(Console *cons, unsigned &x, unsigned &y)
47 cons->write("\033[6n", 4);
49 if (!wait_for_escape(cons))
52 if (cons->getchar(true) != '[')
57 int c = cons->getchar(true);
60 if (c < '0' || c > '9')
66 int c = cons->getchar(true);
69 if (c < '0' || c > '9')
78 Jdb_pcm::detect_screensize()
80 unsigned x, y, max_x, max_y;
84 if (!(uart = Kconsole::console()->find_console(Console::UART)))
87 while (uart->getchar(false) != -1)
89 if (!get_coords(uart, x, y))
91 // set scroll region to the max + set cursor to the max
92 uart->write("\033[1;199r\033[199;199H", 18);
93 if (!get_coords(uart, max_x, max_y))
95 Jdb_screen::set_width(max_x);
96 Jdb_screen::set_height(max_y);
97 // adapt scroll region, restore cursor
98 snprintf(str, sizeof(str), "\033[1;%ur\033[%u;%uH", max_y, y, x);
99 uart->write(str, strlen(str));
103 Jdb_module::Action_code
104 Jdb_pcm::action(int cmd, void *&args, char const *&fmt, int &)
114 fmt = " promptcolor=%c";
115 args = &prompt_color;
119 args = &direct_enable;
122 fmt = " screenheight=%d";
123 args = &screen_height;
126 fmt = " screenwidth=%d";
127 args = &screen_width;
134 printf("\nConnected consoles:\n");
135 Kconsole::console()->list_consoles();
138 printf("\nScreen dimensions: %dx%d Cols: %ld\n",
139 Jdb_screen::width(), Jdb_screen::height(),
146 else if (args == &screen_height)
149 if (24 < screen_height && screen_height < 100)
150 Jdb_screen::set_height(screen_height);
152 else if (args == &screen_width)
155 if (80 < screen_width && screen_width < 600)
156 Jdb_screen::set_width(screen_width);
158 else if (args == &prompt_color)
160 if (!Jdb::set_prompt_color(prompt_color) )
162 putchar(prompt_color);
163 puts(" - color expected (lLrRgGbByYmMcCwW)!");
166 else if (args == &direct_enable)
168 printf(" Direct console %s\n",
169 direct_enable == '+' ? "enabled" : "disabled");
170 Jdb_screen::enable_direct(direct_enable == '+');
171 if (direct_enable == '+')
172 Kconsole::console()->change_state(Console::DIRECT, 0,
173 ~0U, Console::OUTENABLED);
175 Kconsole::console()->change_state(Console::DIRECT, 0,
176 ~Console::OUTENABLED, 0);
183 int Jdb_pcm::num_cmds() const
189 Jdb_module::Cmd const * Jdb_pcm::cmds() const
193 { 0, "J", "Jdb options", "%c",
194 "Jc<color>\tset the Jdb prompt color, <color> must be:\n"
195 "\tnN: noir(black), rR: red, gG: green, bB: blue,\n"
196 "\tyY: yellow, mM: magenta, cC: cyan, wW: white;\n"
197 "\tthe capital letters are for bold text.\n"
198 "Jd{+|-}\ton/off Jdb output to VGA/Hercules console\n"
199 "Jh\tset Jdb screen height\n"
200 "Jw\tset Jdb screen width\n"
201 "JS\tdetect screen size using ESCape sequence ESC [ 6 n\n"
202 "Ji\tshow screen information\n"
203 "Jo\tlist attached consoles",
212 : Jdb_module("GENERAL")
216 IMPLEMENTATION[ia32,ux,amd64,ppc32]:
222 Jdb_pcm::wait_for_escape(Console *cons)
224 Unsigned64 to = Cpu::boot_cpu()->ns_to_tsc (Cpu::boot_cpu()->tsc_to_ns (Cpu::rdtsc()) + 200000000);
226 // This is just a sanity check to ensure that a tool like minicom is attached
227 // at the other end of the serial line and this tools responds to the magical
231 int c = cons->getchar(false);
234 if (c != -1 || Cpu::rdtsc() > to)
243 #include "processor.h"
247 Jdb_pcm::wait_for_escape(Console *cons)
249 for (Mword cnt=100000; ; cnt--)
251 int c = cons->getchar(false);