Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 27 Mar 2003 13:23:38 -0800 (PST)
From:      John Baldwin <jhb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 27479 for review
Message-ID:  <200303272123.h2RLNcBr006129@repoman.freebsd.org>

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

Change 27479 by jhb@jhb_laptop on 2003/03/27 13:23:10

	- Rework to allow for reading CR3 as well (and CR2).
	- Trim the int15_87 handler considerably by wiser choice of
	  instructions.

Affected files ...

.. //depot/projects/smpng/sys/boot/i386/btx/btx/btx.s#5 edit

Differences ...

==== //depot/projects/smpng/sys/boot/i386/btx/btx/btx.s#5 (text+ko) ====

@@ -493,10 +493,8 @@
 		je v86wrmsr			# Yes
 		cmpb $0x32,(%esi)		# Is it a RDMSR?
 		je v86rdmsr			# Yes
-		cmpb $0x20,(%esi)		# Is this a
-		jne v86mon.4			#  MOV reg,CR[04]
-		testb $0x18,0x1(%esi)		#  instruction?
-		jz v86mov			# Yes
+		cmpb $0x20,(%esi)		# Is this a MOV reg,CRx?
+		je v86mov			# Yes
 v86mon.4:	cmpb $0xfa,%al			# CLI?
 		je v86cli			# Yes
 		cmpb $0xfb,%al			# STI?
@@ -527,14 +525,21 @@
 		leal 0x8(%esp,1),%esp		# Discard int no, error
 		iret				# To V86 mode
 #
-# Emulate MOV reg,CR[04].
+# Emulate MOV reg,CRx.
 #
 v86mov: 	movb 0x1(%esi),%bl		# Fetch Mod R/M byte
+		testb $0x10,%bl			# Read CR2 or CR3?
+		jnz v86mov.1			# Yes
 		movl %cr0,%eax			# Read CR0
 		testb $0x20,%bl			# Read CR4 instead?
-		jz v86mov.1			# No
+		jz v86mov.2			# No
 		movl %cr4,%eax			# Read CR4
-v86mov.1:	andl $0x7,%ebx			# Compute offset in
+		jmp v86mov.2
+v86mov.1:	movl %cr2,%eax			# Read CR2
+		testb $0x08,%bl			# Read CR3 instead?
+		jz v86mov.2			# No
+		movl %cr3,%eax			# Read CR3
+v86mov.2:	andl $0x7,%ebx			# Compute offset in
 		shl $2,%ebx			#  frame of destination
 		neg %ebx			#  register
 		movl %eax,0x1c(%ebp,%ebx,1)	# Store CR to reg
@@ -613,41 +618,27 @@
 # reads count of words from saved %cx
 # returns success by setting %ah to 0
 #
-int15_87:	pushl %eax			# Save 
-		pushl %ebx			#  some information 
-		pushl %esi			#  onto the stack.
-		pushl %edi
-		xorl %eax,%eax			# clean EAX 
-		xorl %ebx,%ebx			# clean EBX 
-		movl 0x4(%ebp),%esi		# Get user's ESI
-		movl 0x3C(%ebp),%ebx		# store ES
-		movw %si,%ax			# store SI
-		shll $0x4,%ebx			# Make it a seg.
-		addl %eax,%ebx			# ebx=(es<<4)+si
-		movb 0x14(%ebx),%al		# Grab the
-		movb 0x17(%ebx),%ah		#  necessary
-		shll $0x10,%eax			#  information
-		movw 0x12(%ebx),%ax		#  from
-		movl %eax,%esi			#  the
-		movb 0x1c(%ebx),%al		#  GDT in order to
-		movb 0x1f(%ebx),%ah		#  have %esi offset
-		shll $0x10,%eax			#  of source and %edi
-		movw 0x1a(%ebx),%ax		#  of destination.
-		movl %eax,%edi
+int15_87:	pushl %esi			# Save 
+		pushl %edi			#  registers
+		movzwl 0x4(%ebp),%eax		# Load user's SI
+		movl 0x3C(%ebp),%edi		# Load ES
+		leal (%eax,%edi,4),%edi		# EDI = (ES << 4) + SI
+		movl 0x11(%edi),%eax		# Read base of
+		movb 0x17(%edi),%al		#  GDT entry
+		ror $8,%eax			#  for source
+		movl %eax,%esi			#  into %esi
+		movl 0x19(%edi),%eax		# Read base of
+		movb 0x1f(%edi),%al		#  GDT entry for
+		ror $8,%eax			#  destination
+		movl %eax,%edi			#  into %edi
 		pushl %ds			# Make:
 		popl %es			# es = ds
-		pushl %ecx			# stash ECX
-		xorl %ecx,%ecx			# highw of ECX is clear
-		movw 0x18(%ebp),%cx		# Get user's ECX
-		shll $0x1,%ecx			# Convert from num words to num
-						#  bytes
+		movzwl 0x18(%ebp),%ecx		# Get user's CX
+		shll $0x1,%ecx			# Convert count from words
 		rep				# repeat...
 		movsb				#  perform copy.
-		popl %ecx			# Restore
-		popl %edi
-		popl %esi			#  previous
-		popl %ebx			#  register
-		popl %eax			#  values.
+		popl %edi			# Restore
+		popl %esi			#  registers
 		movb $0x0,0x1d(%ebp)		# set ah = 0 to indicate
 						#  success
 		andb $0xfe,%dl			# clear CF



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