Hi.

I've been working on porting compiler-rt/clang's support for address
sanitization (asan) to FreeBSD.  So far I have it building and it
appears to work properly, however the build system expects to be able
to build 32 bit binaries on amd64.

amd64 doesn't include i386's machine/foo headers.  The included patch
is my proposed solution:

Add i386 headers to /usr/include/i386, and in machine/foo.h, check if
it's a 32 bit build and include the appropriate header from i386.

For example machine/ucontext.h will include i386/ucontext.h if
compiled with -m32.

Thoughts?

If anyone's curious about the compiler_rt port, I have it at
github.com/dannomac/compiler-rt on the branch named freebsd.

Dan
diff --git a/include/Makefile b/include/Makefile
index d2f6d7f..8e29a35 100644
--- a/include/Makefile
+++ b/include/Makefile
@@ -125,6 +125,9 @@ _MARCHS=	${MACHINE_CPUARCH}
 .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
 _MARCHS+=	x86
 .endif
+.if ${MACHINE_CPUARCH} == "amd64"
+_MARCHS+=	i386
+.endif
 
 .include <bsd.prog.mk>
 
diff --git a/sys/amd64/include/acpica_machdep.h b/sys/amd64/include/acpica_machdep.h
index 9943af7..393cd2b 100644
--- a/sys/amd64/include/acpica_machdep.h
+++ b/sys/amd64/include/acpica_machdep.h
@@ -33,6 +33,12 @@
  *
  *****************************************************************************/
 
+#ifdef __i386__
+
+#include <i386/acpica_machdep.h>
+
+#else /* __i386__ */
+
 #ifndef __ACPICA_MACHDEP_H__
 #define	__ACPICA_MACHDEP_H__
 
@@ -82,3 +88,5 @@ void	acpi_unmap_table(void *table);
 vm_paddr_t acpi_find_table(const char *sig);
 
 #endif /* __ACPICA_MACHDEP_H__ */
+
+#endif /* __i386__ */
diff --git a/sys/amd64/include/apicvar.h b/sys/amd64/include/apicvar.h
index ae2f5b9..3369fa1 100644
--- a/sys/amd64/include/apicvar.h
+++ b/sys/amd64/include/apicvar.h
@@ -29,8 +29,10 @@
  * $FreeBSD$
  */
 
-#ifndef _MACHINE_APICVAR_H_
-#define _MACHINE_APICVAR_H_
+#ifndef _AMD64_APICVAR_H_
+#define _AMD64_APICVAR_H_
+
+#ifdef __x86_64__
 
 #include <machine/segments.h>
 
@@ -229,4 +231,10 @@ void	lapic_set_tpr(u_int vector);
 void	lapic_setup(int boot);
 
 #endif /* !LOCORE */
-#endif /* _MACHINE_APICVAR_H_ */
+
+#else /* __x86_64__ */
+
+#include <i386/apicvar.h>
+
+#endif /* __x86_64__ */
+#endif /* _AMD64_APICVAR_H_ */
diff --git a/sys/amd64/include/asm.h b/sys/amd64/include/asm.h
index 7efd642..b1dd8ba 100644
--- a/sys/amd64/include/asm.h
+++ b/sys/amd64/include/asm.h
@@ -33,8 +33,10 @@
  * $FreeBSD$
  */
 
-#ifndef _MACHINE_ASM_H_
-#define	_MACHINE_ASM_H_
+#ifndef _AMD64_ASM_H_
+#define	_AMD64_ASM_H_
+
+#ifdef __x86_64__
 
 #include <sys/cdefs.h>
 
@@ -88,4 +90,9 @@
 #define __FBSDID(s)	/* nothing */
 #endif /* not lint and not STRIP_FBSDID */
 
-#endif /* !_MACHINE_ASM_H_ */
+#else /* __x86_64__ */
+
+#include <i386/asm.h>
+
+#endif /* __x86_64__ */
+#endif /* !_AMD64_ASM_H_ */
diff --git a/sys/amd64/include/asmacros.h b/sys/amd64/include/asmacros.h
index 1fb592a..385e16e 100644
--- a/sys/amd64/include/asmacros.h
+++ b/sys/amd64/include/asmacros.h
@@ -29,8 +29,10 @@
  * $FreeBSD$
  */
 
-#ifndef _MACHINE_ASMACROS_H_
-#define _MACHINE_ASMACROS_H_
+#ifndef _AMD64_ASMACROS_H_
+#define _AMD64_ASMACROS_H_
+
+#ifdef __x86_64__
 
 #include <sys/cdefs.h>
 
