Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Apr 2009 21:04:50 GMT
From:      Marko Zec <zec@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 160293 for review
Message-ID:  <200904062104.n36L4oYf069574@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=160293

Change 160293 by zec@zec_amdx2 on 2009/04/06 21:04:05

	IFC @ 160223

Affected files ...

.. //depot/projects/vimage-commit2/src/sys/amd64/acpica/acpi_switch.S#2 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/acpica/acpi_wakecode.S#2 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/acpica/acpi_wakeup.c#3 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/amd64/apic_vector.S#3 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/amd64/cpu_switch.S#7 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/amd64/db_interface.c#2 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/amd64/db_trace.c#4 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/amd64/elf_machdep.c#5 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/amd64/exception.S#5 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/amd64/genassym.c#6 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/amd64/machdep.c#8 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/amd64/mp_machdep.c#10 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/amd64/sys_machdep.c#2 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/amd64/trap.c#5 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/amd64/vm_machdep.c#6 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/ia32/ia32_exception.S#2 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/ia32/ia32_misc.c#1 branch
.. //depot/projects/vimage-commit2/src/sys/amd64/ia32/ia32_reg.c#2 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/ia32/ia32_signal.c#6 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/ia32/ia32_sigtramp.S#3 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/include/asmacros.h#2 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/include/frame.h#2 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/include/md_var.h#5 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/include/pcb.h#6 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/include/pcpu.h#5 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/include/proc.h#2 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/include/reg.h#2 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/include/segments.h#3 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/include/signal.h#2 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/include/sysarch.h#2 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/include/ucontext.h#2 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/linux32/linux32_locore.s#4 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/linux32/linux32_machdep.c#7 integrate
.. //depot/projects/vimage-commit2/src/sys/amd64/linux32/linux32_sysvec.c#7 integrate
.. //depot/projects/vimage-commit2/src/sys/arm/arm/elf_machdep.c#6 integrate
.. //depot/projects/vimage-commit2/src/sys/arm/include/vmparam.h#3 integrate
.. //depot/projects/vimage-commit2/src/sys/cam/cam_xpt.c#4 integrate
.. //depot/projects/vimage-commit2/src/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c#3 integrate
.. //depot/projects/vimage-commit2/src/sys/compat/freebsd32/freebsd32.h#3 integrate
.. //depot/projects/vimage-commit2/src/sys/compat/freebsd32/freebsd32_proto.h#12 integrate
.. //depot/projects/vimage-commit2/src/sys/compat/freebsd32/freebsd32_syscall.h#12 integrate
.. //depot/projects/vimage-commit2/src/sys/compat/freebsd32/freebsd32_syscalls.c#12 integrate
.. //depot/projects/vimage-commit2/src/sys/compat/freebsd32/freebsd32_sysent.c#12 integrate
.. //depot/projects/vimage-commit2/src/sys/compat/freebsd32/syscalls.master#12 integrate
.. //depot/projects/vimage-commit2/src/sys/compat/ia32/ia32_signal.h#2 integrate
.. //depot/projects/vimage-commit2/src/sys/compat/ia32/ia32_sysvec.c#6 integrate
.. //depot/projects/vimage-commit2/src/sys/conf/files.amd64#11 integrate
.. //depot/projects/vimage-commit2/src/sys/conf/files.ia64#5 integrate
.. //depot/projects/vimage-commit2/src/sys/conf/files.powerpc#9 integrate
.. //depot/projects/vimage-commit2/src/sys/contrib/dev/uath/ar5523.bin.uu#1 branch
.. //depot/projects/vimage-commit2/src/sys/dev/acpi_support/acpi_asus.c#8 integrate
.. //depot/projects/vimage-commit2/src/sys/dev/ata/chipsets/ata-serverworks.c#4 integrate
.. //depot/projects/vimage-commit2/src/sys/dev/drm/drm_pciids.h#6 integrate
.. //depot/projects/vimage-commit2/src/sys/dev/drm/r600_cp.c#3 integrate
.. //depot/projects/vimage-commit2/src/sys/dev/drm/radeon_cp.c#8 integrate
.. //depot/projects/vimage-commit2/src/sys/dev/ed/dl100xxreg.h#2 integrate
.. //depot/projects/vimage-commit2/src/sys/dev/ed/if_ed_pccard.c#6 integrate
.. //depot/projects/vimage-commit2/src/sys/dev/ed/if_edvar.h#3 integrate
.. //depot/projects/vimage-commit2/src/sys/dev/pccbb/pccbb_pci.c#7 integrate
.. //depot/projects/vimage-commit2/src/sys/dev/pci/pci.c#10 integrate
.. //depot/projects/vimage-commit2/src/sys/dev/powermac_nvram/powermac_nvram.c#4 integrate
.. //depot/projects/vimage-commit2/src/sys/dev/sound/pci/hda/hdac.c#13 integrate
.. //depot/projects/vimage-commit2/src/sys/dev/uart/uart_cpu_powerpc.c#2 integrate
.. //depot/projects/vimage-commit2/src/sys/dev/usb/controller/usb_controller.c#4 integrate
.. //depot/projects/vimage-commit2/src/sys/dev/usb/wlan/if_uath.c#1 branch
.. //depot/projects/vimage-commit2/src/sys/dev/usb/wlan/if_uathreg.h#1 branch
.. //depot/projects/vimage-commit2/src/sys/dev/usb/wlan/if_uathvar.h#1 branch
.. //depot/projects/vimage-commit2/src/sys/dev/xen/balloon/balloon.c#3 integrate
.. //depot/projects/vimage-commit2/src/sys/dev/xen/console/console.c#7 integrate
.. //depot/projects/vimage-commit2/src/sys/geom/geom.h#3 integrate
.. //depot/projects/vimage-commit2/src/sys/geom/geom_disk.c#5 integrate
.. //depot/projects/vimage-commit2/src/sys/geom/geom_disk.h#2 integrate
.. //depot/projects/vimage-commit2/src/sys/geom/geom_subr.c#5 integrate
.. //depot/projects/vimage-commit2/src/sys/geom/journal/g_journal.c#6 integrate
.. //depot/projects/vimage-commit2/src/sys/geom/mirror/g_mirror.c#2 integrate
.. //depot/projects/vimage-commit2/src/sys/geom/part/g_part.c#9 integrate
.. //depot/projects/vimage-commit2/src/sys/geom/part/g_part_ebr.c#3 integrate
.. //depot/projects/vimage-commit2/src/sys/geom/raid3/g_raid3.c#2 integrate
.. //depot/projects/vimage-commit2/src/sys/i386/i386/elf_machdep.c#5 integrate
.. //depot/projects/vimage-commit2/src/sys/i386/i386/machdep.c#9 integrate
.. //depot/projects/vimage-commit2/src/sys/i386/include/signal.h#2 integrate
.. //depot/projects/vimage-commit2/src/sys/i386/include/ucontext.h#2 integrate
.. //depot/projects/vimage-commit2/src/sys/i386/include/vmparam.h#3 integrate
.. //depot/projects/vimage-commit2/src/sys/i386/include/xen/xenpmap.h#5 integrate
.. //depot/projects/vimage-commit2/src/sys/i386/include/xen/xenvar.h#4 integrate
.. //depot/projects/vimage-commit2/src/sys/i386/linux/linux_sysvec.c#7 integrate
.. //depot/projects/vimage-commit2/src/sys/i386/xen/pmap.c#7 integrate
.. //depot/projects/vimage-commit2/src/sys/i386/xen/xen_machdep.c#13 integrate
.. //depot/projects/vimage-commit2/src/sys/ia64/ia32/ia32_misc.c#1 branch
.. //depot/projects/vimage-commit2/src/sys/ia64/ia64/elf_machdep.c#5 integrate
.. //depot/projects/vimage-commit2/src/sys/kern/imgact_elf.c#6 integrate
.. //depot/projects/vimage-commit2/src/sys/kern/kern_shutdown.c#5 integrate
.. //depot/projects/vimage-commit2/src/sys/kern/vfs_cache.c#13 integrate
.. //depot/projects/vimage-commit2/src/sys/kern/vfs_mount.c#14 integrate
.. //depot/projects/vimage-commit2/src/sys/mips/mips/elf64_machdep.c#3 integrate
.. //depot/projects/vimage-commit2/src/sys/mips/mips/elf_machdep.c#6 integrate
.. //depot/projects/vimage-commit2/src/sys/modules/usb/uath/Makefile#1 branch
.. //depot/projects/vimage-commit2/src/sys/net/bpf.h#4 integrate
.. //depot/projects/vimage-commit2/src/sys/net80211/ieee80211_freebsd.h#8 integrate
.. //depot/projects/vimage-commit2/src/sys/net80211/ieee80211_output.c#9 integrate
.. //depot/projects/vimage-commit2/src/sys/net80211/ieee80211_wds.c#7 integrate
.. //depot/projects/vimage-commit2/src/sys/netinet/igmp.c#22 integrate
.. //depot/projects/vimage-commit2/src/sys/netinet/ip_fw.h#21 integrate
.. //depot/projects/vimage-commit2/src/sys/netinet/ip_fw2.c#37 integrate
.. //depot/projects/vimage-commit2/src/sys/netinet/ip_fw_pfil.c#15 integrate
.. //depot/projects/vimage-commit2/src/sys/netinet/sctp_indata.c#10 integrate
.. //depot/projects/vimage-commit2/src/sys/netinet/sctp_input.c#11 integrate
.. //depot/projects/vimage-commit2/src/sys/netinet/sctp_output.c#16 integrate
.. //depot/projects/vimage-commit2/src/sys/netinet/sctp_pcb.c#19 integrate
.. //depot/projects/vimage-commit2/src/sys/netinet/sctp_structs.h#5 integrate
.. //depot/projects/vimage-commit2/src/sys/netinet/sctp_sysctl.c#8 integrate
.. //depot/projects/vimage-commit2/src/sys/netinet/sctp_sysctl.h#6 integrate
.. //depot/projects/vimage-commit2/src/sys/netinet/sctp_uio.h#7 integrate
.. //depot/projects/vimage-commit2/src/sys/netinet/sctp_usrreq.c#14 integrate
.. //depot/projects/vimage-commit2/src/sys/netinet/sctputil.c#13 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/aim/machdep.c#5 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/aim/mmu_oea.c#6 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/aim/mmu_oea64.c#1 branch
.. //depot/projects/vimage-commit2/src/sys/powerpc/aim/mp_cpudep.c#3 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/aim/ofw_machdep.c#4 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/aim/swtch.S#4 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/aim/trap_subr.S#4 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/aim/uio_machdep.c#2 delete
.. //depot/projects/vimage-commit2/src/sys/powerpc/aim/uma_machdep.c#2 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/aim/vm_machdep.c#3 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/booke/machdep.c#6 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/booke/pmap.c#7 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/booke/uio_machdep.c#2 delete
.. //depot/projects/vimage-commit2/src/sys/powerpc/include/hid.h#2 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/include/intr.h#2 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/include/md_var.h#3 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/include/pmap.h#4 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/include/sf_buf.h#2 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/include/spr.h#5 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/include/sysarch.h#1 branch
.. //depot/projects/vimage-commit2/src/sys/powerpc/include/vmparam.h#2 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/ofw/ofw_syscons.c#6 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/powermac/cpcht.c#1 branch
.. //depot/projects/vimage-commit2/src/sys/powerpc/powermac/cpchtvar.h#1 branch
.. //depot/projects/vimage-commit2/src/sys/powerpc/powerpc/bus_machdep.c#2 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/powerpc/cpu.c#5 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/powerpc/dump_machdep.c#1 branch
.. //depot/projects/vimage-commit2/src/sys/powerpc/powerpc/elf_machdep.c#5 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/powerpc/mem.c#3 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/powerpc/mmu_if.m#2 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/powerpc/pmap_dispatch.c#4 integrate
.. //depot/projects/vimage-commit2/src/sys/powerpc/powerpc/uio_machdep.c#1 branch
.. //depot/projects/vimage-commit2/src/sys/sparc64/sparc64/elf_machdep.c#5 integrate
.. //depot/projects/vimage-commit2/src/sys/sys/imgact_elf.h#4 integrate
.. //depot/projects/vimage-commit2/src/sys/sys/kerneldump.h#3 integrate
.. //depot/projects/vimage-commit2/src/sys/sys/systm.h#8 integrate
.. //depot/projects/vimage-commit2/src/sys/ufs/ffs/ffs_softdep.c#6 integrate
.. //depot/projects/vimage-commit2/src/sys/vm/vm_mmap.c#8 integrate
.. //depot/projects/vimage-commit2/src/sys/xen/evtchn/evtchn.c#7 integrate
.. //depot/projects/vimage-commit2/src/sys/xen/reboot.c#2 integrate

