1 // 16bit code to handle serial and printer services.
3 // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2002 MandrakeSoft S.A.
6 // This file may be distributed under the terms of the GNU GPLv3 license.
8 #include "biosvar.h" // struct bregs
9 #include "util.h" // debug_enter
12 /****************************************************************
14 ****************************************************************/
17 detect_serial(u16 port, u8 timeout, u8 count)
20 if (inb(port+1) != 0x02)
22 if (inb(port+2) != 0x02)
25 SET_BDA(port_com[count], port);
26 SET_BDA(com_timeout[count], timeout);
34 count += detect_serial(0x3f8, 0x0a, count);
35 count += detect_serial(0x2f8, 0x0a, count);
36 count += detect_serial(0x3e8, 0x0a, count);
37 count += detect_serial(0x2e8, 0x0a, count);
39 // Equipment word bits 9..11 determing # serial ports
40 u16 eqb = GET_BDA(equipment_list_flags);
41 SET_BDA(equipment_list_flags, (eqb & 0xf1ff) | (count << 9));
45 getComAddr(struct bregs *regs)
51 u16 addr = GET_BDA(port_com[regs->dx]);
57 // SERIAL - INITIALIZE PORT
59 handle_1400(struct bregs *regs)
61 u16 addr = getComAddr(regs);
64 outb(inb(addr+3) | 0x80, addr+3);
65 if ((regs->al & 0xE0) == 0) {
69 u16 val16 = 0x600 >> ((regs->al & 0xE0) >> 5);
70 outb(val16 & 0xFF, addr);
71 outb(val16 >> 8, addr+1);
73 outb(regs->al & 0x1F, addr+3);
74 regs->ah = inb(addr+5);
75 regs->al = inb(addr+6);
79 // SERIAL - WRITE CHARACTER TO PORT
81 handle_1401(struct bregs *regs)
83 u16 addr = getComAddr(regs);
86 u16 timer = GET_BDA(timer_counter);
87 u16 timeout = GET_BDA(com_timeout[regs->dx]);
88 while (((inb(addr+5) & 0x60) != 0x60) && (timeout)) {
89 u16 val16 = GET_BDA(timer_counter);
97 regs->ah = inb(addr+5);
103 // SERIAL - READ CHARACTER FROM PORT
105 handle_1402(struct bregs *regs)
107 u16 addr = getComAddr(regs);
110 u16 timer = GET_BDA(timer_counter);
111 u16 timeout = GET_BDA(com_timeout[regs->dx]);
112 while (((inb(addr+5) & 0x01) == 0) && (timeout)) {
113 u16 val16 = GET_BDA(timer_counter);
114 if (val16 != timer) {
121 regs->al = inb(addr);
123 regs->ah = inb(addr+5);
128 // SERIAL - GET PORT STATUS
130 handle_1403(struct bregs *regs)
132 u16 addr = getComAddr(regs);
135 regs->ah = inb(addr+5);
136 regs->al = inb(addr+6);
141 handle_14XX(struct bregs *regs)
147 // INT 14h Serial Communications Service Entry Point
149 handle_14(struct bregs *regs)
156 case 0x00: handle_1400(regs); break;
157 case 0x01: handle_1401(regs); break;
158 case 0x02: handle_1402(regs); break;
159 case 0x03: handle_1403(regs); break;
160 default: handle_14XX(regs); break;
165 /****************************************************************
167 ****************************************************************/
170 detect_parport(u16 port, u8 timeout, u8 count)
173 outb(inb(port+2) & 0xdf, port+2);
176 if (inb(port) != 0xaa)
179 SET_BDA(port_lpt[count], port);
180 SET_BDA(lpt_timeout[count], timeout);
188 count += detect_parport(0x378, 0x14, count);
189 count += detect_parport(0x278, 0x14, count);
191 // Equipment word bits 14..15 determing # parallel ports
192 u16 eqb = GET_BDA(equipment_list_flags);
193 SET_BDA(equipment_list_flags, (eqb & 0x3fff) | (count << 14));
197 getLptAddr(struct bregs *regs)
203 u16 addr = GET_BDA(port_lpt[regs->dx]);
210 lpt_ret(struct bregs *regs, u16 addr, u16 timeout)
212 u8 val8 = inb(addr+1);
213 regs->ah = (val8 ^ 0x48);
219 // INT 17 - PRINTER - WRITE CHARACTER
221 handle_1700(struct bregs *regs)
223 u16 addr = getLptAddr(regs);
226 u16 timeout = GET_BDA(lpt_timeout[regs->dx]) << 8;
228 outb(regs->al, addr);
229 u8 val8 = inb(addr+2);
230 outb(val8 | 0x01, addr+2); // send strobe
232 outb(val8 & ~0x01, addr+2);
233 while (((inb(addr+1) & 0x40) == 0x40) && (timeout))
236 lpt_ret(regs, addr, timeout);
239 // INT 17 - PRINTER - INITIALIZE PORT
241 handle_1701(struct bregs *regs)
243 u16 addr = getLptAddr(regs);
246 u16 timeout = GET_BDA(lpt_timeout[regs->dx]) << 8;
248 u8 val8 = inb(addr+2);
249 outb(val8 & ~0x04, addr+2); // send init
251 outb(val8 | 0x04, addr+2);
253 lpt_ret(regs, addr, timeout);
256 // INT 17 - PRINTER - GET STATUS
258 handle_1702(struct bregs *regs)
260 u16 addr = getLptAddr(regs);
263 u16 timeout = GET_BDA(lpt_timeout[regs->dx]) << 8;
265 lpt_ret(regs, addr, timeout);
269 handle_17XX(struct bregs *regs)
275 // INT17h : Printer Service Entry Point
277 handle_17(struct bregs *regs)
284 case 0x00: handle_1700(regs); break;
285 case 0x01: handle_1701(regs); break;
286 case 0x02: handle_1702(regs); break;
287 default: handle_17XX(regs); break;