@@ -201,4 +203,9 @@
 
 #endif /* LOCORE */
 
-#endif /* !_MACHINE_ASMACROS_H_ */
+#else
+
+#include <i386/asmacros.h>
+
+#endif /* __x86_64__ */
+#endif /* !_AMD64_ASMACROS_H_ */
diff --git a/sys/amd64/include/atomic.h b/sys/amd64/include/atomic.h
index 99a94b7..31fd8ee 100644
--- a/sys/amd64/include/atomic.h
+++ b/sys/amd64/include/atomic.h
@@ -25,8 +25,10 @@
  *
  * $FreeBSD$
  */
-#ifndef _MACHINE_ATOMIC_H_
-#define	_MACHINE_ATOMIC_H_
+#ifndef _AMD64_ATOMIC_H_
+#define	_AMD64_ATOMIC_H_
+
+#ifdef __x86_64__
 
 #ifndef _SYS_CDEFS_H_
 #error this file needs sys/cdefs.h as a prerequisite
@@ -480,4 +482,9 @@ u_long	atomic_readandclear_long(volatile u_long *addr);
 
 #endif /* !WANT_FUNCTIONS */
 
-#endif /* !_MACHINE_ATOMIC_H_ */
+#else /* __x86_64__ */
+
+#include <i386/atomic.h>
+
+#endif /* __x86_64__ */
+#endif /* !_AMD64_ATOMIC_H_ */
diff --git a/sys/amd64/include/clock.h b/sys/amd64/include/clock.h
index d2602d8..9f0db6e 100644
--- a/sys/amd64/include/clock.h
+++ b/sys/amd64/include/clock.h
@@ -6,8 +6,10 @@
  * $FreeBSD$
  */
 
-#ifndef _MACHINE_CLOCK_H_
-#define	_MACHINE_CLOCK_H_
+#ifndef _AMD64_CLOCK_H_
+#define	_AMD64_CLOCK_H_
+
+#ifdef __x86_64__
 
 #ifdef _KERNEL
 /*
@@ -37,4 +39,9 @@ void	timer_spkr_setfreq(int freq);
 
 #endif /* _KERNEL */
 
-#endif /* !_MACHINE_CLOCK_H_ */
+#else /* __x86_64__ */
+
+#include <i386/clock.h>
+
+#endif /* __x86_64__ */
+#endif /* !_AMD64_CLOCK_H_ */
diff --git a/sys/amd64/include/cpu.h b/sys/amd64/include/cpu.h
index 1c2871f..0cfcb03 100644
--- a/sys/amd64/include/cpu.h
+++ b/sys/amd64/include/cpu.h
@@ -33,8 +33,10 @@
  * $FreeBSD$
  */
 
-#ifndef _MACHINE_CPU_H_
-#define	_MACHINE_CPU_H_
+#ifndef _AMD64_CPU_H_
+#define	_AMD64_CPU_H_
+
+#ifdef __x86_64__
 
 /*
  * Definitions unique to i386 cpu support.
@@ -75,4 +77,9 @@ get_cyclecount(void)
 
 #endif
 
-#endif /* !_MACHINE_CPU_H_ */
+#else /* __x86_64__ */
+
+#include <i386/cpu.h>
+
+#endif /* __x86_64__ */
+#endif /* !_AMD64_CPU_H_ */
diff --git a/sys/amd64/include/cpufunc.h b/sys/amd64/include/cpufunc.h
index 881fcd2..baf927e 100644
--- a/sys/amd64/include/cpufunc.h
+++ b/sys/amd64/include/cpufunc.h
@@ -36,13 +36,15 @@
  * used in preference to this.
  */
 
-#ifndef _MACHINE_CPUFUNC_H_
-#define	_MACHINE_CPUFUNC_H_
+#ifndef _AMD64_CPUFUNC_H_
+#define	_AMD64_CPUFUNC_H_
 
 #ifndef _SYS_CDEFS_H_
 #error this file needs sys/cdefs.h as a prerequisite
 #endif
 
+#ifdef __x86_64__
+
 struct region_descriptor;
 
 #define readb(va)	(*(volatile uint8_t *) (va))
@@ -788,4 +790,9 @@ int	rdmsr_safe(u_int msr, uint64_t *val);
 int	wrmsr_safe(u_int msr, uint64_t newval);
 #endif
 
