ReactOS 0.4.15-dev-5666-gc548b97
serial.c
Go to the documentation of this file.
1/*++
2
3Copyright (c) 1998-2001 Klaus P. Gerlicher
4
5Module Name:
6
7 serial.c
8
9Abstract:
10
11 serial debugger connection
12
13Environment:
14
15 LINUX 2.2.X
16 Kernel mode only
17
18Author:
19
20 Klaus P. Gerlicher
21
22Revision History:
23
24 19-Aug-2000: created
25 15-Nov-2000: general cleanup of source files
26
27Copyright notice:
28
29 This file may be distributed under the terms of the GNU Public License.
30
31--*/
32#include "remods.h"
33#include "precomp.h"
34#include "serial_port.h"
35
37
38
39// used for SERIAL window creation
40// NB: at the moment the terminal is 60 lines high.
42{
43 {1,3,1,0,FALSE},
44 {5,8,1,0,FALSE},
45 {14,26,1,0,FALSE},
46 {41,18,1,0,FALSE}
47};
48
50
52
55
58
61
63// SerialSetSpeed()
64//
66void SerialSetSpeed(ULONG baudrate)
67{
68 UCHAR c;
70
71 divisor = (ULONG) (115200L/baudrate);
72
74 outportb((USHORT)(usSerialPortBase + LCR), (UCHAR)(c | 0x80)); // Set DLAB
76 outportb((USHORT)(usSerialPortBase + DLH), (UCHAR)((divisor >> 8) & 0x00FF));
77 outportb((USHORT)(usSerialPortBase + LCR), c); // Reset DLAB
78
79}
80
82// SerialSetOthers()
83//
84// Set other communications parameters
85//************************************************************************
86void SerialSetOthers(ULONG Parity, ULONG Bits, ULONG StopBit)
87{
89 UCHAR c;
90
91 if (usSerialPortBase == 0) return ;
92 if (Bits < 5 || Bits > 8) return ;
93 if (StopBit != 1 && StopBit != 2) return ;
94 if (Parity != NO_PARITY && Parity != ODD_PARITY && Parity != EVEN_PARITY)
95 return;
96
97 setting = Bits-5;
98 setting |= ((StopBit == 1) ? 0x00 : 0x04);
99 setting |= Parity;
100
102 outportb((USHORT)(usSerialPortBase + LCR), (UCHAR)(c & ~0x80)); // Reset DLAB
103
104 // no ints
106
107 // clear FIFO and disable them
109
111
113
114
115 return ;
116}
117
119// FlushSerialBuffer()
120//
123{
124 UCHAR c;
125
126 while(SerialReadByte(&c));
127}
128
130// SetupSerial()
131//
134{
136
137 usSerialPortBase = ports[port-1];
139 SerialSetSpeed(baudrate);
140
141 // clear out received bytes
142 // else we would think there's a terminal connected
144}
145
146
148// SerialReadByte()
149//
150// Output a character to the serial port
151//************************************************************************
153{
155
156 timeout = 0x00FFFFL;
157
158 // Wait for transmitter to clear
159 while ((inportb((USHORT)(usSerialPortBase + LSR)) & RCVRDY) == 0)
160 if (!(--timeout))
161 {
162 return FALSE;
163 }
164
166
167 return TRUE;
168}
169
171// SerialSendByte()
172//
173// Output a character to the serial port
174//************************************************************************
176{
178
179 timeout = 0x00FFFFL;
180
181 // Wait for transmitter to clear
182 while ((inportb((USHORT)(usSerialPortBase + LSR)) & XMTRDY) == 0)
183 if (!(--timeout))
184 {
185 return FALSE;
186 }
187
189
190 return TRUE;
191}
192
193//************************************************************************
194// CheckSum()
195//
196//************************************************************************
198{
199 UCHAR ucCheckSum = 0;
200 ULONG i;
201 for(i=0;i<Len;i++)
202 {
203 ucCheckSum ^= *p++;
204 ucCheckSum += 1;
205 }
206
207 return ucCheckSum;
208}
209
210
212// ReadPacket()
213//
216{
217 return TRUE;
218}
219
220
222// SendPacket()
223//
226{
227 PUCHAR pHeader = (PUCHAR)&p->header;
228 ULONG i;
229 UCHAR c;
231
232 do
233 {
234 timeout = 10;
235 pHeader = (PUCHAR)&p->header;
236 for(i=0;i<(sizeof(SERIAL_PACKET_HEADER)+p->header.packet_size);i++)
237 {
238 if(!SerialSendByte(*pHeader++))
239 {
240 return FALSE;
241 }
242 }
243
244 do
245 {
246 c = 0;
248 if(c != ACK)
250 }while(c != ACK && timeout--);
251
252 }while(c != ACK);
253
254 return TRUE;
255}
256
258// SendPacketTimeout()
259//
262{
263 PUCHAR pHeader = (PUCHAR)&p->header;
264 ULONG i;
265 UCHAR c;
266 ULONG timeout = 20;
267 BOOLEAN bResult = TRUE;
268
269 pHeader = (PUCHAR)&p->header;
270 for(i=0;i<(sizeof(SERIAL_PACKET_HEADER)+p->header.packet_size);i++)
271 {
272 if(!SerialSendByte(*pHeader++))
273 {
274 return FALSE;
275 }
276 }
277
278 do
279 {
280 c = 0xFF;
282 }while(c != ACK && timeout--);
283
284 if(c != ACK)
285 bResult = FALSE;
286
287 return bResult;
288}
289
290
291//************************************************************************
292// AssemblePacket()
293//
294//************************************************************************
296{
298 ULONG ulCheckSum;
299
301
302 // fill in header
303 p->header.packet_chksum = CheckSum(pData,ulSize);
304 p->header.packet_size = ulSize;
305 p->header.packet_header_chksum = 0;
306 ulCheckSum = (ULONG)CheckSum((PUCHAR)p,sizeof(SERIAL_PACKET_HEADER));
307 p->header.packet_header_chksum = ulCheckSum;
308 // attach data to packet
309 PICE_memcpy(p->data,pData,ulSize);
310
311 return p;
312}
313
314
315// OUTPUT handlers
316
317//*************************************************************************
318// SetForegroundColorVga()
319//
320//*************************************************************************
322{
323 eForegroundColor = col;
324}
325
326//*************************************************************************
327// SetBackgroundColorVga()
328//
329//*************************************************************************
331{
332 eBackgroundColor = col;
333}
334
335
336//*************************************************************************
337// PrintGrafSerial()
338//
339//*************************************************************************
341{
342 // put this into memory
344
345 // put this into cache
346 if(ulFlushBufferPos == 0)
347 {
348 g_x = x;
349 g_y = y;
350 }
351
353}
354
355//*************************************************************************
356// FlushSerial()
357//
358//*************************************************************************
359void FlushSerial(void)
360{
363
365 pPrint->type = PACKET_TYPE_PRINT;
366 pPrint->x = g_x;
367 pPrint->y = g_y;
368 pPrint->fgcol = eForegroundColor;
369 pPrint->bkcol = eBackgroundColor;
373
375 SendPacket(p);
376}
377
378//*************************************************************************
379// ShowCursorSerial()
380//
381// show hardware cursor
382//*************************************************************************
384{
387
388 ENTER_FUNC();
389
391
393 pCursor->type = PACKET_TYPE_CURSOR;
394 pCursor->state = (UCHAR)TRUE;
395 pCursor->x = (UCHAR)wWindow[OUTPUT_WINDOW].usCurX;
396 pCursor->y = (UCHAR)wWindow[OUTPUT_WINDOW].usCurY;
397
399 SendPacket(p);
400
401 LEAVE_FUNC();
402}
403
404//*************************************************************************
405// HideCursorSerial()
406//
407// hide hardware cursor
408//*************************************************************************
410{
413
414 ENTER_FUNC();
415
417
419 pCursor->type = PACKET_TYPE_CURSOR;
420 pCursor->state = (UCHAR)TRUE;
421
423 SendPacket(p);
424
425 LEAVE_FUNC();
426}
427
428//*************************************************************************
429// CopyLineToSerial()
430//
431// copy a line from src to dest
432//*************************************************************************
434{
436}
437
438//*************************************************************************
439// InvertLineSerial()
440//
441// invert a line on the screen
442//*************************************************************************
444{
447
449 pInvertLine->type = PACKET_TYPE_INVERTLINE;
450 pInvertLine->line = line;
451
453 SendPacket(p);
454}
455
456//*************************************************************************
457// HatchLineSerial()
458//
459// hatches a line on the screen
460//*************************************************************************
462{
464}
465
466//*************************************************************************
467// ClrLineSerial()
468//
469// clear a line on the screen
470//*************************************************************************
472{
475
477 pClrLine->type = PACKET_TYPE_CLRLINE;
478 pClrLine->fgcol = eForegroundColor;
479 pClrLine->bkcol = eBackgroundColor;
480 pClrLine->line = line;
481
483 SendPacket(p);
484}
485
486//*************************************************************************
487// PrintLogoSerial()
488//
489//*************************************************************************
491{
493}
494
495//*************************************************************************
496// PrintCursorSerial()
497//
498// emulate a blinking cursor block
499//*************************************************************************
501{
503}
504
505//*************************************************************************
506// SaveGraphicsStateSerial()
507//
508//*************************************************************************
510{
511 // not implemented
512}
513
514//*************************************************************************
515// RestoreGraphicsStateSerial()
516//
517//*************************************************************************
519{
520 // not implemented
521}
522
523// INPUT handlers
524//*************************************************************************
525// GetKeyPolledSerial()
526//
527//*************************************************************************
529{
530 UCHAR ucResult;
533
535 pPoll->type = PACKET_TYPE_POLL;
538 pPoll->build_number = PICE_BUILD;
539
541 SendPacket(p);
542
543 ucResult = ucLastKeyRead;
544
545 ucLastKeyRead = 0;
546
547 return ucResult;
548}
549
550//*************************************************************************
551// FlushKeyboardQueueSerial()
552//
553//*************************************************************************
555{
556 // not implemented
557}
558
559//*************************************************************************
560// Connect()
561//
562//*************************************************************************
564{
567
569 pConnect->type = PACKET_TYPE_CONNECT;
570 pConnect->xsize = xSize;
571 pConnect->ysize = ySize;
572
574 return SendPacketTimeout(p);
575}
576
577//*************************************************************************
578// ConsoleInitSerial()
579//
580// init terminal screen
581//*************************************************************************
583{
584 BOOLEAN bResult = FALSE;
585
586 ENTER_FUNC();
587
602
605
607
610
612
614 {
615 bResult = TRUE;
616
618
619 SetupSerial(1,115200);
620
621 // connect to terminal, if none's there, we give up
623
624 if(bResult)
625 {
627 }
628 }
629
630 LEAVE_FUNC();
631
632 return bResult;
633}
634
635
636//*************************************************************************
637// ConsoleShutdownSerial()
638//
639// exit terminal screen
640//*************************************************************************
642{
643 ENTER_FUNC();
644
645 Connect(80,25);
646
648
651
652 LEAVE_FUNC();
653}
654
655
656
unsigned char BOOLEAN
#define BLACK
#define WHITE
return
Definition: dirsup.c:529
#define Len
Definition: deflate.h:82
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
USHORT port
Definition: uri.c:228
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLenum src
Definition: glext.h:6340
const GLubyte * c
Definition: glext.h:8905
GLuint divisor
Definition: glext.h:6313
GLfloat GLfloat p
Definition: glext.h:8902
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
FxContextHeader * pHeader
Definition: handleapi.cpp:604
#define c
Definition: ke_i.h:80
_In_ PKSPIN_CONNECT Connect
Definition: ks.h:4536
unsigned char * PUCHAR
Definition: retypes.h:3
unsigned int ULONG
Definition: retypes.h:1
#define EVEN_PARITY
Definition: serial.c:91
#define NO_PARITY
Definition: serial.c:89
#define ODD_PARITY
Definition: serial.c:90
#define ENTER_FUNC()
Definition: debug.h:42
#define LEAVE_FUNC()
Definition: debug.h:43
void SetWindowGeometry(PVOID pWindow)
Definition: hardware.c:893
ULONG GLOBAL_SCREEN_WIDTH
Definition: hardware.c:62
INPUT_HANDLERS ihandlers
Definition: hardware.c:66
BOOLEAN bCursorEnabled
Definition: hardware.c:51
void EmptyRingBuffer(void)
Definition: hardware.c:104
OUTPUT_HANDLERS ohandlers
Definition: hardware.c:65
WINDOW wWindow[4]
Definition: hardware.c:59
ULONG GLOBAL_SCREEN_HEIGHT
Definition: hardware.c:62
#define NOT_IMPLEMENTED()
Definition: hardware.h:153
@ OUTPUT_WINDOW
Definition: hardware.h:72
#define FRAMEBUFFER_SIZE
Definition: precomp.h:31
void PrintLogoSerial(BOOLEAN bShow)
Definition: serial.c:490
UCHAR flush_buffer[_PAGE_SIZE]
Definition: serial.c:56
UCHAR assemble_packet[_PAGE_SIZE]
Definition: serial.c:54
BOOLEAN ConsoleInitSerial(void)
Definition: serial.c:582
USHORT usSerialPortBase
Definition: serial.c:51
ECOLORS eForegroundColor
Definition: serial.c:60
BOOLEAN SendPacket(PSERIAL_PACKET p)
‍************************************************************************
Definition: serial.c:225
UCHAR g_x
Definition: serial.c:56
UCHAR GetKeyPolledSerial(void)
Definition: serial.c:528
void PrintCursorSerial(BOOLEAN bForce)
Definition: serial.c:500
void SerialSetOthers(ULONG Parity, ULONG Bits, ULONG StopBit)
‍************************************************************************
Definition: serial.c:86
BOOLEAN SerialReadByte(PUCHAR px)
‍************************************************************************
Definition: serial.c:152
void ClrLineSerial(ULONG line)
Definition: serial.c:471
ULONG ulFlushBufferPos
Definition: serial.c:57
void SetBackgroundColorSerial(ECOLORS col)
Definition: serial.c:330
void ShowCursorSerial(void)
Definition: serial.c:383
void HatchLineSerial(ULONG line)
Definition: serial.c:461
UCHAR ucLastKeyRead
Definition: serial.c:59
void CopyLineToSerial(USHORT dest, USHORT src)
Definition: serial.c:433
void FlushKeyboardQueueSerial(void)
Definition: serial.c:554
WINDOW wWindowSerial[4]
Definition: serial.c:41
BOOLEAN SerialSendByte(UCHAR x)
‍************************************************************************
Definition: serial.c:175
BOOLEAN SendPacketTimeout(PSERIAL_PACKET p)
‍************************************************************************
Definition: serial.c:261
void HideCursorSerial(void)
Definition: serial.c:409
void SetForegroundColorSerial(ECOLORS col)
Definition: serial.c:321
void SaveGraphicsStateSerial(void)
Definition: serial.c:509
UCHAR g_y
Definition: serial.c:56
void InvertLineSerial(ULONG line)
Definition: serial.c:443
PSERIAL_PACKET AssemblePacket(PUCHAR pData, ULONG ulSize)
Definition: serial.c:295
void FlushSerial(void)
Definition: serial.c:359
BOOLEAN ReadPacket(PSERIAL_PACKET p)
‍************************************************************************
Definition: serial.c:215
void RestoreGraphicsStateSerial(void)
Definition: serial.c:518
void SerialSetSpeed(ULONG baudrate)
‍************************************************************************
Definition: serial.c:66
void PrintGrafSerial(ULONG x, ULONG y, UCHAR c)
Definition: serial.c:340
void FlushSerialBuffer(void)
‍************************************************************************
Definition: serial.c:122
void ConsoleShutdownSerial(void)
Definition: serial.c:641
UCHAR CheckSum(LPSTR p, ULONG Len)
Definition: serial.c:197
void SetupSerial(ULONG port, ULONG baudrate)
‍************************************************************************
Definition: serial.c:133
PUCHAR pScreenBufferSerial
Definition: serial.c:49
ECOLORS eBackgroundColor
Definition: serial.c:60
void PICE_memcpy(void *t, void *s, int sz)
Definition: utils.c:239
void * PICE_malloc(size_t numBytes, BOOLEAN fromPaged)
Definition: utils.c:2212
void PICE_free(void *p)
Definition: utils.c:2222
void outportb(PUCHAR port, UCHAR data)
Definition: utils.c:2154
UCHAR inportb(PUCHAR port)
Definition: utils.c:2174
USHORT PICE_strlen(const char *s)
Definition: utils.c:547
char * PICE_strcpy(char *s1, char *s2)
Definition: utils.c:302
#define _PAGE_SIZE
Definition: utils.h:269
#define NONPAGEDPOOL
Definition: utils.h:306
struct _SERIAL_DATA_PACKET_PRINT * PSERIAL_DATA_PACKET_PRINT
struct _SERIAL_PACKET_HEADER SERIAL_PACKET_HEADER
#define PACKET_TYPE_CURSOR
Definition: shared.h:179
#define PACKET_TYPE_INVERTLINE
Definition: shared.h:186
#define PACKET_TYPE_CLRLINE
Definition: shared.h:154
#define ACK
Definition: shared.h:126
#define PACKET_TYPE_POLL
Definition: shared.h:193
enum _ECOLORS ECOLORS
struct _SERIAL_DATA_PACKET_CONNECT * PSERIAL_DATA_PACKET_CONNECT
#define PACKET_TYPE_CONNECT
Definition: shared.h:172
struct _SERIAL_DATA_PACKET_CURSOR * PSERIAL_DATA_PACKET_CURSOR
struct _SERIAL_PACKET * PSERIAL_PACKET
#define PACKET_TYPE_PRINT
Definition: shared.h:162
struct _SERIAL_DATA_PACKET_POLL * PSERIAL_DATA_PACKET_POLL
struct _SERIAL_DATA_PACKET_INVERTLINE * PSERIAL_DATA_PACKET_INVERTLINE
struct _SERIAL_DATA_PACKET_CLRLINE * PSERIAL_DATA_PACKET_CLRLINE
static char * dest
Definition: rtl.c:135
unsigned short USHORT
Definition: pedump.c:61
#define PICE_MINOR_VERSION
Definition: pice_ver.h:33
#define PICE_MAJOR_VERSION
Definition: pice_ver.h:32
#define PICE_BUILD
Definition: pice_ver.h:36
#define COM1BASE
Definition: serial_port.h:35
#define DLH
Definition: serial_port.h:70
#define FCR
Definition: serial_port.h:64
#define IER
Definition: serial_port.h:62
#define DLL
Definition: serial_port.h:69
#define XMTRDY
Definition: serial_port.h:109
#define RTS
Definition: serial_port.h:127
#define MCR
Definition: serial_port.h:66
#define DTR
Definition: serial_port.h:126
#define COM4BASE
Definition: serial_port.h:40
#define LCR
Definition: serial_port.h:65
#define RXR
Definition: serial_port.h:61
#define COM2BASE
Definition: serial_port.h:36
#define LSR
Definition: serial_port.h:67
#define TXR
Definition: serial_port.h:60
#define RCVRDY
Definition: serial_port.h:104
#define COM3BASE
Definition: serial_port.h:39
void(* FlushKeyboardQueue)(void)
Definition: hardware.h:61
UCHAR(* GetKeyPolled)(void)
Definition: hardware.h:60
void(* ShowCursor)(void)
Definition: hardware.h:51
void(* HatchLine)(ULONG line)
Definition: hardware.h:46
void(* CopyLineTo)(USHORT dest, USHORT src)
Definition: hardware.h:41
void(* PrintCursor)(BOOLEAN bForce)
Definition: hardware.h:48
void(* ClrLine)(ULONG line)
Definition: hardware.h:44
void(* PrintGraf)(ULONG x, ULONG y, UCHAR c)
Definition: hardware.h:42
void(* PrintLogo)(BOOLEAN bShow)
Definition: hardware.h:47
void(* SetBackgroundColor)(ECOLORS)
Definition: hardware.h:54
void(* InvertLine)(ULONG line)
Definition: hardware.h:45
void(* HideCursor)(void)
Definition: hardware.h:52
void(* SetForegroundColor)(ECOLORS)
Definition: hardware.h:53
void(* RestoreGraphicsState)(void)
Definition: hardware.h:50
void(* SaveGraphicsState)(void)
Definition: hardware.h:49
void(* Flush)(void)
Definition: hardware.h:43
Definition: parser.c:49
Definition: dhcpd.h:135
Definition: dhcpd.h:245
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
char * LPSTR
Definition: xmlstorage.h:182
unsigned char UCHAR
Definition: xmlstorage.h:181