github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/vmm/test/linktest.c (about) 1 /* 2 * File: linktest.c 3 * Description: Get tbooted and boot 64 bit evmm 4 * Author: John Manferdelli 5 * 6 * Copyright (c) 2013 Intel Corporation 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 #include "stdio.h" 20 #include "string.h" 21 #include <stdlib.h> 22 23 24 typedef unsigned char uint8_t; 25 typedef unsigned short uint16_t; 26 typedef unsigned int uint32_t; 27 typedef long long unsigned uint64_t; 28 29 30 void vmm_main(uint32_t local_apic_id, uint64_t startup_struct_u, 31 uint64_t application_params_struct_u, uint64_t reserved) 32 { 33 #if 0 34 printf("In vmm_main (1)\n"); 35 #else 36 printf("In vmm_main (2)\n"); 37 #endif 38 printf("\tlocal_apic_id: %d, startup_struct_u: %ld\n", local_apic_id, (long int)startup_struct_u); 39 printf("\tapplication_params_struct_u: %ld, reserved: %ld\n", 40 (long int)application_params_struct_u, (long int)reserved); 41 exit(0); 42 } 43 44 45 int main(int an, char* av) 46 { 47 uint64_t vmm_main_entry_point= (uint64_t) vmm_main; 48 uint32_t local_apic_id= 1; 49 uint64_t p_startup_struct= 2ULL; 50 uint64_t application_params_struct= 3ULL; 51 uint64_t evmm_reserved= 4ULL; 52 53 printf("vmm_main: 0x%016lx, vmm_main: 0x%016lx\n", 54 (long unsigned int) vmm_main_entry_point, (long unsigned int)vmm_main); 55 56 57 uint64_t args[4]; 58 59 args[0]= evmm_reserved; 60 args[1]= application_params_struct; 61 args[2]= p_startup_struct; 62 args[3]= local_apic_id; 63 asm volatile ( 64 #if 0 65 "\tpushq %[evmm_reserved]\n" 66 "\tpushq %[application_params_struct]\n" 67 "\tpushq %[p_startup_struct]\n" 68 "\tpushq %[local_apic_id]\n" 69 #else 70 "\tmovq %[args], %%rbx\n" 71 "\tpushq (%%rbx)\n" 72 "\taddq $8, %%rbx\n" 73 "\tpushq (%%rbx)\n" 74 "\taddq $8, %%rbx\n" 75 "\tpushq (%%rbx)\n" 76 "\taddq $8, %%rbx\n" 77 "\tpushq (%%rbx)\n" 78 "\tmovq %[vmm_main_entry_point], %%rbx\n" 79 #endif 80 81 // for following retf 82 // "\tjmp 1f\n" 83 "\tpush $1f\n" 84 "\tret\n" 85 "1:\n" 86 "\tpopq %%rdi\n" 87 "\tpopq %%rsi\n" 88 "\tpopq %%rdx\n" 89 "\tpopq %%rcx\n" 90 #if 0 91 "\tjmpq %[vmm_main_entry_point]\n" 92 #else 93 "\tjmpq %%rbx\n" 94 #endif 95 "\tud2\n" 96 :: 97 #if 0 98 [local_apic_id] "m" (local_apic_id), [p_startup_struct] "m" (p_startup_struct), 99 [application_params_struct] "m" (application_params_struct), 100 [evmm_reserved] "m" (evmm_reserved), 101 #else 102 [args] "p" (args), 103 #endif 104 [vmm_main_entry_point] "m" (vmm_main_entry_point) 105 : "%rax", "%rbx", "%rcx", "%rdx", "%rsi", "%rdi"); 106 107 return 0; 108 } 109