-#endif /* !_MACHINE_CPUFUNC_H_ */
+#else /* __x86_64__ */
+
+#include <i386/cpufunc.h>
+
+#endif /* __x86_64__ */
+#endif /* !_AMD64_CPUFUNC_H_ */
diff --git a/sys/amd64/include/cputypes.h b/sys/amd64/include/cputypes.h
index eeec4e0..e2f23ec 100644
--- a/sys/amd64/include/cputypes.h
+++ b/sys/amd64/include/cputypes.h
@@ -27,8 +27,10 @@
  * $FreeBSD$
  */
 
-#ifndef _MACHINE_CPUTYPES_H_
-#define	_MACHINE_CPUTYPES_H_
+#ifndef _AMD64_CPUTYPES_H_
+#define	_AMD64_CPUTYPES_H_
+
+#ifdef __x86_64__
 
 /*
  * Classes of processor.
@@ -56,4 +58,9 @@ extern int	cpu;
 extern int	cpu_class;
 #endif
 
-#endif /* !_MACHINE_CPUTYPES_H_ */
+#else /* __x86_64__ */
+
+#include <i386/cputypes.h>
+
+#endif /* __x86_64__ */
+#endif /* !_AMD64_CPUTYPES_H_ */
diff --git a/sys/amd64/include/db_machdep.h b/sys/amd64/include/db_machdep.h
index 29e385e..ae8e5d6 100644
--- a/sys/amd64/include/db_machdep.h
+++ b/sys/amd64/include/db_machdep.h
@@ -26,8 +26,10 @@
  * $FreeBSD$
  */
 
-#ifndef _MACHINE_DB_MACHDEP_H_
-#define	_MACHINE_DB_MACHDEP_H_
+#ifndef _AMD64_DB_MACHDEP_H_
+#define	_AMD64_DB_MACHDEP_H_
+
+#ifdef __x86_64__
 
 #include <machine/frame.h>
 #include <machine/trap.h>
