TLS works in SPARC
authorAndrew Waterman <waterman@r53.millennium.berkeley.edu>
Mon, 30 Nov 2009 11:28:51 +0000 (03:28 -0800)
committerAndrew Waterman <waterman@r53.millennium.berkeley.edu>
Mon, 30 Nov 2009 11:28:51 +0000 (03:28 -0800)
augment-gcc [deleted file]
scripts/augment-gcc [new file with mode: 0755]
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]

diff --git a/augment-gcc b/augment-gcc
deleted file mode 100755 (executable)
index ccf1ad4..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-#!/bin/bash
-
-function overwrite
-{
-       for i in `find $1 -iname $3`
-       do
-               if [ ! -f $i.bak ]
-               then
-                       cp $i $i.bak
-               fi
-               cp $2 $i
-       done
-}
-
-if [ -z "$1" -o -z "$2" ]
-then
-       echo usage: $1 path-to-ros-gcc target-arch
-       exit
-fi
-
-overwrite $1 obj/user/parlib/src/$2/crtbegin.o crtbegin.o
-overwrite $1 obj/user/parlib/src/$2/crtend.o crtend.o
-overwrite $1 obj/user/parlib/src/$2/entry.o crt0.o
-
-LIBGCC=`find $1 -iname libgcc.a.bak`
-if [ -z "$LIBGCC" ]
-then
-       LIBGCC=`find $1 -iname libgcc.a`
-fi
-LIBC=`find $1 -iname libc.a`
-LIBM=`find $1 -iname libm.a`
-LIBG=`find $1 -iname libg.a`
-LIBPARLIB=../obj/user/parlib/libparlib.a
-LIBPTHREAD=../obj/user/parlib/libpthread.a
-mkdir tmp
-cd tmp
-ar x $LIBPARLIB
-for i in *.o; do mv $i first-$i; ar xN 1 $LIBPARLIB $i 2> /dev/null; done
-ar rcs libgcc.a *.o; rm *.o
-ar x $LIBPTHREAD
-for i in *.o; do mv $i first-$i; ar xN 1 $LIBPTHREAD $i 2> /dev/null; done
-ar rcs libgcc.a *.o; rm *.o
-ar x $LIBGCC
-ar x $LIBC
-ar x $LIBM
-ar x $LIBG
-ar rcs libgcc.a *.o
-cd ..
-
-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
-
diff --git a/scripts/augment-gcc b/scripts/augment-gcc
new file mode 100755 (executable)
index 0000000..ccf1ad4
--- /dev/null
@@ -0,0 +1,56 @@
+#!/bin/bash
+
+function overwrite
+{
+       for i in `find $1 -iname $3`
+       do
+               if [ ! -f $i.bak ]
+               then
+                       cp $i $i.bak
+               fi
+               cp $2 $i
+       done
+}
+
+if [ -z "$1" -o -z "$2" ]
+then
+       echo usage: $1 path-to-ros-gcc target-arch
+       exit
+fi
+
+overwrite $1 obj/user/parlib/src/$2/crtbegin.o crtbegin.o
+overwrite $1 obj/user/parlib/src/$2/crtend.o crtend.o
+overwrite $1 obj/user/parlib/src/$2/entry.o crt0.o
+
+LIBGCC=`find $1 -iname libgcc.a.bak`
+if [ -z "$LIBGCC" ]
+then
+       LIBGCC=`find $1 -iname libgcc.a`
+fi
+LIBC=`find $1 -iname libc.a`
+LIBM=`find $1 -iname libm.a`
+LIBG=`find $1 -iname libg.a`
+LIBPARLIB=../obj/user/parlib/libparlib.a
+LIBPTHREAD=../obj/user/parlib/libpthread.a
+mkdir tmp
+cd tmp
+ar x $LIBPARLIB
+for i in *.o; do mv $i first-$i; ar xN 1 $LIBPARLIB $i 2> /dev/null; done
+ar rcs libgcc.a *.o; rm *.o
+ar x $LIBPTHREAD
+for i in *.o; do mv $i first-$i; ar xN 1 $LIBPTHREAD $i 2> /dev/null; done
+ar rcs libgcc.a *.o; rm *.o
+ar x $LIBGCC
+ar x $LIBC
+ar x $LIBM
+ar x $LIBG
+ar rcs libgcc.a *.o
+cd ..
+
+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
+
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 aa5cc48..33a0043 100644 (file)
@@ -113,7 +113,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