2023-01-06 12:31:14 +00:00
|
|
|
.section .text
|
|
|
|
|
|
|
|
.global _start
|
|
|
|
.extern exit
|
2023-03-18 18:23:18 +00:00
|
|
|
.extern libc_init
|
2024-01-04 20:02:51 +00:00
|
|
|
.extern _init
|
|
|
|
.extern _fini
|
2023-01-06 12:31:14 +00:00
|
|
|
_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-03-18 21:25:19 +00:00
|
|
|
pushq %rsi
|
|
|
|
pushq %rdi
|
2023-04-07 13:03:38 +00:00
|
|
|
pushq %rcx
|
2023-03-18 21:25:19 +00:00
|
|
|
|
2023-03-18 18:23:18 +00:00
|
|
|
call libc_init
|
|
|
|
|
2023-01-06 12:31:14 +00:00
|
|
|
# Run the global constructors.
|
|
|
|
call _init
|
|
|
|
|
2023-04-07 13:03:38 +00:00
|
|
|
popq %rdx
|
2023-03-18 21:25:19 +00:00
|
|
|
popq %rdi
|
|
|
|
popq %rsi
|
|
|
|
|
2023-01-06 12:31:14 +00:00
|
|
|
# Run main
|
|
|
|
call main
|
|
|
|
|
2024-01-04 20:02:51 +00:00
|
|
|
# Store the exit code before calling _fini.
|
|
|
|
push %rax
|
|
|
|
|
|
|
|
call _fini
|
|
|
|
|
2023-01-06 12:31:14 +00:00
|
|
|
# Terminate the process with the exit code.
|
2024-01-04 20:02:51 +00:00
|
|
|
pop %rdi
|
2023-01-06 12:31:14 +00:00
|
|
|
call exit
|