Merge branch 'sparc-dev' of ssh://scm.millennium.berkeley.edu/project/cs/radlab/src...
authorKevin Klues <klueska@parcad.millennium.berkeley.edu>
Tue, 1 Dec 2009 04:27:53 +0000 (20:27 -0800)
committerKevin Klues <klueska@parcad.millennium.berkeley.edu>
Tue, 1 Dec 2009 04:27:53 +0000 (20:27 -0800)
scripts/augment-gcc
user/apps/parlib/matrix.c
user/apps/parlib/run_binary.c
user/apps/parlib/run_binary_colored.c
user/parlib/src/hart.c
user/parlib/src/sparc/entry.S
user/parlib/src/sparc/newlib_backend.c
usrbin/sparc/tlstest [new file with mode: 0755]

index f98a4be..3658402 100755 (executable)
@@ -52,7 +52,4 @@ overwrite $1 tmp/libgcc.a libgcc.a
 rm -rf tmp
 
 SYS_INC=`find $1 -iname sys-include`
-rm -rf $SYS_INC/ros
-cp -r user/parlib/inc/ros $SYS_INC
-cp -r user/parlib/inc/sys/* $SYS_INC/sys
-
+cp -Lr user/parlib/inc/* $SYS_INC
index 3513ab3..5337282 100644 (file)
@@ -3,6 +3,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <ros/common.h>
+#include <sys/stat.h>
 
 extern char * readline(const char *prompt);
 extern void draw_nanwan();
index ebf0e21..2f2e6bd 100644 (file)
@@ -40,27 +40,26 @@ void run_binary()
                printf("Error reading from console.\n");
                return;
        }
-       char * file_name = malloc(strlen(readline_result) + 8);
-       sprintf(file_name, "./apps/%s", readline_result);
+       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);
+       //free(file_name);
        if(fd < 0) { fd_error(); return; };
        
-       int iters = 1;
-       binary_buf = malloc(READ_SIZE);
-       if(binary_buf == NULL) { malloc_error(); return; }
-       
+       int iters = 0;
        int total_bytes_read = 0;
-       int bytes_read = read(fd, binary_buf, READ_SIZE);
-       if(bytes_read < 0) { read_error(binary_buf, fd); return; }
+       int bytes_read = 0;
+       binary_buf = NULL;
        
-       while(bytes_read > 0) {
+       while(1) {
                total_bytes_read += bytes_read; 
                void* temp_buf = realloc(binary_buf, READ_SIZE*(++iters));
                if(temp_buf == NULL) { realloc_error(binary_buf, fd); return; } 
                binary_buf = temp_buf;
                bytes_read = read(fd, binary_buf+total_bytes_read, READ_SIZE);
                if(bytes_read < 0) { read_error(binary_buf, fd); return; }
+               if(bytes_read == 0) break;
        }
        printf("Loading Binary: %s, ROMSIZE: %d\n", readline_result, total_bytes_read);
        ssize_t error = sys_run_binary(binary_buf, NULL, total_bytes_read, 0);
index 0055e3a..b0d25c6 100644 (file)
@@ -44,10 +44,11 @@ void run_binary_colored()
                printf("Error reading from console.\n");
                return;
        }
-       char * file_name = malloc(strlen(name) + 8);
-       sprintf(file_name, "./apps/%s", name);
+       char* file_name = name;
+       //char * file_name = malloc(strlen(name) + 8);
+       //sprintf(file_name, "./apps/%s", name);
        int fd = open(file_name, O_RDONLY, 0);
-       free(file_name);
+       //free(file_name);
        if(fd < 0) { fd_error(); return; };
 
        char* colors = readline("\nEnter number of colors: ");
index 322726b..ee193a8 100644 (file)
@@ -27,7 +27,12 @@ static void _hart_init()
        extern void** stack_ptr_array;
        stack_ptr_array = (void**)malloc(hart_max_harts()*sizeof(void*));
        memset(stack_ptr_array,0,hart_max_harts()*sizeof(void*));
-       if(stack_ptr_array == NULL)
+
+       extern void** tls_array;
+       tls_array = (void**)malloc(hart_max_harts()*sizeof(void*));
+       memset(tls_array,0,hart_max_harts()*sizeof(void*));
+
+       if(stack_ptr_array == NULL || tls_array == NULL)
                hart_abort("Harts initialization ran out of memory!\n");
        #endif
 }
@@ -35,10 +40,11 @@ static void _hart_init()
 error_t hart_request(size_t k)
 {
        size_t i,j;
-       const int user_stack_size = 1024*1024;
+       const int user_stack_size = 1024*1024, tls_size = 1024*1024;
 
        #ifdef HART_ALLOCATE_STACKS
        extern void** stack_ptr_array;
+       extern void** tls_array;
        #endif
 
        _hart_init();
@@ -51,18 +57,19 @@ error_t hart_request(size_t k)
        #ifdef HART_ALLOCATE_STACKS
        for(i = _hart_current_harts; i < _hart_current_harts+k; i++)
        {
-               char* stack = (char*)malloc(user_stack_size);
+               char* stack = (char*)malloc(user_stack_size+tls_size);
                if(stack == NULL)
                {
                        for(j = _hart_current_harts; j < i; j++)
                        {
                                free(stack_ptr_array[j]);
-                               stack_ptr_array[j] = 0;
+                               stack_ptr_array[j] = tls_array[i] = 0;
                        }
                        hart_lock_unlock(&_hart_lock);
                        return -ENOMEM;
                }
                stack_ptr_array[i] = stack + user_stack_size;
+               tls_array[i] = stack_ptr_array[i]+tls_size;
        }
        #endif
 
@@ -78,7 +85,7 @@ error_t hart_request(size_t k)
        for(i = _hart_current_harts; i < _hart_current_harts+k; i++)
        {
                free(stack_ptr_array[i]);
-               stack_ptr_array[i] = 0;
+               stack_ptr_array[i] = tls_array[i] = 0;
        }
        #endif
 
index 09a68b1..336b60c 100644 (file)
 .align 4
 .globl stack_ptr_array
 stack_ptr_array:
-   .word 0
+       .word 0
+.globl tls_array
+tls_array:
+       .word 0
+
+.align 8
+core0_tls:
+       .skip 1024*1024
 
 
 // Entrypoint - this is where the kernel (or our parent environment)
@@ -33,6 +40,9 @@ _start:
        bne     notcore0
         nop
 
+       // Set up TLS
+       set     core0_tls,%g7
+
        call    parlibmain
         nop
 
@@ -45,8 +55,13 @@ notcore0:
        set     stack_ptr_array, %l0
        ld      [%l0], %l0
        sll     %g6, 2, %l1
-       ld      [%l0+%l1], %l1
-       sub     %l1, 64, %sp
+       ld      [%l0+%l1], %l0
+       sub     %l0, 64, %sp
+
+       // Set up TLS
+       set     tls_array, %l0
+       ld      [%l0], %l0
+       ld      [%l0+%l1],%g7
 
        call    hart_entry
         nop
index 6a9c212..d2ecf19 100644 (file)
@@ -240,7 +240,8 @@ read(int fd, void* ptr, size_t len)
 int
 open(char* name, int flags, int mode)
 {
-       return syscall(SYS_frontend,RAMP_SYSCALL_open,(int)name,flags,mode,0);
+       int ret = syscall(SYS_frontend,RAMP_SYSCALL_open,(int)name,flags,mode,0);
+       return ret;
 }
 
 int
diff --git a/usrbin/sparc/tlstest b/usrbin/sparc/tlstest
new file mode 100755 (executable)
index 0000000..cc25815
Binary files /dev/null and b/usrbin/sparc/tlstest differ