e2k-host: initial commit

This commit is contained in:
Denis Drakhnia 2024-03-14 20:54:12 +02:00
parent 6e4ae247a7
commit 484b0dd212
22 changed files with 1600 additions and 18 deletions

View File

@ -129,3 +129,15 @@ bool kvm_hwpoisoned_mem(void)
{
return false;
}
int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n,
EventNotifier *rn, qemu_irq irq)
{
return -ENOSYS;
}
int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n,
qemu_irq irq)
{
return -ENOSYS;
}

View File

@ -0,0 +1,111 @@
/*
* safe-syscall.inc.S : host-specific assembly fragment
* to handle signals occurring at the same time as system calls.
* This is intended to be included by common-user/safe-syscall.S
*
* Copyright (C) 2024 Denis Drakhnia <numas13@gmail.com>
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*/
.global safe_syscall_base
.global safe_syscall_start
.global safe_syscall_end
.type safe_syscall_base, @function
.type safe_syscall_start, @function
.type safe_syscall_end, @function
/*
* This is the entry point for making a system call. The calling
* convention here is that of a C varargs function with the
* first argument an 'int *' to the signal_pending flag, the
* second one the system call number (as a 'long'), and all further
* arguments being syscall arguments (also 'long').
*/
safe_syscall_base:
.cfi_startproc
/*
* The syscall calling convention is the same as C:
* we enter with r0 == &signal_pending
* r1 == syscall number
* r2 ... r8 == syscall arguments
* and return the result in b0
* and the syscall instruction needs
* b0 == syscall number
* b1 ... b7 == syscall arguments
* and returns the result in b0
* Shuffle everything around appropriately.
*/
{
setwd wsz=8, nfx=1
setbn rsz=3, rbs=4, rcur=0
sdisp %ctpr1, 0x3
}
{
disp %ctpr2, safe_syscall_set_errno_tail
addd,0,sm %r1, 0, %b[0] /* syscall number */
addd,1,sm %r2, 0, %b[1] /* syscall arguments */
addd,2,sm %r3, 0, %b[2]
addd,3,sm %r4, 0, %b[3]
addd,4,sm %r5, 0, %b[4]
addd,5,sm %r6, 0, %b[5]
}
/*
* This next sequence of code works in conjunction with the
* rewind_if_safe_syscall_function(). If a signal is taken
* and the interrupted PC is anywhere between 'safe_syscall_start'
* and 'safe_syscall_end' then we rewind it to 'safe_syscall_start'.
* The code sequence must therefore be able to cope with this, and
* the syscall instruction must be the final one in the sequence.
*/
safe_syscall_start:
{
ldw,0 %r0, 0, %g16
addd,1,sm %r7, 0, %b[6]
addd,2,sm %r8, 0, %b[7]
#if __iset__ == 6
nop 4
#else
nop 2
#endif
}
{
/* If signal_pending is non-zero, don't do the call */
cmpedb,0 %g16, 0, %pred0
#if __iset__ < 6
nop 1
#endif
}
{
call %ctpr1, wbs=4 ? %pred0
}
safe_syscall_end:
{
return %ctpr3
addd,0 %b[0], 0, %r0 ? %pred0
cmpbedb,1 %b[0], -4096, %pred1
/* code path when we didn't execute the syscall */
addd,2 0, QEMU_ERESTARTSYS, %r0 ? ~%pred0
ct %ctpr2 ? ~%pred0
}
{
disp %ctpr1, safe_syscall_set_errno_tail
nop 4
}
{
subd,0 0, %r0, %r0 ? ~%pred1
/* code path for having successfully executed the syscall */
ct %ctpr3 ? %pred1
}
{
/* code path setting errno */
ct %ctpr1
}
.cfi_endproc
.size safe_syscall_base, .-safe_syscall_base

10
configure vendored
View File

@ -407,6 +407,8 @@ elif check_define __aarch64__ ; then
cpu="aarch64"
elif check_define __loongarch64 ; then
cpu="loongarch64"
elif check_define __e2k__ ; then
cpu="e2k"
else
# Using uname is really broken, but it is just a fallback for architectures
# that are going to use TCI anyway
@ -435,6 +437,11 @@ case "$cpu" in
linux_arch=arm
;;
e2k)
host_arch=e2k
linux_arch=e2k
;;
i386|i486|i586|i686)
cpu="i386"
host_arch=i386
@ -1160,6 +1167,7 @@ fi
: ${cross_prefix_arm="arm-linux-gnueabihf-"}
: ${cross_prefix_armeb="$cross_prefix_arm"}
: ${cross_prefix_hexagon="hexagon-unknown-linux-musl-"}
: ${cross_prefix_e2k="e2k-linux-"}
: ${cross_prefix_loongarch64="loongarch64-unknown-linux-gnu-"}
: ${cross_prefix_hppa="hppa-linux-gnu-"}
: ${cross_prefix_i386="i686-linux-gnu-"}
@ -1196,8 +1204,6 @@ fi
: ${cross_cc_sparc="$cross_cc_sparc64"}
: ${cross_cc_cflags_sparc="-m32 -mcpu=supersparc"}
: ${cross_cc_cflags_x86_64="-m64"}
: ${cross_cc_e2k="e2k-linux-as"} # C compiler isn't public yet
: ${cross_cc_e2k_ignore_checks="yes"}
compute_target_variable() {
eval "$2="

View File

@ -0,0 +1,65 @@
/*
* SPDX-License-Identifier: GPL-2.0-or-later
* Load/store for 128-bit atomic operations, e2k version.
*
* Copyright (C) 2024 Denis Drakhnia <numas13@gmail.com>
*
* See docs/devel/atomics.rst for discussion about the guarantees each
* atomic primitive is meant to provide.
*/
#ifndef E2K_ATOMIC128_LDST_H
#define E2K_ATOMIC128_LDST_H
#if defined(CONFIG_INT128_TYPE) && __iset__ >= 5
#include <e2kintrin.h>
#if __LCC__ >= 128
# define E2K_ASM_QR "x"
#else
# define E2K_ASM_QR "r"
#endif
typedef union {
__v2di v;
Int128 s;
} E2KInt128Union;
#define HAVE_ATOMIC128_RO 1
#define HAVE_ATOMIC128_RW 1
/* NOTE: DO NOT USE pragma asm_inline because LCC can convert
* ldqp|stqp into a two separate ldd|std. */
static inline Int128 atomic16_read_ro(const Int128 *ptr)
{
E2KInt128Union r;
asm("ldqp [ %1 ], %0" : "=" E2K_ASM_QR (r.v) : "m" (*ptr));
return r.s;
}
static inline Int128 atomic16_read_rw(Int128 *ptr)
{
__v2di *ptr_align = (__v2di *) __builtin_assume_aligned(ptr, 16);
E2KInt128Union r;
asm("ldqp [ %1 ], %0" : "=" E2K_ASM_QR (r.v) : "m" (*ptr_align));
return r.s;
}
static inline void atomic16_set(Int128 *ptr, Int128 val)
{
__v2di *ptr_align = (__v2di *) __builtin_assume_aligned(ptr, 16);
E2KInt128Union r = { .s = val };
asm("stqp [ %0 ], %1" : "=m" (*ptr_align) : E2K_ASM_QR (r.v));
}
#else
/* Provide QEMU_ERROR stubs. */
#include "host/include/generic/host/atomic128-ldst.h"
#endif
#endif /* E2K_ATOMIC128_LDST_H */

View File

@ -0,0 +1,22 @@
/*
* SPDX-License-Identifier: GPL-2.0-or-later
* Host specific cpu indentification for E2K.
*/
#ifndef HOST_CPUINFO_H
#define HOST_CPUINFO_H
/* Digested version of <cpuid.h> */
#define CPUINFO_ALWAYS (1u << 0) /* so cpuinfo is nonzero */
/* Initialized with a constructor. */
extern unsigned cpuinfo;
/*
* We cannot rely on constructor ordering, so other constructors must
* use the function interface rather than the variable above.
*/
unsigned cpuinfo_init(void);
#endif /* HOST_CPUINFO_H */

View File

@ -862,9 +862,12 @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp)
* have IRQ lines delegated by their parent APLIC.
*/
if (!aplic->parent) {
#ifdef CONFIG_KVM
if (kvm_enabled() && is_kvm_aia(aplic->msimode)) {
qdev_init_gpio_in(dev, riscv_kvm_aplic_request, aplic->num_irqs);
} else {
} else
#endif
{
qdev_init_gpio_in(dev, riscv_aplic_request, aplic->num_irqs);
}
}

