]> xenbits.xensource.com Git - mini-os.git/commitdiff
Mini-OS: add some macros for asm statements
authorJuergen Gross <jgross@suse.com>
Mon, 22 Jul 2024 10:46:43 +0000 (12:46 +0200)
committerJan Beulich <jbeulich@suse.com>
Mon, 22 Jul 2024 10:46:43 +0000 (12:46 +0200)
Instead of having #ifdefs sprinkled around in x86 code, add some
macros defining constants for asm statements to address differences
between 32- and 64-bit mode.

Modify existing code to use those macros.

While at it convert the assembler parts of run_idle_thread() to a more
sane variant.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
arch/x86/sched.c
include/x86/os.h

index dabe6fd64538ad16c59be53f80c040ccc7f75d49..3c02647d9b9e335fc02a0e32c7c3df85087385c9 100644 (file)
@@ -60,16 +60,10 @@ void dump_stack(struct thread *thread)
     unsigned long *bottom = (unsigned long *)(thread->stack + STACK_SIZE); 
     unsigned long *pointer = (unsigned long *)thread->sp;
     int count;
-    if(thread == current)
-    {
-#ifdef __i386__    
-        asm("movl %%esp,%0"
-            : "=r"(pointer));
-#else
-        asm("movq %%rsp,%0"
-            : "=r"(pointer));
-#endif
-    }
+
+    if ( thread == current )
+        asm ( "mov %%"ASM_SP",%0" : "=r" (pointer) );
+
     printk("The stack for \"%s\"\n", thread->name);
     for(count = 0; count < 25 && pointer < bottom; count ++)
     {
@@ -119,20 +113,12 @@ struct thread* arch_create_thread(char *name, void (*function)(void *),
 
 void run_idle_thread(void)
 {
-    /* Switch stacks and run the thread */ 
-#if defined(__i386__)
-    __asm__ __volatile__("mov %0,%%esp\n\t"
-                         "push %1\n\t" 
-                         "ret"                                            
-                         :"=m" (idle_thread->sp)
-                         :"m" (idle_thread->ip));                          
-#elif defined(__x86_64__)
-    __asm__ __volatile__("mov %0,%%rsp\n\t"
-                         "push %1\n\t" 
-                         "ret"                                            
-                         :"=m" (idle_thread->sp)
-                         :"m" (idle_thread->ip));                                                    
-#endif
+    /* Switch stacks and run the thread */
+    asm volatile ( "mov %[sp], %%"ASM_SP"\n\t"
+                   "jmp *%[ip]\n\t"
+                   :
+                   : [sp] "m" (idle_thread->sp),
+                     [ip] "m" (idle_thread->ip) );
 }
 
 unsigned long __local_irq_save(void)
index ee34d7849e7bfb29f58d900636f4fc9ac2c10ab8..0095be1342b83e6eaa8fb133e70769757da080ad 100644 (file)
 #define TRAP_deferred_nmi     31
 #define TRAP_xen_callback     32
 
+#if defined(__i386__)
+#define __SZ    "l"
+#define __REG   "e"
+#else
+#define __SZ    "q"
+#define __REG   "r"
+#endif
+
+#define ASM_SP  __REG"sp"
+
 /* Everything below this point is not included by assembler (.S) files. */
 #ifndef __ASSEMBLY__
 
@@ -141,14 +151,6 @@ do {                                                                       \
 
 #else
 
-#if defined(__i386__)
-#define __SZ "l"
-#define __REG "e"
-#else
-#define __SZ "q"
-#define __REG "r"
-#endif
-
 #define __cli() asm volatile ( "cli" : : : "memory" )
 #define __sti() asm volatile ( "sti" : : : "memory" )