2023-04-07 02:27:15 +03:00
|
|
|
.section .text
|
|
|
|
|
|
|
|
.global _start
|
|
|
|
_start:
|
|
|
|
# Set up end of the stack frame linked list.
|
|
|
|
movq $0, %rbp
|
|
|
|
pushq %rbp # rip=0
|
|
|
|
pushq %rbp # rbp=0
|
|
|
|
movq %rsp, %rbp
|
|
|
|
|
2023-10-30 11:06:13 +02:00
|
|
|
# Save argc, argv, environ
|
2023-06-05 20:34:08 +03:00
|
|
|
pushq %rdx
|
2023-04-07 02:27:15 +03:00
|
|
|
pushq %rsi
|
|
|
|
pushq %rdi
|
|
|
|
|
2023-10-30 11:06:13 +02:00
|
|
|
# Prepare malloc, environment
|
2023-06-05 20:34:08 +03:00
|
|
|
movq %rdx, %rdi
|
2023-05-29 20:21:19 +03:00
|
|
|
call _init_libc
|
2023-04-07 02:27:15 +03:00
|
|
|
|
2023-10-30 11:06:13 +02:00
|
|
|
# Call global constructos
|
2023-04-07 02:27:15 +03:00
|
|
|
call _init
|
|
|
|
|
2023-10-30 11:06:13 +02:00
|
|
|
# Restore argc, argv, environ
|
2023-04-07 02:27:15 +03:00
|
|
|
popq %rdi
|
|
|
|
popq %rsi
|
2023-06-05 20:34:08 +03:00
|
|
|
popq %rdx
|
2023-04-07 02:27:15 +03:00
|
|
|
|
|
|
|
# Run main
|
|
|
|
call main
|
|
|
|
|
2023-10-30 11:06:13 +02:00
|
|
|
# Cleanly exit the process
|
2023-04-07 02:27:15 +03:00
|
|
|
movl %eax, %edi
|
|
|
|
call exit
|
2023-10-30 11:06:13 +02:00
|
|
|
|
2023-04-07 02:27:15 +03:00
|
|
|
.size _start, . - _start
|