Skip to contentSkip to conversation

x86 assmebly code clean up

PATCH In review Wei Liu 3 participants 17 messages Aug 25, 2016 – Aug 26, 2016 x86

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

cover x86 assmebly code clean up

Wei Liu (5):
x86_32: remove inclusion of x86-32.h
x86_64: remove unused labels
x86_64: merge RESTORE_REST into RESTORE_ALL
x86_64: introduce and use SAVE_ALL
x86_64: don't unnecessarily export some entries

 arch/x86/x86_32.S |  2 --
 arch/x86/x86_64.S | 74 ++++++++++++++++++++++---------------------------------
 2 files changed, 29 insertions(+), 47 deletions(-)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#1 lore raw

PATCH 1/5 x86_32: remove inclusion of x86-32.h

There is no need to do that explicitly.

---
 arch/x86/x86_32.S | 2 --
 1 file changed, 2 deletions(-)
arch/x86/x86_32.S +0 -2
index 9241418..f70fc65 100644
@@ -3,9 +3,7 @@
 #include <mini-os/asm_macros.h>
 #include <mini-os/arch_mm.h>
 #include <mini-os/desc.h>
-#include <xen/arch-x86_32.h>
 #include <xen/elfnote.h>
-#include <xen/arch-x86_32.h>
 
 #ifdef CONFIG_PARAVIRT
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#3 lore raw

PATCH 2/5 x86_64: remove unused labels

In reply to Wei Liu
---
 arch/x86/x86_64.S | 3 ---
 1 file changed, 3 deletions(-)
arch/x86/x86_64.S +0 -3
index 5932bfb..c57ee10 100644
@@ -177,7 +177,6 @@ ENTRY(error_entry)
 	movq %r14,1*8(%rsp) 
 	movq %r15,(%rsp) 
 
-error_call_handler:
 	movq %rdi, RDI(%rsp)
 	movq %rsp,%rdi
 	movq ORIG_RAX(%rsp),%rsi	# get error code 
@@ -212,7 +211,6 @@ ENTRY(hypervisor_callback2)
 	decl %gs:0
 
 error_exit:
-retint_kernel:
 	movl RFLAGS(%rsp), %eax
 	shr $9, %eax			# EAX[0] == IRET_RFLAGS.IF
 	XEN_GET_VCPU_INFO(%rsi)
@@ -221,7 +219,6 @@ retint_kernel:
 	jnz restore_all_enable_events	#        != 0 => enable event delivery
 	XEN_PUT_VCPU_INFO(%rsi)
 
-retint_restore_args:
 	RESTORE_REST
 	RESTORE_ALL
 	HYPERVISOR_IRET 0
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#5 lore raw

PATCH 3/5 x86_64: merge RESTORE_REST into RESTORE_ALL

In reply to Wei Liu
---
 arch/x86/x86_64.S | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)
arch/x86/x86_64.S +11 -18
index c57ee10..8432d69 100644
@@ -101,27 +101,23 @@ KERNEL_CS_MASK = 0xfc
 .endm
 
 .macro RESTORE_ALL
-	movq (%rsp),%r11
-	movq 1*8(%rsp),%r10
-	movq 2*8(%rsp),%r9
-	movq 3*8(%rsp),%r8
-	movq 4*8(%rsp),%rax
-	movq 5*8(%rsp),%rcx
-	movq 6*8(%rsp),%rdx
-	movq 7*8(%rsp),%rsi
-	movq 8*8(%rsp),%rdi
-	addq $9*8+8,%rsp
-.endm	
-
-.macro RESTORE_REST
 	movq (%rsp),%r15
 	movq 1*8(%rsp),%r14
 	movq 2*8(%rsp),%r13
 	movq 3*8(%rsp),%r12
 	movq 4*8(%rsp),%rbp
 	movq 5*8(%rsp),%rbx