Differences ...

==== //depot/projects/vimage-commit2/src/sys/amd64/acpica/acpi_switch.S#2 (text+ko) ====

@@ -25,7 +25,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/amd64/acpica/acpi_switch.S,v 1.1 2009/03/17 00:48:11 jkim Exp $
+ * $FreeBSD: src/sys/amd64/acpica/acpi_switch.S,v 1.4 2009/04/02 01:46:57 jkim Exp $
  */
 
 #include <machine/asmacros.h>
@@ -64,12 +64,15 @@
 	/* Fetch PCB. */
 	movq	WAKEUP_CTX(xpcb), %r11
 
-	/* Restore segment registers. */
-	mov	WAKEUP_PCB(DS), %ds
-	mov	WAKEUP_PCB(ES), %es
-	mov	WAKEUP_XPCB(SS), %ss
-	mov	WAKEUP_PCB(FS), %fs
-	mov	WAKEUP_PCB(GS), %gs
+	/* Force kernel segment registers. */
+	movl	$KDSEL, %eax
+	movw	%ax, %ds
+	movw	%ax, %es
+	movw	%ax, %ss
+	movl	$KUF32SEL, %eax
+	movw	%ax, %fs
+	movl	$KUG32SEL, %eax
+	movw	%ax, %gs
 
 	movl	$MSR_FSBASE, %ecx
 	movl	WAKEUP_PCB(FSBASE), %eax
@@ -123,9 +126,19 @@
 	/* Restore descriptor tables. */
 	lidt	WAKEUP_XPCB(IDT)
 	lldt	WAKEUP_XPCB(LDT)
+
+#define	SDT_SYSTSS	9
+#define	SDT_SYSBSY	11
+
+	/* Clear "task busy" bit and reload TR. */
+	movq	PCPU(TSS), %rax
+	andb	$(~SDT_SYSBSY | SDT_SYSTSS), 5(%rax)
 	movw	WAKEUP_XPCB(TR), %ax
 	ltr	%ax
 
+#undef	SDT_SYSTSS
+#undef	SDT_SYSBSY
+
 	/* Restore other callee saved registers. */
 	movq	WAKEUP_PCB(R15), %r15
 	movq	WAKEUP_PCB(R14), %r14

==== //depot/projects/vimage-commit2/src/sys/amd64/acpica/acpi_wakecode.S#2 (text+ko) ====

@@ -26,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/amd64/acpica/acpi_wakecode.S,v 1.2 2009/03/23 22:35:30 jkim Exp $
+ * $FreeBSD: src/sys/amd64/acpica/acpi_wakecode.S,v 1.3 2009/04/02 00:23:56 jkim Exp $
  */
 
 #define LOCORE
@@ -223,6 +223,12 @@
 bootgdt:
 	.long	0x00000000
 	.long	0x00000000
+	.long	0x00000000
+	.long	0x00000000
+	.long	0x00000000
+	.long	0x00000000
+	.long	0x00000000
+	.long	0x00000000
 
 bootcode64:
 	.long	0x0000ffff
@@ -261,6 +267,8 @@
 wakeup_gdt:
 	.word	0
 	.quad	0
+
+	ALIGN_DATA
 wakeup_efer:
 	.quad	0
 wakeup_pat:

==== //depot/projects/vimage-commit2/src/sys/amd64/acpica/acpi_wakeup.c#3 (text+ko) ====

@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/amd64/acpica/acpi_wakeup.c,v 1.24 2009/03/23 22:35:30 jkim Exp $");
+__FBSDID("$FreeBSD: src/sys/amd64/acpica/acpi_wakeup.c,v 1.25 2009/04/02 00:23:56 jkim Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -78,7 +78,6 @@
 int			acpi_restorecpu(struct xpcb *, vm_offset_t);
 int			acpi_savecpu(struct xpcb *);
 
-static void		acpi_reset_tss(int cpu);
 static void		acpi_alloc_wakeup_handler(void);
 static void		acpi_stop_beep(void *);
 
@@ -116,8 +115,6 @@
 	    stopxpcbs[cpu].xpcb_gdt.rd_base);
 	WAKECODE_FIXUP(wakeup_cpu, int, cpu);
 
-	acpi_reset_tss(cpu);
-
 	/* do an INIT IPI: assert RESET */
 	lapic_ipi_raw(APIC_DEST_DESTFLD | APIC_TRIGMOD_EDGE |
 	    APIC_LEVEL_ASSERT | APIC_DESTMODE_PHY | APIC_DELMODE_INIT, apic_id);
@@ -220,19 +217,6 @@
 }
 #endif
 
-static void
-acpi_reset_tss(int cpu)
-{
-	uint32_t	*tss;
-
-	/*
-	 * We have to clear "task busy" bit in TSS to restore
-	 * task register later.  Otherwise, ltr causes GPF.
-	 */
-	tss = (uint32_t *)&gdt[NGDT * cpu + GPROC0_SEL] + 1;
-	*tss &= ~((SDT_SYSBSY ^ SDT_SYSTSS) << 8);
-}
-
 int
 acpi_sleep_machdep(struct acpi_softc *sc, int state)
 {
@@ -289,8 +273,6 @@
 		    stopxpcbs[0].xpcb_gdt.rd_base);
 		WAKECODE_FIXUP(wakeup_cpu, int, 0);
 
-		acpi_reset_tss(0);
-
 		/* Call ACPICA to enter the desired sleep state */
 		if (state == ACPI_STATE_S4 && sc->acpi_s4bios)
 			status = AcpiEnterSleepStateS4bios();

