├── .gitignore ├── CONTRIBUTING ├── LICENSE ├── Makefile ├── README.md ├── VERSION ├── bin └── README ├── bootloader ├── zc702 │ └── BOOT.bin ├── zedboard │ └── BOOT.bin └── zybo │ └── BOOT.bin ├── documentation └── README └── src ├── arch └── armv7 │ ├── Cortex-A9 │ ├── inc │ │ └── platform_asm.h │ └── objects.mk │ ├── asm-offsets.c │ ├── cpu_cache.S │ ├── cpu_cp15_switch.S │ ├── cpu_entry.S │ ├── cpu_handlers.c │ ├── cpu_helper.c │ ├── cpu_monitor.S │ ├── cpu_stack.c │ ├── inc │ ├── asm-offsets.h │ ├── cpu_cp15_switch.h │ ├── cpu_defines.h │ ├── cpu_handlers.h │ ├── cpu_helper.h │ ├── cpu_stack.h │ ├── cpu_vcpu.h │ └── types.h │ └── objects.mk ├── boards ├── zc702 │ ├── board.c │ ├── inc │ │ ├── board.h │ │ ├── ltzvisor_hw.h │ │ ├── platform_zynq.h │ │ ├── zynq_ttc.h │ │ └── zynq_uart.h │ ├── linker.ld │ ├── ltzvisor_hw.c │ ├── objects.mk │ ├── zynq_ttc.c │ └── zynq_uart.c ├── zedboard │ ├── board.c │ ├── inc │ │ ├── board.h │ │ ├── ltzvisor_hw.h │ │ ├── platform_zynq.h │ │ ├── zynq_ttc.h │ │ └── zynq_uart.h │ ├── linker.ld │ ├── ltzvisor_hw.c │ ├── objects.mk │ ├── zynq_ttc.c │ └── zynq_uart.c └── zybo │ ├── board.c │ ├── inc │ ├── board.h │ ├── ltzvisor_hw.h │ ├── platform_zynq.h │ ├── zynq_ttc.h │ └── zynq_uart.h │ ├── linker.ld │ ├── ltzvisor_hw.c │ ├── objects.mk │ ├── zynq_ttc.c │ └── zynq_uart.c ├── core ├── inc │ ├── ltzvisor.h │ ├── ltzvisor_api.h │ └── ltzvisor_syscall_asm.h ├── ltzvisor.c ├── ltzvisor_api.c └── objects.mk ├── drivers ├── common │ ├── gic.c │ ├── inc │ │ └── gic.h │ └── objects.mk ├── gic.c ├── inc │ └── gic.h ├── objects.mk └── zynq │ ├── board.c │ ├── inc │ ├── board.h │ ├── ltzvisor_hw.h │ ├── platform_zynq.h │ ├── xilinx_uart.h │ └── zynq_ttc.h │ ├── linker.ld │ ├── ltzvisor_hw.c │ ├── objects.mk │ ├── xilinx_uart.c │ └── zynq_ttc.c ├── lib ├── inc │ ├── io.h │ ├── math.h │ ├── printk.h │ └── string.h ├── io.c ├── objects.mk ├── printk.c └── string.c ├── makefile ├── ns_guest ├── inc │ └── ltzvisor_nsguest_config.h ├── ltzvisor_nsguest.S ├── ltzvisor_nsguest_config.c ├── objects.mk └── zynq │ ├── README │ └── baremetal.bin └── s_guest ├── BareApp ├── blink.c ├── objects.mk └── portable │ ├── hw_zynq.c │ ├── inc │ ├── hw_zynq.h │ └── s_isr.h │ ├── objects.mk │ ├── s_handlers.S │ └── s_isr.c └── README /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | bin/* 3 | -------------------------------------------------------------------------------- /CONTRIBUTING: -------------------------------------------------------------------------------- 1 | CONTRIBUTING TO LTZVISOR 2 | ------------------------------------------------------------------------ 3 | 4 | Contributions to the LTZVisor are always welcome; however, contributions 5 | to the LTZVisor will require to sign a contribution agreement, which 6 | states the exact rights TZVisor project (trademark of Sandro Pinto) 7 | receives from contributors planning to submit code to the LTZVisor. 8 | 9 | In this way, it will be possible to redistribute all contributions 10 | under the open source license, while enabling the participation of 11 | commercial users in the TZVisor project development. We strongly 12 | believe this strategy will result in a stronger commitment and 13 | diffusion of LTZVisor in the embedded systems industry. 14 | 15 | Details of the contribution agreement will be disclosed in a few weeks. 16 | Contributors are invited to kindly postpone their contributions till 17 | the contribution agreement is set. 18 | 19 | If you have any further questions, please do not hesitate to contact us 20 | by dropping an email to info@tzvisor.org. 21 | 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | HYPERVISOR_PRODUCT = LTZVisor 2 | HYPERVISOR_MAJOR_VERSION = 0 3 | HYPERVISOR_MINOR_VERSION = 2 4 | HYPERVISOR_REVISION_VERSION = 1 5 | 6 | export BOARD:= ZEDBOARD 7 | export S_GUEST:= BARE_METAL 8 | export NS_GUEST:= BARE_METAL 9 | export CROSS_COMPILE:= arm-none-eabi- 10 | 11 | export SDK_PATH = $(CURDIR) 12 | 13 | #export CROSS_COMPILE = /opt/CodeSourcery/arm-xilinx-gnueabi/bin/arm-xilinx-eabi- 14 | export CROSS_COMPILE = /opt/Linaro/gcc-linaro-7.1.1-2017.08-x86_64_arm-eabi/bin/arm-eabi- 15 | 16 | all: 17 | echo 'LTZVisor builds start' 18 | $(MAKE) -C $(SDK_PATH)/src 19 | 20 | clean: 21 | $(MAKE) -C $(SDK_PATH)/src clean 22 | 23 | sudo rm -f bin/*.bin bin/*.elf 24 | sudo rm -f $(VERSION_FILE) 25 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | LTZVisor_version = 0.2.2 2 | -------------------------------------------------------------------------------- /bin/README: -------------------------------------------------------------------------------- 1 | Binary will be created here! 2 | -------------------------------------------------------------------------------- /bootloader/zc702/BOOT.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tzvisor/ltzvisor/f5b55394e3f3602a5c8c9ffce2563bf89b1b7c29/bootloader/zc702/BOOT.bin -------------------------------------------------------------------------------- /bootloader/zedboard/BOOT.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tzvisor/ltzvisor/f5b55394e3f3602a5c8c9ffce2563bf89b1b7c29/bootloader/zedboard/BOOT.bin -------------------------------------------------------------------------------- /bootloader/zybo/BOOT.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tzvisor/ltzvisor/f5b55394e3f3602a5c8c9ffce2563bf89b1b7c29/bootloader/zybo/BOOT.bin -------------------------------------------------------------------------------- /documentation/README: -------------------------------------------------------------------------------- 1 | Documentation will be placed here! 2 | -------------------------------------------------------------------------------- /src/arch/armv7/Cortex-A9/inc/platform_asm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [platform_asm.h] 42 | * 43 | * This file contains CortexA9-specific register definitions. 44 | * 45 | * (#) $id: platform_asm.h 01-01-2015 s_pinto & j_pereira $ 46 | */ 47 | 48 | #ifndef __PLATFORM_ASM 49 | #define __PLATFORM_ASM 50 | 51 | #define NSACR_REG_VAL 0x60C00 52 | #define CPACR_REG_VAL 0xF00000 53 | 54 | #define CACHE_LEVEL1_SET 1 55 | #define CACHE_LEVEL2_SET 0 56 | 57 | /* 58 | * LEVEL 1 Configuration 59 | * 32KB, NumSets = 256, Ways=4, 60 | * Line Size = 5 (log2 line_len) and Line len = 32 bytes 61 | */ 62 | #define MAX_L1_CACHE_WAYS 3 /* Ways -1 */ 63 | #define MAX_L1_SETS 255 /* NumSets -1 */ 64 | #define MAX_L1_LINE_LEN 5 65 | 66 | #define MAX_L2_CACHE_WAYS 0 /* Ways -1 */ 67 | #define MAX_L2_SETS 0 /* NumSets -1 */ 68 | #define MAX_L2_LINE_LEN 0 69 | 70 | #endif /* __PLATFORM_ASM */ 71 | -------------------------------------------------------------------------------- /src/arch/armv7/Cortex-A9/objects.mk: -------------------------------------------------------------------------------- 1 | #cpu-platform-objs-y += private_timer.o 2 | -------------------------------------------------------------------------------- /src/arch/armv7/asm-offsets.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [asm_offsets.c] 42 | * 43 | * This file contains code for generating asm_offsets.h. 44 | * 45 | * (#) $id: asm_offsets.c 03-05-2015 j_pereira $ 46 | */ 47 | 48 | 49 | #include 50 | #include 51 | #include 52 | 53 | #define pos(a, b) ((size_t) &((a*)0)->b) 54 | #define GEN_SYM(name, value) \ 55 | asm volatile("\n->" #name " %0 " #value : : "j" (value)) 56 | 57 | int main(void) 58 | { 59 | 60 | GEN_SYM(_ASM_CP_SCTLR_OFFSET, pos(tzmachine, core.vcpu_regs_cp15.c1_SCTLR)); 61 | GEN_SYM(_ASM_MON_SPSR_OFFSET, pos(tzmachine, core.vcpu_regs_core.spsr_mon)); 62 | GEN_SYM(_ASM_MON_LR_OFFSET, pos(tzmachine, core.vcpu_regs_core.lr_mon)); 63 | GEN_SYM(_ASM_R4_OFFSET, pos(tzmachine, core.vcpu_regs_core.r4)); 64 | GEN_SYM(_ASM_SP_OFFSET, pos(tzmachine, core.vcpu_regs_core.r13_sys)); 65 | 66 | GEN_SYM(_ASM_ARCH_REGS_OFFSET, pos(tzmachine, core.vcpu_regs_core)); 67 | 68 | GEN_SYM(_ASM_GIC_INT_ID, pos(Cpu_Interface, ICCIAR)); 69 | 70 | return 0; 71 | } 72 | 73 | -------------------------------------------------------------------------------- /src/arch/armv7/cpu_cache.S: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [cpu_cache.S] 42 | * 43 | * This file contains the ARMv7-A cache driver. 44 | * 45 | * (#) $id: cpu_cache.S 04-05-2015 s_pinto & j_pereira $ 46 | */ 47 | 48 | #include 49 | #include 50 | 51 | /** 52 | * L1 (I/D)-cache enable 53 | * 54 | * @param 55 | * 56 | * @retval 57 | */ 58 | .global enable_l1_cache 59 | .func enable_l1_cache 60 | enable_l1_cache: 61 | @ void enable_l1_cache(void) 62 | push {r0-r12, lr} 63 | mrc p15, 0, r0, c1, c0, 0 64 | orr r1, r1, #SCTLR_ICACHE_BIT 65 | orr r1, r1, #SCTLR_DCACHE_BIT 66 | mcr p15, 0, r1, c1, c0, 0 67 | isb 68 | pop {r0-r12, lr} 69 | bx lr 70 | .endfunc 71 | 72 | /** 73 | * L1 I-cache invalidate all entries 74 | * 75 | * @param 76 | * 77 | * @retval 78 | */ 79 | .global icache_inv_all 80 | .func icache_inv_all 81 | @ void icache_inv_all(void); 82 | icache_inv_all: 83 | @ void icache_inv_all(void) 84 | push {r0-r12, lr} 85 | mov r0, #0 86 | mcr p15, 0, r0, c7, c5, 0 87 | isb 88 | pop {r0-r12, lr} 89 | bx lr 90 | .endfunc 91 | 92 | /** 93 | * D-Cache clean/invalidate way (auxiliar) 94 | * 95 | * @param r0 - Cache level 96 | * r1 - Log2 Line Length 97 | * r2 - Way 98 | * r3 - LEADING ZEROS of WAY 99 | * r4 - Set 100 | * r5 - clean or invalidate 101 | * 102 | * @retval 103 | */ 104 | data_cache_clean_invalidate_set_way: 105 | mov r9, r2 106 | 2: 107 | /* 108 | val = (cache level << 1) | (set << log2 LINE_LEN) | (way << LEADING_ZEROS_OF WAY) 109 | */ 110 | orr r11, r0, r9, lsl r3 111 | orr r11, r11, r4, lsl r1 112 | cmp r5, #1 113 | mcreq p15, 0, r11, c7, c6, 2 114 | mcrne p15, 0, r11, c7, c14, 2 115 | subs r9, r9, #1 116 | bge 2b 117 | subs r4, r4, #1 118 | bge data_cache_clean_invalidate_set_way 119 | bx lr 120 | 121 | /** 122 | * D-Cache clean/invalidate all entries 123 | * 124 | * @param r0 - Clean or Invalidate 125 | * 126 | * @retval 127 | */ 128 | .global data_cache_clean_invalidate_all 129 | .func data_cache_clean_invalidate_all 130 | @ void data_cache_clean_invalidate_all(int invalid_only); 131 | data_cache_clean_invalidate_all: 132 | push {r0-r12, lr} 133 | dmb 134 | mov r5, r0 135 | ldr r0, =CACHE_LEVEL1_SET 136 | cmp r0, #1 137 | bne 1f 138 | /* Level 1 */ 139 | mov r0, #0 140 | mcr p15, 2, r0, c0, c0, 0 141 | isb 142 | ldr r1, =MAX_L1_LINE_LEN 143 | ldr r2, =MAX_L1_CACHE_WAYS 144 | clz r3, r2 145 | ldr r4, =MAX_L1_SETS 146 | bl data_cache_clean_invalidate_set_way 147 | /* Level 2 */ 148 | ldr r0, =CACHE_LEVEL2_SET 149 | cmp r0, #1 150 | bne 1f 151 | mov r0, #2 152 | mcr p15, 2, r0, c0, c0, 0 153 | isb 154 | ldr r1, =MAX_L2_LINE_LEN 155 | ldr r2, =MAX_L2_CACHE_WAYS 156 | clz r3, r2 157 | ldr r4, =MAX_L2_SETS 158 | bl data_cache_clean_invalidate_set_way 159 | 1: 160 | mov r0, #0 161 | mcr p15, 2, r10, c0, c0, 0 162 | dsb 163 | isb 164 | pop {r0-r12, lr} 165 | bx lr 166 | .endfunc 167 | 168 | /** 169 | * TLB flush all entries 170 | * 171 | * @param 172 | * 173 | * @retval 174 | */ 175 | .global flush_all_translation_table_entries 176 | .func flush_all_translation_table_entries 177 | @ void flush_all_translation_table_entries(void); 178 | flush_all_translation_table_entries: 179 | mcr p15, 0, r0, c8, c3, 0 180 | mcr p15, 0, r0, c7, c5, 6 @ Inval. branch predict. array 181 | dsb 182 | isb 183 | mov pc, lr 184 | .endfunc 185 | 186 | /** 187 | * TLB invalidate by VA_ASID 188 | * 189 | * @param 190 | * 191 | * @retval 192 | */ 193 | .global inv_translation_table_by_va_asid 194 | .func inv_translation_table_by_va_asid 195 | @ void inv_translation_table_by_va_asid(sw_uint va); 196 | inv_translation_table_by_va_asid: 197 | mcr p15, 0, r0, c8, c3, 1 198 | mcr p15, 0, r0, c7, c5, 6 @ Inval. branch predict. array 199 | dsb 200 | isb 201 | mov pc, lr 202 | .endfunc 203 | 204 | /** 205 | * TLB invalidate by ASID 206 | * 207 | * @param 208 | * 209 | * @retval 210 | */ 211 | .global inv_translation_table_by_asid 212 | .func inv_translation_table_by_asid 213 | @ void inv_translation_table_by_asid(sw_uint asid); 214 | inv_translation_table_by_asid: 215 | mcr p15, 0, r0, c8, c3, 2 216 | mcr p15, 0, r0, c7, c5, 6 @ Inval. branch predict. array 217 | dsb 218 | isb 219 | mov pc, lr 220 | .endfunc 221 | 222 | /** 223 | * (I/D)-cache flush 224 | * 225 | * @param 226 | * 227 | * @retval 228 | */ 229 | .global flush_icache_and_dcache 230 | .func flush_icache_and_dcache 231 | @ void flush_icache_and_dcache(void); 232 | flush_icache_and_dcache: 233 | push {r0-r12, lr} 234 | mov r0, #0 235 | bl data_cache_clean_invalidate_all 236 | mov r0, #0 237 | /* Invalidate instruction cache */ 238 | mcr p15, 0, r0, c7, c5, 0 239 | dsb 240 | isb 241 | pop {r0-r12, lr} 242 | mov pc, lr 243 | .endfunc 244 | -------------------------------------------------------------------------------- /src/arch/armv7/cpu_cp15_switch.S: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [cpu_cp15_switch.S] 42 | * 43 | * This file contains the CP15 coprocessor context-switch code. 44 | * 45 | * (#) $id: cpu_cp15_switch.S 04-05-2015 s_pinto & j_pereira $ 46 | */ 47 | 48 | 49 | /** 50 | * SCR_NS_Bit set (macro) 51 | */ 52 | .macro scr_nsbit_set rt 53 | mrc p15, 0, \rt, c1, c1, 0 @ Read Secure Configuration Register 54 | orr \rt, \rt, #1 55 | mcr p15, 0, \rt, c1, c1, 0 @ Write Secure Configuration Register 56 | .endm 57 | 58 | /** 59 | * SCR_NS_Bit clear (macro) 60 | */ 61 | .macro scr_nsbit_clear rt 62 | mrc p15, 0, \rt, c1, c1, 0 @ Read Secure Configuration Register 63 | bic \rt, \rt, #1 64 | mcr p15, 0, \rt, c1, c1, 0 @ Write Secure Configuration Register 65 | .endm 66 | 67 | /** 68 | * CP15 save context (macro) 69 | * 70 | * @param r0 - cp15 context pointer 71 | * 72 | * @retval 73 | */ 74 | .macro save_cp15_context 75 | mrc p15, 2, r2, c0, c0, 0 /* CSSELR */ 76 | str r2, [r0], #4 77 | mrc p15, 0, r2, c1, c0, 0 /* SCTLR */ 78 | str r2, [r0], #4 79 | mrc p15, 0, r2, c1, c0, 1 /* ACTLR */ 80 | str r2, [r0], #4 81 | mrc p15, 0, r2, c2, c0, 0 /* TTBR0 */ 82 | str r2, [r0], #4 83 | mrc p15, 0, r2, c2, c0, 1 /* TTBR1 */ 84 | str r2, [r0], #4 85 | mrc p15, 0, r2, c2, c0, 2 /* TTBCR */ 86 | str r2, [r0], #4 87 | mrc p15, 0, r2, c3, c0, 0 /* DACR */ 88 | str r2, [r0], #4 89 | mrc p15, 0, r2, c5, c0, 0 /* DFSR */ 90 | str r2, [r0], #4 91 | mrc p15, 0, r2, c5, c0, 1 /* IFSR */ 92 | str r2, [r0], #4 93 | mrc p15, 0, r2, c6, c0, 0 /* DFAR */ 94 | str r2, [r0], #4 95 | mrc p15, 0, r2, c6, c0, 2 /* IFAR */ 96 | str r2, [r0], #4 97 | mrc p15, 0, r2, c7, c4, 0 /* PAR */ 98 | str r2, [r0], #4 99 | mrc p15, 0, r2, c10, c2, 0 /* PRRR */ 100 | str r2, [r0], #4 101 | mrc p15, 0, r2, c10, c2, 1 /* NMRR */ 102 | str r2, [r0], #4 103 | mrc p15, 0, r2, c12, c0, 0 /* VBAR */ 104 | str r2, [r0], #4 105 | mrc p15, 0, r2, c13, c0, 0 /* FCSEIDR */ 106 | str r2, [r0], #4 107 | mrc p15, 0, r2, c13, c0, 1 /* CONTEXTIDR */ 108 | str r2, [r0], #4 109 | mrc p15, 0, r2, c13, c0, 2 /* TPIDRURW */ 110 | str r2, [r0], #4 111 | mrc p15, 0, r2, c13, c0, 3 /* TPIDRURO */ 112 | str r2, [r0], #4 113 | mrc p15, 0, r2, c13, c0, 4 /* TPIDRPRW */ 114 | str r2, [r0], #4 115 | .endm 116 | 117 | /** 118 | * CP15 restore context (macro) 119 | * 120 | * @param r0 - cp15 context pointer 121 | * 122 | * @retval 123 | */ 124 | .macro restore_cp15_context 125 | ldr r2, [r0], #4 126 | mcr p15, 2, r2, c0, c0, 0 /* CSSELR */ 127 | ldr r2, [r0], #4 128 | mcr p15, 0, r2, c1, c0, 0 /* SCTLR */ 129 | ldr r2, [r0], #4 130 | mcr p15, 0, r2, c1, c0, 1 /* ACTLR */ 131 | ldr r2, [r0], #4 132 | mcr p15, 0, r2, c2, c0, 0 /* TTBR0 */ 133 | ldr r2, [r0], #4 134 | mcr p15, 0, r2, c2, c0, 1 /* TTBR1 */ 135 | ldr r2, [r0], #4 136 | mcr p15, 0, r2, c2, c0, 2 /* TTBCR */ 137 | ldr r2, [r0], #4 138 | mcr p15, 0, r2, c3, c0, 0 /* DACR */ 139 | ldr r2, [r0], #4 140 | mcr p15, 0, r2, c5, c0, 0 /* DFSR */ 141 | ldr r2, [r0], #4 142 | mcr p15, 0, r2, c5, c0, 1 /* IFSR */ 143 | ldr r2, [r0], #4 144 | mcr p15, 0, r2, c6, c0, 0 /* DFAR */ 145 | ldr r2, [r0], #4 146 | mcr p15, 0, r2, c6, c0, 2 /* IFAR */ 147 | ldr r2, [r0], #4 148 | mcr p15, 0, r2, c7, c4, 0 /* PAR */ 149 | ldr r2, [r0], #4 150 | mcr p15, 0, r2, c10, c2, 0 /* PRRR */ 151 | ldr r2, [r0], #4 152 | mcr p15, 0, r2, c10, c2, 1 /* NMRR */ 153 | ldr r2, [r0], #4 154 | mcr p15, 0, r2, c12, c0, 0 /* VBAR */ 155 | ldr r2, [r0], #4 156 | mcr p15, 0, r2, c13, c0, 0 /* FCSEIDR */ 157 | ldr r2, [r0], #4 158 | mcr p15, 0, r2, c13, c0, 1 /* CONTEXTIDR */ 159 | ldr r2, [r0], #4 160 | mcr p15, 0, r2, c13, c0, 2 /* TPIDRURW */ 161 | ldr r2, [r0], #4 162 | mcr p15, 0, r2, c13, c0, 3 /* TPIDRURO */ 163 | ldr r2, [r0], #4 164 | mcr p15, 0, r2, c13, c0, 4 /* TPIDRPRW */ 165 | .endm 166 | 167 | /** 168 | * CP15 restore context 169 | * 170 | * @param r0 - cp15 context pointer 171 | * 172 | * @retval 173 | */ 174 | .global cp15_restore 175 | .func cp15_restore 176 | @ void cp15_restore(struct cp15_regs * p_cp15_context); 177 | cp15_restore: 178 | @ Move to NS 179 | scr_nsbit_set r2 180 | @ restore c15 context 181 | restore_cp15_context 182 | @ Move back to secure 183 | scr_nsbit_clear r2 184 | bx lr 185 | .endfunc 186 | -------------------------------------------------------------------------------- /src/arch/armv7/cpu_handlers.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [cpu_handlers.c] 42 | * 43 | * This file contains monitor exception handling related code. 44 | * 45 | * (#) $id: cpu_handlers.c 04-05-2015 s_pinto & j_pereira $ 46 | * (#) $id: cpu_handlers.c 16-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #include 50 | 51 | 52 | 53 | /** 54 | * Monitor SWI exception handling 55 | * 56 | * @param 57 | * 58 | * @retval 59 | */ 60 | void mon_swi_handler(void){ 61 | 62 | printk("LTZVisor: SWI Exception\n\r"); 63 | /* FIXME */ 64 | while(1); 65 | } 66 | 67 | /** 68 | * Monitor ABORT exception handling 69 | * 70 | * @param 71 | * 72 | * @retval 73 | */ 74 | void mon_abort_handler(void){ 75 | 76 | printk("LTZVisor: ABORT Exception\n\r"); 77 | /* FIXME */ 78 | while(1); 79 | } 80 | 81 | /** 82 | * Monitor IRQ exception handling 83 | * 84 | * @param 85 | * 86 | * @retval 87 | */ 88 | void mon_irq_handler(void){ 89 | 90 | /** By design it is not supposed to come here */ 91 | printk("LTZVisor: IRQ Exception\n\r"); 92 | /* FIXME */ 93 | while(1); 94 | } 95 | 96 | /** 97 | * Monitor PREFETCH exception handling 98 | * 99 | * @param 100 | * 101 | * @retval 102 | */ 103 | void mon_prefetch_handler(void){ 104 | 105 | printk("LTZVisor: PREFETCH Exception\n\r"); 106 | /* FIXME */ 107 | while(1); 108 | } 109 | -------------------------------------------------------------------------------- /src/arch/armv7/cpu_helper.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [cpu_helper.c] 42 | * 43 | * This file contains ARMv7-specific miscelaneous operations. 44 | * 45 | * (#) $id: cpu_helper.c 03-05-2015 s_pinto & j_pereira $ 46 | * (#) $id: cpu_helper.c 18-09-2017 s_pinto (modified) $ 47 | */ 48 | 49 | #include 50 | 51 | /** 52 | * Set the NS guest context pointer (optimization) 53 | * 54 | * @param addr = context pointer address 55 | * 56 | * @retval 57 | */ 58 | void set_guest_context(uint32_t addr) { 59 | /** Software Thread ID - TPIDRPRW */ 60 | asm volatile("mcr p15, 0, r0, c13, c0, 4\n\t"); 61 | } 62 | 63 | -------------------------------------------------------------------------------- /src/arch/armv7/cpu_stack.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [cpu_stack.c] 42 | * 43 | * This file contains stack allocation for all processor modes. 44 | * 45 | * (#) $id: cpu_stack.c 10-05-2015 s_pinto & j_pereira $ 46 | * (#) $id: cpu_stack.c 19-09-2017 s_pinto (modified) $ 47 | */ 48 | 49 | #include 50 | 51 | /** IRQ stack allocation (4-bit alligned) */ 52 | uint32_t _irq_stack[STACK_SIZE/4] __attribute__ ((aligned (4))) __attribute__ ((section (".bss"))); 53 | 54 | /** FIQ stack allocation (4-bit alligned) */ 55 | uint32_t _fiq_stack[STACK_SIZE/4] __attribute__ ((aligned (4))) __attribute__ ((section (".bss"))); 56 | 57 | /** ABORT stack allocation (4-bit alligned) */ 58 | uint32_t _abort_stack[STACK_SIZE/4] __attribute__ ((aligned (4))) __attribute__ ((section (".bss"))); 59 | 60 | /** UNDEF stack allocation (4-bit alligned) */ 61 | uint32_t _undefined_stack[STACK_SIZE/4] __attribute__ ((aligned (4))) __attribute__ ((section (".bss"))); 62 | 63 | /** SYS stack allocation (4-bit alligned) */ 64 | uint32_t _user_stack[(STACK_SIZE)/4] __attribute__ ((aligned (4))) __attribute__ ((section (".bss"))); 65 | 66 | /** MON stack allocation (4-bit alligned) */ 67 | uint32_t _monitor_stack[STACK_SIZE/4] __attribute__ ((aligned (4))) __attribute__ ((section (".bss"))); 68 | 69 | /** SVC stack allocation (4-bit alligned) */ 70 | uint32_t _supervisor_stack[STACK_SIZE/4] __attribute__ ((aligned (4))) __attribute__ ((section (".bss"))); 71 | 72 | -------------------------------------------------------------------------------- /src/arch/armv7/inc/asm-offsets.h: -------------------------------------------------------------------------------- 1 | /* THIS FILE WAS GENERATED AUTOMATICALLY */ 2 | #define _ASM_CP_SCTLR_OFFSET 124 /* pos(tzmachine, core.vcpu_regs_cp15.c1_SCTLR) */ 3 | #define _ASM_MON_SPSR_OFFSET 52 /* pos(tzmachine, core.vcpu_regs_core.spsr_mon) */ 4 | #define _ASM_MON_LR_OFFSET 56 /* pos(tzmachine, core.vcpu_regs_core.lr_mon) */ 5 | #define _ASM_R4_OFFSET 16 /* pos(tzmachine, core.vcpu_regs_core.r4) */ 6 | #define _ASM_SP_OFFSET 76 /* pos(tzmachine, core.vcpu_regs_core.r13_sys) */ 7 | #define _ASM_ARCH_REGS_OFFSET 0 /* pos(tzmachine, core.vcpu_regs_core) */ 8 | #define _ASM_GIC_INT_ID 12 /* pos(Cpu_Interface, ICCIAR) */ 9 | -------------------------------------------------------------------------------- /src/arch/armv7/inc/cpu_cp15_switch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [cpu_cp15_switch.h] 42 | * 43 | * This file contains the CP15 coprocessor context-switch code (header). 44 | * 45 | * (#) $id: cpu_cp15_switch.h 07-10-2017 s_pinto $ 46 | */ 47 | 48 | #ifndef __CPU_CP15_H 49 | #define __CPU_CP15_H 50 | 51 | #include 52 | 53 | void cp15_restore(struct cp15_regs * p_cp15_context); 54 | 55 | #endif /* __CPU_CP15_H */ 56 | 57 | 58 | -------------------------------------------------------------------------------- /src/arch/armv7/inc/cpu_defines.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [cpu_defines.h] 42 | * 43 | * This file contains ARMv7-specific register definitions. 44 | * 45 | * (#) $id: cpu_defines.h 03-05-2015 s_pinto & j_pereira $ 46 | */ 47 | 48 | #ifndef __ARMV7_CPU_DEFINES_H__ 49 | #define __ARMV7_CPU_DEFINES_H__ 50 | 51 | /** CPU Operation Modes */ 52 | #define USER_MODE 0x10 53 | #define FIQ_MODE 0x11 54 | #define IRQ_MODE 0x12 55 | #define SUPERVISOR_MODE 0x13 56 | #define MONITOR_MODE 0x16 57 | #define ABORT_MODE 0x17 58 | #define HYPERVISOR_MODE 0x1A // Not Used 59 | #define UNDEFINED_MODE 0x1B 60 | #define SYSTEM_MODE 0x1F 61 | 62 | /** CPSR FIQ & IRQ Bits*/ 63 | #define FIQ_BIT 0x40 64 | #define IRQ_BIT 0x80 65 | 66 | #define STACK_SIZE 8192 67 | #define STACK_SIZE_SHIFT 12 68 | 69 | /** SCR Bits*/ 70 | #define SCR_NS_BIT 0x1 71 | #define SCR_FIQ_BIT 0x4 72 | #define SCR_IRQ_BIT 0x2 73 | #define SCR_HCR_BIT 0x100 74 | 75 | /** SCTLR Bits*/ 76 | #define SCTLR_MMU_BIT 0x1 77 | #define SCTLR_DCACHE_BIT (1 << 2) 78 | #define SCTLR_BRANCH_PRED_BIT (1 << 11) 79 | #define SCTLR_ICACHE_BIT (1 << 12) 80 | 81 | #define AUXREG_SMP 0x41 82 | #define AUXREG_UP 0x0 83 | 84 | #endif /* __ARMV7_CPU_DEFINES_H__ */ 85 | -------------------------------------------------------------------------------- /src/arch/armv7/inc/cpu_handlers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [cpu_handlers.h] 42 | * 43 | * This file contains monitor exceptions handling related code (header). 44 | * 45 | * (#) $id: cpu_handlers.h 04-05-2015 s_pinto & j_pereira $ 46 | */ 47 | 48 | #ifndef __ARMV7_CPU_HANDLERS_H 49 | #define __ARMV7_CPU_HANDLERS_H 50 | 51 | #include 52 | 53 | /** 54 | * Monitor FIQ exception handling 55 | * 56 | * @param 57 | * 58 | * @retval 59 | */ 60 | void mon_fiq_handler(void) __attribute__ ((interrupt ("FIQ"))); 61 | 62 | /** 63 | * Monitor ABORT exception handling 64 | * 65 | * @param 66 | * 67 | * @retval 68 | */ 69 | void mon_abort_handler(void) __attribute__ ((interrupt ("ABT"))); 70 | 71 | /** 72 | * Monitor PREFETCH exception handling 73 | * 74 | * @param 75 | * 76 | * @retval 77 | */ 78 | void mon_prefetch_handler(void) __attribute__ ((interrupt ("ABT"))); 79 | 80 | /** 81 | * Monitor IRQ exception handling 82 | * 83 | * @param 84 | * 85 | * @retval 86 | */ 87 | void mon_irq_handler(void) __attribute__ ((interrupt ("IRQ"))); 88 | 89 | /** 90 | * Monitor SWI exception handling 91 | * 92 | * @param 93 | * 94 | * @retval 95 | */ 96 | void mon_swi_handler(void) __attribute__ ((interrupt ("SWI"))); 97 | 98 | #endif /* __ARMV7_CPU_HANDLERS_H */ 99 | -------------------------------------------------------------------------------- /src/arch/armv7/inc/cpu_helper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [cpu_helper.h] 42 | * 43 | * This file contains ARMv7-specific miscelaneous operations (header). 44 | * 45 | * (#) $id: cpu_helper.h 03-05-2015 s_pinto & j_pereira $ 46 | * (#) $id: cpu_helper.h 18-09-2017 s_pinto (modified) $ 47 | */ 48 | 49 | #ifndef __ARMV7_CPU_HELPER_H 50 | #define __ARMV7_CPU_HELPER_H 51 | 52 | #include 53 | 54 | /** 55 | * Set the NS guest context pointer (optimization) 56 | * 57 | * @param addr = context pointer address 58 | * 59 | * @retval 60 | */ 61 | void set_guest_context(uint32_t addr); 62 | 63 | 64 | #endif /* __ARMV7_CPU_HELPER_H */ 65 | -------------------------------------------------------------------------------- /src/arch/armv7/inc/cpu_stack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [cpu_stack.h] 42 | * 43 | * This file contains stack allocation for all processor modes (header). 44 | * 45 | * (#) $id: cpu_stack.h 10-05-2015 s_pinto & j_pereira $ 46 | * (#) $id: cpu_stack.h 19-09-2017 s_pinto (modified) $ 47 | */ 48 | 49 | #ifndef __ARMV7_CPU_STACK_H 50 | #define __ARMV7_CPU_STACK_H 51 | 52 | #include 53 | #include 54 | 55 | /** IRQ stack allocation */ 56 | extern uint32_t _irq_stack[STACK_SIZE/4]; 57 | 58 | /** FIQ stack allocation */ 59 | extern uint32_t _fiq_stack[STACK_SIZE/4]; 60 | 61 | /** ABORT stack allocation */ 62 | extern uint32_t _abort_stack[STACK_SIZE/4]; 63 | 64 | /** UNDEF stack allocation */ 65 | extern uint32_t _undefined_stack[STACK_SIZE/4]; 66 | 67 | /** SYS stack allocation */ 68 | extern uint32_t _user_stack[(STACK_SIZE)/4]; 69 | 70 | /** MON stack allocation */ 71 | extern uint32_t _monitor_stack[STACK_SIZE/4]; 72 | 73 | /** SVC stack allocation */ 74 | extern uint32_t _supervisor_stack[STACK_SIZE/4]; 75 | 76 | #endif /* __ARMV7_CPU_STACK_H */ 77 | -------------------------------------------------------------------------------- /src/arch/armv7/inc/cpu_vcpu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [cpu_vcpu.h] 42 | * 43 | * This file contains (V)CPU-specific registers definition (header). 44 | * 45 | * (#) $id: cpu_vcpu.h 10-05-2015 s_pinto & j_pereira $ 46 | */ 47 | 48 | #ifndef __ARMV7_CPU_VCPU_H 49 | #define __ARMV7_CPU_VCPU_H 50 | 51 | #include 52 | 53 | /** ARMv7-A CPU core registers */ 54 | struct core_regs { 55 | uint32_t r0; 56 | uint32_t r1; 57 | uint32_t r2; 58 | uint32_t r3; 59 | uint32_t r4; 60 | uint32_t r5; 61 | uint32_t r6; 62 | uint32_t r7; 63 | uint32_t r8; 64 | uint32_t r9; 65 | uint32_t r10; 66 | uint32_t r11; 67 | uint32_t r12; 68 | uint32_t spsr_mon; 69 | uint32_t lr_mon; 70 | uint32_t spsr_svc; 71 | uint32_t r13_svc; 72 | uint32_t lr_svc; 73 | uint32_t spsr_sys; 74 | uint32_t r13_sys; 75 | uint32_t lr_sys; 76 | uint32_t spsr_abt; 77 | uint32_t r13_abt; 78 | uint32_t lr_abt; 79 | uint32_t spsr_undef; 80 | uint32_t r13_undef; 81 | uint32_t lr_undef; 82 | uint32_t spsr_irq; 83 | uint32_t r13_irq; 84 | uint32_t lr_irq; 85 | }; 86 | 87 | /** ARMv7-A CPU CP15 registers */ 88 | struct cp15_regs { 89 | uint32_t c0_CSSELR; /* Cache Size Selection Register */ 90 | uint32_t c1_SCTLR; /* System Control Register */ 91 | uint32_t c1_ACTLR; /* Auxilliary Control Register */ 92 | uint32_t c2_TTBR0; /* Translation Table Base Register 0 */ 93 | uint32_t c2_TTBR1; /* Translation Table Base Register 1 */ 94 | uint32_t c2_TTBCR; /* Translation Table Base Register Control */ 95 | uint32_t c3_DACR; /* Domain Access Control Register */ 96 | uint32_t c5_DFSR; /* Data Fault Status Register */ 97 | uint32_t c5_IFSR; /* Instruction Fault Status Register */ 98 | uint32_t c6_DFAR; /* Data Fault Address Register */ 99 | uint32_t c6_IFAR; /* Instruction Fault Address Register */ 100 | uint32_t c7_PAR; /* Physical Address Register */ 101 | uint32_t c10_PRRR; /* PRRR */ 102 | uint32_t c10_NMRR; /* NMRR */ 103 | uint32_t c12_VBAR; /* VBAR register */ 104 | uint32_t c13_FCSEIDR; /* FCSE PID Register */ 105 | uint32_t c13_CONTEXTIDR; /* Context ID Register */ 106 | uint32_t c13_TPIDRURW; /* User Read/Write Thread and Process ID */ 107 | uint32_t c13_TPIDRURO; /* User Read-only Thread and Process ID */ 108 | uint32_t c13_TPIDRPRW; /* Privileged only Thread and Process ID */ 109 | }; 110 | 111 | /** ARMv7-A CPU GIC registers */ 112 | struct gic_regs { 113 | uint32_t gic_icdiser[4]; 114 | }; 115 | 116 | /** ARMv7-A CPU architecture registers */ 117 | struct vcpu_arch { 118 | struct core_regs vcpu_regs_core; 119 | struct cp15_regs vcpu_regs_cp15; 120 | struct gic_regs vcpu_regs_gic; 121 | }; 122 | 123 | #endif /* __ARMV7_CPU_VCPU_H */ 124 | -------------------------------------------------------------------------------- /src/arch/armv7/inc/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [types.h] 42 | * 43 | * This file contains type definitions. 44 | * 45 | * (#) $id: types.h 01-01-2015 s_pinto & j_pereira $ 46 | */ 47 | 48 | 49 | #ifndef __TYPES_H 50 | #define __TYPES_H 51 | 52 | #define min(a, b) ((a) < (b) ? (a) : (b)) 53 | #define max(a, b) ((a) < (b) ? (b) : (a)) 54 | 55 | #define TRUE 1 56 | #define FALSE 0 57 | 58 | #define true 1 59 | #define false 0 60 | 61 | #ifndef NULL 62 | #define NULL 0 63 | #endif 64 | 65 | typedef char char_t; 66 | typedef const char cchar_t; 67 | typedef signed char int8_t; 68 | typedef signed short int16_t; 69 | typedef signed int int32_t; 70 | //typedef signed long int64_t; 71 | typedef unsigned char uint8_t; 72 | typedef unsigned short uint16_t; 73 | typedef unsigned int uint32_t; 74 | typedef unsigned long uint64_t; 75 | typedef float float32_t; 76 | typedef double float64_t; 77 | typedef long double float128_t; 78 | typedef unsigned int size_t; 79 | typedef unsigned long long big_ulong; 80 | 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /src/arch/armv7/objects.mk: -------------------------------------------------------------------------------- 1 | cpu-objs-y = cpu_entry.o 2 | cpu-objs-y += cpu_handlers.o 3 | cpu-objs-y += cpu_monitor.o 4 | cpu-objs-y += cpu_stack.o 5 | cpu-objs-y += cpu_cache.o 6 | cpu-objs-y += cpu_cp15_switch.o 7 | cpu-objs-y += cpu_helper.o 8 | cpu-objs-$(MP_AMP) += cpu_sec_entry.o 9 | cpu-objs-$(MP_AMP) += cpu_sec_monitor.o 10 | -------------------------------------------------------------------------------- /src/boards/zc702/board.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [board.c] 42 | * 43 | * This file contains board-specific initializations. 44 | * 45 | * (#) $id: board.c 15-10-2015 s_pinto & j_pereira $ 46 | * (#) $id: board.c 20-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #include 50 | 51 | /** 52 | * TrustZone-specific initializations 53 | * 54 | * @param 55 | * 56 | * @retval 57 | */ 58 | uint32_t board_init(void){ 59 | 60 | /** Unlocking SLCR register */ 61 | write32( (void *)SLCR_UNLOCK, SLCR_UNLOCK_KEY); 62 | 63 | /** Handling memory security */ 64 | write32( (void *)TZ_OCM_RAM0, 0xffffffff); 65 | write32( (void *)TZ_OCM_RAM1, 0xffffffff); 66 | write32( (void *)TZ_OCM, 0xffffffff); 67 | /* Handling DDR memory security (first 14segments NS)l */ 68 | write32( (void *)TZ_DDR_RAM, 0x00007fff); 69 | printk(" * Memory security - OK \n\t"); 70 | 71 | /** Handling devices security */ 72 | /* SDIO0 slave security (NS) */ 73 | write32( (void *)SECURITY2_SDIO0, 0x1); 74 | /* SDIO1 slave security (NS) */ 75 | write32( (void *)SECURITY3_SDIO1, 0x1); 76 | /* QSPI slave security (NS) */ 77 | write32( (void *)SECURITY4_QSPI, 0x1); 78 | /* APB slave security (NS) */ 79 | write32( (void *) SECURITY6_APBSL, 0x00007fff); 80 | /* DMA slave security (S) */ 81 | write32( (void *)TZ_DMA_NS, 0x0); 82 | write32( (void *)TZ_DMA_IRQ_NS, 0x0); 83 | /* Ethernet security */ 84 | write32( (void *)TZ_GEM, 0x3); 85 | /* FPGA AFI AXI ports TrustZone */ 86 | write32( (void *)SECURITY_APB, 0x3F); 87 | /* Handling more devices ... */ 88 | printk(" * Devices security - OK \n\t"); 89 | 90 | /** Locking SLCR register */ 91 | write32( (void *)SLCR_LOCK, SLCR_LOCK_KEY); 92 | 93 | return TRUE; 94 | } 95 | 96 | /** 97 | * Handling syscalls (SMCs) 98 | * 99 | * @param 100 | * 101 | * @retval 102 | */ 103 | uint32_t board_handler(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3) 104 | { 105 | switch(arg0) { 106 | case (LTZVISOR_READ_SYSCALL):{ 107 | arg0 = read32((volatile void*)arg1); 108 | break; 109 | } 110 | case (LTZVISOR_WRITE_SYSCALL):{ 111 | write32( (volatile void*)arg1, arg2); 112 | break; 113 | } 114 | default: 115 | 116 | break; 117 | } 118 | 119 | return arg0; 120 | } 121 | 122 | -------------------------------------------------------------------------------- /src/boards/zc702/inc/board.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [board.h] 42 | * 43 | * This file contains board-specific initializations (header). 44 | * 45 | * (#) $id: board.h 15-10-2015 s_pinto & j_pereira $ 46 | * (#) $id: board.h 20-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #ifndef __BOARD_H 50 | #define __BOARD_H 51 | 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | 58 | /** TrustZone on Xilinx Zynq-7000 (UG1019) */ 59 | 60 | #define SECURITY_MOD2 0xE0200000 61 | #define SECURITY2_SDIO0 (SECURITY_MOD2 + 0x8) 62 | #define SECURITY3_SDIO1 (SECURITY_MOD2 + 0xC) 63 | #define SECURITY4_QSPI (SECURITY_MOD2 + 0x10) 64 | #define SECURITY5_MIOU (SECURITY_MOD2 + 0x14) 65 | #define SECURITY6_APBSL (SECURITY_MOD2 + 0x18) 66 | #define SECURITY7_SMC (SECURITY_MOD2 + 0x1C) 67 | 68 | #define SLCR_BASE 0xF8000000 69 | #define SLCR_LOCK_KEY 0x767B 70 | #define SLCR_UNLOCK_KEY 0xDF0D 71 | #define SLCR_LOCK (SLCR_BASE + 0x4) 72 | #define SLCR_UNLOCK (SLCR_BASE + 0x8) 73 | #define DMAC_RST_CTRL (SLCR_BASE + 0x20C) 74 | #define TZ_OCM_RAM0 (SLCR_BASE + 0x400) 75 | #define TZ_OCM_RAM1 (SLCR_BASE + 0x404) 76 | #define TZ_OCM (SLCR_BASE + 0x408) 77 | #define TZ_DDR_RAM (SLCR_BASE + 0x430) 78 | #define TZ_DMA_NS (SLCR_BASE + 0x440) 79 | #define TZ_DMA_IRQ_NS (SLCR_BASE + 0x444) 80 | #define TZ_DMA_PERIPH_NS (SLCR_BASE + 0x448) 81 | #define TZ_GEM (SLCR_BASE + 0x450) 82 | #define TZ_SDIO (SLCR_BASE + 0x454) 83 | #define TZ_USB (SLCR_BASE + 0x458) 84 | #define TZ_FPGA_M (SLCR_BASE + 0x484) 85 | #define TZ_FPGA_AFI (SLCR_BASE + 0x488) 86 | 87 | #define SECURITY_MOD3 0xF8900000 88 | #define SECURITY_FSSW_S0 (SECURITY_MOD3 + 0x1C) 89 | #define SECURITY_FSSW_S1 (SECURITY_MOD3 + 0x20) 90 | #define SECURITY_APB (SECURITY_MOD3 + 0x28) 91 | 92 | /** 93 | * TrustZone-specific initializations 94 | * 95 | * @param 96 | * 97 | * @retval 98 | */ 99 | uint32_t board_init(void); 100 | 101 | /** 102 | * Handling syscalls (SMCs) 103 | * 104 | * @param 105 | * 106 | * @retval 107 | */ 108 | uint32_t board_handler(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3); 109 | 110 | #endif /* __BOARD_H */ 111 | -------------------------------------------------------------------------------- /src/boards/zc702/inc/ltzvisor_hw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [ltzvisor_hw.h] 42 | * 43 | * This file contains the LTZVisor hardware-specific initialization. 44 | * 45 | * (#) $id: ltzvisor_hw.h 10-06-2015 s_pinto & j_pereira $ 46 | * (#) $id: ltzvisor_hw.h 17-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #ifndef __LTZVISOR_HW_H 50 | #define __LTZVISOR_HW_H 51 | 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | #define ARCH "ARMv7-A" 60 | #define CPU "Cortex-A9" 61 | #define PLATFORM "Zynq-7000" 62 | 63 | #define LTZVISOR_MON_EXIT() {\ 64 | asm volatile("msr cpsr_c,#(0x13 | 0x80 | 0x40)");\ 65 | asm volatile("ldr r1,=_supervisor_stack");\ 66 | asm volatile("add r1, r1, r0, lsl #12");\ 67 | asm volatile("add sp, r1, #4096");\ 68 | } 69 | 70 | /** 71 | * LTZVisor hardware initialization 72 | * 73 | * @param 74 | * 75 | * @retval Return TRUE if success or False if not 76 | */ 77 | uint32_t ltzvisor_hw_init(void); 78 | 79 | #endif /* __LTZVISOR_HW_H */ 80 | -------------------------------------------------------------------------------- /src/boards/zc702/inc/platform_zynq.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [platform_zynq.h] 42 | * 43 | * This file contains board-specific register definitions (header). 44 | * 45 | * (#) $id: platform_zynq.h 15-10-2015 s_pinto & j_pereira $ 46 | * (#) $id: platform_zynq.h 20-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #ifndef __PLATF_ZYNQ_H 50 | #define __PLATF_ZYNQ_H 51 | 52 | #define XSCU_BASE 0xF8F00000 53 | 54 | #define GICC_OFFSET 0x0100 55 | #define GICD_OFFSET 0x1000 56 | #define MPIC_BASE (XSCU_BASE + GICC_OFFSET) 57 | #define MPID_BASE (XSCU_BASE + GICD_OFFSET) 58 | 59 | #define MPTW_BASE (XSCU_BASE + 0x0600) 60 | 61 | #define UART_BASE_0 0xE0000000 62 | #define UART_BASE_1 0xE0001000 63 | 64 | #define TTC0_BASE 0xF8001000 65 | #define TTC1_BASE 0xF8002000 66 | 67 | #endif /* __PLATF_ZYNQ_H */ 68 | -------------------------------------------------------------------------------- /src/boards/zc702/inc/zynq_ttc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [zynq_ttc.h] 42 | * 43 | * This file contains the Zynq Triple Timer Counter driver (header). 44 | * 45 | * (#) $id: zynq_ttc.h 20-05-2015 s_pinto$ 46 | * (#) $id: zynq_ttc.h 19-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #ifndef __ZYNQ_TTC_H 50 | #define __ZYNQ_TTC_H 51 | 52 | #include"types.h" 53 | #include"gic.h" 54 | #include"platform_zynq.h" 55 | 56 | /** TTC Interrupts IDs */ 57 | #define TTC0_TTCx_1_INTERRUPT 42 58 | #define TTC0_TTCx_2_INTERRUPT 43 59 | #define TTC0_TTCx_3_INTERRUPT 44 60 | #define TTC1_TTCx_1_INTERRUPT 69 61 | #define TTC1_TTCx_2_INTERRUPT 70 62 | #define TTC1_TTCx_3_INTERRUPT 71 63 | 64 | /** TTC Clock Control Register Flags */ 65 | #define TTC_CLK_CNTRL_EXT_EDGE (1 << 6) 66 | #define TTC_CLK_CNTRL_SRC (1 << 5) 67 | #define TTC_CLK_CNTRL_PS_EN (1 << 0) 68 | #define TTC_CLK_CNTRL_PS_VAL (4) 69 | 70 | /** TTC Counter Control Register Flags */ 71 | #define TTC_CNT_CNTRL_POL_WAVE (1 << 6) 72 | #define TTC_CNT_CNTRL_EN_WAVE (1 << 5) 73 | #define TTC_CNT_CNTRL_RST (1 << 4) 74 | #define TTC_CNT_CNTRL_MATCH (1 << 3) 75 | #define TTC_CNT_CNTRL_DEC (1 << 2) 76 | #define TTC_CNT_CNTRL_INT (1 << 1) 77 | #define TTC_CNT_CNTRL_DIS (1 << 0) 78 | 79 | /** TTC Interrupt Enable Register Flags */ 80 | #define TTC_INT_EN_EV (1 << 5) 81 | #define TTC_INT_EN_CNT_OVR (1 << 4) 82 | #define TTC_INT_EN_MATCH3 (1 << 3) 83 | #define TTC_INT_EN_MATCH2 (1 << 2) 84 | #define TTC_INT_EN_MATCH1 (1 << 1) 85 | #define TTC_INT_EN_INTERVAL (1 << 0) 86 | 87 | /** TTC Event Control Timer Register Flags */ 88 | #define TTC_EV_CNTRL_TIM_E_OV (1 << 2) 89 | #define TTC_EV_CNTRL_TIM_E_LO (1 << 1) 90 | #define TTC_EV_CNTRL_TIM_E_EN (1 << 0) 91 | 92 | /** TTC Reset Configuration value */ 93 | /*Output waveform enable & disable counter*/ 94 | #define TTC_RESET_CONFIG (0x21) 95 | 96 | /** TTC Values */ 97 | #define TTC_INT_VALUE (111) 98 | #define TTC_MATCH1_VALUE (111) 99 | 100 | /** Number of TTCs */ 101 | #define NUM_TTC 2 102 | /** Number of Timers per TTC */ 103 | #define NUM_TIM_PER_TTC 3 104 | 105 | /** TTC Number Definition */ 106 | #define TTC0 0 107 | #define TTC1 1 108 | /** TTC's Timer Number Definition */ 109 | #define TTCx_1 0 110 | #define TTCx_2 1 111 | #define TTCx_3 2 112 | 113 | /** TTC Modes */ 114 | #define INTERVAL 0 115 | #define MATCH 1 116 | #define FREE_RUNNING 2 117 | 118 | /** TTC registers structure */ 119 | typedef struct{ 120 | /* Clock Control Register */ 121 | volatile uint32_t clk_cntrl[NUM_TIM_PER_TTC]; 122 | /* Operational mode and reset */ 123 | volatile uint32_t cnt_cntrl[NUM_TIM_PER_TTC]; 124 | /* Current counter value */ 125 | volatile const uint32_t cnt_value[NUM_TIM_PER_TTC]; 126 | /* Interval value */ 127 | volatile uint32_t interv_cnt[NUM_TIM_PER_TTC]; 128 | /* Match values */ 129 | volatile uint32_t match1_cnt[NUM_TIM_PER_TTC]; 130 | volatile uint32_t match2_cnt[NUM_TIM_PER_TTC]; 131 | volatile uint32_t match3_cnt[NUM_TIM_PER_TTC]; 132 | /* Counter Interval, Match, Overflow and Event interrupts (RO) */ 133 | volatile const uint32_t interrupt_reg[NUM_TIM_PER_TTC]; 134 | /* */ 135 | volatile uint32_t interrupt_en[NUM_TIM_PER_TTC]; 136 | /* */ 137 | volatile uint32_t event_cntrl_tim[NUM_TIM_PER_TTC]; 138 | /* */ 139 | volatile const uint32_t event_reg[NUM_TIM_PER_TTC]; 140 | } Zynq_Ttc; 141 | 142 | /** 143 | * TTC initialization 144 | * 145 | * @param ttc_num = TTC number 146 | * timer_num = TTC's timer number 147 | * mode = timer mode 148 | * 149 | * @retval True for success and FALSE in case ERROR 150 | */ 151 | uint32_t ttc_init(uint32_t ttc_num, uint32_t timer_num, uint32_t mode); 152 | 153 | /** 154 | * TTC enable 155 | * 156 | * @param ttc_num = TTC number 157 | * timer_num = TTC's timer number 158 | * 159 | * @retval True for success and FALSE in case ERROR 160 | */ 161 | uint32_t ttc_enable(uint32_t ttc_num, uint32_t timer_num); 162 | 163 | /** 164 | * TTC disable 165 | * 166 | * @param ttc_num = TTC number 167 | * timer_num = TTC's timer number 168 | * 169 | * @retval True for success and FALSE in case ERROR 170 | */ 171 | uint32_t ttc_disable(uint32_t ttc_num, uint32_t timer_num); 172 | 173 | /** 174 | * TTC timer request 175 | * 176 | * @param ttc_num = TTC number 177 | * timer_num = TTC's timer number 178 | * useconds = time 179 | * 180 | * @retval True for success and FALSE in case ERROR 181 | */ 182 | uint32_t ttc_request(uint32_t ttc_num, uint32_t timer_num, uint32_t useconds); 183 | 184 | /** 185 | * TTC interrupt clear 186 | * 187 | * @param interrupt = interrupt number 188 | * 189 | * @retval True for success and FALSE in case ERROR 190 | */ 191 | uint32_t ttc_interrupt_clear(uint32_t interrupt); 192 | 193 | #endif /* __ZYNQ_TTC_H */ 194 | -------------------------------------------------------------------------------- /src/boards/zc702/linker.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") 2 | OUTPUT_ARCH("arm") 3 | 4 | ENTRY(_reset_handler) 5 | 6 | phy_offset = 0x3C000000; 7 | 8 | 9 | SECTIONS 10 | { 11 | . = phy_offset; 12 | _code_begin = .; 13 | 14 | .text : { 15 | *(.text) 16 | } 17 | . = ALIGN(0x1000); 18 | 19 | .data : { 20 | *(.data) 21 | } 22 | . = ALIGN(0x1000); 23 | 24 | .rodata : { 25 | *(.rodata) 26 | } 27 | . = ALIGN(0x1000); 28 | 29 | _SW_BSS_START = .; 30 | .bss : { 31 | *(.bss) 32 | *(COMMON) 33 | } 34 | . = ALIGN(0x1000); 35 | _bss_size = _SW_BSS_END - _SW_BSS_START; 36 | _SW_BSS_END = .; 37 | 38 | .heap (NOLOAD) : { 39 | . = ALIGN(16); 40 | _heap = .; 41 | HeapBase = .; 42 | PROVIDE(_heap_start = .); 43 | . += 0x2000; 44 | PROVIDE(_heap_end = .); 45 | HeapLimit = .; 46 | } 47 | _SW_CODE_END = .; 48 | } 49 | -------------------------------------------------------------------------------- /src/boards/zc702/ltzvisor_hw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This program is free software; you can redistribute it and/or 11 | * modify it under the terms of the GNU General Public License as 12 | * published by the Free Software Foundation; either version 2 of 13 | * the License, or (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | * 02110-1301 USA. 24 | * 25 | * [ltzvisor_hw.c] 26 | * 27 | * This file contains the LTZVisor hardware-specific initialization. 28 | * 29 | * (#) $id: ltzvisor_hw.c 10-06-2015 s_pinto & j_pereira $ 30 | * (#) $id: ltzvisor_hw.c 17-09-2017 s_pinto (modified)$ 31 | */ 32 | 33 | #include 34 | 35 | /** 36 | * LTZVisor hardware initialization 37 | * 38 | * @param 39 | * 40 | * @retval Return TRUE if success or False if not 41 | */ 42 | uint32_t ltzvisor_hw_init(void){ 43 | 44 | uint32_t ret = TRUE; 45 | uint32_t i; 46 | 47 | /** Init Serial Port */ 48 | for(i=0; i<10000; i++); //Comment if not running with U-boot 49 | ret = uart_init(1); 50 | if(!ret){ 51 | /* ERROR */ 52 | /* FIXME - Signal Error somewhere (LED) */ 53 | return ret; 54 | } 55 | 56 | printk("\n\n\t"); 57 | printk("----------------------------------------------------------\n\t"); 58 | printk(" LTZVisor (version %s) \n\t", VERSION); 59 | printk("----------------------------------------------------------\n\t"); 60 | printk(" -> Arch (%s): CPU (%s) initialization ... \n\t", ARCH, CPU); 61 | printk(" -> Arch (%s): GIC initialization ... \n\t", ARCH); 62 | 63 | /** Initialize GIC Distributer and GIC Interface*/ 64 | /* Distributor init */ 65 | ret = interrupt_distributor_init(); 66 | if(!ret){ 67 | 68 | /* ERROR */ 69 | printk("ERROR: GIC distributor init!\n\r"); 70 | return ret; 71 | } 72 | printk(" * GIC distributor - OK \n\t"); 73 | /* Interface init */ 74 | ret = interrupt_interface_init(); 75 | if(!ret){ 76 | 77 | /* ERROR */ 78 | printk("ERROR: GIC interface init!\n\r"); 79 | return ret; 80 | } 81 | printk(" * GIC interface - OK \n\t"); 82 | /* Config Interrupts Security */ 83 | interrupt_security_configall(); 84 | interrupt_security_config(UART_1_INTERRUPT,Int_NS); 85 | interrupt_security_config(TTC1_TTCx_2_INTERRUPT,Int_S); 86 | printk(" * GIC security - OK \n\t"); 87 | 88 | /** Initialize Platform-specific */ 89 | printk(" -> Platform (%s): initialization ... \n\t", PLATFORM); 90 | ret = board_init(); 91 | if(!ret){ 92 | /* ERROR */ 93 | printk("ERROR: Platform init!\n\r"); 94 | return ret; 95 | } 96 | 97 | return ret; 98 | } 99 | 100 | -------------------------------------------------------------------------------- /src/boards/zc702/objects.mk: -------------------------------------------------------------------------------- 1 | boards-objs-y = board.o 2 | boards-objs-y += zynq_uart.o 3 | boards-objs-y += zynq_ttc.o 4 | boards-objs-y += ltzvisor_hw.o 5 | -------------------------------------------------------------------------------- /src/boards/zc702/zynq_uart.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [zynq_uart.c] 42 | * 43 | * This file contains the Zynq UART driver (header). 44 | * 45 | * (#) $id: zynq_uart.c 20-10-2015 s_pinto$ 46 | * (#) $id: zynq_uart.c 19-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #include 50 | 51 | Uart_Zynq * const Ptr_Uart[NUM_UART] = {(Uart_Zynq *)UART_BASE_0,(Uart_Zynq *)UART_BASE_1}; 52 | 53 | 54 | /** 55 | * UART initialization (default 115200) 56 | * 57 | * @param uart_id = ID uart 58 | * 59 | * @retval TRUE in sucess; FALSE in case error 60 | */ 61 | uint32_t uart_init(uint8_t uart_id){ 62 | 63 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 64 | uint32_t ret; 65 | 66 | ret = uart_set_baud_rate(uart_id, UART_BAUD_RATE); 67 | if(ret == FALSE){ 68 | return FALSE; 69 | } 70 | 71 | /* Set the level of the RxFIFO trigger level */ 72 | ptr_uart->rx_fifo_trig = UART_RX_TRIGGER_LVL; 73 | /* Program the Receiver Timeout Mechanism (Disabled) */ 74 | ptr_uart->rx_timeout = UART_RX_TIMEOUT_DIS; 75 | 76 | /* Clear all the interrupts in Interrupt Status Register */ 77 | ptr_uart->isr_status = 0xFFFFFFFF; 78 | /* Enable RxFIFO Trigger Interrupt */ 79 | ptr_uart->isr_en = UART_ISR_EN_RTRIG; 80 | 81 | /** Enable the Controller */ 82 | ptr_uart->control |= (UART_CONTROL_STPBRK|UART_CONTROL_RXRES|UART_CONTROL_TXRES); 83 | 84 | return TRUE; 85 | } 86 | 87 | /** 88 | * UART enable 89 | * 90 | * @param uart_id = ID uart 91 | * 92 | * @retval 93 | */ 94 | void uart_enable(uint8_t uart_id){ 95 | 96 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 97 | 98 | uint32_t ctrl_reg = ptr_uart->control; 99 | ctrl_reg = ( UART_CONTROL_STPBRK | UART_CONTROL_TXEN | 100 | UART_CONTROL_RXEN | UART_CONTROL_RXRES | UART_CONTROL_TXRES ); 101 | ptr_uart->control = ctrl_reg; 102 | 103 | } 104 | 105 | /** 106 | * UART disable 107 | * 108 | * @param uart_id = ID uart 109 | * 110 | * @retval 111 | */ 112 | void uart_disable(uint8_t uart_id){ 113 | 114 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 115 | 116 | uint32_t ctrl_reg = ptr_uart->control; 117 | ctrl_reg = ( UART_CONTROL_STPBRK | UART_CONTROL_TXDIS | UART_CONTROL_RXDIS ); 118 | ptr_uart->control = ctrl_reg; 119 | } 120 | 121 | /** 122 | * UART baudrate set 123 | * 124 | * @param uart_id = ID uart 125 | * baud_rate = baudrate speed of the uart 126 | * 127 | * @retval TRUE in sucess; FALSE in case error 128 | */ 129 | uint32_t uart_set_baud_rate(uint8_t uart_id, uint32_t baud_rate){ 130 | 131 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 132 | 133 | //uint32_t sel_clk = UART_FREQ_CLK; 134 | uint8_t bdiv = 0; 135 | uint16_t cd_calc = 0; 136 | 137 | /** Handling corner case */ 138 | if(baud_rate == 0){ 139 | baud_rate = UART_BAUD_RATE; 140 | } 141 | 142 | /* baud_rate = sel_clk / (CD * (BDIV+1)) 143 | * baud_rate -> Baud Rate 144 | * sel_clk -> Selected Clock 145 | * CD -> Baud Rate Generator 146 | * BDIV -> Baud Rate Divider 147 | */ 148 | /** FIXME - Handling statically 115200 */ 149 | bdiv = UART_BDIV_115200; 150 | cd_calc = UART_CD_115200; 151 | 152 | /** Configure the Baud Rate */ 153 | /* Disable the Rx and Tx path */ 154 | ptr_uart->control = (UART_CONTROL_RXDIS|UART_CONTROL_TXDIS); 155 | /* Write the calculated CD value */ 156 | ptr_uart->br_gen = cd_calc; 157 | /* Write the calculated BDIV value */ 158 | ptr_uart->br_div = bdiv; 159 | /* Reset Tx and Rx paths */ 160 | ptr_uart->control = (UART_CONTROL_TXRES|UART_CONTROL_RXRES); 161 | /* Enable the Rx and Tx path */ 162 | ptr_uart->control = (UART_CONTROL_TXEN|UART_CONTROL_RXEN); 163 | 164 | return TRUE; 165 | } 166 | 167 | /** 168 | * UART get character 169 | * 170 | * @param uart_id = ID uart 171 | * baud_rate = baudrate speed of the uart 172 | * 173 | * @retval Received character 174 | */ 175 | uint32_t uart_getc(uint8_t uart_id){ 176 | 177 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 178 | uint32_t data = 0; 179 | 180 | /* Wait until RxFIFO is filled up to the trigger level */ 181 | while(!ptr_uart->ch_status & UART_CH_STATUS_RTRIG); 182 | 183 | data = ptr_uart->tx_rx_fifo; 184 | 185 | return data; 186 | } 187 | 188 | /** 189 | * UART send character 190 | * 191 | * @param uart_id = ID uart 192 | * c = Character to be sent 193 | * 194 | * @retval 195 | */ 196 | void uart_putc(uint8_t uart_id,int8_t c){ 197 | 198 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 199 | 200 | //wait until txFIFO is not full 201 | while(ptr_uart->ch_status & UART_CH_STATUS_TFUL); 202 | 203 | ptr_uart->tx_rx_fifo = c; 204 | 205 | } 206 | 207 | /** 208 | * UART send string 209 | * 210 | * @param uart_id = ID uart 211 | * c = String to be sent 212 | * 213 | * @retval 214 | */ 215 | void uart_puts(uint8_t uart_id, const int8_t *s){ 216 | 217 | while (*s){ 218 | uart_putc(uart_id,*s++); 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /src/boards/zedboard/board.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [board.c] 42 | * 43 | * This file contains board-specific initializations. 44 | * 45 | * (#) $id: board.c 15-10-2015 s_pinto & j_pereira $ 46 | * (#) $id: board.c 20-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #include 50 | 51 | /** 52 | * TrustZone-specific initializations 53 | * 54 | * @param 55 | * 56 | * @retval 57 | */ 58 | uint32_t board_init(void){ 59 | 60 | /** Unlocking SLCR register */ 61 | write32( (void *)SLCR_UNLOCK, SLCR_UNLOCK_KEY); 62 | 63 | /** Handling memory security */ 64 | write32( (void *)TZ_OCM_RAM0, 0xffffffff); 65 | write32( (void *)TZ_OCM_RAM1, 0xffffffff); 66 | write32( (void *)TZ_OCM, 0xffffffff); 67 | /* Handling DDR memory security (first 14segments NS)l */ 68 | write32( (void *)TZ_DDR_RAM, 0x0000007f); 69 | printk(" * Memory security - OK \n\t"); 70 | 71 | /** Handling devices security */ 72 | /* SDIO0 slave security (NS) */ 73 | write32( (void *)SECURITY2_SDIO0, 0x1); 74 | /* SDIO1 slave security (NS) */ 75 | write32( (void *)SECURITY3_SDIO1, 0x1); 76 | /* QSPI slave security (NS) */ 77 | write32( (void *)SECURITY4_QSPI, 0x1); 78 | /* APB slave security (NS) */ 79 | write32( (void *) SECURITY6_APBSL, 0x00007fff); 80 | /* DMA slave security (S) */ 81 | write32( (void *)TZ_DMA_NS, 0x0); 82 | write32( (void *)TZ_DMA_IRQ_NS, 0x0); 83 | /* Ethernet security */ 84 | write32( (void *)TZ_GEM, 0x3); 85 | /* FPGA AFI AXI ports TrustZone */ 86 | write32( (void *)SECURITY_APB, 0x3F); 87 | /* Handling more devices ... */ 88 | printk(" * Devices security - OK \n\t"); 89 | 90 | /** Locking SLCR register */ 91 | write32( (void *)SLCR_LOCK, SLCR_LOCK_KEY); 92 | 93 | return TRUE; 94 | } 95 | 96 | /** 97 | * Handling syscalls (SMCs) 98 | * 99 | * @param 100 | * 101 | * @retval 102 | */ 103 | uint32_t board_handler(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3) 104 | { 105 | switch(arg0) { 106 | case (LTZVISOR_READ_SYSCALL):{ 107 | arg0 = read32((volatile void*)arg1); 108 | break; 109 | } 110 | case (LTZVISOR_WRITE_SYSCALL):{ 111 | write32( (volatile void*)arg1, arg2); 112 | break; 113 | } 114 | default: 115 | 116 | break; 117 | } 118 | 119 | return arg0; 120 | } 121 | 122 | -------------------------------------------------------------------------------- /src/boards/zedboard/inc/board.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [board.h] 42 | * 43 | * This file contains board-specific initializations (header). 44 | * 45 | * (#) $id: board.h 15-10-2015 s_pinto & j_pereira $ 46 | * (#) $id: board.h 20-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #ifndef __BOARD_H 50 | #define __BOARD_H 51 | 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | 58 | /** TrustZone on Xilinx Zynq-7000 (UG1019) */ 59 | 60 | #define SECURITY_MOD2 0xE0200000 61 | #define SECURITY2_SDIO0 (SECURITY_MOD2 + 0x8) 62 | #define SECURITY3_SDIO1 (SECURITY_MOD2 + 0xC) 63 | #define SECURITY4_QSPI (SECURITY_MOD2 + 0x10) 64 | #define SECURITY5_MIOU (SECURITY_MOD2 + 0x14) 65 | #define SECURITY6_APBSL (SECURITY_MOD2 + 0x18) 66 | #define SECURITY7_SMC (SECURITY_MOD2 + 0x1C) 67 | 68 | #define SLCR_BASE 0xF8000000 69 | #define SLCR_LOCK_KEY 0x767B 70 | #define SLCR_UNLOCK_KEY 0xDF0D 71 | #define SLCR_LOCK (SLCR_BASE + 0x4) 72 | #define SLCR_UNLOCK (SLCR_BASE + 0x8) 73 | #define DMAC_RST_CTRL (SLCR_BASE + 0x20C) 74 | #define TZ_OCM_RAM0 (SLCR_BASE + 0x400) 75 | #define TZ_OCM_RAM1 (SLCR_BASE + 0x404) 76 | #define TZ_OCM (SLCR_BASE + 0x408) 77 | #define TZ_DDR_RAM (SLCR_BASE + 0x430) 78 | #define TZ_DMA_NS (SLCR_BASE + 0x440) 79 | #define TZ_DMA_IRQ_NS (SLCR_BASE + 0x444) 80 | #define TZ_DMA_PERIPH_NS (SLCR_BASE + 0x448) 81 | #define TZ_GEM (SLCR_BASE + 0x450) 82 | #define TZ_SDIO (SLCR_BASE + 0x454) 83 | #define TZ_USB (SLCR_BASE + 0x458) 84 | #define TZ_FPGA_M (SLCR_BASE + 0x484) 85 | #define TZ_FPGA_AFI (SLCR_BASE + 0x488) 86 | 87 | #define SECURITY_MOD3 0xF8900000 88 | #define SECURITY_FSSW_S0 (SECURITY_MOD3 + 0x1C) 89 | #define SECURITY_FSSW_S1 (SECURITY_MOD3 + 0x20) 90 | #define SECURITY_APB (SECURITY_MOD3 + 0x28) 91 | 92 | /** 93 | * TrustZone-specific initializations 94 | * 95 | * @param 96 | * 97 | * @retval 98 | */ 99 | uint32_t board_init(void); 100 | 101 | /** 102 | * Handling syscalls (SMCs) 103 | * 104 | * @param 105 | * 106 | * @retval 107 | */ 108 | uint32_t board_handler(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3); 109 | 110 | #endif /* __BOARD_H */ 111 | -------------------------------------------------------------------------------- /src/boards/zedboard/inc/ltzvisor_hw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [ltzvisor_hw.h] 42 | * 43 | * This file contains the LTZVisor hardware-specific initialization. 44 | * 45 | * (#) $id: ltzvisor_hw.h 10-06-2015 s_pinto & j_pereira $ 46 | * (#) $id: ltzvisor_hw.h 17-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #ifndef __LTZVISOR_HW_H 50 | #define __LTZVISOR_HW_H 51 | 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | #define ARCH "ARMv7-A" 60 | #define CPU "Cortex-A9" 61 | #define PLATFORM "Zynq-7000" 62 | 63 | #define LTZVISOR_MON_EXIT() {\ 64 | asm volatile("msr cpsr_c,#(0x13 | 0x80 | 0x40)");\ 65 | asm volatile("ldr r1,=_supervisor_stack");\ 66 | asm volatile("add r1, r1, r0, lsl #12");\ 67 | asm volatile("add sp, r1, #4096");\ 68 | } 69 | 70 | /** 71 | * LTZVisor hardware initialization 72 | * 73 | * @param 74 | * 75 | * @retval Return TRUE if success or False if not 76 | */ 77 | uint32_t ltzvisor_hw_init(void); 78 | 79 | #endif /* __LTZVISOR_HW_H */ 80 | -------------------------------------------------------------------------------- /src/boards/zedboard/inc/platform_zynq.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [platform_zynq.h] 42 | * 43 | * This file contains board-specific register definitions (header). 44 | * 45 | * (#) $id: platform_zynq.h 15-10-2015 s_pinto & j_pereira $ 46 | * (#) $id: platform_zynq.h 20-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #ifndef __PLATF_ZYNQ_H 50 | #define __PLATF_ZYNQ_H 51 | 52 | #define XSCU_BASE 0xF8F00000 53 | 54 | #define GICC_OFFSET 0x0100 55 | #define GICD_OFFSET 0x1000 56 | #define MPIC_BASE (XSCU_BASE + GICC_OFFSET) 57 | #define MPID_BASE (XSCU_BASE + GICD_OFFSET) 58 | 59 | #define MPTW_BASE (XSCU_BASE + 0x0600) 60 | 61 | #define UART_BASE_0 0xE0000000 62 | #define UART_BASE_1 0xE0001000 63 | 64 | #define TTC0_BASE 0xF8001000 65 | #define TTC1_BASE 0xF8002000 66 | 67 | #endif /* __PLATF_ZYNQ_H */ 68 | -------------------------------------------------------------------------------- /src/boards/zedboard/linker.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") 2 | OUTPUT_ARCH("arm") 3 | 4 | ENTRY(_reset_handler) 5 | 6 | 7 | MEMORY 8 | { 9 | OCM (rwx): ORIGIN = 0x00000000, LENGTH = 0x00030000 10 | DDR_NS (rwx) : ORIGIN = 0x00100000, LENGTH = 0x1BEFFFFF 11 | DDR_S (rwx) : ORIGIN = 0x1C000000, LENGTH = 0x03F00000 12 | } 13 | 14 | 15 | SECTIONS 16 | { 17 | _code_begin = .; 18 | 19 | .startup :{ 20 | __startup_start = .; 21 | *(.startup) 22 | __startup_end = .; 23 | } > DDR_S 24 | . = ALIGN(0x1000); 25 | 26 | .text : { 27 | *(.text) 28 | } > DDR_S 29 | . = ALIGN(0x1000); 30 | 31 | .data : { 32 | *(.data) 33 | } > DDR_S 34 | . = ALIGN(0x1000); 35 | 36 | .rodata : { 37 | *(.rodata) 38 | } > DDR_S 39 | . = ALIGN(0x1000); 40 | 41 | _SW_BSS_START = .; 42 | .bss : { 43 | *(.bss) 44 | *(COMMON) 45 | } > DDR_S 46 | . = ALIGN(0x1000); 47 | _bss_size = _SW_BSS_END - _SW_BSS_START; 48 | _SW_BSS_END = .; 49 | 50 | .heap (NOLOAD) : { 51 | . = ALIGN(16); 52 | _heap = .; 53 | HeapBase = .; 54 | PROVIDE(_heap_start = .); 55 | . += 0x2000; 56 | PROVIDE(_heap_end = .); 57 | HeapLimit = .; 58 | } > DDR_S 59 | _SW_CODE_END = .; 60 | } 61 | 62 | -------------------------------------------------------------------------------- /src/boards/zedboard/ltzvisor_hw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This program is free software; you can redistribute it and/or 11 | * modify it under the terms of the GNU General Public License as 12 | * published by the Free Software Foundation; either version 2 of 13 | * the License, or (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | * 02110-1301 USA. 24 | * 25 | * [ltzvisor_hw.c] 26 | * 27 | * This file contains the LTZVisor hardware-specific initialization. 28 | * 29 | * (#) $id: ltzvisor_hw.c 10-06-2015 s_pinto & j_pereira $ 30 | * (#) $id: ltzvisor_hw.c 17-09-2017 s_pinto (modified)$ 31 | */ 32 | 33 | #include 34 | 35 | /** 36 | * LTZVisor hardware initialization 37 | * 38 | * @param 39 | * 40 | * @retval Return TRUE if success or False if not 41 | */ 42 | uint32_t ltzvisor_hw_init(void){ 43 | 44 | uint32_t ret = TRUE; 45 | uint32_t i; 46 | 47 | /** Init Serial Port */ 48 | for(i=0; i<10000; i++); //Comment if not running with U-boot 49 | ret = uart_init(1); 50 | if(!ret){ 51 | /* ERROR */ 52 | /* FIXME - Signal Error somewhere (LED) */ 53 | return ret; 54 | } 55 | 56 | printk("\n\n\t"); 57 | printk("----------------------------------------------------------\n\t"); 58 | printk(" LTZVisor (version %s) \n\t", VERSION); 59 | printk("----------------------------------------------------------\n\t"); 60 | printk(" -> Arch (%s): CPU (%s) initialization ... \n\t", ARCH, CPU); 61 | printk(" -> Arch (%s): GIC initialization ... \n\t", ARCH); 62 | 63 | /** Initialize GIC Distributer and GIC Interface*/ 64 | /* Distributor init */ 65 | ret = interrupt_distributor_init(); 66 | if(!ret){ 67 | 68 | /* ERROR */ 69 | printk("ERROR: GIC distributor init!\n\r"); 70 | return ret; 71 | } 72 | printk(" * GIC distributor - OK \n\t"); 73 | /* Interface init */ 74 | ret = interrupt_interface_init(); 75 | if(!ret){ 76 | 77 | /* ERROR */ 78 | printk("ERROR: GIC interface init!\n\r"); 79 | return ret; 80 | } 81 | printk(" * GIC interface - OK \n\t"); 82 | /* Config Interrupts Security */ 83 | interrupt_security_configall(); 84 | interrupt_security_config(UART_1_INTERRUPT,Int_NS); 85 | interrupt_security_config(TTC1_TTCx_2_INTERRUPT,Int_S); 86 | printk(" * GIC security - OK \n\t"); 87 | 88 | /** Initialize Platform-specific */ 89 | printk(" -> Platform (%s): initialization ... \n\t", PLATFORM); 90 | ret = board_init(); 91 | if(!ret){ 92 | /* ERROR */ 93 | printk("ERROR: Platform init!\n\r"); 94 | return ret; 95 | } 96 | 97 | return ret; 98 | } 99 | 100 | -------------------------------------------------------------------------------- /src/boards/zedboard/objects.mk: -------------------------------------------------------------------------------- 1 | boards-objs-y = board.o 2 | boards-objs-y += zynq_uart.o 3 | boards-objs-y += zynq_ttc.o 4 | boards-objs-y += ltzvisor_hw.o 5 | -------------------------------------------------------------------------------- /src/boards/zedboard/zynq_uart.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [zynq_uart.c] 42 | * 43 | * This file contains the Zynq UART driver (header). 44 | * 45 | * (#) $id: zynq_uart.c 20-10-2015 s_pinto$ 46 | * (#) $id: zynq_uart.c 19-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #include 50 | 51 | Uart_Zynq * const Ptr_Uart[NUM_UART] = {(Uart_Zynq *)UART_BASE_0,(Uart_Zynq *)UART_BASE_1}; 52 | 53 | 54 | /** 55 | * UART initialization (default 115200) 56 | * 57 | * @param uart_id = ID uart 58 | * 59 | * @retval TRUE in sucess; FALSE in case error 60 | */ 61 | uint32_t uart_init(uint8_t uart_id){ 62 | 63 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 64 | uint32_t ret; 65 | 66 | ret = uart_set_baud_rate(uart_id, UART_BAUD_RATE); 67 | if(ret == FALSE){ 68 | return FALSE; 69 | } 70 | 71 | /* Set the level of the RxFIFO trigger level */ 72 | ptr_uart->rx_fifo_trig = UART_RX_TRIGGER_LVL; 73 | /* Program the Receiver Timeout Mechanism (Disabled) */ 74 | ptr_uart->rx_timeout = UART_RX_TIMEOUT_DIS; 75 | 76 | /* Clear all the interrupts in Interrupt Status Register */ 77 | ptr_uart->isr_status = 0xFFFFFFFF; 78 | /* Enable RxFIFO Trigger Interrupt */ 79 | ptr_uart->isr_en = UART_ISR_EN_RTRIG; 80 | 81 | /** Enable the Controller */ 82 | ptr_uart->control |= (UART_CONTROL_STPBRK|UART_CONTROL_RXRES|UART_CONTROL_TXRES); 83 | 84 | return TRUE; 85 | } 86 | 87 | /** 88 | * UART enable 89 | * 90 | * @param uart_id = ID uart 91 | * 92 | * @retval 93 | */ 94 | void uart_enable(uint8_t uart_id){ 95 | 96 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 97 | 98 | uint32_t ctrl_reg = ptr_uart->control; 99 | ctrl_reg = ( UART_CONTROL_STPBRK | UART_CONTROL_TXEN | 100 | UART_CONTROL_RXEN | UART_CONTROL_RXRES | UART_CONTROL_TXRES ); 101 | ptr_uart->control = ctrl_reg; 102 | 103 | } 104 | 105 | /** 106 | * UART disable 107 | * 108 | * @param uart_id = ID uart 109 | * 110 | * @retval 111 | */ 112 | void uart_disable(uint8_t uart_id){ 113 | 114 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 115 | 116 | uint32_t ctrl_reg = ptr_uart->control; 117 | ctrl_reg = ( UART_CONTROL_STPBRK | UART_CONTROL_TXDIS | UART_CONTROL_RXDIS ); 118 | ptr_uart->control = ctrl_reg; 119 | } 120 | 121 | /** 122 | * UART baudrate set 123 | * 124 | * @param uart_id = ID uart 125 | * baud_rate = baudrate speed of the uart 126 | * 127 | * @retval TRUE in sucess; FALSE in case error 128 | */ 129 | uint32_t uart_set_baud_rate(uint8_t uart_id, uint32_t baud_rate){ 130 | 131 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 132 | 133 | //uint32_t sel_clk = UART_FREQ_CLK; 134 | uint8_t bdiv = 0; 135 | uint16_t cd_calc = 0; 136 | 137 | /** Handling corner case */ 138 | if(baud_rate == 0){ 139 | baud_rate = UART_BAUD_RATE; 140 | } 141 | 142 | /* baud_rate = sel_clk / (CD * (BDIV+1)) 143 | * baud_rate -> Baud Rate 144 | * sel_clk -> Selected Clock 145 | * CD -> Baud Rate Generator 146 | * BDIV -> Baud Rate Divider 147 | */ 148 | /** FIXME - Handling statically 115200 */ 149 | bdiv = UART_BDIV_115200; 150 | cd_calc = UART_CD_115200; 151 | 152 | /** Configure the Baud Rate */ 153 | /* Disable the Rx and Tx path */ 154 | ptr_uart->control = (UART_CONTROL_RXDIS|UART_CONTROL_TXDIS); 155 | /* Write the calculated CD value */ 156 | ptr_uart->br_gen = cd_calc; 157 | /* Write the calculated BDIV value */ 158 | ptr_uart->br_div = bdiv; 159 | /* Reset Tx and Rx paths */ 160 | ptr_uart->control = (UART_CONTROL_TXRES|UART_CONTROL_RXRES); 161 | /* Enable the Rx and Tx path */ 162 | ptr_uart->control = (UART_CONTROL_TXEN|UART_CONTROL_RXEN); 163 | 164 | return TRUE; 165 | } 166 | 167 | /** 168 | * UART get character 169 | * 170 | * @param uart_id = ID uart 171 | * baud_rate = baudrate speed of the uart 172 | * 173 | * @retval Received character 174 | */ 175 | uint32_t uart_getc(uint8_t uart_id){ 176 | 177 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 178 | uint32_t data = 0; 179 | 180 | /* Wait until RxFIFO is filled up to the trigger level */ 181 | while(!ptr_uart->ch_status & UART_CH_STATUS_RTRIG); 182 | 183 | data = ptr_uart->tx_rx_fifo; 184 | 185 | return data; 186 | } 187 | 188 | /** 189 | * UART send character 190 | * 191 | * @param uart_id = ID uart 192 | * c = Character to be sent 193 | * 194 | * @retval 195 | */ 196 | void uart_putc(uint8_t uart_id,int8_t c){ 197 | 198 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 199 | 200 | //wait until txFIFO is not full 201 | while(ptr_uart->ch_status & UART_CH_STATUS_TFUL); 202 | 203 | ptr_uart->tx_rx_fifo = c; 204 | 205 | } 206 | 207 | /** 208 | * UART send string 209 | * 210 | * @param uart_id = ID uart 211 | * c = String to be sent 212 | * 213 | * @retval 214 | */ 215 | void uart_puts(uint8_t uart_id, const int8_t *s){ 216 | 217 | while (*s){ 218 | uart_putc(uart_id,*s++); 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /src/boards/zybo/board.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [board.c] 42 | * 43 | * This file contains board-specific initializations. 44 | * 45 | * (#) $id: board.c 15-10-2015 s_pinto & j_pereira $ 46 | * (#) $id: board.c 20-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #include 50 | 51 | /** 52 | * TrustZone-specific initializations 53 | * 54 | * @param 55 | * 56 | * @retval 57 | */ 58 | uint32_t board_init(void){ 59 | 60 | /** Unlocking SLCR register */ 61 | write32( (void *)SLCR_UNLOCK, SLCR_UNLOCK_KEY); 62 | 63 | /** Handling memory security */ 64 | write32( (void *)TZ_OCM_RAM0, 0xffffffff); 65 | write32( (void *)TZ_OCM_RAM1, 0xffffffff); 66 | write32( (void *)TZ_OCM, 0xffffffff); 67 | /* Handling DDR memory security (first 14segments NS)l */ 68 | write32( (void *)TZ_DDR_RAM, 0x0000007f); 69 | printk(" * Memory security - OK \n\t"); 70 | 71 | /** Handling devices security */ 72 | /* SDIO0 slave security (NS) */ 73 | write32( (void *)SECURITY2_SDIO0, 0x1); 74 | /* SDIO1 slave security (NS) */ 75 | write32( (void *)SECURITY3_SDIO1, 0x1); 76 | /* QSPI slave security (NS) */ 77 | write32( (void *)SECURITY4_QSPI, 0x1); 78 | /* APB slave security (NS) */ 79 | write32( (void *) SECURITY6_APBSL, 0x00007fff); 80 | /* DMA slave security (S) */ 81 | write32( (void *)TZ_DMA_NS, 0x0); 82 | write32( (void *)TZ_DMA_IRQ_NS, 0x0); 83 | /* Ethernet security */ 84 | write32( (void *)TZ_GEM, 0x3); 85 | /* FPGA AFI AXI ports TrustZone */ 86 | write32( (void *)SECURITY_APB, 0x3F); 87 | /* Handling more devices ... */ 88 | printk(" * Devices security - OK \n\t"); 89 | 90 | /** Locking SLCR register */ 91 | write32( (void *)SLCR_LOCK, SLCR_LOCK_KEY); 92 | 93 | return TRUE; 94 | } 95 | 96 | /** 97 | * Handling syscalls (SMCs) 98 | * 99 | * @param 100 | * 101 | * @retval 102 | */ 103 | uint32_t board_handler(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3) 104 | { 105 | switch(arg0) { 106 | case (LTZVISOR_READ_SYSCALL):{ 107 | arg0 = read32((volatile void*)arg1); 108 | break; 109 | } 110 | case (LTZVISOR_WRITE_SYSCALL):{ 111 | write32( (volatile void*)arg1, arg2); 112 | break; 113 | } 114 | default: 115 | 116 | break; 117 | } 118 | 119 | return arg0; 120 | } 121 | 122 | -------------------------------------------------------------------------------- /src/boards/zybo/inc/board.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [board.h] 42 | * 43 | * This file contains board-specific initializations (header). 44 | * 45 | * (#) $id: board.h 15-10-2015 s_pinto & j_pereira $ 46 | * (#) $id: board.h 20-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #ifndef __BOARD_H 50 | #define __BOARD_H 51 | 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | 58 | /** TrustZone on Xilinx Zynq-7000 (UG1019) */ 59 | 60 | #define SECURITY_MOD2 0xE0200000 61 | #define SECURITY2_SDIO0 (SECURITY_MOD2 + 0x8) 62 | #define SECURITY3_SDIO1 (SECURITY_MOD2 + 0xC) 63 | #define SECURITY4_QSPI (SECURITY_MOD2 + 0x10) 64 | #define SECURITY5_MIOU (SECURITY_MOD2 + 0x14) 65 | #define SECURITY6_APBSL (SECURITY_MOD2 + 0x18) 66 | #define SECURITY7_SMC (SECURITY_MOD2 + 0x1C) 67 | 68 | #define SLCR_BASE 0xF8000000 69 | #define SLCR_LOCK_KEY 0x767B 70 | #define SLCR_UNLOCK_KEY 0xDF0D 71 | #define SLCR_LOCK (SLCR_BASE + 0x4) 72 | #define SLCR_UNLOCK (SLCR_BASE + 0x8) 73 | #define DMAC_RST_CTRL (SLCR_BASE + 0x20C) 74 | #define TZ_OCM_RAM0 (SLCR_BASE + 0x400) 75 | #define TZ_OCM_RAM1 (SLCR_BASE + 0x404) 76 | #define TZ_OCM (SLCR_BASE + 0x408) 77 | #define TZ_DDR_RAM (SLCR_BASE + 0x430) 78 | #define TZ_DMA_NS (SLCR_BASE + 0x440) 79 | #define TZ_DMA_IRQ_NS (SLCR_BASE + 0x444) 80 | #define TZ_DMA_PERIPH_NS (SLCR_BASE + 0x448) 81 | #define TZ_GEM (SLCR_BASE + 0x450) 82 | #define TZ_SDIO (SLCR_BASE + 0x454) 83 | #define TZ_USB (SLCR_BASE + 0x458) 84 | #define TZ_FPGA_M (SLCR_BASE + 0x484) 85 | #define TZ_FPGA_AFI (SLCR_BASE + 0x488) 86 | 87 | #define SECURITY_MOD3 0xF8900000 88 | #define SECURITY_FSSW_S0 (SECURITY_MOD3 + 0x1C) 89 | #define SECURITY_FSSW_S1 (SECURITY_MOD3 + 0x20) 90 | #define SECURITY_APB (SECURITY_MOD3 + 0x28) 91 | 92 | /** 93 | * TrustZone-specific initializations 94 | * 95 | * @param 96 | * 97 | * @retval 98 | */ 99 | uint32_t board_init(void); 100 | 101 | /** 102 | * Handling syscalls (SMCs) 103 | * 104 | * @param 105 | * 106 | * @retval 107 | */ 108 | uint32_t board_handler(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3); 109 | 110 | #endif /* __BOARD_H */ 111 | -------------------------------------------------------------------------------- /src/boards/zybo/inc/ltzvisor_hw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [ltzvisor_hw.h] 42 | * 43 | * This file contains the LTZVisor hardware-specific initialization. 44 | * 45 | * (#) $id: ltzvisor_hw.h 10-06-2015 s_pinto & j_pereira $ 46 | * (#) $id: ltzvisor_hw.h 17-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #ifndef __LTZVISOR_HW_H 50 | #define __LTZVISOR_HW_H 51 | 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | #define ARCH "ARMv7-A" 60 | #define CPU "Cortex-A9" 61 | #define PLATFORM "Zynq-7000" 62 | 63 | #define LTZVISOR_MON_EXIT() {\ 64 | asm volatile("msr cpsr_c,#(0x13 | 0x80 | 0x40)");\ 65 | asm volatile("ldr r1,=_supervisor_stack");\ 66 | asm volatile("add r1, r1, r0, lsl #12");\ 67 | asm volatile("add sp, r1, #4096");\ 68 | } 69 | 70 | /** 71 | * LTZVisor hardware initialization 72 | * 73 | * @param 74 | * 75 | * @retval Return TRUE if success or False if not 76 | */ 77 | uint32_t ltzvisor_hw_init(void); 78 | 79 | #endif /* __LTZVISOR_HW_H */ 80 | -------------------------------------------------------------------------------- /src/boards/zybo/inc/platform_zynq.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [platform_zynq.h] 42 | * 43 | * This file contains board-specific register definitions (header). 44 | * 45 | * (#) $id: platform_zynq.h 15-10-2015 s_pinto & j_pereira $ 46 | * (#) $id: platform_zynq.h 20-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #ifndef __PLATF_ZYNQ_H 50 | #define __PLATF_ZYNQ_H 51 | 52 | #define XSCU_BASE 0xF8F00000 53 | 54 | #define GICC_OFFSET 0x0100 55 | #define GICD_OFFSET 0x1000 56 | #define MPIC_BASE (XSCU_BASE + GICC_OFFSET) 57 | #define MPID_BASE (XSCU_BASE + GICD_OFFSET) 58 | 59 | #define MPTW_BASE (XSCU_BASE + 0x0600) 60 | 61 | #define UART_BASE_0 0xE0000000 62 | #define UART_BASE_1 0xE0001000 63 | 64 | #define TTC0_BASE 0xF8001000 65 | #define TTC1_BASE 0xF8002000 66 | 67 | #endif /* __PLATF_ZYNQ_H */ 68 | -------------------------------------------------------------------------------- /src/boards/zybo/linker.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") 2 | OUTPUT_ARCH("arm") 3 | 4 | ENTRY(_reset_handler) 5 | 6 | 7 | MEMORY 8 | { 9 | OCM (rwx): ORIGIN = 0x00000000, LENGTH = 0x00030000 10 | DDR_NS (rwx) : ORIGIN = 0x00100000, LENGTH = 0x1BEFFFFF 11 | DDR_S (rwx) : ORIGIN = 0x1C000000, LENGTH = 0x03F00000 12 | } 13 | 14 | 15 | SECTIONS 16 | { 17 | _code_begin = .; 18 | 19 | .startup :{ 20 | __startup_start = .; 21 | *(.startup) 22 | __startup_end = .; 23 | } > DDR_S 24 | . = ALIGN(0x1000); 25 | 26 | .text : { 27 | *(.text) 28 | } > DDR_S 29 | . = ALIGN(0x1000); 30 | 31 | .data : { 32 | *(.data) 33 | } > DDR_S 34 | . = ALIGN(0x1000); 35 | 36 | .rodata : { 37 | *(.rodata) 38 | } > DDR_S 39 | . = ALIGN(0x1000); 40 | 41 | _SW_BSS_START = .; 42 | .bss : { 43 | *(.bss) 44 | *(COMMON) 45 | } > DDR_S 46 | . = ALIGN(0x1000); 47 | _bss_size = _SW_BSS_END - _SW_BSS_START; 48 | _SW_BSS_END = .; 49 | 50 | .heap (NOLOAD) : { 51 | . = ALIGN(16); 52 | _heap = .; 53 | HeapBase = .; 54 | PROVIDE(_heap_start = .); 55 | . += 0x2000; 56 | PROVIDE(_heap_end = .); 57 | HeapLimit = .; 58 | } > DDR_S 59 | _SW_CODE_END = .; 60 | } 61 | 62 | -------------------------------------------------------------------------------- /src/boards/zybo/ltzvisor_hw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This program is free software; you can redistribute it and/or 11 | * modify it under the terms of the GNU General Public License as 12 | * published by the Free Software Foundation; either version 2 of 13 | * the License, or (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | * 02110-1301 USA. 24 | * 25 | * [ltzvisor_hw.c] 26 | * 27 | * This file contains the LTZVisor hardware-specific initialization. 28 | * 29 | * (#) $id: ltzvisor_hw.c 10-06-2015 s_pinto & j_pereira $ 30 | * (#) $id: ltzvisor_hw.c 17-09-2017 s_pinto (modified)$ 31 | */ 32 | 33 | #include 34 | 35 | /** 36 | * LTZVisor hardware initialization 37 | * 38 | * @param 39 | * 40 | * @retval Return TRUE if success or False if not 41 | */ 42 | uint32_t ltzvisor_hw_init(void){ 43 | 44 | uint32_t ret = TRUE; 45 | uint32_t i; 46 | 47 | /** Init Serial Port */ 48 | for(i=0; i<10000; i++); //Comment if not running with U-boot 49 | ret = uart_init(1); 50 | if(!ret){ 51 | /* ERROR */ 52 | /* FIXME - Signal Error somewhere (LED) */ 53 | return ret; 54 | } 55 | 56 | printk("\n\n\t"); 57 | printk("----------------------------------------------------------\n\t"); 58 | printk(" LTZVisor (version %s) \n\t", VERSION); 59 | printk("----------------------------------------------------------\n\t"); 60 | printk(" -> Arch (%s): CPU (%s) initialization ... \n\t", ARCH, CPU); 61 | printk(" -> Arch (%s): GIC initialization ... \n\t", ARCH); 62 | 63 | /** Initialize GIC Distributer and GIC Interface*/ 64 | /* Distributor init */ 65 | ret = interrupt_distributor_init(); 66 | if(!ret){ 67 | 68 | /* ERROR */ 69 | printk("ERROR: GIC distributor init!\n\r"); 70 | return ret; 71 | } 72 | printk(" * GIC distributor - OK \n\t"); 73 | /* Interface init */ 74 | ret = interrupt_interface_init(); 75 | if(!ret){ 76 | 77 | /* ERROR */ 78 | printk("ERROR: GIC interface init!\n\r"); 79 | return ret; 80 | } 81 | printk(" * GIC interface - OK \n\t"); 82 | /* Config Interrupts Security */ 83 | interrupt_security_configall(); 84 | interrupt_security_config(UART_1_INTERRUPT,Int_NS); 85 | interrupt_security_config(TTC1_TTCx_2_INTERRUPT,Int_S); 86 | printk(" * GIC security - OK \n\t"); 87 | 88 | /** Initialize Platform-specific */ 89 | printk(" -> Platform (%s): initialization ... \n\t", PLATFORM); 90 | ret = board_init(); 91 | if(!ret){ 92 | /* ERROR */ 93 | printk("ERROR: Platform init!\n\r"); 94 | return ret; 95 | } 96 | 97 | return ret; 98 | } 99 | 100 | -------------------------------------------------------------------------------- /src/boards/zybo/objects.mk: -------------------------------------------------------------------------------- 1 | boards-objs-y = board.o 2 | boards-objs-y += zynq_uart.o 3 | boards-objs-y += zynq_ttc.o 4 | boards-objs-y += ltzvisor_hw.o 5 | -------------------------------------------------------------------------------- /src/boards/zybo/zynq_uart.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [zynq_uart.c] 42 | * 43 | * This file contains the Zynq UART driver (header). 44 | * 45 | * (#) $id: zynq_uart.c 20-10-2015 s_pinto$ 46 | * (#) $id: zynq_uart.c 19-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #include 50 | 51 | Uart_Zynq * const Ptr_Uart[NUM_UART] = {(Uart_Zynq *)UART_BASE_0,(Uart_Zynq *)UART_BASE_1}; 52 | 53 | 54 | /** 55 | * UART initialization (default 115200) 56 | * 57 | * @param uart_id = ID uart 58 | * 59 | * @retval TRUE in sucess; FALSE in case error 60 | */ 61 | uint32_t uart_init(uint8_t uart_id){ 62 | 63 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 64 | uint32_t ret; 65 | 66 | ret = uart_set_baud_rate(uart_id, UART_BAUD_RATE); 67 | if(ret == FALSE){ 68 | return FALSE; 69 | } 70 | 71 | /* Set the level of the RxFIFO trigger level */ 72 | ptr_uart->rx_fifo_trig = UART_RX_TRIGGER_LVL; 73 | /* Program the Receiver Timeout Mechanism (Disabled) */ 74 | ptr_uart->rx_timeout = UART_RX_TIMEOUT_DIS; 75 | 76 | /* Clear all the interrupts in Interrupt Status Register */ 77 | ptr_uart->isr_status = 0xFFFFFFFF; 78 | /* Enable RxFIFO Trigger Interrupt */ 79 | ptr_uart->isr_en = UART_ISR_EN_RTRIG; 80 | 81 | /** Enable the Controller */ 82 | ptr_uart->control |= (UART_CONTROL_STPBRK|UART_CONTROL_RXRES|UART_CONTROL_TXRES); 83 | 84 | return TRUE; 85 | } 86 | 87 | /** 88 | * UART enable 89 | * 90 | * @param uart_id = ID uart 91 | * 92 | * @retval 93 | */ 94 | void uart_enable(uint8_t uart_id){ 95 | 96 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 97 | 98 | uint32_t ctrl_reg = ptr_uart->control; 99 | ctrl_reg = ( UART_CONTROL_STPBRK | UART_CONTROL_TXEN | 100 | UART_CONTROL_RXEN | UART_CONTROL_RXRES | UART_CONTROL_TXRES ); 101 | ptr_uart->control = ctrl_reg; 102 | 103 | } 104 | 105 | /** 106 | * UART disable 107 | * 108 | * @param uart_id = ID uart 109 | * 110 | * @retval 111 | */ 112 | void uart_disable(uint8_t uart_id){ 113 | 114 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 115 | 116 | uint32_t ctrl_reg = ptr_uart->control; 117 | ctrl_reg = ( UART_CONTROL_STPBRK | UART_CONTROL_TXDIS | UART_CONTROL_RXDIS ); 118 | ptr_uart->control = ctrl_reg; 119 | } 120 | 121 | /** 122 | * UART baudrate set 123 | * 124 | * @param uart_id = ID uart 125 | * baud_rate = baudrate speed of the uart 126 | * 127 | * @retval TRUE in sucess; FALSE in case error 128 | */ 129 | uint32_t uart_set_baud_rate(uint8_t uart_id, uint32_t baud_rate){ 130 | 131 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 132 | 133 | //uint32_t sel_clk = UART_FREQ_CLK; 134 | uint8_t bdiv = 0; 135 | uint16_t cd_calc = 0; 136 | 137 | /** Handling corner case */ 138 | if(baud_rate == 0){ 139 | baud_rate = UART_BAUD_RATE; 140 | } 141 | 142 | /* baud_rate = sel_clk / (CD * (BDIV+1)) 143 | * baud_rate -> Baud Rate 144 | * sel_clk -> Selected Clock 145 | * CD -> Baud Rate Generator 146 | * BDIV -> Baud Rate Divider 147 | */ 148 | /** FIXME - Handling statically 115200 */ 149 | bdiv = UART_BDIV_115200; 150 | cd_calc = UART_CD_115200; 151 | 152 | /** Configure the Baud Rate */ 153 | /* Disable the Rx and Tx path */ 154 | ptr_uart->control = (UART_CONTROL_RXDIS|UART_CONTROL_TXDIS); 155 | /* Write the calculated CD value */ 156 | ptr_uart->br_gen = cd_calc; 157 | /* Write the calculated BDIV value */ 158 | ptr_uart->br_div = bdiv; 159 | /* Reset Tx and Rx paths */ 160 | ptr_uart->control = (UART_CONTROL_TXRES|UART_CONTROL_RXRES); 161 | /* Enable the Rx and Tx path */ 162 | ptr_uart->control = (UART_CONTROL_TXEN|UART_CONTROL_RXEN); 163 | 164 | return TRUE; 165 | } 166 | 167 | /** 168 | * UART get character 169 | * 170 | * @param uart_id = ID uart 171 | * baud_rate = baudrate speed of the uart 172 | * 173 | * @retval Received character 174 | */ 175 | uint32_t uart_getc(uint8_t uart_id){ 176 | 177 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 178 | uint32_t data = 0; 179 | 180 | /* Wait until RxFIFO is filled up to the trigger level */ 181 | while(!ptr_uart->ch_status & UART_CH_STATUS_RTRIG); 182 | 183 | data = ptr_uart->tx_rx_fifo; 184 | 185 | return data; 186 | } 187 | 188 | /** 189 | * UART send character 190 | * 191 | * @param uart_id = ID uart 192 | * c = Character to be sent 193 | * 194 | * @retval 195 | */ 196 | void uart_putc(uint8_t uart_id,int8_t c){ 197 | 198 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 199 | 200 | //wait until txFIFO is not full 201 | while(ptr_uart->ch_status & UART_CH_STATUS_TFUL); 202 | 203 | ptr_uart->tx_rx_fifo = c; 204 | 205 | } 206 | 207 | /** 208 | * UART send string 209 | * 210 | * @param uart_id = ID uart 211 | * c = String to be sent 212 | * 213 | * @retval 214 | */ 215 | void uart_puts(uint8_t uart_id, const int8_t *s){ 216 | 217 | while (*s){ 218 | uart_putc(uart_id,*s++); 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /src/core/inc/ltzvisor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [ltzvisor.h] 42 | * 43 | * This file contains the ltzvisor main entry point (header). 44 | * 45 | * (#) $id: ltzvisor.h 04-05-2015 s_pinto & j_pereira $ 46 | * (#) $id: ltzvisor.h 16-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #ifndef __LTZVISOR_H 50 | #define __LTZVISOR_H 51 | 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | #define VERSION "0.2.2" 60 | 61 | #define PREEMPTION 1 62 | #define NO_PREEMPTION 0 63 | 64 | typedef struct { 65 | struct vcpu_arch core; 66 | char_t name[30]; 67 | uint32_t id; 68 | uint32_t booting; 69 | }tzmachine; 70 | 71 | extern tzmachine NS_Guest; 72 | 73 | /** 74 | * LTZVisor main entry point 75 | * 76 | * @param 77 | * 78 | * @retval 79 | */ 80 | void ltzvisor_main(void); 81 | 82 | #endif /* __LTZVISOR_H */ 83 | -------------------------------------------------------------------------------- /src/core/inc/ltzvisor_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [ltzvisor_api.h] 42 | * 43 | * This file contains the LTZVisor API header. 44 | * 45 | * (#) $id: ltzvisor_api.h 10-06-2015 s_pinto & j_pereira $ 46 | * (#) $id: ltzvisor_api.h 18-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #ifndef __LTZVISOR_API_H 50 | #define __LTZVISOR_API_H 51 | 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | 61 | 62 | /** 63 | * LTZVisor initialization 64 | * 65 | * @param 66 | * 67 | * @retval 68 | */ 69 | uint32_t ltzvisor_init(void); 70 | 71 | /** 72 | * LTZVisor Kick off implementation 73 | * 74 | * @param 75 | * 76 | * @retval 77 | */ 78 | void ltzvisor_kickoff(void); 79 | 80 | /** 81 | * LTZVisor Scheduler 82 | * 83 | * @param 84 | * 85 | * @retval 86 | */ 87 | void ltzvisor_schedule(void); 88 | 89 | /** 90 | * LTZVisor NS_guest create 91 | * 92 | * @param g = pointer to guest configuration 93 | * 94 | * @retval TRUE if it is successful; FALSE if not! 95 | */ 96 | uint32_t ltzvisor_nsguest_create( struct nsguest_conf_entry *g ); 97 | 98 | /** 99 | * LTZVisor NS_guest restart 100 | * 101 | * @param g = pointer to guest configuration 102 | * 103 | * @retval TRUE if it is successful; FALSE if not! 104 | */ 105 | uint32_t ltzvisor_nsguest_restart( struct nsguest_conf_entry *g ); 106 | 107 | 108 | #endif /* __LTZVISOR_API_H */ 109 | -------------------------------------------------------------------------------- /src/core/inc/ltzvisor_syscall_asm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [ltzvisor_syscall_asm.h] 42 | * 43 | * This file contains LTZVisor syscalls definition. 44 | * 45 | * (#) $id: ltzvisor_syscall_asm.h 19-09-2017 s_pinto $ 46 | */ 47 | 48 | #ifndef __LTZVISOR_SYSCALL_ASM 49 | #define __LTZVISOR_SYSCALL_ASM 50 | 51 | /** SMC Identifiers for secure world functions */ 52 | #define LTZVISOR_SCHED_SYSCALL (0x0ffffff1) 53 | #define LTZVISOR_READ_SYSCALL (-30) 54 | #define LTZVISOR_WRITE_SYSCALL (-31) 55 | 56 | #endif /* __LTZVISOR_SYSCALL_ASM */ 57 | -------------------------------------------------------------------------------- /src/core/ltzvisor.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [ltzvisor.c] 42 | * 43 | * This file contains the ltzvisor main entry point. 44 | * 45 | * (#) $id: ltzvisor.c 04-05-2015 s_pinto & j_pereira $ 46 | * (#) $id: ltzvisor.c 16-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #include 50 | 51 | /** Config NS_Guest struct */ 52 | extern struct nsguest_conf_entry nsguest_config; 53 | 54 | /** NS_Guest context */ 55 | tzmachine NS_Guest __attribute__ ((aligned (4))) __attribute__ ((section (".bss"))); 56 | 57 | /** 58 | * LTZVisor main entry point 59 | * 60 | * @param 61 | * 62 | * @retval 63 | */ 64 | void ltzvisor_main(void){ 65 | uint32_t ret; 66 | 67 | /** Initialize LTZVisor */ 68 | ret = ltzvisor_init(); 69 | if(!ret){ 70 | /* ERROR */ 71 | printk("ERROR: LTZVisor Init ... \n\t"); 72 | while(1); 73 | } 74 | 75 | /** Create NS_Guest (Linux) */ 76 | printk(" -> Guests: NS_Guest creation ... \n\t", ARCH); 77 | ret = ltzvisor_nsguest_create( &nsguest_config ); 78 | if(!ret){ 79 | /* ERROR */ 80 | printk("Error: LTZVisor NS_Guest Create\n\t"); 81 | while(1); 82 | } 83 | 84 | /** Kick off LTZVisor and start running Guests */ 85 | printk(" -> LTZVisor: kicking off ... \n\t", ARCH); 86 | printk(" -> LTZVisor: starting S_Guest ... \n\t", ARCH); 87 | printk("----------------------------------------------------------\n\n\t"); 88 | ltzvisor_kickoff(); 89 | 90 | /** This point should never be reached */ 91 | while (1); 92 | } 93 | 94 | -------------------------------------------------------------------------------- /src/core/ltzvisor_api.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [ltzvisor_api.c] 42 | * 43 | * This file contains the LTZVisor API implementation. 44 | * 45 | * (#) $id: ltzvisor_api.c 10-06-2015 s_pinto & j_pereira $ 46 | * (#) $id: ltzvisor_api.c 18-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #include 50 | 51 | /** Main is part of the secure VM */ 52 | extern void main(void); 53 | 54 | /** 55 | * LTZVisor initialization 56 | * 57 | * @param 58 | * 59 | * @retval 60 | */ 61 | uint32_t ltzvisor_init(void){ 62 | 63 | uint32_t ret; 64 | 65 | /** Initialize LTZVisor-related hardware*/ 66 | ret = ltzvisor_hw_init(); 67 | 68 | /** Perform other hypervisor-related initializations here*/ 69 | 70 | return ret; 71 | } 72 | 73 | /** 74 | * LTZVisor Kick off implementation 75 | * 76 | * @param 77 | * 78 | * @retval 79 | */ 80 | void ltzvisor_kickoff(void){ 81 | 82 | /** Exit from Monitor mode */ 83 | LTZVISOR_MON_EXIT() 84 | 85 | /** Secure guest entry point */ 86 | main(); 87 | 88 | /** This point should never be reached */ 89 | while(1); 90 | } 91 | 92 | /** 93 | * LTZVisor Scheduler 94 | * 95 | * @param 96 | * 97 | * @retval 98 | */ 99 | void ltzvisor_schedule(void){ 100 | 101 | /** TODO - In case implementing a different scheduling policy */ 102 | while(1); 103 | 104 | } 105 | 106 | /** 107 | * LTZVisor NS_guest create 108 | * 109 | * @param g = pointer to guest configuration 110 | * 111 | * @retval TRUE if goes well; FALSE if not! 112 | */ 113 | uint32_t ltzvisor_nsguest_create( struct nsguest_conf_entry *g ) 114 | { 115 | 116 | /** Init Guest attributes */ 117 | NS_Guest.booting = 1; 118 | NS_Guest.id = g->gce_id; 119 | strcpy(NS_Guest.name, g->gce_name); 120 | printk(" * NS_Guest attributes - OK \n\t"); 121 | 122 | /** Guest Core Registers */ 123 | /* Clean core registers */ 124 | memset(&NS_Guest.core.vcpu_regs_core,0,sizeof(struct core_regs)); 125 | /* lr = start_addr & spsr=supervisor */ 126 | NS_Guest.core.vcpu_regs_core.lr_mon = g->gce_bin_load; 127 | NS_Guest.core.vcpu_regs_core.spsr_mon = 0x193; 128 | printk(" * NS_Guest core registers - OK \n\t"); 129 | 130 | /** Guest CP15 Registers */ 131 | /* Clean CP15 registers */ 132 | memset(&NS_Guest.core.vcpu_regs_cp15,0,sizeof(struct cp15_regs)); 133 | NS_Guest.core.vcpu_regs_cp15.c1_SCTLR = 0x00c50078; 134 | printk(" * NS_Guest CP15 registers - OK \n\t"); 135 | 136 | // #ifdef CONFIG_CACHE_L2X0 137 | NS_Guest.core.vcpu_regs_cp15.c1_ACTLR = 0x00000006; /* L1 prefetch enable -bit2- + L2 Prefetch hint enable -bit1-*/ 138 | printk(" * NS_Guest L2 Cache - OK \n\t"); 139 | // #endif 140 | 141 | /** Load Guest bin to Non-Secure Memory */ 142 | printk(" * NS_Guest loading ... \n\t"); 143 | printk(" * NS_Guest gce_bin_load: 0x%x \n\t", g->gce_bin_load); 144 | printk(" * NS_Guest gce_bin_start: 0x%x \n\t", g->gce_bin_start); 145 | printk(" * NS_Guest gce_bin_end: 0x%x \n\t", g->gce_bin_end); 146 | memcpy((uint32_t *)g->gce_bin_load,(uint32_t *)g->gce_bin_start,(g->gce_bin_end - g->gce_bin_start)); 147 | if(g->gce_trd_init) { 148 | memcpy((uint32_t *)g->gce_trd_load,(uint32_t *)g->gce_trd_start,(g->gce_trd_end - g->gce_trd_start)); 149 | } 150 | printk(" * NS_Guest load - OK \n\t"); 151 | 152 | /* Get NS_Guest ready to run */ 153 | cp15_restore(&NS_Guest.core.vcpu_regs_cp15); 154 | set_guest_context( (uint32_t)&NS_Guest); 155 | printk(" * NS_Guest ready to run - OK \n\t"); 156 | 157 | return TRUE; 158 | } 159 | 160 | /** 161 | * LTZVisor NS_guest restart 162 | * 163 | * @param g = pointer to guest configuration 164 | * 165 | * @retval TRUE if it is successful; FALSE if not! 166 | */ 167 | uint32_t ltzvisor_nsguest_restart( struct nsguest_conf_entry *g ){ 168 | 169 | /** TODO - Implement restart of NS_Guest */ 170 | while(1); 171 | } 172 | 173 | 174 | -------------------------------------------------------------------------------- /src/core/objects.mk: -------------------------------------------------------------------------------- 1 | core-objs-y = ltzvisor_api.o 2 | core-objs-y += ltzvisor.o 3 | 4 | -------------------------------------------------------------------------------- /src/drivers/common/objects.mk: -------------------------------------------------------------------------------- 1 | drivers-common-objs-y = gic.o 2 | -------------------------------------------------------------------------------- /src/drivers/objects.mk: -------------------------------------------------------------------------------- 1 | drivers-common-objs-y = gic.o 2 | -------------------------------------------------------------------------------- /src/drivers/zynq/board.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [board.c] 42 | * 43 | * This file contains board-specific initializations. 44 | * 45 | * (#) $id: board.c 15-10-2015 s_pinto & j_pereira $ 46 | * (#) $id: board.c 20-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #include 50 | 51 | /** 52 | * TrustZone-specific initializations 53 | * 54 | * @param 55 | * 56 | * @retval 57 | */ 58 | uint32_t board_init(void){ 59 | 60 | /** Unlocking SLCR register */ 61 | write32( (void *)SLCR_UNLOCK, SLCR_UNLOCK_KEY); 62 | 63 | /** Handling memory security */ 64 | write32( (void *)TZ_OCM_RAM0, 0xffffffff); 65 | write32( (void *)TZ_OCM_RAM1, 0xffffffff); 66 | write32( (void *)TZ_OCM, 0xffffffff); 67 | /* Handling DDR memory security (first 14segments NS)l */ 68 | write32( (void *)TZ_DDR_RAM, 0x00007fff); 69 | printk(" * Memory security - OK \n\t"); 70 | 71 | /** Handling devices security */ 72 | /* SDIO0 slave security (NS) */ 73 | write32( (void *)SECURITY2_SDIO0, 0x1); 74 | /* SDIO1 slave security (NS) */ 75 | write32( (void *)SECURITY3_SDIO1, 0x1); 76 | /* QSPI slave security (NS) */ 77 | write32( (void *)SECURITY4_QSPI, 0x1); 78 | /* APB slave security (NS) */ 79 | write32( (void *) SECURITY6_APBSL, 0x00007fff); 80 | /* DMA slave security (S) */ 81 | write32( (void *)TZ_DMA_NS, 0x0); 82 | write32( (void *)TZ_DMA_IRQ_NS, 0x0); 83 | /* Ethernet security */ 84 | write32( (void *)TZ_GEM, 0x3); 85 | /* FPGA AFI AXI ports TrustZone */ 86 | write32( (void *)SECURITY_APB, 0x3F); 87 | /* Handling more devices ... */ 88 | printk(" * Devices security - OK \n\t"); 89 | 90 | /** Locking SLCR register */ 91 | write32( (void *)SLCR_LOCK, SLCR_LOCK_KEY); 92 | 93 | return TRUE; 94 | } 95 | 96 | /** 97 | * Handling syscalls (SMCs) 98 | * 99 | * @param 100 | * 101 | * @retval 102 | */ 103 | uint32_t board_handler(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3) 104 | { 105 | switch(arg0) { 106 | case (LTZVISOR_READ_SYSCALL):{ 107 | arg0 = read32((volatile void*)arg1); 108 | break; 109 | } 110 | case (LTZVISOR_WRITE_SYSCALL):{ 111 | write32( (volatile void*)arg1, arg2); 112 | break; 113 | } 114 | default: 115 | 116 | break; 117 | } 118 | 119 | return arg0; 120 | } 121 | 122 | -------------------------------------------------------------------------------- /src/drivers/zynq/inc/board.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [board.h] 42 | * 43 | * This file contains board-specific initializations (header). 44 | * 45 | * (#) $id: board.h 15-10-2015 s_pinto & j_pereira $ 46 | * (#) $id: board.h 20-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #ifndef __BOARD_H 50 | #define __BOARD_H 51 | 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | 58 | /** TrustZone on Xilinx Zynq-7000 (UG1019) */ 59 | 60 | #define SECURITY_MOD2 0xE0200000 61 | #define SECURITY2_SDIO0 (SECURITY_MOD2 + 0x8) 62 | #define SECURITY3_SDIO1 (SECURITY_MOD2 + 0xC) 63 | #define SECURITY4_QSPI (SECURITY_MOD2 + 0x10) 64 | #define SECURITY5_MIOU (SECURITY_MOD2 + 0x14) 65 | #define SECURITY6_APBSL (SECURITY_MOD2 + 0x18) 66 | #define SECURITY7_SMC (SECURITY_MOD2 + 0x1C) 67 | 68 | #define SLCR_BASE 0xF8000000 69 | #define SLCR_LOCK_KEY 0x767B 70 | #define SLCR_UNLOCK_KEY 0xDF0D 71 | #define SLCR_LOCK (SLCR_BASE + 0x4) 72 | #define SLCR_UNLOCK (SLCR_BASE + 0x8) 73 | #define DMAC_RST_CTRL (SLCR_BASE + 0x20C) 74 | #define TZ_OCM_RAM0 (SLCR_BASE + 0x400) 75 | #define TZ_OCM_RAM1 (SLCR_BASE + 0x404) 76 | #define TZ_OCM (SLCR_BASE + 0x408) 77 | #define TZ_DDR_RAM (SLCR_BASE + 0x430) 78 | #define TZ_DMA_NS (SLCR_BASE + 0x440) 79 | #define TZ_DMA_IRQ_NS (SLCR_BASE + 0x444) 80 | #define TZ_DMA_PERIPH_NS (SLCR_BASE + 0x448) 81 | #define TZ_GEM (SLCR_BASE + 0x450) 82 | #define TZ_SDIO (SLCR_BASE + 0x454) 83 | #define TZ_USB (SLCR_BASE + 0x458) 84 | #define TZ_FPGA_M (SLCR_BASE + 0x484) 85 | #define TZ_FPGA_AFI (SLCR_BASE + 0x488) 86 | 87 | #define SECURITY_MOD3 0xF8900000 88 | #define SECURITY_FSSW_S0 (SECURITY_MOD3 + 0x1C) 89 | #define SECURITY_FSSW_S1 (SECURITY_MOD3 + 0x20) 90 | #define SECURITY_APB (SECURITY_MOD3 + 0x28) 91 | 92 | /** 93 | * TrustZone-specific initializations 94 | * 95 | * @param 96 | * 97 | * @retval 98 | */ 99 | uint32_t board_init(void); 100 | 101 | /** 102 | * Handling syscalls (SMCs) 103 | * 104 | * @param 105 | * 106 | * @retval 107 | */ 108 | uint32_t board_handler(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3); 109 | 110 | #endif /* __BOARD_H */ 111 | -------------------------------------------------------------------------------- /src/drivers/zynq/inc/ltzvisor_hw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [ltzvisor_hw.h] 42 | * 43 | * This file contains the LTZVisor hardware-specific initialization. 44 | * 45 | * (#) $id: ltzvisor_hw.h 10-06-2015 s_pinto & j_pereira $ 46 | * (#) $id: ltzvisor_hw.h 17-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #ifndef __LTZVISOR_HW_H 50 | #define __LTZVISOR_HW_H 51 | 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | 60 | #define ARCH "ARMv7-A" 61 | #define CPU "Cortex-A9" 62 | #define PLATFORM "Zynq-7000" 63 | 64 | #define LTZVISOR_MON_EXIT() {\ 65 | asm volatile("msr cpsr_c,#(0x13 | 0x80 | 0x40)");\ 66 | asm volatile("ldr r1,=_supervisor_stack");\ 67 | asm volatile("add r1, r1, r0, lsl #12");\ 68 | asm volatile("add sp, r1, #4096");\ 69 | } 70 | 71 | /** 72 | * LTZVisor hardware initialization 73 | * 74 | * @param 75 | * 76 | * @retval Return TRUE if success or False if not 77 | */ 78 | uint32_t ltzvisor_hw_init(void); 79 | 80 | #endif /* __LTZVISOR_HW_H */ 81 | -------------------------------------------------------------------------------- /src/drivers/zynq/inc/platform_zynq.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [platform_zynq.h] 42 | * 43 | * This file contains board-specific register definitions (header). 44 | * 45 | * (#) $id: platform_zynq.h 15-10-2015 s_pinto & j_pereira $ 46 | * (#) $id: platform_zynq.h 20-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #ifndef __PLATF_ZYNQ_H 50 | #define __PLATF_ZYNQ_H 51 | 52 | #define XSCU_BASE 0xF8F00000 53 | 54 | #define GICC_OFFSET 0x0100 55 | #define GICD_OFFSET 0x1000 56 | #define MPIC_BASE (XSCU_BASE + GICC_OFFSET) 57 | #define MPID_BASE (XSCU_BASE + GICD_OFFSET) 58 | 59 | #define MPTW_BASE (XSCU_BASE + 0x0600) 60 | 61 | #define UART_BASE_0 0xE0000000 62 | #define UART_BASE_1 0xE0001000 63 | 64 | #define TTC0_BASE 0xF8001000 65 | #define TTC1_BASE 0xF8002000 66 | 67 | #endif /* __PLATF_ZYNQ_H */ 68 | -------------------------------------------------------------------------------- /src/drivers/zynq/linker.ld: -------------------------------------------------------------------------------- 1 | OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") 2 | OUTPUT_ARCH("arm") 3 | 4 | ENTRY(_reset_handler) 5 | 6 | phy_offset = 0x3C000000; 7 | 8 | 9 | SECTIONS 10 | { 11 | . = phy_offset; 12 | _code_begin = .; 13 | 14 | .text : { 15 | *(.text) 16 | } 17 | . = ALIGN(0x1000); 18 | 19 | .data : { 20 | *(.data) 21 | } 22 | . = ALIGN(0x1000); 23 | 24 | .rodata : { 25 | *(.rodata) 26 | } 27 | . = ALIGN(0x1000); 28 | 29 | _SW_BSS_START = .; 30 | .bss : { 31 | *(.bss) 32 | *(COMMON) 33 | } 34 | . = ALIGN(0x1000); 35 | _bss_size = _SW_BSS_END - _SW_BSS_START; 36 | _SW_BSS_END = .; 37 | 38 | .heap (NOLOAD) : { 39 | . = ALIGN(16); 40 | _heap = .; 41 | HeapBase = .; 42 | PROVIDE(_heap_start = .); 43 | . += 0x2000; 44 | PROVIDE(_heap_end = .); 45 | HeapLimit = .; 46 | } 47 | _SW_CODE_END = .; 48 | } 49 | -------------------------------------------------------------------------------- /src/drivers/zynq/ltzvisor_hw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This program is free software; you can redistribute it and/or 11 | * modify it under the terms of the GNU General Public License as 12 | * published by the Free Software Foundation; either version 2 of 13 | * the License, or (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | * 02110-1301 USA. 24 | * 25 | * [ltzvisor_hw.c] 26 | * 27 | * This file contains the LTZVisor hardware-specific initialization. 28 | * 29 | * (#) $id: ltzvisor_hw.c 10-06-2015 s_pinto & j_pereira $ 30 | * (#) $id: ltzvisor_hw.c 17-09-2017 s_pinto (modified)$ 31 | */ 32 | 33 | #include 34 | 35 | /** 36 | * LTZVisor hardware initialization 37 | * 38 | * @param 39 | * 40 | * @retval Return TRUE if success or False if not 41 | */ 42 | uint32_t ltzvisor_hw_init(void){ 43 | 44 | uint32_t ret = TRUE; 45 | uint32_t i; 46 | 47 | /** Init Serial Port */ 48 | for(i=0; i<10000; i++); //Comment if not running with U-boot 49 | ret = uart_init(1); 50 | if(!ret){ 51 | /* ERROR */ 52 | /* FIXME - Signal Error somewhere (LED) */ 53 | return ret; 54 | } 55 | 56 | printk("\n\n\t"); 57 | printk("----------------------------------------------------------\n\t"); 58 | printk(" LTZVisor (version %s) \n\t", VERSION); 59 | printk("----------------------------------------------------------\n\t"); 60 | printk(" -> Arch (%s): CPU (%s) initialization ... \n\t", ARCH, CPU); 61 | printk(" -> Arch (%s): GIC initialization ... \n\t", ARCH); 62 | 63 | /** Initialize GIC Distributer and GIC Interface*/ 64 | /* Distributor init */ 65 | ret = interrupt_distributor_init(); 66 | if(!ret){ 67 | 68 | /* ERROR */ 69 | printk("ERROR: GIC distributor init!\n\r"); 70 | return ret; 71 | } 72 | printk(" * GIC distributor - OK \n\t"); 73 | /* Interface init */ 74 | ret = interrupt_interface_init(); 75 | if(!ret){ 76 | 77 | /* ERROR */ 78 | printk("ERROR: GIC interface init!\n\r"); 79 | return ret; 80 | } 81 | printk(" * GIC interface - OK \n\t"); 82 | /* Config Interrupts Security */ 83 | interrupt_security_configall(); 84 | interrupt_security_config(UART_1_INTERRUPT,Int_NS); 85 | interrupt_security_config(TTC1_TTCx_2_INTERRUPT,Int_S); 86 | printk(" * GIC security - OK \n\t"); 87 | 88 | /** Initialize Platform-specific */ 89 | printk(" -> Platform (%s): initialization ... \n\t", PLATFORM); 90 | ret = board_init(); 91 | if(!ret){ 92 | /* ERROR */ 93 | printk("ERROR: Platform init!\n\r"); 94 | return ret; 95 | } 96 | 97 | return ret; 98 | } 99 | 100 | -------------------------------------------------------------------------------- /src/drivers/zynq/objects.mk: -------------------------------------------------------------------------------- 1 | drivers-objs-y += board.o 2 | drivers-objs-y += xilinx_uart.o 3 | drivers-objs-y += zynq_ttc.o 4 | drivers-objs-y += ltzvisor_hw.o 5 | -------------------------------------------------------------------------------- /src/drivers/zynq/xilinx_uart.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [xilinx_uart.c] 42 | * 43 | * This file contains the Zynq UART driver (header). 44 | * 45 | * (#) $id: xilinx_uart.c 20-10-2015 s_pinto$ 46 | * (#) $id: xilinx_uart.c 19-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #include 50 | 51 | Uart_Zynq * const Ptr_Uart[NUM_UART] = {(Uart_Zynq *)UART_BASE_0,(Uart_Zynq *)UART_BASE_1}; 52 | 53 | 54 | /** 55 | * UART initialization (default 115200) 56 | * 57 | * @param uart_id = ID uart 58 | * 59 | * @retval TRUE in sucess; FALSE in case error 60 | */ 61 | uint32_t uart_init(uint8_t uart_id){ 62 | 63 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 64 | uint32_t ret; 65 | 66 | ret = uart_set_baud_rate(uart_id, UART_BAUD_RATE); 67 | if(ret == FALSE){ 68 | return FALSE; 69 | } 70 | 71 | /* Set the level of the RxFIFO trigger level */ 72 | ptr_uart->rx_fifo_trig = UART_RX_TRIGGER_LVL; 73 | /* Program the Receiver Timeout Mechanism (Disabled) */ 74 | ptr_uart->rx_timeout = UART_RX_TIMEOUT_DIS; 75 | 76 | /* Clear all the interrupts in Interrupt Status Register */ 77 | ptr_uart->isr_status = 0xFFFFFFFF; 78 | /* Enable RxFIFO Trigger Interrupt */ 79 | ptr_uart->isr_en = UART_ISR_EN_RTRIG; 80 | 81 | /** Enable the Controller */ 82 | ptr_uart->control |= (UART_CONTROL_STPBRK|UART_CONTROL_RXRES|UART_CONTROL_TXRES); 83 | 84 | return TRUE; 85 | } 86 | 87 | /** 88 | * UART enable 89 | * 90 | * @param uart_id = ID uart 91 | * 92 | * @retval 93 | */ 94 | void uart_enable(uint8_t uart_id){ 95 | 96 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 97 | 98 | uint32_t ctrl_reg = ptr_uart->control; 99 | ctrl_reg = ( UART_CONTROL_STPBRK | UART_CONTROL_TXEN | 100 | UART_CONTROL_RXEN | UART_CONTROL_RXRES | UART_CONTROL_TXRES ); 101 | ptr_uart->control = ctrl_reg; 102 | 103 | } 104 | 105 | /** 106 | * UART disable 107 | * 108 | * @param uart_id = ID uart 109 | * 110 | * @retval 111 | */ 112 | void uart_disable(uint8_t uart_id){ 113 | 114 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 115 | 116 | uint32_t ctrl_reg = ptr_uart->control; 117 | ctrl_reg = ( UART_CONTROL_STPBRK | UART_CONTROL_TXDIS | UART_CONTROL_RXDIS ); 118 | ptr_uart->control = ctrl_reg; 119 | } 120 | 121 | /** 122 | * UART baudrate set 123 | * 124 | * @param uart_id = ID uart 125 | * baud_rate = baudrate speed of the uart 126 | * 127 | * @retval TRUE in sucess; FALSE in case error 128 | */ 129 | uint32_t uart_set_baud_rate(uint8_t uart_id, uint32_t baud_rate){ 130 | 131 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 132 | 133 | uint32_t sel_clk = UART_FREQ_CLK; 134 | uint8_t bdiv = 0; 135 | uint16_t cd_calc = 0; 136 | 137 | /** Handling corner case */ 138 | if(baud_rate == 0){ 139 | baud_rate = UART_BAUD_RATE; 140 | } 141 | 142 | /* baud_rate = sel_clk / (CD * (BDIV+1)) 143 | * baud_rate -> Baud Rate 144 | * sel_clk -> Selected Clock 145 | * CD -> Baud Rate Generator 146 | * BDIV -> Baud Rate Divider 147 | */ 148 | /** FIXME - Handling statically 115200 */ 149 | bdiv = UART_BDIV_115200; 150 | cd_calc = UART_CD_115200; 151 | 152 | /** Configure the Baud Rate */ 153 | /* Disable the Rx and Tx path */ 154 | ptr_uart->control = (UART_CONTROL_RXDIS|UART_CONTROL_TXDIS); 155 | /* Write the calculated CD value */ 156 | ptr_uart->br_gen = cd_calc; 157 | /* Write the calculated BDIV value */ 158 | ptr_uart->br_div = bdiv; 159 | /* Reset Tx and Rx paths */ 160 | ptr_uart->control = (UART_CONTROL_TXRES|UART_CONTROL_RXRES); 161 | /* Enable the Rx and Tx path */ 162 | ptr_uart->control = (UART_CONTROL_TXEN|UART_CONTROL_RXEN); 163 | 164 | return TRUE; 165 | } 166 | 167 | /** 168 | * UART get character 169 | * 170 | * @param uart_id = ID uart 171 | * baud_rate = baudrate speed of the uart 172 | * 173 | * @retval Received character 174 | */ 175 | uint32_t uart_getc(uint8_t uart_id){ 176 | 177 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 178 | uint32_t data = 0; 179 | 180 | /* Wait until RxFIFO is filled up to the trigger level */ 181 | while(!ptr_uart->ch_status & UART_CH_STATUS_RTRIG); 182 | 183 | data = ptr_uart->tx_rx_fifo; 184 | 185 | return data; 186 | } 187 | 188 | /** 189 | * UART send character 190 | * 191 | * @param uart_id = ID uart 192 | * c = Character to be sent 193 | * 194 | * @retval 195 | */ 196 | void uart_putc(uint8_t uart_id,int8_t c){ 197 | 198 | Uart_Zynq * ptr_uart = Ptr_Uart[uart_id]; 199 | 200 | //wait until txFIFO is not full 201 | while(ptr_uart->ch_status & UART_CH_STATUS_TFUL); 202 | 203 | ptr_uart->tx_rx_fifo = c; 204 | 205 | } 206 | 207 | /** 208 | * UART send string 209 | * 210 | * @param uart_id = ID uart 211 | * c = String to be sent 212 | * 213 | * @retval 214 | */ 215 | void uart_puts(uint8_t uart_id,const int8_t *s){ 216 | 217 | while (*s){ 218 | uart_putc(uart_id,*s++); 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /src/lib/inc/io.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [io.h] 42 | * 43 | * This file contains read/write address operations (header). 44 | * 45 | * (#) $id: io.h 01-09-2015 s_pinto & j_pereira $ 46 | */ 47 | 48 | #ifndef __IO_H 49 | #define __IO_H 50 | 51 | #include 52 | 53 | /** 54 | * Read a 32-bit address 55 | * 56 | * @param addr = pointer to address 57 | * 58 | * @retval content of address 59 | */ 60 | uint32_t read32( volatile void *addr ); 61 | 62 | /** 63 | * Read a 32-bit address 64 | * 65 | * @param addr = pointer to address 66 | * 67 | * @retval content of address 68 | */ 69 | void write32( volatile void *addr, uint32_t data ); 70 | 71 | #endif /* __IO_H */ 72 | -------------------------------------------------------------------------------- /src/lib/inc/math.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [math.h] 42 | * 43 | * This file contains math library related code (header). 44 | * 45 | * (#) $id: math.h 01-09-2015 s_pinto & j_pereira $ 46 | * (#) $id: math.h 18-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #ifndef __MATH_H 50 | #define __MATH_H 51 | 52 | #include 53 | 54 | /** 55 | * Check if is pow of 2 56 | * 57 | * @param number = value whose pow of 2 58 | * 59 | * @retval pow of 2 of x 60 | */ 61 | inline int is_pow_of_2(big_ulong x); 62 | 63 | /** 64 | * Compute next pow of 2 65 | * 66 | * @param number = value whose pow is calculated 67 | * 68 | * @retval next pow of 2 of x 69 | */ 70 | inline uint32_t next_pow_of_2(uint32_t x); 71 | 72 | /** 73 | * Compute binary logarithm 74 | * 75 | * @param number = value whose logarithm is calculated 76 | * 77 | * @retval binary logarithm of number 78 | */ 79 | uint32_t log_of_2(uint32_t number); 80 | 81 | 82 | #endif /* __MATH_H */ 83 | -------------------------------------------------------------------------------- /src/lib/inc/printk.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [printk.h] 42 | * 43 | * This file contains PRINTK implementation (header). 44 | * 45 | * (#) $id: printk.h 01-09-2015 s_pinto & j_pereira $ 46 | * (#) $id: printk.h 18-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | /** 50 | * @file stdio_functions.h 51 | * @author Jorge Pereira & Sandro Pinto 52 | * @version 1.0 53 | * @date 19 October, 2015 54 | * @brief Stdio functions Header File 55 | */ 56 | 57 | #ifndef __PRINTK_H 58 | #define __PRINTK_H 59 | 60 | #include 61 | #include 62 | #include 63 | 64 | typedef char *va_list; 65 | 66 | #define ALIGNBND (sizeof (signed int) - 1) 67 | 68 | #define bnd(X, bnd) (((sizeof (X)) + (bnd)) & (~(bnd))) 69 | 70 | #define va_arg(ap, T) (*(T *)(((ap) += (bnd (T, ALIGNBND))) - (bnd (T,ALIGNBND)))) 71 | 72 | #define va_end(ap) (void) 0 73 | 74 | #define va_start(ap, A) (void) ((ap) = (((char *) &(A)) + (bnd (A,ALIGNBND)))) 75 | 76 | #define PRINT_TEXT_LEN 0x100 77 | 78 | /** 79 | * Print formatted data to stdout 80 | * 81 | * @param fmt = 82 | * 83 | * @retval 84 | */ 85 | uint32_t printk(const char *fmt, ...); 86 | 87 | #endif /* __PRINTK_H */ 88 | -------------------------------------------------------------------------------- /src/lib/inc/string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This program is free software; you can redistribute it and/or 11 | * modify it under the terms of the GNU General Public License as 12 | * published by the Free Software Foundation; either version 2 of 13 | * the License, or (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23 | * 02110-1301 USA. 24 | * 25 | * [string.h] 26 | * 27 | * This file contains string library related code (header). 28 | * 29 | * (#) $id: string.h 04-07-2015 s_pinto & j_pereira $ 30 | * (#) $id: string.h 16-09-2017 s_pinto (modified)$ 31 | */ 32 | 33 | #ifndef __STRING_H_ 34 | #define __STRING_H_ 35 | 36 | #include 37 | 38 | /** 39 | * Copy block of memory 40 | * 41 | * @param dst = pointer to the destination array 42 | * src = pointer to the source of data to be copied 43 | * count = number of bytes to copy 44 | * 45 | * @retval destination is returned 46 | */ 47 | void *memcpy(void *dst, const void *src, uint32_t count); 48 | 49 | /** 50 | * Fill block of memory 51 | * 52 | * @param dst = pointer to the block of memory 53 | * c = value to be set 54 | * count = number of bytes to be set 55 | * 56 | * @retval pointer to the block of memory is returned 57 | */ 58 | void *memset(void * dest, uint32_t c, uint32_t count); 59 | 60 | /** 61 | * Concatenate strings 62 | * 63 | * @param dest = pointer to the destination array 64 | * src = C string to be appended 65 | * 66 | * @retval destination is returned 67 | */ 68 | char_t * strcat(char_t *dest, cchar_t *src); 69 | 70 | 71 | /** 72 | * Get string length 73 | * 74 | * @param s = C string 75 | * 76 | * @retval The length of string 77 | */ 78 | uint32_t strlen(char_t * s); 79 | 80 | /** 81 | * Get fixed-size string length 82 | * 83 | * @param S = C string 84 | * n = lsize 85 | * 86 | * @retval The length of string 87 | */ 88 | uint32_t strnlen(char_t * s, size_t n); 89 | 90 | /** 91 | * Copy string 92 | * 93 | * @param dest = pointer to the destination array 94 | * src = C string to be copied 95 | * 96 | * @retval destination is returned 97 | */ 98 | char_t * strcpy(char_t * dest, char_t * src); 99 | 100 | #endif /* __STRING_H_ */ 101 | -------------------------------------------------------------------------------- /src/lib/io.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [io.c] 42 | * 43 | * This file contains read/write address operations. 44 | * 45 | * (#) $id: io.c 01-09-2015 s_pinto & j_pereira $ 46 | */ 47 | 48 | #include 49 | 50 | /** 51 | * Read a 32-bit address 52 | * 53 | * @param addr = pointer of address 54 | * 55 | * @retval value pointed by addr 56 | */ 57 | inline uint32_t read32( volatile void * addr ){ 58 | 59 | return *(uint32_t*)addr; 60 | } 61 | /** 62 | * Write in a 32-bit address 63 | * 64 | * @param addr = pointer of address 65 | * data = value 66 | * 67 | * @retval 68 | */ 69 | inline void write32( volatile void *addr, uint32_t data ){ 70 | 71 | *(uint32_t*)addr = data; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /src/lib/objects.mk: -------------------------------------------------------------------------------- 1 | lib-objs-y = string.o 2 | lib-objs-y += printk.o 3 | lib-objs-y += io.o 4 | -------------------------------------------------------------------------------- /src/lib/string.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [string.c] 42 | * 43 | * This file contains string library related code. 44 | * 45 | * (#) $id: string.c 04-07-2015 s_pinto & j_pereira $ 46 | * (#) $id: string.c 16-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #include 50 | 51 | /** 52 | * Copy block of memory 53 | * 54 | * @param dst = pointer to the destination array 55 | * src = pointer to the source of data to be copied 56 | * count = number of bytes to copy 57 | * 58 | * @retval destination is returned 59 | */ 60 | void * memcpy(void * dst, const void * src, uint32_t count) 61 | { 62 | int32_t i; 63 | char_t *dst_tmp = dst; 64 | const char_t *src_tmp = src; 65 | 66 | if (!((uint32_t)src & 0x3) && !((uint32_t)dst & 0x3)){ 67 | /** Word aligned - safe word copies */ 68 | for (i=0; i < count; i+=4){ 69 | if (i + 3 > count - 1) 70 | break; /* Don't copy too much */ 71 | *(uint32_t *)dst_tmp = *(uint32_t *)src_tmp; 72 | dst_tmp += 4; 73 | src_tmp += 4; 74 | } 75 | if (i <= count - 1){ 76 | for (; i < count; i++){ 77 | *dst_tmp = *src_tmp; 78 | dst_tmp++; 79 | src_tmp++; 80 | } 81 | } 82 | } 83 | else{ 84 | /* Generic version */ 85 | for (i=0; i < count; i++) 86 | dst_tmp[i] = src_tmp[i]; 87 | } 88 | return dst; 89 | } 90 | 91 | /** 92 | * Fill block of memory 93 | * 94 | * @param dst = pointer to the block of memory 95 | * c = value to be set 96 | * count = number of bytes to be set 97 | * 98 | * @retval pointer to the block of memory is returned 99 | */ 100 | void *memset(void * dest, uint32_t c, uint32_t count) 101 | { 102 | /** Standard bytewise memset */ 103 | char_t* d; 104 | d = (char_t*) dest; 105 | 106 | while(count--){ 107 | *d = c; 108 | d++; 109 | } 110 | 111 | return dest; 112 | } 113 | 114 | /** 115 | * Concatenate strings 116 | * 117 | * @param dest = pointer to the destination array 118 | * src = C string to be appended 119 | * 120 | * @retval destination is returned 121 | */ 122 | char_t * strcat(char_t *dest, cchar_t *src) 123 | { 124 | char_t *save = dest; 125 | 126 | for (; *dest; ++dest) ; 127 | while ((*dest++ = *src++) != 0) ; 128 | 129 | return (save); 130 | } 131 | 132 | /** 133 | * Get string length 134 | * 135 | * @param s = C string 136 | * 137 | * @retval The length of string 138 | */ 139 | uint32_t strlen(char_t * s){ 140 | 141 | char_t *sc; 142 | for (sc = s; *sc != '\0'; ++sc){ 143 | /* Do nothing */ 144 | } 145 | return sc - s; 146 | } 147 | 148 | /** 149 | * Get fixed-size string length 150 | * 151 | * @param S = C string 152 | * n = lsize 153 | * 154 | * @retval The length of string 155 | */ 156 | uint32_t strnlen(char_t * s, size_t n){ 157 | char_t *str; 158 | 159 | for(str = s; *str != '\0' && n-- ; ++str){ 160 | /* Do nothing */ 161 | } 162 | return str-s; 163 | } 164 | 165 | /** 166 | * Copy string 167 | * 168 | * @param dest = pointer to the destination array 169 | * src = C string to be copied 170 | * 171 | * @retval destination is returned 172 | */ 173 | char_t * strcpy(char_t * dest, char_t * src) 174 | { 175 | char_t *tmp = dest; 176 | 177 | while ((*dest++ = *src++) != '\0'){ 178 | /* Do nothing */ 179 | } 180 | return tmp; 181 | } 182 | 183 | -------------------------------------------------------------------------------- /src/ns_guest/inc/ltzvisor_nsguest_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [ltzvisor_nsguest_config.h] 42 | * 43 | * This file contains the LTZVisor NS Guest configuration (header). 44 | * 45 | * (#) $id: ltzvisor_nsguest_config.h 10-10-2015 s_pinto & j_pereira $ 46 | * (#) $id: ltzvisor_nsguest_config.h 18-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #ifndef __LTZVISOR_NSGUEST_CONFIG_H 50 | #define __LTZVISOR_NSGUEST_CONFIG_H 51 | 52 | #include 53 | 54 | /** NS Guest config structure */ 55 | struct nsguest_conf_entry { 56 | 57 | char_t gce_name[30]; 58 | uint32_t gce_id; 59 | /* Initial Ram Disk info */ 60 | uint32_t gce_trd_init; 61 | uint32_t gce_trd_start; 62 | uint32_t gce_trd_end; 63 | uint32_t gce_trd_load; 64 | /* Binary info */ 65 | uint32_t gce_bin_start; 66 | uint32_t gce_bin_end; 67 | uint32_t gce_bin_load; 68 | }; 69 | 70 | #endif /* __LTZVISOR_NSGUEST_CONFIG_H */ 71 | -------------------------------------------------------------------------------- /src/ns_guest/ltzvisor_nsguest.S: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [ltzvisor_nsguest.S] 42 | * 43 | * This file includes the NS Guest binary image. 44 | * 45 | * (#) $id: ltzvisor_nsguest.S 10-10-2015 s_pinto & j_pereira $ 46 | * (#) $id: ltzvisor_nsguest.S 18-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #include 50 | 51 | .section normal_image1, "a" 52 | 53 | .global GPOS0_start 54 | .global GPOS0_end 55 | GPOS0_start: 56 | #ifdef CONFIG_NS_BM 57 | .incbin "./ns_guest/zynq/baremetal.bin"; 58 | #else 59 | /* include OS binary here */ 60 | #endif 61 | GPOS0_end: 62 | -------------------------------------------------------------------------------- /src/ns_guest/ltzvisor_nsguest_config.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * Jorge Pereira 9 | * 10 | * This file is part of LTZVisor. 11 | * 12 | * LTZVisor is free software; you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License version 2 14 | * as published by the Free Software Foundation, with a special 15 | * exception described below. 16 | * 17 | * Linking this code statically or dynamically with other modules 18 | * is making a combined work based on this code. Thus, the terms 19 | * and conditions of the GNU General Public License V2 cover the 20 | * whole combination. 21 | * 22 | * As a special exception, the copyright holders of LTZVisor give 23 | * you permission to link LTZVisor with independent modules to 24 | * produce a statically linked executable, regardless of the license 25 | * terms of these independent modules, and to copy and distribute 26 | * the resulting executable under terms of your choice, provided that 27 | * you also meet, for each linked independent module, the terms and 28 | * conditions of the license of that module. An independent module 29 | * is a module which is not derived from or based on LTZVisor. 30 | * 31 | * LTZVisor is distributed in the hope that it will be useful, but 32 | * WITHOUT ANY WARRANTY; without even the implied warranty of 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | * GNU General Public License for more details. 35 | * 36 | * You should have received a copy of the GNU General Public License 37 | * along with this program; if not, write to the Free Software 38 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 39 | * 02110-1301 USA. 40 | * 41 | * [ltzvisor_nsguest_config.c] 42 | * 43 | * This file contains the LTZVisor NS Guest configuration. 44 | * 45 | * (#) $id: ltzvisor_nsguest_config.c 10-10-2015 s_pinto & j_pereira $ 46 | * (#) $id: ltzvisor_nsguest_config.c 18-09-2017 s_pinto (modified)$ 47 | */ 48 | 49 | #include 50 | 51 | /** Info from ltzvisor_nsguest.S */ 52 | extern uint32_t GPOS0_start, GPOS0_end; 53 | 54 | /** Config structure according to NS Guest */ 55 | struct nsguest_conf_entry nsguest_config[] ={ 56 | { 57 | .gce_name = "Linux 3.3 (vanilla)", 58 | .gce_id = 0, 59 | /* No ram disk needed */ 60 | .gce_trd_init = 0, 61 | /* Binary image size */ 62 | .gce_bin_start = (uint32_t) &GPOS0_start, 63 | .gce_bin_end = (uint32_t) &GPOS0_end, 64 | /* Load address */ 65 | .gce_bin_load = 0x00100000, 66 | 67 | } 68 | }; 69 | -------------------------------------------------------------------------------- /src/ns_guest/objects.mk: -------------------------------------------------------------------------------- 1 | ns_guest-objs-y = ltzvisor_nsguest.o 2 | ns_guest-objs-y += ltzvisor_nsguest_config.o 3 | -------------------------------------------------------------------------------- /src/ns_guest/zynq/README: -------------------------------------------------------------------------------- 1 | Non-Secure Guest OS binary image should be placed here! 2 | -------------------------------------------------------------------------------- /src/ns_guest/zynq/baremetal.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tzvisor/ltzvisor/f5b55394e3f3602a5c8c9ffce2563bf89b1b7c29/src/ns_guest/zynq/baremetal.bin -------------------------------------------------------------------------------- /src/s_guest/BareApp/blink.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * 9 | * This file is part of LTZVisor. 10 | * 11 | * LTZVisor is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License version 2 13 | * as published by the Free Software Foundation, with a special 14 | * exception described below. 15 | * 16 | * Linking this code statically or dynamically with other modules 17 | * is making a combined work based on this code. Thus, the terms 18 | * and conditions of the GNU General Public License V2 cover the 19 | * whole combination. 20 | * 21 | * As a special exception, the copyright holders of LTZVisor give 22 | * you permission to link LTZVisor with independent modules to 23 | * produce a statically linked executable, regardless of the license 24 | * terms of these independent modules, and to copy and distribute 25 | * the resulting executable under terms of your choice, provided that 26 | * you also meet, for each linked independent module, the terms and 27 | * conditions of the license of that module. An independent module 28 | * is a module which is not derived from or based on LTZVisor. 29 | * 30 | * LTZVisor is distributed in the hope that it will be useful, but 31 | * WITHOUT ANY WARRANTY; without even the implied warranty of 32 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 33 | * GNU General Public License for more details. 34 | * 35 | * You should have received a copy of the GNU General Public License 36 | * along with this program; if not, write to the Free Software 37 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 38 | * 02110-1301 USA. 39 | * 40 | * [blink.c] 41 | * 42 | * This file contains a bare-metal Blink application. 43 | * 44 | * (#) $id: blink.c 27-09-2017 s_pinto$ 45 | */ 46 | 47 | #include 48 | #include 49 | 50 | void led_blink( void * pvParameters ); 51 | 52 | int main() { 53 | 54 | /** Initialize hardware */ 55 | hw_init(); 56 | 57 | printk(" * Secure bare metal VM: running ... \n\t"); 58 | 59 | /** Generate tick every 1s */ 60 | tick_set(1000000); 61 | 62 | /* Calling Blinking Task (LED blink at 1s) */ 63 | led_blink((void*)0); 64 | 65 | /* This point will never be reached */ 66 | for( ;; ); 67 | 68 | } 69 | 70 | /** 71 | * Blink LED "Task" 72 | * 73 | * @param 74 | * 75 | * @retval 76 | */ 77 | void led_blink( void * parameters ){ 78 | 79 | static uint32_t toggle; 80 | /** 4GPIO (LED) in FPGA fabric */ 81 | static uint32_t *ptr = (uint32_t *) 0x41200000; 82 | 83 | for( ;; ){ 84 | toggle ^=0xFF; 85 | *ptr = toggle; 86 | YIELD() 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/s_guest/BareApp/objects.mk: -------------------------------------------------------------------------------- 1 | s_guest-objs-y = blink.o 2 | -------------------------------------------------------------------------------- /src/s_guest/BareApp/portable/hw_zynq.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * 9 | * This file is part of LTZVisor. 10 | * 11 | * LTZVisor is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License version 2 13 | * as published by the Free Software Foundation, with a special 14 | * exception described below. 15 | * 16 | * Linking this code statically or dynamically with other modules 17 | * is making a combined work based on this code. Thus, the terms 18 | * and conditions of the GNU General Public License V2 cover the 19 | * whole combination. 20 | * 21 | * As a special exception, the copyright holders of LTZVisor give 22 | * you permission to link LTZVisor with independent modules to 23 | * produce a statically linked executable, regardless of the license 24 | * terms of these independent modules, and to copy and distribute 25 | * the resulting executable under terms of your choice, provided that 26 | * you also meet, for each linked independent module, the terms and 27 | * conditions of the license of that module. An independent module 28 | * is a module which is not derived from or based on LTZVisor. 29 | * 30 | * LTZVisor is distributed in the hope that it will be useful, but 31 | * WITHOUT ANY WARRANTY; without even the implied warranty of 32 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 33 | * GNU General Public License for more details. 34 | * 35 | * You should have received a copy of the GNU General Public License 36 | * along with this program; if not, write to the Free Software 37 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 38 | * 02110-1301 USA. 39 | * 40 | * [hw_zynq.c] 41 | * 42 | * This file contains hardware-related initializations for Zynq. 43 | * 44 | * (#) $id: hw_zynq.c 02-10-2017 s_pinto$ 45 | */ 46 | 47 | #include 48 | 49 | extern tHandler* sfiq_handlers[NO_OF_INTERRUPTS_IMPLEMENTED]; 50 | 51 | /** 52 | * Zynq-specific hardware initialization 53 | * 54 | * @param 55 | * 56 | * @retval 57 | */ 58 | void hw_init( void ){ 59 | 60 | /** Initialize TTC1_2 as S Tick */ 61 | ttc_init(TTC1,TTCx_2,INTERVAL); 62 | 63 | /** Config TTC1_2 ISR*/ 64 | interrupt_enable(TTC1_TTCx_2_INTERRUPT,TRUE); 65 | interrupt_target_set(TTC1_TTCx_2_INTERRUPT,0,1); 66 | interrupt_priority_set(TTC1_TTCx_2_INTERRUPT,6); 67 | 68 | } 69 | 70 | /** 71 | * Set secure world tick 72 | * 73 | * @param time = time in useconds 74 | * 75 | * @retval 76 | */ 77 | uint32_t tick_set( uint32_t time ){ 78 | 79 | uint32_t ret = 1; 80 | 81 | /** Set tick rate */ 82 | ret = ttc_request(TTC1, TTCx_2, time); 83 | 84 | /** Start counting */ 85 | ttc_enable(TTC1, TTCx_2); 86 | 87 | return ret; 88 | } 89 | -------------------------------------------------------------------------------- /src/s_guest/BareApp/portable/inc/hw_zynq.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * 9 | * This file is part of LTZVisor. 10 | * 11 | * LTZVisor is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License version 2 13 | * as published by the Free Software Foundation, with a special 14 | * exception described below. 15 | * 16 | * Linking this code statically or dynamically with other modules 17 | * is making a combined work based on this code. Thus, the terms 18 | * and conditions of the GNU General Public License V2 cover the 19 | * whole combination. 20 | * 21 | * As a special exception, the copyright holders of LTZVisor give 22 | * you permission to link LTZVisor with independent modules to 23 | * produce a statically linked executable, regardless of the license 24 | * terms of these independent modules, and to copy and distribute 25 | * the resulting executable under terms of your choice, provided that 26 | * you also meet, for each linked independent module, the terms and 27 | * conditions of the license of that module. An independent module 28 | * is a module which is not derived from or based on LTZVisor. 29 | * 30 | * LTZVisor is distributed in the hope that it will be useful, but 31 | * WITHOUT ANY WARRANTY; without even the implied warranty of 32 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 33 | * GNU General Public License for more details. 34 | * 35 | * You should have received a copy of the GNU General Public License 36 | * along with this program; if not, write to the Free Software 37 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 38 | * 02110-1301 USA. 39 | * 40 | * [hw_zynq.h] 41 | * 42 | * This file contains hardware-related initializations for Zynq (header). 43 | * 44 | * (#) $id: hw_zynq.h 02-10-2017 s_pinto$ 45 | */ 46 | 47 | #ifndef __HW_ZYNQ_H 48 | #define __HW_ZYNQ_H 49 | 50 | #include 51 | #include 52 | #include 53 | 54 | /** 55 | * Zynq-specific hardware initialization 56 | * 57 | * @param 58 | * 59 | * @retval 60 | */ 61 | void hw_init( void ); 62 | 63 | /** 64 | * Set secure world tick 65 | * 66 | * @param time = time in useconds 67 | * 68 | * @retval 69 | */ 70 | uint32_t tick_set( uint32_t time ); 71 | 72 | #endif /* __HW_ZYNQ_H */ 73 | -------------------------------------------------------------------------------- /src/s_guest/BareApp/portable/inc/s_isr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * 9 | * This file is part of LTZVisor. 10 | * 11 | * LTZVisor is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License version 2 13 | * as published by the Free Software Foundation, with a special 14 | * exception described below. 15 | * 16 | * Linking this code statically or dynamically with other modules 17 | * is making a combined work based on this code. Thus, the terms 18 | * and conditions of the GNU General Public License V2 cover the 19 | * whole combination. 20 | * 21 | * As a special exception, the copyright holders of LTZVisor give 22 | * you permission to link LTZVisor with independent modules to 23 | * produce a statically linked executable, regardless of the license 24 | * terms of these independent modules, and to copy and distribute 25 | * the resulting executable under terms of your choice, provided that 26 | * you also meet, for each linked independent module, the terms and 27 | * conditions of the license of that module. An independent module 28 | * is a module which is not derived from or based on LTZVisor. 29 | * 30 | * LTZVisor is distributed in the hope that it will be useful, but 31 | * WITHOUT ANY WARRANTY; without even the implied warranty of 32 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 33 | * GNU General Public License for more details. 34 | * 35 | * You should have received a copy of the GNU General Public License 36 | * along with this program; if not, write to the Free Software 37 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 38 | * 02110-1301 USA. 39 | * 40 | * [s_isr.h] 41 | * 42 | * This file contains the interrupt handling. 43 | * 44 | * (#) $id: s_isr.h 29-09-2017 s_pinto$ 45 | */ 46 | 47 | #ifndef __S_ISR_H 48 | #define __S_ISR_H 49 | 50 | #include 51 | 52 | #define YIELD(){ \ 53 | asm volatile("ldr r0, =0x0ffffff1");\ 54 | asm volatile("smc #0");\ 55 | } 56 | 57 | /** Type definition of the interrupt handler */ 58 | typedef void (handler)(void * t); 59 | 60 | #endif /* __S_ISR_H */ 61 | 62 | -------------------------------------------------------------------------------- /src/s_guest/BareApp/portable/objects.mk: -------------------------------------------------------------------------------- 1 | s_guest_port-objs-y = s_handlers.o 2 | s_guest_port-objs-y += s_isr.o 3 | s_guest_port-objs-y += hw_zynq.o 4 | -------------------------------------------------------------------------------- /src/s_guest/BareApp/portable/s_handlers.S: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * 9 | * This file is part of LTZVisor. 10 | * 11 | * LTZVisor is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License version 2 13 | * as published by the Free Software Foundation, with a special 14 | * exception described below. 15 | * 16 | * Linking this code statically or dynamically with other modules 17 | * is making a combined work based on this code. Thus, the terms 18 | * and conditions of the GNU General Public License V2 cover the 19 | * whole combination. 20 | * 21 | * As a special exception, the copyright holders of LTZVisor give 22 | * you permission to link LTZVisor with independent modules to 23 | * produce a statically linked executable, regardless of the license 24 | * terms of these independent modules, and to copy and distribute 25 | * the resulting executable under terms of your choice, provided that 26 | * you also meet, for each linked independent module, the terms and 27 | * conditions of the license of that module. An independent module 28 | * is a module which is not derived from or based on LTZVisor. 29 | * 30 | * LTZVisor is distributed in the hope that it will be useful, but 31 | * WITHOUT ANY WARRANTY; without even the implied warranty of 32 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 33 | * GNU General Public License for more details. 34 | * 35 | * You should have received a copy of the GNU General Public License 36 | * along with this program; if not, write to the Free Software 37 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 38 | * 02110-1301 USA. 39 | * 40 | * [s_handlers.S] 41 | * 42 | * This file contains the secure vector table. 43 | * 44 | * (#) $id: s_handlers.S 27-09-2017 s_pinto$ 45 | */ 46 | 47 | #include 48 | 49 | /** 50 | * Secure vector table 51 | * 52 | * @param 53 | * 54 | * @retval 55 | */ 56 | .align 8 57 | .globl _secure_vector_table 58 | /** Monitor Vector Table definition */ 59 | _secure_vector_table: 60 | b . @ Reset exception handler 61 | b _undefined_entry @ Undefined exception handler 62 | b . @ SVC exception handler 63 | b _prefetch_entry @ Prefetch Abort exception handler 64 | b _low_level_abt @ Data Abort exception handler 65 | nop @ Placeholder for address exception vector 66 | b . @ IRQ exception handler -not used 67 | ldr pc, _fiq @ FIQ exception handler 68 | 69 | .globl sFIQ_handler 70 | _fiq: 71 | .word sFIQ_handler 72 | 73 | _undefined_entry: 74 | b . @ Stuck (FIXME) 75 | 76 | _prefetch_entry: 77 | b . @ Stuck (FIXME) 78 | 79 | _low_level_abt: 80 | b . @ Stuck (FIXME) 81 | 82 | 83 | .global yield 84 | yield: 85 | /* Explicit hypercall */ 86 | ldr r0,=LTZVISOR_SCHED_SYSCALL 87 | smc 0 88 | bx lr 89 | 90 | 91 | -------------------------------------------------------------------------------- /src/s_guest/BareApp/portable/s_isr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LTZVisor, a Lightweight TrustZone-assisted Hypervisor 3 | * 4 | * Copyright (c) TZVisor Project (www.tzvisor.org), 2017- 5 | * 6 | * Authors: 7 | * Sandro Pinto 8 | * 9 | * This file is part of LTZVisor. 10 | * 11 | * LTZVisor is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License version 2 13 | * as published by the Free Software Foundation, with a special 14 | * exception described below. 15 | * 16 | * Linking this code statically or dynamically with other modules 17 | * is making a combined work based on this code. Thus, the terms 18 | * and conditions of the GNU General Public License V2 cover the 19 | * whole combination. 20 | * 21 | * As a special exception, the copyright holders of LTZVisor give 22 | * you permission to link LTZVisor with independent modules to 23 | * produce a statically linked executable, regardless of the license 24 | * terms of these independent modules, and to copy and distribute 25 | * the resulting executable under terms of your choice, provided that 26 | * you also meet, for each linked independent module, the terms and 27 | * conditions of the license of that module. An independent module 28 | * is a module which is not derived from or based on LTZVisor. 29 | * 30 | * LTZVisor is distributed in the hope that it will be useful, but 31 | * WITHOUT ANY WARRANTY; without even the implied warranty of 32 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 33 | * GNU General Public License for more details. 34 | * 35 | * You should have received a copy of the GNU General Public License 36 | * along with this program; if not, write to the Free Software 37 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 38 | * 02110-1301 USA. 39 | * 40 | * [s_isr.c] 41 | * 42 | * This file contains the interrupt handling. 43 | * 44 | * (#) $id: s_isr.c 27-09-2017 s_pinto$ 45 | */ 46 | 47 | #include 48 | #include 49 | 50 | uint32_t interrupt; 51 | 52 | tHandler* sfiq_handlers[NO_OF_INTERRUPTS_IMPLEMENTED] = {NULL}; 53 | 54 | /** 55 | * Generic FIQ handler 56 | * 57 | * @param interrupt_ = interrupt number 58 | * 59 | * @retval 60 | */ 61 | void sFIQ_handler(uint32_t interrupt_){ 62 | 63 | if (sfiq_handlers[interrupt_]) 64 | sfiq_handlers[interrupt_]((void *) interrupt_); 65 | } 66 | 67 | -------------------------------------------------------------------------------- /src/s_guest/README: -------------------------------------------------------------------------------- 1 | Secure Guest OS code should be placed here! 2 | --------------------------------------------------------------------------------