summaryrefslogtreecommitdiffstats
path: root/sys/amd64/include
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>2003-05-14 04:10:49 +0000
committerpeter <peter@FreeBSD.org>2003-05-14 04:10:49 +0000
commit770abdbb9c2f22fc13f2dc8ee14024fe29933651 (patch)
tree65e4ac1aca11723390006ee027d286f8177b0ec6 /sys/amd64/include
parent94122e1008f06fc69b00745c3556ee667db464b3 (diff)
downloadFreeBSD-src-770abdbb9c2f22fc13f2dc8ee14024fe29933651.zip
FreeBSD-src-770abdbb9c2f22fc13f2dc8ee14024fe29933651.tar.gz
Add BASIC i386 binary support for the amd64 kernel. This is largely
stolen from the ia64/ia32 code (indeed there was a repocopy), but I've redone the MD parts and added and fixed a few essential syscalls. It is sufficient to run i386 binaries like /bin/ls, /usr/bin/id (dynamic) and p4. The ia64 code has not implemented signal delivery, so I had to do that. Before you say it, yes, this does need to go in a common place. But we're in a freeze at the moment and I didn't want to risk breaking ia64. I will sort this out after the freeze so that the common code is in a common place. On the AMD64 side, this required adding segment selector context switch support and some other support infrastructure. The %fs/%gs etc code is hairy because loading %gs will clobber the kernel's current MSR_GSBASE setting. The segment selectors are not used by the kernel, so they're only changed at context switch time or when changing modes. This still needs to be optimized. Approved by: re (amd64/* blanket)
Diffstat (limited to 'sys/amd64/include')
-rw-r--r--sys/amd64/include/cpufunc.h13
-rw-r--r--sys/amd64/include/elf.h18
-rw-r--r--sys/amd64/include/md_var.h1
-rw-r--r--sys/amd64/include/pcb.h5
-rw-r--r--sys/amd64/include/segments.h2
5 files changed, 35 insertions, 4 deletions
diff --git a/sys/amd64/include/cpufunc.h b/sys/amd64/include/cpufunc.h
index 1e1df33..21257dd 100644
--- a/sys/amd64/include/cpufunc.h
+++ b/sys/amd64/include/cpufunc.h
@@ -447,7 +447,6 @@ invlpg(u_long addr)
__asm __volatile("invlpg %0" : : "m" (*(char *)addr) : "memory");
}
-/* XXX these are replaced with rdmsr/wrmsr */
static __inline u_int
rfs(void)
{
@@ -465,6 +464,18 @@ rgs(void)
}
static __inline void
+load_ds(u_int sel)
+{
+ __asm __volatile("movl %0,%%ds" : : "rm" (sel));
+}
+
+static __inline void
+load_es(u_int sel)
+{
+ __asm __volatile("movl %0,%%es" : : "rm" (sel));
+}
+
+static __inline void
load_fs(u_int sel)
{
__asm __volatile("movl %0,%%fs" : : "rm" (sel));
diff --git a/sys/amd64/include/elf.h b/sys/amd64/include/elf.h
index 3883d49..b675859 100644
--- a/sys/amd64/include/elf.h
+++ b/sys/amd64/include/elf.h
@@ -33,9 +33,12 @@
* ELF definitions for the AMD64 architecture.
*/
-#include <sys/elf64.h> /* Definitions common to all 64 bit architectures. */
+#ifndef __ELF_WORD_SIZE
#define __ELF_WORD_SIZE 64 /* Used by <sys/elf_generic.h> */
+#endif
+#include <sys/elf32.h> /* Definitions common to all 32 bit architectures. */
+#include <sys/elf64.h> /* Definitions common to all 64 bit architectures. */
#include <sys/elf_generic.h>
#define ELF_ARCH EM_X86_64
@@ -48,6 +51,13 @@
* The i386 supplement to the SVR4 ABI specification names this "auxv_t",
* but POSIX lays claim to all symbols ending with "_t".
*/
+typedef struct { /* Auxiliary vector entry on initial stack */
+ int a_type; /* Entry type. */
+ union {
+ int a_val; /* Integer value. */
+ } a_un;
+} Elf32_Auxinfo;
+
typedef struct { /* Auxiliary vector entry on initial stack */
long a_type; /* Entry type. */
@@ -118,7 +128,11 @@ __ElfType(Auxinfo);
#define R_X86_64_COUNT 16 /* Count of defined relocation types. */
/* Define "machine" characteristics */
-#define ELF_TARG_CLASS ELFCLASS64
+#if __ELF_WORD_SIZE == 32
+#define ELF_TARG_CLASS ELFCLASS32
+#else
+#define ELF_TARG_CLASS ELFCLASS64
+#endif
#define ELF_TARG_DATA ELFDATA2LSB
#define ELF_TARG_MACH EM_X86_64
#define ELF_TARG_VER 1
diff --git a/sys/amd64/include/md_var.h b/sys/amd64/include/md_var.h
index ad35173..63e9b2b 100644
--- a/sys/amd64/include/md_var.h
+++ b/sys/amd64/include/md_var.h
@@ -69,5 +69,6 @@ void pagezero(void *addr);
int is_physical_memory(vm_offset_t addr);
void setidt(int idx, alias_for_inthand_t *func, int typ, int dpl, int ist);
void swi_vm(void *);
+void fpstate_drop(struct thread *td);
#endif /* !_MACHINE_MD_VAR_H_ */
diff --git a/sys/amd64/include/pcb.h b/sys/amd64/include/pcb.h
index c17709b..5bfb41f 100644
--- a/sys/amd64/include/pcb.h
+++ b/sys/amd64/include/pcb.h
@@ -59,6 +59,11 @@ struct pcb {
register_t pcb_rflags;
register_t pcb_fsbase;
register_t pcb_gsbase;
+ register_t pcb_kgsbase;
+ u_int32_t pcb_ds;
+ u_int32_t pcb_es;
+ u_int32_t pcb_fs;
+ u_int32_t pcb_gs;
struct savefpu pcb_save;
u_long pcb_flags;
diff --git a/sys/amd64/include/segments.h b/sys/amd64/include/segments.h
index 0f9a59b..919eeff 100644
--- a/sys/amd64/include/segments.h
+++ b/sys/amd64/include/segments.h
@@ -166,7 +166,7 @@ struct region_descriptor {
/*
* Size of IDT table
*/
-#define NIDT 129 /* 32 reserved, 16 h/w, 0 s/w, linux's 0x80 */
+#define NIDT 256 /* 32 reserved, 16 h/w, 0 s/w, linux's 0x80 */
#define NRSVIDT 32 /* reserved entries for cpu exceptions */
/*
OpenPOWER on IntegriCloud