linux-x86.S 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. .text
  2. .globl _start
  3. .type _start,@function
  4. .p2align 4
  5. _start:
  6. xorl %ebp, %ebp
  7. #ifdef __LP64__
  8. popq %rdi
  9. movq %rsp, %rsi
  10. andq $~15, %rsp
  11. #elif defined __x86_64__
  12. mov (%rsp),%edi
  13. addl $4,%esp
  14. movl %esp, %esi
  15. andl $~15, %esp
  16. #else
  17. popl %esi
  18. movl %esp, %ecx
  19. andl $~15, %esp
  20. subl $8,%esp
  21. pushl %ecx
  22. pushl %esi
  23. #endif
  24. call main
  25. hlt
  26. .type syscall, @function
  27. .globl syscall
  28. .p2align 4
  29. syscall:
  30. #ifdef __x86_64__
  31. movq %rdi, %rax /* Syscall number -> rax. */
  32. movq %rsi, %rdi /* shift arg1 - arg5. */
  33. movq %rdx, %rsi
  34. movq %rcx, %rdx
  35. movq %r8, %r10
  36. movq %r9, %r8
  37. movq 8(%rsp),%r9 /* arg6 is on the stack. */
  38. syscall /* Do the system call. */
  39. #else
  40. push %ebp
  41. push %edi
  42. push %esi
  43. push %ebx
  44. mov 0x2c(%esp),%ebp
  45. mov 0x28(%esp),%edi
  46. mov 0x24(%esp),%esi
  47. mov 0x20(%esp),%edx
  48. mov 0x1c(%esp),%ecx
  49. mov 0x18(%esp),%ebx
  50. mov 0x14(%esp),%eax
  51. int $0x80
  52. pop %ebx
  53. pop %esi
  54. pop %edi
  55. pop %ebp
  56. #endif
  57. ret /* Return to caller. */
  58. .size syscall, .-syscall
  59. .section .note.GNU-stack,"",@progbits
  60. .section ".note.gnu.property", "a"
  61. #ifdef __LP64__
  62. .p2align 3
  63. #else
  64. .p2align 2
  65. #endif
  66. .long 1f - 0f /* name length */
  67. .long 5f - 2f /* data length */
  68. .long 5 /* note type */
  69. 0: .asciz "GNU" /* vendor name */
  70. 1:
  71. #ifdef __LP64__
  72. .p2align 3
  73. #else
  74. .p2align 2
  75. #endif
  76. 2: .long 0xc0000002 /* pr_type. */
  77. .long 4f - 3f /* pr_datasz. */
  78. 3:
  79. .long 0x2
  80. 4:
  81. #ifdef __LP64__
  82. .p2align 3
  83. #else
  84. .p2align 2
  85. #endif
  86. 5: