ReactOS 0.4.16-dev-336-gb667d82
kdterminal.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _SIZE
 

Macros

#define KEY_BS   8
 
#define KEY_ESC   27
 
#define KEY_DEL   127
 
#define KEY_SCAN_UP   72
 
#define KEY_SCAN_DOWN   80
 
#define KEYSC_END   0x004f
 
#define KEYSC_PAGEUP   0x0049
 
#define KEYSC_PAGEDOWN   0x0051
 
#define KEYSC_HOME   0x0047
 
#define KEYSC_ARROWUP   0x0048
 

Typedefs

typedef struct _SIZE SIZE
 
typedef struct _SIZEPSIZE
 
typedef enum _KDB_OUTPUT_SETTINGS KDB_OUTPUT_SETTINGS
 

Enumerations

enum  _KDB_OUTPUT_SETTINGS { KD_DEBUG_KDSERIAL = 1 , KD_DEBUG_KDNOECHO = 2 }
 

Functions

BOOLEAN KdpInitTerminal (VOID)
 Initializes the controlling terminal.
 
BOOLEAN KdpUpdateTerminalSize (_Out_ PSIZE TermSize)
 
VOID KdpFlushTerminalInput (VOID)
 Flushes terminal input (either serial or PS/2).
 
CHAR KdpReadTermKey (_Out_ PULONG ScanCode)
 Reads one character from the terminal. This function returns a scan code even when reading is done from a serial terminal.
 

Variables

ULONG KdbDebugState
 
SIZE KdTermSize
 
BOOLEAN KdTermConnected
 
BOOLEAN KdTermSerial
 
BOOLEAN KdTermReportsSize
 

Macro Definition Documentation

◆ KEY_BS

#define KEY_BS   8

Definition at line 10 of file kdterminal.h.

◆ KEY_DEL

#define KEY_DEL   127

Definition at line 12 of file kdterminal.h.

◆ KEY_ESC

#define KEY_ESC   27

Definition at line 11 of file kdterminal.h.

◆ KEY_SCAN_DOWN

#define KEY_SCAN_DOWN   80

Definition at line 15 of file kdterminal.h.

◆ KEY_SCAN_UP

#define KEY_SCAN_UP   72

Definition at line 14 of file kdterminal.h.

◆ KEYSC_ARROWUP

#define KEYSC_ARROWUP   0x0048

Definition at line 22 of file kdterminal.h.

◆ KEYSC_END

#define KEYSC_END   0x004f

Definition at line 18 of file kdterminal.h.

◆ KEYSC_HOME

#define KEYSC_HOME   0x0047

Definition at line 21 of file kdterminal.h.

◆ KEYSC_PAGEDOWN

#define KEYSC_PAGEDOWN   0x0051

Definition at line 20 of file kdterminal.h.

◆ KEYSC_PAGEUP

#define KEYSC_PAGEUP   0x0049

Definition at line 19 of file kdterminal.h.

Typedef Documentation

◆ KDB_OUTPUT_SETTINGS

◆ PSIZE

typedef struct _SIZE * PSIZE

◆ SIZE

Enumeration Type Documentation

◆ _KDB_OUTPUT_SETTINGS

Enumerator
KD_DEBUG_KDSERIAL 
KD_DEBUG_KDNOECHO 

Definition at line 34 of file kdterminal.h.

