From ee92c0fe5c1b9d59508273916e2c9a75b68dbc13 Mon Sep 17 00:00:00 2001 From: Waldemar Brodkorb Date: Thu, 21 Apr 2016 01:25:29 +0200 Subject: nds32: add support for new architecture Add support for Andes Technology NDS32 architecture. See here http://www.andestech.com/en/index/index.htm for more informaton. Verification of the port from an older uClibc port was done on a sponsored AG101p board. The testsuite only has 5 errors, three are related to an existing bug in dlclose() with LT.old, also happening on cris32 and m68k. Failures to fallocate/posix_fallocate are unresolved. Thanks to Andes Technology sponsoring the hardware and being very helpful while doing the uClibc-ng porting. Signed-off-by: Waldemar Brodkorb --- libc/string/nds32/Makefile | 13 +++++++ libc/string/nds32/memcpy.S | 88 ++++++++++++++++++++++++++++++++++++++++++++++ libc/string/nds32/memset.S | 66 ++++++++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 libc/string/nds32/Makefile create mode 100644 libc/string/nds32/memcpy.S create mode 100644 libc/string/nds32/memset.S (limited to 'libc/string') diff --git a/libc/string/nds32/Makefile b/libc/string/nds32/Makefile new file mode 100644 index 000000000..0a95346fd --- /dev/null +++ b/libc/string/nds32/Makefile @@ -0,0 +1,13 @@ +# Makefile for uClibc +# +# Copyright (C) 2000-2005 Erik Andersen +# +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. +# + +top_srcdir:=../../../ +top_builddir:=../../../ +all: objs +include $(top_builddir)Rules.mak +include ../Makefile.in +include $(top_srcdir)Makerules diff --git a/libc/string/nds32/memcpy.S b/libc/string/nds32/memcpy.S new file mode 100644 index 000000000..4f285b5ee --- /dev/null +++ b/libc/string/nds32/memcpy.S @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2016 Andes Technology, Inc. + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +#include +!========================================================== +! void *memcpy(void *dst, const void *src, int n); +! +! dst: $r0 +! src: $r1 +! n : $r2 +! ret: $r0 - pointer to the memory area dst. +!========================================================== +.weak memcpy +ENTRY(memcpy) + move $r5, $r0 + beq $r0, $r1, .Lquit_memcpy + beqz $r2, .Lquit_memcpy + srli $r3, $r2, #5 ! check if len < cache-line size 32 + beqz $r3, .Lword_copy_entry + andi $r4, $r0, #0x3 ! check byte-align + beqz $r4, .Lunalign_word_copy_entry + + addi $r4, $r4, #-4 + abs $r4, $r4 ! check how many un-align byte to copy + sub $r2, $r2, $r4 ! update $R2 + +.Lunalign_byte_copy: + lbi.bi $r3, [$r1], #1 + addi $r4, $r4, #-1 + sbi.bi $r3, [$r0], #1 + bnez $r4, .Lunalign_byte_copy + beqz $r2, .Lquit_memcpy + +.Lunalign_word_copy_entry: + andi $r3, $r0, 0x1f ! check cache-line unaligncount + beqz $r3, .Lcache_copy + + addi $r3, $r3, #-32 + abs $r3, $r3 + sub $r2, $r2, $r3 ! update $R2 + +.Lunalign_word_copy: + lmw.bim $r4, [$r1], $r4 + addi $r3, $r3, #-4 + smw.bim $r4, [$r0], $r4 + bnez $r3, .Lunalign_word_copy + beqz $r2, .Lquit_memcpy + + addi $r3, $r2, #-32 ! to check $r2 < cache_line, than go to .Lword_copy + bltz $r3, .Lword_copy_entry +.Lcache_copy: + srli $r3, $r2, #5 + beqz $r3, .Lword_copy_entry + pushm $r6, $r13 +.L3: + lmw.bim $r6, [$r1], $r13 + addi $r3, $r3, #-1 + smw.bim $r6, [$r0], $r13 + bnez $r3, .L3 + popm $r6, $r13 + +.Lword_copy_entry: + andi $r2, $r2, #31 + beqz $r2, .Lquit_memcpy + srli $r3, $r2, #2 + beqz $r3, .Lbyte_copy +.Lword_copy: + lmw.bim $r4, [$r1], $r4 + addi $r3, $r3, #-1 + smw.bim $r4, [$r0], $r4 + bnez $r3, .Lword_copy + andi $r2, $r2, #3 + beqz $r2, .Lquit_memcpy + +.Lbyte_copy: + lbi.bi $r3, [$r1], #1 + addi $r2, $r2, #-1 + sbi.bi $r3, [$r0], #1 + bnez $r2, .Lbyte_copy + +.Lquit_memcpy: + move $r0, $r5 + ret + +END(memcpy) +libc_hidden_def(memcpy) diff --git a/libc/string/nds32/memset.S b/libc/string/nds32/memset.S new file mode 100644 index 000000000..edd15a410 --- /dev/null +++ b/libc/string/nds32/memset.S @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2016 Andes Technology, Inc. + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +/* Copyright (C) 1998, 2003 Free Software Foundation, Inc. + * Contributed by Philip Blundell + * + * 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, write to the Free + * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + */ + +#include +#include +!========================================================== +! void *memset(void *dst, int val, int len); +! +! dst: $r0 +! val: $r1 +! len: $r2 +! ret: $r0 - pointer to the memory area dst. +!========================================================== +.weak memset +ENTRY(memset) + move $r5, $r0 ! Return value + beqz $r2, .Lend_memset ! Exit when len = 0 + srli $r3, $r2, 2 ! r3 is how many words to copy + andi $r2, $r2, 3 ! How many bytes are less than a word + beqz $r3, .Lbyte_set ! When n is less than a word + + ! set r1 from to abababab + andi $r1, $r1, 0x00ff ! r1 = 000000ab + slli $r4, $r1, 8 ! r4 = 0000ab00 + or $r1, $r1, $r4 ! r1 = 0000abab + slli $r4, $r1, 16 ! r4 = abab0000 + or $r1, $r1, $r4 ! r1 = abababab + +.Lword_set: + addi $r3, $r3, -1 ! How many words left to copy + smw.bim $r1, [$r5], $r1 ! Copy the word to det + bnez $r3, .Lword_set ! Still words to set, continue looping + beqz $r2, .Lend_memset ! No left byte to set + +.Lbyte_set: + ! Less than 4 bytes left to set + addi $r2, $r2, -1 ! Decrease len by 1 + sbi.p $r1, [$r5], 1 ! Set data of the next byte to r1 + bnez $r2, .Lbyte_set ! Still bytes left to set + +.Lend_memset: + ret + +END(memset) +libc_hidden_def(memset) -- cgit v1.2.3