Skip to contentSkip to conversation

mini-os implementation of xenbus, some 64bit fixes

PATCH New Grzegorz Milos 1 participant 1 message Sep 7, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mini-os implementation of xenbus, some 64bit fixes

This patch ports the Linux implementation of xenbus, in order to do that very simple threading support is introduced. Apart of that numerous fixes for 64 bit are included. Mini-os now compiles (for 64bit) but requires memory management and threading fixes before it works as well as 32bit version.

Gregor

# HG changeset patch
# User [email protected]
# Node ID 8d393e2d3b6633cf0d97d7bf83f73cd441e4dbdb
# Parent de8a90fc266798037134fa8b96a39b2150b3a0f6
Xenbus implementation ported from Linux to Mini-os, simple thread support introduced to simplify the porting. 64 bit version of Mini-os now compiles, but does not work because of the pagetables and some bits of scheduler not being written.

extras/mini-os/Makefile +7 -4
diff -r de8a90fc2667 -r 8d393e2d3b66 extras/mini-os/Makefile
@@ -31,16 +31,18 @@
 OBJS := $(TARGET_ARCH).o
 OBJS += $(patsubst %.c,%.o,$(wildcard *.c))
 OBJS += $(patsubst %.c,%.o,$(wildcard lib/*.c))
-
+OBJS += $(patsubst %.c,%.o,$(wildcard xenbus/*.c))
+										   
 HDRS := $(wildcard include/*.h)
 HDRS += $(wildcard include/xen/*.h)
 
 default: $(TARGET)
 
-xen-public:
+links:
 	[ -e include/xen ] || ln -sf ../../../xen/include/public include/xen
-
-$(TARGET): xen-public $(OBJS)
+	[ -e xenbus/xenstored.h ] || ln -sf ../../../tools/xenstore/xenstored.h xenbus/xenstored.h
+	
+$(TARGET): links $(OBJS)
 	$(LD) -N -T minios-$(TARGET_ARCH).lds $(OBJS) -o [email protected]
 	gzip -f -9 -c [email protected] >[email protected]
 
@@ -55,3 +57,4 @@
 %.o: %.S $(HDRS) Makefile
 	$(CC) $(CFLAGS) -D__ASSEMBLY__ -c $< -o $@
 
+
extras/mini-os/events.c +20 -18
diff -r de8a90fc2667 -r 8d393e2d3b66 extras/mini-os/events.c
@@ -17,13 +17,13 @@
  */
 
 #include <os.h>
+#include <mm.h>
 #include <hypervisor.h>
 #include <events.h>
 #include <lib.h>
 
-#include <xen/event_channel.h>
 static ev_action_t ev_actions[NR_EVS];
-void default_handler(u32 port, struct pt_regs *regs);
+void default_handler(int port, struct pt_regs *regs);
 
 
 /*
@@ -32,7 +32,6 @@
 int do_event(u32 port, struct pt_regs *regs)
 {
     ev_action_t  *action;
-
     if (port >= NR_EVS) {
         printk("Port number too large: %d\n", port);
         return 0;
@@ -57,11 +56,23 @@
 
 }
 
+void bind_evtchn( u32 port, void (*handler)(int, struct pt_regs *) )
+{
+ 	if(ev_actions[port].handler)
+        printk("WARN: Handler for port %d already registered, replacing\n",
+				port);
+
+	ev_actions[port].handler = handler;
+	ev_actions[port].status &= ~EVS_DISABLED;	  
+ 
+	/* Finally unmask the port */
+	unmask_evtchn(port);
+}
+
 int bind_virq( u32 virq, void (*handler)(int, struct pt_regs *) )
 {
 	evtchn_op_t op;
 	int ret = 0;
-	u32 port;
 
 	/* Try to bind the virq to a port */
 	op.cmd = EVTCHNOP_bind_virq;
@@ -73,21 +84,12 @@
 		printk("Failed to bind virtual IRQ %d\n", virq);
 		goto out;
     }
-
-    port = op.u.bind_virq.port;
-	
-	if(ev_actions[port].handler)
-        printk("WARN: Handler for port %d already registered, replacing\n",
-				port);
-
-	ev_actions[port].handler = handler;
-	ev_actions[port].status &= ~EVS_DISABLED;
-	
-	/* Finally unmask the port */
-	unmask_evtchn(port);
+    bind_evtchn(op.u.bind_virq.port, handler);	
 out:
 	return ret;
 }
