Define serial port bases only once

Formatting, cleanup, code factorization

svn path=/trunk/; revision=31039
This commit is contained in:
Hervé Poussineau 2007-12-06 13:11:21 +00:00
parent 8b186a16b8
commit 82efa9c6a0

View file

@ -1,13 +1,10 @@
/* $Id: kdbg.c 23670 2006-08-23 17:28:39Z ion $ /*
*
* 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: drivers/base/kdcom/kdbg.c
* PURPOSE: Serial i/o functions for the kernel debugger. * PURPOSE: Serial i/o functions for the kernel debugger.
* PROGRAMMER: Emanuele Aliberti * PROGRAMMER: Alex Ionescu
* Eric Kohl * Hervé Poussineau
* UPDATE HISTORY:
* Created 05/09/99
*/ */
/* INCLUDES *****************************************************************/ /* INCLUDES *****************************************************************/
@ -20,6 +17,7 @@
#include <debug.h> #include <debug.h>
#include "arc/arc.h" #include "arc/arc.h"
#include "windbgkd.h" #include "windbgkd.h"
#include <kddll.h>
typedef struct _KD_PORT_INFORMATION typedef struct _KD_PORT_INFORMATION
{ {
@ -28,27 +26,61 @@ typedef struct _KD_PORT_INFORMATION
ULONG BaseAddress; ULONG BaseAddress;
} KD_PORT_INFORMATION, *PKD_PORT_INFORMATION; } KD_PORT_INFORMATION, *PKD_PORT_INFORMATION;
BOOLEAN
NTAPI
KdPortInitializeEx(
IN PKD_PORT_INFORMATION PortInformation,
IN ULONG Unknown1,
IN ULONG Unknown2);
BOOLEAN
NTAPI
KdPortGetByteEx(
IN PKD_PORT_INFORMATION PortInformation,
OUT PUCHAR ByteReceived);
BOOLEAN
NTAPI
KdPortPollByteEx(
IN PKD_PORT_INFORMATION PortInformation,
OUT PUCHAR ByteReceived);
VOID
NTAPI
KdPortPutByteEx(
IN PKD_PORT_INFORMATION PortInformation,
IN UCHAR ByteToSend);
#define DEFAULT_BAUD_RATE 19200 #define DEFAULT_BAUD_RATE 19200
#ifdef _M_IX86
const ULONG BaseArray[5] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8};
#elif defined(_M_PPC)
const ULONG BaseArray[5] = {0, 0x800003f8};
#elif defined(_M_MIPS)
const ULONG BaseArray[5] = {0, 0x80006000, 0x80007000};
#else
#error Unknown architecture
#endif
/* MACROS *******************************************************************/ /* MACROS *******************************************************************/
#define SER_RBR(x) ((x)+0) #define SER_RBR(x) ((PUCHAR)(x)+0)
#define SER_THR(x) ((x)+0) #define SER_THR(x) ((PUCHAR)(x)+0)
#define SER_DLL(x) ((x)+0) #define SER_DLL(x) ((PUCHAR)(x)+0)
#define SER_IER(x) ((x)+1) #define SER_IER(x) ((PUCHAR)(x)+1)
#define SR_IER_ERDA 0x01 #define SR_IER_ERDA 0x01
#define SR_IER_ETHRE 0x02 #define SR_IER_ETHRE 0x02
#define SR_IER_ERLSI 0x04 #define SR_IER_ERLSI 0x04
#define SR_IER_EMS 0x08 #define SR_IER_EMS 0x08
#define SR_IER_ALL 0x0F #define SR_IER_ALL 0x0F
#define SER_DLM(x) ((x)+1) #define SER_DLM(x) ((PUCHAR)(x)+1)
#define SER_IIR(x) ((x)+2) #define SER_IIR(x) ((PUCHAR)(x)+2)
#define SER_FCR(x) ((x)+2) #define SER_FCR(x) ((PUCHAR)(x)+2)
#define SR_FCR_ENABLE_FIFO 0x01 #define SR_FCR_ENABLE_FIFO 0x01
#define SR_FCR_CLEAR_RCVR 0x02 #define SR_FCR_CLEAR_RCVR 0x02
#define SR_FCR_CLEAR_XMIT 0x04 #define SR_FCR_CLEAR_XMIT 0x04
#define SER_LCR(x) ((x)+3) #define SER_LCR(x) ((PUCHAR)(x)+3)
#define SR_LCR_CS5 0x00 #define SR_LCR_CS5 0x00
#define SR_LCR_CS6 0x01 #define SR_LCR_CS6 0x01
#define SR_LCR_CS7 0x02 #define SR_LCR_CS7 0x02
@ -62,28 +94,26 @@ typedef struct _KD_PORT_INFORMATION
#define SR_LCR_PSP 0x38 #define SR_LCR_PSP 0x38
#define SR_LCR_BRK 0x40 #define SR_LCR_BRK 0x40
#define SR_LCR_DLAB 0x80 #define SR_LCR_DLAB 0x80
#define SER_MCR(x) ((x)+4) #define SER_MCR(x) ((PUCHAR)(x)+4)
#define SR_MCR_DTR 0x01 #define SR_MCR_DTR 0x01
#define SR_MCR_RTS 0x02 #define SR_MCR_RTS 0x02
#define SR_MCR_OUT1 0x04 #define SR_MCR_OUT1 0x04
#define SR_MCR_OUT2 0x08 #define SR_MCR_OUT2 0x08
#define SR_MCR_LOOP 0x10 #define SR_MCR_LOOP 0x10
#define SER_LSR(x) ((x)+5) #define SER_LSR(x) ((PUCHAR)(x)+5)
#define SR_LSR_DR 0x01 #define SR_LSR_DR 0x01
#define SR_LSR_TBE 0x20 #define SR_LSR_TBE 0x20
#define SER_MSR(x) ((x)+6) #define SER_MSR(x) ((PUCHAR)(x)+6)
#define SR_MSR_CTS 0x10 #define SR_MSR_CTS 0x10
#define SR_MSR_DSR 0x20 #define SR_MSR_DSR 0x20
#define SER_SCR(x) ((x)+7) #define SER_SCR(x) ((PUCHAR)(x)+7)
/* GLOBAL VARIABLES *********************************************************/ /* GLOBAL VARIABLES *********************************************************/
/* STATIC VARIABLES *********************************************************/ /* STATIC VARIABLES *********************************************************/
static ULONG ComPort = 0; static KD_PORT_INFORMATION DefaultPort = { 0, 0, 0 };
static ULONG BaudRate = 0;
static PUCHAR PortBase = (PUCHAR)0;
/* The com port must only be initialized once! */ /* The com port must only be initialized once! */
static BOOLEAN PortInitialized = FALSE; static BOOLEAN PortInitialized = FALSE;
@ -92,7 +122,8 @@ static BOOLEAN PortInitialized = FALSE;
/* STATIC FUNCTIONS *********************************************************/ /* STATIC FUNCTIONS *********************************************************/
static BOOLEAN static BOOLEAN
KdpDoesComPortExist (PUCHAR BaseAddress) KdpDoesComPortExist(
IN ULONG BaseAddress)
{ {
BOOLEAN found; BOOLEAN found;
UCHAR mcr; UCHAR mcr;
@ -101,16 +132,16 @@ KdpDoesComPortExist (PUCHAR BaseAddress)
found = FALSE; found = FALSE;
/* save Modem Control Register (MCR) */ /* save Modem Control Register (MCR) */
mcr = READ_PORT_UCHAR (SER_MCR(BaseAddress)); mcr = READ_PORT_UCHAR(SER_MCR(BaseAddress));
/* enable loop mode (set Bit 4 of the MCR) */ /* enable loop mode (set Bit 4 of the MCR) */
WRITE_PORT_UCHAR (SER_MCR(BaseAddress), 0x10); WRITE_PORT_UCHAR(SER_MCR(BaseAddress), SR_MCR_LOOP);
/* clear all modem output bits */ /* clear all modem output bits */
WRITE_PORT_UCHAR (SER_MCR(BaseAddress), 0x10); WRITE_PORT_UCHAR(SER_MCR(BaseAddress), SR_MCR_LOOP);
/* read the Modem Status Register */ /* read the Modem Status Register */
msr = READ_PORT_UCHAR (SER_MSR(BaseAddress)); msr = READ_PORT_UCHAR(SER_MSR(BaseAddress));
/* /*
* the upper nibble of the MSR (modem output bits) must be * the upper nibble of the MSR (modem output bits) must be
@ -119,10 +150,10 @@ KdpDoesComPortExist (PUCHAR BaseAddress)
if ((msr & 0xF0) == 0x00) if ((msr & 0xF0) == 0x00)
{ {
/* set all modem output bits */ /* set all modem output bits */
WRITE_PORT_UCHAR (SER_MCR(BaseAddress), 0x1F); WRITE_PORT_UCHAR(SER_MCR(BaseAddress), SR_MCR_DTR | SR_MCR_RTS | SR_MCR_OUT1 | SR_MCR_OUT2 | SR_MCR_LOOP);
/* read the Modem Status Register */ /* read the Modem Status Register */
msr = READ_PORT_UCHAR (SER_MSR(BaseAddress)); msr = READ_PORT_UCHAR(SER_MSR(BaseAddress));
/* /*
* the upper nibble of the MSR (modem output bits) must be * the upper nibble of the MSR (modem output bits) must be
@ -134,19 +165,19 @@ KdpDoesComPortExist (PUCHAR BaseAddress)
* setup a resonable state for the port: * setup a resonable state for the port:
* enable fifo and clear recieve/transmit buffers * enable fifo and clear recieve/transmit buffers
*/ */
WRITE_PORT_UCHAR (SER_FCR(BaseAddress), WRITE_PORT_UCHAR(SER_FCR(BaseAddress),
(SR_FCR_ENABLE_FIFO | SR_FCR_CLEAR_RCVR | SR_FCR_CLEAR_XMIT)); (SR_FCR_ENABLE_FIFO | SR_FCR_CLEAR_RCVR | SR_FCR_CLEAR_XMIT));
WRITE_PORT_UCHAR (SER_FCR(BaseAddress), 0); WRITE_PORT_UCHAR(SER_FCR(BaseAddress), 0);
READ_PORT_UCHAR (SER_RBR(BaseAddress)); READ_PORT_UCHAR(SER_RBR(BaseAddress));
WRITE_PORT_UCHAR (SER_IER(BaseAddress), 0); WRITE_PORT_UCHAR(SER_IER(BaseAddress), 0);
found = TRUE; found = TRUE;
} }
} }
/* restore MCR */ /* restore MCR */
WRITE_PORT_UCHAR (SER_MCR(BaseAddress), mcr); WRITE_PORT_UCHAR(SER_MCR(BaseAddress), mcr);
return (found); return found;
} }
@ -154,87 +185,37 @@ KdpDoesComPortExist (PUCHAR BaseAddress)
/* HAL.KdPortInitialize */ /* HAL.KdPortInitialize */
BOOLEAN BOOLEAN
STDCALL NTAPI
KdPortInitialize ( KdPortInitialize(
PKD_PORT_INFORMATION PortInformation, IN PKD_PORT_INFORMATION PortInformation,
ULONG Unknown1, IN ULONG Unknown1,
ULONG Unknown2 IN ULONG Unknown2)
)
{ {
ULONG BaseArray[5] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8}; SIZE_T i;
char buffer[80]; CHAR buffer[80];
ULONG divisor;
UCHAR lcr;
if (PortInitialized == FALSE) if (!PortInitialized)
{ {
if (PortInformation->BaudRate != 0) DefaultPort.BaudRate = PortInformation->BaudRate;
{
BaudRate = PortInformation->BaudRate;
}
else
{
BaudRate = DEFAULT_BAUD_RATE;
}
if (PortInformation->ComPort == 0) if (PortInformation->ComPort == 0)
{ {
if (KdpDoesComPortExist ((PUCHAR)BaseArray[2])) for (i = sizeof(BaseArray) / sizeof(BaseArray[0]) - 1; i > 0; i--)
{ {
PortBase = (PUCHAR)BaseArray[2]; if (KdpDoesComPortExist(BaseArray[i]))
ComPort = 2;
PortInformation->BaseAddress = (ULONG)PortBase;
PortInformation->ComPort = ComPort;
#ifndef NDEBUG
sprintf (buffer,
"\nSerial port COM%ld found at 0x%lx\n",
ComPort,
(ULONG)PortBase);
HalDisplayString (buffer);
#endif /* NDEBUG */
}
else if (KdpDoesComPortExist ((PUCHAR)BaseArray[1]))
{ {
PortBase = (PUCHAR)BaseArray[1]; DefaultPort.BaseAddress = BaseArray[i];
ComPort = 1; DefaultPort.ComPort = i;
PortInformation->BaseAddress = (ULONG)PortBase; PortInformation->BaseAddress = DefaultPort.BaseAddress;
PortInformation->ComPort = ComPort; PortInformation->ComPort = DefaultPort.ComPort;
#ifndef NDEBUG break;
sprintf (buffer,
"\nSerial port COM%ld found at 0x%lx\n",
ComPort,
(ULONG)PortBase);
HalDisplayString (buffer);
#endif /* NDEBUG */
}
else
{
sprintf (buffer,
"\nKernel Debugger: No COM port found!!!\n\n");
HalDisplayString (buffer);
return FALSE;
} }
} }
else if (i == 0)
{ {
if (KdpDoesComPortExist ((PUCHAR)BaseArray[PortInformation->ComPort])) sprintf(buffer,
{ "\nKernel Debugger: No COM port found!\n\n");
PortBase = (PUCHAR)BaseArray[PortInformation->ComPort]; HalDisplayString(buffer);
ComPort = PortInformation->ComPort;
PortInformation->BaseAddress = (ULONG)PortBase;
#ifndef NDEBUG
sprintf (buffer,
"\nSerial port COM%ld found at 0x%lx\n",
ComPort,
(ULONG)PortBase);
HalDisplayString (buffer);
#endif /* NDEBUG */
}
else
{
sprintf (buffer,
"\nKernel Debugger: No serial port found!!!\n\n");
HalDisplayString (buffer);
return FALSE; return FALSE;
} }
} }
@ -242,44 +223,12 @@ KdPortInitialize (
PortInitialized = TRUE; PortInitialized = TRUE;
} }
/* /* initialize port */
* set baud rate and data format (8N1) if (!KdPortInitializeEx(&DefaultPort, Unknown1, Unknown2))
*/ return FALSE;
/* turn on DTR and RTS */ /* set global info */
WRITE_PORT_UCHAR (SER_MCR(PortBase), SR_MCR_DTR | SR_MCR_RTS); *KdComPortInUse = (PUCHAR)DefaultPort.BaseAddress;
/* set DLAB */
lcr = READ_PORT_UCHAR (SER_LCR(PortBase)) | SR_LCR_DLAB;
WRITE_PORT_UCHAR (SER_LCR(PortBase), lcr);
/* set baud rate */
divisor = 115200 / BaudRate;
WRITE_PORT_UCHAR (SER_DLL(PortBase), (UCHAR)(divisor & 0xff));
WRITE_PORT_UCHAR (SER_DLM(PortBase), (UCHAR)((divisor >> 8) & 0xff));
/* reset DLAB and set 8N1 format */
WRITE_PORT_UCHAR (SER_LCR(PortBase),
SR_LCR_CS8 | SR_LCR_ST1 | SR_LCR_PNO);
/* read junk out of the RBR */
lcr = READ_PORT_UCHAR (SER_RBR(PortBase));
/*
* set global info
*/
*KdComPortInUse = PortBase;
/*
* print message to blue screen
*/
sprintf (buffer,
"\nKernel Debugger: COM%ld (Port 0x%lx) BaudRate %ld\n\n",
ComPort,
(ULONG)PortBase,
BaudRate);
HalDisplayString (buffer);
return TRUE; return TRUE;
} }
@ -287,91 +236,71 @@ KdPortInitialize (
/* HAL.KdPortInitializeEx */ /* HAL.KdPortInitializeEx */
BOOLEAN BOOLEAN
STDCALL NTAPI
KdPortInitializeEx ( KdPortInitializeEx(
PKD_PORT_INFORMATION PortInformation, IN PKD_PORT_INFORMATION PortInformation,
ULONG Unknown1, IN ULONG Unknown1,
ULONG Unknown2 IN ULONG Unknown2)
)
{ {
#ifdef _M_IX86 ULONG ComPortBase;
ULONG BaseArray[5] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8}; CHAR buffer[80];
#elif defined(_M_PPC)
ULONG BaseArray[5] = {0, 0x800003f8};
#endif
PUCHAR ComPortBase;
char buffer[80];
ULONG divisor; ULONG divisor;
UCHAR lcr; UCHAR lcr;
if (PortInformation->BaudRate == 0) if (PortInformation->BaudRate == 0)
{
PortInformation->BaudRate = DEFAULT_BAUD_RATE; PortInformation->BaudRate = DEFAULT_BAUD_RATE;
}
if (PortInformation->ComPort == 0) if (PortInformation->ComPort == 0)
return FALSE;
if (!KdpDoesComPortExist(BaseArray[PortInformation->ComPort]))
{ {
sprintf(buffer,
"\nKernel Debugger: Serial port not found!\n\n");
HalDisplayString(buffer);
return FALSE; return FALSE;
} }
else
{ ComPortBase = BaseArray[PortInformation->ComPort];
if (KdpDoesComPortExist ((PUCHAR)BaseArray[PortInformation->ComPort])) PortInformation->BaseAddress = ComPortBase;
{
ComPortBase = (PUCHAR)BaseArray[PortInformation->ComPort];
PortInformation->BaseAddress = (ULONG)ComPortBase;
#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",
PortInformation->ComPort, PortInformation->ComPort,
(ULONG)ComPortBase]; ComPortBase];
HalDisplayString (buffer); HalDisplayString(buffer);
#endif /* NDEBUG */ #endif /* NDEBUG */
}
else
{
sprintf (buffer,
"\nKernel Debugger: Serial port not found!!!\n\n");
HalDisplayString (buffer);
return FALSE;
}
}
/* /* set baud rate and data format (8N1) */
* set baud rate and data format (8N1)
*/
/* turn on DTR and RTS */ /* turn on DTR and RTS */
WRITE_PORT_UCHAR (SER_MCR(ComPortBase), SR_MCR_DTR | SR_MCR_RTS); WRITE_PORT_UCHAR(SER_MCR(ComPortBase), SR_MCR_DTR | SR_MCR_RTS);
/* set DLAB */ /* set DLAB */
lcr = READ_PORT_UCHAR (SER_LCR(ComPortBase)) | SR_LCR_DLAB; lcr = READ_PORT_UCHAR(SER_LCR(ComPortBase)) | SR_LCR_DLAB;
WRITE_PORT_UCHAR (SER_LCR(ComPortBase), lcr); WRITE_PORT_UCHAR(SER_LCR(ComPortBase), lcr);
/* set baud rate */ /* set baud rate */
divisor = 115200 / PortInformation->BaudRate; divisor = 115200 / PortInformation->BaudRate;
WRITE_PORT_UCHAR (SER_DLL(ComPortBase), (UCHAR)(divisor & 0xff)); WRITE_PORT_UCHAR(SER_DLL(ComPortBase), (UCHAR)(divisor & 0xff));
WRITE_PORT_UCHAR (SER_DLM(ComPortBase), (UCHAR)((divisor >> 8) & 0xff)); WRITE_PORT_UCHAR(SER_DLM(ComPortBase), (UCHAR)((divisor >> 8) & 0xff));
/* reset DLAB and set 8N1 format */ /* reset DLAB and set 8N1 format */
WRITE_PORT_UCHAR (SER_LCR(ComPortBase), WRITE_PORT_UCHAR(SER_LCR(ComPortBase),
SR_LCR_CS8 | SR_LCR_ST1 | SR_LCR_PNO); SR_LCR_CS8 | SR_LCR_ST1 | SR_LCR_PNO);
/* read junk out of the RBR */ /* read junk out of the RBR */
lcr = READ_PORT_UCHAR (SER_RBR(ComPortBase)); lcr = READ_PORT_UCHAR(SER_RBR(ComPortBase));
#ifndef NDEBUG #ifndef NDEBUG
/* print message to blue screen */
/* sprintf(buffer,
* print message to blue screen
*/
sprintf (buffer,
"\nKernel Debugger: COM%ld (Port 0x%lx) BaudRate %ld\n\n", "\nKernel Debugger: COM%ld (Port 0x%lx) BaudRate %ld\n\n",
PortInformation->ComPort, PortInformation->ComPort,
(ULONG)ComPortBase, ComPortBase,
PortInformation->BaudRate); PortInformation->BaudRate);
HalDisplayString (buffer); HalDisplayString(buffer);
#endif /* NDEBUG */ #endif /* NDEBUG */
return TRUE; return TRUE;
@ -380,37 +309,28 @@ KdPortInitializeEx (
/* HAL.KdPortGetByte */ /* HAL.KdPortGetByte */
BOOLEAN BOOLEAN
STDCALL NTAPI
KdPortGetByte ( KdPortGetByte(
PUCHAR ByteRecieved OUT PUCHAR ByteReceived)
)
{ {
if (PortInitialized == FALSE) if (!PortInitialized)
return FALSE;
if ((READ_PORT_UCHAR (SER_LSR(PortBase)) & SR_LSR_DR))
{
*ByteRecieved = READ_PORT_UCHAR (SER_RBR(PortBase));
return TRUE;
}
return FALSE; return FALSE;
return KdPortGetByteEx(&DefaultPort, ByteReceived);
} }
/* HAL.KdPortGetByteEx */ /* HAL.KdPortGetByteEx */
BOOLEAN BOOLEAN
STDCALL NTAPI
KdPortGetByteEx ( KdPortGetByteEx(
PKD_PORT_INFORMATION PortInformation, IN PKD_PORT_INFORMATION PortInformation,
PUCHAR ByteRecieved OUT PUCHAR ByteReceived)
)
{ {
PUCHAR ComPortBase = (PUCHAR)PortInformation->BaseAddress; PUCHAR ComPortBase = (PUCHAR)PortInformation->BaseAddress;
if ((READ_PORT_UCHAR (SER_LSR(ComPortBase)) & SR_LSR_DR)) if ((READ_PORT_UCHAR(SER_LSR(ComPortBase)) & SR_LSR_DR))
{ {
*ByteRecieved = READ_PORT_UCHAR (SER_RBR(ComPortBase)); *ByteReceived = READ_PORT_UCHAR(SER_RBR(ComPortBase));
return TRUE; return TRUE;
} }
@ -420,114 +340,96 @@ KdPortGetByteEx (
/* HAL.KdPortPollByte */ /* HAL.KdPortPollByte */
BOOLEAN BOOLEAN
STDCALL NTAPI
KdPortPollByte ( KdPortPollByte(
PUCHAR ByteRecieved OUT PUCHAR ByteReceived)
)
{ {
if (PortInitialized == FALSE) if (!PortInitialized)
return FALSE; return FALSE;
return KdPortPollByteEx(&DefaultPort, ByteReceived);
while ((READ_PORT_UCHAR (SER_LSR(PortBase)) & SR_LSR_DR) == 0)
;
*ByteRecieved = READ_PORT_UCHAR (SER_RBR(PortBase));
return TRUE;
} }
/* HAL.KdPortPollByteEx */ /* HAL.KdPortPollByteEx */
BOOLEAN BOOLEAN
STDCALL NTAPI
KdPortPollByteEx ( KdPortPollByteEx(
PKD_PORT_INFORMATION PortInformation, IN PKD_PORT_INFORMATION PortInformation,
PUCHAR ByteRecieved OUT PUCHAR ByteReceived)
)
{ {
PUCHAR ComPortBase = (PUCHAR)PortInformation->BaseAddress; PUCHAR ComPortBase = (PUCHAR)PortInformation->BaseAddress;
while ((READ_PORT_UCHAR (SER_LSR(ComPortBase)) & SR_LSR_DR) == 0) while ((READ_PORT_UCHAR(SER_LSR(ComPortBase)) & SR_LSR_DR) == 0)
; ;
*ByteRecieved = READ_PORT_UCHAR (SER_RBR(ComPortBase)); *ByteReceived = READ_PORT_UCHAR(SER_RBR(ComPortBase));
return TRUE; return TRUE;
} }
/* HAL.KdPortPutByte */ /* HAL.KdPortPutByte */
VOID VOID
STDCALL NTAPI
KdPortPutByte ( KdPortPutByte(
UCHAR ByteToSend IN UCHAR ByteToSend)
)
{ {
if (PortInitialized == FALSE) if (!PortInitialized)
return; return;
KdPortPutByteEx(&DefaultPort, ByteToSend);
while ((READ_PORT_UCHAR (SER_LSR(PortBase)) & SR_LSR_TBE) == 0)
;
WRITE_PORT_UCHAR (SER_THR(PortBase), ByteToSend);
} }
/* HAL.KdPortPutByteEx */ /* HAL.KdPortPutByteEx */
VOID VOID
STDCALL NTAPI
KdPortPutByteEx ( KdPortPutByteEx(
PKD_PORT_INFORMATION PortInformation, IN PKD_PORT_INFORMATION PortInformation,
UCHAR ByteToSend IN UCHAR ByteToSend)
)
{ {
PUCHAR ComPortBase = (PUCHAR)PortInformation->BaseAddress; PUCHAR ComPortBase = (PUCHAR)PortInformation->BaseAddress;
while ((READ_PORT_UCHAR (SER_LSR(ComPortBase)) & SR_LSR_TBE) == 0) while ((READ_PORT_UCHAR(SER_LSR(ComPortBase)) & SR_LSR_TBE) == 0)
; ;
WRITE_PORT_UCHAR (SER_THR(ComPortBase), ByteToSend); WRITE_PORT_UCHAR(SER_THR(ComPortBase), ByteToSend);
} }
/* HAL.KdPortRestore */ /* HAL.KdPortRestore */
VOID VOID
STDCALL NTAPI
KdPortRestore ( KdPortRestore(VOID)
VOID
)
{ {
UNIMPLEMENTED;
} }
/* HAL.KdPortSave */ /* HAL.KdPortSave */
VOID VOID
STDCALL NTAPI
KdPortSave ( KdPortSave(VOID)
VOID
)
{ {
UNIMPLEMENTED;
} }
/* HAL.KdPortDisableInterrupts */ /* HAL.KdPortDisableInterrupts */
BOOLEAN BOOLEAN
STDCALL NTAPI
KdPortDisableInterrupts() KdPortDisableInterrupts(VOID)
{ {
UCHAR ch; UCHAR ch;
if (PortInitialized == FALSE) if (!PortInitialized)
return FALSE; return FALSE;
ch = READ_PORT_UCHAR (SER_MCR (PortBase)); ch = READ_PORT_UCHAR(SER_MCR(DefaultPort.BaseAddress));
ch &= (~(SR_MCR_OUT1 | SR_MCR_OUT2)); ch &= (~(SR_MCR_OUT1 | SR_MCR_OUT2));
WRITE_PORT_UCHAR (SER_MCR (PortBase), ch); WRITE_PORT_UCHAR(SER_MCR(DefaultPort.BaseAddress), ch);
ch = READ_PORT_UCHAR (SER_IER (PortBase)); ch = READ_PORT_UCHAR(SER_IER(DefaultPort.BaseAddress));
ch &= (~SR_IER_ALL); ch &= (~SR_IER_ALL);
WRITE_PORT_UCHAR (SER_IER (PortBase), ch); WRITE_PORT_UCHAR(SER_IER(DefaultPort.BaseAddress), ch);
return TRUE; return TRUE;
} }
@ -535,23 +437,23 @@ KdPortDisableInterrupts()
/* HAL.KdPortEnableInterrupts */ /* HAL.KdPortEnableInterrupts */
BOOLEAN BOOLEAN
STDCALL NTAPI
KdPortEnableInterrupts() KdPortEnableInterrupts(VOID)
{ {
UCHAR ch; UCHAR ch;
if (PortInitialized == FALSE) if (PortInitialized == FALSE)
return FALSE; return FALSE;
ch = READ_PORT_UCHAR (SER_IER (PortBase)); ch = READ_PORT_UCHAR(SER_IER(DefaultPort.BaseAddress));
ch &= (~SR_IER_ALL); ch &= (~SR_IER_ALL);
ch |= SR_IER_ERDA; ch |= SR_IER_ERDA;
WRITE_PORT_UCHAR (SER_IER (PortBase), ch); WRITE_PORT_UCHAR(SER_IER(DefaultPort.BaseAddress), ch);
ch = READ_PORT_UCHAR (SER_MCR (PortBase)); ch = READ_PORT_UCHAR(SER_MCR(DefaultPort.BaseAddress));
ch &= (~SR_MCR_LOOP); ch &= (~SR_MCR_LOOP);
ch |= (SR_MCR_OUT1 | SR_MCR_OUT2); ch |= (SR_MCR_OUT1 | SR_MCR_OUT2);
WRITE_PORT_UCHAR (SER_MCR (PortBase), ch); WRITE_PORT_UCHAR(SER_MCR(DefaultPort.BaseAddress), ch);
return TRUE; return TRUE;
} }
@ -561,10 +463,11 @@ KdPortEnableInterrupts()
*/ */
NTSTATUS NTSTATUS
NTAPI NTAPI
KdDebuggerInitialize0(IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL) KdDebuggerInitialize0(
IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
{ {
/* FIXME: TODO */ UNIMPLEMENTED;
return STATUS_UNSUCCESSFUL; return STATUS_NOT_IMPLEMENTED;
} }
/* /*
@ -572,10 +475,11 @@ KdDebuggerInitialize0(IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
*/ */
NTSTATUS NTSTATUS
NTAPI NTAPI
KdDebuggerInitialize1(IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL) KdDebuggerInitialize1(
IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
{ {
/* FIXME: TODO */ UNIMPLEMENTED;
return STATUS_UNSUCCESSFUL; return STATUS_NOT_IMPLEMENTED;
} }
/* /*
@ -583,7 +487,8 @@ KdDebuggerInitialize1(IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL)
*/ */
NTSTATUS NTSTATUS
NTAPI NTAPI
KdSave(IN BOOLEAN SleepTransition) KdSave(
IN BOOLEAN SleepTransition)
{ {
/* Nothing to do on COM ports */ /* Nothing to do on COM ports */
return STATUS_SUCCESS; return STATUS_SUCCESS;
@ -594,7 +499,8 @@ KdSave(IN BOOLEAN SleepTransition)
*/ */
NTSTATUS NTSTATUS
NTAPI NTAPI
KdRestore(IN BOOLEAN SleepTransition) KdRestore(
IN BOOLEAN SleepTransition)
{ {
/* Nothing to do on COM ports */ /* Nothing to do on COM ports */
return STATUS_SUCCESS; return STATUS_SUCCESS;
@ -605,27 +511,29 @@ KdRestore(IN BOOLEAN SleepTransition)
*/ */
VOID VOID
NTAPI NTAPI
KdSendPacket(IN USHORT PacketType, KdSendPacket(
IN PSTRING Header, IN ULONG PacketType,
IN PSTRING Data OPTIONAL, IN PSTRING MessageHeader,
OUT PKD_CONTEXT Context) IN PSTRING MessageData,
IN OUT PKD_CONTEXT Context)
{ {
/* FIXME: TODO */ UNIMPLEMENTED;
return; return;
} }
/* /*
* @unimplemented * @unimplemented
*/ */
ULONG KDSTATUS
NTAPI NTAPI
KdReceivePacket(IN USHORT PacketType, KdReceivePacket(
OUT PSTRING Header, IN ULONG PacketType,
OUT PSTRING Data, OUT PSTRING MessageHeader,
OUT PUSHORT DataSize, OUT PSTRING MessageData,
OUT PKD_CONTEXT Context OPTIONAL) OUT PULONG DataLength,
IN OUT PKD_CONTEXT Context)
{ {
/* FIXME: TODO */ UNIMPLEMENTED;
return 0; return 0;
} }