]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/kernel_console.cpp
475b499a0a251b3013e244384edebeb9a0a2026e
[l4.git] / kernel / fiasco / src / kern / kernel_console.cpp
1 INTERFACE:
2
3 #include "mux_console.h"
4 #include "std_macros.h"
5
6 class Kconsole : public Mux_console
7 {
8 public:
9   int  getchar(bool blocking = true);
10   void getchar_chance();
11
12   static Mux_console *console() FIASCO_CONST;
13
14 private:
15   static bool initialized;
16 };
17
18 IMPLEMENTATION:
19
20 #include "config.h"
21 #include "console.h"
22 #include "mux_console.h"
23 #include "processor.h"
24
25
26 IMPLEMENT
27 int Kconsole::getchar(bool blocking)
28 {
29   if (!blocking)
30     return Mux_console::getchar(false);
31
32   while(1)
33     {
34       int c;
35       if ((c = Mux_console::getchar(false)) != -1)
36         return c;
37
38       if (Config::getchar_does_hlt &&           // does work in principle
39           Config::getchar_does_hlt_works_ok &&  // wakeup timer is enabled
40           Proc::interrupts())                   // does'nt work without ints
41         Proc::halt();
42       else
43         Proc::pause();
44     }
45 }
46
47
48
49 bool Kconsole::initialized;
50
51 PUBLIC static
52 void
53 Kconsole::activate()
54 {
55   if (!initialized)
56     {
57       initialized = true;
58       Console::stdout = console();
59       Console::stderr = Console::stdout;
60       Console::stdin  = Console::stdout;
61     }
62 }
63
64 PUBLIC
65 virtual bool
66 Kconsole::register_console(Console *c, int pos = 0)
67 {
68   bool b = Mux_console::register_console(c, pos);
69   if (b) 
70     activate();
71   
72   return b;
73 }
74
75 IMPLEMENT 
76 Mux_console *Kconsole::console()
77 {
78   static Kconsole cons;
79   return &cons;
80 }
81