libc-core.M1 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. ## Copyright (C) 2016 Jeremiah Orians
  2. ## This file is part of M2-Planet.
  3. ##
  4. ## M2-Planet is free software: you can redistribute it and/or modify
  5. ## it under the terms of the GNU General Public License as published by
  6. ## the Free Software Foundation, either version 3 of the License, or
  7. ## (at your option) any later version.
  8. ##
  9. ## M2-Planet is distributed in the hope that it will be useful,
  10. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ## GNU General Public License for more details.
  13. ##
  14. ## You should have received a copy of the GNU General Public License
  15. ## along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
  16. :_start
  17. mov_rbp,rsp ; Protect rsp
  18. ;; Prepare argv
  19. lea_rax,[rbp+DWORD] %8 ; ARGV_address = RBP + 8
  20. push_rax ; Put argv on the stack
  21. ;; Prepare envp
  22. mov_rax,rbp ; Address we need to load from
  23. mov_rax,[rax] ; Get ARGC
  24. add_rax, %2 ; OFFSET = ARGC + 2
  25. sal_rax, !3 ; OFFSET = OFFSET * WORDSIZE
  26. add_rax,rbp ; ENVP_address = RSP + OFFSET
  27. push_rax ; Put envp on the stack
  28. ;; Stack offset
  29. add_rbp, %8 ; Fix rbp
  30. ;; Perform the main loop
  31. call %FUNCTION_main
  32. push_rax ; Put return value on the stack
  33. push_rax ; So that _exit gets it
  34. :FUNCTION_exit
  35. :FUNCTION__exit
  36. pop_rbx
  37. pop_rdi
  38. mov_rax, %0x3C
  39. syscall