@@ -91,4 +93,9 @@ do {						\
 #define	DB_SMALL_VALUE_MAX	0x7fffffff
 #define	DB_SMALL_VALUE_MIN	(-0x400001)
 
-#endif /* !_MACHINE_DB_MACHDEP_H_ */
+#else /* __x86_64__ */
+
+#include <i386/db_machdep.h>
+
+#endif /* __x86_64__ */
+#endif /* !_AMD64_DB_MACHDEP_H_ */
diff --git a/sys/amd64/include/elf.h b/sys/amd64/include/elf.h
index d69c6b4..dee410e 100644
--- a/sys/amd64/include/elf.h
+++ b/sys/amd64/include/elf.h
@@ -26,8 +26,10 @@
  * $FreeBSD$
  */
 
-#ifndef _MACHINE_ELF_H_
-#define	_MACHINE_ELF_H_ 1
+#ifndef _AMD64_ELF_H_
+#define	_AMD64_ELF_H_ 1
+
+#ifdef __x86_64__
 
 /*
  * ELF definitions for the AMD64 architecture.
@@ -44,7 +46,7 @@
 #define	ELF_ARCH	EM_X86_64
 #define	ELF_ARCH32	EM_386
 
-#define	ELF_MACHINE_OK(x) ((x) == EM_X86_64)
+#define	ELF_AMD64_OK(x) ((x) == EM_X86_64)
 
 /*
  * Auxiliary vector entries for passing information to the interpreter.
@@ -121,4 +123,9 @@ __ElfType(Auxinfo);
 #define	ET_DYN_LOAD_ADDR 0x01021000
 #endif
 
-#endif /* !_MACHINE_ELF_H_ */
+#else /* __x86_64__ */
+
+#include <i386/elf.h>
+
+#endif /* __x86_64__ */
+#endif /* !_AMD64_ELF_H_ */
diff --git a/sys/amd64/include/exec.h b/sys/amd64/include/exec.h
index 8d07887..0a31c95 100644
--- a/sys/amd64/include/exec.h
+++ b/sys/amd64/include/exec.h
@@ -30,9 +30,16 @@
  * $FreeBSD$
  */
 
-#ifndef	_MACHINE_EXEC_H_
-#define	_MACHINE_EXEC_H_
+#ifndef	_AMD64_EXEC_H_
+#define	_AMD64_EXEC_H_
+
+#ifdef __x86_64__
 
 #define	__LDPGSZ	4096
 
-#endif /* !_MACHINE_EXEC_H_ */
+#else /* __x86_64__ */
+
+#include <i386/exec.h>
+
+#endif /* __x86_64__ */
+#endif /* !_AMD64_EXEC_H_ */
diff --git a/sys/amd64/include/fpu.h b/sys/amd64/include/fpu.h
index 7d0f0ea..7d5318a 100644
--- a/sys/amd64/include/fpu.h
+++ b/sys/amd64/include/fpu.h
@@ -38,8 +38,8 @@
  * W. Jolitz 1/90
  */
 
-#ifndef _MACHINE_FPU_H_
-#define	_MACHINE_FPU_H_
+#ifndef _AMD64_FPU_H_
+#define	_AMD64_FPU_H_
 
 #include <x86/fpu.h>
 
@@ -81,4 +81,4 @@ int	is_fpu_kern_thread(u_int flags);
 
 #endif
 
-#endif /* !_MACHINE_FPU_H_ */
+#endif /* !_AMD64_FPU_H_ */
diff --git a/sys/amd64/include/frame.h b/sys/amd64/include/frame.h
index e171407..e9fb3d8 100644
--- a/sys/amd64/include/frame.h
+++ b/sys/amd64/include/frame.h
@@ -34,8 +34,10 @@
  * $FreeBSD$
  */
 
-#ifndef _MACHINE_FRAME_H_
-#define _MACHINE_FRAME_H_ 1
+#ifndef _AMD64_FRAME_H_
+#define _AMD64_FRAME_H_ 1
+
+#ifdef __x86_64__
 
 /*
  * System stack frames.
@@ -84,4 +86,9 @@ struct trapframe {
 #define	TF_HASBASES	0x2
 #define	TF_HASFPXSTATE	0x4
 
-#endif /* _MACHINE_FRAME_H_ */
+#else /* __x86_64__ */
+
+#include <i386/frame.h>
+
+#endif /* __x86_64__ */
+#endif /* _AMD64_FRAME_H_ */
diff --git a/sys/amd64/include/gdb_machdep.h b/sys/amd64/include/gdb_machdep.h
index d8c25b9..f1274ca 100644
--- a/sys/amd64/include/gdb_machdep.h
+++ b/sys/amd64/include/gdb_machdep.h
@@ -26,8 +26,10 @@
  * $FreeBSD$
  */
 
-#ifndef _MACHINE_GDB_MACHDEP_H_
-#define	_MACHINE_GDB_MACHDEP_H_
+#ifndef _AMD64_GDB_MACHDEP_H_
+#define	_AMD64_GDB_MACHDEP_H_
+
+#ifdef __x86_64__
 
 #define	GDB_BUFSZ	(GDB_NREGS * 16)
 #define	GDB_NREGS	56
@@ -49,4 +51,9 @@ void *gdb_cpu_getreg(int, size_t *);
 void gdb_cpu_setreg(int, void *);
 int gdb_cpu_signal(int, int);
 
-#endif /* !_MACHINE_GDB_MACHDEP_H_ */
+#else /* __x86_64__ */
+
+#include <i386/gdb_machdep.h>
+
+#endif /* __x86_64__ */
+#endif /* !_AMD64_GDB_MACHDEP_H_ */
diff --git a/sys/amd64/include/ieeefp.h b/sys/amd64/include/ieeefp.h
index a403660..33789f9 100644
--- a/sys/amd64/include/ieeefp.h
+++ b/sys/amd64/include/ieeefp.h
@@ -35,8 +35,8 @@
  * $FreeBSD$
  */
 
-#ifndef _MACHINE_IEEEFP_H_
-#define _MACHINE_IEEEFP_H_
+#ifndef _AMD64_IEEEFP_H_
+#define _AMD64_IEEEFP_H_
 
 /*
  * Deprecated historical FPU control interface
@@ -49,6 +49,8 @@
 #error this file needs sys/cdefs.h as a prerequisite
 #endif
 
+#ifdef __x86_64__
+
 /*
  * Rounding modes.
  */
@@ -305,4 +307,9 @@ __END_DECLS
 
 #endif /* !__IEEEFP_NOINLINES__ && __GNUCLIKE_ASM */
 
-#endif /* !_MACHINE_IEEEFP_H_ */
+#else /* __x86_64__ */
+
+#include <i386/ieeefp.h>
+
+#endif
+#endif /* !_AMD64_IEEEFP_H_ */
diff --git a/sys/amd64/include/in_cksum.h b/sys/amd64/include/in_cksum.h
index 156035e..59d209d 100644
--- a/sys/amd64/include/in_cksum.h
+++ b/sys/amd64/include/in_cksum.h
@@ -32,13 +32,15 @@
  * $FreeBSD$
  */
 
-#ifndef _MACHINE_IN_CKSUM_H_
-#define	_MACHINE_IN_CKSUM_H_	1
+#ifndef _AMD64_IN_CKSUM_H_
+#define	_AMD64_IN_CKSUM_H_	1
 
 #ifndef _SYS_CDEFS_H_
 #error this file needs sys/cdefs.h as a prerequisite
 #endif
 
+#ifdef __x86_64__
+
 #include <sys/cdefs.h>
 
 #define in_cksum(m, len)	in_cksum_skip(m, len, 0)
@@ -81,4 +83,9 @@ u_short	in_pseudo(u_int sum, u_int b, u_int c);
 u_short	in_cksum_skip(struct mbuf *m, int len, int skip);
 #endif
 
-#endif /* _MACHINE_IN_CKSUM_H_ */
+#else /* __x86_64__ */
+
+#include <i386/in_cksum.h>
+
+#endif /* __x86_64__ */
+#endif /* _AMD64_IN_CKSUM_H_ */
diff --git a/sys/amd64/include/intr_machdep.h b/sys/amd64/include/intr_machdep.h
index 9d066b1..0fbafe2 100644
--- a/sys/amd64/include/intr_machdep.h
+++ b/sys/amd64/include/intr_machdep.h
@@ -26,8 +26,14 @@
  * $FreeBSD$
  */
 
-#ifndef __MACHINE_INTR_MACHDEP_H__
-#define	__MACHINE_INTR_MACHDEP_H__
+#ifndef __AMD64_INTR_MACHDEP_H__
+#define	__AMD64_INTR_MACHDEP_H__
+
+#ifndef __x86_64__
+
+#include <i386/intr_machdep.h>
+
+#else
 
 #ifdef _KERNEL
 
@@ -169,4 +175,5 @@ int	msix_release(int irq);
 
 #endif	/* !LOCORE */
 #endif	/* _KERNEL */
-#endif	/* !__MACHINE_INTR_MACHDEP_H__ */
+#endif	/* !__x86_64__ */
+#endif	/* !__AMD64_INTR_MACHDEP_H__ */
diff --git a/sys/amd64/include/kdb.h b/sys/amd64/include/kdb.h
index 56d2018..2da448d 100644
--- a/sys/amd64/include/kdb.h
+++ b/sys/amd64/include/kdb.h
@@ -26,6 +26,12 @@
  * $FreeBSD$
  */
 
+#ifdef __i386__
+
+#include <i386/kdb.h>
+
+#else
+
 #ifndef _MACHINE_KDB_H_
 #define _MACHINE_KDB_H_
 
@@ -57,3 +63,4 @@ kdb_cpu_trap(int type, int code)
 }
 
 #endif /* _MACHINE_KDB_H_ */
