summaryrefslogtreecommitdiff
path: root/i386/util
diff options
context:
space:
mode:
authorThomas Bushnell <thomas@gnu.org>1997-02-25 21:28:37 +0000
committerThomas Bushnell <thomas@gnu.org>1997-02-25 21:28:37 +0000
commitf07a4c844da9f0ecae5bbee1ab94be56505f26f7 (patch)
tree12b07c7e578fc1a5f53dbfde2632408491ff2a70 /i386/util
Initial source
Diffstat (limited to 'i386/util')
-rw-r--r--i386/util/Makerules38
-rw-r--r--i386/util/NOTES35
-rw-r--r--i386/util/anno.c92
-rw-r--r--i386/util/anno.h92
-rw-r--r--i386/util/cpu.h57
-rw-r--r--i386/util/cpu_subs.h26
-rw-r--r--i386/util/cpu_tables_init.c37
-rw-r--r--i386/util/cpu_tables_load.c70
-rw-r--r--i386/util/crtn.S33
-rw-r--r--i386/util/debug.h50
-rw-r--r--i386/util/gdt.c80
-rw-r--r--i386/util/gdt.h88
-rw-r--r--i386/util/gdt_sels.h45
-rw-r--r--i386/util/i16/debug.h42
-rw-r--r--i386/util/i16/i16.h58
-rw-r--r--i386/util/i16/i16_die.c34
-rw-r--r--i386/util/i16/i16_gdt_init_temp.c53
-rw-r--r--i386/util/i16/i16_nanodelay.c35
-rw-r--r--i386/util/i16/i16_puts.c34
-rw-r--r--i386/util/i16/i16_writehex.c57
-rw-r--r--i386/util/i386_asm.sym36
-rw-r--r--i386/util/idt.c50
-rw-r--r--i386/util/idt.h43
-rw-r--r--i386/util/idt_inittab.S128
-rw-r--r--i386/util/idt_inittab.h57
-rw-r--r--i386/util/ldt.h45
-rw-r--r--i386/util/trap.h100
-rw-r--r--i386/util/trap_asm.sym45
-rw-r--r--i386/util/trap_dump.c63
-rw-r--r--i386/util/trap_dump_die.c12
-rw-r--r--i386/util/trap_handler.S32
-rw-r--r--i386/util/trap_return.S39
-rw-r--r--i386/util/tss.c45
-rw-r--r--i386/util/tss.h30
-rw-r--r--i386/util/tss_dump.c44
-rw-r--r--i386/util/vm_param.h89
36 files changed, 1914 insertions, 0 deletions
diff --git a/i386/util/Makerules b/i386/util/Makerules
new file mode 100644
index 0000000..8bdb020
--- /dev/null
+++ b/i386/util/Makerules
@@ -0,0 +1,38 @@
+#
+# Copyright (c) 1995 The University of Utah and
+# the Computer Systems Laboratory (CSL). All rights reserved.
+#
+# Permission to use, copy, modify and distribute this software and its
+# documentation is hereby granted, provided that both the copyright
+# notice and this permission notice appear in all copies of the
+# software, derivative works or modified versions, and any portions
+# thereof, and that both notices appear in supporting documentation.
+#
+# THE UNIVERSITY OF UTAH AND CSS ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+# IS" CONDITION. THE UNIVERSITY OF UTAH AND CSS DISCLAIM ANY LIABILITY OF
+# ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+#
+# CSS requests users of this software to return to css-dist@cs.utah.edu any
+# improvements that they make and grant CSS redistribution rights.
+#
+# Author: Bryan Ford, University of Utah CSS
+#
+ifndef _mach4_i386_kernel_util_makerules_
+_mach4_i386_kernel_util_makerules = yes
+
+
+CLEAN_FILES += i386_asm.h
+
+
+include $(MSRCDIR)/Makerules
+include $(GSRCDIR)/kernel/util/Makerules
+
+
+# Handy rule to show what's in the GDT...
+gdt-list:
+ echo '#include "gdt_sels.h"' >gdt-list.c
+ $(CC) -E $(CFLAGS) $(TARGET_CFLAGS) gdt-list.c | grep ^gdt_sel
+ rm -f gdt-list.c
+
+
+endif
diff --git a/i386/util/NOTES b/i386/util/NOTES
new file mode 100644
index 0000000..770bbef
--- /dev/null
+++ b/i386/util/NOTES
@@ -0,0 +1,35 @@
+
+raw_switch:
+
+ Provides the code to switch between real and protected mode.
+ Switches between the environments "completely":
+ e.g. when switching to protected mode,
+ all the normal protected-mode state for that environment is set up.
+
+raw_pmode:
+
+ i16_raw_enter_pmode()
+ Enters protoected mode from real mode.
+ Does not initialize IDT or TSS or anything else;
+ just gets the system into protected mode
+ with a simple temporary GDT.
+ Returns with interrupts turned off
+ (and they'd better stay off until there's a valid pmode IDT!)
+
+ i16_raw_leave_pmode()
+ Assumes paging is turned off.
+ Returns with interrupts turned off;
+ they can probably be turned back on at any time.
+
+ Depends on:
+ i16_die()
+ A20 enable/disable code (e.g. raw_a20).
+ gdt.h: KERNEL_16_CS, KERNEL_16_DS
+
+
+
+vm_param.h:
+
+ Must export kvtolin(), lintokv()
+
+
diff --git a/i386/util/anno.c b/i386/util/anno.c
new file mode 100644
index 0000000..0137fe8
--- /dev/null
+++ b/i386/util/anno.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 1995 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+
+#include "anno.h"
+#include "debug.h"
+
+#ifdef ENABLE_ANNO
+
+void anno_init()
+{
+ extern struct anno_entry __ANNO_START__[], __ANNO_END__[];
+ struct anno_entry *base;
+
+ /* Sort the tables using a slow, simple selection sort;
+ it only needs to be done once. */
+ for (base = __ANNO_START__; base < __ANNO_END__; base++)
+ {
+ struct anno_entry *cur, *low, tmp;
+
+ /* Select the lowermost remaining entry,
+ and swap it into the base slot.
+ Sort by table first, then by val1, val2, val3. */
+ low = base;
+ for (cur = base+1; cur < __ANNO_END__; cur++)
+ if ((cur->table < low->table)
+ || ((cur->table == low->table)
+ && ((cur->val1 < low->val1)
+ || ((cur->val1 == low->val1)
+ && ((cur->val2 < low->val2)
+ || ((cur->val2 == low->val2)
+ && (cur->val3 < low->val3)))))))
+ low = cur;
+ tmp = *base;
+ *base = *low;
+ *low = tmp;
+ }
+
+ /* Initialize each anno_table structure with entries in the array. */
+ for (base = __ANNO_START__; base < __ANNO_END__; )
+ {
+ struct anno_entry *end;
+
+ for (end = base;
+ (end < __ANNO_END__) && (end->table == base->table);
+ end++);
+ base->table->start = base;
+ base->table->end = end;
+
+ base = end;
+ }
+
+#if 0 /* debugging code */
+ {
+ struct anno_table *t = 0;
+
+ for (base = __ANNO_START__; base < __ANNO_END__; base++)
+ {
+ if (t != base->table)
+ {
+ t = base->table;
+ printf("table %08x: %08x-%08x (%d entries)\n",
+ t, t->start, t->end, t->end - t->start);
+ assert(t->start == base);
+ }
+ printf(" vals %08x %08x %08x\n",
+ base->table, base->val1, base->val2, base->val3);
+ }
+ }
+#endif
+}
+
+#endif ENABLE_ANNO
diff --git a/i386/util/anno.h b/i386/util/anno.h
new file mode 100644
index 0000000..67e2778
--- /dev/null
+++ b/i386/util/anno.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 1995-1994 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+#ifndef _I386_KERNEL_UTIL_ANNO_H_
+#define _I386_KERNEL_UTIL_ANNO_H_
+
+#ifndef ASSEMBLER
+
+
+struct anno_table
+{
+ struct anno_entry *start;
+ struct anno_entry *end;
+};
+
+struct anno_entry
+{
+ int val1;
+ int val2;
+ int val3;
+ struct anno_table *table;
+};
+
+
+#else /* ASSEMBLER */
+
+
+/* Create an arbitrary annotation entry.
+ Must switch back to an appropriate segment afterward. */
+#define ANNO_ENTRY(table, val1, val2, val3) \
+ .section .anno,"aw",@progbits ;\
+ .long val1,val2,val3,table
+
+/* Create an annotation entry for code in a text segment. */
+#define ANNO_TEXT(table, val2, val3) \
+9: ANNO_ENTRY(table, 9b, val2, val3) ;\
+ .text
+
+
+
+/* The following are for common annotation tables.
+ These don't have to be used in any given kernel,
+ and others can be defined as convenient. */
+
+
+/* The anno_intr table is generally accessed
+ on hardware interrupts that occur while running in kernel mode.
+ The value is a routine for the trap handler in interrupt.S
+ to jump to before processing the hardware interrupt.
+ This routine applies to all code from this address
+ up to but not including the address of the next ANNO_INTR.
+ To disable interrupt redirection for a piece of code,
+ place an ANNO_INTR(0) before it. */
+
+#define ANNO_INTR(routine) \
+ ANNO_TEXT(anno_intr, routine, 0)
+
+
+/* The anno_trap table is accessed
+ on processor traps that occur in kernel mode.
+ If a match is found in this table,
+ the specified alternate handler is run instead of the generic handler.
+ A match is found only if the EIP exactly matches an ANNO_TRAP entry
+ (i.e. these entries apply to individual instructions, not groups),
+ and if the trap type that occurred matches the type specified. */
+
+#define ANNO_TRAP(type, routine) \
+ ANNO_TEXT(anno_trap, type, routine)
+
+
+#endif /* ASSEMBLER */
+
+#endif _I386_KERNEL_UTIL_ANNO_H_
diff --git a/i386/util/cpu.h b/i386/util/cpu.h
new file mode 100644
index 0000000..d90c6f8
--- /dev/null
+++ b/i386/util/cpu.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 1995-1994 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+#ifndef _I386_UTIL_CPU_H_
+#define _I386_UTIL_CPU_H_
+
+#include <mach/machine/tss.h>
+
+#include "config.h"
+#include "gdt.h"
+#include "ldt.h"
+#include "idt.h"
+
+/*
+ * Multiprocessor i386/i486 systems use a separate copy of the
+ * GDT, IDT, LDT, and kernel TSS per processor. The first three
+ * are separate to avoid lock contention: the i386 uses locked
+ * memory cycles to access the descriptor tables. The TSS is
+ * separate since each processor needs its own kernel stack,
+ * and since using a TSS marks it busy.
+ */
+
+/* This structure holds the processor tables for this cpu. */
+struct cpu_tables
+{
+ struct i386_gate idt[IDTSZ];
+ struct i386_descriptor gdt[GDTSZ];
+#ifdef ENABLE_KERNEL_LDT
+ struct i386_descriptor ldt[LDTSZ];
+#endif
+#ifdef ENABLE_KERNEL_TSS
+ struct i386_tss tss;
+#endif
+};
+
+#include_next "cpu.h"
+
+#endif _I386_UTIL_CPU_H_
diff --git a/i386/util/cpu_subs.h b/i386/util/cpu_subs.h
new file mode 100644
index 0000000..f814d93
--- /dev/null
+++ b/i386/util/cpu_subs.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 1995-1994 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+
+cpu_sub(tables)
+
+#include_next "cpu_subs.h"
diff --git a/i386/util/cpu_tables_init.c b/i386/util/cpu_tables_init.c
new file mode 100644
index 0000000..48e840d
--- /dev/null
+++ b/i386/util/cpu_tables_init.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 1995-1994 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+
+#include "cpu.h"
+
+void cpu_tables_init(struct cpu *cpu)
+{
+ cpu_idt_init(cpu);
+ cpu_gdt_init(cpu);
+#ifdef ENABLE_KERNEL_LDT
+ cpu_ldt_init(cpu);
+#endif
+#ifdef ENABLE_KERNEL_TSS
+ cpu_tss_init(cpu);
+#endif
+}
+
diff --git a/i386/util/cpu_tables_load.c b/i386/util/cpu_tables_load.c
new file mode 100644
index 0000000..2237b33
--- /dev/null
+++ b/i386/util/cpu_tables_load.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 1995-1994 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+
+#include <mach/machine/proc_reg.h>
+
+#include "cpu.h"
+#include "vm_param.h"
+
+void cpu_tables_load(struct cpu *cpu)
+{
+ struct pseudo_descriptor pdesc;
+
+ /* Load the final GDT.
+ If paging is now on,
+ then this will point the processor to the GDT
+ at its new linear address in the kernel linear space. */
+ pdesc.limit = sizeof(cpu->tables.gdt)-1;
+ pdesc.linear_base = kvtolin(&cpu->tables.gdt);
+ set_gdt(&pdesc);
+
+ /* Reload all the segment registers from the new GDT. */
+ asm volatile("
+ ljmp %0,$1f
+ 1:
+ " : : "i" (KERNEL_CS));
+ set_ds(KERNEL_DS);
+ set_es(KERNEL_DS);
+ set_fs(0);
+ set_gs(0);
+ set_ss(KERNEL_DS);
+
+ /* Load the IDT. */
+ pdesc.limit = sizeof(cpu[0].tables.idt)-1;
+ pdesc.linear_base = kvtolin(&cpu->tables.idt);
+ set_idt(&pdesc);
+
+#ifdef DEFAULT_LDT
+ /* Load the default LDT. */
+ set_ldt(DEFAULT_LDT);
+#endif
+
+#ifdef DEFAULT_TSS
+ /* Make sure it isn't marked busy. */
+ cpu->tables.gdt[DEFAULT_TSS_IDX].access &= ~ACC_TSS_BUSY;
+
+ /* Load the default TSS. */
+ set_tr(DEFAULT_TSS);
+#endif
+}
+
diff --git a/i386/util/crtn.S b/i386/util/crtn.S
new file mode 100644
index 0000000..6a89150
--- /dev/null
+++ b/i386/util/crtn.S
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 1995 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+
+#ifdef __ELF__
+
+#include <mach/machine/asm.h>
+
+
+ .section .anno,"aw",@progbits
+ .globl __ANNO_END__
+__ANNO_END__:
+
+#endif /* __ELF__ */
diff --git a/i386/util/debug.h b/i386/util/debug.h
new file mode 100644
index 0000000..15ebac5
--- /dev/null
+++ b/i386/util/debug.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 1995-1994 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+#ifndef _UTIL_I386_DEBUG_H_
+#define _UTIL_I386_DEBUG_H_
+
+#ifdef ASSEMBLER
+#ifdef DEBUG
+
+
+#define A(cond,a,b) \
+ a,b ;\
+ j##cond 8f ;\
+ int $0xda ;\
+8:
+
+
+#else !DEBUG
+
+
+#define A(cond,a,b)
+
+
+#endif !DEBUG
+#else !ASSEMBLER
+
+#include_next "debug.h"
+
+#endif !ASSEMBLER
+
+#endif _UTIL_I386_DEBUG_H_
diff --git a/i386/util/gdt.c b/i386/util/gdt.c
new file mode 100644
index 0000000..7bfa6aa
--- /dev/null
+++ b/i386/util/gdt.c
@@ -0,0 +1,80 @@
+/*
+ * Mach Operating System
+ * Copyright (c) 1991,1990 Carnegie Mellon University
+ * Copyright (c) 1991 IBM Corporation
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation,
+ * and that the name IBM not be used in advertising or publicity
+ * pertaining to distribution of the software without specific, written
+ * prior permission.
+ *
+ * CARNEGIE MELLON AND IBM ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON AND IBM DISCLAIM ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie Mellon
+ * the rights to redistribute these changes.
+ */
+
+#include "cpu.h"
+#include "vm_param.h"
+
+
+/* Initialize the 32-bit kernel code and data segment descriptors
+ to point to the base of the kernel linear space region. */
+gdt_desc_initializer(KERNEL_CS,
+ kvtolin(0), 0xffffffff,
+ ACC_PL_K|ACC_CODE_R, SZ_32);
+gdt_desc_initializer(KERNEL_DS,
+ kvtolin(0), 0xffffffff,
+ ACC_PL_K|ACC_DATA_W, SZ_32);
+
+/* Initialize the 16-bit real-mode code and data segment descriptors. */
+gdt_desc_initializer(KERNEL_16_CS,
+ kvtolin(0), 0xffff,
+ ACC_PL_K|ACC_CODE_R, SZ_16);
+gdt_desc_initializer(KERNEL_16_DS,
+ kvtolin(0), 0xffff,
+ ACC_PL_K|ACC_DATA_W, SZ_16);
+
+/* Initialize the linear-space data segment descriptor. */
+gdt_desc_initializer(LINEAR_CS,
+ 0, 0xffffffff,
+ ACC_PL_K|ACC_CODE_R, SZ_32);
+gdt_desc_initializer(LINEAR_DS,
+ 0, 0xffffffff,
+ ACC_PL_K|ACC_DATA_W, SZ_32);
+
+/* Initialize the master LDT and TSS descriptors. */
+#ifdef ENABLE_KERNEL_LDT
+gdt_desc_initializer(KERNEL_LDT,
+ kvtolin(&cpu->tables.ldt), sizeof(cpu->tables.ldt)-1,
+ ACC_PL_K|ACC_LDT, 0);
+#endif
+#ifdef ENABLE_KERNEL_TSS
+gdt_desc_initializer(KERNEL_TSS,
+ kvtolin(&cpu->tables.tss), sizeof(cpu->tables.tss)-1,
+ ACC_PL_K|ACC_TSS, 0);
+#endif
+
+
+void cpu_gdt_init(struct cpu *cpu)
+{
+ /* Initialize all the selectors of the GDT. */
+#define gdt_sel(name) cpu_gdt_init_##name(cpu);
+#include "gdt_sels.h"
+#undef gdt_sel
+}
+
diff --git a/i386/util/gdt.h b/i386/util/gdt.h
new file mode 100644
index 0000000..5b422ae
--- /dev/null
+++ b/i386/util/gdt.h
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 1995-1994 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+#ifndef _I386_GDT_
+#define _I386_GDT_
+
+#include <mach/machine/seg.h>
+
+/*
+ * Collect and define the GDT segment selectors.
+ * xxx_IDX is the index number of the selector;
+ * xxx is the actual selector value (index * 8).
+ */
+enum gdt_idx
+{
+ GDT_NULL_IDX = 0,
+
+#define gdt_sel(name) name##_IDX,
+#include "gdt_sels.h"
+#undef gdt_sel
+
+ GDT_FIRST_FREE_IDX
+};
+
+enum gdt_sel
+{
+ GDT_NULL = 0,
+
+#define gdt_sel(name) name = name##_IDX * 8,
+#include "gdt_sels.h"
+#undef gdt_sel
+};
+
+#define GDTSZ GDT_FIRST_FREE_IDX
+
+
+/* If we have a KERNEL_TSS, use that as our DEFAULT_TSS if none is defined yet.
+ (The DEFAULT_TSS gets loaded by cpu_tables_load() upon switching to pmode.)
+ Similarly with DEFAULT_LDT. */
+#if defined(ENABLE_KERNEL_TSS) && !defined(DEFAULT_TSS)
+#define DEFAULT_TSS KERNEL_TSS
+#define DEFAULT_TSS_IDX KERNEL_TSS_IDX
+#endif
+#if defined(ENABLE_KERNEL_LDT) && !defined(DEFAULT_LDT)
+#define DEFAULT_LDT KERNEL_LDT
+#define DEFAULT_LDT_IDX KERNEL_LDT_IDX
+#endif
+
+
+/* Fill a segment descriptor in a CPU's GDT. */
+#define fill_gdt_descriptor(cpu, segment, base, limit, access, sizebits) \
+ fill_descriptor(&(cpu)->tables.gdt[segment/8], \
+ base, limit, access, sizebits)
+
+#define i16_fill_gdt_descriptor(cpu, segment, base, limit, access, sizebits) \
+ i16_fill_descriptor(&(cpu)->tables.gdt[segment/8], \
+ base, limit, access, sizebits)
+
+
+/* This automatically defines GDT descriptor initialization functions. */
+#define gdt_desc_initializer(segment, base, limit, access, sizebits) \
+ void cpu_gdt_init_##segment(struct cpu *cpu) \
+ { \
+ fill_gdt_descriptor(cpu, segment, base, limit, \
+ access, sizebits); \
+ }
+
+
+#endif _I386_GDT_
diff --git a/i386/util/gdt_sels.h b/i386/util/gdt_sels.h
new file mode 100644
index 0000000..e9b33fe
--- /dev/null
+++ b/i386/util/gdt_sels.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 1995-1994 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+
+#include "config.h"
+
+/* Kernel segment descriptors (32-bit flat address space). */
+gdt_sel(KERNEL_CS)
+gdt_sel(KERNEL_DS)
+
+/* Corresponding 16-bit descriptors for protected-mode entry and exit. */
+gdt_sel(KERNEL_16_CS)
+gdt_sel(KERNEL_16_DS)
+
+/* Code and data segments that always maps directly to flat, linear memory. */
+gdt_sel(LINEAR_CS)
+gdt_sel(LINEAR_DS)
+
+/* Standard LDT and TSS descriptors. */
+#ifdef ENABLE_KERNEL_LDT
+gdt_sel(KERNEL_LDT)
+#endif
+#ifdef ENABLE_KERNEL_TSS
+gdt_sel(KERNEL_TSS)
+#endif
+
diff --git a/i386/util/i16/debug.h b/i386/util/i16/debug.h
new file mode 100644
index 0000000..6bce9d2
--- /dev/null
+++ b/i386/util/i16/debug.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 1995 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+#ifndef _UTIL_I386_I16_DEBUG_H_
+#define _UTIL_I386_I16_DEBUG_H_
+
+#include_next "debug.h"
+
+#ifdef DEBUG
+
+#define i16_assert(v) \
+ MACRO_BEGIN \
+ if (!(v)) \
+ i16_die(__FILE__":?: failed assertion `"#v"'"); \
+ MACRO_END
+
+#else /* !DEBUG */
+
+#define i16_assert(v) (0)
+
+#endif /* !DEBUG */
+
+#endif /* _UTIL_I386_I16_DEBUG_H_ */
diff --git a/i386/util/i16/i16.h b/i386/util/i16/i16.h
new file mode 100644
index 0000000..0eae59a
--- /dev/null
+++ b/i386/util/i16/i16.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 1995-1994 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+#ifndef _I386_I16_
+#define _I386_I16_
+
+#include <mach/machine/code16.h>
+
+#include "gdt.h"
+
+
+/* Macros to switch between 16-bit and 32-bit code
+ in the middle of a C function.
+ Be careful with these! */
+#define i16_switch_to_32bit() asm volatile("
+ ljmp %0,$1f
+ .code32
+ 1:
+ " : : "i" (KERNEL_CS));
+#define switch_to_16bit() asm volatile("
+ ljmp %0,$1f
+ .code16
+ 1:
+ " : : "i" (KERNEL_16_CS));
+
+
+/* From within one type of code, execute 'stmt' in the other.
+ These are safer and harder to screw up with than the above macros. */
+#define i16_do_32bit(stmt) \
+ ({ i16_switch_to_32bit(); \
+ { stmt; } \
+ switch_to_16bit(); })
+#define do_16bit(stmt) \
+ ({ switch_to_16bit(); \
+ { stmt; } \
+ i16_switch_to_32bit(); })
+
+
+#endif _I386_I16_
diff --git a/i386/util/i16/i16_die.c b/i386/util/i16/i16_die.c
new file mode 100644
index 0000000..e3cd533
--- /dev/null
+++ b/i386/util/i16/i16_die.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 1995-1994 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+
+#include <mach/machine/code16.h>
+
+CODE16
+
+void i16_die(char *mes)
+{
+ if (mes)
+ i16_puts(mes);
+
+ i16_exit(mes != 0);
+}
diff --git a/i386/util/i16/i16_gdt_init_temp.c b/i386/util/i16/i16_gdt_init_temp.c
new file mode 100644
index 0000000..14f2d0e
--- /dev/null
+++ b/i386/util/i16/i16_gdt_init_temp.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 1995-1994 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+
+#include <mach/machine/code16.h>
+#include <mach/machine/seg.h>
+
+#include "vm_param.h"
+#include "cpu.h"
+
+
+CODE16
+
+/* This 16-bit function initializes CPU 0's GDT
+ just enough to get in and out of protected (and possibly paged) mode,
+ with all addresses assuming identity-mapped memory. */
+void i16_gdt_init_temp()
+{
+ /* Create temporary kernel code and data segment descriptors.
+ (They'll be reinitialized later after paging is enabled.) */
+ i16_fill_gdt_descriptor(&cpu[0], KERNEL_CS,
+ boot_image_pa, 0xffffffff,
+ ACC_PL_K|ACC_CODE_R, SZ_32);
+ i16_fill_gdt_descriptor(&cpu[0], KERNEL_DS,
+ boot_image_pa, 0xffffffff,
+ ACC_PL_K|ACC_DATA_W, SZ_32);
+ i16_fill_gdt_descriptor(&cpu[0], KERNEL_16_CS,
+ boot_image_pa, 0xffff,
+ ACC_PL_K|ACC_CODE_R, SZ_16);
+ i16_fill_gdt_descriptor(&cpu[0], KERNEL_16_DS,
+ boot_image_pa, 0xffff,
+ ACC_PL_K|ACC_DATA_W, SZ_16);
+}
+
diff --git a/i386/util/i16/i16_nanodelay.c b/i386/util/i16/i16_nanodelay.c
new file mode 100644
index 0000000..7b23cb5
--- /dev/null
+++ b/i386/util/i16/i16_nanodelay.c
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 1995-1994 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+
+#include <mach/machine/code16.h>
+
+CODE16
+
+/* XXX */
+void i16_nanodelay(int ns)
+{
+ asm("jmp 1f; 1:");
+ asm("jmp 1f; 1:");
+ asm("jmp 1f; 1:");
+}
+
diff --git a/i386/util/i16/i16_puts.c b/i386/util/i16/i16_puts.c
new file mode 100644
index 0000000..c43a3e1
--- /dev/null
+++ b/i386/util/i16/i16_puts.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 1995-1994 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+
+#include <mach/machine/code16.h>
+
+CODE16
+
+void i16_puts(const char *mes)
+{
+ while (*mes)
+ i16_putchar(*mes++);
+ i16_putchar('\n');
+}
+
diff --git a/i386/util/i16/i16_writehex.c b/i386/util/i16/i16_writehex.c
new file mode 100644
index 0000000..4a1b2af
--- /dev/null
+++ b/i386/util/i16/i16_writehex.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 1995-1994 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+
+#include <mach/machine/code16.h>
+
+CODE16
+
+void i16_writehexdigit(unsigned char digit)
+{
+ digit &= 0xf;
+ i16_putchar(digit < 10 ? digit+'0' : digit-10+'A');
+}
+
+void i16_writehexb(unsigned char val)
+{
+ i16_writehexdigit(val >> 4);
+ i16_writehexdigit(val);
+}
+
+void i16_writehexw(unsigned short val)
+{
+ i16_writehexb(val >> 8);
+ i16_writehexb(val);
+}
+
+void i16_writehexl(unsigned long val)
+{
+ i16_writehexw(val >> 16);
+ i16_writehexw(val);
+}
+
+void i16_writehexll(unsigned long long val)
+{
+ i16_writehexl(val >> 32);
+ i16_writehexl(val);
+}
+
diff --git a/i386/util/i386_asm.sym b/i386/util/i386_asm.sym
new file mode 100644
index 0000000..9de12c3
--- /dev/null
+++ b/i386/util/i386_asm.sym
@@ -0,0 +1,36 @@
+/*
+ * MOSS - DOS extender built from the Mach 4 source tree
+ * Copyright (C) 1995-1994 Sleepless Software
+ *
+ * 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.
+ *
+ * Author: Bryan Ford
+ */
+
+#include <mach/machine/tss.h>
+
+#include "gdt.h"
+
+offset i386_tss tss esp0
+offset i386_tss tss ss
+size i386_tss tss
+
+expr KERNEL_CS
+expr KERNEL_DS
+expr KERNEL_16_CS
+expr KERNEL_16_DS
+expr LINEAR_CS
+expr LINEAR_DS
+
diff --git a/i386/util/idt.c b/i386/util/idt.c
new file mode 100644
index 0000000..234b60e
--- /dev/null
+++ b/i386/util/idt.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 1995-1994 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+
+#include <mach/machine/seg.h>
+#include <mach/machine/proc_reg.h>
+
+#include "vm_param.h"
+#include "cpu.h"
+
+struct idt_init_entry
+{
+ unsigned entrypoint;
+ unsigned short vector;
+ unsigned short type;
+};
+extern struct idt_init_entry idt_inittab[];
+
+void cpu_idt_init(struct cpu *cpu)
+{
+ struct idt_init_entry *iie = idt_inittab;
+
+ /* Initialize the trap/interrupt vectors from the idt_inittab. */
+ while (iie->entrypoint)
+ {
+ fill_idt_gate(cpu, iie->vector, iie->entrypoint,
+ KERNEL_CS, iie->type);
+ iie++;
+ }
+}
+
diff --git a/i386/util/idt.h b/i386/util/idt.h
new file mode 100644
index 0000000..a94019f
--- /dev/null
+++ b/i386/util/idt.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 1995-1994 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+#ifndef _I386_IDT_
+#define _I386_IDT_
+
+#include <mach/vm_param.h>
+#include <mach/machine/seg.h>
+
+#include "irq.h"
+
+/* On a standard PC, we only need 16 interrupt vectors,
+ because that's all the PIC hardware supports. */
+#ifndef IDTSZ
+#define IDTSZ (IDT_IRQ_BASE+IRQ_COUNT)
+#endif
+
+
+/* Fill a gate in a CPU's IDT. */
+#define fill_idt_gate(cpu, int_num, entry, selector, access) \
+ fill_gate(&(cpu)->tables.idt[int_num], \
+ entry, selector, access, 0)
+
+#endif _I386_IDT_
diff --git a/i386/util/idt_inittab.S b/i386/util/idt_inittab.S
new file mode 100644
index 0000000..3fc6b5c
--- /dev/null
+++ b/i386/util/idt_inittab.S
@@ -0,0 +1,128 @@
+/*
+ * Mach Operating System
+ * Copyright (c) 1993,1992,1991,1990 Carnegie Mellon University
+ * Copyright (c) 1991 IBM Corporation
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation,
+ * and that the nema IBM not be used in advertising or publicity
+ * pertaining to distribution of the software without specific, written
+ * prior permission.
+ *
+ * CARNEGIE MELLON AND IBM ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON AND IBM DISCLAIM ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie Mellon
+ * the rights to redistribute these changes.
+ */
+
+#include <mach/machine/asm.h>
+#include <mach/machine/eflags.h>
+#include <mach/machine/trap.h>
+#include <mach/machine/seg.h>
+
+#include "trap.h"
+#include "idt_inittab.h"
+#include "debug.h"
+
+/*
+ * This is a default idt_inittab
+ * that simply invokes panic_trap on any trap.
+ * All gates are interrupt gates,
+ * so that interrupts will be immediately turned off.
+ */
+
+
+/*
+ * No error code. Clear error code and push trap number.
+ */
+#define EXCEPTION(n,name) \
+ IDT_ENTRY(n,EXT(name),ACC_PL_K|ACC_INTR_GATE);\
+ENTRY(name) ;\
+ pushl $(0) ;\
+ pushl $(n) ;\
+ jmp alltraps
+
+/*
+ * User-accessible exception. Otherwise, same as above.
+ */
+#define EXCEP_USR(n,name) \
+ IDT_ENTRY(n,EXT(name),ACC_PL_U|ACC_INTR_GATE);\
+ENTRY(name) ;\
+ pushl $(0) ;\
+ pushl $(n) ;\
+ jmp alltraps
+
+/*
+ * Error code has been pushed. Just push trap number.
+ */
+#define EXCEP_ERR(n,name) \
+ IDT_ENTRY(n,EXT(name),ACC_PL_K|ACC_INTR_GATE);\
+ENTRY(name) ;\
+ pushl $(n) ;\
+ jmp alltraps
+
+/*
+ * Special interrupt code: dispatches to a unique entrypoint,
+ * not defined automatically here.
+ */
+#define EXCEP_SPC(n,name) \
+ IDT_ENTRY(n,EXT(name),ACC_PL_K|ACC_INTR_GATE)
+
+
+IDT_INITTAB_BEGIN
+
+EXCEPTION(0x00,t_zero_div)
+EXCEPTION(0x01,t_debug)
+EXCEP_USR(0x03,t_int3)
+EXCEP_USR(0x04,t_into)
+EXCEP_USR(0x05,t_bounds)
+EXCEPTION(0x06,t_invop)
+EXCEPTION(0x07,t_nofpu)
+EXCEPTION(0x08,a_dbl_fault)
+EXCEPTION(0x09,a_fpu_over)
+EXCEP_ERR(0x0a,a_inv_tss)
+EXCEP_ERR(0x0b,t_segnp)
+EXCEP_ERR(0x0c,t_stack_fault)
+EXCEP_ERR(0x0d,t_gen_prot)
+EXCEP_ERR(0x0e,t_page_fault)
+EXCEPTION(0x0f,t_trap_0f)
+EXCEPTION(0x10,t_fpu_err)
+EXCEPTION(0x11,t_trap_11)
+EXCEPTION(0x12,t_trap_12)
+EXCEPTION(0x13,t_trap_13)
+EXCEPTION(0x14,t_trap_14)
+EXCEPTION(0x15,t_trap_15)
+EXCEPTION(0x16,t_trap_16)
+EXCEPTION(0x17,t_trap_17)
+EXCEPTION(0x18,t_trap_18)
+EXCEPTION(0x19,t_trap_19)
+EXCEPTION(0x1a,t_trap_1a)
+EXCEPTION(0x1b,t_trap_1b)
+EXCEPTION(0x1c,t_trap_1c)
+EXCEPTION(0x1d,t_trap_1d)
+EXCEPTION(0x1e,t_trap_1e)
+EXCEPTION(0x1f,t_trap_1f)
+
+IDT_INITTAB_END
+
+alltraps:
+ pusha
+ pushl %ds
+ pushl %es
+ pushl %fs
+ pushl %gs
+ jmp EXT(trap_handler)
+
diff --git a/i386/util/idt_inittab.h b/i386/util/idt_inittab.h
new file mode 100644
index 0000000..9cb994f
--- /dev/null
+++ b/i386/util/idt_inittab.h
@@ -0,0 +1,57 @@
+/*
+ * Mach Operating System
+ * Copyright (c) 1991,1990 Carnegie Mellon University
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie Mellon
+ * the rights to redistribute these changes.
+ */
+#ifndef _I386_UTIL_IDT_INITTAB_H_
+
+
+
+/* We'll be using macros to fill in a table in data hunk 2
+ while writing trap entrypoint routines at the same time.
+ Here's the header that comes before everything else. */
+#define IDT_INITTAB_BEGIN \
+ .data 2 ;\
+ENTRY(idt_inittab) ;\
+ .text
+
+/*
+ * Interrupt descriptor table and code vectors for it.
+ */
+#define IDT_ENTRY(n,entry,type) \
+ .data 2 ;\
+ .long entry ;\
+ .word n ;\
+ .word type ;\
+ .text
+
+/*
+ * Terminator for the end of the table.
+ */
+#define IDT_INITTAB_END \
+ .data 2 ;\
+ .long 0 ;\
+ .text
+
+
+#endif _I386_UTIL_IDT_INITTAB_H_
diff --git a/i386/util/ldt.h b/i386/util/ldt.h
new file mode 100644
index 0000000..135632f
--- /dev/null
+++ b/i386/util/ldt.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 1995-1994 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+#ifndef _I386_UTIL_LDT_
+#define _I386_UTIL_LDT_
+
+#include "config.h"
+
+/* If more-specific code wants a standard LDT,
+ then it should define ENABLE_KERNEL_LDT in config.h. */
+#ifdef ENABLE_KERNEL_LDT
+
+#include <mach/machine/seg.h>
+
+/* Fill a segment descriptor in a CPU's master LDT. */
+#define fill_ldt_descriptor(cpu, selector, base, limit, access, sizebits) \
+ fill_descriptor(&(cpu)->tables.ldt[(selector)/8], \
+ base, limit, access, sizebits)
+
+#define fill_ldt_gate(cpu, selector, offset, dest_selector, access, word_count) \
+ fill_gate((struct i386_gate*)&(cpu)->tables.ldt[(selector)/8], \
+ offset, dest_selector, access, word_count)
+
+#endif ENABLE_KERNEL_LDT
+
+#endif _I386_UTIL_LDT_
diff --git a/i386/util/trap.h b/i386/util/trap.h
new file mode 100644
index 0000000..98d586c
--- /dev/null
+++ b/i386/util/trap.h
@@ -0,0 +1,100 @@
+/*
+ * Mach Operating System
+ * Copyright (c) 1991,1990,1989 Carnegie Mellon University.
+ * Copyright (c) 1994 The University of Utah and
+ * the Center for Software Science (CSS).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON, THE UNIVERSITY OF UTAH AND CSS ALLOW FREE USE OF
+ * THIS SOFTWARE IN ITS "AS IS" CONDITION, AND DISCLAIM ANY LIABILITY
+ * OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF
+ * THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie Mellon
+ * the rights to redistribute these changes.
+ */
+#ifndef _I386_MOSS_TRAP_H_
+#define _I386_MOSS_TRAP_H_
+
+#ifndef ASSEMBLER
+
+
+/* This structure corresponds to the state of user registers
+ as saved upon kernel trap/interrupt entry.
+ As always, it is only a default implementation;
+ a well-optimized microkernel will probably want to override it
+ with something that allows better optimization. */
+
+struct trap_state {
+
+ /* Saved segment registers */
+ unsigned int gs;
+ unsigned int fs;
+ unsigned int es;
+ unsigned int ds;
+
+ /* PUSHA register state frame */
+ unsigned int edi;
+ unsigned int esi;
+ unsigned int ebp;
+ unsigned int cr2; /* we save cr2 over esp for page faults */
+ unsigned int ebx;
+ unsigned int edx;
+ unsigned int ecx;
+ unsigned int eax;
+
+ unsigned int trapno;
+ unsigned int err;
+
+ /* Processor state frame */
+ unsigned int eip;
+ unsigned int cs;
+ unsigned int eflags;
+ unsigned int esp;
+ unsigned int ss;
+
+ /* Virtual 8086 segment registers */
+ unsigned int v86_es;
+ unsigned int v86_ds;
+ unsigned int v86_fs;
+ unsigned int v86_gs;
+};
+
+/* The actual trap_state frame pushed by the processor
+ varies in size depending on where the trap came from. */
+#define TR_KSIZE ((int)&((struct trap_state*)0)->esp)
+#define TR_USIZE ((int)&((struct trap_state*)0)->v86_es)
+#define TR_V86SIZE sizeof(struct trap_state)
+
+
+#else ASSEMBLER
+
+#include <mach/machine/asm.h>
+
+#define UNEXPECTED_TRAP \
+ movw %ss,%ax ;\
+ movw %ax,%ds ;\
+ movw %ax,%es ;\
+ movl %esp,%eax ;\
+ pushl %eax ;\
+ call EXT(trap_dump_die) ;\
+
+
+#endif ASSEMBLER
+
+#include <mach/machine/trap.h>
+
+#endif _I386_MOSS_TRAP_H_
diff --git a/i386/util/trap_asm.sym b/i386/util/trap_asm.sym
new file mode 100644
index 0000000..ef95638
--- /dev/null
+++ b/i386/util/trap_asm.sym
@@ -0,0 +1,45 @@
+/*
+ * MOSS - DOS extender built from the Mach 4 source tree
+ * Copyright (C) 1995-1994 Sleepless Software
+ *
+ * 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.
+ *
+ * Author: Bryan Ford
+ */
+
+#include "trap.h"
+
+offset trap_state tr edi
+offset trap_state tr esi
+offset trap_state tr ebp
+offset trap_state tr ebx
+offset trap_state tr edx
+offset trap_state tr ecx
+offset trap_state tr eax
+offset trap_state tr trapno
+offset trap_state tr err
+offset trap_state tr eip
+offset trap_state tr cs
+offset trap_state tr eflags
+offset trap_state tr esp
+offset trap_state tr ss
+offset trap_state tr v86_es
+offset trap_state tr v86_ds
+offset trap_state tr v86_fs
+offset trap_state tr v86_gs
+expr TR_KSIZE
+expr TR_USIZE
+expr TR_V86SIZE
+
diff --git a/i386/util/trap_dump.c b/i386/util/trap_dump.c
new file mode 100644
index 0000000..62540d5
--- /dev/null
+++ b/i386/util/trap_dump.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 1994 The University of Utah and
+ * the Center for Software Science (CSS). All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * THE UNIVERSITY OF UTAH AND CSS ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSS DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSS requests users of this software to return to css-dist@cs.utah.edu any
+ * improvements that they make and grant CSS redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSS
+ */
+
+#include <mach/machine/eflags.h>
+#include <mach/machine/proc_reg.h>
+
+#include "vm_param.h"
+#include "trap.h"
+
+void trap_dump(struct trap_state *st)
+{
+ short flags;
+ int from_user = (st->cs & 3) || (st->eflags & EFL_VM);
+ unsigned *dump_sp = 0;
+ int i;
+
+ printf("Dump of trap_state at %08x:\n", st);
+ printf("EAX %08x EBX %08x ECX %08x EDX %08x\n",
+ st->eax, st->ebx, st->ecx, st->edx);
+ printf("ESI %08x EDI %08x EBP %08x ESP %08x\n",
+ st->esi, st->edi, st->ebp,
+ from_user ? st->esp : (unsigned)&st->esp);
+ printf("EIP %08x EFLAGS %08x\n", st->eip, st->eflags);
+ printf("CS %04x SS %04x DS %04x ES %04x FS %04x GS %04x\n",
+ st->cs & 0xffff, from_user ? st->ss & 0xffff : get_ss(),
+ st->ds & 0xffff, st->es & 0xffff,
+ st->fs & 0xffff, st->gs & 0xffff);
+ printf("v86: DS %04x ES %04x FS %04x GS %04x\n",
+ st->v86_ds & 0xffff, st->v86_es & 0xffff,
+ st->v86_gs & 0xffff, st->v86_gs & 0xffff);
+ printf("trapno %d, error %08x, from %s mode\n",
+ st->trapno, st->err, from_user ? "user" : "kernel");
+ if (st->trapno == T_PAGE_FAULT)
+ printf("page fault linear address %08x\n", st->cr2);
+
+ /* Dump the top of the stack too. */
+ if (!from_user)
+ {
+ for (i = 0; i < 32; i++)
+ {
+ printf("%08x%c", (&st->esp)[i],
+ ((i & 7) == 7) ? '\n' : ' ');
+ }
+ }
+}
+
diff --git a/i386/util/trap_dump_die.c b/i386/util/trap_dump_die.c
new file mode 100644
index 0000000..0407657
--- /dev/null
+++ b/i386/util/trap_dump_die.c
@@ -0,0 +1,12 @@
+
+#include "trap.h"
+
+void trap_dump_die(struct trap_state *st)
+{
+ about_to_die(1);
+
+ trap_dump(st);
+
+ die("terminated due to trap\n");
+}
+
diff --git a/i386/util/trap_handler.S b/i386/util/trap_handler.S
new file mode 100644
index 0000000..f11ba10
--- /dev/null
+++ b/i386/util/trap_handler.S
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 1995-1994 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+
+#include <mach/machine/asm.h>
+
+#include "trap.h"
+
+ .text
+
+ENTRY(trap_handler)
+ UNEXPECTED_TRAP
+
diff --git a/i386/util/trap_return.S b/i386/util/trap_return.S
new file mode 100644
index 0000000..b122312
--- /dev/null
+++ b/i386/util/trap_return.S
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 1995-1994 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+
+#include <mach/machine/asm.h>
+
+#include "trap.h"
+
+ .text
+
+ENTRY(trap_return)
+ popl %gs
+ popl %fs
+ popl %es
+ popl %ds
+ popa
+ addl $4*2,%esp
+ iret
+
+
diff --git a/i386/util/tss.c b/i386/util/tss.c
new file mode 100644
index 0000000..a9be7bf
--- /dev/null
+++ b/i386/util/tss.c
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 1995-1994 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+
+#include <mach/machine/tss.h>
+#include <mach/machine/proc_reg.h>
+
+#include "cpu.h"
+
+#ifdef ENABLE_KERNEL_TSS
+
+void
+cpu_tss_init(struct cpu *cpu)
+{
+ /* Only initialize once. */
+ if (!cpu->tables.tss.ss0)
+ {
+ /* Initialize the master TSS. */
+ cpu->tables.tss.ss0 = KERNEL_DS;
+ cpu->tables.tss.esp0 = get_esp(); /* only temporary */
+ cpu->tables.tss.io_bit_map_offset = sizeof(cpu->tables.tss);
+ }
+}
+
+#endif
+
diff --git a/i386/util/tss.h b/i386/util/tss.h
new file mode 100644
index 0000000..8ecabf5
--- /dev/null
+++ b/i386/util/tss.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 1995-1994 The University of Utah and
+ * the Computer Systems Laboratory at the University of Utah (CSL).
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software is hereby
+ * granted provided that (1) source code retains these copyright, permission,
+ * and disclaimer notices, and (2) redistributions including binaries
+ * reproduce the notices in supporting documentation, and (3) all advertising
+ * materials mentioning features or use of this software display the following
+ * acknowledgement: ``This product includes software developed by the
+ * Computer Systems Laboratory at the University of Utah.''
+ *
+ * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSL requests users of this software to return to csl-dist@cs.utah.edu any
+ * improvements that they make and grant CSL redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSL
+ */
+#ifndef _I386_KTSS_
+#define _I386_KTSS_
+
+#include <mach/machine/tss.h>
+
+extern struct i386_tss ktss;
+
+#endif _I386_KTSS_
diff --git a/i386/util/tss_dump.c b/i386/util/tss_dump.c
new file mode 100644
index 0000000..037774e
--- /dev/null
+++ b/i386/util/tss_dump.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 1994 The University of Utah and
+ * the Center for Software Science (CSS). All rights reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * THE UNIVERSITY OF UTAH AND CSS ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
+ * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSS DISCLAIM ANY LIABILITY OF
+ * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * CSS requests users of this software to return to css-dist@cs.utah.edu any
+ * improvements that they make and grant CSS redistribution rights.
+ *
+ * Author: Bryan Ford, University of Utah CSS
+ */
+
+#include <mach/machine/tss.h>
+
+void tss_dump(struct i386_tss *tss)
+{
+ printf("Dump of TSS at %08x:\n", tss);
+ printf("back_link %04x\n", tss->back_link & 0xffff);
+ printf("ESP0 %08x SS0 %04x\n", tss->esp0, tss->ss0 & 0xffff);
+ printf("ESP1 %08x SS1 %04x\n", tss->esp1, tss->ss1 & 0xffff);
+ printf("ESP2 %08x SS2 %04x\n", tss->esp2, tss->ss2 & 0xffff);
+ printf("CR3 %08x\n", tss->cr3);
+ printf("EIP %08x EFLAGS %08x\n", tss->eip, tss->eflags);
+ printf("EAX %08x EBX %08x ECX %08x EDX %08x\n",
+ tss->eax, tss->ebx, tss->ecx, tss->edx);
+ printf("ESI %08x EDI %08x EBP %08x ESP %08x\n",
+ tss->esi, tss->edi, tss->ebp, tss->esp);
+ printf("CS %04x SS %04x DS %04x ES %04x FS %04x GS %04x\n",
+ tss->cs & 0xffff, tss->ss & 0xffff,
+ tss->ds & 0xffff, tss->es & 0xffff,
+ tss->fs & 0xffff, tss->gs & 0xffff);
+ printf("LDT %04x\n", tss->ldt & 0xffff);
+ printf("trace_trap %04x\n", tss->trace_trap);
+ printf("IOPB offset %04x\n", tss->io_bit_map_offset);
+}
+
diff --git a/i386/util/vm_param.h b/i386/util/vm_param.h
new file mode 100644
index 0000000..c24ed07
--- /dev/null
+++ b/i386/util/vm_param.h
@@ -0,0 +1,89 @@
+/*
+ * Mach Operating System
+ * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
+ * All Rights Reserved.
+ *
+ * Permission to use, copy, modify and distribute this software and its
+ * documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie Mellon
+ * the rights to redistribute these changes.
+ */
+/*
+ * File: vm_param.h
+ * Author: Avadis Tevanian, Jr.
+ * Date: 1985
+ *
+ * I386 machine dependent virtual memory parameters.
+ * Most of the declarations are preceeded by I386_ (or i386_)
+ * which is OK because only I386 specific code will be using
+ * them.
+ */
+
+#ifndef _I386_KERNEL_UTIL_VM_PARAM_H_
+#define _I386_KERNEL_UTIL_VM_PARAM_H_
+
+#include <mach/vm_param.h>
+
+
+/* This variable is expected always to contain
+ the kernel virtual address at which physical memory is mapped.
+ It may change as paging is turned on or off. */
+extern vm_offset_t phys_mem_va;
+
+
+/* Calculate a kernel virtual address from a physical address. */
+#define phystokv(pa) ((vm_offset_t)(pa) + phys_mem_va)
+
+/* Same, but in reverse.
+ This only works for the region of kernel virtual addresses
+ that directly map physical addresses. */
+#define kvtophys(va) ((vm_offset_t)(va) - phys_mem_va)
+
+
+/* This variable contains the kernel virtual address
+ corresponding to linear address 0.
+ In the absence of paging,
+ linear addresses are always the same as physical addresses. */
+#ifndef linear_base_va
+#define linear_base_va phys_mem_va
+#endif
+
+/* Convert between linear and kernel virtual addresses. */
+#define lintokv(la) ((vm_offset_t)(la) + linear_base_va)
+#define kvtolin(va) ((vm_offset_t)(va) - linear_base_va)
+
+
+/* This variable keeps track of where in physical memory
+ our boot image was loaded.
+ It holds the physical address
+ corresponding to the boot image's virtual address 0.
+ When paging is disabled, this is simply -phys_mem_va.
+ However, when paging is enabled,
+ phys_mem_va points to the place physical memory is mapped into exec space,
+ and has no relationship to where in physical memory the boot image is.
+ Thus, this variable always contains the location of the boot image
+ whether or not paging is enabled. */
+extern vm_offset_t boot_image_pa;
+
+/* Code segment we originally had when we started in real mode.
+ Always equal to boot_image_pa >> 4. */
+extern unsigned short real_cs;
+
+
+
+#endif /* _I386_KERNEL_UTIL_VM_PARAM_H_ */