ソースを参照

fix(crt0): do not use parameters on the stack

greatbridf 1 年間 前
コミット
225bbdf08a
1 ファイル変更13 行追加11 行削除
  1. 13 11
      gblibc/src/crt0.s

+ 13 - 11
gblibc/src/crt0.s

@@ -6,28 +6,30 @@
 .globl _start
 .type  _start @function
 _start:
-    movl (%esp), %eax   # argc
-    leal 4(%esp), %ecx  # argv
-    movl %esp, %ebx
-
+    movl %esp, %ebx     # initial stack
     andl $0xfffffff0, %esp
-
-    pushl %ebx
+    pushl $0
     movl %esp, %ebp
 
-    leal (%ebx, %eax, 4), %ebx
-    addl $8, %ebx
-    pushl %ebx
+    movl (%ebx), %eax           # %eax = argc
 
+    leal 8(%ebx, %eax, 4), %ecx # %ecx = envp
     pushl %ecx
+
+    leal 4(%ebx), %ecx          # %ecx = argv
+    pushl %ecx
+
     pushl %eax
 
     call __init_gblibc
 
-    subl $4, %ebp
+    movl (%ebx), %eax # %eax = argc
+    movl %eax, (%esp)
+    leal 4(%ebx), %eax
+    movl %eax, 4(%esp)
 
     call main
 
     movl %eax, %edi  # code
-    movl $60, %eax # SYS_exit
+    movl $60, %eax   # SYS_exit
     int $0x80        # syscall