rust-kernel
Rustbelt: a hobby x86_64 kernel written in Rust
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | //! The console "tty": keyboard input, and the `File` behind file
//! descriptors 0, 1 and 2.
//!
//! Two input modes, like a Linux terminal:
//!
//! * **cooked** (canonical, the default): typed characters are echoed and
//! collected in a line buffer (Backspace edits it); only when Enter is
//! pressed does the whole line become readable from fd 0. So `read(0)`
//! gets a complete, already-edited line. Programs like `cat` use this.
//! * **raw**: every key goes to the reader immediately and nothing is echoed;
//! arrow keys arrive as ANSI escape sequences (`ESC [ A` = up). The shell
//! switches to raw while it edits its command line, so it can do its own
//! echo, Backspace and up-arrow history. (Linux: `tcsetattr` / `ioctl`.)
//!
//! Output (`Console::write`) understands two control characters besides
//! '\n': '\x08' erases the character before the cursor, and '\x0c' (form
//! feed) clears the screen.
use crateErrno;
use crate;
use crateWaitQueue;
use crate::;
use String;
use OnceCell;
use ;
use ArrayQueue;
use KeyCode;
use Mutex;
/// The line being typed in cooked mode (not yet readable).
static LINE: = new;
/// Bytes waiting for `read(0, ...)`: finished lines (cooked) or keys (raw).
static INPUT: = uninit;
/// Raw mode on?
static RAW: AtomicBool = new;
/// pid of the process that switched raw mode on (0 = none). If it exits
/// without switching back, the console goes back to cooked mode.
static RAW_OWNER: AtomicU64 = new;
/// Threads blocked in `Console::read`, waiting for input.
static INPUT_WAIT: WaitQueue = new;
/// Switch between raw (`true`) and cooked mode for process `pid`. Returns
/// the old mode.
/// A process ended: if it left the console in raw mode, undo that (so the
/// next program, or a respawned shell, gets normal line input).
/// Make `bytes` readable and wake readers. (Queue full: drop -- nobody reads.)
/// Called by the keyboard task for every typed character.
/// Called by the keyboard task for keys that aren't characters (arrows...).
/// The console as a file: reading gets keyboard input, writing prints to the
/// screen and serial port.
;
/// Held for the whole of one console `write` (see `Console::write`).
static CONSOLE_WRITE: Mutex = new;
|