}
void
-serial_setup()
+serial_setup(void)
{
if (! CONFIG_SERIAL)
return;
getComAddr(struct bregs *regs)
{
if (regs->dx >= 4) {
- set_fail(regs);
+ set_invalid(regs);
return 0;
}
u16 addr = GET_BDA(port_com[regs->dx]);
if (! addr)
- set_fail(regs);
+ set_invalid(regs);
return addr;
}
u16 addr = getComAddr(regs);
if (!addr)
return;
- u16 timer = GET_BDA(timer_counter);
- u16 timeout = GET_BDA(com_timeout[regs->dx]);
- while (((inb(addr+SEROFF_LSR) & 0x60) != 0x60) && (timeout)) {
- u16 val16 = GET_BDA(timer_counter);
- if (val16 != timer) {
- timer = val16;
- timeout--;
+ u32 end = calc_future_timer_ticks(GET_BDA(com_timeout[regs->dx]));
+ for (;;) {
+ u8 lsr = inb(addr+SEROFF_LSR);
+ if ((lsr & 0x60) == 0x60) {
+ // Success - can write data
+ outb(regs->al, addr+SEROFF_DATA);
+ // XXX - reread lsr?
+ regs->ah = lsr;
+ break;
}
+ if (check_timer(end)) {
+ // Timed out - can't write data.
+ regs->ah = lsr | 0x80;
+ break;
+ }
+ yield();
}
- if (timeout)
- outb(regs->al, addr+SEROFF_DATA);
- regs->ah = inb(addr+SEROFF_LSR);
- if (!timeout)
- regs->ah |= 0x80;
set_success(regs);
}
u16 addr = getComAddr(regs);
if (!addr)
return;
- u16 timer = GET_BDA(timer_counter);
- u16 timeout = GET_BDA(com_timeout[regs->dx]);
- while (((inb(addr+SEROFF_LSR) & 0x01) == 0) && (timeout)) {
- u16 val16 = GET_BDA(timer_counter);
- if (val16 != timer) {
- timer = val16;
- timeout--;
+ u32 end = calc_future_timer_ticks(GET_BDA(com_timeout[regs->dx]));
+ for (;;) {
+ u8 lsr = inb(addr+SEROFF_LSR);
+ if (lsr & 0x01) {
+ // Success - can read data
+ regs->al = inb(addr+SEROFF_DATA);
+ regs->ah = lsr;
+ break;
}
- }
- if (timeout) {
- regs->ah = 0;
- regs->al = inb(addr+SEROFF_DATA);
- } else {
- regs->ah = inb(addr+SEROFF_LSR);
+ if (check_timer(end)) {
+ // Timed out - can't read data.
+ regs->ah = lsr | 0x80;
+ break;
+ }
+ yield();
}
set_success(regs);
}
static void
handle_14XX(struct bregs *regs)
{
- // Unsupported
- set_fail(regs);
+ set_unimplemented(regs);
}
// INT 14h Serial Communications Service Entry Point
return;
}
- irq_enable();
-
switch (regs->ah) {
case 0x00: handle_1400(regs); break;
case 0x01: handle_1401(regs); break;
}
void
-lpt_setup()
+lpt_setup(void)
{
if (! CONFIG_LPT)
return;
dprintf(3, "init lpt\n");
u16 count = 0;
- count += detect_parport(0x378, 0x14, count);
- count += detect_parport(0x278, 0x14, count);
+ count += detect_parport(PORT_LPT1, 0x14, count);
+ count += detect_parport(PORT_LPT2, 0x14, count);
dprintf(1, "Found %d lpt ports\n", count);
// Equipment word bits 14..15 determing # parallel ports
getLptAddr(struct bregs *regs)
{
if (regs->dx >= 3) {
- set_fail(regs);
+ set_invalid(regs);
return 0;
}
u16 addr = GET_BDA(port_lpt[regs->dx]);
if (! addr)
- set_fail(regs);
+ set_invalid(regs);
return addr;
}
-static void
-lpt_ret(struct bregs *regs, u16 addr, u16 timeout)
-{
- u8 val8 = inb(addr+1);
- regs->ah = (val8 ^ 0x48);
- if (!timeout)
- regs->ah |= 0x01;
- set_success(regs);
-}
-
// INT 17 - PRINTER - WRITE CHARACTER
static void
handle_1700(struct bregs *regs)
u16 addr = getLptAddr(regs);
if (!addr)
return;
- u16 timeout = GET_BDA(lpt_timeout[regs->dx]) << 8;
+
+ u32 end = calc_future_timer_ticks(GET_BDA(lpt_timeout[regs->dx]));
outb(regs->al, addr);
u8 val8 = inb(addr+2);
outb(val8 | 0x01, addr+2); // send strobe
- nop();
+ udelay(5);
outb(val8 & ~0x01, addr+2);
- // XXX - implement better timeout code.
- while (((inb(addr+1) & 0x40) == 0x40) && (timeout))
- timeout--;
- lpt_ret(regs, addr, timeout);
+ for (;;) {
+ u8 v = inb(addr+1);
+ if (!(v & 0x40)) {
+ // Success
+ regs->ah = v ^ 0x48;
+ break;
+ }
+ if (check_timer(end)) {
+ // Timeout
+ regs->ah = (v ^ 0x48) | 0x01;
+ break;
+ }
+ yield();
+ }
+
+ set_success(regs);
}
// INT 17 - PRINTER - INITIALIZE PORT
u16 addr = getLptAddr(regs);
if (!addr)
return;
- u16 timeout = GET_BDA(lpt_timeout[regs->dx]) << 8;
u8 val8 = inb(addr+2);
outb(val8 & ~0x04, addr+2); // send init
- nop();
+ udelay(5);
outb(val8 | 0x04, addr+2);
- lpt_ret(regs, addr, timeout);
+ regs->ah = inb(addr+1) ^ 0x48;
+ set_success(regs);
}
// INT 17 - PRINTER - GET STATUS
u16 addr = getLptAddr(regs);
if (!addr)
return;
- u16 timeout = GET_BDA(lpt_timeout[regs->dx]) << 8;
-
- lpt_ret(regs, addr, timeout);
+ regs->ah = inb(addr+1) ^ 0x48;
+ set_success(regs);
}
static void
handle_17XX(struct bregs *regs)
{
- // Unsupported
- set_fail(regs);
+ set_unimplemented(regs);
}
// INT17h : Printer Service Entry Point
return;
}
- irq_enable();
-
switch (regs->ah) {
case 0x00: handle_1700(regs); break;
case 0x01: handle_1701(regs); break;