Bug#413858: archdetect: detect amd64 as a subarch of i386
Package: libdebian-installer4
Version: 0.49
Severity: wishlist
Tags: patch
With this patch, amd64 can be detected as a subarch of i386. e.g.
$ ./archdetect
i386/amd64
This can be useful to conditionalise install of stuff like libc6-amd64,
and possibly other things.
-- System Information:
Debian Release: 4.0
APT prefers testing
APT policy: (500, 'testing')
Architecture: amd64 (x86_64)
Shell: /bin/sh linked to /bin/bash
Kernel: Linux 2.6.18-4-amd64
Locale: LANG=ca_AD.UTF-8, LC_CTYPE=ca_AD.UTF-8 (charmap=UTF-8)
Versions of packages libdebian-installer4 depends on:
ii libc6 2.3.6.ds1-13 GNU C Library: Shared libraries
libdebian-installer4 recommends no packages.
-- no debconf information
Index: libdebian-installer/configure.ac
===================================================================
--- libdebian-installer/configure.ac (revision 45613)
+++ libdebian-installer/configure.ac (working copy)
@@ -71,6 +71,8 @@
if test -f "$srcdir/src/system/subarch-$DEB_HOST_ARCH_CPU-$DEB_HOST_ARCH_OS.c"; then
SUBARCH_SYSTEM="subarch-$DEB_HOST_ARCH_CPU-$DEB_HOST_ARCH_OS.lo"
+elif test -f "$srcdir/src/system/subarch-$DEB_HOST_ARCH_CPU.c"; then
+ SUBARCH_SYSTEM="subarch-$DEB_HOST_ARCH_CPU.lo"
else
SUBARCH_SYSTEM="subarch-generic.lo"
fi
Index: libdebian-installer/src/system/subarch-i386.c
===================================================================
--- libdebian-installer/src/system/subarch-i386.c (revision 0)
+++ libdebian-installer/src/system/subarch-i386.c (revision 0)
@@ -0,0 +1,80 @@
+#include <debian-installer/system/subarch.h>
+
+int check_64bit ();
+
+const char *di_system_subarch_analyze(void)
+{
+ return check_64bit () ? "amd64" : "generic";
+}
+
+/* This amd64 detection code is copied from win32-loader/cpuid/cpuid.c,
+ if you have to modify it, please keep it in sync. */
+
+/**********************************************************
+ stolen from linux/arch/i386/kernel/cpu/common.c
+ **********************************************************/
+
+/* Standard macro to see if a specific flag is changeable */
+static inline int
+flag_is_changeable_p (unsigned int flag)
+{
+ unsigned int f1, f2;
+ asm ("pushfl\n\t"
+ "pushfl\n\t"
+ "popl %0\n\t"
+ "movl %0,%1\n\t"
+ "xorl %2,%0\n\t"
+ "pushl %0\n\t"
+ "popfl\n\t"
+ "pushfl\n\t"
+ "popl %0\n\t"
+ "popfl\n\t"
+ : "=&r" (f1), "=&r" (f2)
+ :"ir" (flag));
+ return ((f1 ^ f2) & flag) != 0;
+}
+
+#ifndef X86_EFLAGS_ID
+#define X86_EFLAGS_ID 0x00200000 /* CPUID detection flag */
+#endif
+
+/**********************************************************
+ stolen from linux/include/asm-i386/processor.h
+ **********************************************************/
+
+static inline unsigned int
+cpuid_eax(unsigned int op)
+{
+ unsigned int eax;
+ __asm__("pushl %%ebx; cpuid; popl %%ebx": "=a" (eax): "0" (op): "cx", "dx");
+ return eax;
+}
+
+static inline unsigned int
+cpuid_edx (unsigned int op)
+{
+ unsigned int eax, edx;
+ __asm__ ("pushl %%ebx; cpuid; popl %%ebx": "=a" (eax), "=d" (edx): "0" (op): "cx");
+ return edx;
+}
+
+/**********************************************************
+ Based on specs from:
+ - http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/25481.pdf
+ - http://download.intel.com/design/Xeon/applnots/24161831.pdf
+ **********************************************************/
+
+int
+check_64bit ()
+{
+ /* probe for CPUID instruction */
+ if (!flag_is_changeable_p (X86_EFLAGS_ID))
+ return 0;
+
+ /* probe for 0x80000001-level CPUID support */
+ if (cpuid_eax (0x80000000) < 0x80000001)
+ return 0;
+
+ /* probe for 64-bit support */
+ return (cpuid_edx (0x80000001) & (1 << 29)) ? 1 : 0;
+}
Index: libdebian-installer/src/system/Makefile.am
===================================================================
--- libdebian-installer/src/system/Makefile.am (revision 45613)
+++ libdebian-installer/src/system/Makefile.am (working copy)
@@ -15,6 +15,7 @@
subarch-arm-linux.c \
subarch-armeb-linux.c \
subarch-armel-linux.c \
+ subarch-i386.c \
subarch-m68k-linux.c \
subarch-mips-linux.c \
subarch-mipsel-linux.c \
Reply to: