Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft: hexagon system emulation initial #99

Open
wants to merge 109 commits into
base: tip
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
521f902
target/hexagon: Fix badva reference, delete CAUSE
androm3da Aug 8, 2024
1cb87d4
target/hexagon: Add missing A_CALL attr, hintjumpr to multi_cof
androm3da May 18, 2024
736cebe
target/hexagon: Add System/Guest register definitions
androm3da May 18, 2024
64d2954
target/hexagon: Add some utility functions for sysemu
androm3da May 18, 2024
de05b22
target/hexagon: Make gen_exception_end_tb non-static
androm3da May 20, 2024
31efbf2
target/hexagon: Guard system insts
androm3da May 18, 2024
87b2699
target/hexagon: Switch to tag_ignore(), generate via get_{user,sys}_t…
androm3da May 18, 2024
368dd86
target/hexagon: Guard system insts, switch to tag_ignore()
androm3da May 18, 2024
8c2e641
target/hexagon: Add sysemu instructions triggering need_next_PC, mult…
androm3da May 18, 2024
ce5058f
target/hexagon: Add is_pair() method to scalars
androm3da May 18, 2024
c6fd603
gdb-xml: Add gdb-xml for hexagon sysemu
quic-mathbern Nov 8, 2023
e976e8e
target/hexagon: Add memory order definition
androm3da May 20, 2024
7220f12
target/hexagon: Add a placeholder fp exception
androm3da May 20, 2024
c0bbdbd
target/hexagon: Define page size for sysemu
androm3da May 20, 2024
f18e9bd
target/hexagon: Add guest, system reg number defs
androm3da May 20, 2024
0451994
target/hexagon: Add guest, system reg number state
androm3da May 29, 2024
b7fff0a
target/hexagon: Add TCG values for sreg, greg
androm3da May 20, 2024
7ad9f91
target/hexagon: Add guest/sys reg writes to DC
androm3da May 20, 2024
2809f85
target/hexagon: Add imported macro, attr defs for sysemu
androm3da May 20, 2024
ade7eec
target/hexagon: Define DC states
androm3da Sep 9, 2024
b961c8e
FIXME: target/hexagon: Add new macro definitions for sysemu
androm3da May 20, 2024
7ad78ae
target/hexagon: Add handlers for guest/sysreg r/w
androm3da May 20, 2024
79ccf99
target/hexagon: Add placeholder greg/sreg r/w helpers
androm3da May 20, 2024
e43d4f1
target/hexagon: Add vmstate representation
androm3da Sep 8, 2024
cd9ce8b
docs: Add hexagon sysemu docs
androm3da Apr 30, 2024
8bb107c
FIXME: docs: Add hexagon VM info
androm3da Jul 9, 2024
5836715
docs/system: Add hexagon CPU emulation
androm3da Oct 26, 2024
b894648
target/hexagon: Make A_PRIV, "J2_trap*" insts need_env()
androm3da May 27, 2024
95f9dac
target/hexagon: Define register fields for system regs
androm3da May 24, 2024
404f998
FIXME this unused fixes some errs
androm3da May 24, 2024
51ddc6c
target/hexagon: Add TCG overrides for break,unpause,fetchbo,dczeroa
androm3da May 27, 2024
3fdb2f0
target/hexagon: Implement do_raise_exception()
androm3da Sep 5, 2024
46b7c36
target/hexagon: Add system reg insns
androm3da May 29, 2024
d08ab18
target/hexagon: Add sysemu TCG overrides
androm3da Jul 8, 2024
903067d
target/hexagon: Add implicit attributes to sysemu macros
androm3da Sep 12, 2024
49b7120
target/hexagon: Add TCG overrides for int handler insts
androm3da Jul 25, 2024
17e09db
target/hexagon: Add TCG overrides for thread ctl
androm3da Jul 25, 2024
560243f
target/hexagon: Add TCG overrides for rte, nmi
androm3da Jul 25, 2024
0c3f47f
target/hexagon: Add sreg_{read,write} helpers
androm3da Jul 26, 2024
d82c776
target/hexagon: Initialize htid, modectl regs
androm3da Aug 9, 2024
f2e343c
target/hexagon: Add locks, id, next_PC to state
androm3da Aug 10, 2024
7411a69
target/hexagon: Add a TLB count property
androm3da Aug 10, 2024
ad71d23
target/hexagon: Add {TLB,k0}lock, cause code, wait_next_pc
androm3da Aug 16, 2024
3243399
target/hexagon: Add stubs for modify_ssr/get_exe_mode
androm3da Aug 16, 2024
2ce28d3
target/hexagon: Add gdb support for sys regs
androm3da Aug 27, 2024
8cc9d4a
FIXME: target/hexagon: Add initial MMU model
androm3da Aug 26, 2024
dbf9147
target/hexagon: Add IRQ events
androm3da Aug 27, 2024
29c5a16
target/hexagon: Add clear_wait_mode() definition
androm3da Aug 27, 2024
9dcba11
target/hexagon: Define f{S,G}ET_FIELD macros
androm3da Aug 27, 2024
edf745f
target/hexagon: Add hex_interrupts support
androm3da Aug 27, 2024
ea7ac92
hw/intc: Add l2vic interrupt controller
SidManning Nov 8, 2023
1ed4048
target/hexagon: Implement ciad helper
androm3da Aug 28, 2024
75bd590
target/hexagon: Implement {c,}swi helpers
androm3da Aug 28, 2024
2af5088
target/hexagon: Implement iassign{r,w} helpers
androm3da Aug 28, 2024
d905f73
target/hexagon: Implement start/stop helpers
androm3da Aug 28, 2024
a7f2da3
target/hexagon: Implement modify SSR
androm3da Aug 28, 2024
f700155
target/hexagon: Implement {g,s}etimask helpers
androm3da Aug 28, 2024
6a9cc68
target/hexagon: Implement wait helper
androm3da Aug 28, 2024
b72c595
target/hexagon: Implement get_exe_mode()
androm3da Aug 28, 2024
15e0625
target/hexagon: Implement arch_get_system_reg()
androm3da Aug 28, 2024
9fc10a7
target/hexagon: Implement arch_{s,g}et_{thread,system}_reg()
androm3da Aug 28, 2024
5026cc9
target/hexagon: Add representation to count cycles
androm3da Aug 29, 2024
9c30064
target/hexagon: Add implementation of cycle counters
androm3da Aug 29, 2024
209a966
target/hexagon: Implement modify_syscfg()
androm3da Aug 29, 2024
5186210
target/hexagon: Add system event, cause codes
androm3da Sep 4, 2024
64f749a
target/hexagon: Implement hex_tlb_entry_get_perm()
androm3da Sep 4, 2024
4e99d60
target/hexagon: Implement hex_tlb_lookup_by_asid()
androm3da Sep 4, 2024
14e3167
target/hexagon: Implement software interrupt
androm3da Sep 4, 2024
189c35b
target/hexagon: Implement exec_interrupt, set_irq
androm3da Sep 5, 2024
a1e454d
FIXME: target/hexagon: Implement hexagon_tlb_fill()
androm3da Sep 5, 2024
5df06af
target/hexagon: Implement siad inst
androm3da Sep 5, 2024
24f2069
target/hexagon: Implement hexagon_resume_threads()
androm3da Sep 5, 2024
93a8b32
target/hexagon: Implement setprio, resched
androm3da Sep 5, 2024
f0c8321
target/hexagon: Add sysemu_ops
androm3da Sep 5, 2024
ba898c1
target/hexagon: Add cpu_get_phys_page_debug()
androm3da Sep 5, 2024
223548b
target/hexagon: Add vmsd
androm3da Sep 5, 2024
5262161
target/hexagon: Add exec-start-addr prop
androm3da Sep 5, 2024
95a2d24
target/hexagon: Add hexagon_cpu_mmu_index()
androm3da Sep 5, 2024
c968627
FIXME: why remove this unreachable?
androm3da Sep 5, 2024
28c8c09
FIXME: target/hexagon: handle .new values
androm3da Sep 6, 2024
018dcf7
target/hexagon: Decode trap1, rte as COF
androm3da Sep 6, 2024
6ec1673
hw/hexagon: Add machine configs for sysemu
androm3da Dec 2, 2023
9df8d78
hw/hexagon: Add support for cfgbase
SidManning Dec 18, 2024
206e1cb
qapi: Add hexagon machine to QAPI
androm3da Oct 3, 2024
7212626
target/hexagon: add build config for softmmu
androm3da Dec 2, 2023
a72e283
target/hexagon: Implement hexagon_find_last_irq()
androm3da Sep 8, 2024
2d3237b
target/hexagon: Implement modify_ssr, resched, pending_interrupt
androm3da Sep 9, 2024
0c23a77
target/hexagon: Add pkt_ends_tb to translation
androm3da Sep 9, 2024
d819f50
FIXME target/hexagon: Add next_PC, {s,g}reg writes
androm3da Sep 9, 2024
4ace7fa
target/hexagon: s/pkt_has_store/pkt_has_scalar_store
androm3da Sep 9, 2024
aebf62b
target/hexagon: Add implicit sysreg writes
androm3da Sep 9, 2024
4433c21
FIXME target/hexagon: Omit A_SCALAR_STORE from cancelled
androm3da Sep 9, 2024
515be7f
target/hexagon: Define system, guest reg names
androm3da Sep 11, 2024
ccf017d
target/hexagon: initialize sys/guest reg TCGvs
androm3da Sep 11, 2024
2163ff5
target/hexagon: Add TLB, k0 {un,}lock
androm3da Sep 12, 2024
61f5ce8
FIXME target/hexagon: Define gen_precise_exception()
androm3da Sep 12, 2024
4237944
target/hexagon: Add TCG overrides for transfer insts
androm3da Sep 18, 2024
d4d0a5f
target/hexagon: Add support for loadw_phys
androm3da Sep 18, 2024
ea6db76
hw/hexagon: Add v68, sa8775-cdsp0 defs
androm3da Oct 16, 2024
8932b0c
hw/hexagon: Modify "Standalone" symbols
androm3da Oct 22, 2024
ab9a180
hw/hexagon: Define hexagon "virt" machine
androm3da Jul 29, 2024
55a84e3
target/hexagon: Add guest reg reading functionality
quic-mathbern Dec 6, 2024
cc1b794
target/hexagon: Add pcycle setting functionality
androm3da Dec 11, 2024
1dd8d5d
tests/functional: Add a hexagon minivm test
androm3da Oct 26, 2024
c425299
FIXME: target/hexagon: Add exit pattern for standalone programs
SidManning Dec 18, 2024
3a44861
target/hexagon: Add a QTimer address prop
androm3da Jan 3, 2025
3440997
hw/timer: Add QTimer device
SidManning Nov 8, 2023
6f08d02
target/hexagon: Implement hexagon_read_timer()
androm3da Jan 3, 2025
1298fe7
Update initialization sequence to fix l2vic interrupts
SidManning Jan 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ F: disas/hexagon.c
F: configs/targets/hexagon-linux-user/default.mak
F: docker/dockerfiles/debian-hexagon-cross.docker
F: gdb-xml/hexagon*.xml
F: docs/system/target-hexagon.rst
F: docs/devel/hexagon-sys.rst
F: docs/devel/hexagon-vm.rst
T: git https://github.com/quic/qemu.git hex-next

