Skip to content

Commit 3012af5

Browse files
committed
[CPORTLIB][FREELDR][KD][NTOS] Move duplicated UART settings into a common header
1 parent 73413d4 commit 3012af5

File tree

9 files changed

+65
-134
lines changed

9 files changed

+65
-134
lines changed

boot/freeldr/freeldr/include/comm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121

2222
#pragma once
2323

24+
#if DBG
2425
BOOLEAN Rs232PortInitialize(ULONG ComPort, ULONG BaudRate);
2526
BOOLEAN Rs232PortGetByte(PUCHAR ByteReceived);
2627
// BOOLEAN Rs232PortPollByte(PUCHAR ByteReceived);
2728
VOID Rs232PortPutByte(UCHAR ByteToSend);
29+
#endif
2830
BOOLEAN Rs232PortInUse(PUCHAR Base);

boot/freeldr/freeldr/lib/comm/rs232.c

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,13 @@
2424
/* INCLUDES *******************************************************************/
2525

2626
#include <freeldr.h>
27-
#include <cportlib/cportlib.h>
2827

2928
#if DBG
3029

31-
/* STATIC VARIABLES ***********************************************************/
32-
33-
#if defined(SARCH_PC98)
34-
#define DEFAULT_BAUD_RATE 9600
35-
#else
36-
#define DEFAULT_BAUD_RATE 19200
37-
#endif
38-
39-
#if defined(_M_IX86) || defined(_M_AMD64)
40-
#if defined(SARCH_PC98)
41-
static const ULONG BaseArray[] = {0, 0x30, 0x238};
42-
#else
43-
static const ULONG BaseArray[] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8};
44-
#endif
45-
#elif defined(_M_PPC)
46-
static const ULONG BaseArray[] = {0, 0x800003F8};
47-
#elif defined(_M_MIPS)
48-
static const ULONG BaseArray[] = {0, 0x80006000, 0x80007000};
49-
#elif defined(_M_ARM)
50-
static const ULONG BaseArray[] = {0, 0xF1012000};
51-
#else
52-
#error Unknown architecture
53-
#endif
30+
#include <cportlib/cportlib.h>
31+
#include <cportlib/uartinfo.h>
5432

55-
#define MAX_COM_PORTS (sizeof(BaseArray) / sizeof(BaseArray[0]) - 1)
33+
/* STATIC VARIABLES ***********************************************************/
5634

5735
/* The COM port must only be initialized once! */
5836
static ULONG Rs232ComPort = 0;

boot/freeldr/freeldr/lib/debug.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,8 @@ static UCHAR DbgChannels[DBG_CHANNELS_COUNT];
4343
ULONG DebugPort = RS232;
4444

4545
/* Serial debug connection */
46-
#if defined(SARCH_PC98)
47-
ULONG BaudRate = 9600;
48-
#else
49-
ULONG BaudRate = 115200;
50-
#endif
51-
46+
#include <cportlib/uartinfo.h>
47+
ULONG BaudRate = DEFAULT_DEBUG_BAUD_RATE;
5248
ULONG ComPort = 0; // The COM port initializer chooses the first available port starting from COM4 down to COM1.
5349
ULONG PortIrq = 0; // Not used at the moment.
5450

drivers/base/kdcom/kdcom.c

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,13 @@
88

99
#include "kddll.h"
1010

11-
#include <cportlib/cportlib.h>
1211
#include <arc/arc.h>
1312
#include <stdio.h>
1413
#include <stdlib.h>
1514
#include <ndk/halfuncs.h>
1615

