2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/kd/i386/kdbg.c
5 * PURPOSE: Serial i/o functions for the kernel debugger.
6 * PROGRAMMER: Alex Ionescu
10 /* INCLUDES *****************************************************************/
17 #define DEFAULT_BAUD_RATE 19200
19 #if defined(_M_IX86) || defined(_M_AMD64)
20 const ULONG BaseArray
[] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8};
22 const ULONG BaseArray
[] = {0, 0x800003F8};
23 #elif defined(_M_MIPS)
24 const ULONG BaseArray
[] = {0, 0x80006000, 0x80007000};
26 const ULONG BaseArray
[] = {0, 0xF1012000};
28 #error Unknown architecture
31 #define MAX_COM_PORTS (sizeof(BaseArray) / sizeof(BaseArray[0]) - 1)
33 /* STATIC VARIABLES ***********************************************************/
35 // static CPPORT DefaultPort = {0, 0, 0};
37 /* The COM port must only be initialized once! */
38 // static BOOLEAN PortInitialized = FALSE;
40 /* REACTOS FUNCTIONS **********************************************************/
44 KdDebuggerInitialize1(
45 IN PLOADER_PARAMETER_BLOCK LoaderBlock OPTIONAL
)
47 return STATUS_NOT_IMPLEMENTED
;
53 IN PCPPORT PortInformation
,
54 IN ULONG ComPortNumber
)
58 #if 0 // Deactivated because never used in fact (was in KdPortInitialize but we use KdPortInitializeEx)
60 * Find the port if needed
65 DefaultPort
.BaudRate
= PortInformation
->BaudRate
;
67 if (ComPortNumber
== 0)
70 * Start enumerating COM ports from the last one to the first one,
71 * and break when we find a valid port.
72 * If we reach the first element of the list, the invalid COM port,
73 * then it means that no valid port was found.
75 for (ComPortNumber
= MAX_COM_PORTS
; ComPortNumber
> 0; ComPortNumber
--)
77 if (CpDoesPortExist(UlongToPtr(BaseArray
[ComPortNumber
])))
79 PortInformation
->Address
= DefaultPort
.Address
= BaseArray
[ComPortNumber
];
83 if (ComPortNumber
== 0)
85 HalDisplayString("\r\nKernel Debugger: No COM port found!\r\n\r\n");
90 PortInitialized
= TRUE
;
97 Status
= CpInitialize(PortInformation
,
98 (ComPortNumber
== 0 ? PortInformation
->Address
99 : UlongToPtr(BaseArray
[ComPortNumber
])),
100 (PortInformation
->BaudRate
== 0 ? DEFAULT_BAUD_RATE
101 : PortInformation
->BaudRate
));
102 if (!NT_SUCCESS(Status
))
104 HalDisplayString("\r\nKernel Debugger: Serial port not found!\r\n\r\n");
112 /* Print message to blue screen */
114 "\r\nKernel Debugger: Serial port found: COM%ld (Port 0x%p) BaudRate %ld\r\n\r\n",
116 PortInformation
->Address
,
117 PortInformation
->BaudRate
);
118 HalDisplayString(buffer
);
122 /* Set global info */
123 KdComPortInUse
= DefaultPort
.Address
;
132 IN PCPPORT PortInformation
,
133 OUT PUCHAR ByteReceived
)
135 return (CpGetByte(PortInformation
, ByteReceived
, FALSE
, FALSE
) == CP_GET_SUCCESS
);
141 IN PCPPORT PortInformation
,
144 CpPutByte(PortInformation
, ByteToSend
);