Hexagon idef-parser
Expand Down
106 changes: 106 additions & 0 deletions docs/devel/hexagon-sys.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
.. _Hexagon-System-arch:

Hexagon System Architecture
===========================

The hexagon architecture has some unique elements which are described here.

Interrupts
----------
When interrupts arrive at a Hexagon DSP core, they are priority-steered to
be handled by an eligible hardware thread with the lowest priority.

Memory
------
Each hardware thread has an ``SSR.ASID`` field that contains its Address
Space Identifier. This value is catenated with a 32-bit virtual address -
the MMU can then resolve this extended virtual address to a physical address.

TLBs
----
The format of a TLB entry is shown below.

.. note::
The Small Core DSPs have a different TLB format which is not yet
supported.

.. admonition:: Diagram

.. code:: text

6 5 4 3
3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|v|g|x|A|A| | |
|a|l|P|1|0| ASID | Virtual Page |
|l|b| | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

3 2 1 0
1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | | | | | | |
|x|w|r|u|Cacheab| Physical Page |S|
| | | | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+


* ASID: the address-space identifier
* A1, A0: the behavior of these cache line attributes are not modeled by QEMU.
* xP: the extra-physical bit is the most significant physical address bit.
* S: the S bit and the LSBs of the physical page indicate the page size
* val: this is the 'valid' bit, when set it indicates that page matching
should consider this entry.

