Changeset 39e1b9a in mainline
- Timestamp:
- 2025-04-17T15:37:05Z (5 days ago)
- Branches:
- master
- Children:
- 250a435
- Parents:
- 690ad20
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2025-04-14 16:54:54)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2025-04-17 15:37:05)
- Location:
- kernel
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/genarch/src/drivers/ega/ega.c
r690ad20 r39e1b9a 69 69 uint8_t *backbuf; 70 70 ioport8_t *base; 71 mbstate_t mbstate; 71 72 } ega_instance_t; 72 73 73 static void ega_ putuchar(outdev_t *, char32_t);74 static void ega_write(outdev_t *, const char *, size_t); 74 75 static void ega_redraw(outdev_t *); 75 76 76 77 static outdev_operations_t egadev_ops = { 77 .write = ega_ putuchar,78 .write = ega_write, 78 79 .redraw = ega_redraw, 79 80 .scroll_up = NULL, … … 538 539 } 539 540 540 static void ega_putuchar(outdev_t *dev, char32_t ch) 541 { 542 ega_instance_t *instance = (ega_instance_t *) dev->data; 543 544 irq_spinlock_lock(&instance->lock, true); 545 541 static void _putuchar(ega_instance_t *instance, char32_t ch) 542 { 546 543 switch (ch) { 547 544 case '\n': … … 564 561 ega_check_cursor(instance); 565 562 ega_move_cursor(instance); 563 } 564 565 static void ega_write(outdev_t *dev, const char *s, size_t n) 566 { 567 ega_instance_t *instance = (ega_instance_t *) dev->data; 568 569 irq_spinlock_lock(&instance->lock, true); 570 571 size_t offset = 0; 572 char32_t ch; 573 574 while ((ch = str_decode_r(s, &offset, n, U_SPECIAL, &instance->mbstate))) 575 _putuchar(instance, ch); 566 576 567 577 irq_spinlock_unlock(&instance->lock, true); -
kernel/genarch/src/drivers/ns16550/ns16550.c
r690ad20 r39e1b9a 112 112 } 113 113 114 static void ns16550_ putuchar(outdev_t *dev, char32_t ch)114 static void ns16550_write(outdev_t *dev, const char *s, size_t n) 115 115 { 116 116 ns16550_instance_t *instance = (ns16550_instance_t *) dev->data; 117 117 118 if ((!instance->parea.mapped) || (console_override)) { 119 if (ch == '\n') 118 if (instance->parea.mapped && !console_override) 119 return; 120 121 const char *top = s + n; 122 assert(top >= s); 123 124 for (; s < top; s++) { 125 if (*s == '\n') 120 126 ns16550_sendb(instance, '\r'); 121 127 122 if (ascii_check(ch)) 123 ns16550_sendb(instance, (uint8_t) ch); 124 else 125 ns16550_sendb(instance, U_SPECIAL); 128 ns16550_sendb(instance, (uint8_t) *s); 126 129 } 127 130 } 128 131 129 132 static outdev_operations_t ns16550_ops = { 130 .write = ns16550_ putuchar,133 .write = ns16550_write, 131 134 .redraw = NULL 132 135 }; -
kernel/genarch/src/drivers/pl011/pl011.c
r690ad20 r39e1b9a 56 56 } 57 57 58 static void pl011_uart_ putuchar(outdev_t *dev, char32_t ch)58 static void pl011_uart_write(outdev_t *dev, const char *s, size_t n) 59 59 { 60 60 pl011_uart_t *uart = dev->data; … … 64 64 return; 65 65 66 if (!ascii_check(ch)) 67 pl011_uart_sendb(uart, U_SPECIAL); 68 else { 69 if (ch == '\n') 70 pl011_uart_sendb(uart, (uint8_t) '\r'); 71 pl011_uart_sendb(uart, (uint8_t) ch); 66 const char *top = s + n; 67 assert(top >= s); 68 69 for (; s < top; s++) { 70 if (*s == '\n') 71 pl011_uart_sendb(uart, '\r'); 72 73 pl011_uart_sendb(uart, (uint8_t) *s); 72 74 } 73 75 } 74 76 75 77 static outdev_operations_t pl011_uart_ops = { 76 .write = pl011_uart_ putuchar,78 .write = pl011_uart_write, 77 79 .redraw = NULL, 78 80 .scroll_up = NULL, -
kernel/genarch/src/fb/fb.c
r690ad20 r39e1b9a 121 121 /** Current backbuffer position */ 122 122 unsigned int position; 123 124 /** Partial character between writes */ 125 mbstate_t mbstate; 123 126 } fb_instance_t; 124 127 125 static void fb_ putuchar(outdev_t *, char32_t);128 static void fb_write(outdev_t *, const char *, size_t); 126 129 static void fb_redraw(outdev_t *); 127 130 static void fb_scroll_up(outdev_t *); … … 129 132 130 133 static outdev_operations_t fbdev_ops = { 131 .write = fb_ putuchar,134 .write = fb_write, 132 135 .redraw = fb_redraw, 133 136 .scroll_up = fb_scroll_up, … … 418 421 * 419 422 */ 420 static void fb_putuchar(outdev_t *dev, char32_t ch) 421 { 422 fb_instance_t *instance = (fb_instance_t *) dev->data; 423 spinlock_lock(&instance->lock); 424 423 static void _putuchar(fb_instance_t *instance, char32_t ch) 424 { 425 425 switch (ch) { 426 426 case '\n': 427 cursor_remove(instance);428 427 instance->position += instance->cols; 429 428 instance->position -= instance->position % instance->cols; 430 429 break; 431 430 case '\r': 432 cursor_remove(instance);433 431 instance->position -= instance->position % instance->cols; 434 432 break; 435 433 case '\b': 436 cursor_remove(instance);437 434 if (instance->position % instance->cols) 438 435 instance->position--; 439 436 break; 440 437 case '\t': 441 cursor_remove(instance);442 438 do { 443 439 glyph_draw(instance, fb_font_glyph(' '), … … 459 455 screen_scroll(instance); 460 456 } 457 } 458 459 static void fb_write(outdev_t *dev, const char *s, size_t n) 460 { 461 fb_instance_t *instance = (fb_instance_t *) dev->data; 462 463 spinlock_lock(&instance->lock); 464 cursor_remove(instance); 465 466 size_t offset = 0; 467 char32_t ch; 468 469 while ((ch = str_decode_r(s, &offset, n, U_SPECIAL, &instance->mbstate))) 470 _putuchar(instance, ch); 461 471 462 472 cursor_put(instance); 463 464 473 spinlock_unlock(&instance->lock); 465 474 } -
kernel/generic/include/console/chardev.h
r690ad20 r39e1b9a 81 81 /** Output character device operations interface. */ 82 82 typedef struct { 83 /** Write characterto output. */84 void (*write)(struct outdev *, c har32_t);83 /** Write string to output. */ 84 void (*write)(struct outdev *, const char *, size_t); 85 85 86 86 /** Redraw any previously cached characters. */ -
kernel/generic/src/console/console.c
r690ad20 r39e1b9a 80 80 IRQ_SPINLOCK_INITIALIZE(kio_lock); 81 81 82 static IRQ_SPINLOCK_INITIALIZE(flush_lock); 83 82 84 static IRQ_SPINLOCK_INITIALIZE(early_mbstate_lock); 83 85 static mbstate_t early_mbstate; … … 93 95 }; 94 96 95 static void stdout_write(outdev_t *, c har32_t);97 static void stdout_write(outdev_t *, const char *, size_t); 96 98 static void stdout_redraw(outdev_t *); 97 99 static void stdout_scroll_up(outdev_t *); … … 146 148 } 147 149 148 static void stdout_write(outdev_t *dev, c har32_t ch)150 static void stdout_write(outdev_t *dev, const char *s, size_t n) 149 151 { 150 152 list_foreach(dev->list, link, outdev_t, sink) { 151 153 if ((sink) && (sink->op->write)) 152 sink->op->write(sink, ch);154 sink->op->write(sink, s, n); 153 155 } 154 156 } … … 249 251 irq_spinlock_lock(&kio_lock, true); 250 252 251 static mbstate_t mbstate; 253 if (!irq_spinlock_trylock(&flush_lock)) { 254 /* Someone is currently flushing. */ 255 irq_spinlock_unlock(&kio_lock, true); 256 return; 257 } 258 259 /* A small-ish local buffer so that we can write to output in chunks. */ 260 char buffer[256]; 252 261 253 262 /* Print characters that weren't printed earlier */ … … 255 264 size_t offset = kio_processed % KIO_LENGTH; 256 265 size_t len = min(kio_written - kio_processed, KIO_LENGTH - offset); 257 size_t bytes = 0;258 259 char32_t ch = str_decode_r(&kio[offset], &bytes, len, U'�', &mbstate);260 assert(bytes <= 4);261 kio_processed += bytes;266 len = min(len, sizeof(buffer)); 267 268 /* Take out a chunk of the big buffer. */ 269 memcpy(buffer, &kio[offset], len); 270 kio_processed += len; 262 271 263 272 /* 264 * We need to give up the spinlock for 265 * the physical operation of writing out 266 * the character. 273 * We need to give up the spinlock for the physical operation of writing 274 * out the buffer. 267 275 */ 268 276 irq_spinlock_unlock(&kio_lock, true); 269 stdout->op->write(stdout, ch);277 stdout->op->write(stdout, buffer, len); 270 278 irq_spinlock_lock(&kio_lock, true); 271 279 } 272 280 281 irq_spinlock_unlock(&flush_lock, false); 273 282 irq_spinlock_unlock(&kio_lock, true); 274 283 }
Note:
See TracChangeset
for help on using the changeset viewer.