_exit.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2016,2017,2019,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  4. * Copyright © 2019,2020 Danny Milosavljevic <dannym@scratchpost.org>
  5. *
  6. * This file is part of GNU Mes.
  7. *
  8. * GNU Mes is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or (at
  11. * your option) any later version.
  12. *
  13. * GNU Mes is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include "mes/lib-mini.h"
  22. // *INDENT-OFF*
  23. #if !__TINYC__
  24. #define SYS_exit "0x01"
  25. void
  26. _exit (int code)
  27. {
  28. asm (
  29. "mov r7, $"SYS_exit"\n\t"
  30. "mov r0, %0\n\t"
  31. "swi $0\n\t"
  32. : // no outputs "=" (r)
  33. : "r" (code)
  34. : "r0", "r7"
  35. );
  36. // not reached
  37. _exit (0);
  38. }
  39. #else //__TINYC__
  40. #define SYS_exit 0x01
  41. void
  42. _exit (int code)
  43. {
  44. int c = SYS_exit;
  45. __asm__ (".int 0xe51b7004\n"); //ldr r7, [fp, #-4] ; "c"
  46. __asm__ (".int 0xe59b000c\n"); //ldr r0, [fp, #12] ; code
  47. __asm__ (".int 0xef000000\n"); //svc 0x00000000
  48. }
  49. #endif //__TINYC__