diff --git a/Makefile b/Makefile index c95d3ca..cce1686 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ EXPORT_UNPREFIXED := yes FREESTANDING := no ifeq ($(FREESTANDING),yes) - CFLAGS += -DFREESTANDING -isystem arch/${ARCH}/freestanding + CFLAGS += -DFREESTANDING EXPORT_UNPREFIXED = no endif @@ -215,13 +215,13 @@ examples/cooperative_threading: examples/cooperative_threading.c ${LIBUCONTEXT_N ifeq ($(FREESTANDING),no) -include/libucontext/bits.h: arch/common/bits.h - cp arch/common/bits.h $@ +include/libucontext/bits.h: arch/common/include/libucontext/bits.h + cp $< $@ else -include/libucontext/bits.h: arch/${ARCH}/freestanding/bits.h - cp arch/${ARCH}/freestanding/bits.h $@ +include/libucontext/bits.h: arch/${ARCH}/include/libucontext/bits.h + cp $< $@ endif diff --git a/arch/aarch64/getcontext.S b/arch/aarch64/getcontext.S index 2a1c4d7..1098706 100644 --- a/arch/aarch64/getcontext.S +++ b/arch/aarch64/getcontext.S @@ -15,7 +15,11 @@ ALIAS(getcontext, libucontext_getcontext) ALIAS(__getcontext, libucontext_getcontext) -FUNC(libucontext_getcontext) + .global PROC_NAME(libucontext_getcontext); + .align 2; + TYPE(libucontext_getcontext) + ENT(libucontext_getcontext) +PROC_NAME(libucontext_getcontext): str xzr, [x0, #REG_OFFSET(0)] /* save GPRs */ diff --git a/arch/aarch64/freestanding/bits.h b/arch/aarch64/include/libucontext/bits.h similarity index 100% rename from arch/aarch64/freestanding/bits.h rename to arch/aarch64/include/libucontext/bits.h diff --git a/arch/aarch64/setcontext.S b/arch/aarch64/setcontext.S index 994652b..3d455a5 100644 --- a/arch/aarch64/setcontext.S +++ b/arch/aarch64/setcontext.S @@ -15,7 +15,11 @@ ALIAS(setcontext, libucontext_setcontext) ALIAS(__setcontext, libucontext_setcontext) -FUNC(libucontext_setcontext) + .global PROC_NAME(libucontext_setcontext); + .align 2; + TYPE(libucontext_setcontext) + ENT(libucontext_setcontext) +PROC_NAME(libucontext_setcontext): /* restore GPRs */ ldp x18, x19, [x0, #REG_OFFSET(18)] ldp x20, x21, [x0, #REG_OFFSET(20)] diff --git a/arch/aarch64/swapcontext.S b/arch/aarch64/swapcontext.S index d5bad2c..fddfa41 100644 --- a/arch/aarch64/swapcontext.S +++ b/arch/aarch64/swapcontext.S @@ -15,7 +15,11 @@ ALIAS(swapcontext, libucontext_swapcontext) ALIAS(__swapcontext, libucontext_swapcontext) -FUNC(libucontext_swapcontext) + .global PROC_NAME(libucontext_swapcontext); + .align 2; + TYPE(libucontext_swapcontext) + ENT(libucontext_swapcontext) +PROC_NAME(libucontext_swapcontext): str xzr, [x0, #REG_OFFSET(0)] /* save GPRs */ diff --git a/arch/arm/freestanding/bits.h b/arch/arm/include/libucontext/bits.h similarity index 100% rename from arch/arm/freestanding/bits.h rename to arch/arm/include/libucontext/bits.h diff --git a/arch/common/bits.h b/arch/common/include/libucontext/bits.h similarity index 100% rename from arch/common/bits.h rename to arch/common/include/libucontext/bits.h diff --git a/arch/m68k/freestanding/bits.h b/arch/m68k/include/libucontext/bits.h similarity index 100% rename from arch/m68k/freestanding/bits.h rename to arch/m68k/include/libucontext/bits.h diff --git a/arch/mips/freestanding/bits.h b/arch/mips/include/libucontext/bits.h similarity index 100% rename from arch/mips/freestanding/bits.h rename to arch/mips/include/libucontext/bits.h diff --git a/arch/mips64/freestanding/bits.h b/arch/mips64/include/libucontext/bits.h similarity index 100% rename from arch/mips64/freestanding/bits.h rename to arch/mips64/include/libucontext/bits.h diff --git a/arch/riscv64/freestanding/bits.h b/arch/riscv64/include/libucontext/bits.h similarity index 100% rename from arch/riscv64/freestanding/bits.h rename to arch/riscv64/include/libucontext/bits.h diff --git a/arch/s390x/freestanding/bits.h b/arch/s390x/include/libucontext/bits.h similarity index 100% rename from arch/s390x/freestanding/bits.h rename to arch/s390x/include/libucontext/bits.h diff --git a/arch/sh/freestanding/bits.h b/arch/sh/include/libucontext/bits.h similarity index 100% rename from arch/sh/freestanding/bits.h rename to arch/sh/include/libucontext/bits.h diff --git a/arch/x86/defs.h b/arch/x86/defs.h index 0bf73ba..9370869 100644 --- a/arch/x86/defs.h +++ b/arch/x86/defs.h @@ -1,7 +1,6 @@ #ifndef __ARCH_X86_DEFS_H #define __ARCH_X86_DEFS_H -#ifndef _GNU_SOURCE #ifndef REG_GS # define REG_GS (0) #endif @@ -53,7 +52,6 @@ #ifndef REG_EIP # define REG_EIP (14) #endif -#endif #define REG_SZ (4) diff --git a/arch/x86/freestanding/bits.h b/arch/x86/include/libucontext/bits.h similarity index 100% rename from arch/x86/freestanding/bits.h rename to arch/x86/include/libucontext/bits.h diff --git a/arch/x86_64/defs.h b/arch/x86_64/defs.h index c5fd126..1ebf3a9 100644 --- a/arch/x86_64/defs.h +++ b/arch/x86_64/defs.h @@ -1,29 +1,95 @@ #ifndef __ARCH_X86_64_DEFS_H #define __ARCH_X86_64_DEFS_H -#ifndef _GNU_SOURCE +#ifndef REG_R8 # define REG_R8 (0) +#endif + +#ifndef REG_R9 # define REG_R9 (1) +#endif + +#ifndef REG_R10 # define REG_R10 (2) +#endif + +#ifndef REG_R11 # define REG_R11 (3) +#endif + +#ifndef REG_R12 # define REG_R12 (4) +#endif + +#ifndef REG_R13 # define REG_R13 (5) +#endif + +#ifndef REG_R14 # define REG_R14 (6) +#endif + +#ifndef REG_R15 # define REG_R15 (7) +#endif + +#ifndef REG_RDI # define REG_RDI (8) +#endif + +#ifndef REG_RSI # define REG_RSI (9) +#endif + +#ifndef REG_RBP # define REG_RBP (10) +#endif + +#ifndef REG_RBX # define REG_RBX (11) +#endif + +#ifndef REG_RDX # define REG_RDX (12) +#endif + +#ifndef REG_RAX # define REG_RAX (13) +#endif + +#ifndef REG_RCX # define REG_RCX (14) +#endif + +#ifndef REG_RSP # define REG_RSP (15) +#endif + +#ifndef REG_RIP # define REG_RIP (16) +#endif + +#ifndef REG_EFL # define REG_EFL (17) +#endif + +#ifndef REG_CSGSFS # define REG_CSGSFS (18) +#endif + +#ifndef REG_ERR # define REG_ERR (19) +#endif + +#ifndef REG_TRAPNO # define REG_TRAPNO (20) +#endif + +#ifndef REG_OLDMASK # define REG_OLDMASK (21) +#endif + +#ifndef REG_CR2 # define REG_CR2 (22) #endif diff --git a/arch/x86_64/freestanding/bits.h b/arch/x86_64/include/libucontext/bits.h similarity index 100% rename from arch/x86_64/freestanding/bits.h rename to arch/x86_64/include/libucontext/bits.h diff --git a/meson.build b/meson.build index 948b071..e863780 100644 --- a/meson.build +++ b/meson.build @@ -70,9 +70,11 @@ if freestanding build_args += '-DFREESTANDING' build_posix = false export_unprefixed = false - project_headers += ['arch' / cpu / 'freestanding/bits.h'] + project_headers += ['arch' / cpu / 'include/libucontext/bits.h'] + project_includes += ['arch' / cpu / 'include'] else - project_headers += ['arch/common/bits.h'] + project_headers += ['arch/common/include/libucontext/bits.h'] + project_includes += ['arch/common/include'] endif if export_unprefixed