mirror of
https://github.com/ipxe/ipxe
synced 2026-02-14 02:31:26 +03:00
[linux] Use host glibc system call wrappers
When building as a Linux userspace application, iPXE currently implements its own system calls to the host kernel rather than relying on the host's C library. The output binary is statically linked and has no external dependencies. This matches the general philosophy of other platforms on which iPXE runs, since there are no external libraries available on either BIOS or UEFI bare metal. However, it would be useful for the Linux userspace application to be able to link against host libraries such as libslirp. Modify the build process to perform a two-stage link: first picking out the requested objects in the usual way from blib.a but with relocations left present, then linking again with a helper object to create a standard hosted application. The helper object provides the standard main() entry point and wrappers for the Linux system calls required by the iPXE Linux drivers and interface code. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
# -*- makefile -*- : Force emacs to use Makefile mode
|
||||
|
||||
# Linker script
|
||||
#
|
||||
LDSCRIPT = arch/x86_64/scripts/linux.lds
|
||||
|
||||
SRCDIRS += arch/x86_64/core/linux
|
||||
|
||||
# Include generic Linux Makefile
|
||||
#
|
||||
MAKEDEPS += arch/x86/Makefile.linux
|
||||
include arch/x86/Makefile.linux
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
|
||||
.section ".data"
|
||||
.globl linux_errno
|
||||
|
||||
linux_errno: .int 0
|
||||
|
||||
.section ".text"
|
||||
.code64
|
||||
.globl linux_syscall
|
||||
.type linux_syscall, @function
|
||||
|
||||
linux_syscall:
|
||||
movq %rdi, %rax // C arg1 -> syscall number
|
||||
movq %rsi, %rdi // C arg2 -> syscall arg1
|
||||
movq %rdx, %rsi // C arg3 -> syscall arg2
|
||||
movq %rcx, %rdx // C arg4 -> syscall arg3
|
||||
movq %r8, %r10 // C arg5 -> syscall arg4
|
||||
movq %r9, %r8 // C arg6 -> syscall arg5
|
||||
movq 8(%rsp), %r9 // C arg7 -> syscall arg6
|
||||
|
||||
syscall
|
||||
|
||||
cmpq $-4095, %rax
|
||||
jae 1f
|
||||
ret
|
||||
|
||||
1:
|
||||
negq %rax
|
||||
movl %eax, linux_errno
|
||||
movq $-1, %rax
|
||||
ret
|
||||
|
||||
.size linux_syscall, . - linux_syscall
|
||||
@@ -1,25 +0,0 @@
|
||||
#include <linux/unistd.h>
|
||||
|
||||
.section ".text"
|
||||
.code64
|
||||
.globl _linux_start
|
||||
.type _linux_start, @function
|
||||
|
||||
_linux_start:
|
||||
xorq %rbp, %rbp
|
||||
|
||||
popq %rdi // argc -> C arg1
|
||||
movq %rsp, %rsi // argv -> C arg2
|
||||
|
||||
andq $~15, %rsp // 16-byte align the stack
|
||||
|
||||
call save_args
|
||||
|
||||
/* Our main doesn't use any arguments */
|
||||
call main
|
||||
|
||||
movq %rax, %rdi // rc -> syscall arg1
|
||||
movq $__NR_exit, %rax
|
||||
syscall
|
||||
|
||||
.size _linux_start, . - _linux_start
|
||||
@@ -1,6 +0,0 @@
|
||||
#ifndef _X86_64_LINUX_API_H
|
||||
#define _X86_64_LINUX_API_H
|
||||
|
||||
#define __SYSCALL_mmap __NR_mmap
|
||||
|
||||
#endif /* _X86_64_LINUX_API_H */
|
||||
Reference in New Issue
Block a user