Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/console/console.c

    r0fe52ef rd7533c7  
    5353#include <str.h>
    5454
    55 #define KLOG_PAGES    8
     55#define KLOG_PAGES    4
    5656#define KLOG_LENGTH   (KLOG_PAGES * PAGE_SIZE / sizeof(wchar_t))
     57#define KLOG_LATENCY  8
    5758
    5859/** Kernel log cyclic buffer */
     
    6061
    6162/** Kernel log initialized */
    62 static atomic_t klog_inited = {false};
     63static bool klog_inited = false;
    6364
    6465/** First kernel log characters */
     
    7576
    7677/** Kernel log spinlock */
    77 SPINLOCK_STATIC_INITIALIZE_NAME(klog_lock, "klog_lock");
     78SPINLOCK_STATIC_INITIALIZE_NAME(klog_lock, "*klog_lock");
    7879
    7980/** Physical memory area used for klog buffer */
     
    8788};
    8889
    89 static void stdout_write(outdev_t *, wchar_t);
     90static void stdout_write(outdev_t *, wchar_t, bool);
    9091static void stdout_redraw(outdev_t *);
    9192
     
    9596};
    9697
    97 /** Override kernel console lockout */
    98 bool console_override = false;
     98/** Silence output */
     99bool silent = false;
    99100
    100101/** Standard input and output character devices */
     
    122123}
    123124
    124 static void stdout_write(outdev_t *dev, wchar_t ch)
    125 {
    126         list_foreach(dev->list, cur) {
     125static void stdout_write(outdev_t *dev, wchar_t ch, bool silent)
     126{
     127        link_t *cur;
     128       
     129        for (cur = dev->list.next; cur != &dev->list; cur = cur->next) {
    127130                outdev_t *sink = list_get_instance(cur, outdev_t, link);
    128131                if ((sink) && (sink->op->write))
    129                         sink->op->write(sink, ch);
     132                        sink->op->write(sink, ch, silent);
    130133        }
    131134}
     
    133136static void stdout_redraw(outdev_t *dev)
    134137{
    135         list_foreach(dev->list, cur) {
     138        link_t *cur;
     139       
     140        for (cur = dev->list.next; cur != &dev->list; cur = cur->next) {
    136141                outdev_t *sink = list_get_instance(cur, outdev_t, link);
    137142                if ((sink) && (sink->op->redraw))
     
    156161        klog_parea.frames = SIZE2FRAMES(sizeof(klog));
    157162        klog_parea.unpriv = false;
    158         klog_parea.mapped = false;
    159163        ddi_parea_register(&klog_parea);
    160164       
     
    162166        sysinfo_set_item_val("klog.pages", NULL, KLOG_PAGES);
    163167       
    164         event_set_unmask_callback(EVENT_KLOG, klog_update);
    165         atomic_set(&klog_inited, true);
     168        spinlock_lock(&klog_lock);
     169        klog_inited = true;
     170        spinlock_unlock(&klog_lock);
    166171}
    167172
    168173void grab_console(void)
    169174{
    170         bool prev = console_override;
    171        
    172         console_override = true;
     175        bool prev = silent;
     176       
     177        silent = false;
    173178        if ((stdout) && (stdout->op->redraw))
    174179                stdout->op->redraw(stdout);
    175180       
    176         if ((stdin) && (!prev)) {
     181        if ((stdin) && (prev)) {
    177182                /*
    178183                 * Force the console to print the prompt.
     
    184189void release_console(void)
    185190{
    186         console_override = false;
    187 }
    188 
    189 /** Activate kernel console override */
    190 sysarg_t sys_debug_activate_console(void)
     191        // FIXME arch_release_console
     192        silent = true;
     193}
     194
     195/** Tell kernel to get keyboard/console access again */
     196sysarg_t sys_debug_enable_console(void)
    191197{
    192198#ifdef CONFIG_KCONSOLE
     
    196202        return false;
    197203#endif
     204}
     205
     206/** Tell kernel to relinquish keyboard/console access */
     207sysarg_t sys_debug_disable_console(void)
     208{
     209        release_console();
     210        return true;
    198211}
    199212
     
    248261}
    249262
    250 void klog_update(void *event)
    251 {
    252         if (!atomic_get(&klog_inited))
    253                 return;
    254        
     263void klog_update(void)
     264{
    255265        spinlock_lock(&klog_lock);
    256266       
    257         if (klog_uspace > 0) {
    258                 if (event_notify_3(EVENT_KLOG, true, klog_start, klog_len,
    259                     klog_uspace) == EOK)
    260                         klog_uspace = 0;
     267        if ((klog_inited) && (event_is_subscribed(EVENT_KLOG)) && (klog_uspace > 0)) {
     268                event_notify_3(EVENT_KLOG, klog_start, klog_len, klog_uspace);
     269                klog_uspace = 0;
    261270        }
    262271       
     
    266275void putchar(const wchar_t ch)
    267276{
    268         bool ordy = ((stdout) && (stdout->op->write));
    269        
    270277        spinlock_lock(&klog_lock);
    271278       
    272         /* Print charaters stored in kernel log */
    273         if (ordy) {
    274                 while (klog_stored > 0) {
    275                         wchar_t tmp = klog[(klog_start + klog_len - klog_stored) % KLOG_LENGTH];
    276                         klog_stored--;
    277                        
    278                         /*
    279                          * We need to give up the spinlock for
    280                          * the physical operation of writting out
    281                          * the character.
    282                          */
    283                         spinlock_unlock(&klog_lock);
    284                         stdout->op->write(stdout, tmp);
    285                         spinlock_lock(&klog_lock);
    286                 }
     279        if ((klog_stored > 0) && (stdout) && (stdout->op->write)) {
     280                /* Print charaters stored in kernel log */
     281                size_t i;
     282                for (i = klog_len - klog_stored; i < klog_len; i++)
     283                        stdout->op->write(stdout, klog[(klog_start + i) % KLOG_LENGTH], silent);
     284                klog_stored = 0;
    287285        }
    288286       
     
    294292                klog_start = (klog_start + 1) % KLOG_LENGTH;
    295293       
    296         if (!ordy) {
    297                 if (klog_stored < klog_len)
    298                         klog_stored++;
    299         }
    300        
    301         /* The character is stored for uspace */
    302         if (klog_uspace < klog_len)
    303                 klog_uspace++;
    304        
    305         spinlock_unlock(&klog_lock);
    306        
    307         if (ordy) {
    308                 /*
    309                  * Output the character. In this case
    310                  * it should be no longer buffered.
    311                  */
    312                 stdout->op->write(stdout, ch);
    313         } else {
     294        if ((stdout) && (stdout->op->write))
     295                stdout->op->write(stdout, ch, silent);
     296        else {
    314297                /*
    315298                 * No standard output routine defined yet.
     
    321304                 * Note that the early_putc() function might be
    322305                 * a no-op on certain hardware configurations.
     306                 *
    323307                 */
    324308                early_putchar(ch);
    325         }
    326        
    327         /* Force notification on newline */
    328         if (ch == '\n')
    329                 klog_update(NULL);
     309               
     310                if (klog_stored < klog_len)
     311                        klog_stored++;
     312        }
     313       
     314        /* The character is stored for uspace */
     315        if (klog_uspace < klog_len)
     316                klog_uspace++;
     317       
     318        /* Check notify uspace to update */
     319        bool update;
     320        if ((klog_uspace > KLOG_LATENCY) || (ch == '\n'))
     321                update = true;
     322        else
     323                update = false;
     324       
     325        spinlock_unlock(&klog_lock);
     326       
     327        if (update)
     328                klog_update();
    330329}
    331330
     
    358357                free(data);
    359358        } else
    360                 klog_update(NULL);
     359                klog_update();
    361360       
    362361        return size;
Note: See TracChangeset for help on using the changeset viewer.