github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/vmm/host/hw/em64t/fixup.c (about) 1 /* 2 * Copyright (c) 2013 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 * http://www.apache.org/licenses/LICENSE-2.0 8 * Unless required by applicable law or agreed to in writing, software 9 * distributed under the License is distributed on an "AS IS" BASIS, 10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 * See the License for the specific language governing permissions and 12 * limitations under the License. 13 */ 14 #include "vmm_defs.h" 15 #define VMM_NATIVE_VMCALL_SIGNATURE 0x024694D40 16 UINT64 t_vmcs_save_area[512]; // never bigger than 4KB 17 extern void vmm_print_vmcs_region(UINT64* pu); 18 #ifdef JLMDEBUG 19 #include "bootstrap_print.h" 20 #include "jlmdebug.h" 21 22 extern void** g_guest_regs_save_area; 23 extern void vmm_vmcs_guest_state_read(UINT64* area); 24 #endif 25 26 extern void vmm_vmcs_guest_state_read(UINT64* area); 27 extern int vmx_vmread(UINT64 index, UINT64 *value); 28 extern int vmx_vmwrite(UINT64 index, UINT64 value); 29 30 extern UINT64 getphysical(UINT64 cr3, UINT64 virt); 31 32 33 #ifdef JLMDEBUG 34 typedef unsigned char uint8_t; 35 typedef unsigned short uint16_t; 36 typedef unsigned int uint32_t; 37 typedef long long unsigned uint64_t; 38 39 typedef int bool; 40 typedef unsigned char u8; 41 typedef unsigned short u16; 42 typedef unsigned int u32; 43 typedef long long unsigned u64; 44 45 #include "../../../bootstrap/linux_defns.h" 46 47 void check_boot_parameters() 48 { 49 UINT64* regs = *g_guest_regs_save_area; 50 UINT64 rdi_reg= regs[4]; 51 UINT64 rsi_reg= regs[5]; 52 UINT64 ept; 53 UINT64 real; 54 UINT64 virt; 55 UINT64 value; 56 57 bprint("rdi on entry: %llx, rsi: %llx\n", rdi_reg, rsi_reg); 58 boot_params_t* boot_params= (boot_params_t*) rdi_reg; 59 //HexDump((UINT8*)rdi_reg, (UINT8*)rdi_reg+32); 60 //bprint("cmd line ptr: %p\n", boot_params->hdr.cmd_line_ptr); 61 //bprint("code32_start: %p\n", boot_params->hdr.code32_start); 62 bprint("loadflags: %02x\n", boot_params->hdr.loadflags); 63 64 vmx_vmread(0x201a, &ept); 65 virt= rdi_reg; 66 real= getphysical(ept, virt); 67 bprint("virt: %016llx, real: %016llx\n", virt, real); 68 virt= (UINT64) &(boot_params->hdr.loadflags); 69 real= getphysical(ept, virt); 70 bprint("virt: %016llx, real: %016llx\n", virt, real); 71 72 vmx_vmread(0x681e, &value); // guest_rip 73 virt =value; 74 real= getphysical(ept, virt); 75 bprint("virt: %016llx, real: %016llx\n", virt, real); 76 virt =value+10; 77 real= getphysical(ept, virt); 78 bprint("virt: %016llx, real: %016llx\n", virt, real); 79 } 80 #endif 81 82 83 84 // fixup control registers and make guest loop forever 85 86 __asm__ ( 87 ".text\n" 88 ".globl loop_forever\n" 89 ".type loop_forever, @function\n" 90 "loop_forever:\n" 91 "\tjmp .\n" 92 "\tret\n" 93 ); 94 95 96 void fixupvmcs() 97 { 98 UINT64 value; 99 void loop_forever(); 100 101 #ifdef JLMDEBUG 102 UINT16* loop= (UINT16*)loop_forever; 103 bprint("fixupvmcs %04x\n\n", *loop); 104 #endif 105 vmx_vmread(0x681e, &value); // guest_rip 106 #ifdef JLMDEBUG 107 check_boot_parameters(); 108 #endif 109 //bprint("Code at %p\n", value); 110 //HexDump((UINT8*)value, (UINT8*)value+32); 111 //*(UINT16*) (value+0x8)= *loop; // feeb 112 //*(UINT16*) (value+0xa)= *loop; // feeb 113 //*(UINT16*) (value+0x10)= *loop; // feeb 114 //*(UINT16*) (value+0x16)= *loop; // feeb 115 116 // vmx_vmread(0x4000, &value); // vmx_pin_controls 117 // vmx_vmwrite(0x4000, value); // vmx_pin_controls 118 119 // vmx_vmread(0x4002, &value); // vmx_cpu_controls 120 // vmx_vmwrite(0x4002, value); // vmx_cpu_controls 121 122 // vmx_vmread(0x401e, &value); // vmx_secondary_controls 123 // vmx_vmwrite(0x401e, value); // vmx_secondary_controls 124 125 // vmx_vmread(0x4012, &value); // vmx_entry_controls 126 // vmx_vmwrite(0x4012, value); // vmx_entry_controls 127 128 // vmx_vmread(0x4002, &value); // vmx_exit_controls 129 // vmx_vmwrite(0x4002, value); // vmx_exit_controls 130 131 vmm_vmcs_guest_state_read((UINT64*) t_vmcs_save_area); 132 vmm_print_vmcs_region((UINT64*) t_vmcs_save_area); 133 } 134 135