| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761 |
- /* Terminal: prompt, datetime (top right), blinking cursor, echo loop, command dispatch.
- Commands are spawned as separate processes for preemptive multitasking. */
- #include "io.h"
- #include "fbtext.h"
- #include "idle.h"
- #include "kexec.h"
- #include "mouse.h"
- #include "process.h"
- #include "rtc.h"
- #include "terminal.h"
- #include "timer.h"
- #include "version.h"
- #include "vga.h"
- extern void program_hello_main(void);
- extern void program_reboot_main(void);
- extern void program_poweroff_main(void);
- extern void program_ls_main(void);
- extern void program_cat_main(const char *filename);
- extern void program_run_main(const char *filename);
- extern void program_clock_main(void);
- extern void program_colors_main(void);
- extern void program_display_main(void);
- extern void program_cpuinfo_main(void);
- extern void program_mouseinfo_main(void);
- extern void program_power_main(const char *args);
- extern void program_serial_loop_main(const char *arg);
- extern void program_serial_recv_main(const char *arg);
- extern void program_run_serial_main(const char *arg);
- extern void disk_set_drive(unsigned int drive);
- extern unsigned int disk_get_drive(void);
- #define DATETIME_MS 1000
- #define LINE_MAX 64
- #define HISTORY_SIZE 32
- static unsigned int last_datetime_tick;
- static char datetime_buf[IO_DATETIME_LEN + 1];
- static char history[HISTORY_SIZE][LINE_MAX];
- static unsigned int history_count;
- static unsigned int history_next;
- static int cursor_visible;
- static unsigned int last_cursor_tick;
- static void redraw_datetime(void)
- {
- rtc_read_datetime(datetime_buf);
- {
- unsigned int i;
- for (i = 0; i < IO_DATETIME_LEN && datetime_buf[i]; i++)
- io_vga_write(IO_DATETIME_POS + i,
- (unsigned short)((0x0A << 8) | (unsigned char)datetime_buf[i]));
- }
- }
- static void update_datetime(void)
- {
- unsigned int t = get_ticks_ms();
- if (t - last_datetime_tick >= DATETIME_MS) {
- last_datetime_tick = t;
- redraw_datetime();
- }
- }
- static void update_cursor_blink(void)
- {
- unsigned int t = get_ticks_ms();
- if (t - last_cursor_tick >= CURSOR_MS) {
- last_cursor_tick = t;
- cursor_visible = !cursor_visible;
- }
- if (cursor_visible)
- io_cursor_show_block();
- else
- io_cursor_hide_block();
- }
- static const char banner[] __attribute__((section(".text"))) = OS_NAME " v" OS_VERSION;
- #define BANNER_LEN 14
- static const char prompt[] __attribute__((section(".text"))) = "\n> ";
- static const char prompt_first[] __attribute__((section(".text"))) = "> ";
- /* Draw row 0: banner left, datetime right. Call when terminal is active. */
- static void draw_header_row(void)
- {
- unsigned int i;
- for (i = 0; i < BANNER_LEN && banner[i]; i++)
- io_vga_write(i, (unsigned short)((0x0A << 8) | (unsigned char)banner[i]));
- for (; i < IO_DATETIME_POS; i++)
- io_vga_write(i, (unsigned short)(0x0A << 8));
- redraw_datetime();
- fbtext_draw_rainbow_separator();
- }
- static int is_cmd_hello(const char *line, unsigned int line_len)
- {
- unsigned int i = 0;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i + 5 > line_len)
- return 0;
- if (line[i] != 'h' || line[i+1] != 'e' || line[i+2] != 'l' || line[i+3] != 'l' || line[i+4] != 'o')
- return 0;
- i += 5;
- while (i < line_len && line[i] == ' ')
- i++;
- return (i == line_len);
- }
- static int is_cmd_reboot(const char *line, unsigned int line_len)
- {
- unsigned int i = 0;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i + 6 > line_len)
- return 0;
- if (line[i] != 'r' || line[i+1] != 'e' || line[i+2] != 'b' || line[i+3] != 'o' || line[i+4] != 'o' || line[i+5] != 't')
- return 0;
- i += 6;
- while (i < line_len && line[i] == ' ')
- i++;
- return (i == line_len);
- }
- static int is_cmd_poweroff(const char *line, unsigned int line_len)
- {
- unsigned int i = 0;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i + 8 > line_len)
- return 0;
- if (line[i] != 'p' || line[i+1] != 'o' || line[i+2] != 'w' || line[i+3] != 'e' ||
- line[i+4] != 'r' || line[i+5] != 'o' || line[i+6] != 'f' || line[i+7] != 'f')
- return 0;
- i += 8;
- while (i < line_len && line[i] == ' ')
- i++;
- return (i == line_len);
- }
- static int is_cmd_ls(const char *line, unsigned int line_len)
- {
- unsigned int i = 0;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i + 2 > line_len)
- return 0;
- if (line[i] != 'l' || line[i+1] != 's')
- return 0;
- i += 2;
- while (i < line_len && line[i] == ' ')
- i++;
- return (i == line_len);
- }
- static int is_cmd_clock(const char *line, unsigned int line_len)
- {
- unsigned int i = 0;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i + 5 > line_len)
- return 0;
- if (line[i] != 'c' || line[i+1] != 'l' || line[i+2] != 'o' ||
- line[i+3] != 'c' || line[i+4] != 'k')
- return 0;
- i += 5;
- while (i < line_len && line[i] == ' ')
- i++;
- return (i == line_len);
- }
- static int is_cmd_colors(const char *line, unsigned int line_len)
- {
- unsigned int i = 0;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i + 6 > line_len)
- return 0;
- if (line[i] != 'c' || line[i+1] != 'o' || line[i+2] != 'l' ||
- line[i+3] != 'o' || line[i+4] != 'r' || line[i+5] != 's')
- return 0;
- i += 6;
- while (i < line_len && line[i] == ' ')
- i++;
- return (i == line_len);
- }
- static int is_cmd_display(const char *line, unsigned int line_len)
- {
- unsigned int i = 0;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i + 7 > line_len)
- return 0;
- if (line[i] != 'd' || line[i+1] != 'i' || line[i+2] != 's' || line[i+3] != 'p' ||
- line[i+4] != 'l' || line[i+5] != 'a' || line[i+6] != 'y')
- return 0;
- i += 7;
- while (i < line_len && line[i] == ' ')
- i++;
- return (i == line_len);
- }
- static int is_cmd_cpuinfo(const char *line, unsigned int line_len)
- {
- unsigned int i = 0;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i + 7 > line_len)
- return 0;
- if (line[i] != 'c' || line[i+1] != 'p' || line[i+2] != 'u' || line[i+3] != 'i' ||
- line[i+4] != 'n' || line[i+5] != 'f' || line[i+6] != 'o')
- return 0;
- i += 7;
- while (i < line_len && line[i] == ' ')
- i++;
- return (i == line_len);
- }
- static int is_cmd_mouseinfo(const char *line, unsigned int line_len)
- {
- unsigned int i = 0;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i + 9 > line_len)
- return 0;
- if (line[i] != 'm' || line[i+1] != 'o' || line[i+2] != 'u' ||
- line[i+3] != 's' || line[i+4] != 'e' || line[i+5] != 'i' ||
- line[i+6] != 'n' || line[i+7] != 'f' || line[i+8] != 'o')
- return 0;
- i += 9;
- while (i < line_len && line[i] == ' ')
- i++;
- return (i == line_len);
- }
- static int is_cmd_space(const char *line, unsigned int line_len)
- {
- unsigned int i = 0;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i + 5 > line_len)
- return 0;
- if (line[i] != 's' || line[i+1] != 'p' || line[i+2] != 'a' ||
- line[i+3] != 'c' || line[i+4] != 'e')
- return 0;
- i += 5;
- while (i < line_len && line[i] == ' ')
- i++;
- return (i == line_len);
- }
- #define CAT_FNAME_MAX 64
- static int is_cmd_cat(const char *line, unsigned int line_len, char *filename_buf, unsigned int buf_size)
- {
- unsigned int i = 0, j;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i + 3 > line_len)
- return 0;
- if (line[i] != 'c' || line[i+1] != 'a' || line[i+2] != 't')
- return 0;
- i += 3;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i >= line_len)
- return 0;
- j = 0;
- while (i < line_len && line[i] != ' ' && j < buf_size - 1)
- filename_buf[j++] = line[i++];
- filename_buf[j] = '\0';
- return (j > 0);
- }
- static int is_cmd_run(const char *line, unsigned int line_len, char *filename_buf, unsigned int buf_size)
- {
- unsigned int i = 0, j;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i + 3 > line_len)
- return 0;
- if (line[i] != 'r' || line[i+1] != 'u' || line[i+2] != 'n')
- return 0;
- i += 3;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i >= line_len)
- return 0;
- j = 0;
- while (i < line_len && line[i] != ' ' && j < buf_size - 1)
- filename_buf[j++] = line[i++];
- filename_buf[j] = '\0';
- return (j > 0);
- }
- static int is_cmd_drive(const char *line, unsigned int line_len, unsigned int *drive_num)
- {
- unsigned int i = 0;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i + 5 > line_len)
- return 0;
- if (line[i] != 'd' || line[i+1] != 'r' || line[i+2] != 'i' || line[i+3] != 'v' || line[i+4] != 'e')
- return 0;
- i += 5;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i >= line_len || line[i] < '0' || line[i] > '1')
- return 0;
- *drive_num = (unsigned int)(line[i] - '0');
- i++;
- while (i < line_len && line[i] == ' ')
- i++;
- return (i == line_len);
- }
- static int is_cmd_help(const char *line, unsigned int line_len)
- {
- unsigned int i = 0;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i + 4 > line_len)
- return 0;
- if (line[i] != 'h' || line[i+1] != 'e' || line[i+2] != 'l' || line[i+3] != 'p')
- return 0;
- i += 4;
- while (i < line_len && line[i] == ' ')
- i++;
- return (i == line_len);
- }
- static int is_cmd_clear(const char *line, unsigned int line_len)
- {
- unsigned int i = 0;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i + 5 > line_len)
- return 0;
- if (line[i] != 'c' || line[i+1] != 'l' || line[i+2] != 'e' ||
- line[i+3] != 'a' || line[i+4] != 'r')
- return 0;
- i += 5;
- while (i < line_len && line[i] == ' ')
- i++;
- return (i == line_len);
- }
- static int is_cmd_ps(const char *line, unsigned int line_len)
- {
- unsigned int i = 0;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i + 2 > line_len)
- return 0;
- if (line[i] != 'p' || line[i+1] != 's')
- return 0;
- i += 2;
- while (i < line_len && line[i] == ' ')
- i++;
- return (i == line_len);
- }
- static int is_cmd_kill(const char *line, unsigned int line_len, unsigned int *pid_out)
- {
- unsigned int i = 0, num = 0;
- int has_digit = 0;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i + 4 > line_len)
- return 0;
- if (line[i] != 'k' || line[i+1] != 'i' || line[i+2] != 'l' || line[i+3] != 'l')
- return 0;
- i += 4;
- while (i < line_len && line[i] == ' ')
- i++;
- while (i < line_len && line[i] >= '0' && line[i] <= '9') {
- num = num * 10 + (unsigned int)(line[i] - '0');
- has_digit = 1;
- i++;
- }
- if (!has_digit)
- return 0;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i != line_len)
- return 0;
- *pid_out = num;
- return 1;
- }
- static int is_cmd_kexec(const char *line, unsigned int line_len)
- {
- unsigned int i = 0;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i + 5 > line_len)
- return 0;
- if (line[i] != 'k' || line[i+1] != 'e' || line[i+2] != 'x' || line[i+3] != 'e' || line[i+4] != 'c')
- return 0;
- i += 5;
- while (i < line_len && line[i] == ' ')
- i++;
- return (i == line_len);
- }
- static int is_cmd_serial(const char *line, unsigned int line_len, char *arg_buf, unsigned int buf_size)
- {
- unsigned int i = 0, j = 0;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i + 6 > line_len)
- return 0;
- if (line[i] != 's' || line[i+1] != 'e' || line[i+2] != 'r' ||
- line[i+3] != 'i' || line[i+4] != 'a' || line[i+5] != 'l')
- return 0;
- i += 6;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i >= line_len) {
- if (buf_size > 0)
- arg_buf[0] = '\0';
- return 1;
- }
- while (i < line_len && j + 1 < buf_size)
- arg_buf[j++] = line[i++];
- while (j > 0 && arg_buf[j - 1] == ' ')
- j--;
- arg_buf[j] = '\0';
- while (i < line_len && line[i] == ' ')
- i++;
- return (i == line_len);
- }
- #define POWER_ARGS_MAX 32
- static int is_cmd_power(const char *line, unsigned int line_len, char *args_buf, unsigned int buf_size)
- {
- unsigned int i = 0, j = 0;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i + 5 > line_len)
- return 0;
- if (line[i] != 'p' || line[i+1] != 'o' || line[i+2] != 'w' || line[i+3] != 'e' || line[i+4] != 'r')
- return 0;
- i += 5;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i == line_len) {
- if (buf_size > 0)
- args_buf[0] = '\0';
- return 1;
- }
- while (i < line_len && j + 1 < buf_size)
- args_buf[j++] = line[i++];
- while (j > 0 && args_buf[j - 1] == ' ')
- j--;
- args_buf[j] = '\0';
- while (i < line_len && line[i] == ' ')
- i++;
- return (i == line_len);
- }
- /* Redraw line from index `from` to end, clear one cell after, set cursor to line_pos. */
- static void redraw_line_from(const char *line, unsigned int line_len,
- unsigned int line_pos, unsigned int line_start, unsigned int from)
- {
- unsigned int i;
- io_set_cursor(line_start + from);
- for (i = from; i < line_len; i++)
- io_putchar(line[i]);
- io_putchar(' ');
- io_set_cursor(line_start + line_pos);
- }
- /* Redraw entire line and clear through clear_through (so leftover chars are erased). */
- static void redraw_line_clear(const char *line, unsigned int line_len,
- unsigned int line_pos, unsigned int line_start, unsigned int clear_through)
- {
- unsigned int i;
- io_set_cursor(line_start);
- for (i = 0; i < line_len; i++)
- io_putchar(line[i]);
- for (i = line_len; i <= clear_through; i++)
- io_putchar(' ');
- io_set_cursor(line_start + line_pos);
- }
- /* Copy history entry (1 = newest) into line, set line_len/line_pos, redraw from start. */
- static void history_load_into_line(char *line, unsigned int *line_len, unsigned int *line_pos,
- unsigned int line_start, unsigned int browse)
- {
- unsigned int slot, len, old_len;
- const char *src;
- if (browse < 1 || browse > history_count)
- return;
- old_len = *line_len;
- slot = (history_next + HISTORY_SIZE - browse) % HISTORY_SIZE;
- src = history[slot];
- for (len = 0; len < LINE_MAX - 1 && src[len]; len++)
- line[len] = src[len];
- line[len] = '\0';
- *line_len = len;
- *line_pos = len;
- redraw_line_clear(line, len, len, line_start, old_len > len ? old_len : len);
- }
- /* Push current line to history if non-empty (and not duplicate of newest). */
- static void history_push(const char *line, unsigned int line_len)
- {
- unsigned int i, slot;
- int all_spaces = 1;
- if (line_len == 0)
- return;
- for (i = 0; i < line_len; i++) {
- if (line[i] != ' ') {
- all_spaces = 0;
- break;
- }
- }
- if (all_spaces)
- return;
- if (history_count > 0) {
- slot = (history_next + HISTORY_SIZE - 1) % HISTORY_SIZE;
- for (i = 0; i < line_len && i < LINE_MAX - 1 && history[slot][i]; i++) {
- if (history[slot][i] != line[i])
- break;
- }
- if (i == line_len && history[slot][i] == '\0')
- return; /* duplicate of newest */
- }
- slot = history_next;
- for (i = 0; i < line_len && i < LINE_MAX - 1; i++)
- history[slot][i] = line[i];
- history[slot][i] = '\0';
- history_next = (history_next + 1) % HISTORY_SIZE;
- if (history_count < HISTORY_SIZE)
- history_count++;
- }
- void terminal_run(void)
- {
- static char line[LINE_MAX];
- static unsigned int line_len;
- static unsigned int line_pos; /* cursor index in line, 0..line_len */
- static unsigned int line_start; /* VGA position of first char of line */
- static unsigned int history_browse; /* 0 = not browsing, 1 = newest, 2 = older, ... */
- last_cursor_tick = get_ticks_ms();
- last_datetime_tick = get_ticks_ms();
- cursor_visible = 1;
- line_len = 0;
- line_pos = 0;
- line[0] = '\0';
- history_browse = 0;
- io_drain_keyboard();
- draw_header_row();
- io_putstr(prompt_first);
- line_start = io_get_cursor();
- for (;;) {
- vga_fb_flush_pending_check();
- mouse_poll_update();
- update_datetime();
- update_cursor_blink();
- {
- int k = io_poll_key();
- if (k) {
- if (k == IO_KEY_LEFT) {
- if (line_pos > 0) {
- line_pos--;
- io_set_cursor(line_start + line_pos);
- }
- } else if (k == IO_KEY_RIGHT) {
- if (line_pos < line_len) {
- line_pos++;
- io_set_cursor(line_start + line_pos);
- }
- } else if (k == IO_KEY_UP) {
- if (history_count > 0) {
- if (history_browse < history_count)
- history_browse++;
- history_load_into_line(line, &line_len, &line_pos, line_start, history_browse);
- }
- } else if (k == IO_KEY_DOWN) {
- if (history_browse > 0) {
- history_browse--;
- if (history_browse == 0) {
- {
- unsigned int clear_len = line_len;
- line_len = 0;
- line_pos = 0;
- line[0] = '\0';
- redraw_line_clear(line, 0, 0, line_start, clear_len);
- }
- } else {
- history_load_into_line(line, &line_len, &line_pos, line_start, history_browse);
- }
- }
- } else if (k == '\b') {
- if (line_pos > 0) {
- unsigned int i;
- line_pos--;
- for (i = line_pos; i < line_len; i++)
- line[i] = line[i + 1];
- line_len--;
- line[line_len] = '\0';
- redraw_line_from(line, line_len, line_pos, line_start, line_pos);
- }
- } else if (k == '\n') {
- static char cat_fname[CAT_FNAME_MAX];
- static char power_args[POWER_ARGS_MAX];
- unsigned int drive_sel, kill_pid;
- int skip_prompt = 0;
- io_putchar('\n');
- history_push(line, line_len);
- history_browse = 0;
- if (is_cmd_hello(line, line_len)) {
- if (process_create("hello", program_hello_main) < 0)
- io_putstr("error: too many processes\n");
- } else if (is_cmd_reboot(line, line_len)) {
- program_reboot_main();
- } else if (is_cmd_poweroff(line, line_len)) {
- program_poweroff_main();
- } else if (is_cmd_ls(line, line_len)) {
- if (process_create("ls", program_ls_main) < 0)
- io_putstr("error: too many processes\n");
- } else if (is_cmd_clock(line, line_len)) {
- if (process_create("clock", program_clock_main) < 0)
- io_putstr("error: too many processes\n");
- } else if (is_cmd_colors(line, line_len)) {
- if (process_create("colors", program_colors_main) < 0)
- io_putstr("error: too many processes\n");
- } else if (is_cmd_cat(line, line_len, cat_fname, CAT_FNAME_MAX)) {
- if (process_create_arg("cat", program_cat_main, cat_fname) < 0)
- io_putstr("error: too many processes\n");
- } else if (is_cmd_run(line, line_len, cat_fname, CAT_FNAME_MAX)) {
- if (cat_fname[0] == 's' && cat_fname[1] == 'e' &&
- cat_fname[2] == 'r' && cat_fname[3] == 'i' &&
- cat_fname[4] == 'a' && cat_fname[5] == 'l' &&
- cat_fname[6] == '\0') {
- if (process_create_arg("run_serial", program_run_serial_main, cat_fname) < 0)
- io_putstr("error: too many processes\n");
- } else {
- if (process_create_arg("run", program_run_main, cat_fname) < 0)
- io_putstr("error: too many processes\n");
- }
- } else if (is_cmd_space(line, line_len)) {
- if (process_create_arg("space", program_run_main, "space.bin") < 0)
- io_putstr("error: too many processes\n");
- } else if (is_cmd_display(line, line_len)) {
- if (process_create("display", program_display_main) < 0)
- io_putstr("error: too many processes\n");
- } else if (is_cmd_cpuinfo(line, line_len)) {
- if (process_create("cpuinfo", program_cpuinfo_main) < 0)
- io_putstr("error: too many processes\n");
- } else if (is_cmd_mouseinfo(line, line_len)) {
- if (process_create("mouseinfo", program_mouseinfo_main) < 0)
- io_putstr("error: too many processes\n");
- } else if (is_cmd_power(line, line_len, power_args, POWER_ARGS_MAX)) {
- if (process_create_arg("power", program_power_main, power_args) < 0)
- io_putstr("error: too many processes\n");
- } else if (is_cmd_drive(line, line_len, &drive_sel)) {
- disk_set_drive(drive_sel);
- io_putstr("drive ");
- io_putchar((char)('0' + disk_get_drive()));
- io_putstr(" selected\n");
- } else if (is_cmd_ps(line, line_len)) {
- process_ps();
- } else if (is_cmd_kill(line, line_len, &kill_pid)) {
- if (process_kill(kill_pid) < 0)
- io_putstr("kill: no such process\n");
- else
- io_putstr("killed\n");
- } else if (is_cmd_kexec(line, line_len)) {
- if (kexec_busy) {
- io_putstr("kexec: already receiving\n");
- } else {
- kexec_busy = 1;
- if (process_create("kexec", program_kexec_main) < 0) {
- kexec_busy = 0;
- io_putstr("error: too many processes\n");
- }
- }
- } else if (is_cmd_help(line, line_len)) {
- io_putstr("hello reboot poweroff\n");
- io_putstr("ls cat <file>\n");
- io_putstr("run <file> space\n");
- io_putstr("clock colors\n");
- io_putstr("display cpuinfo\n");
- io_putstr("mouseinfo\n");
- io_putstr("power [info|set <low|balanced|max>]\n");
- io_putstr("drive <0|1>\n");
- io_putstr("ps kill <pid>\n");
- io_putstr("kexec serial test|recv clear\n");
- } else if (is_cmd_clear(line, line_len)) {
- io_clear_screen();
- draw_header_row();
- io_set_cursor(IO_CONTENT_OFFSET);
- io_putstr(prompt_first);
- line_start = io_get_cursor();
- skip_prompt = 1;
- } else {
- static char serial_arg[8];
- if (is_cmd_serial(line, line_len, serial_arg, sizeof(serial_arg))) {
- if (serial_arg[0] == 't' && serial_arg[1] == 'e' &&
- serial_arg[2] == 's' && serial_arg[3] == 't' &&
- serial_arg[4] == '\0') {
- if (process_create_arg("serial_loop", program_serial_loop_main, serial_arg) < 0)
- io_putstr("error: too many processes\n");
- } else if (serial_arg[0] == 'r' && serial_arg[1] == 'e' &&
- serial_arg[2] == 'c' && serial_arg[3] == 'v' &&
- serial_arg[4] == '\0') {
- program_serial_recv_main(serial_arg);
- } else {
- io_putstr("serial: usage serial test|recv\n");
- }
- } else {
- unsigned int i = 0;
- while (i < line_len && line[i] == ' ')
- i++;
- if (i < line_len)
- io_putstr("command not found\n");
- }
- }
- line_len = 0;
- line_pos = 0;
- line[0] = '\0';
- if (!skip_prompt) {
- io_putstr(prompt);
- line_start = io_get_cursor();
- }
- if (io_did_scroll())
- redraw_datetime();
- } else {
- {
- unsigned char u = (unsigned char)k;
- if (u >= 0x20 && u < 0x7F && line_len < LINE_MAX - 1) {
- unsigned int i;
- history_browse = 0;
- for (i = line_len; i > line_pos; i--)
- line[i] = line[i - 1];
- line[line_pos] = (char)k;
- line_len++;
- line[line_len] = '\0';
- line_pos++;
- redraw_line_from(line, line_len, line_pos, line_start, line_pos - 1);
- }
- }
- }
- } else {
- if (!kexec_busy && kexec_pending()) {
- kexec_busy = 1;
- if (process_create("kexec", program_kexec_main) < 0)
- kexec_busy = 0;
- }
- cpu_idle();
- }
- }
- }
- }
|