+
+
 
 /*
  * Initially all events are without a handler and disabled
@@ -100,10 +102,10 @@
     for ( i = 0; i < NR_EVS; i++ )
     {
         ev_actions[i].status  = EVS_DISABLED;
-        ev_actions[i].handler = NULL;
+        ev_actions[i].handler = default_handler;
     }
 }
 
-void default_handler(u32 port, struct pt_regs *regs) {
+void default_handler(int port, struct pt_regs *regs) {
     printk("[Port %d] - event received\n", port);
 }
extras/mini-os/include/events.h +11 -0
diff -r de8a90fc2667 -r 8d393e2d3b66 extras/mini-os/include/events.h
@@ -20,6 +20,7 @@
 #define _EVENTS_H_
 
 #include<traps.h>
+#include <xen/event_channel.h>
 
 #define NR_EVS 1024
 
@@ -39,6 +40,16 @@
 /* prototypes */
 int do_event(u32 port, struct pt_regs *regs);
 int bind_virq( u32 virq, void (*handler)(int, struct pt_regs *) );
+void bind_evtchn( u32 virq, void (*handler)(int, struct pt_regs *) );
 void init_events(void);
 
+static inline int notify_via_evtchn(int port)
+{
+    evtchn_op_t op;
+    op.cmd = EVTCHNOP_send;
+    op.u.send.local_port = port;
+    return HYPERVISOR_event_channel_op(&op);
+}
+
+
 #endif /* _EVENTS_H_ */
extras/mini-os/include/hypervisor.h +962 -267

1,288 lines not on this page · raw message

extras/mini-os/include/lib.h +26 -4
diff -r de8a90fc2667 -r 8d393e2d3b66 extras/mini-os/include/lib.h
@@ -60,10 +60,22 @@
 /* printing */
 #define printk  printf
 #define kprintf printf
-int printf(const char *fmt, ...);
-int vprintf(const char *fmt, va_list ap);
-int sprintf(char *buf, const char *cfmt, ...);
-int vsprintf(char *buf, const char *cfmt, va_list ap);
+#define _p(_x) ((void *)(unsigned long)(_x))
+void printf(const char *fmt, ...);
+int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
+int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
+int snprintf(char * buf, size_t size, const char *fmt, ...);
+int scnprintf(char * buf, size_t size, const char *fmt, ...);
+int vsprintf(char *buf, const char *fmt, va_list args);
+int sprintf(char * buf, const char *fmt, ...);
+int vsscanf(const char * buf, const char * fmt, va_list args);
+int sscanf(const char * buf, const char * fmt, ...);
+
+long simple_strtol(const char *cp,char **endp,unsigned int base);
+unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base);
+long long simple_strtoll(const char *cp,char **endp,unsigned int base);
+unsigned long long simple_strtoull(const char *cp,char **endp,unsigned int base);
+
 
 /* string and memory manipulation */
 int    memcmp(const void *cs, const void *ct, size_t count);
@@ -77,6 +89,16 @@
 size_t strlen(const char *s);
 char  *strchr(const char *s, int c);
 char  *strstr(const char *s1, const char *s2);
+char * strcat(char * dest, const char * src);
+
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
+struct kvec {
+    void *iov_base;
+    size_t iov_len;
+};
+
 
 
 #endif /* _LIB_H_ */
extras/mini-os/include/mm.h +16 -4
diff -r de8a90fc2667 -r 8d393e2d3b66 extras/mini-os/include/mm.h
@@ -24,6 +24,15 @@
 
 #ifndef _MM_H_
 #define _MM_H_
+
+#ifdef __i386__
+#include <xen/arch-x86_32.h>
+#endif
+
+#ifdef __x86_64__
+#include <xen/arch-x86_64.h>
+#endif
+
 
 #ifdef __x86_64__
 
@@ -56,6 +65,8 @@
 
 #define L1_PAGETABLE_ENTRIES    1024
 #define L2_PAGETABLE_ENTRIES    1024
+
+#elif defined(__x86_64__)
 #endif
 
 /* Given a virtual address, get an entry offset into a page table. */
@@ -97,13 +108,15 @@
 
 extern unsigned long *phys_to_machine_mapping;
 #define pfn_to_mfn(_pfn) (phys_to_machine_mapping[(_pfn)])
-#define mfn_to_pfn(_mfn) (machine_to_phys_mapping[(_mfn)])
 static __inline__ unsigned long phys_to_machine(unsigned long phys)
 {
     unsigned long machine = pfn_to_mfn(phys >> L1_PAGETABLE_SHIFT);
     machine = (machine << L1_PAGETABLE_SHIFT) | (phys & ~PAGE_MASK);
     return machine;
 }
