Fixed run_binary and SPARC processes
authorAndrew Waterman <waterman@ubuntu.(none)>
Wed, 16 Dec 2009 21:11:45 +0000 (13:11 -0800)
committerAndrew Waterman <waterman@ubuntu.(none)>
Wed, 16 Dec 2009 21:11:45 +0000 (13:11 -0800)
kern/arch/sparc/smp.c
kern/src/env.c
kern/src/process.c
kern/src/syscall.c
user/apps/parlib/matrix.c
user/apps/parlib/run_binary.c
user/parlib/src/parlibmain.c
usrbin/sparc/tlstest

index 8ff3ff9..8be3e2a 100644 (file)
@@ -23,7 +23,7 @@ smp_boot(void)
        cprintf("Cores, report in!\n");
        time_for_smp_init = 1;
 
-       while(*(volatile uint8_t*)&num_cpus < num_cores());
+       while(*(volatile uint32_t*)&num_cpus < num_cores());
 
        cprintf("All cores reporting!\n");
 }
@@ -33,12 +33,12 @@ smp_init(void)
 {
        static spinlock_t report_in_lock = SPINLOCK_INITIALIZER;
 
-       cprintf("Good morning, Vietnam! (core id = %d)\n",core_id());
-
        spin_lock(&report_in_lock);
        num_cpus++;
        spin_unlock(&report_in_lock);
 
+       cprintf("Good morning, Vietnam! (core id = %d)\n",core_id());
+
        smp_idle();
 }
 
index 36c63fe..a263892 100644 (file)
@@ -145,15 +145,6 @@ env_setup_vm_error:
        return -ENOMEM;
 }
 
-static void
-proc_init_procinfo(struct proc* p)
-{
-       p->env_procinfo->pid = p->pid;
-       p->env_procinfo->tsc_freq = system_timing.tsc_freq;
-       // TODO: maybe do something smarter here
-       p->env_procinfo->max_harts = MAX(1,num_cpus); // hack to use all cores
-}
-
 // Sets up argc/argv in procinfo.  Returns number of
 // args successfully imported (because of size restrictions).
 // The procinfo pages must have been mapped into the user's
@@ -319,8 +310,8 @@ static void* load_icode(env_t *SAFE e, env_t* binary_env,
        proghdr_t phdr;
        void* _end = 0;
 
-       assert(load_icode_memcpy(NULL,binary_env,&elfhdr, binary, sizeof(elfhdr))
-              == ESUCCESS);
+       assert(load_icode_memcpy(NULL,binary_env,&elfhdr, binary,
+                                sizeof(elfhdr)) == ESUCCESS);
 
        int i, r;
 
index 15d90dd..d4b883e 100644 (file)
@@ -190,6 +190,15 @@ void proc_init(void)
        atomic_init(&num_envs, 0);
 }
 
+static void
+proc_init_procinfo(struct proc* p)
+{
+       p->env_procinfo->pid = p->pid;
+       p->env_procinfo->tsc_freq = system_timing.tsc_freq;
+       // TODO: maybe do something smarter here
+       p->env_procinfo->max_harts = MAX(1,num_cpus); // hack to use all cores
+}
+
 /* Allocates and initializes a process, with the given parent.  Currently
  * writes the *p into **pp, and returns 0 on success, < 0 for an error.
  * Errors include:
@@ -241,7 +250,7 @@ static error_t proc_alloc(struct proc *SAFE*SAFE pp, pid_t parent_id)
        proc_init_trapframe(&p->env_tf);
 
        /* Initialize the contents of the e->env_procinfo structure */
-       p->env_procinfo->pid = p->pid;
+       proc_init_procinfo(p);
        /* Initialize the contents of the e->env_procdata structure */
 
        /* Initialize the generic syscall ring buffer */
@@ -279,7 +288,8 @@ struct proc *proc_create(uint8_t *binary, size_t size)
        curid = (current ? current->pid : 0);
        if ((r = proc_alloc(&p, curid)) < 0)
                panic("proc_create: %e", r); // one of 3 quaint usages of %e.
-       env_load_icode(p, NULL, binary, size);
+       if(binary != NULL)
+               env_load_icode(p, NULL, binary, size);
        return p;
 }
 
