#define PORT_DMA2_MODE_REG 0x00d6
#define PORT_DMA2_MASTER_CLEAR 0x00da
#define PORT_MATH_CLEAR 0x00f0
+#define PORT_SERIAL4 0x02e8
+#define PORT_SERIAL2 0x02f8
+#define PORT_SERIAL3 0x03e8
#define PORT_FD_DOR 0x03f2
#define PORT_FD_STATUS 0x03f4
#define PORT_FD_DATA 0x03f5
#define PORT_HD_DATA 0x03f6
#define PORT_FD_DIR 0x03f7
+#define PORT_SERIAL1 0x03f8
#define PORT_PCI_CMD 0x0cf8
#define PORT_PCI_DATA 0x0cfc
#define PORT_BIOS_DEBUG 0x0402
#define PORT_SMB_BASE 0xb100
#define PORT_BIOS_APM 0x8900
+// Serial port offsets
+#define SEROFF_DATA 0
+#define SEROFF_DLL 0
+#define SEROFF_IER 1
+#define SEROFF_DLH 1
+#define SEROFF_IIR 2
+#define SEROFF_LCR 3
+#define SEROFF_LSR 5
+#define SEROFF_MSR 6
+
// PORT_A20 bitdefs
#define A20_ENABLE_BIT 0x02
#include "config.h" // CONFIG_*
#include "biosvar.h" // GET_GLOBAL
-#define DEBUG_PORT 0x03f8
+#define DEBUG_PORT PORT_SERIAL1
#define DEBUG_TIMEOUT 100000
void
return;
// setup for serial logging: 8N1
u8 oldparam, newparam = 0x03;
- oldparam = inb(DEBUG_PORT+3);
- outb(newparam, DEBUG_PORT+3);
+ oldparam = inb(DEBUG_PORT+SEROFF_LCR);
+ outb(newparam, DEBUG_PORT+SEROFF_LCR);
// Disable irqs
u8 oldier, newier = 0;
- oldier = inb(DEBUG_PORT+1);
- outb(newier, DEBUG_PORT+1);
+ oldier = inb(DEBUG_PORT+SEROFF_IER);
+ outb(newier, DEBUG_PORT+SEROFF_IER);
if (oldparam != newparam || oldier != newier)
dprintf(1, "Changing serial settings was %x/%x now %x/%x\n"
debug_serial(char c)
{
int timeout = DEBUG_TIMEOUT;
- while ((inb(DEBUG_PORT+5) & 0x60) != 0x60)
+ while ((inb(DEBUG_PORT+SEROFF_LSR) & 0x60) != 0x60)
if (!timeout--)
// Ran out of time.
return;
- outb(c, DEBUG_PORT);
+ outb(c, DEBUG_PORT+SEROFF_DATA);
}
// Show a character on the screen.
static u16
detect_serial(u16 port, u8 timeout, u8 count)
{
- outb(0x02, port+1);
- if (inb(port+1) != 0x02)
+ outb(0x02, port+SEROFF_IER);
+ u8 ier = inb(port+SEROFF_IER);
+ if (ier != 0x02)
return 0;
- if (inb(port+2) != 0x02)
+ u8 iir = inb(port+SEROFF_IIR);
+ if ((iir & 0x3f) != 0x02)
return 0;
- outb(0x00, port+1);
+
+ outb(0x00, port+SEROFF_IER);
SET_BDA(port_com[count], port);
SET_BDA(com_timeout[count], timeout);
return 1;
dprintf(3, "init serial\n");
u16 count = 0;
- count += detect_serial(0x3f8, 0x0a, count);
- count += detect_serial(0x2f8, 0x0a, count);
- count += detect_serial(0x3e8, 0x0a, count);
- count += detect_serial(0x2e8, 0x0a, count);
+ count += detect_serial(PORT_SERIAL1, 0x0a, count);
+ count += detect_serial(PORT_SERIAL2, 0x0a, count);
+ count += detect_serial(PORT_SERIAL3, 0x0a, count);
+ count += detect_serial(PORT_SERIAL4, 0x0a, count);
dprintf(1, "Found %d serial ports\n", count);
// Equipment word bits 9..11 determing # serial ports
u16 addr = getComAddr(regs);
if (!addr)
return;
- outb(inb(addr+3) | 0x80, addr+3);
+ outb(inb(addr+SEROFF_LCR) | 0x80, addr+SEROFF_LCR);
if ((regs->al & 0xE0) == 0) {
- outb(0x17, addr);
- outb(0x04, addr+1);
+ outb(0x17, addr+SEROFF_DLL);
+ outb(0x04, addr+SEROFF_DLH);
} else {
u16 val16 = 0x600 >> ((regs->al & 0xE0) >> 5);
- outb(val16 & 0xFF, addr);
- outb(val16 >> 8, addr+1);
+ outb(val16 & 0xFF, addr+SEROFF_DLL);
+ outb(val16 >> 8, addr+SEROFF_DLH);
}
- outb(regs->al & 0x1F, addr+3);
- regs->ah = inb(addr+5);
- regs->al = inb(addr+6);
+ outb(regs->al & 0x1F, addr+SEROFF_LCR);
+ regs->ah = inb(addr+SEROFF_LSR);
+ regs->al = inb(addr+SEROFF_MSR);
set_success(regs);
}
return;
u16 timer = GET_BDA(timer_counter);
u16 timeout = GET_BDA(com_timeout[regs->dx]);
- while (((inb(addr+5) & 0x60) != 0x60) && (timeout)) {
+ while (((inb(addr+SEROFF_LSR) & 0x60) != 0x60) && (timeout)) {
u16 val16 = GET_BDA(timer_counter);
if (val16 != timer) {
timer = val16;
}
}
if (timeout)
- outb(regs->al, addr);
- regs->ah = inb(addr+5);
+ outb(regs->al, addr+SEROFF_DATA);
+ regs->ah = inb(addr+SEROFF_LSR);
if (!timeout)
regs->ah |= 0x80;
set_success(regs);
return;
u16 timer = GET_BDA(timer_counter);
u16 timeout = GET_BDA(com_timeout[regs->dx]);
- while (((inb(addr+5) & 0x01) == 0) && (timeout)) {
+ while (((inb(addr+SEROFF_LSR) & 0x01) == 0) && (timeout)) {
u16 val16 = GET_BDA(timer_counter);
if (val16 != timer) {
timer = val16;
}
if (timeout) {
regs->ah = 0;
- regs->al = inb(addr);
+ regs->al = inb(addr+SEROFF_DATA);
} else {
- regs->ah = inb(addr+5);
+ regs->ah = inb(addr+SEROFF_LSR);
}
set_success(regs);
}
u16 addr = getComAddr(regs);
if (!addr)
return;
- regs->ah = inb(addr+5);
- regs->al = inb(addr+6);
+ regs->ah = inb(addr+SEROFF_LSR);
+ regs->al = inb(addr+SEROFF_MSR);
set_success(regs);
}