Skip to content

Commit f83319d

Browse files
antonblanchardozbenh
authored andcommitted
powerpc: Add lq/stq emulation
Recent CPUs support quad word load and store instructions. Add support to the alignment handler for them. Signed-off-by: Anton Blanchard <anton@samba.org> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
1 parent e28b05e commit f83319d

3 files changed

Lines changed: 46 additions & 8 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ extern struct ppc_emulated {
5454
#ifdef CONFIG_PPC64
5555
struct ppc_emulated_entry mfdscr;
5656
struct ppc_emulated_entry mtdscr;
57+
struct ppc_emulated_entry lq_stq;
5758
#endif
5859
} ppc_emulated;
5960

‎arch/powerpc/kernel/align.c‎

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static struct aligninfo aligninfo[128] = {
7373
{ 8, LD+F }, /* 00 0 1001: lfd */
7474
{ 4, ST+F+S }, /* 00 0 1010: stfs */
7575
{ 8, ST+F }, /* 00 0 1011: stfd */
76-
INVALID, /* 00 0 1100 */
76+
{ 16, LD }, /* 00 0 1100: lq */
7777
{ 8, LD }, /* 00 0 1101: ld/ldu/lwa */
7878
INVALID, /* 00 0 1110 */
7979
{ 8, ST }, /* 00 0 1111: std/stdu */
@@ -140,7 +140,7 @@ static struct aligninfo aligninfo[128] = {
140140
{ 2, LD+SW }, /* 10 0 1100: lhbrx */
141141
{ 4, LD+SE }, /* 10 0 1101 lwa */
142142
{ 2, ST+SW }, /* 10 0 1110: sthbrx */
143-
INVALID, /* 10 0 1111 */
143+
{ 16, ST }, /* 10 0 1111: stq */
144144
INVALID, /* 10 1 0000 */
145145
INVALID, /* 10 1 0001 */
146146
INVALID, /* 10 1 0010 */
@@ -385,8 +385,6 @@ static int emulate_fp_pair(unsigned char __user *addr, unsigned int reg,
385385
char *ptr1 = (char *) &current->thread.TS_FPR(reg+1);
386386
int i, ret, sw = 0;
387387

388-
if (!(flags & F))
389-
return 0;
390388
if (reg & 1)
391389
return 0; /* invalid form: FRS/FRT must be even */
392390
if (flags & SW)
@@ -406,6 +404,34 @@ static int emulate_fp_pair(unsigned char __user *addr, unsigned int reg,
406404
return 1; /* exception handled and fixed up */
407405
}
408406

407+
#ifdef CONFIG_PPC64
408+
static int emulate_lq_stq(struct pt_regs *regs, unsigned char __user *addr,
409+
unsigned int reg, unsigned int flags)
410+
{
411+
char *ptr0 = (char *)&regs->gpr[reg];
412+
char *ptr1 = (char *)&regs->gpr[reg+1];
413+
int i, ret, sw = 0;
414+
415+
if (reg & 1)
416+
return 0; /* invalid form: GPR must be even */
417+
if (flags & SW)
418+
sw = 7;
419+
ret = 0;
420+
for (i = 0; i < 8; ++i) {
421+
if (!(flags & ST)) {
422+
ret |= __get_user(ptr0[i^sw], addr + i);
423+
ret |= __get_user(ptr1[i^sw], addr + i + 8);
424+
} else {
425+
ret |= __put_user(ptr0[i^sw], addr + i);
426+
ret |= __put_user(ptr1[i^sw], addr + i + 8);
427+
}
428+
}
429+
if (ret)
430+
return -EFAULT;
431+
return 1; /* exception handled and fixed up */
432+
}
433+
#endif /* CONFIG_PPC64 */
434+
409435
#ifdef CONFIG_SPE
410436

411437
static struct aligninfo spe_aligninfo[32] = {
@@ -914,10 +940,20 @@ int fix_alignment(struct pt_regs *regs)
914940
flush_fp_to_thread(current);
915941
}
916942

917-
/* Special case for 16-byte FP loads and stores */
918-
if (nb == 16) {
919-
PPC_WARN_ALIGNMENT(fp_pair, regs);
920-
return emulate_fp_pair(addr, reg, flags);
943+
if ((nb == 16)) {
944+
if (flags & F) {
945+
/* Special case for 16-byte FP loads and stores */
946+
PPC_WARN_ALIGNMENT(fp_pair, regs);
947+
return emulate_fp_pair(addr, reg, flags);
948+
} else {
949+
#ifdef CONFIG_PPC64
950+
/* Special case for 16-byte loads and stores */
951+
PPC_WARN_ALIGNMENT(lq_stq, regs);
952+
return emulate_lq_stq(regs, addr, reg, flags);
953+
#else
954+
return 0;
955+
#endif
956+
}
921957
}
922958

923959
PPC_WARN_ALIGNMENT(unaligned, regs);

‎arch/powerpc/kernel/traps.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,6 +1868,7 @@ struct ppc_emulated ppc_emulated = {
18681868
#ifdef CONFIG_PPC64
18691869
WARN_EMULATED_SETUP(mfdscr),
18701870
WARN_EMULATED_SETUP(mtdscr),
1871+
WARN_EMULATED_SETUP(lq_stq),
18711872
#endif
18721873
};
18731874

0 commit comments

Comments
 (0)