View File

@ -711,8 +711,10 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap,
qemu_fdt_add_subnode(ms->fdt, "/cpus");
qemu_fdt_setprop_cell(ms->fdt, "/cpus", "timebase-frequency",
#ifdef CONFIG_KVM
kvm_enabled() ?
kvm_riscv_get_timebase_frequency(first_cpu) :
#endif
RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ);
qemu_fdt_setprop_cell(ms->fdt, "/cpus", "#size-cells", 0x0);
qemu_fdt_setprop_cell(ms->fdt, "/cpus", "#address-cells", 0x1);
@ -1516,6 +1518,7 @@ static void virt_machine_init(MachineState *machine)
}
}
#ifdef CONFIG_KVM
if (kvm_enabled() && virt_use_kvm_aia(s)) {
kvm_riscv_aia_create(machine, IMSIC_MMIO_GROUP_MIN_SHIFT,
VIRT_IRQCHIP_NUM_SOURCES, VIRT_IRQCHIP_NUM_MSIS,
@ -1523,6 +1526,7 @@ static void virt_machine_init(MachineState *machine)
memmap[VIRT_IMSIC_S].base,
s->aia_guests);
}
#endif
if (riscv_is_32bit(&s->soc[0])) {
#if HOST_LONG_BITS == 64

View File

@ -11,6 +11,9 @@
#include "qemu/bswap.h"
/* May be defined in ansidecl.h */
#undef PTR
typedef void *PTR;
typedef uint64_t bfd_vma;
typedef int64_t bfd_signed_vma;

View File

@ -29,7 +29,6 @@
#define ARCH_TIMER_NS_EL2_VIRT_IRQ 28
#define ARCH_TIMER_S_EL1_IRQ 29
#define ARCH_TIMER_NS_EL1_IRQ 30
#define INTID_TO_PPI(irq) ((irq) - 16)
#endif /* QEMU_ARM_BSA_H */

View File

@ -257,7 +257,8 @@ extern "C" {
G_NORETURN
void QEMU_ERROR("code path is reachable")
qemu_build_not_reached_always(void);
#if defined(__OPTIMIZE__) && !defined(__NO_INLINE__)
#if defined(__OPTIMIZE__) && !defined(__NO_INLINE__) && \
!(defined(__MCST__) && defined(__LCC__))
#define qemu_build_not_reached() qemu_build_not_reached_always()
#else
#define qemu_build_not_reached() g_assert_not_reached()

View File

@ -0,0 +1,8 @@
#ifndef __ASM_E2K_BITSPERLONG_H
#define __ASM_E2K_BITSPERLONG_H
#define __BITS_PER_LONG 64
#include <asm-generic/bitsperlong.h>
#endif /* __ASM_E2K_BITSPERLONG_H */

510
linux-headers/asm-e2k/kvm.h Normal file
View File

@ -0,0 +1,510 @@
#ifndef _ASM_E2K_KVM_H
#define _ASM_E2K_KVM_H
/*
* KVM e2k specific structures and definitions
*
* Note: you must update KVM_ARCH_API_VERSION if you change this interface.
*/
#ifndef __ASSEMBLY__
#include <linux/types.h>
#include <linux/ioctl.h>
/*
* e2k KVM api is not yet stable, so there is specific e2k arch
* refinement of the interface in format yymmdd so that the version
* number always monotonously increased
*/
#define KVM_ARCH_API_VERSION 210512
#define KVM_COALESCED_MMIO_PAGE_OFFSET 1
/* Select e2k specific features in <linux/kvm.h> */
#define __KVM_HAVE_IRQ_LINE
#define __KVM_HAVE_DEVICE_ASSIGNMENT
#define __KVM_HAVE_USER_NMI
#define __KVM_HAVE_GUEST_DEBUG
#define __KVM_HAVE_MSIX
#define __KVM_HAVE_MCE
#define __KVM_HAVE_VCPU_EVENTS
/* KVM (for /dev/kvm fds) capabilities (especially for e2k arch) */
/* number of CAPs is advisedly very big to don't intersect with other arch'es */
/* Other arch'es CAPs can be amplified and appended in future */
/* The better place for these defines should be at arch-indep header */
/* include/uapi/linux/kvm.h as for all other arch'es */
#define KVM_CAP_E2K_SV_VM 300 /* paravirtualized guest without any */
/* hardware support */
#define KVM_CAP_E2K_SW_PV_VM 301 /* paravirtualized kernel without any */
/* hardware support and can be run */
/* as host (hypervisor) and as guest */
/* especial case to debug purposes */
#define KVM_CAP_E2K_HV_VM 302 /* fully virtualized guest machines */
/* using hardware extensions */
#define KVM_CAP_E2K_HW_PV_VM 303 /* paravirtualized guest machines */
/* using hardware extensions */
/* Flags are bits 63:32 of KVM_CREATE_VM argument */
#define KVM_E2K_VM_TYPE_MASK 0x00000000ffffffffULL
#define KVM_E2K_VM_FLAG_MASK 0xffffffff00000000ULL
/* VM types, to be used as argument to KVM_CREATE_VM */
#define KVM_E2K_SV_VM_TYPE 0 /* software virtualized guest without */
/* any hardware support */
/* now it is default VM type because */
/* of can be available for all CPUs */
#define KVM_E2K_SW_PV_VM_TYPE 1 /* paravirtualized kernel without any */
/* hardware support and can be run */
/* as host (hypervisor) and as guest */
/* especial case to debug purposes */
#define KVM_E2K_HV_VM_TYPE 2 /* fully virtualized guest machines */
/* using hardware extensions */
#define KVM_E2K_HW_PV_VM_TYPE 3 /* paravirtualized guest machines */
/* using hardware extensions */
#define KVM_E2K_EPIC_VM_FLAG 0x100000000ULL /* choose between paravirt */
/* APIC and EPIC models */
/* KVM MMU capabilities */
#define KVM_CAP_E2K_SHADOW_PT_MMU 310 /* is shadow PT enabled */
#define KVM_CAP_E2K_TDP_MMU 311 /* is Two Dimensial Paging */
/* mode enabled */
/* Architectural interrupt line count. */
#define KVM_NR_INTERRUPTS 256
/*
* e2k arch-dependent limits for the nr of threads virtual CPUs
*/
/* KVM manage */
#define KVM_VM_MAX_LIMIT 1024 /* max number of VM IDs at use */
/* VCPUs manage */
#define KVM_MAX_VCPUS 64
typedef struct kvm_memory_alias {
__u32 slot; /* this has a different namespace than memory slots */
__u32 flags;
__u64 guest_alias_addr;
__u64 memory_size;
__u64 target_addr;
} kvm_memory_alias_t;
/* arch e2k additions flags for kvm_memory_region::flags */
#define KVM_MEM_ADD_TYPE 0x0010 /* region should be added with */
/* type of memory */
#define KVM_MEM_VCPU_RAM 0x0020 /* memory region is common RAM */
#define KVM_MEM_VCPU_VRAM 0x0040 /* memory region is virtual */
/* registers emulation memory */
#define KVM_MEM_IO_VRAM 0x0080 /* memory region is virtual IO memory */
/* to emulate ISA, VGA VRAM (low) */
#define KVM_MEM_USER_RAM 0x0100 /* memory is mapped to user space of */
/* host application */
/* (in our case QEMU) */
#define KVM_MEM_TYPE_MASK (KVM_MEM_VCPU_RAM | KVM_MEM_VCPU_VRAM | \
KVM_MEM_IO_VRAM | KVM_MEM_USER_RAM)
typedef enum {
guest_ram_mem_type = 0x01, /* memory is common RAM (low & high) */
guest_vram_mem_type = 0x02, /* memory is virtual registers */
/* memory (VCPU, VMMU ... emulation) */
guest_io_vram_mem_type = 0x03, /* memory is virtual IO memory */
/* to emulate ISA, VGA-VRAM (low) */
guest_user_ram_mem_type = 0x04, /* memory is mapped to user space of */
/* host application (QEMU) */
} kvm_guest_mem_type_t;
#define KVM_MAX_VRAM_AREAS 4 /* max number of VRAM areas */
/* for KVM_GET_IRQCHIP and KVM_SET_IRQCHIP */
struct kvm_pic_state {
__u8 last_irr; /* edge detection */
__u8 irr; /* interrupt request register */
__u8 imr; /* interrupt mask register */
__u8 isr; /* interrupt service register */
__u8 priority_add; /* highest irq priority */
__u8 irq_base;
__u8 read_reg_select;
__u8 poll;
__u8 special_mask;
__u8 init_state;
__u8 auto_eoi;
__u8 rotate_on_auto_eoi;
__u8 special_fully_nested_mode;
__u8 init4; /* true if 4 byte init */
__u8 elcr; /* PIIX edge/trigger selection */
__u8 elcr_mask;
};
typedef struct kvm_kernel_area_shadow {
__u32 slot; /* this has a different namespace than memory and */
/* alias slots */
__u32 flags;
__u64 kernel_addr; /* host kernel area base address */
__u64 area_size;
__u64 guest_shadow_addr; /* guest kernel base address */
/* should be alias of memory region */
} kvm_kernel_area_shadow_t;
#define KVM_IOAPIC_NUM_PINS 24
struct kvm_ioapic_state {
__u64 base_address;
__u32 ioregsel;
__u32 id;
__u32 irr;
__u32 pad;
union {
__u64 bits;
struct {
__u8 vector;
__u8 delivery_mode:3;
__u8 dest_mode:1;
__u8 delivery_status:1;
__u8 polarity:1;
__u8 remote_irr:1;
__u8 trig_mode:1;
__u8 mask:1;
__u8 reserve:7;
__u8 reserved[4];
__u8 dest_id;
} fields;
} redirtbl[KVM_IOAPIC_NUM_PINS];
__u32 node_id;
};
#define KVM_IOEPIC_NUM_PINS 64
#define KVM_IRQCHIP_IOAPIC 0
#define KVM_IRQCHIP_IOEPIC 1
#define KVM_NR_IRQCHIPS 2
/* for KVM_GET_REGS and KVM_SET_REGS */
struct kvm_regs {
/* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
__u64 upsr;
};
/* for KVM_GET_LAPIC and KVM_SET_LAPIC */
#define KVM_APIC_REG_SIZE 0x400
struct kvm_lapic_state {
char regs[KVM_APIC_REG_SIZE];
};
/* for KVM_GET_SREGS and KVM_SET_SREGS */
struct kvm_sregs {
/* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */
__u64 USD_lo, USD_hi;
__u64 PSP_lo, PSP_hi;
__u64 PCSP_lo, PCSP_hi;
__u64 apic_base;
__u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
};
/* for KVM_GET_FPU and KVM_SET_FPU */
struct kvm_fpu {
};
struct kvm_debug_exit_arch {
__u32 exception;
__u32 pad;
__u64 pc;
__u64 dr6;
__u64 dr7;
};
#define KVM_GUESTDBG_USE_SW_BP 0x00010000
#define KVM_GUESTDBG_USE_HW_BP 0x00020000
#define KVM_GUESTDBG_INJECT_DB 0x00040000
#define KVM_GUESTDBG_INJECT_BP 0x00080000
/* for KVM_SET_GUEST_DEBUG */
struct kvm_guest_debug_arch {
__u64 debugreg[8];
};
/* When set in flags, include corresponding fields on KVM_SET_VCPU_EVENTS */
#define KVM_VCPUEVENT_VALID_NMI_PENDING 0x00000001
#define KVM_VCPUEVENT_VALID_SIPI_VECTOR 0x00000002
/* for KVM_GET/SET_VCPU_EVENTS */
struct kvm_vcpu_events {
struct {
__u8 injected;
__u8 nr;
__u8 has_error_code;
__u8 pad;
__u32 error_code;
} exception;
struct {
__u8 injected;
__u8 nr;
__u8 soft;
__u8 pad;
} interrupt;
struct {
__u8 injected;
__u8 pending;
__u8 masked;
__u8 pad;
} nmi;
__u32 sipi_vector;
__u32 flags;
__u32 reserved[10];
};
/* for KVM_GET_PIT and KVM_SET_PIT */
struct kvm_pit_channel_state {
__u32 count; /* can be 65536 */
__u16 latched_count;
__u8 count_latched;
__u8 status_latched;
__u8 status;
__u8 read_state;
__u8 write_state;
__u8 write_latch;
__u8 rw_mode;
__u8 mode;
__u8 bcd;
__u8 gate;
__s64 count_load_time;
};
struct kvm_pit_state {
struct kvm_pit_channel_state channels[3];
};
#define KVM_PIT_FLAGS_HPET_LEGACY 0x00000001
struct kvm_pit_state2 {
struct kvm_pit_channel_state channels[3];
__u32 flags;
__u32 reserved[9];
};
struct kvm_reinject_control {
__u8 pit_reinject;
__u8 reserved[31];
};
/* definition of registers in kvm_run */
struct kvm_sync_regs {
};
/*
* e2k arch specific kvm dev/vm/vcpu ioctl's
*/
/*
* Guest machine info
*/
typedef struct kvm_guest_info {
int cpu_mdl; /* guest CPU model (as at IDR) */
int cpu_rev; /* guest CPU revision (as at IDR) */
int cpu_iset; /* guest CPU instruction set version */
_Bool is_stranger; /* guest is stranger type */
/* of CPU/machine */
_Bool mmu_support_pt_v6; /* guest MMU support new MMU Page */
/* Tables structures V6 */
_Bool is_pv; /* guest is paravirtualized */
/* and should not be run as bare */
unsigned long features; /* guest features */
/* see details <asm/kvm/hypervisor.h> */
} kvm_guest_info_t;
typedef struct kvm_guest_area_alloc {
void *region; /* guest memory region to allocate area */
/* or NULL if any region */
void *area; /* allocated area - result of ioctl() */
unsigned long start; /* start address to allocate */
/* or 0 if any address */
unsigned long size; /* area size (bytes) */
unsigned long align; /* the area beginning align */
unsigned long flags; /* allocation flags and modes */
kvm_guest_mem_type_t type; /* type of memory: RAM, VRAM */
} kvm_guest_area_alloc_t;
typedef struct kvm_guest_area_reserve {
unsigned long start; /* start address to reserve */
unsigned long size; /* area size (bytes) */
kvm_guest_mem_type_t type; /* type of memory: RAM, VRAM */
} kvm_guest_area_reserve_t;
/* guest area allocation flags */
#define KVM_ALLOC_AREA_PRESENT 0x00000001ULL
#define KVM_ALLOC_AREA_LOCKED 0x00000002ULL
#define KVM_ALLOC_AREA_ZEROED 0x00000004ULL
/* protections as part of flags */
#define KVM_ALLOC_AREA_PROT_READ 0x00010000ULL
#define KVM_ALLOC_AREA_PROT_WRITE 0x00020000ULL
#define KVM_ALLOC_AREA_PROT_EXEC 0x00040000ULL
/* some additional features */
#define KVM_ALLOC_AREA_HUGE 0x00100000ULL /* prefered mapping */
/* to huge pages */
#define KVM_ALLOC_AREA_MAP_FLAGS \
(KVM_ALLOC_AREA_PROT_READ | KVM_ALLOC_AREA_PROT_WRITE | \
KVM_ALLOC_AREA_PROT_EXEC | \
KVM_ALLOC_AREA_HUGE)
/* guest addresses map */
#define KVM_GUEST_PAGE_OFFSET 0x00000010
#define KVM_GUEST_KERNEL_IMAGE_BASE 0x00000020
#define KVM_GUEST_VCPU_VRAM_PHYS_BASE 0x00000040
#define KVM_GUEST_VCPU_VRAM_VIRT_BASE 0x00000080
#define KVM_GUEST_VCPU_VRAM_SIZE 0x00000100
#define KVM_GUEST_IO_VRAM_PHYS_BASE 0x00000200
#define KVM_GUEST_IO_VRAM_VIRT_BASE 0x00000400
#define KVM_GUEST_IO_VRAM_SIZE 0x00000800
#define KVM_HOST_PAGE_OFFSET 0x00001000
#define KVM_HOST_KERNEL_IMAGE_BASE 0x00002000
#define KVM_KERNEL_AREAS_SIZE 0x00004000
#define KVM_SHADOW_KERNEL_IMAGE_BASE 0x00008000
#define KVM_GUEST_IO_PORTS_BASE 0x00010000
#define KVM_GUEST_NBSR_BASE_NODE_0 0x00020000
#define KVM_GUEST_NBSR_BASE_NODE_1 0x00040000
#define KVM_GUEST_NBSR_BASE_NODE_2 0x00080000
#define KVM_GUEST_NBSR_BASE_NODE_3 0x00100000
#define KVM_HOST_INFO_VRAM_SIZE 0x00200000
/* flags of IO ports area mapping for guest */
#define KVM_IO_PORTS_MMAP 0x1ff00000000 /* > max physical memory */
#define KVM_VCPU_MAX_GUEST_ARGS 4
typedef struct kvm_vcpu_guest_startup {
char *kernel_base; /* base address of guest kernel image */
long kernel_size; /* guest kernel image size */
char *entry_point; /* entry point to startup guest image */
int args_num; /* number of additional arguments to pass */
/* to guest image */
unsigned long args[KVM_VCPU_MAX_GUEST_ARGS]; /* arguments */
unsigned long flags; /* flags specifying guest properties */
/* see details below */
unsigned long trap_off; /* trap entry (ttable #0) offset from guest */
/* kernel image base */
} kvm_vcpu_guest_startup_t;
typedef enum kvm_pci_region_type {
kvm_pci_undef_region_type,
kvm_pci_io_type, /* PCI IO ports region */
kvm_pci_mem_type, /* PCI memory region */
kvm_pci_pref_mem_type, /* PCI prefetchable memory region */
} kvm_pci_region_type_t;
typedef struct kvm_pci_region {
int node_id; /* the node # */
kvm_pci_region_type_t type; /* the region type: IO/MEM/PMEM */
unsigned long base; /* the base address of the region */
unsigned long size; /* the region size */
} kvm_pci_region_t;
typedef struct kvm_base_addr_node {
int node_id; /* the node # */
unsigned long base; /* the base address */
} kvm_base_addr_node_t;
typedef struct kvm_guest_nbsr_state {
int node_id;
unsigned int rt_pcim0;
unsigned int rt_pcim1;
unsigned int rt_pcim2;
unsigned int rt_pcim3;
unsigned int rt_pciio0;
unsigned int rt_pciio1;
unsigned int rt_pciio2;
unsigned int rt_pciio3;
unsigned int rt_pcimp_b0;
unsigned int rt_pcimp_b1;
unsigned int rt_pcimp_b2;
unsigned int rt_pcimp_b3;
unsigned int rt_pcimp_e0;
unsigned int rt_pcimp_e1;
unsigned int rt_pcimp_e2;
unsigned int rt_pcimp_e3;
unsigned int rt_pcicfgb;
unsigned long rt_msi;
unsigned int iommu_ctrl;
unsigned long iommu_ptbar;
unsigned long iommu_dtbar;
unsigned long iommu_err;
unsigned long iommu_err_info;
unsigned int prepic_ctrl2;
unsigned int prepic_err_stat;
unsigned int prepic_err_int;
unsigned int prepic_linp0;
unsigned int prepic_linp1;
unsigned int prepic_linp2;
unsigned int prepic_linp3;
unsigned int prepic_linp4;
unsigned int prepic_linp5;
} kvm_guest_nbsr_state_t;
#endif /* __ASSEMBLY__ */
/*
* Flags specifying guest properties (see field flags above)
*/
#define NATIVE_KERNEL_IMAGE_GUEST_FLAG 0x0000000000000001UL
#define PARAVIRT_KERNEL_IMAGE_GUEST_FLAG 0x0000000000000002UL
#define LINTEL_IMAGE_GUEST_FLAG 0x0000000000000100UL
#define E2K_SYSCALL_TRAP_ENTRY_SIZE (2 * 1024) /* 2Kb */
#define KVM_GUEST_STARTUP_SYSCALL_NUM 12 /* # of system call to launch */
/* guest using such method */
#define KVM_GUEST_STARTUP_ENTRY_NUM 32 /* # of trap table entry to */
/* launch guest using direct */
/* control transfer (call or */
/* return) */
#define KVM_PV_VCPU_TRAP_ENTRY_NUM 36 /* # of trap table entry to */
/* launch trap handler of */
/* paravirtualized guest */
/* (same as ttable #0) */
#define GUEST_COMPAT_FAST_SYSCALL_TRAP_NUM 5
#define GUEST_FAST_SYSCALL_TRAP_NUM 6
#define GUEST_PROT_FAST_SYSCALL_TRAP_NUM 7
#ifndef __ASSEMBLY__
#define KVM_GET_ARCH_API_VERSION _IO(KVMIO, 0xe1)
#define KVM_VCPU_THREAD_SETUP _IO(KVMIO, 0xe0)
#define KVM_GET_GUEST_ADDRESS _IOWR(KVMIO, 0xe2, unsigned long *)
#define KVM_RESET_E2K_VCPU _IO(KVMIO, 0xe3)
#define KVM_ALLOC_GUEST_AREA _IOWR(KVMIO, 0xe4, \
kvm_guest_area_alloc_t)
#define KVM_VCPU_GUEST_STARTUP _IOW(KVMIO, 0xe5, \
kvm_vcpu_guest_startup_t)
#define KVM_SET_KERNEL_IMAGE_SHADOW _IOW(KVMIO, 0xe6, \
kvm_kernel_area_shadow_t)
#define KVM_SET_IRQCHIP_BASE _IOW(KVMIO, 0xe7, unsigned long)
#define KVM_SET_SYS_TIMER_BASE _IOW(KVMIO, 0xe8, unsigned long)
#define KVM_SET_SPMC_CONF_BASE _IOW(KVMIO, 0xe9, unsigned long)
#define KVM_RESERVE_GUEST_AREA _IOWR(KVMIO, 0xea, \
kvm_guest_area_reserve_t)
#define KVM_SET_SPMC_CONF_BASE_SPMC_IN_QEMU \
_IOW(KVMIO, 0xeb, unsigned long)
#define KVM_SET_I2C_SPI_CONF_BASE _IOW(KVMIO, 0xec, unsigned long)
#define KVM_SET_GUEST_INFO _IOW(KVMIO, 0xed, unsigned long)
#define KVM_GET_NBSR_STATE _IOR(KVMIO, 0xee, \
kvm_guest_nbsr_state_t)
#define KVM_CREATE_SIC_NBSR _IO(KVMIO, 0xef)
#define KVM_SET_PCI_REGION _IOW(KVMIO, 0xf0, kvm_pci_region_t)
#define KVM_SET_COUNT_NUMA_NODES _IOW(KVMIO, 0xf1, unsigned long)
#define KVM_SET_MAX_NR_NODE_CPU _IOW(KVMIO, 0xf2, unsigned long)
#define KVM_SET_CEPIC_FREQUENCY _IOW(KVMIO, 0xf3, unsigned long)
#define KVM_SET_WD_PRESCALER_MULT _IOW(KVMIO, 0xf4, unsigned long)
/* IOCTL 0xf5 reserved for Imagination GPU passthrough */
#define KVM_SET_LEGACY_VGA_PASSTHROUGH _IOW(KVMIO, 0xf6, unsigned long)
/* e2k-specific exit reasons from KVM to userspace assistance */
#define KVM_EXIT_E2K_NOTIFY_IO 33
#define KVM_EXIT_E2K_SHUTDOWN 36
#define KVM_EXIT_E2K_RESTART 37
#define KVM_EXIT_E2K_PANIC 38
#define KVM_EXIT_E2K_INTR 39
#define KVM_EXIT_E2K_UNKNOWN 44
#endif /* __ASSEMBLY__ */
#endif /* _ASM_E2K_KVM_H */