17-
/* Serial debug connection */
18-
#if defined(SARCH_PC98)
19-
#define DEFAULT_DEBUG_PORT 2 /* COM2 */
20-
#define DEFAULT_DEBUG_COM1_IRQ 4
21-
#define DEFAULT_DEBUG_COM2_IRQ 5
22-
#define DEFAULT_DEBUG_BAUD_RATE 9600
23-
#define DEFAULT_BAUD_RATE 9600
24-
#else
25-
#define DEFAULT_DEBUG_PORT 2 /* COM2 */
26-
#define DEFAULT_DEBUG_COM1_IRQ 4
27-
#define DEFAULT_DEBUG_COM2_IRQ 3
28-
#define DEFAULT_DEBUG_BAUD_RATE 115200
29-
#define DEFAULT_BAUD_RATE 19200
30-
#endif
31-
32-
#if defined(_M_IX86) || defined(_M_AMD64)
33-
#if defined(SARCH_PC98)
34-
const ULONG BaseArray[] = {0, 0x30, 0x238};
35-
#else
36-
const ULONG BaseArray[] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8};
37-
#endif
38-
#elif defined(_M_PPC)
39-
const ULONG BaseArray[] = {0, 0x800003F8};
40-
#elif defined(_M_MIPS)
41-
const ULONG BaseArray[] = {0, 0x80006000, 0x80007000};
42-
#elif defined(_M_ARM)
43-
const ULONG BaseArray[] = {0, 0xF1012000};
44-
#else
45-
#error Unknown architecture
46-
#endif
47-
48-
#define MAX_COM_PORTS (sizeof(BaseArray) / sizeof(BaseArray[0]) - 1)
16+
#include <cportlib/cportlib.h>
17+
#include <cportlib/uartinfo.h>
4918

5019
/* GLOBALS ********************************************************************/
5120

drivers/base/kdgdb/kdcom.c

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,12 @@
77

88
#include "kdgdb.h"
99

10-
#include <cportlib/cportlib.h>
1110
#include <arc/arc.h>
1211
#include <stdlib.h>
1312
#include <ndk/halfuncs.h>
1413

15-
/* Serial debug connection */
16-
#if defined(SARCH_PC98)
17-
#define DEFAULT_DEBUG_PORT 2 /* COM2 */
18-
#define DEFAULT_DEBUG_COM1_IRQ 4
19-
#define DEFAULT_DEBUG_COM2_IRQ 5
20-
#define DEFAULT_DEBUG_BAUD_RATE 9600
21-
#define DEFAULT_BAUD_RATE 9600
22-
#else
23-
#define DEFAULT_DEBUG_PORT 2 /* COM2 */
24-
#define DEFAULT_DEBUG_COM1_IRQ 4
25-
#define DEFAULT_DEBUG_COM2_IRQ 3
26-
#define DEFAULT_DEBUG_BAUD_RATE 115200
27-
#define DEFAULT_BAUD_RATE 19200
28-
#endif
29-
30-
#if defined(_M_IX86) || defined(_M_AMD64)
31-
#if defined(SARCH_PC98)
32-
const ULONG BaseArray[] = {0, 0x30, 0x238};
33-
#else
34-
const ULONG BaseArray[] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8};
35-
#endif
36-
#elif defined(_M_PPC)
37-
const ULONG BaseArray[] = {0, 0x800003F8};
38-
#elif defined(_M_MIPS)
39-
const ULONG BaseArray[] = {0, 0x80006000, 0x80007000};
40-
#elif defined(_M_ARM)
41-
const ULONG BaseArray[] = {0, 0xF1012000};
42-
#else
43-
#error Unknown architecture
44-
#endif
45-
46-
#define MAX_COM_PORTS (sizeof(BaseArray) / sizeof(BaseArray[0]) - 1)
14+
#include <cportlib/cportlib.h>
15+
#include <cportlib/uartinfo.h>
4716

4817
/* GLOBALS ********************************************************************/
4918

ntoskrnl/kd/i386/kdserial.c

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* FILE: ntoskrnl/kd/i386/kdbg.c
55
* PURPOSE: Serial i/o functions for the kernel debugger.
66
* PROGRAMMER: Alex Ionescu
7-
* Hervé Poussineau
7+
* Hervé Poussineau
88
*/
99

1010
/* INCLUDES *****************************************************************/
@@ -13,29 +13,8 @@
1313
#define NDEBUG
1414
#include <debug.h>
1515

16-
#if defined(SARCH_PC98)
17-
#define DEFAULT_BAUD_RATE 9600
18-
#else
19-
#define DEFAULT_BAUD_RATE 19200
20-
#endif
21-
22-
#if defined(_M_IX86) || defined(_M_AMD64)
23-
#if defined(SARCH_PC98)
24-
const ULONG BaseArray[] = {0, 0x30, 0x238};
25-
#else
26-
const ULONG BaseArray[] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8};
27-
#endif
28-
#elif defined(_M_PPC)
29-
const ULONG BaseArray[] = {0, 0x800003F8};
30-
#elif defined(_M_MIPS)
31-
const ULONG BaseArray[] = {0, 0x80006000, 0x80007000};
32-
#elif defined(_M_ARM)
33-
const ULONG BaseArray[] = {0, 0xF1012000};
34-
#else
35-
#error Unknown architecture
36-
#endif
37-
38-
#define MAX_COM_PORTS (sizeof(BaseArray) / sizeof(BaseArray[0]) - 1)
16+
//#include <cportlib/cportlib.h>
17+
#include <cportlib/uartinfo.h>
3918

