Rev 4296 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4296 | Rev 4420 | ||
|---|---|---|---|
| Line 42... | Line 42... | ||
| 42 | #include <ddi/irq.h> |
42 | #include <ddi/irq.h> |
| 43 | #include <ddi/ddi.h> |
43 | #include <ddi/ddi.h> |
| 44 | #include <ipc/event.h> |
44 | #include <ipc/event.h> |
| 45 | #include <ipc/irq.h> |
45 | #include <ipc/irq.h> |
| 46 | #include <arch.h> |
46 | #include <arch.h> |
| 47 | #include <func.h> |
- | |
| 48 | #include <print.h> |
47 | #include <print.h> |
| 49 | #include <putchar.h> |
48 | #include <putchar.h> |
| 50 | #include <atomic.h> |
49 | #include <atomic.h> |
| 51 | #include <syscall/copy.h> |
50 | #include <syscall/copy.h> |
| 52 | #include <errno.h> |
51 | #include <errno.h> |
| Line 68... | Line 67... | ||
| 68 | /** Number of stored (not printed) kernel log characters */ |
67 | /** Number of stored (not printed) kernel log characters */ |
| 69 | static size_t klog_stored = 0; |
68 | static size_t klog_stored = 0; |
| 70 | /** Number of stored kernel log characters for uspace */ |
69 | /** Number of stored kernel log characters for uspace */ |
| 71 | static size_t klog_uspace = 0; |
70 | static size_t klog_uspace = 0; |
| 72 | 71 | ||
| 73 | /** Silence output */ |
- | |
| 74 | bool silent = false; |
- | |
| 75 | - | ||
| 76 | /** Kernel log spinlock */ |
72 | /** Kernel log spinlock */ |
| 77 | SPINLOCK_INITIALIZE(klog_lock); |
73 | SPINLOCK_INITIALIZE(klog_lock); |
| 78 | 74 | ||
| 79 | /** Physical memory area used for klog buffer */ |
75 | /** Physical memory area used for klog buffer */ |
| 80 | static parea_t klog_parea; |
76 | static parea_t klog_parea; |
| 81 | 77 | ||
| - | 78 | static indev_operations_t stdin_ops = { |
|
| - | 79 | .poll = NULL |
|
| - | 80 | }; |
|
| - | 81 | ||
| - | 82 | /** Silence output */ |
|
| - | 83 | bool silent = false; |
|
| - | 84 | ||
| 82 | /** Standard input and output character devices */ |
85 | /** Standard input and output character devices */ |
| 83 | indev_t *stdin = NULL; |
86 | indev_t *stdin = NULL; |
| 84 | outdev_t *stdout = NULL; |
87 | outdev_t *stdout = NULL; |
| 85 | 88 | ||
| - | 89 | indev_t *stdin_wire(void) |
|
| - | 90 | { |
|
| - | 91 | if (stdin == NULL) { |
|
| - | 92 | stdin = malloc(sizeof(indev_t), FRAME_ATOMIC); |
|
| - | 93 | if (stdin != NULL) |
|
| - | 94 | indev_initialize("stdin", stdin, &stdin_ops); |
|
| - | 95 | } |
|
| - | 96 | ||
| - | 97 | return stdin; |
|
| - | 98 | } |
|
| - | 99 | ||
| 86 | /** Initialize kernel logging facility |
100 | /** Initialize kernel logging facility |
| 87 | * |
101 | * |
| 88 | * The shared area contains kernel cyclic buffer. Userspace application may |
102 | * The shared area contains kernel cyclic buffer. Userspace application may |
| 89 | * be notified on new data with indication of position and size |
103 | * be notified on new data with indication of position and size |
| 90 | * of the data within the circular buffer. |
104 | * of the data within the circular buffer. |
| Line 108... | Line 122... | ||
| 108 | spinlock_unlock(&klog_lock); |
122 | spinlock_unlock(&klog_lock); |
| 109 | } |
123 | } |
| 110 | 124 | ||
| 111 | void grab_console(void) |
125 | void grab_console(void) |
| 112 | { |
126 | { |
| - | 127 | bool prev = silent; |
|
| - | 128 | ||
| 113 | silent = false; |
129 | silent = false; |
| 114 | arch_grab_console(); |
130 | arch_grab_console(); |
| - | 131 | ||
| - | 132 | /* Force the console to print the prompt */ |
|
| - | 133 | if ((stdin) && (prev)) |
|
| - | 134 | indev_push_character(stdin, '\n'); |
|
| 115 | } |
135 | } |
| 116 | 136 | ||
| 117 | void release_console(void) |
137 | void release_console(void) |
| 118 | { |
138 | { |
| 119 | silent = true; |
139 | silent = true; |
| Line 136... | Line 156... | ||
| 136 | { |
156 | { |
| 137 | release_console(); |
157 | release_console(); |
| 138 | return true; |
158 | return true; |
| 139 | } |
159 | } |
| 140 | 160 | ||
| 141 | bool check_poll(indev_t *indev) |
- | |
| 142 | { |
- | |
| 143 | if (indev == NULL) |
- | |
| 144 | return false; |
- | |
| 145 | - | ||
| 146 | if (indev->op == NULL) |
- | |
| 147 | return false; |
- | |
| 148 | - | ||
| 149 | return (indev->op->poll != NULL); |
- | |
| 150 | } |
- | |
| 151 | - | ||
| 152 | /** Get character from input character device. Do not echo character. |
- | |
| 153 | * |
- | |
| 154 | * @param indev Input character device. |
- | |
| 155 | * @return Character read. |
- | |
| 156 | * |
- | |
| 157 | */ |
- | |
| 158 | wchar_t _getc(indev_t *indev) |
- | |
| 159 | { |
- | |
| 160 | if (atomic_get(&haltstate)) { |
- | |
| 161 | /* If we are here, we are hopefully on the processor that |
- | |
| 162 | * issued the 'halt' command, so proceed to read the character |
- | |
| 163 | * directly from input |
- | |
| 164 | */ |
- | |
| 165 | if (check_poll(indev)) |
- | |
| 166 | return indev->op->poll(indev); |
- | |
| 167 | - | ||
| 168 | /* No other way of interacting with user */ |
- | |
| 169 | interrupts_disable(); |
- | |
| 170 | - | ||
| 171 | if (CPU) |
- | |
| 172 | printf("cpu%u: ", CPU->id); |
- | |
| 173 | else |
- | |
| 174 | printf("cpu: "); |
- | |
| 175 | printf("halted (no polling input)\n"); |
- | |
| 176 | cpu_halt(); |
- | |
| 177 | } |
- | |
| 178 | - | ||
| 179 | waitq_sleep(&indev->wq); |
- | |
| 180 | ipl_t ipl = interrupts_disable(); |
- | |
| 181 | spinlock_lock(&indev->lock); |
- | |
| 182 | wchar_t ch = indev->buffer[(indev->index - indev->counter) % INDEV_BUFLEN]; |
- | |
| 183 | indev->counter--; |
- | |
| 184 | spinlock_unlock(&indev->lock); |
- | |
| 185 | interrupts_restore(ipl); |
- | |
| 186 | - | ||
| 187 | return ch; |
- | |
| 188 | } |
- | |
| 189 | - | ||
| 190 | /** Get string from input character device. |
161 | /** Get string from input character device. |
| 191 | * |
162 | * |
| 192 | * Read characters from input character device until first occurrence |
163 | * Read characters from input character device until first occurrence |
| 193 | * of newline character. |
164 | * of newline character. |
| 194 | * |
165 | * |
| Line 204... | Line 175... | ||
| 204 | size_t offset = 0; |
175 | size_t offset = 0; |
| 205 | count_t count = 0; |
176 | count_t count = 0; |
| 206 | buf[offset] = 0; |
177 | buf[offset] = 0; |
| 207 | 178 | ||
| 208 | wchar_t ch; |
179 | wchar_t ch; |
| 209 | while ((ch = _getc(indev)) != '\n') { |
180 | while ((ch = indev_pop_character(indev)) != '\n') { |
| 210 | if (ch == '\b') { |
181 | if (ch == '\b') { |
| 211 | if (count > 0) { |
182 | if (count > 0) { |
| 212 | /* Space, backspace, space */ |
183 | /* Space, backspace, space */ |
| 213 | putchar('\b'); |
184 | putchar('\b'); |
| 214 | putchar(' '); |
185 | putchar(' '); |
| Line 230... | Line 201... | ||
| 230 | } |
201 | } |
| 231 | 202 | ||
| 232 | /** Get character from input device & echo it to screen */ |
203 | /** Get character from input device & echo it to screen */ |
| 233 | wchar_t getc(indev_t *indev) |
204 | wchar_t getc(indev_t *indev) |
| 234 | { |
205 | { |
| 235 | wchar_t ch = _getc(indev); |
206 | wchar_t ch = indev_pop_character(indev); |
| 236 | putchar(ch); |
207 | putchar(ch); |
| 237 | return ch; |
208 | return ch; |
| 238 | } |
209 | } |
| 239 | 210 | ||
| 240 | void klog_update(void) |
211 | void klog_update(void) |