-	addq $6*8,%rsp
-.endm
+	movq 6*8(%rsp),%r11
+	movq 7*8(%rsp),%r10
+	movq 8*8(%rsp),%r9
+	movq 9*8(%rsp),%r8
+	movq 10*8(%rsp),%rax
+	movq 11*8(%rsp),%rcx
+	movq 12*8(%rsp),%rdx
+	movq 13*8(%rsp),%rsi
+	movq 14*8(%rsp),%rdi
+	addq $15*8+8,%rsp
+.endm	
 
 .macro SAVE_REST
 	subq $6*8,%rsp
@@ -219,12 +215,10 @@ error_exit:
 	jnz restore_all_enable_events	#        != 0 => enable event delivery
 	XEN_PUT_VCPU_INFO(%rsi)
 
-	RESTORE_REST
 	RESTORE_ALL
 	HYPERVISOR_IRET 0
 
 restore_all_enable_events:
-	RESTORE_REST
 	RESTORE_ALL
 	pushq %rax                      # save rax for it will be clobbered later
 	RSP_OFFSET=8                    # record the stack frame layout changes
@@ -289,7 +283,6 @@ critical_region_fixup:
 
 #else
 error_exit:
-	RESTORE_REST
 	RESTORE_ALL
 	HYPERVISOR_IRET 0
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#8 lore raw

PATCH 4/5 x86_64: introduce and use SAVE_ALL

In reply to Wei Liu

Introduce this macro to match RESTORE_ALL. Also delete the unused SAVE_REST.

---
 arch/x86/x86_64.S | 38 ++++++++++++++++----------------------
 1 file changed, 16 insertions(+), 22 deletions(-)
arch/x86/x86_64.S +16 -22
index 8432d69..21fa61b 100644
@@ -119,14 +119,26 @@ KERNEL_CS_MASK = 0xfc
 	addq $15*8+8,%rsp
 .endm	
 
-.macro SAVE_REST
-	subq $6*8,%rsp
+.macro SAVE_ALL
+	/* rdi slot contains rax, oldrax contains error code */
+	cld
+	subq $14*8,%rsp
+	movq %rsi,13*8(%rsp)
+	movq 14*8(%rsp),%rsi	/* load rax from rdi slot */
+	movq %rdx,12*8(%rsp)
+	movq %rcx,11*8(%rsp)
+	movq %rsi,10*8(%rsp)	/* store rax */
+	movq %r8, 9*8(%rsp)
+	movq %r9, 8*8(%rsp)
+	movq %r10,7*8(%rsp)
+	movq %r11,6*8(%rsp)
 	movq %rbx,5*8(%rsp)
 	movq %rbp,4*8(%rsp)
 	movq %r12,3*8(%rsp)
 	movq %r13,2*8(%rsp)
 	movq %r14,1*8(%rsp)
 	movq %r15,(%rsp)
+	movq %rdi, RDI(%rsp)	/* put rdi into the slot */
 .endm
 
 .macro HYPERVISOR_IRET flag
@@ -154,26 +166,8 @@ KERNEL_CS_MASK = 0xfc
  * and the exception handler in %rax.	
  */ 		  				
 ENTRY(error_entry)
-	/* rdi slot contains rax, oldrax contains error code */
-	cld	
-	subq  $14*8,%rsp
-	movq %rsi,13*8(%rsp)
-	movq 14*8(%rsp),%rsi	/* load rax from rdi slot */
-	movq %rdx,12*8(%rsp)
-	movq %rcx,11*8(%rsp)
-	movq %rsi,10*8(%rsp)	/* store rax */ 
-	movq %r8, 9*8(%rsp)
-	movq %r9, 8*8(%rsp)
-	movq %r10,7*8(%rsp)
-	movq %r11,6*8(%rsp)
-	movq %rbx,5*8(%rsp) 
-	movq %rbp,4*8(%rsp) 
-	movq %r12,3*8(%rsp) 
-	movq %r13,2*8(%rsp) 
-	movq %r14,1*8(%rsp) 
-	movq %r15,(%rsp) 
-
-	movq %rdi, RDI(%rsp)
+	SAVE_ALL
+
 	movq %rsp,%rdi
 	movq ORIG_RAX(%rsp),%rsi	# get error code 
 	movq $-1,ORIG_RAX(%rsp)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#10 lore raw