35{
@ KD_DEBUG_KDSERIAL
Definition: kdterminal.h:36
@ KD_DEBUG_KDNOECHO
Definition: kdterminal.h:37
enum _KDB_OUTPUT_SETTINGS KDB_OUTPUT_SETTINGS

Function Documentation

◆ KdpFlushTerminalInput()

VOID KdpFlushTerminalInput ( VOID  )

Flushes terminal input (either serial or PS/2).

Definition at line 197 of file kdterminal.c.

198{
201 {
202 while (KdbpTryGetCharSerial(1) != -1);
203 }
204 else
205 {
207 while (KdbpTryGetCharKeyboard(&ScanCode, 1) != -1);
208 }
209}
UINT ScanCode
Definition: VirtualKey.c:24
CHAR KdbpTryGetCharKeyboard(PULONG ScanCode, ULONG Retry)
Definition: kdps2kbd.c:104
static CHAR KdTermNextKey
Definition: kdterminal.c:38
ULONG KdbDebugState
Definition: kdterminal.c:32
CHAR KdbpTryGetCharSerial(_In_ ULONG Retry)
Definition: kdserial.c:25
#define ANSI_NULL
uint32_t ULONG
Definition: typedefs.h:59

Referenced by KdIoReadLine(), KdpInitTerminal(), and KdpUpdateTerminalSize().

◆ KdpInitTerminal()

BOOLEAN KdpInitTerminal ( VOID  )

Initializes the controlling terminal.

Returns
TRUE if the controlling terminal is serial and detected as being connected, or FALSE if not.

Definition at line 51 of file kdterminal.c.

52{
53 /* Determine whether the controlling terminal is a serial terminal:
54 * serial output is enabled *and* KDSERIAL is set (i.e. user input
55 * through serial). */
57#if 0
58 // Old logic where KDSERIAL also enables serial output.
61#else
62 // New logic where KDSERIAL does not necessarily enable serial output.
65#endif
66
67 /* Flush the input buffer */
69
70 if (KdTermSerial)
71 {
73
74 /* Enable line-wrap */
75 KdbpSendCommandSerial("\x1b[?7h");
76
77 /*
78 * Query terminal type.
79 * Historically it was done with CTRL-E ('\x05'), however nowadays
80 * terminals respond to it with an empty (or a user-configurable)
81 * string. Instead, use the VT52-compatible 'ESC Z' sequence or the
82 * VT100-compatible 'ESC[c' one.
83 */
84 KdbpSendCommandSerial("\x1b[c");
86
87 Length = 0;
88 for (;;)
89 {
90 /* Verify we get an answer, but don't care about it */
91 if (KdbpTryGetCharSerial(5000) == -1)
92 break;
93 ++Length;
94 }
95
96 /* Terminal is connected (TRUE) or not connected (FALSE) */
97 KdTermConnected = (Length > 0);
98 }
99 else
100 {
101 /* Terminal is not serial, assume it's *not* connected */
103 }
104 return KdTermConnected;
105}
#define FALSE
Definition: types.h:117
KDP_DEBUG_MODE KdpDebugMode
Definition: kdio.c:46
VOID KdpFlushTerminalInput(VOID)
Flushes terminal input (either serial or PS/2).
Definition: kdterminal.c:197
BOOLEAN KdTermConnected
Definition: kdterminal.c:34
VOID KdbpSendCommandSerial(_In_ PCSTR Command)
Definition: kdserial.c:17
BOOLEAN KdTermSerial
Definition: kdterminal.c:35
#define KeStallExecutionProcessor(MicroSeconds)
Definition: precomp.h:27
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
UCHAR Screen
Definition: kd.h:100
UCHAR Serial
Definition: kd.h:101

Referenced by KdbpPagerInternal().

◆ KdpReadTermKey()

CHAR KdpReadTermKey ( _Out_ PULONG  ScanCode)

Reads one character from the terminal. This function returns a scan code even when reading is done from a serial terminal.

Definition at line 217 of file kdterminal.c.

219{
220 CHAR Key;
221
222 *ScanCode = 0;
223
225 {
228 if (Key == KEY_ESC) /* ESC */
229 {
231 if (Key == '[')
232 {
234 switch (Key)
235 {
236 case 'A':
238 break;
239 case 'B':
241 break;
242 case 'C':
243 break;
244 case 'D':
245 break;
246 }
247 }
248 }
249 }
250 else
251 {
254 }
255
256 /* Check for return */
257 if (Key == '\r')
258 {
259 /*
260 * We might need to discard the next '\n' which most clients
261 * should send after \r. Wait a bit to make sure we receive it.
262 */
264
267 else
269
270 if (KdTermNextKey == '\n' || KdTermNextKey == -1) /* \n or no response at all */
272 }
273
274 return Key;
275}
#define KdbpGetCharSerial()
Definition: kdterminal.c:19
#define KdbpGetCharKeyboard(ScanCode)
Definition: kdterminal.c:15
#define KEY_SCAN_DOWN
Definition: kdterminal.h:15
#define KEY_SCAN_UP
Definition: kdterminal.h:14
#define KEY_ESC
Definition: keycodes.h:49
char CHAR
Definition: xmlstorage.h:175

Referenced by KdbpPagerInternal(), and KdIoReadLine().

◆ KdpUpdateTerminalSize()

BOOLEAN KdpUpdateTerminalSize ( _Out_ PSIZE  TermSize)

Definition at line 108 of file kdterminal.c.

110{
111 static CHAR Buffer[128];
112 CHAR c;
113 LONG NumberOfCols = -1; // Or initialize to TermSize->cx ??
114 LONG NumberOfRows = -1; // Or initialize to TermSize->cy ??
115
116 /* Retrieve the size of the controlling terminal only when it is serial */
118 {
119 /* Flush the input buffer */
121
122 /* Try to query the terminal size. A reply looks like "\x1b[8;24;80t" */
124 KdbpSendCommandSerial("\x1b[18t");
126
127 c = KdbpTryGetCharSerial(5000);
128 if (c == KEY_ESC)
129 {
130 c = KdbpTryGetCharSerial(5000);
131 if (c == '[')
132 {
133 ULONG Length = 0;
134 for (;;)
135 {
136 c = KdbpTryGetCharSerial(5000);
137 if (c == -1)
138 break;
139
140 Buffer[Length++] = c;
141 if (isalpha(c) || Length >= (sizeof(Buffer) - 1))
142 break;
143 }
145
146 if (Buffer[0] == '8' && Buffer[1] == ';')
147 {
148 SIZE_T i;
149 for (i = 2; (i < Length) && (Buffer[i] != ';'); i++);
150
151 if (Buffer[i] == ';')
152 {
153 Buffer[i++] = ANSI_NULL;
154
155 /* Number of rows is now at Buffer + 2
156 * and number of columns at Buffer + i */
157 NumberOfRows = strtoul(Buffer + 2, NULL, 0);
158 NumberOfCols = strtoul(Buffer + i, NULL, 0);
160 }
161 }
162 }
163 /* Clear further characters */
164 while (KdbpTryGetCharSerial(5000) != -1);
165 }
166 }
167
168 if (NumberOfCols <= 0)
169 {
170 /* Set the number of columns to the default */
172 NumberOfCols = (SCREEN_WIDTH / 8 /*BOOTCHAR_WIDTH*/);
173 else
174 NumberOfCols = 80;
175 }
176 if (NumberOfRows <= 0)
177 {
178 /* Set the number of rows to the default */
180 NumberOfRows = (SCREEN_HEIGHT / (13 /*BOOTCHAR_HEIGHT*/ + 1));
181 else
182 NumberOfRows = 24;
183 }
184
185 TermSize->cx = NumberOfCols;
186 TermSize->cy = NumberOfRows;
187
188 // KdIoPrintf("Cols/Rows: %dx%d\n", TermSize->cx, TermSize->cy);
189
190 return KdTermReportsSize;
191}
#define isalpha(c)
Definition: acclib.h:74
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
const GLubyte * c
Definition: glext.h:8905
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
BOOLEAN KdTermReportsSize
Definition: kdterminal.c:36
#define c
Definition: ke_i.h:80
#define SCREEN_WIDTH
Definition: pc98video.c:27
#define SCREEN_HEIGHT
Definition: pc98video.c:28
long LONG
Definition: pedump.c:60
ULONG_PTR SIZE_T
Definition: typedefs.h:80

Referenced by KdbpPagerInternal().

Variable Documentation

◆ KdbDebugState

◆ KdTermConnected

BOOLEAN KdTermConnected
extern

Definition at line 34 of file kdterminal.c.

Referenced by KdbpPagerInternal(), KdpInitTerminal(), and KdpUpdateTerminalSize().

◆ KdTermReportsSize

BOOLEAN KdTermReportsSize
extern

Definition at line 36 of file kdterminal.c.

Referenced by KdpUpdateTerminalSize().

◆ KdTermSerial

BOOLEAN KdTermSerial
extern

Definition at line 35 of file kdterminal.c.

Referenced by KdpInitTerminal(), and KdpUpdateTerminalSize().

◆ KdTermSize

SIZE KdTermSize
extern

Definition at line 33 of file kdterminal.c.

Referenced by KdbpPagerInternal().