From nobody Sat May 4 23:25:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1494632285398599.268247494469; Fri, 12 May 2017 16:38:05 -0700 (PDT) Received: from localhost ([::1]:55665 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9K8K-0007N6-28 for importer@patchew.org; Fri, 12 May 2017 19:38:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43646) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9K6m-0006LM-S8 for qemu-devel@nongnu.org; Fri, 12 May 2017 19:36:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d9K6i-0007qf-Cv for qemu-devel@nongnu.org; Fri, 12 May 2017 19:36:28 -0400 Received: from mail-lf0-x242.google.com ([2a00:1450:4010:c07::242]:36594) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d9K6i-0007q5-5z; Fri, 12 May 2017 19:36:24 -0400 Received: by mail-lf0-x242.google.com with SMTP id h4so1188986lfj.3; Fri, 12 May 2017 16:36:24 -0700 (PDT) Received: from octofox.metropolis ([5.19.183.212]) by smtp.gmail.com with ESMTPSA id n79sm796790lfi.53.2017.05.12.16.36.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 May 2017 16:36:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=twuKJWiR3/yK+bOmrKiYcpmHKmVnugQVZrIeynHiI8g=; b=WsdCks7I3cPljkh84HJlVFo2Ww7A2myQx4HqYBlvLYYvM/jsG24tSWe+x81IBjzY5N H1Fx0++cGYbZ0KJDt4Oe2L5b9AUYFokRwZR8Ox4gcDg3ZMSFqFY/1RNmxxCc1BQYGhOI IPDmFa80A9tpfc1N/DAVdbPFpkVJwsk5I9+PLHDGdhs/3/p6UZNrXGY094BkAZcT9FDx gy+9tSiH+IH6t7saWEnwavHk/ZzzplvWgGlAMQoM9rMaSYNDcAskR0riAEW+XoMKGgFr V5H7aAwVClLdNCiWG3k/dOPXQJZaPlqPHEL7+iZrJG5ulPCh1zqrIf+0AD83oh8irZCc 97tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=twuKJWiR3/yK+bOmrKiYcpmHKmVnugQVZrIeynHiI8g=; b=l5tQyz0t9H58ulP4UH7BLquZz89hndm2J3wBc9Drwwk6kXzOuMDNmI3Owj4/E6aATS noHt0VP43ji2tbrZBnz+v5Kw5zF86ps2J1WfnkJJQT7jId9BWdNClKvxVhLgsQg/qNtl twdXlmDKVdEhXGJFILTuYFzs6moTWJsBZnHQ/iNztthWEPXiti0fkpWX1BJXAsmLln9r VO+jTdoXI7hmt9ij/eflLNHMhNtxW+kspGUdhF121nz6JQ9tC/xSQe2AfjIGivEPFcBZ WX5h2LeJWlE7w2hrJv84SXwNw5HsU7U7mc8b/cWuVjB2ucaSxHZcIC90DbIMypHq0nFa 4lTg== X-Gm-Message-State: AODbwcCq3bhG0EfTBzm73k59g9MoIhEz/sf0FbdF0OAWQKqLNaGr6ShR w4QtxsM3MPkizQ== X-Received: by 10.25.154.130 with SMTP id c124mr2273338lfe.71.1494632182870; Fri, 12 May 2017 16:36:22 -0700 (PDT) From: Max Filippov To: qemu-devel@nongnu.org Date: Fri, 12 May 2017 16:36:02 -0700 Message-Id: <1494632164-23799-2-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1494632164-23799-1-git-send-email-jcmvbkbc@gmail.com> References: <1494632164-23799-1-git-send-email-jcmvbkbc@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::242 Subject: [Qemu-devel] [PATCH 1/3] target/xtensa: fix mapping direction in read/write simcalls 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: Max Filippov , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Read and write simcalls map physical memory to access I/O buffers, but 'read' simcall need to map it for writing and 'write' simcall need to map it for reading, i.e. the opposite of what they do now. Fix that. Cc: qemu-stable@nongnu.org Signed-off-by: Max Filippov --- target/xtensa/xtensa-semi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/xtensa/xtensa-semi.c b/target/xtensa/xtensa-semi.c index a888a9d..98ae28c 100644 --- a/target/xtensa/xtensa-semi.c +++ b/target/xtensa/xtensa-semi.c @@ -173,7 +173,7 @@ void HELPER(simcall)(CPUXtensaState *env) TARGET_PAGE_SIZE - (vaddr & (TARGET_PAGE_SIZE - 1)); uint32_t io_sz =3D page_left < len ? page_left : len; hwaddr sz =3D io_sz; - void *buf =3D cpu_physical_memory_map(paddr, &sz, is_write= ); + void *buf =3D cpu_physical_memory_map(paddr, &sz, !is_writ= e); =20 if (buf) { vaddr +=3D io_sz; @@ -182,7 +182,7 @@ void HELPER(simcall)(CPUXtensaState *env) write(fd, buf, io_sz) : read(fd, buf, io_sz); regs[3] =3D errno_h2g(errno); - cpu_physical_memory_unmap(buf, sz, is_write, sz); + cpu_physical_memory_unmap(buf, sz, !is_write, sz); if (regs[2] =3D=3D -1) { break; } --=20 2.1.4 From nobody Sat May 4 23:25:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1494632284953196.97677921450975; Fri, 12 May 2017 16:38:04 -0700 (PDT) Received: from localhost ([::1]:55664 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9K8J-0007Kr-2a for importer@patchew.org; Fri, 12 May 2017 19:38:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43647) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9K6m-0006LN-S6 for qemu-devel@nongnu.org; Fri, 12 May 2017 19:36:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d9K6k-0007rm-6q for qemu-devel@nongnu.org; Fri, 12 May 2017 19:36:28 -0400 Received: from mail-lf0-x243.google.com ([2a00:1450:4010:c07::243]:36594) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d9K6j-0007r2-Vm; Fri, 12 May 2017 19:36:26 -0400 Received: by mail-lf0-x243.google.com with SMTP id h4so1189015lfj.3; Fri, 12 May 2017 16:36:25 -0700 (PDT) Received: from octofox.metropolis ([5.19.183.212]) by smtp.gmail.com with ESMTPSA id n79sm796790lfi.53.2017.05.12.16.36.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 May 2017 16:36:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sCjDPYQKWj+P1yzZnsSXmqd4QP6dOWyYcYNIk/6aLc8=; b=hCnoFw8UdUkzBXtK+vrQs89rCauPrQkHkAwFaQDfFVOiprcJ/JVK/mQj3zqC2iinSa ou2VyxiWRmP0Vs6AsIureRI/UeLq9no4DP3LQYGY4NkwzqdRv/SvFYYfVuYNn/jQ8iTp dcn1EusixS2QKSMIZ1tbjfzTg1fRrksXJJxzMZRy252egbAmps0uFHIYY7swXpaly3To r4PdrzbsAArdjgno/afhjRqqCxUAWqEhZWGlXiySHA6Bo4nkzT/xKLQQN7iALlebz/q4 Fn+C5MMDf06ktdX0LPsVsFr81bj3yTt9HaZNMFRaP99lQrh15cQgGW8hl2XUatF6vw8x GKuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sCjDPYQKWj+P1yzZnsSXmqd4QP6dOWyYcYNIk/6aLc8=; b=RTUNndO5zNAWKGLteQnNYUI/9o6hT7uyn4bs4lOHuS8EVAoove8yFZv3tOaXAYhMQ8 pDGMQnVG9GkXc+u4D/xQnD2SYYlWbfkKI3LGuAdmV1EFYN3wdwMKOPKoGtVOs42yl4lg cGXrUS1n6mrM+B22u2lCx+f56orRssCmAOZN4Q5VrGwtE+/PtZXCFX/1tuhtXttQu0ht a54JKfJQtH2ykQmdjXQZ7HiTrAYwyGe1UtqfiB27vYxkHaBJjabAxIuf0/9gjD3VjVVg k4HJVhd5zTQIG2iF6XESoeVfXhi7sapbYu3coKQ0631mRqXhhPyFdoxPv+rxJ7iS8XBp QxMA== X-Gm-Message-State: AODbwcBF5dCyOq8ACtSMtBQxcyvcfLN2lCsWKmvHNXC+6VSz+f+sQAro iIZOyudlYJbUIA== X-Received: by 10.25.35.87 with SMTP id j84mr2421541lfj.118.1494632184806; Fri, 12 May 2017 16:36:24 -0700 (PDT) From: Max Filippov To: qemu-devel@nongnu.org Date: Fri, 12 May 2017 16:36:03 -0700 Message-Id: <1494632164-23799-3-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1494632164-23799-1-git-send-email-jcmvbkbc@gmail.com> References: <1494632164-23799-1-git-send-email-jcmvbkbc@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::243 Subject: [Qemu-devel] [PATCH 2/3] target/xtensa: fix return value of read/write simcalls 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: Max Filippov , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Return value of read/write simcalls is not calculated correctly in case of operations crossing page boundary and in case of short reads/writes. Read and write simcalls should return the size of data actually read/written or -1 in case of error. Cc: qemu-stable@nongnu.org Signed-off-by: Max Filippov --- target/xtensa/xtensa-semi.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/target/xtensa/xtensa-semi.c b/target/xtensa/xtensa-semi.c index 98ae28c..ffcaf8d 100644 --- a/target/xtensa/xtensa-semi.c +++ b/target/xtensa/xtensa-semi.c @@ -166,6 +166,7 @@ void HELPER(simcall)(CPUXtensaState *env) uint32_t fd =3D regs[3]; uint32_t vaddr =3D regs[4]; uint32_t len =3D regs[5]; + uint32_t len_done =3D 0; =20 while (len > 0) { hwaddr paddr =3D cpu_get_phys_page_debug(cs, vaddr); @@ -174,24 +175,38 @@ void HELPER(simcall)(CPUXtensaState *env) uint32_t io_sz =3D page_left < len ? page_left : len; hwaddr sz =3D io_sz; void *buf =3D cpu_physical_memory_map(paddr, &sz, !is_writ= e); + uint32_t io_done; + bool error =3D false; =20 if (buf) { vaddr +=3D io_sz; len -=3D io_sz; - regs[2] =3D is_write ? + io_done =3D is_write ? write(fd, buf, io_sz) : read(fd, buf, io_sz); regs[3] =3D errno_h2g(errno); - cpu_physical_memory_unmap(buf, sz, !is_write, sz); - if (regs[2] =3D=3D -1) { - break; + if (io_done =3D=3D -1) { + error =3D true; + io_done =3D 0; } + cpu_physical_memory_unmap(buf, sz, !is_write, io_done); } else { - regs[2] =3D -1; + error =3D true; regs[3] =3D TARGET_EINVAL; break; } + if (error) { + if (!len_done) { + len_done =3D -1; + } + break; + } + len_done +=3D io_done; + if (io_done < io_sz) { + break; + } } + regs[2] =3D len_done; } break; =20 --=20 2.1.4 From nobody Sat May 4 23:25:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1494632411306133.3747163161537; Fri, 12 May 2017 16:40:11 -0700 (PDT) Received: from localhost ([::1]:55673 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9KAL-0000fz-UJ for importer@patchew.org; Fri, 12 May 2017 19:40:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43672) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9K6n-0006LV-S6 for qemu-devel@nongnu.org; Fri, 12 May 2017 19:36:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d9K6m-0007tl-GW for qemu-devel@nongnu.org; Fri, 12 May 2017 19:36:29 -0400 Received: from mail-lf0-x243.google.com ([2a00:1450:4010:c07::243]:35176) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d9K6l-0007sQ-U4 for qemu-devel@nongnu.org; Fri, 12 May 2017 19:36:28 -0400 Received: by mail-lf0-x243.google.com with SMTP id 99so1192952lfu.2 for ; Fri, 12 May 2017 16:36:27 -0700 (PDT) Received: from octofox.metropolis ([5.19.183.212]) by smtp.gmail.com with ESMTPSA id n79sm796790lfi.53.2017.05.12.16.36.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 May 2017 16:36:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nps4SenmXQBWRJjFI/xCn8AV23qrpKf7SFIlbumP/Xg=; b=mhkpIiyrWLOeddPfQWuRx36WrQiDZ9BgEHoow/7EC27/EY4+64GbbBryqF2JVmUi1y B7R1LYSkf6A4CNW0E1ySRyfGLwKa6ntFWWr+U+vGKGhJiL4xm0f7iMvYKS6RAvJjFpZH 6fdBu+qwRxuCLgaypzc7fSkiGmWjdieR4Zfrr7qyPnMC8wHlM67KZK87flJff7U6HRBg st9D/J8C+073ZL2ZHLYToPpzf1tMSHPgC16uKoiiWVsHU7Agy+J/tpwOaR0w9ZG65noK A6FTtVjbOqyLxoWhRjCEbcjgSIpt0Nt9B68VMdQUSmLRX7j3DfT2wUBGLxI+MQlPf/Re +nNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nps4SenmXQBWRJjFI/xCn8AV23qrpKf7SFIlbumP/Xg=; b=Oy7n/eI+b0s2Q2k1nEI6MHZFo6CkX6rvOJJdgiJei2i05SJJNu6ZpaY3j6ZL6xTWqK ly/5AEi2GA5Oog7q5+E6tnzHHUD4eIfrGFxRPi46K4fiz84ov8kxGzRKP6V5//yTTAPL Rs9ozcRw3CimieMvBOW5IMss8f25gI5zkhzfCAVTBsmhGVJSbGvVJSBwza8AD/tWA99K biKw8l0F+Y4NvmZINGOIjNySkNDHjq8TFxI4GNcZq3MuuJ0Bh1XZKV8FJUXd0wE42lIy 3JG6VmwgQHxX3hMbiePogccct/XyIpyGNbe9RYeyP4gTh/aF6DXObhOXO7nNJtWd5TqQ 4QHg== X-Gm-Message-State: AODbwcCIqT9iE/bCE7Qb6DuAFO/yzkdFSRsOFZA4xZQfXuYQWbLlBuAn BhKxDXISgzyJfg== X-Received: by 10.46.5.199 with SMTP id 190mr2130927ljf.3.1494632186682; Fri, 12 May 2017 16:36:26 -0700 (PDT) From: Max Filippov To: qemu-devel@nongnu.org Date: Fri, 12 May 2017 16:36:04 -0700 Message-Id: <1494632164-23799-4-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1494632164-23799-1-git-send-email-jcmvbkbc@gmail.com> References: <1494632164-23799-1-git-send-email-jcmvbkbc@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::243 Subject: [Qemu-devel] [PATCH 3/3] target/xtensa: support output to chardev console 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: Max Filippov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In semihosting mode QEMU allows guest to read and write host file descriptors directly, including descriptors 0..2, a.k.a. stdin, stdout and stderr. Sometimes it's desirable to have semihosting console controlled by -serial option, e.g. to connect it to network. Add semihosting console to xtensa-semi.c, open it in the 'sim' machine in the presence of -serial option and direct stdout and stderr to it when it's present. Signed-off-by: Max Filippov --- hw/xtensa/sim.c | 4 +++ target/xtensa/cpu.h | 1 + target/xtensa/xtensa-semi.c | 66 +++++++++++++++++++++++++++++++++++------= ---- 3 files changed, 57 insertions(+), 14 deletions(-) diff --git a/hw/xtensa/sim.c b/hw/xtensa/sim.c index b27e28d..5521e91 100644 --- a/hw/xtensa/sim.c +++ b/hw/xtensa/sim.c @@ -114,6 +114,9 @@ static void xtensa_sim_init(MachineState *machine) xtensa_create_memory_regions(&sysram, "xtensa.sysram"); } =20 + if (serial_hds[0]) { + xtensa_sim_open_console(serial_hds[0]); + } if (kernel_filename) { uint64_t elf_entry; uint64_t elf_lowaddr; @@ -136,6 +139,7 @@ static void xtensa_sim_machine_init(MachineClass *mc) mc->is_default =3D true; mc->init =3D xtensa_sim_init; mc->max_cpus =3D 4; + mc->no_serial =3D 1; } =20 DEFINE_MACHINE("sim", xtensa_sim_machine_init) diff --git a/target/xtensa/cpu.h b/target/xtensa/cpu.h index ecca17d..ee29fb1 100644 --- a/target/xtensa/cpu.h +++ b/target/xtensa/cpu.h @@ -483,6 +483,7 @@ void xtensa_translate_init(void); void xtensa_breakpoint_handler(CPUState *cs); void xtensa_finalize_config(XtensaConfig *config); void xtensa_register_core(XtensaConfigList *node); +void xtensa_sim_open_console(Chardev *chr); void check_interrupts(CPUXtensaState *s); void xtensa_irq_init(CPUXtensaState *env); void *xtensa_get_extint(CPUXtensaState *env, unsigned extint); diff --git a/target/xtensa/xtensa-semi.c b/target/xtensa/xtensa-semi.c index ffcaf8d..01c622e 100644 --- a/target/xtensa/xtensa-semi.c +++ b/target/xtensa/xtensa-semi.c @@ -29,7 +29,12 @@ #include "cpu.h" #include "exec/helper-proto.h" #include "exec/semihost.h" +#include "qapi/error.h" #include "qemu/log.h" +#include "sysemu/char.h" +#include "sysemu/sysemu.h" + +static CharBackend *xtensa_sim_console; =20 enum { TARGET_SYS_exit =3D 1, @@ -148,6 +153,15 @@ static uint32_t errno_h2g(int host_errno) } } =20 +void xtensa_sim_open_console(Chardev *chr) +{ + static CharBackend console; + + qemu_chr_fe_init(&console, chr, &error_abort); + qemu_chr_fe_set_handlers(&console, NULL, NULL, NULL, NULL, NULL, true); + xtensa_sim_console =3D &console; +} + void HELPER(simcall)(CPUXtensaState *env) { CPUState *cs =3D CPU(xtensa_env_get_cpu(env)); @@ -181,10 +195,25 @@ void HELPER(simcall)(CPUXtensaState *env) if (buf) { vaddr +=3D io_sz; len -=3D io_sz; - io_done =3D is_write ? - write(fd, buf, io_sz) : - read(fd, buf, io_sz); - regs[3] =3D errno_h2g(errno); + if (fd < 3 && xtensa_sim_console) { + if (is_write && (fd =3D=3D 1 || fd =3D=3D 2)) { + io_done =3D qemu_chr_fe_write_all(xtensa_sim_c= onsole, + buf, io_sz); + regs[3] =3D errno_h2g(errno); + } else { + qemu_log_mask(LOG_GUEST_ERROR, + "%s fd %d is not supported with = chardev console\n", + is_write ? + "writing to" : "reading from", f= d); + io_done =3D -1; + regs[3] =3D TARGET_EBADF; + } + } else { + io_done =3D is_write ? + write(fd, buf, io_sz) : + read(fd, buf, io_sz); + regs[3] =3D errno_h2g(errno); + } if (io_done =3D=3D -1) { error =3D true; io_done =3D 0; @@ -256,10 +285,6 @@ void HELPER(simcall)(CPUXtensaState *env) uint32_t target_tvv[2]; =20 struct timeval tv =3D {0}; - fd_set fdset; - - FD_ZERO(&fdset); - FD_SET(fd, &fdset); =20 if (target_tv) { cpu_memory_rw_debug(cs, target_tv, @@ -267,12 +292,25 @@ void HELPER(simcall)(CPUXtensaState *env) tv.tv_sec =3D (int32_t)tswap32(target_tvv[0]); tv.tv_usec =3D (int32_t)tswap32(target_tvv[1]); } - regs[2] =3D select(fd + 1, - rq =3D=3D SELECT_ONE_READ ? &fdset : NULL, - rq =3D=3D SELECT_ONE_WRITE ? &fdset : NULL, - rq =3D=3D SELECT_ONE_EXCEPT ? &fdset : NULL, - target_tv ? &tv : NULL); - regs[3] =3D errno_h2g(errno); + if (fd < 3 && xtensa_sim_console) { + if ((fd =3D=3D 1 || fd =3D=3D 2) && rq =3D=3D SELECT_ONE_W= RITE) { + regs[2] =3D 1; + } else { + regs[2] =3D 0; + } + regs[3] =3D 0; + } else { + fd_set fdset; + + FD_ZERO(&fdset); + FD_SET(fd, &fdset); + regs[2] =3D select(fd + 1, + rq =3D=3D SELECT_ONE_READ ? &fdset : NU= LL, + rq =3D=3D SELECT_ONE_WRITE ? &fdset : NU= LL, + rq =3D=3D SELECT_ONE_EXCEPT ? &fdset : NU= LL, + target_tv ? &tv : NULL); + regs[3] =3D errno_h2g(errno); + } } break; =20 --=20 2.1.4