2007-12-06 13:11:21 +00:00
|
|
|
|
/*
|
2007-10-23 08:30:39 +00:00
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
|
* PROJECT: ReactOS kernel
|
2015-10-04 11:54:25 +00:00
|
|
|
|
* FILE: ntoskrnl/kd/i386/kdbg.c
|
2007-10-23 08:30:39 +00:00
|
|
|
|
* PURPOSE: Serial i/o functions for the kernel debugger.
|
2007-12-06 13:11:21 +00:00
|
|
|
|
* PROGRAMMER: Alex Ionescu
|
|
|
|
|
* Herv<EFBFBD> Poussineau
|
2007-10-23 08:30:39 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
|
2013-05-08 15:36:38 +00:00
|
|
|
|
#include <ntoskrnl.h>
|
2012-11-29 10:26:00 +00:00
|
|
|
|
#define NDEBUG
|
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
2020-04-21 20:22:42 +00:00
|
|
|
|
#if defined(SARCH_PC98)
|
|
|
|
|
#define DEFAULT_BAUD_RATE 9600
|
|
|
|
|
#else
|
2013-05-07 00:14:36 +00:00
|
|
|
|
#define DEFAULT_BAUD_RATE 19200
|
2020-04-21 20:22:42 +00:00
|
|
|
|
#endif
|
2007-10-23 08:30:39 +00:00
|
|
|
|
|
2012-11-29 10:26:00 +00:00
|
|
|
|
#if defined(_M_IX86) || defined(_M_AMD64)
|
2020-03-06 18:50:31 +00:00
|
|
|
|
#if defined(SARCH_PC98)
|
|
|
|
|
const ULONG BaseArray[] = {0, 0x30, 0x238};
|
|
|
|
|
#else
|
2012-11-29 10:26:00 +00:00
|
|
|
|
const ULONG BaseArray[] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8};
|
2020-03-06 18:50:31 +00:00
|
|
|
|
#endif
|
2007-12-06 13:11:21 +00:00
|
|
|
|
#elif defined(_M_PPC)
|
2012-11-29 10:26:00 +00:00
|
|
|
|
const ULONG BaseArray[] = {0, 0x800003F8};
|
2007-12-06 13:11:21 +00:00
|
|
|
|
#elif defined(_M_MIPS)
|
2012-11-29 10:26:00 +00:00
|
|
|
|
const ULONG BaseArray[] = {0, 0x80006000, 0x80007000};
|
2008-02-08 08:20:06 +00:00
|
|
|
|
#elif defined(_M_ARM)
|
2012-11-29 10:26:00 +00:00
|
|
|
|
const ULONG BaseArray[] = {0, 0xF1012000};
|
2007-12-06 13:11:21 +00:00
|
|
|
|
#else
|
|
|
|
|
#error Unknown architecture
|
|
|
|
|
#endif
|
2007-10-23 08:30:39 +00:00
|
|
|
|
|
2015-12-20 02:53:30 +00:00
|
|
|
|
#define MAX_COM_PORTS (sizeof(BaseArray) / sizeof(BaseArray[0]) - 1)
|
|
|
|
|
|
2013-05-07 00:14:36 +00:00
|
|
|
|
/* STATIC VARIABLES ***********************************************************/
|
2007-10-23 08:30:39 +00:00
|
|
|
|
|
2013-05-07 00:14:36 +00:00
|
|
|
|
// static CPPORT DefaultPort = {0, 0, 0};
|
2007-10-23 08:30:39 +00:00
|
|
|
|
|
2013-05-07 00:14:36 +00:00
|
|
|
|
/* The COM port must only be initialized once! */
|
2013-05-05 20:05:50 +00:00
|
|
|
|
// static BOOLEAN PortInitialized = FALSE;
|
2007-10-23 08:30:39 +00:00
|
|
|
|
|
2013-05-05 21:57:42 +00:00
|
|
|
|
/* REACTOS FUNCTIONS **********************************************************/
|
2007-10-23 08:30:39 +00:00
|
|
|
|
|
|
|
|
|
BOOLEAN
|
2007-12-06 13:11:21 +00:00
|
|
|
|
NTAPI
|
2013-05-05 19:55:42 +00:00
|
|
|
|
KdPortInitializeEx(
|
2013-05-07 00:14:36 +00:00
|
|
|
|
IN PCPPORT PortInformation,
|
|
|
|
|
IN ULONG ComPortNumber)
|
2007-10-23 08:30:39 +00:00
|
|
|
|
{
|
2013-05-07 00:14:36 +00:00
|
|
|
|
NTSTATUS Status;
|
2013-05-05 19:55:42 +00:00
|
|
|
|
|
2013-05-05 20:05:50 +00:00
|
|
|
|
#if 0 // Deactivated because never used in fact (was in KdPortInitialize but we use KdPortInitializeEx)
|
2013-05-05 19:55:42 +00:00
|
|
|
|
/*
|
|
|
|
|
* Find the port if needed
|
|
|
|
|
*/
|
2007-10-23 08:30:39 +00:00
|
|
|
|
|
2007-12-06 13:11:21 +00:00
|
|
|
|
if (!PortInitialized)
|
|
|
|
|
{
|
|
|
|
|
DefaultPort.BaudRate = PortInformation->BaudRate;
|
2007-10-23 08:30:39 +00:00
|
|
|
|
|
2013-05-07 00:14:36 +00:00
|
|
|
|
if (ComPortNumber == 0)
|
2007-12-06 13:11:21 +00:00
|
|
|
|
{
|
2012-11-29 10:26:00 +00:00
|
|
|
|
/*
|
|
|
|
|
* Start enumerating COM ports from the last one to the first one,
|
|
|
|
|
* and break when we find a valid port.
|
|
|
|
|
* If we reach the first element of the list, the invalid COM port,
|
|
|
|
|
* then it means that no valid port was found.
|
|
|
|
|
*/
|
2015-12-20 02:53:30 +00:00
|
|
|
|
for (ComPortNumber = MAX_COM_PORTS; ComPortNumber > 0; ComPortNumber--)
|
2007-12-06 13:11:21 +00:00
|
|
|
|
{
|
2015-12-20 02:53:30 +00:00
|
|
|
|
if (CpDoesPortExist(UlongToPtr(BaseArray[ComPortNumber])))
|
2007-10-23 08:30:39 +00:00
|
|
|
|
{
|
2015-12-20 02:53:30 +00:00
|
|
|
|
PortInformation->Address = DefaultPort.Address = BaseArray[ComPortNumber];
|
2007-12-06 13:11:21 +00:00
|
|
|
|
break;
|
2007-10-23 08:30:39 +00:00
|
|
|
|
}
|
2007-12-06 13:11:21 +00:00
|
|
|
|
}
|
2013-05-07 00:14:36 +00:00
|
|
|
|
if (ComPortNumber == 0)
|
2007-12-06 13:11:21 +00:00
|
|
|
|
{
|
2013-10-13 23:04:13 +00:00
|
|
|
|
HalDisplayString("\r\nKernel Debugger: No COM port found!\r\n\r\n");
|
2007-12-06 13:11:21 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2007-10-23 08:30:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-12-06 13:11:21 +00:00
|
|
|
|
PortInitialized = TRUE;
|
|
|
|
|
}
|
2013-05-05 20:05:50 +00:00
|
|
|
|
#endif
|
2007-10-23 08:30:39 +00:00
|
|
|
|
|
2013-05-05 19:55:42 +00:00
|
|
|
|
/*
|
|
|
|
|
* Initialize the port
|
|
|
|
|
*/
|
2013-05-07 00:14:36 +00:00
|
|
|
|
Status = CpInitialize(PortInformation,
|
|
|
|
|
(ComPortNumber == 0 ? PortInformation->Address
|
|
|
|
|
: UlongToPtr(BaseArray[ComPortNumber])),
|
|
|
|
|
(PortInformation->BaudRate == 0 ? DEFAULT_BAUD_RATE
|
|
|
|
|
: PortInformation->BaudRate));
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
2011-11-22 02:30:16 +00:00
|
|
|
|
{
|
2013-10-13 23:04:13 +00:00
|
|
|
|
HalDisplayString("\r\nKernel Debugger: Serial port not found!\r\n\r\n");
|
2013-05-07 00:14:36 +00:00
|
|
|
|
return FALSE;
|
2011-11-22 02:30:16 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2007-12-06 13:11:21 +00:00
|
|
|
|
{
|
2007-10-23 08:30:39 +00:00
|
|
|
|
#ifndef NDEBUG
|
2013-10-13 23:07:26 +00:00
|
|
|
|
CHAR buffer[80];
|
|
|
|
|
|
2013-05-07 00:14:36 +00:00
|
|
|
|
/* Print message to blue screen */
|
|
|
|
|
sprintf(buffer,
|
2018-01-04 10:00:36 +00:00
|
|
|
|
"\r\nKernel Debugger: Serial port found: COM%ld (Port 0x%p) BaudRate %ld\r\n\r\n",
|
2013-05-07 00:14:36 +00:00
|
|
|
|
ComPortNumber,
|
|
|
|
|
PortInformation->Address,
|
|
|
|
|
PortInformation->BaudRate);
|
|
|
|
|
HalDisplayString(buffer);
|
2007-10-23 08:30:39 +00:00
|
|
|
|
#endif /* NDEBUG */
|
|
|
|
|
|
2013-05-05 21:23:20 +00:00
|
|
|
|
#if 0
|
2013-05-07 00:14:36 +00:00
|
|
|
|
/* Set global info */
|
|
|
|
|
KdComPortInUse = DefaultPort.Address;
|
2013-05-05 21:23:20 +00:00
|
|
|
|
#endif
|
2013-05-07 00:14:36 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2007-10-23 08:30:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOLEAN
|
2007-12-06 13:11:21 +00:00
|
|
|
|
NTAPI
|
|
|
|
|
KdPortGetByteEx(
|
2013-05-07 00:14:36 +00:00
|
|
|
|
IN PCPPORT PortInformation,
|
2007-12-06 13:11:21 +00:00
|
|
|
|
OUT PUCHAR ByteReceived)
|
2007-10-23 08:30:39 +00:00
|
|
|
|
{
|
2013-08-31 15:01:50 +00:00
|
|
|
|
return (CpGetByte(PortInformation, ByteReceived, FALSE, FALSE) == CP_GET_SUCCESS);
|
2007-10-23 08:30:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VOID
|
2007-12-06 13:11:21 +00:00
|
|
|
|
NTAPI
|
|
|
|
|
KdPortPutByteEx(
|
2013-05-07 00:14:36 +00:00
|
|
|
|
IN PCPPORT PortInformation,
|
2007-12-06 13:11:21 +00:00
|
|
|
|
IN UCHAR ByteToSend)
|
2007-10-23 08:30:39 +00:00
|
|
|
|
{
|
2013-05-07 00:14:36 +00:00
|
|
|
|
CpPutByte(PortInformation, ByteToSend);
|
2007-10-23 08:30:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* EOF */
|