+
+
+#define mfn_to_pfn(_mfn) (machine_to_phys_mapping[(_mfn)])
 static __inline__ unsigned long machine_to_phys(unsigned long machine)
 {
     unsigned long phys = mfn_to_pfn(machine >> L1_PAGETABLE_SHIFT);
@@ -119,16 +132,15 @@
 
 #define to_phys(x)                 ((unsigned long)(x)-VIRT_START)
 #define to_virt(x)                 ((void *)((unsigned long)(x)+VIRT_START))
-#define __va to_virt
-#define __pa to_phys
 
 #define virt_to_pfn(_virt)         (PFN_DOWN(to_phys(_virt)))
+#define mach_to_virt(_mach)        (to_virt(machine_to_phys(_mach)))
+#define mfn_to_virt(_mfn)          (mach_to_virt(_mfn << PAGE_SHIFT))
 
 void init_mm(void);
 unsigned long alloc_pages(int order);
 #define alloc_page()    alloc_pages(0);
 void free_pages(void *pointer, int order);
-//int is_mfn_mapped(unsigned long mfn);
 
 static __inline__ int get_order(unsigned long size)
 {
extras/mini-os/include/os.h +265 -108

483 lines not on this page · raw message

extras/mini-os/include/time.h +1 -1
diff -r de8a90fc2667 -r 8d393e2d3b66 extras/mini-os/include/time.h
@@ -58,6 +58,6 @@
 s_time_t get_s_time(void);
 s_time_t get_v_time(void);
 void     gettimeofday(struct timeval *tv);
-void     block(u32 millisecs);
+void     block_domain(u32 millisecs);
 
 #endif /* _TIME_H_ */
extras/mini-os/include/traps.h +32 -0
diff -r de8a90fc2667 -r 8d393e2d3b66 extras/mini-os/include/traps.h
@@ -17,6 +17,7 @@
 #ifndef _TRAPS_H_
 #define _TRAPS_H_
 
+#ifdef __i386__
 struct pt_regs {
 	long ebx;
 	long ecx;
@@ -34,7 +35,38 @@
 	long esp;
 	int  xss;
 };
+#elif __x86_64__
 
+struct pt_regs {
+	unsigned long r15;
+	unsigned long r14;
+	unsigned long r13;
+	unsigned long r12;
+	unsigned long rbp;
+	unsigned long rbx;
+/* arguments: non interrupts/non tracing syscalls only save upto here*/
+ 	unsigned long r11;
+	unsigned long r10;	
+	unsigned long r9;
+	unsigned long r8;
+	unsigned long rax;
+	unsigned long rcx;
+	unsigned long rdx;
+	unsigned long rsi;
+	unsigned long rdi;
+	unsigned long orig_rax;
+/* end of arguments */ 	
+/* cpu exception frame or undefined */
+	unsigned long rip;
+	unsigned long cs;
+	unsigned long eflags; 
+	unsigned long rsp; 
+	unsigned long ss;
+/* top of stack page */ 
+};
+
+
+#endif
 
 void dump_regs(struct pt_regs *regs);
 
extras/mini-os/include/types.h +8 -0
diff -r de8a90fc2667 -r 8d393e2d3b66 extras/mini-os/include/types.h
@@ -44,11 +44,19 @@
 typedef long long           quad_t;
 typedef unsigned long long  u_quad_t;
 typedef unsigned int        uintptr_t;
+
+typedef struct { unsigned long pte_low; } pte_t;
 #elif defined(__x86_64__)
 typedef long                quad_t;
 typedef unsigned long       u_quad_t;
 typedef unsigned long       uintptr_t;
+
+typedef struct { unsigned long pte; } pte_t;
 #endif
 
+
+
+
+#define INT_MAX         ((int)(~0U>>1))
 #define UINT_MAX            (~0U)
 #endif /* _TYPES_H_ */
extras/mini-os/kernel.c +13 -12
diff -r de8a90fc2667 -r 8d393e2d3b66 extras/mini-os/kernel.c
@@ -33,6 +33,8 @@
 #include <time.h>
 #include <types.h>
 #include <lib.h>
+#include <sched.h>
+#include <xenbus.h>
 
 /*
  * Shared page for communicating with the hypervisor.
@@ -59,10 +61,12 @@
 
 extern char shared_info[PAGE_SIZE];
 
+#define __pte(x) ((pte_t) { (0) } )
+
 static shared_info_t *map_shared_info(unsigned long pa)
 {
     if ( HYPERVISOR_update_va_mapping(
-        (unsigned long)shared_info, pa | 7, UVMF_INVLPG) )
+        (unsigned long)shared_info, __pte(pa | 7), UVMF_INVLPG) )
     {
         printk("Failed to map shared_info!!\n");
         *(int*)0=0;
@@ -77,7 +81,6 @@
 void start_kernel(start_info_t *si)
 {
     static char hello[] = "Bootstrapping...\n";
-    int i;
     (void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(hello), hello);
 
     /* Copy the start_info struct to a globally-accessible area. */
@@ -96,7 +99,6 @@
         (unsigned long)hypervisor_callback,
         (unsigned long)failsafe_callback, 0);
 #endif
-
     trap_init();
 
     /* ENABLE EVENT DELIVERY. This is disabled at start of day. */
@@ -119,7 +121,6 @@
      * If used for porting another OS, start here to figure out your
      * guest os entry point. Otherwise continue below...
      */
-
     /* init memory management */
     init_mm();
 
@@ -127,15 +128,15 @@
     init_events();
     /* init time and timers */
     init_time();
+    
+    /* init scheduler */
+    init_sched();
 
-    /* do nothing */
-    i = 0;
-    for ( ; ; ) 
-    {      
-//        HYPERVISOR_yield();
-        block(100);
-        i++;
-    }
+    /* init xenbus */
+    xs_init();
+    
+    /* Everything initialised, start idle thread */
+    run_idle_thread();
 }
 
 
