Initial PCI setup.
[qemu-palcode.git] / console.c
blobd5fb07df1793aa783cc12e334a56d4ab15f3f215
1 /* The SRM console prompt.
3 Copyright (C) 2011 Richard Henderson
5 This file is part of QEMU PALcode.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the text
15 of the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "protos.h"
22 #include "console.h"
25 static void
26 output_crnl(void)
28 crb_puts(0, "\r\n", 2);
31 static void
32 output_bell(void)
34 crb_puts(0, "\a", 1);
37 static void
38 backspace_and_erase(void)
40 crb_puts(0, "\b \b", 3);
43 static unsigned long
44 getline(char *buf, unsigned long bufsize)
46 unsigned long len = 0;
47 long c;
49 while (1)
51 c = crb_getc(0);
52 if (c < 0)
53 continue;
54 switch ((int)c)
56 case '\r':
57 case '\n':
58 output_crnl();
59 buf[len] = 0;
60 return len;
62 case '\b':
63 case 0x7f: /* Delete */
64 if (len > 0)
66 backspace_and_erase();
67 len--;
69 else
70 output_bell();
71 break;
73 default:
74 if (len + 1 < bufsize)
76 buf[len] = c;
77 crb_puts(0, buf+len, 1);
78 len++;
80 else
81 output_bell();
82 break;
87 static inline void set_console_alarm(void)
89 /* Just set a new timeout for 10ms = 10M ns. */
90 set_alarm_rel(10 * 1000 * 1000);
93 void
94 do_entInt(unsigned long type, unsigned long vector)
96 switch (type)
98 case 0:
99 /* ??? SMP interrupt. We're going to need this for starting up
100 secondary cpus. */
101 break;
102 case 1:
103 /* Timer interrupt. */
104 set_console_alarm();
105 break;
106 case 2:
107 /* ??? Device interrupt. We're going to need this for virtio disk
108 operations at minimum. */
109 break;
113 void
114 do_console(void)
116 char line[256];
117 unsigned long len;
119 wrkgp();
120 wrent(entInt, 0);
121 set_console_alarm();
122 swpipl(0);
124 pci_setup();
126 while (1)
128 crb_puts(0, ">>> ", 4);
129 len = getline(line, sizeof(line));
130 crb_puts(0, "got: ", 5);
131 crb_puts(0, line, len);
132 output_crnl();