Changeset 6fa9a99d in mainline for kernel/generic/src/console/console.c
- Timestamp:
- 2014-01-05T17:50:01Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 91db0280
- Parents:
- 208b5f5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/console/console.c
r208b5f5 r6fa9a99d 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(k log_lock, "klog_lock");79 80 /** Physical memory area used for k logbuffer */81 static parea_t k log_parea;78 SPINLOCK_STATIC_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(&k log_lock);255 256 if (k log_uspace > 0) {257 if (event_notify_3(EVENT_K LOG, true, klog_start, klog_len,258 k log_uspace) == EOK)259 k log_uspace = 0;260 } 261 262 spinlock_unlock(&k log_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 263 } 264 264 … … 267 267 bool ordy = ((stdout) && (stdout->op->write)); 268 268 269 spinlock_lock(&k log_lock);269 spinlock_lock(&kio_lock); 270 270 271 271 /* Print charaters stored in kernel log */ 272 272 if (ordy) { 273 while (k log_stored > 0) {274 wchar_t tmp = k log[(klog_start + klog_len - klog_stored) % KLOG_LENGTH];275 k log_stored--;273 while (kio_stored > 0) { 274 wchar_t tmp = kio[(kio_start + kio_len - kio_stored) % KIO_LENGTH]; 275 kio_stored--; 276 276 277 277 /* … … 280 280 * the character. 281 281 */ 282 spinlock_unlock(&k log_lock);282 spinlock_unlock(&kio_lock); 283 283 stdout->op->write(stdout, tmp); 284 spinlock_lock(&k log_lock);284 spinlock_lock(&kio_lock); 285 285 } 286 286 } 287 287 288 288 /* Store character in the cyclic kernel log */ 289 k log[(klog_start + klog_len) % KLOG_LENGTH] = ch;290 if (k log_len < KLOG_LENGTH)291 k log_len++;289 kio[(kio_start + kio_len) % KIO_LENGTH] = ch; 290 if (kio_len < KIO_LENGTH) 291 kio_len++; 292 292 else 293 k log_start = (klog_start + 1) % KLOG_LENGTH;293 kio_start = (kio_start + 1) % KIO_LENGTH; 294 294 295 295 if (!ordy) { 296 if (k log_stored < klog_len)297 k log_stored++;296 if (kio_stored < kio_len) 297 kio_stored++; 298 298 } 299 299 300 300 /* The character is stored for uspace */ 301 if (k log_uspace < klog_len)302 k log_uspace++;303 304 spinlock_unlock(&k log_lock);301 if (kio_uspace < kio_len) 302 kio_uspace++; 303 304 spinlock_unlock(&kio_lock); 305 305 306 306 if (ordy) { … … 326 326 /* Force notification on newline */ 327 327 if (ch == '\n') 328 k log_update(NULL);328 kio_update(NULL); 329 329 } 330 330 … … 334 334 * 335 335 */ 336 sysarg_t sys_k log(int cmd, const void *buf, size_t size)336 sysarg_t sys_kio(int cmd, const void *buf, size_t size) 337 337 { 338 338 char *data; … … 340 340 341 341 switch (cmd) { 342 case K LOG_UPDATE:343 k log_update(NULL);342 case KIO_UPDATE: 343 kio_update(NULL); 344 344 return EOK; 345 case K LOG_WRITE:346 case K LOG_COMMAND:345 case KIO_WRITE: 346 case KIO_COMMAND: 347 347 break; 348 348 default: … … 366 366 367 367 switch (cmd) { 368 case K LOG_WRITE:368 case KIO_WRITE: 369 369 printf("%s", data); 370 370 break; 371 case K LOG_COMMAND:371 case KIO_COMMAND: 372 372 if (!stdin) 373 373 break;
Note:
See TracChangeset
for help on using the changeset viewer.