Adjust memory layout for 2.6.22+ kernels with 32KB setup code
[mknbi.git] / misc.c
1 #include        "ansiesc.h"
2 #include        "etherboot.h"
3 #include        "start32.h"
4 #include        "misc.h"
5 #ifdef CONSOLE_SERIAL
6 #include        "serial.h"
7 #endif /* CONSOLE_SERIAL */
8
9 #if     ANSIMODE==-1
10 static int ansion = 0;
11 #endif
12
13 /**************************************************************************
14 SLEEP
15 **************************************************************************/
16 void sleep(int secs)
17 {
18         unsigned long tmo;
19
20         for (tmo = currticks()+secs*TICKS_PER_SEC; currticks() < tmo; )
21                 /* Nothing */;
22 }
23
24 int getdecopt(unsigned char **ptr, int *len)
25 {
26         char *p = *ptr;
27         int negative=0, ret=0;
28         int l = *len;
29
30         if (l <= 0)
31                 return 0;
32
33         if (*p == '-') {
34                 negative = 1;
35                 p++;
36                 l--;
37         }
38         if ((l <= 0) || (*p < '0') || (*p > '9'))
39                 return 0;
40         while ((l > 0) && (*p >= '0') && (*p <= '9')) {
41                 ret = ret*10 + (*p - '0');
42                 p++;
43                 l--;
44         }
45         *ptr = p;
46         *len = l;
47         if (negative)
48                 ret = -ret;
49         return(ret);
50 }
51
52 #if     ANSIMODE==-1
53 void
54 ansiswitch(int i)
55 {
56         ansion = i;
57 }
58 #endif
59
60 void
61 putchar(int c)
62 {
63 #ifdef  CONSOLE_CRT
64 #if     ANSIMODE==-1    /* choose by variable */
65         if (ansion)
66                 ansi_putc(c);
67         else {
68                 if (c == '\n')
69                         console_putc('\r');
70                 console_putc(c);
71         }
72 #elif   ANSIMODE==1     /* always ANSI */
73         ansi_putc(c);
74 #else                   /* always console */
75         if (c == '\n')
76                 console_putc('\r');
77         console_putc(c);
78 #endif
79 #endif
80
81 #ifdef  CONSOLE_SERIAL
82         if (c == '\n')
83                 serial_putc('\r');
84         serial_putc(c);
85 #endif
86 }
87
88 /**************************************************************************
89 GETCHAR - Read the next character from input device WITHOUT ECHO
90 **************************************************************************/
91 int getchar(void)
92 {
93         int c = 256;
94
95         do {
96 #ifdef  POWERSAVE
97                 /* Doze for a while (until the next interrupt).  This works
98                  * fine, because the keyboard is interrupt-driven, and the
99                  * timer interrupt (approx. every 50msec) takes care of the
100                  * serial port, which is read by polling.  This reduces the
101                  * power dissipation of a modern CPU considerably, and also
102                  * makes Etherboot waiting for user interaction waste a lot
103                  * less CPU time in a VMware session.  */
104                 cpu_nap();
105 #endif  /* POWERSAVE */
106 #ifdef  CONSOLE_CRT
107                 if (console_ischar())
108                         c = console_getc();
109 #endif
110 #ifdef  CONSOLE_SERIAL
111                 if (serial_ischar())
112                         c = serial_getc();
113 #endif
114         } while (c==256);
115         if (c == '\r')
116                 c = '\n';
117         return c;
118 }
119
120 int iskey(void)
121 {
122 #ifdef  CONSOLE_CRT
123         if (console_ischar())
124                 return 1;
125 #endif
126 #ifdef  CONSOLE_SERIAL
127         if (serial_ischar())
128                 return 1;
129 #endif
130         return 0;
131 }