aboutsummaryrefslogtreecommitdiffstats
path: root/exec/loader-x86.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.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.s')
-rw-r--r--exec/loader-x86.s187
1 files changed, 92 insertions, 95 deletions
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