==== //depot/projects/vimage-commit2/src/sys/amd64/amd64/apic_vector.S#3 (text+ko) ====

@@ -28,7 +28,7 @@
  * SUCH DAMAGE.
  *
  *	from: vector.s, 386BSD 0.1 unknown origin
- * $FreeBSD: src/sys/amd64/amd64/apic_vector.S,v 1.111 2009/03/17 00:48:11 jkim Exp $
+ * $FreeBSD: src/sys/amd64/amd64/apic_vector.S,v 1.112 2009/04/01 13:09:26 kib Exp $
  */
 
 /*
@@ -219,10 +219,8 @@
 	movl	$0, LA_EOI(%rax)	/* End Of Interrupt to APIC */
 
 	call	cpustop_handler
+	jmp	doreti
 
-	POP_FRAME
-	iretq
-
 /*
  * Executed by a CPU when it receives an IPI_SUSPEND from another CPU.
  */
@@ -251,6 +249,5 @@
 	call	smp_rendezvous_action
 	movq	lapic, %rax
 	movl	$0, LA_EOI(%rax)	/* End Of Interrupt to APIC */
-	POP_FRAME			/* Why not doreti? */
-	iretq
+	jmp	doreti
 #endif /* SMP */

==== //depot/projects/vimage-commit2/src/sys/amd64/amd64/cpu_switch.S#7 (text+ko) ====

@@ -30,7 +30,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/amd64/amd64/cpu_switch.S,v 1.167 2009/03/17 00:48:11 jkim Exp $
+ * $FreeBSD: src/sys/amd64/amd64/cpu_switch.S,v 1.168 2009/04/01 13:09:26 kib Exp $
  */
 
 #include <machine/asmacros.h>
@@ -75,8 +75,6 @@
 1:
 	movq	TD_PCB(%rdi),%r8		/* Old pcb */
 	movl	PCPU(CPUID), %eax
-	movq	PCB_FSBASE(%r8),%r9
-	movq	PCB_GSBASE(%r8),%r10
 	/* release bit from old pm_active */
 	movq	TD_PROC(%rdi), %rdx		/* oldtd->td_proc */
 	movq	P_VMSPACE(%rdx), %rdx		/* proc->p_vmspace */
@@ -110,28 +108,6 @@
 	movq	%rbx,PCB_RBX(%r8)
 	movq	%rax,PCB_RIP(%r8)
 
-	/*
-	 * Reread fs and gs bases. Explicit fs segment register load
-	 * by the usermode code may change actual fs base without
-	 * updating pcb_{fs,gs}base.
-	 *
-	 * %rdx still contains the mtx, save %rdx around rdmsr.
-	 */
-	movq	%rdx,%r11
-	movl	$MSR_FSBASE,%ecx
-	rdmsr
-	shlq	$32,%rdx
-	leaq	(%rax,%rdx),%r9
-	movl	$MSR_KGSBASE,%ecx
-	rdmsr
-	shlq	$32,%rdx
-	leaq	(%rax,%rdx),%r10
-	movq	%r11,%rdx
-
-	testl	$PCB_32BIT,PCB_FLAGS(%r8)
-	jnz	store_seg
-done_store_seg:
-
 	testl	$PCB_DBREGS,PCB_FLAGS(%r8)
 	jnz	store_dr			/* static predict not taken */
 done_store_dr:
@@ -192,36 +168,47 @@
 	testl	$TDP_KTHREAD,TD_PFLAGS(%rsi)
 	jnz	do_kthread
 
-	testl	$PCB_32BIT,PCB_FLAGS(%r8)
-	jnz	load_seg
-done_load_seg:
+	/*
+	 * Load ldt register
+	 */
+	movq	TD_PROC(%rsi),%rcx
+	cmpq	$0, P_MD+MD_LDT(%rcx)
+	jne	do_ldt
+	xorl	%eax,%eax
+ld_ldt:	lldt	%ax
 
-	cmpq	PCB_FSBASE(%r8),%r9
-	jz	1f
-	/* Restore userland %fs */
-restore_fsbase:
-	movl	$MSR_FSBASE,%ecx
+	/* Restore fs base in GDT */
 	movl	PCB_FSBASE(%r8),%eax
-	movl	PCB_FSBASE+4(%r8),%edx
-	wrmsr
-1:
-	cmpq	PCB_GSBASE(%r8),%r10
-	jz	2f
-	/* Restore userland %gs */
-	movl	$MSR_KGSBASE,%ecx
+	movq	PCPU(FS32P),%rdx
+	movw	%ax,2(%rdx)
+	shrl	$16,%eax
+	movb	%al,4(%rdx)
+	shrl	$8,%eax
+	movb	%al,7(%rdx)
+
+	/* Restore gs base in GDT */
 	movl	PCB_GSBASE(%r8),%eax
-	movl	PCB_GSBASE+4(%r8),%edx
-	wrmsr
-2:
+	movq	PCPU(GS32P),%rdx
+	movw	%ax,2(%rdx)
+	shrl	$16,%eax
+	movb	%al,4(%rdx)
+	shrl	$8,%eax
+	movb	%al,7(%rdx)
 
-do_tss:
+do_kthread:
+	/* Do we need to reload tss ? */
+	movq	PCPU(TSSP),%rax
+	movq	PCB_TSSP(%r8),%rdx
+	testq	%rdx,%rdx
+	cmovzq	PCPU(COMMONTSSP),%rdx
+	cmpq	%rax,%rdx
+	jne	do_tss
+done_tss:
+	movq	%r8,PCPU(RSP0)
+	movq	%r8,PCPU(CURPCB)
 	/* Update the TSS_RSP0 pointer for the next interrupt */
-	movq	PCPU(TSSP), %rax
-	movq	%r8, PCPU(RSP0)
-	movq	%r8, PCPU(CURPCB)
-	addq	$COMMON_TSS_RSP0, %rax
-	movq	%rsi, PCPU(CURTHREAD)		/* into next thread */
-	movq	%r8, (%rax)
+	movq	%r8,COMMON_TSS_RSP0(%rdx)
+	movq	%rsi,PCPU(CURTHREAD)		/* into next thread */
 
 	/* Test if debug registers should be restored. */
 	testl	$PCB_DBREGS,PCB_FLAGS(%r8)
