1 /* $OpenBSD: cons.c,v 1.2 2010/02/16 21:28:39 miod Exp $ */ 2 3 /* 4 * Copyright (c) 2010 Miodrag Vallat. 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #include <lib/libkern/libkern.h> 20 #include "libsa.h" 21 #include <dev/cons.h> 22 #include <machine/cpu.h> 23 #include <machine/pmon.h> 24 25 /* 26 * PMON console 27 */ 28 29 void 30 pmon_cnprobe(struct consdev *cn) 31 { 32 cn->cn_pri = CN_HIGHPRI; 33 } 34 35 void 36 pmon_cninit(struct consdev *cn) 37 { 38 } 39 40 int 41 pmon_cngetc(dev_t dev) 42 { 43 /* 44 * PMON does not give us a getc routine. So try to get a whole line 45 * and return it char by char, trying not to lose the \n. Kind 46 * of ugly but should work. 47 * 48 * Note that one could theoretically use pmon_read(STDIN, &c, 1) 49 * but the value of STDIN within PMON is not a constant and there 50 * does not seem to be a way of letting us know which value to use. 51 */ 52 static char buf[1 + PMON_MAXLN]; 53 static char *bufpos = buf; 54 int c; 55 56 if (*bufpos == '\0') { 57 bufpos = buf; 58 if (pmon_gets(buf) == NULL) { 59 /* either an empty line or EOF, assume the former */ 60 strlcpy(buf, "\n", sizeof buf); 61 } else { 62 /* put back the \n sign */ 63 buf[strlen(buf)] = '\n'; 64 } 65 } 66 67 c = (int)*bufpos; 68 if ((dev & 0x80) == 0) { 69 bufpos++; 70 if (bufpos - buf > PMON_MAXLN) { 71 bufpos = buf; 72 *bufpos = '\0'; 73 } 74 } 75 76 return c; 77 } 78 79 void 80 pmon_cnputc(dev_t dev, int c) 81 { 82 if (c == '\n') 83 pmon_printf("\n"); 84 else 85 pmon_printf("%c", c); 86 } 87