31 #define COM1ADDR 0x3f8
32 #define COM2ADDR 0x2f8
33 #define COM3ADDR 0x3e8
34 #define COM4ADDR 0x3e0
54 #define COMTICK (1843200/16)
55 #define SPEED_TOLERANCE 30
58 #define IER_ERXRDY 0x1
59 #define IER_ETXRDY 0x2
64 #define IIR_FIFO_MASK 0xc0
66 #define IIR_NOPEND 0x1
69 #define IIR_RXTOUT 0xc
75 #define FIFO_ENABLE 0x01
76 #define FIFO_RCV_RST 0x02
77 #define FIFO_XMT_RST 0x04
78 #define FIFO_DMA_MODE 0x08
79 #define FIFO_TRIGGER_1 0x00
80 #define FIFO_TRIGGER_4 0x40
81 #define FIFO_TRIGGER_8 0x80
82 #define FIFO_TRIGGER_14 0xc0
85 #define CFCR_DLAB 0x80
86 #define CFCR_SBREAK 0x40
87 #define CFCR_PZERO 0x30
88 #define CFCR_PONE 0x20
89 #define CFCR_PEVEN 0x10
90 #define CFCR_PODD 0x00
91 #define CFCR_PENAB 0x08
92 #define CFCR_STOPB 0x04
93 #define CFCR_8BITS 0x03
94 #define CFCR_7BITS 0x02
95 #define CFCR_6BITS 0x01
96 #define CFCR_5BITS 0x00
99 #define MCR_LOOPBACK 0x10
100 #define MCR_IENABLE 0x08
106 #define LSR_RCV_FIFO 0x80
107 #define LSR_TSRE 0x40
108 #define LSR_TXRDY 0x20
113 #define LSR_RXRDY 0x01
114 #define LSR_RCV_MASK 0x1f
121 #define MSR_DDCD 0x08
122 #define MSR_TERI 0x04
123 #define MSR_DDSR 0x02
124 #define MSR_DCTS 0x01
133 #define FIFO_TRIGGER FIFO_TRIGGER_4
148 static size_t cnts[NCNT];
149 static char *cntnames[NCNT] =
152 "mlsc",
"nopend",
"txrdy",
"?3",
153 "rxrdy",
"?5",
"rls",
"?7",
154 "?8",
"?9",
"?a",
"?b",
155 "rxtout",
"?d",
"?e",
"?f",
157 "rxcnt",
"txcnt",
"stray",
"swoflo"
160 #define COUNT(x) cnts[x]++
166 #define ICU_BASE 0x20
167 #define ICU_OCW2 (ICU_BASE + 0)
168 #define ICU_MASK (ICU_BASE + 1)
210 COM1ADDR, 4, 0, NULL, 0, 0,
"", 0, 0, 0, 0, 0, 0, 0, 0
214 COM2ADDR, 3, 0, NULL, 0, 0,
"", 0, 0, 0, 0, 0, 0, 0, 0
218 COM3ADDR, 4, 0, NULL, 0, 0,
"", 0, 0, 0, 0, 0, 0, 0, 0
222 COM4ADDR, 3, 0, NULL, 0, 0,
"", 0, 0, 0, 0, 0, 0, 0, 0
230 static int dos_write (
struct serial *scb,
const void *buf,
size_t count);
236 #define inb(p,a) inportb((p)->base + (a))
237 #define outb(p,a,v) outportb((p)->base + (a), (v))
238 #define disable() asm volatile ("cli");
239 #define enable() asm volatile ("sti");
247 if (port->
count == 0)
275 unsigned char iir, lsr, c;
351 #define ISRNAME(x) dos_comisr##x
352 #define ISR(x) static void ISRNAME(x)(void) {dos_comisr(x);}
357 typedef
void (*isr_t) (
void);
359 static isr_t isrs[
NINTR] =
385 _go32_dpmi_get_real_mode_interrupt_vector (vec, &intr->
old_rmhandler);
389 if (_go32_dpmi_allocate_real_mode_callback_iret (&intr->
new_rmhandler,
395 if (_go32_dpmi_set_real_mode_interrupt_vector (vec, &intr->
new_rmhandler))
401 _go32_dpmi_get_protected_mode_interrupt_vector (vec, &intr->
old_pmhandler);
407 if (_go32_dpmi_set_protected_mode_interrupt_vector (vec,
426 unsigned int irq, vec;
439 _go32_dpmi_set_real_mode_interrupt_vector (vec, &intr->
old_rmhandler);
443 _go32_dpmi_set_protected_mode_interrupt_vector (vec, &intr->
old_pmhandler);
456 if (strncasecmp (name,
"/dev/", 5) == 0)
458 else if (strncasecmp (name,
"\\dev\\", 5) == 0)
461 if (strlen (name) != 4 || strncasecmp (name,
"com", 3) != 0)
467 if (name[3] <
'1' || name[3] >
'4')
489 for (i = 0; i < 17; i++)
569 if (!(intrupt = port->
intrupt))
588 "Serial input overruns occurred.\n");
590 port->
fifo ?
"cannot" :
"needs a 16550 to",
616 then = rawclock () + (timeout *
RAWHZ);
619 if (timeout >= 0 && (rawclock () - then) >= 0)
642 if (scb->
fd >= 3 || !isatty (scb->
fd))
712 #define divrnd(n, q) (((n) * 2 / (q) + 1) / 2)
790 size_t fifosize = port->
fifo ? 16 : 1;
793 const char *str = buf;
798 cnt = fifosize > count ? count : fifosize;
802 #ifdef UART_FIFO_WORKS
807 for ( ; cnt > 0; cnt--, count--)
814 then = rawclock () +
RAWHZ;
817 if ((rawclock () - then) >= 0)
839 then = rawclock () +
RAWHZ / 4;
840 while ((rawclock () - then) < 0)
892 printf_filtered (
"Port:\tCOM%ld (%sactive)\n", (
long)(port - ports) + 1,
903 for (i = 0; i < NCNT; i++)
926 Set COM1 base i/o port address."),
_(
"\
927 Show COM1 base i/o port address."), NULL,
933 Set COM1 interrupt request."),
_(
"\
934 Show COM1 interrupt request."), NULL,
940 Set COM2 base i/o port address."),
_(
"\
941 Show COM2 base i/o port address."), NULL,
947 Set COM2 interrupt request."),
_(
"\
948 Show COM2 interrupt request."), NULL,
954 Set COM3 base i/o port address."),
_(
"\
955 Show COM3 base i/o port address."), NULL,
961 Set COM3 interrupt request."),
_(
"\
962 Show COM3 interrupt request."), NULL,
968 Set COM4 base i/o port address."),
_(
"\
969 Show COM4 base i/o port address."), NULL,
975 Set COM4 interrupt request."),
_(
"\
976 Show COM4 interrupt request."), NULL,
982 _(
"Print DOS serial port status."));
static void dos_info(char *arg, int from_tty)
static int dos_noflush_set_tty_state(struct serial *scb, serial_ttystate new_ttystate, serial_ttystate old_ttystate)
_go32_dpmi_seginfo old_pmhandler
_go32_dpmi_seginfo new_rmhandler
static int dos_readchar(struct serial *scb, int timeout)
static int dos_write(struct serial *scb, const void *buf, size_t count)
void add_setshow_zinteger_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
static int dos_getc(volatile struct dos_ttystate *port)
initialize_file_ftype _initialize_ser_dos
_go32_dpmi_seginfo new_pmhandler
static int dos_sendbreak(struct serial *scb)
unsigned char icu_oldmask
_go32_dpmi_registers regs
static struct dos_ttystate ports[4]
static void dos_raw(struct serial *scb)
static void dos_print_tty_state(struct serial *scb, serial_ttystate ttystate, struct ui_file *stream)
static int dos_setbaudrate(struct serial *scb, int rate)
static int dos_open(struct serial *scb, const char *name)
void printf_filtered(const char *format,...)
struct cmd_list_element * setlist
static int dos_set_tty_state(struct serial *scb, serial_ttystate state)
void initialize_file_ftype(void)
static void dos_comisr(int irq)
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t err
unsigned char cbuf[CBSIZE]
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
struct cmd_list_element * showlist
struct cmd_list_element * add_info(const char *name, cmd_cfunc_ftype *fun, const char *doc)
static struct intrupt intrupts[NINTR]
static void dos_close(struct serial *scb)
static int dos_noop(struct serial *scb)
static serial_ttystate dos_copy_tty_state(struct serial *scb, serial_ttystate ttystate)
static struct intrupt * dos_hookirq(unsigned int irq)
#define SERIAL_1_AND_A_HALF_STOPBITS
int gdb_pipe(int pdes[2])
#define SERIAL_1_STOPBITS
static int dos_setstopbits(struct serial *scb, int num)
const char const char int
_go32_dpmi_seginfo old_rmhandler
#define SERIAL_2_STOPBITS
void serial_add_interface(const struct serial_ops *optable)
static serial_ttystate dos_get_tty_state(struct serial *scb)
struct ui_file * gdb_stderr
struct dos_ttystate * port
static void dos_unhookirq(struct intrupt *intr)
static int dos_putc(int c, struct dos_ttystate *port)
static int dos_flush_input(struct serial *scb)
static int dos_baudconv(int rate)