.. list-table:: Page sizes
:widths: 25 25 50
:header-rows: 1

* - S-bit
- Phys page LSBs
- Page size
* - 1
- N/A
- 4kb
* - 0
- 0b1
- 16kb
* - 0
- 0b10
- 64kb
* - 0
- 0b100
- 256kb
* - 0
- 0b1000
- 1MB
* - 0
- 0b10000
- 4MB
* - 0
- 0b100000
- 16MB

* glb: if the global bit is set, the ASID is not considered when matching
TLBs.
* Cacheab: the cacheability attributes of TLBs are not modeled, these bits
are ignored.
* RWX: read-, write-, execute-, enable bits. Indicates if user programs
are permitted to read/write/execute the given page.
* U: indicates if user programs can access this page.

Scheduler
---------
The Hexagon system architecture has a feature to assist the guest OS
task scheduler. The guest OS can enable this feature by setting
``SCHEDCFG.EN``. The ``BESTWAIT`` register is programmed by the guest OS
to indicate the priority of the highest priority task waiting to run on a
hardware thread. The reschedule interrupt is triggered when any hardware
thread's priority in ``STID.PRIO`` is worse than the ``BESTWAIT``. When
it is triggered, the ``BESTWAIT.PRIO`` value is reset to 0x1ff.