View File

@ -0,0 +1,101 @@
#ifndef _E2K_MMAN_H_
#define _E2K_MMAN_H_
/*
* Copyright (C) 1998-2000 Hewlett-Packard Co
* Copyright (C) 1998-2000 David Mosberger-Tang <davidm@hpl.hp.com>
*
* Adopted for Linux/E2K. To be extended for proper E2K mem. management.
*/
#define PROT_NONE 0x0 /* page can not be accessed */
#define PROT_READ 0x1 /* page can be read */
#define PROT_WRITE 0x2 /* page can be written */
#define PROT_EXEC 0x4 /* page can be executed */
#define PROT_SEM 0x8 /* page may be used for atomic ops */
#define PROT_GROWSDOWN 0x20 /* mprotect flag: extend change */
/* to start of growsdown vma */
#define PROT_GROWSUP 0x40 /* mprotect flag: extend change */
/* to end of growsup vma */
#define PROT_CUI 0xffff00
#define PROT_CUI_SHIFT 8
#define PROT_CUI_MASK 0xFFFF
#define GET_CUI_FROM_INT_PROT(prot) (((prot) >> PROT_CUI_SHIFT) & \
PROT_CUI_MASK)
#define PUT_CUI_TO_INT_PROT(prot, cui) ((((cui) & PROT_CUI_MASK) << \
PROT_CUI_SHIFT) | prot)
/* 0x01 - 0x03 are defined in linux/mman.h */
#define MAP_TYPE 0x00000f /* Mask for type of mapping */
#define MAP_ANONYMOUS 0x000010 /* don't use a file */
#define MAP_FIXED 0x000100 /* Interpret addr exactly */
#define MAP_DENYWRITE 0x000800 /* ETXTBSY */
#define MAP_GROWSDOWN 0x001000 /* stack-like segment */
#define MAP_GROWSUP 0x002000 /* register stack-like segment */
#define MAP_EXECUTABLE 0x004000 /* mark it as an executable */
#define MAP_LOCKED 0x008000 /* pages are locked */
#define MAP_NORESERVE 0x010000 /* don't check for reservations */
#define MAP_POPULATE 0x020000 /* populate (prefault) pagetables */
#define MAP_NONBLOCK 0x040000 /* do not block on IO */
#define MAP_FIRST32 0x080000 /* in protected mode map in */
/* first 2 ** 32 area */
#define MAP_WRITECOMBINED 0x100000 /* Write combine */
#define MAP_HUGETLB 0x200000 /* create a huge page mapping */
#define MAP_FIXED_NOREPLACE 0x400000 /* MAP_FIXED which doesn't unmap */
/* underlying mapping */
#define MAP_STACK MAP_GROWSDOWN
#define MLOCK_ONFAULT 0x01 /* Lock pages in range after they are faulted in, do not prefault */
#define MS_ASYNC 1 /* sync memory asynchronously */
#define MS_INVALIDATE 2 /* invalidate the caches */
#define MS_SYNC 4 /* synchronous memory sync */
#define MCL_CURRENT 1 /* lock all current mappings */
#define MCL_FUTURE 2 /* lock all future mappings */
#define MCL_ONFAULT 4 /* lock all pages that are faulted in */
#define MADV_NORMAL 0 /* no further special treatment */
#define MADV_RANDOM 1 /* expect random page references */
#define MADV_SEQUENTIAL 2 /* expect sequential page references */
#define MADV_WILLNEED 3 /* will need these pages */
#define MADV_DONTNEED 4 /* don't need these pages */
/* common parameters: try to keep these consistent across architectures */
#define MADV_FREE 8 /* free pages only if memory pressure */
#define MADV_REMOVE 9 /* remove these pages & resources */
#define MADV_DONTFORK 10 /* don't inherit across fork */
#define MADV_DOFORK 11 /* do inherit across fork */
#define MADV_HWPOISON 100 /* poison a page for testing */
#define MADV_SOFT_OFFLINE 101 /* soft offline page for testing */
#define MADV_MERGEABLE 12 /* KSM may merge identical pages */
#define MADV_UNMERGEABLE 13 /* KSM may not merge identical pages */
#define MADV_HUGEPAGE 14 /* Worth backing with hugepages */
#define MADV_NOHUGEPAGE 15 /* Not worth backing with hugepages */
#define MADV_DONTDUMP 16 /* Explicity exclude from the core dump,
overrides the coredump filter bits */
#define MADV_DODUMP 17 /* Clear the MADV_NODUMP flag */
#define MADV_WIPEONFORK 18 /* Zero memory on fork, child only */
#define MADV_KEEPONFORK 19 /* Undo MADV_WIPEONFORK */
#define MADV_COLD 20 /* deactivate these pages */
#define MADV_PAGEOUT 21 /* reclaim these pages */
/* compatibility flags */
#define MAP_ANON MAP_ANONYMOUS
#define MAP_FILE 0
#define PKEY_DISABLE_ACCESS 0x1
#define PKEY_DISABLE_WRITE 0x2
#define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS |\
PKEY_DISABLE_WRITE)
#endif /* _E2K_MMAN_H_ */

