Would anyone object if I add a ficl word to detect whether we're booting
from a vmware virtual machine? I find it extremely useful when I'm running
FreeBSD as a guest under NT. Because it is a dual cpu box, I can't use a
single kernel to boot both directly or inside the virtual machine. With this
new word, I can determine which kernel to use in the loader script, saving
me the trouble to unload and reload a new kernel each time I reboot.

Here's the patch to the boot loader,

Index: boot/ficl/ficl.h
===================================================================
RCS file: /home/ncvs/src/sys/boot/ficl/ficl.h,v
retrieving revision 1.14
diff -u -r1.14 ficl.h
--- boot/ficl/ficl.h    2000/06/01 18:10:43     1.14
+++ boot/ficl/ficl.h    2000/06/07 18:18:38
@@ -860,6 +860,7 @@
 #if defined(__i386__) && !defined(TESTMAIN)
 extern void ficlOutb(FICL_VM *pVM);
 extern void ficlInb(FICL_VM *pVM);
+extern void vmware(FICL_VM *pVM);
 #endif
 
 #ifdef __cplusplus
Index: boot/ficl/words.c
===================================================================
RCS file: /home/ncvs/src/sys/boot/ficl/words.c,v
retrieving revision 1.27
diff -u -r1.27 words.c
--- boot/ficl/words.c   2000/06/01 18:10:43     1.27
+++ boot/ficl/words.c   2000/06/07 18:19:13
@@ -4800,6 +4800,7 @@
 #ifdef __i386__
     dictAppendWord(dp, "outb",      ficlOutb,       FW_DEFAULT);
     dictAppendWord(dp, "inb",       ficlInb,        FW_DEFAULT);
+    dictAppendWord(dp, "vmware",    vmware,         FW_DEFAULT);
 #endif
 #endif
 
Index: boot/ficl/i386/sysdep.c
===================================================================
RCS file: /home/ncvs/src/sys/boot/ficl/i386/sysdep.c,v
retrieving revision 1.7
diff -u -r1.7 sysdep.c
--- boot/ficl/i386/sysdep.c     1999/09/29 04:43:07     1.7
+++ boot/ficl/i386/sysdep.c     2000/06/07 18:18:13
@@ -111,6 +111,26 @@
        c=inb(port);
        stackPushINT(pVM->pStack,c);
 }
+
+/*
+ * vmware ( -- version )
+ * Get vmware version.
+ */
+void
+vmware(FICL_VM *pVM)
+{
+        int version, magic = 0;
+
+#define        VMWARE_MAGIC    0x564d5868
+#define        VMWARE_PORT     0x5658
+
+       __asm __volatile("inl %%dx, %%eax"
+           : "=a" (version), "=b" (magic)
+           : "0" (VMWARE_MAGIC), "d" (VMWARE_PORT), "c" (0xa));
+       if (magic != VMWARE_MAGIC)
+               version = -1;
+       stackPushINT(pVM->pStack, version);
+}
 #endif
 #endif
 

To use this feature, you first create a file /boot/vmware.4th:

        : vmware-conf
                vmware dup 0> if
                        ." VMware version " . cr
                        ." Loading /boot/vmware.conf..." cr
                        s" /boot/vmware.conf" read-conf
                else
                        drop
                then
        ;

then create /boot/vmware.conf which sets the kernel to use:

        kernel="/kernel.VMWARE"

finally, change your /boot/loader.rc to

        include /boot/loader.4th
        include /boot/vmware.4th
        initialize drop
        vmware-conf
        boot-conf
        check-password

-lq


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message

Reply via email to