Skip to content

Commit f6869e7

Browse files
committed
Merge remote-tracking branch 'anton/abiv2' into next
This series adds support for building the powerpc 64-bit LE kernel using the new ABI v2. We already supported running ABI v2 userspace programs but this adds support for building the kernel itself using the new ABI.
2 parents 5a4e58b + cec4b7e commit f6869e7

55 files changed

Lines changed: 902 additions & 680 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎arch/powerpc/Makefile‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,13 @@ else
113113
endif
114114
endif
115115

116-
CFLAGS-$(CONFIG_PPC64) := -mtraceback=no -mcall-aixdesc
117-
CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mabi=elfv1)
116+
CFLAGS-$(CONFIG_PPC64) := -mtraceback=no
117+
ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y)
118+
CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mabi=elfv2,-mcall-aixdesc)
119+
AFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mabi=elfv2)
120+
else
121+
CFLAGS-$(CONFIG_PPC64) += -mcall-aixdesc
122+
endif
118123
CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mcmodel=medium,-mminimal-toc)
119124
CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mno-pointers-to-nested-functions)
120125
CFLAGS-$(CONFIG_PPC32) := -ffixed-r2 $(MULTIPLEWORD)
@@ -151,7 +156,7 @@ endif
151156
CFLAGS-$(CONFIG_TUNE_CELL) += $(call cc-option,-mtune=cell)
152157

153158
KBUILD_CPPFLAGS += -Iarch/$(ARCH)
154-
KBUILD_AFLAGS += -Iarch/$(ARCH)
159+
KBUILD_AFLAGS += -Iarch/$(ARCH) $(AFLAGS-y)
155160
KBUILD_CFLAGS += -msoft-float -pipe -Iarch/$(ARCH) $(CFLAGS-y)
156161
CPP = $(CC) -E $(KBUILD_CFLAGS)
157162

‎arch/powerpc/boot/util.S‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ udelay:
4545
mfspr r4,SPRN_PVR
4646
srwi r4,r4,16
4747
cmpwi 0,r4,1 /* 601 ? */
48-
bne .udelay_not_601
48+
bne .Ludelay_not_601
4949
00: li r0,86 /* Instructions / microsecond? */
5050
mtctr r0
5151
10: addi r0,r0,0 /* NOP */
@@ -54,7 +54,7 @@ udelay:
5454
bne 00b
5555
blr
5656

57-
.udelay_not_601:
57+
.Ludelay_not_601:
5858
mulli r4,r3,1000 /* nanoseconds */
5959
/* Change r4 to be the number of ticks using:
6060
* (nanoseconds + (timebase_period_ns - 1 )) / timebase_period_ns

‎arch/powerpc/include/asm/code-patching.h‎

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,47 @@ void __patch_exception(int exc, unsigned long addr);
4242
} while (0)
4343
#endif
4444

45+
#define OP_RT_RA_MASK 0xffff0000UL
46+
#define LIS_R2 0x3c020000UL
47+
#define ADDIS_R2_R12 0x3c4c0000UL
48+
#define ADDI_R2_R2 0x38420000UL
49+
4550
static inline unsigned long ppc_function_entry(void *func)
4651
{
47-
#ifdef CONFIG_PPC64
52+
#if defined(CONFIG_PPC64)
53+
#if defined(_CALL_ELF) && _CALL_ELF == 2
54+
u32 *insn = func;
55+
56+
/*
57+
* A PPC64 ABIv2 function may have a local and a global entry
58+
* point. We need to use the local entry point when patching
59+
* functions, so identify and step over the global entry point
60+
* sequence.
61+
*
62+
* The global entry point sequence is always of the form:
63+
*
64+
* addis r2,r12,XXXX
65+
* addi r2,r2,XXXX
66+
*
67+
* A linker optimisation may convert the addis to lis:
68+
*
69+
* lis r2,XXXX
70+
* addi r2,r2,XXXX
71+
*/
72+
if ((((*insn & OP_RT_RA_MASK) == ADDIS_R2_R12) ||
73+
((*insn & OP_RT_RA_MASK) == LIS_R2)) &&
74+
((*(insn+1) & OP_RT_RA_MASK) == ADDI_R2_R2))
75+
return (unsigned long)(insn + 2);
76+
else
77+
return (unsigned long)func;
78+
#else
4879
/*
49-
* On PPC64 the function pointer actually points to the function's
50-
* descriptor. The first entry in the descriptor is the address
51-
* of the function text.
80+
* On PPC64 ABIv1 the function pointer actually points to the
81+
* function's descriptor. The first entry in the descriptor is the
82+
* address of the function text.
5283
*/
5384
return ((func_descr_t *)func)->entry;
85+
#endif
5486
#else
5587
return (unsigned long)func;
5688
#endif

‎arch/powerpc/include/asm/context_tracking.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#define _ASM_POWERPC_CONTEXT_TRACKING_H
33

44
#ifdef CONFIG_CONTEXT_TRACKING
5-
#define SCHEDULE_USER bl .schedule_user
5+
#define SCHEDULE_USER bl schedule_user
66
#else
7-
#define SCHEDULE_USER bl .schedule
7+
#define SCHEDULE_USER bl schedule
88
#endif
99

1010
#endif

