Added ability to load an arbitrary binary from an ethernet server and launch it
authorKevin Klues <klueska@eecs.berkeley.edu>
Sat, 27 Jun 2009 06:05:58 +0000 (23:05 -0700)
committerKevin Klues <klueska@eecs.berkeley.edu>
Wed, 1 Jul 2009 20:33:36 +0000 (13:33 -0700)
Right now everything has only been tested with a single application, draw_nanwan_standalone, but hopefully other programs will work as well.  This impolementation relies on the changes made to master to allow syscalls made with sysenter to return to a different context than the calling one.

14 files changed:
.gitignore
GNUmakefile
include/ros/syscall.h
kern/src/Makefrag
kern/src/init.c
kern/src/rl8168.c
kern/src/syscall.c
user/apps/parlib/Makefrag
user/apps/parlib/draw_nanwan_standalone.c [new file with mode: 0644]
user/apps/parlib/matrix.c
user/apps/parlib/run_binary.c [new file with mode: 0644]
user/parlib/inc/parlib.h
user/parlib/src/newlib_backend.c
user/parlib/src/syscall.c

index 319d2a2..513b1e5 100644 (file)
@@ -14,3 +14,4 @@ Makelocal
 ne2k*
 .textmate*
 .DS_*
 ne2k*
 .textmate*
 .DS_*
+ros-project.tmproj
index cd4bad1..064879b 100644 (file)
@@ -77,9 +77,9 @@ OBJDIRS :=
 all:
 
 # Include Makefrags for subdirectories
 all:
 
 # Include Makefrags for subdirectories
+-include Makelocal
 include user/Makefrag
 include kern/Makefrag
 include user/Makefrag
 include kern/Makefrag
--include Makelocal
 
 # Eliminate default suffix rules
 .SUFFIXES:
 
 # Eliminate default suffix rules
 .SUFFIXES:
index dcc7ec4..b1f7a30 100644 (file)
@@ -21,6 +21,7 @@ enum
        SYS_serial_read,
        SYS_eth_read,
        SYS_eth_write,
        SYS_serial_read,
        SYS_eth_read,
        SYS_eth_write,
+       SYS_run_binary,
 
        SYS_endofcalls //Should always be last
 };
 
        SYS_endofcalls //Should always be last
 };
index 61c3e6d..9453a3c 100644 (file)
@@ -45,6 +45,7 @@ KERN_SRCFILES := $(wildcard $(KERN_SRCFILES))
 KERN_APPFILES :=    $(USER_APPS_PARLIB_DIR)/matrix \
                     $(USER_APPS_ROSLIB_DIR)/null \
                     $(USER_APPS_ROSLIB_DIR)/hello \
 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)/measurements
 #                    $(USER_APPS_PARLIB_DIR)/draw_nanwan
 #                    $(USER_APPS_PARLIB_DIR)/open_read \
                     $(USER_APPS_ROSLIB_DIR)/measurements
 #                    $(USER_APPS_PARLIB_DIR)/draw_nanwan
 #                    $(USER_APPS_PARLIB_DIR)/open_read \
index 8facc5d..2ec771f 100644 (file)
@@ -57,9 +57,9 @@ void kernel_init(multiboot_info_t *mboot_info)
        idt_init();
        sysenter_init();
        timer_init();
        idt_init();
        sysenter_init();
        timer_init();
+       init_nic();
        // this returns when all other cores are done and ready to receive IPIs
        smp_boot();
        // this returns when all other cores are done and ready to receive IPIs
        smp_boot();
