aboutsummaryrefslogtreecommitdiffstats
path: root/exec/loader-x86_64.s
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/loader-x86_64.s
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/loader-x86_64.s')
-rw-r--r--exec/loader-x86_64.s215
1 files changed, 106 insertions, 109 deletions
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."