syscalls_asm.S 870 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <lkmc.h>
  2. /* This is implemented in assembly so that it does not use the stack,
  3. * and thus can be called safely from programs without the bootloader.
  4. * C signature:
  5. *
  6. * void _exit(int status)
  7. *
  8. * If only there was a GCC attribute to create such a function!
  9. * https://stackoverflow.com/questions/43310704/creating-a-c-function-without-compiler-generated-prologue-epilogue-ret-instruc
  10. */
  11. .text
  12. .global _exit
  13. _exit:
  14. #if LKMC_GEM5
  15. LKMC_M5OPS_EXIT_ASM
  16. #else
  17. /* Use semihosting:
  18. * https://cirosantilli.com/linux-kernel-module-cheat#semihosting */
  19. #if defined(__arm__)
  20. mov r0, #0x18
  21. ldr r1, =#0x20026
  22. svc 0x00123456
  23. #elif defined(__aarch64__)
  24. mov x1, 0x26
  25. movk x1, 2, lsl 16
  26. ldr x2, =.Lsemihost_args
  27. str x1, [x2, 0]
  28. str x0, [x2, 8]
  29. mov x1, x2
  30. mov w0, 0x18
  31. hlt 0xf000
  32. .Lsemihost_args:
  33. .skip 16
  34. #endif
  35. #endif