View File

@ -0,0 +1,470 @@
#ifndef _E2K_UNISTD_H_
#define _E2K_UNISTD_H_
/*
* Taken from i386 sub-tree.
* Migration to E2K is still in progress. Please, be patient.
*/
#ifdef __ptr64__
#define LINUX_SYSCALL_TRAPNUM LINUX_SYSCALL64_TRAPNUM
#else /* !__ptr64__ */
#define LINUX_SYSCALL_TRAPNUM LINUX_SYSCALL32_TRAPNUM
#endif /* __ptr64__ */
#define LINUX_SYSCALL_TRAPNUM_OLD 4 /* Deprecated */
#define LINUX_SYSCALL32_TRAPNUM 1 /* Use E2K trap entry #1 */
#define LINUX_SYSCALL64_TRAPNUM 3 /* Use E2K trap entry #3 */
#define LINUX_FAST_SYSCALL32_TRAPNUM 5
#define LINUX_FAST_SYSCALL64_TRAPNUM 6
#define LINUX_FAST_SYSCALL128_TRAPNUM 7
/*
* This file contains the system call numbers.
*/
#define __NR_restart_syscall 0
#define __NR_exit 1
#define __NR_fork 2
#define __NR_read 3
#define __NR_write 4
#define __NR_open 5
#define __NR_close 6
#define __NR_waitpid 7
#define __NR_creat 8
#define __NR_link 9
#define __NR_unlink 10
#define __NR_execve 11
#define __NR_chdir 12
#define __NR_time 13
#define __NR_mknod 14
#define __NR_chmod 15
#define __NR_lchown 16
#define __NR_break 17
#define __NR_oldstat 18
#define __NR_lseek 19
#define __NR_getpid 20
#define __NR_mount 21
#define __NR_umount 22
#define __NR_setuid 23
#define __NR_getuid 24
#define __NR_stime 25
#define __NR_ptrace 26
#define __NR_alarm 27
#define __NR_oldfstat 28
#define __NR_pause 29
#define __NR_utime 30
#define __NR_stty 31
#define __NR_gtty 32
#define __NR_access 33
#define __NR_nice 34
#define __NR_ftime 35
#define __NR_sync 36
#define __NR_kill 37
#define __NR_rename 38
#define __NR_mkdir 39
#define __NR_rmdir 40
#define __NR_dup 41
#define __NR_pipe 42
#define __NR_times 43
#define __NR_prof 44
#define __NR_brk 45
#define __NR_setgid 46
#define __NR_getgid 47
#define __NR_signal 48
#define __NR_geteuid 49
#define __NR_getegid 50
#define __NR_acct 51
#define __NR_umount2 52
#define __NR_lock 53
#define __NR_ioctl 54
#define __NR_fcntl 55
#define __NR_mpx 56
#define __NR_setpgid 57
#define __NR_ulimit 58
#define __NR_oldolduname 59
#define __NR_umask 60
#define __NR_chroot 61
#define __NR_ustat 62
#define __NR_dup2 63
#define __NR_getppid 64
#define __NR_getpgrp 65
#define __NR_setsid 66
#define __NR_sigaction 67
#define __NR_sgetmask 68
#define __NR_ssetmask 69
#define __NR_setreuid 70
#define __NR_setregid 71
#define __NR_sigsuspend 72
#define __NR_sigpending 73
#define __NR_sethostname 74
#define __NR_setrlimit 75
#define __NR_getrlimit 76 /* Back compatible 2Gig limited rlimit */
#define __NR_getrusage 77
#define __NR_gettimeofday 78
#define __NR_settimeofday 79
#define __NR_getgroups 80
#define __NR_setgroups 81
#define __NR_select 82
#define __NR_symlink 83
#define __NR_oldlstat 84
#define __NR_readlink 85
#define __NR_uselib 86
#define __NR_swapon 87
#define __NR_reboot 88
#define __NR_readdir 89
#define __NR_mmap 90
#define __NR_munmap 91
#define __NR_truncate 92
#define __NR_ftruncate 93
#define __NR_fchmod 94
#define __NR_fchown 95
#define __NR_getpriority 96
#define __NR_setpriority 97
#define __NR_profil 98
#define __NR_statfs 99
#define __NR_fstatfs 100
#define __NR_ioperm 101
#define __NR_socketcall 102
#define __NR_syslog 103
#define __NR_setitimer 104
#define __NR_getitimer 105
#define __NR_stat 106
#define __NR_lstat 107
#define __NR_fstat 108
#define __NR_olduname 109
#define __NR_iopl 110
#define __NR_vhangup 111
#define __NR_idle 112
#define __NR_vm86old 113
#define __NR_wait4 114
#define __NR_swapoff 115
#define __NR_sysinfo 116
#define __NR_ipc 117
#define __NR_fsync 118
#define __NR_sigreturn 119
#define __NR_clone 120
#define __NR_setdomainname 121
#define __NR_uname 122
#define __NR_modify_ldt 123
#define __NR_adjtimex 124
#define __NR_mprotect 125
#define __NR_sigprocmask 126
#define __NR_create_module 127
#define __NR_init_module 128
#define __NR_delete_module 129
#define __NR_get_kernel_syms 130
#define __NR_quotactl 131
#define __NR_getpgid 132
#define __NR_fchdir 133
#define __NR_bdflush 134
#define __NR_sysfs 135
#define __NR_personality 136
#define __NR_afs_syscall 137 /* Syscall for Andrew File System */
#define __NR_setfsuid 138
#define __NR_setfsgid 139
#define __NR__llseek 140
#define __NR_getdents 141
#define __NR__newselect 142
#define __NR_flock 143
#define __NR_msync 144
#define __NR_readv 145
#define __NR_writev 146
#define __NR_getsid 147
#define __NR_fdatasync 148
#define __NR__sysctl 149
#define __NR_mlock 150
#define __NR_munlock 151
#define __NR_mlockall 152
#define __NR_munlockall 153
#define __NR_sched_setparam 154
#define __NR_sched_getparam 155
#define __NR_sched_setscheduler 156
#define __NR_sched_getscheduler 157
#define __NR_sched_yield 158
#define __NR_sched_get_priority_max 159
#define __NR_sched_get_priority_min 160
#define __NR_sched_rr_get_interval 161
#define __NR_nanosleep 162
#define __NR_mremap 163
#define __NR_setresuid 164
#define __NR_getresuid 165
#define __NR_vm86 166
#define __NR_query_module 167
#define __NR_poll 168
#define __NR_nfsservctl 169
#define __NR_setresgid 170
#define __NR_getresgid 171
#define __NR_prctl 172
#define __NR_rt_sigreturn 173
#define __NR_rt_sigaction 174
#define __NR_rt_sigprocmask 175
#define __NR_rt_sigpending 176
#define __NR_rt_sigtimedwait 177
#define __NR_rt_sigqueueinfo 178
#define __NR_rt_sigsuspend 179
#define __NR_pread 180
#define __NR_pwrite 181
#define __NR_chown 182
#define __NR_getcwd 183
#define __NR_capget 184
#define __NR_capset 185
#define __NR_sigaltstack 186
#define __NR_sendfile 187
#define __NR_getpmsg 188 /* some people actually want streams */
#define __NR_putpmsg 189 /* some people actually want streams */
#define __NR_vfork 190
#define __NR_ugetrlimit 191 /* SuS compliant getrlimit */
#define __NR_mmap2 192
#define __NR_truncate64 193
#define __NR_ftruncate64 194
#define __NR_stat64 195
#define __NR_lstat64 196
#define __NR_fstat64 197
#define __NR_pidfd_send_signal 205
#define __NR_pidfd_open 206
#define __NR_pivot_root 217
#define __NR_mincore 218
#define __NR_madvise 219
#define __NR_madvise1 219 /* delete when C lib stub is removed */
#define __NR_getdents64 220
#define __NR_fcntl64 221
#define __NR_core 222 /* for analys kernel core */
#define __NR_macctl 223 /* MCST trust linux */
#define __NR_newfstatat 224
#define __NR_emergency 225
#define __NR_e2k_sigsetjmp 226 /* setjmp e2k specific */
#define __NR_e2k_longjmp 227 /* longjmp e2k specific */
#define __NR_e2k_syswork 228 /* e2k_syswork */
#define __NR_clone_thread 229
#define __NR_clone2 __NR_clone_thread /* don't delete old name */
#define __NR_e2k_longjmp2 230 /* Second Edition */
#define __NR_soft_debug 231
#define __NR_setxattr 232
#define __NR_lsetxattr 233
#define __NR_fsetxattr 234
#define __NR_getxattr 235
#define __NR_lgetxattr 236
#define __NR_fgetxattr 237
#define __NR_listxattr 238
#define __NR_llistxattr 239
#define __NR_flistxattr 240
#define __NR_removexattr 241
#define __NR_lremovexattr 242
#define __NR_fremovexattr 243
#define __NR_gettid 244
#define __NR_readahead 245
#define __NR_tkill 246
#define __NR_sendfile64 247
#define __NR_futex 248
#define __NR_sched_setaffinity 249
#define __NR_sched_getaffinity 250
#define __NR_pipe2 251
#define __NR_set_backtrace 252
#define __NR_get_backtrace 253
#define __NR_access_hw_stacks 254
#define __NR_el_posix 255
#define __NR_io_uring_setup 256
#define __NR_io_uring_enter 257
#define __NR_io_uring_register 258
#define __NR_set_tid_address 259
#define __NR_el_binary 260
#define __NR_timer_create 261
#define __NR_timer_settime 262
#define __NR_timer_gettime 263
#define __NR_timer_getoverrun 264
#define __NR_timer_delete 265
#define __NR_clock_settime 266
#define __NR_clock_gettime 267
#define __NR_clock_getres 268
#define __NR_clock_nanosleep 269
/* added for compatibility with x86_64 */
#define __NR_msgget 270
#define __NR_msgctl 271
#define __NR_msgrcv 272
#define __NR_msgsnd 273
#define __NR_semget 274
#define __NR_semctl 275
#define __NR_semtimedop 276
#define __NR_semop 277
#define __NR_shmget 278
#define __NR_shmctl 279
#define __NR_shmat 280
#define __NR_shmdt 281
#define __NR_open_tree 282
#define __NR_move_mount 283
#define __NR_rseq 284
#define __NR_io_pgetevents 285
#define __NR_accept4 286
#define __NR_sched_setattr 287
#define __NR_sched_getattr 288
#define __NR_ioprio_set 289
#define __NR_ioprio_get 290
#define __NR_inotify_init 291
#define __NR_inotify_add_watch 292
#define __NR_inotify_rm_watch 293
#define __NR_io_setup 294
#define __NR_io_destroy 295
#define __NR_io_getevents 296
#define __NR_io_submit 297
#define __NR_io_cancel 298
#define __NR_fadvise64 299
#define __NR_exit_group 300
#define __NR_lookup_dcookie 301
#define __NR_epoll_create 302
#define __NR_epoll_ctl 303
#define __NR_epoll_wait 304
#define __NR_remap_file_pages 305
#define __NR_statfs64 306
#define __NR_fstatfs64 307
#define __NR_tgkill 308
#define __NR_utimes 309
#define __NR_fadvise64_64 310
#define __NR_vserver 311
#define __NR_mbind 312
#define __NR_get_mempolicy 313
#define __NR_set_mempolicy 314
#define __NR_mq_open 315
#define __NR_mq_unlink 316
#define __NR_mq_timedsend 317
#define __NR_mq_timedreceive 318
#define __NR_mq_notify 319
#define __NR_mq_getsetattr 320
#define __NR_kexec_load 321
#define __NR_waitid 322
#define __NR_add_key 323
#define __NR_request_key 324
#define __NR_keyctl 325
#define __NR_mcst_rt 326
#define __NR_getcpu 327
#define __NR_move_pages 328
#define __NR_splice 329
#define __NR_vmsplice 330
#define __NR_tee 331
#define __NR_migrate_pages 332
#define __NR_utimensat 333
#define __NR_rt_tgsigqueueinfo 334
#define __NR_openat 335
#define __NR_mkdirat 336
#define __NR_mknodat 337
#define __NR_fchownat 338
#define __NR_unlinkat 339
#define __NR_renameat 340
#define __NR_linkat 341
#define __NR_symlinkat 342
#define __NR_readlinkat 343
#define __NR_fchmodat 344
#define __NR_faccessat 345
#define __NR_epoll_pwait 346
#define __NR_signalfd4 347
#define __NR_eventfd2 348
#define __NR_recvmmsg 349
/* free (unused) entries - reserve 350 - 350 */
#define __NR_timerfd_create 351
#define __NR_timerfd_settime 352
#define __NR_timerfd_gettime 353
#define __NR_preadv 354
#define __NR_pwritev 355
#define __NR_fallocate 356
#define __NR_sync_file_range 357
#define __NR_dup3 358
#define __NR_inotify_init1 359
#define __NR_epoll_create1 360
#define __NR_fstatat64 361
#define __NR_futimesat 362
#define __NR_perf_event_open 363
#define __NR_unshare 364
#define __NR_get_robust_list 365
#define __NR_set_robust_list 366
#define __NR_pselect6 367
#define __NR_ppoll 368
#define __NR_setcontext 369
#define __NR_makecontext 370
#define __NR_swapcontext 371
#define __NR_freecontext 372
#define __NR_fanotify_init 373
#define __NR_fanotify_mark 374
#define __NR_prlimit64 375
#define __NR_clock_adjtime 376
#define __NR_syncfs 377
#define __NR_sendmmsg 378
#define __NR_setns 379
#define __NR_process_vm_readv 380
#define __NR_process_vm_writev 381
#define __NR_kcmp 382
#define __NR_finit_module 383
#define __NR_renameat2 384
#define __NR_getrandom 385
#define __NR_memfd_create 386
#define __NR_bpf 387
#define __NR_execveat 388
#define __NR_userfaultfd 389
#define __NR_membarrier 390
#define __NR_mlock2 391
#define __NR_seccomp 392
#define __NR_shutdown 393
#define __NR_copy_file_range 394
#define __NR_preadv2 395
#define __NR_pwritev2 396
/* free (unused) entries - reserve 397 - 399 */
#define __NR_name_to_handle_at 400
#define __NR_open_by_handle_at 401
#define __NR_statx 402
/* added for compatibility with x86_64 */
#define __NR_socket 403
#define __NR_connect 404
#define __NR_accept 405
#define __NR_sendto 406
#define __NR_recvfrom 407
#define __NR_sendmsg 408
#define __NR_recvmsg 409
#define __NR_bind 410
#define __NR_listen 411
#define __NR_getsockname 412
#define __NR_getpeername 413
#define __NR_socketpair 414
#define __NR_setsockopt 415
#define __NR_getsockopt 416
/* free (unused) entries - reserve 417 - 418 */
#define __NR_arch_prctl 419
/* added for combability of protected system calls v1-v5 & v6 */
#define __NR_newuselib 420
#define __NR_rt_sigaction_ex 421
/* protected Mode specific memory allocation syscall number */
#define __NR_get_mem 422
#define __NR_free_mem 423
/* protected mode specific clean memory from old invalid descriptors */
#define __NR_clean_descriptors 424
/* protected mode specific unloading module from memory */
#define __NR_unuselib 425
#define __NR_clone3 426
#define __NR_fsopen 427
#define __NR_fsconfig 428
#define __NR_fsmount 429
#define __NR_fspick 430
#define NR_syscalls 431
/* compatibility with x86_64 */
#define __NR_pread64 __NR_pread
#define __NR_pwrite64 __NR_pwrite
/* Fast system calls */
#define __NR_fast_sys_gettimeofday 0
#define __NR_fast_sys_clock_gettime 1
#define __NR_fast_sys_getcpu 2
#define __NR_fast_sys_siggetmask 3
#define __NR_fast_sys_getcontext 4
#define __NR_fast_sys_set_return 5
#endif /* _E2K_UNISTD_H_ */

