From patchwork Wed Feb 8 14:01:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stafford Horne X-Patchwork-Id: 9562589 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9DF40601E5 for ; Wed, 8 Feb 2017 14:02:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E4DC284EF for ; Wed, 8 Feb 2017 14:02:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F4E4284F1; Wed, 8 Feb 2017 14:02:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 519D9284EF for ; Wed, 8 Feb 2017 14:02:03 +0000 (UTC) Received: from localhost ([::1]:59675 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cbSos-0004X7-Sn for patchwork-qemu-devel@patchwork.kernel.org; Wed, 08 Feb 2017 09:02:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43205) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cbSoL-0004VH-NF for qemu-devel@nongnu.org; Wed, 08 Feb 2017 09:01:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cbSoI-0005KU-Mi for qemu-devel@nongnu.org; Wed, 08 Feb 2017 09:01:29 -0500 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:33716) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cbSoI-0005Jv-G1 for qemu-devel@nongnu.org; Wed, 08 Feb 2017 09:01:26 -0500 Received: by mail-pg0-x244.google.com with SMTP id 194so15282379pgd.0 for ; Wed, 08 Feb 2017 06:01:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=pPCVIFulV0dwLiCNJrhK3cvlSZcCHkcinjeaZViA2qo=; b=V6J93GDDowL0oBEepPwo+Nq01x3d7oYjvqBoE92dJ5uxbT+doZ0y7S2m6U1DDps0cy in/aRzfZoy8/Bctbz24O35+pnBEkbgCnRnbqDuFB66ezzHZumVRBZGHIF7jNqlvcirne EsU3RERFS5UK2SvxekJ3x6hWvdyT9pjp1a38QNf57/CGCLFTSSAVv9FMZgVCiOteSjSg LYYJFu9W4ipnlAWTviG0StCtfybtkrrzlO459hniegn5uXyk/N4ftMOWgh6kpm/1kpqL 1eQHoRq/IdHF5JyoeBl/gQIZxn4mVyzwmMB3Tdg9ebxDQEbMgifVSRU5k59cXCWwPFuK Gw+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=pPCVIFulV0dwLiCNJrhK3cvlSZcCHkcinjeaZViA2qo=; b=avIo7GLK6RFhqsMH66UGDmywS2ykuPoj4nOp5xeV0UcdQxb82hSS4U1+iF2KCSg1dD 4kRhx0UrsuuUmee8XrroXlXX8lwVbYA7j5zH0h0jZ4DEw7lilK4DPErfu3UULCvuaI8Y 6/C7CkJAm2FdlzDuD3LmRFKZXsF1sIK7A7C5w5bDMX7DMughICVNxaE7vEHQch29fEhh /+2awup7rz9/A6gAl5evUu1XXFNfcwpwPMmhZCid7dCuEkeuz9FMBGOa8Ja+w1+R35qN jWbWetBxqim1MJ/pR/3kgJeHaqB9KKYbnOGBxzZgsp3oB+9DxvlCHWu5LfAlpP7x+XDU flUw== X-Gm-Message-State: AIkVDXJ/0YoH1xaY6V8FEz9Gkk0SYfJM64OlaC/KKz66RIHvT5aNjz91zq/q+zMdJ6X+5Q== X-Received: by 10.98.74.202 with SMTP id c71mr26433042pfj.28.1486562483915; Wed, 08 Feb 2017 06:01:23 -0800 (PST) Received: from localhost (z192.124-44-186.ppp.wakwak.ne.jp. [124.44.186.192]) by smtp.gmail.com with ESMTPSA id s64sm20831987pfe.27.2017.02.08.06.01.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 08 Feb 2017 06:01:23 -0800 (PST) Date: Wed, 8 Feb 2017 23:01:20 +0900 From: Stafford Horne To: Richard Henderson Message-ID: <20170208140120.GI32144@lianli.shorne-pla.net> References: <20170120163918.GD7836@lianli.shorne-pla.net> <20170124102625.GF7836@lianli.shorne-pla.net> <01f7a18d-f4f5-18f3-0932-b32c06ad0b0c@twiddle.net> <20170125123430.GG7836@lianli.shorne-pla.net> <39f927aa-26fe-0e43-7c6b-efe1b70bc5fa@twiddle.net> <20170126131229.GB16014@lianli.shorne-pla.net> <20170201100423.GE21641@lianli.shorne-pla.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.7.1 (2016-10-04) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::244 Subject: Re: [Qemu-devel] [PATCH] target-openrisc: Fix exception handling status registers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: openrisc@lists.librecores.org, Jia Liu , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP On Mon, Feb 06, 2017 at 09:53:26PM -0800, Richard Henderson wrote: > On 02/01/2017 02:04 AM, Stafford Horne wrote: > > For kernel builds I have created toolchain binaries here: > > > > http://shorne.noip.me/crosstool/files/bin/x86_64/5.4.0/ > > > > These should work. > > This gdb crashes on the first "stepi" that I issue. To reproduce, > > $ cat z.c > int main() { return 0; } > $ or1k-musl-linux-gcc -g z.c > $ qemu-or32 -g 10001 ./a.out > > // another window > > $ or1k-musl-linux-gdb ./a.out > (gdb) target remote localhost:10001 > // should see that the pc is at _start > (gdb) stepi > // crash > > I won't be able to debug this myself until I can build my own gdb. Hello, The gdb branch I use is the following, it is tracking very close to upsstream: git@github.com:stffrdhrn/binutils-gdb.git or1k-upstream I have sent this for review to the gdb list and currently waiting on comments for version 4. Most of the code is the same as in openrisc github. However, I have just rebased and cleaned up for upstreaming. Note, I can get basic programs running fine on your qemu branch using linux-user i.e. $ cat main.c #include int main() { printf("hello"); return 0; } $ or1k-linux-musl-gcc -g -static main.c $ ./qemu/build/or32-linux-user/qemu-or32 ./a.out hello However, when debugging I ran into a few errors. 1. qemu aborts the program and sends SIGILL to gdb, this is caused by the openrisc loop in linux-user missing handlers for EXCP_INTERRUPT and EXCP_DEBUG, I patched that see below: 2. After patching I got 1 step to work then gdb crashes with SIGSEGV Currently looking at it, Interestingly the code that is failing is in gdb/or1k-tdep.c: or1k_single_step_through_delay() cgen_lookup_insn() - returns NULL (shouldnt happen though) then NULL is dereferenced Interesting because it seems you wrote cgen_lookup_insn :) I am investigating more, but it seems like gdb issue. Notes on the debugger: - The support for linux user processes is not implemented. Eventually I think it will crash somewhere. But it shouldnt crash where it is. - I tested the same program with the baremetal (newlib) toolchain * gdb native sim - OK can debug * or1ksim (via target remote) - Crashes same as QEMU -Stafford Patch for qemu issue mentioned in (1) above. From 777bd1c6641ea919799579dfbc99db4338db11bf Mon Sep 17 00:00:00 2001 From: Stafford Horne Date: Wed, 8 Feb 2017 22:20:01 +0900 Subject: [PATCH] linux-user: openrisc: Implement EXCP_INTERRUPT and EXCP_DEBUG These were not implemented. They are required escpecially if we want to debug user processes in openrisc. Signed-off-by: Stafford Horne --- linux-user/main.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/linux-user/main.c b/linux-user/main.c index 94a636f..1c33378 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -2468,6 +2468,7 @@ void cpu_loop(CPUOpenRISCState *env) { CPUState *cs = CPU(openrisc_env_get_cpu(env)); int trapnr, gdbsig; + target_siginfo_t info; abi_long ret; for (;;) { @@ -2542,6 +2543,23 @@ void cpu_loop(CPUOpenRISCState *env) case EXCP_ATOMIC: cpu_exec_step_atomic(cs); break; + case EXCP_INTERRUPT: + /* just indicate that signals should be handled asap */ + break; + case EXCP_DEBUG: + { + int sig; + + sig = gdb_handlesig(cs, TARGET_SIGTRAP); + if (sig) + { + info.si_signo = sig; + info.si_errno = 0; + info.si_code = TARGET_TRAP_BRKPT; + queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info); + } + } + break; default: EXCP_DUMP(env, "\nqemu: unhandled CPU exception %#x - aborting\n", trapnr);