From patchwork Wed Jul 31 14:49:54 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 18707 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f199.google.com (mail-ve0-f199.google.com [209.85.128.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A06CF248E6 for ; Wed, 31 Jul 2013 14:50:03 +0000 (UTC) Received: by mail-ve0-f199.google.com with SMTP id m1sf1040024ves.2 for ; Wed, 31 Jul 2013 07:50:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-removed-original-auth :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:x-google-group-id:list-post:list-help :list-archive:list-unsubscribe; bh=J00QKQzsFWTFrbysjPVZyq9W/HVRFpSM+kwcPR/tBqw=; b=k0/l5fXirVBW+NWUO690JXuPc5jlpcOrX/2TFGTuyTLQXpTwWBprUc6+73OOdxH+uR T7HGQZ64qezin872nVDYnMZ9MPnvBpr1fBGqCyEvtIDL+fu+bjZxWoaL83JCFkljVi8E 8u48EUOWsdN00peESflwCqz14BpayB7E399N/xslC85J0Q0nHP1yPZ5pcZ1WRztm5VOT hwH1h69TuASsWdvr1Xf9gckP8LuCzxOd23ve41IoisqyziLynz4Se73nOLZpg8jr9PUC ZN/M5PSokwHIFX7/XHoZE3PP3qCFAb1h41KtetQP5Kk2QiS4nJ8DpDLVp724cqoAIuiP fOSw== X-Received: by 10.236.140.40 with SMTP id d28mr23073023yhj.24.1375282203201; Wed, 31 Jul 2013 07:50:03 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.106.195 with SMTP id gw3ls709993qeb.64.gmail; Wed, 31 Jul 2013 07:50:03 -0700 (PDT) X-Received: by 10.220.182.193 with SMTP id cd1mr11808849vcb.32.1375282203063; Wed, 31 Jul 2013 07:50:03 -0700 (PDT) Received: from mail-ve0-f174.google.com (mail-ve0-f174.google.com [209.85.128.174]) by mx.google.com with ESMTPS id zw14si367192veb.102.2013.07.31.07.50.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 31 Jul 2013 07:50:02 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.174; Received: by mail-ve0-f174.google.com with SMTP id d10so864429vea.5 for ; Wed, 31 Jul 2013 07:50:02 -0700 (PDT) X-Received: by 10.52.180.229 with SMTP id dr5mr3991590vdc.20.1375282202780; Wed, 31 Jul 2013 07:50:02 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.11.8 with SMTP id pc8csp240829vcb; Wed, 31 Jul 2013 07:50:02 -0700 (PDT) X-Received: by 10.180.92.1 with SMTP id ci1mr4586813wib.14.1375282201664; Wed, 31 Jul 2013 07:50:01 -0700 (PDT) Received: from mail-wi0-f170.google.com (mail-wi0-f170.google.com [209.85.212.170]) by mx.google.com with ESMTPS id zb6si948980wjc.124.2013.07.31.07.50.01 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 31 Jul 2013 07:50:01 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.170 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=209.85.212.170; Received: by mail-wi0-f170.google.com with SMTP id hi8so3696976wib.3 for ; Wed, 31 Jul 2013 07:50:01 -0700 (PDT) X-Received: by 10.180.105.71 with SMTP id gk7mr1523506wib.1.1375282201052; Wed, 31 Jul 2013 07:50:01 -0700 (PDT) Received: from belegaer.uk.xensource.com. (firewall.ctxuk.citrix.com. [46.33.159.2]) by mx.google.com with ESMTPSA id b13sm15773911wic.9.2013.07.31.07.49.59 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 31 Jul 2013 07:50:00 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org, ian.campbell@citrix.com Cc: stefano.stabellini@eu.citrix.com, patches@linaro.org, tim@xen.org, Julien Grall Subject: [PATCH v3 1/2] xen/arm: Start to implement an ARM decoder instruction Date: Wed, 31 Jul 2013 15:49:54 +0100 Message-Id: <1375282195-21653-2-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1375282195-21653-1-git-send-email-julien.grall@linaro.org> References: <1375282195-21653-1-git-send-email-julien.grall@linaro.org> X-Gm-Message-State: ALoCoQllnlQcwAbUvE4Jwp7NXXF1Sa0LW/PqBkJm3x6mSilH7EacIDilvjTFLD3YMco/jo1vcXPB X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Some erratas on ARM processor requires to decode the instruction. The decoder will, obviously, decode and fill the ISS fields of the hsr_dabt. For the moment, the decoder only supports: - THUMB2 store instruction - THUMB single load/store instruction Signed-off-by: Julien Grall --- xen/arch/arm/Makefile | 1 + xen/arch/arm/decode.c | 143 +++++++++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/decode.h | 38 +++++++++++++ 3 files changed, 182 insertions(+) create mode 100644 xen/arch/arm/decode.c create mode 100644 xen/arch/arm/decode.h diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 5ae5831..5c13a65 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -30,6 +30,7 @@ obj-y += vtimer.o obj-y += vpl011.o obj-y += hvm.o obj-y += device.o +obj-y += decode.o #obj-bin-y += ....o diff --git a/xen/arch/arm/decode.c b/xen/arch/arm/decode.c new file mode 100644 index 0000000..e432d2a --- /dev/null +++ b/xen/arch/arm/decode.c @@ -0,0 +1,143 @@ +/* + * xen/arch/arm/decode.c + * + * Instruction decoder + * + * Julien Grall + * Copyright (C) 2013 Linaro Limited. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + */ + +#include +#include +#include +#include +#include + +#include "decode.h" + +/* TODO: Handle all THUMB2 instruction other than simple store */ +static int decode_thumb2(register_t pc, struct hsr_dabt *dabt, uint16_t hw1) +{ + uint16_t hw2; + int rc; + uint16_t op1, op2, op; + + rc = raw_copy_from_guest(&hw2, (void *__user)(pc + 2), sizeof (hw2)); + if ( rc ) + return rc; + + /* See A6.3 of DDI 0406C.b */ + op1 = (hw1 >> 11) & 0x3; + op2 = (hw1 >> 4) & 0x7f; + op = hw2 >> 15; + + if ( op1 == 3 && ((op2 & 0x71) == 0x00) ) + { + /* Store single data item */ + dabt->reg = (hw2 >> 12) & 0x7; + /* TODO: Handle access size */ + return 0; + } + + printk("DOM%u: unhandled THUMB2 instruction 0x%x%x\n", + current->domain->domain_id, hw1, hw2); + + return 1; +} + +/* TODO: Handle all THUMB instructions other than store */ +static int decode_thumb(register_t pc, struct hsr_dabt *dabt) +{ + uint16_t instr; + int rc; + + rc = raw_copy_from_guest(&instr, (void * __user)pc, sizeof (instr)); + if ( rc ) + return rc; + + switch ( instr >> 12 ) + { + case 5: + { + /* Load/Store register */ + uint16_t opB = (instr >> 9) & 0x7; + + switch ( opB & 0x3 ) + { + case 0: + dabt->size = 2; + break; + case 1: + dabt->size = 1; + break; + case 3: + dabt->sign = 1; + /* Fall-through */ + case 2: + dabt->size = 0; + break; + } + + dabt->reg = instr & 7; + + break; + } + case 6: + /* Load/Store word immediate offset */ + dabt->size = 2; + dabt->reg = instr & 7; + break; + case 7: + /* Load/Store byte immediate offset */ + dabt->size = 0; + dabt->reg = instr & 7; + break; + case 8: + /* Load/Store halfword immediate offset */ + dabt->size = 1; + dabt->reg = instr & 7; + break; + case 9: + /* Load/Store word sp offset */ + dabt->size = 2; + dabt->reg = (instr >> 8) & 7; + break; + case 14: + if ( instr & (1 << 11) ) + return decode_thumb2(pc, dabt, instr); + goto bad_thumb; + case 15: + return decode_thumb2(pc, dabt, instr); + default: + goto bad_thumb; + } + + return 0; + +bad_thumb: + printk("DOM%u: unhandled THUMB instruction 0x%x\n", + current->domain->domain_id, instr); + return 1; +} + +int decode_instruction(const struct cpu_user_regs *regs, struct hsr_dabt *dabt) +{ + /* XXX: zeroed ISS when decode will be fully implemented */ + + if ( regs->cpsr & PSR_THUMB ) + return decode_thumb(regs->pc, dabt); + + /* TODO: Handle ARM instruction */ + + return 1; +} diff --git a/xen/arch/arm/decode.h b/xen/arch/arm/decode.h new file mode 100644 index 0000000..dc130a3 --- /dev/null +++ b/xen/arch/arm/decode.h @@ -0,0 +1,38 @@ +/* + * xen/arch/arm/decode.h + * + * Instruction decoder + * + * Julien Grall + * Copyright (C) 2013 Linaro Limited. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + */ + +#ifndef __ARCH_ARM_DECODE_H_ +#define __ARCH_ARM_DECODE_H_ + +#include +#include + +int decode_instruction(const struct cpu_user_regs *regs, + struct hsr_dabt *dabt); + +#endif /* __ARCH_ARM_DECODE_H_ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */