Fixed ugly bug in the serial debugging code

svn path=/trunk/; revision=941
This commit is contained in:
Eric Kohl 2000-01-19 16:24:15 +00:00
parent 90e1f4cbf9
commit 75f2f5b22e
2 changed files with 36 additions and 72 deletions

View file

@ -1,10 +1,11 @@
/* $Id: kdbg.c,v 1.3 1999/12/12 03:48:47 phreak Exp $ /* $Id: kdbg.c,v 1.4 2000/01/19 16:24:15 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/hal/x86/kdbg.c * FILE: ntoskrnl/hal/x86/kdbg.c
* PURPOSE: Serial i/o functions for the kernel debugger. * PURPOSE: Serial i/o functions for the kernel debugger.
* PROGRAMMER: Emanuele Aliberti * PROGRAMMER: Emanuele Aliberti
* Eric Kohl
* UPDATE HISTORY: * UPDATE HISTORY:
* Created 05/09/99 * Created 05/09/99
*/ */
@ -13,16 +14,11 @@
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#define NDEBUG
#include <internal/debug.h> #include <internal/debug.h>
#define DEFAULT_BAUD_RATE 19200 #define DEFAULT_BAUD_RATE 19200
//#define DEFAULT_COM_PORT 2
//#define DEFAULT_BASE_ADDRESS 0x2F8
#define DEFAULT_COM_PORT 1
#define DEFAULT_BASE_ADDRESS 0x3F8
/* MACROS *******************************************************************/ /* MACROS *******************************************************************/
@ -58,8 +54,6 @@
#define SER_SCR(x) ((x)+7) #define SER_SCR(x) ((x)+7)
/* GLOBAL VARIABLES *********************************************************/ /* GLOBAL VARIABLES *********************************************************/
ULONG KdComPortInUse = 0; ULONG KdComPortInUse = 0;
@ -78,7 +72,7 @@ static BOOLEAN PortInitialized = FALSE;
/* STATIC FUNCTIONS *********************************************************/ /* STATIC FUNCTIONS *********************************************************/
static BOOLEAN static BOOLEAN
KdDoesComPortExist (PUCHAR BaseAddress) KdpDoesComPortExist (PUCHAR BaseAddress)
{ {
BOOLEAN found; BOOLEAN found;
BYTE mcr; BYTE mcr;
@ -131,17 +125,16 @@ KdDoesComPortExist (PUCHAR BaseAddress)
BOOLEAN BOOLEAN
STDCALL STDCALL
KdPortInitialize ( KdPortInitialize (
PKD_PORT_INFORMATION PortInformation, PKD_PORT_INFORMATION PortInformation,
DWORD Unknown1, DWORD Unknown1,
DWORD Unknown2 DWORD Unknown2
) )
{ {
ULONG BaseArray[5] = {0, 0x3F8, 0x2F8, 3E8, 2E8}; ULONG BaseArray[5] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8};
char buffer[80]; char buffer[80];
ULONG divisor; ULONG divisor;
BYTE lcr; BYTE lcr;
if (PortInitialized == FALSE) if (PortInitialized == FALSE)
{ {
if (PortInformation->BaudRate != 0) if (PortInformation->BaudRate != 0)
@ -155,97 +148,69 @@ KdPortInitialize (
if (PortInformation->ComPort == 0) if (PortInformation->ComPort == 0)
{ {
if (KdDoesComPortExist ((PUCHAR)BaseArray[2])) if (KdpDoesComPortExist ((PUCHAR)BaseArray[2]))
{ {
PortBase = (PUCHAR)BaseArray[2]; PortBase = (PUCHAR)BaseArray[2];
ComPort = 2; ComPort = 2;
PortInformation->BaseAddress = (ULONG)PortBase;
PortInformation->ComPort = ComPort;
#ifndef NDEBUG #ifndef NDEBUG
sprintf (buffer, sprintf (buffer,
"\nSerial port COM%ld found at 0x%lx\n", "\nSerial port COM%ld found at 0x%lx\n",
ComPort, ComPort,
(ULONG)PortBase); (ULONG)PortBase);
HalDisplayString (buffer); HalDisplayString (buffer);
#endif #endif /* NDEBUG */
} }
else if (KdDoesComPortExist ((PUCHAR)BaseArray[1])) else if (KdpDoesComPortExist ((PUCHAR)BaseArray[1]))
{ {
PortBase = (PUCHAR)BaseArray[1]; PortBase = (PUCHAR)BaseArray[1];
ComPort = 1; ComPort = 1;
PortInformation->BaseAddress = (ULONG)PortBase;
PortInformation->ComPort = ComPort;
#ifndef NDEBUG #ifndef NDEBUG
sprintf (buffer, sprintf (buffer,
"\nSerial port COM%ld found at 0x%lx\n", "\nSerial port COM%ld found at 0x%lx\n",
ComPort, ComPort,
(ULONG)PortBase); (ULONG)PortBase);
HalDisplayString (buffer); HalDisplayString (buffer);
#endif #endif /* NDEBUG */
} }
else else
{ {
sprintf (buffer, sprintf (buffer,
"\nKernel Debugger: No COM port found!!!\n\n"); "\nKernel Debugger: No COM port found!!!\n\n");
HalDisplayString (buffer); HalDisplayString (buffer);
return FALSE; return FALSE;
} }
} }
else else
{ {
if (KdDoesComPortExist ((PUCHAR)BaseArray[PortInformation->ComPort])) if (KdpDoesComPortExist ((PUCHAR)BaseArray[PortInformation->ComPort]))
{ {
PortBase = (PUCHAR)BaseArray[PortInformation->ComPort]; PortBase = (PUCHAR)BaseArray[PortInformation->ComPort];
ComPort = PortInformation->ComPort; ComPort = PortInformation->ComPort;
PortInformation->BaseAddress = (ULONG)PortBase;
#ifndef NDEBUG #ifndef NDEBUG
sprintf (buffer, sprintf (buffer,
"\nSerial port COM%ld found at 0x%lx\n", "\nSerial port COM%ld found at 0x%lx\n",
ComPort, ComPort,
(ULONG)PortBase); (ULONG)PortBase);
HalDisplayString (buffer); HalDisplayString (buffer);
#endif #endif /* NDEBUG */
} }
else else
{ {
sprintf (buffer, sprintf (buffer,
"\nKernel Debugger: No serial port found!!!\n\n"); "\nKernel Debugger: No serial port found!!!\n\n");
HalDisplayString (buffer); HalDisplayString (buffer);
return FALSE; return FALSE;
} }
} }
/*
if (KdDoesComPortExist ((PUCHAR)BaseArray[2]))
{
PortBase = (PUCHAR)BaseArray[2];
ComPort = 2;
sprintf (buffer,
"\nCOM port found at 0x%lx\n",
(ULONG)PortBase);
HalDisplayString (buffer);
}
else if (KdDoesComPortExist ((PUCHAR)BaseArray[1]))
{
PortBase = (PUCHAR)BaseArray[1];
ComPort = 1;
sprintf (buffer,
"\nCOM port found at 0x%lx\n",
(ULONG)PortBase);
HalDisplayString (buffer);
}
else
{
sprintf (buffer,
"\nKernel Debugger: No COM port found!!!\n");
HalDisplayString (buffer);
return FALSE;
}
*/
PortInitialized = TRUE; PortInitialized = TRUE;
} }
/* /*
* set baud rate and data format (8N1) * set baud rate and data format (8N1)
*/ */
@ -278,7 +243,7 @@ KdPortInitialize (
* print message to blue screen * print message to blue screen
*/ */
sprintf (buffer, sprintf (buffer,
"\nKernel Debugger using: COM%ld (Port 0x%lx) BaudRate %ld\n\n", "\nKernel Debugger: COM%ld (Port 0x%lx) BaudRate %ld\n\n",
ComPort, ComPort,
(ULONG)PortBase, (ULONG)PortBase,
BaudRate); BaudRate);
@ -296,9 +261,8 @@ KdPortGetByte (
VOID VOID
) )
{ {
if (PortInitialized == FALSE) if (PortInitialized == FALSE)
return 0; return 0;
return (BYTE) 0; return (BYTE) 0;
} }
@ -319,16 +283,16 @@ KdPortPollByte (
VOID VOID
STDCALL STDCALL
KdPortPutByte ( KdPortPutByte (
UCHAR ByteToSend UCHAR ByteToSend
) )
{ {
if (PortInitialized == FALSE) if (PortInitialized == FALSE)
return; return;
while ((READ_PORT_UCHAR (SER_LSR(PortBase)) & SR_LSR_TBE) == 0) while ((READ_PORT_UCHAR (SER_LSR(PortBase)) & SR_LSR_TBE) == 0)
; ;
WRITE_PORT_UCHAR (SER_THR(PortBase), ByteToSend); WRITE_PORT_UCHAR (SER_THR(PortBase), ByteToSend);
} }

View file

@ -1,4 +1,4 @@
/* $Id: kdebug.c,v 1.3 2000/01/17 21:02:06 ekohl Exp $ /* $Id: kdebug.c,v 1.4 2000/01/19 16:23:56 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -30,13 +30,13 @@
* writes the output to a log file. * writes the output to a log file.
*/ */
#define SCREEN_DEBUGGING /* debug info is printed on the screen */ #define SCREEN_DEBUGGING /* debug info is printed on the screen */
//#define SERIAL_DEBUGGING /* remote debugging */ //#define SERIAL_DEBUGGING /* remote debugging */
//#define BOCHS_DEBUGGING /* debug output using bochs */ //#define BOCHS_DEBUGGING /* debug output using bochs */
#define SERIAL_DEBUG_PORT 0x03f8 /* COM 1 */ #define SERIAL_DEBUG_PORT 1 /* COM 1 */
// #define SERIAL_DEBUG_PORT 0x02f8 /* COM 2 */ // #define SERIAL_DEBUG_PORT 2 /* COM 2 */
#define SERIAL_DEBUG_BAUD_RATE 19200 #define SERIAL_DEBUG_BAUD_RATE 19200
@ -75,7 +75,7 @@ KdInitSystem (VOID)
#ifdef SERIAL_DEBUGGING #ifdef SERIAL_DEBUGGING
KD_PORT_INFORMATION PortInfo; KD_PORT_INFORMATION PortInfo;
PortInfo.BaseAddress = SERIAL_DEBUG_PORT; PortInfo.ComPort = SERIAL_DEBUG_PORT;
PortInfo.BaudRate = SERIAL_DEBUG_BAUD_RATE; PortInfo.BaudRate = SERIAL_DEBUG_BAUD_RATE;
KdPortInitialize (&PortInfo, KdPortInitialize (&PortInfo,