|
|
1.1 root 1: /*
2: * Linux kernel print routine.
3: * Copyright (C) 1995 Shantanu Goel.
4: *
5: * This program is free software; you can redistribute it and/or modify
6: * it under the terms of the GNU General Public License as published by
7: * the Free Software Foundation; either version 2, or (at your option)
8: * any later version.
9: *
10: * This program is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: * GNU General Public License for more details.
14: *
15: * You should have received a copy of the GNU General Public License
16: * along with this program; if not, write to the Free Software
17: * Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18: */
19:
20: /*
21: * linux/kernel/printk.c
22: *
23: * Copyright (C) 1991, 1992 Linus Torvalds
24: */
25:
26: #define MACH_INCLUDE
27: #include <stdarg.h>
28: #include <asm/system.h>
1.1.1.2 ! root 29: #include <kern/assert.h>
! 30: #include <kern/printf.h>
! 31: #include <device/cons.h>
1.1 root 32:
33: static char buf[2048];
34:
35: #define DEFAULT_MESSAGE_LOGLEVEL 4
36: #define DEFAULT_CONSOLE_LOGLEVEL 7
37:
38: int console_loglevel = DEFAULT_CONSOLE_LOGLEVEL;
39:
40: int
41: printk (char *fmt, ...)
42: {
43: va_list args;
1.1.1.2 ! root 44: int n;
! 45: unsigned long flags;
1.1 root 46: char *p, *msg, *buf_end;
47: static int msg_level = -1;
48:
49: save_flags (flags);
50: cli ();
51: va_start (args, fmt);
1.1.1.2 ! root 52: n = vsnprintf (buf + 3, sizeof (buf) - 3, fmt, args);
! 53: assert (n <= sizeof (buf) - 3);
1.1 root 54: buf_end = buf + 3 + n;
55: va_end (args);
56: for (p = buf + 3; p < buf_end; p++)
57: {
58: msg = p;
59: if (msg_level < 0)
60: {
61: if (p[0] != '<' || p[1] < '0' || p[1] > '7' || p[2] != '>')
62: {
63: p -= 3;
64: p[0] = '<';
65: p[1] = DEFAULT_MESSAGE_LOGLEVEL + '0';
66: p[2] = '>';
67: }
68: else
69: msg += 3;
70: msg_level = p[1] - '0';
71: }
72: for (; p < buf_end; p++)
73: if (*p == '\n')
74: break;
75: if (msg_level < console_loglevel)
76: while (msg <= p)
77: cnputc (*msg++);
78: if (*p == '\n')
79: msg_level = -1;
80: }
81: restore_flags (flags);
82: return n;
83: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.