comconsole.c revision 39441
138465Smsmith/* 238465Smsmith * Copyright (c) 1998 Michael Smith (msmith@freebsd.org) 338465Smsmith * 438465Smsmith * Redistribution and use in source and binary forms, with or without 538465Smsmith * modification, are permitted provided that the following conditions 638465Smsmith * are met: 738465Smsmith * 1. Redistributions of source code must retain the above copyright 838465Smsmith * notice, this list of conditions and the following disclaimer. 938465Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1038465Smsmith * notice, this list of conditions and the following disclaimer in the 1138465Smsmith * documentation and/or other materials provided with the distribution. 1238465Smsmith * 1338465Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1438465Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1538465Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1638465Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1738465Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1838465Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 1938465Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2038465Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2138465Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2238465Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2338465Smsmith * SUCH DAMAGE. 2438465Smsmith * 2538465Smsmith * From Id: probe_keyboard.c,v 1.13 1997/06/09 05:10:55 bde Exp 2638465Smsmith * 2739441Smsmith * $Id: comconsole.c,v 1.1.1.1 1998/08/21 03:17:41 msmith Exp $ 2838465Smsmith */ 2938465Smsmith 3038465Smsmith#include <stand.h> 3139441Smsmith#include <bootstrap.h> 3239441Smsmith#include <btxv86.h> 3339441Smsmith#include "libi386.h" 3438465Smsmith 3538465Smsmithstatic void comc_probe(struct console *cp); 3638465Smsmithstatic int comc_init(int arg); 3739441Smsmithstatic void comc_putchar(int c); 3839441Smsmithstatic int comc_getchar(void); 3939441Smsmithstatic int comc_ischar(void); 4038465Smsmith 4138465Smsmithstruct console comconsole = { 4238465Smsmith "comconsole", 4338465Smsmith "BIOS serial port", 4438465Smsmith 0, 4538465Smsmith comc_probe, 4638465Smsmith comc_init, 4739441Smsmith comc_putchar, 4839441Smsmith comc_getchar, 4939441Smsmith comc_ischar 5038465Smsmith}; 5138465Smsmith 5239441Smsmith#define BIOS_COMPORT 0 5339441Smsmith 5438465Smsmithstatic void 5538465Smsmithcomc_probe(struct console *cp) 5638465Smsmith{ 5738465Smsmith /* XXX check the BIOS equipment list? */ 5838465Smsmith cp->c_flags |= (C_PRESENTIN | C_PRESENTOUT); 5938465Smsmith} 6038465Smsmith 6138465Smsmithstatic int 6238465Smsmithcomc_init(int arg) 6338465Smsmith{ 6439441Smsmith v86.ctl = V86_FLAGS; 6539441Smsmith v86.addr = 0x14; 6639441Smsmith v86.eax = 0xe3; /* 9600N81 */ 6739441Smsmith v86.edx = BIOS_COMPORT; /* XXX take as arg, or use env var? */ 6839441Smsmith v86int(); 6939441Smsmith return(v86.efl & 1); 7038465Smsmith} 7138465Smsmith 7239441Smsmithstatic void 7339441Smsmithcomc_putchar(int c) 7439441Smsmith{ 7539441Smsmith v86.ctl = 0; 7639441Smsmith v86.addr = 0x14; 7739441Smsmith v86.eax = 0x100 | c; 7839441Smsmith v86int(); 7939441Smsmith} 8039441Smsmith 8138465Smsmithstatic int 8239441Smsmithcomc_getchar(void) 8338465Smsmith{ 8439441Smsmith if (comc_ischar()) { 8539441Smsmith v86.ctl = 0; 8639441Smsmith v86.addr = 0x14; 8739441Smsmith v86.eax = 0x300; 8839441Smsmith v86int(); 8939441Smsmith return(v86.eax); 9038465Smsmith } else { 9138465Smsmith return(-1); 9238465Smsmith } 9338465Smsmith} 9439441Smsmith 9539441Smsmithstatic int 9639441Smsmithcomc_ischar(void) 9739441Smsmith{ 9839441Smsmith v86.ctl = 0; 9939441Smsmith v86.addr = 0x14; 10039441Smsmith v86.eax = 0x200; 10139441Smsmith v86int(); 10239441Smsmith return(v86.eax & 0x1); 10339441Smsmith} 104