@samitouri / QOSamiQemu / commits / 336af956e8

hw/char/serial: Add constants for Line Control Register

Substitute some magic numbers by named constants for slightly improved readability. Signed-off-by: Bernhard Beschow <shentey@gmail.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Message-ID: <20260305220911.131508-10-shentey@gmail.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Bernhard Beschow committed Mar 5, 2026 at 23:09 UTC 336af956e8fd56b4db9e8f431ca3e1b13f846f0a
1 file changed +11 -6
hw/char/serial.c
+11 -6
@@ -39,6 +39,11 @@
39 #include "hw/core/qdev-properties-system.h"
40
41 #define UART_LCR_DLAB 0x80 /* Divisor latch access bit */
42 +#define UART_LCR_SB 0x40 /* Set break */
43 +#define UART_LCR_EPS 0x10 /* Even parity select */
44 +#define UART_LCR_PEN 0x08 /* Parity enable */
45 +#define UART_LCR_NSTB 0x04 /* Number of stop bits */
46 +#define UART_LCR_WLS 0x03 /* Word length select */
47
48 #define UART_IER_MSI 0x08 /* Enable Modem status interrupt */
49 #define UART_IER_RLSI 0x04 /* Enable receiver line status interrupt */
@@ -153,23 +158,23 @@ static void serial_update_parameters(SerialState *s)
158
159 /* Start bit. */
160 frame_size = 1;
156 - if (s->lcr & 0x08) {
161 + if (s->lcr & UART_LCR_PEN) {
162 /* Parity bit. */
163 frame_size++;
159 - if (s->lcr & 0x10)
164 + if (s->lcr & UART_LCR_EPS)
165 parity = 'E';
166 else
167 parity = 'O';
168 } else {
169 parity = 'N';
170 }
166 - if (s->lcr & 0x04) {
171 + if (s->lcr & UART_LCR_NSTB) {
172 stop_bits = 2;
173 } else {
174 stop_bits = 1;
175 }
176
172 - data_bits = (s->lcr & 0x03) + 5;
177 + data_bits = (s->lcr & UART_LCR_WLS) + 5;
178 frame_size += data_bits + stop_bits;
179 /* Zero divisor should give about 3500 baud */
180 speed = (s->divider == 0) ? 3500 : (float) s->baudbase / s->divider;
@@ -430,7 +435,7 @@ static void serial_ioport_write(void *opaque, hwaddr addr, uint64_t val,
435 int break_enable;
436 s->lcr = val;
437 serial_update_parameters(s);
433 - break_enable = (val >> 6) & 1;
438 + break_enable = !!(val & UART_LCR_SB);
439 if (break_enable != s->last_break_enable) {
440 s->last_break_enable = break_enable;
441 qemu_chr_fe_ioctl(&s->chr, CHR_IOCTL_SERIAL_SET_BREAK,
@@ -676,7 +681,7 @@ static int serial_post_load(void *opaque, int version_id)
681 }
682 }
683
679 - s->last_break_enable = (s->lcr >> 6) & 1;
684 + s->last_break_enable = !!(s->lcr & UART_LCR_SB);
685 /* Initialize fcr via setter to perform essential side-effects */
686 serial_write_fcr(s, s->fcr_vmstate);
687 serial_update_parameters(s);