[RFC] libx86 - AMD64 fix-ups

TJ ubuntu at tjworld.net
Fri Sep 21 21:11:47 BST 2007


I've made some fix-ups to the libx86 library to ensure a clean build
without warnings on AMD64 but not being massively familiar with the code
hoped some others could cast their eyes over it.

In building the 64-bit version I encountered a series of compiler
warnings. The same warnings are in the buildd logs for the amd64
package.

https://edge.launchpad.net/ubuntu/+source/libx86/0.99-1.2ubuntu1/+build/375499

The issue is sizes of data-types, and the 64-bit build using the wrong
sizes in some places. 

My fix-ups solve the 64-bit build warnings and from what I can see fix
the underlying issues that would be caused by unintended 64-bit
conversion, although I may be confused, hence this RFC.

In particular they deal with:

* 32-bit integers being cast to 64-pointers
* 32-bits wide define made 64-bits wide as a result of unsigned long
* a 64-bit pointer value assigned to a 16-bit (SS) register

The patch is in-line at the end of this email. 

Thanks for checking this.

TJ (IntuitiveNipple)


== Background ==

I'm developing a user-space application that can enable Intel VT
features (hardware virtualisation) on PCs where the BIOS does not
provide the means to enable them, thus allowing kvm to be used.

The tool is designed to work with Phoenix BIOSs and began life as a
means to enable VT on various Sony Vaio models where Sony do not provide
the option to enable VT, and lock MSR 0x3A so it can't be done during
boot.

The tool has to modify NVRAM. To do that safely it needs to make calls
into the BIOS to have an NVRAM 'Token' value changed. It makes calls via
the Phoenix BIOS dispatchManager() function.

NVRAM 'Token' numbers change on a per-BIOS-version basis so the tool has
to do some initial parsing of the BIOS via /dev/mem to identify the
correct Token number to change. In other words, the R0200J3 BIOS uses
Token 0x0195 whereas the R0092N0 uses 0x0399 for the VT flag.

Having proved the concept successfully I'm now attempting to make the
tool as generic as possible. One issue I've had to address is
cross-architecture support since it needs to work on 64-bit systems. 

I found Mathew Garrett's libx86 package. It combines x86emu and LRMI,
meaning it has a use for my tool as well as it's original target,
vbetool.


=== patch ===
diff -aur libx86-0.99.orig/thunk.c libx86-0.99/thunk.c
--- libx86-0.99.orig/thunk.c	2006-10-30 20:42:15.000000000 +0000
+++ libx86-0.99/thunk.c	2007-09-21 19:33:35.000000000 +0100
@@ -25,7 +25,10 @@
 #include "lrmi.h"
 #include "x86-common.h"
 
+/* 2007-09-21 TJ commented out to prevent compiler warning
+ *  "DEBUG" redefined 
 #define DEBUG
+*/
 #define ALLOC_ENTRIES(x) (V_RAM - 1)
 #define TRUE 1
 #define FALSE 0
@@ -163,7 +166,9 @@
 	 * Allocate a 64k stack.
 	 */
 	stack = LRMI_alloc_real(64 * 1024);
-	X86_SS = (unsigned int) stack >> 4;
+	/* 2007-09-21 TJ fixup using (u16)(unsigned long...) to prevent AMD64 
+	 * compiler warning "cast from pointer to integer of different size" */
+	X86_SS = (u16) ((unsigned long) stack >> 4);
 	X86_ESP = 0xFFF9;
 	memset (stack, 0, 64*1024);
 
@@ -195,7 +200,9 @@
         if (registers->ss != 0) {
                 X86_SS = registers->ss;
         } else {
-	        X86_SS = (unsigned int) stack >> 4;
+        	/* 2007-09-21 TJ fixup using (unsigned long) to prevent AMD64 compiler
+        	 * warning "cast from pointer to integer of different size" */
+	        X86_SS = (unsigned long) stack >> 4;
 	}
 
 	if (registers->ds != 0) { 
diff -aur libx86-0.99.orig/x86-common.c libx86-0.99/x86-common.c
--- libx86-0.99.orig/x86-common.c	2006-09-07 23:44:27.000000000 +0100
+++ libx86-0.99/x86-common.c	2007-09-21 17:51:54.000000000 +0100
@@ -190,14 +190,18 @@
 static inline unsigned int
 get_int_seg(int i)
 {
-	return *(unsigned short *)(i * 4 + 2);
+	/* 2007-09-21 TJ fixup using (unsigned long) to prevent AMD64 compiler
+	 * warning "cast to pointer from integer of different size" */
+	return *(unsigned short *)((unsigned long)i * 4 + 2);
 }
 

 static inline unsigned int
 get_int_off(int i)
 {
-	return *(unsigned short *)(i * 4);
+	/* 2007-09-21 TJ fixup using (unsigned long) to prevent AMD64 compiler
+	 * warning "cast to pointer from integer of different size" */
+	return *(unsigned short *)((unsigned long)i * 4);
 }
 
 int LRMI_common_init(void)
diff -aur libx86-0.99.orig/x86emu/include/xf86int10.h libx86-0.99/x86emu/include/xf86int10.h
--- libx86-0.99.orig/x86emu/include/xf86int10.h	2006-09-07 23:44:28.000000000 +0100
+++ libx86-0.99/x86emu/include/xf86int10.h	2007-09-21 18:26:37.000000000 +0100
@@ -18,7 +18,9 @@
 
 #define CARD8  unsigned char
 #define CARD16 unsigned short
-#define CARD32 unsigned long
+/* 2007-09-21 TJ fixup using (unsigned int) to prevent AMD64 compiler
+ * warning "initialization from incompatible pointer type" */
+#define CARD32 unsigned int
 #define pointer void *
 #define IOADDRESS void *
 #define Bool int




More information about the ubuntu-devel mailing list