signal.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* idt.c - routines for constructing IDT fot the GDB stub */
  2. /*
  3. * Copyright (C) 2006 Lubomir Kundrak
  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 of the License, or
  8. * (at your option) 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, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. #include <grub/machine/memory.h>
  20. #include <grub/misc.h>
  21. #include <grub/cpu/gdb.h>
  22. #include <grub/gdb.h>
  23. /* Converting CPU trap number to UNIX signal number as
  24. described in System V ABI i386 Processor Supplement, 3-25. */
  25. unsigned int
  26. grub_gdb_trap2sig (int trap_no)
  27. {
  28. const int signals[] = {
  29. SIGFPE, /* 0: Divide error fault */
  30. SIGTRAP, /* 1: Single step trap fault */
  31. SIGABRT, /* 2: # Nonmaskable interrupt */
  32. SIGTRAP, /* 3: Breakpoint trap */
  33. SIGSEGV, /* 4: Overflow trap */
  34. SIGSEGV, /* 5: Bounds check fault */
  35. SIGILL, /* 6: Invalid opcode fault */
  36. SIGFPE, /* 7: No coprocessor fault */
  37. SIGABRT, /* 8: # Double fault abort */
  38. SIGSEGV, /* 9: Coprocessor overrun abort */
  39. SIGSEGV, /* 10: Invalid TSS fault */
  40. SIGSEGV, /* 11: Segment not present fault */
  41. SIGSEGV, /* 12: Stack exception fault */
  42. SIGSEGV, /* 13: General protection fault abort */
  43. SIGSEGV, /* 14: Page fault */
  44. SIGABRT, /* 15: (reserved) */
  45. SIGFPE, /* 16: Coprocessor error fault */
  46. SIGUSR1 /* other */
  47. };
  48. return signals[trap_no < 17 ? trap_no : 17];
  49. }