|
From: <ep...@us...> - 2013-11-13 09:15:31
|
Revision: 5999
http://sourceforge.net/p/jnode/svn/5999
Author: epr
Date: 2013-11-13 09:15:27 +0000 (Wed, 13 Nov 2013)
Log Message:
-----------
Improving HyperV support.
Modified Paths:
--------------
trunk/core/src/core/org/jnode/vm/x86/UnsafeX86.java
trunk/core/src/core/org/jnode/vm/x86/VmX86Architecture.java
trunk/core/src/core/org/jnode/vm/x86/X86CpuID.java
trunk/core/src/native/x86/syscall.asm
trunk/core/src/native/x86/syscall.h
trunk/core/src/native/x86/unsafex86.asm
Added Paths:
-----------
trunk/core/src/core/org/jnode/vm/x86/HyperV.java
Added: trunk/core/src/core/org/jnode/vm/x86/HyperV.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/x86/HyperV.java (rev 0)
+++ trunk/core/src/core/org/jnode/vm/x86/HyperV.java 2013-11-13 09:15:27 UTC (rev 5999)
@@ -0,0 +1,12 @@
+package org.jnode.vm.x86;
+
+/**
+ * Hyper-V constants
+ * @author ep...@jn...
+ */
+class HyperV {
+ /**
+ * MSR index for identifying the guest OS
+ */
+ static final int HV_X64_MSR_GUEST_OS_ID = 0x40000000;
+}
Modified: trunk/core/src/core/org/jnode/vm/x86/UnsafeX86.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/x86/UnsafeX86.java 2013-11-12 15:21:28 UTC (rev 5998)
+++ trunk/core/src/core/org/jnode/vm/x86/UnsafeX86.java 2013-11-13 09:15:27 UTC (rev 5999)
@@ -21,6 +21,7 @@
package org.jnode.vm.x86;
import org.jnode.annotation.Internal;
+import org.jnode.annotation.KernelSpace;
import org.vmmagic.unboxed.Address;
import org.vmmagic.unboxed.Word;
@@ -78,7 +79,19 @@
* @return 1 on success, 0 otherwise (result == null or result.length less than 4).
*/
@Internal
- public static native int getCPUID(Word input, int[] result);
+ static native int getCPUID(Word input, int[] result);
+
+ /**
+ * Read a model specific register
+ */
+ @KernelSpace
+ static native long readMSR(Word index);
+
+ /**
+ * Write a model specific register
+ */
+ @KernelSpace
+ static native void writeMSR(Word index, long value);
/**
* Gets the address of first entry in the multiboot mmap table.
Modified: trunk/core/src/core/org/jnode/vm/x86/VmX86Architecture.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/x86/VmX86Architecture.java 2013-11-12 15:21:28 UTC (rev 5998)
+++ trunk/core/src/core/org/jnode/vm/x86/VmX86Architecture.java 2013-11-13 09:15:27 UTC (rev 5999)
@@ -22,6 +22,7 @@
import java.nio.ByteOrder;
import java.util.HashMap;
+
import org.jnode.annotation.Internal;
import org.jnode.annotation.MagicPermission;
import org.jnode.assembler.x86.X86Constants;
@@ -48,6 +49,7 @@
import org.vmmagic.unboxed.Address;
import org.vmmagic.unboxed.Extent;
import org.vmmagic.unboxed.Offset;
+import org.vmmagic.unboxed.Word;
/**
* Architecture descriptor for the Intel X86 architecture.
@@ -245,6 +247,9 @@
this.bootProcessor = bootCpu;
bootCpu.setBootProcessor(true);
+ // Initialize HyperV
+ initializeHyperV();
+
final String cmdLine = VmSystem.getCmdLine();
if (cmdLine.contains("mp=no")) {
return;
@@ -466,4 +471,17 @@
return super.createMultiMediaSupport();
}
}
+
+ /**
+ * Identify ourselves in HyperV (when that is detected)
+ */
+ void initializeHyperV() {
+ final X86CpuID id = (X86CpuID) VmProcessor.current().getCPUID();
+ if (!id.detectHyperV())
+ return;
+ Unsafe.debug("Initializing HyperV");
+ long guestOsId = (0x29L << 48);
+ UnsafeX86.writeMSR(Word.fromIntZeroExtend(HyperV.HV_X64_MSR_GUEST_OS_ID), guestOsId);
+ Unsafe.debug("Initialized Hyper-V guest OS ID");
+ }
}
Modified: trunk/core/src/core/org/jnode/vm/x86/X86CpuID.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/x86/X86CpuID.java 2013-11-12 15:21:28 UTC (rev 5998)
+++ trunk/core/src/core/org/jnode/vm/x86/X86CpuID.java 2013-11-13 09:15:27 UTC (rev 5999)
@@ -194,23 +194,31 @@
}
X86CpuID id = new X86CpuID(data, brand);
-
- // Load hypervisor data
- if (id.hasHYPERVISOR()) {
- UnsafeX86.getCPUID(Word.fromIntZeroExtend(0x40000001), regs);
- if (regs[0] == 0x31237648) {
- // Found 'Hv#1' Hypervisor vendor neutral identification
- UnsafeX86.getCPUID(Word.fromIntZeroExtend(0x40000000), regs);
- final StringBuilder buf = new StringBuilder();
- intToString(buf, regs[1]); // ebx
- intToString(buf, regs[2]); // ecx
- intToString(buf, regs[3]); // edx
- id.hypervisorVendor = buf.toString().trim();
- }
- }
-
+ id.detectHyperV();
return id;
}
+
+ /**
+ * Try to detect if we're running in HyperV.
+ * @return true if we're running in HyperV, false otherwise.
+ */
+ public boolean detectHyperV() {
+ if (!hasHYPERVISOR())
+ return false;
+
+ int[] regs = new int[4];
+ UnsafeX86.getCPUID(Word.fromIntZeroExtend(0x40000001), regs);
+ if (regs[0] != 0x31237648)
+ return false;
+ // Found 'Hv#1' Hypervisor vendor neutral identification
+ UnsafeX86.getCPUID(Word.fromIntZeroExtend(0x40000000), regs);
+ final StringBuilder buf = new StringBuilder();
+ intToString(buf, regs[1]); // ebx
+ intToString(buf, regs[2]); // ecx
+ intToString(buf, regs[3]); // edx
+ hypervisorVendor = buf.toString().trim();
+ return true;
+ }
/**
* Processor vendor string
Modified: trunk/core/src/native/x86/syscall.asm
===================================================================
--- trunk/core/src/native/x86/syscall.asm 2013-11-12 15:21:28 UTC (rev 5998)
+++ trunk/core/src/native/x86/syscall.asm 2013-11-13 09:15:27 UTC (rev 5999)
@@ -25,6 +25,7 @@
DA sc_SyncMSRs
DA sc_SaveMSRs
DA sc_RestoreMSRs
+ DA sc_WriteMSR
sc_SyncMSRs:
mov ADI,CURRENTTHREAD
@@ -43,4 +44,11 @@
RESTORE_MSR_ARRAY [ADI+VmX86Thread_READWRITEMSRS_OFS]
RESTORE_MSR_ARRAY [ADI+VmX86Thread_WRITEONLYMSRS_OFS]
ret
+
+sc_WriteMSR:
+ mov ACX,GET_OLD_ECX
+ mov AAX,GET_OLD_EBX
+ mov ADX,GET_OLD_EDX
+ wrmsr
+ ret
\ No newline at end of file
Modified: trunk/core/src/native/x86/syscall.h
===================================================================
(Binary files differ)
Modified: trunk/core/src/native/x86/unsafex86.asm
===================================================================
--- trunk/core/src/native/x86/unsafex86.asm 2013-11-12 15:21:28 UTC (rev 5998)
+++ trunk/core/src/native/x86/unsafex86.asm 2013-11-13 09:15:27 UTC (rev 5999)
@@ -164,4 +164,33 @@
GLABEL Q53org5jnode2vm3x869UnsafeX8623restoreMSRs2e2829V
SYSCALL SC_RESTORE_MSRS
ret
-
\ No newline at end of file
+
+; /**
+; * Read a model specific register
+; */
+; @KernelSpace
+; static native long readMSR(Word index);
+GLABEL Q53org5jnode2vm3x869UnsafeX8623readMSR2e28Lorg2fvmmagic2funboxed2fWord3b29J
+ push ACX
+ mov ecx,[ASP+(2*SLOT_SIZE)] ; index
+ rdmsr
+ pop ACX
+ ret
+
+; /**
+; * Write a model specific register
+; */
+; @KernelSpace
+; static native void writeMSR(Word index, long value);
+GLABEL Q53org5jnode2vm3x869UnsafeX8623writeMSR2e28Lorg2fvmmagic2funboxed2fWord3bJ29V
+ push ACX
+ mov ecx,[ASP+(2*SLOT_SIZE)+8] ; index
+ mov edx,[ASP+(2*SLOT_SIZE)+4] ; value MSB
+ mov eax,[ASP+(2*SLOT_SIZE)+0] ; value LSB
+ push ABX
+ mov ABX,AAX
+ SYSCALL SC_WRITE_MSR
+ pop ABX
+ pop ACX
+ ret
+
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|