From patchwork Fri Oct 18 07:38:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfgang Denk X-Patchwork-Id: 284454 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id A98C02C00CB for ; Fri, 18 Oct 2013 18:38:52 +1100 (EST) Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4B95A2C00AD for ; Fri, 18 Oct 2013 18:38:28 +1100 (EST) Received: from frontend1.mail.m-online.net (frontend1.mail.intern.m-online.net [192.168.8.180]) by mail-out.m-online.net (Postfix) with ESMTP id 3d1Jy012SYz3hjKT; Fri, 18 Oct 2013 09:38:16 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.68]) by mail.m-online.net (Postfix) with ESMTP id 3d1Jy00tcjzbbs7; Fri, 18 Oct 2013 09:38:16 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from smtp-auth.mnet-online.de ([192.168.8.180]) by localhost (dynscan1.mail.m-online.net [192.168.6.68]) (amavisd-new, port 10024) with ESMTP id PD0MC3KrzJLV; Fri, 18 Oct 2013 09:38:14 +0200 (CEST) X-Auth-Info: 2XsCh4wM//n1ObZoKL440C4g7gzW52j1mrnFpwttZiU= Received: from diddl.denx.de (host-80-81-18-216.customer.m-online.net [80.81.18.216]) by smtp-auth.mnet-online.de (Postfix) with ESMTPA; Fri, 18 Oct 2013 09:38:14 +0200 (CEST) Received: from gemini.denx.de (gemini.denx.de [10.0.0.2]) by diddl.denx.de (Postfix) with ESMTP id 49ADF1A239E; Fri, 18 Oct 2013 09:38:14 +0200 (CEST) Received: by gemini.denx.de (Postfix, from userid 500) id 288633811D6; Fri, 18 Oct 2013 09:38:14 +0200 (MEST) From: Wolfgang Denk To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH] [RFC] Emulate "lwsync" to run standard user land on e500 cores Date: Fri, 18 Oct 2013 09:38:00 +0200 Message-Id: <1382081880-6666-1-git-send-email-wd@denx.de> X-Mailer: git-send-email 1.8.3.1 Cc: Scott Wood , Wolfgang Denk X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.16rc2 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Default Debian PowerPC doesn't work on e500 because the code contains "lwsync" instructions, which are unsupported on this core. As a result, applications using this will crash with an "unhandled signal 4" "Illegal instruction" error. As a work around we add code to emulate this insn. This is expensive performance-wise, but allows to run standard user land code. Signed-off-by: Wolfgang Denk Cc: Benjamin Herrenschmidt Cc: Scott Wood --- I am aware that the clean solution to the problem is to build user space with compiler options that match the target architecture. However, sometimes this is just too much effort. Also, of course the performance of such an emulation sucks. But the the occurrence of such instructions is so rare that no significant slowdown can be oserved. I'm not sure if this should / could go into mainline. I'm posting it primarily so it can be found should anybody else need this. - wd arch/powerpc/kernel/traps.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c index f783c93..f330374 100644 --- a/arch/powerpc/kernel/traps.c +++ b/arch/powerpc/kernel/traps.c @@ -986,6 +986,13 @@ static int emulate_instruction(struct pt_regs *regs) return 0; } + /* Emulating the lwsync insn as a sync insn */ + if (instword == PPC_INST_LWSYNC) { + PPC_WARN_EMULATED(lwsync, regs); + asm volatile("sync" : : : "memory"); + return 0; + } + /* Emulate the mcrxr insn. */ if ((instword & PPC_INST_MCRXR_MASK) == PPC_INST_MCRXR) { int shift = (instword >> 21) & 0x1c;