mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-11-21 06:55:39 +00:00
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.
This commit is contained in:
parent
da11a2a5cc
commit
fa322155ad
@ -44,6 +44,9 @@ FIND_DELETE = @FIND_DELETE@
|
||||
OBJS = @OBJS@
|
||||
LOADOBJS = $(patsubst %.s,%.o,$(LOADER))
|
||||
|
||||
# Compilation parameters.
|
||||
is_mips = @is_mips@
|
||||
|
||||
# Set up automatic dependency tracking.
|
||||
|
||||
AUTO_DEPEND = @AUTO_DEPEND@
|
||||
@ -82,9 +85,15 @@ Makefile: config.status Makefile.in
|
||||
.SUFFIXES: .c .s
|
||||
.c.o:
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEPFLAGS) -I. -I$(srcdir) $< -o $@
|
||||
|
||||
ifeq ($(is_mips),yes)
|
||||
.s.o:
|
||||
$(M4) $< > $(notdir $<).s
|
||||
$(AS) $(ASFLAGS) $(notdir $<).s -o $@
|
||||
else
|
||||
.s.o:
|
||||
$(AS) $(ASFLAGS) $< -o $@
|
||||
endif
|
||||
|
||||
# Set up dependencies for config-mips.m4.
|
||||
|
||||
|
@ -547,7 +547,9 @@ FIND_DELETE=$exec_cv_find_delete
|
||||
AC_SUBST([FIND_DELETE])
|
||||
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
AC_CONFIG_FILES([Makefile config-mips.m4])
|
||||
AC_CONFIG_FILES([Makefile])
|
||||
AS_IF([test "x$is_mips" = xyes],
|
||||
[AC_CONFIG_FILES ([config-mips.m4])])
|
||||
|
||||
AC_SUBST([AUTO_DEPEND])
|
||||
AC_SUBST([LOADERFLAGS])
|
||||
@ -556,5 +558,6 @@ AC_SUBST([ASFLAGS])
|
||||
AC_SUBST([exec_loader])
|
||||
AC_SUBST([MIPS_N32])
|
||||
AC_SUBST([OBJS])
|
||||
AC_SUBST([is_mips])
|
||||
|
||||
AC_OUTPUT
|
||||
|
@ -1,71 +1,68 @@
|
||||
define(`CC', `
|
||||
dnl')
|
||||
|
||||
CC Copyright (C) 2023-2024 Free Software Foundation, Inc.
|
||||
CC
|
||||
CC This file is part of GNU Emacs.
|
||||
CC
|
||||
CC GNU Emacs is free software: you can redistribute it and/or modify
|
||||
CC it under the terms of the GNU General Public License as published
|
||||
CC by the Free Software Foundation, either version 3 of the License,
|
||||
CC or (at your option) any later version.
|
||||
CC
|
||||
CC GNU Emacs is distributed in the hope that it will be useful, but
|
||||
CC WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
CC MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
CC General Public License for more details.
|
||||
CC
|
||||
CC You should have received a copy of the GNU General Public License
|
||||
CC along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
||||
# Copyright (C) 2023-2024 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is part of GNU Emacs.
|
||||
#
|
||||
# GNU Emacs is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License,
|
||||
# or (at your option) any later version.
|
||||
#
|
||||
# GNU Emacs is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
.section .text
|
||||
.global _start
|
||||
_start:
|
||||
dnl movl $162, %eax CC SYS_nanosleep
|
||||
dnl leal timespec, %ebx
|
||||
dnl xorl %ecx, %ecx
|
||||
dnl int $0x80
|
||||
leal 8(%esp), %ebp CC ebp = start of load area
|
||||
subl $8, %esp CC (%esp) = primary fd, 4(%esp) = secondary fd
|
||||
# movl $162, %eax # SYS_nanosleep
|
||||
# leal timespec, %ebx
|
||||
# xorl %ecx, %ecx
|
||||
# int $0x80
|
||||
leal 8(%esp), %ebp # ebp = start of load area
|
||||
subl $8, %esp # (%esp) = primary fd, 4(%esp) = secondary fd
|
||||
movl $-1, 4(%esp)
|
||||
.next_action:
|
||||
movl (%ebp), %edx CC edx = action number
|
||||
movl (%ebp), %edx # edx = action number
|
||||
andl $-17, %edx
|
||||
cmpl $0, %edx CC open file?
|
||||
cmpl $0, %edx # open file?
|
||||
je .open_file
|
||||
cmpl $3, %edx CC jump?
|
||||
cmpl $3, %edx # jump?
|
||||
je .rest_of_exec
|
||||
cmpl $4, %edx CC anonymous mmap?
|
||||
cmpl $4, %edx # anonymous mmap?
|
||||
je .do_mmap_anon
|
||||
.do_mmap:
|
||||
subl $24, %esp
|
||||
movl $90, %eax CC SYS_old_mmap
|
||||
movl $90, %eax # SYS_old_mmap
|
||||
movl %esp, %ebx
|
||||
movl 4(%ebp), %ecx CC address
|
||||
movl 4(%ebp), %ecx # address
|
||||
movl %ecx, (%esp)
|
||||
movl 16(%ebp), %ecx CC length
|
||||
movl 16(%ebp), %ecx # length
|
||||
movl %ecx, 4(%esp)
|
||||
movl 12(%ebp), %ecx CC protection
|
||||
movl 12(%ebp), %ecx # protection
|
||||
movl %ecx, 8(%esp)
|
||||
movl 20(%ebp), %ecx CC flags
|
||||
movl 20(%ebp), %ecx # flags
|
||||
movl %ecx, 12(%esp)
|
||||
testl $16, (%ebp) CC primary?
|
||||
testl $16, (%ebp) # primary?
|
||||
movl 28(%esp), %ecx
|
||||
cmovzl 24(%esp), %ecx
|
||||
movl %ecx, 16(%esp) CC fd
|
||||
movl 8(%ebp), %ecx CC offset
|
||||
movl %ecx, 16(%esp) # fd
|
||||
movl 8(%ebp), %ecx # offset
|
||||
movl %ecx, 20(%esp)
|
||||
.do_mmap_1:
|
||||
int $0x80
|
||||
addl $24, %esp CC restore esp
|
||||
cmpl $-1, %eax CC mmap failed?
|
||||
addl $24, %esp # restore esp
|
||||
cmpl $-1, %eax # mmap failed?
|
||||
je .perror
|
||||
movl 24(%ebp), %ecx CC clear
|
||||
movl 24(%ebp), %ecx # clear
|
||||
testl %ecx, %ecx
|
||||
jz .continue
|
||||
movl 4(%ebp), %esi CC start of mapping
|
||||
addl 16(%ebp), %esi CC end of mapping
|
||||
subl %ecx, %esi CC start of clear area
|
||||
movl 4(%ebp), %esi # start of mapping
|
||||
addl 16(%ebp), %esi # end of mapping
|
||||
subl %ecx, %esi # start of clear area
|
||||
.again:
|
||||
testl %ecx, %ecx
|
||||
jz .continue
|
||||
@ -77,58 +74,58 @@ dnl int $0x80
|
||||
jmp .next_action
|
||||
.do_mmap_anon:
|
||||
subl $24, %esp
|
||||
movl $90, %eax CC SYS_old_mmap
|
||||
movl $90, %eax # SYS_old_mmap
|
||||
movl %esp, %ebx
|
||||
movl 4(%ebp), %ecx CC address
|
||||
movl 4(%ebp), %ecx # address
|
||||
movl %ecx, (%esp)
|
||||
movl 16(%ebp), %ecx CC length
|
||||
movl 16(%ebp), %ecx # length
|
||||
movl %ecx, 4(%esp)
|
||||
movl 12(%ebp), %ecx CC protection
|
||||
movl 12(%ebp), %ecx # protection
|
||||
movl %ecx, 8(%esp)
|
||||
movl 20(%ebp), %ecx CC flags
|
||||
movl 20(%ebp), %ecx # flags
|
||||
movl %ecx, 12(%esp)
|
||||
movl $-1, 16(%esp) CC fd
|
||||
movl 8(%ebp), %ecx CC offset
|
||||
movl $-1, 16(%esp) # fd
|
||||
movl 8(%ebp), %ecx # offset
|
||||
movl %ecx, 20(%esp)
|
||||
jmp .do_mmap_1
|
||||
.open_file:
|
||||
movl $5, %eax CC SYS_open
|
||||
leal 4(%ebp), %ebx CC ebx = %esp + 8
|
||||
movl $5, %eax # SYS_open
|
||||
leal 4(%ebp), %ebx # ebx = %esp + 8
|
||||
pushl %ebx
|
||||
xorl %ecx, %ecx CC flags = O_RDONLY
|
||||
xorl %edx, %edx CC mode = 0
|
||||
xorl %ecx, %ecx # flags = O_RDONLY
|
||||
xorl %edx, %edx # mode = 0
|
||||
int $0x80
|
||||
cmpl $-1, %eax CC open failed?
|
||||
cmpl $-1, %eax # open failed?
|
||||
jle .perror
|
||||
movl %ebp, %esi CC (esi) = original action number
|
||||
popl %ebp CC ebp = start of string
|
||||
movl %ebp, %ecx CC char past separator
|
||||
movl %ebp, %esi # (esi) = original action number
|
||||
popl %ebp # ebp = start of string
|
||||
movl %ebp, %ecx # char past separator
|
||||
decl %ebp
|
||||
.nextc:
|
||||
incl %ebp
|
||||
movb (%ebp), %dl CC dl = *ebp
|
||||
cmpb $47, %dl CC dl == '\?'?
|
||||
movb (%ebp), %dl # dl = *ebp
|
||||
cmpb $47, %dl # dl == '\?'?
|
||||
jne .nextc1
|
||||
leal 1(%ebp), %ecx CC ecx = char past separator
|
||||
leal 1(%ebp), %ecx # ecx = char past separator
|
||||
.nextc1:
|
||||
cmpb $0, %dl CC dl == 0?
|
||||
cmpb $0, %dl # dl == 0?
|
||||
jne .nextc
|
||||
addl $4, %ebp CC adjust past ebp prior to rounding
|
||||
andl $-4, %ebp CC round ebp up to the next long
|
||||
testl $16, (%esi) CC original action number & 16?
|
||||
addl $4, %ebp # adjust past ebp prior to rounding
|
||||
andl $-4, %ebp # round ebp up to the next long
|
||||
testl $16, (%esi) # original action number & 16?
|
||||
jz .primary
|
||||
movl %eax, 4(%esp) CC secondary fd = eax
|
||||
movl %eax, 4(%esp) # secondary fd = eax
|
||||
jmp .next_action
|
||||
.primary:
|
||||
pushl %ebp
|
||||
xorl %esi, %esi CC arg3
|
||||
movl %eax, 4(%esp) CC primary fd = eax
|
||||
xorl %edx, %edx CC arg2
|
||||
movl $15, %ebx CC PR_SET_NAME, arg1 = ecx
|
||||
xorl %edi, %edi CC arg4
|
||||
movl $172, %eax CC SYS_prctl
|
||||
xorl %ebp, %ebp CC arg5
|
||||
int $0x80 CC syscall
|
||||
xorl %esi, %esi # arg3
|
||||
movl %eax, 4(%esp) # primary fd = eax
|
||||
xorl %edx, %edx # arg2
|
||||
movl $15, %ebx # PR_SET_NAME, arg1 = ecx
|
||||
xorl %edi, %edi # arg4
|
||||
movl $172, %eax # SYS_prctl
|
||||
xorl %ebp, %ebp # arg5
|
||||
int $0x80 # syscall
|
||||
popl %ebp
|
||||
jmp .next_action
|
||||
.perror:
|
||||
@ -137,28 +134,28 @@ dnl int $0x80
|
||||
movl $1, %eax
|
||||
int $0x80
|
||||
.rest_of_exec:
|
||||
movl 8(%esp), %ecx CC ecx = original stack pointer
|
||||
movl (%ecx), %esi CC esi = argc
|
||||
leal 8(%ecx, %esi, 4), %ecx CC ecx = start of environ
|
||||
movl 8(%esp), %ecx # ecx = original stack pointer
|
||||
movl (%ecx), %esi # esi = argc
|
||||
leal 8(%ecx, %esi, 4), %ecx # ecx = start of environ
|
||||
.skip_environ:
|
||||
movl (%ecx), %esi CC envp[N]
|
||||
movl (%ecx), %esi # envp[N]
|
||||
addl $4, %ecx
|
||||
testl %esi, %esi CC envp[n] ?
|
||||
jnz .skip_environ CC otherwise, esi is now at the start of auxv
|
||||
testl %esi, %esi # envp[n] ?
|
||||
jnz .skip_environ # otherwise, esi is now at the start of auxv
|
||||
.one_auxv:
|
||||
movl (%ecx), %esi CC auxv type
|
||||
leal 8(%ecx), %ecx CC skip to next auxv
|
||||
testl %esi, %esi CC is 0?
|
||||
movl (%ecx), %esi # auxv type
|
||||
leal 8(%ecx), %ecx # skip to next auxv
|
||||
testl %esi, %esi # is 0?
|
||||
jz .cleanup
|
||||
cmpl $3, %esi CC is AT_PHDR
|
||||
cmpl $3, %esi # is AT_PHDR
|
||||
je .replace_phdr
|
||||
cmpl $4, %esi CC is AT_PHENT?
|
||||
cmpl $4, %esi # is AT_PHENT?
|
||||
je .replace_phent
|
||||
cmpl $5, %esi CC is AT_PHNUM?
|
||||
cmpl $5, %esi # is AT_PHNUM?
|
||||
je .replace_phnum
|
||||
cmpl $9, %esi CC is AT_ENTRY?
|
||||
cmpl $9, %esi # is AT_ENTRY?
|
||||
je .replace_entry
|
||||
cmpl $7, %esi CC is AT_BASE
|
||||
cmpl $7, %esi # is AT_BASE
|
||||
je .replace_base
|
||||
jmp .one_auxv
|
||||
.replace_phdr:
|
||||
@ -182,21 +179,21 @@ dnl int $0x80
|
||||
movl %esi, -4(%ecx)
|
||||
jmp .one_auxv
|
||||
.cleanup:
|
||||
movl $6, %eax CC SYS_close
|
||||
cmpl $-1, 4(%esp) CC see if interpreter fd is set
|
||||
movl $6, %eax # SYS_close
|
||||
cmpl $-1, 4(%esp) # see if interpreter fd is set
|
||||
je .cleanup_1
|
||||
movl 4(%esp), %ebx
|
||||
int $0x80
|
||||
movl $6, %eax CC SYS_close
|
||||
movl $6, %eax # SYS_close
|
||||
.cleanup_1:
|
||||
movl (%esp), %ebx
|
||||
int $0x80
|
||||
.enter:
|
||||
pushl $0
|
||||
popfl CC restore floating point state
|
||||
movl 8(%esp), %esp CC restore initial stack pointer
|
||||
xorl %edx, %edx CC clear rtld_fini
|
||||
jmpl *4(%ebp) CC entry
|
||||
popfl # restore floating point state
|
||||
movl 8(%esp), %esp # restore initial stack pointer
|
||||
xorl %edx, %edx # clear rtld_fini
|
||||
jmpl *4(%ebp) # entry
|
||||
|
||||
timespec:
|
||||
.long 10
|
||||
|
@ -1,64 +1,61 @@
|
||||
define(`CC', `
|
||||
dnl')
|
||||
|
||||
CC Copyright (C) 2023-2024 Free Software Foundation, Inc.
|
||||
CC
|
||||
CC This file is part of GNU Emacs.
|
||||
CC
|
||||
CC GNU Emacs is free software: you can redistribute it and/or modify
|
||||
CC it under the terms of the GNU General Public License as published
|
||||
CC by the Free Software Foundation, either version 3 of the License,
|
||||
CC or (at your option) any later version.
|
||||
CC
|
||||
CC GNU Emacs is distributed in the hope that it will be useful, but
|
||||
CC WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
CC MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
CC General Public License for more details.
|
||||
CC
|
||||
CC You should have received a copy of the GNU General Public License
|
||||
CC along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
||||
# Copyright (C) 2023-2024 Free Software Foundation, Inc.
|
||||
#
|
||||
# This file is part of GNU Emacs.
|
||||
#
|
||||
# GNU Emacs is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License,
|
||||
# or (at your option) any later version.
|
||||
#
|
||||
# GNU Emacs is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
.section .text
|
||||
.global _start
|
||||
_start:
|
||||
dnl movq $35, %rax CC SYS_nanosleep
|
||||
dnl leaq timespec(%rip), %rdi
|
||||
dnl xorq %rsi, %rsi
|
||||
dnl syscall
|
||||
popq %r13 CC original SP
|
||||
popq %r15 CC size of load area.
|
||||
movq $-1, %r12 CC r12 is the interpreter fd
|
||||
# movq $35, %rax # SYS_nanosleep
|
||||
# leaq timespec(%rip), %rdi
|
||||
# xorq %rsi, %rsi
|
||||
# syscall
|
||||
popq %r13 # original SP
|
||||
popq %r15 # size of load area.
|
||||
movq $-1, %r12 # r12 is the interpreter fd
|
||||
.next_action:
|
||||
movq (%rsp), %r14 CC action number
|
||||
movq %r14, %r15 CC original action number
|
||||
movq (%rsp), %r14 # action number
|
||||
movq %r14, %r15 # original action number
|
||||
andq $-17, %r14
|
||||
cmpq $0, %r14 CC open file?
|
||||
cmpq $0, %r14 # open file?
|
||||
je .open_file
|
||||
cmpq $3, %r14 CC jump?
|
||||
cmpq $3, %r14 # jump?
|
||||
je .rest_of_exec
|
||||
cmpq $4, %r14 CC anonymous mmap?
|
||||
cmpq $4, %r14 # anonymous mmap?
|
||||
je .do_mmap_anon
|
||||
.do_mmap:
|
||||
movq $9, %rax CC SYS_mmap
|
||||
movq 8(%rsp), %rdi CC address
|
||||
movq 16(%rsp), %r9 CC offset
|
||||
movq 24(%rsp), %rdx CC protection
|
||||
movq 32(%rsp), %rsi CC length
|
||||
movq 40(%rsp), %r10 CC flags
|
||||
CC set r8 to the primary fd unless r15 & 16
|
||||
movq $9, %rax # SYS_mmap
|
||||
movq 8(%rsp), %rdi # address
|
||||
movq 16(%rsp), %r9 # offset
|
||||
movq 24(%rsp), %rdx # protection
|
||||
movq 32(%rsp), %rsi # length
|
||||
movq 40(%rsp), %r10 # flags
|
||||
# set r8 to the primary fd unless r15 & 16
|
||||
testq $16, %r15
|
||||
movq %r12, %r8
|
||||
cmovzq %rbx, %r8
|
||||
.do_mmap_1:
|
||||
syscall
|
||||
cmpq $-1, %rax CC mmap failed
|
||||
cmpq $-1, %rax # mmap failed
|
||||
je .perror
|
||||
movq 48(%rsp), %r9 CC clear
|
||||
movq 48(%rsp), %r9 # clear
|
||||
testq %r9, %r9
|
||||
jz .continue
|
||||
movq 8(%rsp), %r10 CC start of mapping
|
||||
addq 32(%rsp), %r10 CC end of mapping
|
||||
subq %r9, %r10 CC start of clear area
|
||||
movq 8(%rsp), %r10 # start of mapping
|
||||
addq 32(%rsp), %r10 # end of mapping
|
||||
subq %r9, %r10 # start of clear area
|
||||
.again:
|
||||
testq %r9, %r9
|
||||
jz .continue
|
||||
@ -69,124 +66,124 @@ dnl syscall
|
||||
leaq 56(%rsp), %rsp
|
||||
jmp .next_action
|
||||
.do_mmap_anon:
|
||||
movq $9, %rax CC SYS_mmap
|
||||
movq 8(%rsp), %rdi CC address
|
||||
movq 16(%rsp), %r9 CC offset
|
||||
movq 24(%rsp), %rdx CC protection
|
||||
movq 32(%rsp), %rsi CC length
|
||||
movq 40(%rsp), %r10 CC flags
|
||||
movq $-1, %r8 CC -1
|
||||
movq $9, %rax # SYS_mmap
|
||||
movq 8(%rsp), %rdi # address
|
||||
movq 16(%rsp), %r9 # offset
|
||||
movq 24(%rsp), %rdx # protection
|
||||
movq 32(%rsp), %rsi # length
|
||||
movq 40(%rsp), %r10 # flags
|
||||
movq $-1, %r8 # -1
|
||||
jmp .do_mmap_1
|
||||
.open_file:
|
||||
movq $2, %rax CC SYS_open
|
||||
leaq 8(%rsp), %rdi CC rdi = %rsp + 8
|
||||
xorq %rsi, %rsi CC flags = O_RDONLY
|
||||
xorq %rdx, %rdx CC mode = 0
|
||||
movq $2, %rax # SYS_open
|
||||
leaq 8(%rsp), %rdi # rdi = %rsp + 8
|
||||
xorq %rsi, %rsi # flags = O_RDONLY
|
||||
xorq %rdx, %rdx # mode = 0
|
||||
syscall
|
||||
cmpq $-1, %rax CC open failed
|
||||
cmpq $-1, %rax # open failed
|
||||
jle .perror
|
||||
movq %rdi, %rsp CC rsp = start of string
|
||||
movq %rdi, %rsp # rsp = start of string
|
||||
subq $1, %rsp
|
||||
movq %rsp, %r14 CC r14 = start of string
|
||||
movq %rsp, %r14 # r14 = start of string
|
||||
.nextc:
|
||||
addq $1, %rsp
|
||||
movb (%rsp), %dil CC rdi = *rsp
|
||||
cmpb $47, %dil CC *rsp == '/'?
|
||||
movb (%rsp), %dil # rdi = *rsp
|
||||
cmpb $47, %dil # *rsp == '/'?
|
||||
jne .nextc1
|
||||
movq %rsp, %r14 CC r14 = rsp
|
||||
addq $1, %r14 CC r14 = char past separator
|
||||
movq %rsp, %r14 # r14 = rsp
|
||||
addq $1, %r14 # r14 = char past separator
|
||||
.nextc1:
|
||||
cmpb $0, %dil CC *rsp == 0?
|
||||
cmpb $0, %dil # *rsp == 0?
|
||||
jne .nextc
|
||||
addq $8, %rsp CC adjust past rsp prior to rounding
|
||||
andq $-8, %rsp CC round rsp up to the next quad
|
||||
testq $16, %r15 CC r15 & 16?
|
||||
addq $8, %rsp # adjust past rsp prior to rounding
|
||||
andq $-8, %rsp # round rsp up to the next quad
|
||||
testq $16, %r15 # r15 & 16?
|
||||
jz .primary
|
||||
movq %rax, %r12 CC otherwise, move fd to r12
|
||||
movq %rax, %r12 # otherwise, move fd to r12
|
||||
jmp .next_action
|
||||
.primary:
|
||||
movq %rax, %rbx CC if not, move fd to rbx
|
||||
movq $157, %rax CC SYS_prctl
|
||||
movq $15, %rdi CC PR_SET_NAME
|
||||
movq %r14, %rsi CC arg1
|
||||
xorq %rdx, %rdx CC arg2
|
||||
xorq %r10, %r10 CC arg3
|
||||
xorq %r8, %r8 CC arg4
|
||||
xorq %r9, %r9 CC arg5
|
||||
movq %rax, %rbx # if not, move fd to rbx
|
||||
movq $157, %rax # SYS_prctl
|
||||
movq $15, %rdi # PR_SET_NAME
|
||||
movq %r14, %rsi # arg1
|
||||
xorq %rdx, %rdx # arg2
|
||||
xorq %r10, %r10 # arg3
|
||||
xorq %r8, %r8 # arg4
|
||||
xorq %r9, %r9 # arg5
|
||||
syscall
|
||||
jmp .next_action
|
||||
.perror:
|
||||
movq %rax, %r12 CC error code
|
||||
movq %rax, %r12 # error code
|
||||
negq %r12
|
||||
movq $1, %rax CC SYS_write
|
||||
movq $1, %rdi CC stdout
|
||||
leaq error(%rip), %rsi CC buffer
|
||||
movq $23, %rdx CC count
|
||||
movq $1, %rax # SYS_write
|
||||
movq $1, %rdi # stdout
|
||||
leaq error(%rip), %rsi # buffer
|
||||
movq $23, %rdx # count
|
||||
syscall
|
||||
movq $60, %rax CC SYS_exit
|
||||
movq %r12, %rdi CC code
|
||||
movq $60, %rax # SYS_exit
|
||||
movq %r12, %rdi # code
|
||||
syscall
|
||||
.rest_of_exec: CC rsp now points to six quads:
|
||||
movq %rsp, %r8 CC now, they are r8
|
||||
movq %r13, %rsp CC restore SP
|
||||
popq %r10 CC argc
|
||||
leaq 8(%rsp,%r10,8), %rsp CC now at start of environ
|
||||
.rest_of_exec: # rsp now points to six quads:
|
||||
movq %rsp, %r8 # now, they are r8
|
||||
movq %r13, %rsp # restore SP
|
||||
popq %r10 # argc
|
||||
leaq 8(%rsp,%r10,8), %rsp # now at start of environ
|
||||
.skip_environ:
|
||||
popq %r10 CC envp[N]
|
||||
testq %r10, %r10 CC envp[n]?
|
||||
jnz .skip_environ CC otherwise, rsp is now at the start of auxv
|
||||
popq %r10 # envp[N]
|
||||
testq %r10, %r10 # envp[n]?
|
||||
jnz .skip_environ # otherwise, rsp is now at the start of auxv
|
||||
.one_auxv:
|
||||
popq %rcx CC auxv type
|
||||
addq $8, %rsp CC skip value
|
||||
testq %rcx, %rcx CC is 0?
|
||||
popq %rcx # auxv type
|
||||
addq $8, %rsp # skip value
|
||||
testq %rcx, %rcx # is 0?
|
||||
jz .cleanup
|
||||
cmpq $3, %rcx CC is AT_PHDR?
|
||||
cmpq $3, %rcx # is AT_PHDR?
|
||||
je .replace_phdr
|
||||
cmpq $4, %rcx CC is AT_PHENT?
|
||||
cmpq $4, %rcx # is AT_PHENT?
|
||||
je .replace_phent
|
||||
cmpq $5, %rcx CC is AT_PHNUM?
|
||||
cmpq $5, %rcx # is AT_PHNUM?
|
||||
je .replace_phnum
|
||||
cmpq $9, %rcx CC is AT_ENTRY?
|
||||
cmpq $9, %rcx # is AT_ENTRY?
|
||||
je .replace_entry
|
||||
cmpq $7, %rcx CC is AT_BASE?
|
||||
cmpq $7, %rcx # is AT_BASE?
|
||||
je .replace_base
|
||||
jmp .one_auxv
|
||||
.replace_phdr:
|
||||
movq 40(%r8), %r9
|
||||
movq %r9, -8(%rsp) CC set at_phdr
|
||||
movq %r9, -8(%rsp) # set at_phdr
|
||||
jmp .one_auxv
|
||||
.replace_phent:
|
||||
movq 24(%r8), %r9
|
||||
movq %r9, -8(%rsp) CC set at_phent
|
||||
movq %r9, -8(%rsp) # set at_phent
|
||||
jmp .one_auxv
|
||||
.replace_phnum:
|
||||
movq 32(%r8), %r9
|
||||
movq %r9, -8(%rsp) CC set at_phnum
|
||||
movq %r9, -8(%rsp) # set at_phnum
|
||||
jmp .one_auxv
|
||||
.replace_entry:
|
||||
movq 16(%r8), %r9
|
||||
movq %r9, -8(%rsp) CC set at_entry
|
||||
movq %r9, -8(%rsp) # set at_entry
|
||||
jmp .one_auxv
|
||||
.replace_base:
|
||||
movq 48(%r8), %r9
|
||||
movq %r9, -8(%rsp) CC set at_base
|
||||
movq %r9, -8(%rsp) # set at_base
|
||||
jmp .one_auxv
|
||||
.cleanup:
|
||||
movq $3, %rax CC SYS_close
|
||||
cmpq $-1, %r12 CC see if interpreter fd is set
|
||||
movq $3, %rax # SYS_close
|
||||
cmpq $-1, %r12 # see if interpreter fd is set
|
||||
je .cleanup_1
|
||||
movq %r12, %rdi
|
||||
syscall
|
||||
movq $3, %rax CC SYS_close
|
||||
movq $3, %rax # SYS_close
|
||||
.cleanup_1:
|
||||
movq %rbx, %rdi
|
||||
syscall
|
||||
.enter:
|
||||
pushq $0
|
||||
popfq CC clear FP state
|
||||
movq %r13, %rsp CC restore SP
|
||||
xorq %rdx, %rdx CC clear rtld_fini
|
||||
jmpq *8(%r8) CC entry
|
||||
popfq # clear FP state
|
||||
movq %r13, %rsp # restore SP
|
||||
xorq %rdx, %rdx # clear rtld_fini
|
||||
jmpq *8(%r8) # entry
|
||||
|
||||
error:
|
||||
.ascii "_start: internal error."
|
||||
|
Loading…
Reference in New Issue
Block a user