| 1 |
/* |
| 2 |
* Copyright (c) 1995-1994 The University of Utah and |
| 3 |
* the Computer Systems Laboratory at the University of Utah (CSL). |
| 4 |
* All rights reserved. |
| 5 |
* |
| 6 |
* Permission to use, copy, modify and distribute this software is hereby |
| 7 |
* granted provided that (1) source code retains these copyright, permission, |
| 8 |
* and disclaimer notices, and (2) redistributions including binaries |
| 9 |
* reproduce the notices in supporting documentation, and (3) all advertising |
| 10 |
* materials mentioning features or use of this software display the following |
| 11 |
* acknowledgement: ``This product includes software developed by the |
| 12 |
* Computer Systems Laboratory at the University of Utah.'' |
| 13 |
* |
| 14 |
* THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS |
| 15 |
* IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF |
| 16 |
* ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. |
| 17 |
* |
| 18 |
* CSL requests users of this software to return to [email protected] any |
| 19 |
* improvements that they make and grant CSL redistribution rights. |
| 20 |
* |
| 21 |
* Author: Bryan Ford, University of Utah CSL |
| 22 |
*/ |
| 23 |
|
| 24 |
#if ENABLE_IMMEDIATE_CONSOLE |
| 25 |
|
| 26 |
#include <device/cons.h> |
| 27 |
#include <mach/boolean.h> |
| 28 |
#include <i386/vm_param.h> |
| 29 |
#include <string.h> |
| 30 |
|
| 31 |
/* This is a special "feature" (read: kludge) |
| 32 |
intended for use only for kernel debugging. |
| 33 |
It enables an extremely simple console output mechanism |
| 34 |
that sends text straight to CGA/EGA/VGA video memory. |
| 35 |
It has the nice property of being functional right from the start, |
| 36 |
so it can be used to debug things that happen very early |
| 37 |
before any devices are initialized. */ |
| 38 |
|
| 39 |
boolean_t immediate_console_enable = TRUE; |
| 40 |
|
| 41 |
/* |
| 42 |
* XXX we assume that pcs *always* have a console |
| 43 |
*/ |
| 44 |
int |
| 45 |
immc_cnprobe(struct consdev *cp) |
| 46 |
{ |
| 47 |
int maj, unit, pri; |
| 48 |
|
| 49 |
maj = 0; |
| 50 |
unit = 0; |
| 51 |
pri = CN_INTERNAL; |
| 52 |
|
| 53 |
cp->cn_dev = makedev(maj, unit); |
| 54 |
cp->cn_pri = pri; |
| 55 |
return 0; |
| 56 |
} |
| 57 |
|
| 58 |
int |
| 59 |
immc_cninit(struct consdev *cp) |
| 60 |
{ |
| 61 |
return 0; |
| 62 |
} |
| 63 |
|
| 64 |
int immc_cnmaygetc(void) |
| 65 |
{ |
| 66 |
return -1; |
| 67 |
} |
| 68 |
|
| 69 |
int |
| 70 |
immc_cngetc(dev_t dev, int wait) |
| 71 |
{ |
| 72 |
if (wait) { |
| 73 |
int c; |
| 74 |
while ((c = immc_cnmaygetc()) < 0) |
| 75 |
continue; |
| 76 |
return c; |
| 77 |
} |
| 78 |
else |
| 79 |
return immc_cnmaygetc(); |
| 80 |
} |
| 81 |
|
| 82 |
int |
| 83 |
immc_cnputc(dev_t dev, int c) |
| 84 |
{ |
| 85 |
static int ofs = -1; |
| 86 |
|
| 87 |
if (!immediate_console_enable) |
| 88 |
return -1; |
| 89 |
if (ofs < 0 || ofs >= 80) |
| 90 |
{ |
| 91 |
ofs = 0; |
| 92 |
immc_cnputc(dev, '\n'); |
| 93 |
} |
| 94 |
|
| 95 |
if (c == '\n') |
| 96 |
{ |
| 97 |
memmove((void *) phystokv(0xb8000), |
| 98 |
(void *) phystokv(0xb8000+80*2), 80*2*24); |
| 99 |
memset((void *) phystokv((0xb8000+80*2*24)), 0, 80*2); |
| 100 |
ofs = 0; |
| 101 |
} |
| 102 |
else if (c == '\r') |
| 103 |
{ |
| 104 |
ofs = 0; |
| 105 |
} |
| 106 |
else if (c == '\t') |
| 107 |
{ |
| 108 |
ofs = (ofs & ~7) + 8; |
| 109 |
} |
| 110 |
else |
| 111 |
{ |
| 112 |
volatile unsigned char *p; |
| 113 |
|
| 114 |
if (ofs >= 80) |
| 115 |
{ |
| 116 |
immc_cnputc(dev, '\r'); |
| 117 |
immc_cnputc(dev, '\n'); |
| 118 |
} |
| 119 |
|
| 120 |
p = (void *) phystokv(0xb8000 + 80*2*24 + ofs*2); |
| 121 |
p[0] = c; |
| 122 |
p[1] = 0x0f; |
| 123 |
ofs++; |
| 124 |
} |
| 125 |
return 0; |
| 126 |
} |
| 127 |
|
| 128 |
void |
| 129 |
immc_romputc(char c) |
| 130 |
{ |
| 131 |
immc_cnputc (0, c); |
| 132 |
} |
| 133 |
|
| 134 |
#endif /* ENABLE_IMMEDIATE_CONSOLE */ |