Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 1113 → Rev 1112

/uspace/trunk/init/init.c
33,7 → 33,6
#include <stdlib.h>
#include <ns.h>
#include <thread.h>
#include <psthread.h>
#include <futex.h>
 
int a;
253,25 → 252,11
ipc_wait_for_call(&data, 0);
}
 
static int ptest(void *arg)
{
printf("Pseudo thread-1\n");
ps_preempt();
printf("Pseudo thread-2\n");
ps_preempt();
printf("Pseudo thread-3\n");
ps_preempt();
printf("Pseudo thread-4\n");
ps_preempt();
printf("Pseudo finish\n");
return 0;
}
 
 
int main(int argc, char *argv[])
{
pstid_t ptid;
int tid;
 
version_print();
 
/* test_printf(); */
288,10 → 273,6
if (futex_up(&ftx) < 0)
printf("Futex failed.\n");
 
if ((tid = thread_create(utest, NULL, "utest") != -1)) {
printf("Created thread tid=%d\n", tid);
}
 
if (futex_down(&ftx) < 0)
printf("Futex failed.\n");
 
307,16 → 288,6
if (futex_up(&ftx) < 0)
printf("Futex failed.\n");
 
ptid = psthread_create(ptest, NULL);
printf("Main thread-1\n");
ps_preempt();
printf("Main thread-2\n");
ps_preempt();
printf("main thread-3\n");
 
ps_join(ptid);
printf("Main exiting\n");
 
printf("Main thread exiting.\n");
return 0;
}
/uspace/trunk/libc/include/psthread.h
File deleted
/uspace/trunk/libc/include/types.h
File deleted
/uspace/trunk/libc/include/atomic.h
33,7 → 33,7
volatile long count;
} atomic_t;
 
#include <libarch/atomic.h>
#include <atomic_arch.h>
 
static inline void atomic_set(atomic_t *val, long i)
{
/uspace/trunk/libc/include/thread.h
30,14 → 30,11
#define __LIBC__THREAD_H__
 
#include <kernel/proc/uarg.h>
#include <libarch/thread.h>
 
extern void __thread_entry(void);
extern void __thread_main(uspace_arg_t *uarg);
extern void thread_main(uspace_arg_t *uarg);
 
extern int thread_create(void (* function)(void *arg), void *arg, char *name);
extern void thread_exit(int status);
void * __make_tls(void);
void __free_tls(void *);
 
#endif
/uspace/trunk/libc/include/unistd.h
30,10 → 30,8
#define __LIBC__UNISTD_H__
 
#include <types.h>
#include <arch/mm/page.h>
 
#define NULL 0
#define getpagesize() (PAGE_SIZE)
 
extern ssize_t write(int fd, const void * buf, size_t count);
extern void _exit(int status);
/uspace/trunk/libc/include/stdint.h
30,7 → 30,7
#define __LIBC__STDINT_H__
 
/* Definitions of types with fixed size*/
#include <types.h>
#include<types.h>
 
#define MAX_INT8 (0x7F)
#define MIN_INT8 (0x80)
/uspace/trunk/libc/include/stdarg.h
29,8 → 29,8
#ifndef __LIBC__STDARG_H__
#define __LIBC__STDARG_H__
 
#include <types.h>
#include <libarch/stackarg.h>
#include<types.h>
#include<stackarg.h>
 
#ifndef __VARARGS_DEFINED
# define __VARARGS_DEFINED
/uspace/trunk/libc/include/io/io.h
29,7 → 29,7
#ifndef __LIBC__IO_H__
#define __LIBC__IO_IO_H__
 
#include <libarch/types.h>
#include <types.h>
 
int putnchars(const char * buf, size_t count);
int putstr(const char * str);
/uspace/trunk/libc/include/libc.h
30,7 → 30,9
#define __LIBC__LIBC_H__
 
#include <types.h>
 
#include <kernel/syscall/syscall.h>
#include <kernel/arch/mm/page.h>
 
#define __SYSCALL0(id) __syscall(0, 0, 0, 0, id)
#define __SYSCALL1(id, p1) __syscall(p1, 0, 0, 0, id)
38,6 → 40,8
#define __SYSCALL3(id, p1, p2, p3) __syscall(p1,p2,p3, 0, id)
#define __SYSCALL4(id, p1, p2, p3, p4) __syscall(p1,p2,p3,p4,id)
 
#define getpagesize() (PAGE_SIZE)
 
extern void __main(void);
extern void __exit(void);
extern sysarg_t __syscall(const sysarg_t p1, const sysarg_t p2,
/uspace/trunk/libc/generic/psthread.c
File deleted
/uspace/trunk/libc/generic/thread.c
31,24 → 31,7
#include <stdlib.h>
#include <arch/faddr.h>
#include <kernel/proc/uarg.h>
#include <psthread.h>
 
#include <stdio.h>
void * __make_tls(void)
{
psthread_data_t *pt;
 
pt = malloc(sizeof(psthread_data_t));
pt->self = pt;
 
return pt;
}
 
void __free_tls(void *tls)
{
free(tls);
}
 
/** Main thread function.
*
* This function is called from __thread_entry() and is used
58,17 → 41,11
*
* @param uarg Pointer to userspace argument structure.
*/
void __thread_main(uspace_arg_t *uarg)
void thread_main(uspace_arg_t *uarg)
{
/* This should initialize the area according to TLS specicification */
__tls_set(__make_tls());
 
uarg->uspace_thread_function(uarg->uspace_thread_arg);
free(uarg->uspace_stack);
free(uarg);
 
__free_tls(__tls_get());
 
thread_exit(0);
}
 
/uspace/trunk/libc/generic/libc.c
29,8 → 29,6
#include <libc.h>
#include <unistd.h>
#include <thread.h>
#include <malloc.h>
#include <psthread.h>
 
void _exit(int status) {
thread_exit(status);
37,11 → 35,8
}
 
void __main(void) {
__tls_set(__make_tls());
}
 
void __exit(void) {
free(__tls_get());
_exit(0);
}
/uspace/trunk/libc/Makefile
49,8 → 49,7
generic/futex.c \
generic/io/io.c \
generic/io/print.c \
malloc/malloc.c \
generic/psthread.c
malloc/malloc.c
 
ARCH_SOURCES += \
arch/$(ARCH)/src/entry.s \
66,17 → 65,14
kerninc:
ln -sfn ../../../kernel/generic/include include/kernel
ln -sfn kernel/arch include/arch
ln -sfn ../arch/$(ARCH)/include include/libarch
ln -sfn ../../libipc/include include/libipc
ln -sfn ../../libadt/include include/libadt
 
-include Makefile.depend
 
clean:
-rm -f include/kernel include/arch include/libarch include/libipc include/libadt libc.a arch/$(ARCH)/_link.ld Makefile.depend
-rm -f include/kernel include/arch libc.a arch/$(ARCH)/_link.ld Makefile.depend
find generic/ arch/$(ARCH)/ -name '*.o' -follow -exec rm \{\} \;
 
depend: kerninc
depend:
$(CC) $(DEFS) $(CFLAGS) -M $(ARCH_SOURCES) $(GENERIC_SOURCES) > Makefile.depend
 
libc.a: depend $(ARCH_OBJECTS) $(GENERIC_OBJECTS)
/uspace/trunk/libc/arch/ia64/include/atomic.h
File deleted
/uspace/trunk/libc/arch/ia64/include/atomic_arch.h
0,0 → 1,57
/*
* Copyright (C) 2005 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __ia64_ATOMIC_H__
#define __ia64_ATOMIC_H__
 
/** Atomic addition.
*
* @param val Atomic value.
* @param imm Value to add.
*
* @return Value before addition.
*/
static inline long atomic_add(atomic_t *val, int imm)
{
long v;
 
__asm__ volatile ("fetchadd8.rel %0 = %1, %2\n" : "=r" (v), "+m" (val->count) : "i" (imm));
return v;
}
 
static inline void atomic_inc(atomic_t *val) { atomic_add(val, 1); }
static inline void atomic_dec(atomic_t *val) { atomic_add(val, -1); }
 
static inline long atomic_preinc(atomic_t *val) { return atomic_add(val, 1) + 1; }
static inline long atomic_predec(atomic_t *val) { return atomic_add(val, -1) - 1; }
 
static inline long atomic_postinc(atomic_t *val) { return atomic_add(val, 1); }
static inline long atomic_postdec(atomic_t *val) { return atomic_add(val, -1); }
 
#endif
/uspace/trunk/libc/arch/ia64/src/entry.s
38,7 → 38,6
__entry:
alloc loc0 = ar.pfs, 0, 1, 2, 0
mov r1 = _gp
{ br.call.sptk.many b0 = __main }
{ br.call.sptk.many b0 = main }
{ br.call.sptk.many b0 = __exit }
/uspace/trunk/libc/arch/ia64/src/thread_entry.s
43,7 → 43,7
#
mov out0 = r8
{ br.call.sptk.many b0 = __thread_main }
{ br.call.sptk.many b0 = thread_main }
#
# Not reached.
/uspace/trunk/libc/arch/amd64/include/psthread.h
File deleted
/uspace/trunk/libc/arch/amd64/include/thread.h
File deleted
/uspace/trunk/libc/arch/amd64/include/context_offset.h
File deleted
/uspace/trunk/libc/arch/amd64/include/atomic.h
File deleted
/uspace/trunk/libc/arch/amd64/include/atomic_arch.h
0,0 → 1,69
/*
* Copyright (C) 2001-2004 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __amd64_ATOMIC_H__
#define __amd64_ATOMIC_H__
 
static inline void atomic_inc(atomic_t *val) {
__asm__ volatile ("lock incq %0\n" : "=m" (val->count));
}
 
static inline void atomic_dec(atomic_t *val) {
__asm__ volatile ("lock decq %0\n" : "=m" (val->count));
}
 
static inline long atomic_postinc(atomic_t *val)
{
long r;
 
__asm__ volatile (
"movq $1, %0\n"
"lock xaddq %0, %1\n"
: "=r" (r), "=m" (val->count)
);
 
return r;
}
 
static inline long atomic_postdec(atomic_t *val)
{
long r;
__asm__ volatile (
"movq $-1, %0\n"
"lock xaddq %0, %1\n"
: "=r" (r), "=m" (val->count)
);
return r;
}
 
#define atomic_preinc(val) (atomic_postinc(val)+1)
#define atomic_predec(val) (atomic_postdec(val)-1)
 
#endif
/uspace/trunk/libc/arch/amd64/src/psthread.S
File deleted
/uspace/trunk/libc/arch/amd64/src/thread_entry.s
38,6 → 38,6
# RAX contains address of uarg
#
movq %rax, %rdi
call __thread_main
call thread_main
.end __thread_entry
/uspace/trunk/libc/arch/amd64/src/entry.s
36,7 → 36,6
#
#
__entry:
call __main
call main
call __exit
/uspace/trunk/libc/arch/amd64/Makefile.inc
32,7 → 32,6
TARGET = amd64-linux-gnu
TOOLCHAIN_DIR = /usr/local/amd64/bin
 
ARCH_SOURCES += arch/$(ARCH)/src/syscall.S \
arch/$(ARCH)/src/psthread.S
ARCH_SOURCES += arch/$(ARCH)/src/syscall.S
 
LFLAGS += -N
/uspace/trunk/libc/arch/mips32/include/psthread.h
File deleted
/uspace/trunk/libc/arch/mips32/include/thread.h
File deleted
/uspace/trunk/libc/arch/mips32/include/context_offset.h
File deleted
/uspace/trunk/libc/arch/mips32/include/atomic.h
File deleted
/uspace/trunk/libc/arch/mips32/include/atomic_arch.h
0,0 → 1,67
/*
* Copyright (C) 2005 Ondrej Palkovsky
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __mips32_ATOMIC_H__
#define __mips32_ATOMIC_H__
 
#define atomic_inc(x) ((void) atomic_add(x, 1))
#define atomic_dec(x) ((void) atomic_add(x, -1))
 
#define atomic_postinc(x) (atomic_add(x, 1) - 1)
#define atomic_postdec(x) (atomic_add(x, -1) + 1)
 
#define atomic_preinc(x) atomic_add(x, 1)
#define atomic_predec(x) atomic_add(x, -1)
 
/* Atomic addition of immediate value.
*
* @param val Memory location to which will be the immediate value added.
* @param i Signed immediate that will be added to *val.
*
* @return Value after addition.
*/
static inline long atomic_add(atomic_t *val, int i)
{
long tmp, v;
 
__asm__ volatile (
"1:\n"
" ll %0, %1\n"
" addiu %0, %0, %3\n" /* same as addi, but never traps on overflow */
" move %2, %0\n"
" sc %0, %1\n"
" beq %0, %4, 1b\n" /* if the atomic operation failed, try again */
/* nop */ /* nop is inserted automatically by compiler */
: "=r" (tmp), "=m" (val->count), "=r" (v)
: "i" (i), "i" (0)
);
 
return v;
}
 
#endif
/uspace/trunk/libc/arch/mips32/src/psthread.S
File deleted
/uspace/trunk/libc/arch/mips32/src/entry.s
36,18 → 36,13
## User-space task entry point
#
#
.ent __entry
__entry:
lui $28, _gp
# Mips o32 may store its arguments on stack, make space,
# so that it could work with -O0
addiu $sp, -16
jal __main
 
jal main
nop
jal __exit
nop
.end __entry
/uspace/trunk/libc/arch/mips32/src/thread_entry.s
37,7 → 37,6
## User-space thread entry point for all but the first threads.
#
#
.ent __thread_entry
__thread_entry:
lui $28, _gp
 
45,13 → 44,9
# v0 contains address of uarg.
#
add $4, $2, 0
# Mips o32 may store its arguments on stack, make space
addiu $sp, -16
jal thread_main
nop
j __thread_main
nop
#
# Not reached.
#
.end __thread_entry
/uspace/trunk/libc/arch/mips32/Makefile.inc
31,10 → 31,9
 
TARGET = mipsel-linux-gnu
TOOLCHAIN_DIR = /usr/local/mipsel/bin
CFLAGS += -mno-abicalls -mips3 -ftls-model=global-dynamic
CFLAGS += -mno-abicalls -mips3
 
ARCH_SOURCES += arch/$(ARCH)/src/syscall.c \
arch/$(ARCH)/src/psthread.S
ARCH_SOURCES += arch/$(ARCH)/src/syscall.c
 
LFLAGS += -N
 
/uspace/trunk/libc/arch/ia32/include/atomic.h
File deleted
/uspace/trunk/libc/arch/ia32/include/atomic_arch.h
0,0 → 1,69
/*
* Copyright (C) 2001-2004 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __ia32_ATOMIC_H__
#define __ia32_ATOMIC_H__
 
static inline void atomic_inc(atomic_t *val) {
__asm__ volatile ("lock incl %0\n" : "=m" (val->count));
}
 
static inline void atomic_dec(atomic_t *val) {
__asm__ volatile ("lock decl %0\n" : "=m" (val->count));
}
 
static inline long atomic_postinc(atomic_t *val)
{
long r;
 
__asm__ volatile (
"movl $1, %0\n"
"lock xaddl %0, %1\n"
: "=r" (r), "=m" (val->count)
);
 
return r;
}
 
static inline long atomic_postdec(atomic_t *val)
{
long r;
__asm__ volatile (
"movl $-1, %0\n"
"lock xaddl %0, %1\n"
: "=r" (r), "=m" (val->count)
);
return r;
}
 
#define atomic_preinc(val) (atomic_postinc(val)+1)
#define atomic_predec(val) (atomic_postdec(val)-1)
 
#endif
/uspace/trunk/libc/arch/ia32/src/thread_entry.s
38,13 → 38,14
mov %dx, %ds
mov %dx, %es
mov %dx, %fs
# Do not set %gs, it contains descriptor that can see TLS
mov %dx, %gs
 
#
# EAX contains address of uarg.
#
pushl %eax
call __thread_main
call thread_main
addl $4, %esp
#
# Not reached.
/uspace/trunk/libc/arch/ia32/src/entry.s
40,9 → 40,8
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
# Do not set %gs, it contains descriptor that can see TLS
mov %ax, %gs
call __main
call main
call __exit
/uspace/trunk/libc/arch/ia32/Makefile.inc
32,7 → 32,6
TARGET = i686-pc-linux-gnu
TOOLCHAIN_DIR = /usr/local/i686/bin
 
ARCH_SOURCES += arch/$(ARCH)/src/syscall.c \
arch/$(ARCH)/src/psthread.S
ARCH_SOURCES += arch/$(ARCH)/src/syscall.c
 
LFLAGS += -N
/uspace/trunk/libc/Makefile.toolchain
27,7 → 27,7
#
 
DEFS = -DARCH=$(ARCH)
CFLAGS = -fno-builtin -Werror-implicit-function-declaration -Wmissing-prototypes -Werror -O3 -nostdlib -nostdinc -I$(LIBC_PREFIX)/include
CFLAGS = -fno-builtin -Werror-implicit-function-declaration -Wmissing-prototypes -Werror -O3 -nostdlib -nostdinc -I$(LIBC_PREFIX)/include -I$(LIBC_PREFIX)/arch/$(ARCH)/include
LFLAGS = -M -N $(SOFTINT_PREFIX)/softint.a
AFLAGS =
 
/uspace/trunk/libc/malloc/malloc.c
536,7 → 536,7
#endif /* LACKS_STDLIB_H */
#ifdef DEBUG
#if ABORT_ON_ASSERT_FAILURE
#define assert(x) {if(!(x)) {printf(#x);ABORT;}}
#define assert(x) if(!(x)) ABORT
#else /* ABORT_ON_ASSERT_FAILURE */
#include <assert.h>
#endif /* ABORT_ON_ASSERT_FAILURE */
/uspace/trunk/Makefile
32,9 → 32,9
-include Makefile.config
 
DIRS = \
libc \
softint \
softfloat \
libc \
libipc \
libadt \
init \