4019
/* STATIC VARIABLES ***********************************************************/
4120

ntoskrnl/kd/kd.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,6 @@ KdpDebugLogInit(
7676

7777
/* KD GLOBALS ****************************************************************/
7878

79-
/* Serial debug connection */
80-
#if defined(SARCH_PC98)
81-
#define DEFAULT_DEBUG_PORT 2 /* COM2 */
82-
#define DEFAULT_DEBUG_COM1_IRQ 4 /* COM1 IRQ */
83-
#define DEFAULT_DEBUG_COM2_IRQ 5 /* COM2 IRQ */
84-
#define DEFAULT_DEBUG_BAUD_RATE 9600 /* 9600 Baud */
85-
#else
86-
#define DEFAULT_DEBUG_PORT 2 /* COM2 */
87-
#define DEFAULT_DEBUG_COM1_IRQ 4 /* COM1 IRQ */
88-
#define DEFAULT_DEBUG_COM2_IRQ 3 /* COM2 IRQ */
89-
#define DEFAULT_DEBUG_BAUD_RATE 115200 /* 115200 Baud */
90-
#endif
91-
9279
/* KD Native Modes */
9380
// #define KdScreen 0
9481
// #define KdSerial 1

ntoskrnl/kd/kdio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#ifdef KDBG
1717
#include "../kdbg/kdb.h"
1818
#endif
19+
#include <cportlib/uartinfo.h>
1920

2021
#define NDEBUG
2122
#include <debug.h>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* PROJECT: ReactOS ComPort Library
3+
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4+
* or MIT (https://spdx.org/licenses/MIT)
5+
* PURPOSE: Default UART Settings
6+
* COPYRIGHT: Copyright 2022-2026 Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
7+
*/
8+
9+
#pragma once
10+
11+
/* Serial debug connection */
12+
#if defined(SARCH_PC98)
13+
#define DEFAULT_DEBUG_PORT 2 /* COM2 */
14+
#define DEFAULT_DEBUG_COM1_IRQ 4
15+
#define DEFAULT_DEBUG_COM2_IRQ 5
16+
#define DEFAULT_DEBUG_BAUD_RATE 9600
17+
#else
18+
#define DEFAULT_DEBUG_PORT 2 /* COM2 */
19+
#define DEFAULT_DEBUG_COM1_IRQ 4
20+
#define DEFAULT_DEBUG_COM2_IRQ 3
21+
#define DEFAULT_DEBUG_BAUD_RATE 115200
22+
#endif
23+
24+
/* Serial connection */
25+
#if defined(SARCH_PC98)
26+
#define DEFAULT_BAUD_RATE 9600
27+
#else
28+
#define DEFAULT_BAUD_RATE 19200
29+
#endif
30+
31+
#if defined(_M_IX86) || defined(_M_AMD64)
32+
#if defined(SARCH_PC98)
33+
static const ULONG BaseArray[] = {0, 0x30, 0x238};
34+
#else
35+
static const ULONG BaseArray[] = {0, 0x3F8, 0x2F8, 0x3E8, 0x2E8};
36+
#endif
37+
#elif defined(_M_PPC)
38+
static const ULONG BaseArray[] = {0, 0x800003F8};
39+
#elif defined(_M_MIPS)
40+
static const ULONG BaseArray[] = {0, 0x80006000, 0x80007000};
41+
#elif defined(_M_ARM)
42+
static const ULONG BaseArray[] = {0, 0xF1012000};
43+
// #define QEMUUART ((ULONG)0x09000000)
44+
#else
45+
#error Unknown architecture
46+
#endif
47+
48+
#define MAX_COM_PORTS (sizeof(BaseArray) / sizeof(BaseArray[0]) - 1)
49+
50+
/* EOF */

0 commit comments

Comments
 (0)