From nobody@FreeBSD.org  Sun Oct  6 11:28:32 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTP id 1A51B1CD
	for <freebsd-gnats-submit@FreeBSD.org>; Sun,  6 Oct 2013 11:28:32 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from oldred.freebsd.org (oldred.freebsd.org [8.8.178.121])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id 07F00253E
	for <freebsd-gnats-submit@FreeBSD.org>; Sun,  6 Oct 2013 11:28:32 +0000 (UTC)
Received: from oldred.freebsd.org ([127.0.1.6])
	by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id r96BSVUw087064
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 6 Oct 2013 11:28:31 GMT
	(envelope-from nobody@oldred.freebsd.org)
Received: (from nobody@localhost)
	by oldred.freebsd.org (8.14.5/8.14.5/Submit) id r96BSVOa087061;
	Sun, 6 Oct 2013 11:28:31 GMT
	(envelope-from nobody)
Message-Id: <201310061128.r96BSVOa087061@oldred.freebsd.org>
Date: Sun, 6 Oct 2013 11:28:31 GMT
From: Julian Pidancet <julian.pidancet@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: BTX halted on Jetway NF81 motherboard when RAID is enabled
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         182740
>Category:       amd64
>Synopsis:       BTX halted on Jetway NF81 motherboard when RAID is enabled
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jhb
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Oct 06 11:30:00 UTC 2013
>Closed-Date:    Fri Nov 15 15:09:18 UTC 2013
>Last-Modified:  Fri Nov 15 15:10:02 UTC 2013
>Originator:     Julian Pidancet
>Release:        8.2
>Organization:
>Environment:
>Description:
Just got this brand new motherboard with an AMD APU and an AMD chipset.

Whenever I try to boot FreeBSD and AHCI or RAID is enabled in the BIOS, I am getting this message:

BTX loader 1.00  BTX version is 1.02
int=0000000a  err=00000000  efl=00006402  eip=000093e0
eax=534d4150  ebx=00000001  ecx=00000014  edx=534d4150
esi=00000000  edi=00000004  ebp=00000000  esp=0000004e
cs=0008  ds=0033  es=0033    fs=0033  gs=0033  ss=0010
cs:eip=cf 83 f8 01 75 1a 16 87-86 1f 1e 0f a1 0f a0 0f
       a9 b8 00 a0 00 00 03 44-24 0c 8d 60 04 58 ff d0
ss:esp=00 f0 39 e7 00 f0 e3 21-80 ce 2e e8 00 f0 d2 ef
       00 f0 00 e0 00 f0 f2 e6-00 f0 6e fe 00 f0 53 ff
BTX halted

It looks like to me the BTX is taking an "Invalid TSS" exception while executing an iret instruction.
>How-To-Repeat:
I tried: - Booting from the install cdrom
         - Booting from an USB install disk
         - Booting from boot/pxeboot in PXE mode

All exhibit the same issue.
>Fix:
Selecting "Legacy IDE" mode in the BIOS configuration instead of AHCI/RAID.

>Release-Note:
>Audit-Trail:

From: John Baldwin <jhb@freebsd.org>
To: freebsd-amd64@freebsd.org
Cc: Julian Pidancet <julian.pidancet@gmail.com>,
 freebsd-gnats-submit@freebsd.org
