Ignore:
Timestamp:
2014-01-17T17:02:59Z (10 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
476f62c, facc34d
Parents:
2e80321 (diff), 61b5b73d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Mainline changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/console/console.c

    r2e80321 r66be0288  
    5252#include <errno.h>
    5353#include <str.h>
    54 #include <abi/klog.h>
    55 
    56 #define KLOG_PAGES    8
    57 #define KLOG_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))
    5858
    5959/** Kernel log cyclic buffer */
    60 wchar_t klog[KLOG_LENGTH] __attribute__((aligned(PAGE_SIZE)));
     60wchar_t kio[KIO_LENGTH] __attribute__((aligned(PAGE_SIZE)));
    6161
    6262/** Kernel log initialized */
    63 static atomic_t klog_inited = {false};
     63static atomic_t kio_inited = {false};
    6464
    6565/** First kernel log characters */
    66 static size_t klog_start = 0;
     66static size_t kio_start = 0;
    6767
    6868/** Number of valid kernel log characters */
    69 static size_t klog_len = 0;
     69static size_t kio_len = 0;
    7070
    7171/** Number of stored (not printed) kernel log characters */
    72 static size_t klog_stored = 0;
     72static size_t kio_stored = 0;
    7373
    7474/** Number of stored kernel log characters for uspace */
    75 static size_t klog_uspace = 0;
     75static size_t kio_uspace = 0;
    7676
    7777/** Kernel log spinlock */
    78 SPINLOCK_STATIC_INITIALIZE_NAME(klog_lock, "klog_lock");
    79 
    80 /** Physical memory area used for klog buffer */
    81 static parea_t klog_parea;
     78SPINLOCK_INITIALIZE_NAME(kio_lock, "kio_lock");
     79
     80/** Physical memory area used for kio buffer */
     81static parea_t kio_parea;
    8282
    8383static indev_t stdin_sink;
     
    146146 *
    147147 */
    148 void klog_init(void)
    149 {
    150         void *faddr = (void *) KA2PA(klog);
     148void kio_init(void)
     149{
     150        void *faddr = (void *) KA2PA(kio);
    151151       
    152152        ASSERT((uintptr_t) faddr % FRAME_SIZE == 0);
    153153       
    154         klog_parea.pbase = (uintptr_t) faddr;
    155         klog_parea.frames = SIZE2FRAMES(sizeof(klog));
    156         klog_parea.unpriv = false;
    157         klog_parea.mapped = false;
    158         ddi_parea_register(&klog_parea);
    159        
    160         sysinfo_set_item_val("klog.faddr", NULL, (sysarg_t) faddr);
    161         sysinfo_set_item_val("klog.pages", NULL, KLOG_PAGES);
    162        
    163         event_set_unmask_callback(EVENT_KLOG, klog_update);
    164         atomic_set(&klog_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);
    165165}
    166166
     
    247247}
    248248
    249 void klog_update(void *event)
    250 {
    251         if (!atomic_get(&klog_inited))
     249void kio_update(void *event)
     250{
     251        if (!atomic_get(&kio_inited))
    252252                return;
    253253       
    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 */
     268void 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 */
     299void 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++;
    263313}
    264314
     
    267317        bool ordy = ((stdout) && (stdout->op->write));
    268318       
    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();
    294325       
    295326        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 case
    309                  * it should be no longer buffered.
    310                  */
    311                 stdout->op->write(stdout, ch);
    312         } else {
    313327                /*
    314328                 * No standard output routine defined yet.
     
    326340        /* Force notification on newline */
    327341        if (ch == '\n')
    328                 klog_update(NULL);
     342                kio_update(NULL);
    329343}
    330344
     
    334348 *
    335349 */
    336 sysarg_t sys_klog(int cmd, const void *buf, size_t size)
     350sysarg_t sys_kio(int cmd, const void *buf, size_t size)
    337351{
    338352        char *data;
     
    340354
    341355        switch (cmd) {
    342         case KLOG_UPDATE:
    343                 klog_update(NULL);
     356        case KIO_UPDATE:
     357                kio_update(NULL);
    344358                return EOK;
    345         case KLOG_WRITE:
    346         case KLOG_COMMAND:
     359        case KIO_WRITE:
     360        case KIO_COMMAND:
    347361                break;
    348362        default:
     
    366380               
    367381                switch (cmd) {
    368                 case KLOG_WRITE:
     382                case KIO_WRITE:
    369383                        printf("%s", data);
    370384                        break;
    371                 case KLOG_COMMAND:
     385                case KIO_COMMAND:
    372386                        if (!stdin)
    373387                                break;
Note: See TracChangeset for help on using the changeset viewer.