2
0

entry_unix_no_crt_amd64.asm 1.1 KB

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