index b08fcac..163efe7 100644 (file)
@@ -85,8 +85,9 @@ static ssize_t sys_serial_read(env_t* e, char *DANGEROUS _buf, size_t len)
 static ssize_t sys_run_binary(env_t* e, void *DANGEROUS binary_buf,
                   void*DANGEROUS arg, size_t len, size_t num_colors)
 {
-       env_t* env = proc_create(0, 0);
-       env_load_icode(env, e, binary_buf, len);
+       env_t* env = proc_create(NULL,0);
+       assert(env != NULL);
+       env_load_icode(env,e,binary_buf,len);
        __proc_set_state(env, PROC_RUNNABLE_S);
        schedule_proc(env);
        if(num_colors > 0) {
index fcb26ab..145e82b 100644 (file)
@@ -14,6 +14,7 @@ extern void set_default_user();
 extern void file_io();
 extern void file_error();
 extern void run_binary();
+extern int  run_binary_filename(const char* fn);
 extern void run_binary_colored();
 extern char prompt[256];
 
@@ -58,6 +59,8 @@ int main(int argc, char** argv)
                        run_binary();
                else if (strcmp(s, "run_binary_colored") == 0)
                        run_binary_colored();
+               else if (run_binary_filename(s) == 0)
+                       ;
                else
                        help(); 
 
index 36cd8c8..4357681 100644 (file)
@@ -33,19 +33,10 @@ static void realloc_error(void* buf, int fd) {
        fprintf(stderr, "Error: Unable to run remote binary: No more memory available!\n");
 }
 
-void run_binary()
+int run_binary_filename(const char* file_name)
 {      
-       char * readline_result = readline("\nEnter name of binary to execute: ");
-       if (readline_result == NULL) {
-               printf("Error reading from console.\n");
-               return;
-       }
-       char* file_name = readline_result;
-       //char * file_name = malloc(strlen(readline_result) + 8);
-       //sprintf(file_name, "./apps/%s", readline_result);
        int fd = open(file_name, O_RDONLY, 0);
-       //free(file_name);
-       if(fd < 0) { fd_error(); return; };
+       if(fd < 0) return fd;
        
        int total_bytes_read = 0;
        int bytes_read = 0;
@@ -56,17 +47,17 @@ void run_binary()
                if(total_bytes_read+READ_SIZE > bufsz)
                {
                        void* temp_buf = realloc(binary_buf,bufsz+MALLOC_SIZE);
-                       if(temp_buf == NULL) { realloc_error(binary_buf, fd); return; }
+                       if(temp_buf == NULL) { realloc_error(binary_buf, fd); return 0; }
                        binary_buf = temp_buf;
                        bufsz += MALLOC_SIZE;
                }
 
                bytes_read = read(fd, binary_buf+total_bytes_read, READ_SIZE);
                total_bytes_read += bytes_read;
-               if(bytes_read < 0) { read_error(binary_buf, fd); return; }
+               if(bytes_read < 0) { read_error(binary_buf, fd); return 0; }
                if(bytes_read == 0) break;
        }
-       printf("Loading Binary: %s, ROMSIZE: %d\n", readline_result, total_bytes_read);
+       printf("Loading Binary: %s, ROMSIZE: %d\n",file_name,total_bytes_read);
        ssize_t error = sys_run_binary(binary_buf, NULL, total_bytes_read, 0);
        if(error < 0) {
                fprintf(stderr, "Error: Unable to run remote binary\n");
@@ -74,5 +65,17 @@ void run_binary()
        free(binary_buf);
        close(fd);
        syscall(SYS_yield,0,0,0,0,0);
+       return 0;
+}
+
+void run_binary()
+{
+       char* readline_result = readline("\nEnter name of binary to execute: ");
+       if (readline_result == NULL) {
+               printf("Error reading from console.\n");
+               return;
+       }
+       if(run_binary_filename(readline_result) < 0)
+               fd_error();
 }
 
index 2a6b23a..43c26b3 100644 (file)
@@ -12,7 +12,7 @@ void parlib_dtors()
 {
        typedef void (*dtor)(void);
        extern char __DTOR_LIST__[],__DTOR_END__[];
-       int ndtor = ((unsigned int)(__DTOR_END__ - __DTOR_LIST__))/sizeof(void*);
+       int ndtor = ((unsigned int)(__DTOR_END__-__DTOR_LIST__))/sizeof(void*);
 
        // make sure only one thread actually runs the dtors
        static int already_done = 0;
@@ -38,9 +38,19 @@ struct timeval timeval_start;
 
 void parlibmain()
 {
+       // only core 0 runs parlibmain, but if it yields then
+       // is given back, we don't want it to reinit things
+       static int initialized = 0;
+       if(initialized)
+       {
+               hart_entry();
+               hart_yield();
+       }
+       initialized = 1;
+
        // get start time (for times)
        if(gettimeofday(&timeval_start,NULL))
-               timeval_start.tv_sec = 0;
+               timeval_start.tv_sec = timeval_start.tv_usec = 0;
 
        // call static destructors
        parlib_ctors();
index 7a4af1b..19a6a5c 100755 (executable)
Binary files a/usrbin/sparc/tlstest and b/usrbin/sparc/tlstest differ