extras/mini-os/lib/printf.c +735 -398

863 lines not on this page · raw message

extras/mini-os/lib/string.c +13 -0
diff -r de8a90fc2667 -r 8d393e2d3b66 extras/mini-os/lib/string.c

Lines of this file are not shown. View the raw message.

extras/mini-os/mm.c +4 -6
diff -r de8a90fc2667 -r 8d393e2d3b66 extras/mini-os/mm.c

Lines of this file are not shown. View the raw message.

extras/mini-os/time.c +2 -1
diff -r de8a90fc2667 -r 8d393e2d3b66 extras/mini-os/time.c

Lines of this file are not shown. View the raw message.

extras/mini-os/traps.c +6 -41

47 lines not on this page · raw message

extras/mini-os/include/ctype.h new file +79 -0

79 lines not on this page · raw message

extras/mini-os/include/err.h new file +31 -0
diff -r de8a90fc2667 -r 8d393e2d3b66 extras/mini-os/include/err.h

Lines of this file are not shown. View the raw message.

extras/mini-os/include/errno-base.h new file +39 -0
diff -r de8a90fc2667 -r 8d393e2d3b66 extras/mini-os/include/errno-base.h

Lines of this file are not shown. View the raw message.

extras/mini-os/include/errno.h new file +109 -0

109 lines not on this page · raw message

extras/mini-os/include/fcntl.h new file +89 -0

89 lines not on this page · raw message

extras/mini-os/include/list.h new file +187 -0

187 lines not on this page · raw message

extras/mini-os/include/sched.h new file +38 -0
diff -r de8a90fc2667 -r 8d393e2d3b66 extras/mini-os/include/sched.h

Lines of this file are not shown. View the raw message.

extras/mini-os/include/semaphore.h new file +46 -0

46 lines not on this page · raw message

extras/mini-os/include/wait.h new file +91 -0

91 lines not on this page · raw message

extras/mini-os/include/xenbus.h new file +89 -0

89 lines not on this page · raw message

extras/mini-os/sched.c new file +300 -0

300 lines not on this page · raw message

extras/mini-os/xenbus/Makefile new file +9 -0
diff -r de8a90fc2667 -r 8d393e2d3b66 extras/mini-os/xenbus/Makefile

Lines of this file are not shown. View the raw message.

extras/mini-os/xenbus/xenbus_comms.c new file +231 -0

231 lines not on this page · raw message

extras/mini-os/xenbus/xenbus_comms.h new file +40 -0
diff -r de8a90fc2667 -r 8d393e2d3b66 extras/mini-os/xenbus/xenbus_comms.h

Lines of this file are not shown. View the raw message.

extras/mini-os/xenbus/xenbus_xs.c new file +554 -0

554 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

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

Part of the diff is not shown here. View the raw message.