mirror of
https://gitlab.com/bztsrc/posix-uefi.git
synced 2024-12-29 05:55:31 +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
|
include uefi/Makefile
|
||||||
```
|
```
|
||||||
The build environment configurator was created in a way that it can handle any number of architectures, however
|
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
|
only `x86_64` crt0 has been throughfully tested for now. There's an `aarch64` crt0 too, but since I don't have
|
||||||
the LLVM toolchain, GNU ld has some issues with it, saying "unsupported relocation" for ImageBase.
|
an ARM UEFI board, it hasn't been tested on real machine. Should work though.
|
||||||
|
|
||||||
Notable Differences to POSIX libc
|
Notable Differences to POSIX libc
|
||||||
---------------------------------
|
---------------------------------
|
||||||
|
|
|
@ -5,7 +5,7 @@ TARGET = helloworld.efi
|
||||||
#define your sources here
|
#define your sources here
|
||||||
SRCS = $(wildcard *.c)
|
SRCS = $(wildcard *.c)
|
||||||
# define your default compiler flags
|
# 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
|
# define your default linker flags
|
||||||
#LDFLAGS =
|
#LDFLAGS =
|
||||||
# define your additional libraries here
|
# define your additional libraries here
|
||||||
|
|
|
@ -34,14 +34,20 @@ LIBS += -o $(TARGET).so -luefi -T uefi/elf_$(ARCH)_efi.lds
|
||||||
ifneq ($(ARCH),$(MYARCH))
|
ifneq ($(ARCH),$(MYARCH))
|
||||||
CC = $(ARCH)-elf-gcc
|
CC = $(ARCH)-elf-gcc
|
||||||
LD = $(ARCH)-elf-ld
|
LD = $(ARCH)-elf-ld
|
||||||
|
OBJCOPY ?= $(ARCH)-elf-objcopy
|
||||||
else
|
else
|
||||||
CC = gcc
|
CC = gcc
|
||||||
LD = ld
|
LD = ld
|
||||||
endif
|
|
||||||
OBJCOPY ?= objcopy
|
OBJCOPY ?= objcopy
|
||||||
|
endif
|
||||||
|
ifeq ($(ARCH),aarch64)
|
||||||
|
EFIARCH = pei-aarch64-little
|
||||||
|
else
|
||||||
|
EFIARCH = efi-app-$(ARCH)
|
||||||
|
endif
|
||||||
AR ?= ar
|
AR ?= ar
|
||||||
else
|
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
|
LDFLAGS += -subsystem:efi_application -nodefaultlib -dll -entry:uefi_init uefi/*.o
|
||||||
LIBS = -out:$(TARGET)
|
LIBS = -out:$(TARGET)
|
||||||
CC = clang
|
CC = clang
|
||||||
|
@ -73,7 +79,7 @@ endif
|
||||||
|
|
||||||
$(TARGET): $(TARGET).so
|
$(TARGET): $(TARGET).so
|
||||||
ifeq ($(USE_LLVM),)
|
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
|
@rm $(TARGET).so
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
|
@ -74,8 +74,7 @@ void bootstrap()
|
||||||
#ifndef __clang__
|
#ifndef __clang__
|
||||||
" .globl _start\n"
|
" .globl _start\n"
|
||||||
"_start:\n"
|
"_start:\n"
|
||||||
" adr x2, ImageBase\n"
|
" ldr x2, =ImageBase\n"
|
||||||
/* " mov x2, xzr\n" */
|
|
||||||
" adrp x3, _DYNAMIC\n"
|
" adrp x3, _DYNAMIC\n"
|
||||||
" add x3, x3, #:lo12:_DYNAMIC\n"
|
" add x3, x3, #:lo12:_DYNAMIC\n"
|
||||||
" bl uefi_init\n"
|
" bl uefi_init\n"
|
||||||
|
@ -95,8 +94,10 @@ void bootstrap()
|
||||||
"__chkstk:\n"
|
"__chkstk:\n"
|
||||||
" ret\n"
|
" ret\n"
|
||||||
#endif
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
/* setjmp and longjmp */
|
/* setjmp and longjmp */
|
||||||
|
__asm__ __volatile__ (
|
||||||
" .p2align 3\n"
|
" .p2align 3\n"
|
||||||
" .globl setjmp\n"
|
" .globl setjmp\n"
|
||||||
"setjmp:\n"
|
"setjmp:\n"
|
||||||
|
@ -114,7 +115,8 @@ void bootstrap()
|
||||||
" stp d14, d15, [x0, #160]\n"
|
" stp d14, d15, [x0, #160]\n"
|
||||||
" mov w0, #0\n"
|
" mov w0, #0\n"
|
||||||
" ret\n"
|
" ret\n"
|
||||||
|
);
|
||||||
|
__asm__ __volatile__ (
|
||||||
" .globl longjmp\n"
|
" .globl longjmp\n"
|
||||||
"longjmp:\n"
|
"longjmp:\n"
|
||||||
" ldp x19, x20, [x0, #0]\n"
|
" ldp x19, x20, [x0, #0]\n"
|
||||||
|
|
|
@ -93,8 +93,10 @@ void bootstrap()
|
||||||
"__chkstk:\n"
|
"__chkstk:\n"
|
||||||
" ret\n"
|
" ret\n"
|
||||||
#endif
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
/* setjmp and longjmp */
|
/* setjmp and longjmp */
|
||||||
|
__asm__ __volatile__ (
|
||||||
" .globl setjmp\n"
|
" .globl setjmp\n"
|
||||||
"setjmp:\n"
|
"setjmp:\n"
|
||||||
" pop %rsi\n"
|
" pop %rsi\n"
|
||||||
|
@ -109,7 +111,8 @@ void bootstrap()
|
||||||
" movq %rsi,0x38(%rdi)\n"
|
" movq %rsi,0x38(%rdi)\n"
|
||||||
" xor %rax,%rax\n"
|
" xor %rax,%rax\n"
|
||||||
" ret\n"
|
" ret\n"
|
||||||
|
);
|
||||||
|
__asm__ __volatile__ (
|
||||||
" .globl longjmp\n"
|
" .globl longjmp\n"
|
||||||
"longjmp:\n"
|
"longjmp:\n"
|
||||||
" movl %esi, %eax\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 uint64_t;
|
||||||
typedef unsigned long long uintptr_t;
|
typedef unsigned long long uintptr_t;
|
||||||
#endif
|
#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
|
#ifndef NULL
|
||||||
#define NULL ((void*)0)
|
#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);
|
void *Buffer);
|
||||||
typedef efi_status_t (EFIAPI *efi_file_flush_t)(efi_file_handle_t *File);
|
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;
|
uint64_t Revision;
|
||||||
efi_file_open_t Open;
|
efi_file_open_t Open;
|
||||||
efi_file_close_t Close;
|
efi_file_close_t Close;
|
||||||
|
@ -913,7 +916,7 @@ typedef struct efi_file_handle_s {
|
||||||
efi_file_get_info_t GetInfo;
|
efi_file_get_info_t GetInfo;
|
||||||
efi_file_set_info_t SetInfo;
|
efi_file_set_info_t SetInfo;
|
||||||
efi_file_flush_t Flush;
|
efi_file_flush_t Flush;
|
||||||
} efi_file_handle_t;
|
};
|
||||||
|
|
||||||
/*** Shell Parameter Protocols ***/
|
/*** Shell Parameter Protocols ***/
|
||||||
#ifndef EFI_SHELL_PARAMETERS_PROTOCOL_GUID
|
#ifndef EFI_SHELL_PARAMETERS_PROTOCOL_GUID
|
||||||
|
@ -939,9 +942,9 @@ typedef struct {
|
||||||
uintn_t Argc;
|
uintn_t Argc;
|
||||||
wchar_t **RedirArgv;
|
wchar_t **RedirArgv;
|
||||||
uintn_t RedirArgc;
|
uintn_t RedirArgc;
|
||||||
efi_handle_t StdIn;
|
efi_handle_t StdIn;
|
||||||
efi_handle_t StdOut;
|
efi_handle_t StdOut;
|
||||||
efi_handle_t StdErr;
|
efi_handle_t StdErr;
|
||||||
} efi_shell_interface_protocol_t;
|
} efi_shell_interface_protocol_t;
|
||||||
|
|
||||||
/*** Random Number Generator ***/
|
/*** Random Number Generator ***/
|
||||||
|
|
Loading…
Reference in a new issue