Changeset 44b7783 in mainline for kernel/generic/src/console/console.c
- Timestamp:
- 2009-04-21T12:43:14Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c2417bc
- Parents:
- d6d04e7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/console/console.c
rd6d04e7 r44b7783 45 45 #include <ipc/irq.h> 46 46 #include <arch.h> 47 #include <func.h>48 47 #include <print.h> 49 48 #include <putchar.h> … … 71 70 static size_t klog_uspace = 0; 72 71 72 /** Kernel log spinlock */ 73 SPINLOCK_INITIALIZE(klog_lock); 74 75 /** Physical memory area used for klog buffer */ 76 static parea_t klog_parea; 77 78 static indev_operations_t stdin_ops = { 79 .poll = NULL 80 }; 81 73 82 /** Silence output */ 74 83 bool silent = false; 75 76 /** Kernel log spinlock */77 SPINLOCK_INITIALIZE(klog_lock);78 79 /** Physical memory area used for klog buffer */80 static parea_t klog_parea;81 84 82 85 /** Standard input and output character devices */ 83 86 indev_t *stdin = NULL; 84 87 outdev_t *stdout = NULL; 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 } 85 99 86 100 /** Initialize kernel logging facility … … 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 that162 * issued the 'halt' command, so proceed to read the character163 * directly from input164 */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 else174 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 155 /** Get string from input character device. 191 156 * … … 207 172 208 173 wchar_t ch; 209 while ((ch = _getc(indev)) != '\n') {174 while ((ch = indev_pop_character(indev)) != '\n') { 210 175 if (ch == '\b') { 211 176 if (count > 0) { … … 233 198 wchar_t getc(indev_t *indev) 234 199 { 235 wchar_t ch = _getc(indev);200 wchar_t ch = indev_pop_character(indev); 236 201 putchar(ch); 237 202 return ch;
Note:
See TracChangeset
for help on using the changeset viewer.