Changeset 690ad20 in mainline
- 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)
- Files:
-
- 1 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/console/console.h
rd5b37b6 r690ad20 64 64 extern void kio_update(void *); 65 65 extern void kio_flush(void); 66 extern void kio_push_ char(const char32_t);66 extern void kio_push_bytes(const char *, size_t); 67 67 extern irq_spinlock_t kio_lock; 68 68 … … 78 78 extern void console_unlock(void); 79 79 80 extern void putstr(const char *s, size_t n); 81 80 82 #endif /* KERN_CONSOLE_H_ */ 81 83 -
kernel/generic/include/stdio.h
rd5b37b6 r690ad20 37 37 38 38 #include <print.h> 39 #include <putchar.h>40 39 41 40 #endif -
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 -
kernel/generic/src/console/kconsole.c
rd5b37b6 r690ad20 39 39 */ 40 40 41 #include <adt/list.h> 42 #include <arch.h> 41 43 #include <assert.h> 42 #include <console/kconsole.h>43 #include <console/console.h>44 44 #include <console/chardev.h> 45 45 #include <console/cmd.h> 46 #include <console/console.h> 47 #include <console/kconsole.h> 46 48 #include <console/prompt.h> 49 #include <debug.h> 50 #include <errno.h> 51 #include <halt.h> 52 #include <macros.h> 53 #include <panic.h> 47 54 #include <stdio.h> 48 #include <panic.h> 55 #include <stdlib.h> 56 #include <str.h> 57 #include <symtab.h> 58 #include <sysinfo/sysinfo.h> 49 59 #include <typedefs.h> 50 #include <adt/list.h>51 #include <arch.h>52 #include <macros.h>53 #include <debug.h>54 #include <halt.h>55 #include <str.h>56 #include <sysinfo/sysinfo.h>57 #include <symtab.h>58 #include <errno.h>59 #include <putchar.h>60 #include <stdlib.h>61 60 62 61 /** Simple kernel console. … … 158 157 159 158 /** Print count times a character */ 160 _NO_TRACE static void print_cc(char32_t ch, size_t count) 161 { 162 size_t i; 163 for (i = 0; i < count; i++) 164 putuchar(ch); 159 _NO_TRACE static void print_cc(char ch, size_t count) 160 { 161 // FIXME: only lock once 162 163 for (size_t i = 0; i < count; i++) 164 putstr(&ch, 1); 165 165 } 166 166 … … 347 347 if (ch == '\n') { 348 348 /* Enter */ 349 put uchar(ch);349 putstr("\n", 1); 350 350 break; 351 351 } … … 358 358 if (wstr_remove(current, position - 1)) { 359 359 position--; 360 put uchar('\b');360 putstr("\b", 1); 361 361 printf("%ls ", current + position); 362 362 print_cc('\b', wstr_length(current) - position + 1); … … 368 368 /* Tab completion */ 369 369 370 /* Move to the end of the word */ 371 for (; (current[position] != 0) && (!isspace(current[position])); 372 position++) 373 putuchar(current[position]); 370 size_t i = position; 371 while (current[i] && !isspace(current[i])) 372 i++; 373 374 char32_t stash = current[i]; 375 current[i] = 0; 376 printf("%ls", ¤t[position]); 377 current[i] = stash; 378 position = i; 374 379 375 380 /* … … 430 435 */ 431 436 size_t off = 0; 432 size_t i = 0; 433 while ((ch = str_decode(tmp, &off, STR_NO_LIMIT)) != 0) { 437 for (size_t i = 0; (ch = str_decode(tmp, &off, STR_NO_LIMIT)); i++) 434 438 if (!wstr_linsert(current, ch, position + i, MAX_CMDLINE)) 435 439 break; 436 437 i++;438 }439 440 440 441 if (found > 1) { … … 466 467 /* Left */ 467 468 if (position > 0) { 468 put uchar('\b');469 putstr("\b", 1); 469 470 position--; 470 471 } … … 475 476 /* Right */ 476 477 if (position < wstr_length(current)) { 477 p utuchar(current[position]);478 printf("%lc", current[position]); 478 479 position++; 479 480 } -
kernel/generic/src/log/log.c
rd5b37b6 r690ad20 46 46 #include <print.h> 47 47 #include <printf_core.h> 48 #include <putchar.h>49 48 #include <stdarg.h> 50 49 #include <stdlib.h> … … 179 178 log_used += log_current_len; 180 179 181 kio_push_ char('\n');180 kio_push_bytes("\n", 1); 182 181 irq_spinlock_unlock(&kio_lock, true); 183 182 irq_spinlock_unlock(&log_lock, true); … … 203 202 static int log_printf_str_write(const char *str, size_t size, void *data) 204 203 { 205 size_t offset = 0; 206 207 while (offset < size) 208 kio_push_char(str_decode(str, &offset, size)); 209 204 kio_push_bytes(str, size); 210 205 log_append((const uint8_t *)str, size); 211 212 206 return EOK; 213 207 } -
kernel/generic/src/printf/vprintf.c
rd5b37b6 r690ad20 37 37 #include <print.h> 38 38 #include <printf_core.h> 39 #include <putchar.h>40 39 #include <str.h> 41 40 #include <synch/spinlock.h> … … 44 43 static errno_t vprintf_str_write(const char *str, size_t size, void *data) 45 44 { 46 size_t offset = 0; 47 48 while (offset < size) 49 putuchar(str_decode(str, &offset, size)); 50 45 putstr(str, size); 51 46 return EOK; 52 47 } … … 54 49 int puts(const char *str) 55 50 { 56 size_t offset = 0; 57 size_t chars = 0; 58 char32_t uc; 59 60 console_lock(); 61 62 while ((uc = str_decode(str, &offset, STR_NO_LIMIT)) != 0) { 63 putuchar(uc); 64 chars++; 65 } 66 67 putuchar('\n'); 68 69 console_unlock(); 70 return chars; 51 size_t n = str_size(str); 52 putstr(str, n); 53 return n; 71 54 } 72 55 -
uspace/app/kio/kio.c
rd5b37b6 r690ad20 59 59 typedef struct { 60 60 link_t link; 61 size_t length;62 char 32_t*data;61 size_t bytes; 62 char *data; 63 63 } item_t; 64 64 … … 68 68 static FIBRIL_MUTEX_INITIALIZE(mtx); 69 69 70 #define READ_BUFFER_SIZE (PAGE_SIZE / sizeof(char32_t))70 #define READ_BUFFER_SIZE PAGE_SIZE 71 71 72 72 static size_t current_at; 73 static char 32_tread_buffer[READ_BUFFER_SIZE];73 static char read_buffer[READ_BUFFER_SIZE]; 74 74 75 75 /** Klog producer … … 82 82 * 83 83 */ 84 static void producer(size_t length, char32_t*data)85 { 86 item_t *item = (item_t *)malloc(sizeof(item_t));84 static void producer(size_t bytes, char *data) 85 { 86 item_t *item = malloc(sizeof(item_t)); 87 87 if (item == NULL) 88 88 return; 89 89 90 size_t sz = sizeof(char32_t) * length;91 char32_t *buf = (char32_t *) malloc(sz);92 if ( buf == NULL) {90 item->bytes = bytes; 91 item->data = malloc(bytes); 92 if (!item->data) { 93 93 free(item); 94 94 return; 95 95 } 96 96 97 memcpy( buf, data, sz);97 memcpy(item->data, data, bytes); 98 98 99 99 link_initialize(&item->link); 100 item->length = length;101 item->data = buf;102 100 prodcons_produce(&pc, &item->link); 103 101 } … … 125 123 item_t *item = list_get_instance(link, item_t, link); 126 124 127 for (size_t i = 0; i < item->length; i++) 128 putuchar(item->data[i]); 129 130 if (log != NULL) { 131 for (size_t i = 0; i < item->length; i++) 132 fputuc(item->data[i], log); 133 125 fwrite(item->data, 1, item->bytes, stdout); 126 127 if (log) { 128 fwrite(item->data, 1, item->bytes, log); 134 129 fflush(log); 135 130 vfs_sync(fileno(log)); -
uspace/lib/c/generic/io/kio.c
rd5b37b6 r690ad20 113 113 } 114 114 115 size_t kio_read(char 32_t*buf, size_t n, size_t at)115 size_t kio_read(char *buf, size_t n, size_t at) 116 116 { 117 117 return __SYSCALL3(SYS_KIO_READ, (sysarg_t) buf, n, at); -
uspace/lib/c/include/io/kio.h
rd5b37b6 r690ad20 52 52 extern int kio_vprintf(const char *, va_list); 53 53 54 extern size_t kio_read(char 32_t*buf, size_t n, size_t at);54 extern size_t kio_read(char *buf, size_t n, size_t at); 55 55 56 56 /*
Note:
See TracChangeset
for help on using the changeset viewer.