Changeset c859753 in mainline for kernel/generic/src/console/console.c


Ignore:
Timestamp:
2008-06-03T14:55:09Z (17 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
419886f6
Parents:
aa48a9d
Message:

remove original klog
permanent kernel cyclic log buffer
proper printf formatting

File:
1 edited

Legend:

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

    raa48a9d rc859753  
    4444#include <atomic.h>
    4545
    46 #define BUFLEN 2048
    47 static char debug_buffer[BUFLEN];
    48 static size_t offset = 0;
    49 /** Initialize stdout to something that does not print, but does not fail
    50  *
    51  * Save data in some buffer so that it could be retrieved in the debugger
    52  */
    53 static void null_putchar(chardev_t *d, const char ch)
    54 {
    55         if (offset >= BUFLEN)
    56                 offset = 0;
    57         debug_buffer[offset++] = ch;
    58 }
     46#define KLOG_SIZE 4096
     47
     48/**< Kernel log cyclic buffer */
     49static char klog[KLOG_SIZE];
     50
     51/**< First kernel log characters */
     52static index_t klog_start = 0;
     53/**< Number of valid kernel log characters */
     54static size_t klog_len = 0;
     55/**< Number of stored (not printed) kernel log characters */
     56static size_t klog_stored = 0;
    5957
    6058static chardev_operations_t null_stdout_ops = {
    61         .write = null_putchar
     59        .suspend = NULL,
     60        .resume = NULL,
     61        .write = NULL,
     62        .read = NULL
    6263};
    6364
     
    9192                /* no other way of interacting with user, halt */
    9293                if (CPU)
    93                         printf("cpu%d: ", CPU->id);
     94                        printf("cpu%u: ", CPU->id);
    9495                else
    9596                        printf("cpu: ");
     
    162163void putchar(char c)
    163164{
     165        if ((klog_stored > 0) && (stdout->op->write)) {
     166                /* Print charaters stored in kernel log */
     167                index_t i;
     168                for (i = klog_len - klog_stored; i < klog_len; i++)
     169                        stdout->op->write(stdout, klog[(klog_start + i) % KLOG_SIZE]);
     170                klog_stored = 0;
     171        }
     172       
     173        /* Store character in the cyclic kernel log */
     174        klog[(klog_start + klog_len) % KLOG_SIZE] = c;
     175        if (klog_len < KLOG_SIZE)
     176                klog_len++;
     177        else
     178                klog_start = (klog_start + 1) % KLOG_SIZE;
     179       
    164180        if (stdout->op->write)
    165181                stdout->op->write(stdout, c);
     182        else {
     183                /* The character is just in the kernel log */
     184                if (klog_stored < klog_len)
     185                        klog_stored++;
     186        }
    166187}
    167188
Note: See TracChangeset for help on using the changeset viewer.