mirror of
https://gitlab.com/bztsrc/posix-uefi.git
synced 2024-12-28 06:55:08 +01:00
ANSI C compatibility and support for AArch64
This commit is contained in:
parent
6ce6aa74a9
commit
a8ad890000
6 changed files with 29 additions and 15 deletions
|
@ -83,8 +83,8 @@ USE_LLVM = 1
|
|||
include uefi/Makefile
|
||||
```
|
||||
The build environment configurator was created in a way that it can handle any number of architectures, however
|
||||
there's only `x86_64` crt0 implemented for now. There's an experimental `aarch64` crt0, which only compiles with
|
||||
the LLVM toolchain, GNU ld has some issues with it, saying "unsupported relocation" for ImageBase.
|
||||
only `x86_64` crt0 has been throughfully tested for now. There's an `aarch64` crt0 too, but since I don't have
|
||||
an ARM UEFI board, it hasn't been tested on real machine. Should work though.
|
||||
|
||||
Notable Differences to POSIX libc
|
||||
---------------------------------
|
||||
|
|
|
@ -5,7 +5,7 @@ TARGET = helloworld.efi
|
|||
#define your sources here
|
||||
SRCS = $(wildcard *.c)
|
||||
# define your default compiler flags
|
||||
CFLAGS = -pedantic -Wall -Wextra -Werror --std=c11 -O2
|
||||
CFLAGS = -pedantic -Wall -Wextra -Werror --ansi -O2
|
||||
# define your default linker flags
|
||||
#LDFLAGS =
|
||||
# define your additional libraries here
|
||||
|
|
|
@ -34,14 +34,20 @@ LIBS += -o $(TARGET).so -luefi -T uefi/elf_$(ARCH)_efi.lds
|
|||
ifneq ($(ARCH),$(MYARCH))
|
||||
CC = $(ARCH)-elf-gcc
|
||||
LD = $(ARCH)-elf-ld
|
||||
OBJCOPY ?= $(ARCH)-elf-objcopy
|
||||
else
|
||||
CC = gcc
|
||||
LD = ld
|
||||
endif
|
||||
OBJCOPY ?= objcopy
|
||||
endif
|
||||
ifeq ($(ARCH),aarch64)
|
||||
EFIARCH = pei-aarch64-little
|
||||
else
|
||||
EFIARCH = efi-app-$(ARCH)
|
||||
endif
|
||||
AR ?= ar
|
||||
else
|
||||
CFLAGS += --target=$(ARCH)-pc-win32-coff -Wno-builtin-requires-header -Wno-incompatible-library-redeclaration
|
||||
CFLAGS += --target=$(ARCH)-pc-win32-coff -Wno-builtin-requires-header -Wno-incompatible-library-redeclaration -Wno-long-long
|
||||
LDFLAGS += -subsystem:efi_application -nodefaultlib -dll -entry:uefi_init uefi/*.o
|
||||
LIBS = -out:$(TARGET)
|
||||
CC = clang
|
||||
|
@ -73,7 +79,7 @@ endif
|
|||
|
||||
$(TARGET): $(TARGET).so
|
||||
ifeq ($(USE_LLVM),)
|
||||
@$(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .reloc --target efi-app-$(ARCH) --subsystem=10 $^ $@
|
||||
@$(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .reloc --target $(EFIARCH) --subsystem=10 $^ $@ || echo target: $(EFIARCH)
|
||||
@rm $(TARGET).so
|
||||
endif
|
||||
|
||||
|
|
|
@ -74,8 +74,7 @@ void bootstrap()
|
|||
#ifndef __clang__
|
||||
" .globl _start\n"
|
||||
"_start:\n"
|
||||
" adr x2, ImageBase\n"
|
||||
/* " mov x2, xzr\n" */
|
||||
" ldr x2, =ImageBase\n"
|
||||
" adrp x3, _DYNAMIC\n"
|
||||
" add x3, x3, #:lo12:_DYNAMIC\n"
|
||||
" bl uefi_init\n"
|
||||
|
@ -95,8 +94,10 @@ void bootstrap()
|
|||
"__chkstk:\n"
|
||||
" ret\n"
|
||||
#endif
|
||||
);
|
||||
|
||||
/* setjmp and longjmp */
|
||||
__asm__ __volatile__ (
|
||||
" .p2align 3\n"
|
||||
" .globl setjmp\n"
|
||||
"setjmp:\n"
|
||||
|
@ -114,7 +115,8 @@ void bootstrap()
|
|||
" stp d14, d15, [x0, #160]\n"
|
||||
" mov w0, #0\n"
|
||||
" ret\n"
|
||||
|
||||
);
|
||||
__asm__ __volatile__ (
|
||||
" .globl longjmp\n"
|
||||
"longjmp:\n"
|
||||
" ldp x19, x20, [x0, #0]\n"
|
||||
|
|
|
@ -93,8 +93,10 @@ void bootstrap()
|
|||
"__chkstk:\n"
|
||||
" ret\n"
|
||||
#endif
|
||||
);
|
||||
|
||||
/* setjmp and longjmp */
|
||||
__asm__ __volatile__ (
|
||||
" .globl setjmp\n"
|
||||
"setjmp:\n"
|
||||
" pop %rsi\n"
|
||||
|
@ -109,7 +111,8 @@ void bootstrap()
|
|||
" movq %rsi,0x38(%rdi)\n"
|
||||
" xor %rax,%rax\n"
|
||||
" ret\n"
|
||||
|
||||
);
|
||||
__asm__ __volatile__ (
|
||||
" .globl longjmp\n"
|
||||
"longjmp:\n"
|
||||
" movl %esi, %eax\n"
|
||||
|
|
13
uefi/uefi.h
13
uefi/uefi.h
|
@ -51,6 +51,9 @@ typedef long long int64_t;
|
|||
typedef unsigned long long uint64_t;
|
||||
typedef unsigned long long uintptr_t;
|
||||
#endif
|
||||
extern char c_assert1[sizeof(uint32_t) == 4 ? 1 : -1];
|
||||
extern char c_assert2[sizeof(uint64_t) == 8 ? 1 : -1];
|
||||
extern char c_assert3[sizeof(uintptr_t) == 8 ? 1 : -1];
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void*)0)
|
||||
|
@ -901,7 +904,7 @@ typedef efi_status_t (EFIAPI *efi_file_set_info_t)(efi_file_handle_t *File, efi_
|
|||
void *Buffer);
|
||||
typedef efi_status_t (EFIAPI *efi_file_flush_t)(efi_file_handle_t *File);
|
||||
|
||||
typedef struct efi_file_handle_s {
|
||||
struct efi_file_handle_s {
|
||||
uint64_t Revision;
|
||||
efi_file_open_t Open;
|
||||
efi_file_close_t Close;
|
||||
|
@ -913,7 +916,7 @@ typedef struct efi_file_handle_s {
|
|||
efi_file_get_info_t GetInfo;
|
||||
efi_file_set_info_t SetInfo;
|
||||
efi_file_flush_t Flush;
|
||||
} efi_file_handle_t;
|
||||
};
|
||||
|
||||
/*** Shell Parameter Protocols ***/
|
||||
#ifndef EFI_SHELL_PARAMETERS_PROTOCOL_GUID
|
||||
|
@ -939,9 +942,9 @@ typedef struct {
|
|||
uintn_t Argc;
|
||||
wchar_t **RedirArgv;
|
||||
uintn_t RedirArgc;
|
||||
efi_handle_t StdIn;
|
||||
efi_handle_t StdOut;
|
||||
efi_handle_t StdErr;
|
||||
efi_handle_t StdIn;
|
||||
efi_handle_t StdOut;
|
||||
efi_handle_t StdErr;
|
||||
} efi_shell_interface_protocol_t;
|
||||
|
||||
/*** Random Number Generator ***/
|
||||
|
|
Loading…
Reference in a new issue