From patchwork Tue Jan 13 15:21:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chung-Lin Tang X-Patchwork-Id: 428473 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4957814012F for ; Wed, 14 Jan 2015 02:30:57 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:date:from:mime-version:to:cc :subject:references:in-reply-to:content-type; q=dns; s=default; b= M4tdykyX/VpDtR0+m0o4ucQTTBklu0ttp+uPvvhdA/6Dtmg0pDHa5eXTFDymODpE 0mTd3MXEa/kZOfnEI9Auf391ftOE5h8ilVZpW1iCdhXUVSsEZs7AnUpHSPF6mwaC oMW+sht94stSwUKJbvRq9nj1aSZSyGA4EWo7MY2qOQc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:date:from:mime-version:to:cc :subject:references:in-reply-to:content-type; s=default; bh=VDQW 3RYKPuNSskGzAPJiVjKQCS4=; b=psEDdBkwSV62ytBrMBAiLUCl/TwBCMxXpAg4 Mo0lXtoVsyFn83OAGWei0x9nd3s285H7iwPeyiHN07uA9fkn9CAswXBG7SsKDAfI z66i1CFucH0YT0cyvh6b4G62UWqs2PvYN96IkWsLU8HJ+0a+5rKLQR84MYWsoR7u w9WxOMA= Received: (qmail 3616 invoked by alias); 13 Jan 2015 15:21:32 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 3401 invoked by uid 89); 13 Jan 2015 15:21:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.1 required=5.0 tests=AWL, BAYES_50, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Message-ID: <54B537EB.8020605@codesourcery.com> Date: Tue, 13 Jan 2015 23:21:15 +0800 From: Chung-Lin Tang User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: Joseph Myers CC: GNU C Library Subject: Re: [PATCH v3 2/4] Nios II port re-submission, sysdeps/unix/sysv/linux/nios2 References: <54B018A8.3060306@codesourcery.com> In-Reply-To: On 2015/1/10 02:34 AM, Joseph Myers wrote: > On Sat, 10 Jan 2015, Chung-Lin Tang wrote: > >> The sysdeps/unix/sysv/linux/nios2 portions; version symbol is set at >> GLIBC_2.21. > > Again, GLIBC_2.20 in Versions file needs changing to GLIBC_2.21. > > Again, some files need descriptive comments as their first lines. Updated patch for sysdeps/unix/sysv/linux/nios2 portions as attached. Thanks, Chung-Lin diff --git a/sysdeps/unix/sysv/linux/nios2/Implies b/sysdeps/unix/sysv/linux/nios2/Implies new file mode 100644 index 0000000..4d0478b --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/Implies @@ -0,0 +1,3 @@ +nios2/nptl +unix/sysv/linux/generic/wordsize-32 +unix/sysv/linux/generic diff --git a/sysdeps/unix/sysv/linux/nios2/Makefile b/sysdeps/unix/sysv/linux/nios2/Makefile new file mode 100644 index 0000000..d0af9ec --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/Makefile @@ -0,0 +1,13 @@ +ifeq ($(subdir),stdlib) +gen-as-const-headers += ucontext_i.sym +endif + +ifeq ($(subdir),misc) +# MIPS/Tile-style cacheflush routine +sysdep_headers += sys/cachectl.h +sysdep_routines += cacheflush +endif + +ifeq ($(subdir),nptl) +libpthread-routines := $(filter-out pt-vfork,$(libpthread-routines)) +endif diff --git a/sysdeps/unix/sysv/linux/nios2/Versions b/sysdeps/unix/sysv/linux/nios2/Versions new file mode 100644 index 0000000..e42c85f --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/Versions @@ -0,0 +1,6 @@ +libc { + GLIBC_2.21 { + _flush_cache; + cacheflush; + } +} diff --git a/sysdeps/unix/sysv/linux/nios2/arch-fork.h b/sysdeps/unix/sysv/linux/nios2/arch-fork.h new file mode 100644 index 0000000..23d497e --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/arch-fork.h @@ -0,0 +1,33 @@ +/* ARCH_FORK definition for Linux fork implementation. Nios II version. + Copyright (C) 2005-2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +/* Argument 1 - Clone flags. + 2 - Child stack pointer. + 3 - Parent tid pointer. + 4 - Child tid pointer. + 5 - New TLS area pointer. */ + +#define ARCH_FORK() \ + INLINE_SYSCALL (clone, 5, \ + CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD, \ + NULL, NULL, &THREAD_SELF->tid, NULL) diff --git a/sysdeps/unix/sysv/linux/nios2/bits/atomic.h b/sysdeps/unix/sysv/linux/nios2/bits/atomic.h new file mode 100644 index 0000000..2329f74 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/bits/atomic.h @@ -0,0 +1,92 @@ +/* Low-level functions for atomic operations. Nios II version. + Copyright (C) 2012-2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#ifndef _NIOS2_BITS_ATOMIC_H +#define _NIOS2_BITS_ATOMIC_H 1 + +#include + +typedef int32_t atomic32_t; +typedef uint32_t uatomic32_t; +typedef int_fast32_t atomic_fast32_t; +typedef uint_fast32_t uatomic_fast32_t; + +typedef intptr_t atomicptr_t; +typedef uintptr_t uatomicptr_t; +typedef intmax_t atomic_max_t; +typedef uintmax_t uatomic_max_t; + +#define __HAVE_64B_ATOMICS 0 +#define USE_ATOMIC_COMPILER_BUILTINS 0 + +#define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \ + (abort (), (__typeof (*mem)) 0) +#define __arch_compare_and_exchange_val_16_acq(mem, newval, oldval) \ + (abort (), (__typeof (*mem)) 0) +#define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \ + (abort (), (__typeof (*mem)) 0) + +#define __arch_compare_and_exchange_bool_8_acq(mem, newval, oldval) \ + (abort (), 0) +#define __arch_compare_and_exchange_bool_16_acq(mem, newval, oldval) \ + (abort (), 0) +#define __arch_compare_and_exchange_bool_64_acq(mem, newval, oldval) \ + (abort (), 0) + +#define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \ + ({ \ + register int r2 asm ("r2"); \ + register int* r4 asm ("r4") = (int*)(mem); \ + register int r5 asm ("r5"); \ + register int r6 asm ("r6") = (int)(newval); \ + int retval, orig_oldval = (int)(oldval); \ + long kernel_cmpxchg = 0x1004; \ + while (1) \ + { \ + r5 = *r4; \ + if (r5 != orig_oldval) \ + { \ + retval = r5; \ + break; \ + } \ + asm volatile ("callr %1\n" \ + : "=r" (r2) \ + : "r" (kernel_cmpxchg), "r" (r4), "r" (r5), "r" (r6) \ + : "ra", "memory"); \ + if (!r2) { retval = orig_oldval; break; } \ + } \ + (__typeof (*(mem))) retval; \ + }) + +#define __arch_compare_and_exchange_bool_32_acq(mem, newval, oldval) \ + ({ \ + register int r2 asm ("r2"); \ + register int *r4 asm ("r4") = (int*)(mem); \ + register int r5 asm ("r5") = (int)(oldval); \ + register int r6 asm ("r6") = (int)(newval); \ + long kernel_cmpxchg = 0x1004; \ + asm volatile ("callr %1\n" \ + : "=r" (r2) \ + : "r" (kernel_cmpxchg), "r" (r4), "r" (r5), "r" (r6) \ + : "ra", "memory"); \ + r2; \ + }) + +#define atomic_full_barrier() ({ asm volatile ("sync"); }) + +#endif /* _NIOS2_BITS_ATOMIC_H */ diff --git a/sysdeps/unix/sysv/linux/nios2/bits/mman.h b/sysdeps/unix/sysv/linux/nios2/bits/mman.h new file mode 100644 index 0000000..23e92ab --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/bits/mman.h @@ -0,0 +1,42 @@ +/* Definitions for POSIX memory map interface. Linux/Nios II version. + + Copyright (C) 1997-2015 Free Software Foundation, Inc. + + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#ifndef _SYS_MMAN_H +# error "Never use directly; include instead." +#endif + +/* The following definitions basically come from the kernel headers. + But the kernel header is not namespace clean. */ + +/* These are Linux-specific. */ +#ifdef __USE_MISC +# define MAP_GROWSDOWN 0x00100 /* Stack-like segment. */ +# define MAP_DENYWRITE 0x00800 /* ETXTBSY */ +# define MAP_EXECUTABLE 0x01000 /* Mark it as an executable. */ +# define MAP_LOCKED 0x02000 /* Lock the mapping. */ +# define MAP_NORESERVE 0x04000 /* Don't check for reservations. */ +# define MAP_POPULATE 0x08000 /* Populate (prefault) pagetables. */ +# define MAP_NONBLOCK 0x10000 /* Do not block on IO. */ +# define MAP_STACK 0x20000 /* Allocation is for a stack. */ +# define MAP_HUGETLB 0x40000 /* Create huge page mapping. */ +#endif + +/* Include generic Linux declarations. */ +#include diff --git a/sysdeps/unix/sysv/linux/nios2/cacheflush.c b/sysdeps/unix/sysv/linux/nios2/cacheflush.c new file mode 100644 index 0000000..739e6df --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/cacheflush.c @@ -0,0 +1,28 @@ +/* Copyright (C) 2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include +#include +#include + +/* Flush cache(s). */ +int +_flush_cache (char *addr, const int nbytes, const int op) +{ + return INLINE_SYSCALL (cacheflush, 3, addr, nbytes, op); +} +weak_alias (_flush_cache, cacheflush) diff --git a/sysdeps/unix/sysv/linux/nios2/clone.S b/sysdeps/unix/sysv/linux/nios2/clone.S new file mode 100644 index 0000000..9fab461 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/clone.S @@ -0,0 +1,107 @@ +/* clone() implementation for Nios II. + Copyright (C) 2008-2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Andrew Jenner , 2008. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* clone() is even more special than fork() as it mucks with stacks + and invokes a function in the right context after its all over. */ + +#include +#define _ERRNO_H 1 +#include +#include + +#define CLONE_VM 0x00000100 +#define CLONE_THREAD 0x00010000 + +/* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg, + void *parent_tidptr, void *tls, void *child_tidptr) */ + + .text +ENTRY(__clone) + /* Sanity check arguments. */ + movi r2, EINVAL + /* No NULL function pointers. */ + beq r4, zero, SYSCALL_ERROR_LABEL + /* No NULL stack pointers. */ + beq r5, zero, SYSCALL_ERROR_LABEL + + subi r5, r5, 8 /* Reserve argument save space. */ + stw r4, 4(r5) /* Save function pointer. */ + stw r7, 0(r5) /* Save argument pointer. */ + + /* Load arguments. */ + mov r4, r6 + ldw r6, 0(sp) + ldw r7, 8(sp) + ldw r8, 4(sp) + + /* Do the system call. */ + movi r2, SYS_ify (clone) + + /* End FDE now, because in the child the unwind info will be + wrong. */ + cfi_endproc + trap + + /* Check for errors. */ + bne r7, zero, SYSCALL_ERROR_LABEL + /* See if we're on the newly created thread. */ + beq r2, zero, thread_start + /* Successful return from the parent */ + ret + +thread_start: + cfi_startproc + cfi_undefined (ra) + + /* We expect the argument registers to be preserved across system + calls and across task cloning, so flags should be in r4 here. */ + andhi r2, r4, %hi(CLONE_THREAD) + bne r2, zero, 2f + andi r3, r4, CLONE_VM + movi r2, -1 + bne r3, zero, 3f + DO_CALL (getpid, 0) +3: + stw r2, PID_OFFSET(r23) + stw r2, TID_OFFSET(r23) +2: + ldw r5, 4(sp) /* Function pointer. */ + ldw r4, 0(sp) /* Argument pointer. */ + addi sp, sp, 8 + + /* Call the user's function. */ + callr r5 + + /* _exit with the result. */ + mov r4, r2 +#ifdef PIC + nextpc r22 +1: movhi r8, %hiadj(_gp_got - 1b) + addi r8, r8, %lo(_gp_got - 1b) + add r22, r22, r8 + ldw r8, %call(HIDDEN_JUMPTARGET(_exit))(r22) + jmp r8 +#else + jmpi _exit +#endif + cfi_endproc + + cfi_startproc +PSEUDO_END (__clone) +weak_alias (__clone, clone) diff --git a/sysdeps/unix/sysv/linux/nios2/configure b/sysdeps/unix/sysv/linux/nios2/configure new file mode 100644 index 0000000..d5d117b --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/configure @@ -0,0 +1,4 @@ +# This file is generated from configure.in by Autoconf. DO NOT EDIT! + # Local configure fragment for sysdeps/unix/sysv/linux/nios2. + +arch_minimum_kernel=3.19.0 diff --git a/sysdeps/unix/sysv/linux/nios2/configure.ac b/sysdeps/unix/sysv/linux/nios2/configure.ac new file mode 100644 index 0000000..a8ccc17 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/configure.ac @@ -0,0 +1,4 @@ +GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory. +# Local configure fragment for sysdeps/unix/sysv/linux/nios2. + +arch_minimum_kernel=3.19.0 diff --git a/sysdeps/unix/sysv/linux/nios2/getcontext.S b/sysdeps/unix/sysv/linux/nios2/getcontext.S new file mode 100644 index 0000000..ffbd91f --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/getcontext.S @@ -0,0 +1,66 @@ +/* Save current context. + Copyright (C) 2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include "ucontext_i.h" + +/* int getcontext (ucontext_t *ucp) + + Returns 0 on success -1 and errno on failure. + */ + .text +ENTRY(__getcontext) + stw r16, (UCONTEXT_MCONTEXT + 16*4)(r4) + stw r17, (UCONTEXT_MCONTEXT + 17*4)(r4) + stw r18, (UCONTEXT_MCONTEXT + 18*4)(r4) + stw r19, (UCONTEXT_MCONTEXT + 19*4)(r4) + stw r20, (UCONTEXT_MCONTEXT + 20*4)(r4) + stw r21, (UCONTEXT_MCONTEXT + 21*4)(r4) + stw r22, (UCONTEXT_MCONTEXT + 22*4)(r4) + stw ra, (UCONTEXT_MCONTEXT + 24*4)(r4) + stw fp, (UCONTEXT_MCONTEXT + 25*4)(r4) + stw gp, (UCONTEXT_MCONTEXT + 26*4)(r4) + /* Store return address at place for EA. */ + stw ra, (UCONTEXT_MCONTEXT + 28*4)(r4) + stw sp, (UCONTEXT_MCONTEXT + 29*4)(r4) + /* Store zero for return success. */ + stw zero, (UCONTEXT_MCONTEXT + 2*4)(r4) + + /* Store value "1" at uc_flags to recognize as getcontext created. */ + movi r2, 1 + stw r2, UCONTEXT_FLAGS(r4) + + /* Store MCONTEXT_VERSION at first word of mcontext_t. */ + movi r2, MCONTEXT_VERSION + stw r2, UCONTEXT_MCONTEXT(r4) + + /* Get signal mask. */ + /* rt_sigprocmask (SIG_BLOCK, NULL, &ucp->uc_sigmask, _NSIG8) */ + movi r7, _NSIG8 + addi r6, r4, UCONTEXT_SIGMASK + mov r5, zero + movi r4, SIG_BLOCK + movi r2, SYS_ify (rt_sigprocmask) + trap + bne r7, zero, SYSCALL_ERROR_LABEL + + mov r2, zero + ret + +PSEUDO_END(__getcontext) +weak_alias(__getcontext, getcontext) diff --git a/sysdeps/unix/sysv/linux/nios2/kernel-features.h b/sysdeps/unix/sysv/linux/nios2/kernel-features.h new file mode 100644 index 0000000..f4e96a0 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/kernel-features.h @@ -0,0 +1,31 @@ +/* Set flags signalling availability of kernel features based on given + kernel version number. + + Copyright (C) 2009-2015 Free Software Foundation, Inc. + + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +/* The minimum supported kernel version for Nios II is 3.19.0, + guaranteeing many kernel features. */ + +#define __ASSUME_ACCEPT4_SYSCALL 1 +#define __ASSUME_RECVMMSG_SYSCALL 1 +#define __ASSUME_SENDMMSG_SYSCALL 1 + +#include_next diff --git a/sysdeps/unix/sysv/linux/nios2/kernel_rt_sigframe.h b/sysdeps/unix/sysv/linux/nios2/kernel_rt_sigframe.h new file mode 100644 index 0000000..189edad --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/kernel_rt_sigframe.h @@ -0,0 +1,26 @@ +/* Linux kernel struct rt_sigframe declaration for Nios II. + Copyright (C) 2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* This structure must have the same shape as the Linux kernel + equivalent. */ + +struct kernel_rt_sigframe +{ + siginfo_t info; + struct ucontext uc; +}; diff --git a/sysdeps/unix/sysv/linux/nios2/makecontext.c b/sysdeps/unix/sysv/linux/nios2/makecontext.c new file mode 100644 index 0000000..5df951a --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/makecontext.c @@ -0,0 +1,79 @@ +/* Create new context. + Copyright (C) 2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +/* makecontext sets up a stack and the registers for the + user context. The stack looks like this: + + +-----------------------+ + | padding as required | + +-----------------------+ + sp -> | parameters 5 to n | + +-----------------------+ + + The registers are set up like this: + r4--r7 : parameter 1 to 4 + r16 : uc_link + sp : stack pointer. +*/ + +void +__makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...) +{ + extern void __startcontext (void); + unsigned long *sp; + va_list ap; + int i; + + sp = (unsigned long *) + ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size); + + /* Allocate stack arguments. */ + sp -= argc < 4 ? 0 : argc - 4; + + /* Keep the stack aligned. */ + sp = (unsigned long*) (((uintptr_t) sp) & -4L); + + /* Init version field. */ + ucp->uc_mcontext.version = 2; + /* Keep uc_link in r16. */ + ucp->uc_mcontext.regs[15] = (uintptr_t) ucp->uc_link; + /* Return address points to __startcontext(). */ + ucp->uc_mcontext.regs[23] = (uintptr_t) &__startcontext; + /* Frame pointer is null. */ + ucp->uc_mcontext.regs[24] = (uintptr_t) 0; + /* Restart in user-space starting at 'func'. */ + ucp->uc_mcontext.regs[27] = (uintptr_t) func; + /* Set stack pointer. */ + ucp->uc_mcontext.regs[28] = (uintptr_t) sp; + + va_start (ap, argc); + for (i = 0; i < argc; ++i) + if (i < 4) + ucp->uc_mcontext.regs[i + 3] = va_arg (ap, unsigned long); + else + sp[i - 4] = va_arg (ap, unsigned long); + + va_end (ap); +} + +weak_alias (__makecontext, makecontext) diff --git a/sysdeps/unix/sysv/linux/nios2/profil-counter.h b/sysdeps/unix/sysv/linux/nios2/profil-counter.h new file mode 100644 index 0000000..8a6a0bc --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/profil-counter.h @@ -0,0 +1,2 @@ +/* We can use the ix86 version. */ +#include diff --git a/sysdeps/unix/sysv/linux/nios2/setcontext.S b/sysdeps/unix/sysv/linux/nios2/setcontext.S new file mode 100644 index 0000000..9a8dd87 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/setcontext.S @@ -0,0 +1,103 @@ +/* Set current context. + Copyright (C) 2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include "ucontext_i.h" + +/* int setcontext (const ucontext_t *ucp) */ + .text +ENTRY(__setcontext) + ldw r5, UCONTEXT_FLAGS(r4) + movi r6, 1 + bne r5, r6, .Lsigreturn + + mov r10, r4 + + /* Restore signal mask. */ + /* rt_sigprocmask (SIG_SETMASK, NULL, &ucp->uc_sigmask, _NSIG8) */ + movi r7, _NSIG8 + addi r6, r4, UCONTEXT_SIGMASK + mov r5, zero + movi r4, SIG_SETMASK + movi r2, SYS_ify (rt_sigprocmask) + trap + bne r7, zero, SYSCALL_ERROR_LABEL + + /* Restore argument registers, for the makecontext() case. */ + ldw r4, (UCONTEXT_MCONTEXT + 4*4)(r10) + ldw r5, (UCONTEXT_MCONTEXT + 5*4)(r10) + ldw r6, (UCONTEXT_MCONTEXT + 6*4)(r10) + ldw r7, (UCONTEXT_MCONTEXT + 7*4)(r10) + + ldw r16, (UCONTEXT_MCONTEXT + 16*4)(r10) + ldw r17, (UCONTEXT_MCONTEXT + 17*4)(r10) + ldw r18, (UCONTEXT_MCONTEXT + 18*4)(r10) + ldw r19, (UCONTEXT_MCONTEXT + 19*4)(r10) + ldw r20, (UCONTEXT_MCONTEXT + 20*4)(r10) + ldw r21, (UCONTEXT_MCONTEXT + 21*4)(r10) + ldw r22, (UCONTEXT_MCONTEXT + 22*4)(r10) + ldw ra, (UCONTEXT_MCONTEXT + 24*4)(r10) + ldw fp, (UCONTEXT_MCONTEXT + 25*4)(r10) + ldw gp, (UCONTEXT_MCONTEXT + 26*4)(r10) + /* Load address to continue execution. */ + ldw r3, (UCONTEXT_MCONTEXT + 28*4)(r10) + ldw sp, (UCONTEXT_MCONTEXT + 29*4)(r10) + + mov r2, zero + jmp r3 + +.Lsigreturn: + addi sp, sp, -RT_SIGFRAME_SIZE + cfi_adjust_cfa_offset (RT_SIGFRAME_SIZE) + + addi r2, sp, RT_SIGFRAME_UCONTEXT + movi r3, UCONTEXT_SIZE-4 +1: + add r6, r4, r3 + ldw r5, 0(r6) + add r7, r2, r3 + addi r3, r3, -4 + stw r5, 0(r7) + bgt r3, zero, 1b + + movi r2, SYS_ify (rt_sigreturn) + trap + + addi sp, sp, RT_SIGFRAME_SIZE + cfi_adjust_cfa_offset (-RT_SIGFRAME_SIZE) + br SYSCALL_ERROR_LABEL + +PSEUDO_END (__setcontext) +weak_alias (__setcontext, setcontext) + +ENTRY(__startcontext) + mov r4, r16 + bne r4, zero, __setcontext + + /* If uc_link == zero, call _exit. */ +#ifdef PIC + nextpc r22 +1: movhi r8, %hiadj(_gp_got - 1b) + addi r8, r8, %lo(_gp_got - 1b) + add r22, r22, r8 + ldw r8, %call(HIDDEN_JUMPTARGET(_exit))(r22) + jmp r8 +#else + jmpi _exit +#endif +END(__startcontext) diff --git a/sysdeps/unix/sysv/linux/nios2/shlib-versions b/sysdeps/unix/sysv/linux/nios2/shlib-versions new file mode 100644 index 0000000..443fd4d --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/shlib-versions @@ -0,0 +1,2 @@ +DEFAULT GLIBC_2.21 +ld=ld-linux-nios2.so.1 diff --git a/sysdeps/unix/sysv/linux/nios2/sigcontextinfo.h b/sysdeps/unix/sysv/linux/nios2/sigcontextinfo.h new file mode 100644 index 0000000..ef77d82 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/sigcontextinfo.h @@ -0,0 +1,35 @@ +/* Nios II definitions for signal handling calling conventions. + Copyright (C) 2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include "kernel-features.h" + +#define SIGCONTEXT siginfo_t *_si, struct ucontext * +#define GET_PC(ctx) ((void *) (ctx)->uc_mcontext.regs[27]) + +/* There is no reliable way to get the sigcontext unless we use a + three-argument signal handler. */ +#define __sigaction(sig, act, oact) ({ \ + (act)->sa_flags |= SA_SIGINFO; \ + (__sigaction) (sig, act, oact); \ +}) + +#define sigaction(sig, act, oact) ({ \ + (act)->sa_flags |= SA_SIGINFO; \ + (sigaction) (sig, act, oact); \ +}) diff --git a/sysdeps/unix/sysv/linux/nios2/swapcontext.S b/sysdeps/unix/sysv/linux/nios2/swapcontext.S new file mode 100644 index 0000000..c2c321d --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/swapcontext.S @@ -0,0 +1,125 @@ +/* Modify saved context. + Copyright (C) 2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include "ucontext_i.h" + +/* int swapcontext (ucontext_t *oucp, const ucontext_t *ucp) */ + .text +ENTRY(__swapcontext) + + /* Same as getcontext(). */ + stw r16, (UCONTEXT_MCONTEXT + 16*4)(r4) + stw r17, (UCONTEXT_MCONTEXT + 17*4)(r4) + stw r18, (UCONTEXT_MCONTEXT + 18*4)(r4) + stw r19, (UCONTEXT_MCONTEXT + 19*4)(r4) + stw r20, (UCONTEXT_MCONTEXT + 20*4)(r4) + stw r21, (UCONTEXT_MCONTEXT + 21*4)(r4) + stw r22, (UCONTEXT_MCONTEXT + 22*4)(r4) + stw ra, (UCONTEXT_MCONTEXT + 24*4)(r4) + stw fp, (UCONTEXT_MCONTEXT + 25*4)(r4) + stw gp, (UCONTEXT_MCONTEXT + 26*4)(r4) + /* Store return address at place for EA. */ + stw ra, (UCONTEXT_MCONTEXT + 28*4)(r4) + stw sp, (UCONTEXT_MCONTEXT + 29*4)(r4) + /* Store zero for return success. */ + stw zero, (UCONTEXT_MCONTEXT + 2*4)(r4) + + /* Store value "1" at uc_flags to recognize as getcontext created. */ + movi r2, 1 + stw r2, UCONTEXT_FLAGS(r4) + + /* Store MCONTEXT_VERSION at first word of mcontext_t. */ + movi r2, MCONTEXT_VERSION + stw r2, UCONTEXT_MCONTEXT(r4) + + /* Save ucp to non-argument syscall preserved register. */ + mov r10, r5 + + /* Get signal mask. */ + /* rt_sigprocmask (SIG_BLOCK, NULL, &ucp->uc_sigmask, _NSIG8) */ + movi r7, _NSIG8 + addi r6, r4, UCONTEXT_SIGMASK + mov r5, zero + movi r4, SIG_BLOCK + movi r2, SYS_ify (rt_sigprocmask) + trap + bne r7, zero, SYSCALL_ERROR_LABEL + + + /* Same as setcontext(). */ + ldw r5, UCONTEXT_FLAGS(r10) + movi r6, 1 + bne r5, r6, .Lsigreturn + + /* Restore signal mask. */ + /* rt_sigprocmask (SIG_SETMASK, NULL, &ucp->uc_sigmask, _NSIG8) */ + movi r7, _NSIG8 + addi r6, r10, UCONTEXT_SIGMASK + mov r5, zero + movi r4, SIG_SETMASK + movi r2, SYS_ify (rt_sigprocmask) + trap + bne r7, zero, SYSCALL_ERROR_LABEL + + /* Restore argument registers, for the makecontext() case. */ + ldw r4, (UCONTEXT_MCONTEXT + 4*4)(r10) + ldw r5, (UCONTEXT_MCONTEXT + 5*4)(r10) + ldw r6, (UCONTEXT_MCONTEXT + 6*4)(r10) + ldw r7, (UCONTEXT_MCONTEXT + 7*4)(r10) + + ldw r16, (UCONTEXT_MCONTEXT + 16*4)(r10) + ldw r17, (UCONTEXT_MCONTEXT + 17*4)(r10) + ldw r18, (UCONTEXT_MCONTEXT + 18*4)(r10) + ldw r19, (UCONTEXT_MCONTEXT + 19*4)(r10) + ldw r20, (UCONTEXT_MCONTEXT + 20*4)(r10) + ldw r21, (UCONTEXT_MCONTEXT + 21*4)(r10) + ldw r22, (UCONTEXT_MCONTEXT + 22*4)(r10) + ldw ra, (UCONTEXT_MCONTEXT + 24*4)(r10) + ldw fp, (UCONTEXT_MCONTEXT + 25*4)(r10) + ldw gp, (UCONTEXT_MCONTEXT + 26*4)(r10) + /* Load address to continue execution. */ + ldw r3, (UCONTEXT_MCONTEXT + 28*4)(r10) + ldw sp, (UCONTEXT_MCONTEXT + 29*4)(r10) + + mov r2, zero + jmp r3 + +.Lsigreturn: + addi sp, sp, -RT_SIGFRAME_SIZE + cfi_adjust_cfa_offset (RT_SIGFRAME_SIZE) + + addi r2, sp, RT_SIGFRAME_UCONTEXT + movi r3, UCONTEXT_SIZE-4 +1: + add r6, r4, r3 + ldw r5, 0(r6) + add r7, r2, r3 + addi r3, r3, -4 + stw r5, 0(r7) + bgt r3, zero, 1b + + movi r2, SYS_ify (rt_sigreturn) + trap + + addi sp, sp, RT_SIGFRAME_SIZE + cfi_adjust_cfa_offset (-RT_SIGFRAME_SIZE) + br SYSCALL_ERROR_LABEL + +PSEUDO_END (__swapcontext) +weak_alias (__swapcontext, swapcontext) diff --git a/sysdeps/unix/sysv/linux/nios2/sys/cachectl.h b/sysdeps/unix/sysv/linux/nios2/sys/cachectl.h new file mode 100644 index 0000000..ac992a2 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/sys/cachectl.h @@ -0,0 +1,35 @@ +/* Copyright (C) 2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#ifndef _SYS_CACHECTL_H +#define _SYS_CACHECTL_H 1 + +#include + +/* Get the kernel definition for the op bits. */ +#include + +__BEGIN_DECLS + +#ifdef __USE_MISC +extern int cacheflush (void *__addr, const int __nbytes, const int __op) __THROW; +#endif +extern int _flush_cache (char *__addr, const int __nbytes, const int __op) __THROW; + +__END_DECLS + +#endif /* sys/cachectl.h */ diff --git a/sysdeps/unix/sysv/linux/nios2/sys/procfs.h b/sysdeps/unix/sysv/linux/nios2/sys/procfs.h new file mode 100644 index 0000000..2126503 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/sys/procfs.h @@ -0,0 +1,122 @@ +/* Copyright (C) 1996-2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _SYS_PROCFS_H +#define _SYS_PROCFS_H 1 + +/* This is somewhat modelled after the file of the same name on SVR4 + systems. It provides a definition of the core file format for ELF + used on Linux. It doesn't have anything to do with the /proc file + system, even though Linux has one. + + Anyway, the whole purpose of this file is for GDB and GDB only. + Don't read too much into it. Don't use it for anything other than + GDB unless you know what you are doing. */ + +#include +#include +#include +#include + +__BEGIN_DECLS + +/* Type for a general-purpose register. */ +typedef unsigned long elf_greg_t; + +/* And the whole bunch of them. We could have used `struct + user_regs' directly in the typedef, but tradition says that + the register set is an array, which does have some peculiar + semantics, so leave it that way. */ +#define ELF_NGREG (sizeof (struct user_regs) / sizeof(elf_greg_t)) +typedef elf_greg_t elf_gregset_t[ELF_NGREG]; + +/* Register set for the floating-point registers. */ +typedef struct user_fpregs elf_fpregset_t; + +/* Signal info. */ +struct elf_siginfo + { + int si_signo; /* Signal number. */ + int si_code; /* Extra code. */ + int si_errno; /* Errno. */ + }; + +/* Definitions to generate Intel SVR4-like core files. These mostly + have the same names as the SVR4 types with "elf_" tacked on the + front to prevent clashes with Linux definitions, and the typedef + forms have been avoided. This is mostly like the SVR4 structure, + but more Linuxy, with things that Linux does not support and which + GDB doesn't really use excluded. */ + +struct elf_prstatus + { + struct elf_siginfo pr_info; /* Info associated with signal. */ + short int pr_cursig; /* Current signal. */ + unsigned long int pr_sigpend; /* Set of pending signals. */ + unsigned long int pr_sighold; /* Set of held signals. */ + __pid_t pr_pid; + __pid_t pr_ppid; + __pid_t pr_pgrp; + __pid_t pr_sid; + struct timeval pr_utime; /* User time. */ + struct timeval pr_stime; /* System time. */ + struct timeval pr_cutime; /* Cumulative user time. */ + struct timeval pr_cstime; /* Cumulative system time. */ + elf_gregset_t pr_reg; /* GP registers. */ + int pr_fpvalid; /* True if math copro being used. */ + }; + + +#define ELF_PRARGSZ (80) /* Number of chars for args. */ + +struct elf_prpsinfo + { + char pr_state; /* Numeric process state. */ + char pr_sname; /* Char for pr_state. */ + char pr_zomb; /* Zombie. */ + char pr_nice; /* Nice val. */ + unsigned long int pr_flag; /* Flags. */ + unsigned short int pr_uid; + unsigned short int pr_gid; + int pr_pid, pr_ppid, pr_pgrp, pr_sid; + /* Lots missing */ + char pr_fname[16]; /* Filename of executable. */ + char pr_psargs[ELF_PRARGSZ]; /* Initial part of arg list. */ + }; + +/* The rest of this file provides the types for emulation of the + Solaris interfaces that should be implemented by + users of libthread_db. */ + +/* Addresses. */ +typedef void *psaddr_t; + +/* Register sets. Linux has different names. */ +typedef elf_gregset_t prgregset_t; +typedef elf_fpregset_t prfpregset_t; + +/* We don't have any differences between processes and threads, + therefore have only one PID type. */ +typedef __pid_t lwpid_t; + +/* Process status and info. In the end we do provide typedefs for them. */ +typedef struct elf_prstatus prstatus_t; +typedef struct elf_prpsinfo prpsinfo_t; + +__END_DECLS + +#endif /* sys/procfs.h */ diff --git a/sysdeps/unix/sysv/linux/nios2/sys/ucontext.h b/sysdeps/unix/sysv/linux/nios2/sys/ucontext.h new file mode 100644 index 0000000..404c662 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/sys/ucontext.h @@ -0,0 +1,48 @@ +/* Copyright (C) 2015 Free Software Foundation, Inc. + + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* System V/Nios II ABI compliant context switching support. */ + +#ifndef _SYS_UCONTEXT_H +#define _SYS_UCONTEXT_H 1 + +#include +#include + +/* These definitions must be in sync with the kernel. */ + +#define MCONTEXT_VERSION 2 + +/* Context to describe whole processor state. */ +typedef struct mcontext + { + int version; + unsigned long regs[32]; + } mcontext_t; + +/* Userlevel context. */ +typedef struct ucontext + { + unsigned long uc_flags; + struct ucontext *uc_link; + stack_t uc_stack; + mcontext_t uc_mcontext; + __sigset_t uc_sigmask; + } ucontext_t; + +#endif /* sys/ucontext.h */ diff --git a/sysdeps/unix/sysv/linux/nios2/sys/user.h b/sysdeps/unix/sysv/linux/nios2/sys/user.h new file mode 100644 index 0000000..323d8eb --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/sys/user.h @@ -0,0 +1,57 @@ +/* Copyright (C) 1998-2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _SYS_USER_H +#define _SYS_USER_H 1 + +/* The whole purpose of this file is for GDB and GDB only. Don't read + too much into it. Don't use it for anything other than GDB unless + you know what you are doing. */ + +struct user_fpregs +{ +}; + +struct user_regs +{ + unsigned long int uregs[49]; +}; + +struct user +{ + struct user_regs regs; /* General registers */ + int u_fpvalid; /* True if math co-processor being used. */ + + unsigned long int u_tsize; /* Text segment size (pages). */ + unsigned long int u_dsize; /* Data segment size (pages). */ + unsigned long int u_ssize; /* Stack segment size (pages). */ + + unsigned long start_code; /* Starting virtual address of text. */ + unsigned long start_stack; /* Starting virtual address of stack. */ + + long int signal; /* Signal that caused the core dump. */ + int reserved; /* No longer used */ + struct user_regs *u_ar0; /* help gdb to find the general registers. */ + + unsigned long magic; /* uniquely identify a core file */ + char u_comm[32]; /* User command that was responsible */ + int u_debugreg[8]; + struct user_fpregs u_fp; /* Floating point registers */ + struct user_fpregs *u_fp0; /* help gdb to find the FP registers. */ +}; + +#endif /* sys/user.h */ diff --git a/sysdeps/unix/sysv/linux/nios2/syscall.S b/sysdeps/unix/sysv/linux/nios2/syscall.S new file mode 100644 index 0000000..a6c4a5f --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/syscall.S @@ -0,0 +1,35 @@ +/* Copyright (C) 2005-2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +/* We don't need a special syscall to implement syscall(). It won't work + reliably with 64-bit arguments (but that is true on many modern platforms). +*/ + +ENTRY (syscall) + mov r2, r4 + mov r4, r5 + mov r5, r6 + mov r6, r7 + ldw r7, 0(sp) + ldw r8, 4(sp) + ldw r9, 8(sp) + trap + bne r7, zero, SYSCALL_ERROR_LABEL + ret +PSEUDO_END (syscall) diff --git a/sysdeps/unix/sysv/linux/nios2/sysdep-cancel.h b/sysdeps/unix/sysv/linux/nios2/sysdep-cancel.h new file mode 100644 index 0000000..a82dcf9 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/sysdep-cancel.h @@ -0,0 +1,140 @@ +/* Copyright (C) 2003-2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#ifndef __ASSEMBLER__ +# include +#endif + +#if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt) + +# undef PSEUDO +# define PSEUDO(name, syscall_name, args) \ + .type __##syscall_name##_nocancel, @function; \ + .globl __##syscall_name##_nocancel; \ + __##syscall_name##_nocancel: \ + cfi_startproc; \ + DO_CALL (syscall_name, args); \ + bne r7, zero, SYSCALL_ERROR_LABEL; \ + ret; \ + cfi_endproc; \ + .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \ + ENTRY (name) \ + SINGLE_THREAD_P(r2); \ + bne r2, zero, pseudo_cancel; \ + DO_CALL (syscall_name, args); \ + bne r7, zero, SYSCALL_ERROR_LABEL; \ + ret; \ + pseudo_cancel: \ + SAVESTK_##args; /* save syscall args and adjust stack */ \ + SAVEREG(ra, 0); /* save return address */ \ + SAVEREG(r22, 4); /* save GOT pointer */ \ + nextpc r22; \ +1: movhi r2, %hiadj(_gp_got - 1b); \ + addi r2, r2, %lo(_gp_got - 1b); \ + add r22, r22, r2; \ + CENABLE; \ + callr r3; \ + stw r2, 8(sp); /* save mask */ \ + LOADARGS_##args; \ + movi r2, SYS_ify(syscall_name); \ + trap; \ + stw r2, 12(sp); /* save syscall result */ \ + stw r7, 16(sp); /* save syscall error flag */ \ + ldw r4, 8(sp); /* pass mask as argument 1 */ \ + CDISABLE; \ + callr r3; \ + ldw r7, 16(sp); /* restore syscall error flag */ \ + ldw r2, 12(sp); /* restore syscall result */ \ + ldw ra, 0(sp); /* restore return address */ \ + ldw r22, 4(sp); /* restore GOT pointer */ \ + RESTORESTK_##args; \ + bne r7, zero, SYSCALL_ERROR_LABEL; + + +# undef PSEUDO_END +# define PSEUDO_END(sym) \ + SYSCALL_ERROR_HANDLER \ + END (sym) + +#define SAVEREG(REG, LOC) stw REG, LOC(sp); cfi_rel_offset (REG, LOC) +#define SAVESTK(X) subi sp, sp, X; cfi_adjust_cfa_offset(X) +#define SAVESTK_0 SAVESTK(20) +#define SAVEARG_1 SAVEREG(r4, 20) +#define SAVESTK_1 SAVESTK(24); SAVEARG_1 +#define SAVEARG_2 SAVEREG(r5, 24); SAVEARG_1 +#define SAVESTK_2 SAVESTK(28); SAVEARG_2 +#define SAVEARG_3 SAVEREG(r6, 28); SAVEARG_2 +#define SAVESTK_3 SAVESTK(32); SAVEARG_3 +#define SAVEARG_4 SAVEREG(r7, 32); SAVEARG_3 +#define SAVESTK_4 SAVESTK(36); SAVEARG_4 +#define SAVESTK_5 SAVESTK_4 +#define SAVESTK_6 SAVESTK_5 + +#define LOADARGS_0 +#define LOADARGS_1 ldw r4, 20(sp) +#define LOADARGS_2 LOADARGS_1; ldw r5, 24(sp) +#define LOADARGS_3 LOADARGS_2; ldw r6, 28(sp) +#define LOADARGS_4 LOADARGS_3; ldw r7, 32(sp) +#define LOADARGS_5 LOADARGS_4; ldw r8, 36(sp) +#define LOADARGS_6 LOADARGS_5; ldw r9, 40(sp) + +#define RESTORESTK(X) addi sp, sp, X; cfi_adjust_cfa_offset(-X) +#define RESTORESTK_0 RESTORESTK(20) +#define RESTORESTK_1 RESTORESTK(24) +#define RESTORESTK_2 RESTORESTK(28) +#define RESTORESTK_3 RESTORESTK(32) +#define RESTORESTK_4 RESTORESTK(36) +#define RESTORESTK_5 RESTORESTK(36) +#define RESTORESTK_6 RESTORESTK(36) + +# if IS_IN (libpthread) +# define CENABLE ldw r3, %call(__pthread_enable_asynccancel)(r22) +# define CDISABLE ldw r3, %call(__pthread_disable_asynccancel)(r22) +# elif IS_IN (librt) +# define CENABLE ldw r3, %call(__librt_enable_asynccancel)(r22) +# define CDISABLE ldw r3, %call(__librt_disable_asynccancel)(r22) +# elif IS_IN (libc) +# define CENABLE ldw r3, %call(__libc_enable_asynccancel)(r22) +# define CDISABLE ldw r3, %call(__libc_disable_asynccancel)(r22) +# else +# error Unsupported library +# endif + +# ifndef __ASSEMBLER__ +# define SINGLE_THREAD_P \ + __builtin_expect (THREAD_GETMEM (THREAD_SELF, \ + header.multiple_threads) \ + == 0, 1) +# else +# define SINGLE_THREAD_P(reg) \ + ldw reg, MULTIPLE_THREADS_OFFSET(r23) +#endif + +#elif !defined __ASSEMBLER__ + +# define SINGLE_THREAD_P 1 +# define NO_CANCELLATION 1 + +#endif + +#ifndef __ASSEMBLER__ +# define RTLD_SINGLE_THREAD_P \ + __builtin_expect (THREAD_GETMEM (THREAD_SELF, \ + header.multiple_threads) == 0, 1) +#endif diff --git a/sysdeps/unix/sysv/linux/nios2/sysdep.S b/sysdeps/unix/sysv/linux/nios2/sysdep.S new file mode 100644 index 0000000..93610cc --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/sysdep.S @@ -0,0 +1,49 @@ +/* Copyright (C) 2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +/* The following code is only used in the static library. In the shared + library, the error handling code is at the end of each function. */ + +#ifndef PIC + +/* In the static library, the syscall stubs jump here when they detect + an error. */ + +# undef CALL_MCOUNT +# define CALL_MCOUNT /* Don't insert the profiling call, it clobbers r2. */ + +# if IS_IN (libc) +# define SYSCALL_ERROR_ERRNO __libc_errno +# else +# define SYSCALL_ERROR_ERRNO errno +# endif + .text +ENTRY (__syscall_error) + nextpc r3 +1: + movhi r8, %hiadj(_gp_got - 1b) + addi r8, r8, %lo(_gp_got - 1b) + add r3, r3, r8 + ldw r3, %tls_ie(SYSCALL_ERROR_ERRNO)(r3) + add r3, r23, r3 + stw r2, 0(r3) + movi r2, -1 + ret +END (__syscall_error) +#endif diff --git a/sysdeps/unix/sysv/linux/nios2/sysdep.h b/sysdeps/unix/sysv/linux/nios2/sysdep.h new file mode 100644 index 0000000..7b53d5e --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/sysdep.h @@ -0,0 +1,260 @@ +/* Assembler macros for Nios II. + Copyright (C) 2000-2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _LINUX_NIOS2_SYSDEP_H +#define _LINUX_NIOS2_SYSDEP_H 1 + +#include +#include +#include +#include + +/* For RTLD_PRIVATE_ERRNO. */ +#include + +#include + +/* For Linux we can use the system call table in the header file + /usr/include/asm/unistd.h + of the kernel. But these symbols do not follow the SYS_* syntax + so we have to redefine the `SYS_ify' macro here. */ +#undef SYS_ify +#define SYS_ify(syscall_name) __NR_##syscall_name + +#ifdef __ASSEMBLER__ + +#define SYSCALL_ERROR_LABEL __local_syscall_error + +#undef PSEUDO +#define PSEUDO(name, syscall_name, args) \ + ENTRY (name) \ + DO_CALL (syscall_name, args) \ + bne r7, zero, SYSCALL_ERROR_LABEL; \ + +#undef PSEUDO_END +#define PSEUDO_END(name) \ + SYSCALL_ERROR_HANDLER \ + END (name) + +#undef PSEUDO_NOERRNO +#define PSEUDO_NOERRNO(name, syscall_name, args) \ + ENTRY (name) \ + DO_CALL (syscall_name, args) + +#undef PSEUDO_END_NOERRNO +#define PSEUDO_END_NOERRNO(name) \ + END (name) + +#undef ret_NOERRNO +#define ret_NOERRNO ret + +#undef DO_CALL +#define DO_CALL(syscall_name, args) \ + DOARGS_##args \ + movi r2, SYS_ify(syscall_name); \ + trap; + +#if defined(__PIC__) || defined(PIC) + +# if RTLD_PRIVATE_ERRNO + +# define SYSCALL_ERROR_HANDLER \ + SYSCALL_ERROR_LABEL: \ + nextpc r3; \ +1: \ + movhi r8, %hiadj(rtld_errno - 1b); \ + addi r8, r8, %lo(rtld_errno - 1b); \ + add r3, r3, r8; \ + stw r2, 0(r3); \ + movi r2, -1; \ + ret; + +# else + +# if IS_IN (libc) +# define SYSCALL_ERROR_ERRNO __libc_errno +# else +# define SYSCALL_ERROR_ERRNO errno +# endif +# define SYSCALL_ERROR_HANDLER \ + SYSCALL_ERROR_LABEL: \ + nextpc r3; \ +1: \ + movhi r8, %hiadj(_gp_got - 1b); \ + addi r8, r8, %lo(_gp_got - 1b); \ + add r3, r3, r8; \ + ldw r3, %tls_ie(SYSCALL_ERROR_ERRNO)(r3); \ + add r3, r23, r3; \ + stw r2, 0(r3); \ + movi r2, -1; \ + ret; + +# endif + +#else + +/* We can use a single error handler in the static library. */ +#define SYSCALL_ERROR_HANDLER \ + SYSCALL_ERROR_LABEL: \ + jmpi __syscall_error; + +#endif + +#define DOARGS_0 /* nothing */ +#define DOARGS_1 /* nothing */ +#define DOARGS_2 /* nothing */ +#define DOARGS_3 /* nothing */ +#define DOARGS_4 /* nothing */ +#define DOARGS_5 ldw r8, 0(sp); +#define DOARGS_6 ldw r9, 4(sp); ldw r8, 0(sp); + +/* The function has to return the error code. */ +#undef PSEUDO_ERRVAL +#define PSEUDO_ERRVAL(name, syscall_name, args) \ + ENTRY (name) \ + DO_CALL (syscall_name, args) + +#undef PSEUDO_END_ERRVAL +#define PSEUDO_END_ERRVAL(name) \ + END (name) + +#define ret_ERRVAL ret + +#else /* __ASSEMBLER__ */ + +/* In order to get __set_errno() definition in INLINE_SYSCALL. */ +#include + +/* Define a macro which expands into the inline wrapper code for a system + call. */ +#undef INLINE_SYSCALL +#define INLINE_SYSCALL(name, nr, args...) \ + ({ INTERNAL_SYSCALL_DECL(err); \ + unsigned int result_var = INTERNAL_SYSCALL (name, err, nr, args); \ + if ( INTERNAL_SYSCALL_ERROR_P (result_var, err) ) \ + { \ + __set_errno (INTERNAL_SYSCALL_ERRNO (result_var, err)); \ + result_var = -1L; \ + } \ + (int) result_var; }) + +#undef INTERNAL_SYSCALL_DECL +#define INTERNAL_SYSCALL_DECL(err) unsigned int err __attribute__((unused)) + +#undef INTERNAL_SYSCALL_ERROR_P +#define INTERNAL_SYSCALL_ERROR_P(val, err) ((void) (val), (unsigned int) (err)) + +#undef INTERNAL_SYSCALL_ERRNO +#define INTERNAL_SYSCALL_ERRNO(val, err) ((void) (err), val) + +#undef INTERNAL_SYSCALL_RAW +#define INTERNAL_SYSCALL_RAW(name, err, nr, args...) \ + ({ unsigned int _sys_result; \ + { \ + /* Load argument values in temporary variables + to perform side effects like function calls + before the call-used registers are set. */ \ + LOAD_ARGS_##nr (args) \ + LOAD_REGS_##nr \ + register int _r2 asm ("r2") = (int)(name); \ + register int _err asm ("r7"); \ + asm volatile ("trap" \ + : "+r" (_r2), "=r" (_err) \ + : ASM_ARGS_##nr \ + : __SYSCALL_CLOBBERS); \ + _sys_result = _r2; \ + err = _err; \ + } \ + (int) _sys_result; }) + +#undef INTERNAL_SYSCALL +#define INTERNAL_SYSCALL(name, err, nr, args...) \ + INTERNAL_SYSCALL_RAW(SYS_ify(name), err, nr, args) + +#undef INTERNAL_SYSCALL_NCS +#define INTERNAL_SYSCALL_NCS(number, err, nr, args...) \ + INTERNAL_SYSCALL_RAW(number, err, nr, args) + +#define LOAD_ARGS_0() +#define LOAD_REGS_0 +#define ASM_ARGS_0 +#define LOAD_ARGS_1(a1) \ + LOAD_ARGS_0 () \ + int __arg1 = (int) (a1); +#define LOAD_REGS_1 \ + register int _r4 asm ("r4") = __arg1; \ + LOAD_REGS_0 +#define ASM_ARGS_1 "r" (_r4) +#define LOAD_ARGS_2(a1, a2) \ + LOAD_ARGS_1 (a1) \ + int __arg2 = (int) (a2); +#define LOAD_REGS_2 \ + register int _r5 asm ("r5") = __arg2; \ + LOAD_REGS_1 +#define ASM_ARGS_2 ASM_ARGS_1, "r" (_r5) +#define LOAD_ARGS_3(a1, a2, a3) \ + LOAD_ARGS_2 (a1, a2) \ + int __arg3 = (int) (a3); +#define LOAD_REGS_3 \ + register int _r6 asm ("r6") = __arg3; \ + LOAD_REGS_2 +#define ASM_ARGS_3 ASM_ARGS_2, "r" (_r6) +#define LOAD_ARGS_4(a1, a2, a3, a4) \ + LOAD_ARGS_3 (a1, a2, a3) \ + int __arg4 = (int) (a4); +#define LOAD_REGS_4 \ + register int _r7 asm ("r7") = __arg4; \ + LOAD_REGS_3 +#define ASM_ARGS_4 ASM_ARGS_3, "r" (_r7) +#define LOAD_ARGS_5(a1, a2, a3, a4, a5) \ + LOAD_ARGS_4 (a1, a2, a3, a4) \ + int __arg5 = (int) (a5); +#define LOAD_REGS_5 \ + register int _r8 asm ("r8") = __arg5; \ + LOAD_REGS_4 +#define ASM_ARGS_5 ASM_ARGS_4, "r" (_r8) +#define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \ + LOAD_ARGS_5 (a1, a2, a3, a4, a5) \ + int __arg6 = (int) (a6); +#define LOAD_REGS_6 \ + register int _r9 asm ("r9") = __arg6; \ + LOAD_REGS_5 +#define ASM_ARGS_6 ASM_ARGS_5, "r" (_r9) + +#define __SYSCALL_CLOBBERS "memory" + +#endif /* __ASSEMBLER__ */ + +/* Pointer mangling support. */ +#if IS_IN (rtld) +/* We cannot use the thread descriptor because in ld.so we use setjmp + earlier than the descriptor is initialized. */ +#else +# ifdef __ASSEMBLER__ +# define PTR_MANGLE_GUARD(guard) ldw guard, POINTER_GUARD(r23) +# define PTR_MANGLE(dst, src, guard) xor dst, src, guard +# define PTR_DEMANGLE(dst, src, guard) PTR_MANGLE (dst, src, guard) +# else +# define PTR_MANGLE(var) \ + (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ()) +# define PTR_DEMANGLE(var) PTR_MANGLE (var) +# endif +#endif + + +#endif /* linux/nios2/sysdep.h */ diff --git a/sysdeps/unix/sysv/linux/nios2/ucontext_i.sym b/sysdeps/unix/sysv/linux/nios2/ucontext_i.sym new file mode 100644 index 0000000..a844c96 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/ucontext_i.sym @@ -0,0 +1,29 @@ +#include +#include +#include +#include + +#include "kernel_rt_sigframe.h" + +SIG_BLOCK +SIG_SETMASK + +_NSIG8 (_NSIG / 8) + +MCONTEXT_VERSION + +-- Offsets of the fields in the kernel rt_sigframe_t structure. +#define rt_sigframe(member) offsetof (struct kernel_rt_sigframe, member) + +RT_SIGFRAME_SIZE sizeof (struct kernel_rt_sigframe) +RT_SIGFRAME_UCONTEXT rt_sigframe (uc) + +-- Offsets of the fields in the ucontext_t structure. +#define ucontext(member) offsetof (ucontext_t, member) + +UCONTEXT_FLAGS ucontext (uc_flags) +UCONTEXT_LINK ucontext (uc_link) +UCONTEXT_STACK ucontext (uc_stack) +UCONTEXT_MCONTEXT ucontext (uc_mcontext) +UCONTEXT_SIGMASK ucontext (uc_sigmask) +UCONTEXT_SIZE sizeof (ucontext_t) diff --git a/sysdeps/unix/sysv/linux/nios2/vfork.S b/sysdeps/unix/sysv/linux/nios2/vfork.S new file mode 100644 index 0000000..c9ef6ad --- /dev/null +++ b/sysdeps/unix/sysv/linux/nios2/vfork.S @@ -0,0 +1,44 @@ +/* vfork for Nios II Linux. + Copyright (C) 2005-2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +ENTRY(__vfork) + + ldw r6, PID_OFFSET(r23) + sub r7, zero, r6 + bne r7, zero, 2f + movhi r7, %hi(0x80000000) +2: + stw r7, PID_OFFSET(r23) + + movi r4, 0x4111 /* (CLONE_VM | CLONE_VFORK | SIGCHLD) */ + mov r5, zero + DO_CALL (clone, 2) + + beq r2, zero, 1f + stw r6, PID_OFFSET(r23) +1: + bne r7, zero, SYSCALL_ERROR_LABEL + ret + +PSEUDO_END (__vfork) +libc_hidden_def (__vfork) + +weak_alias (__vfork, vfork)