mirror of
https://github.com/ipxe/ipxe
synced 2026-01-13 17:43:49 +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,14 @@
|
||||
# -*- makefile -*- : Force emacs to use Makefile mode
|
||||
|
||||
# Linker script
|
||||
#
|
||||
LDSCRIPT = arch/i386/scripts/linux.lds
|
||||
|
||||
SRCDIRS += arch/i386/core/linux
|
||||
# Compiler flags for building host API wrapper
|
||||
#
|
||||
LINUX_CFLAGS += -m32
|
||||
|
||||
# Include generic Linux Makefile
|
||||
#
|
||||
MAKEDEPS += arch/x86/Makefile.linux
|
||||
include arch/x86/Makefile.linux
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
|
||||
.section ".data"
|
||||
.globl linux_errno
|
||||
|
||||
linux_errno: .int 0
|
||||
|
||||
.section ".text"
|
||||
.code32
|
||||
.globl linux_syscall
|
||||
.type linux_syscall, @function
|
||||
|
||||
linux_syscall:
|
||||
/* Save registers */
|
||||
pushl %ebx
|
||||
pushl %esi
|
||||
pushl %edi
|
||||
pushl %ebp
|
||||
|
||||
movl 20(%esp), %eax // C arg1 -> syscall number
|
||||
movl 24(%esp), %ebx // C arg2 -> syscall arg1
|
||||
movl 28(%esp), %ecx // C arg3 -> syscall arg2
|
||||
movl 32(%esp), %edx // C arg4 -> syscall arg3
|
||||
movl 36(%esp), %esi // C arg5 -> syscall arg4
|
||||
movl 40(%esp), %edi // C arg6 -> syscall arg5
|
||||
movl 44(%esp), %ebp // C arg7 -> syscall arg6
|
||||
|
||||
int $0x80
|
||||
|
||||
/* Restore registers */
|
||||
popl %ebp
|
||||
popl %edi
|
||||
popl %esi
|
||||
popl %ebx
|
||||
|
||||
cmpl $-4095, %eax
|
||||
jae 1f
|
||||
ret
|
||||
|
||||
1:
|
||||
negl %eax
|
||||
movl %eax, linux_errno
|
||||
movl $-1, %eax
|
||||
ret
|
||||
|
||||
.size linux_syscall, . - linux_syscall
|
||||
@@ -1,28 +0,0 @@
|
||||
#include <linux/unistd.h>
|
||||
|
||||
.section ".text"
|
||||
.code32
|
||||
.globl _linux_start
|
||||
.type _linux_start, @function
|
||||
|
||||
_linux_start:
|
||||
xorl %ebp, %ebp
|
||||
|
||||
popl %esi // save argc
|
||||
movl %esp, %edi // save argv
|
||||
|
||||
andl $~15, %esp // 16-byte align the stack
|
||||
|
||||
pushl %edi // argv -> C arg2
|
||||
pushl %esi // argc -> C arg1
|
||||
|
||||
call save_args
|
||||
|
||||
/* Our main doesn't use any arguments */
|
||||
call main
|
||||
|
||||
movl %eax, %ebx // rc -> syscall arg1
|
||||
movl $__NR_exit, %eax
|
||||
int $0x80
|
||||
|
||||
.size _linux_start, . - _linux_start
|
||||
@@ -1,6 +0,0 @@
|
||||
#ifndef _I386_LINUX_API_H
|
||||
#define _I386_LINUX_API_H
|
||||
|
||||
#define __SYSCALL_mmap __NR_mmap2
|
||||
|
||||
#endif /* _I386_LINUX_API_H */
|
||||
Reference in New Issue
Block a user