X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=blobdiff_plain;f=palacios%2Finclude%2Fpalacios%2Fvmm_lowlevel.h;h=af1f8209caf98526fcafb0e8d4f3ce7138164333;hp=f3c8db524babbc498b3e4dde09d43d32f4da5fc6;hb=571979dad8fc2138a7e11c4fe61e812a0a0b17d1;hpb=ed2b3c62f54f46c31ed18a100bb442e1656a3ddd diff --git a/palacios/include/palacios/vmm_lowlevel.h b/palacios/include/palacios/vmm_lowlevel.h index f3c8db5..af1f820 100644 --- a/palacios/include/palacios/vmm_lowlevel.h +++ b/palacios/include/palacios/vmm_lowlevel.h @@ -23,16 +23,70 @@ #define CPUID_FEATURE_IDS 0x00000001 #define CPUID_EXT_FEATURE_IDS 0x80000001 +struct seg_selector { + union { + uint16_t value; + struct { + uint8_t rpl : 2; + uint8_t ti : 1; + uint16_t si : 13; + } __attribute__((packed)); + } __attribute__((packed)); +} __attribute__((packed)); + +struct gen_segment { + uint16_t limit_lo; + uint32_t base_lo : 24; + uint8_t type : 4; + uint8_t system : 1; + uint8_t dpl : 2; + uint8_t present : 1; + uint8_t limit_hi : 4; + uint8_t avail : 1; + uint8_t long_mode : 1; + uint8_t db : 1; + uint8_t granularity : 1; + uint8_t base_hi : 8; +} __attribute__((packed)); + +struct sys_segment64 { + uint16_t limit_lo; + uint32_t base_lo : 24; + uint8_t type : 4; + uint8_t rsvd0 : 1; + uint8_t dpl : 2; + uint8_t present : 1; + uint8_t limit_hi : 4; + uint8_t avail : 1; + uint8_t rsvd1 : 3; + uint8_t granularity : 1; + uint64_t base_hi : 40; + uint32_t rsvd2; +} __attribute__((packed)); + static void __inline__ v3_cpuid(uint32_t target, uint32_t * eax, uint32_t * ebx, uint32_t * ecx, uint32_t * edx) { +#ifdef __V3_64BIT__ __asm__ __volatile__ ( "cpuid\n\t" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) : "0" (target), "2" (*ecx) ); +#elif __V3_32BIT__ + // 32 bit code compiled with -fPIC, cannot use ebx as an ouput reg. Fantastic. + __asm__ __volatile__ ( + "pushl %%ebx\n\t" + "movl %%edi, %%ebx\n\t" + "cpuid\n\t" + "movl %%ebx, %%edi\n\t" + "popl %%ebx\n\t" + : "=a" (*eax), "=D" (*ebx), "=c" (*ecx), "=d" (*edx) + : "0" (target), "2" (*ecx) + ); +#endif return; }