Changeset 44b7783 in mainline


Ignore:
Timestamp:
2009-04-21T12:43:14Z (16 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c2417bc
Parents:
d6d04e7
Message:

rename _getc() to indev_pop_character()
implicit creation of stdin via stdin_wire()

Location:
kernel/generic
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/console/chardev.h

    rd6d04e7 r44b7783  
    9090    indev_operations_t *op);
    9191extern void indev_push_character(indev_t *indev, wchar_t ch);
     92extern wchar_t indev_pop_character(indev_t *indev);
    9293
    9394extern void outdev_initialize(char *name, outdev_t *outdev,
    9495    outdev_operations_t *op);
     96
     97extern bool check_poll(indev_t *indev);
    9598
    9699#endif /* KERN_CHARDEV_H_ */
  • kernel/generic/include/console/console.h

    rd6d04e7 r44b7783  
    4141extern indev_t *stdin;
    4242extern outdev_t *stdout;
    43 
    4443extern bool silent;
    4544
     45extern indev_t *stdin_wire(void);
    4646extern void console_init(void);
    4747
     
    4949extern void klog_update(void);
    5050
    51 extern bool check_poll(indev_t *indev);
    5251extern wchar_t getc(indev_t *indev);
    53 extern wchar_t _getc(indev_t *indev);
    5452extern count_t gets(indev_t *indev, char *buf, size_t buflen);
    5553extern unative_t sys_klog(int fd, const void *buf, size_t size);
  • kernel/generic/src/console/chardev.c

    rd6d04e7 r44b7783  
    3636#include <synch/waitq.h>
    3737#include <synch/spinlock.h>
     38#include <print.h>
     39#include <func.h>
     40#include <arch.h>
    3841
    3942/** Initialize input character device.
     
    8083}
    8184
     85/** Pop character from input character device.
     86 *
     87 * @param indev Input character device.
     88 *
     89 * @return Character read.
     90 *
     91 */
     92wchar_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
    82125/** Initialize output character device.
    83126 *
     
    94137}
    95138
     139bool 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
    96150/** @}
    97151 */
  • kernel/generic/src/console/console.c

    rd6d04e7 r44b7783  
    4545#include <ipc/irq.h>
    4646#include <arch.h>
    47 #include <func.h>
    4847#include <print.h>
    4948#include <putchar.h>
     
    7170static size_t klog_uspace = 0;
    7271
     72/** Kernel log spinlock */
     73SPINLOCK_INITIALIZE(klog_lock);
     74
     75/** Physical memory area used for klog buffer */
     76static parea_t klog_parea;
     77
     78static indev_operations_t stdin_ops = {
     79        .poll = NULL
     80};
     81
    7382/** Silence output */
    7483bool 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;
    8184
    8285/** Standard input and output character devices */
    8386indev_t *stdin = NULL;
    8487outdev_t *stdout = NULL;
     88
     89indev_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}
    8599
    86100/** Initialize kernel logging facility
     
    139153}
    140154
    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 
    190155/** Get string from input character device.
    191156 *
     
    207172       
    208173        wchar_t ch;
    209         while ((ch = _getc(indev)) != '\n') {
     174        while ((ch = indev_pop_character(indev)) != '\n') {
    210175                if (ch == '\b') {
    211176                        if (count > 0) {
     
    233198wchar_t getc(indev_t *indev)
    234199{
    235         wchar_t ch = _getc(indev);
     200        wchar_t ch = indev_pop_character(indev);
    236201        putchar(ch);
    237202        return ch;
  • kernel/generic/src/console/kconsole.c

    rd6d04e7 r44b7783  
    246246       
    247247        while (true) {
    248                 wchar_t ch = _getc(indev);
     248                wchar_t ch = indev_pop_character(indev);
    249249               
    250250                if (ch == '\n') {
     
    654654       
    655655        if (kcon)
    656                 _getc(stdin);
     656                indev_pop_character(stdin);
    657657        else
    658658                printf("Type \"exit\" to leave the console.\n");
  • kernel/generic/src/interrupt/interrupt.c

    rd6d04e7 r44b7783  
    146146                        printf(" -- Press any key to continue -- ");
    147147                        spinlock_unlock(&exctbl_lock);
    148                         _getc(stdin);
     148                        indev_pop_character(stdin);
    149149                        spinlock_lock(&exctbl_lock);
    150150                        printf("\n");
Note: See TracChangeset for help on using the changeset viewer.