1ca987d46SWarner Losh /*-
2ca987d46SWarner Losh * spinconsole.c
3ca987d46SWarner Losh *
4ca987d46SWarner Losh * Author: Maksym Sobolyev <sobomax@sippysoft.com>
5ca987d46SWarner Losh * Copyright (c) 2009 Sippy Software, Inc.
6ca987d46SWarner Losh * All rights reserved.
7ca987d46SWarner Losh *
8ca987d46SWarner Losh * Subject to the following obligations and disclaimer of warranty, use and
9ca987d46SWarner Losh * redistribution of this software, in source or object code forms, with or
10ca987d46SWarner Losh * without modifications are expressly permitted by Whistle Communications;
11ca987d46SWarner Losh * provided, however, that:
12ca987d46SWarner Losh * 1. Any and all reproductions of the source or object code must include the
13ca987d46SWarner Losh * copyright notice above and the following disclaimer of warranties; and
14ca987d46SWarner Losh * 2. No rights are granted, in any manner or form, to use Whistle
15ca987d46SWarner Losh * Communications, Inc. trademarks, including the mark "WHISTLE
16ca987d46SWarner Losh * COMMUNICATIONS" on advertising, endorsements, or otherwise except as
17ca987d46SWarner Losh * such appears in the above copyright notice or in the software.
18ca987d46SWarner Losh *
19ca987d46SWarner Losh * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
20ca987d46SWarner Losh * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
21ca987d46SWarner Losh * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
22ca987d46SWarner Losh * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
23ca987d46SWarner Losh * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
24ca987d46SWarner Losh * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
25ca987d46SWarner Losh * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
26ca987d46SWarner Losh * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
27ca987d46SWarner Losh * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
28ca987d46SWarner Losh * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
29ca987d46SWarner Losh * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
30ca987d46SWarner Losh * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
31ca987d46SWarner Losh * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
32ca987d46SWarner Losh * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33ca987d46SWarner Losh * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34ca987d46SWarner Losh * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
35ca987d46SWarner Losh * OF SUCH DAMAGE.
36ca987d46SWarner Losh */
37ca987d46SWarner Losh
38ca987d46SWarner Losh #include <stand.h>
39ca987d46SWarner Losh #include <bootstrap.h>
40ca987d46SWarner Losh
41ca987d46SWarner Losh static void spinc_probe(struct console *cp);
42ca987d46SWarner Losh static int spinc_init(int arg);
43ca987d46SWarner Losh static void spinc_putchar(int c);
44ca987d46SWarner Losh static int spinc_getchar(void);
45ca987d46SWarner Losh static int spinc_ischar(void);
46ca987d46SWarner Losh
47ca987d46SWarner Losh extern struct console *consoles[];
48ca987d46SWarner Losh
49ca987d46SWarner Losh struct console spinconsole = {
50*803060b2SWarner Losh .c_name = "spinconsole",
51*803060b2SWarner Losh .c_desc = "spin port",
52*803060b2SWarner Losh .c_probe = spinc_probe,
53*803060b2SWarner Losh .c_init = spinc_init,
54*803060b2SWarner Losh .c_out = spinc_putchar,
55*803060b2SWarner Losh .c_in = spinc_getchar,
56*803060b2SWarner Losh .c_ready = spinc_ischar
57ca987d46SWarner Losh };
58ca987d46SWarner Losh
59ca987d46SWarner Losh static struct console *parent = NULL;
60ca987d46SWarner Losh
61ca987d46SWarner Losh static void
spinc_probe(struct console * cp)62ca987d46SWarner Losh spinc_probe(struct console *cp)
63ca987d46SWarner Losh {
64ca987d46SWarner Losh
65ca987d46SWarner Losh if (parent == NULL)
66ca987d46SWarner Losh parent = consoles[0];
67ca987d46SWarner Losh parent->c_probe(cp);
68ca987d46SWarner Losh }
69ca987d46SWarner Losh
70ca987d46SWarner Losh static int
spinc_init(int arg)71ca987d46SWarner Losh spinc_init(int arg)
72ca987d46SWarner Losh {
73ca987d46SWarner Losh
74ca987d46SWarner Losh return (parent->c_init(arg));
75ca987d46SWarner Losh }
76ca987d46SWarner Losh
77ca987d46SWarner Losh static void
spinc_putchar(int c)78ca987d46SWarner Losh spinc_putchar(int c)
79ca987d46SWarner Losh {
80ca987d46SWarner Losh static unsigned tw_chars = 0x5C2D2F7C; /* "\-/|" */
81ca987d46SWarner Losh static time_t lasttime = 0;
82ca987d46SWarner Losh time_t now;
83ca987d46SWarner Losh
84ca987d46SWarner Losh now = time(0);
85ca987d46SWarner Losh if (now < (lasttime + 1))
86ca987d46SWarner Losh return;
87ca987d46SWarner Losh #ifdef TERM_EMU
88ca987d46SWarner Losh if (lasttime > 0)
89ca987d46SWarner Losh parent->c_out('\b');
90ca987d46SWarner Losh #endif
91ca987d46SWarner Losh lasttime = now;
92ca987d46SWarner Losh parent->c_out((char)tw_chars);
93ca987d46SWarner Losh tw_chars = (tw_chars >> 8) | ((tw_chars & (unsigned long)0xFF) << 24);
94ca987d46SWarner Losh }
95ca987d46SWarner Losh
96ca987d46SWarner Losh static int
spinc_getchar(void)97ca987d46SWarner Losh spinc_getchar(void)
98ca987d46SWarner Losh {
99ca987d46SWarner Losh
100ca987d46SWarner Losh return (-1);
101ca987d46SWarner Losh }
102ca987d46SWarner Losh
103ca987d46SWarner Losh static int
spinc_ischar(void)104ca987d46SWarner Losh spinc_ischar(void)
105ca987d46SWarner Losh {
106ca987d46SWarner Losh
107ca987d46SWarner Losh return (0);
108ca987d46SWarner Losh }
109