@@ -250,45 +237,6 @@
 	 * We use jumps rather than call in order to avoid the stack.
 	 */
 
-do_kthread:
-	/*
-	 * Copy old fs/gsbase to new kthread pcb for future switches
-	 * This maintains curpcb->pcb_[fg]sbase as caches of the MSR
-	 */
-	movq	%r9,PCB_FSBASE(%r8)
-	movq	%r10,PCB_GSBASE(%r8)
-	jmp	do_tss
-
-store_seg:
-	mov	%gs,PCB_GS(%r8)
-	testl	$PCB_GS32BIT,PCB_FLAGS(%r8)
-	jnz	2f
-1:	mov	%ds,PCB_DS(%r8)
-	mov	%es,PCB_ES(%r8)
-	mov	%fs,PCB_FS(%r8)
-	jmp	done_store_seg
-2:	movq	PCPU(GS32P),%rax
-	movq	(%rax),%rax
-	movq	%rax,PCB_GS32SD(%r8)
-	jmp	1b
-
-load_seg:
-	testl	$PCB_GS32BIT,PCB_FLAGS(%r8)
-	jnz	2f
-1:	movl	$MSR_GSBASE,%ecx
-	rdmsr
-	mov	PCB_GS(%r8),%gs
-	wrmsr
-	mov	PCB_DS(%r8),%ds
-	mov	PCB_ES(%r8),%es
-	mov	PCB_FS(%r8),%fs
-	jmp	restore_fsbase
-	/* Restore userland %gs while preserving kernel gsbase */
-2:	movq	PCPU(GS32P),%rax
-	movq	PCB_GS32SD(%r8),%rcx
-	movq	%rcx,(%rax)
-	jmp	1b
-
 store_dr:
 	movq	%dr7,%rax			/* yes, do the save */
 	movq	%dr0,%r15
@@ -325,6 +273,29 @@
 	movq	%r11,%dr6
 	movq	%rax,%dr7
 	jmp	done_load_dr
+
+do_tss:	movq	%rdx,PCPU(TSSP)
+	movq	%rdx,%rcx
+	movq	PCPU(TSS),%rax
+	movw	%rcx,2(%rax)
+	shrq	$16,%rcx
+	movb	%cl,4(%rax)
+	shrq	$8,%rcx
+	movb	%cl,7(%rax)
+	shrq	$8,%rcx
+	movl	%ecx,8(%rax)
+	movb	$0x89,5(%rax)	/* unset busy */
+	movl	$TSSSEL,%eax
+	ltr	%ax
+	jmp	done_tss
+
+do_ldt:	movq	PCPU(LDT),%rax
+	movq	P_MD+MD_LDT_SD(%rcx),%rdx
+	movq	%rdx,(%rax)
+	movq	P_MD+MD_LDT_SD+8(%rcx),%rdx
+	movq	%rdx,8(%rax)
+	movl	$LDTSEL,%eax
+	jmp	ld_ldt
 END(cpu_switch)
 
 /*
@@ -398,12 +369,6 @@
 	movq	(%rsp),%rax
 	movq	%rax,PCB_RIP(%r8)
 
-	mov	%ds,PCB_DS(%r8)
-	mov	%es,PCB_ES(%r8)
-	mov	%ss,XPCB_SS(%r8)
-	mov	%fs,PCB_FS(%r8)
-	mov	%gs,PCB_GS(%r8)
-
 	movq	%rbx,PCB_RBX(%r8)
 	movq	%rsp,PCB_RSP(%r8)
 	movq	%rbp,PCB_RBP(%r8)

==== //depot/projects/vimage-commit2/src/sys/amd64/amd64/db_interface.c#2 (text+ko) ====

@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/amd64/amd64/db_interface.c,v 1.81 2005/01/05 20:17:20 imp Exp $");
+__FBSDID("$FreeBSD: src/sys/amd64/amd64/db_interface.c,v 1.82 2009/04/01 13:09:26 kib Exp $");
 
 /*
  * Interface to new debugger.
@@ -139,7 +139,11 @@
 db_show_mdpcpu(struct pcpu *pc)
 {
 
-#if 0
-	db_printf("currentldt   = 0x%x\n", pc->pc_currentldt);
-#endif
+	db_printf("curpmap		= %p\n", pc->pc_curpmap);
+	db_printf("tssp		= %p\n", pc->pc_tssp);
+	db_printf("commontssp	= %p\n", pc->pc_commontssp);
+	db_printf("rsp0		= 0x%lx\n", pc->pc_rsp0);
+	db_printf("gs32p		= %p\n", pc->pc_gs32p);
+	db_printf("ldt		= %p\n", pc->pc_ldt);
+	db_printf("tss		= %p\n", pc->pc_tss);
 }

==== //depot/projects/vimage-commit2/src/sys/amd64/amd64/db_trace.c#4 (text+ko) ====

@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/amd64/amd64/db_trace.c,v 1.84 2009/03/17 00:48:11 jkim Exp $");
+__FBSDID("$FreeBSD: src/sys/amd64/amd64/db_trace.c,v 1.85 2009/04/01 13:09:26 kib Exp $");
 
 #include "opt_compat.h"
 
@@ -69,12 +69,10 @@
 #define	DB_OFFSET(x)	(db_expr_t *)offsetof(struct trapframe, x)
 struct db_variable db_regs[] = {
 	{ "cs",		DB_OFFSET(tf_cs),	db_frame },
-#if 0
 	{ "ds",		DB_OFFSET(tf_ds),	db_frame },
 	{ "es",		DB_OFFSET(tf_es),	db_frame },
 	{ "fs",		DB_OFFSET(tf_fs),	db_frame },
 	{ "gs",		DB_OFFSET(tf_gs),	db_frame },
-#endif
 	{ "ss",		NULL,			db_ss },
 	{ "rax",	DB_OFFSET(tf_rax),	db_frame },
 	{ "rcx",        DB_OFFSET(tf_rcx),	db_frame },
@@ -94,7 +92,7 @@
 	{ "r15",	DB_OFFSET(tf_r15),	db_frame },
 	{ "rip",	DB_OFFSET(tf_rip),	db_frame },
 	{ "rflags",	DB_OFFSET(tf_rflags),	db_frame },
-#define	DB_N_SHOW_REGS	20	/* Don't show registers after here. */
+#define	DB_N_SHOW_REGS	24	/* Don't show registers after here. */
 	{ "dr0",	NULL,			db_dr0 },
 	{ "dr1",	NULL,			db_dr1 },
 	{ "dr2",	NULL,			db_dr2 },
