aboutsummaryrefslogtreecommitdiff
path: root/Makefile.main
diff options
context:
space:
mode:
authorNicholas Piggin <npiggin@gmail.com>2020-04-27 21:08:00 +1000
committerOliver O'Halloran <oohall@gmail.com>2020-06-11 12:51:36 +1000
commit11ce9612b3aab362e9139bf7a4e7198408af2832 (patch)
treeffe27f045b9d0af852e24ff7349a76aa7a8f3420 /Makefile.main
parent7f3dfa7fc8478d22a4cd8af45fc636c3ed9737ea (diff)
downloadskiboot-11ce9612b3aab362e9139bf7a4e7198408af2832.zip
skiboot-11ce9612b3aab362e9139bf7a4e7198408af2832.tar.gz
skiboot-11ce9612b3aab362e9139bf7a4e7198408af2832.tar.bz2
move the __this_cpu register to r16, reserve r13-r15
There have been several bugs between Linux and OPAL caused by both using r13 for their primary per-CPU data address. This patch moves OPAL to use r16 for this, and prevents the compiler from touching r13-r15 (r14,r15 allow Linux to use additional fixed registers in future). This helps code to be a little more robust, and may make crashes in OPAL (or debugging with pdbg or in simulators) easier to debug by having easy access to the PACA. Later, if we allow interrupts (other than non-maskable) to be taken when running in skiboot, Linux's interrupt return handler does not restore r13 if the interrupt was taken in PR=0 state, which would corrupt the skiboot r13 register, so this allows for the possibility, although it will have to become a formal OPAL ABI requirement if we rely on it. Signed-off-by: Nicholas Piggin <npiggin@gmail.com> [oliver: x86_64 has an r13, but not an r16 so the tests broke] Signed-off-by: Oliver O'Halloran <oohall@gmail.com> wip: fix __this_cpu() in the test cases
Diffstat (limited to 'Makefile.main')
-rw-r--r--Makefile.main11
1 files changed, 9 insertions, 2 deletions
diff --git a/Makefile.main b/Makefile.main
index 12aa253..bf0fcfa 100644
--- a/Makefile.main
+++ b/Makefile.main
@@ -96,7 +96,14 @@ endif
CFLAGS := -fno-strict-aliasing -pie -fpie -fno-pic -m64 -fno-asynchronous-unwind-tables
CFLAGS += -mcpu=power8
CFLAGS += -Wl,--oformat,elf64-powerpc -ggdb
-CFLAGS += $(call try-cflag,$(CC),-ffixed-r13)
+# r13,r14,r15 are preserved for OS to use as fixed registers.
+# These could be saved and restored in and out of skiboot, but it's more
+# robust to avoid touching them.
+CFLAGS += -ffixed-r13
+CFLAGS += -ffixed-r14
+CFLAGS += -ffixed-r15
+# r16 is skiboot's per-CPU data pointer.
+CFLAGS += -ffixed-r16
CFLAGS += $(call try-cflag,$(CC),-std=gnu11)
ifeq ($(LITTLE_ENDIAN),1)
@@ -127,7 +134,7 @@ endif
# Check if the new parametrized stack protector option is supported
# by gcc, otherwise disable stack protector
-STACK_PROT_CFLAGS := -mstack-protector-guard=tls -mstack-protector-guard-reg=r13
+STACK_PROT_CFLAGS := -mstack-protector-guard=tls -mstack-protector-guard-reg=r16
STACK_PROT_CFLAGS += -mstack-protector-guard-offset=0
HAS_STACK_PROT := $(call test_cflag,$(CC),$(STACK_PROT_CFLAGS))