entry_unix_no_crt_amd64.asm 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. bits 64
  2. extern _start_odin
  3. global _start
  4. section .text
  5. ;; Entry point for programs that specify -no-crt option
  6. ;; This entry point should be compatible with dynamic loaders on linux
  7. ;; The parameters the dynamic loader passes to the _start function:
  8. ;; RDX = pointer to atexit function
  9. ;; The stack layout is as follows:
  10. ;; +-------------------+
  11. ;; NULL
  12. ;; +-------------------+
  13. ;; envp[m]
  14. ;; +-------------------+
  15. ;; ...
  16. ;; +-------------------+
  17. ;; envp[0]
  18. ;; +-------------------+
  19. ;; NULL
  20. ;; +-------------------+
  21. ;; argv[n]
  22. ;; +-------------------+
  23. ;; ...
  24. ;; +-------------------+
  25. ;; argv[0]
  26. ;; +-------------------+
  27. ;; argc
  28. ;; +-------------------+ <------ RSP
  29. ;;
  30. _start:
  31. ;; Mark stack frame as the top of the stack
  32. xor rbp, rbp
  33. ;; Load argc into 1st param reg, argv into 2nd param reg
  34. pop rdi
  35. mov rdx, rsi
  36. ;; Align stack pointer down to 16-bytes (sysv calling convention)
  37. and rsp, -16
  38. ;; Call into odin entry point
  39. call _start_odin
  40. jmp $$