PATCH 5/5 x86_64: don't unnecessarily export some entries

In reply to Wei Liu
---
 arch/x86/x86_64.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/x86_64.S +2 -2
index 21fa61b..2046187 100644
@@ -165,7 +165,7 @@ KERNEL_CS_MASK = 0xfc
  * Exception entry point. This expects an error code/orig_rax on the stack
  * and the exception handler in %rax.	
  */ 		  				
-ENTRY(error_entry)
+error_entry:
 	SAVE_ALL
 
 	movq %rsp,%rdi
@@ -182,7 +182,7 @@ ENTRY(error_entry)
 ENTRY(hypervisor_callback)
 	zeroentry hypervisor_callback2
 
-ENTRY(hypervisor_callback2)
+hypervisor_callback2:
 	movq %rdi, %rsp
 
 	/* check against event re-entrant */
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#12 lore raw
In reply to Wei Liu
Quoted 11 lines · Wei Liu

Wei Liu (5):
x86_32: remove inclusion of x86-32.h
x86_64: remove unused labels
x86_64: merge RESTORE_REST into RESTORE_ALL
x86_64: introduce and use SAVE_ALL
x86_64: don't unnecessarily export some entries

 arch/x86/x86_32.S |  2 --
 arch/x86/x86_64.S | 74 ++++++++++++++++++++++---------------------------------
 2 files changed, 29 insertions(+), 47 deletions(-)

BTW: perhaps you should Cc: [email protected] next time?

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#13 lore raw
Quoted 8 lines · Juergen Gross
Quoted 7 lines · Wei Liu

Wei Liu (5):
x86_32: remove inclusion of x86-32.h
x86_64: remove unused labels
x86_64: merge RESTORE_REST into RESTORE_ALL
x86_64: introduce and use SAVE_ALL
x86_64: don't unnecessarily export some entries

Quoted 7 lines
Quoted 4 lines
 arch/x86/x86_32.S |  2 --
 arch/x86/x86_64.S | 74 ++++++++++++++++++++++---------------------------------
 2 files changed, 29 insertions(+), 47 deletions(-)

BTW: perhaps you should Cc: [email protected] next time?

Oops, I normally do that but forgot this time.

Quoted 2 lines

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Acked-by on the v1 series
#14 lore raw
In reply to Wei Liu
Quoted 6 lines · Wei Liu, on Thu 25 Aug 2016 17:38:23 +0100, wrote:

Wei Liu (5):
x86_32: remove inclusion of x86-32.h
x86_64: remove unused labels
x86_64: merge RESTORE_REST into RESTORE_ALL
x86_64: introduce and use SAVE_ALL
x86_64: don't unnecessarily export some entries

For the whole series,

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#15 lore raw
In reply to Wei Liu

Send this cover letter to minios-devel -- forgot to do that when I sent this series out.

Quoted 7 lines · Wei Liu

Wei Liu (5):
x86_32: remove inclusion of x86-32.h
x86_64: remove unused labels
x86_64: merge RESTORE_REST into RESTORE_ALL
x86_64: introduce and use SAVE_ALL
x86_64: don't unnecessarily export some entries

Quoted 7 lines
 arch/x86/x86_32.S |  2 --
 arch/x86/x86_64.S | 74 ++++++++++++++++++++++---------------------------------
 2 files changed, 29 insertions(+), 47 deletions(-)
Signature · 1 line
2.1.4

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#16 lore raw
Quoted 18 lines · Wei Liu

Send this cover letter to minios-devel -- forgot to do that when I sent this series out.

Quoted 14 lines · Wei Liu

Wei Liu (5):
x86_32: remove inclusion of x86-32.h
x86_64: remove unused labels
x86_64: merge RESTORE_REST into RESTORE_ALL
x86_64: introduce and use SAVE_ALL
x86_64: don't unnecessarily export some entries

 arch/x86/x86_32.S |  2 --
 arch/x86/x86_64.S | 74 ++++++++++++++++++++++---------------------------------
 2 files changed, 29 insertions(+), 47 deletions(-)
Signature · 1 line
2.1.4

Series pushed.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel