libc-full.M1 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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_ebp,esp ; Protect esp
  18. ;; Prepare argv
  19. lea_eax,[ebp+DWORD] %4 ; ARGV_address = EBP + 4
  20. push_eax ; Put argv on the stack
  21. ;; Prepare envp
  22. mov_eax,ebp ; Address we need to load from
  23. mov_eax,[eax] ; Get ARGC
  24. add_eax, %2 ; OFFSET = ARGC + 2
  25. sal_eax, !2 ; OFFSET = OFFSET * WORDSIZE
  26. add_eax,ebp ; ENVP_address = ESP + OFFSET
  27. push_eax ; Put envp on the stack
  28. mov_ebx, &GLOBAL__envp ; Get _envp global
  29. mov_[ebx],eax ; Save environment to _envp
  30. ;; Stack offset
  31. add_ebp, %4 ; Fix ebp
  32. ;; Setup for malloc
  33. call %FUNCTION___init_malloc
  34. ;; Setup for FILE*
  35. call %FUNCTION___init_io
  36. ;; Perform the main loop
  37. call %FUNCTION_main
  38. push_eax ; Put return on stack
  39. push_eax ; so that _exit gets the value
  40. :FUNCTION_exit
  41. call %FUNCTION___kill_io
  42. :FUNCTION__exit
  43. pop_ebx
  44. pop_ebx
  45. mov_eax, %1
  46. int !0x80
  47. :GLOBAL__envp
  48. NULL