HVX Coprocessor
---------------
The Supervisor Status Register field ``SSR.XA`` binds a DSP hardware thread
to one of the eight possible HVX contexts. The guest OS is responsible for
managing this resource.
190 changes: 190 additions & 0 deletions docs/devel/hexagon-vm.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
Hexagon Virtual Machine
=======================

The hexagon virtual machine is a hypervisor that can partition a single
Hexagon DSP among multiple guest operating systems, and abstracts the
specific details of a DSP architectural revision for the sake of consistency
among generations.

Events
------

The guest operating system should register the Guest Event Vector Base
via the ``vmsetvec`` virtual instruction at system startup. The vector table
and handlers are determined by the guest OS.

Guests return from event handlers with ``vmrte``. This instruction will restore
the mode (user versus guest), interrupt enable state, PC, SP.

.. list-table:: Event types
:header-rows: 1

* - Number
- Name
- Description
- Maskable
- Detail
* - 0
- Reserved
-
-
-
* - 1
- Machine check event
- unrecoverable VM state
- No
- execution terminates if unhandled
* - 2
- General exception
- internal hardware or software exception
- No
-
* - 3-4
- Reserved
-
-
-
* - 5
- ``trap0``
- ``trap0`` instruction
- No
-
* - 6
- Reserved
-
-
-
* - 7
- Interrupt
- external interrupts
- Yes
- increasing interrupt numbers have descending priority

Startup
-------
In order to transition to user-mode, the guest OS must set the ``UM`` bit in
the guest status register and specify the address to start executing in
user mode in the guest event link register.

Virtual Instructions
--------------------

.. list-table:: Virtual Instructions
:header-rows: 1

