Changes in kernel/generic/src/console/console.c [b366a6f4:d7533c7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/console/console.c
rb366a6f4 rd7533c7 53 53 #include <str.h> 54 54 55 #define KLOG_PAGES 855 #define KLOG_PAGES 4 56 56 #define KLOG_LENGTH (KLOG_PAGES * PAGE_SIZE / sizeof(wchar_t)) 57 #define KLOG_LATENCY 8 57 58 58 59 /** Kernel log cyclic buffer */ … … 60 61 61 62 /** Kernel log initialized */ 62 static atomic_t klog_inited = {false};63 static bool klog_inited = false; 63 64 64 65 /** First kernel log characters */ … … 75 76 76 77 /** Kernel log spinlock */ 77 SPINLOCK_STATIC_INITIALIZE_NAME(klog_lock, " klog_lock");78 SPINLOCK_STATIC_INITIALIZE_NAME(klog_lock, "*klog_lock"); 78 79 79 80 /** Physical memory area used for klog buffer */ … … 87 88 }; 88 89 89 static void stdout_write(outdev_t *, wchar_t );90 static void stdout_write(outdev_t *, wchar_t, bool); 90 91 static void stdout_redraw(outdev_t *); 91 92 … … 95 96 }; 96 97 97 /** Override kernel console lockout */98 bool console_override= false;98 /** Silence output */ 99 bool silent = false; 99 100 100 101 /** Standard input and output character devices */ … … 122 123 } 123 124 124 static void stdout_write(outdev_t *dev, wchar_t ch) 125 { 126 list_foreach(dev->list, cur) { 125 static void stdout_write(outdev_t *dev, wchar_t ch, bool silent) 126 { 127 link_t *cur; 128 129 for (cur = dev->list.next; cur != &dev->list; cur = cur->next) { 127 130 outdev_t *sink = list_get_instance(cur, outdev_t, link); 128 131 if ((sink) && (sink->op->write)) 129 sink->op->write(sink, ch );132 sink->op->write(sink, ch, silent); 130 133 } 131 134 } … … 133 136 static void stdout_redraw(outdev_t *dev) 134 137 { 135 list_foreach(dev->list, cur) { 138 link_t *cur; 139 140 for (cur = dev->list.next; cur != &dev->list; cur = cur->next) { 136 141 outdev_t *sink = list_get_instance(cur, outdev_t, link); 137 142 if ((sink) && (sink->op->redraw)) … … 156 161 klog_parea.frames = SIZE2FRAMES(sizeof(klog)); 157 162 klog_parea.unpriv = false; 158 klog_parea.mapped = false;159 163 ddi_parea_register(&klog_parea); 160 164 … … 162 166 sysinfo_set_item_val("klog.pages", NULL, KLOG_PAGES); 163 167 164 event_set_unmask_callback(EVENT_KLOG, klog_update); 165 atomic_set(&klog_inited, true); 168 spinlock_lock(&klog_lock); 169 klog_inited = true; 170 spinlock_unlock(&klog_lock); 166 171 } 167 172 168 173 void grab_console(void) 169 174 { 170 bool prev = console_override;171 172 console_override = true;175 bool prev = silent; 176 177 silent = false; 173 178 if ((stdout) && (stdout->op->redraw)) 174 179 stdout->op->redraw(stdout); 175 180 176 if ((stdin) && ( !prev)) {181 if ((stdin) && (prev)) { 177 182 /* 178 183 * Force the console to print the prompt. … … 184 189 void release_console(void) 185 190 { 186 console_override = false; 187 } 188 189 /** Activate kernel console override */ 190 sysarg_t sys_debug_activate_console(void) 191 // FIXME arch_release_console 192 silent = true; 193 } 194 195 /** Tell kernel to get keyboard/console access again */ 196 sysarg_t sys_debug_enable_console(void) 191 197 { 192 198 #ifdef CONFIG_KCONSOLE … … 196 202 return false; 197 203 #endif 204 } 205 206 /** Tell kernel to relinquish keyboard/console access */ 207 sysarg_t sys_debug_disable_console(void) 208 { 209 release_console(); 210 return true; 198 211 } 199 212 … … 250 263 void klog_update(void) 251 264 { 252 if (!atomic_get(&klog_inited))253 return;254 255 265 spinlock_lock(&klog_lock); 256 266 257 if (klog_uspace > 0) { 258 if (event_notify_3(EVENT_KLOG, true, klog_start, klog_len, 259 klog_uspace) == EOK) 260 klog_uspace = 0; 267 if ((klog_inited) && (event_is_subscribed(EVENT_KLOG)) && (klog_uspace > 0)) { 268 event_notify_3(EVENT_KLOG, klog_start, klog_len, klog_uspace); 269 klog_uspace = 0; 261 270 } 262 271 … … 266 275 void putchar(const wchar_t ch) 267 276 { 268 bool ordy = ((stdout) && (stdout->op->write));269 270 277 spinlock_lock(&klog_lock); 271 278 272 /* Print charaters stored in kernel log */ 273 if (ordy) { 274 while (klog_stored > 0) { 275 wchar_t tmp = klog[(klog_start + klog_len - klog_stored) % KLOG_LENGTH]; 276 klog_stored--; 277 278 /* 279 * We need to give up the spinlock for 280 * the physical operation of writting out 281 * the character. 282 */ 283 spinlock_unlock(&klog_lock); 284 stdout->op->write(stdout, tmp); 285 spinlock_lock(&klog_lock); 286 } 279 if ((klog_stored > 0) && (stdout) && (stdout->op->write)) { 280 /* Print charaters stored in kernel log */ 281 size_t i; 282 for (i = klog_len - klog_stored; i < klog_len; i++) 283 stdout->op->write(stdout, klog[(klog_start + i) % KLOG_LENGTH], silent); 284 klog_stored = 0; 287 285 } 288 286 … … 294 292 klog_start = (klog_start + 1) % KLOG_LENGTH; 295 293 296 if (!ordy) { 297 if (klog_stored < klog_len) 298 klog_stored++; 299 } 300 301 /* The character is stored for uspace */ 302 if (klog_uspace < klog_len) 303 klog_uspace++; 304 305 spinlock_unlock(&klog_lock); 306 307 if (ordy) { 308 /* 309 * Output the character. In this case 310 * it should be no longer buffered. 311 */ 312 stdout->op->write(stdout, ch); 313 } else { 294 if ((stdout) && (stdout->op->write)) 295 stdout->op->write(stdout, ch, silent); 296 else { 314 297 /* 315 298 * No standard output routine defined yet. … … 321 304 * Note that the early_putc() function might be 322 305 * a no-op on certain hardware configurations. 306 * 323 307 */ 324 308 early_putchar(ch); 325 } 326 327 /* Force notification on newline */ 328 if (ch == '\n') 309 310 if (klog_stored < klog_len) 311 klog_stored++; 312 } 313 314 /* The character is stored for uspace */ 315 if (klog_uspace < klog_len) 316 klog_uspace++; 317 318 /* Check notify uspace to update */ 319 bool update; 320 if ((klog_uspace > KLOG_LATENCY) || (ch == '\n')) 321 update = true; 322 else 323 update = false; 324 325 spinlock_unlock(&klog_lock); 326 327 if (update) 329 328 klog_update(); 330 329 }
Note:
See TracChangeset
for help on using the changeset viewer.