-       init_nic();
        /*
        test_smp_call_functions();
        test_checklists();
        /*
        test_smp_call_functions();
        test_checklists();
@@ -68,8 +68,9 @@ void kernel_init(multiboot_info_t *mboot_info)
        test_lapic_status_bit();
        test_ipi_sending();
        test_pit();
        test_lapic_status_bit();
        test_ipi_sending();
        test_pit();
-       */      
-       manager();
+       */
+       env_run(ENV_CREATE(parlib_matrix));     
+       //manager();
 }
 
 /*
 }
 
 /*
index d3c0903..d23f1e6 100644 (file)
@@ -351,7 +351,6 @@ void setup_interrupts() {
        register_interrupt_handler(interrupt_handlers, KERNEL_IRQ_OFFSET + irq, nic_interrupt_handler, 0);
        pic_unmask_irq(irq);
        unmask_lapic_lvt(LAPIC_LVT_LINT0);
        register_interrupt_handler(interrupt_handlers, KERNEL_IRQ_OFFSET + irq, nic_interrupt_handler, 0);
        pic_unmask_irq(irq);
        unmask_lapic_lvt(LAPIC_LVT_LINT0);
-       enable_irq();
        
        return;
 }
        
        return;
 }
@@ -361,7 +360,7 @@ void setup_interrupts() {
 void nic_interrupt_handler(trapframe_t *tf, void* data) {
        
        nic_interrupt_debug("\nNic interrupt on core %u!\n", lapic_get_id());
 void nic_interrupt_handler(trapframe_t *tf, void* data) {
        
        nic_interrupt_debug("\nNic interrupt on core %u!\n", lapic_get_id());
-               
+                               
        // Read the offending interrupt(s)
        uint16_t interrupt_status = inw(io_base_addr + RL_IS_REG);
 
        // Read the offending interrupt(s)
        uint16_t interrupt_status = inw(io_base_addr + RL_IS_REG);
 
@@ -691,7 +690,9 @@ const char *packet_wrap(const char* data, size_t len) {
        };      
        
        // Hard coded to paul's laptop's mac
        };      
        
        // Hard coded to paul's laptop's mac
-       char dest_mac_address[6] = {0x00, 0x23, 0x32, 0xd5, 0xae, 0x82};
+       //Format for Makelocal file: -DUSER_MAC_ADDRESS="{0x00, 0x23, 0x32, 0xd5, 0xae, 0x82}"
+       char dest_mac_address[6] = USER_MAC_ADDRESS;
+       
        
        uint32_t source_ip = 0xC0A8000A; // 192.168.0.10
        uint32_t dest_ip   = 0xC0A8000B; // 192.168.0.11
        
        uint32_t source_ip = 0xC0A8000A; // 192.168.0.10
        uint32_t dest_ip   = 0xC0A8000B; // 192.168.0.11
@@ -738,4 +739,4 @@ const char *packet_wrap(const char* data, size_t len) {
        memcpy (wrap_buffer + PACKET_HEADER_SIZE, data, len);
        
        return wrap_buffer;     
        memcpy (wrap_buffer + PACKET_HEADER_SIZE, data, len);
        
        return wrap_buffer;     
-}
\ No newline at end of file
+}
index 99cc333..0be42f8 100644 (file)
@@ -73,6 +73,18 @@ static ssize_t sys_serial_read(env_t* e, char *DANGEROUS buf, size_t len)
        #endif
 }
 
        #endif
 }
 
+static ssize_t sys_run_binary(env_t* e, void* binary_buf, void* arg, size_t len) {
+       uint8_t* new_binary = kmalloc(len, 0);
+       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) 
 { 
 // 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) 
 { 
@@ -319,6 +331,9 @@ intreg_t syscall(env_t* e, uint32_t syscallno, uint32_t a1, uint32_t a2,
                        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);
                        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:
                case SYS_eth_write:
                        return sys_eth_write(e, (char *DANGEROUS)a1, (size_t)a2);
                case SYS_eth_read:
index 8ab9070..9b7ea44 100644 (file)
@@ -19,6 +19,7 @@ USER_APPS_PARLIB_LDOBJS    := $(OBJDIR)/$(USER_PARLIB_DIR)/entry.o \
                               $(OBJDIR)/$(USER_APPS_PARLIB_DIR)/file_error.o \
                               $(OBJDIR)/$(USER_APPS_PARLIB_DIR)/clrscrn.o \
                               $(OBJDIR)/$(USER_APPS_PARLIB_DIR)/draw_nanwan.o \
                               $(OBJDIR)/$(USER_APPS_PARLIB_DIR)/file_error.o \
                               $(OBJDIR)/$(USER_APPS_PARLIB_DIR)/clrscrn.o \
                               $(OBJDIR)/$(USER_APPS_PARLIB_DIR)/draw_nanwan.o \
+                              $(OBJDIR)/$(USER_APPS_PARLIB_DIR)/run_binary.o \
                               $(OBJDIR)/$(USER_APPS_PARLIB_DIR)/change_user.o  
 
 
                               $(OBJDIR)/$(USER_APPS_PARLIB_DIR)/change_user.o  
 
 
diff --git a/user/apps/parlib/draw_nanwan_standalone.c b/user/apps/parlib/draw_nanwan_standalone.c
new file mode 100644 (file)
index 0000000..16f6663
--- /dev/null
@@ -0,0 +1,34 @@
+#include <stdio.h>
+
+int main(int argc, char** argv)
+{
+       /* Borrowed with love from http://www.geocities.com/SoHo/7373/zoo.htm
+        * (http://www.ascii-art.com/).  Slightly modified to make it 25 lines tall.
+        */
+       printf("\n");
+       printf("             .-.  .-.\n");
+       printf("             |  \\/  |\n");
+       printf("            /,   ,_  `'-.\n");
+       printf("          .-|\\   /`\\     '. \n");
+       printf("        .'  0/   | 0\\  \\_  `\".  \n");
+       printf("     .-'  _,/    '--'.'|#''---'\n");
+       printf("      `--'  |       /   \\#\n");
+       printf("            |      /     \\#\n");
+       printf("            \\     ;|\\    .\\#\n");
+       printf("            |' ' //  \\   ::\\# \n");
+       printf("            \\   /`    \\   ':\\#\n");
+       printf("             `\"`       \\..   \\#\n");
+       printf("                        \\::.  \\#\n");
+       printf("                         \\::   \\#\n");
+       printf("                          \\'  .:\\#\n");
+       printf("                           \\  :::\\#\n");
+       printf("                            \\  '::\\#\n");
+       printf("                             \\     \\#\n");
+       printf("                              \\:.   \\#\n");
+       printf("                               \\::   \\#\n");
+       printf("                                \\'   .\\#\n");
+       printf("                             jgs \\   ::\\#\n");
+       printf("                                  \\      \n");
+       return 0;
+}
+
index 2ee6686..fc5569a 100644 (file)
@@ -11,6 +11,7 @@ extern void change_user();
 extern void set_default_user();
 extern void file_io();
 extern void file_error();
 extern void set_default_user();
 extern void file_io();
 extern void file_error();
