Subversion Repositories HelenOS

Rev

Rev 2927 | Rev 3153 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2927 Rev 3149
Line 41... Line 41...
41
#include <arch.h>
41
#include <arch.h>
42
#include <func.h>
42
#include <func.h>
43
#include <print.h>
43
#include <print.h>
44
#include <atomic.h>
44
#include <atomic.h>
45
 
45
 
46
#define BUFLEN 2048
46
#define KLOG_SIZE 4096
-
 
47
 
47
static char debug_buffer[BUFLEN];
48
/**< Kernel log cyclic buffer */
48
static size_t offset = 0;
49
static char klog[KLOG_SIZE];
49
/** Initialize stdout to something that does not print, but does not fail
-
 
50
 *
50
 
51
 * Save data in some buffer so that it could be retrieved in the debugger
51
/**< First kernel log characters */
52
 */
-
 
53
static void null_putchar(chardev_t *d, const char ch)
52
static index_t klog_start = 0;
54
{
-
 
55
    if (offset >= BUFLEN)
53
/**< Number of valid kernel log characters */
56
        offset = 0;
54
static size_t klog_len = 0;
-
 
55
/**< Number of stored (not printed) kernel log characters */
57
    debug_buffer[offset++] = ch;
56
static size_t klog_stored = 0;
58
}
-
 
59
 
57
 
60
static chardev_operations_t null_stdout_ops = {
58
static chardev_operations_t null_stdout_ops = {
-
 
59
    .suspend = NULL,
-
 
60
    .resume = NULL,
61
    .write = null_putchar
61
    .write = NULL,
-
 
62
    .read = NULL
62
};
63
};
63
 
64
 
64
chardev_t null_stdout = {
65
chardev_t null_stdout = {
65
    .name = "null",
66
    .name = "null",
66
    .op = &null_stdout_ops
67
    .op = &null_stdout_ops
Line 88... Line 89...
88
         */
89
         */
89
        if (chardev->op->read)
90
        if (chardev->op->read)
90
            return chardev->op->read(chardev);
91
            return chardev->op->read(chardev);
91
        /* no other way of interacting with user, halt */
92
        /* no other way of interacting with user, halt */
92
        if (CPU)
93
        if (CPU)
93
            printf("cpu%d: ", CPU->id);
94
            printf("cpu%u: ", CPU->id);
94
        else
95
        else
95
            printf("cpu: ");
96
            printf("cpu: ");
96
        printf("halted - no kconsole\n");
97
        printf("halted - no kconsole\n");
97
        cpu_halt();
98
        cpu_halt();
98
    }
99
    }
Line 159... Line 160...
159
    return ch;
160
    return ch;
160
}
161
}
161
 
162
 
162
void putchar(char c)
163
void putchar(char c)
163
{
164
{
-
 
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
   
164
    if (stdout->op->write)
180
    if (stdout->op->write)
165
        stdout->op->write(stdout, c);
181
        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
    }
166
}
187
}
167
 
188
 
168
/** @}
189
/** @}
169
 */
190
 */