Changes in kernel/generic/src/console/console.c [feeac0d:91db0280] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/console/console.c
rfeeac0d r91db0280 52 52 #include <errno.h> 53 53 #include <str.h> 54 #include <abi/k log.h>55 56 #define K LOG_PAGES 857 #define K LOG_LENGTH (KLOG_PAGES * PAGE_SIZE / sizeof(wchar_t))54 #include <abi/kio.h> 55 56 #define KIO_PAGES 8 57 #define KIO_LENGTH (KIO_PAGES * PAGE_SIZE / sizeof(wchar_t)) 58 58 59 59 /** Kernel log cyclic buffer */ 60 wchar_t k log[KLOG_LENGTH] __attribute__((aligned(PAGE_SIZE)));60 wchar_t kio[KIO_LENGTH] __attribute__((aligned(PAGE_SIZE))); 61 61 62 62 /** Kernel log initialized */ 63 static atomic_t k log_inited = {false};63 static atomic_t kio_inited = {false}; 64 64 65 65 /** First kernel log characters */ 66 static size_t k log_start = 0;66 static size_t kio_start = 0; 67 67 68 68 /** Number of valid kernel log characters */ 69 static size_t k log_len = 0;69 static size_t kio_len = 0; 70 70 71 71 /** Number of stored (not printed) kernel log characters */ 72 static size_t k log_stored = 0;72 static size_t kio_stored = 0; 73 73 74 74 /** Number of stored kernel log characters for uspace */ 75 static size_t k log_uspace = 0;75 static size_t kio_uspace = 0; 76 76 77 77 /** Kernel log spinlock */ 78 SPINLOCK_ STATIC_INITIALIZE_NAME(klog_lock, "klog_lock");79 80 /** Physical memory area used for k logbuffer */81 static parea_t k log_parea;78 SPINLOCK_INITIALIZE_NAME(kio_lock, "kio_lock"); 79 80 /** Physical memory area used for kio buffer */ 81 static parea_t kio_parea; 82 82 83 83 static indev_t stdin_sink; … … 146 146 * 147 147 */ 148 void k log_init(void)149 { 150 void *faddr = (void *) KA2PA(k log);148 void kio_init(void) 149 { 150 void *faddr = (void *) KA2PA(kio); 151 151 152 152 ASSERT((uintptr_t) faddr % FRAME_SIZE == 0); 153 153 154 k log_parea.pbase = (uintptr_t) faddr;155 k log_parea.frames = SIZE2FRAMES(sizeof(klog));156 k log_parea.unpriv = false;157 k log_parea.mapped = false;158 ddi_parea_register(&k log_parea);159 160 sysinfo_set_item_val("k log.faddr", NULL, (sysarg_t) faddr);161 sysinfo_set_item_val("k log.pages", NULL, KLOG_PAGES);162 163 event_set_unmask_callback(EVENT_K LOG, klog_update);164 atomic_set(&k log_inited, true);154 kio_parea.pbase = (uintptr_t) faddr; 155 kio_parea.frames = SIZE2FRAMES(sizeof(kio)); 156 kio_parea.unpriv = false; 157 kio_parea.mapped = false; 158 ddi_parea_register(&kio_parea); 159 160 sysinfo_set_item_val("kio.faddr", NULL, (sysarg_t) faddr); 161 sysinfo_set_item_val("kio.pages", NULL, KIO_PAGES); 162 163 event_set_unmask_callback(EVENT_KIO, kio_update); 164 atomic_set(&kio_inited, true); 165 165 } 166 166 … … 247 247 } 248 248 249 void k log_update(void *event)250 { 251 if (!atomic_get(&k log_inited))249 void kio_update(void *event) 250 { 251 if (!atomic_get(&kio_inited)) 252 252 return; 253 253 254 spinlock_lock(&klog_lock); 255 256 if (klog_uspace > 0) { 257 if (event_notify_3(EVENT_KLOG, true, klog_start, klog_len, 258 klog_uspace) == EOK) 259 klog_uspace = 0; 260 } 261 262 spinlock_unlock(&klog_lock); 254 spinlock_lock(&kio_lock); 255 256 if (kio_uspace > 0) { 257 if (event_notify_3(EVENT_KIO, true, kio_start, kio_len, 258 kio_uspace) == EOK) 259 kio_uspace = 0; 260 } 261 262 spinlock_unlock(&kio_lock); 263 } 264 265 /** Flush characters that are stored in the output buffer 266 * 267 */ 268 void kio_flush(void) 269 { 270 bool ordy = ((stdout) && (stdout->op->write)); 271 272 if (!ordy) 273 return; 274 275 spinlock_lock(&kio_lock); 276 277 /* Print characters that weren't printed earlier */ 278 while (kio_stored > 0) { 279 wchar_t tmp = kio[(kio_start + kio_len - kio_stored) % KIO_LENGTH]; 280 kio_stored--; 281 282 /* 283 * We need to give up the spinlock for 284 * the physical operation of writing out 285 * the character. 286 */ 287 spinlock_unlock(&kio_lock); 288 stdout->op->write(stdout, tmp); 289 spinlock_lock(&kio_lock); 290 } 291 292 spinlock_unlock(&kio_lock); 293 } 294 295 /** Put a character into the output buffer. 296 * 297 * The caller is required to hold kio_lock 298 */ 299 void kio_push_char(const wchar_t ch) 300 { 301 kio[(kio_start + kio_len) % KIO_LENGTH] = ch; 302 if (kio_len < KIO_LENGTH) 303 kio_len++; 304 else 305 kio_start = (kio_start + 1) % KIO_LENGTH; 306 307 if (kio_stored < kio_len) 308 kio_stored++; 309 310 /* The character is stored for uspace */ 311 if (kio_uspace < kio_len) 312 kio_uspace++; 263 313 } 264 314 … … 267 317 bool ordy = ((stdout) && (stdout->op->write)); 268 318 269 spinlock_lock(&klog_lock); 270 271 /* Print charaters stored in kernel log */ 272 if (ordy) { 273 while (klog_stored > 0) { 274 wchar_t tmp = klog[(klog_start + klog_len - klog_stored) % KLOG_LENGTH]; 275 klog_stored--; 276 277 /* 278 * We need to give up the spinlock for 279 * the physical operation of writting out 280 * the character. 281 */ 282 spinlock_unlock(&klog_lock); 283 stdout->op->write(stdout, tmp); 284 spinlock_lock(&klog_lock); 285 } 286 } 287 288 /* Store character in the cyclic kernel log */ 289 klog[(klog_start + klog_len) % KLOG_LENGTH] = ch; 290 if (klog_len < KLOG_LENGTH) 291 klog_len++; 292 else 293 klog_start = (klog_start + 1) % KLOG_LENGTH; 319 spinlock_lock(&kio_lock); 320 kio_push_char(ch); 321 spinlock_unlock(&kio_lock); 322 323 /* Output stored characters */ 324 kio_flush(); 294 325 295 326 if (!ordy) { 296 if (klog_stored < klog_len)297 klog_stored++;298 }299 300 /* The character is stored for uspace */301 if (klog_uspace < klog_len)302 klog_uspace++;303 304 spinlock_unlock(&klog_lock);305 306 if (ordy) {307 /*308 * Output the character. In this case309 * it should be no longer buffered.310 */311 stdout->op->write(stdout, ch);312 } else {313 327 /* 314 328 * No standard output routine defined yet. … … 326 340 /* Force notification on newline */ 327 341 if (ch == '\n') 328 k log_update(NULL);342 kio_update(NULL); 329 343 } 330 344 … … 334 348 * 335 349 */ 336 sysarg_t sys_k log(int cmd, const void *buf, size_t size)350 sysarg_t sys_kio(int cmd, const void *buf, size_t size) 337 351 { 338 352 char *data; … … 340 354 341 355 switch (cmd) { 342 case K LOG_UPDATE:343 k log_update(NULL);356 case KIO_UPDATE: 357 kio_update(NULL); 344 358 return EOK; 345 case K LOG_WRITE:346 case K LOG_COMMAND:359 case KIO_WRITE: 360 case KIO_COMMAND: 347 361 break; 348 362 default: … … 366 380 367 381 switch (cmd) { 368 case K LOG_WRITE:382 case KIO_WRITE: 369 383 printf("%s", data); 370 384 break; 371 case K LOG_COMMAND:385 case KIO_COMMAND: 372 386 if (!stdin) 373 387 break;
Note:
See TracChangeset
for help on using the changeset viewer.