[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[mini-os master] Mini-OS: add some macros for asm statements



commit 618e99105e7433913ca00a3da5373915d7e1343c
Author:     Juergen Gross <jgross@xxxxxxxx>
AuthorDate: Mon Jul 22 12:46:43 2024 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Mon Jul 22 12:46:43 2024 +0200

    Mini-OS: add some macros for asm statements
    
    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@xxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 arch/x86/sched.c | 34 ++++++++++------------------------
 include/x86/os.h | 18 ++++++++++--------
 2 files changed, 20 insertions(+), 32 deletions(-)

diff --git a/arch/x86/sched.c b/arch/x86/sched.c
index dabe6fd..3c02647 100644
--- a/arch/x86/sched.c
+++ b/arch/x86/sched.c
@@ -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)
diff --git a/include/x86/os.h b/include/x86/os.h
index ee34d78..0095be1 100644
--- a/include/x86/os.h
+++ b/include/x86/os.h
@@ -61,6 +61,16 @@
 #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" )
 
--
generated by git-patchbot for /home/xen/git/mini-os.git#master



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.