crt0.s 651 B

1234567891011121314151617181920212223242526272829303132333435
  1. .code32
  2. .text
  3. # TODO: call .init and .fini, initialize c standard library
  4. .globl _start
  5. .type _start @function
  6. _start:
  7. movl %esp, %ebx # initial stack
  8. andl $0xfffffff0, %esp
  9. pushl $0
  10. movl %esp, %ebp
  11. movl (%ebx), %eax # %eax = argc
  12. leal 8(%ebx, %eax, 4), %ecx # %ecx = envp
  13. pushl %ecx
  14. leal 4(%ebx), %ecx # %ecx = argv
  15. pushl %ecx
  16. pushl %eax
  17. call __init_gblibc
  18. movl (%ebx), %eax # %eax = argc
  19. movl %eax, (%esp)
  20. leal 4(%ebx), %eax
  21. movl %eax, 4(%esp)
  22. call main
  23. movl %eax, %ebx # code
  24. movl $0xfc, %eax # SYS_exit_group
  25. int $0x80 # syscall