+#endif /* __i386__ */
diff --git a/sys/amd64/include/md_var.h b/sys/amd64/include/md_var.h
index ff322bb..c4765ea 100644
--- a/sys/amd64/include/md_var.h
+++ b/sys/amd64/include/md_var.h
@@ -29,6 +29,12 @@
  * $FreeBSD$
  */
 
+#ifndef __x86_64__
+
+#include <i386/md_var.h>
+
+#else
+
 #ifndef _MACHINE_MD_VAR_H_
 #define	_MACHINE_MD_VAR_H_
 
@@ -118,3 +124,4 @@ struct savefpu *get_pcb_user_save_pcb(struct pcb *pcb);
 struct pcb *get_pcb_td(struct thread *td);
 
 #endif /* !_MACHINE_MD_VAR_H_ */
+#endif /* !__x86_64__ */
diff --git a/sys/amd64/include/minidump.h b/sys/amd64/include/minidump.h
index 2ac529c..ea519ba 100644
--- a/sys/amd64/include/minidump.h
+++ b/sys/amd64/include/minidump.h
@@ -26,6 +26,12 @@
  * $FreeBSD$
  */
 
+#ifndef __x86_64__
+
+#include <i386/minidump.h>
+
+#else
+
 #ifndef	_MACHINE_MINIDUMP_H_
 #define	_MACHINE_MINIDUMP_H_ 1
 
@@ -44,3 +50,4 @@ struct minidumphdr {
 };
 
 #endif /* _MACHINE_MINIDUMP_H_ */
