├── .gitignore ├── Makefile ├── README.md ├── common └── include │ └── common_types.h ├── core ├── Makefile ├── acpi │ ├── Makefile │ ├── mon_acpi.c │ ├── mon_acpi_pm.c │ └── mon_acpi_resume_after_s3_c_main_gnu.S ├── arch │ ├── Makefile │ ├── e820_abstraction.c │ ├── efer_msr_abstraction.c │ ├── mtrrs_abstraction.c │ └── pat_manager.c ├── common │ ├── Makefile │ ├── include │ │ ├── arch │ │ │ ├── em64t_defs.h │ │ │ ├── ia32_defs.h │ │ │ ├── ia32_low_level.h │ │ │ └── msr_defs.h │ │ ├── array_iterators.h │ │ ├── common_libc.h │ │ ├── elf32.h │ │ ├── elf64.h │ │ ├── elf_common.h │ │ ├── elf_defs.h │ │ ├── elf_env.h │ │ ├── elf_info.h │ │ ├── elf_ld.h │ │ ├── event_mgr.h │ │ ├── file_codes.h │ │ ├── image_access_env.h │ │ ├── image_access_gen.h │ │ ├── image_access_mem.h │ │ ├── image_loader.h │ │ ├── loader.h │ │ ├── mon_arch_defs.h │ │ ├── mon_defs.h │ │ ├── mon_startup.h │ │ ├── mon_version_struct.h │ │ ├── platform │ │ │ └── uart.h │ │ └── vmcall_api.h │ └── libc │ │ ├── Makefile │ │ ├── bitarray_utilities.c │ │ ├── common_libc.c │ │ ├── em64t │ │ ├── Makefile │ │ └── em64t_mem.S │ │ ├── ia32 │ │ ├── Makefile │ │ └── ia32_low_level.c │ │ └── sprintf.c ├── dbg │ ├── Makefile │ ├── cli_libc.c │ ├── mon_dbg.c │ ├── trace.c │ ├── trace.h │ ├── vmdb.c │ ├── vmx_trace.c │ └── vt100.c ├── guest │ ├── Makefile │ ├── guest.c │ ├── guest_control.c │ ├── guest_cpu │ │ ├── Makefile │ │ ├── guest_cpu.c │ │ ├── guest_cpu_access.c │ │ ├── guest_cpu_control.c │ │ ├── guest_cpu_control.h │ │ ├── guest_cpu_internal.h │ │ ├── guest_cpu_switch.c │ │ ├── guest_cpu_vmenter_event.c │ │ ├── unrestricted_guest.c │ │ └── unrestricted_guest.h │ ├── guest_internal.h │ ├── guest_pci_configuration.c │ └── scheduler │ │ ├── Makefile │ │ └── scheduler.c ├── host │ ├── Makefile │ ├── host_cpu.c │ ├── hw │ │ ├── Makefile │ │ ├── em64t │ │ │ ├── Makefile │ │ │ ├── em64t_gcpu_regs_save_restore.S │ │ │ ├── em64t_gdt.c │ │ │ ├── em64t_gnu_asm.c │ │ │ ├── em64t_idt.c │ │ │ ├── em64t_interlocked.S │ │ │ ├── em64t_isr.S │ │ │ ├── em64t_setjmp.S │ │ │ ├── em64t_utils.S │ │ │ ├── em64t_vmx.S │ │ │ ├── gas_defs.h │ │ │ └── isr_generated.h │ │ ├── host_pci_configuration.c │ │ ├── hw_utils.c │ │ ├── local_apic.c │ │ ├── reset.c │ │ └── vmcs_init.c │ ├── isr.c │ ├── mon_globals.c │ ├── policy_manager.c │ └── trial_exec.c ├── include │ ├── acconfig.h │ ├── actbl.h │ ├── actbl2.h │ ├── actypes.h │ ├── address.h │ ├── appliances │ │ └── tscdt_emulator_api.h │ ├── cache64.h │ ├── cli.h │ ├── cli_env.h │ ├── cli_libc.h │ ├── cli_monitor.h │ ├── device_drivers_manager.h │ ├── flat_page_tables.h │ ├── gpm_api.h │ ├── guest.h │ ├── guest_cpu.h │ ├── guest_cpu_vmenter_event.h │ ├── guest_pci_configuration.h │ ├── hash64_api.h │ ├── heap.h │ ├── host_cpu.h │ ├── host_memory_manager_api.h │ ├── hw │ │ ├── 8259a_pic.h │ │ ├── e820_abstraction.h │ │ ├── efer_msr_abstraction.h │ │ ├── gdt.h │ │ ├── host_pci_configuration.h │ │ ├── hw_interlocked.h │ │ ├── hw_setjmp.h │ │ ├── hw_utils.h │ │ ├── hw_vmx_utils.h │ │ ├── idt.h │ │ ├── local_apic.h │ │ ├── mon_phys_mem_types.h │ │ ├── mtrrs_abstraction.h │ │ ├── pci_configuration.h │ │ ├── vmcs_init.h │ │ ├── vmx_asm.h │ │ ├── vmx_ctrl_msrs.h │ │ ├── vmx_vmcs.h │ │ ├── vtd.h │ │ ├── vtd_acpi_dmar.h │ │ ├── vtd_domain.h │ │ └── vtd_hw_layer.h │ ├── hw_includes.h │ ├── ipc.h │ ├── isr.h │ ├── libc.h │ ├── list.h │ ├── lock.h │ ├── memory_address_mapper_api.h │ ├── memory_allocator.h │ ├── memory_dump.h │ ├── mon_acpi.h │ ├── mon_addons.h │ ├── mon_api.h │ ├── mon_bootstrap_utils.h │ ├── mon_callback.h │ ├── mon_dbg.h │ ├── mon_events_data.h │ ├── mon_globals.h │ ├── mon_objects.h │ ├── mon_serial.h │ ├── mon_stack_api.h │ ├── page_walker.h │ ├── parse_image.h │ ├── pat_manager.h │ ├── pfec.h │ ├── policy_manager.h │ ├── pool_api.h │ ├── scheduler.h │ ├── trial_exec.h │ ├── vmcall.h │ ├── vmcs_actual.h │ ├── vmcs_api.h │ ├── vmcs_hierarchy.h │ ├── vmcs_merge_split.h │ ├── vmcs_sw_object.h │ ├── vmdb.h │ ├── vmenter_checks.h │ ├── vmexit.h │ ├── vmexit_analysis.h │ ├── vmexit_cpuid.h │ ├── vmexit_cr_access.h │ ├── vmexit_dtr_tr.h │ ├── vmexit_io.h │ ├── vmexit_msr.h │ ├── vmx_nmi.h │ ├── vmx_timer.h │ ├── vmx_trace.h │ └── vt100.h ├── ipc │ ├── Makefile │ ├── ipc.c │ ├── ipc_api.c │ └── ipc_impl.h ├── libc │ ├── Makefile │ ├── libc.c │ ├── libc_internal.h │ ├── mon_io.c │ └── mon_serial.c ├── linker.lds ├── main.c ├── memory │ ├── Makefile │ ├── ept │ │ ├── Makefile │ │ ├── ept.c │ │ ├── ept.h │ │ ├── ept_hw_layer.c │ │ ├── ept_hw_layer.h │ │ ├── fvs.c │ │ ├── fvs.h │ │ ├── invept.S │ │ ├── ve.c │ │ └── ve.h │ └── memory_manager │ │ ├── Makefile │ │ ├── flat_page_tables.c │ │ ├── gpm.c │ │ ├── host_memory_manager.c │ │ ├── host_memory_manager.h │ │ ├── mam_forward_declarations.h │ │ ├── memory_address_mapper.c │ │ ├── memory_address_mapper.h │ │ ├── mon_stack.c │ │ ├── mon_stack.h │ │ ├── page_walker.c │ │ ├── pool.c │ │ └── pool.h ├── mon_entry.S ├── rule.linux ├── startup │ ├── Makefile │ ├── addons.c │ ├── copy_input_structs.c │ ├── create_guests.c │ ├── dummy_event_handler.c │ ├── elf_info.c │ ├── layout_host_memory.h │ ├── layout_host_memory_for_mbr_loader.c │ └── parse_elf_image.c ├── utils │ ├── Makefile │ ├── address.c │ ├── array_list.c │ ├── cache64.c │ ├── event_mgr.c │ ├── hash64.c │ ├── hash64.h │ ├── heap.c │ ├── lock.c │ ├── math_utils.c │ ├── memory_allocator.c │ └── utils_asm.S ├── vmexit │ ├── Makefile │ ├── vmcall.c │ ├── vmexit.c │ ├── vmexit_analysis.c │ ├── vmexit_cpuid.c │ ├── vmexit_cr_access.c │ ├── vmexit_dbg.c │ ├── vmexit_dtr_tr_access.c │ ├── vmexit_ept.c │ ├── vmexit_init.c │ ├── vmexit_interrupt_exception_nmi.c │ ├── vmexit_invd.c │ ├── vmexit_invlpg.c │ ├── vmexit_io.c │ ├── vmexit_msr.c │ ├── vmexit_sipi.c │ ├── vmexit_task_switch.c │ ├── vmexit_triple_fault.c │ ├── vmexit_ud.c │ └── vmexit_vmx.c └── vmx │ ├── Makefile │ ├── vmcs.c │ ├── vmcs_actual.c │ ├── vmcs_hierarchy.c │ ├── vmcs_internal.h │ ├── vmcs_merge_split.c │ ├── vmcs_sw_object.c │ └── vmx_nmi.c └── package ├── 20_linux_ikgt ├── 20_linux_ikgt_tboot ├── check_ikgt ├── check_vtx.sh └── ikgt.cfg /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | mon/build/ 3 | loader/pre_os/build/ 4 | loader/startap/build/ 5 | lk/ 6 | plugins/ 7 | build/ 8 | loader/ 9 | api/ 10 | *.bin 11 | *.elf 12 | *.elf.z 13 | 14 | 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DISCONTINUATION OF PROJECT # 2 | This project will no longer be maintained by Intel. 3 | Intel has ceased development and contributions including, but not limited to, maintenance, bug fixes, new releases, or updates, to this project. 4 | Intel no longer accepts patches to this project. 5 | If you have an ongoing need to use this project, are interested in independently developing it, or would like to maintain patches for the open source software community, please create your own fork of this project. 6 | 7 | # ikgt-core 8 | Intel Kernel Guard Technology Core Repo 9 | 10 | Use "trusty" branch to support Trusty TEE. 11 | 12 | Security related issues should be reported via https://01.org/security 13 | -------------------------------------------------------------------------------- /core/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | CSOURCES = main.c 17 | ASOURCES = mon_entry.S 18 | include rule.linux 19 | 20 | SUBDIRS = arch common dbg guest host ipc libc \ 21 | memory startup utils vmexit vmx acpi 22 | 23 | $(shell mkdir -p $(OUTDIR)core/) 24 | 25 | .PHONY: all subdirs libmon.a 26 | 27 | TARGET = libmon.a 28 | 29 | all: subdirs $(TARGET) 30 | 31 | subdirs: 32 | $(foreach D, $(SUBDIRS), $(MAKE) -C $(D);) 33 | 34 | libmon.a: 35 | $(AR) rcs $(BINDIR)$@ $(wildcard $(OUTDIR)core/*.o) 36 | 37 | -------------------------------------------------------------------------------- /core/acpi/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | CSOURCES = $(wildcard *.c) 18 | ASOURCES = $(wildcard *.S) 19 | include $(PROJS)/core/rule.linux 20 | -------------------------------------------------------------------------------- /core/acpi/mon_acpi_resume_after_s3_c_main_gnu.S: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | .file "mon_acpi_resume_after_s3_c_main_gnu.s" 18 | 19 | 20 | .text 21 | 22 | #------------------------------------------------------------------------------ 23 | # Registers for passing parameters: 24 | # %rdi, %rsi, %rdx, %rcx, %r8, %r9 25 | # The rest parameters are in stack 26 | # Preserved regs 27 | # %rbp,%rbx,%r12,%r15 28 | # System calls via syscall 29 | # Kernel destroys %r11, %rcx 30 | # The number of syscall is in %rax 31 | #------------------------------------------------------------------------------ 32 | 33 | #void mon_acpi_resume_after_s3_c_main(uint32_t , uint64_t , uint64_t , uint64_t ) 34 | .extern mon_acpi_resume_after_s3_c_main 35 | 36 | #------------------------------------------------------------------------------ 37 | # void_t 38 | # mon_acpi_resume_after_s3_c_main_gnu ( 39 | # ) 40 | # 41 | # This function used as entry point to uMON. It assumes that loader is in PE format, 42 | # so it displace 4 arguments passed in registers RCX, RDX, R8, R9 43 | # (Microsoft-like arguments passing), to registers RDI, RSI, RDX, RCX, 44 | # i.e. GNU arguments passing convention 45 | #------------------------------------------------------------------------------ 46 | 47 | .globl mon_acpi_resume_after_s3_c_main_gnu 48 | mon_acpi_resume_after_s3_c_main_gnu: 49 | mov %rcx, %rdi 50 | mov %rdx, %rsi 51 | mov %r8, %rdx 52 | mov %r9, %rcx 53 | call mon_acpi_resume_after_s3_c_main 54 | # jmp . # should never reach this point 55 | ret 56 | -------------------------------------------------------------------------------- /core/arch/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | CSOURCES = $(wildcard *.c) 18 | include $(PROJS)/core/rule.linux 19 | -------------------------------------------------------------------------------- /core/arch/efer_msr_abstraction.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | 23 | void efer_msr_set_nxe(void) 24 | { 25 | ia32_efer_t efer_reg; 26 | 27 | efer_reg.uint64 = hw_read_msr(IA32_MSR_EFER); 28 | if (efer_reg.bits.nxe == 0) { 29 | efer_reg.bits.nxe = 1; 30 | hw_write_msr(IA32_MSR_EFER, efer_reg.uint64); 31 | } 32 | } 33 | 34 | boolean_t efer_msr_is_nxe_bit_set(IN uint64_t efer_msr_value) 35 | { 36 | ia32_efer_t efer_reg; 37 | 38 | efer_reg.uint64 = efer_msr_value; 39 | return efer_reg.bits.nxe != 0; 40 | } 41 | 42 | uint64_t efer_msr_read_reg(void) 43 | { 44 | return hw_read_msr(IA32_MSR_EFER); 45 | } 46 | -------------------------------------------------------------------------------- /core/arch/pat_manager.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include "file_codes.h" 33 | 34 | #define MON_DEADLOOP() MON_DEADLOOP_LOG(PAT_MANAGER_C) 35 | #define MON_ASSERT(__condition) MON_ASSERT_LOG(PAT_MANAGER_C, __condition) 36 | 37 | /*--------------------------------------------------------------------------- */ 38 | #define PAT_MNGR_INVALID_PAT_MSR_VALUE (~((uint64_t)0)) 39 | #define PAT_MNGR_NUM_OF_ATTRUBUTE_FIELDS 8 40 | 41 | /*--------------------------------------------------------------------------- */ 42 | static 43 | mon_phys_mem_type_t pat_mngr_get_memory_type(uint64_t pat_value, uint32_t index) 44 | { 45 | uint64_t memory_type = ((pat_value >> (index * 8)) & 0xff); 46 | 47 | return (mon_phys_mem_type_t)memory_type; 48 | } 49 | 50 | uint32_t pat_mngr_get_earliest_pat_index_for_mem_type( 51 | mon_phys_mem_type_t mem_type, 52 | uint64_t pat_msr_value) 53 | { 54 | uint32_t i; 55 | 56 | if (pat_msr_value == PAT_MNGR_INVALID_PAT_MSR_VALUE) { 57 | return PAT_MNGR_INVALID_PAT_INDEX; 58 | } 59 | 60 | for (i = 0; i < PAT_MNGR_NUM_OF_ATTRUBUTE_FIELDS; i++) { 61 | if (pat_mngr_get_memory_type(pat_msr_value, i) == mem_type) { 62 | return i; 63 | } 64 | } 65 | 66 | return PAT_MNGR_INVALID_PAT_INDEX; 67 | } 68 | 69 | uint32_t 70 | pat_mngr_retrieve_current_earliest_pat_index_for_mem_type(mon_phys_mem_type_t 71 | mem_type) 72 | { 73 | uint64_t pat_msr_value = hw_read_msr(IA32_MSR_PAT); 74 | uint32_t result = 0; 75 | 76 | /* assume that PAT MSR not used if its value is ZERO 77 | * then use compatibility setttings. */ 78 | if (pat_msr_value == 0) { 79 | switch (mem_type) { 80 | case MON_PHYS_MEM_WRITE_BACK: 81 | /* see IA32 SDM, table 11-11/12 */ 82 | result = 0; 83 | break; 84 | 85 | case MON_PHYS_MEM_UNCACHABLE: 86 | /* see IA32 SDM, table 11-11/12 */ 87 | result = 3; 88 | break; 89 | 90 | default: 91 | result = PAT_MNGR_INVALID_PAT_INDEX; 92 | MON_LOG(mask_mon, 93 | level_error, 94 | "CPU%d: %s: Error: mem type(%d) currently not supported\n", 95 | hw_cpu_id(), 96 | __FUNCTION__, 97 | mem_type); 98 | MON_DEBUG_CODE(MON_DEADLOOP();) 99 | break; 100 | } 101 | } else { 102 | result = pat_mngr_get_earliest_pat_index_for_mem_type(mem_type, 103 | pat_msr_value); 104 | } 105 | 106 | return result; 107 | } 108 | -------------------------------------------------------------------------------- /core/common/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | SUBDIRS = libc 18 | 19 | .PHONY: all 20 | 21 | all: 22 | $(foreach D, $(SUBDIRS), $(MAKE) -C $(D);) 23 | -------------------------------------------------------------------------------- /core/common/include/arch/ia32_low_level.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _IA32_LOW_LEVEL_H_ 18 | #define _IA32_LOW_LEVEL_H_ 19 | 20 | #include "ia32_defs.h" 21 | 22 | uint32_t CDECL ia32_read_cr0(void); 23 | void CDECL ia32_write_cr0(uint32_t value); 24 | uint32_t CDECL ia32_read_cr2(void); 25 | uint32_t CDECL ia32_read_cr3(void); 26 | void CDECL ia32_write_cr3(uint32_t value); 27 | uint32_t CDECL ia32_read_cr4(void); 28 | void CDECL ia32_write_cr4(uint32_t value); 29 | void CDECL ia32_write_gdtr(ia32_gdtr_t *p_descriptor); 30 | void CDECL ia32_read_gdtr(ia32_gdtr_t *p_descriptor); 31 | void CDECL ia32_read_idtr(ia32_idtr_t *p_descriptor); 32 | void CDECL ia32_write_idtr(ia32_idtr_t *p_descriptor); 33 | uint16_t CDECL ia32_read_ldtr(void); 34 | uint16_t CDECL ia32_read_tr(void); 35 | void CDECL ia32_read_msr(uint32_t msr_id, uint64_t *p_value); 36 | void CDECL ia32_write_msr(uint32_t msr_id, uint64_t *p_value); 37 | uint32_t CDECL ia32_read_eflags(void); 38 | uint16_t CDECL ia32_read_cs(void); 39 | uint16_t CDECL ia32_read_ds(void); 40 | uint16_t CDECL ia32_read_es(void); 41 | uint16_t CDECL ia32_read_fs(void); 42 | uint16_t CDECL ia32_read_gs(void); 43 | uint16_t CDECL ia32_read_ss(void); 44 | 45 | /* CPUID */ 46 | /* compiler intrinsic */ 47 | extern void __cpuid(int cpu_info[4], int info_type); 48 | #define CPUID_EAX 0 49 | #define CPUID_EBX 1 50 | #define CPUID_ECX 2 51 | #define CPUID_EDX 3 52 | #define ia32_cpuid __cpuid 53 | 54 | /* This function is for use when the compiler intrinsic is not available */ 55 | void CDECL ia32_cpu_id(int cpu_info[4], int info_type); 56 | 57 | #endif /* _IA32_LOW_LEVEL_H_ */ 58 | -------------------------------------------------------------------------------- /core/common/include/elf_defs.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _ELF_DEFS_H_ 18 | #define _ELF_DEFS_H_ 19 | 20 | typedef unsigned int u_int32_t; 21 | #include "elf_common.h" 22 | 23 | /* currently unsupported flags... this is a kind of version number */ 24 | #define MULTIBOOT_UNSUPPORTED 0x0000FFF8 25 | /* Magic value identifying the multiboot_header */ 26 | #define MULTIBOOT_MAGIC 0x1BADB002 27 | /* Must pass video information to OS */ 28 | #define MULTIBOOT_VIDEO_MODE 0x00000004 29 | /* This flag indicates the use of the address fields in the header */ 30 | #define MULTIBOOT_AOUT_KLUDGE 0x00010000 31 | 32 | /* Macros to facilitate locations of program segment headers and section 33 | * headers */ 34 | #define GET_PHDR(__ehdr, __phdrtab, __i) \ 35 | ((__phdrtab) + (__i) * (__ehdr)->e_phentsize) 36 | #define GET_SHDR(__ehdr, __shdrtab, __i) \ 37 | ((__shdrtab) + (__i) * (__ehdr)->e_shentsize) 38 | 39 | #define GOT_SECTION_NAME ".got" 40 | #define DYNRELA_SECTION_NAME ".rela.dyn" 41 | #define DYNSYM_SECTION_NAME ".dynsym" 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /core/common/include/elf_env.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _ELF_ENV_H_ 18 | #define _ELF_ENV_H_ 19 | 20 | #include "mon_defs.h" 21 | #define elf_err_print 22 | #define elf_debug_print 23 | 24 | #endif /* _ELF_ENV_H_ */ 25 | -------------------------------------------------------------------------------- /core/common/include/elf_info.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _ELF_INFO_H_ 18 | #define _ELF_INFO_H_ 19 | 20 | typedef enum { 21 | ELF_ATTR_EXECUTABLE = 1, 22 | ELF_ATTR_WRITABLE = 2, 23 | ELF_ATTR_READABLE = 4 24 | } elf_attr_type_t; 25 | 26 | typedef struct { 27 | void *address; 28 | uint32_t size; 29 | elf_attr_type_t attribute; 30 | } elf_segment_info_t; 31 | 32 | int elf_is_elf(const char *p_buffer); 33 | int elf32_header_is_valid(const void *p_buffer); 34 | int elf64_header_is_valid(const void *p_buffer); 35 | int elf_get_segment_info(const void *p_image, 36 | int16_t segment_no, 37 | elf_segment_info_t *info); 38 | 39 | #endif /* _ELF_INFO_H_ */ 40 | -------------------------------------------------------------------------------- /core/common/include/elf_ld.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _ELF_LD_H_ 18 | #define _ELF_LD_H_ 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #include "mon_defs.h" 25 | #include "image_access_gen.h" 26 | #include "image_loader.h" 27 | 28 | /* Legal values for machine_type below */ 29 | 30 | #define EM_386 3 /* Intel 80386 */ 31 | #define EM_X86_64 62 /* AMD x86-64 architecture */ 32 | 33 | typedef struct { 34 | boolean_t copy_section_headers; /* input */ 35 | boolean_t copy_symbol_tables; /* input */ 36 | uint64_t start_addr; /* output */ 37 | uint64_t end_addr; /* output */ 38 | uint64_t entry_addr; /* output */ 39 | uint64_t sections_addr; /* output (0 means there are no sections) */ 40 | int64_t relocation_offset; /* output */ 41 | int machine_type; /* output */ 42 | void *sh_got; /* ptr to GOT section header */ 43 | void *sh_rela_dyn; /* ptr to Dynamic Relo section header */ 44 | void *sh_dynsym; /* ptr to GOT Dynamic Symbol Table section header */ 45 | } elf_load_info_t; 46 | 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | #endif /* _ELF_LD_H_ */ 52 | -------------------------------------------------------------------------------- /core/common/include/image_access_env.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _IMAGE_ACCESS_ENV_H_ 18 | #define _IMAGE_ACCESS_ENV_H_ 19 | 20 | /* defintions for Mon environment */ 21 | #include "mon_defs.h" 22 | #define MALLOC(__x) mon_page_alloc(((__x) + PAGE_4KB_SIZE - 1) / PAGE_4KB_SIZE) 23 | #define FREE(__x) 24 | 25 | #endif /* _IMAGE_ACCESS_ENV_H_ */ 26 | -------------------------------------------------------------------------------- /core/common/include/image_access_gen.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _IMAGE_ACCESS_GEN_H_ 18 | #define _IMAGE_ACCESS_GEN_H_ 19 | 20 | #include "image_access_env.h" 21 | 22 | typedef struct gen_image_access_t { 23 | size_t (*read)(struct gen_image_access_t *ia, void *dest, 24 | size_t src_offset, size_t bytes); 25 | size_t (*map_to_mem)(struct gen_image_access_t *ia, void **dest, 26 | size_t src_offset, size_t bytes); 27 | void (*close)(struct gen_image_access_t *ia); 28 | } gen_image_access_t; 29 | 30 | #endif /* _IMAGE_ACCESS_GEN_H_ */ 31 | -------------------------------------------------------------------------------- /core/common/include/image_access_mem.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _IMAGE_ACCESS_MEM_H_ 18 | #define _IMAGE_ACCESS_MEM_H_ 19 | 20 | #include "image_access_gen.h" 21 | 22 | /*--------------------------Local Types Definitions-------------------------*/ 23 | typedef struct { 24 | gen_image_access_t gen; /* inherits to gen_image_access_t */ 25 | char *image; /* image located in memory */ 26 | size_t size; /* size of image in memory, counted in bytes */ 27 | } mem_image_access_t; 28 | 29 | gen_image_access_t *mem_image_create(char *image, size_t size); 30 | void mem_image_close(gen_image_access_t *); 31 | size_t mem_image_read(gen_image_access_t *, void *, size_t, size_t); 32 | size_t mem_image_map_to_mem(gen_image_access_t *, void **, size_t, size_t); 33 | gen_image_access_t *mem_image_create_ex(char *image, size_t size, void *buf); 34 | 35 | #endif /* _IMAGE_ACCESS_MEM_H_ */ 36 | -------------------------------------------------------------------------------- /core/common/include/image_loader.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _IMAGE_LOADER_H_ 18 | #define _IMAGE_LOADER_H_ 19 | 20 | #include "mon_defs.h" 21 | 22 | typedef enum { 23 | IMAGE_MACHINE_UNKNOWN = 0, 24 | IMAGE_MACHINE_X86, 25 | IMAGE_MACHINE_EM64T, 26 | } image_machine_type_t; 27 | 28 | typedef enum { 29 | IMAGE_INFO_OK = 0, 30 | IMAGE_INFO_WRONG_PARAMS, 31 | IMAGE_INFO_WRONG_FORMAT, 32 | IMAGE_INFO_WRONG_MACHINE, 33 | IMAGE_INFO_NOT_RELOCATABLE, 34 | IMAGE_INFO_UNRESOLVED_SYMBOLS 35 | } image_info_status_t; 36 | 37 | typedef struct { 38 | image_machine_type_t machine_type; 39 | uint32_t load_size; /* size as required for loading */ 40 | } image_info_t; 41 | 42 | 43 | /*---------------------------------------------------------------------- 44 | * 45 | * load image into memory 46 | * 47 | * Input: 48 | * void* file_mapped_into_memory - file directly read or mapped in RAM 49 | * void* image_base_address - load image to this address. Must be alined 50 | * on 4K. 51 | * uint32_t allocated_size - buffer size for image 52 | * uint64_t* p_entry_point_address - address of the uint64_t that will be filled 53 | * with the address of image entry point if 54 | * all is ok 55 | * 56 | * Output: 57 | * Return value - FALSE on any error 58 | *---------------------------------------------------------------------- */ 59 | boolean_t 60 | load_image(const void *file_mapped_into_memory, 61 | void *image_base_address, 62 | uint32_t allocated_size, 63 | uint64_t *p_entry_point_address); 64 | 65 | /*---------------------------------------------------------------------- 66 | * 67 | * Get info required for image loading 68 | * 69 | * Input: 70 | * void* file_mapped_into_memory - file directly read or mapped in RAM 71 | * 72 | * Output: 73 | * image_info_t - fills the structure 74 | * 75 | * Return value - image_info_status_t 76 | *---------------------------------------------------------------------- */ 77 | image_info_status_t get_image_info(const void *file_mapped_into_memory, 78 | uint32_t allocated_size, 79 | image_info_t *p_image_info); 80 | 81 | #endif /* _IMAGE_LOADER_H_ */ 82 | -------------------------------------------------------------------------------- /core/common/include/mon_version_struct.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _MON_VERSION_STRUCT_H_ 18 | #define _MON_VERSION_STRUCT_H_ 19 | 20 | /* 21 | * 22 | * Version string is generated as an ASCII string that resides between 23 | * header and trailer: 24 | * 25 | * VERSION_START::VERSION_END\0 26 | * 27 | */ 28 | 29 | #if defined DEBUG 30 | /* This is done to remove out the strings from the release build */ 31 | #define MON_VERSION_START "MON_VERSION_START:" 32 | #define MON_VERSION_END ":MON_VERSION_END" 33 | #else 34 | #define MON_VERSION_START "START" 35 | #define MON_VERSION_END "END" 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /core/common/libc/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | CSOURCES = $(wildcard *.c) 18 | include $(PROJS)/core/rule.linux 19 | 20 | SUBDIRS = em64t 21 | 22 | .PHONY: all 23 | 24 | all: 25 | $(foreach D, $(SUBDIRS), $(MAKE) -C $(D);) 26 | -------------------------------------------------------------------------------- /core/common/libc/bitarray_utilities.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #include "mon_defs.h" 18 | #include "hw_utils.h" 19 | 20 | /*************************************************************************** 21 | * 22 | * Implement utilities for BITARRAY 23 | * 24 | ***************************************************************************/ 25 | 26 | #if 8 == ARCH_ADDRESS_WIDTH 27 | #define SCAN_TYPE uint64_t 28 | #define SCAN_FUNC hw_scan_bit_forward64 29 | #else 30 | #define SCAN_TYPE uint32_t 31 | #define SCAN_FUNC hw_scan_bit_forward 32 | #endif 33 | 34 | void bitarray_enumerate_bits(uint8_t *bitarray, uint32_t bitarray_size_in_bits, 35 | func_bitarray_enum_t cb, void *cb_data) 36 | { 37 | uint32_t base_field_id = 0; 38 | uint32_t idx; 39 | uint32_t bit_idx; 40 | uint32_t bytes_to_copy; 41 | uint32_t extra_bytes; 42 | 43 | union { 44 | SCAN_TYPE uint; 45 | uint8_t uint8[sizeof(SCAN_TYPE)]; 46 | } temp_mask; 47 | 48 | /* something was changed. need to copy it to the hw data base */ 49 | base_field_id = 0; 50 | 51 | while (base_field_id < bitarray_size_in_bits) { 52 | /* fill what to search. Bit numbers in our case raise from MSB to LSB. */ 53 | bytes_to_copy = sizeof(SCAN_TYPE); 54 | extra_bytes = (bitarray_size_in_bits - base_field_id + 7) / 8; 55 | if (extra_bytes < bytes_to_copy) { 56 | bytes_to_copy = extra_bytes; 57 | } 58 | 59 | temp_mask.uint = 0; 60 | for (idx = 0; idx < bytes_to_copy; ++idx) 61 | temp_mask.uint8[idx] = 62 | bitarray[BITARRAY_BYTE(base_field_id + idx * 63 | 8)]; 64 | 65 | while (temp_mask.uint != 0) { 66 | SCAN_FUNC(&bit_idx, temp_mask.uint); 67 | 68 | BITARRAY_CLR(temp_mask.uint8, bit_idx); 69 | 70 | cb(base_field_id + bit_idx, cb_data); 71 | } 72 | 73 | base_field_id += sizeof(SCAN_TYPE) * 8; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /core/common/libc/em64t/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | CSOURCES = $(wildcard *.c) 18 | ASOURCES = $(wildcard *.S) 19 | include $(PROJS)/core/rule.linux 20 | -------------------------------------------------------------------------------- /core/common/libc/em64t/em64t_mem.S: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | #------------------------------------------------------------------------------ 18 | # System V AMD64 ABI for passing parameters and preserved registers: 19 | # Registers for passing parameters: 20 | # %rdi, %rsi, %rdx, %rcx, %r8, %r9 21 | # Preserved registers: 22 | # %rbp, %rbx, %rdi, %rsi, %rsp, %r12-r15 23 | #------------------------------------------------------------------------------ 24 | 25 | .extern mon_memset 26 | .extern mon_memcpy 27 | .extern mon_strlen 28 | 29 | .text 30 | 31 | 32 | #------------------------------------------------------------------------------ 33 | # force compiler intrinsics to use our code 34 | #------------------------------------------------------------------------------ 35 | .globl memset 36 | memset: 37 | jmp mon_memset 38 | 39 | 40 | .globl memcpy 41 | memcpy: 42 | jmp mon_memcpy 43 | 44 | .globl strlen 45 | strlen: 46 | jmp mon_strlen 47 | 48 | .globl strcpy 49 | strcpy: 50 | jmp mon_strcpy 51 | 52 | .globl strncpy 53 | strncpy: 54 | jmp mon_strcpy_s 55 | 56 | #**************************************************************************** 57 | #* 58 | #* Lock exchange qword 59 | #* void_t 60 | #* mon_lock_xchg_qword ( 61 | #* uint64_t *dst, ; rdi 62 | #* uint64_t *src ; rsi 63 | #* ) 64 | #**************************************************************************** 65 | .global mon_lock_xchg_qword 66 | mon_lock_xchg_qword: 67 | push %r8 68 | 69 | movq (%rsi), %r8 # copy src to r8 70 | lock xchgq %r8, (%rdi) 71 | 72 | pop %r8 73 | ret 74 | 75 | #**************************************************************************** 76 | #* 77 | #* Lock exchange byte 78 | #* void_t 79 | #* mon_lock_xchg_byte ( 80 | #* uint8_t *dst, ; rdi 81 | #* uint8_t *src ; rsi 82 | #* ) 83 | #**************************************************************************** 84 | .global mon_lock_xchg_byte 85 | mon_lock_xchg_byte: 86 | push %rbx 87 | 88 | movb (%rsi), %bl # copy src to bl 89 | lock xchgb %bl, (%rdi) 90 | 91 | pop %rbx 92 | ret 93 | 94 | -------------------------------------------------------------------------------- /core/common/libc/ia32/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | CSOURCES = ia32_low_level.c 17 | include $(PROJS)/loader/rule.linux 18 | -------------------------------------------------------------------------------- /core/dbg/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | CSOURCES = $(wildcard *.c) 18 | include $(PROJS)/core/rule.linux 19 | -------------------------------------------------------------------------------- /core/dbg/cli_libc.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #include "common_libc.h" 18 | #include "hw_utils.h" 19 | #include "cli_libc.h" 20 | 21 | typedef int32_t (*fun_ascii_to_digit_t) (char); 22 | 23 | int CLI_strcmp(char *string1, char *string2) 24 | { 25 | while ((*string1 == *string2) && (0 != *string1)) { 26 | string1++; 27 | string2++; 28 | } 29 | return *string1 - *string2; 30 | } 31 | 32 | int CLI_strncmp(char *string1, char *string2, size_t n) 33 | { 34 | size_t i; 35 | 36 | for (i = 0; i < n; ++i) 37 | if (string1[i] != string2[i]) { 38 | return 1; 39 | } 40 | return 0; 41 | } 42 | 43 | int CLI_is_substr(char *bigstring, char *smallstring) 44 | { 45 | while ((*bigstring == *smallstring) && (0 != *smallstring)) { 46 | bigstring++; 47 | smallstring++; 48 | } 49 | return 0 == *smallstring; 50 | } 51 | 52 | int32_t ascii_to_dec_digit(char ch) 53 | { 54 | if (ch >= '0' && ch <= '9') { 55 | return ch - '0'; 56 | } 57 | return -1; 58 | } 59 | 60 | int32_t ascii_to_hex_digit(char ch) 61 | { 62 | if (ch >= '0' && ch <= '9') { 63 | return ch - '0'; 64 | } 65 | if (ch >= 'a' && ch <= 'f') { 66 | return ch - 'a' + 10; 67 | } 68 | if (ch >= 'A' && ch <= 'F') { 69 | return ch - 'A' + 10; 70 | } 71 | return -1; 72 | } 73 | 74 | uint64_t cli_atol64(char *string, unsigned base, int *perror) 75 | { 76 | uint64_t value = 0; 77 | int32_t last_digit; 78 | fun_ascii_to_digit_t ascii_to_digit; 79 | int error = 0; 80 | 81 | do { 82 | if (10 == base) { 83 | ascii_to_digit = ascii_to_dec_digit; 84 | } else if (16 == base) { 85 | ascii_to_digit = ascii_to_hex_digit; 86 | } else { 87 | error = -1; /* bad base */ 88 | value = 0; 89 | break; 90 | } 91 | 92 | while (*string != 0) { 93 | last_digit = (*ascii_to_digit) (*string); 94 | if (-1 == last_digit) { 95 | error = -1; /* bad input */ 96 | value = 0; 97 | break; 98 | } 99 | value = value * base + last_digit; 100 | string++; 101 | } 102 | } while (0); 103 | 104 | if (NULL != perror) { 105 | *perror = error; 106 | } 107 | return value; 108 | } 109 | 110 | uint32_t cli_atol32(char *string, unsigned base, int *error) 111 | { 112 | return (uint32_t)cli_atol64(string, base, error); 113 | } 114 | -------------------------------------------------------------------------------- /core/dbg/trace.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef TRACE_H 18 | #define TRACE_H 19 | 20 | #include "mon_defs.h" 21 | 22 | #define MAX_TRACE_BUFFERS 1 23 | #define MAX_STRING_LENGTH 128 24 | #define MAX_RECORDS_IN_BUFFER 2048 25 | 26 | typedef struct { 27 | uint64_t tsc; 28 | uint64_t exit_reason; 29 | uint64_t guest_eip; 30 | char string[MAX_STRING_LENGTH]; 31 | } trace_record_data_t; 32 | 33 | boolean_t trace_init(uint32_t max_num_guests, uint32_t max_num_guest_cpus); 34 | 35 | boolean_t trace_add_record(IN uint32_t vm_index, 36 | IN uint32_t cpu_index, 37 | IN uint32_t buffer_index, 38 | IN trace_record_data_t *data); 39 | 40 | boolean_t trace_remove_oldest_record(OUT uint32_t *vm_index, 41 | OUT uint32_t *cpu_index, 42 | OUT uint32_t *buffer_index, 43 | OUT uint32_t *record_index, 44 | OUT trace_record_data_t *data); 45 | 46 | boolean_t trace_lock(void); 47 | 48 | boolean_t trace_unlock(void); 49 | 50 | void trace_set_recyclable(boolean_t recyclable); 51 | 52 | #endif /* TRACE_H */ 53 | -------------------------------------------------------------------------------- /core/guest/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | CSOURCES = $(wildcard *.c) 18 | include $(PROJS)/core/rule.linux 19 | 20 | SUBDIRS = guest_cpu scheduler 21 | 22 | .PHONY: all 23 | 24 | all: 25 | $(foreach D, $(SUBDIRS), $(MAKE) -C $(D);) 26 | -------------------------------------------------------------------------------- /core/guest/guest_cpu/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | CSOURCES = $(wildcard *.c) 18 | include $(PROJS)/core/rule.linux 19 | -------------------------------------------------------------------------------- /core/guest/guest_cpu/guest_cpu_control.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _GUEST_CPU_CONTROL_INTERNAL_H_ 18 | #define _GUEST_CPU_CONTROL_INTERNAL_H_ 19 | 20 | #include "mon_defs.h" 21 | #include "vmx_ctrl_msrs.h" 22 | #include "lock.h" 23 | 24 | /* -------------------------- types ----------------------------------------- */ 25 | typedef struct { 26 | uint8_t counters[64]; 27 | uint64_t bit_field; /* 1bit for each non-zero counter */ 28 | uint64_t minimal_1_settings; /* one time calculated at boot; enforce 1 for each bit set */ 29 | uint64_t minimal_0_settings; /* one time calculated at boot; enforce 0 or each bit cleared */ 30 | } gcpu_vmexit_control_field_counters_t; 31 | 32 | typedef struct { 33 | gcpu_vmexit_control_field_counters_t cr0; 34 | gcpu_vmexit_control_field_counters_t cr4; 35 | gcpu_vmexit_control_field_counters_t pin_ctrls; 36 | gcpu_vmexit_control_field_counters_t processor_ctrls; 37 | gcpu_vmexit_control_field_counters_t processor_ctrls2; 38 | gcpu_vmexit_control_field_counters_t exceptions_ctrls; 39 | gcpu_vmexit_control_field_counters_t vm_entry_ctrls; 40 | gcpu_vmexit_control_field_counters_t vm_exit_ctrls; 41 | mon_lock_t lock; 42 | } gcpu_vmexit_controls_t; 43 | 44 | void guest_cpu_control_setup(guest_cpu_handle_t gcpu); 45 | 46 | typedef enum { 47 | GCPU_TEMP_EXCEPTIONS_EXIT_ON_ALL, 48 | GCPU_TEMP_EXCEPTIONS_RESTORE_ALL, 49 | 50 | GCPU_TEMP_EXIT_ON_PF_AND_CR3, 51 | GCPU_TEMP_RESTORE_PF_AND_CR3, 52 | 53 | GCPU_TEMP_CR0_NO_EXIT_ON_WP, 54 | GCPU_TEMP_CR0_RESTORE_WP, 55 | 56 | GCPU_TEMP_EXIT_ON_INTR_UNBLOCK, 57 | GCPU_TEMP_NO_EXIT_ON_INTR_UNBLOCK, 58 | } gcpu_temp_exceptions_setup_t; 59 | 60 | void gcpu_temp_exceptions_setup(guest_cpu_handle_t gcpu, 61 | gcpu_temp_exceptions_setup_t action); 62 | 63 | boolean_t gcpu_cr3_virtualized(guest_cpu_handle_t gcpu); 64 | 65 | void gcpu_enforce_settings_on_hardware(guest_cpu_handle_t gcpu, 66 | gcpu_temp_exceptions_setup_t action); 67 | 68 | #endif /* _GUEST_CPU_CONTROL_INTERNAL_H_ */ 69 | -------------------------------------------------------------------------------- /core/guest/guest_cpu/unrestricted_guest.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _UNRESTRICTED_GUEST_H 18 | #define _UNRESTRICTED_GUEST_H 19 | 20 | #include "mon_defs.h" 21 | #include "vmcs_init.h" 22 | #include "guest_cpu_internal.h" 23 | 24 | #define IS_MODE_UNRESTRICTED_GUEST(gcpu) (GET_UNRESTRICTED_GUEST_FLAG(gcpu) \ 25 | == 1) 26 | #define SET_MODE_UNRESTRICTED_GUEST(gcpu) SET_UNRESTRICTED_GUEST_FLAG(gcpu) 27 | 28 | #define SET_UNRESTRICTED_GUEST_FLAG(gcpu) \ 29 | BIT_SET((gcpu)->state_flags, GCPU_UNRESTRICTED_GUEST_FLAG) 30 | #define CLR_UNRESTRICTED_GUEST_FLAG(gcpu) \ 31 | BIT_CLR((gcpu)->state_flags, GCPU_UNRESTRICTED_GUEST_FLAG) 32 | #define GET_UNRESTRICTED_GUEST_FLAG(gcpu) \ 33 | BIT_GET((gcpu)->state_flags, GCPU_UNRESTRICTED_GUEST_FLAG) 34 | 35 | /* Counter to run emulator initially and then switch to unrestricted guest. */ 36 | #define UNRESTRICTED_GUEST_EMU_COUNTER 1 37 | 38 | boolean_t mon_is_unrestricted_guest_enabled(guest_cpu_handle_t gcpu); 39 | boolean_t hw_is_unrestricted_guest_enabled(guest_cpu_handle_t gcpu); 40 | void unrestricted_guest_hw_disable(guest_cpu_handle_t gcpu); 41 | 42 | void mon_unrestricted_guest_disable(guest_cpu_handle_t gcpu); 43 | void mon_unrestricted_guest_enable(guest_cpu_handle_t gcpu); 44 | 45 | /* Check whether Unrestricted guest is supported */ 46 | INLINE boolean_t mon_is_unrestricted_guest_supported(void) 47 | { 48 | const vmcs_hw_constraints_t *hw_constraints = 49 | mon_vmcs_hw_get_vmx_constraints(); 50 | 51 | return hw_constraints->unrestricted_guest_supported; 52 | } 53 | 54 | void make_segreg_hw_compliant(guest_cpu_handle_t gcpu, 55 | uint16_t selector, 56 | uint64_t base, 57 | uint32_t limit, 58 | uint32_t attr, 59 | mon_ia32_segment_registers_t reg_id); 60 | 61 | void make_segreg_hw_real_mode_compliant(guest_cpu_handle_t gcpu, 62 | uint16_t selector, 63 | uint64_t base, 64 | uint32_t limit, 65 | uint32_t attr, 66 | mon_ia32_segment_registers_t reg_id); 67 | #endif /* _UNRESTRICTED_GUEST_H */ 68 | -------------------------------------------------------------------------------- /core/guest/scheduler/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | CSOURCES = $(wildcard *.c) 18 | include $(PROJS)/core/rule.linux 19 | -------------------------------------------------------------------------------- /core/host/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | CSOURCES = $(wildcard *.c) 18 | include $(PROJS)/core/rule.linux 19 | 20 | SUBDIRS = hw 21 | 22 | .PHONY: all 23 | 24 | all: 25 | $(foreach D, $(SUBDIRS), $(MAKE) -C $(D);) 26 | -------------------------------------------------------------------------------- /core/host/hw/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | CSOURCES = $(wildcard *.c) 18 | include $(PROJS)/core/rule.linux 19 | 20 | SUBDIRS = em64t 21 | 22 | .PHONY: all 23 | 24 | all: 25 | $(foreach D, $(SUBDIRS), $(MAKE) -C $(D);) 26 | -------------------------------------------------------------------------------- /core/host/hw/em64t/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | CSOURCES = $(wildcard *.c) 18 | ASOURCES = $(wildcard *.S) 19 | include $(PROJS)/core/rule.linux 20 | -------------------------------------------------------------------------------- /core/host/hw/em64t/em64t_interlocked.S: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | # 17 | # Module Name: 18 | # 19 | # em64t_interlocked.s 20 | # 21 | # Abstract: 22 | # 23 | #***************************************************************************** 24 | 25 | .text 26 | 27 | #------------------------------------------------------------------------------ 28 | # Registers for passing parameters: 29 | # %rdi, %rsi, %rdx, %rcx, %r8, %r9 30 | # The rest parameters are in stack 31 | # Preserved regs 32 | # %rbp,%rbx,%r12,%r15 33 | # System calls via syscall 34 | # Kernel destroys %r11, %rcx 35 | # The number of syscall is in %rax 36 | #------------------------------------------------------------------------------ 37 | 38 | 39 | .macro monitor_instr 40 | .ascii "\x0F\x01\xC8" 41 | .endm 42 | 43 | .macro mwait_instr 44 | .ascii "\x0F\x01\xC9" 45 | .endm 46 | 47 | #------------------------------------------------------------------------------ 48 | # 49 | # Execute assembler 'pause' instruction 50 | # 51 | #void ASM_FUNCTION hw_pause( void ); 52 | #------------------------------------------------------------------------------ 53 | .globl hw_pause 54 | hw_pause: 55 | pause 56 | ret 57 | 58 | 59 | #------------------------------------------------------------------------------ 60 | # 61 | # Execute assembler 'monitor' instruction 62 | # 63 | # void ASM_FUNCTION hw_monitor( void* addr, uint32_t extension, uint32_t hint ); 64 | #------------------------------------------------------------------------------ 65 | .globl hw_monitor 66 | hw_monitor: 67 | # on entry 68 | # %rdi RCX contains addr 69 | # %rsi RDX contains extension 70 | # %rdx R8 contains hint 71 | mov %rdi, %rax 72 | mov %rsi, %rcx 73 | # %rdx already contains hint 74 | monitor_instr 75 | ret 76 | 77 | 78 | #------------------------------------------------------------------------------ 79 | # 80 | # Execute assembler 'mwait' instruction 81 | # 82 | # void ASM_FUNCTION hw_mwait( uint32_t extension, uint32_t hint ); 83 | #------------------------------------------------------------------------------ 84 | .globl hw_mwait 85 | hw_mwait: 86 | # on entry 87 | # %rdi RCX contains extension 88 | # %rsi RDX contains hint 89 | mov %rdi, %rcx 90 | mov %rsi, %rax 91 | mwait_instr 92 | ret 93 | 94 | 95 | -------------------------------------------------------------------------------- /core/host/hw/em64t/em64t_setjmp.S: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | # 17 | # Module Name: 18 | # 19 | # em64t_setjmp.S 20 | # 21 | # Abstract: 22 | # 23 | #***************************************************************************** 24 | 25 | .text 26 | 27 | 28 | #------------------------------------------------------------------------------ 29 | # Registers for passing parameters: 30 | # %rdi, %rsi, %rdx, %rcx, %r8, %r9 31 | # The rest parameters are in stack 32 | # Callee saved regs 33 | # %rbp,%rbx,%r12-%r15, %rsp 34 | # System calls via syscall 35 | # Kernel destroys %r11, %rcx 36 | # The number of syscall is in %rax 37 | #------------------------------------------------------------------------------ 38 | 39 | 40 | #------------------------------------------------------------------------------ 41 | # int cdecl 42 | # globl setjmp() 43 | # Arguments: RDI: Buffer to save the context 44 | # Returns : 0 - if first time, retcode otherwise 45 | #------------------------------------------------------------------------------ 46 | .globl setjmp 47 | setjmp: 48 | movq %rbx,(%rdi) 49 | movq %rbp,8(%rdi) 50 | movq %r12,16(%rdi) 51 | movq %r13,24(%rdi) 52 | movq %r14,32(%rdi) 53 | movq %r15,40(%rdi) 54 | pop %rax # Return address, and adjust the stack 55 | movq %rsp,48(%rdi) # Post-return %rsp! 56 | push %rax # Make the call/return stack happy 57 | movq %rax,56(%rdi) # Return address 58 | xorl %eax,%eax # Return value 59 | ret 60 | # end of setjmp() 61 | 62 | 63 | #------------------------------------------------------------------------------ 64 | # void cdecl 65 | # globl longjmp() 66 | # Arguments: RDI: Buffer to save the context 67 | # : RSI: ret code for hw_setjmp 68 | # Returns : 0 - if first time, retcode otherwise 69 | #------------------------------------------------------------------------------ 70 | .globl longjmp 71 | longjmp: 72 | movq %rsi,%rax # Return value (int) 73 | movq (%rdi),%rbx 74 | movq 8(%rdi),%rbp 75 | movq 16(%rdi),%r12 76 | movq 24(%rdi),%r13 77 | movq 32(%rdi),%r14 78 | movq 40(%rdi),%r15 79 | movq 48(%rdi),%rsp 80 | jmp *56(%rdi) 81 | # end of longjmp() 82 | 83 | 84 | .globl hw_exception_post_handler 85 | hw_exception_post_handler: 86 | mov $1, %rsi # err code for longjmp 87 | movq %rsp, %rdi # address of setjmp_buffer_t 88 | jmp longjmp 89 | # end of hw_exception_post_handler() 90 | 91 | 92 | ### EOF ### 93 | 94 | -------------------------------------------------------------------------------- /core/host/hw/em64t/gas_defs.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _GAS_DEFS_H_ 18 | #define _GAS_DEFS_H_ 19 | 20 | #define ARG1_U8 %di 21 | #define ARG1_U16 %di 22 | #define ARG1_U32 %edi 23 | #define ARG1_U64 %rdi 24 | 25 | 26 | #define ARG2_U8 %si 27 | #define ARG2_U16 %si 28 | #define ARG2_U32 %esi 29 | #define ARG2_U64 %rsi 30 | 31 | #define ARG3_U32 %edx 32 | #define ARG3_U64 %rdx 33 | 34 | 35 | #define ARG4_U64 %rcx 36 | #define ARG5_U64 %r8 37 | #define ARG6_U64 %r9 38 | 39 | 40 | /* -- structure definition for mon_gp_registers_t */ 41 | #define IA32_REG_RAX 0 42 | #define IA32_REG_RBX 1 43 | #define IA32_REG_RCX 2 44 | #define IA32_REG_RDX 3 45 | #define IA32_REG_RDI 4 46 | #define IA32_REG_RSI 5 47 | #define IA32_REG_RBP 6 48 | #define IA32_REG_RSP 7 49 | #define IA32_REG_R8 8 50 | #define IA32_REG_R9 9 51 | #define IA32_REG_R10 10 52 | #define IA32_REG_R11 11 53 | #define IA32_REG_R12 12 54 | #define IA32_REG_R13 13 55 | #define IA32_REG_R14 14 56 | #define IA32_REG_R15 15 57 | #define IA32_REG_RIP 16 58 | #define IA32_REG_RFLAGS 17 59 | #define IA32_REG_COUNT 18 60 | 61 | /* __gp_reg_id : IA32_REG_RAX..IA32_REG_RFLAGS */ 62 | #define GR_REG_OFFSET(__gp_reg_id) (__gp_reg_id * 8) 63 | 64 | /* __xmm_reg_id : 0..15 */ 65 | #define XMM_REG_OFFSET(__xmm_reg_id) \ 66 | (GR_REG_OFFSET(IA32_REG_COUNT) + __xmm_reg_id * 16) 67 | 68 | #endif /* _GAS_DEFS_H_ */ 69 | -------------------------------------------------------------------------------- /core/host/hw/reset.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #include "mon_defs.h" 18 | #include "hw_utils.h" 19 | #include "common_libc.h" 20 | #include "mon_dbg.h" 21 | #include "file_codes.h" 22 | 23 | #define MON_DEADLOOP() MON_DEADLOOP_LOG(RESET_C) 24 | #define MON_ASSERT(__condition) MON_ASSERT_LOG(RESET_C, __condition) 25 | 26 | #define RESET_CONTROL_REGISTER_IO_PORT 0xCF9 27 | 28 | typedef enum { 29 | SYSTEM_RESET_BIT = 1, /* 0 = cpu_reset generates an INIT(Soft Reset), 30 | * 1 = cpu_reset generates platform reset (Hard 31 | * Reset) */ 32 | CPU_RESET_BIT = 2, /* 0->1 transition generates the reset type 33 | * specified by system_reset */ 34 | FULL_RESET_BIT = 3 35 | } reset_control_register_bits_t; 36 | 37 | #define SET_SYSTEM_RESET(v) BIT_SET(v, SYSTEM_RESET_BIT) 38 | #define CLR_SYSTEM_RESET(v) BIT_CLR(v, SYSTEM_RESET_BIT) 39 | #define GET_SYSTEM_RESET(v) BIT_GET(v, SYSTEM_RESET_BIT) 40 | 41 | #define SET_CPU_RESET(v) BIT_SET(v, CPU_RESET_BIT) 42 | #define CLR_CPU_RESET(v) BIT_CLR(v, CPU_RESET_BIT) 43 | #define GET_CPU_RESET(v) BIT_GET(v, CPU_RESET_BIT) 44 | 45 | #define SET_FULL_RESET(v) BIT_SET(v, FULL_RESET_BIT) 46 | #define CLR_FULL_RESET(v) BIT_CLR(v, FULL_RESET_BIT) 47 | #define GET_FULL_RESET(v) BIT_GET(v, FULL_RESET_BIT) 48 | 49 | void hw_reset_platform(void) 50 | { 51 | uint8_t reset_control_register; 52 | 53 | /* 54 | * Write the ICH register required to perform a platform reset 55 | * (Cold Reset) 56 | */ 57 | reset_control_register = hw_read_port_8(RESET_CONTROL_REGISTER_IO_PORT); 58 | 59 | SET_CPU_RESET(reset_control_register); 60 | SET_SYSTEM_RESET(reset_control_register); 61 | 62 | hw_write_port_8(RESET_CONTROL_REGISTER_IO_PORT, reset_control_register); 63 | 64 | /* 65 | * Never returns 66 | */ 67 | MON_DEADLOOP(); 68 | } 69 | -------------------------------------------------------------------------------- /core/host/mon_globals.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #include "mon_globals.h" 18 | #include "mon_version_struct.h" 19 | #include "mon_dbg.h" 20 | #include "libc.h" 21 | #include "file_codes.h" 22 | 23 | #define MON_DEADLOOP() MON_DEADLOOP_LOG(MON_GLOBALS_C) 24 | #define MON_ASSERT(__condition) MON_ASSERT_LOG(MON_GLOBALS_C, __condition) 25 | 26 | /*************************************************************************** 27 | * 28 | * Just instaniation of global variables 29 | * 30 | ***************************************************************************/ 31 | 32 | mon_state_t g_mon_state = MON_STATE_UNINITIALIZED; 33 | 34 | #if defined DEBUG 35 | /* This is done to remove out the strings from the release build */ 36 | #ifdef MON_VERSION_STRING 37 | const char *g_mon_version_string = 38 | MON_VERSION_START MON_VERSION_STRING MON_VERSION_END; 39 | #else 40 | const char *g_mon_version_string = NULL; 41 | #endif 42 | #else 43 | const char *g_mon_version_string = NULL; 44 | #endif 45 | 46 | void mon_version_print(void) 47 | { 48 | uint32_t global_string_length = 0; 49 | uint32_t header_len, trailer_len; 50 | uint32_t cur; 51 | 52 | /* 53 | * Version string is surrounded with MON_VERSION_START and MON_VERSION_END 54 | * MON_VERSION_END must be followed with NULL 55 | */ 56 | 57 | if (NULL == g_mon_version_string) { 58 | return; 59 | } 60 | 61 | header_len = (uint32_t)mon_strlen(MON_VERSION_START); 62 | trailer_len = (uint32_t)mon_strlen(MON_VERSION_END); 63 | 64 | MON_ASSERT((0 != header_len) && (0 != trailer_len)) 65 | 66 | global_string_length = (uint32_t)mon_strlen(g_mon_version_string); 67 | 68 | if (global_string_length <= (header_len + trailer_len)) { 69 | /* nothing between header and trailer */ 70 | return; 71 | } 72 | 73 | /* check that header and trailer match */ 74 | for (cur = 0; cur < header_len; ++cur) { 75 | if (g_mon_version_string[cur] != MON_VERSION_START[cur]) { 76 | /* header does not match */ 77 | return; 78 | } 79 | } 80 | 81 | for (cur = 0; cur < trailer_len; ++cur) { 82 | if (g_mon_version_string[global_string_length - trailer_len + 83 | cur] != 84 | MON_VERSION_END[cur]) { 85 | /* trailer does not match */ 86 | return; 87 | } 88 | } 89 | 90 | /* if we are here - version string is ok. Print it. */ 91 | MON_LOG(mask_anonymous, level_trace, 92 | "\n----------------------------------------------------------\n"); 93 | 94 | MON_LOG(mask_anonymous, level_trace, "%*s\n", 95 | global_string_length - header_len - trailer_len, 96 | g_mon_version_string + header_len); 97 | 98 | MON_LOG(mask_anonymous, 99 | level_trace, 100 | "------------------------------------------------------------\n\n"); 101 | } 102 | -------------------------------------------------------------------------------- /core/host/trial_exec.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #include "mon_defs.h" 18 | #include "mon_dbg.h" 19 | #include "trial_exec.h" 20 | #include "file_codes.h" 21 | 22 | #define MON_DEADLOOP() MON_DEADLOOP_LOG(TRIAL_EXEC_C) 23 | #define MON_ASSERT(__condition) MON_ASSERT_LOG(TRIAL_EXEC_C, __condition) 24 | 25 | /* max phys. CPUs supported */ 26 | static trial_data_t *trial_data[MON_MAX_CPU_SUPPORTED]; 27 | 28 | void trial_execution_push(trial_data_t *p_trial_data, setjmp_buffer_t *p_env) 29 | { 30 | cpu_id_t cpu_id = hw_cpu_id(); 31 | 32 | MON_ASSERT(cpu_id < NELEMENTS(trial_data)); 33 | 34 | p_trial_data->saved_env = p_env; 35 | p_trial_data->error_code = 0; 36 | p_trial_data->fault_vector = 0; 37 | p_trial_data->prev = trial_data[cpu_id]; 38 | trial_data[cpu_id] = p_trial_data; 39 | } 40 | 41 | trial_data_t *trial_execution_pop(void) 42 | { 43 | trial_data_t *p_last_trial; 44 | cpu_id_t cpu_id = hw_cpu_id(); 45 | 46 | MON_ASSERT(cpu_id < NELEMENTS(trial_data)); 47 | 48 | if (NULL != trial_data[cpu_id]) { 49 | p_last_trial = trial_data[cpu_id]; 50 | trial_data[cpu_id] = trial_data[cpu_id]->prev; 51 | } else { 52 | MON_LOG(mask_anonymous, level_trace, 53 | "Error. Attempt to Pop Empty Trial Stack\n"); 54 | p_last_trial = NULL; 55 | } 56 | 57 | return p_last_trial; 58 | } 59 | 60 | trial_data_t *trial_execution_get_last(void) 61 | { 62 | cpu_id_t cpu_id = hw_cpu_id(); 63 | 64 | MON_ASSERT(cpu_id < NELEMENTS(trial_data)); 65 | return trial_data[cpu_id]; 66 | } 67 | -------------------------------------------------------------------------------- /core/include/acconfig.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _ACCONFIG_H 18 | #define _ACCONFIG_H 19 | 20 | /* Constants used in searching for the RSDP in low memory */ 21 | #define ACPI_RSDP_SCAN_STEP 16 22 | 23 | /* RSDP checksums */ 24 | 25 | #define ACPI_RSDP_CHECKSUM_LENGTH 20 26 | #define ACPI_RSDP_XCHECKSUM_LENGTH 36 27 | 28 | #endif /* _ACCONFIG_H */ 29 | -------------------------------------------------------------------------------- /core/include/actbl2.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef __ACTBL2_H__ 18 | #define __ACTBL2_H__ 19 | 20 | #define ACPI_SIG_DMAR "DMAR" /* DMA Remapping table */ 21 | 22 | #endif /* __ACTBL2_H__ */ 23 | -------------------------------------------------------------------------------- /core/include/actypes.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef __ACTYPES_H__ 18 | #define __ACTYPES_H__ 19 | 20 | /* Names within the namespace are 4 bytes long */ 21 | #define ACPI_NAME_SIZE 4 22 | /* Sizes for ACPI table headers */ 23 | #define ACPI_OEM_ID_SIZE 6 24 | #define ACPI_OEM_TABLE_ID_SIZE 8 25 | 26 | /* 27 | * Power state values 28 | */ 29 | #define ACPI_STATE_UNKNOWN ((uint8_t)0xFF) 30 | 31 | #define ACPI_STATE_S0 ((uint8_t)0) 32 | #define ACPI_STATE_S1 ((uint8_t)1) 33 | #define ACPI_STATE_S2 ((uint8_t)2) 34 | #define ACPI_STATE_S3 ((uint8_t)3) 35 | #define ACPI_STATE_S4 ((uint8_t)4) 36 | #define ACPI_STATE_S5 ((uint8_t)5) 37 | #define ACPI_S_STATES_MAX ACPI_STATE_S5 38 | #define ACPI_S_STATE_COUNT 6 39 | 40 | #endif /* __ACTYPES_H__ */ 41 | -------------------------------------------------------------------------------- /core/include/address.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _ADDRESS_H_ 18 | #define _ADDRESS_H_ 19 | 20 | void API_FUNCTION addr_setup_address_space(void); 21 | address_t API_FUNCTION addr_canonize_address(address_t address); 22 | uint8_t API_FUNCTION addr_get_physical_address_size(void); 23 | uint8_t API_FUNCTION addr_get_virtual_address_size(void); 24 | 25 | boolean_t API_FUNCTION addr_is_canonical(address_t address); 26 | boolean_t API_FUNCTION addr_physical_is_valid(address_t address); 27 | 28 | #endif /* _ADDRESS_H_ */ 29 | -------------------------------------------------------------------------------- /core/include/appliances/tscdt_emulator_api.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef TSCDT_EMULATOR_API_H 18 | #define TSCDT_EMULATOR_API_H 19 | 20 | typedef enum { 21 | TSCDTE_MODE_OFF, 22 | TSCDTE_MODE_LAPIC_VIRTUALIZATION_OFF, 23 | TSCDTE_MODE_LAPIC_VIRTUALIZATION_USE_MSRS, 24 | TSCDTE_MODE_LAPIC_VIRTUALIZATION_USE_VMCALL, 25 | TSCDTE_MODE_PARTIAL_LAPIC_VIRTUALIZATION, 26 | TSCDTE_MODE_FULL_LAPIC_VIRTUALIZATION 27 | } tscdte_mode_t; 28 | 29 | void tscdte_initialize(tscdte_mode_t mode); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /core/include/cache64.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _CACHE64_H_ 18 | #define _CACHE64_H_ 19 | 20 | typedef struct cache64_struct_t *cache64_object_t; 21 | 22 | typedef void (*func_cache64_field_process_t) (uint32_t entry_no, void *arg); 23 | 24 | #define CACHE_ALL_ENTRIES ((uint32_t)-1) 25 | 26 | #define CACHE_DIRTY_FLAG 1 27 | #define CACHE_VALID_FLAG 2 28 | 29 | cache64_object_t cache64_create(uint32_t num_of_entries); 30 | void cache64_write(cache64_object_t cache, uint64_t value, uint32_t entry_no); 31 | /* return TRUE if entry is valid */ 32 | boolean_t cache64_read(cache64_object_t cache, 33 | uint64_t *p_value, 34 | uint32_t entry_no); 35 | /* return cache flags */ 36 | uint32_t cache64_read_raw(cache64_object_t cache, 37 | uint64_t *p_value, 38 | uint32_t entry_no); 39 | /* clean valid bits */ 40 | void cache64_invalidate(cache64_object_t cache, uint32_t entry_no); 41 | /* clean dirty bits */ 42 | void cache64_flush_dirty(cache64_object_t cache, 43 | uint32_t entry_no, 44 | func_cache64_field_process_t function, 45 | void *arg); 46 | void cache64_flush_to_memory(cache64_object_t cache, 47 | void *p_dest, 48 | uint32_t max_bytes); 49 | /* return TRUE if any field is dirty valid */ 50 | boolean_t cache64_is_dirty(cache64_object_t cache); 51 | void cache64_destroy(cache64_object_t cache); 52 | 53 | #endif /* _CACHE64_H_ */ 54 | -------------------------------------------------------------------------------- /core/include/cli.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _CLI_H_ 18 | #define _CLI_H_ 19 | 20 | #if defined(__cplusplus) 21 | extern "C" { 22 | #endif 23 | 24 | #include "cli_env.h" 25 | 26 | typedef int (*func_cli_t) (unsigned argc, char *args[]); 27 | 28 | #ifdef CLI_INCLUDE 29 | 30 | void cli_open_session(const char *reason, uint32_t access_level); 31 | boolean_t cli_close_session(void); 32 | void cli_end_session(boolean_t cli_retvalue); 33 | boolean_t cli_is_session_active(void); 34 | boolean_t cli_is_session_active_on_this_cpu(void); 35 | void cli_print_session_reason(void); 36 | int cli_add_command(func_cli_t function, 37 | char *path, 38 | char *help, 39 | char *usage, 40 | uint32_t access_level); 41 | int cli_exec_command(char *path); 42 | void cli_prompt(void); 43 | void cli_init(void); 44 | void cli_emulator_register(guest_id_t guest_id); 45 | uint32_t cli_get_level(void); 46 | boolean_t cli_set_level(uint32_t level); 47 | 48 | #else /* ! CLI_INCLUDE */ 49 | 50 | INLINE void cli_open_session(const char *reason, uint32_t access_level) 51 | { 52 | } 53 | INLINE boolean_t cli_close_session(void) 54 | { 55 | return FALSE; 56 | } 57 | INLINE void cli_end_session(boolean_t cli_retvalue) 58 | { 59 | } 60 | INLINE boolean_t cli_is_session_active(void) 61 | { 62 | return FALSE; 63 | } 64 | INLINE boolean_t cli_is_session_active_on_this_cpu(void) 65 | { 66 | return FALSE; 67 | } 68 | INLINE void cli_print_session_reason(void) 69 | { 70 | } 71 | INLINE int cli_add_command(func_cli_t function, char *path, char *help, 72 | char *usage, uint32_t access_level) 73 | { 74 | return -1; 75 | } 76 | INLINE int cli_exec_command(char *path) 77 | { 78 | return -1; 79 | } 80 | INLINE void cli_prompt(void) 81 | { 82 | } 83 | INLINE void cli_emulator_register(guest_id_t guest_id) 84 | { 85 | } 86 | INLINE uint32_t cli_get_level(void) 87 | { 88 | return 0; 89 | } 90 | INLINE boolean_t cli_set_level(uint32_t level) 91 | { 92 | return FALSE; 93 | } 94 | #endif /* CLI_INCLUDE */ 95 | 96 | #if defined(__cplusplus) 97 | } 98 | #endif 99 | 100 | #endif /* _CLI_H_ */ 101 | -------------------------------------------------------------------------------- /core/include/cli_libc.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _CLI_LIBC_H_ 18 | #define _CLI_LIBC_H_ 19 | 20 | #include "mon_defs.h" 21 | #include "libc.h" 22 | 23 | int CLI_strcmp(char *string1, char *string2); 24 | int CLI_strncmp(char *string1, char *string2, size_t n); 25 | int CLI_is_substr(char *bigstring, char *smallstring); 26 | uint32_t cli_atol32(char *string, unsigned base, int *error); 27 | uint64_t cli_atol64(char *string, unsigned base, int *error); 28 | 29 | #endif /* _CLI_LIBC_H_ */ 30 | -------------------------------------------------------------------------------- /core/include/cli_monitor.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _CLI_MONITOR_H_ 18 | #define _CLI_MONITOR_H_ 19 | 20 | #include "cli_env.h" 21 | 22 | #ifdef CLI_INCLUDE 23 | 24 | void cli_monitor_init(void); 25 | /* returns TRUE if BREAK_POINT is required */ 26 | boolean_t cli_monitor(const char *title, uint32_t access_level); 27 | 28 | boolean_t cli_deadloop_helper(const char *assert_condition, 29 | const char *func_name, 30 | const char *file_name, 31 | uint32_t line_num, 32 | uint32_t access_level); 33 | 34 | /* returns TRUE if MON_BREAKPOINT is required */ 35 | void cli_handle_error(const char *assert_condition, 36 | const char *func_name, 37 | const char *file_name, 38 | uint32_t line_num, 39 | uint32_t error_level); 40 | #else /* ! CLI_INCLUDE */ 41 | 42 | 43 | INLINE void cli_monitor_init(void) 44 | { 45 | } 46 | 47 | INLINE boolean_t cli_monitor(const char *title, uint32_t access_level) 48 | { 49 | return FALSE; 50 | } 51 | 52 | INLINE boolean_t cli_deadloop_helper(const char *assert_condition, 53 | const char *func_name, 54 | const char *file_name, 55 | uint32_t line_num, 56 | uint32_t access_level) 57 | { 58 | return TRUE; 59 | } 60 | 61 | INLINE void cli_handle_error(const char *assert_condition, 62 | const char *func_name, 63 | const char *file_name, 64 | uint32_t line_num, 65 | uint32_t error_level) 66 | { 67 | MON_UP_BREAKPOINT(); 68 | } 69 | 70 | 71 | #endif /* CLI_INCLUDE */ 72 | 73 | #endif /* _CLI_MONITOR_H_ */ 74 | -------------------------------------------------------------------------------- /core/include/device_drivers_manager.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef DEVICE_DRIVERS_MANAGER_H 18 | #define DEVICE_DRIVERS_MANAGER_H 19 | 20 | #include 21 | #include 22 | 23 | void ddm_initialize(void); 24 | void ddm_register_guest(guest_handle_t guest_handle); 25 | boolean_t ddm_notify_driver(uint64_t descriptor_handle, uint32_t component_id); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /core/include/guest_pci_configuration.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _GUEST_PCI_CONFIG_H 18 | #define _GUEST_PCI_CONFIG_H 19 | 20 | #include "list.h" 21 | #include "host_pci_configuration.h" 22 | #include "mon_objects.h" 23 | 24 | struct guest_pci_device_t; 25 | 26 | typedef void (*guest_pci_read_handler_t) (guest_cpu_handle_t gcpu, 27 | struct guest_pci_device_t *pci_device, 28 | uint32_t port_id, uint32_t port_size, 29 | void *value); 30 | 31 | typedef void (*guest_pci_write_handler_t) (guest_cpu_handle_t gcpu, 32 | struct guest_pci_device_t *pci_device, 33 | uint32_t port_id, uint32_t port_size, 34 | void *value); 35 | 36 | typedef struct { 37 | guest_pci_read_handler_t pci_read; 38 | guest_pci_write_handler_t pci_write; 39 | } gpci_guest_profile_t; 40 | 41 | typedef enum { 42 | GUEST_DEVICE_VIRTUALIZATION_DIRECT_ASSIGNMENT, 43 | GUEST_DEVICE_VIRTUALIZATION_HIDDEN 44 | } guest_device_virtualization_type_t; 45 | 46 | typedef struct guest_pci_device_t { 47 | guest_id_t guest_id; 48 | char padding[2]; 49 | guest_device_virtualization_type_t type; 50 | host_pci_device_t *host_device; 51 | guest_pci_read_handler_t pci_read; 52 | guest_pci_write_handler_t pci_write; 53 | uint8_t *config_space; 54 | } guest_pci_device_t; 55 | 56 | typedef struct { 57 | guest_id_t guest_id; 58 | char padding[2]; 59 | uint32_t num_devices; 60 | guest_pci_device_t devices[PCI_MAX_NUM_SUPPORTED_DEVICES + 1]; 61 | /* index 0 is reserved to mark "not-present" device */ 62 | pci_dev_index_t device_lookup_table[PCI_MAX_NUM_FUNCTIONS]; 63 | list_element_t guests[1]; 64 | pci_config_address_t *gcpu_pci_access_address; 65 | } guest_pci_devices_t; 66 | 67 | boolean_t gpci_initialize(void); 68 | 69 | boolean_t gpci_guest_initialize(guest_id_t guest_id); 70 | 71 | boolean_t gpci_register_device(guest_id_t guest_id, 72 | guest_device_virtualization_type_t type, 73 | host_pci_device_t *host_pci_device, 74 | uint8_t *config_space, 75 | guest_pci_read_handler_t pci_read, 76 | guest_pci_write_handler_t pci_write); 77 | 78 | guest_id_t gpci_get_device_guest_id(uint16_t bus, 79 | uint16_t device, 80 | uint16_t function); 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /core/include/hw/8259a_pic.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _8259A_PIC_H 18 | #define _8259A_PIC_H 19 | 20 | #include "mon_defs.h" 21 | 22 | /************************************************************************* 23 | * 24 | * 8259A Prigrammable Interrupt Controller (legacy) 25 | * 26 | *************************************************************************/ 27 | 28 | /* 29 | * Init PIC support. Accesses HW PIC and changes its Read Register Command 30 | * state 31 | * to IRR read. 32 | * Registers to ICW3 port writes for the given guest to trace 33 | * Read Register Command state changes. */ 34 | void pic_init(guest_id_t pic_owner); 35 | 36 | /* Test for ready-to-be-accepted fixed interrupts. */ 37 | boolean_t pic_is_ready_interrupt_exist(void); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /core/include/hw/efer_msr_abstraction.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef EFER_MSR_ABSTRACTION_H 18 | #define EFER_MSR_ABSTRACTION_H 19 | 20 | /* Function: efer_msr_set_nxe 21 | * Description: This function sets NXE bit in hardware EFER MSR register 22 | */ 23 | void efer_msr_set_nxe(void); 24 | 25 | /* Function: efer_msr_is_nxe_bit_set 26 | * Description: This function checks whether NXE bit is set in EFER MSR value 27 | * Input: efer_msr_value - 64 bit value of EFER MSR 28 | * Return Value: TRUE or FALSE 29 | */ 30 | boolean_t efer_msr_is_nxe_bit_set(IN uint64_t efer_msr_value); 31 | 32 | /* Function: efer_msr_read_reg 33 | * Description: This function reads and returns the value of hardware EFER MSR 34 | * Return Value: 64 bit value of EFER MSR 35 | */ 36 | uint64_t efer_msr_read_reg(void); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /core/include/hw/gdt.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _GDT_H_ 18 | #define _GDT_H_ 19 | 20 | #define TSS_ENTRY_SIZE (sizeof(address_t) * 2) 21 | #define TSS_ENTRY_OFFSET(__cpuid) \ 22 | (TSS_FIRST_GDT_ENTRY_OFFSET + (__cpuid) * TSS_ENTRY_SIZE) 23 | 24 | enum { 25 | NULL_GDT_ENTRY_OFFSET = 0, 26 | DATA32_GDT_ENTRY_OFFSET = 8, 27 | CODE32_GDT_ENTRY_OFFSET = 0x10, 28 | CODE64_GDT_ENTRY_OFFSET = 0x18, 29 | TSS_FIRST_GDT_ENTRY_OFFSET = 0x20, 30 | /* this value is used in assembler. */ 31 | CPU_LOCATOR_GDT_ENTRY_OFFSET = TSS_FIRST_GDT_ENTRY_OFFSET 32 | }; 33 | 34 | void hw_gdt_setup(cpu_id_t number_of_cpus); 35 | void hw_gdt_load(cpu_id_t cpu_id); 36 | void hw_gdt_set_ist_pointer(cpu_id_t cpu_id, uint8_t ist_no, address_t address); 37 | mon_status_t hw_gdt_parse_entry(IN uint8_t *p_gdt, 38 | IN uint16_t selector, 39 | OUT address_t *p_base, 40 | OUT uint32_t *p_limit, 41 | OUT uint32_t *p_attributes); 42 | 43 | #endif /*_GDT_H_ */ 44 | -------------------------------------------------------------------------------- /core/include/hw/host_pci_configuration.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _HOST_PCI_CONFIG_H 18 | #define _HOST_PCI_CONFIG_H 19 | 20 | #include "pci_configuration.h" 21 | 22 | typedef struct host_pci_device_t { 23 | pci_device_address_t address; 24 | char padding0[6]; 25 | struct host_pci_device_t *parent; 26 | uint8_t depth; /* number of bridges up to the device */ 27 | pci_path_t path; /* path to the device */ 28 | uint16_t vendor_id; 29 | uint16_t device_id; 30 | uint8_t revision_id; /* device-specific revision id chosen by vendor */ 31 | uint8_t base_class; 32 | uint8_t sub_class; 33 | uint8_t programming_interface; 34 | uint8_t header_type; /* =0x0 for devices, 0x1 for p2p bridge, 0x2 for cardbus bridge */ 35 | char padding1[1]; 36 | boolean_t is_multifunction; 37 | boolean_t is_pci_2_pci_bridge; /* baseclass and subclass specify pci2pci bridge */ 38 | uint8_t interrupt_pin; /* interrupt pin (R/O) used by the device (INTA, INTB, INTC or INTD) */ 39 | uint8_t interrupt_line; /* interrupt line that connects to interrupt controller (0xFF - not connected) */ 40 | char padding2[2]; 41 | pci_base_address_register_t bars[PCI_MAX_BAR_NUMBER]; 42 | } host_pci_device_t; 43 | 44 | uint8_t pci_read8(uint8_t bus, uint8_t device, uint8_t function, 45 | uint8_t reg_id); 46 | void pci_write8(uint8_t bus, 47 | uint8_t device, 48 | uint8_t function, 49 | uint8_t reg_id, 50 | uint8_t value); 51 | 52 | uint16_t pci_read16(uint8_t bus, 53 | uint8_t device, 54 | uint8_t function, 55 | uint8_t reg_id); 56 | void pci_write16(uint8_t bus, 57 | uint8_t device, 58 | uint8_t function, 59 | uint8_t reg_id, 60 | uint16_t value); 61 | 62 | uint32_t pci_read32(uint8_t bus, 63 | uint8_t device, 64 | uint8_t function, 65 | uint8_t reg_id); 66 | void pci_write32(uint8_t bus, 67 | uint8_t device, 68 | uint8_t function, 69 | uint8_t reg_id, 70 | uint32_t value); 71 | 72 | void host_pci_initialize(void); 73 | 74 | host_pci_device_t *get_host_pci_device(uint8_t bus, 75 | uint8_t device, 76 | uint8_t function); 77 | 78 | boolean_t pci_read_secondary_bus_reg(uint8_t bus, 79 | uint8_t device, 80 | uint8_t func, 81 | OUT uint8_t *secondary_bus); 82 | 83 | uint32_t host_pci_get_num_devices(void); 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /core/include/hw/hw_setjmp.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _HW_SETJMP_H_ 18 | #define _HW_SETJMP_H_ 19 | 20 | /* Context saved registers: 21 | * rbx, rbp 22 | * r12, r13, r14, r15, 23 | * rsp, rip */ 24 | #define SETJMP_BUFFER_ITEMS 8 25 | 26 | typedef uint8_t setjmp_buffer_t[SETJMP_BUFFER_ITEMS * sizeof(address_t)]; 27 | 28 | extern int setjmp(setjmp_buffer_t *env); 29 | extern void longjmp(setjmp_buffer_t *env, int errcode); 30 | extern void hw_exception_post_handler(void); 31 | 32 | #endif /* _HW_SETJMP_H_ */ 33 | -------------------------------------------------------------------------------- /core/include/hw/idt.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _IDT_H_ 18 | #define _IDT_H_ 19 | 20 | /*-------------------------------------------------------* 21 | * FUNCTION : hw_idt_register_handler() 22 | * PURPOSE : Register interrupt handler at spec. vector 23 | * ARGUMENTS : uint8_t vector_id 24 | * : address_t handler - address of function 25 | * RETURNS : void 26 | *-------------------------------------------------------*/ 27 | void hw_idt_register_handler(vector_id_t vector_id, 28 | address_t isr_handler_address); 29 | 30 | /*-------------------------------------------------------* 31 | * FUNCTION : hw_idt_load() 32 | * PURPOSE : Load IDT descriptor into IDTR on given CPU 33 | * ARGUMENTS : void 34 | * RETURNS : void 35 | *-------------------------------------------------------*/ 36 | void hw_idt_load(void); 37 | 38 | /*-------------------------------------------------------* 39 | * FUNCTION : hw_idt_setup() 40 | * PURPOSE : Build and populate IDT tables, one per CPU 41 | * ARGUMENTS : void 42 | * RETURNS : void 43 | *-------------------------------------------------------*/ 44 | void hw_idt_setup(void); 45 | 46 | /*----------------------------------------------------* 47 | * FUNCTION : idt_get_extra_stacks_required() 48 | * PURPOSE : Returns the number of extra stacks required by ISRs 49 | * ARGUMENTS : void 50 | * RETURNS : number between 0..7 51 | * NOTES : per CPU 52 | *-------------------------------------------------------*/ 53 | uint8_t idt_get_extra_stacks_required(void); 54 | 55 | #endif /* _IDT_H_ */ 56 | -------------------------------------------------------------------------------- /core/include/hw/mon_phys_mem_types.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef MON_PHYS_MEM_TYPES_H 18 | #define MON_PHYS_MEM_TYPES_H 19 | 20 | typedef enum { 21 | MON_PHYS_MEM_UNCACHABLE = 0x0, /* UC */ 22 | MON_PHYS_MEM_WRITE_COMBINING = 0x1, /* WC */ 23 | MON_PHYS_MEM_WRITE_THROUGH = 0x4, /* WT */ 24 | MON_PHYS_MEM_WRITE_PROTECTED = 0x5, /* WP */ 25 | MON_PHYS_MEM_WRITE_BACK = 0x6, /* WB */ 26 | MON_PHYS_MEM_UNCACHED = 0x7, /* UC- */ 27 | MON_PHYS_MEM_LAST_TYPE = MON_PHYS_MEM_UNCACHED, 28 | MON_PHYS_MEM_UNDEFINED = (~0) 29 | } mon_phys_mem_type_t; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /core/include/hw/vmx_asm.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _VMX_ASM_H_ 18 | #define _VMX_ASM_H_ 19 | 20 | /*------------------------------------------------------------------------* 21 | * FUNCTION : vmexit_func() 22 | * PURPOSE : Called upon VMEXIT. It in turn calls vmexit_common_handler() 23 | * ARGUMENTS: none 24 | * RETURNS : void 25 | *------------------------------------------------------------------------*/ 26 | void ASM_FUNCTION vmexit_func(void); 27 | 28 | /*------------------------------------------------------------------------* 29 | * FUNCTION : vmentry_func() 30 | * PURPOSE : Called upon VMENTER. 31 | * ARGUMENTS: int32_t launch - if not zero do VMLAUNCH, otherwise VMRESUME 32 | * RETURNS : void 33 | *------------------------------------------------------------------------*/ 34 | void ASM_FUNCTION vmentry_func(int32_t launch); 35 | 36 | void ASM_FUNCTION ITP_JMP_DEADLOOP(void); 37 | 38 | #endif /* _VMX_ASM_H_ */ 39 | -------------------------------------------------------------------------------- /core/include/hw/vtd_acpi_dmar.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _VTD_ACPI_DMAR_H 18 | #define _VTD_ACPI_DMAR_H 19 | 20 | #include "mon_defs.h" 21 | #include "pci_configuration.h" 22 | #include "list.h" 23 | 24 | typedef pci_device_address_t source_id_t; 25 | 26 | typedef enum { 27 | DMAR_DEVICE_PCI_DEVICE, 28 | DMAR_DEVICE_IOAPIC, 29 | DMAR_DEVICE_HPET 30 | } dmar_device_type_t; 31 | 32 | typedef struct { 33 | dmar_device_type_t type; 34 | source_id_t source_id; /* pci-device or HPET */ 35 | uint8_t ioapic_id; /* valid if type == IOAPIC */ 36 | char padding0[1]; 37 | } dmar_device_t; 38 | 39 | typedef struct { 40 | list_element_t list; 41 | uint32_t id; 42 | boolean_t include_all; 43 | uint16_t segment; 44 | char padding0[6]; 45 | uint64_t register_base; 46 | uint16_t num_devices; 47 | char padding1[6]; 48 | dmar_device_t *devices; 49 | } dmar_hw_unit_t; 50 | 51 | typedef struct { 52 | list_element_t list; 53 | uint16_t segment; 54 | char padding0[6]; 55 | uint64_t base; 56 | uint64_t limit; 57 | uint16_t num_devices; 58 | char padding1[6]; 59 | dmar_device_t *devices; 60 | } dmar_reserved_memory_t; 61 | 62 | typedef struct { 63 | list_element_t list; 64 | uint16_t segment; 65 | char padding0[2]; 66 | boolean_t supported_on_all_ports; 67 | uint16_t num_devices; 68 | char padding1[6]; 69 | dmar_device_t *devices; 70 | } dmar_addr_translation_service_t; 71 | 72 | int vtd_acpi_dmar_init(hva_t address); 73 | void restore_dmar_table(void); 74 | 75 | uint32_t dmar_num_dma_remapping_hw_units(void); 76 | 77 | list_element_t *dmar_get_dmar_unit_definitions(void); 78 | list_element_t *dmar_get_reserved_memory_regions(void); 79 | 80 | boolean_t rmrr_contains_device(dmar_reserved_memory_t *rmrr, 81 | uint8_t bus, 82 | uint8_t device, 83 | uint8_t function); 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /core/include/hw/vtd_domain.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _VTD_DOMAIN_H 18 | #define _VTD_DOMAIN_H 19 | 20 | #include "list.h" 21 | #include "memory_address_mapper_api.h" 22 | #include "vtd_acpi_dmar.h" 23 | #include "mon_startup.h" 24 | 25 | typedef uint32_t vtd_domain_id_t; 26 | 27 | #define INVALID_VTD_DOMAIN_ID ((vtd_domain_id_t)-1) 28 | 29 | typedef struct { 30 | list_element_t list; /* list of devices that belong to the same domain */ 31 | source_id_t source_id; 32 | char padding[6]; 33 | } vtd_pci_device_t; 34 | 35 | typedef struct { 36 | vtd_domain_id_t domain_id; 37 | uint32_t sagaw_bit_index; 38 | guest_id_t guest_id; 39 | char padding0[6]; 40 | mam_handle_t address_space; 41 | uint64_t address_space_root; 42 | list_element_t devices; 43 | struct vtd_dma_remapping_hw_uint_t *dmar; 44 | list_element_t list; /* list of all existing domains */ 45 | list_element_t dmar_list; /* list of domains in the same dmar */ 46 | } vtd_domain_t; 47 | 48 | vtd_domain_t *vtd_domain_create(mam_handle_t address_space, 49 | uint32_t sagaw_bit_index); 50 | vtd_domain_t *vtd_domain_create_guest_domain(struct vtd_dma_remapping_hw_uint_t 51 | *dmar, 52 | guest_id_t gid, 53 | uint32_t sagaw_bit_index, 54 | const mon_memory_layout_t * 55 | mon_memory_layout, 56 | const mon_application_params_struct_t * 57 | application_params); 58 | 59 | vtd_domain_t *vtd_get_domain(struct vtd_dma_remapping_hw_uint_t *dmar, 60 | vtd_domain_id_t domain_id); 61 | list_element_t *vtd_get_domain_list(void); 62 | 63 | boolean_t vtd_domain_add_device(vtd_domain_t *domain, 64 | uint8_t bus, 65 | uint8_t device, 66 | uint8_t function); 67 | void vtd_domain_remove_device(vtd_domain_t *domain, 68 | uint8_t bus, 69 | uint8_t device, 70 | uint8_t function); 71 | 72 | boolean_t vtd_domain_add_to_dmar(vtd_domain_t *domain, 73 | struct vtd_dma_remapping_hw_uint_t *dmar); 74 | 75 | uint64_t vtd_domain_get_address_space_root(vtd_domain_t *domain, 76 | mam_vtdpt_snoop_behavior_t common_snpb, 77 | mam_vtdpt_trans_mapping_t common_tm); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /core/include/hw_includes.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _HW_INCLUDES_H_ 18 | #define _HW_INCLUDES_H_ 19 | 20 | #include "hw_utils.h" 21 | #include "hw_interlocked.h" 22 | 23 | #endif /* _HW_INCLUDES_H_ */ 24 | -------------------------------------------------------------------------------- /core/include/libc.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _MON_CRT_H_ 18 | #define _MON_CRT_H_ 19 | 20 | #include "common_libc.h" 21 | 22 | /* 23 | * Set of CRT-like routines to be used in MON environment 24 | */ 25 | #define EOF (-1) 26 | 27 | /*------------------------------------------------------------------------- 28 | * 29 | * Console I/O functions 30 | * 31 | * The normal version of putc() and puts() perform locking of the output as a 32 | * critical resource, in order to avoid intermingling of printed lines. 33 | * The "nolock" version of these functions just print to the output. They 34 | * should be used in places, such as exception handlers, where there's a danger 35 | * of deadlock (should they be called while the output is locked). */ 36 | 37 | void mon_libc_init(void); 38 | int mon_puts(const char *string); 39 | int mon_puts_nolock(const char *string); 40 | uint8_t mon_putc(uint8_t ch); 41 | uint8_t mon_putc_nolock(uint8_t ch); 42 | uint8_t mon_getc(void); 43 | 44 | /*------------------------------------------------------------------------- 45 | * 46 | * mon_printf() is declared in the common_libc.h 47 | * If uses global buffers and use locks for avoid cluttered prints on COM port 48 | * 49 | *------------------------------------------------------------------------- */ 50 | 51 | /*------------------------------------------------------------------------- 52 | * 53 | * mon_printf_nolock() 54 | * 55 | * Like mon_printf() but uses buffers on the stack and does not use locks 56 | * 57 | * Use it in the NMI handler to avoid deadlocks 58 | * 59 | *------------------------------------------------------------------------- */ 60 | int CDECL mon_printf_nolock(const char *format, ...); 61 | 62 | #endif /* _MON_CRT_H_ */ 63 | -------------------------------------------------------------------------------- /core/include/lock.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _MON_LOCK_H_ 18 | #define _MON_LOCK_H_ 19 | 20 | #include "mon_defs.h" 21 | #include "hw_interlocked.h" 22 | #include "mon_dbg.h" 23 | 24 | typedef struct { 25 | volatile uint32_t uint32_lock; 26 | volatile cpu_id_t owner_cpu_id; 27 | char padding[2]; 28 | } mon_lock_t; 29 | 30 | #define LOCK_INIT_STATE { (uint32_t)0, (cpu_id_t)-1, 0 } 31 | 32 | /* 33 | * Read/Write lock 34 | * 35 | * multiple readers can read the data in parallel but an exclusive lock is 36 | * needed while writing the data. When a writer is writing the data, readers 37 | * will be blocked until the writer has finished writing 38 | */ 39 | typedef struct { 40 | mon_lock_t lock; 41 | uint32_t padding; 42 | volatile int32_t readers; 43 | } mon_read_write_lock_t; 44 | 45 | /* 46 | * Various locking routines 47 | */ 48 | void lock_acquire(mon_lock_t *lock); 49 | 50 | void interruptible_lock_acquire(mon_lock_t *lock); 51 | 52 | void lock_release(mon_lock_t *lock); 53 | 54 | void lock_initialize(mon_lock_t *lock); 55 | 56 | #ifdef DEBUG 57 | void lock_print(mon_lock_t *lock); 58 | #endif 59 | 60 | void lock_initialize_read_write_lock(mon_read_write_lock_t *lock); 61 | 62 | void lock_acquire_readlock(mon_read_write_lock_t *lock); 63 | 64 | void interruptible_lock_acquire_readlock(mon_read_write_lock_t *lock); 65 | 66 | void lock_release_readlock(mon_read_write_lock_t *lock); 67 | 68 | void lock_acquire_writelock(mon_read_write_lock_t *lock); 69 | 70 | void interruptible_lock_acquire_writelock(mon_read_write_lock_t *lock); 71 | 72 | void lock_release_writelock(mon_read_write_lock_t *lock); 73 | 74 | #endif /* _MON_LOCK_H_ */ 75 | -------------------------------------------------------------------------------- /core/include/mon_acpi.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _MON_ACPI_H_ 18 | #define _MON_ACPI_H_ 19 | 20 | #define ACPI_PM1_CNTRL_REG_A 0 21 | #define ACPI_PM1_CNTRL_REG_B 1 22 | #define ACPI_PM1_CNTRL_REG_COUNT 2 23 | 24 | #include "actypes.h" 25 | #include "actbl.h" 26 | #include "actbl2.h" 27 | #include "acconfig.h" 28 | 29 | int mon_acpi_init(hva_t address); 30 | acpi_table_header_t *mon_acpi_locate_table(char *sig); 31 | uint16_t mon_acpi_smi_cmd_port(void); 32 | uint8_t mon_acpi_pm_port_size(void); 33 | uint32_t mon_acpi_pm_port_a(void); 34 | uint32_t mon_acpi_pm_port_b(void); 35 | unsigned mon_acpi_sleep_type_to_state(unsigned pm_reg_id, unsigned sleep_type); 36 | int mon_acpi_waking_vector(uint32_t *p_waking_vector, 37 | uint64_t *p_extended_waking_vector); 38 | int mon_acpi_facs_flag(uint32_t *flags, uint32_t *ospm_flags); 39 | 40 | typedef void (*mon_acpi_callback_t) (void); 41 | boolean_t mon_acpi_register_platform_suspend_callback(mon_acpi_callback_t 42 | suspend_cb); 43 | boolean_t mon_acpi_register_platform_resume_callback( 44 | mon_acpi_callback_t resume_cb); 45 | 46 | #endif /* _MON_ACPI_H_ */ 47 | -------------------------------------------------------------------------------- /core/include/mon_addons.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _MON_ADDONS_H_ 18 | #define _MON_ADDONS_H_ 19 | 20 | #include "mon_defs.h" 21 | #include "mon_startup.h" 22 | 23 | /************************************************************************* 24 | * 25 | * List of all known addons 26 | * 27 | ************************************************************************* */ 28 | 29 | extern void init_ept_addon(uint32_t num_of_cpus); 30 | void init_guest_create_addon(void); 31 | extern void gdb_stub_addon_initialize(uint32_t max_num_of_guest_cpus, 32 | const mon_debug_port_params_t *p_params); 33 | 34 | #endif /* _MON_ADDONS_H_ */ 35 | -------------------------------------------------------------------------------- /core/include/mon_globals.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _MON_GLOBALS_H_ 18 | #define _MON_GLOBALS_H_ 19 | 20 | #include "mon_defs.h" 21 | 22 | /*************************************************************************** 23 | * 24 | * Set of global variables 25 | * 26 | ***************************************************************************/ 27 | 28 | /* MON running state */ 29 | typedef enum { 30 | MON_STATE_UNINITIALIZED = 0, 31 | /* initial boot state - only BSP is active and is in MON */ 32 | MON_STATE_BOOT, 33 | /* BSP waits for APs to finish initialization */ 34 | MON_STATE_WAIT_FOR_APS, 35 | /* All CPUs finished init and are in normal running state or in 36 | * Wait-For-SIPI state on behalf of guest */ 37 | MON_STATE_RUN 38 | } mon_state_t; 39 | 40 | extern mon_state_t g_mon_state; 41 | 42 | INLINE mon_state_t mon_get_state(void) 43 | { 44 | return g_mon_state; 45 | } 46 | 47 | INLINE void mon_set_state(mon_state_t new_state) 48 | { 49 | g_mon_state = new_state; 50 | } 51 | 52 | void mon_version_print(void); 53 | 54 | extern cpu_id_t g_num_of_cpus; 55 | 56 | #endif /* _MON_GLOBALS_H_ */ 57 | -------------------------------------------------------------------------------- /core/include/mon_objects.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _MON_OBJECTS_H_ 18 | #define _MON_OBJECTS_H_ 19 | 20 | /* 21 | * Typedefs of the mostly used objects 22 | */ 23 | 24 | typedef void *gpm_handle_t; 25 | typedef struct guest_cpu_t *guest_cpu_handle_t; 26 | typedef struct guest_descriptor_t *guest_handle_t; 27 | 28 | /* 29 | * Support for call from NMI exception handler 30 | */ 31 | typedef enum { 32 | MON_CALL_NORMAL = 0, 33 | MON_CALL_FROM_NMI_HANDLER 34 | } mon_calling_environment_t; 35 | 36 | #endif /* _MON_OBJECTS_H_ */ 37 | -------------------------------------------------------------------------------- /core/include/parse_image.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _PARSE_IMAGE_H_ 18 | #define _PARSE_IMAGE_H_ 19 | 20 | #include "mon_defs.h" 21 | #include "array_iterators.h" 22 | 23 | /************************************************************************** 24 | * 25 | * Get info about the MON memory image itself 26 | * 27 | ************************************************************************** */ 28 | typedef struct { 29 | const char *name; 30 | const char *start; 31 | uint32_t size; 32 | boolean_t readable; 33 | boolean_t writable; 34 | boolean_t executable; 35 | } exec_image_section_info_t; 36 | 37 | typedef generic_array_iterator_t exec_image_section_iterator_t; 38 | 39 | /*------------------------------------------------------------------------- 40 | * 41 | * Iterate through section info while exec_image_section_info_t* != NULL 42 | * 43 | *------------------------------------------------------------------------- */ 44 | const exec_image_section_info_t 45 | *exec_image_section_first(const void *image, 46 | uint32_t image_size, 47 | exec_image_section_iterator_t *ctx); 48 | 49 | const exec_image_section_info_t 50 | *exec_image_section_next(exec_image_section_iterator_t *ctx); 51 | 52 | /*------------------------------------------------------------------------- 53 | * 54 | * initialize 55 | * 56 | *------------------------------------------------------------------------- */ 57 | void exec_image_initialize(void); 58 | 59 | #endif /* _PARSE_IMAGE_H_ */ 60 | -------------------------------------------------------------------------------- /core/include/pat_manager.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef PAT_MANAGER_H 18 | #define PAT_MANAGER_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #define PAT_MNGR_INVALID_PAT_INDEX 0xffffffff 26 | 27 | uint32_t pat_mngr_get_earliest_pat_index_for_mem_type( 28 | mon_phys_mem_type_t mem_type, 29 | uint64_t pat_msr_value); 30 | 31 | uint32_t 32 | pat_mngr_retrieve_current_earliest_pat_index_for_mem_type(mon_phys_mem_type_t 33 | mem_type); 34 | 35 | mon_phys_mem_type_t pat_mngr_retrieve_current_pat_mem_type(uint32_t pat_index); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /core/include/pfec.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef PFEC_H 18 | #define PFEC_H 19 | 20 | typedef union { 21 | struct { 22 | uint32_t present:1; 23 | uint32_t is_write:1; 24 | uint32_t is_user:1; 25 | uint32_t is_reserved:1; 26 | uint32_t is_fetch:1; 27 | uint32_t reserved:27; 28 | } bits; 29 | uint64_t value; 30 | } mon_pfec_t; 31 | 32 | #define MON_PFEC_NUM_OF_USED_BITS 5 33 | 34 | #endif /* PFEC_H */ 35 | -------------------------------------------------------------------------------- /core/include/pool_api.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _POOL_API_H_ 18 | #define _POOL_API_H_ 19 | 20 | #include 21 | #include 22 | 23 | typedef void *pool_handle_t; 24 | #define POOL_INVALID_HANDLE ((pool_handle_t)NULL) 25 | 26 | pool_handle_t assync_pool_create(uint32_t size_of_single_element); 27 | 28 | void *pool_allocate(pool_handle_t pool_handle); 29 | 30 | void pool_free(pool_handle_t pool_handle, void *data); 31 | 32 | #endif /* _POOL_API_H_ */ 33 | -------------------------------------------------------------------------------- /core/include/trial_exec.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _TRIAL_EXEC_H_ 18 | #define _TRIAL_EXEC_H_ 19 | 20 | #include "hw_setjmp.h" 21 | 22 | typedef struct trial_data_t { 23 | struct trial_data_t *prev; 24 | setjmp_buffer_t *saved_env; 25 | uint32_t error_code; /* output */ 26 | vector_id_t fault_vector; /* output */ 27 | uint8_t pad[3]; 28 | } trial_data_t; 29 | 30 | void trial_execution_push(trial_data_t *p_trial_data, setjmp_buffer_t *p_env); 31 | trial_data_t *trial_execution_pop(void); 32 | trial_data_t *trial_execution_get_last(void); 33 | 34 | /* TRY/CATCH/END_TRY macros together build the construction for trial(safe) 35 | * execution. They must be used together and only in that order. 36 | * Note: Use __p_catch_data carefully, because is declared before 37 | * TRY/CATCH/END_TRY, but it points to buffer, which is invalid out 38 | * of TRY... construction. */ 39 | /*------------------------------------------------------------------------- */ 40 | #define TRY { \ 41 | trial_data_t __trial_data; \ 42 | setjmp_buffer_t __env; \ 43 | if (0 == setjmp(&__env)) { \ 44 | trial_execution_push(&__trial_data, &__env); 45 | /*------------------------------------------------------------------------- */ 46 | #define CATCH(__p_catch_data) \ 47 | trial_execution_pop(); \ 48 | } \ 49 | else { \ 50 | __p_catch_data = trial_execution_pop(); 51 | /*------------------------------------------------------------------------- */ 52 | #define END_TRY \ 53 | } \ 54 | } 55 | /*------------------------------------------------------------------------- */ 56 | 57 | #endif /* _TRIAL_EXEC_H_ */ 58 | -------------------------------------------------------------------------------- /core/include/vmcall.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _VMCALL_H_ 18 | #define _VMCALL_H_ 19 | 20 | #include "vmcall_api.h" 21 | #include "mon_objects.h" 22 | 23 | typedef mon_status_t (*vmcall_handler_t) (guest_cpu_handle_t gcpu, 24 | address_t *arg1, address_t *arg2, 25 | address_t *arg3); 26 | 27 | void vmcall_intialize(void); 28 | 29 | void vmcall_guest_intialize(guest_id_t guest_id); 30 | 31 | void mon_vmcall_register(guest_id_t guest_id, 32 | vmcall_id_t vmcall_id, 33 | vmcall_handler_t handler, 34 | boolean_t special_call); 35 | 36 | #endif /* _VMCALL_H_ */ 37 | -------------------------------------------------------------------------------- /core/include/vmcs_hierarchy.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _VMCS_HIERARCHY_H_ 18 | #define _VMCS_HIERARCHY_H_ 19 | 20 | #include "list.h" 21 | #include "vmcs_api.h" 22 | 23 | typedef struct { 24 | vmcs_object_t *vmcs[VMCS_LEVELS]; 25 | /* contains list of vmcs_1_descriptor_t, empty means no layering */ 26 | list_element_t vmcs_1_list[1]; 27 | } vmcs_hierarchy_t; 28 | 29 | INLINE boolean_t vmcs_hierarchy_is_layered(vmcs_hierarchy_t *obj) 30 | { 31 | return obj->vmcs[VMCS_LEVEL_0] != obj->vmcs[VMCS_MERGED]; 32 | } 33 | 34 | mon_status_t vmcs_hierarchy_create(vmcs_hierarchy_t *obj, 35 | guest_cpu_handle_t gcpu); 36 | mon_status_t vmcs_hierarchy_add_vmcs(vmcs_hierarchy_t *obj, 37 | guest_cpu_handle_t gcpu, 38 | address_t gpa); 39 | mon_status_t vmcs_hierarchy_remove_vmcs(vmcs_hierarchy_t *obj, 40 | vmcs_object_t *vmcs_1); 41 | vmcs_object_t *vmcs_hierarchy_get_vmcs(vmcs_hierarchy_t *obj, 42 | vmcs_level_t level); 43 | vmcs_object_t *vmcs_hierarchy_get_next_vmcs_1(vmcs_hierarchy_t *obj); 44 | vmcs_object_t *vmcs_hierarchy_select_vmcs_1(vmcs_hierarchy_t *obj, 45 | vmcs_object_t *vmcs); 46 | 47 | #endif /* _VMCS_HIERARCHY_H_ */ 48 | -------------------------------------------------------------------------------- /core/include/vmcs_merge_split.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef VMCS_MERGE_SPLIT_H 18 | #define VMCS_MERGE_SPLIT_H 19 | 20 | #include 21 | #include 22 | 23 | void ms_merge_to_level2(IN guest_cpu_handle_t gcpu, 24 | IN boolean_t merge_only_dirty); 25 | 26 | void ms_split_from_level2(IN guest_cpu_handle_t gcpu); 27 | 28 | void ms_merge_to_level1(IN guest_cpu_handle_t gcpu, 29 | IN boolean_t was_vmexit_from_level1, 30 | IN boolean_t merge_only_dirty); 31 | 32 | #endif /* VMCS_MERGE_SPLIT_H */ 33 | -------------------------------------------------------------------------------- /core/include/vmcs_sw_object.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _VMCS_SW_OBJECT_H_ 18 | #define _VMCS_SW_OBJECT_H_ 19 | 20 | #include "mon_objects.h" 21 | 22 | vmcs_object_t *vmcs_0_create(vmcs_object_t *vmcs_origin); 23 | vmcs_object_t *vmcs_1_create(guest_cpu_handle_t gcpu, address_t gpa); 24 | 25 | #endif /* _VMCS_SW_OBJECT_H_ */ 26 | -------------------------------------------------------------------------------- /core/include/vmdb.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _VMDB_H_ 18 | #define _VMDB_H_ 19 | 20 | typedef enum { 21 | VMDB_BREAK_ON_EXE = 0, 22 | VMDB_BREAK_ON_WO = 1, /* break on memory write only */ 23 | VMDB_BREAK_ON_IO = 2, /* break on IO read/write */ 24 | VMDB_BREAK_ON_RW = 3, /* break on memory read/write */ 25 | VMDB_BREAK_TYPE_FIRST = 0, 26 | VMDB_BREAK_TYPE_LAST = 3 27 | } vmdb_breakpoint_type_t; 28 | 29 | typedef enum { 30 | VMDB_BREAK_LENGTH_1 = 0, /* used for exe breaks */ 31 | VMDB_BREAK_LENGTH_2 = 1, 32 | VMDB_BREAK_LENGTH_8 = 2, 33 | VMDB_BREAK_LENGTH_4 = 3, 34 | VMDB_BREAK_LENGTH_FIRST = 0, 35 | VMDB_BREAK_LENGTH_LAST = 3 36 | } vmdb_break_length_type_t; 37 | 38 | #define VMDB_INCLUDE 39 | 40 | #ifdef VMDB_INCLUDE 41 | 42 | void vmdb_initialize(void); 43 | mon_status_t vmdb_guest_initialize(guest_id_t); 44 | mon_status_t vmdb_thread_attach(guest_cpu_handle_t gcpu); 45 | mon_status_t vmdb_thread_detach(guest_cpu_handle_t gcpu); 46 | 47 | boolean_t vmdb_exception_handler(guest_cpu_handle_t gcpu); 48 | mon_status_t vmdb_breakpoint_info(guest_cpu_handle_t gcpu, 49 | uint32_t bp_id, 50 | address_t *linear_address, 51 | vmdb_breakpoint_type_t *bp_type, 52 | vmdb_break_length_type_t *bp_len, 53 | uint16_t *skip_counter); 54 | mon_status_t vmdb_breakpoint_add(guest_cpu_handle_t gcpu, 55 | address_t linear_address, 56 | vmdb_breakpoint_type_t bp_type, 57 | vmdb_break_length_type_t bp_len, 58 | uint16_t skip_counter); 59 | mon_status_t vmdb_breakpoint_delete(guest_cpu_handle_t gcpu, 60 | address_t linear_address); 61 | mon_status_t vmdb_breakpoint_delete_all(guest_cpu_handle_t gcpu); 62 | mon_status_t vmdb_single_step_enable(guest_cpu_handle_t gcpu, boolean_t enable); 63 | mon_status_t vmdb_single_step_info(guest_cpu_handle_t gcpu, boolean_t *enable); 64 | void vmdb_settings_apply_to_hw(guest_cpu_handle_t gcpu); 65 | 66 | #else 67 | #define vmdb_initialize() 68 | #define vmdb_guest_initialize(guest_id) MON_OK 69 | #define vmdb_thread_attach(gcpu) MON_ERROR 70 | #define vmdb_thread_detach(gcpu) MON_ERROR 71 | #define vmdb_exception_handler(gcpu) (FALSE /* exception NOT handled */) 72 | #define vmdb_breakpoint_add(gcpu, linear_address, bp_type, bp_len, skip_counter) \ 73 | MON_OK 74 | #define vmdb_breakpoint_delete(gcpu, linear_address) MON_OK 75 | #define vmdb_breakpoint_delete_all(gcpu) MON_OK 76 | #define vmdb_settings_apply_to_hw(gcpu) 77 | #define vmdb_single_step_enable(gcpu, enable) MON_OK 78 | 79 | #endif /* VMDB_INCLUDE */ 80 | 81 | #endif /* _VMDB_H_ */ 82 | -------------------------------------------------------------------------------- /core/include/vmenter_checks.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _VMENTER_CHECKS_H_ 18 | #define _VMENTER_CHECKS_H_ 19 | 20 | #include "cli_env.h" 21 | 22 | #ifdef CLI_INCLUDE 23 | 24 | void vmenter_checkings_register(void); 25 | void vmenter_failure_check_guest_state(void); 26 | 27 | #else 28 | 29 | #define vmenter_checkings_register() {} 30 | #define vmenter_failure_check_guest_state() {} 31 | 32 | #endif 33 | 34 | #endif /* _VMENTER_CHECKS_H_ */ 35 | -------------------------------------------------------------------------------- /core/include/vmexit_analysis.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef VMEXIT_ANALYSIS_H 18 | 19 | boolean_t vmexit_analysis_was_control_requested(guest_cpu_handle_t gcpu, 20 | vmcs_object_t *vmexit_vmcs, 21 | vmcs_object_t *control_vmcs, 22 | ia32_vmx_exit_basic_reason_t 23 | exit_reason); 24 | 25 | #endif /* VMEXIT_ANALYSIS_H */ 26 | -------------------------------------------------------------------------------- /core/include/vmexit_cpuid.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _VMEXIT_CPUID_H_ 18 | #define _VMEXIT_CPUID_H_ 19 | 20 | #include "hw_utils.h" /* for cpuid_params_t */ 21 | 22 | /* return TRUE if instruction was executed, FAULSE in case of exception */ 23 | typedef void (*cpuid_filter_handler_t) (guest_cpu_handle_t, cpuid_params_t *); 24 | 25 | void vmexit_cpuid_guest_intialize(guest_id_t guest_id); 26 | 27 | #endif /* _VMEXIT_CPUID_H_ */ 28 | -------------------------------------------------------------------------------- /core/include/vmexit_cr_access.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef VMEXIT_CR_ACCESS_H 18 | #define VMEXIT_CR_ACCESS_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | mon_ia32_control_registers_t vmexit_cr_access_get_cr_from_qualification( 26 | uint64_t qualification); 27 | mon_ia32_gp_registers_t vmexit_cr_access_get_operand_from_qualification( 28 | uint64_t qualification); 29 | raise_event_retval_t cr_raise_write_events(guest_cpu_handle_t gcpu, 30 | mon_ia32_control_registers_t reg_id, 31 | address_t new_value); 32 | 33 | #endif /* VMEXIT_CR_ACCESS_H */ 34 | -------------------------------------------------------------------------------- /core/include/vmexit_dtr_tr.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _VMEXIT_DTR_TR_H_ 18 | #define _VMEXIT_DTR_TR_H_ 19 | 20 | vmexit_handling_status_t vmexit_dr_access(guest_cpu_handle_t gcpu); 21 | vmexit_handling_status_t vmexit_gdtr_idtr_access(guest_cpu_handle_t gcpu); 22 | vmexit_handling_status_t vmexit_ldtr_tr_access(guest_cpu_handle_t gcpu); 23 | 24 | #endif /* _VMEXIT_DTR_TR_H_ */ 25 | -------------------------------------------------------------------------------- /core/include/vmx_nmi.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _VMX_NMI_H_ 18 | #define _VMX_NMI_H_ 19 | 20 | boolean_t nmi_manager_initialize(cpu_id_t num_of_cores); 21 | 22 | static void nmi_raise(cpu_id_t cpu_id); 23 | static void nmi_clear(cpu_id_t cpu_id); 24 | static boolean_t nmi_is_pending(cpu_id_t cpu_id); 25 | void nmi_raise_this(void); 26 | void nmi_clear_this(void); 27 | boolean_t nmi_is_pending_this(void); 28 | 29 | /*------------------------------------------------------------------------* 30 | * FUNCTION : nmi_resume_handler() 31 | * PURPOSE : If current CPU is platform NMI owner and unhandled platform NMI 32 | * : exists on current CPU, sets NMI-Window to get VMEXIT asap. 33 | * ARGUMENTS: guest_cpu_handle_t gcpu 34 | * RETURNS : void 35 | *------------------------------------------------------------------------*/ 36 | void nmi_resume_handler(guest_cpu_handle_t gcpu); 37 | 38 | /*------------------------------------------------------------------------* 39 | * FUNCTION : nmi_vmexit_handler() 40 | * PURPOSE : Process NMI VMEXIT 41 | * ARGUMENTS: guest_cpu_handle_t gcpu 42 | * RETURNS : Status which says if VMEXIT was finally handled or 43 | * : it should be processed by upper layer 44 | * CALLED : called as bottom-up local handler 45 | *------------------------------------------------------------------------*/ 46 | vmexit_handling_status_t nmi_vmexit_handler(guest_cpu_handle_t gcpu); 47 | 48 | /*------------------------------------------------------------------------* 49 | * FUNCTION : nmi_window_vmexit_handler() 50 | * PURPOSE : Process NMI Window VMEXIT 51 | * ARGUMENTS: guest_cpu_handle_t gcpu 52 | * RETURNS : Status which says if VMEXIT was finally handled or 53 | * : it should be processed by upper layer 54 | * CALLED : called as bottom-up local handler 55 | *------------------------------------------------------------------------*/ 56 | vmexit_handling_status_t nmi_window_vmexit_handler(guest_cpu_handle_t gcpu); 57 | 58 | #endif /* _VMX_NMI_H_ */ 59 | -------------------------------------------------------------------------------- /core/include/vmx_timer.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _VMX_TIMER_H_ 18 | #define _VMX_TIMER_H_ 19 | 20 | /* 21 | * Function : vmx_timer_hw_setup 22 | * Purpose : Checks if VMX timer is supported by hardware and if so, 23 | * : calculates its rate relative to TSC. 24 | * Arguments: void 25 | * Return : TRUE id supported 26 | * Note : Must be call 1st on the given core. 27 | */ 28 | boolean_t vmx_timer_hw_setup(void); 29 | boolean_t vmx_timer_create(guest_cpu_handle_t gcpu); 30 | boolean_t vmx_timer_start(guest_cpu_handle_t gcpu); 31 | boolean_t vmx_timer_stop(guest_cpu_handle_t gcpu); 32 | boolean_t vmx_timer_set_period(guest_cpu_handle_t gcpu, uint64_t period); 33 | boolean_t vmx_timer_launch(guest_cpu_handle_t gcpu, 34 | uint64_t time_to_expiration, 35 | boolean_t periodic); 36 | boolean_t vmx_timer_set_mode(guest_cpu_handle_t gcpu, 37 | boolean_t save_value_mode); 38 | 39 | #endif /* _VMX_TIMER_H_ */ 40 | -------------------------------------------------------------------------------- /core/include/vmx_trace.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | /* 18 | * 19 | * Trace mechanism 20 | * 21 | */ 22 | 23 | #ifndef VMX_TRACE_H 24 | #define VMX_TRACE_H 25 | 26 | #include "mon_defs.h" 27 | #include "guest_cpu.h" 28 | 29 | typedef enum { 30 | MON_TRACE_DISABLED, 31 | MON_TRACE_ENABLED_RECYCLED, 32 | MON_TRACE_ENABLED_NON_RECYCLED 33 | } mon_trace_state_t; 34 | 35 | boolean_t mon_trace_init(uint32_t max_num_guests, uint32_t max_num_guest_cpus); 36 | 37 | boolean_t mon_trace(guest_cpu_handle_t guest_cpu, const char *format, ...); 38 | 39 | boolean_t 40 | mon_trace_buffer(guest_cpu_handle_t guest_cpu, 41 | uint8_t buffer_index, 42 | const char *format, 43 | ...); 44 | 45 | boolean_t mon_trace_print_all(uint32_t guest_num, char *guest_names[]); 46 | 47 | void mon_trace_state_set(mon_trace_state_t state); 48 | 49 | #endif /* VMX_TRACE_H */ 50 | -------------------------------------------------------------------------------- /core/include/vt100.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _VT100_H_ 18 | #define _VT100_H_ 19 | 20 | #define ASCII_ESCAPE 0x1B 21 | 22 | #define VT100_KEY_CR ('\r') 23 | #define VT100_KEY_LN ('\n') 24 | #define VT100_KEY_RUBOUT 8 25 | #define VT100_KEY_ABORT ASCII_ESCAPE 26 | #define VT100_KEY_UP 1 27 | #define VT100_KEY_DOWN 2 28 | #define VT100_KEY_LEFT 3 29 | #define VT100_KEY_RIGHT 4 30 | #define VT100_KEY_HOME 5 31 | #define VT100_KEY_END 6 32 | #define VT100_KEY_DELETE 7 33 | #define VT100_KEY_INSERT 9 34 | 35 | void vt100_putch(char ch); 36 | void vt100_puts(char *string); 37 | void vt100_gotoxy(unsigned line, unsigned col); 38 | int vt100_getpos(unsigned *line, unsigned *col); 39 | void vt100_delsym(void); 40 | void vt100_clrline(void); 41 | char vt100_getch(void); 42 | void vt100_flush_input(void); 43 | 44 | #endif /* _VT100_H_ */ 45 | -------------------------------------------------------------------------------- /core/ipc/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | CSOURCES = $(wildcard *.c) 18 | include $(PROJS)/core/rule.linux 19 | -------------------------------------------------------------------------------- /core/ipc/ipc_impl.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _IPC_IMPL_H 18 | #define _IPC_IMPL_H 19 | 20 | #include "mon_defs.h" 21 | #include "isr.h" 22 | #include "list.h" 23 | #include "ipc.h" 24 | #include "lock.h" 25 | 26 | #define IPC_ALIGNMENT ARCH_ADDRESS_WIDTH 27 | 28 | #define IPC_CPU_ID() hw_cpu_id() 29 | 30 | #define NMI_VECTOR 2 31 | 32 | #define NMIS_WAITING_FOR_PROCESSING(ipc) \ 33 | (ipc->num_received_nmi_interrupts - ipc->num_processed_nmi_interrupts) 34 | #define IPC_NMIS_WAITING_FOR_PROCESSING(ipc) \ 35 | (ipc->num_of_sent_ipc_nmi_interrupts - \ 36 | ipc->num_of_processed_ipc_nmi_interrupts) 37 | 38 | typedef struct { 39 | ipc_message_type_t type; 40 | cpu_id_t from; 41 | char padding[2]; 42 | func_ipc_handler_t handler; 43 | void *arg; 44 | volatile uint32_t *before_handler_ack; 45 | volatile uint32_t *after_handler_ack; 46 | } ipc_message_t; 47 | 48 | typedef enum { 49 | IPC_CPU_NOT_ACTIVE = 0, 50 | IPC_CPU_ACTIVE, 51 | IPC_CPU_SIPI 52 | } ipc_cpu_activity_state_t; 53 | 54 | typedef struct { 55 | volatile uint64_t num_received_nmi_interrupts; 56 | uint64_t num_processed_nmi_interrupts; 57 | 58 | uint64_t num_of_sent_ipc_nmi_interrupts; 59 | uint64_t num_of_processed_ipc_nmi_interrupts; 60 | 61 | volatile uint64_t num_blocked_nmi_injections_to_guest; 62 | volatile uint64_t num_start_messages; 63 | volatile uint64_t num_stop_messages; 64 | 65 | array_list_handle_t message_queue; 66 | uint64_t num_of_sent_ipc_messages; 67 | uint64_t num_of_received_ipc_messages; 68 | 69 | mon_lock_t data_lock; 70 | } ipc_cpu_context_t; 71 | 72 | boolean_t ipc_state_init(uint16_t number_of_host_processors); 73 | 74 | boolean_t ipc_guest_state_init(guest_id_t guest_id); 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /core/libc/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | CSOURCES = $(wildcard *.c) 18 | include $(PROJS)/core/rule.linux 19 | -------------------------------------------------------------------------------- /core/libc/libc.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #include "libc_internal.h" 18 | 19 | static boolean_t g_init_done = FALSE; 20 | 21 | void mon_libc_init(void) 22 | { 23 | if (g_init_done) { 24 | return; 25 | } 26 | 27 | mon_io_init(); 28 | 29 | g_init_done = TRUE; 30 | } 31 | -------------------------------------------------------------------------------- /core/libc/libc_internal.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _MON_LIBC_INTERNAL_H_ 18 | #define _MON_LIBC_INTERNAL_H_ 19 | 20 | /* 21 | * Internal header for libc 22 | */ 23 | #include "libc.h" 24 | 25 | void mon_io_init(void); 26 | void mon_debug_port_clear(void); 27 | 28 | #endif /* _MON_LIBC_INTERNAL_H_ */ 29 | -------------------------------------------------------------------------------- /core/linker.lds: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", 18 | "elf64-x86-64") 19 | OUTPUT_ARCH(i386:x86-64) 20 | 21 | ENTRY(mon_main_asm); 22 | 23 | SECTIONS 24 | { 25 | /* Read-only sections, merged into text segment: */ 26 | . = SEGMENT_START("text-segment", 0) + SIZEOF_HEADERS; 27 | .hash : { *(.hash) } 28 | .dynsym : { *(.dynsym) } 29 | .dynstr : { *(.dynstr) } 30 | .rela.dyn : 31 | { 32 | *(.rela.init) 33 | *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) 34 | *(.rela.fini) 35 | *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) 36 | *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) 37 | *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) 38 | *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) 39 | *(.rela.ctors) 40 | *(.rela.dtors) 41 | *(.rela.got) 42 | *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) 43 | *(.rela.ldata .rela.ldata.* .rela.gnu.linkonce.l.*) 44 | *(.rela.lbss .rela.lbss.* .rela.gnu.linkonce.lb.*) 45 | *(.rela.lrodata .rela.lrodata.* .rela.gnu.linkonce.lr.*) 46 | *(.rela.ifunc) 47 | } 48 | .rela.plt : 49 | { 50 | *(.rela.plt) 51 | *(.rela.iplt) 52 | } 53 | .text : 54 | { 55 | *(.text.unlikely .text.*_unlikely) 56 | *(.text.exit .text.exit.*) 57 | *(.text.startup .text.startup.*) 58 | *(.text.hot .text.hot.*) 59 | *(.text .stub .text.* .gnu.linkonce.t.*) 60 | /* .gnu.warning sections are handled specially by elf32.em. */ 61 | *(.gnu.warning) 62 | } =0x90909090 63 | .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) } 64 | .eh_frame : { *(.eh_frame) } 65 | /* Adjust the address for the data segment. We want to adjust up to 66 | the same address within the page on the next page up. */ 67 | . = ALIGN (4k); 68 | .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) } 69 | .dynamic : { *(.dynamic) } 70 | .got : { *(.got) *(.igot) } 71 | .got.plt : { *(.got.plt) *(.igot.plt) } 72 | .data : 73 | { 74 | *(.data .data.* .gnu.linkonce.d.*) 75 | } 76 | .bss : 77 | { 78 | *(.dynbss) 79 | *(.bss .bss.* .gnu.linkonce.b.*) 80 | *(COMMON) 81 | /* Align here to ensure that the .bss section occupies space up to 82 | _end. Align after .bss to ensure correct alignment even if the 83 | .bss section disappears because there are no input sections. 84 | FIXME: Why do we need it? When there is no .bss section, we don't 85 | pad the .data section. */ 86 | . = ALIGN(. != 0 ? 64 / 8 : 1); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /core/memory/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | SUBDIRS = ept memory_manager 18 | 19 | .PHONY: all 20 | 21 | all: 22 | $(foreach D, $(SUBDIRS), $(MAKE) -C $(D);) 23 | -------------------------------------------------------------------------------- /core/memory/ept/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | CSOURCES = $(wildcard *.c) 18 | ASOURCES = $(wildcard *.S) 19 | include $(PROJS)/core/rule.linux 20 | -------------------------------------------------------------------------------- /core/memory/ept/ept_hw_layer.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _EPT_HW_LAYER_H 18 | #define _EPT_HW_LAYER_H 19 | 20 | #include "mon_defs.h" 21 | #include "mon_objects.h" 22 | #include "mon_phys_mem_types.h" 23 | #include "scheduler.h" 24 | 25 | #define EPT_LOG(...) MON_LOG(mask_ept, level_trace, __VA_ARGS__) 26 | #define EPT_PRINTERROR(...) MON_LOG(mask_ept, level_error, __VA_ARGS__) 27 | 28 | #define EPT_NUM_PDPTRS 4 29 | 30 | typedef union { 31 | struct { 32 | uint32_t etmt:3; 33 | uint32_t gaw:3; 34 | uint32_t reserved:6; 35 | uint32_t address_space_root_low:20; 36 | uint32_t address_space_root_high; 37 | } bits; 38 | uint64_t uint64; 39 | } eptp_t; 40 | 41 | typedef enum { 42 | INVEPT_INDIVIDUAL_ADDRESS = 0, 43 | INVEPT_CONTEXT_WIDE, 44 | INVEPT_ALL_CONTEXTS 45 | } invept_cmd_type_t; 46 | 47 | typedef enum { 48 | INVVPID_INDIVIDUAL_ADDRESS = 0, 49 | INVVPID_SINGLE_CONTEXT, 50 | INVVPID_ALL_CONTEXTS, 51 | INVVPID_SINGLE_CONTEXT_GLOBAL 52 | } invvpid_cmd_type_t; 53 | 54 | boolean_t ept_hw_is_ept_supported(void); 55 | boolean_t ept_hw_is_ept_enabled(guest_cpu_handle_t gcpu); 56 | 57 | boolean_t ept_hw_enable_ept(guest_cpu_handle_t gcpu); 58 | void ept_hw_disable_ept(guest_cpu_handle_t gcpu); 59 | 60 | uint64_t ept_hw_get_eptp(guest_cpu_handle_t gcpu); 61 | boolean_t ept_hw_set_eptp(guest_cpu_handle_t gcpu, 62 | hpa_t ept_root_hpa, 63 | uint32_t gaw); 64 | 65 | mon_phys_mem_type_t mon_ept_hw_get_ept_memory_type(void); 66 | 67 | uint32_t mon_ept_hw_get_guest_address_width(uint32_t actual_gaw); 68 | uint32_t mon_ept_hw_get_guest_address_width_encoding(uint32_t width); 69 | uint32_t ept_hw_get_guest_address_width_from_encoding(uint32_t gaw_encoding); 70 | 71 | void ept_hw_set_pdtprs(guest_cpu_handle_t gcpu, uint64_t pdptr[]); 72 | 73 | boolean_t ept_hw_is_invept_supported(void); 74 | boolean_t ept_hw_invept_all_contexts(void); 75 | boolean_t ept_hw_invept_context(uint64_t eptp); 76 | boolean_t ept_hw_invept_individual_address(uint64_t eptp, address_t gpa); 77 | boolean_t ept_hw_invvpid_single_context(uint64_t vpid); 78 | boolean_t ept_hw_invvpid_all_contexts(void); 79 | boolean_t ept_hw_is_invvpid_supported(void); 80 | boolean_t ept_hw_invvpid_individual_address(uint64_t vpid, address_t gva); 81 | 82 | #define CHECK_EXECUTION_ON_LOCAL_HOST_CPU(gcpu) \ 83 | MON_DEBUG_CODE( \ 84 | { \ 85 | cpu_id_t host_cpu_id = scheduler_get_host_cpu_id(gcpu); \ 86 | MON_ASSERT(host_cpu_id == hw_cpu_id()); \ 87 | } \ 88 | ) 89 | 90 | #endif /*_EPT_HW_LAYER_H */ 91 | -------------------------------------------------------------------------------- /core/memory/ept/fvs.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _FVS_H 18 | #define _FVS_H 19 | 20 | #define MAX_EPTP_ENTRIES 512 21 | #define FVS_ENABLE_FLAG 1 22 | #define FVS_DISABLE_FLAG 0 23 | 24 | #define FAST_VIEW_SWITCH_LEAF 0x0 /* EPTP-switching (VM function 0) */ 25 | 26 | typedef struct { 27 | hpa_t *eptp_list_paddress; 28 | hva_t *eptp_list_vaddress; 29 | uint32_t padding; 30 | /* Each CPU has its own eptp list. Use cpu id as array index of 31 | * eptp_list_paddress[] and eptp_list_vaddress[] */ 32 | uint32_t num_of_cpus; 33 | } fvs_descriptor_t; 34 | 35 | typedef fvs_descriptor_t *fvs_object_t; 36 | 37 | boolean_t fvs_is_eptp_switching_supported(void); 38 | void fvs_guest_vmfunc_enable(guest_cpu_handle_t gcpu); 39 | hpa_t *mon_fvs_get_all_eptp_list_paddress(guest_cpu_handle_t gcpu); 40 | boolean_t mon_fvs_add_entry_to_eptp_list(guest_handle_t guest, 41 | hpa_t ept_root_hpa, 42 | uint32_t gaw, 43 | uint64_t index); 44 | boolean_t mon_fvs_add_entry_to_eptp_list_single_core(guest_handle_t guest, 45 | cpu_id_t cpu_id, 46 | hpa_t ept_root_hpa, 47 | uint32_t gaw, 48 | uint64_t index); 49 | boolean_t mon_fvs_delete_entry_from_eptp_list(guest_handle_t guest, 50 | uint64_t index); 51 | boolean_t mon_fvs_delete_entry_from_eptp_list_single_core(guest_handle_t guest, 52 | cpu_id_t cpu_id, 53 | uint64_t index); 54 | boolean_t mon_fvs_update_entry_in_eptp_list(guest_handle_t guest, 55 | hpa_t ept_root_hpa, 56 | uint32_t gaw, 57 | uint64_t index); 58 | uint64_t mon_fvs_get_eptp_entry(guest_cpu_handle_t gcpu, uint64_t index); 59 | void fvs_vmfunc_vmcs_init(guest_cpu_handle_t gcpu); 60 | void mon_fvs_enable_fvs(guest_cpu_handle_t gcpu); 61 | void mon_fvs_disable_fvs(guest_cpu_handle_t gcpu); 62 | boolean_t mon_fvs_is_fvs_enabled(guest_cpu_handle_t gcpu); 63 | void fvs_vmexit_handler(guest_cpu_handle_t gcpu); 64 | void fvs_save_resumed_eptp(guest_cpu_handle_t gcpu); 65 | void mon_fvs_enable_eptp_switching(cpu_id_t gcpu, void *arg); 66 | void mon_fvs_disable_eptp_switching(cpu_id_t gcpu, void *arg); 67 | #endif 68 | -------------------------------------------------------------------------------- /core/memory/ept/invept.S: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | .text 18 | 19 | #------------------------------------------------------------------------------ 20 | # Registers for passing parameters: 21 | # %rdi, %rsi, %rdx, %rcx, %r8, %r9 22 | # The rest parameters are in stack 23 | # Preserved regs 24 | # %rbp,%rbx,%r12,%r15 25 | # System calls via syscall 26 | # Kernel destroys %r11, %rcx 27 | # The number of syscall is in %rax 28 | #------------------------------------------------------------------------------ 29 | 30 | 31 | .macro INVEPT 32 | .ascii "\x66\x48\x0f\x38\x80\x08" 33 | .endm 34 | 35 | .macro INVVPID 36 | .ascii "\x66\x48\x0f\x38\x81\x08" 37 | .endm 38 | 39 | #------------------------------------------------------------------------------ 40 | # void_t 41 | # mon_asm_invept ( 42 | # invept_arg_t *arg, %rdi 43 | # uint32_t modifier %rsi 44 | # uint64_t *rflags %rdx 45 | # ) 46 | #------------------------------------------------------------------------------ 47 | 48 | .globl mon_asm_invept 49 | mon_asm_invept: 50 | mov %rdi, %rax 51 | mov %rsi, %rcx 52 | INVEPT 53 | pushfq 54 | pop (%rdx) 55 | ret 56 | 57 | #------------------------------------------------------------------------------ 58 | # void_t 59 | # mon_asm_invvpid ( 60 | # invept_arg_t *arg, %rdi 61 | # uint32_t modifier %rsi 62 | # uint64_t *rflags %rdx 63 | # ) 64 | #------------------------------------------------------------------------------ 65 | 66 | .globl mon_asm_invvpid 67 | mon_asm_invvpid: 68 | mov %rdi, %rax 69 | mov %rsi, %rcx 70 | INVVPID 71 | pushfq 72 | pop (%rdx) 73 | ret 74 | 75 | 76 | -------------------------------------------------------------------------------- /core/memory/ept/ve.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _VE_H 18 | #define _VE_H 19 | 20 | typedef struct { 21 | uint32_t exit_reason; 22 | uint32_t flag; 23 | uint64_t exit_qualification; 24 | uint64_t gla; /* guest linear address; */ 25 | uint64_t gpa; /* guest physical address; */ 26 | uint16_t eptp_index; 27 | uint8_t padding[6]; 28 | } ve_ept_info_t; 29 | 30 | boolean_t mon_ve_is_hw_supported(void); 31 | boolean_t mon_ve_is_ve_enabled(guest_cpu_handle_t gcpu); 32 | boolean_t mon_ve_update_hpa(guest_id_t guest_id, 33 | cpu_id_t guest_cpu_id, 34 | hpa_t hpa, 35 | uint32_t enable); 36 | void mon_ve_enable_ve(guest_cpu_handle_t gcpu); 37 | void mon_ve_disable_ve(guest_cpu_handle_t gcpu); 38 | boolean_t mon_ve_handle_sw_ve(guest_cpu_handle_t gcpu, 39 | uint64_t qualification, 40 | uint64_t gla, 41 | uint64_t gpa, 42 | uint64_t view); 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /core/memory/memory_manager/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | CSOURCES = $(wildcard *.c) 18 | include $(PROJS)/core/rule.linux 19 | -------------------------------------------------------------------------------- /core/memory/memory_manager/mon_stack.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef MON_STACK_H 18 | #define MON_STACK_H 19 | 20 | #ifdef DEBUG 21 | #define MON_STACK_DEBUG_CODE 22 | #endif 23 | 24 | typedef struct { 25 | uint64_t stacks_base; 26 | uint32_t size_of_single_stack; 27 | uint32_t max_allowed_cpus; 28 | uint32_t num_of_exception_stacks; 29 | boolean_t is_initialized; 30 | } mon_stacks_info_t; 31 | 32 | INLINE 33 | uint64_t mon_stacks_info_get_stacks_base(const mon_stacks_info_t *stacks_info) 34 | { 35 | return stacks_info->stacks_base; 36 | } 37 | 38 | INLINE 39 | void mon_stacks_info_set_stacks_base(mon_stacks_info_t *stacks_info, 40 | uint64_t base) 41 | { 42 | stacks_info->stacks_base = base; 43 | } 44 | 45 | INLINE 46 | uint32_t mon_stacks_info_get_size_of_single_stack(const mon_stacks_info_t * 47 | stacks_info) 48 | { 49 | return stacks_info->size_of_single_stack; 50 | } 51 | 52 | INLINE 53 | void mon_stacks_info_set_size_of_single_stack(mon_stacks_info_t *stacks_info, 54 | uint32_t size) 55 | { 56 | stacks_info->size_of_single_stack = size; 57 | } 58 | 59 | INLINE 60 | uint32_t mon_stacks_info_get_max_allowed_cpus(const mon_stacks_info_t * 61 | stacks_info) 62 | { 63 | return stacks_info->max_allowed_cpus; 64 | } 65 | 66 | INLINE 67 | void mon_stacks_info_set_max_allowed_cpus(mon_stacks_info_t *stacks_info, 68 | uint32_t cpus_num) 69 | { 70 | stacks_info->max_allowed_cpus = cpus_num; 71 | } 72 | 73 | INLINE 74 | uint32_t mon_stacks_info_get_num_of_exception_stacks(const mon_stacks_info_t * 75 | stacks_info) 76 | { 77 | return stacks_info->num_of_exception_stacks; 78 | } 79 | 80 | INLINE 81 | void mon_stacks_info_set_num_of_exception_stacks(mon_stacks_info_t * 82 | stacks_info, 83 | uint32_t num_of_stacks) 84 | { 85 | stacks_info->num_of_exception_stacks = num_of_stacks; 86 | } 87 | 88 | INLINE boolean_t mon_stacks_is_initialized(const mon_stacks_info_t *stacks_info) 89 | { 90 | return stacks_info->is_initialized; 91 | } 92 | 93 | INLINE void mon_stacks_set_initialized(mon_stacks_info_t *stacks_info) 94 | { 95 | stacks_info->is_initialized = TRUE; 96 | } 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /core/mon_entry.S: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | .text 18 | 19 | #------------------------------------------------------------------------------ 20 | # Registers for passing parameters: 21 | # %rdi, %rsi, %rdx, %rcx, %r8, %r9 22 | # The rest parameters are in stack 23 | # Preserved regs 24 | # %rbp,%rbx,%r12,%r15 25 | # System calls via syscall 26 | # Kernel destroys %r11, %rcx 27 | # The number of syscall is in %rax 28 | #------------------------------------------------------------------------------ 29 | 30 | #void mon_main(uint32_t , uint64_t , uint64_t , uint64_t ) 31 | .extern mon_main 32 | 33 | 34 | #------------------------------------------------------------------------------ 35 | # void_t 36 | # mon_main_asm ( 37 | # ) 38 | # 39 | # This function used as entry point to MON. It assumes that loader 40 | # displaces 4 arguments passed in registers RCX, RDX, R8, R9 41 | # (Microsoft-like arguments passing), to registers RDI, RSI, RDX, RCX, 42 | # i.e. GNU arguments passing convention 43 | #------------------------------------------------------------------------------ 44 | 45 | .globl mon_main_asm 46 | mon_main_asm: 47 | mov %rcx, %rdi 48 | mov %rdx, %rsi 49 | mov %r8, %rdx 50 | mov %r9, %rcx 51 | call mon_main 52 | # jmp . # should never reach this point 53 | ret 54 | 55 | 56 | -------------------------------------------------------------------------------- /core/rule.linux: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | find_xmon_opt = \ 17 | $(if $(findstring $(1),$(XMON_CMPL_OPT_FLAGS)),1) 18 | 19 | INCLUDES = -I. \ 20 | -I$(PROJS)/common/include \ 21 | -I$(PROJS)/core/common/include \ 22 | -I$(PROJS)/core/common/include/arch \ 23 | -I$(PROJS)/core/common/include/platform \ 24 | -I$(PROJS)/core/guest \ 25 | -I$(PROJS)/core/guest/guest_cpu \ 26 | -I$(PROJS)/core/host/hw \ 27 | -I$(PROJS)/core/include \ 28 | -I$(PROJS)/core/include/appliances \ 29 | -I$(PROJS)/core/include/hw \ 30 | -I$(PROJS)/core/memory/ept 31 | 32 | CFLAGS = -c $(XMON_CMPL_OPT_FLAGS) \ 33 | -O2 -std=gnu99 -fPIC -nostdinc -fno-stack-protector \ 34 | -fdiagnostics-show-option -funsigned-bitfields \ 35 | -m64 -march=nocona -D ARCH_ADDRESS_WIDTH=8 \ 36 | -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow \ 37 | -fno-hosted -fomit-frame-pointer \ 38 | -Werror 39 | 40 | CFLAGS += $(INCLUDES) 41 | 42 | AFLAGS = -c -m64 43 | 44 | COBJS = $(addprefix $(OUTDIR)core/, $(notdir $(patsubst %.c, %.o, $(CSOURCES)))) 45 | 46 | AOBJS = $(addprefix $(OUTDIR)core/, $(notdir $(patsubst %.S, %.o, $(ASOURCES)))) 47 | 48 | all: $(COBJS) $(AOBJS) 49 | 50 | $(COBJS): $(CSOURCES) 51 | $(CC) $(CFLAGS) -o $@ $(filter $(*F).c, $(CSOURCES)) 52 | 53 | $(AOBJS): $(ASOURCES) 54 | $(AS) $(AFLAGS) -o $@ $(filter $(*F).S, $(ASOURCES)) 55 | -------------------------------------------------------------------------------- /core/startup/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | CSOURCES = $(filter-out parse_pe_image.c, $(wildcard *.c)) 18 | include $(PROJS)/core/rule.linux 19 | -------------------------------------------------------------------------------- /core/startup/addons.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #include "mon_bootstrap_utils.h" 18 | #include "policy_manager.h" 19 | #include "mon_addons.h" 20 | #include "mon_dbg.h" 21 | #include 22 | #include "file_codes.h" 23 | 24 | #define MON_DEADLOOP() MON_DEADLOOP_LOG(ADDONS_C) 25 | #define MON_ASSERT(__condition) MON_ASSERT_LOG(ADDONS_C, __condition) 26 | 27 | void start_addons(uint32_t num_of_cpus, 28 | const mon_startup_struct_t *startup_struct, 29 | const mon_application_params_struct_t * 30 | application_params_struct UNUSED) 31 | { 32 | MON_LOG(mask_anonymous, level_trace, "start addons\r\n"); 33 | 34 | if (global_policy_uses_ept()) { 35 | init_ept_addon(num_of_cpus); 36 | } else { 37 | MON_LOG(mask_anonymous, level_error, "No supported addons\r\n"); 38 | MON_DEADLOOP(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /core/startup/dummy_event_handler.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | #ifndef EXTERN_EVENT_HANDLER 17 | #include "mon_callback.h" 18 | 19 | 20 | boolean_t report_mon_event(report_mon_event_t event, 21 | mon_identification_data_t gcpu, 22 | const guest_vcpu_t *vcpu_id, 23 | void *event_specific_data) 24 | { 25 | boolean_t status = TRUE; 26 | 27 | switch (event) { 28 | case MON_EVENT_INITIALIZATION_BEFORE_APS_STARTED: 29 | break; 30 | case MON_EVENT_INITIALIZATION_AFTER_APS_STARTED: 31 | break; 32 | case MON_EVENT_EPT_VIOLATION: 33 | break; 34 | case MON_EVENT_MTF_VMEXIT: 35 | break; 36 | case MON_EVENT_CR_ACCESS: 37 | status = FALSE; 38 | break; 39 | case MON_EVENT_DR_LOAD_ACCESS: 40 | break; 41 | case MON_EVENT_LDTR_LOAD_ACCESS: 42 | break; 43 | case MON_EVENT_GDTR_IDTR_ACCESS: 44 | break; 45 | case MON_EVENT_MSR_READ_ACCESS: 46 | break; 47 | case MON_EVENT_MSR_WRITE_ACCESS: 48 | break; 49 | case MON_EVENT_SET_ACTIVE_EPTP: 50 | break; 51 | case MON_EVENT_INITIAL_VMEXIT_CHECK: 52 | status = FALSE; 53 | break; 54 | case MON_EVENT_SINGLE_STEPPING_CHECK: 55 | break; 56 | case MON_EVENT_MON_TEARDOWN: 57 | break; 58 | case MON_EVENT_INVALID_FAST_VIEW_SWITCH: 59 | break; 60 | case MON_EVENT_VMX_PREEMPTION_TIMER: 61 | break; 62 | case MON_EVENT_HALT_INSTRUCTION: 63 | break; 64 | case MON_EVENT_LOG: 65 | break; 66 | case MON_EVENT_CPUID: 67 | status = FALSE; 68 | break; 69 | } 70 | 71 | return status; 72 | } 73 | 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /core/startup/layout_host_memory.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #ifndef _LAYOUT_HOST_MEMORY_H_ 18 | #define _LAYOUT_HOST_MEMORY_H_ 19 | 20 | #include "mon_startup.h" 21 | #include "mon_objects.h" 22 | 23 | /************************************************************************** 24 | * 25 | * Perform host memory layout for multiguest environment 26 | * 27 | * Different algorithms should be used for MBR-based abd loader-based 28 | * MON load scenarios 29 | * 30 | ************************************************************************** */ 31 | 32 | /*------------------------------------------------------------------------- 33 | * 34 | * init memory layout 35 | * This function should perform init of "memory layout object" and 36 | * init the primary guest memory layout. 37 | * 38 | *------------------------------------------------------------------------- */ 39 | boolean_t init_memory_layout_from_mbr( 40 | const mon_memory_layout_t *mon_memory_layout, 41 | gpm_handle_t primary_guest_gpm, 42 | boolean_t are_secondary_guests_exist, 43 | const mon_application_params_struct_t * 44 | application_params); 45 | 46 | /*------------------------------------------------------------------------- 47 | * 48 | * Allocate memory for seondary guest, remove it from primary guest and 49 | * return allocated address 50 | * 51 | *------------------------------------------------------------------------- */ 52 | uint64_t allocate_memory_for_secondary_guest_from_mbr(gpm_handle_t 53 | primary_guest_gpm, 54 | gpm_handle_t 55 | secondary_guest_gpm, 56 | uint32_t required_size); 57 | 58 | /* wrappers */ 59 | INLINE 60 | boolean_t init_memory_layout(const mon_memory_layout_t *mon_memory_layout, 61 | gpm_handle_t primary_guest_gpm, 62 | boolean_t are_secondary_guests_exist, 63 | const mon_application_params_struct_t * 64 | application_params) 65 | { 66 | return init_memory_layout_from_mbr(mon_memory_layout, 67 | primary_guest_gpm, 68 | are_secondary_guests_exist, 69 | application_params); 70 | } 71 | 72 | #endif /* _LAYOUT_HOST_MEMORY_H_ */ 73 | -------------------------------------------------------------------------------- /core/utils/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | CSOURCES = $(wildcard *.c) 18 | ASOURCES = $(wildcard *.S) 19 | include $(PROJS)/core/rule.linux 20 | -------------------------------------------------------------------------------- /core/utils/address.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #include "hw_includes.h" 18 | #include "address.h" 19 | 20 | static address_t max_virtual_address; 21 | static address_t virtual_address_copmplement; 22 | 23 | static uint8_t physical_address_size; 24 | static uint8_t virtual_address_size; 25 | 26 | extern uint32_t pw_reserved_bits_high_mask; 27 | 28 | void API_FUNCTION addr_setup_address_space(void) 29 | { 30 | uint32_t value = hw_read_address_size(); 31 | 32 | physical_address_size = (uint8_t)(value & 0xFF); 33 | virtual_address_size = (uint8_t)((value >> 8) & 0xFF); 34 | 35 | max_virtual_address = ((address_t)1 << virtual_address_size) - 1;; 36 | virtual_address_copmplement = ~(max_virtual_address >> 1);; 37 | 38 | /* bit mask to identify the reserved bits in paging structure high order 39 | * address field */ 40 | pw_reserved_bits_high_mask = ~((1 << (physical_address_size - 32)) - 1); 41 | } 42 | 43 | uint8_t API_FUNCTION addr_get_physical_address_size(void) 44 | { 45 | return physical_address_size; 46 | } 47 | 48 | address_t API_FUNCTION addr_canonize_address(address_t address) 49 | { 50 | if (address & virtual_address_copmplement) { 51 | address |= virtual_address_copmplement; 52 | } 53 | return address; 54 | } 55 | 56 | boolean_t addr_is_canonical(address_t address) 57 | { 58 | return addr_canonize_address(address) == address; 59 | } 60 | 61 | boolean_t addr_physical_is_valid(address_t address) 62 | { 63 | address_t phys_address_space = 64 | BIT_VALUE64((address_t)(physical_address_size)); 65 | 66 | return address < phys_address_space; 67 | } 68 | -------------------------------------------------------------------------------- /core/utils/math_utils.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #include "mon_defs.h" 18 | #include "hw_utils.h" 19 | 20 | uint32_t align_forward_to_power_of_2(uint64_t number) 21 | { 22 | uint32_t msb_index = 0; 23 | 24 | if (0 == number) { 25 | return 1; 26 | } 27 | 28 | hw_scan_bit_backward64((uint32_t *)&msb_index, number); 29 | if (!IS_POW_OF_2(number)) { 30 | msb_index++; 31 | } 32 | 33 | return 1 << msb_index; 34 | } 35 | -------------------------------------------------------------------------------- /core/vmexit/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | CSOURCES = $(wildcard *.c) 18 | include $(PROJS)/core/rule.linux 19 | -------------------------------------------------------------------------------- /core/vmexit/vmexit_dbg.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include "file_codes.h" 22 | 23 | #define MON_DEADLOOP() MON_DEADLOOP_LOG(VMEXIT_DBG_C) 24 | #define MON_ASSERT(__condition) MON_ASSERT_LOG(VMEXIT_DBG_C, __condition) 25 | 26 | const char *string = "bla bla"; 27 | 28 | #define CTRL(__char) (__char - 'a' + 1) 29 | 30 | #define REQUEST_COUNT 8 31 | static char monitor_requested[REQUEST_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0 }; 32 | 33 | static char monitor_request_keys[REQUEST_COUNT] = { 34 | CTRL('q'), 35 | CTRL('w'), 36 | CTRL('e'), 37 | CTRL('r'), 38 | CTRL('t'), 39 | CTRL('y'), 40 | CTRL('u'), 41 | CTRL('i') 42 | }; 43 | 44 | int monitor_was_requested(char key) 45 | { 46 | size_t i; 47 | 48 | for (i = 0; i < NELEMENTS(monitor_request_keys); ++i) { 49 | if (key == monitor_request_keys[i]) { 50 | return (int)i; 51 | } 52 | } 53 | return -1; 54 | } 55 | 56 | void vmexit_check_keystroke(guest_cpu_handle_t gcpu) 57 | { 58 | uint8_t key = mon_getc(); 59 | int monitor_cpu; 60 | 61 | switch (key) { 62 | case 0: 63 | /* optimization */ 64 | break; 65 | 66 | case 's': 67 | case 'S': 68 | MON_LOG(mask_anonymous, level_trace, "%s\n", string); 69 | break; 70 | 71 | case CTRL('b'): 72 | case CTRL('d'): 73 | MON_DEADLOOP(); 74 | break; 75 | 76 | default: 77 | monitor_cpu = monitor_was_requested(key); 78 | if (monitor_cpu != -1) { 79 | monitor_requested[monitor_cpu] = 1; 80 | } 81 | if (monitor_requested[hw_cpu_id()] != 0) { 82 | monitor_requested[hw_cpu_id()] = 0; 83 | MON_DEADLOOP(); 84 | } 85 | 86 | break; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /core/vmexit/vmexit_ept.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #include "mon_defs.h" 18 | #include "guest_cpu.h" 19 | #include "mon_events_data.h" 20 | #include "vmcs_api.h" 21 | #include "hw_utils.h" 22 | #include "mon_callback.h" 23 | #include "file_codes.h" 24 | 25 | #define MON_DEADLOOP() MON_DEADLOOP_LOG(VMEXIT_EPT_C) 26 | #define MON_ASSERT(__condition) MON_ASSERT_LOG(VMEXIT_EPT_C, __condition) 27 | 28 | vmexit_handling_status_t vmexit_mtf(guest_cpu_handle_t gcpu) 29 | { 30 | if (!report_mon_event 31 | (MON_EVENT_MTF_VMEXIT, (mon_identification_data_t)gcpu, 32 | (const guest_vcpu_t *)mon_guest_vcpu(gcpu), NULL)) { 33 | MON_LOG(mask_mon, level_trace, "Report MTF VMExit failed.\n"); 34 | } 35 | 36 | return VMEXIT_HANDLED; 37 | } 38 | 39 | 40 | boolean_t ept_violation_vmexit(guest_cpu_handle_t gcpu, void *pv); 41 | 42 | vmexit_handling_status_t vmexit_ept_violation(guest_cpu_handle_t gcpu) 43 | { 44 | event_gcpu_ept_violation_data_t data; 45 | vmcs_object_t *vmcs = mon_gcpu_get_vmcs(gcpu); 46 | 47 | data.qualification.uint64 = mon_vmcs_read(vmcs, 48 | VMCS_EXIT_INFO_QUALIFICATION); 49 | data.guest_linear_address = 50 | mon_vmcs_read(vmcs, VMCS_EXIT_INFO_GUEST_LINEAR_ADDRESS); 51 | data.guest_physical_address = 52 | mon_vmcs_read(vmcs, VMCS_EXIT_INFO_GUEST_PHYSICAL_ADDRESS); 53 | data.processed = FALSE; 54 | 55 | ept_violation_vmexit(gcpu, &data); 56 | 57 | if (!data.processed) { 58 | MON_LOG(mask_anonymous, 59 | level_trace, 60 | "Unsupported ept violation in \n"); 61 | PRINT_GCPU_IDENTITY(gcpu); 62 | MON_DEADLOOP(); 63 | } 64 | 65 | return VMEXIT_HANDLED; 66 | } 67 | 68 | vmexit_handling_status_t vmexit_ept_misconfiguration(guest_cpu_handle_t gcpu) 69 | { 70 | event_gcpu_ept_misconfiguration_data_t data; 71 | vmcs_object_t *vmcs = mon_gcpu_get_vmcs(gcpu); 72 | 73 | data.guest_physical_address = 74 | mon_vmcs_read(vmcs, VMCS_EXIT_INFO_GUEST_PHYSICAL_ADDRESS); 75 | data.processed = FALSE; 76 | 77 | event_raise(EVENT_GCPU_EPT_MISCONFIGURATION, gcpu, &data); 78 | 79 | MON_ASSERT(data.processed); 80 | 81 | if (!data.processed) { 82 | MON_LOG(mask_anonymous, level_trace, 83 | "Unsupported ept misconfiguration in \n"); 84 | PRINT_GCPU_IDENTITY(gcpu); 85 | MON_DEADLOOP(); 86 | } 87 | 88 | return VMEXIT_HANDLED; 89 | } 90 | -------------------------------------------------------------------------------- /core/vmexit/vmexit_init.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #include "file_codes.h" 18 | #define MON_DEADLOOP() MON_DEADLOOP_LOG(VMEXIT_INIT_C) 19 | #define MON_ASSERT(__condition) MON_ASSERT_LOG(VMEXIT_INIT_C, __condition) 20 | #include "mon_defs.h" 21 | #include "guest_cpu.h" 22 | #include "guest.h" 23 | #include "local_apic.h" 24 | #include "mon_dbg.h" 25 | #include "hw_utils.h" 26 | #include "vmcs_init.h" 27 | #include "mon_events_data.h" 28 | 29 | /*-------------------------------------------------------------------------* 30 | * FUNCTION : vmexit_init_event() 31 | * PURPOSE : reset CPU 32 | * ARGUMENTS: guest_cpu_handle_t gcpu 33 | * RETURNS : void 34 | * NOTE : Propagate INIT signal from primary guest to CPU 35 | *-------------------------------------------------------------------------*/ 36 | vmexit_handling_status_t vmexit_init_event(guest_cpu_handle_t gcpu) 37 | { 38 | cpu_id_t cpu_id = hw_cpu_id(); 39 | 40 | MON_LOG(mask_anonymous, level_trace, 41 | "INIT signal in Guest#%d GuestCPU#%d HostCPU#%d\n", 42 | mon_guest_vcpu(gcpu)->guest_id, mon_guest_vcpu( 43 | gcpu)->guest_cpu_id, 44 | hw_cpu_id()); 45 | 46 | MON_ASSERT(guest_is_primary(mon_gcpu_guest_handle(gcpu))); 47 | 48 | if (cpu_id == 0) { /* If cpu is BSP */ 49 | MON_LOG(mask_anonymous, 50 | level_trace, 51 | "[%d] Perform global reset\n", 52 | cpu_id); 53 | hw_reset_platform(); /* then preform cold reset. */ 54 | MON_DEADLOOP(); 55 | } else { 56 | MON_LOG(mask_anonymous, level_trace, 57 | "[%d] Switch to Wait for SIPI mode\n", cpu_id); 58 | 59 | /* Switch to Wait for SIPI state. */ 60 | gcpu_set_activity_state(gcpu, 61 | IA32_VMX_VMCS_GUEST_SLEEP_STATE_WAIT_FOR_SIPI); 62 | } 63 | 64 | return VMEXIT_HANDLED; 65 | } 66 | -------------------------------------------------------------------------------- /core/vmexit/vmexit_invd.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #include "mon_defs.h" 18 | #include "hw_utils.h" 19 | #include "guest_cpu.h" 20 | #include "vmexit.h" 21 | 22 | vmexit_handling_status_t vmexit_invd(guest_cpu_handle_t gcpu) 23 | { 24 | /* We can't invalidate caches without writing them to memory */ 25 | hw_wbinvd(); 26 | gcpu_skip_guest_instruction(gcpu); 27 | return VMEXIT_HANDLED; 28 | } 29 | -------------------------------------------------------------------------------- /core/vmexit/vmexit_invlpg.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #include "mon_defs.h" 18 | #include "vmx_vmcs.h" 19 | #include "vmcs_api.h" 20 | #include "mon_dbg.h" 21 | #include "em64t_defs.h" 22 | #include "mon_events_data.h" 23 | #include "guest_cpu.h" 24 | 25 | vmexit_handling_status_t vmexit_invlpg(guest_cpu_handle_t gcpu) 26 | { 27 | event_gcpu_invalidate_page_data_t data; 28 | ia32_vmx_exit_qualification_t qualification; 29 | vmcs_object_t *vmcs = mon_gcpu_get_vmcs(gcpu); 30 | 31 | qualification.uint64 = 32 | mon_vmcs_read(vmcs, VMCS_EXIT_INFO_QUALIFICATION); 33 | data.invlpg_addr = qualification.invlpg_instruction.address; 34 | 35 | /* Return value of raising event is not important */ 36 | event_raise(EVENT_GCPU_INVALIDATE_PAGE, gcpu, &data); 37 | 38 | /* Instruction will be skipped in upper "bottom-up" handler */ 39 | 40 | 41 | return VMEXIT_HANDLED; 42 | } 43 | -------------------------------------------------------------------------------- /core/vmexit/vmexit_triple_fault.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #include "mon_defs.h" 18 | #include "guest_cpu.h" 19 | #include "hw_utils.h" 20 | #include "scheduler.h" 21 | #include "mon_dbg.h" 22 | #include "file_codes.h" 23 | 24 | #define MON_DEADLOOP() MON_DEADLOOP_LOG(VMEXIT_TRIPLE_fault_C) 25 | #define MON_ASSERT(__condition) \ 26 | MON_ASSERT_LOG(VMEXIT_TRIPLE_fault_C, __condition) 27 | 28 | vmexit_handling_status_t vmexit_triple_fault(guest_cpu_handle_t gcpu) 29 | { 30 | MON_LOG(mask_anonymous, level_trace, "Triple Fault Occured on \n"); 31 | PRINT_GCPU_IDENTITY(gcpu); 32 | MON_LOG(mask_anonymous, level_trace, " Reset the System.\n"); 33 | MON_DEBUG_CODE(MON_DEADLOOP()); 34 | hw_reset_platform(); 35 | /* TODO: Tear down the guest */ 36 | 37 | /* just to pass release compilation */ 38 | if (0) { 39 | gcpu = NULL; 40 | } 41 | return VMEXIT_HANDLED; 42 | } 43 | -------------------------------------------------------------------------------- /core/vmexit/vmexit_ud.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #include "mon_defs.h" 18 | #include "isr.h" 19 | #include "guest_cpu.h" 20 | #include "guest_cpu_vmenter_event.h" 21 | 22 | vmexit_handling_status_t vmexit_undefined_opcode(guest_cpu_handle_t gcpu) 23 | { 24 | vmenter_event_t ud_event; 25 | 26 | ud_event.interrupt_info.bits.valid = 1; 27 | ud_event.interrupt_info.bits.vector = 28 | IA32_EXCEPTION_VECTOR_UNDEFINED_OPCODE; 29 | ud_event.interrupt_info.bits.interrupt_type = 30 | VMENTER_INTERRUPT_TYPE_HARDWARE_EXCEPTION; 31 | /* no error code delivered */ 32 | ud_event.interrupt_info.bits.deliver_code = 0; 33 | gcpu_inject_event(gcpu, &ud_event); 34 | return VMEXIT_HANDLED; 35 | } 36 | -------------------------------------------------------------------------------- /core/vmx/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Copyright (c) 2015 Intel Corporation 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | ################################################################################ 16 | 17 | CSOURCES = $(wildcard *.c) 18 | include $(PROJS)/core/rule.linux 19 | -------------------------------------------------------------------------------- /core/vmx/vmcs_hierarchy.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Intel Corporation 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | #include "mon_defs.h" 18 | #include "mon_dbg.h" 19 | #include "memory_allocator.h" 20 | #include "mon_objects.h" 21 | #include "vmcs_api.h" 22 | #include "vmcs_sw_object.h" 23 | #include "vmcs_actual.h" 24 | #include "vmcs_hierarchy.h" 25 | #include "file_codes.h" 26 | 27 | #define MON_DEADLOOP() MON_DEADLOOP_LOG(VMCS_HIERARCHY_C) 28 | #define MON_ASSERT(__condition) MON_ASSERT_LOG(VMCS_HIERARCHY_C, __condition) 29 | 30 | typedef struct { 31 | vmcs_object_t *vmcs; 32 | list_element_t list[1]; 33 | } vmcs_1_descriptor_t; 34 | 35 | static vmcs_1_descriptor_t *vmcs_hierarchy_vmcs1_lkup(vmcs_hierarchy_t *obj, 36 | vmcs_object_t *vmcs); 37 | 38 | mon_status_t vmcs_hierarchy_create(vmcs_hierarchy_t *obj, 39 | guest_cpu_handle_t gcpu) 40 | { 41 | mon_status_t status; 42 | 43 | MON_ASSERT(obj); 44 | 45 | obj->vmcs[VMCS_LEVEL_0] = obj->vmcs[VMCS_MERGED] = 46 | vmcs_act_create(gcpu); 47 | 48 | if (NULL == obj->vmcs[VMCS_LEVEL_0]) { 49 | MON_LOG(mask_anonymous, 50 | level_trace, 51 | "Failed to create merged VMCS\n"); 52 | status = MON_ERROR; 53 | } else { 54 | obj->vmcs[VMCS_LEVEL_1] = NULL; 55 | list_init(obj->vmcs_1_list); 56 | status = MON_OK; 57 | } 58 | 59 | return status; 60 | } 61 | 62 | vmcs_object_t *vmcs_hierarchy_get_vmcs(vmcs_hierarchy_t *obj, 63 | vmcs_level_t level) 64 | { 65 | vmcs_object_t *vmcs; 66 | 67 | MON_ASSERT(obj); 68 | 69 | if (level >= VMCS_LEVEL_0 && level < VMCS_LEVELS) { 70 | vmcs = obj->vmcs[level]; 71 | } else { 72 | MON_LOG(mask_anonymous, level_trace, "Invalid VMCS level\n"); 73 | MON_ASSERT(0); 74 | vmcs = NULL; 75 | } 76 | 77 | return vmcs; 78 | } 79 | -------------------------------------------------------------------------------- /package/check_ikgt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/ikgt-core/1f53455d25ff5ee67f2ed323c98893dfc7d98f5d/package/check_ikgt -------------------------------------------------------------------------------- /package/check_vtx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -n "$(cat /proc/cpuinfo | grep vmx)" ]; then 4 | echo "VTx is available" 5 | else 6 | echo "VTx is not available" 7 | fi 8 | 9 | # End of this script 10 | -------------------------------------------------------------------------------- /package/ikgt.cfg: -------------------------------------------------------------------------------- 1 | # 2 | # Set to 0 or 1 to avoid warning. 3 | # 4 | IKGT_OVERRIDE_GRUB_DEFAULT= 5 | 6 | echo "Including ikgt overrides from /etc/default/grub.d/ikgt.cfg" 7 | 8 | # 9 | # Make booting into ikgt the default if not changed above. Finding the 10 | # current string for it always has been a problem. 11 | # 12 | if [ "$IKGT_OVERRIDE_GRUB_DEFAULT" = "" ]; then 13 | echo "WARNING: GRUB_DEFAULT changed to boot into ikgt by default!" 14 | echo " Edit /etc/default/grub.d/ikgt.cfg to avoid this warning." 15 | IKGT_OVERRIDE_GRUB_DEFAULT=1 16 | fi 17 | if [ "$IKGT_OVERRIDE_GRUB_DEFAULT" = "1" ]; then 18 | GRUB_DEFAULT="Ubuntu GNU/Linux, with iKGT" 19 | fi 20 | --------------------------------------------------------------------------------