Changes in kernel/generic/src/console/console.c [7ddc2c7:11527051] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/console/console.c
r7ddc2c7 r11527051 52 52 #include <errno.h> 53 53 #include <str.h> 54 #include <abi/k io.h>55 56 #define K IO_PAGES 857 #define K IO_LENGTH (KIO_PAGES * PAGE_SIZE / sizeof(wchar_t))54 #include <abi/klog.h> 55 56 #define KLOG_PAGES 8 57 #define KLOG_LENGTH (KLOG_PAGES * PAGE_SIZE / sizeof(wchar_t)) 58 58 59 59 /** Kernel log cyclic buffer */ 60 wchar_t k io[KIO_LENGTH] __attribute__((aligned(PAGE_SIZE)));60 wchar_t klog[KLOG_LENGTH] __attribute__((aligned(PAGE_SIZE))); 61 61 62 62 /** Kernel log initialized */ 63 static atomic_t k io_inited = {false};63 static atomic_t klog_inited = {false}; 64 64 65 65 /** First kernel log characters */ 66 static size_t k io_start = 0;66 static size_t klog_start = 0; 67 67 68 68 /** Number of valid kernel log characters */ 69 static size_t k io_len = 0;69 static size_t klog_len = 0; 70 70 71 71 /** Number of stored (not printed) kernel log characters */ 72 static size_t k io_stored = 0;72 static size_t klog_stored = 0; 73 73 74 74 /** Number of stored kernel log characters for uspace */ 75 static size_t k io_uspace = 0;75 static size_t klog_uspace = 0; 76 76 77 77 /** Kernel log spinlock */ 78 SPINLOCK_ INITIALIZE_NAME(kio_lock, "kio_lock");79 80 /** Physical memory area used for k iobuffer */81 static parea_t k io_parea;78 SPINLOCK_STATIC_INITIALIZE_NAME(klog_lock, "klog_lock"); 79 80 /** Physical memory area used for klog buffer */ 81 static parea_t klog_parea; 82 82 83 83 static indev_t stdin_sink; 84 84 static outdev_t stdout_source; 85 85 86 static void stdin_signal(indev_t *, indev_signal_t);87 88 86 static indev_operations_t stdin_ops = { 89 .poll = NULL, 90 .signal = stdin_signal 87 .poll = NULL 91 88 }; 92 89 93 90 static void stdout_write(outdev_t *, wchar_t); 94 91 static void stdout_redraw(outdev_t *); 95 static void stdout_scroll_up(outdev_t *);96 static void stdout_scroll_down(outdev_t *);97 92 98 93 static outdev_operations_t stdout_ops = { 99 94 .write = stdout_write, 100 .redraw = stdout_redraw, 101 .scroll_up = stdout_scroll_up, 102 .scroll_down = stdout_scroll_down 95 .redraw = stdout_redraw 103 96 }; 104 97 … … 120 113 } 121 114 122 static void stdin_signal(indev_t *indev, indev_signal_t signal)123 {124 switch (signal) {125 case INDEV_SIGNAL_SCROLL_UP:126 if (stdout != NULL)127 stdout_scroll_up(stdout);128 break;129 case INDEV_SIGNAL_SCROLL_DOWN:130 if (stdout != NULL)131 stdout_scroll_down(stdout);132 break;133 }134 }135 136 115 void stdout_wire(outdev_t *outdev) 137 116 { … … 146 125 static void stdout_write(outdev_t *dev, wchar_t ch) 147 126 { 148 list_foreach(dev->list, link, outdev_t, sink) { 127 list_foreach(dev->list, cur) { 128 outdev_t *sink = list_get_instance(cur, outdev_t, link); 149 129 if ((sink) && (sink->op->write)) 150 130 sink->op->write(sink, ch); … … 154 134 static void stdout_redraw(outdev_t *dev) 155 135 { 156 list_foreach(dev->list, link, outdev_t, sink) { 136 list_foreach(dev->list, cur) { 137 outdev_t *sink = list_get_instance(cur, outdev_t, link); 157 138 if ((sink) && (sink->op->redraw)) 158 139 sink->op->redraw(sink); 159 }160 }161 162 static void stdout_scroll_up(outdev_t *dev)163 {164 list_foreach(dev->list, link, outdev_t, sink) {165 if ((sink) && (sink->op->scroll_up))166 sink->op->scroll_up(sink);167 }168 }169 170 static void stdout_scroll_down(outdev_t *dev)171 {172 list_foreach(dev->list, link, outdev_t, sink) {173 if ((sink) && (sink->op->scroll_down))174 sink->op->scroll_down(sink);175 140 } 176 141 } … … 183 148 * 184 149 */ 185 void k io_init(void)186 { 187 void *faddr = (void *) KA2PA(k io);150 void klog_init(void) 151 { 152 void *faddr = (void *) KA2PA(klog); 188 153 189 154 ASSERT((uintptr_t) faddr % FRAME_SIZE == 0); 190 155 191 k io_parea.pbase = (uintptr_t) faddr;192 k io_parea.frames = SIZE2FRAMES(sizeof(kio));193 k io_parea.unpriv = false;194 k io_parea.mapped = false;195 ddi_parea_register(&k io_parea);196 197 sysinfo_set_item_val("k io.faddr", NULL, (sysarg_t) faddr);198 sysinfo_set_item_val("k io.pages", NULL, KIO_PAGES);199 200 event_set_unmask_callback(EVENT_K IO, kio_update);201 atomic_set(&k io_inited, true);156 klog_parea.pbase = (uintptr_t) faddr; 157 klog_parea.frames = SIZE2FRAMES(sizeof(klog)); 158 klog_parea.unpriv = false; 159 klog_parea.mapped = false; 160 ddi_parea_register(&klog_parea); 161 162 sysinfo_set_item_val("klog.faddr", NULL, (sysarg_t) faddr); 163 sysinfo_set_item_val("klog.pages", NULL, KLOG_PAGES); 164 165 event_set_unmask_callback(EVENT_KLOG, klog_update); 166 atomic_set(&klog_inited, true); 202 167 } 203 168 … … 266 231 } 267 232 } 268 269 233 if (chr_encode(ch, buf, &offset, buflen - 1) == EOK) { 270 234 putchar(ch); … … 285 249 } 286 250 287 void k io_update(void *event)288 { 289 if (!atomic_get(&k io_inited))251 void klog_update(void *event) 252 { 253 if (!atomic_get(&klog_inited)) 290 254 return; 291 255 292 spinlock_lock(&kio_lock); 293 294 if (kio_uspace > 0) { 295 if (event_notify_3(EVENT_KIO, true, kio_start, kio_len, 296 kio_uspace) == EOK) 297 kio_uspace = 0; 298 } 299 300 spinlock_unlock(&kio_lock); 301 } 302 303 /** Flush characters that are stored in the output buffer 304 * 305 */ 306 void kio_flush(void) 256 spinlock_lock(&klog_lock); 257 258 if (klog_uspace > 0) { 259 if (event_notify_3(EVENT_KLOG, true, klog_start, klog_len, 260 klog_uspace) == EOK) 261 klog_uspace = 0; 262 } 263 264 spinlock_unlock(&klog_lock); 265 } 266 267 void putchar(const wchar_t ch) 307 268 { 308 269 bool ordy = ((stdout) && (stdout->op->write)); 309 270 310 if (!ordy) 311 return; 312 313 spinlock_lock(&kio_lock); 314 315 /* Print characters that weren't printed earlier */ 316 while (kio_stored > 0) { 317 wchar_t tmp = kio[(kio_start + kio_len - kio_stored) % KIO_LENGTH]; 318 kio_stored--; 319 271 spinlock_lock(&klog_lock); 272 273 /* Print charaters stored in kernel log */ 274 if (ordy) { 275 while (klog_stored > 0) { 276 wchar_t tmp = klog[(klog_start + klog_len - klog_stored) % KLOG_LENGTH]; 277 klog_stored--; 278 279 /* 280 * We need to give up the spinlock for 281 * the physical operation of writting out 282 * the character. 283 */ 284 spinlock_unlock(&klog_lock); 285 stdout->op->write(stdout, tmp); 286 spinlock_lock(&klog_lock); 287 } 288 } 289 290 /* Store character in the cyclic kernel log */ 291 klog[(klog_start + klog_len) % KLOG_LENGTH] = ch; 292 if (klog_len < KLOG_LENGTH) 293 klog_len++; 294 else 295 klog_start = (klog_start + 1) % KLOG_LENGTH; 296 297 if (!ordy) { 298 if (klog_stored < klog_len) 299 klog_stored++; 300 } 301 302 /* The character is stored for uspace */ 303 if (klog_uspace < klog_len) 304 klog_uspace++; 305 306 spinlock_unlock(&klog_lock); 307 308 if (ordy) { 320 309 /* 321 * We need to give up the spinlock for 322 * the physical operation of writing out 323 * the character. 310 * Output the character. In this case 311 * it should be no longer buffered. 324 312 */ 325 spinlock_unlock(&kio_lock); 326 stdout->op->write(stdout, tmp); 327 spinlock_lock(&kio_lock); 328 } 329 330 spinlock_unlock(&kio_lock); 331 } 332 333 /** Put a character into the output buffer. 334 * 335 * The caller is required to hold kio_lock 336 */ 337 void kio_push_char(const wchar_t ch) 338 { 339 kio[(kio_start + kio_len) % KIO_LENGTH] = ch; 340 if (kio_len < KIO_LENGTH) 341 kio_len++; 342 else 343 kio_start = (kio_start + 1) % KIO_LENGTH; 344 345 if (kio_stored < kio_len) 346 kio_stored++; 347 348 /* The character is stored for uspace */ 349 if (kio_uspace < kio_len) 350 kio_uspace++; 351 } 352 353 void putchar(const wchar_t ch) 354 { 355 bool ordy = ((stdout) && (stdout->op->write)); 356 357 spinlock_lock(&kio_lock); 358 kio_push_char(ch); 359 spinlock_unlock(&kio_lock); 360 361 /* Output stored characters */ 362 kio_flush(); 363 364 if (!ordy) { 313 stdout->op->write(stdout, ch); 314 } else { 365 315 /* 366 316 * No standard output routine defined yet. … … 378 328 /* Force notification on newline */ 379 329 if (ch == '\n') 380 k io_update(NULL);330 klog_update(NULL); 381 331 } 382 332 … … 386 336 * 387 337 */ 388 sysarg_t sys_k io(int cmd, const void *buf, size_t size)338 sysarg_t sys_klog(int cmd, const void *buf, size_t size) 389 339 { 390 340 char *data; … … 392 342 393 343 switch (cmd) { 394 case K IO_UPDATE:395 k io_update(NULL);344 case KLOG_UPDATE: 345 klog_update(NULL); 396 346 return EOK; 397 case K IO_WRITE:398 case K IO_COMMAND:347 case KLOG_WRITE: 348 case KLOG_COMMAND: 399 349 break; 400 350 default: … … 418 368 419 369 switch (cmd) { 420 case K IO_WRITE:370 case KLOG_WRITE: 421 371 printf("%s", data); 422 372 break; 423 case K IO_COMMAND:373 case KLOG_COMMAND: 424 374 if (!stdin) 425 375 break;
Note:
See TracChangeset
for help on using the changeset viewer.