Changeset 82b71ef1 in mainline


Ignore:
Timestamp:
2008-06-04T19:17:36Z (17 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
32443b0
Parents:
7ba289a
Message:

resurrect klog

Location:
kernel
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/ia32/src/smp/ap.S

    r7ba289a r82b71ef1  
    4646KDATA=16
    4747
    48 # This piece of code is real-mode and is meant to be alligned at 4K boundary.
     48# This piece of code is real-mode and is meant to be aligned at 4K boundary.
    4949# The requirement for such an alignment comes from MP Specification's STARTUP IPI
    5050# requirements.
  • kernel/generic/include/console/console.h

    r7ba289a r82b71ef1  
    4242extern chardev_t *stdout;
    4343
     44extern void klog_init(void);
     45extern void klog_update(void);
     46
    4447extern uint8_t getc(chardev_t *chardev);
    4548uint8_t _getc(chardev_t *chardev);
  • kernel/generic/src/console/console.c

    r7ba289a r82b71ef1  
    3636#include <console/console.h>
    3737#include <console/chardev.h>
     38#include <sysinfo/sysinfo.h>
    3839#include <synch/waitq.h>
    3940#include <synch/spinlock.h>
    4041#include <arch/types.h>
     42#include <ddi/device.h>
     43#include <ddi/irq.h>
     44#include <ddi/ddi.h>
     45#include <ipc/irq.h>
    4146#include <arch.h>
    4247#include <func.h>
     
    4449#include <atomic.h>
    4550
    46 #define KLOG_SIZE 4096
     51#define KLOG_SIZE PAGE_SIZE
    4752
    4853/**< Kernel log cyclic buffer */
    49 static char klog[KLOG_SIZE];
    50 
     54static char klog[KLOG_SIZE] __attribute__ ((aligned (PAGE_SIZE)));
     55
     56/**< Kernel log initialized */
     57static bool klog_inited = false;
    5158/**< First kernel log characters */
    5259static index_t klog_start = 0;
     
    5562/**< Number of stored (not printed) kernel log characters */
    5663static size_t klog_stored = 0;
     64/**< Number of stored kernel log characters for uspace */
     65static size_t klog_uspace = 0;
     66
     67/**< Kernel log spinlock */
     68SPINLOCK_INITIALIZE(klog_lock);
     69
     70/** Physical memory area used for klog buffer */
     71static parea_t klog_parea;
     72       
     73/*
     74 * For now, we use 0 as INR.
     75 * However, it is therefore desirable to have architecture specific
     76 * definition of KLOG_VIRT_INR in the future.
     77 */
     78#define KLOG_VIRT_INR   0
     79
     80static irq_t klog_irq;
    5781
    5882static chardev_operations_t null_stdout_ops = {
     
    6892};
    6993
    70 /** Standard input character device. */
     94/** Allways refuse IRQ ownership.
     95 *
     96 * This is not a real IRQ, so we always decline.
     97 *
     98 * @return Always returns IRQ_DECLINE.
     99 */
     100static irq_ownership_t klog_claim(void)
     101{
     102        return IRQ_DECLINE;
     103}
     104
     105/** Standard input character device */
    71106chardev_t *stdin = NULL;
    72107chardev_t *stdout = &null_stdout;
     108
     109/** Initialize kernel logging facility
     110 *
     111 * The shared area contains kernel cyclic buffer. Userspace application may
     112 * be notified on new data with indication of position and size
     113 * of the data within the circular buffer.
     114 */
     115void klog_init(void)
     116{
     117        void *faddr = (void *) KA2PA(klog);
     118       
     119        ASSERT((uintptr_t) faddr % FRAME_SIZE == 0);
     120        ASSERT(KLOG_SIZE % FRAME_SIZE == 0);
     121
     122        devno_t devno = device_assign_devno();
     123       
     124        klog_parea.pbase = (uintptr_t) faddr;
     125        klog_parea.vbase = (uintptr_t) klog;
     126        klog_parea.frames = SIZE2FRAMES(KLOG_SIZE);
     127        klog_parea.cacheable = true;
     128        ddi_parea_register(&klog_parea);
     129
     130        sysinfo_set_item_val("klog.faddr", NULL, (unative_t) faddr);
     131        sysinfo_set_item_val("klog.pages", NULL, SIZE2FRAMES(KLOG_SIZE));
     132        sysinfo_set_item_val("klog.devno", NULL, devno);
     133        sysinfo_set_item_val("klog.inr", NULL, KLOG_VIRT_INR);
     134
     135        irq_initialize(&klog_irq);
     136        klog_irq.devno = devno;
     137        klog_irq.inr = KLOG_VIRT_INR;
     138        klog_irq.claim = klog_claim;
     139        irq_register(&klog_irq);
     140       
     141        spinlock_lock(&klog_lock);
     142        klog_inited = true;
     143        spinlock_unlock(&klog_lock);
     144}
    73145
    74146/** Get character from character device. Do not echo character.
     
    161233}
    162234
     235void klog_update(void)
     236{
     237        spinlock_lock(&klog_lock);
     238       
     239        if ((klog_inited) && (klog_irq.notif_cfg.notify) && (klog_uspace > 0)) {
     240                ipc_irq_send_msg_3(&klog_irq, klog_start, klog_len, klog_uspace);
     241                klog_uspace = 0;
     242        }
     243       
     244        spinlock_unlock(&klog_lock);
     245}
     246
    163247void putchar(char c)
    164248{
     249        spinlock_lock(&klog_lock);
     250       
    165251        if ((klog_stored > 0) && (stdout->op->write)) {
    166252                /* Print charaters stored in kernel log */
     
    185271                        klog_stored++;
    186272        }
     273       
     274        /* The character is stored for uspace */
     275        if (klog_uspace < klog_len)
     276                klog_uspace++;
     277       
     278        spinlock_unlock(&klog_lock);
     279       
     280        klog_update();
    187281}
    188282
  • kernel/generic/src/main/main.c

    r7ba289a r82b71ef1  
    8181#include <smp/smp.h>
    8282#include <ddi/ddi.h>
     83#include <console/console.h>
    8384
    8485/** Global configuration structure. */
     
    257258       
    258259        LOG_EXEC(ipc_init());
     260        LOG_EXEC(klog_init());
    259261
    260262        /*
  • kernel/generic/src/syscall/syscall.c

    r7ba289a r82b71ef1  
    6464        int rc;
    6565
    66         if (count == 0)
    67                 return 0;
    68 
    6966        if (count > PAGE_SIZE)
    7067                return ELIMIT;
    71 
    72         data = (char *) malloc(count, 0);
    73         if (!data)
    74                 return ENOMEM;
    7568       
    76         rc = copy_from_uspace(data, buf, count);
    77         if (rc) {
     69        if (count > 0) {
     70                data = (char *) malloc(count, 0);
     71                if (!data)
     72                        return ENOMEM;
     73               
     74                rc = copy_from_uspace(data, buf, count);
     75                if (rc) {
     76                        free(data);
     77                        return rc;
     78                }
     79       
     80                for (i = 0; i < count; i++)
     81                        putchar(data[i]);
    7882                free(data);
    79                 return rc;
    80         }
    81 
    82         for (i = 0; i < count; i++)
    83                 putchar(data[i]);
    84         free(data);
     83        } else
     84                klog_update();
    8585       
    8686        return count;
Note: See TracChangeset for help on using the changeset viewer.