// Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
// Copyright (C) 2002 MandrakeSoft S.A.
//
-// This file may be distributed under the terms of the GNU GPLv3 license.
+// This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "biosvar.h" // struct bregs
+#include "biosvar.h" // SET_BDA
#include "util.h" // debug_enter
+#include "bregs.h" // struct bregs
/****************************************************************
* COM ports
****************************************************************/
+static u16
+detect_serial(u16 port, u8 timeout, u8 count)
+{
+ outb(0x02, port+1);
+ if (inb(port+1) != 0x02)
+ return 0;
+ if (inb(port+2) != 0x02)
+ return 0;
+ outb(0x00, port+1);
+ SET_BDA(port_com[count], port);
+ SET_BDA(com_timeout[count], timeout);
+ return 1;
+}
+
+void
+serial_setup()
+{
+ if (! CONFIG_SERIAL)
+ return;
+ 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);
+
+ // Equipment word bits 9..11 determing # serial ports
+ u16 eqb = GET_BDA(equipment_list_flags);
+ SET_BDA(equipment_list_flags, (eqb & 0xf1ff) | (count << 9));
+}
+
static u16
getComAddr(struct bregs *regs)
{
if (regs->dx >= 4) {
- set_cf(regs, 1);
+ set_fail(regs);
return 0;
}
u16 addr = GET_BDA(port_com[regs->dx]);
if (! addr)
- set_cf(regs, 1);
+ set_fail(regs);
return addr;
}
+// SERIAL - INITIALIZE PORT
static void
handle_1400(struct bregs *regs)
{
outb(regs->al & 0x1F, addr+3);
regs->ah = inb(addr+5);
regs->al = inb(addr+6);
- set_cf(regs, 0);
+ set_success(regs);
}
+// SERIAL - WRITE CHARACTER TO PORT
static void
handle_1401(struct bregs *regs)
{
regs->ah = inb(addr+5);
if (!timeout)
regs->ah |= 0x80;
- set_cf(regs, 0);
+ set_success(regs);
}
+// SERIAL - READ CHARACTER FROM PORT
static void
handle_1402(struct bregs *regs)
{
} else {
regs->ah = inb(addr+5);
}
- set_cf(regs, 0);
+ set_success(regs);
}
+// SERIAL - GET PORT STATUS
static void
handle_1403(struct bregs *regs)
{
return;
regs->ah = inb(addr+5);
regs->al = inb(addr+6);
- set_cf(regs, 0);
+ set_success(regs);
}
static void
handle_14XX(struct bregs *regs)
{
// Unsupported
- set_cf(regs, 1);
+ set_fail(regs);
}
// INT 14h Serial Communications Service Entry Point
-void VISIBLE
+void VISIBLE16
handle_14(struct bregs *regs)
{
- debug_enter(regs);
+ debug_enter(regs, DEBUG_HDL_14);
+ if (! CONFIG_SERIAL) {
+ handle_14XX(regs);
+ return;
+ }
irq_enable();
case 0x03: handle_1403(regs); break;
default: handle_14XX(regs); break;
}
- debug_exit(regs);
}
+// XXX - Baud Rate Generator Table
+u8 BaudTable[16] VAR16FIXED(0xe729);
+
/****************************************************************
* LPT ports
****************************************************************/
+static u16
+detect_parport(u16 port, u8 timeout, u8 count)
+{
+ // clear input mode
+ outb(inb(port+2) & 0xdf, port+2);
+
+ outb(0xaa, port);
+ if (inb(port) != 0xaa)
+ // Not present
+ return 0;
+ SET_BDA(port_lpt[count], port);
+ SET_BDA(lpt_timeout[count], timeout);
+ return 1;
+}
+
+void
+lpt_setup()
+{
+ if (! CONFIG_LPT)
+ return;
+ dprintf(3, "init lpt\n");
+
+ u16 count = 0;
+ count += detect_parport(0x378, 0x14, count);
+ count += detect_parport(0x278, 0x14, count);
+
+ // Equipment word bits 14..15 determing # parallel ports
+ u16 eqb = GET_BDA(equipment_list_flags);
+ SET_BDA(equipment_list_flags, (eqb & 0x3fff) | (count << 14));
+}
+
static u16
getLptAddr(struct bregs *regs)
{
if (regs->dx >= 3) {
- set_cf(regs, 1);
+ set_fail(regs);
return 0;
}
u16 addr = GET_BDA(port_lpt[regs->dx]);
if (! addr)
- set_cf(regs, 1);
+ set_fail(regs);
return addr;
}
regs->ah = (val8 ^ 0x48);
if (!timeout)
regs->ah |= 0x01;
- set_cf(regs, 0);
+ set_success(regs);
}
// INT 17 - PRINTER - WRITE CHARACTER
outb(val8 | 0x01, addr+2); // send strobe
nop();
outb(val8 & ~0x01, addr+2);
+ // XXX - implement better timeout code.
while (((inb(addr+1) & 0x40) == 0x40) && (timeout))
timeout--;
handle_17XX(struct bregs *regs)
{
// Unsupported
- set_cf(regs, 1);
+ set_fail(regs);
}
// INT17h : Printer Service Entry Point
-void VISIBLE
+void VISIBLE16
handle_17(struct bregs *regs)
{
- debug_enter(regs);
+ debug_enter(regs, DEBUG_HDL_17);
+ if (! CONFIG_LPT) {
+ handle_17XX(regs);
+ return;
+ }
irq_enable();
case 0x02: handle_1702(regs); break;
default: handle_17XX(regs); break;
}
- debug_exit(regs);
}