From nobody Tue Jul 1 11:32:48 2025 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1674585159; cv=none; d=zohomail.com; s=zohoarc; b=HGho0f+QFOYj9nNp6aciIYlv0kQ98e76dyop7OJoetDFI7OJVX4qfZMdTu4xb6Jb3daGDnJojPH+Ww7Hr+3eDCCADnZGaxhjCFqt+lH2opydy1iM0QtGC2in30m2TelAi5GwqxIeKjhfuxi8t+eGDOI1gf87aJ5TqI2BkXT3HZg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674585159; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VtC2HtpKin4UrNqNqeKJgg5NfJ+lmXNI0G+VdILgJfA=; b=ljmmkuNFWpIy16mYW5+SAqKJD/KMjyl6cvXQTkSU5BFysYeiCSk4bJpsnCASPiwnfuJWlNpZxgDOfs+bBCY5N3yUFLytwYYG4ug2WakVCQuzbE7aQh1SvsBhKXhvfVaiuqOCAIJpaRRhINJNdIq6SL834ZPNciKni2meYbqCs/g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674585159910989.6435856216436; Tue, 24 Jan 2023 10:32:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pKNiD-0006c5-6J; Tue, 24 Jan 2023 13:08:01 -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 1pKNhO-0005BL-Tf for qemu-devel@nongnu.org; Tue, 24 Jan 2023 13:07:13 -0500 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pKNhI-00075b-Er for qemu-devel@nongnu.org; Tue, 24 Jan 2023 13:07:10 -0500 Received: by mail-wm1-x336.google.com with SMTP id f12-20020a7bc8cc000000b003daf6b2f9b9so13413371wml.3 for ; Tue, 24 Jan 2023 10:07:03 -0800 (PST) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id r18-20020a05600c435200b003db06224953sm2888995wme.41.2023.01.24.10.06.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jan 2023 10:06:58 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 3ED521FFCA; Tue, 24 Jan 2023 18:01:30 +0000 (GMT) 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=VtC2HtpKin4UrNqNqeKJgg5NfJ+lmXNI0G+VdILgJfA=; b=MjO19im85MdlWJG4f5j296Q95BNFHQlTBBit/k7q2bcwfJxNwq7EmpRo5lgAXtXA9/ 5ZyphAD7f/acxB4qcTkdfTuyBehDpqv0HrTMqpDIDhlpZJwo8h+N4mvX3bgf09VQInzZ elFGHTdfDctDcnVK8HAhIyHCwt4cu23ITumP5tySqRzromLDwPozrfMwyJPoEBjfCSRg aS9l1nAENDdtVE8kXcXm/mlHXEy3R11Vuipgiv01m0JnlrK9BqrafFXpiXfy8vZNep3J 2OGaOzA6nVldk1v9ptw5LFD0pj0M0B0yCcmnXJmp+IjUgFEV7S82ohj1amL+QIFhnNao 9oNg== 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=VtC2HtpKin4UrNqNqeKJgg5NfJ+lmXNI0G+VdILgJfA=; b=oxAQZ4Mp0cSJjH/gOys0bftuhLkL58iez2U6MtIRkJJxuKWPntvXtzU7AWBnihHE76 f/NUhqTuIQAdBYt1t3A2uV/wOqyYjaYfJNhQq4Lr0nAaSJmfmyBcCSz+e4qtHC57bqv+ qtB5qix0Sb5IZjmXXB5EY2Hx6gDRYqiINRVs40MpVaRcAqr500npK+wDIXP+unmpd7uN 9S1DFF+CNZfyYEHcJg37eu6Yht1yd5IoI2bc7ba44oDFRnSGlPxhZD5vFZyJrbwUWuY0 fwNzpOWMQBgoBrbKOU4Krg6k3S4k9cIJV8hjqQaipQWxDKwCwTdu9RL2jA7za1/Mmo93 lU3w== X-Gm-Message-State: AFqh2koF85KzRB4pZsMQbwowopDYHYAtl3vISXRq+S3EqTe3K5Q6Nyvv S3fXnvQDjviStiJFUqxWpptSnw== X-Google-Smtp-Source: AMrXdXtI05INx5aGuWkrVXgfI+KkXA0jQCOKlQODMMN/+7UDRDmkbj4Prw0GuNhrSFXOoYlU5q4FRg== X-Received: by 2002:a05:600c:4f96:b0:3db:2df0:f2b8 with SMTP id n22-20020a05600c4f9600b003db2df0f2b8mr18118781wmq.36.1674583622546; Tue, 24 Jan 2023 10:07:02 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Richard Henderson , Ed Maste , Thomas Huth , Alexandre Iooss , Markus Armbruster , Jagannathan Raman , John G Johnson , Mahmoud Mandour , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Bandan Das , Elena Ufimtseva , Michael Roth , Eduardo Habkost , Beraldo Leal , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Qiuhao Li , Stefan Hajnoczi , Alexander Bulekov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , John Snow , Paolo Bonzini , Darren Kenny , qemu-arm@nongnu.org, Yanan Wang , Cleber Rosa , Wainer dos Santos Moschetta , Marcel Apfelbaum , Li-Wen Hsu , Peter Maydell Subject: [PATCH v2 21/35] semihosting: add semihosting section to the docs Date: Tue, 24 Jan 2023 18:01:13 +0000 Message-Id: <20230124180127.1881110-22-alex.bennee@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230124180127.1881110-1-alex.bennee@linaro.org> References: <20230124180127.1881110-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x336.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=unavailable 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1674585161802100003 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. Acked-by: Richard Henderson Reviewed-by: Richard Henderson Signed-off-by: Alex Benn=C3=A9e --- v2 - moved inside the generic emulation section - make it clearer semihosting is specified by the architecture - more expansive description for O_BINARY - s/mips/MIPS/ --- docs/about/emulation.rst | 89 ++++++++++++++++++++++++++++++++++++++++ qemu-options.hx | 27 +++++------- 2 files changed, 99 insertions(+), 17 deletions(-) diff --git a/docs/about/emulation.rst b/docs/about/emulation.rst index bdc0630b35..dde892a226 100644 --- a/docs/about/emulation.rst +++ b/docs/about/emulation.rst @@ -101,3 +101,92 @@ depending on the guest architecture. =20 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 defined by the owner of the architecture to +allow programs to interact with a debugging host system. On real +hardware this is usually provided by an In-circuit emulator (ICE) +hooked directly to the board. QEMU's implementation allows for +semihosting calls to be passed to the host system or via the +``gdbstub``. + +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 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. + +For full details of the ABI for a particular target, and the set of +calls it provides, you should consult the semihosting specification +for that architecture. + +.. note:: + QEMU makes an implementation decision to implement all file + access in ``O_BINARY`` mode. The user-visible effect of this is + regardless of the text/binary mode the program sets QEMU will + always select a binary mode ensuring no line-terminator conversion + is performed on input or output. 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/semihos= ting.rst + * - m68k + - System + - https://sourceware.org/git/?p=3Dnewlib-cygwin.git;a=3Dblob;f=3Dlibgl= oss/m68k/m68k-semi.txt;hb=3DHEAD + * - MIPS + - System + - Unified Hosting Interface (MD01069) + * - Nios II + - System + - https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;a=3Dblob= ;f=3Dlibgloss/nios2/nios2-semi.txt;hb=3DHEAD + * - RISC-V + - System and User-mode + - https://github.com/riscv/riscv-semihosting-spec/blob/main/riscv-semi= hosting-spec.adoc + * - Xtensa + - System + - Tensilica ISS SIMCALL diff --git a/qemu-options.hx b/qemu-options.hx index d59d19704b..4508a00c59 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). =20 - 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: =20 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=3Don|off][,target=3Dnative|gdb|auto][,charde= v=3Did][,userspace=3Don|off][,arg=3Dstr[,...]]`` - Enable and configure semihosting (ARM, M68K, Xtensa, MIPS, Nios II, RI= SC-V + Enable and configure :ref:`Semihosting` (ARM, M68K, Xtensa, MIPS, Nios= II, RISC-V only). =20 - 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. =20 ``target=3Dnative|gdb|auto`` Defines where the semihosting calls will be addressed, to QEMU --=20 2.34.1