mbr/Makefile: run checksize on the proper binaries...
[syslinux.git] / memdump / serial.c
blob902dcc3d7e86789595a0710a7bae3530ed8b15ea
1 #include "mystuff.h"
2 #include "ymsend.h"
3 #include "io.h"
5 enum {
6 THR = 0,
7 RBR = 0,
8 DLL = 0,
9 DLM = 1,
10 IER = 1,
11 IIR = 2,
12 FCR = 2,
13 LCR = 3,
14 MCR = 4,
15 LSR = 5,
16 MSR = 6,
17 SCR = 7,
20 int serial_init(struct serial_if *sif)
22 uint16_t port = sif->port;
23 uint8_t dll, dlm, lcr;
25 /* Set 115200n81 */
26 outb(0x83, port+LCR);
27 outb(0x01, port+DLL);
28 outb(0x00, port+DLM);
29 (void)inb(port+IER); /* Synchronize */
30 dll = inb(port+DLL);
31 dlm = inb(port+DLM);
32 lcr = inb(port+LCR);
33 outb(0x03, port+LCR);
34 (void)inb(port+IER); /* Synchronize */
36 if (dll != 0x01 || dlm != 0x00 || lcr != 0x83)
37 return -1; /* This doesn't look like a serial port */
39 /* Disable interrupts */
40 outb(port+IER, 0);
42 /* Enable 16550A FIFOs if available */
43 outb(port+FCR, 0x01); /* Enable FIFO */
44 (void)inb(port+IER); /* Synchronize */
45 if (inb(port+IIR) < 0xc0)
46 outb(port+FCR, 0x00); /* Disable FIFOs if non-functional */
47 (void)inb(port+IER); /* Synchronize */
49 return 0;
52 void serial_write(struct serial_if *sif, const void *data, size_t n)
54 uint16_t port = sif->port;
55 const char *p = data;
56 uint8_t lsr;
58 while (n--) {
59 do {
60 lsr = inb(port+LSR);
61 } while (!(lsr & 0x20));
63 outb(*p++, port+THR);
67 void serial_read(struct serial_if *sif, void *data, size_t n)
69 uint16_t port = sif->port;
70 char *p = data;
71 uint8_t lsr;
73 while (n--) {
74 do {
75 lsr = inb(port+LSR);
76 } while (!(lsr & 0x01));
78 *p++ = inb(port+RBR);