Changeset ac8e7a9 in mainline


Ignore:
Timestamp:
2009-03-12T17:46:26Z (16 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
67a88c3
Parents:
8030f49
Message:

use indev_t
remove console IRQ notification (will be replaced by a proper solution)
remove null_stdout (just initialize stdout to NULL)
remove console_init()
add check_poll()
more understandable message on halt with no polled input device
cleanup

Location:
kernel/generic
Files:
2 edited

Legend:

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

    r8030f49 rac8e7a9  
    3939#include <console/chardev.h>
    4040
    41 extern chardev_t *stdin;
    42 extern chardev_t *stdout;
     41extern indev_t *stdin;
     42extern outdev_t *stdout;
    4343
    4444extern bool silent;
     
    4949extern void klog_update(void);
    5050
    51 extern uint8_t getc(chardev_t *chardev);
    52 extern uint8_t _getc(chardev_t *chardev);
    53 extern count_t gets(chardev_t *chardev, char *buf, size_t buflen);
     51extern bool check_poll(indev_t *indev);
     52extern uint8_t getc(indev_t *indev);
     53extern uint8_t _getc(indev_t *indev);
     54extern count_t gets(indev_t *indev, char *buf, size_t buflen);
    5455extern void putchar(char c);
    5556
  • kernel/generic/src/console/console.c

    r8030f49 rac8e7a9  
    7575static parea_t klog_parea;
    7676
    77 /*
    78  * For now, we use 0 as INR.
    79  * However, it is therefore desirable to have architecture specific
    80  * definition of KLOG_VIRT_INR in the future.
    81  */
    82 #define KLOG_VIRT_INR   0
    83 
    84 static irq_t klog_irq;
    85 
    86 static chardev_operations_t null_stdout_ops = {
    87         .suspend = NULL,
    88         .resume = NULL,
    89         .write = NULL,
    90         .read = NULL
    91 };
    92 
    93 chardev_t null_stdout = {
    94         .name = "null",
    95         .op = &null_stdout_ops
    96 };
    97 
    98 /** Allways refuse IRQ ownership.
    99  *
    100  * This is not a real IRQ, so we always decline.
    101  *
    102  * @return Always returns IRQ_DECLINE.
    103  */
    104 static irq_ownership_t klog_claim(irq_t *irq)
    105 {
    106         return IRQ_DECLINE;
    107 }
    108 
    109 static void stdin_suspend(chardev_t *d)
    110 {
    111 }
    112 
    113 static void stdin_resume(chardev_t *d)
    114 {
    115 }
    116 
    117 static chardev_operations_t stdin_ops = {
    118         .suspend = stdin_suspend,
    119         .resume = stdin_resume,
    120 };
    121 
    122 /** Standard input character device */
    123 static chardev_t _stdin;
    124 chardev_t *stdin = NULL;
    125 chardev_t *stdout = &null_stdout;
    126 
    127 void console_init(void)
    128 {
    129         chardev_initialize("stdin", &_stdin, &stdin_ops);
    130         stdin = &_stdin;
    131 }
     77/** Standard input and output character devices */
     78indev_t *stdin = NULL;
     79outdev_t *stdout = NULL;
    13280
    13381/** Initialize kernel logging facility
     
    13684 * be notified on new data with indication of position and size
    13785 * of the data within the circular buffer.
     86 *
    13887 */
    13988void klog_init(void)
     
    14392        ASSERT((uintptr_t) faddr % FRAME_SIZE == 0);
    14493        ASSERT(KLOG_SIZE % FRAME_SIZE == 0);
    145 
    146         devno_t devno = device_assign_devno();
    14794       
    14895        klog_parea.pbase = (uintptr_t) faddr;
    14996        klog_parea.frames = SIZE2FRAMES(KLOG_SIZE);
    15097        ddi_parea_register(&klog_parea);
    151 
     98       
    15299        sysinfo_set_item_val("klog.faddr", NULL, (unative_t) faddr);
    153100        sysinfo_set_item_val("klog.pages", NULL, SIZE2FRAMES(KLOG_SIZE));
    154         sysinfo_set_item_val("klog.devno", NULL, devno);
    155         sysinfo_set_item_val("klog.inr", NULL, KLOG_VIRT_INR);
    156 
    157         irq_initialize(&klog_irq);
    158         klog_irq.devno = devno;
    159         klog_irq.inr = KLOG_VIRT_INR;
    160         klog_irq.claim = klog_claim;
    161         irq_register(&klog_irq);
     101       
     102        //irq_initialize(&klog_irq);
     103        //klog_irq.devno = devno;
     104        //klog_irq.inr = KLOG_VIRT_INR;
     105        //klog_irq.claim = klog_claim;
     106        //irq_register(&klog_irq);
    162107       
    163108        spinlock_lock(&klog_lock);
     
    178123}
    179124
    180 /** Get character from character device. Do not echo character.
    181  *
    182  * @param chardev Character device.
    183  *
     125bool check_poll(indev_t *indev)
     126{
     127        if (indev == NULL)
     128                return false;
     129       
     130        if (indev->op == NULL)
     131                return false;
     132       
     133        return (indev->op->poll != NULL);
     134}
     135
     136/** Get character from input character device. Do not echo character.
     137 *
     138 * @param indev Input character device.
    184139 * @return Character read.
    185  */
    186 uint8_t _getc(chardev_t *chardev)
    187 {
    188         uint8_t ch;
    189         ipl_t ipl;
    190 
     140 *
     141 */
     142uint8_t _getc(indev_t *indev)
     143{
    191144        if (atomic_get(&haltstate)) {
    192                 /* If we are here, we are hopefully on the processor, that
     145                /* If we are here, we are hopefully on the processor that
    193146                 * issued the 'halt' command, so proceed to read the character
    194147                 * directly from input
    195148                 */
    196                 if (chardev->op->read)
    197                         return chardev->op->read(chardev);
    198                 /* no other way of interacting with user, halt */
     149                if (check_poll(indev))
     150                        return indev->op->poll(indev);
     151               
     152                /* No other way of interacting with user */
     153                interrupts_disable();
     154               
    199155                if (CPU)
    200156                        printf("cpu%u: ", CPU->id);
    201157                else
    202158                        printf("cpu: ");
    203                 printf("halted (no kconsole)\n");
     159                printf("halted (no polling input)\n");
    204160                cpu_halt();
    205161        }
    206 
    207         waitq_sleep(&chardev->wq);
    208         ipl = interrupts_disable();
    209         spinlock_lock(&chardev->lock);
    210         ch = chardev->buffer[(chardev->index - chardev->counter) % CHARDEV_BUFLEN];
    211         chardev->counter--;
    212         spinlock_unlock(&chardev->lock);
     162       
     163        waitq_sleep(&indev->wq);
     164        ipl_t ipl = interrupts_disable();
     165        spinlock_lock(&indev->lock);
     166        uint8_t ch = indev->buffer[(indev->index - indev->counter) % INDEV_BUFLEN];
     167        indev->counter--;
     168        spinlock_unlock(&indev->lock);
    213169        interrupts_restore(ipl);
    214 
    215         chardev->op->resume(chardev);
    216 
     170       
    217171        return ch;
    218172}
    219173
    220 /** Get string from character device.
    221  *
    222  * Read characters from character device until first occurrence
     174/** Get string from input character device.
     175 *
     176 * Read characters from input character device until first occurrence
    223177 * of newline character.
    224178 *
    225  * @param chardev Character device.
    226  * @param buf Buffer where to store string terminated by '\0'.
     179 * @param indev  Input character device.
     180 * @param buf    Buffer where to store string terminated by '\0'.
    227181 * @param buflen Size of the buffer.
    228182 *
    229183 * @return Number of characters read.
    230  */
    231 count_t gets(chardev_t *chardev, char *buf, size_t buflen)
     184 *
     185 */
     186count_t gets(indev_t *indev, char *buf, size_t buflen)
    232187{
    233188        index_t index = 0;
    234         char ch;
    235189       
    236190        while (index < buflen) {
    237                 ch = _getc(chardev);
     191                char ch = _getc(indev);
    238192                if (ch == '\b') {
    239193                        if (index > 0) {
     
    254208                buf[index++] = ch;
    255209        }
     210       
    256211        return (count_t) index;
    257212}
    258213
    259 /** Get character from device & echo it to screen */
    260 uint8_t getc(chardev_t *chardev)
    261 {
    262         uint8_t ch;
    263 
    264         ch = _getc(chardev);
     214/** Get character from input device & echo it to screen */
     215uint8_t getc(indev_t *indev)
     216{
     217        uint8_t ch = _getc(indev);
    265218        putchar(ch);
    266219        return ch;
     
    271224        spinlock_lock(&klog_lock);
    272225       
    273         if ((klog_inited) && (klog_irq.notif_cfg.notify) && (klog_uspace > 0)) {
    274                 ipc_irq_send_msg_3(&klog_irq, klog_start, klog_len, klog_uspace);
    275                 klog_uspace = 0;
    276         }
     226//      if ((klog_inited) && (klog_irq.notif_cfg.notify) && (klog_uspace > 0)) {
     227//              ipc_irq_send_msg_3(&klog_irq, klog_start, klog_len, klog_uspace);
     228//              klog_uspace = 0;
     229//      }
    277230       
    278231        spinlock_unlock(&klog_lock);
     
    283236        spinlock_lock(&klog_lock);
    284237       
    285         if ((klog_stored > 0) && (stdout->op->write)) {
     238        if ((klog_stored > 0) && (stdout) && (stdout->op->write)) {
    286239                /* Print charaters stored in kernel log */
    287240                index_t i;
     
    298251                klog_start = (klog_start + 1) % KLOG_SIZE;
    299252       
    300         if (stdout->op->write)
     253        if ((stdout) && (stdout->op->write))
    301254                stdout->op->write(stdout, c, silent);
    302255        else {
Note: See TracChangeset for help on using the changeset viewer.