All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Richard Henderson" <richard.henderson@linaro.org>,
	"Ed Maste" <emaste@freebsd.org>, "Thomas Huth" <thuth@redhat.com>,
	"Alexandre Iooss" <erdnaxe@crans.org>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Jagannathan Raman" <jag.raman@oracle.com>,
	"John G Johnson" <john.g.johnson@oracle.com>,
	"Mahmoud Mandour" <ma.mandourr@gmail.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Bandan Das" <bsd@redhat.com>,
	"Elena Ufimtseva" <elena.ufimtseva@oracle.com>,
	"Michael Roth" <michael.roth@amd.com>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Beraldo Leal" <bleal@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Qiuhao Li" <Qiuhao.Li@outlook.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Alexander Bulekov" <alxndr@bu.edu>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"John Snow" <jsnow@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Darren Kenny" <darren.kenny@oracle.com>,
	qemu-arm@nongnu.org, "Yanan Wang" <wangyanan55@huawei.com>,
	"Cleber Rosa" <crosa@redhat.com>,
	"Wainer dos Santos Moschetta" <wainersm@redhat.com>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"Li-Wen Hsu" <lwhsu@freebsd.org>,
	"Peter Maydell" <peter.maydell@linaro.org>
Subject: [PATCH v2 21/35] semihosting: add semihosting section to the docs
Date: Tue, 24 Jan 2023 18:01:13 +0000	[thread overview]
Message-ID: <20230124180127.1881110-22-alex.bennee@linaro.org> (raw)
In-Reply-To: <20230124180127.1881110-1-alex.bennee@linaro.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.

Acked-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
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.
 
 A number of features are are only available when running under
 emulation including :ref:`Record/Replay<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<GDB usage>`. 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<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/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 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).
 