‎arch/powerpc/include/asm/exception-64e.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,18 @@ exc_##label##_book3e:
174174
mtlr r16;
175175
#define TLB_MISS_STATS_D(name) \
176176
addi r9,r13,MMSTAT_DSTATS+name; \
177-
bl .tlb_stat_inc;
177+
bl tlb_stat_inc;
178178
#define TLB_MISS_STATS_I(name) \
179179
addi r9,r13,MMSTAT_ISTATS+name; \
180-
bl .tlb_stat_inc;
180+
bl tlb_stat_inc;
181181
#define TLB_MISS_STATS_X(name) \
182182
ld r8,PACA_EXTLB+EX_TLB_ESR(r13); \
183183
cmpdi cr2,r8,-1; \
184184
beq cr2,61f; \
185185
addi r9,r13,MMSTAT_DSTATS+name; \
186186
b 62f; \
187187
61: addi r9,r13,MMSTAT_ISTATS+name; \
188-
62: bl .tlb_stat_inc;
188+
62: bl tlb_stat_inc;
189189
#define TLB_MISS_STATS_SAVE_INFO \
190190
std r14,EX_TLB_ESR(r12); /* save ESR */
191191
#define TLB_MISS_STATS_SAVE_INFO_BOLTED \

‎arch/powerpc/include/asm/exception-64s.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ label##_relon_hv: \
517517
#define DISABLE_INTS RECONCILE_IRQ_STATE(r10,r11)
518518

519519
#define ADD_NVGPRS \
520-
bl .save_nvgprs
520+
bl save_nvgprs
521521

522522
#define RUNLATCH_ON \
523523
BEGIN_FTR_SECTION \

‎arch/powerpc/include/asm/ftrace.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct dyn_arch_ftrace {
6161
#endif
6262

6363
#if defined(CONFIG_FTRACE_SYSCALLS) && defined(CONFIG_PPC64) && !defined(__ASSEMBLY__)
64+
#if !defined(_CALL_ELF) || _CALL_ELF != 2
6465
#define ARCH_HAS_SYSCALL_MATCH_SYM_NAME
6566
static inline bool arch_syscall_match_sym_name(const char *sym, const char *name)
6667
{
@@ -72,6 +73,7 @@ static inline bool arch_syscall_match_sym_name(const char *sym, const char *name
7273
*/
7374
return !strcmp(sym + 4, name + 3);
7475
}
76+
#endif
7577
#endif /* CONFIG_FTRACE_SYSCALLS && CONFIG_PPC64 && !__ASSEMBLY__ */
7678

7779
#endif /* _ASM_POWERPC_FTRACE */

‎arch/powerpc/include/asm/irqflags.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
*/
2121
#define TRACE_WITH_FRAME_BUFFER(func) \
2222
mflr r0; \
23-
stdu r1, -32(r1); \
23+
stdu r1, -STACK_FRAME_OVERHEAD(r1); \
2424
std r0, 16(r1); \
25-
stdu r1, -32(r1); \
25+
stdu r1, -STACK_FRAME_OVERHEAD(r1); \
2626
bl func; \
2727
ld r1, 0(r1); \
2828
ld r1, 0(r1);
@@ -36,8 +36,8 @@
3636
* have to call a C function so call a wrapper that saves all the
3737
* C-clobbered registers.
3838
*/
39-
#define TRACE_ENABLE_INTS TRACE_WITH_FRAME_BUFFER(.trace_hardirqs_on)
40-
#define TRACE_DISABLE_INTS TRACE_WITH_FRAME_BUFFER(.trace_hardirqs_off)
39+
#define TRACE_ENABLE_INTS TRACE_WITH_FRAME_BUFFER(trace_hardirqs_on)
40+
#define TRACE_DISABLE_INTS TRACE_WITH_FRAME_BUFFER(trace_hardirqs_off)
4141

4242
/*
4343
* This is used by assembly code to soft-disable interrupts first and

‎arch/powerpc/include/asm/kprobes.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <linux/ptrace.h>
3131
#include <linux/percpu.h>
3232
#include <asm/probes.h>
33+
#include <asm/code-patching.h>
3334

3435
#define __ARCH_WANT_KPROBES_INSN_SLOT
3536

@@ -56,9 +57,9 @@ typedef ppc_opcode_t kprobe_opcode_t;
5657
if ((colon = strchr(name, ':')) != NULL) { \
5758
colon++; \
5859
if (*colon != '\0' && *colon != '.') \
59-
addr = *(kprobe_opcode_t **)addr; \
60+
addr = (kprobe_opcode_t *)ppc_function_entry(addr); \
6061
} else if (name[0] != '.') \
61-
addr = *(kprobe_opcode_t **)addr; \
62+
addr = (kprobe_opcode_t *)ppc_function_entry(addr); \
6263
} else { \
6364
char dot_name[KSYM_NAME_LEN]; \
6465
dot_name[0] = '.'; \

‎arch/powerpc/include/asm/linkage.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
#define _ASM_POWERPC_LINKAGE_H
33

44
#ifdef CONFIG_PPC64
5+
#if !defined(_CALL_ELF) || _CALL_ELF != 2
56
#define cond_syscall(x) \
67
asm ("\t.weak " #x "\n\t.set " #x ", sys_ni_syscall\n" \
78
"\t.weak ." #x "\n\t.set ." #x ", .sys_ni_syscall\n")
89
#define SYSCALL_ALIAS(alias, name) \
910
asm ("\t.globl " #alias "\n\t.set " #alias ", " #name "\n" \
1011
"\t.globl ." #alias "\n\t.set ." #alias ", ." #name)
1112
#endif
13+
#endif
1214

1315
#endif /* _ASM_POWERPC_LINKAGE_H */

0 commit comments

Comments
 (0)