From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1J0Gdk-0003xm-Ip for mharc-grub-devel@gnu.org; Thu, 06 Dec 2007 08:19:44 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1J0Gdj-0003uk-9a for grub-devel@gnu.org; Thu, 06 Dec 2007 08:19:43 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1J0Gde-0003if-Eg for grub-devel@gnu.org; Thu, 06 Dec 2007 08:19:42 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J0Gde-0003iO-A9 for grub-devel@gnu.org; Thu, 06 Dec 2007 08:19:38 -0500 Received: from mail.gmx.net ([213.165.64.20]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1J0Gdd-00030q-Mh for grub-devel@gnu.org; Thu, 06 Dec 2007 08:19:38 -0500 Received: (qmail invoked by alias); 06 Dec 2007 13:19:35 -0000 Received: from m128b.studby.ntnu.no (EHLO m128b.studby.ntnu.no) [129.241.129.128] by mail.gmx.net (mp006) with SMTP; 06 Dec 2007 14:19:35 +0100 X-Authenticated: #1421993 X-Provags-ID: V01U2FsdGVkX19SlIY1Ml1SwJaMlAoCpESE5CX1saEx2Jtzajc4wx ft0lBacGLVbAHT From: Martin =?iso-8859-1?q?Haa=DF?= To: grub-devel@gnu.org User-Agent: KMail/1.9.5 MIME-Version: 1.0 Date: Thu, 6 Dec 2007 14:19:25 +0100 Content-Type: Multipart/Mixed; boundary="Boundary-00=_db/VH8gV2XCldiq" Message-Id: <200712061419.25555.> X-Y-GMX-Trusted: 0 X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Subject: New module to detect vmware X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Dec 2007 13:19:43 -0000 --Boundary-00=_db/VH8gV2XCldiq Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi all! I tried to build a module to detect vmware. Attached is the module and a test grub.cfg It is basically working though I have some questions: can i use the return value of the function (e.g. vmware_detect) to give back a value or am I supposed to always return something like GRUB_ERR_NONE? is there a script to add a module to the makefile or do I have to copy/paste it? if I use this: if vmware_detect = 1; then set foo=1 else set foo=0 fi I get syntax error and unknown command in an infinite loop is this expected? It should not be a problem with my module, as it also happend while testing a environment variable. So, is it a problem with my if-syntax? greetings Martin PS:*ahem* I tested against 1.95+20070604 of the debian tree. I will test against current cvs as soon as possible / as soon as someone tells me how to automate the makefile updating --Boundary-00=_db/VH8gV2XCldiq Content-Type: text/plain; charset="us-ascii"; name="grub.cfg" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="grub.cfg" insmod vmware-detect vmware_detect set default=2 if vmware = 0; then set default=1 else set default=0 fi menuentry "nummer0" { linux (hd0,6)/boot/vmlinuz } menuentry "nummer1" { linux (hd0,6)/boot/vmlinuz } --Boundary-00=_db/VH8gV2XCldiq Content-Type: text/x-csrc; charset="us-ascii"; name="vmware-detect.c" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="vmware-detect.c" /* vmware-detect.c - module to detect vmware */ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 2007 Martin Haa=C3=9F * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * VMWARE detection code taken from=20 * http://chitchat.at.infoseek.co.jp/vmware/backdoor.html */ #include #include #include #include #include #include //this gives a warning, but looks more fancy than VMWARE_MAGIC 0x564D5868 #define VMWARE_MAGIC 'VMXh' #define VMWARE_COMMAND_GETVERSION 0x000a #define VMWARE_PORTNUMBER 0x5658=20 static void vmware_getversion( unsigned int *version_number, unsigned int *= magic_number,=20 unsigned int *product_type)=20 { grub_dprintf ("vmware","requesting vmware version\n");=20 =20 //reference for this is given at top of file, //no further magic involved than inline asm __asm__("inl %%dx, %%eax\n\t" //outputs : "=3Da" (*version_number), "=3Db" (*magic_number), "=3Dc" (*product_type) //inputs : "a" (VMWARE_MAGIC), "b" (0), "c" (VMWARE_COMMAND_GETVERSION), "d" (VMWARE_PORTNUMBER) ); grub_dprintf("vmware","magic:0x%x, version:0x%x, product 0x%x\n",*magic_n= umber, *version_number, *product_type); } static grub_err_t grub_cmd_vmwaredetect (struct grub_arg_list *state __attribute__ ((unused)), int argc __attribute__ ((unused)), char **args __attribute__ ((unused))) { unsigned int version_number;=20 unsigned int magic_number; unsigned int product_type; vmware_getversion(&version_number,&magic_number,&product_type); if (magic_number =3D=3D VMWARE_MAGIC) { grub_dprintf("vmware","inside in a vmware\n"); grub_env_set("vmware","1"); return 1; } else { grub_dprintf("vmware","not in a vmware\n"); grub_env_set("vmware","0"); return 0; } } static grub_err_t grub_cmd_vmwareversion (struct grub_arg_list *state __attribute__ ((unu= sed)), int argc __attribute__ ((unused)), char **args __attribute__ ((unused))) { unsigned int version_number;=20 unsigned int magic_number; unsigned int product_type; vmware_getversion(&version_number,&magic_number,&product_type); =20 if (magic_number =3D=3D VMWARE_MAGIC) { grub_dprintf("vmware","version number 0x%x\n",version_number); return version_number; } else { grub_dprintf("vmware","not in a vmware\n"); return 0; } } static grub_err_t grub_cmd_vmwaretype (struct grub_arg_list *state __attribute__ ((unused= )), int argc __attribute__ ((unused)), char **args __attribute__ ((unused))) { unsigned int version_number;=20 unsigned int magic_number; unsigned int product_type; vmware_getversion(&version_number,&magic_number,&product_type); if (magic_number =3D=3D VMWARE_MAGIC) { grub_dprintf("vmware","product type 0x%x\n",product_type); return product_type; } else { grub_dprintf("vmware","not in a vmware\n"); return 0; } } GRUB_MOD_INIT(vmwaredetect) { (void)mod; /* To stop warning. */ grub_register_command ("vmware_detect", grub_cmd_vmwaredetect, GRUB_COMMA= ND_FLAG_BOTH, "vmware_detect", "returns 1 if inside vmware, 0 ot= herwise. " "set debug=3D\"vmware\" to see more", 0); grub_register_command ("vmware_version", grub_cmd_vmwareversion, GRUB_COM= MAND_FLAG_BOTH, "vmware_version", "returns version number(always 6= ?)", 0); grub_register_command ("vmware_type", grub_cmd_vmwaretype, GRUB_COMMAND_F= LAG_BOTH, "vmware_type", "returns product type", 0); } GRUB_MOD_FINI(vmwaredetect) { grub_unregister_command ("vmware_detect"); grub_unregister_command ("vmware_version"); grub_unregister_command ("vmware_type"); } --Boundary-00=_db/VH8gV2XCldiq--