Warning, cross-references for /kernel/util/logger.c need to be fixed.
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
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
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
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
0053
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
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
0116
0117
0118
0119
0120
0121
0122
0123