Subject: Re: amd64/182740: BTX halted on Jetway NF81 motherboard when RAID is enabled
Date: Mon, 7 Oct 2013 11:47:32 -0400

 On Sunday, October 06, 2013 7:28:31 am Julian Pidancet wrote:
 > 
 > >Number:         182740
 > >Category:       amd64
 > >Synopsis:       BTX halted on Jetway NF81 motherboard when RAID is enabled
 > >Confidential:   no
 > >Severity:       non-critical
 > >Priority:       low
 > >Responsible:    freebsd-amd64
 > >State:          open
 > >Quarter:        
 > >Keywords:       
 > >Date-Required:
 > >Class:          sw-bug
 > >Submitter-Id:   current-users
 > >Arrival-Date:   Sun Oct 06 11:30:00 UTC 2013
 > >Closed-Date:
 > >Last-Modified:
 > >Originator:     Julian Pidancet
 > >Release:        8.2
 > >Organization:
 > >Environment:
 > >Description:
 > Just got this brand new motherboard with an AMD APU and an AMD chipset.
 > 
 > Whenever I try to boot FreeBSD and AHCI or RAID is enabled in the BIOS, I am 
 getting this message:
 > 
 > BTX loader 1.00  BTX version is 1.02
 > int=0000000a  err=00000000  efl=00006402  eip=000093e0
 > eax=534d4150  ebx=00000001  ecx=00000014  edx=534d4150
 > esi=00000000  edi=00000004  ebp=00000000  esp=0000004e
 > cs=0008  ds=0033  es=0033    fs=0033  gs=0033  ss=0010
 > cs:eip=cf 83 f8 01 75 1a 16 87-86 1f 1e 0f a1 0f a0 0f
 >        a9 b8 00 a0 00 00 03 44-24 0c 8d 60 04 58 ff d0
 > ss:esp=00 f0 39 e7 00 f0 e3 21-80 ce 2e e8 00 f0 d2 ef
 >        00 f0 00 e0 00 f0 f2 e6-00 f0 6e fe 00 f0 53 ff
 > BTX halted
 > 
 > It looks like to me the BTX is taking an "Invalid TSS" exception while 
 executing an iret instruction.
 > >How-To-Repeat:
 > I tried: - Booting from the install cdrom
 >          - Booting from an USB install disk
 >          - Booting from boot/pxeboot in PXE mode
 > 
 > All exhibit the same issue.
 > >Fix:
 > Selecting "Legacy IDE" mode in the BIOS configuration instead of AHCI/RAID.
 
 Ok, can you take this patch and use it to build an updated pxeboot and test
 if it fixes disk access with AHCI enabled?
 
 Index: boot/i386/btx/btx/btx.S
 ===================================================================
 --- boot/i386/btx/btx/btx.S	(revision 247010)
 +++ boot/i386/btx/btx/btx.S	(working copy)
 @@ -41,6 +41,8 @@
  		.set PSL_RESERVED_DEFAULT,0x00000002
  		.set PSL_T,0x00000100		# Trap flag
  		.set PSL_I,0x00000200		# Interrupt enable flag
 +		.set PSL_D,0x00000400		# String instruction direction
 +		.set PSL_NT,0x00004000		# Nested task flag
  		.set PSL_VM,0x00020000		# Virtual 8086 mode flag
  		.set PSL_AC,0x00040000		# Alignment check flag
  /*
 @@ -611,8 +613,8 @@
  		pushl %ds			#  regs
  		pushl %es
  		pushfl				# Save %eflags
 -		cli				# Disable interrupts
 -		std				# String ops dec
 +		pushl $PSL_RESERVED_DEFAULT|PSL_D # Use clean %eflags with
 +		popfl				#  string ops dec
  		xorw %ax,%ax			# Reset seg 
  		movw %ax,%ds			#  regs
  		movw %ax,%es			#  (%ss is already 0)
 @@ -675,6 +677,7 @@
  		testl $V86F_FLAGS,%edx		# User wants flags?
  		jz rret_tramp.3			# No
  		movl MEM_ESPR-0x3c,%eax		# Read real mode flags
 +		andl $~(PSL_T|PSL_NT),%eax	# Clear unsafe flags
  		movw %ax,-0x08(%esi)		# Update user flags (low 16)
  /*
   * Return to the user task
 
 -- 
 John Baldwin

From: Julian Pidancet <julian.pidancet@gmail.com>
To: John Baldwin <jhb@freebsd.org>
Cc: freebsd-amd64@freebsd.org, freebsd-gnats-submit@freebsd.org
Subject: Re: amd64/182740: BTX halted on Jetway NF81 motherboard when RAID is enabled
Date: Wed, 9 Oct 2013 10:21:05 +0100

 --90e6ba614a76d24c8804e84b689c
 Content-Type: text/plain; charset=UTF-8
 
 On 7 October 2013 16:47, John Baldwin <jhb@freebsd.org> wrote:
 
 >
 > Ok, can you take this patch and use it to build an updated pxeboot and test
 > if it fixes disk access with AHCI enabled?
 >
 >
 
 That seems to have fixed the issue, thanks.
 
 -- 
 Julian
 
 --90e6ba614a76d24c8804e84b689c
 Content-Type: text/html; charset=UTF-8
 Content-Transfer-Encoding: quoted-printable
 
 <div dir=3D"ltr">On 7 October 2013 16:47, John Baldwin <span dir=3D"ltr">&l=
 t;<a href=3D"mailto:jhb@freebsd.org" target=3D"_blank">jhb@freebsd.org</a>&=
 gt;</span> wrote:<br><div class=3D"gmail_extra"><div class=3D"gmail_quote">=
 <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
 x #ccc solid;padding-left:1ex">
 
 <br>
 Ok, can you take this patch and use it to build an updated pxeboot and test=
 <br>
 if it fixes disk access with AHCI enabled?<br>
 <br></blockquote><div><br><br></div><div>That seems to have fixed the issue=
 , thanks. <br><br>-- <br></div><div>Julian<br><br></div></div></div></div>
 
 --90e6ba614a76d24c8804e84b689c--

From: John Baldwin <jhb@freebsd.org>
To: Julian Pidancet <julian.pidancet@gmail.com>
Cc: freebsd-amd64@freebsd.org,
 freebsd-gnats-submit@freebsd.org
Subject: Re: amd64/182740: BTX halted on Jetway NF81 motherboard when RAID is enabled
Date: Thu, 10 Oct 2013 11:20:40 -0400

 On Wednesday, October 09, 2013 5:21:05 am Julian Pidancet wrote:
 > On 7 October 2013 16:47, John Baldwin <jhb@freebsd.org> wrote:
 > 
 > >
 > > Ok, can you take this patch and use it to build an updated pxeboot and 
 test
 > > if it fixes disk access with AHCI enabled?
 > >
 > >
 > 
 > That seems to have fixed the issue, thanks.
 
 Great, thanks!
 
 -- 
 John Baldwin

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: amd64/182740: commit references a PR
Date: Thu, 10 Oct 2013 19:51:45 +0000 (UTC)

 Author: jhb
 Date: Thu Oct 10 19:51:38 2013
 New Revision: 256293
 URL: http://svnweb.freebsd.org/changeset/base/256293
 
 Log:
   Sanitize the %eflags returned by BIOS routines.  Some BIOS routines enter
   protected mode and may leave protected-mode-specific flags like PSL_NT set
   when they return to real mode.  This can cause a fault when BTX re-enters
   protected mode after the BIOS mode returns.
   
   PR:		amd64/182740
   Reported by:	Julian Pidancet <julian.pidancet@gmail.com>
   Approved by:	re (gjb)
   MFC after:	1 week
 
 Modified:
   head/sys/boot/i386/btx/btx/btx.S
 
 Modified: head/sys/boot/i386/btx/btx/btx.S
 ==============================================================================
 --- head/sys/boot/i386/btx/btx/btx.S	Thu Oct 10 19:48:43 2013	(r256292)
 +++ head/sys/boot/i386/btx/btx/btx.S	Thu Oct 10 19:51:38 2013	(r256293)
 @@ -41,6 +41,8 @@
  		.set PSL_RESERVED_DEFAULT,0x00000002
  		.set PSL_T,0x00000100		# Trap flag
  		.set PSL_I,0x00000200		# Interrupt enable flag
 +		.set PSL_D,0x00000400		# String instruction direction
 +		.set PSL_NT,0x00004000		# Nested task flag
  		.set PSL_VM,0x00020000		# Virtual 8086 mode flag
  		.set PSL_AC,0x00040000		# Alignment check flag
  /*
 @@ -611,8 +613,8 @@ rret_tramp:	movw $MEM_ESPR-0x08,%sp		# R
  		pushl %ds			#  regs
  		pushl %es
  		pushfl				# Save %eflags
 -		cli				# Disable interrupts
 -		std				# String ops dec
 +		pushl $PSL_RESERVED_DEFAULT|PSL_D # Use clean %eflags with
 +		popfl				#  string ops dec
  		xorw %ax,%ax			# Reset seg 
  		movw %ax,%ds			#  regs
  		movw %ax,%es			#  (%ss is already 0)
 @@ -675,6 +677,7 @@ rret_tramp.1:	xorl %ecx,%ecx			# Zero
  		testl $V86F_FLAGS,%edx		# User wants flags?
  		jz rret_tramp.3			# No
  		movl MEM_ESPR-0x3c,%eax		# Read real mode flags
 +		andl $~(PSL_T|PSL_NT),%eax	# Clear unsafe flags
  		movw %ax,-0x08(%esi)		# Update user flags (low 16)
  /*
   * Return to the user task
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: jhb 
State-Changed-When: Thu Oct 10 20:07:02 UTC 2013 
State-Changed-Why:  
Fix committed to HEAD. 


Responsible-Changed-From-To: freebsd-amd64->jhb 
Responsible-Changed-By: jhb 
Responsible-Changed-When: Thu Oct 10 20:07:02 UTC 2013 
Responsible-Changed-Why:  
Fix committed to HEAD. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=182740 
State-Changed-From-To: patched->closed 
State-Changed-By: jhb 
State-Changed-When: Fri Nov 15 15:09:04 UTC 2013 
State-Changed-Why:  
Fix merged to 8 and 9. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=182740 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: amd64/182740: commit references a PR
Date: Fri, 15 Nov 2013 15:09:00 +0000 (UTC)

 Author: jhb
 Date: Fri Nov 15 15:08:53 2013
 New Revision: 258171
 URL: http://svnweb.freebsd.org/changeset/base/258171
 
 Log:
   MFC 256293:
   Sanitize the %eflags returned by BIOS routines.  Some BIOS routines enter
   protected mode and may leave protected-mode-specific flags like PSL_NT set
   when they return to real mode.  This can cause a fault when BTX re-enters
   protected mode after the BIOS mode returns.
   
   PR:		amd64/182740
 
 Modified:
   stable/9/sys/boot/i386/btx/btx/btx.S
 Directory Properties:
   stable/9/sys/   (props changed)
   stable/9/sys/boot/   (props changed)
 
 Modified: stable/9/sys/boot/i386/btx/btx/btx.S
 ==============================================================================
 --- stable/9/sys/boot/i386/btx/btx/btx.S	Fri Nov 15 13:55:55 2013	(r258170)
 +++ stable/9/sys/boot/i386/btx/btx/btx.S	Fri Nov 15 15:08:53 2013	(r258171)
 @@ -41,6 +41,8 @@
  		.set PSL_RESERVED_DEFAULT,0x00000002
  		.set PSL_T,0x00000100		# Trap flag
  		.set PSL_I,0x00000200		# Interrupt enable flag
 +		.set PSL_D,0x00000400		# String instruction direction
 +		.set PSL_NT,0x00004000		# Nested task flag
  		.set PSL_VM,0x00020000		# Virtual 8086 mode flag
  		.set PSL_AC,0x00040000		# Alignment check flag
  /*
 @@ -611,8 +613,8 @@ rret_tramp:	movw $MEM_ESPR-0x08,%sp		# R
  		pushl %ds			#  regs
  		pushl %es
  		pushfl				# Save %eflags
 -		cli				# Disable interrupts
 -		std				# String ops dec
 +		pushl $PSL_RESERVED_DEFAULT|PSL_D # Use clean %eflags with
 +		popfl				#  string ops dec
  		xorw %ax,%ax			# Reset seg 
  		movw %ax,%ds			#  regs
  		movw %ax,%es			#  (%ss is already 0)
 @@ -675,6 +677,7 @@ rret_tramp.1:	xorl %ecx,%ecx			# Zero
  		testl $V86F_FLAGS,%edx		# User wants flags?
  		jz rret_tramp.3			# No
  		movl MEM_ESPR-0x3c,%eax		# Read real mode flags
 +		andl $~(PSL_T|PSL_NT),%eax	# Clear unsafe flags
  		movw %ax,-0x08(%esi)		# Update user flags (low 16)
  /*
   * Return to the user task
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: amd64/182740: commit references a PR
Date: Fri, 15 Nov 2013 15:09:07 +0000 (UTC)

 Author: jhb
 Date: Fri Nov 15 15:08:58 2013
 New Revision: 258172
 URL: http://svnweb.freebsd.org/changeset/base/258172
 
 Log:
   MFC 256293:
   Sanitize the %eflags returned by BIOS routines.  Some BIOS routines enter
   protected mode and may leave protected-mode-specific flags like PSL_NT set
   when they return to real mode.  This can cause a fault when BTX re-enters
   protected mode after the BIOS mode returns.
   
   PR:		amd64/182740
 
 Modified:
   stable/8/sys/boot/i386/btx/btx/btx.S
 Directory Properties:
   stable/8/sys/   (props changed)
   stable/8/sys/boot/   (props changed)
 
 Modified: stable/8/sys/boot/i386/btx/btx/btx.S
 ==============================================================================
 --- stable/8/sys/boot/i386/btx/btx/btx.S	Fri Nov 15 15:08:53 2013	(r258171)
 +++ stable/8/sys/boot/i386/btx/btx/btx.S	Fri Nov 15 15:08:58 2013	(r258172)
 @@ -41,6 +41,8 @@
  		.set PSL_RESERVED_DEFAULT,0x00000002
  		.set PSL_T,0x00000100		# Trap flag
  		.set PSL_I,0x00000200		# Interrupt enable flag
 +		.set PSL_D,0x00000400		# String instruction direction
 +		.set PSL_NT,0x00004000		# Nested task flag
  		.set PSL_VM,0x00020000		# Virtual 8086 mode flag
  		.set PSL_AC,0x00040000		# Alignment check flag
  /*
 @@ -611,8 +613,8 @@ rret_tramp:	movw $MEM_ESPR-0x08,%sp		# R
  		pushl %ds			#  regs
  		pushl %es
  		pushfl				# Save %eflags
 -		cli				# Disable interrupts
 -		std				# String ops dec
 +		pushl $PSL_RESERVED_DEFAULT|PSL_D # Use clean %eflags with
 +		popfl				#  string ops dec
  		xorw %ax,%ax			# Reset seg 
  		movw %ax,%ds			#  regs
  		movw %ax,%es			#  (%ss is already 0)
 @@ -675,6 +677,7 @@ rret_tramp.1:	xorl %ecx,%ecx			# Zero
  		testl $V86F_FLAGS,%edx		# User wants flags?
  		jz rret_tramp.3			# No
  		movl MEM_ESPR-0x3c,%eax		# Read real mode flags
 +		andl $~(PSL_T|PSL_NT),%eax	# Clear unsafe flags
  		movw %ax,-0x08(%esi)		# Update user flags (low 16)
  /*
   * Return to the user task
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
