about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAjax <commial@gmail.com>2018-07-16 17:56:27 +0200
committerAjax <commial@gmail.com>2018-07-19 14:03:34 +0200
commit520623b42f1d75231509a7b181838ef7bb2db6c3 (patch)
tree67fcbe3b7d5b9f2722914027e1abfac6b792e7db
parent7e412335ba4df14270561e030c0991dbcca88d38 (diff)
downloadmiasm-520623b42f1d75231509a7b181838ef7bb2db6c3.tar.gz
miasm-520623b42f1d75231509a7b181838ef7bb2db6c3.zip
CPUID: add suport for more cpuid leaves
CPUID is set to let Miasm run libc with supported instruction
-rw-r--r--miasm2/jitter/op_semantics.c60
1 files changed, 54 insertions, 6 deletions
diff --git a/miasm2/jitter/op_semantics.c b/miasm2/jitter/op_semantics.c
index 061e7736..e997226a 100644
--- a/miasm2/jitter/op_semantics.c
+++ b/miasm2/jitter/op_semantics.c
@@ -302,11 +302,12 @@ unsigned int x86_cpuid(unsigned int a, unsigned int reg_num)
 		fprintf(stderr, "not implemented x86_cpuid reg %x\n", reg_num);
 		exit(EXIT_FAILURE);
 	}
-
+	// cases are output: EAX: 0; EBX: 1; ECX: 2; EDX: 3
 	if (a == 0){
 		switch(reg_num){
 		case 0:
 			return 0xa;
+		// "GenuineIntel"
 		case 1:
 			return 0x756E6547;
 		case 2:
@@ -319,8 +320,10 @@ unsigned int x86_cpuid(unsigned int a, unsigned int reg_num)
 	else if (a == 1){
 		switch(reg_num){
 		case 0:
-			//return 0x000006FB;
-			return 0x00020652;
+			// Using a version too high will enable recent
+			// instruction set
+			return 0x000006FB;
+			//return 0x00020652;
 		case 1:
 			//return 0x02040800;
 			return 0x00000800;
@@ -328,13 +331,58 @@ unsigned int x86_cpuid(unsigned int a, unsigned int reg_num)
 			//return 0x0004E3BD;
 			return 0x00000209;
 		case 3:
-			//return 0xBFEBFBFF;
-			return 0x078bf9ff;
+			return (/* fpu */ 1 << 0) |
+				(/* tsc */ 1 << 4) |
+				(/* cx8 */ 1 << 8) |
+				(/* cmov */ 1 << 15) |
+				(/* mmx */ 1 << 23) |
+				(/* sse */ 1 << 25) |
+				(/* sse2 */ 1 << 26) |
+				(/* ia64 */ 1 << 30);
+		}
+	}
+	// Cache and TLB
+	else if (a == 2){
+		switch(reg_num){
+		case 0:
+			return 0x00000000;
+		case 1:
+			return 0x00000000;
+		case 2:
+			return 0x00000000;
+		case 3:
+			return 0x00000000;
+		}
+	}
+	// Intel thread/core and cache topology
+	else if (a == 4){
+		switch(reg_num){
+		case 0:
+			return 0x00000000;
+		case 1:
+			return 0x00000000;
+		case 2:
+			return 0x00000000;
+		case 3:
+			return 0x00000000;
+		}
+	}
+	// Extended features
+	else if (a == 7){
+		switch(reg_num){
+		case 0:
+			return 0x00000000;
+		case 1:
+			return (/* fsgsbase */ 1 << 0) | (/* bmi1 */ 1 << 3);
+		case 2:
+			return 0x00000000;
+		case 3:
+			return 0x00000000;
 		}
 	}
 	else{
 		fprintf(stderr, "WARNING not implemented x86_cpuid index %X!\n", a);
-		//exit(EXIT_FAILURE);
+		exit(EXIT_FAILURE);
 	}
 	return 0;
 }