-    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
-- 
2.34.1



  parent reply	other threads:[~2023-01-24 18:08 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-24 18:00 [PATCH v2 00/35] maintainer tree pre-PR (testing/docs/semihosting/plugins) Alex Bennée
2023-01-24 18:00 ` [PATCH v2 01/35] scripts/ci: update gitlab-runner playbook to use latest runner Alex Bennée
2023-01-24 19:49   ` Richard Henderson
2023-01-24 18:00 ` [PATCH v2 02/35] gitlab: add FF_SCRIPT_SECTIONS for timings Alex Bennée
2023-01-25 12:09   ` Philippe Mathieu-Daudé
2023-01-25 12:15   ` Daniel P. Berrangé
2023-01-24 18:00 ` [PATCH v2 03/35] gitlab: just use plain --cc=clang for custom runner build Alex Bennée
2023-01-24 18:00 ` [PATCH v2 04/35] tests/unit: drop hacky race avoidance in test-io-channel-command Alex Bennée
2023-01-24 18:00 ` [PATCH v2 05/35] build-sys: fix crlf-ending C code Alex Bennée
2023-01-24 18:00 ` [PATCH v2 06/35] .gitlab-ci.d/windows: do not disable opengl Alex Bennée
2023-01-24 18:00 ` [PATCH v2 07/35] meson: replace Perl usage with Python Alex Bennée
2023-01-24 18:01 ` [PATCH v2 08/35] docs: drop texinfo options Alex Bennée
2023-01-24 18:01 ` [PATCH v2 09/35] gitlab: add lsan suppression file to workaround tcmalloc issues Alex Bennée
2023-01-25  7:44   ` Thomas Huth
2023-01-25 12:13   ` Philippe Mathieu-Daudé
2023-01-24 18:01 ` [PATCH v2 10/35] Update lcitool and fedora to 37 Alex Bennée
2023-01-24 18:01 ` [PATCH v2 11/35] lcitool: drop perl from QEMU project/dependencies Alex Bennée
2023-01-24 18:01 ` [PATCH v2 12/35] lcitool: drop texinfo " Alex Bennée
2023-01-24 18:01 ` [PATCH v2 13/35] tests/docker: Install flex in debian-tricore-cross Alex Bennée
2023-01-24 18:01 ` [PATCH v2 14/35] tests/docker: drop debian-tricore-cross's partial status Alex Bennée
2023-01-24 18:01 ` [PATCH v2 15/35] tests/tcg: skip the vma-pthread test on CI Alex Bennée
2023-01-24 18:01 ` [PATCH v2 16/35] tests/tcg: Use SIGKILL for timeout Alex Bennée
2023-01-25 12:14   ` Philippe Mathieu-Daudé
2023-01-24 18:01 ` [PATCH v2 17/35] gitlab: wrap up test results for custom runners Alex Bennée
2023-01-24 18:01 ` [PATCH v2 18/35] MAINTAINERS: Fix the entry for tests/tcg/nios2 Alex Bennée
2023-01-24 18:01 ` [PATCH v2 19/35] docs: add hotlinks to about preface text Alex Bennée
2023-01-25 12:16   ` Philippe Mathieu-Daudé
2023-01-24 18:01 ` [PATCH v2 20/35] docs: add a new section to outline emulation support Alex Bennée
2023-01-25  7:58   ` Thomas Huth
2023-01-25 12:18     ` Philippe Mathieu-Daudé
2023-01-24 18:01 ` Alex Bennée [this message]
2023-01-24 18:01 ` [PATCH v2 22/35] docs: add an introduction to the system docs Alex Bennée
2023-01-25  7:53   ` Thomas Huth
2023-01-24 18:01 ` [PATCH v2 23/35] semihosting: Write back semihosting data before completion callback Alex Bennée
2023-01-25 23:21   ` Philippe Mathieu-Daudé
2023-01-24 18:01 ` [PATCH v2 24/35] semihosting: add O_BINARY flag in host_open for NT compatibility Alex Bennée
2023-01-24 18:01 ` [PATCH v2 25/35] tests/tcg: add memory-sve test for aarch64 Alex Bennée
2023-01-24 18:01 ` [PATCH v2 26/35] cpu: free cpu->tb_jmp_cache with RCU Alex Bennée
2023-01-24 18:01 ` [PATCH v2 27/35] util/qht: add missing atomic_set(hashes[i]) Alex Bennée
2023-01-24 18:01 ` [PATCH v2 28/35] thread: de-const qemu_spin_destroy Alex Bennée
2023-01-24 18:01 ` [PATCH v2 29/35] util/qht: use striped locks under TSAN Alex Bennée
2023-01-24 18:01 ` [PATCH v2 30/35] plugins: make qemu_plugin_user_exit's locking order consistent with fork_start's Alex Bennée
2023-01-24 18:01 ` [PATCH v2 31/35] plugins: fix optimization in plugin_gen_disable_mem_helpers Alex Bennée
2023-01-24 18:01 ` [PATCH v2 32/35] translator: always pair plugin_gen_insn_{start, end} calls Alex Bennée
2023-01-24 18:01 ` [PATCH v2 33/35] tcg: exclude non-memory effecting helpers from instrumentation Alex Bennée
2023-01-24 19:44   ` Richard Henderson
2023-01-24 18:01 ` [PATCH v2 34/35] cpu-exec: assert that plugin_mem_cbs is NULL after execution Alex Bennée
2023-01-24 19:46   ` Richard Henderson
2023-01-25 23:27   ` Philippe Mathieu-Daudé
2023-01-24 18:01 ` [PATCH v2 35/35] plugins: Iterate on cb_lists in qemu_plugin_user_exit Alex Bennée
2023-01-25 23:26   ` Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230124180127.1881110-22-alex.bennee@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=Qiuhao.Li@outlook.com \
    --cc=alxndr@bu.edu \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=bleal@redhat.com \
    --cc=bsd@redhat.com \
    --cc=crosa@redhat.com \
    --cc=darren.kenny@oracle.com \
    --cc=eduardo@habkost.net \
    --cc=elena.ufimtseva@oracle.com \
    --cc=emaste@freebsd.org \
    --cc=erdnaxe@crans.org \
    --cc=jag.raman@oracle.com \
    --cc=john.g.johnson@oracle.com \
    --cc=jsnow@redhat.com \
    --cc=lwhsu@freebsd.org \
    --cc=ma.mandourr@gmail.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=michael.roth@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=stefanha@redhat.com \
    --cc=thuth@redhat.com \
    --cc=wainersm@redhat.com \
    --cc=wangyanan55@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.