Checkin of Andrews stuff needed to compile glibc
authorKevin Klues <klueska@parcad.millennium.berkeley.edu>
Thu, 18 Feb 2010 22:33:11 +0000 (14:33 -0800)
committerKevin Klues <klueska@ros-dev.(none)>
Wed, 24 Mar 2010 19:09:50 +0000 (12:09 -0700)
We may want to roll this back eventually or combine
it with another commit if Andrew ever gets his act together.

14 files changed:
GNUmakefile
kern/arch/i386/ros/hart.h
kern/arch/sparc/pmap.c
kern/arch/sparc/process.c
kern/arch/sparc/ros/hart.h
kern/arch/sparc/trap.c
kern/arch/sparc/trap.h
kern/arch/sparc/trap_entry.S
kern/src/elf.c
kern/src/syscall.c
user/parlib/inc/parlib.h
user/parlib/src/hart.c
user/parlib/src/sparc/syscall.c
user/parlib/src/syscall.c

index ea810f6..479f356 100644 (file)
@@ -86,16 +86,21 @@ CFLAGS += -Wall -Wno-format -Wno-unused -fno-strict-aliasing
 LDFLAGS := -nostdlib
 
 # GCC Library path 
+ifneq ($(shell which $(CC)),)
 GCC_LIB := $(shell $(CC) -print-libgcc-file-name)
+endif
 
 # List of directories that the */Makefrag makefile fragments will add to
 OBJDIRS :=
 
-symlinks:
-       @rm -f kern/include/arch
-       @ln -s ../arch/$(TARGET_ARCH)/ kern/include/arch
-       @rm -f kern/boot
-       @ln -s arch/$(TARGET_ARCH)/boot/ kern/boot
+ROS_ARCH_DIR ?= $(TARGET_ARCH)
+symlinks-remove:
+       @rm -rf kern/include/arch
+       @rm -rf kern/boot
+
+symlinks: symlinks-remove
+       @ln -s ../arch/$(ROS_ARCH_DIR)/ kern/include/arch
+       @ln -s arch/$(ROS_ARCH_DIR)/boot/ kern/boot
 
 # Include Makefrags for subdirectories
 include user/Makefrag
index a5d4cbf..9f5b767 100644 (file)
@@ -12,6 +12,12 @@ __hart_self()
 }
 
 static inline void
