diff mbox series

[kvm-unit-tests] x86: replace segment selector magic number with macro definition

Message ID 20240621122640.2347541-1-darcy.sh@antgroup.com (mailing list archive)
State New, archived
Headers show
Series [kvm-unit-tests] x86: replace segment selector magic number with macro definition | expand

Commit Message

Hang SU June 21, 2024, 12:26 p.m. UTC
Add assembly check in desc.h, to replace segment selector
magic number with macro definition.

Signed-off-by: Hang SU <darcy.sh@antgroup.com>
---
 lib/x86/desc.h    | 12 +++++++++---
 x86/cstart64.S    |  6 +++---
 x86/trampolines.S |  8 +++++---
 3 files changed, 17 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/lib/x86/desc.h b/lib/x86/desc.h
index 7778a0f8..61000257 100644
--- a/lib/x86/desc.h
+++ b/lib/x86/desc.h
@@ -1,8 +1,6 @@ 
 #ifndef _X86_DESC_H_
 #define _X86_DESC_H_
 
-#include <setjmp.h>
-
 #ifdef __ASSEMBLY__
 #define __ASM_FORM(x, ...)	x,## __VA_ARGS__
 #else
@@ -15,6 +13,9 @@ 
 #define __ASM_SEL(a,b)		__ASM_FORM(b)
 #endif
 
+#if !defined(__ASSEMBLY__) && !defined(__ASSEMBLER__)
+#include <setjmp.h>
+
 void setup_idt(void);
 void load_idt(void);
 void setup_alt_stack(void);
@@ -119,6 +120,7 @@  static inline bool is_fep_available(void)
 fep_unavailable:
 	return false;
 }
+#endif //#if !defined(__ASSEMBLY__) && !defined(__ASSEMBLER__)
 
 /*
  * selector     32-bit                        64-bit
@@ -176,6 +178,8 @@  fep_unavailable:
 #define FIRST_SPARE_SEL 0x50
 #define TSS_MAIN 0x80
 
+#if !defined(__ASSEMBLY__) && !defined(__ASSEMBLER__)
+
 typedef struct {
 	unsigned short offset0;
 	unsigned short selector;
@@ -320,4 +324,6 @@  do {									\
 
 #define asm_safe_report_ex __asm_safe_report
 
-#endif
+
+#endif //#if !defined(__ASSEMBLY__) && !defined(__ASSEMBLER__)
+#endif //#ifndef _X86_DESC_H_
diff --git a/x86/cstart64.S b/x86/cstart64.S
index 4dff1102..c78d1a9f 100644
--- a/x86/cstart64.S
+++ b/x86/cstart64.S
@@ -66,7 +66,7 @@  start:
 	mov $stacktop, %esp
 	setup_percpu_area
 	call prepare_64
-	jmpl $8, $start64
+	jmpl $KERNEL_CS, $start64
 
 switch_to_5level:
 	/* Disable CR4.PCIDE */
@@ -86,11 +86,11 @@  switch_to_5level:
 	bts $12, %eax
 	mov %eax, %cr4
 
-	mov $0x10, %ax
+	mov $KERNEL_DS, %ax
 	mov %ax, %ss
 
 	call enter_long_mode
-	jmpl $8, $lvl5
+	jmpl $KERNEL_CS, $lvl5
 
 smp_stacktop:	.long stacktop - 4096
 
diff --git a/x86/trampolines.S b/x86/trampolines.S
index 6a3df9c1..f0b05ab5 100644
--- a/x86/trampolines.S
+++ b/x86/trampolines.S
@@ -3,6 +3,8 @@ 
  * transition from 32-bit to 64-bit code (x86-64 only)
  */
 
+#include "desc.h"
+
  /* EFI provides it's own SIPI sequence to handle relocation. */
 #ifndef CONFIG_EFI
 .code16
@@ -15,7 +17,7 @@  sipi_entry:
 	or $1, %eax
 	mov %eax, %cr0
 	lgdtl ap_rm_gdt_descr - sipi_entry
-	ljmpl $8, $ap_start32
+	ljmpl $KERNEL_CS32, $ap_start32
 sipi_end:
 
 .globl ap_rm_gdt_descr
@@ -66,7 +68,7 @@  MSR_GS_BASE = 0xc0000101
 	mov $MSR_GS_BASE, %ecx
 	rdmsr
 
-	mov $0x10, %bx
+	mov $KERNEL_DS, %bx
 	mov %bx, %ds
 	mov %bx, %es
 	mov %bx, %fs
@@ -123,7 +125,7 @@  ap_start32:
 	call prepare_64
 
 	load_absolute_addr $ap_start64, %edx
-	pushl $0x08
+	pushl $KERNEL_CS
 	pushl %edx
 	lretl
 #endif