1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- ## Copyright (C) 2016 Jeremiah Orians
- ## This file is part of M2-Planet.
- ##
- ## M2-Planet is free software: you can redistribute it and/or modify
- ## it under the terms of the GNU General Public License as published by
- ## the Free Software Foundation, either version 3 of the License, or
- ## (at your option) any later version.
- ##
- ## M2-Planet is distributed in the hope that it will be useful,
- ## but WITHOUT ANY WARRANTY; without even the implied warranty of
- ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ## GNU General Public License for more details.
- ##
- ## You should have received a copy of the GNU General Public License
- ## along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
- :_start
- mov_ebp,esp ; Protect esp
- ;; Prepare argv
- lea_eax,[ebp+DWORD] %4 ; ARGV_address = EBP + 4
- push_eax ; Put argv on the stack
- ;; Prepare envp
- mov_eax,ebp ; Address we need to load from
- mov_eax,[eax] ; Get ARGC
- add_eax, %2 ; OFFSET = ARGC + 2
- sal_eax, !2 ; OFFSET = OFFSET * WORDSIZE
- add_eax,ebp ; ENVP_address = ESP + OFFSET
- push_eax ; Put envp on the stack
- mov_ebx, &GLOBAL__envp ; Get _envp global
- mov_[ebx],eax ; Save environment to _envp
- ;; Stack offset
- add_ebp, %4 ; Fix ebp
- ;; Setup for malloc
- call %FUNCTION___init_malloc
- ;; Setup for FILE*
- call %FUNCTION___init_io
- ;; Perform the main loop
- call %FUNCTION_main
- push_eax ; Put return on stack
- push_eax ; so that _exit gets the value
- :FUNCTION_exit
- call %FUNCTION___kill_io
- :FUNCTION__exit
- pop_ebx
- pop_ebx
- mov_eax, %1
- int !0x80
- :GLOBAL__envp
- NULL
|