diff --git a/LibOS/shim/src/Makefile b/LibOS/shim/src/Makefile
index 199d07c9..8e6a956a 100644
--- a/LibOS/shim/src/Makefile
+++ b/LibOS/shim/src/Makefile
@@ -8,7 +8,8 @@ CFLAGS += -fPIC -Winline -Wwrite-strings \
$(cc-option, -Wnull-dereference) \
-fno-stack-protector -fno-builtin -Wno-inline \
-I../include -I../../../Pal/include/lib -I../../../Pal/include/pal \
- -I../../../Pal/include/elf -I../../../Pal/include/lib/$(ARCH)
+ -I../../../Pal/include/elf -I../../../Pal/include/lib/$(ARCH) \
+ -I../../../Pal/include/arch/$(ARCH)
CFLAGS += -Wextra
diff --git a/LibOS/shim/test/inline/Makefile b/LibOS/shim/test/inline/Makefile
index 5e220587..4dfc2fbd 100644
--- a/LibOS/shim/test/inline/Makefile
+++ b/LibOS/shim/test/inline/Makefile
@@ -18,6 +18,8 @@ include ../../../../Scripts/Makefile.configs
include ../../../../Scripts/Makefile.manifest
include ../../../../Scripts/Makefile.Test
+CFLAGS += -I $(PALDIR)/../include/arch/$(ARCH)
+
.PHONY: crt_init-recurse
crt_init-recurse:
$(MAKE) -C ../crt_init all
diff --git a/Pal/include/arch/x86_64/pal-arch.h b/Pal/include/arch/x86_64/pal-arch.h
new file mode 100644
index 00000000..68f0b15e
--- /dev/null
+++ b/Pal/include/arch/x86_64/pal-arch.h
@@ -0,0 +1,168 @@
+/* Copyright (C) 2014 Stony Brook University
+ This file is part of Graphene Library OS.
+
+ Graphene Library OS is free software: you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ Graphene Library OS is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see . */
+
+/*!
+ * \file pal-arch.h
+ *
+ * This file contains definition of x86_64-specific aspects of PAL.
+ */
+
+#ifndef PAL_ARCH_H
+#define PAL_ARCH_H
+
+#include
+
+typedef struct pal_tcb PAL_TCB;
+
+static inline PAL_TCB * pal_get_tcb (void)
+{
+ PAL_TCB * tcb;
+ __asm__ ("movq %%gs:%c1,%q0"
+ : "=r" (tcb)
+ : "i" (offsetof(struct pal_tcb, self)));
+ return tcb;
+}
+
+union pal_csgsfs {
+ struct {
+ uint16_t cs;
+ uint16_t gs;
+ uint16_t fs;
+ uint16_t ss;
+ };
+ uint64_t csgsfs;
+};
+
+/* Adopt Linux style fp layout, _libc_fpstate of glibc:
+ * Because self-contained definition is needed for Pal definition,
+ * same layout is defined with PAL prefix.
+ */
+#define PAL_FP_XSTATE_MAGIC1 0x46505853U
+#define PAL_FP_XSTATE_MAGIC2 0x46505845U
+#define PAL_FP_XSTATE_MAGIC2_SIZE (sizeof(PAL_FP_XSTATE_MAGIC2))
+
+enum PAL_XFEATURE {
+ PAL_XFEATURE_FP,
+ PAL_XFEATURE_SSE,
+ PAL_XFEATURE_YMM,
+ PAL_XFEATURE_BNDREGS,
+ PAL_XFEATURE_BNDCSR,
+ PAL_XFEATURE_OPMASK,
+ PAL_XFEATURE_ZMM_Hi256,
+ PAL_XFEATURE_Hi16_ZMM,
+ PAL_XFEATURE_PT,
+ PAL_XFEATURE_PKRU,
+
+ PAL_XFEATURE_MAX,
+};
+
+#define PAL_XFEATURE_MASK_FP (1UL << PAL_XFEATURE_FP)
+#define PAL_XFEATURE_MASK_SSE (1UL << PAL_XFEATURE_SSE)
+#define PAL_XFEATURE_MASK_YMM (1UL << PAL_XFEATURE_YMM)
+#define PAL_XFEATURE_MASK_BNDREGS (1UL << PAL_XFEATURE_BNDREGS)
+#define PAL_XFEATURE_MASK_BNDCSR (1UL << PAL_XFEATURE_BNDCSR)
+#define PAL_XFEATURE_MASK_OPMASK (1UL << PAL_XFEATURE_OPMASK)
+#define PAL_XFEATURE_MASK_ZMM_Hi256 (1UL << PAL_XFEATURE_ZMM_Hi256)
+#define PAL_XFEATURE_MASK_Hi16_ZMM (1UL << PAL_XFEATURE_Hi16_ZMM)
+#define PAL_XFEATURE_MASK_PT (1UL << PAL_XFEATURE_PT)
+#define PAL_XFEATURE_MASK_PKRU (1UL << PAL_XFEATURE_PKRU)
+
+#define PAL_XFEATURE_MASK_FPSSE (PAL_XFEATURE_MASK_FP \
+ | PAL_XFEATURE_MASK_SSE)
+#define PAL_XFEATURE_MASK_AVX512 (PAL_XFEATURE_MASK_OPMASK \
+ | PAL_XFEATURE_MASK_ZMM_Hi256 \
+ | PAL_XFEATURE_MASK_Hi16_ZMM)
+
+typedef struct {
+ uint32_t magic1; /*!< PAL_FP_XSTATE_MAGIC1 */
+ uint32_t extended_size; /*!< xsave_size */
+ uint64_t xfeatures; /*!< XSAVE feature */
+ uint32_t xstate_size; /*!< xsave_size + PAL_FP_STATE_MAGIC2_SIZE */
+ uint32_t padding[7];
+} PAL_FPX_SW_BYTES;
+
+typedef struct {
+ uint32_t cwd;
+ uint32_t swd;
+ uint32_t twd;
+ uint32_t fip;
+ uint32_t fcs;
+ uint32_t foo;
+ uint32_t fos;
+ uint32_t st_space[20];
+ uint8_t ftop;
+ uint8_t changed;
+ uint8_t lookahead;
+ uint8_t no_update;
+ uint8_t rm;
+ uint8_t alimit;
+ void* info; /* struct math_emu_info */
+ uint32_t entry_eip;
+} PAL_SWREGS_STATE;
+
+typedef struct {
+ uint16_t significand[4];
+ uint16_t exponent;
+ uint16_t padding[3];
+} PAL_FPXREG;
+
+typedef struct {
+ uint32_t element[4];
+} PAL_XMMREG;
+
+typedef struct {
+ /* 64-bit FXSAVE format. */
+ uint16_t cwd;
+ uint16_t swd;
+ uint16_t ftw;
+ uint16_t fop;
+ uint64_t rip;
+ uint64_t rdp;
+ uint32_t mxcsr;
+ uint32_t mxcr_mask;
+ PAL_FPXREG st[8];
+ PAL_XMMREG xmm[16];
+ union {
+ uint32_t padding[24];
+ struct {
+ uint32_t padding2[12];
+ PAL_FPX_SW_BYTES sw_reserved;
+ };
+ };
+} PAL_FPSTATE;
+
+typedef struct {
+ uint64_t xfeatures;
+ uint64_t xcomp_bv;
+ uint64_t reserved[6];
+} __attribute__((packed)) PAL_XSTATE_HEADER;
+
+#define PAL_XSTATE_ALIGN 64
+
+typedef struct {
+ PAL_FPSTATE fpstate;
+ PAL_XSTATE_HEADER header;
+} __attribute__((packed, aligned(PAL_XSTATE_ALIGN))) PAL_XREGS_STATE;
+
+typedef struct PAL_CONTEXT_ {
+ PAL_NUM r8, r9, r10, r11, r12, r13, r14, r15;
+ PAL_NUM rdi, rsi, rbp, rbx, rdx, rax, rcx;
+ PAL_NUM rsp, rip;
+ PAL_NUM efl, csgsfs, err, trapno, oldmask, cr2;
+ PAL_XREGS_STATE* fpregs;
+} PAL_CONTEXT;
+
+#endif /* PAL_ARCH_H */
diff --git a/Pal/include/pal/pal.h b/Pal/include/pal/pal.h
index 2d6e2783..b5361f37 100644
--- a/Pal/include/pal/pal.h
+++ b/Pal/include/pal/pal.h
@@ -106,151 +106,7 @@ typedef struct pal_tcb {
/* data private to PAL implementation follows this struct. */
} PAL_TCB;
-static inline PAL_TCB * pal_get_tcb (void)
-{
- PAL_TCB * tcb;
- __asm__ ("movq %%gs:%c1,%q0"
- : "=r" (tcb)
- : "i" (offsetof(struct pal_tcb, self)));
- return tcb;
-}
-
-#ifdef __x86_64__
-union pal_csgsfs {
- struct {
- uint16_t cs;
- uint16_t gs;
- uint16_t fs;
- uint16_t ss;
- };
- uint64_t csgsfs;
-};
-
-/* Adopt Linux style fp layout, _libc_fpstate of glibc:
- * Because self-contained definition is needed for Pal definition,
- * same layout is defined with PAL prefix.
- */
-#define PAL_FP_XSTATE_MAGIC1 0x46505853U
-#define PAL_FP_XSTATE_MAGIC2 0x46505845U
-#define PAL_FP_XSTATE_MAGIC2_SIZE (sizeof(PAL_FP_XSTATE_MAGIC2))
-
-enum PAL_XFEATURE {
- PAL_XFEATURE_FP,
- PAL_XFEATURE_SSE,
- PAL_XFEATURE_YMM,
- PAL_XFEATURE_BNDREGS,
- PAL_XFEATURE_BNDCSR,
- PAL_XFEATURE_OPMASK,
- PAL_XFEATURE_ZMM_Hi256,
- PAL_XFEATURE_Hi16_ZMM,
- PAL_XFEATURE_PT,
- PAL_XFEATURE_PKRU,
-
- PAL_XFEATURE_MAX,
-};
-
-#define PAL_XFEATURE_MASK_FP (1UL << PAL_XFEATURE_FP)
-#define PAL_XFEATURE_MASK_SSE (1UL << PAL_XFEATURE_SSE)
-#define PAL_XFEATURE_MASK_YMM (1UL << PAL_XFEATURE_YMM)
-#define PAL_XFEATURE_MASK_BNDREGS (1UL << PAL_XFEATURE_BNDREGS)
-#define PAL_XFEATURE_MASK_BNDCSR (1UL << PAL_XFEATURE_BNDCSR)
-#define PAL_XFEATURE_MASK_OPMASK (1UL << PAL_XFEATURE_OPMASK)
-#define PAL_XFEATURE_MASK_ZMM_Hi256 (1UL << PAL_XFEATURE_ZMM_Hi256)
-#define PAL_XFEATURE_MASK_Hi16_ZMM (1UL << PAL_XFEATURE_Hi16_ZMM)
-#define PAL_XFEATURE_MASK_PT (1UL << PAL_XFEATURE_PT)
-#define PAL_XFEATURE_MASK_PKRU (1UL << PAL_XFEATURE_PKRU)
-
-#define PAL_XFEATURE_MASK_FPSSE (PAL_XFEATURE_MASK_FP \
- | PAL_XFEATURE_MASK_SSE)
-#define PAL_XFEATURE_MASK_AVX512 (PAL_XFEATURE_MASK_OPMASK \
- | PAL_XFEATURE_MASK_ZMM_Hi256 \
- | PAL_XFEATURE_MASK_Hi16_ZMM)
-
-typedef struct {
- uint32_t magic1; /*!< PAL_FP_XSTATE_MAGIC1 */
- uint32_t extended_size; /*!< xsave_size */
- uint64_t xfeatures; /*!< XSAVE feature */
- uint32_t xstate_size; /*!< xsave_size + PAL_FP_STATE_MAGIC2_SIZE */
- uint32_t padding[7];
-} PAL_FPX_SW_BYTES;
-
-typedef struct {
- uint32_t cwd;
- uint32_t swd;
- uint32_t twd;
- uint32_t fip;
- uint32_t fcs;
- uint32_t foo;
- uint32_t fos;
- uint32_t st_space[20];
- uint8_t ftop;
- uint8_t changed;
- uint8_t lookahead;
- uint8_t no_update;
- uint8_t rm;
- uint8_t alimit;
- void* info; /* struct math_emu_info */
- uint32_t entry_eip;
-} PAL_SWREGS_STATE;
-
-typedef struct {
- uint16_t significand[4];
- uint16_t exponent;
- uint16_t padding[3];
-} PAL_FPXREG;
-
-typedef struct {
- uint32_t element[4];
-} PAL_XMMREG;
-
-typedef struct {
- /* 64-bit FXSAVE format. */
- uint16_t cwd;
- uint16_t swd;
- uint16_t ftw;
- uint16_t fop;
- uint64_t rip;
- uint64_t rdp;
- uint32_t mxcsr;
- uint32_t mxcr_mask;
- PAL_FPXREG st[8];
- PAL_XMMREG xmm[16];
- union {
- uint32_t padding[24];
- struct {
- uint32_t padding2[12];
- PAL_FPX_SW_BYTES sw_reserved;
- };
- };
-} PAL_FPSTATE;
-
-typedef struct {
- uint64_t xfeatures;
- uint64_t xcomp_bv;
- uint64_t reserved[6];
-} __attribute__((packed)) PAL_XSTATE_HEADER;
-
-#define PAL_XSTATE_ALIGN 64
-
-typedef struct {
- PAL_FPSTATE fpstate;
- PAL_XSTATE_HEADER header;
-} __attribute__((packed, aligned(PAL_XSTATE_ALIGN))) PAL_XREGS_STATE;
-#else
-# error "Unsupported architecture"
-#endif
-
-typedef struct PAL_CONTEXT_ {
-#ifdef __x86_64__
- PAL_NUM r8, r9, r10, r11, r12, r13, r14, r15;
- PAL_NUM rdi, rsi, rbp, rbx, rdx, rax, rcx;
- PAL_NUM rsp, rip;
- PAL_NUM efl, csgsfs, err, trapno, oldmask, cr2;
- PAL_XREGS_STATE* fpregs;
-#else
-# error "Unsupported architecture"
-#endif
-} PAL_CONTEXT;
+#include "pal-arch.h"
/********** PAL TYPE DEFINITIONS **********/
enum {
diff --git a/Pal/lib/Makefile b/Pal/lib/Makefile
index 8e91fb5c..43f25147 100644
--- a/Pal/lib/Makefile
+++ b/Pal/lib/Makefile
@@ -2,7 +2,8 @@ include ../../Scripts/Makefile.configs
include ../../Scripts/Makefile.rules
include ../src/host/$(PAL_HOST)/Makefile.am
-CFLAGS += -I../include/lib -I../include -I../include/pal -I../include/host/$(PAL_HOST) \
+CFLAGS += -I../include/lib -I../include -I../include/pal -I../include/arch/$(ARCH) \
+ -I../include/host/$(PAL_HOST) \
-I../src/host/$(PAL_HOST) -Icrypto/mbedtls/include -Icrypto/mbedtls/crypto/include
CRYPTO_PROVIDER ?= mbedtls
diff --git a/Pal/regression/Makefile b/Pal/regression/Makefile
index fdf38e6d..c85652b1 100644
--- a/Pal/regression/Makefile
+++ b/Pal/regression/Makefile
@@ -2,7 +2,8 @@ include ../../Scripts/Makefile.configs
include ../../Scripts/Makefile.rules
CFLAGS += -Wp,-U_FORTIFY_SOURCE -fno-builtin -nostdlib \
- -I../include/pal -I../include/lib -I../src -I../include/lib/$(ARCH)
+ -I../include/pal -I../include/lib -I../src -I../include/lib/$(ARCH) \
+ -I../include/arch/$(ARCH)
preloads = \
Preload1.so \