+#endif /* !__x86_64__ */
diff --git a/sys/amd64/include/param.h b/sys/amd64/include/param.h
index 9ddcf68..c464af4 100644
--- a/sys/amd64/include/param.h
+++ b/sys/amd64/include/param.h
@@ -40,8 +40,11 @@
  */
 
 
-#ifndef _AMD64_INCLUDE_PARAM_H_
-#define	_AMD64_INCLUDE_PARAM_H_
+#ifndef __x86_64__
+#include <i386/param.h>
+#else
+#ifndef _MACHINE_INCLUDE_PARAM_H_
+#define	_MACHINE_INCLUDE_PARAM_H_
 
 #include <machine/_align.h>
 
@@ -139,4 +142,5 @@
 
 #define	pgtok(x)	((unsigned long)(x) * (PAGE_SIZE / 1024)) 
 
-#endif /* !_AMD64_INCLUDE_PARAM_H_ */
+#endif /* !_MACHINE_INCLUDE_PARAM_H_ */
+#endif /* !__x86_64__ */
diff --git a/sys/amd64/include/pc/bios.h b/sys/amd64/include/pc/bios.h
index 364f86c..02e8c9c 100644
--- a/sys/amd64/include/pc/bios.h
+++ b/sys/amd64/include/pc/bios.h
@@ -27,6 +27,10 @@
  * $FreeBSD$
  */
 
+#ifndef __x86_64__
+#include <i386/pc/bios.h>
+#else
+
 #ifndef _MACHINE_PC_BIOS_H_
 #define _MACHINE_PC_BIOS_H_
 
@@ -77,3 +81,4 @@ bios_oem_strings(struct bios_oem *oem, u_char *buffer, size_t maxlen);
 
 
 #endif /* _MACHINE_PC_BIOS_H_ */
+#endif /* !__x86_64__ */
diff --git a/sys/amd64/include/pcb.h b/sys/amd64/include/pcb.h
index 22cbbe2..d45a1ff 100644
--- a/sys/amd64/include/pcb.h
+++ b/sys/amd64/include/pcb.h
@@ -34,8 +34,14 @@
  * $FreeBSD$
  */
 
-#ifndef _AMD64_PCB_H_
-#define _AMD64_PCB_H_
+#ifndef __x86_64__
+
+#include <i386/pcb.h>
+
+#else
+
+#ifndef _MACHINE_PCB_H_
+#define _MACHINE_PCB_H_
 
 /*
  * AMD64 process control block
@@ -146,4 +152,5 @@ void	resumectx(struct pcb *);
 
 #endif
 
-#endif /* _AMD64_PCB_H_ */
+#endif /* _MACHINE_PCB_H_ */
+#endif /* !__x86_64__ */
diff --git a/sys/amd64/include/pcpu.h b/sys/amd64/include/pcpu.h
index 2188442..763ff9b 100644
--- a/sys/amd64/include/pcpu.h
+++ b/sys/amd64/include/pcpu.h
@@ -26,13 +26,15 @@
  * $FreeBSD$
  */
 
-#ifndef _MACHINE_PCPU_H_
-#define	_MACHINE_PCPU_H_
+#ifndef _AMD64_PCPU_H_
+#define	_AMD64_PCPU_H_
 
 #ifndef _SYS_CDEFS_H_
 #error "sys/cdefs.h is a prerequisite for this file"
 #endif
 
+#ifdef __x86_64__
+
 #if defined(XEN) || defined(XENHVM)
 #ifndef NR_VIRQS
 #define	NR_VIRQS	24
@@ -256,4 +258,9 @@ __curpcb(void)
 
 #endif /* _KERNEL */
 
-#endif /* !_MACHINE_PCPU_H_ */
+#else  /* __x86_64__ */
+
+#include <i386/pcpu.h>
+
+#endif /* __x86_64__ */
+#endif /* !_AMD64_PCPU_H_ */
diff --git a/sys/amd64/include/pmap.h b/sys/amd64/include/pmap.h
index 71045ae..94a724a 100644
--- a/sys/amd64/include/pmap.h
+++ b/sys/amd64/include/pmap.h
@@ -42,6 +42,12 @@
  * $FreeBSD$
  */
 
+#ifndef __x86_64__
+
+#include <i386/pmap.h>
+
+#else /* __x86_64__ */
+
 #ifndef _MACHINE_PMAP_H_
 #define	_MACHINE_PMAP_H_
 
@@ -338,3 +344,5 @@ void	pmap_invalidate_cache_range(vm_offset_t sva, vm_offset_t eva);
 #endif /* !LOCORE */
 
 #endif /* !_MACHINE_PMAP_H_ */
