From patchwork Fri Nov 8 17:12:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Capper X-Patchwork-Id: 21430 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qe0-f70.google.com (mail-qe0-f70.google.com [209.85.128.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2462C244F2 for ; Fri, 8 Nov 2013 17:12:33 +0000 (UTC) Received: by mail-qe0-f70.google.com with SMTP id 8sf3404572qea.5 for ; Fri, 08 Nov 2013 09:12:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=S5A0TLP7ajB3u2djgLLyTjEmI3mYXmnAL1lDFHpo3/U=; b=VG32ucn6TM3fChLgNJW7WdJETmz0Bmub1/ylRpYX7xVFBqh1wA5YywBag/0EB9x2qm dSLRxLtYDjFw1a69b7eRi/GsjAC8en4KUaqxFcXKCTanTu22U5sdJDZbuQJpTKocq9vY 8hOwO4jHUm24rd4Qfsq6MHUumOhK9jFeXhdTw0VzwBntNbT19GZRgK/C3/ARm9Ce/hAU v6thD4BK7f5bPjx6qyceBJeCeX2JK6jM6Wbkbx1EC9mctdI9O1ZKOVX3FW+XSGywuMDI fdaxT3XqH8ee2t8PhFz2pOz0M2tetKqna5NU1BffeeOiHSvqByTywC96Sn3JkfsUUOxZ mI3A== X-Gm-Message-State: ALoCoQn+fgC3yJtVcWwG4yAXahIC7pDOsi8/milO3FVlxfBio3SeZmmauTKmy8VsIudzMm7jujuO X-Received: by 10.58.171.135 with SMTP id au7mr5027447vec.22.1383930753011; Fri, 08 Nov 2013 09:12:33 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.72.227 with SMTP id g3ls1716859qev.57.gmail; Fri, 08 Nov 2013 09:12:32 -0800 (PST) X-Received: by 10.220.169.203 with SMTP id a11mr13098838vcz.26.1383930752900; Fri, 08 Nov 2013 09:12:32 -0800 (PST) Received: from mail-vb0-f46.google.com (mail-vb0-f46.google.com [209.85.212.46]) by mx.google.com with ESMTPS id v1si1792340vdh.74.2013.11.08.09.12.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 08 Nov 2013 09:12:32 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.46 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.46; Received: by mail-vb0-f46.google.com with SMTP id 10so1567724vbe.33 for ; Fri, 08 Nov 2013 09:12:32 -0800 (PST) X-Received: by 10.221.21.133 with SMTP id qs5mr7517008vcb.28.1383930752669; Fri, 08 Nov 2013 09:12:32 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp45662vcz; Fri, 8 Nov 2013 09:12:32 -0800 (PST) X-Received: by 10.194.250.6 with SMTP id yy6mr13032992wjc.13.1383930751696; Fri, 08 Nov 2013 09:12:31 -0800 (PST) Received: from mail-wg0-f51.google.com (mail-wg0-f51.google.com [74.125.82.51]) by mx.google.com with ESMTPS id ek9si431925wib.22.2013.11.08.09.12.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 08 Nov 2013 09:12:31 -0800 (PST) Received-SPF: neutral (google.com: 74.125.82.51 is neither permitted nor denied by best guess record for domain of steve.capper@linaro.org) client-ip=74.125.82.51; Received: by mail-wg0-f51.google.com with SMTP id l18so2261616wgh.30 for ; Fri, 08 Nov 2013 09:12:31 -0800 (PST) X-Received: by 10.180.12.14 with SMTP id u14mr3130561wib.63.1383930751230; Fri, 08 Nov 2013 09:12:31 -0800 (PST) Received: from marmot.wormnet.eu (marmot.wormnet.eu. [188.246.204.87]) by mx.google.com with ESMTPSA id pi6sm7326982wic.3.2013.11.08.09.12.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Nov 2013 09:12:30 -0800 (PST) From: Steve Capper To: klibc@zytor.com Cc: hpa@zytor.com, anil.singhar@linaro.org, steve.mcintyre@linaro.org, codehelp@debian.org, wookey@wookware.org, patches@linaro.org, Steve Capper Subject: [PATCH 3/3] arm64: Introduce arm64 support Date: Fri, 8 Nov 2013 17:12:16 +0000 Message-Id: <1383930736-20005-4-git-send-email-steve.capper@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1383930736-20005-1-git-send-email-steve.capper@linaro.org> References: <1383930736-20005-1-git-send-email-steve.capper@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: steve.capper@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.46 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Based on work by Neil Williams (codehelp@debian.org) and Anil Singhar (anil.singhar@linaro.org), this patch introduces arm64 support. Signed-off-by: Steve Capper --- Makefile | 3 +- usr/include/arch/arm64/klibc/archconfig.h | 17 ++++++++++ usr/include/arch/arm64/klibc/archsetjmp.h | 20 ++++++++++++ usr/include/arch/arm64/klibc/archsignal.h | 14 +++++++++ usr/include/arch/arm64/klibc/archstat.h | 29 +++++++++++++++++ usr/include/arch/arm64/klibc/asmmacros.h | 11 +++++++ usr/klibc/README.klibc | 1 + usr/klibc/SYSCALLS.def | 8 ++--- usr/klibc/arch/arm64/Kbuild | 7 +++++ usr/klibc/arch/arm64/MCONFIG | 23 ++++++++++++++ usr/klibc/arch/arm64/crt0.S | 19 +++++++++++ usr/klibc/arch/arm64/pipe.c | 10 ++++++ usr/klibc/arch/arm64/setjmp.S | 52 +++++++++++++++++++++++++++++++ usr/klibc/arch/arm64/syscall.S | 25 +++++++++++++++ usr/klibc/arch/arm64/sysstub.ph | 25 +++++++++++++++ usr/klibc/arch/arm64/vfork.S | 34 ++++++++++++++++++++ 16 files changed, 293 insertions(+), 5 deletions(-) create mode 100644 usr/include/arch/arm64/klibc/archconfig.h create mode 100644 usr/include/arch/arm64/klibc/archsetjmp.h create mode 100644 usr/include/arch/arm64/klibc/archsignal.h create mode 100644 usr/include/arch/arm64/klibc/archstat.h create mode 100644 usr/include/arch/arm64/klibc/asmmacros.h create mode 100644 usr/klibc/arch/arm64/Kbuild create mode 100644 usr/klibc/arch/arm64/MCONFIG create mode 100644 usr/klibc/arch/arm64/crt0.S create mode 100644 usr/klibc/arch/arm64/pipe.c create mode 100644 usr/klibc/arch/arm64/setjmp.S create mode 100644 usr/klibc/arch/arm64/syscall.S create mode 100644 usr/klibc/arch/arm64/sysstub.ph create mode 100644 usr/klibc/arch/arm64/vfork.S diff --git a/Makefile b/Makefile index 0a3ee69..a7da622 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,8 @@ export OBJDUMP := $(KLIBCROSS)objdump NOSTDINC_FLAGS := -nostdlib -nostdinc -isystem $(shell $(CC) -print-file-name=include) -ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/parisc64/parisc/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/ -e s/sh.*/sh/) +ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/parisc64/parisc/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/ \ + -e s/aarch64.*/arm64/ -e s/sh.*/sh/) export KLIBCARCH ?= $(ARCH) export KLIBCARCHDIR := $(shell echo $(KLIBCARCH) | sed -e s/s390x/s390/) diff --git a/usr/include/arch/arm64/klibc/archconfig.h b/usr/include/arch/arm64/klibc/archconfig.h new file mode 100644 index 0000000..5e2004b --- /dev/null +++ b/usr/include/arch/arm64/klibc/archconfig.h @@ -0,0 +1,17 @@ +/* + * include/arch/arm64/klibc/archconfig.h + * + * See include/klibc/sysconfig.h for the options that can be set in + * this file. + * + */ + +#ifndef _KLIBC_ARCHCONFIG_H +#define _KLIBC_ARCHCONFIG_H + +/* Use rt_* signals */ +#define _KLIBC_USE_RT_SIG 1 +#define _KLIBC_NO_MMU 0 +#define _KLIBC_REAL_VFORK 1 + +#endif /* _KLIBC_ARCHCONFIG_H */ diff --git a/usr/include/arch/arm64/klibc/archsetjmp.h b/usr/include/arch/arm64/klibc/archsetjmp.h new file mode 100644 index 0000000..1738617 --- /dev/null +++ b/usr/include/arch/arm64/klibc/archsetjmp.h @@ -0,0 +1,20 @@ +/* + * arch/arm64/include/klibc/archsetjmp.h + */ + +#ifndef _KLIBC_ARCHSETJMP_H +#define _KLIBC_ARCHSETJMP_H + +/* + * x19-x28 are callee saved, also save fp, lr, sp. + * d8-d15 are also callee saved. + */ + +struct __jmp_buf { + uint64_t __gregs[13]; + uint64_t __fpregs[8]; +}; + +typedef struct __jmp_buf jmp_buf[1]; + +#endif /* _SETJMP_H */ diff --git a/usr/include/arch/arm64/klibc/archsignal.h b/usr/include/arch/arm64/klibc/archsignal.h new file mode 100644 index 0000000..94e6bc8 --- /dev/null +++ b/usr/include/arch/arm64/klibc/archsignal.h @@ -0,0 +1,14 @@ +/* + * arch/arm64/include/klibc/archsignal.h + * + * Architecture-specific signal definitions + * + */ + +#ifndef _KLIBC_ARCHSIGNAL_H +#define _KLIBC_ARCHSIGNAL_H + +#include +/* No special stuff for this architecture */ + +#endif diff --git a/usr/include/arch/arm64/klibc/archstat.h b/usr/include/arch/arm64/klibc/archstat.h new file mode 100644 index 0000000..a1a3e79 --- /dev/null +++ b/usr/include/arch/arm64/klibc/archstat.h @@ -0,0 +1,29 @@ +#ifndef _KLIBC_ARCHSTAT_H +#define _KLIBC_ARCHSTAT_H + +#include + +struct stat { + unsigned long st_dev; /* Device. */ + unsigned long st_ino; /* File serial number. */ + unsigned int st_mode; /* File mode. */ + unsigned int st_nlink; /* Link count. */ + unsigned int st_uid; /* User ID of the file's owner. */ + unsigned int st_gid; /* Group ID of the file's group. */ + unsigned long st_rdev; /* Device number, if device. */ + unsigned long __pad1; + long st_size; /* Size of file, in bytes. */ + int st_blksize; /* Optimal block size for I/O. */ + int __pad2; + long st_blocks; /* Number 512-byte blocks allocated. */ + long st_atime; /* Time of last access. */ + unsigned long st_atime_nsec; + long st_mtime; /* Time of last modification. */ + unsigned long st_mtime_nsec; + long st_ctime; /* Time of last status change. */ + unsigned long st_ctime_nsec; + unsigned int __unused4; + unsigned int __unused5; + }; + +#endif diff --git a/usr/include/arch/arm64/klibc/asmmacros.h b/usr/include/arch/arm64/klibc/asmmacros.h new file mode 100644 index 0000000..c298f66 --- /dev/null +++ b/usr/include/arch/arm64/klibc/asmmacros.h @@ -0,0 +1,11 @@ +/* + * usr/include/arch/arm64/klibc/asmmacros.h + * + * Assembly macros used by arm64 system call stubs + */ + +#ifndef _KLIBC_ASMMACROS_H +#define _KLIBC_ASMMACROS_H + + +#endif /* _KLIBC_ASMMACROS_H */ diff --git a/usr/klibc/README.klibc b/usr/klibc/README.klibc index 7de5fea..c72ae47 100644 --- a/usr/klibc/README.klibc +++ b/usr/klibc/README.klibc @@ -36,6 +36,7 @@ b) If you're cross-compiling, you need to set KLIBCARCH to the arm-thumb: Untested arm: Working arm26: Not yet ported + arm64: Working avr32: Not yet ported cris: Working h8300: Not yet ported diff --git a/usr/klibc/SYSCALLS.def b/usr/klibc/SYSCALLS.def index c2f36e7..c1f5b70 100644 --- a/usr/klibc/SYSCALLS.def +++ b/usr/klibc/SYSCALLS.def @@ -21,7 +21,7 @@ void _exit,exit::_exit(int); pid_t clone::__clone(unsigned long, void *); pid_t clone::__clone2(unsigned long, void *, void *); # if ! _KLIBC_NO_MMU - pid_t fork(); + pid_t fork(); pid_t fork@forkish(); #endif #if _KLIBC_REAL_VFORK @@ -124,7 +124,7 @@ int fchmod(int, mode_t); int mkdir(const char *, mode_t); int mkdirat(int, const char *, mode_t); int rmdir(const char *); - int pipe(int *); + int pipe(int *); int pipe2(int *, int); mode_t umask(mode_t); int chroot(const char *); @@ -132,8 +132,8 @@ int chroot(const char *); int symlinkat(const char *, int, const char *); int readlink(const char *, char *, size_t); int readlinkat(int, const char *, char *, int); - int stat64,stat::stat(const char *, struct stat *); - int lstat64,lstat::lstat(const char *, struct stat *); + int stat64,stat::stat(const char *, struct stat *); + int lstat64,lstat::lstat(const char *, struct stat *); int fstat64,fstat::fstat(int, struct stat *); int stat::stat(const char *, struct stat *); int lstat::lstat(const char *, struct stat *); diff --git a/usr/klibc/arch/arm64/Kbuild b/usr/klibc/arch/arm64/Kbuild new file mode 100644 index 0000000..c23bd69 --- /dev/null +++ b/usr/klibc/arch/arm64/Kbuild @@ -0,0 +1,7 @@ + +# klibc files for arm64 +# + +klib-y := setjmp.o syscall.o vfork.o pipe.o +always := crt0.o +targets := crt0.o diff --git a/usr/klibc/arch/arm64/MCONFIG b/usr/klibc/arch/arm64/MCONFIG new file mode 100644 index 0000000..dfebc5e --- /dev/null +++ b/usr/klibc/arch/arm64/MCONFIG @@ -0,0 +1,23 @@ +# -*- makefile -*- +# +# arch/arm64/MCONFIG +# +# Special rules for this architecture. Note that this is actually +# included from the main Makefile, and that pathnames should be +# accordingly. +# + +CPU_ARCH ?= armv8-a +CPU_TUNE ?= generic + +KLIBCOPTFLAGS += -g -Os -march=$(CPU_ARCH) -mtune=$(CPU_TUNE) +KLIBCBITSIZE = 64 +KLIBCREQFLAGS += -fno-exceptions + +# Extra linkflags when building the shared version of the library +# This address needs to be reachable using normal inter-module +# calls, and work on the memory models for this architecture + +# On arm64, binaries are normally loaded at 4MB. Place klibc.so +# a little before that at 2MB to prevent overlap. +KLIBCSHAREDFLAGS = -Ttext 0x0200000 diff --git a/usr/klibc/arch/arm64/crt0.S b/usr/klibc/arch/arm64/crt0.S new file mode 100644 index 0000000..0b2dd32 --- /dev/null +++ b/usr/klibc/arch/arm64/crt0.S @@ -0,0 +1,19 @@ +# +# arch/arm64/crt0.S +# +# void _start(void) +# { +# __libc_init(elf_structure, atexit_ptr); +# } +# + + .text + .balign 8 + .type _start,#function + .globl _start + +_start: + mov x0, sp + mov x1, #0 + bl __libc_init + .size _start,.-_start diff --git a/usr/klibc/arch/arm64/pipe.c b/usr/klibc/arch/arm64/pipe.c new file mode 100644 index 0000000..f10a69e --- /dev/null +++ b/usr/klibc/arch/arm64/pipe.c @@ -0,0 +1,10 @@ +#include + +#ifndef __NR_pipe + +int pipe(int pipefd[2]) +{ + return pipe2(pipefd, 0); +} + +#endif /* __NR_pipe */ diff --git a/usr/klibc/arch/arm64/setjmp.S b/usr/klibc/arch/arm64/setjmp.S new file mode 100644 index 0000000..3d5c1c6 --- /dev/null +++ b/usr/klibc/arch/arm64/setjmp.S @@ -0,0 +1,52 @@ +# +# arch/arm64/setjmp.S +# +# setjmp/longjmp for arm64 +# + +#include + + .text + .balign 8 + .globl setjmp + .type setjmp, #function +setjmp: + mov x1, sp + stp x19, x20, [x0, #0] + stp x21, x22, [x0, #16] + stp x23, x24, [x0, #32] + stp x25, x26, [x0, #48] + stp x27, x28, [x0, #64] + stp x29, x30, [x0, #80] + str x1, [x0, #96] + stp d8, d9, [x0, #104] + stp d10, d11, [x0, #120] + stp d12, d13, [x0, #136] + stp d14, d15, [x0, #152] + mov x0, #0 /* set the return value of setjmp */ + br x30 + .size setjmp,.-setjmp + + .text + .balign 8 + .globl longjmp + .type longjmp, #function +longjmp: + ldp x19, x20, [x0, #0] + ldp x21, x22, [x0, #16] + ldp x23, x24, [x0, #32] + ldp x25, x26, [x0, #48] + ldp x27, x28, [x0, #64] + ldp x29, x30, [x0, #80] + ldr x2, [x0, #96] + ldp d8, d9, [x0, #104] + ldp d10, d11, [x0, #120] + ldp d12, d13, [x0, #136] + ldp d14, d15, [x0, #152] + mov sp, x2 + mov x0, x1 + cbnz x1, 1f + mov x0, #1 +1: + br x30 + .size longjmp,.-longjmp diff --git a/usr/klibc/arch/arm64/syscall.S b/usr/klibc/arch/arm64/syscall.S new file mode 100644 index 0000000..3ce91fb --- /dev/null +++ b/usr/klibc/arch/arm64/syscall.S @@ -0,0 +1,25 @@ +/* + * arch/arm64/syscall.S + * + * System call common handling - if the return + * value from the system call is negative, then + * extract the magnitude and return it as errno and + * return -1, if the return value is 0 that is + * success case. + */ + + .type __syscall_common,#function + .globl __syscall_common + .balign 8 + +__syscall_common: + cmp x0, #0x0 + b.ge 2f + neg x0, x0 + ldr x8, 1f + str x0, [x8] + mov x0, #-1 +2: + ret +1: + .dword errno diff --git a/usr/klibc/arch/arm64/sysstub.ph b/usr/klibc/arch/arm64/sysstub.ph new file mode 100644 index 0000000..47cbfd9 --- /dev/null +++ b/usr/klibc/arch/arm64/sysstub.ph @@ -0,0 +1,25 @@ +# -*- perl -*- +# +# arch/arm64/sysstub.ph +# +# Script to generate system call stubs +# + +sub make_sysstub($$$$$@) { + my($outputdir, $fname, $type, $sname, $stype, @args) = @_; + + open(OUT, '>', "${outputdir}/${fname}.S"); + print OUT "#include \n"; + print OUT "#include \n"; + print OUT " .text\n"; + print OUT " .type ${fname}, #function\n"; + print OUT " .globl ${fname}\n"; + print OUT " .balign 8\n"; + print OUT "${fname}:\n"; + print OUT " mov w8,__NR_${sname}\n"; + print OUT " svc 0\n"; + print OUT " b __syscall_common\n"; + print OUT " .size ${fname},.-${fname}\n"; +} + +1; diff --git a/usr/klibc/arch/arm64/vfork.S b/usr/klibc/arch/arm64/vfork.S new file mode 100644 index 0000000..494326c --- /dev/null +++ b/usr/klibc/arch/arm64/vfork.S @@ -0,0 +1,34 @@ +/* + * arch/arm64/vfork.S + * + * vfork - a system call which must not use the stack. + */ + +#include +#include + + .type vfork,#function + .globl vfork + .balign 8 + +vfork: + /* Prepare for the system call */ + /* 1. Push the function pointer and argument location + on to the child process stack */ + /* 2. Gather the Flags */ + /* New sp is already in x1. */ + mov x0, #0x4111 /* CLONE_VM | CLONE_VFORK | SIGCHLD */ + mov x1, sp + mov w8,__NR_clone + svc 0 + cmp x0, #0x0 + b.ge 2f + neg x0, x0 + ldr x8, 1f + str x0, [x8] + mov x0, #-1 +2: + ret +1: + .dword errno + .size vfork,.-vfork