* - Instruction
- Behavior
- Operand
- Input
- Output
* - vmversion
- returns the VM version
- 0x0
- requested VM version
- provided VM version
* - vmrte
- return from event
- 0x1
- Event info in g3:0
- N/A
* - vmsetvec
- set event vector
- 0x2
- r0 is set to vector table addr
- r0 is 0 on success, 1 otherwise
* - vmsetie
- set interrupt enabled
- 0x3
- r0 is set to 1 to enable, 0 to disable
- previous IE bit is stored as LSB of r0
* - vmgetie
- get interrupt enabled
- 0x4
- N/A
- current IE bit is stored as LSB of r0
* - vmintop
- interrupt operation
- 0x5
- r0 = Interrupt Op, r1-r4: Depends on Op
- r0 - value depends on operation
* - vmclrmap
- clear virtual memory map
- 0xa
- r0 = Interrupt Op, r1-r4: Depends on Op
- r0 - value depends on operation
* - vmnewmap
- set new virtual memory map
- 0xb
- + r0 contains logical address of new segment table
+ r1 = type of translations: 0 indicates a logical address of a zero-terminated linear list, 1 indicates a set of page tables.
- r0 contains 0 on success, otherwise negative error code
* - vmcache
- VM cache control: not modeled
- 0xd
- + r0 contains the operation to be performed
+ r1 = Starting virtual address
+ r2 contains the length in bytes
- r0 contains 0 on success, otherwise -1. Cache behavior is not modeled so this operation always succeeds.
* - vmgettime
- Get virtual machine time
- 0xe
- N/A
- r0 contains the least significant 32 bits of timestamp, r1 contains the most significant 32 bits of timestamp
* - vmsettime
- Set virtual machine time
- 0xf
- r0 contains the least significant 32 bits of timestamp, r1 contains the most significant 32 bits of timestamp
- N/A
* - vmwait
- wait for interrupt
- 0x10
- N/A
- r0 contains the interrupt number of the interrupt waking the guest
* - vmyield
- voluntarily yield VM task
- 0x11
- N/A
- N/A
* - vmstart
- Create new virtual processor instance
- 0x12
- r0 contains the starting execution address, r1 contains the starting stack pointer
- r0 contains the Virtual processor number of new virtual processor on success, otherwise -1
* - vmstop
- terminate current virtual processor instance
- 0x13
- N/A
- N/A
* - vmvpid
- get the virtual processor ID
- 0x14
- N/A
- r0 contains the virtual processor number of virtual processor executing the instruction
* - vmsetregs
- Set guest registers
- 0x15
- r0-3 hold g0-3 values
- N/A
* - vmgetregs
- Get guest registers
- 0x16
- N/A
- r0-3 hold g0-3 values
* - vmtimerop
- perform an operation on a system timer
- 0x18
- + getfreq = 0
+ getres = 1
+ gettime = 2
+ gettimeout = 3
+ settimeout = 4
+ deltatimeout = 5
- r0 contains result of the timer operation call
* - vmgetinfo
- Get system info
- 0x1a
- Index of the system info parameter:

+ build_id = 0
+ info_boot_flags = 1
- value of the indicated system info parameter
2 changes: 2 additions & 0 deletions docs/devel/index-internals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Details about QEMU's various subsystems including how to add features to them.
block-coroutine-wrapper
clocks
ebpf_rss
hexagon-sys
hexagon-vm
migration/index
multi-process
reset
Expand Down
10 changes: 10 additions & 0 deletions docs/system/hexagon/cdsp.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Compute DSP
===========

A Hexagon CDSP is designed as a computation offload device for an SoC. The
``V66G_1024`` machine contains:

* L2VIC interrupt controller
* QTimer timer device

This machine will support any Hexagon CPU, but will default to ``v66``.
16 changes: 16 additions & 0 deletions docs/system/hexagon/emulation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.. _Hexagon Emulation:

Hexagon CPU architecture support
================================

QEMU's TCG emulation includes support for v65, v66, v67, v68, v69, v71, v73.
It also has support for the following architecture extensions:

- HVX (Hexagon Vector eXtensions)

For information on the specifics of the HVX extension, please refer
to the `Qualcomm Hexagon V69 HVX Programmer's Reference Manual
<https://docs.qualcomm.com/bundle/publicresource/80-N2040-49_REV_AA_Qualcomm_Hexagon_V69_HVX_ProgrammerS_Reference_Manual.pdf>`_.

.. code-block:: bash

Loading