Changeset 690ad20 in mainline for kernel/generic/src/console/console.c
- Timestamp:
- 2025-04-17T15:29:16Z (5 days ago)
- Branches:
- master
- Children:
- 39e1b9a
- Parents:
- d5b37b6
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2025-04-11 20:06:16)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2025-04-17 15:29:16)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/console/console.c
rd5b37b6 r690ad20 40 40 #include <errno.h> 41 41 #include <ipc/event.h> 42 #include <log.h> 42 43 #include <panic.h> 43 44 #include <preemption.h> 44 45 #include <proc/task.h> 45 #include <putchar.h>46 46 #include <stdatomic.h> 47 47 #include <stdio.h> 48 48 #include <stdlib.h> /* malloc */ 49 #include <str.h> 49 50 #include <synch/mutex.h> 50 51 #include <synch/spinlock.h> … … 53 54 54 55 #define KIO_PAGES 8 55 #define KIO_LENGTH (KIO_PAGES * PAGE_SIZE / sizeof(char32_t))56 #define KIO_LENGTH (KIO_PAGES * PAGE_SIZE) 56 57 57 58 /** Kernel log cyclic buffer */ 58 static char 32_tkio[KIO_LENGTH];59 static char kio[KIO_LENGTH]; 59 60 60 61 /** Kernel log initialized */ … … 78 79 /** Kernel log spinlock */ 79 80 IRQ_SPINLOCK_INITIALIZE(kio_lock); 81 82 static IRQ_SPINLOCK_INITIALIZE(early_mbstate_lock); 83 static mbstate_t early_mbstate; 80 84 81 85 static indev_t stdin_sink; … … 245 249 irq_spinlock_lock(&kio_lock, true); 246 250 251 static mbstate_t mbstate; 252 247 253 /* Print characters that weren't printed earlier */ 248 254 while (kio_written != kio_processed) { 249 char32_t tmp = kio[kio_processed % KIO_LENGTH]; 250 kio_processed++; 255 size_t offset = kio_processed % KIO_LENGTH; 256 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; 251 262 252 263 /* … … 256 267 */ 257 268 irq_spinlock_unlock(&kio_lock, true); 258 stdout->op->write(stdout, tmp);269 stdout->op->write(stdout, ch); 259 270 irq_spinlock_lock(&kio_lock, true); 260 271 } … … 263 274 } 264 275 265 /** Put a character into the output buffer. 266 * 267 * The caller is required to hold kio_lock 268 */ 269 void kio_push_char(const char32_t ch) 270 { 271 kio[kio_written % KIO_LENGTH] = ch; 272 kio_written++; 273 } 274 275 void putuchar(const char32_t ch) 276 void kio_push_bytes(const char *s, size_t n) 277 { 278 /* Skip the section we know we can't keep. */ 279 if (n > KIO_LENGTH) { 280 size_t lost = n - KIO_LENGTH; 281 kio_written += lost; 282 s += lost; 283 n -= lost; 284 } 285 286 size_t offset = kio_written % KIO_LENGTH; 287 if (offset + n > KIO_LENGTH) { 288 size_t first = KIO_LENGTH - offset; 289 size_t last = n - first; 290 memcpy(kio + offset, s, first); 291 memcpy(kio, s + first, last); 292 } else { 293 memcpy(kio + offset, s, n); 294 } 295 296 kio_written += n; 297 } 298 299 static void early_putstr(const char *s, size_t n) 300 { 301 irq_spinlock_lock(&early_mbstate_lock, true); 302 303 size_t offset = 0; 304 char32_t c; 305 306 while ((c = str_decode_r(s, &offset, n, U_SPECIAL, &early_mbstate))) 307 early_putuchar(c); 308 309 irq_spinlock_unlock(&early_mbstate_lock, true); 310 } 311 312 void putstr(const char *s, size_t n) 276 313 { 277 314 bool ordy = ((stdout) && (stdout->op->write)); 278 315 279 316 irq_spinlock_lock(&kio_lock, true); 280 kio_push_ char(ch);317 kio_push_bytes(s, n); 281 318 irq_spinlock_unlock(&kio_lock, true); 282 319 … … 295 332 * a no-op on certain hardware configurations. 296 333 */ 297 early_put uchar(ch);298 } 299 300 /* Force notification onnewline */301 if ( ch == '\n')334 early_putstr(s, n); 335 } 336 337 /* Force notification when containing a newline */ 338 if (memchr(s, '\n', n) != NULL) 302 339 kio_update(NULL); 303 340 } … … 336 373 size_t first = KIO_LENGTH - offset; 337 374 size_t last = actual_read - first; 338 size_t first_bytes = first * sizeof(kio[0]); 339 size_t last_bytes = last * sizeof(kio[0]); 340 341 rc = copy_to_uspace(buf, &kio[offset], first_bytes); 375 376 rc = copy_to_uspace(buf, &kio[offset], first); 342 377 if (rc == EOK) 343 rc = copy_to_uspace(buf + first _bytes, &kio[0], last_bytes);378 rc = copy_to_uspace(buf + first, &kio[0], last); 344 379 } else { 345 rc = copy_to_uspace(buf, &kio[offset], actual_read * sizeof(kio[0]));380 rc = copy_to_uspace(buf, &kio[offset], actual_read); 346 381 } 347 382
Note:
See TracChangeset
for help on using the changeset viewer.