@@ -357,7 +355,7 @@
 		rbp = tf->tf_rbp;
 		switch (frame_type) {
 		case TRAP:
-			db_printf("--- trap %#lr", tf->tf_trapno);
+			db_printf("--- trap %#r", tf->tf_trapno);
 			break;
 		case SYSCALL:
 			db_printf("--- syscall");

==== //depot/projects/vimage-commit2/src/sys/amd64/amd64/elf_machdep.c#5 (text+ko) ====

@@ -24,7 +24,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/amd64/amd64/elf_machdep.c,v 1.29 2009/03/13 16:40:51 dchagin Exp $");
+__FBSDID("$FreeBSD: src/sys/amd64/amd64/elf_machdep.c,v 1.30 2009/04/05 09:27:19 dchagin Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -85,7 +85,7 @@
 	.sysvec		= &elf64_freebsd_sysvec,
 	.interp_newpath	= NULL,
 	.brand_note	= &elf64_freebsd_brandnote,
-	.flags		= BI_CAN_EXEC_DYN
+	.flags		= BI_CAN_EXEC_DYN | BI_BRAND_NOTE
 };
 
 SYSINIT(elf64, SI_SUB_EXEC, SI_ORDER_ANY,
@@ -101,7 +101,7 @@
 	.sysvec		= &elf64_freebsd_sysvec,
 	.interp_newpath	= NULL,
 	.brand_note	= &elf64_freebsd_brandnote,
-	.flags		= BI_CAN_EXEC_DYN
+	.flags		= BI_CAN_EXEC_DYN | BI_BRAND_NOTE
 };
 
 SYSINIT(oelf64, SI_SUB_EXEC, SI_ORDER_ANY,

==== //depot/projects/vimage-commit2/src/sys/amd64/amd64/exception.S#5 (text+ko) ====

@@ -31,7 +31,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/amd64/amd64/exception.S,v 1.137 2009/02/03 09:01:45 jkoshy Exp $
+ * $FreeBSD: src/sys/amd64/amd64/exception.S,v 1.138 2009/04/01 13:09:26 kib Exp $
  */
 
 #include "opt_atpic.h"
@@ -42,6 +42,7 @@
 #include <machine/asmacros.h>
 #include <machine/psl.h>
 #include <machine/trap.h>
+#include <machine/specialreg.h>
 
 #include "assym.s"
 
@@ -99,7 +100,7 @@
 /* Traps that we leave interrupts disabled for.. */
 #define	TRAP_NOEN(a)	\
 	subq $TF_RIP,%rsp; \
-	movq $(a),TF_TRAPNO(%rsp) ; \
+	movl $(a),TF_TRAPNO(%rsp) ; \
 	movq $0,TF_ADDR(%rsp) ; \
 	movq $0,TF_ERR(%rsp) ; \
 	jmp alltraps_noen
@@ -111,7 +112,7 @@
 /* Regular traps; The cpu does not supply tf_err for these. */
 #define	TRAP(a)	 \
 	subq $TF_RIP,%rsp; \
-	movq $(a),TF_TRAPNO(%rsp) ; \
+	movl $(a),TF_TRAPNO(%rsp) ; \
 	movq $0,TF_ADDR(%rsp) ; \
 	movq $0,TF_ERR(%rsp) ; \
 	jmp alltraps
@@ -139,7 +140,7 @@
 /* This group of traps have tf_err already pushed by the cpu */
 #define	TRAP_ERR(a)	\
 	subq $TF_ERR,%rsp; \
-	movq $(a),TF_TRAPNO(%rsp) ; \
+	movl $(a),TF_TRAPNO(%rsp) ; \
 	movq $0,TF_ADDR(%rsp) ; \
 	jmp alltraps
 IDTVEC(tss)
@@ -164,6 +165,10 @@
 	testb	$SEL_RPL_MASK,TF_CS(%rsp) /* Did we come from kernel? */
 	jz	alltraps_testi		/* already running with kernel GS.base */
 	swapgs
+	movw	%fs,TF_FS(%rsp)
+	movw	%gs,TF_GS(%rsp)
+	movw	%es,TF_ES(%rsp)
+	movw	%ds,TF_DS(%rsp)
 alltraps_testi:
 	testl	$PSL_I,TF_RFLAGS(%rsp)
 	jz	alltraps_pushregs
@@ -185,6 +190,7 @@
 	movq	%r13,TF_R13(%rsp)
 	movq	%r14,TF_R14(%rsp)
 	movq	%r15,TF_R15(%rsp)
+	movl	$TF_HASSEGS,TF_FLAGS(%rsp)
 	FAKE_MCOUNT(TF_RIP(%rsp))
 #ifdef KDTRACE_HOOKS
 	/*
@@ -193,7 +199,7 @@
 	 * interrupt. For all other trap types, just handle them in
 	 * the usual way.
 	 */
-	cmpq	$T_BPTFLT,TF_TRAPNO(%rsp)
+	cmpl	$T_BPTFLT,TF_TRAPNO(%rsp)
 	jne	calltrap
 
 	/* Check if there is no DTrace hook registered. */
@@ -228,13 +234,17 @@
 	.type	alltraps_noen,@function
 alltraps_noen:
 	testb	$SEL_RPL_MASK,TF_CS(%rsp) /* Did we come from kernel? */
-	jz	alltraps_pushregs	/* already running with kernel GS.base */
+	jz	1f	/* already running with kernel GS.base */
 	swapgs
+1:	movw	%fs,TF_FS(%rsp)
+	movw	%gs,TF_GS(%rsp)
+	movw	%es,TF_ES(%rsp)
+	movw	%ds,TF_DS(%rsp)
 	jmp	alltraps_pushregs
 
 IDTVEC(dblfault)
 	subq	$TF_ERR,%rsp
-	movq	$T_DOUBLEFLT,TF_TRAPNO(%rsp)
+	movl	$T_DOUBLEFLT,TF_TRAPNO(%rsp)
 	movq	$0,TF_ADDR(%rsp)
 	movq	$0,TF_ERR(%rsp)
 	movq	%rdi,TF_RDI(%rsp)
@@ -252,6 +262,11 @@
 	movq	%r13,TF_R13(%rsp)
 	movq	%r14,TF_R14(%rsp)
 	movq	%r15,TF_R15(%rsp)
+	movw	%fs,TF_FS(%rsp)
+	movw	%gs,TF_GS(%rsp)
+	movw	%es,TF_ES(%rsp)
+	movw	%ds,TF_DS(%rsp)
+	movl	$TF_HASSEGS,TF_FLAGS(%rsp)
 	testb	$SEL_RPL_MASK,TF_CS(%rsp) /* Did we come from kernel? */
 	jz	1f			/* already running with kernel GS.base */
 	swapgs
@@ -262,7 +277,7 @@
 
 IDTVEC(page)
 	subq	$TF_ERR,%rsp
-	movq	$T_PAGEFLT,TF_TRAPNO(%rsp)
+	movl	$T_PAGEFLT,TF_TRAPNO(%rsp)
 	testb	$SEL_RPL_MASK,TF_CS(%rsp) /* Did we come from kernel? */
 	jz	1f			/* already running with kernel GS.base */
 	swapgs
@@ -270,6 +285,10 @@
 	movq	%rdi,TF_RDI(%rsp)	/* free up a GP register */
 	movq	%cr2,%rdi		/* preserve %cr2 before ..  */
 	movq	%rdi,TF_ADDR(%rsp)	/* enabling interrupts. */
+	movw	%fs,TF_FS(%rsp)
+	movw	%gs,TF_GS(%rsp)
+	movw	%es,TF_ES(%rsp)
+	movw	%ds,TF_DS(%rsp)
 	testl	$PSL_I,TF_RFLAGS(%rsp)
 	jz	alltraps_pushregs_no_rdi
 	sti
@@ -283,17 +302,19 @@
 	 */
 IDTVEC(prot)
 	subq	$TF_ERR,%rsp
-	movq	$T_PROTFLT,TF_TRAPNO(%rsp)
+	movl	$T_PROTFLT,TF_TRAPNO(%rsp)
 	movq	$0,TF_ADDR(%rsp)
 	movq	%rdi,TF_RDI(%rsp)	/* free up a GP register */
 	leaq	doreti_iret(%rip),%rdi
 	cmpq	%rdi,TF_RIP(%rsp)
-	je	2f			/* kernel but with user gsbase!! */
+	je	1f			/* kernel but with user gsbase!! */
 	testb	$SEL_RPL_MASK,TF_CS(%rsp) /* Did we come from kernel? */
-	jz	1f			/* already running with kernel GS.base */
-2:
-	swapgs
-1:
+	jz	2f			/* already running with kernel GS.base */
+1:	swapgs
+2:	movw	%fs,TF_FS(%rsp)
+	movw	%gs,TF_GS(%rsp)
+	movw	%es,TF_ES(%rsp)
+	movw	%ds,TF_DS(%rsp)
 	testl	$PSL_I,TF_RFLAGS(%rsp)
 	jz	alltraps_pushregs_no_rdi
 	sti
@@ -316,6 +337,10 @@
 	movq	%rcx,TF_RIP(%rsp)	/* %rcx original value is in %r10 */
 	movq	PCPU(SCRATCH_RSP),%r11	/* %r11 already saved */
 	movq	%r11,TF_RSP(%rsp)	/* user stack pointer */
+	movw	%fs,TF_FS(%rsp)
+	movw	%gs,TF_GS(%rsp)
+	movw	%es,TF_ES(%rsp)
+	movw	%ds,TF_DS(%rsp)
 	sti
 	movq	$KUDSEL,TF_SS(%rsp)
 	movq	$KUCSEL,TF_CS(%rsp)
@@ -333,40 +358,11 @@
 	movq	%r13,TF_R13(%rsp)	/* C preserved */
 	movq	%r14,TF_R14(%rsp)	/* C preserved */
 	movq	%r15,TF_R15(%rsp)	/* C preserved */
+	movl	$TF_HASSEGS,TF_FLAGS(%rsp)
 	FAKE_MCOUNT(TF_RIP(%rsp))
 	movq	%rsp, %rdi
 	call	syscall
 	movq	PCPU(CURPCB),%rax
-	testq	$PCB_FULLCTX,PCB_FLAGS(%rax)
-	jne	3f
-1:	/* Check for and handle AST's on return to userland */
-	cli
-	movq	PCPU(CURTHREAD),%rax
-	testl	$TDF_ASTPENDING | TDF_NEEDRESCHED,TD_FLAGS(%rax)
-	je	2f
-	sti
-	movq	%rsp, %rdi
-	call	ast
-	jmp	1b
-2:	/* restore preserved registers */
-	MEXITCOUNT
-	movq	TF_RDI(%rsp),%rdi	/* bonus; preserve arg 1 */
-	movq	TF_RSI(%rsp),%rsi	/* bonus: preserve arg 2 */
-	movq	TF_RDX(%rsp),%rdx	/* return value 2 */
-	movq	TF_RAX(%rsp),%rax	/* return value 1 */
-	movq	TF_RBX(%rsp),%rbx	/* C preserved */
-	movq	TF_RBP(%rsp),%rbp	/* C preserved */
-	movq	TF_R12(%rsp),%r12	/* C preserved */
-	movq	TF_R13(%rsp),%r13	/* C preserved */
-	movq	TF_R14(%rsp),%r14	/* C preserved */
-	movq	TF_R15(%rsp),%r15	/* C preserved */
-	movq	TF_RFLAGS(%rsp),%r11	/* original %rflags */
-	movq	TF_RIP(%rsp),%rcx	/* original %rip */
-	movq	TF_RSP(%rsp),%r9	/* user stack pointer */
-	movq	%r9,%rsp		/* original %rsp */
-	swapgs
-	sysretq
-3:	/* Requested full context restore, use doreti for that */
 	andq	$~PCB_FULLCTX,PCB_FLAGS(%rax)
 	MEXITCOUNT
 	jmp	doreti
@@ -405,7 +401,7 @@
 
 IDTVEC(nmi)
 	subq	$TF_RIP,%rsp
-	movq	$(T_NMI),TF_TRAPNO(%rsp)
+	movl	$(T_NMI),TF_TRAPNO(%rsp)
 	movq	$0,TF_ADDR(%rsp)
 	movq	$0,TF_ERR(%rsp)
 	movq	%rdi,TF_RDI(%rsp)
@@ -423,6 +419,11 @@
 	movq	%r13,TF_R13(%rsp)
 	movq	%r14,TF_R14(%rsp)
 	movq	%r15,TF_R15(%rsp)
+	movw	%fs,TF_FS(%rsp)
+	movw	%gs,TF_GS(%rsp)
+	movw	%es,TF_ES(%rsp)
+	movw	%ds,TF_DS(%rsp)
+	movl	$TF_HASSEGS,TF_FLAGS(%rsp)
 	xorl	%ebx,%ebx
 	testb	$SEL_RPL_MASK,TF_CS(%rsp)
 	jnz	nmi_fromuserspace
@@ -515,9 +516,7 @@
 nocallchain:
 #endif
 	testl	%ebx,%ebx
-	jz	nmi_kernelexit
-	swapgs
-	jmp	nmi_restoreregs
+	jnz	doreti_exit
 nmi_kernelexit:	
 	/*
 	 * Put back the preserved MSR_GSBASE value.
@@ -633,7 +632,55 @@
 	 */
 doreti_exit:
 	MEXITCOUNT
-	movq	TF_RDI(%rsp),%rdi
+	movq	PCPU(CURTHREAD),%r8
+	movq	TD_PCB(%r8),%r8
+
+	/*
+	 * Do not reload segment registers for kernel.
+	 * Since we do not reload segments registers with sane
+	 * values on kernel entry, descriptors referenced by
+	 * segments registers may be not valid. This is fatal
+	 * for the usermode, but is innocent for the kernel.
+	 */
+	testb	$SEL_RPL_MASK,TF_CS(%rsp)
+	jz	ld_regs
+
+	testl	$TF_HASSEGS,TF_FLAGS(%rsp)
+	je	set_segs
+
+do_segs:
+	/* Restore %fs and fsbase */
+	movw	TF_FS(%rsp),%ax
+	.globl	ld_fs
+ld_fs:	movw	%ax,%fs
+	cmpw	$KUF32SEL,%ax
+	jne	1f
+	movl	$MSR_FSBASE,%ecx
+	movl	PCB_FSBASE(%r8),%eax
+	movl	PCB_FSBASE+4(%r8),%edx
+	wrmsr
+1:
+	/* Restore %gs and gsbase */
+	movw	TF_GS(%rsp),%si
+	pushfq
+	cli
+	movl	$MSR_GSBASE,%ecx
+	rdmsr
+	.globl	ld_gs
+ld_gs:	movw	%si,%gs
+	wrmsr
+	popfq
+	cmpw	$KUG32SEL,%si
+	jne	1f
+	movl	$MSR_KGSBASE,%ecx
+	movl	PCB_GSBASE(%r8),%eax
+	movl	PCB_GSBASE+4(%r8),%edx
+	wrmsr
+1:	.globl	ld_es
+ld_es:	movw	TF_ES(%rsp),%es
+	.globl	ld_ds
+ld_ds:	movw	TF_DS(%rsp),%ds
+ld_regs:movq	TF_RDI(%rsp),%rdi
 	movq	TF_RSI(%rsp),%rsi
 	movq	TF_RDX(%rsp),%rdx
 	movq	TF_RCX(%rsp),%rcx
@@ -657,6 +704,14 @@
 doreti_iret:
 	iretq
 
+set_segs:
+	movw	$KUDSEL,%ax
+	movw	%ax,TF_DS(%rsp)
+	movw	%ax,TF_ES(%rsp)
+	movw	$KUF32SEL,TF_FS(%rsp)
+	movw	$KUG32SEL,TF_GS(%rsp)
+	jmp	do_segs
+
 	/*
 	 * doreti_iret_fault.  Alternative return code for
 	 * the case where we get a fault in the doreti_exit code
@@ -671,7 +726,12 @@
 	testl	$PSL_I,TF_RFLAGS(%rsp)
 	jz	1f
 	sti
-1:	movq	%rdi,TF_RDI(%rsp)
+1:	movw	%fs,TF_FS(%rsp)
+	movw	%gs,TF_GS(%rsp)
+	movw	%es,TF_ES(%rsp)
+	movw	%ds,TF_DS(%rsp)
+	movl	$TF_HASSEGS,TF_FLAGS(%rsp)
+	movq	%rdi,TF_RDI(%rsp)
 	movq	%rsi,TF_RSI(%rsp)
 	movq	%rdx,TF_RDX(%rsp)
 	movq	%rcx,TF_RCX(%rsp)
@@ -686,11 +746,48 @@
 	movq	%r13,TF_R13(%rsp)
 	movq	%r14,TF_R14(%rsp)
 	movq	%r15,TF_R15(%rsp)
-	movq	$T_PROTFLT,TF_TRAPNO(%rsp)
+	movl	$T_PROTFLT,TF_TRAPNO(%rsp)
 	movq	$0,TF_ERR(%rsp)	/* XXX should be the error code */
 	movq	$0,TF_ADDR(%rsp)
 	FAKE_MCOUNT(TF_RIP(%rsp))
 	jmp	calltrap
+
+	ALIGN_TEXT
+	.globl	ds_load_fault
+ds_load_fault:
+	movl	$T_PROTFLT,TF_TRAPNO(%rsp)
+	movzwl	TF_DS(%rsp),%edx
+	movl	%edx,TF_ERR(%rsp)
+	movw	$KUDSEL,TF_DS(%rsp)
+	jmp	calltrap
+
+	ALIGN_TEXT
+	.globl	es_load_fault
+es_load_fault:

>>> TRUNCATED FOR MAIL (1000 lines) <<<



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200904062104.n36L4oYf069574>