| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- /* Copyright (C) 2021 Rain */
- /* This file is part of XNIX. */
- /*
- XNIX is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) and later version.
- */
- /*
- XNIX is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- */
- /*
- You should have received a copy of the GNU General Public License
- along with XNIX. If not, see <https://www.gnu.org/licenses/>.
- */
- #include <kernel/init.h>
- #include <kernel/errno.h>
- #include <kernel/types.h>
- #include <kernel/console.h>
- #include <kernel/panic.h>
- #include <arch/x86/int.h>
- #include <arch/io.h>
- #include <arch/sys.h>
- static int syslog_index = 0;
- void panic(const char *s) {
- printk(red, "kernel panic: %s\n", s);
- trace_syslog();
- for (;;) hlt();
- }
- void syslog(const char *s) {
- /* we can't use schk in this function, */
- /* because this will make a die-loop (schk_init calls this function) */
- int i;
- for (i = 0; s[i]; i++) {
- if (syslog_index == 32768)
- syslog_index = 0;
-
- *(syslog_index + SYSLOG_BUFFER) = s[i];
- syslog_index++;
- }
- return;
- }
- void trace_syslog(void) {
- printk(yellow, "tracing system log: \n");
- #if DEBUG_LEVEL != TEST_DEBUG_LEVEL
- printk(yellow, "system log disabled. \n");
- return;
- #else
- /* put last 8 calls to the screen */
- int i;
- char *fname = SYSLOG_BUFFER + syslog_index - 1;
- for (i = 0; i < TRACE_SYSLOG_NR; i++) {
- while (*--fname != '\t');
- char *fn = fname + 1;
- if (!(i % 3))
- putc('\n', yellow);
- print(yellow, "+ ");
- while (*fn != '\t')
- putc(*fn++, yellow);
- putc('\t', white);
- }
- putc('\n', yellow);
- return;
- #endif
- }
|