Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/util/logger.c need to be fixed.

0001 /*                    The Quest Operating System
0002  *  Copyright (C) 2005-2010  Richard West, Boston University
0003  *
0004  *  This program is free software: you can redistribute it and/or modify
0005  *  it under the terms of the GNU General Public License as published by
0006  *  the Free Software Foundation, either version 3 of the License, or
0007  *  (at your option) any later version.
0008  *
0009  *  This program is distributed in the hope that it will be useful,
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *  GNU General Public License for more details.
0013  *
0014  *  You should have received a copy of the GNU General Public License
0015  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0016  */
0017 
0018 #include "kernel.h"
0019 #include "util/printf.h"
0020 #include "util/debug.h"
0021 #include "sched/sched.h"
0022 
0023 #ifndef NO_LOGGER
0024 static u32 logger_stack[1024] ALIGNED(0x1000);
0025 
0026 #define LOGGER_BUF_SIZE 65536   /* power of 2 please */
0027 #define LOGGER_BUF_MOD_MASK (LOGGER_BUF_SIZE - 1)
0028 
0029 static volatile bool logger_running = FALSE, dropped = FALSE;
0030 static char logger_buf[LOGGER_BUF_SIZE] ALIGNED(0x1000);
0031 static volatile u32 head = 0, tail = LOGGER_BUF_SIZE - 1;
0032 
0033 static char
0034 logger_getc (void)
0035 {
0036   u32 newtail = (tail + 1) & LOGGER_BUF_MOD_MASK;
0037   if (newtail == head) {
0038     /* nothing to get */
0039     return 0;
0040   } else {
0041     char c = logger_buf[newtail];
0042     tail = newtail;
0043     return c;
0044   }
0045 }
0046 
0047 static void
0048 logger_thread (void)
0049 {
0050   logger_running = TRUE;
0051 
0052   /* main point of logger thread is that it runs in kernel space but
0053    * with interrupts enabled */
0054   unlock_kernel ();
0055   sti ();
0056 
0057   com1_printf ("logger: hello from 0x%x\n", str ());
0058   for (;;) {
0059     char c = logger_getc ();
0060     if (c == 0)
0061       asm volatile ("pause");
0062     else
0063       com1_putc (c);
0064     if (dropped) {
0065       printf ("***logger dropped char (h=%d,t=%d)***\n", head, tail);
0066       dropped = FALSE;
0067     }
0068   }
0069 }
0070 #endif
0071 
0072 extern bool
0073 logger_init (void)
0074 {
0075 #ifndef NO_LOGGER
0076   task_id id =
0077     start_kernel_thread ((u32) logger_thread, (u32) &logger_stack[1023]);
0078 
0079   uint lowest_priority_vcpu (void);
0080   lookup_TSS (id)->cpu = lowest_priority_vcpu ();
0081 
0082 #endif
0083   return TRUE;
0084 }
0085 
0086 extern void
0087 logger_putc (char c)
0088 {
0089 #ifdef NO_LOGGER
0090   com1_putc (c);
0091 #else
0092   if (logger_running) {
0093     u32 newhead = (head + 1) & LOGGER_BUF_MOD_MASK;
0094     if (newhead == tail) {
0095       /* drop char */
0096       dropped = TRUE;
0097     } else {
0098       logger_buf[head] = c;
0099       head = newhead;
0100     }
0101   } else
0102     com1_putc (c);
0103 #endif
0104 }
0105 
0106 #include "module/header.h"
0107 
0108 static const struct module_ops mod_ops = {
0109   .init = logger_init
0110 };
0111 
0112 DEF_MODULE (logger, "Log manager", &mod_ops, {});
0113 
0114 /*
0115  * Local Variables:
0116  * indent-tabs-mode: nil
0117  * mode: C
0118  * c-file-style: "gnu"
0119  * c-basic-offset: 2
0120  * End:
0121  */
0122 
0123 /* vi: set et sw=2 sts=2: */