View File

@ -0,0 +1,214 @@
/*
* host-signal.h: signal info dependent on the host architecture
*
* Copyright (c) 2024 Denis Drakhnia <numas13@gmail.com>
*
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
* See the COPYING file in the top-level directory.
*/
#ifndef E2K_HOST_SIGNAL_H
#define E2K_HOST_SIGNAL_H
/* The third argument to a SA_SIGINFO handler is ucontext_t. */
typedef ucontext_t host_sigcontext;
static inline uintptr_t host_signal_pc(host_sigcontext *uc)
{
return uc->uc_mcontext.cr0_hi;
}
static inline void host_signal_set_pc(host_sigcontext *uc, uintptr_t pc)
{
uc->uc_mcontext.cr0_hi = pc & ~7;
}
static inline void *host_signal_mask(host_sigcontext *uc)
{
return &uc->uc_sigmask;
}
#define E2K_HS_SS_BIT (1 << 12)
#define E2K_HS_HAS_CS(h, i) (((h) & (1 << (14 + (i)))) != 0)
#define E2K_HS_HAS_ALS(h, i) (((h) & (1 << (26 + (i)))) != 0)
#define E2K_HS_HAS_ALES(h, i) (((h) & (1 << (20 + (i)))) != 0)
static inline bool e2k_check_store(const uint32_t *syll)
{
uint32_t hs, als, ales25 = 0x01c001c0;
int half_offset, syll_count = 1;
/* bundle header */
hs = syll[0];
/* offset to half-syllables */
half_offset = (hs & 15) + 1;
if (hs & E2K_HS_SS_BIT) {
syll_count += 1;
}
for (int i = 0; i < 6; ++i) {
if (E2K_HS_HAS_ALS(hs, i)) {
syll_count += 1;
}
}
for (int i = 0; i < 2; ++i) {
if (E2K_HS_HAS_CS(hs, i)) {
syll_count += 1;
}
}
if (half_offset > syll_count) {
ales25 = syll[half_offset - (E2K_HS_HAS_CS(hs, 1) ? 2 : 1)];
}
syll += hs & E2K_HS_SS_BIT ? 2 : 1; /* skip HS and SS */
for (int i = 0; i < 6; ++i) {
if (!E2K_HS_HAS_ALS(hs, i)) {
continue;
}
/* store can be only in ALS2 or ALS5 */
if (i != 2 && i != 5) {
syll += 1;
}
als = *syll++;
if (E2K_HS_HAS_ALES(hs, i)) {
uint16_t ales = extract32(ales25, i == 2 ? 16 : 0, 16);
switch (extract16(ales, 8, 8)) {
case 0x01: /* EXT */
switch (extract32(als, 24, 7)) {
case 0x02: /* stcsq */
case 0x03: /* stdsq */
case 0x04: /* stesq */
case 0x05: /* stfsq */
case 0x06: /* stgsq */
case 0x07: /* stssq */
case 0x1b: /* strd */
case 0x24: /* stgdb */
case 0x25: /* stgdh */
case 0x26: /* stgdw */
case 0x27: /* stgdd */
case 0x28: /* stapb */
case 0x29: /* staph */
case 0x2a: /* stapw */
case 0x2b: /* stapd */
case 0x2c: /* stodrb */
case 0x2d: /* stodrh */
case 0x2e: /* stodrw */
case 0x2f: /* stodrd */
case 0x30: /* stodwb */
case 0x31: /* stodwh */
case 0x32: /* stodww */
case 0x33: /* stodwd */
case 0x34: /* stodpb */
case 0x35: /* stodph */
case 0x36: /* stodpw */
case 0x37: /* stodpd */
case 0x39: /* stgdq */
case 0x3a: /* stapq */
case 0x3b: /* stodrq */
case 0x3c: /* stodwq */
case 0x3d: /* stodpq */
case 0x3f: /* staaq */
return true;
}
break;
case 0x02: /* EXT1 */
switch (extract32(als, 24, 7)) {
case 0x11: /* stmqp */
case 0x12: /* stcsmqp */
case 0x13: /* stdsmqp */
case 0x14: /* stesmqp */
case 0x15: /* stfsmqp */
case 0x16: /* stgsmqp */
case 0x17: /* stssmqp */
case 0x19: /* stgdmqp */
case 0x1a: /* stapmqp */
case 0x20: /* staaqp */
case 0x21: /* stqp */
case 0x22: /* stcsqp */
case 0x23: /* stdsqp */
case 0x24: /* stesqp */
case 0x25: /* stfsqp */
case 0x26: /* stgsqp */
case 0x27: /* stssqp */
case 0x29: /* stgdqp */
case 0x2a: /* stapqp */
case 0x2b: /* strqp */
return true;
}
break;
}
} else {
switch (extract32(als, 24, 7)) {
case 0x24: /* stb */
case 0x25: /* sth */
case 0x26: /* stw */
case 0x27: /* std */
case 0x28: /* stcsb */
case 0x29: /* stcsh */
case 0x2a: /* stcsw */
case 0x2b: /* stcsd */
case 0x2c: /* stdsb */
case 0x2d: /* stdsh */
case 0x2e: /* stdsw */
case 0x2f: /* stdsd */
case 0x30: /* stesb */
case 0x31: /* stesh */
case 0x32: /* stesw */
case 0x33: /* stesd */
case 0x34: /* stfsb */
case 0x35: /* stfsh */
case 0x36: /* stfsw */
case 0x37: /* stfsd */
case 0x38: /* stgsb */
case 0x39: /* stgsh */
case 0x3a: /* stgsw */
case 0x3b: /* stgsd */
case 0x3c: /* stssb */
case 0x3d: /* stssh */
case 0x3e: /* stssw */
case 0x3f: /* stssd */
return true;
}
}
}
return false;
}
#define e2k_exc_data_page_num 29
#define E2K_TIR_IP(lo) ((lo) & ((1ULL << 48) - 1))
#define E2K_TIR_HAS_EXCP(hi, i) (((hi) & (1ULL << (i))) != 0)
#define E2K_TIR_HAS_ALS(hi, i) (((hi) & (1ULL << (44 + (i)))) != 0)
static inline bool host_signal_write(siginfo_t *info, host_sigcontext *uc)
{
for (int i = 0; i <= uc->uc_mcontext.nr_TIRs; ++i) {
uint64_t tir_hi = uc->uc_mcontext.tir_hi[i];
if (!E2K_TIR_HAS_EXCP(tir_hi, e2k_exc_data_page_num)) {
continue;
}
if (E2K_TIR_HAS_ALS(tir_hi, 2) || E2K_TIR_HAS_ALS(tir_hi, 5)) {
uint64_t pc = E2K_TIR_IP(uc->uc_mcontext.tir_lo[i]);
if (e2k_check_store ((const uint32_t *) pc)) {
return true;
}
}
}
return false;
}
#endif /* E2K_HOST_SIGNAL_H */

