├── src ├── platform │ ├── cva6 │ │ ├── objects.mk │ │ ├── inc │ │ │ └── plat │ │ │ │ ├── platform.h │ │ │ │ └── plic.h │ │ ├── platform.mk │ │ └── cva6_desc.c │ ├── qemu-riscv64-virt │ │ ├── objects.mk │ │ ├── inc │ │ │ └── plat │ │ │ │ ├── platform.h │ │ │ │ └── plic.h │ │ ├── platform.mk │ │ └── virt_desc.c │ ├── drivers │ │ ├── 8250_uart │ │ │ ├── objects.mk │ │ │ ├── 8250_uart.c │ │ │ └── inc │ │ │ │ └── drivers │ │ │ │ └── 8250_uart.h │ │ ├── sbi_uart │ │ │ ├── objects.mk │ │ │ ├── sbi_uart.c │ │ │ └── inc │ │ │ │ └── drivers │ │ │ │ └── sbi_uart.h │ │ ├── zynq_uart │ │ │ └── objects.mk │ │ ├── imx_uart │ │ │ ├── objects.mk │ │ │ ├── inc │ │ │ │ └── drivers │ │ │ │ │ └── imx_uart.h │ │ │ └── imx_uart.c │ │ ├── nxp_uart │ │ │ ├── objects.mk │ │ │ ├── nxp_uart.c │ │ │ └── inc │ │ │ │ └── drivers │ │ │ │ └── nxp_uart.h │ │ └── pl011_uart │ │ │ └── objects.mk │ ├── imx8mq │ │ ├── inc │ │ │ └── plat │ │ │ │ ├── platform.h │ │ │ │ └── psci.h │ │ ├── objects.mk │ │ ├── platform.mk │ │ └── imx8mq_desc.c │ ├── imx8qm │ │ ├── inc │ │ │ └── plat │ │ │ │ ├── platform.h │ │ │ │ └── psci.h │ │ ├── objects.mk │ │ ├── platform.mk │ │ └── imx8qm_desc.c │ ├── ultra96 │ │ ├── inc │ │ │ └── plat │ │ │ │ ├── platform.h │ │ │ │ └── psci.h │ │ ├── objects.mk │ │ ├── platform.mk │ │ └── ultra96_desc.c │ ├── zcu102 │ │ ├── inc │ │ │ └── plat │ │ │ │ ├── platform.h │ │ │ │ └── psci.h │ │ ├── objects.mk │ │ ├── platform.mk │ │ └── zcu102_desc.c │ ├── zcu104 │ │ ├── inc │ │ │ └── plat │ │ │ │ ├── platform.h │ │ │ │ └── psci.h │ │ ├── objects.mk │ │ ├── platform.mk │ │ └── zcu104_desc.c │ ├── hikey960 │ │ ├── inc │ │ │ └── plat │ │ │ │ ├── platform.h │ │ │ │ └── psci.h │ │ ├── objects.mk │ │ ├── platform.mk │ │ └── hikey960_desc.c │ ├── qemu-aarch64-virt │ │ ├── inc │ │ │ └── plat │ │ │ │ ├── platform.h │ │ │ │ └── psci.h │ │ ├── objects.mk │ │ ├── platform.mk │ │ └── virt_desc.c │ ├── rpi4 │ │ ├── inc │ │ │ └── plat │ │ │ │ ├── platform.h │ │ │ │ └── psci.h │ │ ├── objects.mk │ │ ├── platform.mk │ │ └── rpi4_desc.c │ └── tx2 │ │ ├── objects.mk │ │ ├── inc │ │ └── plat │ │ │ ├── platform.h │ │ │ └── psci.h │ │ ├── platform.mk │ │ └── tx2_desc.c ├── sdees │ ├── sdTZ │ │ ├── arch │ │ │ ├── armv8 │ │ │ │ ├── objects.mk │ │ │ │ ├── inc │ │ │ │ │ └── arch │ │ │ │ │ │ └── sdtz.h │ │ │ │ └── sdtz.c │ │ │ └── riscv │ │ │ │ ├── objects.mk │ │ │ │ └── inc │ │ │ │ └── arch │ │ │ │ └── sdtz.h │ │ ├── inc │ │ │ └── sdtz.h │ │ └── objects.mk │ ├── sdGPOS │ │ ├── arch │ │ │ ├── armv8 │ │ │ │ ├── objects.mk │ │ │ │ ├── inc │ │ │ │ │ └── arch │ │ │ │ │ │ └── sdgpos.h │ │ │ │ └── sdgpos.c │ │ │ └── riscv │ │ │ │ ├── objects.mk │ │ │ │ ├── inc │ │ │ │ └── arch │ │ │ │ │ └── sdgpos.h │ │ │ │ └── sdgpos.c │ │ ├── inc │ │ │ └── sdgpos.h │ │ ├── objects.mk │ │ └── sdgpos.c │ └── sdSGX │ │ ├── inc │ │ └── sdsgx.h │ │ └── objects.mk ├── core │ ├── builtin-config.S │ ├── inc │ │ ├── fences.h │ │ ├── spinlock.h │ │ ├── console.h │ │ ├── vmstack.h │ │ ├── ipc.h │ │ ├── hypercall.h │ │ ├── cache.h │ │ ├── tlb.h │ │ ├── types.h │ │ ├── platform.h │ │ ├── objcache.h │ │ ├── iommu.h │ │ ├── vmm.h │ │ ├── crossconhyp.h │ │ ├── interrupts.h │ │ ├── emul.h │ │ └── page_table.h │ ├── objects.mk │ ├── console.c │ ├── cache.c │ ├── config.c │ ├── iommu.c │ ├── init.c │ └── vmstack.c ├── arch │ ├── riscv │ │ ├── arch.mk │ │ ├── inc │ │ │ └── arch │ │ │ │ ├── hypercall.h │ │ │ │ ├── mem.h │ │ │ │ ├── cache.h │ │ │ │ ├── iommu.h │ │ │ │ ├── platform.h │ │ │ │ ├── cpu.h │ │ │ │ ├── instructions.h │ │ │ │ ├── interrupts.h │ │ │ │ ├── encoding.h │ │ │ │ ├── fences.h │ │ │ │ ├── vplic.h │ │ │ │ ├── spinlock.h │ │ │ │ ├── crossconhyp.h │ │ │ │ ├── tlb.h │ │ │ │ └── plic.h │ │ ├── objects.mk │ │ ├── config.c │ │ ├── asm_defs.c │ │ ├── root_pt.S │ │ ├── iommu.c │ │ ├── vmm.c │ │ ├── cpu.c │ │ ├── cache.c │ │ ├── relocate.S │ │ ├── mem.c │ │ └── page_table.c │ └── armv8 │ │ ├── inc │ │ └── arch │ │ │ ├── hypercall.h │ │ │ ├── aborts.h │ │ │ ├── mem.h │ │ │ ├── cache.h │ │ │ ├── iommu.h │ │ │ ├── interrupts.h │ │ │ ├── smc.h │ │ │ ├── vgicv2.h │ │ │ ├── crossconhyp.h │ │ │ ├── cpu.h │ │ │ ├── vgicv3.h │ │ │ ├── fences.h │ │ │ ├── platform.h │ │ │ ├── spinlock.h │ │ │ ├── gicv2.h │ │ │ ├── tlb.h │ │ │ └── vm.h │ │ ├── impl │ │ └── cortex-a53 │ │ │ └── objects.mk │ │ ├── arch.mk │ │ ├── config.c │ │ ├── pagetables.S │ │ ├── smc.c │ │ ├── objects.mk │ │ ├── asm_defs.c │ │ ├── interrupts.c │ │ ├── platform.c │ │ ├── mem.c │ │ ├── cpu.c │ │ └── relocate.S ├── lib │ ├── objects.mk │ ├── inc │ │ ├── printk.h │ │ ├── string.h │ │ ├── bit.h │ │ ├── util.h │ │ └── bitmap.h │ ├── bitmap.c │ └── string.c └── linker.ld ├── imgs ├── crossconhyp-dynamicvm.drawio.png └── crossconhyp-pervmtee.drawio.png ├── .gitignore ├── .clang-format └── configs ├── linker.ld └── configs.mk /src/platform/cva6/objects.mk: -------------------------------------------------------------------------------- 1 | boards-objs-y+=cva6_desc.o -------------------------------------------------------------------------------- /src/platform/qemu-riscv64-virt/objects.mk: -------------------------------------------------------------------------------- 1 | boards-objs-y+=virt_desc.o 2 | -------------------------------------------------------------------------------- /src/platform/drivers/8250_uart/objects.mk: -------------------------------------------------------------------------------- 1 | drivers-objs-y+=8250_uart/8250_uart.o -------------------------------------------------------------------------------- /src/platform/drivers/sbi_uart/objects.mk: -------------------------------------------------------------------------------- 1 | drivers-objs-y+=sbi_uart/sbi_uart.o -------------------------------------------------------------------------------- /src/platform/drivers/zynq_uart/objects.mk: -------------------------------------------------------------------------------- 1 | drivers-objs-y+=zynq_uart/zynq_uart.o -------------------------------------------------------------------------------- /src/platform/drivers/imx_uart/objects.mk: -------------------------------------------------------------------------------- 1 | drivers-objs-y+=imx_uart/imx_uart.o 2 | -------------------------------------------------------------------------------- /src/platform/drivers/nxp_uart/objects.mk: -------------------------------------------------------------------------------- 1 | drivers-objs-y+=nxp_uart/nxp_uart.o 2 | -------------------------------------------------------------------------------- /src/sdees/sdTZ/arch/armv8/objects.mk: -------------------------------------------------------------------------------- 1 | 2 | sdee-objs-y+=sdTZ/arch/armv8/sdtz.o 3 | -------------------------------------------------------------------------------- /src/sdees/sdTZ/arch/riscv/objects.mk: -------------------------------------------------------------------------------- 1 | 2 | sdee-objs-y+=sdTZ/arch/riscv/sdtz.o 3 | -------------------------------------------------------------------------------- /src/platform/drivers/pl011_uart/objects.mk: -------------------------------------------------------------------------------- 1 | drivers-objs-y+=pl011_uart/pl011_uart.o 2 | -------------------------------------------------------------------------------- /src/sdees/sdGPOS/arch/armv8/objects.mk: -------------------------------------------------------------------------------- 1 | 2 | sdee-objs-y+=sdGPOS/arch/armv8/sdgpos.o 3 | -------------------------------------------------------------------------------- /src/sdees/sdGPOS/arch/riscv/objects.mk: -------------------------------------------------------------------------------- 1 | 2 | sdee-objs-y+=sdGPOS/arch/riscv/sdgpos.o 3 | -------------------------------------------------------------------------------- /src/core/builtin-config.S: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | .section .config, "a" 4 | .incbin XSTR(CONFIG_BIN) -------------------------------------------------------------------------------- /imgs/crossconhyp-dynamicvm.drawio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crosscon/CROSSCON-Hypervisor/HEAD/imgs/crossconhyp-dynamicvm.drawio.png -------------------------------------------------------------------------------- /imgs/crossconhyp-pervmtee.drawio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crosscon/CROSSCON-Hypervisor/HEAD/imgs/crossconhyp-pervmtee.drawio.png -------------------------------------------------------------------------------- /src/platform/imx8mq/inc/plat/platform.h: -------------------------------------------------------------------------------- 1 | #ifndef __PLAT_PLATFORM_H__ 2 | #define __PLAT_PLATFORM_H__ 3 | 4 | #include 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/platform/imx8qm/inc/plat/platform.h: -------------------------------------------------------------------------------- 1 | #ifndef __PLAT_PLATFORM_H__ 2 | #define __PLAT_PLATFORM_H__ 3 | 4 | #include 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/platform/ultra96/inc/plat/platform.h: -------------------------------------------------------------------------------- 1 | #ifndef __PLAT_PLATFORM_H__ 2 | #define __PLAT_PLATFORM_H__ 3 | 4 | #include 5 | 6 | #endif -------------------------------------------------------------------------------- /src/platform/zcu102/inc/plat/platform.h: -------------------------------------------------------------------------------- 1 | #ifndef __PLAT_PLATFORM_H__ 2 | #define __PLAT_PLATFORM_H__ 3 | 4 | #include 5 | 6 | #endif -------------------------------------------------------------------------------- /src/platform/zcu104/inc/plat/platform.h: -------------------------------------------------------------------------------- 1 | #ifndef __PLAT_PLATFORM_H__ 2 | #define __PLAT_PLATFORM_H__ 3 | 4 | #include 5 | 6 | #endif -------------------------------------------------------------------------------- /src/platform/hikey960/inc/plat/platform.h: -------------------------------------------------------------------------------- 1 | #ifndef __PLAT_PLATFORM_H__ 2 | #define __PLAT_PLATFORM_H__ 3 | 4 | #include 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /src/platform/qemu-riscv64-virt/inc/plat/platform.h: -------------------------------------------------------------------------------- 1 | #ifndef __PLAT_PLATFORM_H__ 2 | #define __PLAT_PLATFORM_H__ 3 | 4 | #include 5 | 6 | #endif -------------------------------------------------------------------------------- /src/platform/qemu-aarch64-virt/inc/plat/platform.h: -------------------------------------------------------------------------------- 1 | #ifndef __PLAT_PLATFORM_H__ 2 | #define __PLAT_PLATFORM_H__ 3 | 4 | #include 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin/* 2 | build/* 3 | *.o 4 | *.elf 5 | *.bin 6 | *.d 7 | 8 | configs/* 9 | !configs/configs.mk 10 | !configs/linker.ld 11 | !configs/example/ 12 | 13 | -------------------------------------------------------------------------------- /src/arch/riscv/arch.mk: -------------------------------------------------------------------------------- 1 | CROSS_COMPILE := riscv64-unknown-elf- 2 | 3 | arch-cppflags = 4 | arch-cflags = -mcmodel=medany -march=rv64g 5 | arch-asflags = 6 | arch-ldflags = -z common-page-size=0x1000 -------------------------------------------------------------------------------- /src/sdees/sdTZ/inc/sdtz.h: -------------------------------------------------------------------------------- 1 | #ifndef TEE_H_ 2 | #define TEE_H_ 3 | 4 | #include 5 | #include 6 | 7 | 8 | int64_t sdtz_handler_setup(struct vm *vm); 9 | 10 | #endif /* TEE_H_ */ 11 | -------------------------------------------------------------------------------- /src/sdees/sdGPOS/inc/sdgpos.h: -------------------------------------------------------------------------------- 1 | #ifndef SDGPOS_H_ 2 | #define SDGPOS_H_ 3 | 4 | #include 5 | #include 6 | 7 | int64_t sdgpos_handler_setup(struct vm *vm); 8 | 9 | #endif /* TEE_H_ */ 10 | -------------------------------------------------------------------------------- /src/sdees/sdGPOS/arch/armv8/inc/arch/sdgpos.h: -------------------------------------------------------------------------------- 1 | #ifndef SDGPOS_ARMV8_H_ 2 | #define SDGPOS_ARMV8_H_ 3 | 4 | #include 5 | #include 6 | 7 | bool sdgpos_arch_setup(struct vm *vm); 8 | 9 | #endif 10 | 11 | -------------------------------------------------------------------------------- /src/platform/cva6/inc/plat/platform.h: -------------------------------------------------------------------------------- 1 | #ifndef __PLAT_PLATFORM_H__ 2 | #define __PLAT_PLATFORM_H__ 3 | 4 | #define UART8250_REG_WIDTH (4) 5 | #define UART8250_PAGE_OFFSET (0x40) 6 | 7 | #include 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/platform/cva6/platform.mk: -------------------------------------------------------------------------------- 1 | # Architecture definition 2 | ARCH:=riscv 3 | # CPU definition 4 | CPU:= 5 | 6 | drivers := 8250_uart 7 | 8 | platform-cppflags = 9 | platform-cflags = 10 | platform-asflags = 11 | platform-ldflags = 12 | -------------------------------------------------------------------------------- /src/platform/rpi4/inc/plat/platform.h: -------------------------------------------------------------------------------- 1 | #ifndef __PLAT_PLATFORM_H__ 2 | #define __PLAT_PLATFORM_H__ 3 | 4 | #define UART8250_REG_WIDTH (4) 5 | #define UART8250_PAGE_OFFSET (0x40) 6 | 7 | #include 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/platform/qemu-riscv64-virt/platform.mk: -------------------------------------------------------------------------------- 1 | # Architecture definition 2 | ARCH:=riscv 3 | # CPU definition 4 | CPU:= 5 | 6 | drivers := sbi_uart 7 | 8 | platform-cppflags = 9 | platform-cflags = 10 | platform-asflags = 11 | platform-ldflags = -------------------------------------------------------------------------------- /src/sdees/sdGPOS/arch/riscv/inc/arch/sdgpos.h: -------------------------------------------------------------------------------- 1 | #ifndef SDGPOS_RISCV_H_ 2 | #define SDGPOS_RISCV_H_ 3 | 4 | #include 5 | #include 6 | 7 | // NOT HERE 8 | #define SBI_EXTID_TEE (0x544545) 9 | 10 | bool sdgpos_arch_setup(struct vm *vm); 11 | 12 | #endif 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/arch/armv8/inc/arch/hypercall.h: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-License-Identifier: Apache-2.0 3 | * Copyright (c) CROSSCONHyp Project and Contributors. All rights reserved. 4 | */ 5 | 6 | #ifndef ARCH_HYPERCALL_H 7 | #define ARCH_HYPERCALL_H 8 | 9 | #define HYPCALL_ARG_REG(ARG) (ARG) 10 | 11 | #endif /* ARCH_HYPERCALL_H */ 12 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: Google 3 | BreakAfterJavaFieldAnnotations: 'false' 4 | BreakBeforeBraces: Linux 5 | IncludeBlocks: Preserve 6 | IndentWidth: '4' 7 | SortIncludes: 'false' 8 | AllowShortFunctionsOnASingleLine: 'Empty' 9 | AllowShortLoopsOnASingleLine: 'true' 10 | AlwaysBreakBeforeMultilineStrings: 'false' 11 | ... 12 | -------------------------------------------------------------------------------- /src/sdees/sdSGX/inc/sdsgx.h: -------------------------------------------------------------------------------- 1 | #ifndef SDSGX_H 2 | #define SDSGX_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | void sdsgx_donate(struct vm* vm, struct config* cfg, uint64_t); 9 | void sdsgx_reclaim(struct vcpu* host, struct vcpu* nvclv); 10 | int64_t sdsgx_handler_setup(struct vm *vm); 11 | 12 | #endif /* SDSGX_H */ 13 | -------------------------------------------------------------------------------- /src/arch/riscv/inc/arch/hypercall.h: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-License-Identifier: Apache-2.0 3 | * Copyright (c) CROSSCONHyp Project and Contributors. All rights reserved. 4 | */ 5 | 6 | #ifndef ARCH_HYPERCALL_H 7 | #define ARCH_HYPERCALL_H 8 | 9 | #include 10 | 11 | #define HYPCALL_ARG_REG(ARG) ((ARG)+REG_A0) 12 | 13 | #endif /* ARCH_HYPERCALL_H */ 14 | -------------------------------------------------------------------------------- /src/platform/drivers/sbi_uart/sbi_uart.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | bool uart_init(crossconhyp_uart_t* uart) 5 | { 6 | return true; 7 | } 8 | void uart_enable(crossconhyp_uart_t* uart) {} 9 | 10 | void uart_puts(crossconhyp_uart_t* uart, char const* const str) 11 | { 12 | char const* ptr = str; 13 | while (*ptr) sbi_console_putchar(*ptr++); 14 | } 15 | -------------------------------------------------------------------------------- /src/platform/qemu-riscv64-virt/virt_desc.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct platform_desc platform = { 4 | 5 | .cpu_num = 2, 6 | 7 | .region_num = 1, 8 | .regions = (struct mem_region[]) { 9 | { 10 | .base = 0x80200000, 11 | .size = 0x100000000 - 0x200000 /* almost 4GB */ 12 | } 13 | }, 14 | 15 | .arch = { 16 | .plic_base = 0xc000000, 17 | } 18 | 19 | }; 20 | -------------------------------------------------------------------------------- /src/arch/riscv/objects.mk: -------------------------------------------------------------------------------- 1 | cpu-objs-y+=boot.o 2 | cpu-objs-y+=exceptions.o 3 | cpu-objs-y+=root_pt.o 4 | cpu-objs-y+=sbi.o 5 | cpu-objs-y+=page_table.o 6 | cpu-objs-y+=mem.o 7 | cpu-objs-y+=vm.o 8 | cpu-objs-y+=vmm.o 9 | cpu-objs-y+=plic.o 10 | cpu-objs-y+=interrupts.o 11 | cpu-objs-y+=sync_exceptions.o 12 | cpu-objs-y+=vplic.o 13 | cpu-objs-y+=cpu.o 14 | cpu-objs-y+=cache.o 15 | cpu-objs-y+=config.o 16 | cpu-objs-y+=iommu.o 17 | cpu-objs-y+=relocate.o 18 | -------------------------------------------------------------------------------- /src/platform/cva6/cva6_desc.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct platform_desc platform = { 4 | 5 | .cpu_num = 1, 6 | 7 | .region_num = 1, 8 | .regions = (struct mem_region[]) { 9 | { 10 | .base = 0x80200000, 11 | .size = 0x40000000 - 0x200000 12 | } 13 | }, 14 | 15 | .console = { 16 | .base = 0x10000000, 17 | }, 18 | 19 | .arch = { 20 | .plic_base = 0xc000000, 21 | } 22 | 23 | }; 24 | -------------------------------------------------------------------------------- /src/platform/zcu102/objects.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | boards-objs-y+=zcu102_desc.o -------------------------------------------------------------------------------- /src/platform/zcu104/objects.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | boards-objs-y+=zcu104_desc.o -------------------------------------------------------------------------------- /src/platform/hikey960/objects.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | boards-objs-y+=hikey960_desc.o -------------------------------------------------------------------------------- /src/platform/imx8mq/objects.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | boards-objs-y+=imx8mq_desc.o 17 | -------------------------------------------------------------------------------- /src/platform/imx8qm/objects.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | boards-objs-y+=imx8qm_desc.o 17 | -------------------------------------------------------------------------------- /src/platform/rpi4/objects.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | boards-objs-y+=rpi4_desc.o 17 | -------------------------------------------------------------------------------- /src/platform/ultra96/objects.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | boards-objs-y+=ultra96_desc.o -------------------------------------------------------------------------------- /src/sdees/sdTZ/objects.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | sdee-objs-y+=sdTZ/sdtz.o 17 | 18 | -------------------------------------------------------------------------------- /src/arch/armv8/impl/cortex-a53/objects.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | cpu-common-objs-y:= 17 | -------------------------------------------------------------------------------- /src/platform/qemu-aarch64-virt/objects.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | boards-objs-y+=virt_desc.o -------------------------------------------------------------------------------- /src/sdees/sdGPOS/objects.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | sdee-objs-y+=sdGPOS/sdgpos.o 17 | 18 | -------------------------------------------------------------------------------- /src/lib/objects.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | lib-objs-y+=string.o 17 | lib-objs-y+=printk.o 18 | lib-objs-y+=bitmap.o 19 | -------------------------------------------------------------------------------- /src/arch/riscv/inc/arch/mem.h: -------------------------------------------------------------------------------- 1 | /** 2 | CROSSCONHyp Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __ARCH_MEM_H__ 17 | #define __ARCH_MEM_H__ 18 | 19 | #include 20 | 21 | #endif /* __ARCH_MEM_H__ */ -------------------------------------------------------------------------------- /src/platform/tx2/objects.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # Gero Schwaericke 9 | # 10 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 11 | # terms of the GNU General Public License version 2 as published by the Free 12 | # Software Foundation, with a special exception exempting guest code from such 13 | # license. See the COPYING file in the top-level directory for details. 14 | # 15 | ## 16 | 17 | boards-objs-y+=tx2_desc.o -------------------------------------------------------------------------------- /src/platform/cva6/inc/plat/plic.h: -------------------------------------------------------------------------------- 1 | /** 2 | crossconhyphu separation kernel 3 | * 4 | * Copyright (c) Jose Martins, Sandro Pinto 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | crossconhyphu is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __PLAT_PLIC_H__ 17 | #define __PLAT_PLIC_H__ 18 | 19 | #define PLIC_PLAT_CNTXT_NUM (2) 20 | 21 | #endif /* __PLAT_PLIC_H__ */ 22 | -------------------------------------------------------------------------------- /src/sdees/sdSGX/objects.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | sdee-objs-y+=sdSGX/sdsgx.o 17 | 18 | -include $(addsuffix /objects.mk, $(arch)) 19 | 20 | -------------------------------------------------------------------------------- /src/platform/qemu-riscv64-virt/inc/plat/plic.h: -------------------------------------------------------------------------------- 1 | /** 2 | crossconhyphu separation kernel 3 | * 4 | * Copyright (c) Jose Martins, Sandro Pinto 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | crossconhyphu is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __PLAT_PLIC_H__ 17 | #define __PLAT_PLIC_H__ 18 | 19 | #define PLIC_PLAT_CNTXT_NUM (8) 20 | 21 | #endif /* __PLAT_PLIC_H__ */ -------------------------------------------------------------------------------- /src/core/inc/fences.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __FENCES_H__ 17 | #define __FENCES_H__ 18 | 19 | #include 20 | 21 | #endif /* __FENCES_ARCH_H__ */ -------------------------------------------------------------------------------- /src/arch/armv8/inc/arch/aborts.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __ABORTS_H__ 17 | #define __ABORTS_H__ 18 | 19 | #include 20 | 21 | #endif /* __ABORTS_H__ */ -------------------------------------------------------------------------------- /src/core/inc/spinlock.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __SPINLOCK_H__ 17 | #define __SPINLOCK_H__ 18 | 19 | #include 20 | 21 | #endif /* __SPINLOCK_H__ */ -------------------------------------------------------------------------------- /src/arch/armv8/inc/arch/mem.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __ARCH_MEM_H__ 17 | #define __ARCH_MEM_H__ 18 | 19 | #include 20 | #include 21 | 22 | #endif /* __ARCH_MEM_H__ */ -------------------------------------------------------------------------------- /src/arch/armv8/inc/arch/cache.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __ARCH_CACHE_H__ 17 | #define __ARCH_CACHE_H__ 18 | 19 | #include 20 | 21 | #define CACHE_MAX_LVL 8 22 | 23 | #endif /* __ARCH_CACHE_H__ */ -------------------------------------------------------------------------------- /src/arch/riscv/inc/arch/cache.h: -------------------------------------------------------------------------------- 1 | /** 2 | CROSSCONHyp Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __ARCH_CACHE_H__ 17 | #define __ARCH_CACHE_H__ 18 | 19 | #include 20 | 21 | #define CACHE_MAX_LVL 8 // Does this make sense in all architectures? 22 | 23 | #endif /* __ARCH_CACHE_H__ */ -------------------------------------------------------------------------------- /src/arch/riscv/inc/arch/iommu.h: -------------------------------------------------------------------------------- 1 | /** 2 | CROSSCONHyp Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __IOMMU_ARCH_H__ 17 | #define __IOMMU_ARCH_H__ 18 | 19 | /** 20 | * No IOMMU is availble in the riscv architecture 21 | */ 22 | 23 | struct iommu_vm_arch { 24 | 25 | }; 26 | 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/arch/riscv/inc/arch/platform.h: -------------------------------------------------------------------------------- 1 | /** 2 | CROSSCONHyp Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __ARCH_PLATFORM_H__ 17 | #define __ARCH_PLATFORM_H__ 18 | 19 | #include 20 | 21 | struct arch_platform { 22 | paddr_t plic_base; 23 | }; 24 | 25 | #endif /* __ARCH_PLATFORM_H__ */ 26 | -------------------------------------------------------------------------------- /src/lib/inc/printk.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __PRINTK_H 17 | #define __PRINTK_H 18 | 19 | #include 20 | 21 | size_t printk(const char *fmt, ...); 22 | 23 | #endif /* __PRINTK_H */ 24 | -------------------------------------------------------------------------------- /src/arch/armv8/inc/arch/iommu.h: -------------------------------------------------------------------------------- 1 | /** 2 | crossconhyphu separation kernel 3 | * 4 | * Copyright (c) Jose Martins, Sandro Pinto, David Cerdeira 5 | * 6 | * Authors: 7 | * David Cerdeira 8 | * 9 | crossconhyphu is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __IOMMU_ARCH_H__ 17 | #define __IOMMU_ARCH_H__ 18 | 19 | #include 20 | 21 | struct iommu_vm_arch { 22 | streamid_t global_mask; 23 | size_t ctx_id; 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/core/inc/console.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __CONSOLE_H__ 17 | #define __CONSOLE_H__ 18 | 19 | #include 20 | 21 | void console_init(); 22 | void console_write(char const* const str); 23 | 24 | #endif /* __CONSOLE_H__ */ -------------------------------------------------------------------------------- /src/arch/armv8/arch.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | CROSS_COMPILE ?= aarch64-none-elf- 17 | 18 | arch-cppflags = -DGIC_VERSION=$(GIC_VERSION) 19 | arch-cflags = -march=armv8-a -mcmodel=large -mgeneral-regs-only 20 | arch-asflags = 21 | arch-ldflags = 22 | -------------------------------------------------------------------------------- /src/arch/armv8/config.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | 18 | void config_arch_vm_adjust_to_va(struct vm_config *vm_config, struct config* config, paddr_t phys) 19 | { 20 | adjust_ptr(vm_config->platform.arch.smmu.smmu_groups, config); 21 | } 22 | -------------------------------------------------------------------------------- /src/arch/riscv/inc/arch/cpu.h: -------------------------------------------------------------------------------- 1 | /** 2 | CROSSCONHyp Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __ARCH_CPU_H__ 17 | #define __ARCH_CPU_H__ 18 | 19 | #include 20 | 21 | extern cpuid_t CPU_MASTER; 22 | 23 | struct cpu_arch { 24 | unsigned hart_id; 25 | unsigned plic_cntxt; 26 | }; 27 | 28 | #endif /* __ARCH_CPU_H__ */ 29 | -------------------------------------------------------------------------------- /src/platform/tx2/inc/plat/platform.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * Gero Schwaericke 9 | * 10 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 11 | * terms of the GNU General Public License version 2 as published by the Free 12 | * Software Foundation, with a special exception exempting guest code from such 13 | * license. See the COPYING file in the top-level directory for details. 14 | * 15 | */ 16 | 17 | #ifndef __PLAT_PLATFORM_H__ 18 | #define __PLAT_PLATFORM_H__ 19 | 20 | #define UART8250_REG_WIDTH 4 21 | 22 | #include 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/arch/armv8/inc/arch/interrupts.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __ARCH_INTERRUPTS_H__ 17 | #define __ARCH_INTERRUPTS_H__ 18 | 19 | #include 20 | 21 | #define IPI_CPU_MSG 1 22 | #define MAX_INTERRUPTS GIC_MAX_INTERUPTS 23 | 24 | #endif /* __ARCH_INTERRUPTS_H__ */ 25 | -------------------------------------------------------------------------------- /src/arch/riscv/config.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | 18 | void config_arch_adjust_to_va(struct config *config, paddr_t phys) 19 | { 20 | } 21 | 22 | void config_arch_vm_adjust_to_va(struct vm_config *vm_config, struct config* config, paddr_t phys) 23 | { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/platform/ultra96/platform.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | # Architecture definition 17 | ARCH:=armv8 18 | # CPU definition 19 | CPU:=cortex-a53 20 | 21 | GIC_VERSION:=GICV2 22 | 23 | drivers = zynq_uart 24 | 25 | platform-cppflags = 26 | platform-cflags = -mcpu=$(CPU) 27 | platform-asflags = 28 | platform-ldflags = -------------------------------------------------------------------------------- /src/platform/zcu102/platform.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | # Architecture definition 17 | ARCH:=armv8 18 | # CPU definition 19 | CPU:=cortex-a53 20 | 21 | GIC_VERSION:=GICV2 22 | 23 | drivers = zynq_uart 24 | 25 | platform-cppflags = 26 | platform-cflags = -mcpu=$(CPU) 27 | platform-asflags = 28 | platform-ldflags = -------------------------------------------------------------------------------- /src/platform/zcu104/platform.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | # Architecture definition 17 | ARCH:=armv8 18 | # CPU definition 19 | CPU:=cortex-a53 20 | 21 | GIC_VERSION:=GICV2 22 | 23 | drivers = zynq_uart 24 | 25 | platform-cppflags = 26 | platform-cflags = -mcpu=$(CPU) 27 | platform-asflags = 28 | platform-ldflags = -------------------------------------------------------------------------------- /src/platform/imx8mq/platform.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | # Architecture definition 17 | ARCH:=armv8 18 | # CPU definition 19 | CPU:=cortex-a53 20 | 21 | GIC_VERSION:=GICV3 22 | 23 | drivers = imx_uart 24 | 25 | platform-cppflags = 26 | platform-cflags = -mcpu=$(CPU) 27 | platform-asflags = 28 | platform-ldflags = 29 | -------------------------------------------------------------------------------- /src/platform/imx8qm/platform.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | # Architecture definition 17 | ARCH:=armv8 18 | # CPU definition 19 | CPU:=cortex-a53 20 | 21 | GIC_VERSION:=GICV3 22 | 23 | drivers = nxp_uart 24 | 25 | platform-cppflags = 26 | platform-cflags = -mcpu=$(CPU) 27 | platform-asflags = 28 | platform-ldflags = 29 | -------------------------------------------------------------------------------- /src/platform/hikey960/platform.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | # Architecture definition 17 | ARCH:=armv8 18 | # CPU definition 19 | CPU:=cortex-a53 20 | 21 | GIC_VERSION:=GICV2 22 | 23 | drivers = pl011_uart 24 | 25 | platform-cppflags = 26 | platform-cflags = -mcpu=$(CPU) 27 | platform-asflags = 28 | platform-ldflags = 29 | -------------------------------------------------------------------------------- /src/platform/qemu-aarch64-virt/platform.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | # Architecture definition 17 | ARCH:=armv8 18 | # CPU definition 19 | CPU:=cortex-a53 20 | 21 | GIC_VERSION:=GICV2 22 | 23 | drivers = pl011_uart 24 | 25 | platform-cppflags = 26 | platform-cflags = -mcpu=$(CPU) 27 | platform-asflags = 28 | platform-ldflags = 29 | -------------------------------------------------------------------------------- /src/platform/rpi4/inc/plat/psci.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __PLAT_PSCI_H__ 17 | #define __PLAT_PSCI_H__ 18 | 19 | #define PSCI_POWER_STATE_LVL_0 0x0000002 20 | #define PSCI_STATE_TYPE_STANDBY 0x0000000 21 | #define PSCI_STATE_TYPE_BIT (1UL << 16) 22 | #define PSCI_STATE_TYPE_POWERDOWN PSCI_STATE_TYPE_BIT 23 | 24 | #endif // __PLAT_PSCI_H__ 25 | -------------------------------------------------------------------------------- /src/arch/riscv/inc/arch/instructions.h: -------------------------------------------------------------------------------- 1 | /** 2 | CROSSCONHyp Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef ARCH_INSTRUCTIONS_H 17 | #define ARCH_INSTRUCTIONS_H 18 | 19 | static inline uint64_t hlvxhu(uintptr_t addr){ 20 | uint64_t value; 21 | asm volatile( 22 | ".insn r 0x73, 0x4, 0x32, %0, %1, x3\n\t" 23 | : "=r"(value): "r"(addr) : "memory"); 24 | return value; 25 | } 26 | 27 | #endif /* ARCH_INSTRUCTIONS_H */ -------------------------------------------------------------------------------- /src/arch/riscv/asm_defs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | void cpu_defines() __attribute__((used)); 8 | void cpu_defines() 9 | { 10 | DEFINE_SIZE(CPU_SIZE, struct cpu); 11 | 12 | DEFINE_OFFSET(CPU_ROOT_PT_OFF, struct cpu, root_pt); 13 | 14 | DEFINE_OFFSET(CPU_STACK_OFF, struct cpu, stack); 15 | DEFINE_SIZE(CPU_STACK_SIZE, ((struct cpu*)NULL)->stack); 16 | 17 | DEFINE_OFFSET(CPU_IF_OFF, struct cpu, interface); 18 | DEFINE_SIZE(CPU_IF_SIZE, ((struct cpu*)NULL)->interface); 19 | 20 | DEFINE_OFFSET(CPU_VCPU_OFF, struct cpu, vcpu); 21 | } 22 | 23 | void vcpu_defines() __attribute__((used)); 24 | void vcpu_defines() 25 | { 26 | DEFINE_SIZE(VCPU_ARCH_SIZE, struct vcpu_arch); 27 | DEFINE_OFFSET(VCPU_REGS_OFF, struct vcpu, regs); 28 | DEFINE_SIZE(VCPU_REGS_SIZE, struct arch_regs); 29 | } 30 | -------------------------------------------------------------------------------- /src/platform/rpi4/platform.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | # Architecture definition 17 | ARCH:=armv8 18 | # CPU definition 19 | CPU:=cortex-a72 20 | 21 | GIC_VERSION:=GICV2 22 | RPI4_MEM_GB:=4 23 | 24 | drivers = 8250_uart 25 | 26 | platform-cppflags = 27 | platform-cflags = -mcpu=$(CPU) -DRPI4_MEM_GB=$(RPI4_MEM_GB) 28 | platform-asflags = 29 | platform-ldflags = 30 | -------------------------------------------------------------------------------- /src/arch/riscv/root_pt.S: -------------------------------------------------------------------------------- 1 | /** 2 | CROSSCONHyp Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | 18 | .section .glb_page_tables, "aw" 19 | 20 | .globl root_l1_pt 21 | .balign PAGE_SIZE, 0 22 | root_l1_pt: 23 | .skip PAGE_SIZE 24 | 25 | .globl root_l2_pt 26 | .balign PAGE_SIZE, 0 27 | root_l2_pt: 28 | .skip PAGE_SIZE 29 | 30 | .globl root_l1_flat_pt 31 | .balign PAGE_SIZE, 0 32 | root_l1_flat_pt: 33 | .skip PAGE_SIZE 34 | 35 | -------------------------------------------------------------------------------- /src/core/objects.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | core-objs-y+=init.o 17 | core-objs-y+=mem.o 18 | core-objs-y+=objcache.o 19 | core-objs-y+=cache.o 20 | core-objs-y+=interrupts.o 21 | core-objs-y+=cpu.o 22 | core-objs-y+=vmm.o 23 | core-objs-y+=vm.o 24 | core-objs-y+=config.o 25 | core-objs-y+=console.o 26 | core-objs-y+=iommu.o 27 | core-objs-y+=ipc.o 28 | core-objs-y+=vmstack.o 29 | -------------------------------------------------------------------------------- /src/core/inc/vmstack.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef VMSTACK_H 17 | #define VMSTACK_H 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | void vmstack_push(struct vcpu* vcpu); 25 | struct vcpu* vmstack_pop(); 26 | void vmstack_unwind(struct vcpu* vcpu); 27 | int64_t vmstack_hypercall(uint64_t id, uint64_t arg0, uint64_t arg1, uint64_t arg2); 28 | 29 | #endif /* VMSTACK_H */ 30 | -------------------------------------------------------------------------------- /src/arch/riscv/iommu.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | 18 | /** 19 | * TODO: No IOMMU available in riscv 20 | */ 21 | 22 | bool iommu_arch_init() 23 | { 24 | return true; 25 | } 26 | 27 | inline bool iommu_arch_vm_add_device(struct vm *vm, streamid_t id) 28 | { 29 | return true; 30 | } 31 | 32 | bool iommu_arch_vm_init(struct vm *vm, const struct vm_config *config) 33 | { 34 | return true; 35 | } 36 | -------------------------------------------------------------------------------- /src/platform/hikey960/inc/plat/psci.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * David Cerdeira 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __PLAT_PSCI_H__ 17 | #define __PLAT_PSCI_H__ 18 | 19 | #define PSCI_POWER_STATE_LVL_0 0x0000000 20 | #define PSCI_POWER_STATE_LVL_1 0x1000000 21 | #define PSCI_POWER_STATE_LVL_2 0x2000000 22 | #define PSCI_STATE_TYPE_STANDBY 0x00000 23 | #define PSCI_STATE_TYPE_POWERDOWN (1UL << 16) 24 | #define PSCI_STATE_TYPE_BIT (1UL << 16) 25 | 26 | #endif // __PLAT_PSCI_H__ -------------------------------------------------------------------------------- /src/platform/tx2/platform.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # Gero Schwaericke 9 | # 10 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 11 | # terms of the GNU General Public License version 2 as published by the Free 12 | # Software Foundation, with a special exception exempting guest code from such 13 | # license. See the COPYING file in the top-level directory for details. 14 | # 15 | ## 16 | 17 | # Architecture definition 18 | ARCH:=armv8 19 | # CPU definition 20 | CPU:=cortex-a57 21 | 22 | GIC_VERSION:=GICV2 23 | 24 | # TODO: Driver missing, should be 8250 compatible 25 | drivers = 8250_uart 26 | 27 | platform-cppflags = 28 | platform-cflags = -mcpu=$(CPU) 29 | platform-asflags = 30 | platform-ldflags = -------------------------------------------------------------------------------- /src/platform/zcu102/inc/plat/psci.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __PLAT_PSCI_H__ 17 | #define __PLAT_PSCI_H__ 18 | 19 | #define PSCI_POWER_STATE_LVL_0 0x0000000 20 | #define PSCI_POWER_STATE_LVL_1 0x1000000 21 | #define PSCI_POWER_STATE_LVL_2 0x2000000 22 | #define PSCI_STATE_TYPE_STANDBY 0x00000 23 | #define PSCI_STATE_TYPE_POWERDOWN (1UL << 30) 24 | #define PSCI_STATE_TYPE_BIT (1UL << 30) 25 | 26 | #endif // __PLAT_PSCI_H__ -------------------------------------------------------------------------------- /src/platform/zcu104/inc/plat/psci.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __PLAT_PSCI_H__ 17 | #define __PLAT_PSCI_H__ 18 | 19 | #define PSCI_POWER_STATE_LVL_0 0x0000000 20 | #define PSCI_POWER_STATE_LVL_1 0x1000000 21 | #define PSCI_POWER_STATE_LVL_2 0x2000000 22 | #define PSCI_STATE_TYPE_STANDBY 0x00000 23 | #define PSCI_STATE_TYPE_POWERDOWN (1UL << 30) 24 | #define PSCI_STATE_TYPE_BIT (1UL << 30) 25 | 26 | #endif // __PLAT_PSCI_H__ -------------------------------------------------------------------------------- /src/platform/qemu-aarch64-virt/inc/plat/psci.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __PLAT_PSCI_H__ 17 | #define __PLAT_PSCI_H__ 18 | 19 | #define PSCI_POWER_STATE_LVL_0 0x0000000 20 | #define PSCI_POWER_STATE_LVL_1 0x1000000 21 | #define PSCI_POWER_STATE_LVL_2 0x2000000 22 | #define PSCI_STATE_TYPE_STANDBY 0x00000 23 | #define PSCI_STATE_TYPE_BIT (1UL << 16) 24 | #define PSCI_STATE_TYPE_POWERDOWN (0x1) 25 | 26 | #endif // __PLAT_PSCI_H__ -------------------------------------------------------------------------------- /src/platform/ultra96/inc/plat/psci.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __PLAT_PSCI_H__ 17 | #define __PLAT_PSCI_H__ 18 | 19 | #define PSCI_POWER_STATE_LVL_0 0x0000000 20 | #define PSCI_POWER_STATE_LVL_1 0x1000000 21 | #define PSCI_POWER_STATE_LVL_2 0x2000000 22 | #define PSCI_STATE_TYPE_STANDBY 0x00000 23 | #define PSCI_STATE_TYPE_POWERDOWN (1UL << 30) 24 | #define PSCI_STATE_TYPE_BIT (1UL << 30) 25 | 26 | #endif // __PLAT_PSCI_H__ -------------------------------------------------------------------------------- /src/arch/armv8/inc/arch/smc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __SMC_H__ 17 | #define __SMC_H__ 18 | 19 | #include 20 | 21 | struct smc_res { 22 | unsigned long x0; 23 | unsigned long x1; 24 | unsigned long x2; 25 | unsigned long x3; 26 | }; 27 | 28 | unsigned long smc_call(unsigned long x0, unsigned long x1, unsigned long x2, 29 | unsigned long x3, struct smc_res *res); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/platform/drivers/sbi_uart/inc/drivers/sbi_uart.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __SBI_UART_H__ 17 | #define __SBI_UART_H__ 18 | 19 | #include 20 | 21 | typedef volatile uint8_t crossconhyp_uart_t; 22 | 23 | bool uart_init(crossconhyp_uart_t* uart); 24 | void uart_enable(crossconhyp_uart_t* uart); 25 | void uart_puts(crossconhyp_uart_t* uart,const char *s); 26 | 27 | #endif /* __SBI_UART_H__ */ 28 | -------------------------------------------------------------------------------- /src/platform/imx8mq/inc/plat/psci.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __PLAT_PSCI_H__ 17 | #define __PLAT_PSCI_H__ 18 | 19 | #define PSCI_POWER_STATE_LVL_0 0x0000000 20 | #define PSCI_POWER_STATE_LVL_1 0x1000000 21 | #define PSCI_POWER_STATE_LVL_2 0x2000000 22 | #define PSCI_STATE_TYPE_STANDBY 0x00000 23 | #define PSCI_STATE_TYPE_BIT (1UL << 16) 24 | #define PSCI_STATE_TYPE_POWERDOWN PSCI_STATE_TYPE_BIT 25 | 26 | #endif // __PLAT_PSCI_H__ 27 | -------------------------------------------------------------------------------- /src/platform/imx8qm/inc/plat/psci.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __PLAT_PSCI_H__ 17 | #define __PLAT_PSCI_H__ 18 | 19 | #define PSCI_POWER_STATE_LVL_0 0x0000000 20 | #define PSCI_POWER_STATE_LVL_1 0x1000000 21 | #define PSCI_POWER_STATE_LVL_2 0x2000000 22 | #define PSCI_STATE_TYPE_STANDBY 0x00000 23 | #define PSCI_STATE_TYPE_BIT (1UL << 16) 24 | #define PSCI_STATE_TYPE_POWERDOWN PSCI_STATE_TYPE_BIT 25 | 26 | #endif // __PLAT_PSCI_H__ 27 | -------------------------------------------------------------------------------- /src/arch/armv8/inc/arch/vgicv2.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __VGICV2_H__ 17 | #define __VGICV2_H__ 18 | 19 | #include 20 | #include 21 | 22 | static inline bool vgic_int_vcpu_is_target(struct vcpu *vcpu, struct vgic_int *interrupt) 23 | { 24 | bool priv = gic_is_priv(interrupt->id); 25 | bool target = interrupt->targets & (1 << vcpu->phys_id); 26 | return priv || target; 27 | } 28 | 29 | #endif /* __VGICV2_H__ */ 30 | -------------------------------------------------------------------------------- /src/platform/tx2/inc/plat/psci.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __PLAT_PSCI_H__ 17 | #define __PLAT_PSCI_H__ 18 | 19 | #define PSCI_POWER_STATE_LVL_0 0x0000000 20 | #define PSCI_POWER_STATE_LVL_1 0x1000000 21 | #define PSCI_POWER_STATE_LVL_2 0x2000000 22 | #define PSCI_STATE_TYPE_STANDBY 0x00006 23 | #define PSCI_STATE_TYPE_BIT (1UL << 30) 24 | #define PSCI_STATE_TYPE_POWERDOWN (0x7 | PSCI_STATE_TYPE_BIT) 25 | 26 | #endif // __PLAT_PSCI_H__ 27 | -------------------------------------------------------------------------------- /src/lib/inc/string.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __STRING_H_ 17 | #define __STRING_H_ 18 | 19 | #include 20 | 21 | void *memcpy(void *dst, const void *src, size_t count); 22 | void *memset(void *dest, int c, size_t count); 23 | 24 | char *strcat(char *dest, char *src); 25 | size_t strlen(const char *s); 26 | size_t strnlen(const char *s, size_t n); 27 | char *strcpy(char *dest, char *src); 28 | 29 | #endif /* __STRING_H_ */ 30 | -------------------------------------------------------------------------------- /configs/linker.ld: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | ASSERT(DEFINED(config), "Error: No config structure in configuration file"); 17 | 18 | SECTIONS 19 | { 20 | . = 0x0; 21 | 22 | .config : { 23 | KEEP(*(.config)) 24 | KEEP(*(COMMON)) 25 | } 26 | _config_end = ALIGN(CONSTANT(COMMONPAGESIZE)); 27 | 28 | .vm_images : SUBALIGN(CONSTANT(COMMONPAGESIZE)) { 29 | KEEP(*(.vm_image*)) 30 | } 31 | _images_end = ALIGN(CONSTANT(COMMONPAGESIZE)); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/arch/armv8/inc/arch/crossconhyp.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __ARCH_CROSSCONHYP_H__ 17 | #define __ARCH_CROSSCONHYP_H__ 18 | 19 | #define CROSSCONHYP_VAS_BASE (0xba0000000000) 20 | #define CROSSCONHYP_CPU_BASE (0xbb0000000000) 21 | #define CROSSCONHYP_VM_BASE (0xbc0000000000) 22 | #define CROSSCONHYP_VAS_TOP (0xbf0000000000) 23 | #define PAGE_SIZE (0x1000) 24 | 25 | #ifndef __ASSEMBLER__ 26 | 27 | 28 | #endif /* !__ASSEMBLER__ */ 29 | 30 | 31 | #endif /* __ARCH_CROSSCONHYP_H__ */ 32 | -------------------------------------------------------------------------------- /src/arch/armv8/pagetables.S: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | 18 | .section .glb_page_tables, "aw" 19 | 20 | .globl root_l1_pt 21 | .balign PAGE_SIZE, 0 22 | root_l1_pt: 23 | .skip PAGE_SIZE 24 | 25 | .globl root_l2_pt 26 | .balign PAGE_SIZE, 0 27 | root_l2_pt: 28 | .skip PAGE_SIZE 29 | 30 | .globl root_l3_pt 31 | .balign PAGE_SIZE, 0 32 | root_l3_pt: 33 | .skip PAGE_SIZE 34 | 35 | .globl root_l1_flat_pt 36 | .balign PAGE_SIZE, 0 37 | root_l1_flat_pt: 38 | .skip PAGE_SIZE 39 | 40 | -------------------------------------------------------------------------------- /src/platform/drivers/imx_uart/inc/drivers/imx_uart.h: -------------------------------------------------------------------------------- 1 | #ifndef IMX_UART_H 2 | #define IMX_UART_H 3 | 4 | #include 5 | 6 | struct imx_uart { 7 | uint32_t rxd; /* 0x0 */ 8 | uint32_t reserved1[0xf]; /* (0x40 - 0x4) / 4 */ 9 | uint32_t txd; /* 0x40*/ 10 | uint32_t reserved2[0xf]; /* (0x80 - 0x44) / 4 */ 11 | uint32_t cr1; /* 0x80 */ 12 | uint32_t cr2; /* 0x84 */ 13 | uint32_t cr3; /* 0x88 */ 14 | uint32_t cr4; /* 0x8c */ 15 | uint32_t fcr; /* 0x90 */ 16 | uint32_t stat1; /* 0x94 */ 17 | uint32_t stat2; /* 0x98 */ 18 | uint32_t esc; /* 0x9c */ 19 | uint32_t tim; /* 0xa0 */ 20 | uint32_t bir; /* 0xa4 */ 21 | uint32_t bmr; /* 0xa8 */ 22 | uint32_t brc; /* 0xac */ 23 | uint32_t onems; /* 0xb0 */ 24 | uint32_t ts; /* 0xb4 */ 25 | }; 26 | 27 | typedef struct imx_uart crossconhyp_uart_t; 28 | 29 | void uart_enable(volatile struct imx_uart *uart); 30 | void uart_init(volatile struct imx_uart *uart); 31 | void uart_puts(volatile struct imx_uart * uart, const char* str); 32 | 33 | #endif /* IMX_UART_H */ 34 | -------------------------------------------------------------------------------- /src/platform/drivers/imx_uart/imx_uart.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * David Cerdeira 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | 18 | void uart_init(volatile struct imx_uart *uart){ 19 | return; 20 | } 21 | 22 | void uart_enable(volatile struct imx_uart *uart){ 23 | return; 24 | } 25 | 26 | void uart_putc(volatile struct imx_uart *uart, char c){ 27 | while((uart->ts & 0b1000000) == 0); 28 | uart->txd = c; 29 | } 30 | 31 | void uart_puts(volatile struct imx_uart *uart, char const* str){ 32 | while (*str) { 33 | uart_putc(uart, *str++); 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /src/arch/armv8/inc/arch/cpu.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __ARCH_CPU_H__ 17 | #define __ARCH_CPU_H__ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #define CPU_MAX (8UL) 24 | 25 | struct cpu_arch { 26 | struct psci_off_state psci_off_state; 27 | unsigned long mpidr; 28 | struct { 29 | struct vcpu * next_vcpu; 30 | struct list event_list; 31 | } vtimer; 32 | }; 33 | 34 | unsigned long cpu_id_to_mpidr(cpuid_t id); 35 | cpuid_t cpu_mpidr_to_id(unsigned long mpdir); 36 | 37 | extern cpuid_t CPU_MASTER; 38 | 39 | #endif /* __ARCH_CPU_H__ */ 40 | -------------------------------------------------------------------------------- /src/core/inc/ipc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * David Cerdeira 9 | * 10 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 11 | * terms of the GNU General Public License version 2 as published by the Free 12 | * Software Foundation, with a special exception exempting guest code from such 13 | * license. See the COPYING file in the top-level directory for details. 14 | * 15 | */ 16 | 17 | #ifndef IPC_H 18 | #define IPC_H 19 | 20 | #include 21 | #include 22 | 23 | struct ipc { 24 | paddr_t base; 25 | size_t size; 26 | size_t shmem_id; 27 | size_t interrupt_num; 28 | irqid_t *interrupts; 29 | }; 30 | 31 | struct vm_config; 32 | struct vcpu; 33 | 34 | unsigned long ipc_hypercall(struct vcpu *vcpu, unsigned long arg0, unsigned long arg1, unsigned long arg2); 35 | void ipc_init(const struct vm_config* vm_config, bool vm_master); 36 | struct shmem* ipc_get_shmem(size_t shmem_id); 37 | 38 | #endif /* IPC_H */ 39 | -------------------------------------------------------------------------------- /src/core/inc/hypercall.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef HYPERCALL_H 17 | #define HYPERCALL_H 18 | 19 | #include 20 | 21 | enum { 22 | HC_INVAL = 0, 23 | HC_IPC = 1, 24 | /* TODO: Remove */ 25 | HC_VMSTACK = 2, 26 | HC_ENCLAVE = 3, 27 | HC_TEE = 4, 28 | }; 29 | 30 | enum { 31 | HC_E_SUCCESS = 0, 32 | HC_E_FAILURE = 1, 33 | HC_E_INVAL_ID = 2, 34 | HC_E_INVAL_ARGS = 3 35 | }; 36 | 37 | typedef unsigned long (*hypercall_handler)( unsigned long arg0, 38 | unsigned long arg1, 39 | unsigned long arg2); 40 | 41 | #endif /* HYPERCALL_H */ 42 | -------------------------------------------------------------------------------- /src/arch/riscv/inc/arch/interrupts.h: -------------------------------------------------------------------------------- 1 | /** 2 | CROSSCONHyp Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __ARCH_INTERRUPTS_H__ 17 | #define __ARCH_INTERRUPTS_H__ 18 | 19 | #include 20 | #include 21 | 22 | /** 23 | * In riscv, the ipi (software interrupt) and timer interrupts dont actually 24 | * have an ID as their are treated differently from external interrupts 25 | * routed by the external interrupt controller, the PLIC. 26 | * Will define their ids as the ids after the maximum possible in the PLIC. 27 | */ 28 | #define SOFT_INT_ID (PLIC_MAX_INTERRUPTS + 1) 29 | #define TIMR_INT_ID (PLIC_MAX_INTERRUPTS + 2) 30 | #define MAX_INTERRUPTS (TIMR_INT_ID + 1) 31 | 32 | #define IPI_CPU_MSG SOFT_INT_ID 33 | 34 | #endif /* __ARCH_INTERRUPTS_H__ */ 35 | -------------------------------------------------------------------------------- /src/platform/rpi4/rpi4_desc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * Angelo Ruocco 9 | * 10 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 11 | * terms of the GNU General Public License version 2 as published by the Free 12 | * Software Foundation, with a special exception exempting guest code from such 13 | * license. See the COPYING file in the top-level directory for details. 14 | * 15 | */ 16 | 17 | #include 18 | 19 | struct platform_desc platform = { 20 | .cpu_num = 4, 21 | .region_num = 1, 22 | .regions = (struct mem_region[]) { 23 | { 24 | .base = 0x80000, 25 | .size = 0x100000000 26 | }, 27 | }, 28 | 29 | .console = { 30 | .base = 0xfe215000 31 | }, 32 | 33 | .arch = { 34 | .gic = { 35 | .gicd_addr = 0xff841000, 36 | .gicc_addr = 0xff842000, 37 | .gich_addr = 0xff844000, 38 | .gicv_addr = 0xff846000, 39 | .maintenance_id = 25 40 | }, 41 | } 42 | }; 43 | -------------------------------------------------------------------------------- /src/arch/riscv/inc/arch/encoding.h: -------------------------------------------------------------------------------- 1 | /** 2 | CROSSCONHyp Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __RISCV_ENCODING_H__ 17 | #define __RISCV_ENCODING_H__ 18 | 19 | #include 20 | 21 | #define INS_COMPRESSED(ins) (!((ins & 3) == 3)) 22 | #define INS_SIZE(ins) ((ins & 3) == 3 ? 4 : 2) 23 | 24 | #define INS_OPCODE(ins) ((ins)&0x7f) 25 | #define INS_FUNCT3(ins) ((ins >> 12) & 0x7) 26 | #define INS_RD(ins) (((ins) >> 7) & 0x1f) 27 | #define INS_RS1(ins) (((ins) >> 15) & 0x1f) 28 | #define INS_RS2(ins) (((ins) >> 20) & 0x1f) 29 | #define MATCH_LOAD (0x03) 30 | #define MATCH_STORE (0x23) 31 | 32 | #define INS_C_OPCODE(ins) ((ins)&0xe003) 33 | #define INS_C_RD_RS2(ins) ((ins >> 2) & 0x7) 34 | #define MATCH_C_LOAD (0x4000) 35 | #define MATCH_C_STORE (0xc000) 36 | 37 | #endif /* __RISCV_ENCODING_H__ */ -------------------------------------------------------------------------------- /src/core/inc/cache.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __CACHE_H__ 17 | #define __CACHE_H__ 18 | 19 | #include 20 | #include 21 | 22 | struct cache { 23 | size_t lvls; 24 | size_t min_shared_lvl; 25 | enum { UNIFIED, SEPARATE, DATA, INSTRUCTION } type[CACHE_MAX_LVL]; 26 | enum { PIPT, VIPT } indexed[CACHE_MAX_LVL][2]; 27 | size_t line_size[CACHE_MAX_LVL][2]; 28 | size_t assoc[CACHE_MAX_LVL][2]; 29 | size_t numset[CACHE_MAX_LVL][2]; 30 | }; 31 | 32 | extern size_t COLOR_NUM; 33 | extern size_t COLOR_SIZE; 34 | 35 | void cache_enumerate(); 36 | void cache_flush_range(vaddr_t base, size_t size); 37 | 38 | void cache_arch_enumerate(struct cache* dscrp); 39 | 40 | #endif /* __CACHE_H__ */ 41 | -------------------------------------------------------------------------------- /src/core/inc/tlb.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __TLB_H__ 17 | #define __TLB_H__ 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | static inline void tlb_inv_va(struct addr_space *as, vaddr_t va) 25 | { 26 | if (as->type == AS_HYP) { 27 | tlb_hyp_inv_va(va); 28 | } else if (as->type == AS_VM) { 29 | tlb_vm_inv_va(as->id, va); 30 | // TODO: inval iommu tlbs 31 | } 32 | } 33 | 34 | static inline void tlb_inv_all(struct addr_space *as) 35 | { 36 | if (as->type == AS_HYP) { 37 | tlb_hyp_inv_all(); 38 | } else if (as->type == AS_VM) { 39 | tlb_vm_inv_all(as->id); 40 | // TODO: inval iommu tlbs 41 | } 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /src/core/inc/types.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2021- 5 | * 6 | * Authors: 7 | * Aras Ashraf Gandomi 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __TYPES_H__ 17 | #define __TYPES_H__ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | typedef signed long ssize_t; 24 | 25 | typedef unsigned long asid_t; 26 | 27 | typedef unsigned long vmid_t; 28 | 29 | typedef uintptr_t paddr_t; 30 | typedef uintptr_t vaddr_t; 31 | #define NULL_VA ((vaddr_t)NULL) 32 | #define MAX_VA ((vaddr_t)-1) 33 | 34 | typedef unsigned long colormap_t; 35 | 36 | typedef unsigned long cpuid_t; 37 | typedef unsigned long vcpuid_t; 38 | typedef unsigned long cpumap_t; 39 | #define INVALID_CPUID ((cpuid_t)-1) 40 | 41 | typedef unsigned irqid_t; 42 | 43 | typedef unsigned streamid_t; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/arch/armv8/smc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * David Cerdeira 8 | * Jose Martins 9 | * 10 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 11 | * terms of the GNU General Public License version 2 as published by the Free 12 | * Software Foundation, with a special exception exempting guest code from such 13 | * license. See the COPYING file in the top-level directory for details. 14 | * 15 | */ 16 | 17 | #include 18 | 19 | unsigned long smc_call(unsigned long x0, unsigned long x1, unsigned long x2, 20 | unsigned long x3, struct smc_res *res) 21 | { 22 | register unsigned long r0 asm("x0") = x0; 23 | register unsigned long r1 asm("x1") = x1; 24 | register unsigned long r2 asm("x2") = x2; 25 | register unsigned long r3 asm("x3") = x3; 26 | 27 | asm volatile("smc #0\n" : "=r"(r0) : "r"(r0), "r"(r1), "r"(r2), "r"(r3)); 28 | 29 | if (res != NULL) { 30 | res->x0 = r0; 31 | res->x1 = r1; 32 | res->x2 = r2; 33 | res->x3 = r3; 34 | } 35 | 36 | return r0; 37 | } 38 | -------------------------------------------------------------------------------- /src/core/inc/platform.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __PLATFORM_H__ 17 | #define __PLATFORM_H__ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | struct platform_desc { 27 | size_t cpu_num; 28 | 29 | size_t region_num; 30 | struct mem_region *regions; 31 | 32 | size_t ipc_num; 33 | struct ipc *ipcs; 34 | 35 | size_t dev_num; 36 | struct dev_region *devs; 37 | 38 | struct { 39 | paddr_t base; 40 | } console; 41 | 42 | struct cache cache; 43 | 44 | struct arch_platform arch; 45 | }; 46 | 47 | extern struct platform_desc platform; 48 | 49 | #endif /* __PLATFORM_H__ */ 50 | -------------------------------------------------------------------------------- /src/platform/drivers/nxp_uart/nxp_uart.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | 18 | void uart_init(volatile struct lpuart *uart){ 19 | uart->global |= LPUART_GLOBAL_RST_BIT; 20 | uart->global &= ~LPUART_GLOBAL_RST_BIT; 21 | 22 | uart->baud = LPUART_BAUD_80MHZ_115200; 23 | } 24 | 25 | void uart_enable(volatile struct lpuart *uart){ 26 | uart->ctrl = LPUART_CTRL_TE_BIT; 27 | } 28 | 29 | void uart_putc(volatile struct lpuart *uart, char c){ 30 | while(!(uart->stat & LPUART_STAT_TDRE_BIT)); 31 | uart->data = c; 32 | } 33 | 34 | void uart_puts(volatile struct lpuart *uart, char const* str){ 35 | while (*str) { 36 | uart_putc(uart, *str++); 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /src/sdees/sdGPOS/sdgpos.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "types.h" 5 | #include "vm.h" 6 | #include "vmm.h" 7 | #include 8 | 9 | 10 | /* extern uint64_t interrupt_owner[MAX_INTERRUPTS]; */ 11 | /* static inline uint64_t interrupts_get_vmid(uint64_t int_id) */ 12 | /* { */ 13 | /* return interrupt_owner[int_id]; */ 14 | /* } */ 15 | 16 | void sdgpos_interrupt_handle(struct vcpu* vcpu, irqid_t int_id); 17 | 18 | void sdgpos_interrupt_handle(struct vcpu* vcpu, irqid_t int_id) 19 | { 20 | interrupts_vm_inject(vcpu, int_id); 21 | } 22 | 23 | 24 | struct hndl_irq irq = { 25 | /* TODO: obtain this from config file */ 26 | /* TODO: obtain this to decide whether to invoke handler early on */ 27 | .num = 10, 28 | .irqs = {27,33,72,73,74,75,76,77,78,79}, 29 | .handler = sdgpos_interrupt_handle, 30 | }; 31 | 32 | int64_t sdgpos_handler_setup(struct vm *vm) 33 | { 34 | int64_t ret = 0; 35 | 36 | if(vm == NULL) 37 | return -1; 38 | 39 | sdgpos_arch_setup(vm); 40 | 41 | /* TODO: check config structure or something to check if this VMs wants tz 42 | * to handle its events */ 43 | if(vm->type == 0){ 44 | vm_hndl_irq_add(vm, &irq); 45 | } 46 | 47 | return ret; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /src/arch/riscv/inc/arch/fences.h: -------------------------------------------------------------------------------- 1 | /** 2 | CROSSCONHyp Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | #ifndef __FENCES_ARCH_H__ 16 | #define __FENCES_ARCH_H__ 17 | 18 | static inline void fence_ord_write() 19 | { 20 | asm volatile("fence w, rw\n\t" ::: "memory"); 21 | } 22 | 23 | static inline void fence_ord_read() 24 | { 25 | asm volatile("fence r, rw\n\t" ::: "memory"); 26 | } 27 | 28 | static inline void fence_ord() 29 | { 30 | asm volatile("fence rw, rw\n\t" ::: "memory"); 31 | } 32 | 33 | static inline void fence_sync_write() 34 | { 35 | asm volatile("fence ow, iorw\n\t" ::: "memory"); 36 | } 37 | 38 | static inline void fence_sync_read() 39 | { 40 | asm volatile("fence ir, iorw\n\t" ::: "memory"); 41 | } 42 | 43 | static inline void fence_sync() 44 | { 45 | asm volatile("fence iorw, iorw\n\t" ::: "memory"); 46 | } 47 | 48 | #endif /* __FENCES_ARCH_H__ */ -------------------------------------------------------------------------------- /src/arch/armv8/inc/arch/vgicv3.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __VGICV3_H__ 17 | #define __VGICV3_H__ 18 | 19 | #include 20 | #include 21 | 22 | static inline bool vgic_broadcast(struct vcpu *vcpu, struct vgic_int *interrupt) 23 | { 24 | return (interrupt->route & GICD_IROUTER_IRM_BIT); 25 | } 26 | 27 | static inline bool vgic_int_vcpu_is_target(struct vcpu *vcpu, struct vgic_int *interrupt) 28 | { 29 | bool priv = gic_is_priv(interrupt->id); 30 | bool local = priv && (interrupt->phys.redist == vcpu->phys_id); 31 | bool routed_here = 32 | !priv && !(interrupt->phys.route ^ (MRS(MPIDR_EL1) & MPIDR_AFF_MSK)); 33 | bool any = !priv && vgic_broadcast(vcpu, interrupt); 34 | return local || routed_here || any; 35 | } 36 | 37 | 38 | #endif /* __VGICV3_H__ */ 39 | -------------------------------------------------------------------------------- /src/core/inc/objcache.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __OBJCACHE_H__ 17 | #define __OBJCACHE_H__ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #define SLAB_SIZE PAGE_SIZE 25 | #define SLAB_MIN_HEADER_SIZE (32) 26 | #define SLAB_MAX_OBJECT_SIZE (PAGE_SIZE / 4) 27 | 28 | struct objcache; 29 | union slab; 30 | 31 | struct objcache { 32 | size_t osize; 33 | struct list slabs; 34 | union slab* last_free; 35 | spinlock_t lock; 36 | enum AS_SEC section; 37 | }; 38 | 39 | void objcache_init(struct objcache* oc, size_t osize, enum AS_SEC sec, bool prime); 40 | void objcache_destroy(struct objcache* oc); 41 | void* objcache_alloc(); 42 | bool objcache_free(struct objcache* oc, void* obj); 43 | 44 | #endif /* __OBJCACHE_H__ */ 45 | -------------------------------------------------------------------------------- /src/arch/riscv/inc/arch/vplic.h: -------------------------------------------------------------------------------- 1 | /** 2 | CROSSCONHyp Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __VPLIC_H__ 17 | #define __VPLIC_H__ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | struct vplic { 25 | spinlock_t lock; 26 | size_t cntxt_num; 27 | BITMAP_ALLOC(hw, PLIC_MAX_INTERRUPTS); 28 | BITMAP_ALLOC(pend, PLIC_MAX_INTERRUPTS); 29 | BITMAP_ALLOC(act, PLIC_MAX_INTERRUPTS); 30 | uint32_t prio[PLIC_MAX_INTERRUPTS]; 31 | BITMAP_ALLOC_ARRAY(enbl, PLIC_MAX_INTERRUPTS, PLIC_PLAT_CNTXT_NUM); 32 | uint32_t threshold[PLIC_PLAT_CNTXT_NUM]; 33 | }; 34 | 35 | struct vm; 36 | struct vcpu; 37 | void vplic_init(struct vm *vm, vaddr_t vplic_base); 38 | void vplic_inject(struct vcpu *vcpu, irqid_t id); 39 | void vplic_set_hw(struct vm *vm, irqid_t id); 40 | 41 | #endif /* __VPLIC_H__ */ 42 | -------------------------------------------------------------------------------- /src/arch/riscv/vmm.c: -------------------------------------------------------------------------------- 1 | /** 2 | CROSSCONHyp Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | void vmm_arch_init() 20 | { 21 | /** 22 | * At this point, we should make sure misa's H bit is set (at least by 23 | * reading it). However, current SBI does not allow us to even read it. 24 | * So we assume it is set - if not, the first acess to an hypervisor 25 | * register will set an illegal inst fault. 26 | */ 27 | 28 | /** 29 | * Delegate all interrupts and exceptions not meant to be dealt by 30 | * the hypervisor 31 | */ 32 | 33 | CSRW(CSR_HIDELEG, HIDELEG_VSSI | HIDELEG_VSTI | HIDELEG_VSEI); 34 | CSRW(CSR_HEDELEG, HEDELEG_ECU | HEDELEG_IPF | HEDELEG_LPF | HEDELEG_SPF); 35 | 36 | /** 37 | * TODO: consider delegating other exceptions e.g. breakpoint or ins 38 | * misaligned 39 | */ 40 | } -------------------------------------------------------------------------------- /src/core/inc/iommu.h: -------------------------------------------------------------------------------- 1 | /** 2 | crossconhyphu separation kernel 3 | * 4 | * Copyright (c) Jose Martins, Sandro Pinto, David Cerdeira 5 | * 6 | * Authors: 7 | * David Cerdeira 8 | * 9 | crossconhyphu is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __IOMMU_H__ 17 | #define __IOMMU_H__ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | struct vm_config; 25 | struct vm; 26 | 27 | struct iommu_vm { 28 | struct list dev_list; 29 | struct objcache dev_oc; 30 | struct iommu_vm_arch arch; 31 | }; 32 | 33 | /* Mainly for HW initialization. */ 34 | void iommu_init(); 35 | 36 | /* iommu api for vms. */ 37 | bool iommu_vm_init(struct vm *vm, const struct vm_config *config); 38 | bool iommu_vm_add_device(struct vm *vm, streamid_t dev_id); 39 | 40 | /* Must be implemented by architecture. */ 41 | bool iommu_arch_init(); 42 | bool iommu_arch_vm_init(struct vm *vm, const struct vm_config *config); 43 | bool iommu_arch_vm_add_device(struct vm *vm, streamid_t id); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/platform/qemu-aarch64-virt/virt_desc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | 18 | struct platform_desc platform = { 19 | 20 | .cpu_num = 4, 21 | .region_num = 1, 22 | .regions = (struct mem_region[]) { 23 | { 24 | .base = 0x40000000, 25 | .size = 0x100000000 26 | } 27 | }, 28 | 29 | .console = { 30 | .base = 0x9000000 31 | }, 32 | 33 | .arch = { 34 | .gic = { 35 | .gicd_addr = 0x08000000, 36 | .gicc_addr = 0x08010000, 37 | .gich_addr = 0x08030000, 38 | .gicv_addr = 0x08040000, 39 | .gicr_addr = 0x080A0000, 40 | .maintenance_id = 25 41 | }, 42 | 43 | .generic_timer = { 44 | .irqs = { 45 | .virtual = 27 46 | } 47 | }, 48 | } 49 | 50 | }; 51 | -------------------------------------------------------------------------------- /src/platform/ultra96/ultra96_desc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | 18 | struct platform_desc platform = { 19 | .cpu_num = 4, 20 | .region_num = 2, 21 | .regions = (struct mem_region[]) { 22 | { 23 | .base = 0x00000000, 24 | .size = 0x100000 25 | }, 26 | { 27 | .base = 0x00100000, 28 | .size = 0x7FE00000 29 | }, 30 | }, 31 | 32 | .console = { 33 | .base = 0xFF010000 34 | }, 35 | 36 | .arch = { 37 | .gic = { 38 | .gicd_addr = 0xF9010000, 39 | .gicc_addr = 0xF902f000, 40 | .gich_addr = 0xF9040000, 41 | .gicv_addr = 0xF906f000, 42 | .maintenance_id = 25 43 | }, 44 | 45 | .generic_timer = { 46 | .base_addr = 0xFF260000 47 | } 48 | } 49 | 50 | }; -------------------------------------------------------------------------------- /src/arch/armv8/inc/arch/fences.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __FENCES_ARCH_H__ 17 | #define __FENCES_ARCH_H__ 18 | 19 | #include 20 | 21 | #define DMB(shdmn) asm volatile("dmb " XSTR(shdmn) "\n\t" ::: "memory") 22 | 23 | #define DSB(shdmn) asm volatile("dsb " XSTR(shdmn) "\n\t" ::: "memory") 24 | 25 | #define ISB() asm volatile("isb\n\t" ::: "memory") 26 | 27 | static inline void fence_ord_write() 28 | { 29 | DMB(ishst); 30 | } 31 | 32 | static inline void fence_ord_read() 33 | { 34 | DMB(ishld); 35 | } 36 | 37 | static inline void fence_ord() 38 | { 39 | DMB(ish); 40 | } 41 | 42 | static inline void fence_sync_write() 43 | { 44 | DSB(ishst); 45 | } 46 | 47 | static inline void fence_sync_read() 48 | { 49 | DSB(ishld); 50 | } 51 | 52 | static inline void fence_sync() 53 | { 54 | DSB(ish); 55 | } 56 | 57 | #endif /* __FENCES_ARCH_H__ */ 58 | -------------------------------------------------------------------------------- /src/arch/armv8/objects.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | cpu-objs-y+=boot.o 17 | cpu-objs-y+=exceptions.o 18 | cpu-objs-y+=pagetables.o 19 | cpu-objs-y+=page_table.o 20 | cpu-objs-y+=cache.o 21 | cpu-objs-y+=interrupts.o 22 | cpu-objs-y+=mem.o 23 | cpu-objs-y+=vmm.o 24 | cpu-objs-y+=vm.o 25 | cpu-objs-y+=aborts.o 26 | cpu-objs-y+=smc.o 27 | cpu-objs-y+=psci.o 28 | cpu-objs-y+=cpu.o 29 | cpu-objs-y+=platform.o 30 | cpu-objs-y+=relocate.o 31 | cpu-objs-y+=iommu.o 32 | cpu-objs-y+=smmuv2.o 33 | cpu-objs-y+=gic.o 34 | cpu-objs-y+=vgic.o 35 | cpu-objs-y+=config.o 36 | 37 | ifeq ($(GIC_VERSION), GICV2) 38 | cpu-objs-y+=vgicv2.o 39 | cpu-objs-y+=gicv2.o 40 | else ifeq ($(GIC_VERSION), GICV3) 41 | cpu-objs-y+=vgicv3.o 42 | cpu-objs-y+=gicv3.o 43 | else ifeq ($(GIC_VERSION),) 44 | $(error Platform must define GIC_VERSION) 45 | else 46 | $(error Invalid GIC version $(GIC_VERSION)) 47 | endif 48 | -------------------------------------------------------------------------------- /src/core/inc/vmm.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * Sandro Pinto 9 | * 10 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 11 | * terms of the GNU General Public License version 2 as published by the Free 12 | * Software Foundation, with a special exception exempting guest code from such 13 | * license. See the COPYING file in the top-level directory for details. 14 | * 15 | */ 16 | 17 | #ifndef __VMM_H__ 18 | #define __VMM_H__ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | struct vcpu_node{ 28 | node_t node; 29 | void* data; 30 | }; 31 | 32 | struct partition { 33 | spinlock_t lock; 34 | struct cpu_synctoken sync; 35 | uint64_t master; 36 | struct { 37 | struct vm* curr_vm; 38 | size_t ncpus; 39 | } init; 40 | struct objcache nodes; 41 | struct vm* interrupts[MAX_INTERRUPTS]; 42 | } extern* const partition; 43 | 44 | void vmm_init(); 45 | struct vm* vmm_init_dynamic(struct config*, uint64_t); 46 | void vmm_destroy_dynamic(struct vm *vm); 47 | void vmm_arch_init(); 48 | uint64_t vmm_alloc_vmid(); 49 | 50 | #endif /* __VMM_H__ */ 51 | -------------------------------------------------------------------------------- /src/arch/riscv/inc/arch/spinlock.h: -------------------------------------------------------------------------------- 1 | /** 2 | CROSSCONHyp Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __ARCH_SPINLOCK__ 17 | #define __ARCH_SPINLOCK__ 18 | 19 | #include 20 | 21 | typedef volatile uint32_t __attribute__((aligned(4))) spinlock_t; 22 | 23 | #define SPINLOCK_INITVAL (0) 24 | 25 | static inline void spin_lock(spinlock_t* lock) 26 | { 27 | spinlock_t const ONE = 1; 28 | spinlock_t tmp = SPINLOCK_INITVAL; 29 | 30 | asm volatile("1:\n\t" 31 | "lr.w.aq %0, %1 \n\t" 32 | "bne %0, zero, 1b \n\t" 33 | "sc.w.rl %0, %2, %1 \n\t" 34 | "bne %0, zero, 1b \n\t" 35 | : "=&r"(tmp), "+A"(*lock) 36 | : "r"(ONE)); 37 | } 38 | 39 | static inline void spin_unlock(spinlock_t* lock) 40 | { 41 | asm volatile("sw zero, %0\n\t" 42 | "fence rw, rw\n\t" // Is the full blown barrier really needed? 43 | ::"m"(*lock)); 44 | } 45 | 46 | #endif /* __ARCH_SPINLOCK__ */ 47 | -------------------------------------------------------------------------------- /src/arch/riscv/cpu.c: -------------------------------------------------------------------------------- 1 | /** 2 | CROSSCONHyp Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | cpuid_t CPU_MASTER __attribute__((section(".data"))); 22 | 23 | /* Perform architecture dependent cpu cores initializations */ 24 | void cpu_arch_init(cpuid_t cpuid, paddr_t load_addr) 25 | { 26 | if (cpuid == CPU_MASTER) { 27 | sbi_init(); 28 | for(size_t hartid = 0; hartid < platform.cpu_num; hartid++){ 29 | if(hartid == cpuid) continue; 30 | struct sbiret ret = sbi_hart_start(hartid, load_addr, 0); 31 | if(ret.error < 0) { 32 | WARNING("failed to wake up hart %d", hartid); 33 | } 34 | } 35 | } 36 | } 37 | 38 | void cpu_arch_idle() 39 | { 40 | asm volatile("wfi\n\t" ::: "memory"); 41 | asm volatile("mv sp, %0\n\r" 42 | "j cpu_idle_wakeup\n\r" ::"r"(&cpu.stack[STACK_SIZE])); 43 | ERROR("returned from idle wake up"); 44 | } 45 | -------------------------------------------------------------------------------- /src/sdees/sdTZ/arch/armv8/inc/arch/sdtz.h: -------------------------------------------------------------------------------- 1 | #ifndef SDTZ_ARMV8_H 2 | #define SDTZ_ARMV8_H 3 | 4 | #include 5 | 6 | #define PREFIX_MASK 0xff000000 7 | #define ID_TO_FUNCID(x) ((x) & ~(PREFIX_MASK)) 8 | #define PREFIX 0 9 | #define TEEHC_FUNCID_RETURN_ENTRY_DONE (PREFIX | 0) 10 | #define TEEHC_FUNCID_RETURN_ON_DONE (PREFIX | 1) 11 | #define TEEHC_FUNCID_RETURN_OFF_DONE (PREFIX | 2) 12 | #define TEEHC_FUNCID_RETURN_SUSPEND_DONE (PREFIX | 3) 13 | #define TEEHC_FUNCID_RETURN_RESUME_DONE (PREFIX | 4) 14 | #define TEEHC_FUNCID_RETURN_CALL_DONE (PREFIX | 5) 15 | #define TEEHC_FUNCID_RETURN_FIQ_DONE (PREFIX | 6) 16 | #define TEEHC_FUNCID_RETURN_SYSTEM_OFF_DONE (PREFIX | 7) 17 | #define TEEHC_FUNCID_RETURN_SYSTEM_RESET_DONE (PREFIX | 8) 18 | 19 | #define OPTEE_MSG_CMD_OPEN_SESSION U(0) 20 | #define OPTEE_MSG_CMD_INVOKE_COMMAND U(1) 21 | #define OPTEE_MSG_CMD_CLOSE_SESSION U(2) 22 | #define OPTEE_MSG_CMD_CANCEL U(3) 23 | #define OPTEE_MSG_CMD_REGISTER_SHM U(4) 24 | #define OPTEE_MSG_CMD_UNREGISTER_SHM U(5) 25 | #define OPTEE_MSG_CMD_DO_BOTTOM_HALF U(6) 26 | #define OPTEE_MSG_CMD_STOP_ASYNC_NOTIF U(7) 27 | #define OPTEE_MSG_FUNCID_CALL_WITH_ARG U(0x0004) 28 | 29 | #define TEEHC_FUNCID_CLIENT_FLAG (0x80000000) 30 | #define TEE_NUM_ARGS (6) 31 | 32 | int64_t sdtz_arch_handler_setup(struct vm *vm); 33 | 34 | void tee_arch_interrupt_disable(); 35 | void tee_arch_interrupt_enable(); 36 | void tee_step(struct vcpu* vcpu); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/core/inc/crossconhyp.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * Sandro Pinto 9 | * 10 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 11 | * terms of the GNU General Public License version 2 as published by the Free 12 | * Software Foundation, with a special exception exempting guest code from such 13 | * license. See the COPYING file in the top-level directory for details. 14 | * 15 | */ 16 | 17 | #ifndef __CROSSCONHYP_H__ 18 | #define __CROSSCONHYP_H__ 19 | 20 | #include 21 | 22 | #ifndef __ASSEMBLER__ 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #define INFO(args, ...) \ 29 | printk("CROSSCONHYP INFO: " args "\n" __VA_OPT__(, ) __VA_ARGS__); 30 | 31 | #define WARNING(args, ...) \ 32 | printk("CROSSCONHYP WARNING: " args "\n" __VA_OPT__(, ) __VA_ARGS__); 33 | 34 | #define ERROR(args, ...) \ 35 | { \ 36 | printk("CROSSCONHYP ERROR: " args "\n" __VA_OPT__(, ) __VA_ARGS__); \ 37 | while (1) \ 38 | ; \ 39 | } 40 | 41 | #endif /* __ASSEMBLER__ */ 42 | 43 | #endif /* __CROSSCONHYP_H__ */ 44 | -------------------------------------------------------------------------------- /src/platform/drivers/nxp_uart/inc/drivers/nxp_uart.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef UART_NXP_H 17 | #define UART_NXP_H 18 | 19 | #include 20 | #include 21 | 22 | struct lpuart { 23 | uint32_t verid; 24 | uint32_t param; 25 | uint32_t global; 26 | uint32_t pincfg; 27 | uint32_t baud; 28 | uint32_t stat; 29 | uint32_t ctrl; 30 | uint32_t data; 31 | uint32_t match; 32 | uint32_t modir; 33 | uint32_t fifo; 34 | uint32_t water; 35 | }; 36 | 37 | #define LPUART_GLOBAL_RST_BIT (1U << 1) 38 | #define LPUART_BAUD_80MHZ_115200 ((4 << 24) | (1 << 17) | 138) 39 | #define LPUART_CTRL_TE_BIT (1U << 19) 40 | #define LPUART_STAT_TDRE_BIT (1U << 23) 41 | 42 | typedef struct lpuart crossconhyp_uart_t; 43 | 44 | void uart_enable(volatile struct lpuart *uart); 45 | void uart_init(volatile struct lpuart *uart); 46 | void uart_puts(volatile struct lpuart * uart, const char* str); 47 | 48 | #endif /* __UART_NXP_H */ 49 | -------------------------------------------------------------------------------- /src/platform/imx8mq/imx8mq_desc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * Angelo Ruocco 9 | * 10 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 11 | * terms of the GNU General Public License version 2 as published by the Free 12 | * Software Foundation, with a special exception exempting guest code from such 13 | * license. See the COPYING file in the top-level directory for details. 14 | * 15 | */ 16 | 17 | #include 18 | 19 | struct platform_desc platform = { 20 | .cpu_num = 1, 21 | .region_num = 1, 22 | .regions = (struct mem_region[]) { 23 | { 24 | .base = 0x40000000, 25 | .size = 0xffffffff - 0x40000000, // 3 GiB 26 | }, 27 | { 28 | .base = 0x100000000, 29 | .size = 0x13FFFFFFF-0x100000000, // 1 GiB 30 | } 31 | }, 32 | 33 | .console = { 34 | .base = 0x30860000, 35 | }, 36 | 37 | .arch = { 38 | 39 | .clusters = { 40 | .num = 1, 41 | .core_num = (size_t[]) {4} 42 | }, 43 | 44 | .gic = { 45 | .gicd_addr = 0x38800000, 46 | .gicr_addr = 0x38880000, 47 | .gicc_addr = 0x31000000, 48 | .gicv_addr = 0x31010000, 49 | .gich_addr = 0x31020000, 50 | .maintenance_id = 25 51 | }, 52 | } 53 | }; 54 | -------------------------------------------------------------------------------- /src/platform/tx2/tx2_desc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * Gero Schwaericke 9 | * 10 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 11 | * terms of the GNU General Public License version 2 as published by the Free 12 | * Software Foundation, with a special exception exempting guest code from such 13 | * license. See the COPYING file in the top-level directory for details. 14 | * 15 | */ 16 | 17 | #include 18 | 19 | struct platform_desc platform = { 20 | .cpu_num = 6, 21 | .region_num = 1, 22 | .regions = (struct mem_region[]) { 23 | { 24 | .base = 0x80000000, 25 | .size = 0x200000000 26 | }, 27 | }, 28 | 29 | .console = { 30 | .base = 0x03100000 31 | }, 32 | 33 | .arch = { 34 | .gic = { 35 | .gicd_addr = 0x03881000, 36 | .gicc_addr = 0x03882000, 37 | .gich_addr = 0x03884000, 38 | .gicv_addr = 0x03886000, 39 | .maintenance_id = 25 40 | }, 41 | 42 | .clusters = { 43 | .num = 2, 44 | .core_num = (size_t[]){ 2, 4 }, 45 | }, 46 | 47 | .smmu = { 48 | .base = 0x12000000, 49 | .interrupt_id = 187, 50 | .global_mask = 0x7f80, 51 | } 52 | } 53 | 54 | }; 55 | -------------------------------------------------------------------------------- /src/sdees/sdTZ/arch/riscv/inc/arch/sdtz.h: -------------------------------------------------------------------------------- 1 | #ifndef SDTZ_ARMV8_H 2 | #define SDTZ_ARMV8_H 3 | 4 | #include 5 | 6 | #define SBI_EXTID_TEE (0x544545) 7 | 8 | #define PREFIX_MASK 0xff000000 9 | #define ID_TO_FUNCID(x) (x & ~(PREFIX_MASK)) 10 | #define PREFIX 0 11 | #define TEEHC_FUNCID_RETURN_ENTRY_DONE (PREFIX | 0) 12 | #define TEEHC_FUNCID_RETURN_ON_DONE (PREFIX | 1) 13 | #define TEEHC_FUNCID_RETURN_OFF_DONE (PREFIX | 2) 14 | #define TEEHC_FUNCID_RETURN_SUSPEND_DONE (PREFIX | 3) 15 | #define TEEHC_FUNCID_RETURN_RESUME_DONE (PREFIX | 4) 16 | #define TEEHC_FUNCID_RETURN_CALL_DONE (PREFIX | 5) 17 | #define TEEHC_FUNCID_RETURN_FIQ_DONE (PREFIX | 6) 18 | #define TEEHC_FUNCID_RETURN_SYSTEM_OFF_DONE (PREFIX | 7) 19 | #define TEEHC_FUNCID_RETURN_SYSTEM_RESET_DONE (PREFIX | 8) 20 | 21 | #define OPTEE_MSG_CMD_OPEN_SESSION U(0) 22 | #define OPTEE_MSG_CMD_INVOKE_COMMAND U(1) 23 | #define OPTEE_MSG_CMD_CLOSE_SESSION U(2) 24 | #define OPTEE_MSG_CMD_CANCEL U(3) 25 | #define OPTEE_MSG_CMD_REGISTER_SHM U(4) 26 | #define OPTEE_MSG_CMD_UNREGISTER_SHM U(5) 27 | #define OPTEE_MSG_CMD_DO_BOTTOM_HALF U(6) 28 | #define OPTEE_MSG_CMD_STOP_ASYNC_NOTIF U(7) 29 | #define OPTEE_MSG_FUNCID_CALL_WITH_ARG U(0x0004) 30 | 31 | #define TEEHC_FUNCID_CLIENT_FLAG (0x80000000) 32 | #define TEE_NUM_ARGS (6) 33 | 34 | int64_t sdtz_arch_handler_setup(struct vm *vm); 35 | 36 | void tee_arch_interrupt_disable(); 37 | void tee_arch_interrupt_enable(); 38 | void tee_step(struct vcpu* vcpu); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /src/core/console.c: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 4 | * 5 | * Copyright (c) bao Project (www.bao-project.org), 2019- 6 | * 7 | * Authors: 8 | * Jose Martins 9 | * 10 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 11 | * terms of the GNU General Public License version 2 as published by the Free 12 | * Software Foundation, with a special exception exempting guest code from such 13 | * license. See the COPYING file in the top-level directory for details. 14 | * 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | volatile crossconhyp_uart_t uart 27 | __attribute__((section(".devices"), aligned(PAGE_SIZE))); 28 | bool ready = false; 29 | static spinlock_t print_lock = SPINLOCK_INITVAL; 30 | 31 | void console_init() 32 | { 33 | if((platform.console.base & PAGE_OFFSET_MASK) != 0) { 34 | WARNING("console base must be page aligned"); 35 | } 36 | 37 | mem_map_dev(&cpu.as, (vaddr_t)&uart, platform.console.base, 38 | NUM_PAGES(sizeof(uart))); 39 | 40 | fence_sync_write(); 41 | 42 | uart_init(&uart); 43 | uart_enable(&uart); 44 | 45 | ready = true; 46 | } 47 | 48 | void console_write(char const* const str) 49 | { 50 | if (!ready) return; 51 | spin_lock(&print_lock); 52 | uart_puts(&uart, str); 53 | spin_unlock(&print_lock); 54 | } 55 | -------------------------------------------------------------------------------- /src/arch/riscv/inc/arch/crossconhyp.h: -------------------------------------------------------------------------------- 1 | /** 2 | CROSSCONHyp Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __ARCH_CROSSCONHYP_H__ 17 | #define __ARCH_CROSSCONHYP_H__ 18 | 19 | #define RV64 (__riscv_xlen == 64) 20 | #define RV32 (__riscv_xlen == 32) 21 | 22 | #if (!(RV64)) 23 | #error "Unsupported __riscv_xlen #__riscv_xlen." 24 | #endif 25 | 26 | #if (RV64) 27 | #define LOAD ld 28 | #define STORE sd 29 | #define REGLEN (8) 30 | #elif (RV32) 31 | #define LOAD lw 32 | #define STORE sw 33 | #define REGLEN (4) 34 | #endif 35 | 36 | #if (RV64) 37 | #define CROSSCONHYP_VAS_BASE (0xffffffc000000000) 38 | #define CROSSCONHYP_CPU_BASE (0xffffffc040000000) 39 | #define CROSSCONHYP_VM_BASE (0xffffffe000000000) 40 | #define CROSSCONHYP_VAS_TOP (0xfffffff000000000) 41 | #elif (RV32) 42 | #define CROSSCONHYP_VAS_BASE (0xc0000000) 43 | #define CROSSCONHYP_CPU_BASE (0x00000000) 44 | #define CROSSCONHYP_VM_BASE (0x00000000) 45 | #define CROSSCONHYP_VAS_TOP (0xffffffff) 46 | #endif 47 | 48 | #define PAGE_SIZE (0x1000) 49 | 50 | #ifndef __ASSEMBLER__ 51 | 52 | #endif /* !__ASSEMBLER__ */ 53 | 54 | #endif /* __ARCH_CROSSCONHYP_H__ */ -------------------------------------------------------------------------------- /src/arch/riscv/inc/arch/tlb.h: -------------------------------------------------------------------------------- 1 | /** 2 | CROSSCONHyp Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __ARCH_TLB_H__ 17 | #define __ARCH_TLB_H__ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | /** 24 | * TODO: we are assuming platform.cpu_num is power of two. Make this not true. 25 | */ 26 | 27 | static inline void tlb_hyp_inv_va(vaddr_t va) 28 | { 29 | sbi_remote_sfence_vma((1 << platform.cpu_num) - 1, 0, (unsigned long)va, 30 | PAGE_SIZE); 31 | } 32 | 33 | static inline void tlb_hyp_inv_all() 34 | { 35 | sbi_remote_sfence_vma((1 << platform.cpu_num) - 1, 0, 0, 0); 36 | } 37 | 38 | /** 39 | * TODO: change hart_mask to only take into account the vm physical cpus. 40 | */ 41 | 42 | static inline void tlb_vm_inv_va(asid_t vmid, vaddr_t va) 43 | { 44 | sbi_remote_hfence_gvma_vmid((1 << platform.cpu_num)- 1, 0, (unsigned long)va, 45 | PAGE_SIZE, vmid); 46 | } 47 | 48 | static inline void tlb_vm_inv_all(asid_t vmid) 49 | { 50 | sbi_remote_hfence_gvma_vmid((1 << platform.cpu_num) - 1, 0, 0, 0, vmid); 51 | } 52 | 53 | #endif /* __ARCH_TLB_H__ */ 54 | -------------------------------------------------------------------------------- /src/arch/riscv/cache.c: -------------------------------------------------------------------------------- 1 | /** 2 | CROSSCONHyp Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | /** 20 | * The riscv spec does not include cache maintenance. There are current 21 | * efforts to define and standardize a set of cache management instructions, 22 | * but for now this is platform dependent. 23 | */ 24 | 25 | void cache_arch_enumerate(struct cache* dscrp) 26 | { 27 | /** 28 | * Currently the typical of way for system software to discover cache 29 | * topology is to read it of a dtb passed by the bootloader. As we are not 30 | * implementing an fdt parser, a platform port must add it to the platform 31 | * description. 32 | */ 33 | *dscrp = platform.cache; 34 | } 35 | 36 | __attribute__((weak)) void cache_flush_range(vaddr_t base, size_t size) 37 | { 38 | /** 39 | * A platform must define its custom cache flush operation, otherwise 40 | * certain mechanisms such as coloring and hypervisor relocation will 41 | * most probably fail. 42 | */ 43 | WARNING("trying to flush caches but the operation is not defined for this " 44 | "platform"); 45 | } 46 | -------------------------------------------------------------------------------- /src/platform/hikey960/hikey960_desc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * David Cerdeira 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | 18 | struct platform_desc platform = { 19 | .cpu_num = 4, /* ONLY SUPORT A53 FOR NOW, cpu_num max is 4 */ 20 | .region_num = 2, 21 | 22 | /* plat memory is: 0-3.5GB; 4-4.5GB */ 23 | .regions = (struct mem_region[]) { 24 | { 25 | /* 0-3.5GB*/ 26 | .base = 0x00000000, 27 | .size = 0xE0000000, 28 | }, 29 | { 30 | /* 8-8.5G from UEFI*/ 31 | .base = 0x200000000, 32 | .size = 0x20000000, 33 | }, 34 | }, 35 | 36 | .arch = { 37 | .gic = { 38 | /* check gic 400 manual */ 39 | .gicd_addr = 0xE82B1000, 40 | .gicc_addr = 0xE82B2000, 41 | .gich_addr = 0xE82B4000, 42 | .gicv_addr = 0xE82B6000, 43 | .maintenance_id = 25 44 | }, 45 | 46 | .generic_timer = { 47 | .base_addr = 0xFFF08000 /* SYS_CNT */ 48 | }, 49 | 50 | .smmu = { 51 | .base = 0xE8DC0000 52 | } 53 | }, 54 | 55 | .console = { 56 | .base = 0xFFF32000 /* UART 6 */ 57 | }, 58 | }; 59 | -------------------------------------------------------------------------------- /src/platform/imx8qm/imx8qm_desc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * Angelo Ruocco 9 | * 10 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 11 | * terms of the GNU General Public License version 2 as published by the Free 12 | * Software Foundation, with a special exception exempting guest code from such 13 | * license. See the COPYING file in the top-level directory for details. 14 | * 15 | */ 16 | 17 | #include 18 | 19 | struct platform_desc platform = { 20 | .cpu_num = 6, 21 | .region_num = 2, 22 | .regions = (struct mem_region[]) { 23 | { 24 | .base = 0x80020000, 25 | .size = 0x80000000 - 0x20000 // 2 GiB - 128 KiB (reserved for ATF) 26 | }, 27 | { 28 | .base = 0x800000000, 29 | .size = 0x100000000 // 4 GiB 30 | } 31 | }, 32 | 33 | .console = { 34 | .base = 0x5a060000 35 | }, 36 | 37 | .arch = { 38 | 39 | .clusters = { 40 | .num = 2, 41 | .core_num = (uint8_t[]) {4, 2} 42 | }, 43 | 44 | .gic = { 45 | .gicd_addr = 0x51a00000, 46 | .gicr_addr = 0x51b00000, 47 | .gicc_addr = 0x52000000, 48 | .gich_addr = 0x52010000, 49 | .gicv_addr = 0x52020000, 50 | .maintenance_id = 25 51 | }, 52 | 53 | .smmu = { 54 | .base = 0x51400000, 55 | .interrupt_id = 187, 56 | .global_mask = 0x7fc0, 57 | }, 58 | 59 | } 60 | }; 61 | -------------------------------------------------------------------------------- /src/platform/drivers/8250_uart/8250_uart.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | 18 | void uart_init(volatile struct uart8250_hw *uart) { 19 | 20 | /* set baudrate */ 21 | uart->lcr |= UART8250_LCR_DLAB; 22 | /** 23 | * should set dll and dlh, 24 | * to simplify instead lets assume the firmware did this for us. 25 | * TODO: we should add uart clk and baudrate info to platform descrption 26 | * and use this to calculate this values in runtime. 27 | */ 28 | uart->lcr &= ~UART8250_LCR_DLAB; 29 | 30 | /* configure 8n1 */ 31 | uart->lcr = UART8250_LCR_8BIT; 32 | 33 | /* disable interrupts */ 34 | uart->ier = 0; 35 | 36 | /* no modem */ 37 | uart->mcr = 0; 38 | 39 | /* clear status */ 40 | (void) uart->lsr; 41 | uart->msr = 0; 42 | } 43 | 44 | void uart_enable(volatile struct uart8250_hw *uart){ 45 | uart->fcr = UART8250_FCR_EN; 46 | } 47 | 48 | void uart_putc(volatile struct uart8250_hw *uart, int8_t c){ 49 | while(!(uart->lsr & UART8250_LSR_THRE)); 50 | uart->thr = c; 51 | } 52 | 53 | void uart_puts(volatile struct uart8250_hw *uart, char const* str){ 54 | while (*str) { 55 | uart_putc(uart, *str++); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/arch/armv8/inc/arch/platform.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __ARCH_PLATFORM_H__ 17 | #define __ARCH_PLATFORM_H__ 18 | 19 | #include 20 | 21 | struct arch_platform { 22 | struct gic_dscrp { 23 | paddr_t gicc_addr; 24 | paddr_t gich_addr; 25 | paddr_t gicv_addr; 26 | paddr_t gicd_addr; 27 | paddr_t gicr_addr; 28 | 29 | irqid_t maintenance_id; 30 | 31 | size_t interrupt_num; 32 | } gic; 33 | 34 | struct { 35 | paddr_t base; 36 | irqid_t interrupt_id; 37 | streamid_t global_mask; 38 | 39 | size_t group_num; 40 | struct smmu_group { 41 | streamid_t group_mask; 42 | streamid_t group_id; 43 | } *smmu_groups; 44 | 45 | } smmu; 46 | 47 | struct { 48 | paddr_t base_addr; 49 | struct { 50 | vaddr_t virtual; 51 | uint64_t hyp; 52 | } irqs; 53 | } generic_timer; 54 | 55 | struct clusters { 56 | size_t num; 57 | size_t* core_num; 58 | } clusters; 59 | }; 60 | 61 | struct platform_desc; 62 | unsigned long platform_arch_cpuid_to_mpdir(const struct platform_desc* plat, 63 | cpuid_t cpuid); 64 | cpuid_t platform_arch_mpidr_to_cpuid(const struct platform_desc* plat, 65 | uint64_t mpidr); 66 | #endif /* __ARCH_PLATFORM_H__ */ 67 | -------------------------------------------------------------------------------- /src/core/cache.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | 18 | static struct cache cache_dscr; 19 | 20 | size_t COLOR_NUM = 1; 21 | size_t COLOR_SIZE = 1; 22 | 23 | static void cache_calc_colors(struct cache* dscrp, size_t page_size) 24 | { 25 | if (dscrp->lvls == 0) { 26 | /* No cache? */ 27 | return; 28 | } 29 | 30 | size_t llc = dscrp->min_shared_lvl; 31 | 32 | if ((dscrp->type[llc] != UNIFIED) || (dscrp->indexed[llc][0] != PIPT)) 33 | return; 34 | 35 | size_t llc_way_size = 36 | dscrp->numset[llc][UNIFIED] * dscrp->line_size[llc][UNIFIED]; 37 | 38 | size_t flc_way_size = 0; 39 | if ((dscrp->type[0] != UNIFIED)) { 40 | flc_way_size = dscrp->numset[0][0] * dscrp->line_size[0][0]; 41 | size_t flc_i_way_size = dscrp->numset[0][1] * dscrp->line_size[0][1]; 42 | if (((dscrp->indexed[0][0] == PIPT) || 43 | (flc_i_way_size < flc_way_size)) && 44 | (dscrp->indexed[0][1] == PIPT)) { 45 | flc_way_size = flc_i_way_size; 46 | } 47 | } 48 | 49 | size_t llc_num_colors = llc_way_size / page_size; 50 | size_t flc_num_colors = flc_way_size / page_size; 51 | 52 | COLOR_SIZE = flc_num_colors; 53 | COLOR_NUM = llc_num_colors / COLOR_SIZE; 54 | } 55 | 56 | void cache_enumerate() 57 | { 58 | cache_arch_enumerate(&cache_dscr); 59 | cache_calc_colors(&cache_dscr, PAGE_SIZE); 60 | } 61 | -------------------------------------------------------------------------------- /src/arch/armv8/asm_defs.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | void cpu_defines() __attribute__((used)); 22 | void cpu_defines() 23 | { 24 | DEFINE_SIZE(CPU_SIZE, struct cpu); 25 | 26 | DEFINE_OFFSET(CPU_ROOT_PT_OFF, struct cpu, root_pt); 27 | 28 | DEFINE_OFFSET(CPU_STACK_OFF, struct cpu, stack); 29 | DEFINE_SIZE(CPU_STACK_SIZE, ((struct cpu*)NULL)->stack); 30 | 31 | DEFINE_OFFSET(CPU_IF_OFF, struct cpu, interface); 32 | DEFINE_SIZE(CPU_IF_SIZE, ((struct cpu*)NULL)->interface); 33 | 34 | DEFINE_OFFSET(CPU_VCPU_OFF, struct cpu, vcpu); 35 | 36 | DEFINE_OFFSET(CPU_ARCH_OFF, struct cpu, arch); 37 | DEFINE_OFFSET(CPU_ARCH_OFFSTATE_OFF, struct cpu_arch, psci_off_state); 38 | } 39 | 40 | void vcpu_defines() __attribute__((used)); 41 | void vcpu_defines() 42 | { 43 | DEFINE_SIZE(VCPU_ARCH_SIZE, struct vcpu_arch); 44 | DEFINE_OFFSET(VCPU_REGS_OFF, struct vcpu, regs); 45 | DEFINE_SIZE(VCPU_REGS_SIZE, struct arch_regs); 46 | } 47 | 48 | void platform_defines() __attribute__((used)); 49 | void platform_defines() 50 | { 51 | DEFINE_OFFSET(PLAT_CPUNUM_OFF, struct platform_desc, cpu_num); 52 | DEFINE_OFFSET(PLAT_ARCH_OFF, struct platform_desc, arch); 53 | DEFINE_OFFSET(PLAT_ARCH_CLUSTERS_OFF, struct arch_platform, clusters); 54 | DEFINE_OFFSET(PLAT_CLUSTERS_CORES_NUM_OFF, struct clusters, core_num); 55 | } 56 | -------------------------------------------------------------------------------- /src/core/inc/interrupts.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __INTERRUPTS_H__ 17 | #define __INTERRUPTS_H__ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | struct vm; 26 | 27 | typedef void (*irq_handler_t)(irqid_t int_id); 28 | 29 | void interrupts_init(); 30 | void interrupts_reserve(irqid_t int_id, irq_handler_t handler); 31 | 32 | void interrupts_cpu_sendipi(cpuid_t target_cpu, irqid_t ipi_id); 33 | void interrupts_cpu_enable(irqid_t int_id, bool en); 34 | 35 | bool interrupts_check(irqid_t int_id); 36 | void interrupts_clear(irqid_t int_id); 37 | 38 | enum irq_res { HANDLED_BY_HYP, FORWARD_TO_VM }; 39 | enum irq_res interrupts_handle(irqid_t int_id); 40 | 41 | void interrupts_vm_assign(struct vm *vm, irqid_t id); 42 | void interrupts_vm_inject(struct vcpu* vcpu, uint64_t id); 43 | 44 | void interrupts_set_shared(uint64_t id); 45 | bool interrupts_is_shared(uint64_t id); 46 | 47 | /* Must be implemented by architecture */ 48 | 49 | void interrupts_arch_init(); 50 | void interrupts_arch_enable(irqid_t int_id, bool en); 51 | bool interrupts_arch_check(irqid_t int_id); 52 | void interrupts_arch_clear(irqid_t int_id); 53 | void interrupts_arch_ipi_send(cpuid_t cpu_target, irqid_t ipi_id); 54 | void interrupts_arch_vm_assign(struct vm *vm, irqid_t id); 55 | /* TODO */ 56 | void interrupts_arch_vm_inject(struct vcpu* vcpu, uint64_t id); 57 | bool interrupts_arch_conflict(bitmap_t* interrupt_bitmap, irqid_t id); 58 | 59 | #endif /* __INTERRUPTS_H__ */ 60 | -------------------------------------------------------------------------------- /src/core/config.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | 18 | void config_vm_adjust_to_va(struct vm_config *vm_config, struct config *config, paddr_t phys) { 19 | adjust_ptr(vm_config->image.load_addr, phys); 20 | 21 | adjust_ptr(vm_config->platform.regions, config); 22 | 23 | if (adjust_ptr(vm_config->platform.devs, config)) { 24 | for (size_t j = 0; j < vm_config->platform.dev_num; j++) { 25 | adjust_ptr(vm_config->platform.devs[j].interrupts, config); 26 | } 27 | } 28 | 29 | if(adjust_ptr(vm_config->platform.ipcs, config)){ 30 | for (size_t j = 0; j < vm_config->platform.ipc_num; j++) { 31 | adjust_ptr(vm_config->platform.ipcs[j].interrupts, config); 32 | } 33 | } 34 | 35 | adjust_ptr(vm_config->children, config); 36 | for (size_t i = 0; i < vm_config->children_num; i++) { 37 | adjust_ptr(vm_config->children[i], config); 38 | config_vm_adjust_to_va(vm_config->children[i], config, phys); 39 | } 40 | 41 | config_arch_vm_adjust_to_va(vm_config, config, phys); 42 | } 43 | 44 | bool config_is_builtin() { 45 | extern uint8_t _config_start, _config_end; 46 | return &_config_start != &_config_end; 47 | } 48 | 49 | void config_adjust_to_va(struct config *config, uint64_t phys) { 50 | adjust_ptr(config->shmemlist, config); 51 | 52 | for (int i = 0; i < config->vmlist_size; i++) { 53 | adjust_ptr(config->vmlist[i], config); 54 | config_vm_adjust_to_va(config->vmlist[i], config, phys); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/core/iommu.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * David Cerdeira 8 | * Jose Martins 9 | * Angelo Ruocco 10 | * 11 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 12 | * terms of the GNU General Public License version 2 as published by the Free 13 | * Software Foundation, with a special exception exempting guest code from such 14 | * license. See the COPYING file in the top-level directory for details. 15 | * 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | struct iommu_device { 22 | streamid_t id; 23 | }; 24 | 25 | struct iommu_dev_node { 26 | node_t node; 27 | struct iommu_device dev; 28 | }; 29 | 30 | /* Mainly for HW initialization. */ 31 | void iommu_init() 32 | { 33 | iommu_arch_init(); 34 | } 35 | 36 | /* Configure architecture dependent stuff. */ 37 | bool iommu_vm_init(struct vm *vm, const struct vm_config *config) 38 | { 39 | objcache_init(&vm->iommu.dev_oc, sizeof(struct iommu_dev_node), 40 | SEC_HYP_GLOBAL, false); 41 | 42 | return iommu_arch_vm_init(vm, config); 43 | } 44 | 45 | /* Allows vms to add devices to their address space. */ 46 | bool iommu_vm_add_device(struct vm *vm, streamid_t dev_id) 47 | { 48 | bool res = false; 49 | 50 | /* 51 | * If dev_id == 0 assume global mask includes 52 | * the relevant devices for this VM. 53 | * 54 | * Assume there's no device id = 0 */ 55 | if (dev_id != 0) { 56 | 57 | /* Stream id is valid. Match this device with this VM specifically. */ 58 | res = iommu_arch_vm_add_device(vm, dev_id); 59 | } 60 | 61 | if (res) { 62 | struct iommu_dev_node *ptr = objcache_alloc(&vm->iommu.dev_oc); 63 | if(ptr != NULL){ 64 | ptr->dev.id = dev_id; 65 | list_push(&vm->iommu.dev_list, (node_t*)ptr); 66 | } else { 67 | res = false; 68 | } 69 | } 70 | 71 | return res; 72 | } 73 | -------------------------------------------------------------------------------- /src/arch/riscv/relocate.S: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | /** 22 | * Switch to a new address: 23 | * 24 | * a0: virtual address of new cpu space 25 | * a1: physical address of new translation tables 26 | */ 27 | .globl switch_space 28 | switch_space: 29 | 30 | /* Get current CPU space stack start */ 31 | la a6, cpu 32 | li t0, CPU_STACK_OFF + CPU_STACK_SIZE 33 | add a6, a6, t0 34 | 35 | /* Calculate stack size */ 36 | mv a7, sp 37 | sub a5, a6, a7 38 | 39 | /* Get current CPU space current sp */ 40 | mv a6, sp 41 | 42 | /* Get new CPU space current sp */ 43 | li t0, CPU_STACK_OFF + CPU_STACK_SIZE 44 | add a0, a0, t0 45 | sub a0, a0, a5 46 | 47 | /* Copy stack */ 48 | li a4, 0 49 | 1: 50 | /* Copy two words */ 51 | ld a2, (a6) 52 | sd a2, (a0) 53 | 54 | /* Increment addressess and count accordingly */ 55 | add a6, a6, 8 56 | add a0, a0, 8 57 | add a4, a4, 8 58 | 59 | /* If count is less then size, repeat */ 60 | blt a4, a5, 1b 61 | 62 | /* Restore original addresses */ 63 | sub a6, a6, a4 64 | sub a0, a0, a4 65 | 66 | /* Update root page table pointer */ 67 | srl a1, a1, PAGE_SHIFT 68 | li t0, SATP_MODE_DFLT 69 | or a1, a1, t0 70 | csrw satp, a1 71 | 72 | /** 73 | * Invalidate TLB: we can do this directly here without sbi support 74 | * because we don't really need any shootdown as all harts must go 75 | * through here. 76 | */ 77 | sfence.vma 78 | 79 | ret 80 | -------------------------------------------------------------------------------- /src/sdees/sdGPOS/arch/riscv/sdgpos.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "types.h" 5 | #include 6 | #include "vm.h" 7 | #include "vmm.h" 8 | 9 | 10 | static int64_t sdgpos_smc_handler(struct vcpu* vcpu, uint64_t smc_fid) 11 | { 12 | /* if(vcpu->vm->id != 2) */ 13 | /* return 0; */ 14 | /* int64_t ret = -HC_E_FAILURE; */ 15 | /* uint64_t x1 = vcpu->regs->x[1]; */ 16 | /* uint64_t x2 = vcpu->regs->x[2]; */ 17 | /* uint64_t x3 = vcpu->regs->x[3]; */ 18 | 19 | /* uint64_t pc_step = 2 + (2 * 1); */ 20 | /* vcpu_writepc(vcpu, vcpu_readpc(vcpu) + pc_step); */ 21 | /* ret = 0; */ 22 | /* return ret; */ 23 | return 0; 24 | } 25 | 26 | int64_t sdgpos_hvc_handler(struct vcpu* vcpu, uint64_t fid) 27 | { 28 | if(vcpu->vm->type != 0) 29 | return 0; 30 | 31 | int64_t ret; 32 | 33 | unsigned long arg0 = vcpu_readreg(vcpu, REG_A0); 34 | unsigned long arg1 = vcpu_readreg(vcpu, REG_A1); 35 | unsigned long arg2 = vcpu_readreg(vcpu, REG_A2); 36 | /* unsigned long arg3 = vcpu_readreg(vcpu, REG_A3); */ 37 | 38 | /* TODO: sdee */ 39 | switch(fid) { 40 | case HC_IPC: 41 | ret = ipc_hypercall(vcpu, arg0, arg1, arg2); 42 | break; 43 | default: 44 | /* WARNING("Unknown hypercall id %x", fid); */ 45 | ret = -1; 46 | } 47 | 48 | return ret; 49 | } 50 | static struct hndl_smc smc = { 51 | /* TODO: obtain this to decide whether to invoke handler early on */ 52 | .end = 0xffff0000, 53 | .start = 0x00000000, 54 | .handler = sdgpos_smc_handler, 55 | }; 56 | 57 | static struct hndl_hvc hvc = { 58 | /* TODO: obtain this to decide whether to invoke handler early on */ 59 | .handler = sdgpos_hvc_handler, 60 | }; 61 | 62 | 63 | bool sdgpos_arch_setup(struct vm *vm) 64 | { 65 | int64_t ret = 0; 66 | 67 | if(vm == NULL) 68 | return -1; 69 | 70 | /* TODO: check config structure or something to check if this VMs wants tz 71 | * to handle its events */ 72 | if(vm->type == 0){ 73 | vm_hndl_smc_add(vm, &smc); 74 | vm_hndl_hvc_add(vm, &hvc); 75 | } 76 | 77 | return ret; 78 | } 79 | -------------------------------------------------------------------------------- /src/arch/armv8/interrupts.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * Angelo Ruocco 9 | * 10 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 11 | * terms of the GNU General Public License version 2 as published by the Free 12 | * Software Foundation, with a special exception exempting guest code from such 13 | * license. See the COPYING file in the top-level directory for details. 14 | * 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #ifndef GIC_VERSION 28 | #error "GIC_VERSION not defined for this platform" 29 | #endif 30 | 31 | void interrupts_arch_init() 32 | { 33 | gic_init(); 34 | interrupts_cpu_enable(platform.arch.gic.maintenance_id, true); 35 | } 36 | 37 | void interrupts_arch_ipi_send(cpuid_t target_cpu, irqid_t ipi_id) 38 | { 39 | if (ipi_id < GIC_MAX_SGIS) gic_send_sgi(target_cpu, ipi_id); 40 | } 41 | 42 | void interrupts_arch_enable(irqid_t int_id, bool en) 43 | { 44 | gic_set_enable(int_id, en); 45 | gic_set_prio(int_id, 0x01); 46 | if (GIC_VERSION == GICV2) { 47 | gicd_set_trgt(int_id, 1 << cpu.id); 48 | } else { 49 | gicd_set_route(int_id, cpu.arch.mpidr); 50 | } 51 | } 52 | 53 | bool interrupts_arch_check(irqid_t int_id) 54 | { 55 | return gic_get_pend(int_id); 56 | } 57 | 58 | inline bool interrupts_arch_conflict(bitmap_t* interrupt_bitmap, irqid_t int_id) 59 | { 60 | return (bitmap_get(interrupt_bitmap, int_id) && int_id > GIC_CPU_PRIV); 61 | } 62 | 63 | void interrupts_arch_clear(irqid_t int_id) 64 | { 65 | gic_set_act(int_id, false); 66 | gic_set_pend(int_id, false); 67 | } 68 | 69 | void interrupts_arch_vm_assign(struct vm *vm, irqid_t id) 70 | { 71 | vgic_set_hw(vm, id); 72 | } 73 | 74 | void interrupts_arch_vm_inject(struct vcpu* vcpu, uint64_t id) 75 | { 76 | vgic_inject(vcpu, id, cpu.vcpu->id); 77 | } 78 | -------------------------------------------------------------------------------- /src/arch/armv8/inc/arch/spinlock.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | /** 17 | * TODO: this is a naive implementation to get things going. 18 | * Optimizations needed. See ticket locks in ARMv8-A. 19 | */ 20 | 21 | #ifndef __ARCH_SPINLOCK__ 22 | #define __ARCH_SPINLOCK__ 23 | 24 | #include 25 | 26 | 27 | typedef volatile struct { 28 | uint32_t ticket; 29 | uint32_t next; 30 | } spinlock_t; 31 | 32 | #define SPINLOCK_INITVAL ((spinlock_t){ 0, 0 }) 33 | 34 | static inline void spinlock_init(spinlock_t* lock) 35 | { 36 | lock->ticket = 0; 37 | lock->next = 0; 38 | } 39 | 40 | static inline void spin_lock(spinlock_t* lock) 41 | { 42 | uint32_t ticket; 43 | uint32_t next; 44 | uint32_t temp; 45 | 46 | (void)lock; 47 | __asm__ volatile( 48 | /* Get ticket */ 49 | "1:\n\t" 50 | "ldaxr %w0, %3\n\t" 51 | "add %w1, %w0, 1\n\t" 52 | "stxr %w2, %w1, %3\n\t" 53 | "cbnz %w2, 1b\n\t" 54 | /* Wait for your turn */ 55 | "2:\n\t" 56 | "ldar %w1, %4\n\t" 57 | "cmp %w0, %w1\n\t" 58 | "b.eq 3f\n\t" 59 | "wfe\n\t" 60 | "b 2b\n\t" 61 | "3:\n\t" : "=&r"(ticket), "=&r"(next), "=&r"(temp) : "Q"(lock->ticket), "Q"(lock->next) 62 | : "memory"); 63 | } 64 | 65 | static inline void spin_unlock(spinlock_t* lock) 66 | { 67 | uint32_t temp; 68 | 69 | __asm__ volatile( 70 | /* increment to next ticket */ 71 | "ldr %w0, %1\n\t" 72 | "add %w0, %w0, 1\n\t" 73 | "stlr %w0, %1\n\t" 74 | "dsb ish\n\t" 75 | "sev\n\t" : "=&r"(temp) : "Q"(lock->next) : "memory");} 76 | 77 | #endif /* __ARCH_SPINLOCK__ */ 78 | -------------------------------------------------------------------------------- /src/arch/armv8/inc/arch/gicv2.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __GICV2_H__ 17 | #define __GICV2_H__ 18 | 19 | #include 20 | 21 | static inline uint64_t gich_read_lr(size_t i) 22 | { 23 | if (i < NUM_LRS) { 24 | return gich.LR[i]; 25 | } else { 26 | ERROR("gic: trying to read inexistent list register"); 27 | } 28 | } 29 | 30 | static inline void gich_write_lr(size_t i, uint64_t val) 31 | { 32 | if (i < NUM_LRS) { 33 | gich.LR[i] = val; 34 | } else { 35 | ERROR("gic: trying to write inexistent list register"); 36 | } 37 | } 38 | 39 | static inline uint32_t gich_get_hcr() 40 | { 41 | return gich.HCR; 42 | } 43 | 44 | static inline void gich_set_hcr(uint32_t hcr) 45 | { 46 | gich.HCR = hcr; 47 | } 48 | 49 | static inline uint32_t gich_get_misr() 50 | { 51 | return gich.MISR; 52 | } 53 | 54 | static inline uint64_t gich_get_eisr() 55 | { 56 | uint64_t eisr = gich.EISR[0]; 57 | if (NUM_LRS > 32) eisr |= (((uint64_t)gich.EISR[1] << 32)); 58 | return eisr; 59 | } 60 | 61 | static inline uint64_t gich_get_elrsr() 62 | { 63 | uint64_t elsr = gich.ELSR[0]; 64 | if (NUM_LRS > 32) elsr |= (((uint64_t)gich.ELSR[1] << 32)); 65 | return elsr; 66 | } 67 | 68 | static inline uint32_t gicc_iar() { 69 | return gicc.IAR; 70 | } 71 | 72 | static inline void gicc_eoir(uint32_t eoir) { 73 | gicc.EOIR = eoir; 74 | } 75 | 76 | static inline void gicc_dir(uint32_t dir) { 77 | gicc.DIR = dir; 78 | } 79 | 80 | static inline uint32_t gich_get_vmcr() 81 | { 82 | return gich.VMCR; 83 | } 84 | 85 | static inline void gich_set_vmcr(uint32_t vmcr) 86 | { 87 | gich.VMCR = vmcr; 88 | } 89 | 90 | 91 | #endif /* __GICV2_H__ */ 92 | -------------------------------------------------------------------------------- /src/platform/zcu104/zcu104_desc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * Angelo Ruocco 9 | * 10 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 11 | * terms of the GNU General Public License version 2 as published by the Free 12 | * Software Foundation, with a special exception exempting guest code from such 13 | * license. See the COPYING file in the top-level directory for details. 14 | * 15 | */ 16 | 17 | #include 18 | 19 | struct platform_desc platform = { 20 | .cpu_num = 4, 21 | .region_num = 1, 22 | .regions = (struct mem_region[]) { 23 | { 24 | /** 25 | * The Arm Trusted Firmware shipped in the default Xilinx BOOT.BIN 26 | * is loaded in a non secure zone, more specifically at the end of 27 | * the first memory bank. Being in a non-secure zone means that can 28 | * be easily overwritten. 29 | * 30 | * The memory size is therefore shrunk to take this into account and 31 | * avoid memory corruption. 32 | * 33 | * Note that if the ATF is compiled with debug symbols or with a 34 | * custom SPD service, then it gets loaded at the *beginning* of the 35 | * first memory bank, in that case the base address should be 36 | * changed to 0x80000, and the size shrunk accorindgly. 37 | */ 38 | .base = 0x00080000, 39 | .size = 0x7FF00000 - 0x16000 40 | } 41 | }, 42 | 43 | .console = { 44 | .base = 0xFF000000 45 | }, 46 | 47 | .arch = { 48 | .gic = { 49 | .gicd_addr = 0xF9010000, 50 | .gicc_addr = 0xF902f000, 51 | .gich_addr = 0xF9040000, 52 | .gicv_addr = 0xF906f000, 53 | .maintenance_id = 25 54 | }, 55 | 56 | .smmu = { 57 | .base = 0xFD800000, 58 | .interrupt_id = 187 59 | }, 60 | 61 | .generic_timer = { 62 | .base_addr = 0xFF260000 63 | } 64 | } 65 | }; 66 | -------------------------------------------------------------------------------- /src/arch/riscv/inc/arch/plic.h: -------------------------------------------------------------------------------- 1 | /** 2 | CROSSCONHyp Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __PLIC_H__ 17 | #define __PLIC_H__ 18 | 19 | #include 20 | #include 21 | 22 | #define PLIC_MAX_INTERRUPTS (1024) 23 | #define PLIC_NUM_PRIO_REGS (PLIC_MAX_INTERRUPTS) 24 | #define PLIC_NUM_PEND_REGS (PLIC_MAX_INTERRUPTS) 25 | #define PLIC_NUM_ENBL_REGS (PLIC_MAX_INTERRUPTS / 32) 26 | 27 | #define PLIC_ENBL_OFF (0x002000) 28 | #define PLIC_CLAIMCMPLT_OFF (0x200000) 29 | 30 | struct plic_global_hw { 31 | uint32_t prio[PLIC_NUM_PRIO_REGS]; 32 | uint32_t pend[PLIC_NUM_PEND_REGS]; 33 | uint32_t enbl[PLIC_PLAT_CNTXT_NUM][PLIC_NUM_ENBL_REGS]; 34 | } __attribute__((__packed__, aligned(PAGE_SIZE))); 35 | 36 | struct plic_hart_hw { 37 | uint32_t threshold; 38 | union { 39 | uint32_t claim; 40 | uint32_t complete; 41 | }; 42 | uint8_t res[0x1000 - 0x0008]; 43 | } __attribute__((__packed__, aligned(PAGE_SIZE))); 44 | 45 | extern volatile struct plic_global_hw plic_global; 46 | extern volatile struct plic_hart_hw plic_hart[PLIC_PLAT_CNTXT_NUM]; 47 | extern size_t PLIC_IMPL_INTERRUPTS; 48 | 49 | void plic_init(); 50 | void plic_cpu_init(); 51 | void plic_handle(); 52 | void plic_set_enbl(unsigned cntxt, irqid_t int_id, bool en); 53 | bool plic_get_enbl(unsigned cntxt, irqid_t int_id); 54 | void plic_set_prio(irqid_t int_id, uint32_t prio); 55 | uint32_t plic_get_prio(irqid_t int_id); 56 | void plic_set_threshold(unsigned cntxt, uint32_t threshold); 57 | uint32_t plic_get_threshold(irqid_t int_id); 58 | bool plic_get_pend(irqid_t int_id); 59 | 60 | struct plic_cntxt { 61 | cpuid_t hart_id; 62 | enum { PRIV_M = 3, PRIV_S = 2, PRIV_U = 0 } mode; 63 | }; 64 | 65 | int plic_plat_cntxt_to_id(struct plic_cntxt cntxt); 66 | struct plic_cntxt plic_plat_id_to_cntxt(int id); 67 | 68 | #endif /* __PLIC_H__ */ 69 | -------------------------------------------------------------------------------- /src/lib/inc/bit.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __BIT_H__ 17 | #define __BIT_H__ 18 | 19 | #include 20 | 21 | /** 22 | * The extra shift is because both arm and riscv logical shift instructions 23 | * support a maximum of machine word length minus one bit shits. This covers 24 | * the corner case of runtime full machine word length masks with the cost of 25 | * an extra shift instruction. For static masks, there should be no extra costs. 26 | */ 27 | #define BIT32_MASK(OFF, LEN) ((((UINT32_C(1)<<((LEN)-1))<<1)-1)<<(OFF)) 28 | #define BIT64_MASK(OFF, LEN) ((((UINT64_C(1)<<((LEN)-1))<<1)-1)<<(OFF)) 29 | #define BIT_MASK(OFF, LEN) (((((1UL)<<((LEN)-1))<<1)-1)<<(OFF)) 30 | 31 | #ifndef __ASSEMBLER__ 32 | 33 | #define BIT_OPS_GEN(PRE, TYPE, LIT, MASK) \ 34 | static inline TYPE PRE ## _get(TYPE word, size_t off)\ 35 | {\ 36 | return word & ((LIT) << off);\ 37 | }\ 38 | static inline TYPE PRE ## _set(TYPE word, size_t off)\ 39 | {\ 40 | return word |= ((LIT) << off);\ 41 | }\ 42 | static inline TYPE PRE ## _clear(TYPE word, size_t off)\ 43 | {\ 44 | return word &= ~((LIT) << off);\ 45 | }\ 46 | static inline TYPE PRE ## _extract(TYPE word, size_t off, size_t len)\ 47 | {\ 48 | return (word >> off) & MASK(0, len);\ 49 | }\ 50 | static inline TYPE PRE ## _insert(TYPE word, TYPE val, size_t off,\ 51 | size_t len)\ 52 | {\ 53 | return (~MASK(off, len) & word) | ((MASK(0, len) & val) << off);\ 54 | }\ 55 | 56 | BIT_OPS_GEN(bit32, uint32_t, UINT32_C(1), BIT32_MASK); 57 | BIT_OPS_GEN(bit64, uint64_t, UINT64_C(1), BIT64_MASK); 58 | BIT_OPS_GEN(bit, unsigned long, (1UL), BIT_MASK); 59 | 60 | #endif /* |__ASSEMBLER__ */ 61 | 62 | #endif /* __BIT_H__ */ 63 | -------------------------------------------------------------------------------- /src/arch/armv8/platform.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | unsigned long platform_arch_cpuid_to_mpdir(const struct platform_desc* plat, 20 | cpuid_t cpuid) 21 | { 22 | if (cpuid > plat->cpu_num) { 23 | return ~(~MPIDR_RES1 & MPIDR_RES0_MSK); //return an invlid mpidr by inverting res bits 24 | } 25 | 26 | unsigned long mpidr = 0; 27 | bool found = false; 28 | if (plat->arch.clusters.num > 0) { 29 | for (size_t i = 0, j = 0; i < plat->arch.clusters.num; i++) { 30 | if (cpuid < (j + plat->arch.clusters.core_num[i])) { 31 | mpidr = (i << 8) | ((cpuid - j) & 0xff); 32 | found = true; 33 | break; 34 | } 35 | 36 | j += plat->arch.clusters.core_num[i]; 37 | } 38 | 39 | if (!found) { 40 | ERROR("failed cpuid to mpdir translation"); 41 | } 42 | } else { 43 | /** 44 | * No cluster information in configuration. Assume a singl cluster. 45 | */ 46 | mpidr = cpuid; 47 | } 48 | 49 | mpidr |= MPIDR_RES1; 50 | if (plat->cpu_num == 1) { 51 | mpidr |= MPIDR_U_BIT; 52 | } 53 | 54 | return mpidr; 55 | } 56 | 57 | cpuid_t platform_arch_mpidr_to_cpuid(const struct platform_desc* plat, 58 | uint64_t mpidr){ 59 | int64_t cpuid = 0; 60 | int i = 0; 61 | for(i = 0; i < ((mpidr >> 8) & 0xff) && i < plat->arch.clusters.num; i++){ 62 | cpuid = plat->arch.clusters.core_num[i]; 63 | } 64 | 65 | if(i < plat->arch.clusters.num){ 66 | cpuid += plat->arch.clusters.core_num[i]; 67 | } else { 68 | cpuid = -1; 69 | } 70 | 71 | return cpuid; 72 | } 73 | -------------------------------------------------------------------------------- /src/platform/drivers/8250_uart/inc/drivers/8250_uart.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef UART8250_H 17 | #define UART8250_H 18 | 19 | #include 20 | #include 21 | 22 | #define UART8250_LSR_THRE (1U << 5) 23 | 24 | #ifndef UART8250_REG_WIDTH 25 | #error "uart8259 reg width " UART8250_REG_WIDTH "not defined" 26 | #endif 27 | 28 | #ifndef UART8250_REG_WIDTH 29 | #define UART8250_REG_WIDTH 4 30 | #endif 31 | 32 | #if (UART8250_REG_WIDTH == 1) 33 | typedef uint8_t uart8250_reg_t; 34 | #elif (UART8250_REG_WIDTH == 4) 35 | typedef uint32_t uart8250_reg_t; 36 | #else 37 | #error "uart8250 reg width " UART8250_REG_WIDTH " not supported" 38 | #endif 39 | 40 | 41 | #ifndef UART8250_PAGE_OFFSET 42 | #define UART8250_PAGE_OFFSET 0 43 | #endif 44 | 45 | struct uart8250_hw { 46 | uint8_t offset[UART8250_PAGE_OFFSET]; 47 | union { 48 | uart8250_reg_t thr; 49 | uart8250_reg_t rbr; 50 | uart8250_reg_t dll; 51 | }; 52 | union { 53 | uart8250_reg_t ier; 54 | uart8250_reg_t dlh; 55 | }; 56 | union { 57 | uart8250_reg_t iir; 58 | uart8250_reg_t fcr; 59 | }; 60 | uart8250_reg_t lcr; 61 | uart8250_reg_t mcr; 62 | uart8250_reg_t lsr; 63 | uart8250_reg_t msr; 64 | uart8250_reg_t sr; 65 | }; 66 | 67 | #define UART8250_LCR_DLAB (0x1 << 7) 68 | #define UART8250_LCR_8BIT (0x3 << 0) 69 | 70 | #define UART8250_FCR_TX_CLR (0x1 << 2) 71 | #define UART8250_FCR_RX_CLR (0x1 << 1) 72 | #define UART8250_FCR_EN (0x1 << 0) 73 | 74 | typedef struct uart8250_hw crossconhyp_uart_t; 75 | 76 | void uart_enable(volatile struct uart8250_hw *uart); 77 | void uart_init(volatile struct uart8250_hw *uart); 78 | void uart_puts(volatile struct uart8250_hw *uart, const char* str); 79 | 80 | #endif /* UART8250_H */ 81 | -------------------------------------------------------------------------------- /src/platform/zcu102/zcu102_desc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * Angelo Ruocco 9 | * 10 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 11 | * terms of the GNU General Public License version 2 as published by the Free 12 | * Software Foundation, with a special exception exempting guest code from such 13 | * license. See the COPYING file in the top-level directory for details. 14 | * 15 | */ 16 | 17 | #include 18 | 19 | struct platform_desc platform = { 20 | .cpu_num = 4, 21 | .region_num = 2, 22 | .regions = (struct mem_region[]) { 23 | { 24 | /** 25 | * The Arm Trusted Firmware shipped in the default Xilinx BOOT.BIN 26 | * is loaded in a non secure zone, more specifically at the end of 27 | * the first memory bank. Being in a non-secure zone means that can 28 | * be easily overwritten. 29 | * 30 | * The memory size is therefore shrunk to take this into account and 31 | * avoid memory corruption. 32 | * 33 | * Note that if the ATF is compiled with debug symbols or with a 34 | * custom SPD service, then it gets loaded at the *beginning* of the 35 | * first memory bank, in that case the base address should be 36 | * changed to 0x80000, and the size shrunk accorindgly. 37 | */ 38 | .base = 0x00000000, 39 | .size = 0x80000000 - 0x16000 40 | }, 41 | { 42 | .base = 0x800000000, 43 | .size = 0x80000000 44 | } 45 | }, 46 | 47 | .console = { 48 | .base = 0xFF000000 49 | }, 50 | 51 | .arch = { 52 | .gic = { 53 | .gicd_addr = 0xF9010000, 54 | .gicc_addr = 0xF902f000, 55 | .gich_addr = 0xF9040000, 56 | .gicv_addr = 0xF906f000, 57 | .maintenance_id = 25 58 | }, 59 | 60 | .smmu = { 61 | .base = 0xFD800000, 62 | .interrupt_id = 187 63 | }, 64 | 65 | .generic_timer = { 66 | .base_addr = 0xFF260000 67 | } 68 | } 69 | 70 | }; 71 | -------------------------------------------------------------------------------- /src/lib/bitmap.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | 18 | ssize_t bitmap_find_nth(bitmap_t* map, size_t size, size_t nth, size_t start, 19 | bool set) 20 | { 21 | if (size <= 0 || nth <= 0 || start < 0) return -1; 22 | 23 | size_t count = 0; 24 | unsigned bit = set ? 1 : 0; 25 | 26 | for (ssize_t i = start; i < size; i++) { 27 | if (bitmap_get(map, i) == bit) { 28 | if (++count == nth) return i; 29 | } 30 | } 31 | 32 | return -1; 33 | } 34 | 35 | size_t bitmap_count_consecutive(bitmap_t* map, size_t size, size_t start, 36 | size_t n) 37 | { 38 | if (n <= 1) return n; 39 | 40 | unsigned b = bitmap_get(map, start); 41 | size_t count = 1; 42 | start += 1; 43 | 44 | while (start < size) { 45 | if (bitmap_get(map, start) == b) 46 | count++; 47 | else 48 | break; 49 | if (count == n) break; 50 | start++; 51 | } 52 | 53 | return count; 54 | } 55 | 56 | ssize_t bitmap_find_consec(bitmap_t* map, size_t size, size_t start, size_t n, 57 | bool set) 58 | { 59 | ssize_t count = 0; 60 | ssize_t i = 0; 61 | 62 | // find first set 63 | if ((i = bitmap_find_nth(map, size, 1, start, set)) < 0) return -1; 64 | 65 | while (i < size) { 66 | // find the last (with n as maximum) contiguous set page 67 | count = bitmap_count_consecutive(map, size, i, n); 68 | if (count < n) { // if didn't found enough n contiguous set pages 69 | i += count; 70 | // find the last contiguous ~set page 71 | i += bitmap_count_consecutive(map, size, i, -1); 72 | } else { 73 | break; 74 | } 75 | } 76 | 77 | if (i >= size) i = -1; 78 | 79 | return i; 80 | } 81 | -------------------------------------------------------------------------------- /src/lib/inc/util.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * Sandro Pinto 9 | * 10 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 11 | * terms of the GNU General Public License version 2 as published by the Free 12 | * Software Foundation, with a special exception exempting guest code from such 13 | * license. See the COPYING file in the top-level directory for details. 14 | * 15 | */ 16 | 17 | #ifndef __UTIL_H__ 18 | #define __UTIL_H__ 19 | 20 | /* UTILITY MACROS */ 21 | 22 | /* align VAL to TO which must be power a two */ 23 | #define ALIGN(VAL, TO) ((((VAL) + (TO)-1) / (TO)) * TO) 24 | #define ALIGN_FLOOR(VAL, TO) ((VAL) & ~((TO)-1)) 25 | #define NUM_PAGES(SZ) (ALIGN(SZ, PAGE_SIZE)/PAGE_SIZE) 26 | #define PAGE_OFFSET_MASK ((PAGE_SIZE)-1) 27 | #define PAGE_FRAME_MASK (~(PAGE_OFFSET_MASK)) 28 | 29 | #define SR_OR(VAL, SHIFT) (((VAL) >> (SHIFT)) | VAL) 30 | /* Next Power Of Two */ 31 | #define NPOT(VAL) \ 32 | ((SR_OR(((VAL)-1), 1) | SR_OR(SR_OR(((VAL)-1), 1), 2) | \ 33 | SR_OR(SR_OR(SR_OR(((VAL)-1), 1), 2), 4) | \ 34 | SR_OR(SR_OR(SR_OR(SR_OR(((VAL)-1), 1), 2), 4), 8) | \ 35 | SR_OR(SR_OR(SR_OR(SR_OR(SR_OR(((VAL)-1), 1), 2), 4), 8), 16)) + \ 36 | 1) 37 | 38 | /* Previous Power Of Two */ 39 | #define PPOT(VAL) (NPOT((VAL)) - (NPOT((VAL)) >> 1)) 40 | 41 | #define STR(s) #s 42 | #define XSTR(s) STR(s) 43 | 44 | #ifndef __ASSEMBLER__ 45 | 46 | #define DEFINE_OFFSET(SYMBOL, STRUCT, FIELD) \ 47 | asm volatile("\n-> " XSTR(SYMBOL) " %0 \n" : : "i"(offsetof(STRUCT, FIELD))) 48 | 49 | #define DEFINE_SIZE(SYMBOL, TYPE) \ 50 | asm volatile("\n-> " XSTR(SYMBOL) " %0 \n" : : "i"(sizeof(TYPE))) 51 | 52 | #define max(n1, n2) (((n1) > (n2)) ? (n1) : (n2)) 53 | #define min(n1, n2) (((n1) < (n2)) ? (n1) : (n2)) 54 | 55 | /* WARNING! does not check for overflow! */ 56 | #define range_in_range(_base1, _size1, _base2, _size2) \ 57 | (((_base1) >= (_base2)) && ((_base1 + _size1) <= ((_base2) + (_size2)))) 58 | 59 | /* WARNING! does not check for overflow! */ 60 | #define in_range(_addr, _base, _size) range_in_range(_addr, 0, _base, _size) 61 | 62 | #endif 63 | 64 | #endif /* __UTIL_H__ */ 65 | -------------------------------------------------------------------------------- /src/sdees/sdTZ/arch/armv8/sdtz.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "types.h" 6 | #include "vm.h" 7 | #include "vmm.h" 8 | #include 9 | 10 | 11 | static inline void sdtz_copy_args(struct vcpu *vcpu_dst, struct vcpu *vcpu_src, 12 | size_t num_args) { 13 | for (size_t i = 0; i < num_args; i++) { 14 | size_t regid = HYPCALL_ARG_REG(i); 15 | vcpu_writereg(vcpu_dst, regid, vcpu_readreg(vcpu_src, regid)); 16 | } 17 | } 18 | 19 | static inline void sdtz_copy_args_call_done(struct vcpu *vcpu_dst, struct vcpu 20 | *vcpu_src, size_t num_args) { 21 | for (size_t i = 0; i < num_args; i++) { 22 | size_t regid = HYPCALL_ARG_REG(i); 23 | vcpu_writereg(vcpu_dst, regid, vcpu_readreg(vcpu_src, regid+1)); 24 | } 25 | } 26 | 27 | /* TODO Not good */ 28 | extern int64_t sdtz_handler(struct vcpu* vcpu, uint64_t fid); 29 | 30 | int64_t sdtz_smc_handler(struct vcpu* vcpu, uint64_t smc_fid) { 31 | 32 | int64_t ret = -HC_E_FAILURE; 33 | 34 | struct vcpu *calling_vcpu = cpu.vcpu; 35 | 36 | if (calling_vcpu->vm->type == 0) { /* normal world */ 37 | if (is_psci_fid(smc_fid)) { 38 | /* TODO: signal trusted OS a PSCI event is comming up */ 39 | /* potentially handle core going to sleep */ 40 | return HC_E_SUCCESS; 41 | } else { 42 | /* TODO: If SMC call is for trusted OS */ 43 | ret = sdtz_handler(vcpu, smc_fid); 44 | } 45 | }else{ 46 | ret = sdtz_handler(vcpu, smc_fid); 47 | } 48 | 49 | return ret; 50 | } 51 | 52 | 53 | static struct hndl_smc smc = { 54 | /* TODO: obtain this to decide whether to invoke handler early on */ 55 | .end = 0xffff0000, 56 | .start = 0x00000000, 57 | .handler = sdtz_smc_handler, 58 | }; 59 | 60 | 61 | int64_t sdtz_arch_handler_setup(struct vm *vm) 62 | { 63 | int64_t ret = 0; 64 | 65 | if(vm == NULL) 66 | return -1; 67 | 68 | /* TODO: check config structure or something to check if this VMs wants tz 69 | * to handle its events */ 70 | vm_hndl_smc_add(vm, &smc); 71 | 72 | return ret; 73 | } 74 | 75 | void tee_arch_interrupt_disable() 76 | { 77 | } 78 | 79 | void tee_arch_interrupt_enable() 80 | { 81 | 82 | } 83 | 84 | void tee_step(struct vcpu* vcpu) 85 | { 86 | uint64_t pc_step = 2 + (2 * 1); 87 | vcpu_writepc(vcpu, vcpu_readpc(vcpu) + pc_step); 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/arch/armv8/mem.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | void as_arch_init(struct addr_space* as) 22 | { 23 | size_t index; 24 | 25 | /* 26 | * If the address space is a copy of an existing hypervisor space it's not 27 | * possible to use the PT_CPU_REC index to navigate it, so we have to use 28 | * the PT_VM_REC_IND. 29 | * By using id dependent index we can host more than one VM per pcpu. 30 | */ 31 | if (as->type == AS_HYP_CPY || as->type == AS_VM) { 32 | index = PT_VM_REC_IND - (8*(as->id-1)); /* LPAE is 8bytes per entry */ 33 | } else { 34 | index = PT_CPU_REC_IND; 35 | } 36 | pt_set_recursive(&as->pt, index); 37 | } 38 | 39 | bool mem_translate(struct addr_space* as, vaddr_t va, paddr_t* pa) 40 | { 41 | uint64_t par = 0, par_saved = 0; 42 | 43 | /** 44 | * TODO: are barriers needed in this operation? 45 | */ 46 | 47 | par_saved = MRS(PAR_EL1); 48 | 49 | if (as->type == AS_HYP || as->type == AS_HYP_CPY) 50 | asm volatile("AT S1E2W, %0" ::"r"(va)); 51 | else 52 | asm volatile("AT S12E1W, %0" ::"r"(va)); 53 | 54 | ISB(); 55 | par = MRS(PAR_EL1); 56 | MSR(PAR_EL1, par_saved); 57 | if (par & PAR_F) { 58 | return false; 59 | } else { 60 | if (pa != NULL) 61 | *pa = (par & PAR_PA_MSK) | (va & (PAGE_SIZE - 1)); 62 | return true; 63 | } 64 | } 65 | 66 | void mem_guest_ipa_translate(void* va, uint64_t* physical_address) 67 | { 68 | uint64_t tmp = 0, tmp2 = 0; 69 | tmp = MRS(SCTLR_EL1); 70 | tmp2 = tmp & ~(1ULL << 0); 71 | MSR(SCTLR_EL1, tmp2); 72 | ISB(); 73 | asm volatile("AT S12E1W, %0" ::"r"(va)); 74 | ISB(); 75 | MSR(SCTLR_EL1, tmp); 76 | *physical_address = 77 | (MRS(PAR_EL1) & PAR_PA_MSK) | (((uint64_t)va) & (PAGE_SIZE - 1)); 78 | } 79 | -------------------------------------------------------------------------------- /configs/configs.mk: -------------------------------------------------------------------------------- 1 | ## 2 | # CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | # 4 | # Copyright (c) CROSSCONHyp Project (www.crossconhyp-project.org), 2019- 5 | # 6 | # Authors: 7 | # Jose Martins 8 | # 9 | # CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | # terms of the GNU General Public License version 2 as published by the Free 11 | # Software Foundation, with a special exception exempting guest code from such 12 | # license. See the COPYING file in the top-level directory for details. 13 | # 14 | ## 15 | 16 | 17 | #Note: all directory, toolchain and flag variables are supposed to be 18 | # defined/passed by the main makefile 19 | 20 | ifeq ($(CONFIG),) 21 | $(error Configuration (CONFIG) not defined.) 22 | endif 23 | 24 | config_dir:=$(CONFIG_REPO) 25 | config_src:=$(wildcard $(config_dir)/$(CONFIG).c) 26 | ifeq ($(config_src),) 27 | config_dir:=$(CONFIG_REPO)/$(CONFIG) 28 | config_src:=$(wildcard $(config_dir)/config.c) 29 | endif 30 | ifeq ($(config_src),) 31 | $(error Cant find file for $(CONFIG) config!) 32 | endif 33 | 34 | config_ld:=$(configs_dir)/linker.ld 35 | config_asm:=$(config_src:%.c=%.S) 36 | config_obj:=$(config_src:%.c=%.o) 37 | config_dep:=$(config_src:%.c=%.d) 38 | CONFIG_BIN:=$(config_dir)/$(CONFIG).bin 39 | config_elf=$(CONFIG_BIN:%.bin=%.elf) 40 | 41 | config: $(CONFIG_BIN) 42 | 43 | -include $(config_dep) 44 | 45 | $(config_dep): $(config_src) 46 | @$(cc) $(CPPFLAGS) -S $< -o temp.S 47 | -@grep ".incbin" temp.S > $(patsubst %.d, %.S, $@) 48 | @$(as) -MD $@ $(patsubst %.d, %.S, $@) -o $(patsubst %.d, %.o, $@) 49 | @rm temp.S $(patsubst %.d, %.S, $@) 50 | @$(cc) -MM -MG -MT "$(patsubst %.d, %.o, $@) $@" $(CPPFLAGS) $(filter %.c, $^) >> $@ 51 | 52 | $(config_obj): $(config_src) 53 | @echo "Compiling source $(patsubst $(cur_dir)/%, %, $<)" 54 | @$(cc) $(CFLAGS) -c $< -o $@ 55 | 56 | $(config_asm): $(config_src) 57 | @$(cc) $(CPPFLAGS) -S $< -o $@ 58 | 59 | $(config_elf): $(config_ld) $(config_obj) 60 | @echo "Linking $(patsubst $(cur_dir)/%, %, $@)" 61 | @$(ld) $(LDFLAGS) -T$(config_ld) $(config_obj) -o $@ 62 | 63 | $(CONFIG_BIN): $(config_elf) 64 | @echo "Generating $(patsubst $(cur_dir)/%, %, $@)" 65 | @$(objcopy) -S -O binary $< $@ 66 | 67 | clean-config: 68 | @echo "Erasing config..." 69 | -rm -rf $(config_asm) 70 | -rm -rf $(config_obj) 71 | -rm -rf $(config_dep) 72 | -rm -rf $(CONFIG_BIN) 73 | -rm -rf $(config_elf) 74 | 75 | clean: clean-config 76 | 77 | .PHONY: clean clean-config 78 | -------------------------------------------------------------------------------- /src/arch/armv8/inc/arch/tlb.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __ARCH_TLB_H__ 17 | #define __ARCH_TLB_H__ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | static inline void tlb_hyp_inv_va(vaddr_t va) 24 | { 25 | asm volatile( 26 | "dsb ish\n\t" 27 | "tlbi vae2is, %0\n\t" 28 | "dsb ish\n\t" 29 | "isb\n\t" ::"r"(va >> 12)); 30 | } 31 | 32 | static inline void tlb_hyp_inv_all() 33 | { 34 | asm volatile( 35 | "dsb ish\n\t" 36 | "tlbi alle2is\n\t" 37 | "dsb ish\n\t" 38 | "isb\n\t"); 39 | } 40 | 41 | static inline void tlb_vm_inv_va(asid_t vmid, vaddr_t va) 42 | { 43 | uint64_t vttbr = 0; 44 | vttbr = MRS(VTTBR_EL2); 45 | bool switch_vmid = 46 | bit64_extract(vttbr, VTTBR_VMID_OFF, VTTBR_VMID_LEN) != vmid; 47 | 48 | if (switch_vmid) { 49 | MSR(VTTBR_EL2, ((vmid << VTTBR_VMID_OFF) & VTTBR_VMID_MSK)); 50 | DSB(ish); 51 | ISB(); 52 | } 53 | 54 | asm volatile("tlbi ipas2e1is, %0\n\t" ::"r"(va >> 12)); 55 | 56 | if (switch_vmid) { 57 | DSB(ish); 58 | MSR(VTTBR_EL2, ((vmid << VTTBR_VMID_OFF) & VTTBR_VMID_MSK)); 59 | } 60 | } 61 | 62 | static inline void tlb_vm_inv_all(asid_t vmid) 63 | { 64 | uint64_t vttbr = 0; 65 | vttbr = MRS(VTTBR_EL2); 66 | bool switch_vmid = 67 | bit64_extract(vttbr, VTTBR_VMID_OFF, VTTBR_VMID_LEN) != vmid; 68 | 69 | if (switch_vmid) { 70 | MSR(VTTBR_EL2, ((vmid << VTTBR_VMID_OFF) & VTTBR_VMID_MSK)); 71 | DSB(ish); 72 | ISB(); 73 | } 74 | 75 | asm volatile("tlbi vmalls12e1is\n\t"); 76 | 77 | if (switch_vmid) { 78 | DSB(ish); 79 | MSR(VTTBR_EL2, ((vmid << VTTBR_VMID_OFF) & VTTBR_VMID_MSK)); 80 | } 81 | 82 | /* TODO */ 83 | if (switch_vmid) { 84 | /* restore vttbr */ 85 | MSR(VTTBR_EL2, vttbr); 86 | DSB(ish); 87 | ISB(); 88 | } 89 | } 90 | 91 | #endif /* __ARCH_TLB_H__ */ 92 | -------------------------------------------------------------------------------- /src/core/init.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * Sandro Pinto 9 | * 10 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 11 | * terms of the GNU General Public License version 2 as published by the Free 12 | * Software Foundation, with a special exception exempting guest code from such 13 | * license. See the COPYING file in the top-level directory for details. 14 | * 15 | */ 16 | 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | void init(cpuid_t cpu_id, paddr_t load_addr, paddr_t config_addr) 28 | { 29 | /** 30 | * These initializations must be executed first and in fixed order. 31 | */ 32 | 33 | cpu_init(cpu_id, load_addr); 34 | mem_init(load_addr, config_addr); 35 | 36 | /* -------------------------------------------------------------- */ 37 | 38 | if (cpu.id == CPU_MASTER) { 39 | console_init(); 40 | printk("\n\r" 41 | " _____ _____ ____ _____ _____ _____ ____ _ _ \n\r" 42 | " / ____| __ \\ / __ \\ / ____/ ____|/ ____/ __ \\| \\ | |\n\r" 43 | " | | | |__) | | | | (___| (___ | | | | | | \\| |\n\r" 44 | " | | | _ /| | | |\\___ \\\\___ \\| | | | | | . ` |\n\r"); 45 | printk(" | |____| | \\ \\| |__| |____) |___) | |___| |__| | |\\ |\n\r" 46 | " \\_____|_| \\_\\\\____/|_____/_____/ \\_____\\____/|_| \\_|\n\r"); 47 | printk(" _ _ _\n\r" 48 | " | | | | (_) \n\r" 49 | " | |__| |_ _ _ __ ___ _ ____ ___ ___ ___ _ __ \n\r"); 50 | printk(" | __ | | | | '_ \\ / _ \\ '__\\ \\ / / / __|/ _ \\| '__| \n\r" 51 | " | | | | |_| | |_) | __/ | \\ V /| \\__ \\ (_) | | \n\r" 52 | " |_| |_|\\__, | .__/ \\___|_| \\_/ |_|___/\\___/|_| \n\r" 53 | " __/ | | \n\r" 54 | " |___/|_| \n\r" 55 | "\n\r"); 56 | } 57 | 58 | interrupts_init(); 59 | 60 | vmm_init(); 61 | 62 | /* Should never reach here */ 63 | while (1); 64 | } 65 | -------------------------------------------------------------------------------- /src/core/vmstack.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "list.h" 23 | 24 | void vmstack_push(struct vcpu* vcpu){ 25 | 26 | if(cpu.vcpu != NULL && vcpu->state != VCPU_INACTIVE){ 27 | return; 28 | } 29 | 30 | if(cpu.vcpu != NULL){ 31 | vcpu_save_state(cpu.vcpu); 32 | cpu.vcpu->state = VCPU_STACKED; 33 | list_push_front(&cpu.vcpu_stack, &cpu.vcpu->node); 34 | vcpu->parent = cpu.vcpu; 35 | } 36 | 37 | vcpu_restore_state(vcpu); 38 | vcpu->state = VCPU_ACTIVE; 39 | cpu.vcpu = vcpu; 40 | 41 | /* INFO("Current VM on pCPU %d is VM %d", cpu.id, cpu.vcpu->vm->id); */ 42 | } 43 | 44 | struct vcpu* vmstack_pop(){ 45 | 46 | /* TODO: our nodes do not allow the same vcpu to be in the stack more than 47 | * once */ 48 | struct vcpu* vcpu = (struct vcpu*) list_pop(&cpu.vcpu_stack); 49 | 50 | if(vcpu != NULL){ 51 | vcpu->parent = NULL; 52 | struct vcpu *temp = vcpu; 53 | vcpu = cpu.vcpu; 54 | cpu.vcpu = temp; 55 | vcpu_save_state(vcpu); 56 | vcpu->state = VCPU_INACTIVE; 57 | vcpu_restore_state(cpu.vcpu); 58 | cpu.vcpu->state = VCPU_ACTIVE; 59 | } 60 | 61 | /* INFO("Current VM on pCPU %d is VM %d", cpu.id, cpu.vcpu->vm->id); */ 62 | 63 | return vcpu; 64 | } 65 | 66 | void vmstack_unwind(struct vcpu* vcpu){ 67 | 68 | if(vcpu->state != VCPU_STACKED){ 69 | return; 70 | } 71 | 72 | struct vcpu* temp_vcpu = NULL; 73 | 74 | do { 75 | temp_vcpu = (struct vcpu*) list_pop(&cpu.vcpu_stack); 76 | temp_vcpu->state = VCPU_INACTIVE; 77 | temp_vcpu->parent = NULL; 78 | } while(temp_vcpu != vcpu); 79 | 80 | vcpu_save_state(cpu.vcpu); 81 | cpu.vcpu->state = VCPU_INACTIVE; 82 | cpu.vcpu = vcpu; 83 | vcpu_restore_state(cpu.vcpu); 84 | cpu.vcpu->state = VCPU_ACTIVE; 85 | 86 | /* INFO("Current VM on pCPU %d is VM %d", cpu.id, cpu.vcpu->vm->id); */ 87 | } 88 | -------------------------------------------------------------------------------- /src/core/inc/emul.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __EMUL_H__ 17 | #define __EMUL_H__ 18 | 19 | #include 20 | 21 | struct emul_access { 22 | vaddr_t addr; 23 | bool write; 24 | bool sign_ext; 25 | size_t width; 26 | unsigned long reg; 27 | size_t reg_width; 28 | }; 29 | 30 | typedef bool (*emul_handler_t)(struct emul_access*); 31 | 32 | struct emul_mem { 33 | vaddr_t va_base; 34 | size_t size; 35 | emul_handler_t handler; 36 | }; 37 | 38 | struct emul_reg { 39 | vaddr_t addr; 40 | emul_handler_t handler; 41 | }; 42 | 43 | bool emul_passthrough(struct emul_access*); 44 | 45 | static inline void emul_write(struct emul_access* emul, uint64_t val) 46 | { 47 | switch (emul->width) { 48 | case 1: 49 | *((uint8_t*)emul->addr) = val; 50 | break; 51 | case 2: 52 | *((uint16_t*)emul->addr) = val; 53 | break; 54 | case 4: 55 | *((uint32_t*)emul->addr) = val; 56 | break; 57 | case 8: 58 | *((uint64_t*)emul->addr) = val; 59 | break; 60 | default: 61 | ERROR("unknown emul write size"); 62 | } 63 | } 64 | 65 | static inline unsigned long emul_read(struct emul_access* emul) 66 | { 67 | unsigned long val = 0; 68 | 69 | switch (emul->width) { 70 | case 1: 71 | val = emul->sign_ext ? *((int8_t*)emul->addr) 72 | : *((uint8_t*)emul->addr); 73 | break; 74 | case 2: 75 | val = emul->sign_ext ? *((int16_t*)emul->addr) 76 | : *((uint16_t*)emul->addr); 77 | break; 78 | case 4: 79 | val = emul->sign_ext ? *((int32_t*)emul->addr) 80 | : *((uint32_t*)emul->addr); 81 | break; 82 | case 8: 83 | val = *((uint64_t*)emul->addr); 84 | break; 85 | default: 86 | ERROR("unknown emul read size"); 87 | } 88 | 89 | return val; 90 | } 91 | 92 | #endif /* __EMUL_H__ */ 93 | -------------------------------------------------------------------------------- /src/sdees/sdGPOS/arch/armv8/sdgpos.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "types.h" 5 | #include "vmm.h" 6 | #include "arch/sdgpos.h" 7 | 8 | #define SMCC64_BIT (0x40000000) 9 | 10 | #define SMCC_E_NOT_SUPPORTED (-1) 11 | #define SMCC32_FID_VND_HYP_SRVC (0x86000000) 12 | #define SMCC64_FID_VND_HYP_SRVC (SMCC32_FID_VND_HYP_SRVC | SMCC64_BIT) 13 | #define SMCC_FID_FN_NUM_MSK (0xFFFF) 14 | 15 | int64_t sdgpos_smc_handler(struct vcpu* vcpu, uint64_t smc_fid) 16 | { 17 | if(vcpu->vm->type != 0) 18 | return 0; 19 | int64_t ret = -HC_E_FAILURE; 20 | uint64_t x1 = vcpu->regs->x[1]; 21 | uint64_t x2 = vcpu->regs->x[2]; 22 | uint64_t x3 = vcpu->regs->x[3]; 23 | 24 | if (is_psci_fid(smc_fid)) { 25 | ret = psci_smc_handler(smc_fid, x1, x2, x3); 26 | vcpu_writereg(vcpu, 0, ret); 27 | } 28 | 29 | /* every smc call here increments pc */ 30 | uint64_t pc_step = 2 + (2 * 1); 31 | vcpu_writepc(vcpu, vcpu_readpc(vcpu) + pc_step); 32 | ret = 0; 33 | return ret; 34 | } 35 | 36 | int64_t sdgpos_hvc_handler(struct vcpu* vcpu, uint64_t smc_fid) 37 | { 38 | if(vcpu->vm->type != 0) 39 | return 0; 40 | 41 | unsigned long ret; 42 | unsigned long fid = vcpu_readreg(vcpu, 0); 43 | 44 | unsigned long ipc_id = vcpu_readreg(vcpu, HYPCALL_ARG_REG(1)); 45 | unsigned long arg1 = vcpu_readreg(vcpu, HYPCALL_ARG_REG(2)); 46 | unsigned long arg2 = vcpu_readreg(vcpu, HYPCALL_ARG_REG(3)); 47 | 48 | switch(fid & SMCC_FID_FN_NUM_MSK){ 49 | case HC_IPC: 50 | ret = ipc_hypercall(vcpu, ipc_id, arg1, arg2); 51 | vcpu_writereg(vcpu, 0, ret); 52 | break; 53 | default: 54 | /* WARNING("Unknown hypercall id %x", fid); */ 55 | ret = -1; 56 | } 57 | 58 | return ret; 59 | } 60 | 61 | static struct hndl_smc smc = { 62 | /* TODO: obtain this to decide whether to invoke handler early on */ 63 | .end = 0xffff0000, 64 | .start = 0x00000000, 65 | .handler = sdgpos_smc_handler, 66 | }; 67 | 68 | static struct hndl_hvc hvc = { 69 | /* TODO: obtain this to decide whether to invoke handler early on */ 70 | .handler = sdgpos_hvc_handler, 71 | }; 72 | 73 | 74 | bool sdgpos_arch_setup(struct vm *vm) 75 | { 76 | int64_t ret = 0; 77 | 78 | if(vm == NULL) 79 | return -1; 80 | 81 | /* TODO: check config structure or something to check if this VMs wants tz 82 | * to handle its events */ 83 | if(vm->type == 0){ 84 | vm_hndl_smc_add(vm, &smc); 85 | vm_hndl_hvc_add(vm, &hvc); 86 | } 87 | 88 | return ret; 89 | } 90 | -------------------------------------------------------------------------------- /src/arch/riscv/mem.c: -------------------------------------------------------------------------------- 1 | /** 2 | CROSSCONHyp Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | 18 | #include 19 | #include 20 | 21 | static inline void as_map_physical_identity(struct addr_space *as) { 22 | const size_t lvl = 0; 23 | size_t lvl_size = pt_lvlsize(&as->pt, lvl); 24 | paddr_t lvl_mask = ~((paddr_t)lvl_size - 1); 25 | pte_t *pt = as->pt.root; 26 | 27 | /** 28 | * Create identity mapping of existing physical memory regions using 29 | * the largest pages possible pte (in riscv this is always at level 0 30 | * pt). 31 | */ 32 | 33 | for (size_t i = 0; i < platform.region_num; i++) { 34 | struct mem_region *reg = &platform.regions[i]; 35 | paddr_t base = reg->base & lvl_mask; 36 | paddr_t top = (reg->base + reg->size) & lvl_mask; 37 | size_t num_entries = ((top - base - 1) / lvl_size) + 1; 38 | 39 | paddr_t addr = base; 40 | for (int j = 0; j < num_entries; j++) { 41 | int index = pt_getpteindex_by_va(&as->pt, (vaddr_t)addr, lvl); 42 | pte_set(&pt[index], addr, PTE_SUPERPAGE, PTE_HYP_FLAGS); 43 | addr += lvl_size; 44 | } 45 | } 46 | } 47 | 48 | void as_arch_init(struct addr_space *as) { 49 | 50 | if(as->type == AS_HYP) { 51 | as_map_physical_identity(as); 52 | } 53 | 54 | } 55 | 56 | bool mem_translate(struct addr_space *as, vaddr_t va, paddr_t *pa) 57 | { 58 | size_t pte_index = pt_getpteindex_by_va(&as->pt, va, 0); 59 | pte_t* pte = &(as->pt.root[pte_index]); 60 | size_t lvl = 0; 61 | for (size_t i = 0; i < as->pt.dscr->lvls; i++) { 62 | if (!pte_valid(pte) || !pte_table(&as->pt, pte, i)) { 63 | lvl = i; 64 | break; 65 | } 66 | pte = (pte_t*)pte_addr(pte); 67 | int index = pt_getpteindex_by_va(&as->pt, va, i+1); 68 | pte = &pte[index]; 69 | } 70 | if (pte && pte_valid(pte)) { 71 | *pa = pte_addr(pte); 72 | paddr_t mask = (1ULL << as->pt.dscr->lvl_off[lvl]) - 1; 73 | *pa = (*pa & ~mask) | ((paddr_t)va & mask); 74 | return true; 75 | } else { 76 | return false; 77 | } 78 | } 79 | 80 | void mem_guest_ipa_translate(void* va, uint64_t* physical_address) 81 | { 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/core/inc/page_table.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __PAGE_TABLE_H__ 17 | #define __PAGE_TABLE_H__ 18 | 19 | #include 20 | #include 21 | 22 | #ifndef __ASSEMBLER__ 23 | 24 | struct page_table_dscr { 25 | size_t lvls; 26 | size_t* lvl_off; 27 | size_t* lvl_wdt; 28 | bool* lvl_term; 29 | }; 30 | 31 | struct page_table { 32 | pte_t* root; 33 | pte_t root_flags; 34 | struct page_table_dscr* dscr; 35 | }; 36 | 37 | extern struct page_table_dscr* hyp_pt_dscr; 38 | extern struct page_table_dscr* vm_pt_dscr; 39 | 40 | static inline size_t pt_nentries(struct page_table* pt, size_t lvl) 41 | { 42 | return (1ULL << pt->dscr->lvl_wdt[lvl]) >> pt->dscr->lvl_off[lvl]; 43 | } 44 | 45 | static inline size_t pt_lvlsize(struct page_table* pt, size_t lvl) 46 | { 47 | return 1ULL << pt->dscr->lvl_off[lvl]; 48 | } 49 | 50 | static inline size_t pt_size(struct page_table* pt, size_t lvl) 51 | { 52 | return pt_nentries(pt, lvl) * sizeof(pte_t); 53 | } 54 | 55 | static inline size_t pt_getpteindex(struct page_table* pt, pte_t* pte, size_t lvl) 56 | { 57 | return (size_t)(((size_t)pte) & (pt_size(pt, lvl) - 1)) / sizeof(pte_t); 58 | } 59 | 60 | static inline size_t pt_getpteindex_by_va(struct page_table* pt, vaddr_t va, 61 | size_t lvl) 62 | { 63 | return (va >> pt->dscr->lvl_off[lvl]) & (pt_nentries(pt, lvl) - 1); 64 | } 65 | 66 | static inline bool pt_lvl_terminal(struct page_table* pt, size_t lvl) 67 | { 68 | return pt->dscr->lvl_term[lvl]; 69 | } 70 | 71 | /* Functions implemented in architecture dependent files */ 72 | 73 | pte_t* pt_get_pte(struct page_table* pt, size_t lvl, vaddr_t va); 74 | pte_t* pt_get(struct page_table* pt, size_t lvl, vaddr_t va); 75 | void pte_set(pte_t* pte, paddr_t addr, pte_type_t type, pte_flags_t flags); 76 | 77 | void pte_set_rsw(pte_t* pte, pte_t flag); 78 | bool pte_check_rsw(pte_t* pte, pte_t flag); 79 | 80 | bool pte_valid(pte_t* pte); 81 | bool pte_table(struct page_table* pt, pte_t* pte, size_t lvl); 82 | bool pte_page(struct page_table* pt, pte_t* pte, size_t lvl); 83 | pte_t pt_pte_type(struct page_table* pt, size_t lvl); 84 | 85 | #endif /* __ASSEMBLER__ */ 86 | 87 | #endif /* __PAGE_TABLE_H__ */ 88 | -------------------------------------------------------------------------------- /src/arch/riscv/page_table.c: -------------------------------------------------------------------------------- 1 | /** 2 | CROSSCONHyp Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | #if (SV32) 20 | struct page_table_dscr sv32_pt_dscr = {.lvls = 2, 21 | .lvl_wdt = (size_t[]){32, 22}, 22 | .lvl_off = (size_t[]){22, 12}, 23 | .lvl_term = (bool[]){true, true}}; 24 | struct page_table_dscr sv32x4_pt_dscr = {.lvls = 2, 25 | .lvl_wdt = (size_t[]){34, 22}, 26 | .lvl_off = (size_t[]){22, 12}, 27 | .lvl_term = (bool[]){true, true}}; 28 | struct page_table_dscr* hyp_pt_dscr = &sv32_pt_dscr; 29 | struct page_table_dscr* vm_pt_dscr = &sv32x2_pt_dscr; 30 | #elif (RV64) 31 | struct page_table_dscr sv39_pt_dscr = {.lvls = 3, 32 | .lvl_wdt = (size_t[]){39, 30, 21}, 33 | .lvl_off = (size_t[]){30, 21, 12}, 34 | .lvl_term = (bool[]){true, true, true}}; 35 | struct page_table_dscr sv39x4_pt_dscr = {.lvls = 3, 36 | .lvl_wdt = (size_t[]){41, 30, 21}, 37 | .lvl_off = (size_t[]){30, 21, 12}, 38 | .lvl_term = (bool[]){true, true, true}}; 39 | struct page_table_dscr* hyp_pt_dscr = &sv39_pt_dscr; 40 | struct page_table_dscr* vm_pt_dscr = &sv39x4_pt_dscr; 41 | #endif 42 | 43 | pte_t* pt_get_pte(struct page_table* pt, size_t lvl, vaddr_t va) 44 | { 45 | size_t pte_index = pt_getpteindex_by_va(pt, va, 0); 46 | pte_t* pte = &(pt->root[pte_index]); 47 | 48 | for (size_t i = 0; i < lvl; i++) { 49 | if (!pte_valid(pte)) return NULL; 50 | pte = (pte_t*)pte_addr(pte); 51 | size_t index = pt_getpteindex_by_va(pt, va, i + 1); 52 | pte = &pte[index]; 53 | } 54 | 55 | return pte; 56 | } 57 | 58 | pte_t* pt_get(struct page_table* pt, size_t lvl, vaddr_t va) 59 | { 60 | uintptr_t pte = (uintptr_t)pt_get_pte(pt, lvl, va); 61 | return (pte_t*)(pte & ~(pt_size(pt, lvl) - 1)); 62 | } 63 | 64 | bool pte_page(struct page_table* pt, pte_t* pte, size_t lvl) 65 | { 66 | return ((*pte & PTE_VALID) != 0) && ((*pte & PTE_RWX) != 0); 67 | } 68 | -------------------------------------------------------------------------------- /src/arch/armv8/inc/arch/vm.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __ARCH_VM_H__ 17 | #define __ARCH_VM_H__ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | struct vm_arch { 25 | struct vgicd vgicd; 26 | vaddr_t vgicr_addr; 27 | struct list vgic_spilled; 28 | spinlock_t vgic_spilled_lock; 29 | }; 30 | 31 | struct vcpu_arch { 32 | unsigned long vmpidr; 33 | struct vgic_priv vgic_priv; 34 | struct list vgic_spilled; 35 | struct psci_ctx psci_ctx; 36 | struct { 37 | 38 | struct { 39 | uint64_t elr_el2; 40 | uint64_t spsr_el2; 41 | uint64_t vttbr_el2; 42 | uint64_t vmpidr_el2; 43 | uint64_t cntvoff_el2; 44 | } hyp; 45 | 46 | struct { 47 | uint64_t vbar_el1; 48 | uint64_t tpidr_el1; 49 | uint64_t mair_el1; 50 | uint64_t amair_el1; 51 | uint64_t tcr_el1; 52 | uint64_t ttbr0_el1; 53 | uint64_t ttbr1_el1; 54 | uint64_t sp_el0; 55 | uint64_t sp_el1; 56 | uint64_t spsr_el1; 57 | uint64_t sctlr_el1; 58 | uint64_t actlr_el1; 59 | uint64_t par_el1; 60 | uint64_t far_el1; 61 | uint64_t esr_el1; 62 | uint64_t elr_el1; 63 | uint64_t afsr0_el1; 64 | uint64_t afsr1_el1; 65 | uint64_t tpidrro_el0; 66 | uint64_t tpidr_el0; 67 | uint64_t cntv_ctl_el0; 68 | uint64_t cntv_cval_el0; 69 | uint64_t cntkctl_el1; 70 | } vm; 71 | 72 | } sysregs; 73 | }; 74 | 75 | struct arch_regs { 76 | uint64_t x[31]; 77 | uint64_t elr_el2; 78 | uint64_t spsr_el2; 79 | } __attribute__((aligned(16))); // makes size always aligned to 16 to respect 80 | // stack alignment 81 | 82 | struct vcpu* vm_get_vcpu_by_mpidr(struct vm* vm, unsigned long mpidr); 83 | void vcpu_arch_entry(); 84 | 85 | 86 | static inline void vcpu_arch_inject_hw_irq(struct vcpu* vcpu, uint64_t id) 87 | { 88 | vgic_inject_hw(vcpu, id); 89 | } 90 | 91 | static inline void vcpu_arch_inject_irq(struct vcpu* vcpu, uint64_t id) 92 | { 93 | vgic_inject(vcpu, id, 0); 94 | } 95 | 96 | #endif /* __ARCH_VM_H__ */ 97 | -------------------------------------------------------------------------------- /src/arch/armv8/cpu.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * Gero Schwaericke 9 | * 10 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 11 | * terms of the GNU General Public License version 2 as published by the Free 12 | * Software Foundation, with a special exception exempting guest code from such 13 | * license. See the COPYING file in the top-level directory for details. 14 | * 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | cpuid_t CPU_MASTER __attribute__((section(".data"))); 24 | 25 | /* Perform architecture dependent cpu cores initializations */ 26 | void cpu_arch_init(cpuid_t cpuid, paddr_t load_addr) 27 | { 28 | cpu.arch.mpidr = MRS(MPIDR_EL1); 29 | if (cpuid == CPU_MASTER) { 30 | /* power on necessary, but still sleeping, secondary cpu cores 31 | * Assumes CPU zero is doing this */ 32 | for (size_t cpu_core_id = 0; cpu_core_id < platform.cpu_num; 33 | cpu_core_id++) { 34 | if(cpu_core_id == cpuid) continue; 35 | unsigned long mpdir = cpu_id_to_mpidr(cpu_core_id); 36 | // TODO: pass config addr in contextid (x0 register) 37 | int32_t result = psci_cpu_on(mpdir, load_addr, 0); 38 | if (!(result == PSCI_E_SUCCESS || result == PSCI_E_ALREADY_ON)) { 39 | ERROR("cant wake up cpu %d", cpu_core_id); 40 | } 41 | } 42 | } 43 | } 44 | 45 | unsigned long cpu_id_to_mpidr(cpuid_t id) 46 | { 47 | return platform_arch_cpuid_to_mpdir(&platform, id); 48 | } 49 | 50 | 51 | cpuid_t cpu_mpidr_to_id(unsigned long mpidr) 52 | { 53 | return platform_arch_mpidr_to_cpuid(&platform, mpidr); 54 | } 55 | 56 | 57 | void cpu_arch_idle() 58 | { 59 | int64_t err = psci_power_down(PSCI_WAKEUP_IDLE); 60 | if(err) { 61 | switch (err) { 62 | case PSCI_E_NOT_SUPPORTED: 63 | /** 64 | * If power down is not supported let's just wait for an interrupt 65 | */ 66 | asm volatile("wfi"); 67 | break; 68 | default: 69 | ERROR("PSCI cpu%d power down failed with error %ld", cpu.id, err); 70 | } 71 | } 72 | 73 | /** 74 | * Power down was sucessful but did not jump to requested entry 75 | * point. Manually rewind stack and jump to idle wake up. Therefore, 76 | * we should not return after this point. 77 | */ 78 | asm volatile( 79 | "mov sp, %0\n\r" 80 | "b cpu_idle_wakeup\n\r" 81 | ::"r"(&cpu.stack[STACK_SIZE])); 82 | 83 | ERROR("returned from idle wake up"); 84 | } 85 | -------------------------------------------------------------------------------- /src/lib/inc/bitmap.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #ifndef __BITMAP_H__ 17 | #define __BITMAP_H__ 18 | 19 | #include 20 | #include 21 | 22 | /* TODO: needs optimizations */ 23 | 24 | typedef uint32_t bitmap_granule_t; 25 | typedef bitmap_granule_t bitmap_t; 26 | 27 | static const bitmap_granule_t ONE = 1; 28 | 29 | #define BITMAP_GRANULE_LEN (sizeof(bitmap_granule_t) * 8) 30 | 31 | #define BITMAP_ALLOC(NAME, SIZE) \ 32 | bitmap_granule_t NAME[(SIZE / BITMAP_GRANULE_LEN) + \ 33 | (SIZE % BITMAP_GRANULE_LEN ? 1 : 0)] 34 | 35 | #define BITMAP_ALLOC_ARRAY(NAME, SIZE ,NUM) \ 36 | bitmap_granule_t NAME[NUM][(SIZE / BITMAP_GRANULE_LEN) + \ 37 | (SIZE % BITMAP_GRANULE_LEN ? 1 : 0)] 38 | 39 | 40 | static inline void bitmap_set(bitmap_t* map, size_t bit) 41 | { 42 | map[bit / BITMAP_GRANULE_LEN] |= ONE << (bit % BITMAP_GRANULE_LEN); 43 | } 44 | 45 | static inline void bitmap_clear(bitmap_t* map, size_t bit) 46 | { 47 | map[bit / BITMAP_GRANULE_LEN] &= ~(ONE << (bit % BITMAP_GRANULE_LEN)); 48 | } 49 | 50 | static inline unsigned bitmap_get(bitmap_t* map, size_t bit) 51 | { 52 | return (map[bit / BITMAP_GRANULE_LEN] & (ONE << (bit % BITMAP_GRANULE_LEN))) 53 | ? 1U 54 | : 0U; 55 | } 56 | 57 | static inline void bitmap_set_consecutive(bitmap_t* map, size_t start, size_t n) 58 | { 59 | for (size_t i = 0; i < n; i++) bitmap_set(map, start + i); 60 | } 61 | 62 | static inline void bitmap_clear_consecutive(bitmap_t* map, size_t start, 63 | size_t n) 64 | { 65 | for (size_t i = 0; i < n; i++) bitmap_clear(map, start + i); 66 | } 67 | 68 | static inline size_t bitmap_count(bitmap_t* map, size_t start, size_t n, 69 | bool set) 70 | { 71 | size_t count = 0; 72 | for (size_t i = start; i < n; i++) { 73 | if (bitmap_get(map, i) == set) count++; 74 | } 75 | 76 | return count; 77 | } 78 | 79 | ssize_t bitmap_find_nth(bitmap_t* map, size_t size, size_t nth, size_t start, 80 | bool set); 81 | 82 | size_t bitmap_count_consecutive(bitmap_t* map, size_t size, size_t start, 83 | size_t n); 84 | 85 | ssize_t bitmap_find_consec(bitmap_t* map, size_t size, size_t start, size_t n, 86 | bool set); 87 | 88 | #endif /* __BITMAP_H__ */ 89 | -------------------------------------------------------------------------------- /src/arch/armv8/relocate.S: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * Angelo Ruocco 9 | * 10 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 11 | * terms of the GNU General Public License version 2 as published by the Free 12 | * Software Foundation, with a special exception exempting guest code from such 13 | * license. See the COPYING file in the top-level directory for details. 14 | * 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | /** 23 | * Copy memory: 24 | * 25 | * x2: data 26 | * x3: data 27 | * x4: count 28 | * x5: size 29 | * x0: destination address 30 | * x7: source address 31 | */ 32 | memcpy: 33 | mov x4, #0 34 | 1: 35 | /* Copy two words */ 36 | ldp x2, x3, [x7] 37 | stp x2, x3, [x0] 38 | 39 | /* Increment addressess and count accordingly */ 40 | add x7, x7, 8 41 | add x0, x0, 8 42 | add x4, x4, 8 43 | 44 | /* If count is less then size, repeat */ 45 | cmp x4, x5 46 | b.le 1b 47 | 48 | /* Restore original addresses */ 49 | sub x7, x7, x4 50 | sub x0, x0, x4 51 | 52 | ret 53 | 54 | /** 55 | * Switch to a new address: 56 | * 57 | * x0: virtual address of new cpu space 58 | * x1: physical address of new cpu space 59 | */ 60 | .globl switch_space 61 | switch_space: 62 | 63 | /** 64 | * update flat maping page table entry to feature new physical address space 65 | * entry page 66 | */ 67 | adr x3, _image_start 68 | PTE_INDEX_ASM x4, x3, 1 69 | adr x5, root_l1_flat_pt 70 | add x3, x3, #(PTE_HYP_FLAGS | PTE_TABLE) 71 | str x3, [x5, x4] 72 | 73 | /** 74 | * Copy the stack 75 | */ 76 | 77 | /* Get current CPU space stack start */ 78 | ldr x7, =cpu 79 | add x7, x7, #(CPU_STACK_OFF + CPU_STACK_SIZE) 80 | 81 | /* Calculate stack size */ 82 | mov x8, sp 83 | sub x5, x7, x8 84 | 85 | /* Get current CPU space current sp */ 86 | mov x7, sp 87 | 88 | /* Get new CPU space current sp */ 89 | add x0, x0, #(CPU_STACK_OFF + CPU_STACK_SIZE) 90 | sub x0, x0, x5 91 | 92 | /* Copy */ 93 | mov x8, x30 94 | bl memcpy 95 | mov x30, x8 96 | 97 | /** 98 | * Invalidate TLB 99 | */ 100 | dsb ishst 101 | tlbi alle2 102 | dsb ish 103 | isb 104 | 105 | /** 106 | * Update TTBR 107 | */ 108 | 109 | /* Update value of TTBR0_EL2 */ 110 | msr TTBR0_EL2, x1 111 | dsb ish 112 | isb 113 | 114 | tlbi alle2 115 | dsb ish 116 | isb 117 | 118 | ret 119 | -------------------------------------------------------------------------------- /src/lib/string.c: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | 18 | void *memcpy(void *dst, const void *src, size_t count) 19 | { 20 | size_t i; 21 | uint8_t *dst_tmp = dst; 22 | const uint8_t *src_tmp = src; 23 | static const size_t WORD_SIZE = sizeof(unsigned long); 24 | 25 | if (!((uintptr_t)src & (WORD_SIZE - 1)) && 26 | !((uintptr_t)dst & (WORD_SIZE - 1))) { 27 | for (i = 0; i < count; i += WORD_SIZE) { 28 | if (i + (WORD_SIZE - 1) > count - 1) break; 29 | *(unsigned long *)dst_tmp = *(unsigned long *)src_tmp; 30 | dst_tmp += WORD_SIZE; 31 | src_tmp += WORD_SIZE; 32 | } 33 | if (i <= count - 1) { 34 | for (; i < count; i++) { 35 | *dst_tmp = *src_tmp; 36 | dst_tmp++; 37 | src_tmp++; 38 | } 39 | } 40 | } else { 41 | for (i = 0; i < count; i++) dst_tmp[i] = src_tmp[i]; 42 | } 43 | return dst; 44 | } 45 | 46 | void *memset(void *dest, int c, size_t count) 47 | { 48 | uint8_t *d; 49 | d = (uint8_t *)dest; 50 | 51 | while (count--) { 52 | *d = c; 53 | d++; 54 | } 55 | 56 | return dest; 57 | } 58 | 59 | char *strcat(char *dest, char *src) 60 | { 61 | char *save = dest; 62 | 63 | for (; *dest; ++dest); 64 | while ((*dest++ = *src++) != 0); 65 | 66 | return (save); 67 | } 68 | 69 | size_t strlen(const char *s) 70 | { 71 | const char *sc; 72 | for (sc = s; *sc != '\0'; ++sc) { 73 | /* Just iterate */ 74 | } 75 | return sc - s; 76 | } 77 | 78 | size_t strnlen(const char *s, size_t n) 79 | { 80 | const char *str; 81 | 82 | for (str = s; *str != '\0' && n--; ++str) { 83 | /* Just iterate */ 84 | } 85 | return str - s; 86 | } 87 | 88 | char *strcpy(char *dest, char *src) 89 | { 90 | char *tmp = dest; 91 | 92 | while ((*dest++ = *src++) != '\0') { 93 | /* Just iterate */ 94 | } 95 | return tmp; 96 | } 97 | 98 | int strcmp(char *str0, char *str1) 99 | { 100 | char *tmp0 = str0, *tmp1 = str1; 101 | 102 | while (*tmp0 == *tmp1 && ((*tmp0 != '\0') && (*tmp1 != '\0'))) { 103 | tmp0++; 104 | tmp1++; 105 | } 106 | 107 | return (int)(tmp0 - tmp1); 108 | } 109 | -------------------------------------------------------------------------------- /src/linker.ld: -------------------------------------------------------------------------------- 1 | /** 2 | * CROSSCONHyp, a Lightweight Static Partitioning Hypervisor 3 | * 4 | * Copyright (c) bao Project (www.bao-project.org), 2019- 5 | * 6 | * Authors: 7 | * Jose Martins 8 | * 9 | * CROSSCONHyp is free software; you can redistribute it and/or modify it under the 10 | * terms of the GNU General Public License version 2 as published by the Free 11 | * Software Foundation, with a special exception exempting guest code from such 12 | * license. See the COPYING file in the top-level directory for details. 13 | * 14 | */ 15 | 16 | #include 17 | 18 | ENTRY(_image_start) 19 | 20 | SECTIONS 21 | { 22 | 23 | . = CROSSCONHYP_VAS_BASE; 24 | 25 | _image_start = ABSOLUTE(.); 26 | 27 | .boot : { 28 | *(.boot) 29 | ASSERT((SIZEOF(.boot) <= PAGE_SIZE), 30 | "boot section must fit in one page"); 31 | } 32 | 33 | .text : { 34 | *(.text) 35 | } 36 | 37 | .rodata : { 38 | *(.rdata .rodata .rodata.*) 39 | } 40 | 41 | .data : { 42 | *(.data .data.*) 43 | PROVIDE(__global_pointer$ = . + 0x800); 44 | *(.sdata .sdata.* .sdata2.*) 45 | } 46 | 47 | .ipi_cpumsg_handlers : { 48 | _ipi_cpumsg_handlers_start = .; 49 | *(.ipi_cpumsg_handlers) 50 | } 51 | 52 | .ipi_cpumsg_handlers_id : { 53 | _ipi_cpumsg_handlers_id_start = .; 54 | *(.ipi_cpumsg_handlers_id) 55 | } 56 | 57 | _ipi_cpumsg_handlers_size = SIZEOF(.ipi_cpumsg_handlers); 58 | 59 | . = ALIGN(PAGE_SIZE); 60 | _image_load_end = .; 61 | 62 | /* Sections to be allocated only in physical memory, not in VA space */ 63 | 64 | .config : ALIGN(PAGE_SIZE) { 65 | _config_start = .; 66 | *(.config) 67 | } 68 | 69 | . = ALIGN(PAGE_SIZE); 70 | _config_end = .; 71 | _image_noload_start = .; 72 | extra_allocated_phys_mem = _image_noload_start - _image_load_end; 73 | 74 | /** 75 | * Rewind LC to reuse VMA addresses occupied by config and make VA 76 | * start immediately after image. 77 | * Also, force start address of next section to enforce this. 78 | */ 79 | . = _image_load_end; 80 | 81 | /* Only no load regions below */ 82 | 83 | .bss (NOLOAD) : { 84 | _bss_start = .; 85 | *(.bss* .sbss*) 86 | *(COMMON) 87 | _bss_end = .; 88 | } 89 | 90 | .glb_page_tables (NOLOAD) : ALIGN(PAGE_SIZE) { 91 | _page_tables_start = .; 92 | *(.glb_page_tables) 93 | _page_tables_end = .; 94 | } 95 | 96 | . = ALIGN(PAGE_SIZE); 97 | _image_end = ABSOLUTE(.); 98 | _dmem_phys_beg = ABSOLUTE(.) + extra_allocated_phys_mem; 99 | 100 | .devices _image_end (NOLOAD) : ALIGN(PAGE_SIZE) { 101 | *(.devices) 102 | } 103 | 104 | . = ALIGN(PAGE_SIZE); 105 | _dmem_beg = ABSOLUTE(.); 106 | _cpu_if_base = ABSOLUTE(.); 107 | 108 | /* Global dynamic memory virtual address space here */ 109 | 110 | . = CROSSCONHYP_CPU_BASE; 111 | _cpu_private_beg = ABSOLUTE(.); 112 | 113 | .cpu_private (NOLOAD) : ALIGN(PAGE_SIZE) { 114 | *(.cpu_private) 115 | } 116 | 117 | . = CROSSCONHYP_VM_BASE; 118 | _cpu_private_end = ABSOLUTE(.); 119 | _vm_beg = ABSOLUTE(.); 120 | 121 | . = CROSSCONHYP_VAS_TOP; 122 | _vm_end = ABSOLUTE(.); 123 | } 124 | --------------------------------------------------------------------------------