+extern void run_binary();
 extern char prompt[256];
 
 void help() {
 extern char prompt[256];
 
 void help() {
@@ -18,8 +19,9 @@ void help() {
               "  draw_nanwan:      Draw a picture of Nanwan, our mascot giraffe\n"
               "  clear_screen:     Clear the Screen\n"
               "  change_user:      Change Username\n"
               "  draw_nanwan:      Draw a picture of Nanwan, our mascot giraffe\n"
               "  clear_screen:     Clear the Screen\n"
               "  change_user:      Change Username\n"
-               "  file_io:          Run File Related IO Tests\n"
-               "  file_error:       Run File Error Related Tests\n"
+           "  file_io:          Run File Related IO Tests\n"
+           "  file_error:       Run File Error Related Tests\n"
+           "  run_binary:       Load and run a binary located on the remote server\n"
              );
 }
 
              );
 }
 
@@ -45,6 +47,8 @@ int main(int argc, char** argv)
                        file_io();
                else if (strcmp(s, "file_error") == 0)
                        file_error();
                        file_io();
                else if (strcmp(s, "file_error") == 0)
                        file_error();
+               else if (strcmp(s, "run_binary") == 0)
+                       run_binary();
                else
                        help(); 
 
                else
                        help(); 
 
diff --git a/user/apps/parlib/run_binary.c b/user/apps/parlib/run_binary.c
new file mode 100644 (file)
index 0000000..64f2236
--- /dev/null
@@ -0,0 +1,43 @@
+#include <string.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <parlib.h>
+
+extern char * readline(const char *prompt);
+
+#define READ_SIZE       1024
+uint8_t* binary_buf;
+
+void run_binary()
+{      
+       char * readline_result = readline("\nEnter name of binary to execute: ");
+       if (readline_result == NULL) {
+               printf("Error reading from console.\n");
+               return;
+       }
+
+       char * file_name = malloc(strlen(readline_result) + 8);
+       sprintf(file_name, "./test/%s", readline_result);
+       int fd = open(file_name, O_RDONLY, 0);
+       
+       int iters = 1;
+       binary_buf = malloc(READ_SIZE);
+       
+       int total_bytes_read = 0;
+       int bytes_read = read(fd, binary_buf, READ_SIZE);
+       while(bytes_read > 0) {
+               total_bytes_read += bytes_read; 
+               binary_buf = realloc(binary_buf, READ_SIZE*(++iters));
+               bytes_read = read(fd, binary_buf+total_bytes_read, READ_SIZE);
+       }
+       printf("Loading Binary: %s, ROMSIZE: %d\n", readline_result, total_bytes_read);
+       sys_run_binary(binary_buf, NULL, total_bytes_read);
+       free(binary_buf);
+       close(fd);
+}
+
index 3403b3f..ef5cee7 100644 (file)
@@ -26,6 +26,7 @@ ssize_t     sys_serial_write(void* buf, size_t len);
 ssize_t     sys_serial_read(void* buf, size_t len);
 ssize_t     sys_eth_write(void* buf, size_t len); 
 ssize_t     sys_eth_read(void* buf, size_t len);
 ssize_t     sys_serial_read(void* buf, size_t len);
 ssize_t     sys_eth_write(void* buf, size_t len); 
 ssize_t     sys_eth_read(void* buf, size_t len);
