cons.c revision 1.2
11.2Schristos/* $NetBSD: cons.c,v 1.2 2014/03/26 17:47:10 christos Exp $ */ 21.1Suwe 31.1Suwe/*- 41.1Suwe * Copyright (c) 2005 NONAKA Kimihiro 51.1Suwe * All rights reserved. 61.1Suwe * 71.1Suwe * Redistribution and use in source and binary forms, with or without 81.1Suwe * modification, are permitted provided that the following conditions 91.1Suwe * are met: 101.1Suwe * 1. Redistributions of source code must retain the above copyright 111.1Suwe * notice, this list of conditions and the following disclaimer. 121.1Suwe * 2. Redistributions in binary form must reproduce the above copyright 131.1Suwe * notice, this list of conditions and the following disclaimer in the 141.1Suwe * documentation and/or other materials provided with the distribution. 151.1Suwe * 161.1Suwe * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 171.1Suwe * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 181.1Suwe * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 191.1Suwe * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 201.1Suwe * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 211.1Suwe * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 221.1Suwe * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 231.1Suwe * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 241.1Suwe * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 251.1Suwe * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 261.1Suwe * SUCH DAMAGE. 271.1Suwe */ 281.1Suwe 291.1Suwe#include <lib/libsa/stand.h> 301.1Suwe#include <lib/libkern/libkern.h> 311.1Suwe 321.1Suwe#include <sys/bootblock.h> 331.1Suwe 341.1Suwe#include "boot.h" 351.1Suwe#include "cons.h" 361.1Suwe 371.1Suwe#ifndef CONSPEED 381.1Suwe#define CONSPEED 9600 391.1Suwe#endif 401.1Suwe 411.1Suwe#define POLL_FREQ 10 421.1Suwe 431.1Suweextern struct landisk_boot_params boot_params; 441.1Suwe 451.1Suwestatic int consdev = CONSDEV_BIOSCONS; 461.1Suwe 471.1Suwe/*ARGSUSED*/ 481.1Suweint 491.1Suwecninit(int dev) 501.1Suwe{ 511.1Suwe 521.1Suwe switch (dev) { 531.1Suwe default: 541.1Suwe case CONSDEV_BIOSCONS: 551.1Suwe break; 561.1Suwe 571.1Suwe case CONSDEV_SCIF: 581.1Suwe switch (boot_params.bp_conspeed) { 591.1Suwe default: 601.1Suwe scif_init(CONSPEED); 611.1Suwe break; 621.1Suwe 631.1Suwe case 9600: 641.1Suwe#if 0 651.1Suwe case 19200: 661.1Suwe case 38400: 671.1Suwe case 57600: 681.1Suwe case 115200: 691.1Suwe#endif 701.1Suwe scif_init(boot_params.bp_conspeed); 711.1Suwe break; 721.1Suwe } 731.1Suwe break; 741.1Suwe } 751.1Suwe consdev = dev; 761.1Suwe 771.1Suwe return (0); 781.1Suwe} 791.1Suwe 801.1Suweint 811.1Suwegetchar(void) 821.1Suwe{ 831.1Suwe 841.1Suwe switch (consdev) { 851.1Suwe default: 861.1Suwe case CONSDEV_BIOSCONS: 871.1Suwe return bioscons_getc(); 881.1Suwe 891.1Suwe case CONSDEV_SCIF: 901.1Suwe return scif_getc(); 911.1Suwe } 921.1Suwe} 931.1Suwe 941.1Suwevoid 951.1Suweputchar(int c) 961.1Suwe{ 971.1Suwe 981.1Suwe switch (consdev) { 991.1Suwe default: 1001.1Suwe case CONSDEV_BIOSCONS: 1011.1Suwe bioscons_putc(c); 1021.1Suwe break; 1031.1Suwe 1041.1Suwe case CONSDEV_SCIF: 1051.1Suwe if (c == '\n') 1061.1Suwe scif_putc('\r'); 1071.1Suwe scif_putc(c); 1081.1Suwe break; 1091.1Suwe } 1101.1Suwe} 1111.1Suwe 1121.1Suwe/*ARGSUSED*/ 1131.1Suweint 1141.1Suweiskey(int intr) 1151.1Suwe{ 1161.1Suwe 1171.1Suwe switch (consdev) { 1181.1Suwe default: 1191.1Suwe case CONSDEV_BIOSCONS: 1201.1Suwe return scif_status2(); 1211.1Suwe 1221.1Suwe case CONSDEV_SCIF: 1231.1Suwe return scif_status(); 1241.1Suwe } 1251.1Suwe} 1261.1Suwe 1271.1Suwechar 1281.1Suweawaitkey(int timeout, int tell) 1291.1Suwe{ 1301.1Suwe int i; 1311.1Suwe char c = 0; 1321.1Suwe 1331.1Suwe i = timeout * POLL_FREQ; 1341.1Suwe 1351.1Suwe for (;;) { 1361.1Suwe if (tell && (i % POLL_FREQ) == 0) { 1371.1Suwe char numbuf[20]; 1381.1Suwe int len, j; 1391.1Suwe 1401.2Schristos len = snprintf(numbuf, sizeof(numbuf), 1411.2Schristos "%d ", i / POLL_FREQ); 1421.1Suwe for (j = 0; j < len; j++) 1431.1Suwe numbuf[len + j] = '\b'; 1441.1Suwe numbuf[len + j] = '\0'; 1451.1Suwe printf(numbuf); 1461.1Suwe } 1471.1Suwe if (iskey(1)) { 1481.1Suwe /* flush input buffer */ 1491.1Suwe while (iskey(0)) 1501.1Suwe c = getchar(); 1511.1Suwe if (c == 0) 1521.1Suwe c = -1; 1531.1Suwe goto out; 1541.1Suwe } 1551.1Suwe if (i--) { 1561.1Suwe delay(1000 / POLL_FREQ); 1571.1Suwe } else { 1581.1Suwe break; 1591.1Suwe } 1601.1Suwe } 1611.1Suwe 1621.1Suweout: 1631.1Suwe if (tell) 1641.1Suwe printf("0 \n"); 1651.1Suwe 1661.1Suwe return (c); 1671.1Suwe} 168