Subversion Repositories HelenOS

Rev

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

Rev 4252 Rev 4310
Line 42... Line 42...
42
#include <ddi/irq.h>
42
#include <ddi/irq.h>
43
#include <ddi/ddi.h>
43
#include <ddi/ddi.h>
44
#include <ipc/event.h>
44
#include <ipc/event.h>
45
#include <ipc/irq.h>
45
#include <ipc/irq.h>
46
#include <arch.h>
46
#include <arch.h>
47
#include <func.h>
-
 
48
#include <print.h>
47
#include <print.h>
49
#include <putchar.h>
48
#include <putchar.h>
50
#include <atomic.h>
49
#include <atomic.h>
51
#include <syscall/copy.h>
50
#include <syscall/copy.h>
52
#include <errno.h>
51
#include <errno.h>
Line 68... Line 67...
68
/** Number of stored (not printed) kernel log characters */
67
/** Number of stored (not printed) kernel log characters */
69
static size_t klog_stored = 0;
68
static size_t klog_stored = 0;
70
/** Number of stored kernel log characters for uspace */
69
/** Number of stored kernel log characters for uspace */
71
static size_t klog_uspace = 0;
70
static size_t klog_uspace = 0;
72
 
71
 
73
/** Silence output */
-
 
74
bool silent = false;
-
 
75
 
-
 
76
/** Kernel log spinlock */
72
/** Kernel log spinlock */
77
SPINLOCK_INITIALIZE(klog_lock);
73
SPINLOCK_INITIALIZE(klog_lock);
78
 
74
 
79
/** Physical memory area used for klog buffer */
75
/** Physical memory area used for klog buffer */
80
static parea_t klog_parea;
76
static parea_t klog_parea;
81
 
77
 
-
 
78
static indev_operations_t stdin_ops = {
-
 
79
    .poll = NULL
-
 
80
};
-
 
81
 
-
 
82
/** Silence output */
-
 
83
bool silent = false;
-
 
84
 
82
/** Standard input and output character devices */
85
/** Standard input and output character devices */
83
indev_t *stdin = NULL;
86
indev_t *stdin = NULL;
84
outdev_t *stdout = NULL;
87
outdev_t *stdout = NULL;
85
 
88
 
-
 
89
indev_t *stdin_wire(void)
-
 
90
{
-
 
91
    if (stdin == NULL) {
-
 
92
        stdin = malloc(sizeof(indev_t), FRAME_ATOMIC);
-
 
93
        if (stdin != NULL)
-
 
94
            indev_initialize("stdin", stdin, &stdin_ops);
-
 
95
    }
-
 
96
   
-
 
97
    return stdin;
-
 
98
}
-
 
99
 
86
/** Initialize kernel logging facility
100
/** Initialize kernel logging facility
87
 *
101
 *
88
 * The shared area contains kernel cyclic buffer. Userspace application may
102
 * The shared area contains kernel cyclic buffer. Userspace application may
89
 * be notified on new data with indication of position and size
103
 * be notified on new data with indication of position and size
90
 * of the data within the circular buffer.
104
 * of the data within the circular buffer.
Line 136... Line 150...
136
{
150
{
137
    release_console();
151
    release_console();
138
    return true;
152
    return true;
139
}
153
}
140
 
154
 
141
bool check_poll(indev_t *indev)
-
 
142
{
-
 
143
    if (indev == NULL)
-
 
144
        return false;
-
 
145
   
-
 
146
    if (indev->op == NULL)
-
 
147
        return false;
-
 
148
   
-
 
149
    return (indev->op->poll != NULL);
-
 
150
}
-
 
151
 
-
 
152
/** Get character from input character device. Do not echo character.
-
 
153
 *
-
 
154
 * @param indev Input character device.
-
 
155
 * @return Character read.
-
 
156
 *
-
 
157
 */
-
 
158
wchar_t _getc(indev_t *indev)
-
 
159
{
-
 
160
    if (atomic_get(&haltstate)) {
-
 
161
        /* If we are here, we are hopefully on the processor that
-
 
162
         * issued the 'halt' command, so proceed to read the character
-
 
163
         * directly from input
-
 
164
         */
-
 
165
        if (check_poll(indev))
-
 
166
            return indev->op->poll(indev);
-
 
167
       
-
 
168
        /* No other way of interacting with user */
-
 
169
        interrupts_disable();
-
 
170
       
-
 
171
        if (CPU)
-
 
172
            printf("cpu%u: ", CPU->id);
-
 
173
        else
-
 
174
            printf("cpu: ");
-
 
175
        printf("halted (no polling input)\n");
-
 
176
        cpu_halt();
-
 
177
    }
-
 
178
   
-
 
179
    waitq_sleep(&indev->wq);
-
 
180
    ipl_t ipl = interrupts_disable();
-
 
181
    spinlock_lock(&indev->lock);
-
 
182
    wchar_t ch = indev->buffer[(indev->index - indev->counter) % INDEV_BUFLEN];
-
 
183
    indev->counter--;
-
 
184
    spinlock_unlock(&indev->lock);
-
 
185
    interrupts_restore(ipl);
-
 
186
   
-
 
187
    return ch;
-
 
188
}
-
 
189
 
-
 
190
/** Get string from input character device.
155
/** Get string from input character device.
191
 *
156
 *
192
 * Read characters from input character device until first occurrence
157
 * Read characters from input character device until first occurrence
193
 * of newline character.
158
 * of newline character.
194
 *
159
 *
Line 204... Line 169...
204
    size_t offset = 0;
169
    size_t offset = 0;
205
    count_t count = 0;
170
    count_t count = 0;
206
    buf[offset] = 0;
171
    buf[offset] = 0;
207
   
172
   
208
    wchar_t ch;
173
    wchar_t ch;
209
    while ((ch = _getc(indev)) != '\n') {
174
    while ((ch = indev_pop_character(indev)) != '\n') {
210
        if (ch == '\b') {
175
        if (ch == '\b') {
211
            if (count > 0) {
176
            if (count > 0) {
212
                /* Space, backspace, space */
177
                /* Space, backspace, space */
213
                putchar('\b');
178
                putchar('\b');
214
                putchar(' ');
179
                putchar(' ');
Line 230... Line 195...
230
}
195
}
231
 
196
 
232
/** Get character from input device & echo it to screen */
197
/** Get character from input device & echo it to screen */
233
wchar_t getc(indev_t *indev)
198
wchar_t getc(indev_t *indev)
234
{
199
{
235
    wchar_t ch = _getc(indev);
200
    wchar_t ch = indev_pop_character(indev);
236
    putchar(ch);
201
    putchar(ch);
237
    return ch;
202
    return ch;
238
}
203
}
239
 
204
 
240
void klog_update(void)
205
void klog_update(void)