+__hart_set_stack_pointer(void* sp)
+{
+       FIXME
+}
+
+static inline void
 __hart_relax()
 {
        asm volatile ("pause" : : : "memory");
index de473e4..e175e9d 100644 (file)
@@ -123,7 +123,7 @@ int get_va_perms(pde_t *pgdir, const void *SNT va)
 
 void *get_free_va_range(pde_t *pgdir, uintptr_t addr, size_t len)
 {
-       addr = ROUNDUP(MIN(addr,UMMAP_START),PGSIZE);
+       addr = ROUNDUP(MAX(addr,UMMAP_START),PGSIZE);
        len = ROUNDUP(len,PGSIZE);
 
        for(char* a = (char*)addr; a < (char*)USTACKBOT; a += PGSIZE)
index 0fd5656..04208f9 100644 (file)
@@ -57,7 +57,7 @@ proc_init_trapframe(trapframe_t *tf, uint32_t vcoreid)
 
 void proc_set_tfcoreid(trapframe_t *tf, uint32_t id)
 {
-       tf->gpr[6] = id;
+       tf->asr13 = id;
 }
 
 /* For cases that we won't return from a syscall via the normal path, and need
index 1a0e6e3..822ae2e 100644 (file)
@@ -11,11 +11,17 @@ static inline int
 __hart_self()
 {
        int id;
-       __asm__ __volatile__ ("mov %%g6,%0" : "=r"(id));
+       asm ("mov %%asr13,%0" : "=r"(id));
        return id;
 }
 
 static inline void
+__hart_set_stack_pointer(void* sp)
+{
+       __asm__ __volatile__ ("mov %0,%%sp" : : "r"(sp));
+}
+
+static inline void
 __hart_relax()
 {
        // TODO: relax
index 8a16588..905b3b4 100644 (file)
@@ -74,8 +74,8 @@ void
                        "  psr  0x%08x  pc   0x%08x  npc  0x%08x  wim  0x%08x\n",
                        tf->psr,tf->pc,tf->npc,tf->wim);
        len += snprintf(buf+len,sizeof(buf)-len,
-                       "  tbr  0x%08x  y    0x%08x  fsr  0x%08x  far  0x%08x\n",
-                       tf->tbr,tf->y,tf->fault_status,tf->fault_addr);
+                       "  y    0x%08x  fsr  0x%08x  far  0x%08x\n",
+                       tf->y,tf->fault_status,tf->fault_addr);
        len += snprintf(buf+len,sizeof(buf)-len,
                        "  timestamp  %21lld\n",tf->timestamp);
 
index c13ec69..9575151 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef ROS_INC_ARCH_TRAP_H
 #define ROS_INC_ARCH_TRAP_H
 
-#define SIZEOF_TRAPFRAME_T     0xA8
+#define SIZEOF_TRAPFRAME_T     0xB0
 #define SIZEOF_ACTIVE_MESSAGE_T        0x18
 
 #ifndef __ASSEMBLER__
@@ -17,6 +17,8 @@ typedef struct
        uint32_t wim;
        uint32_t tbr;
        uint32_t y;
+       uint32_t asr13;
+       uint32_t pad;
        uint32_t fault_status;
        uint32_t fault_addr;
        uint64_t timestamp;
index e244e5b..9284f2d 100644 (file)
@@ -102,16 +102,18 @@ env_save_tf:
        mov     %tbr,%o4
        mov     %y,%o5
        std     %o4,[%o0+144]
+       mov     %asr13,%o5
+       st      %o5,[%o0+152]
 
        set     0x300,%o4
        set     0x400,%o5
        lda     [%o4] 4,%o4
        lda     [%o5] 4,%o5
-       std     %o4,[%o0+152]
+       std     %o4,[%o0+160]
        lda     [%g0] 2,%o4
        mov     4,%o5
        lda     [%o5] 2,%o5
-       std     %o4,[%o0+160]
+       std     %o4,[%o0+168]
 
        std     %g0,[%o0+ 0]
        std     %g2,[%o0+ 8]
@@ -223,7 +225,8 @@ env_pop_tf:
        ld      [%o0+136],%l2
        ld      [%o0+148],%l5
        mov     %l5,%y
-       nop
+       ld      [%o0+152],%l5
+       mov %l5,%asr13
 
        jmp     %l1
        rett    %l2
index ee0e48f..27d1380 100644 (file)
@@ -14,7 +14,7 @@ struct elf_info
        char interp[256];
 };
 
-int load_one_elf(struct proc* p, int fd, struct elf_info* ei)
+int load_one_elf(struct proc* p, int fd, int pgoffset, struct elf_info* ei)
 {
        int ret = -1;
        ei->phdr = -1;
@@ -66,21 +66,21 @@ int load_one_elf(struct proc* p, int fd, struct elf_info* ei)
 
                        // mmap will zero the rest of the page if filesz % PGSIZE != 0
                        if(filesz)
-                               if(mmap(p, memstart, filesz,
+                               if(mmap(p, memstart+pgoffset*PGSIZE, filesz,
                                        PROT_READ|PROT_WRITE|PROT_EXEC, MAP_FIXED,
                                        fd, filestart/PGSIZE) == MAP_FAILED)
                                        goto fail;
 
                        filesz = ROUNDUP(filesz,PGSIZE);
                        if(filesz < memsz)
-                               if(mmap(p, memstart+filesz, memsz-filesz,
+                               if(mmap(p, memstart+filesz+pgoffset*PGSIZE, memsz-filesz,
                                        PROT_READ|PROT_WRITE|PROT_EXEC, MAP_FIXED|MAP_ANON,
                                        -1, 0) == MAP_FAILED)
                                        goto fail;
                }
        }
 
-       ei->entry = elfhdr->e_entry;
+       ei->entry = elfhdr->e_entry + pgoffset*PGSIZE;
        ei->phnum = elfhdr->e_phnum;
 
        ret = 0;
@@ -93,14 +93,14 @@ int load_elf(struct proc* p, const char* fn)
 {
        struct elf_info ei,interp_ei;
        int fd = open_file(p,fn,0,0);
-       if(fd == -1 || load_one_elf(p,fd,&ei))
+       if(fd == -1 || load_one_elf(p,fd,0,&ei))
                return -1;
        close_file(p,fd);
 
        if(ei.dynamic)
        {
                int fd2 = open_file(p,ei.interp,0,0);
-               if(fd2 == -1 || load_one_elf(p,fd2,&interp_ei))
+               if(fd2 == -1 || load_one_elf(p,fd2,1,&interp_ei))
                        return -1;
                close_file(p,fd2);
 
@@ -123,8 +123,9 @@ int load_elf(struct proc* p, const char* fn)
                memcpy(p->env_procinfo->argp+auxp_pos,auxp,sizeof(auxp));
        }
 
-       p->env_entry = ei.dynamic ? interp_ei.entry : ei.entry;
-       proc_set_program_counter(&p->env_tf,p->env_entry);
+       intptr_t core0_entry = ei.dynamic ? interp_ei.entry : ei.entry;
+       proc_set_program_counter(&p->env_tf,core0_entry);
+       p->env_entry = ei.entry;
 
        uintptr_t stacksz = USTACK_NUM_PAGES*PGSIZE;
        if(mmap(p,USTACKTOP-stacksz,stacksz,PROT_READ|PROT_WRITE,
index 76004ad..a47d593 100644 (file)
@@ -425,6 +425,8 @@ static intreg_t sys_munmap(struct proc* p, void* addr, size_t len)
 static void* sys_brk(struct proc *p, void* addr) {
        size_t range;
 
+       spin_lock_irqsave(&p->proc_lock);
+
        if((addr < p->heap_bottom) || (addr >= (void*)USTACKBOT))
                goto out;
 
@@ -439,6 +441,7 @@ static void* sys_brk(struct proc *p, void* addr) {
        p->heap_top = addr;
 
 out:
+       spin_unlock_irqsave(&p->proc_lock);
        return p->heap_top;
 }
 
index 6735977..f6134d7 100644 (file)
@@ -25,10 +25,10 @@ enum {
        PG_RDWR   = 6,
 };
 
-extern procinfo_t procinfo;
-extern procdata_t procdata;
+#define procinfo (*(procinfo_t*)UINFO)
+#define procdata (*(procdata_t*)UDATA)
 
-intreg_t syscall(uint16_t num, intreg_t a1,
+intreg_t ros_syscall(uint16_t num, intreg_t a1,
                 intreg_t a2, intreg_t a3,
                 intreg_t a4, intreg_t a5);
 
@@ -41,7 +41,7 @@ ssize_t     sys_eth_read(void *COUNT(len) buf);
 ssize_t     sys_eth_get_mac_addr(void* buf);
 int         sys_eth_recv_check();
 ssize_t     sys_run_binary(void* binary_buf, size_t len,
-                           procinfo_t* procinfo, size_t num_colors);
+                           procinfo_t* pi, size_t num_colors);
 int         sys_getpid(void);
 size_t      sys_getcpuid(void);
 void *      sys_brk(void* addr);
@@ -52,7 +52,6 @@ ssize_t     sys_shared_page_free(void *COUNT(PGSIZE) addr, pid_t p2);
 ssize_t     sys_resource_req(int type, size_t amount, uint32_t flags);
 void        sys_reboot();
 void        sys_yield();
-int         gettimeofday(struct timeval* tp, void* tzp);
 void *COUNT(length) sys_mmap(void *SNT addr, size_t length, int prot, int flags,
                              int fd, size_t offset);
 
index 6460a98..491e825 100644 (file)
@@ -16,11 +16,11 @@ static void _hart_init()
 
        initialized = 1;
 
-       extern void **stack_ptr_array, **tls_array;
-       stack_ptr_array = (void**)calloc(hart_max_harts(),sizeof(void*));
-       tls_array = (void**)calloc(hart_max_harts(),sizeof(void*));
+       extern void **hart_stack_pointers, **hart_thread_control_blocks;
+       hart_stack_pointers = (void**)calloc(hart_max_harts(),sizeof(void*));
+       hart_thread_control_blocks = (void**)calloc(hart_max_harts(),sizeof(void*));
 
-       if(stack_ptr_array == NULL || tls_array == NULL)
+       if(hart_stack_pointers == NULL || hart_thread_control_blocks == NULL)
        {
                fputs("Harts initialization ran out of memory!\n",stderr);
                abort();
@@ -30,10 +30,13 @@ static void _hart_init()
 error_t hart_request(size_t k)
 {
        size_t i,j;
-       const int user_stack_size = PARLIB_TLS_SIZE, tls_size = PARLIB_TLS_SIZE;
+       const int user_stack_size = PARLIB_TLS_SIZE;
+       error_t ret = -1;
 
-       extern void** stack_ptr_array;
-       extern void** tls_array;
+       extern void** hart_stack_pointers;
+       extern void** hart_thread_control_blocks;
+       extern void* _dl_allocate_tls(void*);
+       extern void _dl_deallocate_tls(void*,bool);
 
        _hart_init();
 
@@ -42,31 +45,39 @@ error_t hart_request(size_t k)
        if(k < 0 || _current_harts+k > hart_max_harts())
                return -1;
 
-       char* stack = (char*)calloc(user_stack_size+tls_size,k);
+       char* stack = (char*)calloc(user_stack_size,k);
        if(stack == NULL)
        {
-               hart_lock_unlock(&_hart_lock);
-               return -ENOMEM;
+               errno = ENOMEM;
+               goto fail;
        }
 
        for(i = _current_harts, j = 0; i < _current_harts+k; i++, j++)
        {
-               stack_ptr_array[i] = stack + (j+1)*user_stack_size+j*tls_size;
-               tls_array[i] = stack_ptr_array[i]+tls_size;
+               hart_stack_pointers[i] = stack + (j+1)*user_stack_size-96;
+               if(!(hart_thread_control_blocks[i] = _dl_allocate_tls(NULL)))
+               {
+                       errno = ENOMEM;
+                       goto fail;
+               }
        }
 
-       error_t ret;
        if((ret = sys_resource_req(0,_current_harts+k,0)) == 0)
        {
                _current_harts += k;
-               hart_lock_unlock(&_hart_lock);
-               return 0;
+               goto success;
        }
+       errno = EBUSY;
 
+fail:
        free(stack);
        for(i = _current_harts; i < _current_harts+k; i++)
-               stack_ptr_array[i] = tls_array[i] = 0;
+       {
+               free(hart_thread_control_blocks[i]);
+               hart_stack_pointers[i] = hart_thread_control_blocks[i] = 0;
+       }
 
+success:
        hart_lock_unlock(&_hart_lock);
        return ret;
 }
index 89d414f..5a87422 100644 (file)
@@ -1,7 +1,7 @@
 #include <parlib.h>
 #include <errno.h>
 
-intreg_t syscall(uint16_t _num, intreg_t _a1,
+intreg_t ros_syscall(uint16_t _num, intreg_t _a1,
                 intreg_t _a2, intreg_t _a3,
                 intreg_t _a4, intreg_t _a5)
 {
index ab52e0c..4d71d43 100644 (file)
@@ -1,5 +1,6 @@
 // System call stubs.
 
+#include <unistd.h>
 #include <parlib.h>
 
 error_t sys_proc_destroy(int pid, int exitcode)
@@ -59,10 +60,10 @@ ssize_t sys_serial_read(void* buf, size_t len)
 
 //Run a binary loaded at the specificed address with the specified arguments
 ssize_t sys_run_binary(void* binary_buf, size_t len,
-                       procinfo_t* procinfo, size_t num_colors) 
+                       procinfo_t* pi, size_t num_colors) 
 {
        return syscall(SYS_run_binary, (intreg_t)binary_buf, (intreg_t)len,
-                                   (intreg_t)procinfo,(intreg_t)num_colors, 0);
+                                   (intreg_t)pi,(intreg_t)num_colors, 0);
 }
 
 //Write a buffer over ethernet