Changeset 44b7783 in mainline
- 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
- Location:
- kernel/generic
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/console/chardev.h
rd6d04e7 r44b7783 90 90 indev_operations_t *op); 91 91 extern void indev_push_character(indev_t *indev, wchar_t ch); 92 extern wchar_t indev_pop_character(indev_t *indev); 92 93 93 94 extern void outdev_initialize(char *name, outdev_t *outdev, 94 95 outdev_operations_t *op); 96 97 extern bool check_poll(indev_t *indev); 95 98 96 99 #endif /* KERN_CHARDEV_H_ */ -
kernel/generic/include/console/console.h
rd6d04e7 r44b7783 41 41 extern indev_t *stdin; 42 42 extern outdev_t *stdout; 43 44 43 extern bool silent; 45 44 45 extern indev_t *stdin_wire(void); 46 46 extern void console_init(void); 47 47 … … 49 49 extern void klog_update(void); 50 50 51 extern bool check_poll(indev_t *indev);52 51 extern wchar_t getc(indev_t *indev); 53 extern wchar_t _getc(indev_t *indev);54 52 extern count_t gets(indev_t *indev, char *buf, size_t buflen); 55 53 extern unative_t sys_klog(int fd, const void *buf, size_t size); -
kernel/generic/src/console/chardev.c
rd6d04e7 r44b7783 36 36 #include <synch/waitq.h> 37 37 #include <synch/spinlock.h> 38 #include <print.h> 39 #include <func.h> 40 #include <arch.h> 38 41 39 42 /** Initialize input character device. … … 80 83 } 81 84 85 /** Pop character from input character device. 86 * 87 * @param indev Input character device. 88 * 89 * @return Character read. 90 * 91 */ 92 wchar_t indev_pop_character(indev_t *indev) 93 { 94 if (atomic_get(&haltstate)) { 95 /* If we are here, we are hopefully on the processor that 96 * issued the 'halt' command, so proceed to read the character 97 * directly from input 98 */ 99 if (check_poll(indev)) 100 return indev->op->poll(indev); 101 102 /* No other way of interacting with user */ 103 interrupts_disable(); 104 105 if (CPU) 106 printf("cpu%u: ", CPU->id); 107 else 108 printf("cpu: "); 109 110 printf("halted (no polling input)\n"); 111 cpu_halt(); 112 } 113 114 waitq_sleep(&indev->wq); 115 ipl_t ipl = interrupts_disable(); 116 spinlock_lock(&indev->lock); 117 wchar_t ch = indev->buffer[(indev->index - indev->counter) % INDEV_BUFLEN]; 118 indev->counter--; 119 spinlock_unlock(&indev->lock); 120 interrupts_restore(ipl); 121 122 return ch; 123 } 124 82 125 /** Initialize output character device. 83 126 * … … 94 137 } 95 138 139 bool check_poll(indev_t *indev) 140 { 141 if (indev == NULL) 142 return false; 143 144 if (indev->op == NULL) 145 return false; 146 147 return (indev->op->poll != NULL); 148 } 149 96 150 /** @} 97 151 */ -
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; -
kernel/generic/src/console/kconsole.c
rd6d04e7 r44b7783 246 246 247 247 while (true) { 248 wchar_t ch = _getc(indev);248 wchar_t ch = indev_pop_character(indev); 249 249 250 250 if (ch == '\n') { … … 654 654 655 655 if (kcon) 656 _getc(stdin);656 indev_pop_character(stdin); 657 657 else 658 658 printf("Type \"exit\" to leave the console.\n"); -
kernel/generic/src/interrupt/interrupt.c
rd6d04e7 r44b7783 146 146 printf(" -- Press any key to continue -- "); 147 147 spinlock_unlock(&exctbl_lock); 148 _getc(stdin);148 indev_pop_character(stdin); 149 149 spinlock_lock(&exctbl_lock); 150 150 printf("\n");
Note:
See TracChangeset
for help on using the changeset viewer.