panic.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Copyright (C) 2021 Rain */
  2. /* This file is part of XNIX. */
  3. /*
  4. XNIX is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) and later version.
  8. */
  9. /*
  10. XNIX 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. /*
  16. You should have received a copy of the GNU General Public License
  17. along with XNIX. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. #include <kernel/init.h>
  20. #include <kernel/errno.h>
  21. #include <kernel/types.h>
  22. #include <kernel/console.h>
  23. #include <kernel/panic.h>
  24. #include <arch/x86/int.h>
  25. #include <arch/io.h>
  26. #include <arch/sys.h>
  27. static int syslog_index = 0;
  28. void panic(const char *s) {
  29. printk(red, "kernel panic: %s\n", s);
  30. trace_syslog();
  31. for (;;) hlt();
  32. }
  33. void syslog(const char *s) {
  34. /* we can't use schk in this function, */
  35. /* because this will make a die-loop (schk_init calls this function) */
  36. int i;
  37. for (i = 0; s[i]; i++) {
  38. if (syslog_index == 32768)
  39. syslog_index = 0;
  40. SYSLOG_BUFFER[syslog_index++] = s[i];
  41. }
  42. return;
  43. }
  44. void trace_syslog(void) {
  45. int i;
  46. printk(yellow, "tracing system log: \n");
  47. for (i = 0; i < TRACE_SYSLOG_MAX; i++)
  48. putc(SYSLOG_BUFFER[syslog_index + i], yellow);
  49. return;
  50. }