From patchwork Fri Jan 13 13:39:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 641945 Delivered-To: patch@linaro.org Received: by 2002:a17:522:f3c4:b0:4b4:3859:abed with SMTP id in4csp214526pvb; Fri, 13 Jan 2023 05:55:10 -0800 (PST) X-Google-Smtp-Source: AMrXdXscm7xcKwzNKaQMGIa7/Y4+snXQsjwAIrJCdrifmJbuqbcutBlAz6NkUoRDL69F5MF796Ec X-Received: by 2002:a05:6214:176a:b0:534:2b06:2d7 with SMTP id et10-20020a056214176a00b005342b0602d7mr10362730qvb.47.1673618109754; Fri, 13 Jan 2023 05:55:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673618109; cv=none; d=google.com; s=arc-20160816; b=JRzYga4g8/k+Ata9tJ+hIgDB2TzNaD3FR9qu+qcazp1gUuzBECuhVfBkRMXCFo29X4 5kxnfhu9YxuUEFH9HWMbV4OLP8rC6DnO+gKZgobFNhtsGzC6ySZpPHGzMrEprJdsfVic x2VUAIpIb7Y0MTX8a0ArugKa2EjbJYczv3N0ibQdQn1wiLnvv8K9pR79vV7szgVZ/hkK DnqNhzYe3Q4ax/SfNTWu/4OvZA5r5cBpoC6ASkabOd1gjTPuknh3kgqzyQu2CAfB/Rz/ d3jeFR0f6KVj9coDlhv6rbn+r8nzdpyPyiwuFCziR9KO0CmFLZwT1Re2La+aRd0EoLMX GxBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iH1g5BvDblNdu81W4rW5xEHawJ+gs3U9vzCLE7pUyII=; b=UoiGpDmy/EjSF9JB/u5t0TC2gsFgdo/bymbCH1qYEw9MC/FcexTCNe5bdOt/IwfTEz 1OyKgYJFqbRPXLeBLlaiQ4cme9i185n47XsJagKj6EUFrCzhutwrbvelwksVN6Zn6qPG fj8ZPSPkCtEZmMtzn2dnmZpYf9cptGH3LONpZ0J+RXa8fOtxgo/sJvpk8mD0ygX7q68W FWWwFFz/h4SjjqV5HxXvPhAGASRKEQSTnKorLn9yUV+qnOakH+eVkU7QwwFfwG2QtCc3 L0dOLRheJAmTl8tqcTEdcNIbXmy1g2aIN66D9R/YSivUiMY9bzgtEVvbGHfxyw+NGf5X 5ryA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M61bcgJs; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v5-20020a372f05000000b00705cb0f9d74si6280264qkh.411.2023.01.13.05.55.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Jan 2023 05:55:09 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M61bcgJs; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pGKHN-0007rh-Gl; Fri, 13 Jan 2023 08:39:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pGKHK-0007pa-FM for qemu-devel@nongnu.org; Fri, 13 Jan 2023 08:39:30 -0500 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pGKHI-000539-75 for qemu-devel@nongnu.org; Fri, 13 Jan 2023 08:39:30 -0500 Received: by mail-wm1-x331.google.com with SMTP id m3so15308489wmq.0 for ; Fri, 13 Jan 2023 05:39:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iH1g5BvDblNdu81W4rW5xEHawJ+gs3U9vzCLE7pUyII=; b=M61bcgJsCdi69o8BCb38mAr787MzdVz3EH30l4UmtN05bnkSiIxVuraCAoECjg5Azn gRHe7iGABN1SwUPnIqOfOnciQprWL0wzEagylDWxDHEvpzvLF/yASoIt02fR+nM39/Aq OEyuuyFEoPo/CXnknWL6qvjyH9NfcoQCjYogPLpElnJDhv6coTgs1wrKcfqZ0DGK55SR ZCtv3WsiBFLOpQ4mRrLmR26ZfziBJ11dQCd4pZ2JKCLr7JPnxQYi66O5xMYA3J2k7ne1 hRI3yacC/Ol+TS/cMOiPrUfvSxiUT6Qw2qO9Mg7ZPqZnrMFpN+U4MMLf5km0ZRfuSijS ok3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iH1g5BvDblNdu81W4rW5xEHawJ+gs3U9vzCLE7pUyII=; b=KhyuOPfxlwmg4tJDJ2Zc4vrF5n9ojubFwPWezao/0LfAeCDH/RePtOj82ty27mMM2b dinGmpemu2f6AxLdxnf1nrkzVNP+7FFmUQtS8hJodLeZLpNyiPhpA0NSOiaHFhcwgQcu JQB8lJYxXQB1vEj14c4813hHmZH9OQUvZ4e7VzyYD2R0t2kdcsHMNNVJjqxFvj0pALJU 4Q/e4DUswmqnvERwci1TFivUtJtHaFeUN0JEM8cE+uYweiIZMmcJLwAQoq2nAB8fuyy+ 2Mbp9RJjMXgHcYynzXWe388RhJK4e8BucpB2H3pozcEiuCwbX+Rts5wuM3794zOSMBXw beMA== X-Gm-Message-State: AFqh2kpF1YdH89tPd7M/1Y1SM9wXSxmH5zQb0RHA8RZpMLf/EAmoyVfj VY2KYSmTh7yqNYLWFqh9+GWEIg== X-Received: by 2002:a05:600c:358a:b0:3cf:8d51:1622 with SMTP id p10-20020a05600c358a00b003cf8d511622mr59469648wmq.1.1673617166853; Fri, 13 Jan 2023 05:39:26 -0800 (PST) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id n14-20020a05600c3b8e00b003b49bd61b19sm33546346wms.15.2023.01.13.05.39.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 05:39:25 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id B78621FFBB; Fri, 13 Jan 2023 13:39:23 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Alexandre Iooss , peter.maydell@linaro.org, Markus Armbruster , Mahmoud Mandour , =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson , John G Johnson , Elena Ufimtseva , Paolo Bonzini , Jagannathan Raman Subject: [PATCH 3/4] semihosting: add semihosting section to the docs Date: Fri, 13 Jan 2023 13:39:22 +0000 Message-Id: <20230113133923.1642627-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230113133923.1642627-1-alex.bennee@linaro.org> References: <20230113133923.1642627-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x331.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org The main reason to do this is to document our O_BINARY implementation decision somewhere. However I've also moved some of the implementation details out of qemu-options and added links between the two. As a bonus I've highlighted the scary warnings about host access with the appropriate RST tags. Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée --- v2 - moved inside the generic emulation section --- docs/about/emulation.rst | 80 ++++++++++++++++++++++++++++++++++++++++ qemu-options.hx | 27 +++++--------- 2 files changed, 90 insertions(+), 17 deletions(-) diff --git a/docs/about/emulation.rst b/docs/about/emulation.rst index d919175b5e..4d978e697b 100644 --- a/docs/about/emulation.rst +++ b/docs/about/emulation.rst @@ -101,3 +101,83 @@ depending on the guest architecture. A number of features are are only available when running under emulation including :ref:`Record/Replay` and :ref:`TCG Plugins`. + +.. _Semihosting: + +Semihosting +----------- + +Semihosting is a feature provided by a number of guests that allow the +program running on the target to interact with the host system. On +real hardware this is usually provided by a debugger hooked directly +to the system. + +Generally semihosting makes it easier to bring up low level code before a +more fully functional operating system has been enabled. On QEMU it +also allows for embedded micro-controller code which typically doesn't +have a full libc to be run as "bare-metal" code under QEMU's user-mode +emulation. It is also useful for writing test cases and indeed a +number of compiler suites as well as QEMU itself use semihosting calls +to exit test code while reporting the success state. + +Semihosting is only available using TCG emulation. This is because the +instructions to trigger a semihosting call are typically reserved +causing most hypervisors to trap and fault on them. + +.. warning:: + Semihosting inherently bypasses any isolation there may be between + the guest and the host. As a result a program using semihosting can + happily trash your host system. You should only ever run trusted + code with semihosting enabled. + +Redirection +~~~~~~~~~~~ + +Semihosting calls can be re-directed to a (potentially remote) gdb +during debugging via the :ref:`gdbstub`. Output to the +semihosting console is configured as a ``chardev`` so can be +redirected to a file, pipe or socket like any other ``chardev`` +device. + +See :ref:`Semihosting Options` for details. + +Supported Targets +~~~~~~~~~~~~~~~~~ + +Most targets offer a similar semihosting implementations with some +minor changes to define the appropriate instruction to encode the +semihosting call and which registers hold the parameters. They tend to +presents a simple POSIX-like API which allows your program to read and +write files, access the console and some other basic interactions. + +.. note:: + QEMU makes an implementation decision to implement all file access + in ``O_BINARY`` mode regardless of the host operating system. This + is because gdb semihosting support doesn't make the distinction + between the modes and magically processing line endings can be confusing. + +.. list-table:: Guest Architectures supporting Semihosting + :widths: 10 10 80 + :header-rows: 1 + + * - Architecture + - Modes + - Specification + * - Arm + - System and User-mode + - https://github.com/ARM-software/abi-aa/blob/main/semihosting/semihosting.rst + * - m68k + - System + - https://sourceware.org/git/?p=newlib-cygwin.git;a=blob;f=libgloss/m68k/m68k-semi.txt;hb=HEAD + * - mips + - System + - Unified Hosting Interface (MD01069) + * - Nios II + - System + - https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=libgloss/nios2/nios2-semi.txt;hb=HEAD + * - RISC-V + - System and User-mode + - https://github.com/riscv/riscv-semihosting-spec/blob/main/riscv-semihosting-spec.adoc + * - Xtensa + - System + - Tensilica ISS SIMCALL diff --git a/qemu-options.hx b/qemu-options.hx index 3aa3a2f5a3..de3a368f58 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4633,10 +4633,13 @@ DEF("semihosting", 0, QEMU_OPTION_semihosting, QEMU_ARCH_MIPS | QEMU_ARCH_NIOS2 | QEMU_ARCH_RISCV) SRST ``-semihosting`` - Enable semihosting mode (ARM, M68K, Xtensa, MIPS, Nios II, RISC-V only). + Enable :ref:`Semihosting` mode (ARM, M68K, Xtensa, MIPS, Nios II, RISC-V only). - Note that this allows guest direct access to the host filesystem, so - should only be used with a trusted guest OS. + .. warning:: + Note that this allows guest direct access to the host filesystem, so + should only be used with a trusted guest OS. + + .. _Semihosting Options: See the -semihosting-config option documentation for further information about the facilities this enables. @@ -4648,22 +4651,12 @@ QEMU_ARCH_ARM | QEMU_ARCH_M68K | QEMU_ARCH_XTENSA | QEMU_ARCH_MIPS | QEMU_ARCH_NIOS2 | QEMU_ARCH_RISCV) SRST ``-semihosting-config [enable=on|off][,target=native|gdb|auto][,chardev=id][,userspace=on|off][,arg=str[,...]]`` - Enable and configure semihosting (ARM, M68K, Xtensa, MIPS, Nios II, RISC-V + Enable and configure :ref:`Semihosting` (ARM, M68K, Xtensa, MIPS, Nios II, RISC-V only). - Note that this allows guest direct access to the host filesystem, so - should only be used with a trusted guest OS. - - On Arm this implements the standard semihosting API, version 2.0. - - On M68K this implements the "ColdFire GDB" interface used by - libgloss. - - Xtensa semihosting provides basic file IO calls, such as - open/read/write/seek/select. Tensilica baremetal libc for ISS and - linux platform "sim" use this interface. - - On RISC-V this implements the standard semihosting API, version 0.2. + .. warning:: + Note that this allows guest direct access to the host filesystem, so + should only be used with a trusted guest OS. ``target=native|gdb|auto`` Defines where the semihosting calls will be addressed, to QEMU