1f33c8020SAxel Dörfler /* 2855ab2b3SAxel Dörfler * Copyright 2005-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3f33c8020SAxel Dörfler * Distributed under the terms of the MIT License. 4f33c8020SAxel Dörfler */ 5f33c8020SAxel Dörfler 6f33c8020SAxel Dörfler 7f33c8020SAxel Dörfler #include "blue_screen.h" 8f33c8020SAxel Dörfler 967f20716SAxel Dörfler #include <KernelExport.h> 10f33c8020SAxel Dörfler #include <frame_buffer_console.h> 11f33c8020SAxel Dörfler #include <console.h> 12f33c8020SAxel Dörfler #include <arch/debug_console.h> 13f33c8020SAxel Dörfler 14f33c8020SAxel Dörfler #include <string.h> 15f33c8020SAxel Dörfler #include <stdio.h> 16f33c8020SAxel Dörfler 17855ab2b3SAxel Dörfler #include "debug_commands.h" 18855ab2b3SAxel Dörfler 19f33c8020SAxel Dörfler 20f33c8020SAxel Dörfler #define USE_SCROLLING 0 21f33c8020SAxel Dörfler #define NO_CLEAR 1 22f33c8020SAxel Dörfler 2367f20716SAxel Dörfler #define MAX_ARGS 8 2467f20716SAxel Dörfler 2567f20716SAxel Dörfler #define FMASK 0x0f 2667f20716SAxel Dörfler #define BMASK 0x70 2767f20716SAxel Dörfler 2867f20716SAxel Dörfler typedef enum { 2967f20716SAxel Dörfler CONSOLE_STATE_NORMAL = 0, 3067f20716SAxel Dörfler CONSOLE_STATE_GOT_ESCAPE, 3167f20716SAxel Dörfler CONSOLE_STATE_SEEN_BRACKET, 3267f20716SAxel Dörfler CONSOLE_STATE_NEW_ARG, 3367f20716SAxel Dörfler CONSOLE_STATE_PARSING_ARG, 3467f20716SAxel Dörfler } console_state; 3567f20716SAxel Dörfler 3670c3e1a4SAxel Dörfler typedef enum { 3770c3e1a4SAxel Dörfler LINE_ERASE_WHOLE, 3870c3e1a4SAxel Dörfler LINE_ERASE_LEFT, 3970c3e1a4SAxel Dörfler LINE_ERASE_RIGHT 4070c3e1a4SAxel Dörfler } erase_line_mode; 4170c3e1a4SAxel Dörfler 42f33c8020SAxel Dörfler struct screen_info { 43f33c8020SAxel Dörfler int32 columns; 44f33c8020SAxel Dörfler int32 rows; 45f33c8020SAxel Dörfler int32 x, y; 46f33c8020SAxel Dörfler uint8 attr; 4767f20716SAxel Dörfler bool bright_attr; 4867f20716SAxel Dörfler bool reverse_attr; 49855ab2b3SAxel Dörfler int32 in_command_rows; 50855ab2b3SAxel Dörfler bool paging; 5133965e02SAxel Dörfler bool boot_debug_output; 52855ab2b3SAxel Dörfler bool ignore_output; 5367f20716SAxel Dörfler 5467f20716SAxel Dörfler // state machine 5567f20716SAxel Dörfler console_state state; 5667f20716SAxel Dörfler int32 arg_count; 5767f20716SAxel Dörfler int32 args[MAX_ARGS]; 58f33c8020SAxel Dörfler } sScreen; 59f33c8020SAxel Dörfler 60f33c8020SAxel Dörfler console_module_info *sModule; 61f33c8020SAxel Dörfler 62f33c8020SAxel Dörfler 63f33c8020SAxel Dörfler static inline void 64f33c8020SAxel Dörfler hide_cursor(void) 65f33c8020SAxel Dörfler { 66f33c8020SAxel Dörfler sModule->move_cursor(-1, -1); 67f33c8020SAxel Dörfler } 68f33c8020SAxel Dörfler 69f33c8020SAxel Dörfler 70f33c8020SAxel Dörfler static inline void 71f33c8020SAxel Dörfler update_cursor(int32 x, int32 y) 72f33c8020SAxel Dörfler { 73f33c8020SAxel Dörfler sModule->move_cursor(x, y); 74f33c8020SAxel Dörfler } 75f33c8020SAxel Dörfler 76f33c8020SAxel Dörfler 7767f20716SAxel Dörfler static inline void 7867f20716SAxel Dörfler move_cursor(int32 x, int32 y) 7967f20716SAxel Dörfler { 8067f20716SAxel Dörfler sScreen.x = x; 8167f20716SAxel Dörfler sScreen.y = y; 8267f20716SAxel Dörfler update_cursor(x, y); 8367f20716SAxel Dörfler } 8467f20716SAxel Dörfler 8567f20716SAxel Dörfler 86f33c8020SAxel Dörfler #if USE_SCROLLING 87f33c8020SAxel Dörfler 88855ab2b3SAxel Dörfler /*! Scroll from the cursor line up to the top of the scroll region up one 89855ab2b3SAxel Dörfler line. 90855ab2b3SAxel Dörfler */ 91f33c8020SAxel Dörfler static void 92f33c8020SAxel Dörfler scroll_up(void) 93f33c8020SAxel Dörfler { 94f33c8020SAxel Dörfler // move the screen up one 95f33c8020SAxel Dörfler sModule->blit(0, 1, sScreen.columns, sScreen.rows - 1, 0, 0); 96f33c8020SAxel Dörfler 97f33c8020SAxel Dörfler // clear the bottom line 98f33c8020SAxel Dörfler sModule->fill_glyph(0, 0, sScreen.columns, 1, ' ', sScreen.attr); 99f33c8020SAxel Dörfler } 100f33c8020SAxel Dörfler #endif 101f33c8020SAxel Dörfler 102f33c8020SAxel Dörfler 103f33c8020SAxel Dörfler static void 104f33c8020SAxel Dörfler next_line(void) 105f33c8020SAxel Dörfler { 106a39bfc19SAxel Dörfler #if USE_SCROLLING 107a39bfc19SAxel Dörfler // TODO: scrolling is usually too slow; we could probably just remove it 108a39bfc19SAxel Dörfler if (sScreen.y == sScreen.rows - 1) 109a39bfc19SAxel Dörfler scroll_up(); 110a39bfc19SAxel Dörfler else 111a39bfc19SAxel Dörfler sScreen.y++; 112a39bfc19SAxel Dörfler #else 113855ab2b3SAxel Dörfler if (in_command_invocation()) 114855ab2b3SAxel Dörfler sScreen.in_command_rows++; 115855ab2b3SAxel Dörfler else 116855ab2b3SAxel Dörfler sScreen.in_command_rows = 0; 117855ab2b3SAxel Dörfler 118a39bfc19SAxel Dörfler if (sScreen.paging && ((sScreen.in_command_rows > 0 119a39bfc19SAxel Dörfler && ((sScreen.in_command_rows + 3) % sScreen.rows) == 0) 120a39bfc19SAxel Dörfler || (sScreen.boot_debug_output && sScreen.y == sScreen.rows - 1))) { 121a39bfc19SAxel Dörfler // Use the paging mechanism: either, we're in the debugger, and a 122a39bfc19SAxel Dörfler // command is being executed, or we're currently showing boot debug 123a39bfc19SAxel Dörfler // output 124*73aa393dSIngo Weinhold const char *text = "Press key to continue, Q to quit, A to abort"; 125855ab2b3SAxel Dörfler int32 length = strlen(text); 126855ab2b3SAxel Dörfler if (sScreen.x + length > sScreen.columns) { 127855ab2b3SAxel Dörfler // make sure we don't overwrite too much 128855ab2b3SAxel Dörfler text = "P"; 129855ab2b3SAxel Dörfler length = 1; 130855ab2b3SAxel Dörfler } 131855ab2b3SAxel Dörfler 132855ab2b3SAxel Dörfler for (int32 i = 0; i < length; i++) { 133a39bfc19SAxel Dörfler // yellow on black (or reverse, during boot) 134855ab2b3SAxel Dörfler sModule->put_glyph(sScreen.columns - length + i, sScreen.y, 135a39bfc19SAxel Dörfler text[i], sScreen.boot_debug_output ? 0x6f : 0xf6); 136855ab2b3SAxel Dörfler } 137855ab2b3SAxel Dörfler 138855ab2b3SAxel Dörfler char c = blue_screen_getchar(); 139*73aa393dSIngo Weinhold if (c == 'q') { 140855ab2b3SAxel Dörfler sScreen.ignore_output = true; 141*73aa393dSIngo Weinhold } else if (c == 'a') { 142*73aa393dSIngo Weinhold abort_debugger_command(); 143*73aa393dSIngo Weinhold // should not return 144*73aa393dSIngo Weinhold sScreen.ignore_output = true; 145*73aa393dSIngo Weinhold } 146855ab2b3SAxel Dörfler 147855ab2b3SAxel Dörfler // remove on screen text again 148855ab2b3SAxel Dörfler sModule->fill_glyph(sScreen.columns - length, sScreen.y, length, 149855ab2b3SAxel Dörfler 1, ' ', sScreen.attr); 150855ab2b3SAxel Dörfler } 151a39bfc19SAxel Dörfler if (sScreen.y == sScreen.rows - 1) { 152f33c8020SAxel Dörfler sScreen.y = 0; 153855ab2b3SAxel Dörfler sModule->fill_glyph(0, 0, sScreen.columns, 2, ' ', sScreen.attr); 154a39bfc19SAxel Dörfler } else 155f33c8020SAxel Dörfler sScreen.y++; 156a39bfc19SAxel Dörfler #endif 157f33c8020SAxel Dörfler 158f33c8020SAxel Dörfler #if NO_CLEAR 159855ab2b3SAxel Dörfler if (sScreen.y + 2 < sScreen.rows) { 160855ab2b3SAxel Dörfler sModule->fill_glyph(0, (sScreen.y + 2) % sScreen.rows, sScreen.columns, 161855ab2b3SAxel Dörfler 1, ' ', sScreen.attr); 162855ab2b3SAxel Dörfler } 163f33c8020SAxel Dörfler #endif 164f33c8020SAxel Dörfler sScreen.x = 0; 165f33c8020SAxel Dörfler } 166f33c8020SAxel Dörfler 167f33c8020SAxel Dörfler 168f33c8020SAxel Dörfler static void 16970c3e1a4SAxel Dörfler erase_line(erase_line_mode mode) 17070c3e1a4SAxel Dörfler { 17170c3e1a4SAxel Dörfler switch (mode) { 17270c3e1a4SAxel Dörfler case LINE_ERASE_WHOLE: 173855ab2b3SAxel Dörfler sModule->fill_glyph(0, sScreen.y, sScreen.columns, 1, ' ', 174855ab2b3SAxel Dörfler sScreen.attr); 17570c3e1a4SAxel Dörfler break; 17670c3e1a4SAxel Dörfler case LINE_ERASE_LEFT: 177855ab2b3SAxel Dörfler sModule->fill_glyph(0, sScreen.y, sScreen.x + 1, 1, ' ', 178855ab2b3SAxel Dörfler sScreen.attr); 17970c3e1a4SAxel Dörfler break; 18070c3e1a4SAxel Dörfler case LINE_ERASE_RIGHT: 181855ab2b3SAxel Dörfler sModule->fill_glyph(sScreen.x, sScreen.y, sScreen.columns 182855ab2b3SAxel Dörfler - sScreen.x, 1, ' ', sScreen.attr); 18370c3e1a4SAxel Dörfler break; 18470c3e1a4SAxel Dörfler } 18570c3e1a4SAxel Dörfler } 18670c3e1a4SAxel Dörfler 18770c3e1a4SAxel Dörfler 18870c3e1a4SAxel Dörfler static void 189f33c8020SAxel Dörfler back_space(void) 190f33c8020SAxel Dörfler { 191f33c8020SAxel Dörfler if (sScreen.x <= 0) 192f33c8020SAxel Dörfler return; 193f33c8020SAxel Dörfler 194f33c8020SAxel Dörfler sScreen.x--; 195f33c8020SAxel Dörfler sModule->put_glyph(sScreen.x, sScreen.y, ' ', sScreen.attr); 196f33c8020SAxel Dörfler } 197f33c8020SAxel Dörfler 198f33c8020SAxel Dörfler 199f33c8020SAxel Dörfler static void 200f33c8020SAxel Dörfler put_character(char c) 201f33c8020SAxel Dörfler { 202f33c8020SAxel Dörfler if (++sScreen.x >= sScreen.columns) { 203f33c8020SAxel Dörfler next_line(); 204f33c8020SAxel Dörfler sScreen.x++; 205f33c8020SAxel Dörfler } 206f33c8020SAxel Dörfler 207f33c8020SAxel Dörfler sModule->put_glyph(sScreen.x - 1, sScreen.y, c, sScreen.attr); 208f33c8020SAxel Dörfler } 209f33c8020SAxel Dörfler 210f33c8020SAxel Dörfler 211f33c8020SAxel Dörfler static void 21267f20716SAxel Dörfler set_vt100_attributes(int32 *args, int32 argCount) 21367f20716SAxel Dörfler { 21467f20716SAxel Dörfler if (argCount == 0) { 21567f20716SAxel Dörfler // that's the default (attributes off) 21667f20716SAxel Dörfler argCount++; 21767f20716SAxel Dörfler args[0] = 0; 21867f20716SAxel Dörfler } 21967f20716SAxel Dörfler 22067f20716SAxel Dörfler for (int32 i = 0; i < argCount; i++) { 22167f20716SAxel Dörfler switch (args[i]) { 22267f20716SAxel Dörfler case 0: // reset 22333965e02SAxel Dörfler sScreen.attr = sScreen.boot_debug_output ? 0xf0 : 0x0f; 22467f20716SAxel Dörfler sScreen.bright_attr = true; 22567f20716SAxel Dörfler sScreen.reverse_attr = false; 22667f20716SAxel Dörfler break; 22767f20716SAxel Dörfler case 1: // bright 22867f20716SAxel Dörfler sScreen.bright_attr = true; 22967f20716SAxel Dörfler sScreen.attr |= 0x08; // set the bright bit 23067f20716SAxel Dörfler break; 23167f20716SAxel Dörfler case 2: // dim 23267f20716SAxel Dörfler sScreen.bright_attr = false; 23367f20716SAxel Dörfler sScreen.attr &= ~0x08; // unset the bright bit 23467f20716SAxel Dörfler break; 23567f20716SAxel Dörfler case 4: // underscore we can't do 23667f20716SAxel Dörfler break; 23767f20716SAxel Dörfler case 5: // blink 23867f20716SAxel Dörfler sScreen.attr |= 0x80; // set the blink bit 23967f20716SAxel Dörfler break; 24067f20716SAxel Dörfler case 7: // reverse 24167f20716SAxel Dörfler sScreen.reverse_attr = true; 242855ab2b3SAxel Dörfler sScreen.attr = ((sScreen.attr & BMASK) >> 4) 243855ab2b3SAxel Dörfler | ((sScreen.attr & FMASK) << 4); 24467f20716SAxel Dörfler if (sScreen.bright_attr) 24567f20716SAxel Dörfler sScreen.attr |= 0x08; 24667f20716SAxel Dörfler break; 24767f20716SAxel Dörfler case 8: // hidden? 24867f20716SAxel Dörfler break; 24967f20716SAxel Dörfler 25067f20716SAxel Dörfler /* foreground colors */ 251855ab2b3SAxel Dörfler case 30: // black 252855ab2b3SAxel Dörfler case 31: // red 253855ab2b3SAxel Dörfler case 32: // green 254855ab2b3SAxel Dörfler case 33: // yellow 255855ab2b3SAxel Dörfler case 34: // blue 256855ab2b3SAxel Dörfler case 35: // magenta 257855ab2b3SAxel Dörfler case 36: // cyan 258855ab2b3SAxel Dörfler case 37: // white 259855ab2b3SAxel Dörfler { 260855ab2b3SAxel Dörfler const uint8 colors[] = {0, 4, 2, 6, 1, 5, 3, 7}; 261855ab2b3SAxel Dörfler sScreen.attr = (sScreen.attr & ~FMASK) | colors[args[i] - 30] 262855ab2b3SAxel Dörfler | (sScreen.bright_attr ? 0x08 : 0); 263855ab2b3SAxel Dörfler break; 264855ab2b3SAxel Dörfler } 26567f20716SAxel Dörfler 26667f20716SAxel Dörfler /* background colors */ 26767f20716SAxel Dörfler case 40: sScreen.attr = (sScreen.attr & ~BMASK) | (0 << 4); break; // black 26867f20716SAxel Dörfler case 41: sScreen.attr = (sScreen.attr & ~BMASK) | (4 << 4); break; // red 26967f20716SAxel Dörfler case 42: sScreen.attr = (sScreen.attr & ~BMASK) | (2 << 4); break; // green 27067f20716SAxel Dörfler case 43: sScreen.attr = (sScreen.attr & ~BMASK) | (6 << 4); break; // yellow 27167f20716SAxel Dörfler case 44: sScreen.attr = (sScreen.attr & ~BMASK) | (1 << 4); break; // blue 27267f20716SAxel Dörfler case 45: sScreen.attr = (sScreen.attr & ~BMASK) | (5 << 4); break; // magenta 27367f20716SAxel Dörfler case 46: sScreen.attr = (sScreen.attr & ~BMASK) | (3 << 4); break; // cyan 27467f20716SAxel Dörfler case 47: sScreen.attr = (sScreen.attr & ~BMASK) | (7 << 4); break; // white 27567f20716SAxel Dörfler } 27667f20716SAxel Dörfler } 27767f20716SAxel Dörfler } 27867f20716SAxel Dörfler 27967f20716SAxel Dörfler 28067f20716SAxel Dörfler static bool 28167f20716SAxel Dörfler process_vt100_command(const char c, bool seenBracket, int32 *args, int32 argCount) 28267f20716SAxel Dörfler { 28367f20716SAxel Dörfler bool ret = true; 28467f20716SAxel Dörfler 28567f20716SAxel Dörfler // kprintf("process_vt100_command: c '%c', argCount %ld, arg[0] %ld, arg[1] %ld, seenBracket %d\n", 28667f20716SAxel Dörfler // c, argCount, args[0], args[1], seenBracket); 28767f20716SAxel Dörfler 28867f20716SAxel Dörfler if (seenBracket) { 28967f20716SAxel Dörfler switch (c) { 29067f20716SAxel Dörfler case 'H': /* set cursor position */ 29167f20716SAxel Dörfler case 'f': { 29267f20716SAxel Dörfler int32 row = argCount > 0 ? args[0] : 1; 29367f20716SAxel Dörfler int32 col = argCount > 1 ? args[1] : 1; 29467f20716SAxel Dörfler if (row > 0) 29567f20716SAxel Dörfler row--; 29667f20716SAxel Dörfler if (col > 0) 29767f20716SAxel Dörfler col--; 29867f20716SAxel Dörfler move_cursor(col, row); 29967f20716SAxel Dörfler break; 30067f20716SAxel Dörfler } 30167f20716SAxel Dörfler case 'A': { /* move up */ 30267f20716SAxel Dörfler int32 deltay = argCount > 0 ? -args[0] : -1; 30367f20716SAxel Dörfler if (deltay == 0) 30467f20716SAxel Dörfler deltay = -1; 30567f20716SAxel Dörfler move_cursor(sScreen.x, sScreen.y + deltay); 30667f20716SAxel Dörfler break; 30767f20716SAxel Dörfler } 30867f20716SAxel Dörfler case 'e': 30967f20716SAxel Dörfler case 'B': { /* move down */ 31067f20716SAxel Dörfler int32 deltay = argCount > 0 ? args[0] : 1; 31167f20716SAxel Dörfler if (deltay == 0) 31267f20716SAxel Dörfler deltay = 1; 31367f20716SAxel Dörfler move_cursor(sScreen.x, sScreen.y + deltay); 31467f20716SAxel Dörfler break; 31567f20716SAxel Dörfler } 31667f20716SAxel Dörfler case 'D': { /* move left */ 31767f20716SAxel Dörfler int32 deltax = argCount > 0 ? -args[0] : -1; 31867f20716SAxel Dörfler if (deltax == 0) 31967f20716SAxel Dörfler deltax = -1; 32067f20716SAxel Dörfler move_cursor(sScreen.x + deltax, sScreen.y); 32167f20716SAxel Dörfler break; 32267f20716SAxel Dörfler } 32367f20716SAxel Dörfler case 'a': 32467f20716SAxel Dörfler case 'C': { /* move right */ 32567f20716SAxel Dörfler int32 deltax = argCount > 0 ? args[0] : 1; 32667f20716SAxel Dörfler if (deltax == 0) 32767f20716SAxel Dörfler deltax = 1; 32867f20716SAxel Dörfler move_cursor(sScreen.x + deltax, sScreen.y); 32967f20716SAxel Dörfler break; 33067f20716SAxel Dörfler } 33167f20716SAxel Dörfler case '`': 33267f20716SAxel Dörfler case 'G': { /* set X position */ 33367f20716SAxel Dörfler int32 newx = argCount > 0 ? args[0] : 1; 33467f20716SAxel Dörfler if (newx > 0) 33567f20716SAxel Dörfler newx--; 33667f20716SAxel Dörfler move_cursor(newx, sScreen.y); 33767f20716SAxel Dörfler break; 33867f20716SAxel Dörfler } 33967f20716SAxel Dörfler case 'd': { /* set y position */ 34067f20716SAxel Dörfler int32 newy = argCount > 0 ? args[0] : 1; 34167f20716SAxel Dörfler if (newy > 0) 34267f20716SAxel Dörfler newy--; 34367f20716SAxel Dörfler move_cursor(sScreen.x, newy); 34467f20716SAxel Dörfler break; 34567f20716SAxel Dörfler } 34667f20716SAxel Dörfler #if 0 34767f20716SAxel Dörfler case 's': /* save current cursor */ 34867f20716SAxel Dörfler save_cur(console, false); 34967f20716SAxel Dörfler break; 35067f20716SAxel Dörfler case 'u': /* restore cursor */ 35167f20716SAxel Dörfler restore_cur(console, false); 35267f20716SAxel Dörfler break; 35367f20716SAxel Dörfler case 'r': { /* set scroll region */ 35467f20716SAxel Dörfler int32 low = argCount > 0 ? args[0] : 1; 35567f20716SAxel Dörfler int32 high = argCount > 1 ? args[1] : sScreen.lines; 35667f20716SAxel Dörfler if (low <= high) 35767f20716SAxel Dörfler set_scroll_region(console, low - 1, high - 1); 35867f20716SAxel Dörfler break; 35967f20716SAxel Dörfler } 36067f20716SAxel Dörfler case 'L': { /* scroll virtual down at cursor */ 36167f20716SAxel Dörfler int32 lines = argCount > 0 ? args[0] : 1; 36267f20716SAxel Dörfler while (lines > 0) { 36367f20716SAxel Dörfler scrdown(console); 36467f20716SAxel Dörfler lines--; 36567f20716SAxel Dörfler } 36667f20716SAxel Dörfler break; 36767f20716SAxel Dörfler } 36867f20716SAxel Dörfler case 'M': { /* scroll virtual up at cursor */ 36967f20716SAxel Dörfler int32 lines = argCount > 0 ? args[0] : 1; 37067f20716SAxel Dörfler while (lines > 0) { 37167f20716SAxel Dörfler scrup(console); 37267f20716SAxel Dörfler lines--; 37367f20716SAxel Dörfler } 37467f20716SAxel Dörfler break; 37567f20716SAxel Dörfler } 37670c3e1a4SAxel Dörfler #endif 37767f20716SAxel Dörfler case 'K': 37867f20716SAxel Dörfler if (argCount == 0 || args[0] == 0) { 37967f20716SAxel Dörfler // erase to end of line 38070c3e1a4SAxel Dörfler erase_line(LINE_ERASE_RIGHT); 38167f20716SAxel Dörfler } else if (argCount > 0) { 38267f20716SAxel Dörfler if (args[0] == 1) 38370c3e1a4SAxel Dörfler erase_line(LINE_ERASE_LEFT); 38467f20716SAxel Dörfler else if (args[0] == 2) 38570c3e1a4SAxel Dörfler erase_line(LINE_ERASE_WHOLE); 38667f20716SAxel Dörfler } 38767f20716SAxel Dörfler break; 38870c3e1a4SAxel Dörfler #if 0 38967f20716SAxel Dörfler case 'J': 39067f20716SAxel Dörfler if (argCount == 0 || args[0] == 0) { 39167f20716SAxel Dörfler // erase to end of screen 39267f20716SAxel Dörfler erase_screen(console, SCREEN_ERASE_DOWN); 39367f20716SAxel Dörfler } else { 39467f20716SAxel Dörfler if (args[0] == 1) 39567f20716SAxel Dörfler erase_screen(console, SCREEN_ERASE_UP); 39667f20716SAxel Dörfler else if (args[0] == 2) 39767f20716SAxel Dörfler erase_screen(console, SCREEN_ERASE_WHOLE); 39867f20716SAxel Dörfler } 39967f20716SAxel Dörfler break; 40067f20716SAxel Dörfler #endif 40167f20716SAxel Dörfler case 'm': 40267f20716SAxel Dörfler if (argCount >= 0) 40367f20716SAxel Dörfler set_vt100_attributes(args, argCount); 40467f20716SAxel Dörfler break; 40567f20716SAxel Dörfler default: 40667f20716SAxel Dörfler ret = false; 40767f20716SAxel Dörfler } 40867f20716SAxel Dörfler } else { 40967f20716SAxel Dörfler switch (c) { 41067f20716SAxel Dörfler #if 0 41167f20716SAxel Dörfler case 'c': 41267f20716SAxel Dörfler reset_console(console); 41367f20716SAxel Dörfler break; 41467f20716SAxel Dörfler case 'D': 41567f20716SAxel Dörfler rlf(console); 41667f20716SAxel Dörfler break; 41767f20716SAxel Dörfler case 'M': 41867f20716SAxel Dörfler lf(console); 41967f20716SAxel Dörfler break; 42067f20716SAxel Dörfler case '7': 42167f20716SAxel Dörfler save_cur(console, true); 42267f20716SAxel Dörfler break; 42367f20716SAxel Dörfler case '8': 42467f20716SAxel Dörfler restore_cur(console, true); 42567f20716SAxel Dörfler break; 42667f20716SAxel Dörfler #endif 42767f20716SAxel Dörfler default: 42867f20716SAxel Dörfler ret = false; 42967f20716SAxel Dörfler } 43067f20716SAxel Dörfler } 43167f20716SAxel Dörfler 43267f20716SAxel Dörfler return ret; 43367f20716SAxel Dörfler } 43467f20716SAxel Dörfler 43567f20716SAxel Dörfler 43667f20716SAxel Dörfler static void 437f33c8020SAxel Dörfler parse_character(char c) 438f33c8020SAxel Dörfler { 43967f20716SAxel Dörfler switch (sScreen.state) { 44067f20716SAxel Dörfler case CONSOLE_STATE_NORMAL: 441f33c8020SAxel Dörfler // just output the stuff 442f33c8020SAxel Dörfler switch (c) { 443f33c8020SAxel Dörfler case '\n': 444f33c8020SAxel Dörfler next_line(); 445f33c8020SAxel Dörfler break; 446f33c8020SAxel Dörfler case 0x8: 447f33c8020SAxel Dörfler back_space(); 448f33c8020SAxel Dörfler break; 449f33c8020SAxel Dörfler case '\t': 45067f20716SAxel Dörfler // ToDo: real tab... 451f31dc4ddSAxel Dörfler sScreen.x = (sScreen.x + 8) & ~7; 452f31dc4ddSAxel Dörfler if (sScreen.x >= sScreen.columns) 453f31dc4ddSAxel Dörfler next_line(); 454f33c8020SAxel Dörfler break; 455f33c8020SAxel Dörfler 456f33c8020SAxel Dörfler case '\r': 457f33c8020SAxel Dörfler case '\0': 45867f20716SAxel Dörfler case '\a': // beep 459f33c8020SAxel Dörfler break; 460f33c8020SAxel Dörfler 46167f20716SAxel Dörfler case 0x1b: 46267f20716SAxel Dörfler // escape character 46367f20716SAxel Dörfler sScreen.arg_count = -1; 46467f20716SAxel Dörfler sScreen.state = CONSOLE_STATE_GOT_ESCAPE; 46567f20716SAxel Dörfler break; 466f33c8020SAxel Dörfler default: 467f33c8020SAxel Dörfler put_character(c); 468f33c8020SAxel Dörfler } 46967f20716SAxel Dörfler break; 47067f20716SAxel Dörfler case CONSOLE_STATE_GOT_ESCAPE: 47167f20716SAxel Dörfler // look for either commands with no argument, or the '[' character 47267f20716SAxel Dörfler switch (c) { 47367f20716SAxel Dörfler case '[': 47467f20716SAxel Dörfler sScreen.state = CONSOLE_STATE_SEEN_BRACKET; 47567f20716SAxel Dörfler break; 47667f20716SAxel Dörfler default: 47767f20716SAxel Dörfler sScreen.args[sScreen.arg_count] = 0; 478855ab2b3SAxel Dörfler process_vt100_command(c, false, sScreen.args, 479855ab2b3SAxel Dörfler sScreen.arg_count + 1); 48067f20716SAxel Dörfler sScreen.state = CONSOLE_STATE_NORMAL; 48167f20716SAxel Dörfler } 48267f20716SAxel Dörfler break; 48367f20716SAxel Dörfler case CONSOLE_STATE_SEEN_BRACKET: 48467f20716SAxel Dörfler switch (c) { 48567f20716SAxel Dörfler case '0'...'9': 48667f20716SAxel Dörfler sScreen.arg_count = 0; 48767f20716SAxel Dörfler sScreen.args[sScreen.arg_count] = c - '0'; 48867f20716SAxel Dörfler sScreen.state = CONSOLE_STATE_PARSING_ARG; 48967f20716SAxel Dörfler break; 49067f20716SAxel Dörfler case '?': 491855ab2b3SAxel Dörfler // private DEC mode parameter follows - we ignore those 492855ab2b3SAxel Dörfler // anyway 49367f20716SAxel Dörfler break; 49467f20716SAxel Dörfler default: 495855ab2b3SAxel Dörfler process_vt100_command(c, true, sScreen.args, 496855ab2b3SAxel Dörfler sScreen.arg_count + 1); 49767f20716SAxel Dörfler sScreen.state = CONSOLE_STATE_NORMAL; 49867f20716SAxel Dörfler } 49967f20716SAxel Dörfler break; 50067f20716SAxel Dörfler case CONSOLE_STATE_NEW_ARG: 50167f20716SAxel Dörfler switch (c) { 50267f20716SAxel Dörfler case '0'...'9': 50367f20716SAxel Dörfler sScreen.arg_count++; 50467f20716SAxel Dörfler if (sScreen.arg_count == MAX_ARGS) { 50567f20716SAxel Dörfler sScreen.state = CONSOLE_STATE_NORMAL; 50667f20716SAxel Dörfler break; 50767f20716SAxel Dörfler } 50867f20716SAxel Dörfler sScreen.args[sScreen.arg_count] = c - '0'; 50967f20716SAxel Dörfler sScreen.state = CONSOLE_STATE_PARSING_ARG; 51067f20716SAxel Dörfler break; 51167f20716SAxel Dörfler default: 512855ab2b3SAxel Dörfler process_vt100_command(c, true, sScreen.args, 513855ab2b3SAxel Dörfler sScreen.arg_count + 1); 51467f20716SAxel Dörfler sScreen.state = CONSOLE_STATE_NORMAL; 51567f20716SAxel Dörfler } 51667f20716SAxel Dörfler break; 51767f20716SAxel Dörfler case CONSOLE_STATE_PARSING_ARG: 51867f20716SAxel Dörfler // parse args 51967f20716SAxel Dörfler switch (c) { 52067f20716SAxel Dörfler case '0'...'9': 52167f20716SAxel Dörfler sScreen.args[sScreen.arg_count] *= 10; 52267f20716SAxel Dörfler sScreen.args[sScreen.arg_count] += c - '0'; 52367f20716SAxel Dörfler break; 52467f20716SAxel Dörfler case ';': 52567f20716SAxel Dörfler sScreen.state = CONSOLE_STATE_NEW_ARG; 52667f20716SAxel Dörfler break; 52767f20716SAxel Dörfler default: 528855ab2b3SAxel Dörfler process_vt100_command(c, true, sScreen.args, 529855ab2b3SAxel Dörfler sScreen.arg_count + 1); 53067f20716SAxel Dörfler sScreen.state = CONSOLE_STATE_NORMAL; 53167f20716SAxel Dörfler } 53267f20716SAxel Dörfler } 533f33c8020SAxel Dörfler } 534f33c8020SAxel Dörfler 535f33c8020SAxel Dörfler 536855ab2b3SAxel Dörfler static int 537855ab2b3SAxel Dörfler set_paging(int argc, char **argv) 538855ab2b3SAxel Dörfler { 539855ab2b3SAxel Dörfler if (argc > 1 && !strcmp(argv[1], "--help")) { 540855ab2b3SAxel Dörfler kprintf("usage: %s [on|off]\n", argv[0]); 541855ab2b3SAxel Dörfler return 0; 542855ab2b3SAxel Dörfler } 543855ab2b3SAxel Dörfler 544855ab2b3SAxel Dörfler if (argc == 1) 545855ab2b3SAxel Dörfler sScreen.paging = !sScreen.paging; 546855ab2b3SAxel Dörfler else if (!strcmp(argv[1], "on")) 547855ab2b3SAxel Dörfler sScreen.paging = true; 548855ab2b3SAxel Dörfler else if (!strcmp(argv[1], "off")) 549855ab2b3SAxel Dörfler sScreen.paging = false; 550855ab2b3SAxel Dörfler else 551855ab2b3SAxel Dörfler sScreen.paging = parse_expression(argv[1]) != 0; 552855ab2b3SAxel Dörfler 553855ab2b3SAxel Dörfler kprintf("paging is turned %s now.\n", sScreen.paging ? "on" : "off"); 554855ab2b3SAxel Dörfler return 0; 555855ab2b3SAxel Dörfler } 556855ab2b3SAxel Dörfler 557855ab2b3SAxel Dörfler 558f33c8020SAxel Dörfler // #pragma mark - 559f33c8020SAxel Dörfler 560f33c8020SAxel Dörfler 561f33c8020SAxel Dörfler status_t 562f33c8020SAxel Dörfler blue_screen_init(void) 563f33c8020SAxel Dörfler { 564f33c8020SAxel Dörfler extern console_module_info gFrameBufferConsoleModule; 565f33c8020SAxel Dörfler 566f33c8020SAxel Dörfler // we can't use get_module() here, since it's too early in the boot process 567f33c8020SAxel Dörfler 568f33c8020SAxel Dörfler if (!frame_buffer_console_available()) 569f33c8020SAxel Dörfler return B_ERROR; 570f33c8020SAxel Dörfler 571f33c8020SAxel Dörfler sModule = &gFrameBufferConsoleModule; 572855ab2b3SAxel Dörfler sScreen.paging = true; 573855ab2b3SAxel Dörfler 574855ab2b3SAxel Dörfler add_debugger_command("paging", set_paging, "Enable or disable paging"); 575f33c8020SAxel Dörfler return B_OK; 576f33c8020SAxel Dörfler } 577f33c8020SAxel Dörfler 578f33c8020SAxel Dörfler 579173d0b2fSAxel Dörfler status_t 58092447917SAxel Dörfler blue_screen_enter(bool debugOutput) 581f33c8020SAxel Dörfler { 58292447917SAxel Dörfler sScreen.attr = debugOutput ? 0xf0 : 0x0f; 58392447917SAxel Dörfler // black on white for KDL, white on black for debug output 58433965e02SAxel Dörfler sScreen.boot_debug_output = debugOutput; 58533965e02SAxel Dörfler sScreen.ignore_output = false; 58633965e02SAxel Dörfler 587f33c8020SAxel Dörfler sScreen.x = sScreen.y = 0; 58867f20716SAxel Dörfler sScreen.state = CONSOLE_STATE_NORMAL; 589f33c8020SAxel Dörfler 590173d0b2fSAxel Dörfler if (sModule == NULL) 591173d0b2fSAxel Dörfler return B_NO_INIT; 592173d0b2fSAxel Dörfler 593f33c8020SAxel Dörfler sModule->get_size(&sScreen.columns, &sScreen.rows); 594f33c8020SAxel Dörfler #if !NO_CLEAR 595f33c8020SAxel Dörfler sModule->clear(sScreen.attr); 596f33c8020SAxel Dörfler #else 597f33c8020SAxel Dörfler sModule->fill_glyph(0, sScreen.y, sScreen.columns, 3, ' ', sScreen.attr); 598f33c8020SAxel Dörfler #endif 599173d0b2fSAxel Dörfler return B_OK; 600f33c8020SAxel Dörfler } 601f33c8020SAxel Dörfler 602f33c8020SAxel Dörfler 603a1587d16SIngo Weinhold void 604a1587d16SIngo Weinhold blue_screen_clear_screen(void) 605a1587d16SIngo Weinhold { 606a1587d16SIngo Weinhold sModule->clear(sScreen.attr); 607a1587d16SIngo Weinhold move_cursor(0, 0); 608a1587d16SIngo Weinhold } 609a1587d16SIngo Weinhold 610a1587d16SIngo Weinhold 611f33c8020SAxel Dörfler char 612f33c8020SAxel Dörfler blue_screen_getchar(void) 613f33c8020SAxel Dörfler { 614f33c8020SAxel Dörfler return arch_debug_blue_screen_getchar(); 615f33c8020SAxel Dörfler } 616f33c8020SAxel Dörfler 617f33c8020SAxel Dörfler 618f33c8020SAxel Dörfler void 619f33c8020SAxel Dörfler blue_screen_putchar(char c) 620f33c8020SAxel Dörfler { 62133965e02SAxel Dörfler if (sScreen.ignore_output 62233965e02SAxel Dörfler && (in_command_invocation() || sScreen.boot_debug_output)) 623855ab2b3SAxel Dörfler return; 624855ab2b3SAxel Dörfler 625855ab2b3SAxel Dörfler sScreen.ignore_output = false; 626f33c8020SAxel Dörfler hide_cursor(); 627f33c8020SAxel Dörfler 628f33c8020SAxel Dörfler parse_character(c); 629f33c8020SAxel Dörfler 630f33c8020SAxel Dörfler update_cursor(sScreen.x, sScreen.y); 631f33c8020SAxel Dörfler } 632f33c8020SAxel Dörfler 633f33c8020SAxel Dörfler 634f33c8020SAxel Dörfler void 635f33c8020SAxel Dörfler blue_screen_puts(const char *text) 636f33c8020SAxel Dörfler { 63733965e02SAxel Dörfler if (sScreen.ignore_output 63833965e02SAxel Dörfler && (in_command_invocation() || sScreen.boot_debug_output)) 639855ab2b3SAxel Dörfler return; 640855ab2b3SAxel Dörfler 641855ab2b3SAxel Dörfler sScreen.ignore_output = false; 642f33c8020SAxel Dörfler hide_cursor(); 643f33c8020SAxel Dörfler 644f33c8020SAxel Dörfler while (text[0] != '\0') { 645f33c8020SAxel Dörfler parse_character(text[0]); 646f33c8020SAxel Dörfler text++; 647f33c8020SAxel Dörfler } 648f33c8020SAxel Dörfler 649f33c8020SAxel Dörfler update_cursor(sScreen.x, sScreen.y); 650f33c8020SAxel Dörfler } 651