View File

@ -46,7 +46,7 @@ qapi_trace_events = []
bsd_oses = ['gnu/kfreebsd', 'freebsd', 'netbsd', 'openbsd', 'dragonfly', 'darwin']
supported_oses = ['windows', 'freebsd', 'netbsd', 'openbsd', 'darwin', 'sunos', 'linux']
supported_cpus = ['ppc', 'ppc64', 's390x', 'riscv32', 'riscv64', 'x86', 'x86_64',
'arm', 'aarch64', 'loongarch64', 'mips', 'mips64', 'sparc64']
'arm', 'aarch64', 'loongarch64', 'mips', 'mips64', 'sparc64', 'e2k']
cpu = host_machine.cpu_family()
@ -274,6 +274,8 @@ foreach lang : all_languages
compiler = meson.get_compiler(lang)
if compiler.get_id() == 'gcc' and compiler.version().version_compare('>=7.4')
# ok
elif compiler.get_id() == 'lcc' and compiler.version().version_compare('>=1.25')
# ok
elif compiler.get_id() == 'clang' and compiler.compiles('''
#ifdef __apple_build_version__
# if __clang_major__ < 12 || (__clang_major__ == 12 && __clang_minor__ < 0)
@ -391,7 +393,11 @@ ucontext_probe = '''
#ifdef __stub_makecontext
#error Ignoring glibc stub makecontext which will always fail
#endif
int main(void) { makecontext(0, 0, 0); return 0; }'''
#ifdef __e2k__
int main(void) { makecontext_e2k(0, 0, 0); return 0; }
#else
int main(void) { makecontext(0, 0, 0); return 0; }
#endif'''
# On Windows the only valid backend is the Windows specific one.
# For POSIX prefer ucontext, but it's not always possible. The fallback
@ -403,7 +409,9 @@ else
if host_os != 'darwin' and cc.links(ucontext_probe)
supported_backends += ['ucontext']
endif
supported_backends += ['sigaltstack']
if host_arch != 'e2k'
supported_backends += ['sigaltstack']
endif
endif
if coroutine_backend == 'auto'
@ -746,7 +754,7 @@ endif
tcg_arch = host_arch
if get_option('tcg').allowed()
if host_arch == 'unknown'
if host_arch == 'unknown' or host_arch == 'e2k'
if not get_option('tcg_interpreter')
error('Unsupported CPU @0@, try --enable-tcg-interpreter'.format(cpu))
endif
@ -2706,7 +2714,7 @@ if has_int128_type
# __alignof(unsigned __int128) for the host.
atomic_test_128 = '''
int main(int ac, char **av) {
__uint128_t *p = __builtin_assume_aligned(av[ac - 1], 16);
__uint128_t *p = (__uint128_t *) __builtin_assume_aligned(av[ac - 1], 16);
p[1] = __atomic_load_n(&p[0], __ATOMIC_RELAXED);
__atomic_store_n(&p[2], p[3], __ATOMIC_RELAXED);
__atomic_compare_exchange_n(&p[4], &p[5], p[6], 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);

View File

@ -1012,10 +1012,12 @@ static void riscv_cpu_reset_hold(Object *obj)
riscv_trigger_reset_hold(env);
}
#ifdef CONFIG_KVM
if (kvm_enabled()) {
kvm_riscv_reset_vcpu(cpu);
}
#endif
#endif
}
static void riscv_cpu_disas_set_info(CPUState *s, disassemble_info *info)
@ -1132,13 +1134,16 @@ void riscv_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
error_propagate(errp, local_err);
return;
}
} else if (kvm_enabled()) {
}
#ifdef CONFIG_KVM
else if (kvm_enabled()) {
riscv_kvm_cpu_finalize_features(cpu, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
return;
}
}
#endif
}
static void riscv_cpu_realize(DeviceState *dev, Error **errp)
@ -1253,16 +1258,22 @@ static void riscv_cpu_set_irq(void *opaque, int irq, int level)
case IRQ_U_EXT:
case IRQ_VS_EXT:
case IRQ_M_EXT:
#ifdef CONFIG_KVM
if (kvm_enabled()) {
kvm_riscv_set_irq(cpu, irq, level);
} else {
} else
#endif
{
riscv_cpu_update_mip(env, 1 << irq, BOOL_TO_MASK(level));
}
break;
case IRQ_S_EXT:
#ifdef CONFIG_KVM
if (kvm_enabled()) {
kvm_riscv_set_irq(cpu, irq, level);
} else {
} else
#endif
{
env->external_seip = level;
riscv_cpu_update_mip(env, 1 << irq,
BOOL_TO_MASK(level | env->software_seip));

View File

@ -64,7 +64,8 @@ buffer_zero_int(const void *buf, size_t len)
}
}
#if defined(CONFIG_AVX512F_OPT) || defined(CONFIG_AVX2_OPT) || defined(__SSE2__)
#if defined(CONFIG_AVX512F_OPT) || defined(CONFIG_AVX2_OPT) || \
(defined(__SSE2__) && !defined(__e2k__))
#include <immintrin.h>
/* Note that each of these vectorized functions require len >= 64. */

View File

@ -219,8 +219,16 @@ Coroutine *qemu_coroutine_new(void)
arg.p = co;
on_new_fiber(co);
#ifdef __e2k__
/* TODO: freecontext_e2k??? */
if (makecontext_e2k(&uc, (void (*)(void))coroutine_trampoline,
2, arg.i[0], arg.i[1]) < 0) {
abort();
}
#else
makecontext(&uc, (void (*)(void))coroutine_trampoline,
2, arg.i[0], arg.i[1]);
#endif
/* swapcontext() in, siglongjmp() back out */
if (!sigsetjmp(old_env, 0)) {

23
util/cpuinfo-e2k.c Normal file
View File

@ -0,0 +1,23 @@
/*
* SPDX-License-Identifier: GPL-2.0-or-later
* Host specific cpu indentification for E2K.
*/
#include "qemu/osdep.h"
#include "host/cpuinfo.h"
unsigned cpuinfo;
/* Called both as constructor and (possibly) via other constructors. */
unsigned __attribute__((constructor)) cpuinfo_init(void)
{
unsigned info = cpuinfo;
if (info) {
return info;
}
info |= CPUINFO_ALWAYS;
cpuinfo = info;
return info;
}

View File

@ -365,9 +365,9 @@ static void rb_erase_color(RBNode *parent, RBRoot *root,
* Case 1 - left rotate at parent
*
* P S
* / \ / \
* / \ / \
* N s --> p Sr
* / \ / \
* / \ / \
* Sl Sr N Sl
*/
tmp1 = sibling->rb_left;
@ -387,9 +387,9 @@ static void rb_erase_color(RBNode *parent, RBRoot *root,
* (p could be either color here)
*
* (p) (p)
* / \ / \
* / \ / \
* N S --> N s
* / \ / \
* / \ / \
* Sl Sr Sl Sr
*
* This leaves us violating 5) which

View File

@ -127,4 +127,6 @@ elif cpu == 'loongarch64'
util_ss.add(files('cpuinfo-loongarch.c'))
elif cpu in ['ppc', 'ppc64']
util_ss.add(files('cpuinfo-ppc.c'))
elif cpu in 'e2k'
util_ss.add(files('cpuinfo-e2k.c'))
endif