Rev 4194 | Rev 4226 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4194 | Rev 4218 | ||
---|---|---|---|
Line 48... | Line 48... | ||
48 | #include <print.h> |
48 | #include <print.h> |
49 | #include <putchar.h> |
49 | #include <putchar.h> |
50 | #include <atomic.h> |
50 | #include <atomic.h> |
51 | #include <syscall/copy.h> |
51 | #include <syscall/copy.h> |
52 | #include <errno.h> |
52 | #include <errno.h> |
- | 53 | #include <string.h> |
|
53 | 54 | ||
54 | #define KLOG_SIZE PAGE_SIZE |
55 | #define KLOG_SIZE PAGE_SIZE |
55 | #define KLOG_LATENCY 8 |
56 | #define KLOG_LATENCY 8 |
56 | 57 | ||
57 | /** Kernel log cyclic buffer */ |
58 | /** Kernel log cyclic buffer */ |
Line 152... | Line 153... | ||
152 | * |
153 | * |
153 | * @param indev Input character device. |
154 | * @param indev Input character device. |
154 | * @return Character read. |
155 | * @return Character read. |
155 | * |
156 | * |
156 | */ |
157 | */ |
157 | uint8_t _getc(indev_t *indev) |
158 | wchar_t _getc(indev_t *indev) |
158 | { |
159 | { |
159 | if (atomic_get(&haltstate)) { |
160 | if (atomic_get(&haltstate)) { |
160 | /* If we are here, we are hopefully on the processor that |
161 | /* If we are here, we are hopefully on the processor that |
161 | * issued the 'halt' command, so proceed to read the character |
162 | * issued the 'halt' command, so proceed to read the character |
162 | * directly from input |
163 | * directly from input |
Line 176... | Line 177... | ||
176 | } |
177 | } |
177 | 178 | ||
178 | waitq_sleep(&indev->wq); |
179 | waitq_sleep(&indev->wq); |
179 | ipl_t ipl = interrupts_disable(); |
180 | ipl_t ipl = interrupts_disable(); |
180 | spinlock_lock(&indev->lock); |
181 | spinlock_lock(&indev->lock); |
181 | uint8_t ch = indev->buffer[(indev->index - indev->counter) % INDEV_BUFLEN]; |
182 | wchar_t ch = indev->buffer[(indev->index - indev->counter) % INDEV_BUFLEN]; |
182 | indev->counter--; |
183 | indev->counter--; |
183 | spinlock_unlock(&indev->lock); |
184 | spinlock_unlock(&indev->lock); |
184 | interrupts_restore(ipl); |
185 | interrupts_restore(ipl); |
185 | 186 | ||
186 | return ch; |
187 | return ch; |
Line 190... | Line 191... | ||
190 | * |
191 | * |
191 | * Read characters from input character device until first occurrence |
192 | * Read characters from input character device until first occurrence |
192 | * of newline character. |
193 | * of newline character. |
193 | * |
194 | * |
194 | * @param indev Input character device. |
195 | * @param indev Input character device. |
195 | * @param buf Buffer where to store string terminated by '\0'. |
196 | * @param buf Buffer where to store string terminated by NULL. |
196 | * @param buflen Size of the buffer. |
197 | * @param buflen Size of the buffer. |
197 | * |
198 | * |
198 | * @return Number of characters read. |
199 | * @return Number of characters read. |
199 | * |
200 | * |
200 | */ |
201 | */ |
201 | count_t gets(indev_t *indev, char *buf, size_t buflen) |
202 | count_t gets(indev_t *indev, char *buf, size_t buflen) |
202 | { |
203 | { |
203 | index_t index = 0; |
204 | size_t offset = 0; |
- | 205 | count_t count = 0; |
|
- | 206 | buf[offset] = 0; |
|
204 | 207 | ||
205 | while (index < buflen) { |
208 | wchar_t ch; |
206 | char ch = _getc(indev); |
209 | while ((ch = _getc(indev)) != '\n') { |
207 | if (ch == '\b') { |
210 | if (ch == '\b') { |
208 | if (index > 0) { |
211 | if (count > 0) { |
209 | index--; |
- | |
210 | /* Space backspace, space */ |
212 | /* Space, backspace, space */ |
211 | putchar('\b'); |
213 | putchar('\b'); |
212 | putchar(' '); |
214 | putchar(' '); |
213 | putchar('\b'); |
215 | putchar('\b'); |
- | 216 | ||
- | 217 | count--; |
|
- | 218 | offset = str_lsize(buf, count); |
|
- | 219 | buf[offset] = 0; |
|
214 | } |
220 | } |
215 | continue; |
- | |
216 | } |
- | |
217 | putchar(ch); |
- | |
218 | - | ||
219 | if (ch == '\n') { /* end of string => write 0, return */ |
- | |
220 | buf[index] = '\0'; |
- | |
221 | return (count_t) index; |
- | |
222 | } |
221 | } |
- | 222 | if (chr_encode(ch, buf, &offset, buflen - 1) == EOK) { |
|
- | 223 | putchar(ch); |
|
- | 224 | count++; |
|
223 | buf[index++] = ch; |
225 | buf[offset] = 0; |
- | 226 | } |
|
224 | } |
227 | } |
225 | 228 | ||
226 | return (count_t) index; |
229 | return count; |
227 | } |
230 | } |
228 | 231 | ||
229 | /** Get character from input device & echo it to screen */ |
232 | /** Get character from input device & echo it to screen */ |
230 | uint8_t getc(indev_t *indev) |
233 | wchar_t getc(indev_t *indev) |
231 | { |
234 | { |
232 | uint8_t ch = _getc(indev); |
235 | wchar_t ch = _getc(indev); |
233 | putchar(ch); |
236 | putchar(ch); |
234 | return ch; |
237 | return ch; |
235 | } |
238 | } |
236 | 239 | ||
237 | void klog_update(void) |
240 | void klog_update(void) |
Line 293... | Line 296... | ||
293 | /** Print using kernel facility |
296 | /** Print using kernel facility |
294 | * |
297 | * |
295 | * Print to kernel log. |
298 | * Print to kernel log. |
296 | * |
299 | * |
297 | */ |
300 | */ |
298 | unative_t sys_klog(int fd, const void * buf, size_t count) |
301 | unative_t sys_klog(int fd, const void *buf, size_t size) |
299 | { |
302 | { |
300 | char *data; |
303 | char *data; |
301 | int rc; |
304 | int rc; |
302 | 305 | ||
303 | if (count > PAGE_SIZE) |
306 | if (size > PAGE_SIZE) |
304 | return ELIMIT; |
307 | return ELIMIT; |
305 | 308 | ||
306 | if (count > 0) { |
309 | if (size > 0) { |
307 | data = (char *) malloc(count + 1, 0); |
310 | data = (char *) malloc(size + 1, 0); |
308 | if (!data) |
311 | if (!data) |
309 | return ENOMEM; |
312 | return ENOMEM; |
310 | 313 | ||
311 | rc = copy_from_uspace(data, buf, count); |
314 | rc = copy_from_uspace(data, buf, size); |
312 | if (rc) { |
315 | if (rc) { |
313 | free(data); |
316 | free(data); |
314 | return rc; |
317 | return rc; |
315 | } |
318 | } |
316 | data[count] = 0; |
319 | data[size] = 0; |
317 | 320 | ||
318 | printf("%s", data); |
321 | printf("%s", data); |
319 | free(data); |
322 | free(data); |
320 | } else |
323 | } else |
321 | klog_update(); |
324 | klog_update(); |
322 | 325 | ||
323 | return count; |
326 | return size; |
324 | } |
327 | } |
325 | 328 | ||
326 | /** @} |
329 | /** @} |
327 | */ |
330 | */ |