+ssize_t     sys_run_binary(void* binary_buf, void* arg, size_t len);
 envid_t     sys_getenvid(void);
 envid_t     sys_getcpuid(void);
 void        sys_env_destroy(envid_t);
 envid_t     sys_getenvid(void);
 envid_t     sys_getcpuid(void);
 void        sys_env_destroy(envid_t);
index 784d1db..3ce4de8 100644 (file)
@@ -483,7 +483,7 @@ void* sbrk(ptrdiff_t incr)
        debug_in_out("SBRK\n");
        debug_in_out("\tincr: %u\n", incr);     
 
        debug_in_out("SBRK\n");
        debug_in_out("\tincr: %u\n", incr);     
 
-       #define HEAP_SIZE 8192
+       #define HEAP_SIZE (1<<18)
        static uint8_t array[HEAP_SIZE];
        static uint8_t* heap_end = array;
        static uint8_t* stack_ptr = &(array[HEAP_SIZE-1]);
        static uint8_t array[HEAP_SIZE];
        static uint8_t* heap_end = array;
        static uint8_t* stack_ptr = &(array[HEAP_SIZE-1]);
index 5516845..e0f6c5b 100644 (file)
@@ -112,6 +112,12 @@ ssize_t sys_serial_read(void* buf, size_t len)
        return syscall(SYS_serial_read, (intreg_t)buf, len, 0, 0, 0);
 }
 
        return syscall(SYS_serial_read, (intreg_t)buf, len, 0, 0, 0);
 }
 
+//Run a binary loaded at the specificed address with the specified arguments
+ssize_t sys_run_binary(void* binary_buf, void* arg, size_t len) 
+{
+       return syscall(SYS_run_binary, (intreg_t)binary_buf, (intreg_t)arg, len, 0, 0);
+}
+
 //Write a buffer over ethernet
 ssize_t sys_eth_write(void* buf, size_t len) 
 {
 //Write a buffer over ethernet
 ssize_t sys_eth_write(void* buf, size_t len) 
 {