+
+#endif /* !__x86_64__ */
diff --git a/sys/amd64/include/proc.h b/sys/amd64/include/proc.h
index 14585fb..f0823ab 100644
--- a/sys/amd64/include/proc.h
+++ b/sys/amd64/include/proc.h
@@ -30,6 +30,12 @@
  * $FreeBSD$
  */
 
+#ifndef __x86_64__
+
+#include <i386/proc.h>
+
+#else /* __x86_64__ */
+
 #ifndef _MACHINE_PROC_H_
 #define	_MACHINE_PROC_H_
 
@@ -89,3 +95,4 @@ struct syscall_args {
 #endif  /* _KERNEL */
 
 #endif /* !_MACHINE_PROC_H_ */
+#endif /* !__x86_64__ */
diff --git a/sys/amd64/include/runq.h b/sys/amd64/include/runq.h
index 855e315..004b300 100644
--- a/sys/amd64/include/runq.h
+++ b/sys/amd64/include/runq.h
@@ -26,6 +26,10 @@
  * $FreeBSD$
  */
 
+#ifndef __x86_64__
+#include <i386/runq.h>
+#else
+
 #ifndef	_MACHINE_RUNQ_H_
 #define	_MACHINE_RUNQ_H_
 
@@ -44,3 +48,4 @@
 typedef	u_int64_t	rqb_word_t;
 
 #endif
+#endif
diff --git a/sys/amd64/include/segments.h b/sys/amd64/include/segments.h
index d9f4280..076c5ac 100644
--- a/sys/amd64/include/segments.h
+++ b/sys/amd64/include/segments.h
@@ -34,6 +34,10 @@
  * $FreeBSD$
  */
 
+#ifndef __x86_64__
+#include <i386/segments.h>
+#else
+
 #ifndef _MACHINE_SEGMENTS_H_
 #define	_MACHINE_SEGMENTS_H_
 
@@ -104,3 +108,4 @@ void	update_gdt_fsbase(struct thread *td, uint32_t base);
 #endif /* _KERNEL */
 
 #endif /* !_MACHINE_SEGMENTS_H_ */
+#endif /* !__x86_64__ */
diff --git a/sys/amd64/include/sf_buf.h b/sys/amd64/include/sf_buf.h
index b5245e6..482b3da 100644
--- a/sys/amd64/include/sf_buf.h
+++ b/sys/amd64/include/sf_buf.h
@@ -26,6 +26,10 @@
  * $FreeBSD$
  */
 
+#ifndef __x86_64__
+#include <i386/sf_buf.h>
+#else
+
 #ifndef _MACHINE_SF_BUF_H_
 #define _MACHINE_SF_BUF_H_
 
@@ -56,3 +60,4 @@ sf_buf_page(struct sf_buf *sf)
 }
 
 #endif /* !_MACHINE_SF_BUF_H_ */
+#endif /* !__x86_64__ */
diff --git a/sys/amd64/include/sigframe.h b/sys/amd64/include/sigframe.h
index d104507..8acf0b8 100644
--- a/sys/amd64/include/sigframe.h
+++ b/sys/amd64/include/sigframe.h
@@ -28,6 +28,10 @@
  * $FreeBSD$
  */
 
+#ifndef __x86_64__
+#include <i386/sigframe.h>
+#else
+
 #ifndef _MACHINE_SIGFRAME_H_
 #define	_MACHINE_SIGFRAME_H_
 
@@ -44,3 +48,4 @@ struct sigframe {
 };
 
 #endif /* !_MACHINE_SIGFRAME_H_ */
+#endif /* !__x86_64__ */
diff --git a/sys/amd64/include/signal.h b/sys/amd64/include/signal.h
index 085d43a..76d7018 100644
--- a/sys/amd64/include/signal.h
+++ b/sys/amd64/include/signal.h
@@ -31,6 +31,10 @@
  * $FreeBSD$
  */
 
+#ifndef __x86_64__
+#include <i386/signal.h>
+#else
+
 #ifndef _MACHINE_SIGNAL_H_
 #define	_MACHINE_SIGNAL_H_
 
