Ignore:
Timestamp:
2014-01-05T19:59:56Z (10 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
927cd9c
Parents:
6fa9a99d
Message:

Cherrypick kernel logging facility

File:
1 edited

Legend:

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

    r6fa9a99d r91db0280  
    7676
    7777/** Kernel log spinlock */
    78 SPINLOCK_STATIC_INITIALIZE_NAME(kio_lock, "kio_lock");
     78SPINLOCK_INITIALIZE_NAME(kio_lock, "kio_lock");
    7979
    8080/** Physical memory area used for kio buffer */
     
    263263}
    264264
    265 void putchar(const wchar_t ch)
     265/** Flush characters that are stored in the output buffer
     266 *
     267 */
     268void kio_flush(void)
    266269{
    267270        bool ordy = ((stdout) && (stdout->op->write));
    268271       
     272        if (!ordy)
     273                return;
     274
    269275        spinlock_lock(&kio_lock);
    270        
    271         /* Print charaters stored in kernel log */
    272         if (ordy) {
    273                 while (kio_stored > 0) {
    274                         wchar_t tmp = kio[(kio_start + kio_len - kio_stored) % KIO_LENGTH];
    275                         kio_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(&kio_lock);
    283                         stdout->op->write(stdout, tmp);
    284                         spinlock_lock(&kio_lock);
    285                 }
    286         }
    287        
    288         /* Store character in the cyclic kernel log */
     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{
    289301        kio[(kio_start + kio_len) % KIO_LENGTH] = ch;
    290302        if (kio_len < KIO_LENGTH)
     
    293305                kio_start = (kio_start + 1) % KIO_LENGTH;
    294306       
    295         if (!ordy) {
    296                 if (kio_stored < kio_len)
    297                         kio_stored++;
    298         }
     307        if (kio_stored < kio_len)
     308                kio_stored++;
    299309       
    300310        /* The character is stored for uspace */
    301311        if (kio_uspace < kio_len)
    302312                kio_uspace++;
    303        
     313}
     314
     315void putchar(const wchar_t ch)
     316{
     317        bool ordy = ((stdout) && (stdout->op->write));
     318       
     319        spinlock_lock(&kio_lock);
     320        kio_push_char(ch);
    304321        spinlock_unlock(&kio_lock);
    305322       
    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 {
     323        /* Output stored characters */
     324        kio_flush();
     325       
     326        if (!ordy) {
    313327                /*
    314328                 * No standard output routine defined yet.
Note: See TracChangeset for help on using the changeset viewer.