Merge commit 'origin' into net-dev
authorKevin Klues <klueska@eecs.berkeley.edu>
Wed, 1 Jul 2009 21:08:27 +0000 (14:08 -0700)
committerKevin Klues <klueska@eecs.berkeley.edu>
Wed, 1 Jul 2009 21:08:27 +0000 (14:08 -0700)
Conflicts:
include/ros/syscall.h
kern/src/Makefrag
kern/src/env.c
kern/src/manager.c
kern/src/syscall.c

1  2 
include/ros/syscall.h
kern/src/Makefrag
kern/src/env.c
kern/src/smp.c
kern/src/syscall.c

@@@ -14,14 -14,14 +14,17 @@@ enu
        SYS_cache_invalidate,
        SYS_cputs,
        SYS_cgetc,
-       SYS_getenvid,
        SYS_getcpuid,
-       SYS_env_destroy,
        SYS_serial_write,
        SYS_serial_read,
 +      SYS_eth_read,
 +      SYS_eth_write,
 +      SYS_run_binary,
+       SYS_getenvid,
+       SYS_env_destroy,
+       SYS_yield,
+       SYS_proc_create,
+       SYS_proc_run,
  
        SYS_endofcalls //Should always be last
  };
@@@ -45,7 -43,7 +45,8 @@@ KERN_SRCFILES := $(wildcard $(KERN_SRCF
  KERN_APPFILES :=    $(USER_APPS_PARLIB_DIR)/matrix \
                      $(USER_APPS_ROSLIB_DIR)/null \
                      $(USER_APPS_ROSLIB_DIR)/hello \
 +                    $(USER_APPS_PARLIB_DIR)/draw_nanwan_standalone \
+                     $(USER_APPS_ROSLIB_DIR)/proctests \
                      $(USER_APPS_ROSLIB_DIR)/measurements
  #                    $(USER_APPS_PARLIB_DIR)/draw_nanwan
  #                    $(USER_APPS_PARLIB_DIR)/open_read \
diff --cc kern/src/env.c
@@@ -554,13 -555,21 +555,23 @@@ env_destroy(env_t *e
         * and not from where we left off the last time we called manager.  That
         * would require us to save some context (and a stack to work on) here.
         */
 -      manager();
 -      assert(0); // never get here
 +      //manager();
 +      //assert(0); // never get here
 +
-       // ugly, but for now just linearly search through all possible
-       // environments for a runnable one.
-       for (int i = 0; i < NENV; i++) {
-               e = &envs[ENVX(i)];
++      schedule();
+ }
+ /* ugly, but for now just linearly search through all possible
+  * environments for a runnable one.
+  * the current *policy* is to round-robin the search
+  */
+ void schedule(void)
+ {
+       env_t *e;
+       static int last_picked = 0;
+       
+       for (int i = 0, j = last_picked + 1; i < NENV; i++, j = (j + 1) % NENV) {
+               e = &envs[ENVX(j)];
                // TODO: race here, if another core is just about to start this env.
                // Fix it by setting the status in something like env_dispatch when
                // we have multi-contexted processes
diff --cc kern/src/smp.c
Simple merge
  #include <pmap.h>
  #include <trap.h>
  #include <syscall.h>
 +#include <kmalloc.h>
  
- void syscall_wrapper(struct Trapframe *tf)
+ /* This is called from sysenter's asm, with the tf on the kernel stack. */
+ void sysenter_callwrapper(struct Trapframe *tf)
  {
        env_t* curenv = curenvs[lapic_get_id()];
-     curenv->env_tf = *tf;
-       //Re enable interrupts. sysenter disables them.
-       enable_irq();
+       curenv->env_tf = *tf;
        
-       curenv->env_tf.tf_regs.reg_eax =
-           (intreg_t) syscall(curenv,
-                              tf->tf_regs.reg_eax,
-                              tf->tf_regs.reg_edx,
-                              tf->tf_regs.reg_ecx,
-                              tf->tf_regs.reg_ebx,
-                              tf->tf_regs.reg_edi,
-                              0);
+       // The trapframe on the stack should be ignored from here on.
+       tf = &curenv->env_tf;
+       tf->tf_regs.reg_eax = (intreg_t) syscall(curenv,
+                                                tf->tf_regs.reg_eax,
+                                                tf->tf_regs.reg_edx,
+                                                tf->tf_regs.reg_ecx,
+                                                tf->tf_regs.reg_ebx,
+                                                tf->tf_regs.reg_edi,
+                                                0);
        env_run(curenv);
  }
  
@@@ -73,99 -72,6 +74,99 @@@ static ssize_t sys_serial_read(env_t* e
        #endif
  }
  
-               return -E_NO_MEM;
 +static ssize_t sys_run_binary(env_t* e, void* binary_buf, void* arg, size_t len) {
 +      uint8_t* new_binary = kmalloc(len, 0);
 +      if(new_binary == NULL)
-               return -E_INVAL;
++              return -ENOMEM;
 +      memcpy(new_binary, binary_buf, len);
 +
 +      env_t* env = env_create((uint8_t*)new_binary, len);
 +      kfree(new_binary);
 +      
 +      e->env_status = ENV_RUNNABLE;
 +      env_run(env);
 +      return 0;
 +}
 +
 +// This is probably not a syscall we want. Its hacky. Here just for syscall stuff until get a stack.
 +static ssize_t sys_eth_write(env_t* e, const char *DANGEROUS buf, size_t len) 
 +{ 
 +      extern int eth_up;
 +      
 +      if (eth_up) {
 +              
 +              char *COUNT(len) _buf = user_mem_assert(e, buf, len, PTE_U);
 +              int total_sent = 0;
 +              int just_sent = 0;
 +              int cur_packet_len = 0;
 +              while (total_sent != len) {
 +                      cur_packet_len = ((len - total_sent) > MAX_PACKET_DATA) ? MAX_PACKET_DATA : (len - total_sent);
 +                      char* wrap_buffer = packet_wrap(buf + total_sent, cur_packet_len);
 +                      just_sent = send_frame(wrap_buffer, cur_packet_len + PACKET_HEADER_SIZE);
 +                      
 +                      if (just_sent < 0)
 +                              return 0; // This should be an error code of its own
 +                              
 +                      if (wrap_buffer)
 +                              kfree(wrap_buffer);
 +                              
 +                      total_sent += cur_packet_len;
 +              }
 +              
 +              return (ssize_t)len;
 +              
 +      }
 +      else
-       return -E_INVAL;
++              return -EINVAL;
 +}
 +/*
 +static ssize_t sys_eth_write(env_t* e, const char *DANGEROUS buf, size_t len) 
 +{ 
 +      extern int eth_up;
 +      
 +      if (eth_up) {
 +              
 +              char *COUNT(len) _buf = user_mem_assert(e, buf, len, PTE_U);
 +              
 +              return(send_frame(buf, len));
 +      }
-               return -E_INVAL;
++      return -EINVAL;
 +}
 +*/
 +
 +
 +// This is probably not a syscall we want. Its hacky. Here just for syscall stuff until get a stack.
 +static ssize_t sys_eth_read(env_t* e, char *DANGEROUS buf, size_t len) 
 +{
 +      extern int eth_up;
 +      
 +      if (eth_up) {
 +              extern int packet_waiting;
 +              extern int packet_buffer_size;
 +              extern char* packet_buffer;
 +              extern char* packet_buffer_orig;
 +              extern int packet_buffer_pos;
 +                      
 +              if (packet_waiting == 0)
 +                      return 0;
 +                      
 +              int read_len = ((packet_buffer_pos + len) > packet_buffer_size) ? packet_buffer_size - packet_buffer_pos : len;
 +
 +              memcpy(buf, packet_buffer + packet_buffer_pos, read_len);
 +      
 +              packet_buffer_pos = packet_buffer_pos + read_len;
 +      
 +              if (packet_buffer_pos == packet_buffer_size) {
 +                      kfree(packet_buffer_orig);
 +                      packet_waiting = 0;
 +              }
 +      
 +              return read_len;
 +      }
 +      else
++              return -EINVAL;
 +}
 +
  // Invalidate the cache of this core
  static void sys_cache_invalidate(void)
  {
@@@ -328,21 -246,6 +341,13 @@@ intreg_t syscall(env_t* e, uint32_t sys
                case SYS_null:
                        sys_null();
                        return 0;
-               case SYS_serial_write:
-                       //printk("I am here\n");
-                       return sys_serial_write(e, (char *DANGEROUS)a1, (size_t)a2);
-               case SYS_serial_read:
-                       return sys_serial_read(e, (char *DANGEROUS)a1, (size_t)a2);
 +              case SYS_run_binary:
 +                      return sys_run_binary(e, (char *DANGEROUS)a1, 
 +                                            (char* DANGEROUS)a2, (size_t)a3);
 +              case SYS_eth_write:
 +                      return sys_eth_write(e, (char *DANGEROUS)a1, (size_t)a2);
 +              case SYS_eth_read:
 +                      return sys_eth_read(e, (char *DANGEROUS)a1, (size_t)a2);        
-               case SYS_cache_invalidate:
-                       sys_cache_invalidate();
-                       return 0;
                case SYS_cache_buster:
                        sys_cache_buster(e, a1, a2, a3);
                        return 0;