Merge branch 'master' into proc-work
authorBarret Rhoden <brho@cs.berkeley.edu>
Tue, 4 Aug 2009 02:44:41 +0000 (19:44 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 4 Aug 2009 02:44:41 +0000 (19:44 -0700)
Conflicts:
kern/src/Makefrag
kern/src/manager.c

17 files changed:
.gitignore
GNUmakefile
kern/Makefrag
kern/arch/i386/atomic.h
kern/arch/i386/mmu.h
kern/arch/sparc/Makefrag
kern/boot [deleted symlink]
kern/include/arch [deleted symlink]
kern/include/smp.h
kern/src/Makefrag
kern/src/env.c
kern/src/init.c
kern/src/kfs.c
kern/src/manager.c
kern/src/syscall.c
kern/src/testing.c
user/Makefrag

index a5dde3b..8e29928 100644 (file)
@@ -12,3 +12,7 @@ hdd.img
 *.*~
 Makelocal
 ros-project.tmproj
+kern/boot
+kern/include/arch
+kern/src/arch
+
index 7b8e140..399da63 100644 (file)
@@ -12,11 +12,11 @@ OBJDIR := obj
 # User defined constants passed on the command line 
 TARGET_ARCH := i386
 
+-include Makelocal
+
 # Make sure that 'all' is the first target
 all: symlinks
 
--include Makelocal
-
 TOP_DIR := .
 ARCH_DIR := $(TOP_DIR)/kern/arch
 INCLUDE_DIR := $(TOP_DIR)/kern/include
@@ -83,12 +83,10 @@ endif
 # List of directories that the */Makefrag makefile fragments will add to
 OBJDIRS :=
 
-kern/boot/Makefrag: symlinks
-
 symlinks:
-       @-unlink kern/include/arch
+       @rm -f kern/include/arch
        @ln -s ../arch/$(TARGET_ARCH)/ kern/include/arch
-       @-unlink kern/boot
+       @rm -f kern/boot
        @ln -s arch/$(TARGET_ARCH)/boot/ kern/boot
 
 # Include Makefrags for subdirectories
@@ -113,7 +111,10 @@ $(OBJDIR)/.deps: $(foreach dir, $(OBJDIRS), $(wildcard $(OBJDIR)/$(dir)/*.d))
 
 # For deleting the build
 clean:
-       rm -rf $(OBJDIR)
+       @rm -rf $(OBJDIR)
+       @rm -f kern/boot
+       @rm -f kern/include/arch
+       @echo All clean and pretty!
 
 always:
        @:
index 3523940..3687d72 100644 (file)
@@ -4,7 +4,7 @@ KERN_CFLAGS := $(CFLAGS) -DROS_KERNEL
 KERN_CFLAGS += -I$(INCLUDE_DIR)
 KERN_LDFLAGS := $(LDFLAGS)
 
-include $(KERN_DIR)/boot/Makefrag
+include $(KERN_DIR)/arch/$(TARGET_ARCH)/boot/Makefrag
 include $(KERN_DIR)/ivy/Makefrag
 include $(KERN_DIR)/arch/$(TARGET_ARCH)/Makefrag
 include $(KERN_DIR)/src/Makefrag
index 9ba650d..932887c 100644 (file)
@@ -7,33 +7,47 @@
 #define rmb() ({ asm volatile("lfence"); })
 #define wmb() 
 
-//linux style atomic ops
-typedef struct {volatile uint32_t real_num;} atomic_t;
-#define atomic_read(atom) ((atom)->real_num)
-#define atomic_set(atom, val) (((atom)->real_num) = (val))
-#define atomic_init(i) {(i)}
-//and the atomic incs, etc take an atomic_t ptr, deref inside
-
-static inline void atomic_inc(atomic_t* number);
-static inline void atomic_dec(atomic_t* number);
+typedef void* atomic_t;
+
+static inline void atomic_init(atomic_t *number, int32_t val);
+static inline int32_t atomic_read(atomic_t *number);
+static inline void atomic_set(atomic_t *number, int32_t val);
+static inline void atomic_inc(atomic_t *number);
+static inline void atomic_dec(atomic_t *number);
 static inline void atomic_andb(volatile uint8_t* number, uint8_t mask);
 static inline void spin_lock(volatile uint32_t* lock);
 static inline void spin_unlock(volatile uint32_t* lock);
 
 /* Inlined functions declared above */
+static inline void atomic_init(atomic_t *number, int32_t val)
+{
+       asm volatile("movl %1,%0" : "=m"(*number) : "r"(val));
+}
+
+static inline int32_t atomic_read(atomic_t *number)
+{
+       int32_t val;
+       asm volatile("movl %1,%0" : "=r"(val) : "m"(*number));
+       return val;
+}
+
+static inline void atomic_set(atomic_t *number, int32_t val)
+{
+       asm volatile("movl %1,%0" : "=m"(*number) : "r"(val));
+}
 
 // need to do this with pointers and deref.  %0 needs to be the memory address
-static inline void atomic_inc(atomic_tnumber)
+static inline void atomic_inc(atomic_t *number)
 {
-       asm volatile("lock incl %0" : "=m"(number->real_num) : : "cc");
+       asm volatile("lock incl %0" : "=m"(*number) : : "cc");
 }
 
-static inline void atomic_dec(atomic_tnumber)
+static inline void atomic_dec(atomic_t *number)
 {
-       asm volatile("lock decl %0" : "=m"(number->real_num) : : "cc");
+       asm volatile("lock decl %0" : "=m"(*number) : : "cc");
 }
 
-static inline void atomic_andb(uint8_t* number, uint8_t mask)
+static inline void atomic_andb(volatile uint8_t *number, uint8_t mask)
 {
        asm volatile("lock andb %1,%0" : "=m"(*number) : "r"(mask) : "cc");
 }
index 804260d..115b810 100644 (file)
 #define PTE_USER_RW    (PTE_W | PTE_U) // Kernel/User Read/Write
 #define PTE_USER_RO    PTE_U           // Kernel/User Read-Only
 
-
-#define VALID_USER_PERMS(perm) \
-       (((perm) == PTE_U) || ((perm) == (PTE_U | PTE_W))) 
-
 // The PTE_AVAIL bits aren't used by the kernel or interpreted by the
 // hardware, so user processes are allowed to set them arbitrarily.
 #define PTE_AVAIL      0xE00   // Available for software use
index 519181e..5357327 100644 (file)
@@ -4,7 +4,7 @@
 # where the GNUmakefile is located.
 #
 
-KERN_ARCH_SRC_DIR = $(KERN_DIR)/src/arch
+KERN_ARCH_SRC_DIR = $(KERN_DIR)/arch/$(TARGET_ARCH)
 
 # entry.S must be first, so that it's the first code in the text segment!!!
 #
diff --git a/kern/boot b/kern/boot
deleted file mode 120000 (symlink)
index 1a02482..0000000
--- a/kern/boot
+++ /dev/null
@@ -1 +0,0 @@
-arch/i386/boot/
\ No newline at end of file
diff --git a/kern/include/arch b/kern/include/arch
deleted file mode 120000 (symlink)
index 02e569b..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../arch/i386/
\ No newline at end of file
index 77909b4..d8c1fb0 100644 (file)
 #include <atomic.h>
 #include <workqueue.h>
 
-// be careful changing this, esp if you go over 16
-#define NUM_HANDLER_WRAPPERS           5
-
-typedef struct HandlerWrapper {
-       checklist_t* cpu_list;
-       uint8_t vector;
-} handler_wrapper_t;
-
 // will want this padded out to cacheline alignment
 struct per_cpu_info {
        uint32_t lock;
index 5c7cfa0..724d6bf 100644 (file)
@@ -36,17 +36,21 @@ KERN_SRCFILES := $(KERN_ARCH_SRCFILES) \
 KERN_SRCFILES := $(wildcard $(KERN_SRCFILES))
 
 KERN_APPFILES := \
-                    $(USER_APPS_ROSLIB_DIR)/proctests \
-                    $(USER_APPS_ROSLIB_DIR)/fptest \
-                    $(USER_APPS_ROSLIB_DIR)/null \
-                    $(USER_APPS_ROSLIB_DIR)/hello \
-                    $(USER_APPS_ROSLIB_DIR)/spawn \
-                    $(USER_APPS_PARLIB_DIR)/channel_test_client \
-                    $(USER_APPS_PARLIB_DIR)/channel_test_server \
-                    $(USER_APPS_ROSLIB_DIR)/measurements
-#                    $(USER_APPS_PARLIB_DIR)/draw_nanwan
-#                    $(USER_APPS_PARLIB_DIR)/open_read \
-#                    $(USER_APPS_PARLIB_DIR)/hello
+                 $(USER_APPS_ROSLIB_DIR)/proctests \
+                 $(USER_APPS_ROSLIB_DIR)/fptest \
+                 $(USER_APPS_ROSLIB_DIR)/null \
+                 $(USER_APPS_ROSLIB_DIR)/spawn \
+                 $(USER_APPS_ROSLIB_DIR)/hello
+
+ifeq ($(TARGET_ARCH),i386)
+       KERN_APPFILES += \
+                        $(USER_APPS_PARLIB_DIR)/channel_test_client \
+                        $(USER_APPS_PARLIB_DIR)/channel_test_server \
+                        $(USER_APPS_ROSLIB_DIR)/measurements
+#                       $(USER_APPS_PARLIB_DIR)/draw_nanwan \
+#                       $(USER_APPS_PARLIB_DIR)/open_read \
+#                       $(USER_APPS_PARLIB_DIR)/hello
+endif
 
 KERN_LDFLAGS   := $(KERN_LDFLAGS) -L$(OBJDIR)/$(KERN_DIR) \
                   -T $(ARCH_DIR)/$(TARGET_ARCH)/kernel.ld
index 7a19774..fa5fd05 100644 (file)
@@ -22,7 +22,7 @@
 #include <ros/error.h>
 
 env_t *envs = NULL;            // All environments
-atomic_t num_envs = atomic_init(0);
+atomic_t num_envs;
 // TODO: make this a struct of info including the pointer and cacheline-align it
 // This lets the kernel know what process is running on the core it traps into.
 // A lot of the Env business, including this and its usage, will change when we
@@ -88,6 +88,8 @@ void
 env_init(void)
 {
        int i;
+
+       atomic_init(&num_envs, 0);
        LIST_INIT(&env_free_list);
        assert(envs != NULL);
        for (i = NENV-1; i >= 0; i--) { TRUSTEDBLOCK // asw ivy workaround
index c23b53f..76481bd 100644 (file)
@@ -22,7 +22,6 @@
 #include <pmap.h>
 #include <process.h>
 #include <trap.h>
-#include <testing.h>
 #include <syscall.h>
 #include <kclock.h>
 #include <manager.h>
@@ -58,15 +57,6 @@ void kernel_init(multiboot_info_t *mboot_info)
 
        // this returns when all other cores are done and ready to receive IPIs
        smp_boot();
-       test_smp_call_functions();
-       test_checklists();
-       test_barrier();
-       test_print_info();
-       /*
-       test_lapic_status_bit();
-       test_ipi_sending();
-       test_pit();
-       */
 
        manager();
 }
index 819c8c4..df853fb 100644 (file)
 DECL_PROG(roslib_proctests);
 DECL_PROG(roslib_fptest);
 DECL_PROG(roslib_null);
-DECL_PROG(roslib_hello);
 DECL_PROG(roslib_spawn);
+DECL_PROG(roslib_hello);
+
+#ifdef __i386__
 DECL_PROG(parlib_channel_test_client);
 DECL_PROG(parlib_channel_test_server);
 DECL_PROG(roslib_measurements);
+#endif
 
 struct kfs_entry kfs[MAX_KFS_FILES] = {
        KFS_ENTRY(roslib_proctests)
        KFS_ENTRY(roslib_fptest)
        KFS_ENTRY(roslib_null)
-       KFS_ENTRY(roslib_hello)
        KFS_ENTRY(roslib_spawn)
+       KFS_ENTRY(roslib_hello)
+       #ifdef __i386__
        KFS_ENTRY(parlib_channel_test_client)
        KFS_ENTRY(parlib_channel_test_server)
        KFS_ENTRY(roslib_measurements)
+       #endif
 };
 
 ssize_t kfs_lookup_path(char* path)
index 6a813d5..be5306e 100644 (file)
@@ -35,6 +35,17 @@ void manager(void)
                        proc_set_state(envs[0], PROC_RUNNABLE_S);
                        env_run(envs[0]);
                        break;
+       #ifdef __i386__
+               case 1:
+                       panic("Do not panic");
+                       envs[0] = ENV_CREATE(parlib_channel_test_client);
+                       envs[1] = ENV_CREATE(parlib_channel_test_server);
+                       smp_call_function_single(1, run_env_handler, envs[0], 0);
+                       smp_call_function_single(2, run_env_handler, envs[1], 0);
+                       break;
+               case 2:
+               case 3:
+       #else // sparc
                case 1:
                        panic("Do not panic");
                        envs[0] = ENV_CREATE(roslib_proctests);
@@ -45,11 +56,8 @@ void manager(void)
                        envs[4] = ENV_CREATE(roslib_fptest);
                        envs[5] = ENV_CREATE(roslib_hello);
                        envs[6] = ENV_CREATE(roslib_null);
-                       //envs[6] = ENV_CREATE(roslib_measurements);
                        env_run(envs[0]);
                        break;
-                       #if 0
-                       #endif
                case 2:
                        #if 0
                        // reminder of how to spawn remotely
@@ -61,19 +69,30 @@ void manager(void)
                        process_workqueue();
                        #endif
                case 3:
+       #endif
+
                #if 0
-               case 0:
+               case 4:
                        printk("Beginning Tests\n");
                        test_run_measurements(progress-1);  // should never return
                        break;
-               case 1:
+               case 5:
                        envs[0] = ENV_CREATE(parlib_channel_test_client);
                        envs[1] = ENV_CREATE(parlib_channel_test_server);
                        smp_call_function_single(1, run_env_handler, envs[0], 0);
                        smp_call_function_single(2, run_env_handler, envs[1], 0);
-               case 2:
-               case 3:
+               case 6:
+               #endif
                case 4:
+                       /*
+                       test_smp_call_functions();
+                       test_checklists();
+                       test_barrier();
+                       test_print_info();
+                       test_lapic_status_bit();
+                       test_ipi_sending();
+                       test_pit();
+                       */
                case 5:
                case 6:
                case 7:
@@ -84,9 +103,7 @@ void manager(void)
                case 12:
                case 13:
                case 14:
-                       test_run_measurements(progress-1);
-                       break;
-               #endif
+                       //test_run_measurements(progress-1);
                default:
                        printk("Manager Progress: %d\n", progress);
                        schedule();
index 5ef1bac..537e42c 100644 (file)
@@ -59,8 +59,8 @@ static ssize_t sys_shared_page_alloc(env_t* p1,
                                      int p1_flags, int p2_flags
                                     ) 
 {
-       if (!VALID_USER_PERMS(p1_flags)) return -EPERM;
-       if (!VALID_USER_PERMS(p2_flags)) return -EPERM;
+       //if (!VALID_USER_PERMS(p1_flags)) return -EPERM;
+       //if (!VALID_USER_PERMS(p2_flags)) return -EPERM;
 
        page_t* page;
        env_t* p2 = &(envs[ENVX(p2_id)]);
index 25a6bbf..021a06e 100644 (file)
@@ -74,7 +74,7 @@ void test_pic_reception(void)
        while(1);
 }
 
-#endif
+#endif // __i386__
 
 void test_print_info(void)
 {
@@ -268,7 +268,7 @@ void test_checklists(void)
 
 }
 
-atomic_t a = atomic_init(0), b = atomic_init(0), c = atomic_init(0);
+atomic_t a, b, c;
 
 void test_incrementer_handler(trapframe_t *tf, void* data)
 {
@@ -284,6 +284,9 @@ void test_null_handler(trapframe_t *tf, void* data)
 void test_smp_call_functions(void)
 {
        int i;
+       atomic_init(&a, 0);
+       atomic_init(&b, 0);
+       atomic_init(&c, 0);
        handler_wrapper_t *waiter0 = 0, *waiter1 = 0, *waiter2 = 0, *waiter3 = 0,
                          *waiter4 = 0, *waiter5 = 0;
        uint8_t me = core_id();
@@ -401,7 +404,7 @@ void test_lapic_status_bit(void)
        printk("IPIs received (should be %d): %d\n", a, NUM_IPI);
        // hopefully that handler never fires again.  leaving it registered for now.
 }
-#endif
+#endif // __i386__
 
 /******************************************************************************/
 /*            Test Measurements: Couples with measurement.c                   */
@@ -417,6 +420,8 @@ static void wait_for_all_envs_to_die(void)
                cpu_relax();
 }
 
+#if 0
+
 // this never returns.
 static void sync_tests(int start_core, int num_threads, int job_num)
 {
@@ -533,6 +538,8 @@ void test_run_measurements(uint32_t job_num)
        panic("Error in test setup!!");
 }
 
+#endif // __i386__
+
 /************************************************************/
 /* ISR Handler Functions */
 
@@ -576,7 +583,7 @@ void test_print_info_handler(trapframe_t *tf, void* data)
                read_msr(0x20c), read_msr(0x20d));
        cprintf("MTRR Phys7 Base = 0x%016llx, Mask = 0x%016llx\n",
                read_msr(0x20e), read_msr(0x20f));
-#endif
+#endif // __i386__
        cprintf("----------------------------\n");
        spin_unlock_irqsave(&print_info_lock);
 }
@@ -616,11 +623,12 @@ void test_pit(void)
        enable_irq();
        lapic_set_timer(10000000, FALSE);
 
-       atomic_t waiting = atomic_init(1);
+       atomic_t waiting;
+       atomic_init(&waiting, 1);
        register_interrupt_handler(interrupt_handlers, test_vector,
                                   test_waiting_handler, &waiting);
        while(atomic_read(&waiting))
                cpu_relax();
        cprintf("End now\n");
 }
-#endif
+#endif // __i386__
index 0596f5e..57a7397 100644 (file)
@@ -4,5 +4,9 @@ USER_CFLAGS  := $(CFLAGS) -DROS_USER
 USER_LDFLAGS := $(LDFLAGS)
 
 include $(USER_DIR)/roslib/Makefrag
-include $(USER_DIR)/parlib/Makefrag
+
+ifeq ($(TARGET_ARCH),i386)
+       include $(USER_DIR)/parlib/Makefrag
+endif
+
 include $(USER_DIR)/apps/Makefrag