2017-11-05 20:07:16 +00:00
|
|
|
## Copyright (C) 2016 Jeremiah Orians
|
2018-10-18 00:27:06 +01:00
|
|
|
## This file is part of M2-Planet.
|
2017-11-05 20:07:16 +00:00
|
|
|
##
|
2018-10-18 00:27:06 +01:00
|
|
|
## M2-Planet is free software: you can redistribute it and/or modify
|
2017-11-05 20:07:16 +00:00
|
|
|
## 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.
|
|
|
|
##
|
2018-10-18 00:27:06 +01:00
|
|
|
## M2-Planet is distributed in the hope that it will be useful,
|
2017-11-05 20:07:16 +00:00
|
|
|
## 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
|
2018-10-18 00:27:06 +01:00
|
|
|
## along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
|
2017-11-05 20:07:16 +00:00
|
|
|
|
|
|
|
:_start
|
2018-10-17 21:08:04 +01:00
|
|
|
|
|
|
|
COPY_esp_to_ebp ; Protect esp
|
|
|
|
|
|
|
|
;; Prepare argv
|
|
|
|
LOAD_BASE_ADDRESS_eax %4 ; ARGV_address = EBP + 4
|
|
|
|
PUSH_eax ; Put argv on the stack
|
|
|
|
|
|
|
|
;; Prepare envp
|
|
|
|
COPY_ebp_to_eax ; Address we need to load from
|
|
|
|
LOAD_INTEGER ; Get ARGC
|
|
|
|
ADD_IMMEDIATE_to_eax %2 ; OFFSET = ARGC + 2
|
|
|
|
SAL_eax_Immediate8 !2 ; OFFSET = OFFSET * WORDSIZE
|
|
|
|
ADD_ebp_to_eax ; ENVP_address = ESP + OFFSET
|
|
|
|
PUSH_eax ; Put envp on the stack
|
|
|
|
|
|
|
|
;; Stack offset
|
|
|
|
ADD_IMMEDIATE_to_ebp %4 ; Fix ebp
|
|
|
|
|
|
|
|
;; Perform the main loop
|
2017-11-05 20:07:16 +00:00
|
|
|
CALL_IMMEDIATE %FUNCTION_main
|
2018-10-17 21:08:04 +01:00
|
|
|
|
|
|
|
;; Exit to kernel
|
|
|
|
COPY_eax_to_ebx ; Using the return code given by main
|
|
|
|
LOAD_IMMEDIATE_eax %1 ; Syscall exit
|
|
|
|
INT_80 ; Exit with that code
|