Skip to contentSkip to conversation

64bit arch patch for Mini-OS

PATCH New Grzegorz Milos 1 participant 1 message May 1, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 64bit arch patch for Mini-OS

The patch fixes 64bit version of Mini-OS. It encompasses the following:
a) 64-bit switch_to scheduler macro (by Aravindh Puthiyaparambil)
b) implements 64-bit hypervisor_callback
c) fixes thread creation issues (thread_starter used to perform initialisation)

Keir could you apply?

Thanks
Gregor

extras/mini-os/console/console.c +1 -1
diff -r c9b0b655c052 -r 141811b3244c extras/mini-os/console/console.c
@@ -128,7 +128,7 @@
 {
     va_list       args;
     va_start(args, fmt);
-    print(0, fmt, args);
+    print(1, fmt, args);
     va_end(args);        
 }
 
extras/mini-os/events.c +17 -1
diff -r c9b0b655c052 -r 141811b3244c extras/mini-os/events.c
@@ -106,6 +106,17 @@
 	unbind_evtchn(port);
 }
 
+#if defined(__x86_64__)
+/* Allocate 4 pages for the irqstack */
+#define STACK_PAGES 4
+char irqstack[1024 * 4 * STACK_PAGES];
+
+static struct pda
+{
+    int irqcount;       /* offset 0 (used in x86_64.S) */
+    char *irqstackptr;  /*        8 */
+} cpu0_pda;
+#endif
 
 /*
  * Initially all events are without a handler and disabled
@@ -113,7 +124,12 @@
 void init_events(void)
 {
     int i;
-
+#if defined(__x86_64__)
+    asm volatile("movl %0,%%fs ; movl %0,%%gs" :: "r" (0));
+    wrmsrl(0xc0000101, &cpu0_pda); /* 0xc0000101 is MSR_GS_BASE */
+    cpu0_pda.irqcount = -1;
+    cpu0_pda.irqstackptr = irqstack + 1024 * 4 * STACK_PAGES;
+#endif
     /* inintialise event handler */
     for ( i = 0; i < NR_EVS; i++ )
     {
extras/mini-os/hypervisor.c +1 -1
diff -r c9b0b655c052 -r 141811b3244c extras/mini-os/hypervisor.c
@@ -41,8 +41,8 @@
     shared_info_t *s = HYPERVISOR_shared_info;
     vcpu_info_t   *vcpu_info = &s->vcpu_info[cpu];
 
+   
     vcpu_info->evtchn_upcall_pending = 0;
-    
     /* NB. No need for a barrier here -- XCHG is a barrier on x86. */
     l1 = xchg(&vcpu_info->evtchn_pending_sel, 0);
     while ( l1 != 0 )
extras/mini-os/include/mm.h +1 -1
diff -r c9b0b655c052 -r 141811b3244c extras/mini-os/include/mm.h
@@ -148,7 +148,7 @@
 }
 
 #if defined(__x86_64__)
-#define VIRT_START              0xFFFFFFFF00000000UL
+#define VIRT_START              0xFFFFFFFF80000000UL
 #elif defined(__i386__)
 #define VIRT_START              0xC0000000UL
 #endif
extras/mini-os/include/os.h +7 -0
diff -r c9b0b655c052 -r 141811b3244c extras/mini-os/include/os.h
@@ -434,6 +434,13 @@
      (val) = ((unsigned long)__a) | (((unsigned long)__d)<<32); \
 } while(0)
 
+#define wrmsr(msr,val1,val2) \
+      __asm__ __volatile__("wrmsr" \
+                           : /* no outputs */ \
+                           : "c" (msr), "a" (val1), "d" (val2))
+
+#define wrmsrl(msr,val) wrmsr(msr,(u32)((u64)(val)),((u64)(val))>>32)
+
 
 #else /* ifdef __x86_64__ */
 #error "Unsupported architecture"
extras/mini-os/include/sched.h +5 -3
diff -r c9b0b655c052 -r 141811b3244c extras/mini-os/include/sched.h
@@ -7,8 +7,8 @@
 {
     char *name;
     char *stack;
-    unsigned long eps;
-    unsigned long eip;
+    unsigned long sp;  /* Stack pointer */
+    unsigned long ip;  /* Instruction pointer */
     struct list_head thread_list;
     u32 flags;
 };
@@ -25,7 +25,9 @@
     struct thread **current;
 #ifdef __i386__    
     __asm__("andl %%esp,%0; ":"=r" (current) : "r" (~8191UL));
-#endif    
+#else
+    __asm__("andq %%rsp,%0; ":"=r" (current) : "r" (~8191UL));
+#endif 
     return *current;
 }
           
extras/mini-os/kernel.c +25 -1
diff -r c9b0b655c052 -r 141811b3244c extras/mini-os/kernel.c
@@ -35,6 +35,8 @@
 #include <lib.h>
 #include <sched.h>
 #include <xenbus.h>
+#include <xen/features.h>
+#include <xen/version.h>
 
 /*
  * Shared page for communicating with the hypervisor.
@@ -85,6 +87,26 @@
     test_xenbus();
 }
 
+
+u8 xen_features[XENFEAT_NR_SUBMAPS * 32];
+
+void setup_xen_features(void)
+{
+    xen_feature_info_t fi;
+    int i, j;
+
+    for (i = 0; i < XENFEAT_NR_SUBMAPS; i++) 
+    {
+        fi.submap_idx = i;
+        if (HYPERVISOR_xen_version(XENVER_get_features, &fi) < 0)
+            break;
+        
+        for (j=0; j<32; j++)
+            xen_features[i*32+j] = !!(fi.submap & 1<<j);
+    }
+}
+
+
 /*
  * INITIAL C ENTRY POINT.
  */
@@ -127,7 +149,9 @@
     printk("  flags:      0x%x\n",  (unsigned int)si->flags);
     printk("  cmd_line:   %s\n",  
            si->cmd_line ? (const char *)si->cmd_line : "NULL");
+    printk("  stack:      %p-%p\n", stack, stack + 8192);
 
+    setup_xen_features();
 
     /* Init memory management. */
     init_mm();
@@ -146,7 +170,7 @@
  
     /* Init XenBus from a separate thread */
     create_thread("init_xs", init_xs, NULL);
-    
+
     /* Everything initialised, start idle thread */
     run_idle_thread();
 }
extras/mini-os/minios-x86_64.lds +1 -1
diff -r c9b0b655c052 -r 141811b3244c extras/mini-os/minios-x86_64.lds
@@ -3,7 +3,7 @@
 ENTRY(_start)
 SECTIONS
 {
-  . = 0xFFFFFFFF00000000;
+  . = 0xFFFFFFFF80000000;
   _text = .;			/* Text and read-only data */
   .text : {
 	*(.text)
extras/mini-os/sched.c +63 -28

157 lines not on this page · raw message

extras/mini-os/x86_32.S +8 -0
diff -r c9b0b655c052 -r 141811b3244c extras/mini-os/x86_32.S
@@ -286,3 +286,11 @@
 	pushl $0
 	pushl $do_spurious_interrupt_bug
 	jmp do_exception
+
+ENTRY(thread_starter)
+    popl %eax
+    popl %ebx
+    pushl %eax
+    call *%ebx
+    call exit_thread 
+    
extras/mini-os/x86_64.S +256 -3

273 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel