Add TLS support for m68k.

This commit is contained in:
joerg 2011-11-22 15:25:28 +00:00
parent 439935782f
commit 6133e96c53
7 changed files with 94 additions and 12 deletions

View File

@ -1,6 +1,6 @@
# $NetBSD: Makefile.inc,v 1.13 2008/02/09 02:41:06 mrg Exp $
# $NetBSD: Makefile.inc,v 1.14 2011/11/22 15:25:28 joerg Exp $
SRCS+= __sigaction14_sigtramp.c __sigtramp2.S __mmap.S
SRCS+= __sigaction14_sigtramp.c __sigtramp2.S __m68k_read_tp.S __mmap.S
ASM+= _lwp_getprivate.S mremap.S

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile.inc,v 1.30 2009/12/06 07:12:17 uebayasi Exp $
# $NetBSD: Makefile.inc,v 1.31 2011/11/22 15:25:28 joerg Exp $
SRCS+= alloca.S fabs.S
@ -26,6 +26,7 @@ SRCS+= ashlsi3.S ashrsi3.S \
negdf2.S negsf2.S
SRCS+= bswap16.S bswap32.S bswap64.S
SRCS+= _lwp.c
CPPFLAGS._lwp.c += -D_LIBC_SOURCE
# 68000-based machines build with a libgcc that includes
# much of the (soft)float and integer support that would

View File

@ -1,4 +1,4 @@
/* $NetBSD: _lwp.c,v 1.6 2011/02/24 04:28:42 joerg Exp $ */
/* $NetBSD: _lwp.c,v 1.7 2011/11/22 15:25:28 joerg Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -31,18 +31,19 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: _lwp.c,v 1.6 2011/02/24 04:28:42 joerg Exp $");
__RCSID("$NetBSD: _lwp.c,v 1.7 2011/11/22 15:25:28 joerg Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <sys/types.h>
#include <sys/tls.h>
#include <ucontext.h>
#include <lwp.h>
#include <stdlib.h>
void
_lwp_makecontext(ucontext_t *u, void (*start)(void *),
void *arg, void *private, caddr_t stack_base, size_t stack_size)
void *arg, void *tcb, caddr_t stack_base, size_t stack_size)
{
void **sp;
@ -60,6 +61,7 @@ _lwp_makecontext(ucontext_t *u, void (*start)(void *),
*--sp = (void *) _lwp_exit;
u->uc_mcontext.__gregs[_REG_A7] = (int) sp;
u->uc_mcontext._mc_tlsbase = (uintptr_t)private;
u->uc_mcontext._mc_tlsbase = (uintptr_t)tcb + TLS_TP_OFFSET +
sizeof(struct tls_tcb);
u->uc_flags |= _UC_TLSBASE;
}

View File

@ -0,0 +1,7 @@
#include "SYS.h"
ENTRY(__m68k_read_tp)
SYSTRAP(_lwp_getprivate)
movl %d0,%a0
rts
.size __m68k_read_tp, .-__m68k_read_tp

View File

@ -1,13 +1,13 @@
/* $NetBSD: mdreloc.c,v 1.28 2011/03/25 18:07:05 joerg Exp $ */
/* $NetBSD: mdreloc.c,v 1.29 2011/11/22 15:25:28 joerg Exp $ */
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: mdreloc.c,v 1.28 2011/03/25 18:07:05 joerg Exp $");
__RCSID("$NetBSD: mdreloc.c,v 1.29 2011/11/22 15:25:28 joerg Exp $");
#endif /* not lint */
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: mdreloc.c,v 1.28 2011/03/25 18:07:05 joerg Exp $");
__RCSID("$NetBSD: mdreloc.c,v 1.29 2011/11/22 15:25:28 joerg Exp $");
#endif /* not lint */
#include <sys/types.h>
@ -126,6 +126,47 @@ _rtld_relocate_nonplt_objects(Obj_Entry *obj)
rdbg(("COPY (avoid in main)"));
break;
case R_TYPE(TLS_DTPMOD32):
def = _rtld_find_symdef(symnum, obj, &defobj, false);
if (def == NULL)
return -1;
*where = (Elf_Addr)defobj->tlsindex;
rdbg(("DTPMOD32 %s in %s --> %p in %s",
obj->strtab + obj->symtab[symnum].st_name,
obj->path, (void *)*where, defobj->path));
break;
case R_TYPE(TLS_DTPREL32):
def = _rtld_find_symdef(symnum, obj, &defobj, false);
if (def == NULL)
return -1;
if (!defobj->tls_done && _rtld_tls_offset_allocate(obj))
return -1;
*where = (Elf_Addr)(def->st_value + rela->r_addend
- TLS_DTV_OFFSET);
rdbg(("DTPREL32 %s in %s --> %p in %s",
obj->strtab + obj->symtab[symnum].st_name,
obj->path, (void *)*where, defobj->path));
break;
case R_TYPE(TLS_TPREL32):
def = _rtld_find_symdef(symnum, obj, &defobj, false);
if (def == NULL)
return -1;
if (!defobj->tls_done && _rtld_tls_offset_allocate(obj))
return -1;
*where = (Elf_Addr)(def->st_value + rela->r_addend
+ defobj->tlsoffset - TLS_TP_OFFSET);
rdbg(("TPREL32 %s in %s --> %p in %s",
obj->strtab + obj->symtab[symnum].st_name,
obj->path, (void *)*where, defobj->path));
break;
default:
rdbg(("sym = %lu, type = %lu, offset = %p, "
"addend = %p, contents = %p, symbol = %s",

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcontext.h,v 1.8 2011/02/24 04:28:46 joerg Exp $ */
/* $NetBSD: mcontext.h,v 1.9 2011/11/22 15:25:28 joerg Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -109,4 +109,31 @@ typedef struct {
#define __UCONTEXT_SIZE 1024
#if defined(_LIBC_SOURCE) || defined(_RTLD_SOURCE) || defined(__LIBPTHREAD_SOURCE__)
#define TLS_TP_OFFSET 0x7000
#define TLS_DTV_OFFSET 0x8000
#include <sys/tls.h>
__CTASSERT(TLS_TP_OFFSET + sizeof(struct tls_tcb) < 0x8000);
__CTASSERT(TLS_TP_OFFSET % sizeof(struct tls_tcb) == 0);
void *_lwp_getprivate(void);
void _lwp_setprivate(void *);
static __inline struct tls_tcb *
__lwp_gettcb_fast(void)
{
unsigned int __tcb = (unsigned int)_lwp_getprivate();
return (void *)(__tcb - TLS_TP_OFFSET - sizeof(struct tls_tcb));
}
static inline void
__lwp_settcb(struct tls_tcb *__tcb)
{
__tcb += TLS_TP_OFFSET / sizeof(*__tcb) + 1;
_lwp_setprivate(__tcb);
}
#endif
#endif /* !_M68K_MCONTEXT_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: types.h,v 1.29 2010/12/22 02:42:28 matt Exp $ */
/* $NetBSD: types.h,v 1.30 2011/11/22 15:25:28 joerg Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@ -73,6 +73,10 @@ typedef volatile unsigned char __cpu_simple_lock_t;
#define __HAVE_SYSCALL_INTERN
#define __HAVE_CPU_DATA_FIRST
#define __HAVE_COMMON___TLS_GET_ADDR
#define __HAVE___LWP_GETTCB_FAST
#define __HAVE___LWP_SETTCB
#define __HAVE_TLS_VARIANT_I
#if defined(_KERNEL)
#define __HAVE_RAS