aboutsummaryrefslogtreecommitdiffstats
path: root/exec
diff options
context:
space:
mode:
authorPo Lu2024-06-27 10:15:13 +0800
committerPo Lu2024-06-27 10:15:13 +0800
commitfa322155ad51e3628256232bc113ad7499ab76e7 (patch)
treef1e0161e108fa6da5aa00165e1bc6384ccb16146 /exec
parentda11a2a5cc3fa7e28031dc87e0f07004a9a005f7 (diff)
downloademacs-fa322155ad51e3628256232bc113ad7499ab76e7.tar.gz
emacs-fa322155ad51e3628256232bc113ad7499ab76e7.zip
Disable preprocessing of assembler files with m4 on non-MIPS systems
* exec/Makefile.in (is_mips): New substitution. (.s.o): Avoid calling m4 unless it be set. * exec/configure.ac: Substitute is_mips, and don't generate config-mips.m4 otherwise. * exec/loader-x86.s: * exec/loader-x86_64.s: Use assembler rather than m4-defined comment syntax.
Diffstat (limited to 'exec')
-rw-r--r--exec/Makefile.in9
-rw-r--r--exec/configure.ac5
-rw-r--r--exec/loader-x86.s187
-rw-r--r--exec/loader-x86_64.s215
4 files changed, 211 insertions, 205 deletions
diff --git a/exec/Makefile.in b/exec/Makefile.in
index 36f0c0c74a9..6969039b0a4 100644
--- a/exec/Makefile.in
+++ b/exec/Makefile.in
@@ -44,6 +44,9 @@ FIND_DELETE = @FIND_DELETE@
44 OBJS = @OBJS@ 44 OBJS = @OBJS@
45 LOADOBJS = $(patsubst %.s,%.o,$(LOADER)) 45 LOADOBJS = $(patsubst %.s,%.o,$(LOADER))
46 46
47# Compilation parameters.
48 is_mips = @is_mips@
49
47# Set up automatic dependency tracking. 50# Set up automatic dependency tracking.
48 51
49AUTO_DEPEND = @AUTO_DEPEND@ 52AUTO_DEPEND = @AUTO_DEPEND@
@@ -82,9 +85,15 @@ Makefile: config.status Makefile.in
82.SUFFIXES: .c .s 85.SUFFIXES: .c .s
83.c.o: 86.c.o:
84 $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEPFLAGS) -I. -I$(srcdir) $< -o $@ 87 $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEPFLAGS) -I. -I$(srcdir) $< -o $@
88
89ifeq ($(is_mips),yes)
85.s.o: 90.s.o:
86 $(M4) $< > $(notdir $<).s 91 $(M4) $< > $(notdir $<).s
87 $(AS) $(ASFLAGS) $(notdir $<).s -o $@ 92 $(AS) $(ASFLAGS) $(notdir $<).s -o $@
93else
94.s.o:
95 $(AS) $(ASFLAGS) $< -o $@
96endif
88 97
89# Set up dependencies for config-mips.m4. 98# Set up dependencies for config-mips.m4.
90 99
diff --git a/exec/configure.ac b/exec/configure.ac
index a473a1dc633..5be8a983718 100644
--- a/exec/configure.ac
+++ b/exec/configure.ac
@@ -547,7 +547,9 @@ FIND_DELETE=$exec_cv_find_delete
547AC_SUBST([FIND_DELETE]) 547AC_SUBST([FIND_DELETE])
548 548
549AC_CONFIG_HEADERS([config.h]) 549AC_CONFIG_HEADERS([config.h])
550AC_CONFIG_FILES([Makefile config-mips.m4]) 550AC_CONFIG_FILES([Makefile])
551AS_IF([test "x$is_mips" = xyes],
552 [AC_CONFIG_FILES ([config-mips.m4])])
551 553
552AC_SUBST([AUTO_DEPEND]) 554AC_SUBST([AUTO_DEPEND])
553AC_SUBST([LOADERFLAGS]) 555AC_SUBST([LOADERFLAGS])
@@ -556,5 +558,6 @@ AC_SUBST([ASFLAGS])
556AC_SUBST([exec_loader]) 558AC_SUBST([exec_loader])
557AC_SUBST([MIPS_N32]) 559AC_SUBST([MIPS_N32])
558AC_SUBST([OBJS]) 560AC_SUBST([OBJS])
561AC_SUBST([is_mips])
559 562
560AC_OUTPUT 563AC_OUTPUT
diff --git a/exec/loader-x86.s b/exec/loader-x86.s
index 216bc88f976..3d132dd99e8 100644
--- a/exec/loader-x86.s
+++ b/exec/loader-x86.s
@@ -1,71 +1,68 @@
1define(`CC', ` 1# Copyright (C) 2023-2024 Free Software Foundation, Inc.
2dnl') 2#
3 3# This file is part of GNU Emacs.
4CC Copyright (C) 2023-2024 Free Software Foundation, Inc. 4#
5CC 5# GNU Emacs is free software: you can redistribute it and/or modify
6CC This file is part of GNU Emacs. 6# it under the terms of the GNU General Public License as published
7CC 7# by the Free Software Foundation, either version 3 of the License,
8CC GNU Emacs is free software: you can redistribute it and/or modify 8# or (at your option) any later version.
9CC it under the terms of the GNU General Public License as published 9#
10CC by the Free Software Foundation, either version 3 of the License, 10# GNU Emacs is distributed in the hope that it will be useful, but
11CC or (at your option) any later version. 11# WITHOUT ANY WARRANTY; without even the implied warranty of
12CC 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13CC GNU Emacs is distributed in the hope that it will be useful, but 13# General Public License for more details.
14CC WITHOUT ANY WARRANTY; without even the implied warranty of 14#
15CC MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15# You should have received a copy of the GNU General Public License
16CC General Public License for more details. 16# along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
17CC
18CC You should have received a copy of the GNU General Public License
19CC along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
20 17
21 .section .text 18 .section .text
22 .global _start 19 .global _start
23_start: 20_start:
24dnl movl $162, %eax CC SYS_nanosleep 21# movl $162, %eax # SYS_nanosleep
25dnl leal timespec, %ebx 22# leal timespec, %ebx
26dnl xorl %ecx, %ecx 23# xorl %ecx, %ecx
27dnl int $0x80 24# int $0x80
28 leal 8(%esp), %ebp CC ebp = start of load area 25 leal 8(%esp), %ebp # ebp = start of load area
29 subl $8, %esp CC (%esp) = primary fd, 4(%esp) = secondary fd 26 subl $8, %esp # (%esp) = primary fd, 4(%esp) = secondary fd
30 movl $-1, 4(%esp) 27 movl $-1, 4(%esp)
31.next_action: 28.next_action:
32 movl (%ebp), %edx CC edx = action number 29 movl (%ebp), %edx # edx = action number
33 andl $-17, %edx 30 andl $-17, %edx
34 cmpl $0, %edx CC open file? 31 cmpl $0, %edx # open file?
35 je .open_file 32 je .open_file
36 cmpl $3, %edx CC jump? 33 cmpl $3, %edx # jump?
37 je .rest_of_exec 34 je .rest_of_exec
38 cmpl $4, %edx CC anonymous mmap? 35 cmpl $4, %edx # anonymous mmap?
39 je .do_mmap_anon 36 je .do_mmap_anon
40.do_mmap: 37.do_mmap:
41 subl $24, %esp 38 subl $24, %esp
42 movl $90, %eax CC SYS_old_mmap 39 movl $90, %eax # SYS_old_mmap
43 movl %esp, %ebx 40 movl %esp, %ebx
44 movl 4(%ebp), %ecx CC address 41 movl 4(%ebp), %ecx # address
45 movl %ecx, (%esp) 42 movl %ecx, (%esp)
46 movl 16(%ebp), %ecx CC length 43 movl 16(%ebp), %ecx # length
47 movl %ecx, 4(%esp) 44 movl %ecx, 4(%esp)
48 movl 12(%ebp), %ecx CC protection 45 movl 12(%ebp), %ecx # protection
49 movl %ecx, 8(%esp) 46 movl %ecx, 8(%esp)
50 movl 20(%ebp), %ecx CC flags 47 movl 20(%ebp), %ecx # flags
51 movl %ecx, 12(%esp) 48 movl %ecx, 12(%esp)
52 testl $16, (%ebp) CC primary? 49 testl $16, (%ebp) # primary?
53 movl 28(%esp), %ecx 50 movl 28(%esp), %ecx
54 cmovzl 24(%esp), %ecx 51 cmovzl 24(%esp), %ecx
55 movl %ecx, 16(%esp) CC fd 52 movl %ecx, 16(%esp) # fd
56 movl 8(%ebp), %ecx CC offset 53 movl 8(%ebp), %ecx # offset
57 movl %ecx, 20(%esp) 54 movl %ecx, 20(%esp)
58.do_mmap_1: 55.do_mmap_1:
59 int $0x80 56 int $0x80
60 addl $24, %esp CC restore esp 57 addl $24, %esp # restore esp
61 cmpl $-1, %eax CC mmap failed? 58 cmpl $-1, %eax # mmap failed?
62 je .perror 59 je .perror
63 movl 24(%ebp), %ecx CC clear 60 movl 24(%ebp), %ecx # clear
64 testl %ecx, %ecx 61 testl %ecx, %ecx
65 jz .continue 62 jz .continue
66 movl 4(%ebp), %esi CC start of mapping 63 movl 4(%ebp), %esi # start of mapping
67 addl 16(%ebp), %esi CC end of mapping 64 addl 16(%ebp), %esi # end of mapping
68 subl %ecx, %esi CC start of clear area 65 subl %ecx, %esi # start of clear area
69.again: 66.again:
70 testl %ecx, %ecx 67 testl %ecx, %ecx
71 jz .continue 68 jz .continue
@@ -77,58 +74,58 @@ dnl int $0x80
77 jmp .next_action 74 jmp .next_action
78.do_mmap_anon: 75.do_mmap_anon:
79 subl $24, %esp 76 subl $24, %esp
80 movl $90, %eax CC SYS_old_mmap 77 movl $90, %eax # SYS_old_mmap
81 movl %esp, %ebx 78 movl %esp, %ebx
82 movl 4(%ebp), %ecx CC address 79 movl 4(%ebp), %ecx # address
83 movl %ecx, (%esp) 80 movl %ecx, (%esp)
84 movl 16(%ebp), %ecx CC length 81 movl 16(%ebp), %ecx # length
85 movl %ecx, 4(%esp) 82 movl %ecx, 4(%esp)
86 movl 12(%ebp), %ecx CC protection 83 movl 12(%ebp), %ecx # protection
87 movl %ecx, 8(%esp) 84 movl %ecx, 8(%esp)
88 movl 20(%ebp), %ecx CC flags 85 movl 20(%ebp), %ecx # flags
89 movl %ecx, 12(%esp) 86 movl %ecx, 12(%esp)
90 movl $-1, 16(%esp) CC fd 87 movl $-1, 16(%esp) # fd
91 movl 8(%ebp), %ecx CC offset 88 movl 8(%ebp), %ecx # offset
92 movl %ecx, 20(%esp) 89 movl %ecx, 20(%esp)
93 jmp .do_mmap_1 90 jmp .do_mmap_1
94.open_file: 91.open_file:
95 movl $5, %eax CC SYS_open 92 movl $5, %eax # SYS_open
96 leal 4(%ebp), %ebx CC ebx = %esp + 8 93 leal 4(%ebp), %ebx # ebx = %esp + 8
97 pushl %ebx 94 pushl %ebx
98 xorl %ecx, %ecx CC flags = O_RDONLY 95 xorl %ecx, %ecx # flags = O_RDONLY
99 xorl %edx, %edx CC mode = 0 96 xorl %edx, %edx # mode = 0
100 int $0x80 97 int $0x80
101 cmpl $-1, %eax CC open failed? 98 cmpl $-1, %eax # open failed?
102 jle .perror 99 jle .perror
103 movl %ebp, %esi CC (esi) = original action number 100 movl %ebp, %esi # (esi) = original action number
104 popl %ebp CC ebp = start of string 101 popl %ebp # ebp = start of string
105 movl %ebp, %ecx CC char past separator 102 movl %ebp, %ecx # char past separator
106 decl %ebp 103 decl %ebp
107.nextc: 104.nextc:
108 incl %ebp 105 incl %ebp
109 movb (%ebp), %dl CC dl = *ebp 106 movb (%ebp), %dl # dl = *ebp
110 cmpb $47, %dl CC dl == '\?'? 107 cmpb $47, %dl # dl == '\?'?
111 jne .nextc1 108 jne .nextc1
112 leal 1(%ebp), %ecx CC ecx = char past separator 109 leal 1(%ebp), %ecx # ecx = char past separator
113.nextc1: 110.nextc1:
114 cmpb $0, %dl CC dl == 0? 111 cmpb $0, %dl # dl == 0?
115 jne .nextc 112 jne .nextc
116 addl $4, %ebp CC adjust past ebp prior to rounding 113 addl $4, %ebp # adjust past ebp prior to rounding
117 andl $-4, %ebp CC round ebp up to the next long 114 andl $-4, %ebp # round ebp up to the next long
118 testl $16, (%esi) CC original action number & 16? 115 testl $16, (%esi) # original action number & 16?
119 jz .primary 116 jz .primary
120 movl %eax, 4(%esp) CC secondary fd = eax 117 movl %eax, 4(%esp) # secondary fd = eax
121 jmp .next_action 118 jmp .next_action
122.primary: 119.primary:
123 pushl %ebp 120 pushl %ebp
124 xorl %esi, %esi CC arg3 121 xorl %esi, %esi # arg3
125 movl %eax, 4(%esp) CC primary fd = eax 122 movl %eax, 4(%esp) # primary fd = eax
126 xorl %edx, %edx CC arg2 123 xorl %edx, %edx # arg2
127 movl $15, %ebx CC PR_SET_NAME, arg1 = ecx 124 movl $15, %ebx # PR_SET_NAME, arg1 = ecx
128 xorl %edi, %edi CC arg4 125 xorl %edi, %edi # arg4
129 movl $172, %eax CC SYS_prctl 126 movl $172, %eax # SYS_prctl
130 xorl %ebp, %ebp CC arg5 127 xorl %ebp, %ebp # arg5
131 int $0x80 CC syscall 128 int $0x80 # syscall
132 popl %ebp 129 popl %ebp
133 jmp .next_action 130 jmp .next_action
134.perror: 131.perror:
@@ -137,28 +134,28 @@ dnl int $0x80
137 movl $1, %eax 134 movl $1, %eax
138 int $0x80 135 int $0x80
139.rest_of_exec: 136.rest_of_exec:
140 movl 8(%esp), %ecx CC ecx = original stack pointer 137 movl 8(%esp), %ecx # ecx = original stack pointer
141 movl (%ecx), %esi CC esi = argc 138 movl (%ecx), %esi # esi = argc
142 leal 8(%ecx, %esi, 4), %ecx CC ecx = start of environ 139 leal 8(%ecx, %esi, 4), %ecx # ecx = start of environ
143.skip_environ: 140.skip_environ:
144 movl (%ecx), %esi CC envp[N] 141 movl (%ecx), %esi # envp[N]
145 addl $4, %ecx 142 addl $4, %ecx
146 testl %esi, %esi CC envp[n] ? 143 testl %esi, %esi # envp[n] ?
147 jnz .skip_environ CC otherwise, esi is now at the start of auxv 144 jnz .skip_environ # otherwise, esi is now at the start of auxv
148.one_auxv: 145.one_auxv:
149 movl (%ecx), %esi CC auxv type 146 movl (%ecx), %esi # auxv type
150 leal 8(%ecx), %ecx CC skip to next auxv 147 leal 8(%ecx), %ecx # skip to next auxv
151 testl %esi, %esi CC is 0? 148 testl %esi, %esi # is 0?
152 jz .cleanup 149 jz .cleanup
153 cmpl $3, %esi CC is AT_PHDR 150 cmpl $3, %esi # is AT_PHDR
154 je .replace_phdr 151 je .replace_phdr
155 cmpl $4, %esi CC is AT_PHENT? 152 cmpl $4, %esi # is AT_PHENT?
156 je .replace_phent 153 je .replace_phent
157 cmpl $5, %esi CC is AT_PHNUM? 154 cmpl $5, %esi # is AT_PHNUM?
158 je .replace_phnum 155 je .replace_phnum
159 cmpl $9, %esi CC is AT_ENTRY? 156 cmpl $9, %esi # is AT_ENTRY?
160 je .replace_entry 157 je .replace_entry
161 cmpl $7, %esi CC is AT_BASE 158 cmpl $7, %esi # is AT_BASE
162 je .replace_base 159 je .replace_base
163 jmp .one_auxv 160 jmp .one_auxv
164.replace_phdr: 161.replace_phdr:
@@ -182,21 +179,21 @@ dnl int $0x80
182 movl %esi, -4(%ecx) 179 movl %esi, -4(%ecx)
183 jmp .one_auxv 180 jmp .one_auxv
184.cleanup: 181.cleanup:
185 movl $6, %eax CC SYS_close 182 movl $6, %eax # SYS_close
186 cmpl $-1, 4(%esp) CC see if interpreter fd is set 183 cmpl $-1, 4(%esp) # see if interpreter fd is set
187 je .cleanup_1 184 je .cleanup_1
188 movl 4(%esp), %ebx 185 movl 4(%esp), %ebx
189 int $0x80 186 int $0x80
190 movl $6, %eax CC SYS_close 187 movl $6, %eax # SYS_close
191.cleanup_1: 188.cleanup_1:
192 movl (%esp), %ebx 189 movl (%esp), %ebx
193 int $0x80 190 int $0x80
194.enter: 191.enter:
195 pushl $0 192 pushl $0
196 popfl CC restore floating point state 193 popfl # restore floating point state
197 movl 8(%esp), %esp CC restore initial stack pointer 194 movl 8(%esp), %esp # restore initial stack pointer
198 xorl %edx, %edx CC clear rtld_fini 195 xorl %edx, %edx # clear rtld_fini
199 jmpl *4(%ebp) CC entry 196 jmpl *4(%ebp) # entry
200 197
201timespec: 198timespec:
202 .long 10 199 .long 10
diff --git a/exec/loader-x86_64.s b/exec/loader-x86_64.s
index 2ef779e4504..ea2958b91e0 100644
--- a/exec/loader-x86_64.s
+++ b/exec/loader-x86_64.s
@@ -1,64 +1,61 @@
1define(`CC', ` 1# Copyright (C) 2023-2024 Free Software Foundation, Inc.
2dnl') 2#
3 3# This file is part of GNU Emacs.
4CC Copyright (C) 2023-2024 Free Software Foundation, Inc. 4#
5CC 5# GNU Emacs is free software: you can redistribute it and/or modify
6CC This file is part of GNU Emacs. 6# it under the terms of the GNU General Public License as published
7CC 7# by the Free Software Foundation, either version 3 of the License,
8CC GNU Emacs is free software: you can redistribute it and/or modify 8# or (at your option) any later version.
9CC it under the terms of the GNU General Public License as published 9#
10CC by the Free Software Foundation, either version 3 of the License, 10# GNU Emacs is distributed in the hope that it will be useful, but
11CC or (at your option) any later version. 11# WITHOUT ANY WARRANTY; without even the implied warranty of
12CC 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13CC GNU Emacs is distributed in the hope that it will be useful, but 13# General Public License for more details.
14CC WITHOUT ANY WARRANTY; without even the implied warranty of 14#
15CC MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15# You should have received a copy of the GNU General Public License
16CC General Public License for more details. 16# along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
17CC
18CC You should have received a copy of the GNU General Public License
19CC along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
20 17
21 .section .text 18 .section .text
22 .global _start 19 .global _start
23_start: 20_start:
24dnl movq $35, %rax CC SYS_nanosleep 21# movq $35, %rax # SYS_nanosleep
25dnl leaq timespec(%rip), %rdi 22# leaq timespec(%rip), %rdi
26dnl xorq %rsi, %rsi 23# xorq %rsi, %rsi
27dnl syscall 24# syscall
28 popq %r13 CC original SP 25 popq %r13 # original SP
29 popq %r15 CC size of load area. 26 popq %r15 # size of load area.
30 movq $-1, %r12 CC r12 is the interpreter fd 27 movq $-1, %r12 # r12 is the interpreter fd
31.next_action: 28.next_action:
32 movq (%rsp), %r14 CC action number 29 movq (%rsp), %r14 # action number
33 movq %r14, %r15 CC original action number 30 movq %r14, %r15 # original action number
34 andq $-17, %r14 31 andq $-17, %r14
35 cmpq $0, %r14 CC open file? 32 cmpq $0, %r14 # open file?
36 je .open_file 33 je .open_file
37 cmpq $3, %r14 CC jump? 34 cmpq $3, %r14 # jump?
38 je .rest_of_exec 35 je .rest_of_exec
39 cmpq $4, %r14 CC anonymous mmap? 36 cmpq $4, %r14 # anonymous mmap?
40 je .do_mmap_anon 37 je .do_mmap_anon
41.do_mmap: 38.do_mmap:
42 movq $9, %rax CC SYS_mmap 39 movq $9, %rax # SYS_mmap
43 movq 8(%rsp), %rdi CC address 40 movq 8(%rsp), %rdi # address
44 movq 16(%rsp), %r9 CC offset 41 movq 16(%rsp), %r9 # offset
45 movq 24(%rsp), %rdx CC protection 42 movq 24(%rsp), %rdx # protection
46 movq 32(%rsp), %rsi CC length 43 movq 32(%rsp), %rsi # length
47 movq 40(%rsp), %r10 CC flags 44 movq 40(%rsp), %r10 # flags
48 CC set r8 to the primary fd unless r15 & 16 45 # set r8 to the primary fd unless r15 & 16
49 testq $16, %r15 46 testq $16, %r15
50 movq %r12, %r8 47 movq %r12, %r8
51 cmovzq %rbx, %r8 48 cmovzq %rbx, %r8
52.do_mmap_1: 49.do_mmap_1:
53 syscall 50 syscall
54 cmpq $-1, %rax CC mmap failed 51 cmpq $-1, %rax # mmap failed
55 je .perror 52 je .perror
56 movq 48(%rsp), %r9 CC clear 53 movq 48(%rsp), %r9 # clear
57 testq %r9, %r9 54 testq %r9, %r9
58 jz .continue 55 jz .continue
59 movq 8(%rsp), %r10 CC start of mapping 56 movq 8(%rsp), %r10 # start of mapping
60 addq 32(%rsp), %r10 CC end of mapping 57 addq 32(%rsp), %r10 # end of mapping
61 subq %r9, %r10 CC start of clear area 58 subq %r9, %r10 # start of clear area
62.again: 59.again:
63 testq %r9, %r9 60 testq %r9, %r9
64 jz .continue 61 jz .continue
@@ -69,124 +66,124 @@ dnl syscall
69 leaq 56(%rsp), %rsp 66 leaq 56(%rsp), %rsp
70 jmp .next_action 67 jmp .next_action
71.do_mmap_anon: 68.do_mmap_anon:
72 movq $9, %rax CC SYS_mmap 69 movq $9, %rax # SYS_mmap
73 movq 8(%rsp), %rdi CC address 70 movq 8(%rsp), %rdi # address
74 movq 16(%rsp), %r9 CC offset 71 movq 16(%rsp), %r9 # offset
75 movq 24(%rsp), %rdx CC protection 72 movq 24(%rsp), %rdx # protection
76 movq 32(%rsp), %rsi CC length 73 movq 32(%rsp), %rsi # length
77 movq 40(%rsp), %r10 CC flags 74 movq 40(%rsp), %r10 # flags
78 movq $-1, %r8 CC -1 75 movq $-1, %r8 # -1
79 jmp .do_mmap_1 76 jmp .do_mmap_1
80.open_file: 77.open_file:
81 movq $2, %rax CC SYS_open 78 movq $2, %rax # SYS_open
82 leaq 8(%rsp), %rdi CC rdi = %rsp + 8 79 leaq 8(%rsp), %rdi # rdi = %rsp + 8
83 xorq %rsi, %rsi CC flags = O_RDONLY 80 xorq %rsi, %rsi # flags = O_RDONLY
84 xorq %rdx, %rdx CC mode = 0 81 xorq %rdx, %rdx # mode = 0
85 syscall 82 syscall
86 cmpq $-1, %rax CC open failed 83 cmpq $-1, %rax # open failed
87 jle .perror 84 jle .perror
88 movq %rdi, %rsp CC rsp = start of string 85 movq %rdi, %rsp # rsp = start of string
89 subq $1, %rsp 86 subq $1, %rsp
90 movq %rsp, %r14 CC r14 = start of string 87 movq %rsp, %r14 # r14 = start of string
91.nextc: 88.nextc:
92 addq $1, %rsp 89 addq $1, %rsp
93 movb (%rsp), %dil CC rdi = *rsp 90 movb (%rsp), %dil # rdi = *rsp
94 cmpb $47, %dil CC *rsp == '/'? 91 cmpb $47, %dil # *rsp == '/'?
95 jne .nextc1 92 jne .nextc1
96 movq %rsp, %r14 CC r14 = rsp 93 movq %rsp, %r14 # r14 = rsp
97 addq $1, %r14 CC r14 = char past separator 94 addq $1, %r14 # r14 = char past separator
98.nextc1: 95.nextc1:
99 cmpb $0, %dil CC *rsp == 0? 96 cmpb $0, %dil # *rsp == 0?
100 jne .nextc 97 jne .nextc
101 addq $8, %rsp CC adjust past rsp prior to rounding 98 addq $8, %rsp # adjust past rsp prior to rounding
102 andq $-8, %rsp CC round rsp up to the next quad 99 andq $-8, %rsp # round rsp up to the next quad
103 testq $16, %r15 CC r15 & 16? 100 testq $16, %r15 # r15 & 16?
104 jz .primary 101 jz .primary
105 movq %rax, %r12 CC otherwise, move fd to r12 102 movq %rax, %r12 # otherwise, move fd to r12
106 jmp .next_action 103 jmp .next_action
107.primary: 104.primary:
108 movq %rax, %rbx CC if not, move fd to rbx 105 movq %rax, %rbx # if not, move fd to rbx
109 movq $157, %rax CC SYS_prctl 106 movq $157, %rax # SYS_prctl
110 movq $15, %rdi CC PR_SET_NAME 107 movq $15, %rdi # PR_SET_NAME
111 movq %r14, %rsi CC arg1 108 movq %r14, %rsi # arg1
112 xorq %rdx, %rdx CC arg2 109 xorq %rdx, %rdx # arg2
113 xorq %r10, %r10 CC arg3 110 xorq %r10, %r10 # arg3
114 xorq %r8, %r8 CC arg4 111 xorq %r8, %r8 # arg4
115 xorq %r9, %r9 CC arg5 112 xorq %r9, %r9 # arg5
116 syscall 113 syscall
117 jmp .next_action 114 jmp .next_action
118.perror: 115.perror:
119 movq %rax, %r12 CC error code 116 movq %rax, %r12 # error code
120 negq %r12 117 negq %r12
121 movq $1, %rax CC SYS_write 118 movq $1, %rax # SYS_write
122 movq $1, %rdi CC stdout 119 movq $1, %rdi # stdout
123 leaq error(%rip), %rsi CC buffer 120 leaq error(%rip), %rsi # buffer
124 movq $23, %rdx CC count 121 movq $23, %rdx # count
125 syscall 122 syscall
126 movq $60, %rax CC SYS_exit 123 movq $60, %rax # SYS_exit
127 movq %r12, %rdi CC code 124 movq %r12, %rdi # code
128 syscall 125 syscall
129.rest_of_exec: CC rsp now points to six quads: 126.rest_of_exec: # rsp now points to six quads:
130 movq %rsp, %r8 CC now, they are r8 127 movq %rsp, %r8 # now, they are r8
131 movq %r13, %rsp CC restore SP 128 movq %r13, %rsp # restore SP
132 popq %r10 CC argc 129 popq %r10 # argc
133 leaq 8(%rsp,%r10,8), %rsp CC now at start of environ 130 leaq 8(%rsp,%r10,8), %rsp # now at start of environ
134.skip_environ: 131.skip_environ:
135 popq %r10 CC envp[N] 132 popq %r10 # envp[N]
136 testq %r10, %r10 CC envp[n]? 133 testq %r10, %r10 # envp[n]?
137 jnz .skip_environ CC otherwise, rsp is now at the start of auxv 134 jnz .skip_environ # otherwise, rsp is now at the start of auxv
138.one_auxv: 135.one_auxv:
139 popq %rcx CC auxv type 136 popq %rcx # auxv type
140 addq $8, %rsp CC skip value 137 addq $8, %rsp # skip value
141 testq %rcx, %rcx CC is 0? 138 testq %rcx, %rcx # is 0?
142 jz .cleanup 139 jz .cleanup
143 cmpq $3, %rcx CC is AT_PHDR? 140 cmpq $3, %rcx # is AT_PHDR?
144 je .replace_phdr 141 je .replace_phdr
145 cmpq $4, %rcx CC is AT_PHENT? 142 cmpq $4, %rcx # is AT_PHENT?
146 je .replace_phent 143 je .replace_phent
147 cmpq $5, %rcx CC is AT_PHNUM? 144 cmpq $5, %rcx # is AT_PHNUM?
148 je .replace_phnum 145 je .replace_phnum
149 cmpq $9, %rcx CC is AT_ENTRY? 146 cmpq $9, %rcx # is AT_ENTRY?
150 je .replace_entry 147 je .replace_entry
151 cmpq $7, %rcx CC is AT_BASE? 148 cmpq $7, %rcx # is AT_BASE?
152 je .replace_base 149 je .replace_base
153 jmp .one_auxv 150 jmp .one_auxv
154.replace_phdr: 151.replace_phdr:
155 movq 40(%r8), %r9 152 movq 40(%r8), %r9
156 movq %r9, -8(%rsp) CC set at_phdr 153 movq %r9, -8(%rsp) # set at_phdr
157 jmp .one_auxv 154 jmp .one_auxv
158.replace_phent: 155.replace_phent:
159 movq 24(%r8), %r9 156 movq 24(%r8), %r9
160 movq %r9, -8(%rsp) CC set at_phent 157 movq %r9, -8(%rsp) # set at_phent
161 jmp .one_auxv 158 jmp .one_auxv
162.replace_phnum: 159.replace_phnum:
163 movq 32(%r8), %r9 160 movq 32(%r8), %r9
164 movq %r9, -8(%rsp) CC set at_phnum 161 movq %r9, -8(%rsp) # set at_phnum
165 jmp .one_auxv 162 jmp .one_auxv
166.replace_entry: 163.replace_entry:
167 movq 16(%r8), %r9 164 movq 16(%r8), %r9
168 movq %r9, -8(%rsp) CC set at_entry 165 movq %r9, -8(%rsp) # set at_entry
169 jmp .one_auxv 166 jmp .one_auxv
170.replace_base: 167.replace_base:
171 movq 48(%r8), %r9 168 movq 48(%r8), %r9
172 movq %r9, -8(%rsp) CC set at_base 169 movq %r9, -8(%rsp) # set at_base
173 jmp .one_auxv 170 jmp .one_auxv
174.cleanup: 171.cleanup:
175 movq $3, %rax CC SYS_close 172 movq $3, %rax # SYS_close
176 cmpq $-1, %r12 CC see if interpreter fd is set 173 cmpq $-1, %r12 # see if interpreter fd is set
177 je .cleanup_1 174 je .cleanup_1
178 movq %r12, %rdi 175 movq %r12, %rdi
179 syscall 176 syscall
180 movq $3, %rax CC SYS_close 177 movq $3, %rax # SYS_close
181.cleanup_1: 178.cleanup_1:
182 movq %rbx, %rdi 179 movq %rbx, %rdi
183 syscall 180 syscall
184.enter: 181.enter:
185 pushq $0 182 pushq $0
186 popfq CC clear FP state 183 popfq # clear FP state
187 movq %r13, %rsp CC restore SP 184 movq %r13, %rsp # restore SP
188 xorq %rdx, %rdx CC clear rtld_fini 185 xorq %rdx, %rdx # clear rtld_fini
189 jmpq *8(%r8) CC entry 186 jmpq *8(%r8) # entry
190 187
191error: 188error:
192 .ascii "_start: internal error." 189 .ascii "_start: internal error."