Changeset 29a9f62 in mainline


Ignore:
Timestamp:
2006-03-23T10:33:55Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
77bd004
Parents:
1cef26f
Message:

Added symbolic links 'libarch','libadt','libipc' into libc/include,
so that it can be easily used from anywhere.
Renamed thread_main to thread_main.
Allowed MIPS to compile with -O0.
Added non-preemptible threads support (not yet secured by futexes).
Added simple way to hold Thread Local Storage. Support for compiler
will be added later.
This update breaks IA64 uspace.

There is some forgotten spinlock_lock() in futexes, amd64 gets locked
in the secod uspace thread probably with preemption disabled.

Files:
11 added
25 edited
4 moved

Legend:

Unmodified
Added
Removed
  • Makefile

    r1cef26f r29a9f62  
    3333
    3434DIRS = \
     35        libc \
    3536        softint \
    3637        softfloat \
    37         libc \
    3838        libipc \
    3939        libadt \
  • init/init.c

    r1cef26f r29a9f62  
    3434#include <ns.h>
    3535#include <thread.h>
     36#include <psthread.h>
    3637#include <futex.h>
    3738
     
    253254}
    254255
    255 
     256static int ptest(void *arg)
     257{
     258        printf("Pseudo thread-1\n");
     259        ps_preempt();
     260        printf("Pseudo thread-2\n");
     261        ps_preempt();
     262        printf("Pseudo thread-3\n");
     263        ps_preempt();
     264        printf("Pseudo thread-4\n");
     265        ps_preempt();
     266        printf("Pseudo finish\n");
     267        return 0;       
     268}
    256269
    257270int main(int argc, char *argv[])
    258271{
     272        pstid_t ptid;
    259273        int tid;
     274
    260275        version_print();
    261276
     
    274289                printf("Futex failed.\n");
    275290
     291        if ((tid = thread_create(utest, NULL, "utest") != -1)) {
     292                printf("Created thread tid=%d\n", tid);
     293        }
     294
    276295        if (futex_down(&ftx) < 0)
    277296                printf("Futex failed.\n");
     
    289308                printf("Futex failed.\n");
    290309
     310        ptid = psthread_create(ptest, NULL);
     311        printf("Main thread-1\n");
     312        ps_preempt();
     313        printf("Main thread-2\n");
     314        ps_preempt();
     315        printf("main thread-3\n");
     316
     317        ps_join(ptid);
     318        printf("Main exiting\n");
     319
    291320        printf("Main thread exiting.\n");
    292321        return 0;
  • libc/Makefile

    r1cef26f r29a9f62  
    5050        generic/io/io.c \
    5151        generic/io/print.c \
    52         malloc/malloc.c
     52        malloc/malloc.c \
     53        generic/psthread.c
    5354
    5455ARCH_SOURCES += \
     
    6667        ln -sfn ../../../kernel/generic/include include/kernel
    6768        ln -sfn kernel/arch include/arch
     69        ln -sfn ../arch/$(ARCH)/include include/libarch
     70        ln -sfn ../../libipc/include include/libipc
     71        ln -sfn ../../libadt/include include/libadt
    6872
    6973-include Makefile.depend
    7074
    7175clean:
    72         -rm -f include/kernel include/arch libc.a arch/$(ARCH)/_link.ld Makefile.depend
     76        -rm -f include/kernel include/arch include/libarch include/libipc include/libadt libc.a arch/$(ARCH)/_link.ld Makefile.depend
    7377        find generic/ arch/$(ARCH)/ -name '*.o' -follow -exec rm \{\} \;
    7478
    75 depend:
     79depend: kerninc
    7680        $(CC) $(DEFS) $(CFLAGS) -M $(ARCH_SOURCES) $(GENERIC_SOURCES) > Makefile.depend
    7781
  • libc/Makefile.toolchain

    r1cef26f r29a9f62  
    2828
    2929DEFS = -DARCH=$(ARCH)
    30 CFLAGS = -fno-builtin -Werror-implicit-function-declaration -Wmissing-prototypes -Werror -O3 -nostdlib -nostdinc -I$(LIBC_PREFIX)/include -I$(LIBC_PREFIX)/arch/$(ARCH)/include
     30CFLAGS = -fno-builtin -Werror-implicit-function-declaration -Wmissing-prototypes -Werror -O3 -nostdlib -nostdinc -I$(LIBC_PREFIX)/include
    3131LFLAGS = -M -N $(SOFTINT_PREFIX)/softint.a
    3232AFLAGS =
  • libc/arch/amd64/Makefile.inc

    r1cef26f r29a9f62  
    3333TOOLCHAIN_DIR = /usr/local/amd64/bin
    3434
    35 ARCH_SOURCES += arch/$(ARCH)/src/syscall.S
     35ARCH_SOURCES += arch/$(ARCH)/src/syscall.S \
     36                arch/$(ARCH)/src/psthread.S
    3637
    3738LFLAGS += -N
  • libc/arch/amd64/src/entry.s

    r1cef26f r29a9f62  
    3737#
    3838__entry:
     39        call __main
    3940        call main
    4041        call __exit
  • libc/arch/amd64/src/thread_entry.s

    r1cef26f r29a9f62  
    3939        #
    4040        movq %rax, %rdi
    41         call thread_main
     41        call __thread_main
    4242       
    4343.end __thread_entry
  • libc/arch/ia32/Makefile.inc

    r1cef26f r29a9f62  
    3333TOOLCHAIN_DIR = /usr/local/i686/bin
    3434
    35 ARCH_SOURCES += arch/$(ARCH)/src/syscall.c
     35ARCH_SOURCES += arch/$(ARCH)/src/syscall.c \
     36                arch/$(ARCH)/src/psthread.S
    3637
    3738LFLAGS += -N
  • libc/arch/ia32/src/entry.s

    r1cef26f r29a9f62  
    4141        mov %ax, %es
    4242        mov %ax, %fs
    43         mov %ax, %gs
     43        # Do not set %gs, it contains descriptor that can see TLS
    4444       
     45        call __main     
    4546        call main
    4647        call __exit
  • libc/arch/ia32/src/thread_entry.s

    r1cef26f r29a9f62  
    3939        mov %dx, %es
    4040        mov %dx, %fs
    41         mov %dx, %gs
     41        # Do not set %gs, it contains descriptor that can see TLS
    4242
    4343        #
     
    4545        #
    4646        pushl %eax
    47         call thread_main
    48         addl $4, %esp
     47        call __thread_main
    4948       
    5049        #
  • libc/arch/ia64/src/entry.s

    r1cef26f r29a9f62  
    3939        alloc loc0 = ar.pfs, 0, 1, 2, 0
    4040        mov r1 = _gp
     41        { br.call.sptk.many b0 = __main }
    4142        { br.call.sptk.many b0 = main }
    4243        { br.call.sptk.many b0 = __exit }
  • libc/arch/ia64/src/thread_entry.s

    r1cef26f r29a9f62  
    4444       
    4545        mov out0 = r8
    46         { br.call.sptk.many b0 = thread_main }
     46        { br.call.sptk.many b0 = __thread_main }
    4747       
    4848        #
  • libc/arch/mips32/Makefile.inc

    r1cef26f r29a9f62  
    3232TARGET = mipsel-linux-gnu
    3333TOOLCHAIN_DIR = /usr/local/mipsel/bin
    34 CFLAGS += -mno-abicalls -mips3
     34CFLAGS += -mno-abicalls -mips3 -ftls-model=global-dynamic
    3535
    36 ARCH_SOURCES += arch/$(ARCH)/src/syscall.c
     36ARCH_SOURCES += arch/$(ARCH)/src/syscall.c \
     37        arch/$(ARCH)/src/psthread.S
    3738
    3839LFLAGS += -N
  • libc/arch/mips32/src/entry.s

    r1cef26f r29a9f62  
    3737#
    3838#
     39.ent __entry
    3940__entry:
    4041        lui $28, _gp
    41 
     42       
     43        # Mips o32 may store its arguments on stack, make space,
     44        # so that it could work with -O0
     45        addiu $sp, -16
     46       
     47        jal __main
     48       
    4249        jal main
    43         nop
    4450       
    4551        jal __exit
    46         nop     
    4752       
    4853.end __entry
  • libc/arch/mips32/src/thread_entry.s

    r1cef26f r29a9f62  
    3838#
    3939#
     40.ent __thread_entry
    4041__thread_entry:
    4142        lui $28, _gp
     
    4546        #
    4647        add $4, $2, 0
    47         jal thread_main
     48        # Mips o32 may store its arguments on stack, make space
     49        addiu $sp, -16
     50       
     51        j __thread_main
    4852        nop
    49        
     53               
    5054        #
    5155        # Not reached.
    5256        #
     57.end __thread_entry
  • libc/generic/libc.c

    r1cef26f r29a9f62  
    3030#include <unistd.h>
    3131#include <thread.h>
     32#include <malloc.h>
     33#include <psthread.h>
    3234
    3335void _exit(int status) {
     
    3638
    3739void __main(void) {
     40        __tls_set(__make_tls());
    3841}
    3942
    4043void __exit(void) {
     44        free(__tls_get());
     45       
    4146        _exit(0);
    4247}
  • libc/generic/thread.c

    r1cef26f r29a9f62  
    3232#include <arch/faddr.h>
    3333#include <kernel/proc/uarg.h>
     34#include <psthread.h>
     35
     36#include <stdio.h>
     37void * __make_tls(void)
     38{
     39        psthread_data_t *pt;
     40
     41        pt = malloc(sizeof(psthread_data_t));
     42        pt->self = pt;
     43
     44        return pt;
     45}
     46
     47void __free_tls(void *tls)
     48{
     49        free(tls);
     50}
    3451
    3552/** Main thread function.
     
    4259 * @param uarg Pointer to userspace argument structure.
    4360 */
    44 void thread_main(uspace_arg_t *uarg)
     61void __thread_main(uspace_arg_t *uarg)
    4562{
     63        /* This should initialize the area according to TLS specicification */
     64        __tls_set(__make_tls());
     65
    4666        uarg->uspace_thread_function(uarg->uspace_thread_arg);
    4767        free(uarg->uspace_stack);
    4868        free(uarg);
     69
     70        __free_tls(__tls_get());
     71
    4972        thread_exit(0);
    5073}
  • libc/include/atomic.h

    r1cef26f r29a9f62  
    3434} atomic_t;
    3535
    36 #include <atomic_arch.h>
     36#include <libarch/atomic.h>
    3737
    3838static inline void atomic_set(atomic_t *val, long i)
  • libc/include/io/io.h

    r1cef26f r29a9f62  
    3030#define __LIBC__IO_IO_H__
    3131
    32 #include <types.h>
     32#include <libarch/types.h>
    3333
    3434int putnchars(const char * buf, size_t count);
  • libc/include/libc.h

    r1cef26f r29a9f62  
    3131
    3232#include <types.h>
    33 
    3433#include <kernel/syscall/syscall.h>
    35 #include <kernel/arch/mm/page.h>
    3634
    3735#define __SYSCALL0(id) __syscall(0, 0, 0, 0, id)
     
    4038#define __SYSCALL3(id, p1, p2, p3) __syscall(p1,p2,p3, 0, id)
    4139#define __SYSCALL4(id, p1, p2, p3, p4) __syscall(p1,p2,p3,p4,id)
    42 
    43 #define getpagesize()     (PAGE_SIZE)
    4440
    4541extern void __main(void);
  • libc/include/stdarg.h

    r1cef26f r29a9f62  
    3030#define __LIBC__STDARG_H__
    3131
    32 #include<types.h>
    33 #include<stackarg.h>
     32#include <types.h>
     33#include <libarch/stackarg.h>
    3434
    3535#ifndef __VARARGS_DEFINED
  • libc/include/stdint.h

    r1cef26f r29a9f62  
    3131
    3232/* Definitions of types with fixed size*/
    33 #include<types.h>
     33#include <types.h>
    3434
    3535#define MAX_INT8 (0x7F)
  • libc/include/thread.h

    r1cef26f r29a9f62  
    3131
    3232#include <kernel/proc/uarg.h>
     33#include <libarch/thread.h>
    3334
    3435extern void __thread_entry(void);
    35 extern void thread_main(uspace_arg_t *uarg);
     36extern void __thread_main(uspace_arg_t *uarg);
    3637
    3738extern int thread_create(void (* function)(void *arg), void *arg, char *name);
    3839extern void thread_exit(int status);
     40void * __make_tls(void);
     41void __free_tls(void *);
    3942
    4043#endif
  • libc/include/unistd.h

    r1cef26f r29a9f62  
    3131
    3232#include <types.h>
     33#include <arch/mm/page.h>
    3334
    3435#define NULL 0
     36#define getpagesize()     (PAGE_SIZE)
    3537
    3638extern ssize_t write(int fd, const void * buf, size_t count);
  • libc/malloc/malloc.c

    r1cef26f r29a9f62  
    537537#ifdef DEBUG
    538538#if ABORT_ON_ASSERT_FAILURE
    539 #define assert(x) if(!(x)) ABORT
     539#define assert(x) {if(!(x)) {printf(#x);ABORT;}}
    540540#else /* ABORT_ON_ASSERT_FAILURE */
    541541#include <assert.h>
Note: See TracChangeset for help on using the changeset viewer.