@@ -107,3 +111,4 @@ struct sigcontext {
 #endif /* __BSD_VISIBLE */
 
 #endif /* !_MACHINE_SIGNAL_H_ */
+#endif /* !__x86_64__ */
diff --git a/sys/amd64/include/stack.h b/sys/amd64/include/stack.h
index 24e2547..bc99483 100644
--- a/sys/amd64/include/stack.h
+++ b/sys/amd64/include/stack.h
@@ -26,6 +26,9 @@
  * $FreeBSD$
  */
 
+#ifndef __x86_64__
+#include <i386/stack.h>
+#else
 #ifndef _MACHINE_STACK_H_
 #define	_MACHINE_STACK_H_
 
@@ -42,3 +45,4 @@ struct amd64_frame {
 };
 
 #endif /* !_MACHINE_STACK_H_ */
+#endif /* !__x86_64__ */
diff --git a/sys/amd64/include/timerreg.h b/sys/amd64/include/timerreg.h
index cf5f281..389b5f3 100644
--- a/sys/amd64/include/timerreg.h
+++ b/sys/amd64/include/timerreg.h
@@ -25,6 +25,10 @@
  * $FreeBSD$
  */
 
+#ifndef __x86_64__
+#include <i386/timerreg.h>
+#else
+
 /*
  * The outputs of the three timers are connected as follows:
  *
@@ -52,3 +56,4 @@
 #endif /* _KERNEL */
 
 #endif /* _MACHINE_TIMERREG_H_ */
+#endif /* !__x86_64__ */
diff --git a/sys/amd64/include/tss.h b/sys/amd64/include/tss.h
index fbbe3af..1fd82c1 100644
--- a/sys/amd64/include/tss.h
+++ b/sys/amd64/include/tss.h
@@ -33,6 +33,10 @@
  * $FreeBSD$
  */
 
+#ifndef __x86_64__
+#include <i386/tss.h>
+#else
+
 #ifndef _MACHINE_TSS_H_
 #define _MACHINE_TSS_H_ 1
 
@@ -68,3 +72,4 @@ extern struct amd64tss common_tss[];
 #endif
 
 #endif /* _MACHINE_TSS_H_ */
+#endif /* !__x86_64__ */
diff --git a/sys/amd64/include/ucontext.h b/sys/amd64/include/ucontext.h
index 5ab841e..a84dbb1 100644
--- a/sys/amd64/include/ucontext.h
+++ b/sys/amd64/include/ucontext.h
@@ -29,8 +29,10 @@
  * $FreeBSD$
  */
 
-#ifndef _MACHINE_UCONTEXT_H_
-#define	_MACHINE_UCONTEXT_H_
+#ifndef _AMD64_UCONTEXT_H_
+#define	_AMD64_UCONTEXT_H_
+
+#ifdef __x86_64__
 
 /*
  * mc_trapno bits. Shall be in sync with TF_XXX.
@@ -100,4 +102,10 @@ typedef struct __mcontext {
 	long	mc_spare[4];
 } mcontext_t;
 
-#endif /* !_MACHINE_UCONTEXT_H_ */
+#else /* __x86_64__ */
+
+#include <i386/ucontext.h>
+
+#endif
+
+#endif /* !_AMD64_UCONTEXT_H_ */
diff --git a/sys/amd64/include/varargs.h b/sys/amd64/include/varargs.h
index 93faac6..75c7a6f 100644
--- a/sys/amd64/include/varargs.h
+++ b/sys/amd64/include/varargs.h
@@ -40,6 +40,10 @@
  * $FreeBSD$
  */
 
+#ifndef __x86_64__
+#include <i386/varargs.h>
+#else
+
 #ifndef _MACHINE_VARARGS_H_
 #define	_MACHINE_VARARGS_H_
 
@@ -87,3 +91,4 @@ typedef char *va_list;
 #endif /* __GNUCLIKE_BUILTIN_VARARGS */
 
 #endif /* !_MACHINE_VARARGS_H_ */
+#endif /* !__x86_64__ */
diff --git a/sys/amd64/include/vmparam.h b/sys/amd64/include/vmparam.h
index e06fa39..295fd80 100644
--- a/sys/amd64/include/vmparam.h
+++ b/sys/amd64/include/vmparam.h
@@ -42,6 +42,10 @@
  */
 
 
+#ifndef __x86_64__
+#include <i386/vmparam.h>
+#else
+
 #ifndef _MACHINE_VMPARAM_H_
 #define	_MACHINE_VMPARAM_H_ 1
 
@@ -215,3 +219,4 @@
 #define	ZERO_REGION_SIZE	(2 * 1024 * 1024)	/* 2MB */
 
 #endif /* _MACHINE_VMPARAM_H_ */
+#endif /* !__x86_64__ */
_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"

Reply via email to